Skip to content
Snippets Groups Projects
Commit 66490f66 authored by Elmar Ludwig's avatar Elmar Ludwig
Browse files

drop unused code, fixes #3351

Closes #3351

Merge request studip/studip!2277
parent 737c0b2a
No related branches found
No related tags found
No related merge requests found
STUDIP.domReady(() => {
STUDIP.News.dialog_width = window.innerWidth * (1 / 2);
STUDIP.News.dialog_height = window.innerHeight - 60;
if (STUDIP.News.dialog_width < 550) {
STUDIP.News.dialog_width = 550;
}
if (STUDIP.News.dialog_height < 400) {
STUDIP.News.dialog_height = 400;
}
STUDIP.News.pending_ajax_request = false;
// open/close categories without ajax-request
$(document).on('click', '.news_category_header', function(event) {
event.preventDefault();
STUDIP.News.toggle_category_view(
$(this)
.parent('div')
.attr('id')
);
});
$(document).on('click', '.news_category_header input[type=image]', function(event) {
event.preventDefault();
});
});
...@@ -30,7 +30,6 @@ import "./bootstrap/personal_notifications.js" ...@@ -30,7 +30,6 @@ import "./bootstrap/personal_notifications.js"
import "./bootstrap/dialog.js" import "./bootstrap/dialog.js"
import "./bootstrap/jsupdater.js" import "./bootstrap/jsupdater.js"
import "./bootstrap/files.js" import "./bootstrap/files.js"
import "./bootstrap/news.js"
import "./bootstrap/messages.js" import "./bootstrap/messages.js"
import "./bootstrap/quick_search.js" import "./bootstrap/quick_search.js"
import "./bootstrap/multi_select.js" import "./bootstrap/multi_select.js"
......
...@@ -46,7 +46,6 @@ import Messages from './lib/messages.js'; ...@@ -46,7 +46,6 @@ import Messages from './lib/messages.js';
import MultiPersonSearch from './lib/multi_person_search.js'; import MultiPersonSearch from './lib/multi_person_search.js';
import MultiSelect from './lib/multi_select.js'; import MultiSelect from './lib/multi_select.js';
import NavigationShrinker from './lib/navigation_shrinker.js'; import NavigationShrinker from './lib/navigation_shrinker.js';
import News from './lib/news.js';
import OER from './lib/oer.js'; import OER from './lib/oer.js';
import OldUpload from './lib/old_upload.js'; import OldUpload from './lib/old_upload.js';
import Overlapping from './lib/overlapping.js'; import Overlapping from './lib/overlapping.js';
...@@ -136,7 +135,6 @@ window.STUDIP = _.assign(window.STUDIP || {}, { ...@@ -136,7 +135,6 @@ window.STUDIP = _.assign(window.STUDIP || {}, {
MultiPersonSearch, MultiPersonSearch,
MultiSelect, MultiSelect,
NavigationShrinker, NavigationShrinker,
News,
OER, OER,
OldUpload, OldUpload,
Overlapping, Overlapping,
......
import { $gettext } from '../lib/gettext.js';
const News = {
/**
* (Re-)initialise news-page, f.e. to stay in dialog
*/
init (id) {
$('.add_toolbar').addToolbar();
STUDIP.i18n.init(`#${id}`);
// prevent forms within dialog from reloading whole page, and reload dialog instead
$(`#${id} form`).on('click', function (event) {
$(this).data('clicked', $(event.target));
}).on('submit', function (event) {
event.preventDefault();
var textarea, button, form_route, form_data;
if (STUDIP.editor_enabled) {
textarea = $('textarea.news_body');
// wysiwyg is active, ensure HTML markers are set
textarea.each(function () {
$(this).val(STUDIP.wysiwyg.markAsHtml($(this).val()));
});
}
button = $(this).data('clicked').attr('name');
form_route = $(this).attr('action');
form_data = $(this).serialize() + '&' + button + '=1';
$(this).find(`input[name=${button}]`).showAjaxNotification('left');
News.update_dialog(id, form_route, form_data);
});
$(document).on('change', `#${id} form .news_date`, function () {
// This is neccessary since datepickers are initialiszed on focus
// which might not have occured yet
STUDIP.UI.Datepicker.init();
var start = $('#news_startdate').blur().datepicker('getDate'),
duration,
end,
result;
if ($(this).is('#news_duration')) {
// datepicker assumes beginning of day (00:00), but the duration includes the end date (until 23:59)
duration = window.parseInt(this.value, 10) - 1;
result = new Date(start);
result.setDate(result.getDate() + duration);
$('#news_enddate').datepicker('setDate', result);
} else {
start = $('#news_startdate').datepicker('getDate');
end = $('#news_enddate').datepicker('getDate');
// datepicker assumes beginning of day (see above) and we need to add a day to the duration
duration = Math.round((end - start) / (24 * 60 * 60 * 1000)) + 1;
duration = Math.max(0, duration);
$('#news_duration').val(duration);
}
});
},
update_dialog (id, route, form_data) {
if (!News.pending_ajax_request) {
News.pending_ajax_request = true;
$.post(route, form_data, 'html').done(function (html) {
var obj;
News.pending_ajax_request = false;
if (html.length > 0) {
$(`#${id}`).html(html);
$(`#${id}_content`).css({
height : (News.dialog_height - 120) + 'px',
maxHeight: (News.dialog_height - 120) + 'px'
});
// scroll to anker
obj = $('a[name=anker]');
if (obj.length > 0) {
$(`#${id}_content`).scrollTop(obj.position().top);
}
} else {
$(`#${id}`).dialog('close');
obj = $('#admin_news_form');
if (obj.length > 0) {
$('#admin_news_form').submit();
} else {
location.replace(STUDIP.URLHelper.getURL(location.href, {nsave: 1}));
}
}
News.init(id);
}).fail(function () {
News.pending_ajax_request = false;
window.alert($gettext('Fehler beim Aufruf des News-Controllers'));
});
}
},
toggle_category_view (id) {
if ($(`input[name=${id}_js]`).val() === 'toggle') {
$(`input[name=${id}_js]`).val('');
} else {
$(`input[name=${id}_js]`).val('toggle');
}
if ($(`#${id}_content`).is(':visible')) {
$(`#${id}_content`).slideUp(400);
$(`#${id} input[type=image]:first`)
.attr('src', STUDIP.ASSETS_URL + 'images/icons/blue/arr_1right.svg');
} else {
$(`#${id}_content`).slideDown(400);
$(`#${id} input[type=image]:first`)
.attr('src', STUDIP.ASSETS_URL + 'images/icons/blue/arr_1down.svg');
}
}
};
export default News;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment