import {$gettext} from './lib/gettext';
jQuery(function ($) {
$(document).on('click', 'a.mvv-load-in-new-row', function () {
STUDIP.MVV.Content.loadRow($(this));
return false;
});
$(document).on('click', '.loaded-details a.cancel', function () {
$(this).closest('.loaded-details').prev().find('toggler').click();
return false;
});
STUDIP.MVV.Sort.init($('.sortable'));
$(document).on('change', '#mvv-chooser select', function(){
STUDIP.MVV.Chooser.create($(this));
return false;
});
$(document).on('click', '.mvv-item-remove', function () {
STUDIP.MVV.Content.removeItem(this);
return false;
});
$(document).on('click', '.mvv-item-edit', function () {
STUDIP.MVV.Content.editAnnotation(this);
return false;
});
$(document).on('click', '.mvv-item-edit-properties', function () {
$(this).parents("li").find(".mvv-item-document-comments").toggle();
return false;
});
// get the quicksearch input
$(document).on('click focus', '.ui-autocomplete-input', function() {
STUDIP.MVV.Search.qs_input = this;
return false;
});
$('.with-datepicker').datepicker();
$(document).on('change', '.mvv-inst-chooser select', function() {
STUDIP.MVV.LanguageChooser.showButtons($(this));
return false;
});
$(document).on('click', '.mvv-show-original', function() {
STUDIP.MVV.Content.showOriginal($(this));
return false;
});
$(document).on('click', '.mvv-show-all-original', function() {
STUDIP.MVV.Content.showAllOriginal();
return false;
});
$(document).on('click', 'a.mvv-new-tab', function () {
STUDIP.MVV.Diff.openNewTab(this);
return false;
});
$(document).on('click', 'input.mvv-qs-button', function () {
STUDIP.MVV.Search.addSelect($(this));
return false;
});
$(document).on('click', '.stgfile .remove_attachment', function () {
STUDIP.Dialog.confirm($gettext('Soll die Datei wirklich gelöscht werden?')).done(() => {
STUDIP.MVV.Document.remove_attachment(this);
});
return false;
});
$(document).on('click', '.stgfile .refresh_attachment', (event) => {
STUDIP.MVV.Document.refresh_attachment(event.target);
event.preventDefault();
});
STUDIP.dialogReady(
function() {
const contactSearchParams = $('#search-contact-params');
const contactSearchSelect = $('#search-contact-select');
if (contactSearchParams) {
contactSearchSelect.select2({
placeholder: contactSearchSelect.data('placeholder'),
minimumInputLength: 3,
ajax: {
url: STUDIP.URLHelper.getURL('dispatch.php/shared/contacts/search_'
+ contactSearchSelect.data('search_type')),
data(params) {
return {
term: params.term,
_type: params._type,
contact_id: contactSearchParams.data('contact')
};
},
dataType: 'json'
}
});
}
$('#search-file-select').select2({
placeholder: $gettext('Dokument suchen'),
minimumInputLength: 3,
ajax: {
url: STUDIP.URLHelper.getURL('dispatch.php/materialien/files/search_file'),
dataType: 'json'
}
});
$('#search-file-studiengang-select').select2({
placeholder: $gettext('Studiengang suchen'),
minimumInputLength: 3,
ajax: {
url: STUDIP.URLHelper.getURL('dispatch.php/materialien/files/search_studiengang'),
dataType: 'json'
}
});
$('#search-file-modul-select').select2({
placeholder: $gettext('Modul suchen'),
minimumInputLength: 3,
ajax: {
url: STUDIP.URLHelper.getURL('dispatch.php/materialien/files/search_modul'),
dataType: 'json'
}
});
$('#search-file-abschlusskategorie-select').select2({
placeholder: $gettext('AbschlussKategorie suchen'),
minimumInputLength: 3,
ajax: {
url: STUDIP.URLHelper.getURL('dispatch.php/materialien/files/search_abschlusskategorie'),
dataType: 'json'
}
});
}
);
});
/* ------------------------------------------------------------------------
* the local MVV namespace
* ------------------------------------------------------------------------ */
window.STUDIP.MVV = window.STUDIP.MVV || {};
STUDIP.MVV.Search = {
qs_input : null,
qs_selected_name : null,
getFocus(item_id) {
const qs_input = jQuery(STUDIP.MVV.Search.qs_input);
const qs_item = jQuery('#' + qs_input.attr('id'));
if (item_id === '') {
STUDIP.MVV.Search.addSelect(qs_item);
} else {
qs_input.closest('form')
.find('.mvv-submit')
.show()
.focus();
}
return true;
},
addButton(item_id) {
const qs_input = jQuery(STUDIP.MVV.Search.qs_input);
const qs_item = jQuery('#' + qs_input.attr('id'));
if (item_id === '') {
STUDIP.MVV.Search.addSelect(qs_item);
} else {
STUDIP.MVV.Search.addTheButton(qs_item);
}
return true;
},
addTheButton(qs_item) {
const add_button = jQuery('').addClass('mvv-add-item');
const qs_name = qs_item.attr('id');
const target_name = qs_name.slice(0, qs_name.lastIndexOf('_'));
const item_id = jQuery('#' + qs_name + '_realvalue').val();
jQuery('')
.attr('alt', $gettext("hinzufügen"))
.appendTo(add_button);
if (item_id === '') {
qs_item.siblings('.mvv-add-button').find('.mvv-add-item')
.fadeOut('slow', function () {
qs_item.val('').focus();
jQuery(this).remove();
});
} else {
add_button.click(function () {
if (_.isNull(STUDIP.MVV.Search.qs_selected_name)) {
STUDIP.MVV.Content.addItem(target_name, item_id,
qs_item.val());
} else {
STUDIP.MVV.Content.addItem(target_name, item_id,
STUDIP.MVV.Search.qs_selected_name);
}
jQuery(this).fadeOut('slow', function () {
qs_item.val('').focus();
jQuery(this).remove();
});
jQuery('#select_' + qs_name).fadeOut('fast', function () {
jQuery(this).next('.mvv-search-reset').fadeOut();
jQuery('#' + qs_name).fadeIn();
jQuery(this).remove();
});
return false;
}
);
qs_item.siblings('.mvv-add-button').first().children('.mvv-add-item')
.fadeOut('slow').remove();
qs_item.siblings('.mvv-add-button').first().append(add_button);
add_button.fadeIn('slow');
qs_item.siblings('.mvv-select-group').fadeIn();
add_button.focus();
qs_item.focus(function () {
add_button.fadeOut();
qs_item.siblings('.mvv-select-group').fadeOut();
});
}
return true;
},
addSelect: function (qs_item) {
var qs_input = jQuery('#' + qs_item.data('qs_name')),
qs_real = qs_input.prev('input'),
qs_name = qs_input.attr('id'),
qs_select = jQuery('').attr('id', 'select_' + qs_name)
.addClass('mvv-search-select-list'),
qs_id = qs_item.data('qs_id'),
do_submit = qs_item.data('qs_submit');
var reset_button = jQuery('');
reset_button.attr({
src: STUDIP.ASSETS_URL+'images/icons/blue/decline.svg',
title: $gettext("Suche zurücksetzen")
}).addClass('mvv-search-reset');
if (!_.isUndefined(do_submit)) {
qs_select.change(function() {
var selected = qs_select.children('option:selected');
qs_real.val(selected.val());
if (do_submit === 'yes') {
qs_input.closest('form').submit();
}
});
} else {
qs_select.change(function() {
var selected = qs_select.children('option:selected');
STUDIP.MVV.Search.addSelected.call(
qs_real,
selected.val(),
selected.text().trim()
);
});
}
jQuery.ajax({
url: STUDIP.URLHelper.getURL(STUDIP.MVV.CONTROLLER_URL + 'qs_result'),
data: {'qs_id': qs_id, 'qs_term': qs_input.val()},
type: 'POST',
success: function (data) {
for (var i in data) {
var d = data[i];
jQuery('').attr('value', d.id).text(d.name)
.appendTo(qs_select);
}
qs_input.fadeOut('fast', function () {
var inp = jQuery(this);
reset_button.click(function () {
qs_select.fadeOut('fast', function () {
reset_button.hide();
qs_select.remove();
inp.val('');
inp.fadeIn().focus();
qs_item.fadeIn();
});
reset_button.remove();
});
qs_select.insertAfter(qs_input);
qs_item.fadeOut('fast', function () {
reset_button.insertAfter(this).fadeIn();
});
qs_select.fadeIn().focus();
});
}
});
},
submitSelected() {
jQuery(this).closest('form').submit();
},
addSelected(item_id, item_name) {
const strip_tags = /<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi;
const qs_name = $(this).attr('name');
//QUICKSEARCHTODO
//target_name = qs_id.slice(0, qs_id.lastIndexOf('_'));
const target_name = qs_name.split('_')[0];
STUDIP.MVV.Content.addItem(
target_name,
item_id,
jQuery('
')
.appendTo(prop_input);
jQuery('').appendTo(prop_input);
jQuery('
')
.appendTo(prop_input);
jQuery('').appendTo(prop_input);
prop_input.appendTo(item);
}
if (target.hasClass('mvv-assign-group')) {
target = target.find('#' + target_name + '_' + group_id);
target.append(item);
target.parent().fadeIn('fast', function () {
item.effect('highlight', {color: '#55ff55'}, 1500);
});
} else {
target.append(item);
item.effect('highlight', {color: '#55ff55'}, 1500);
}
}
},
addItemFromDialog(data) {
STUDIP.MVV.Content.addItem(data.target, data.item_id, data.item_name);
},
removeItem(this_button) {
var item = jQuery(this_button).closest('li');
if (item.closest('.mvv-assigned-items').hasClass('mvv-assign-group')) {
if (item.siblings().length == 0) {
item.parent().parent('li').fadeOut();
}
if (item.parent().parent().siblings(':visible').length == 0) {
item.parent().parent()
.siblings('.mvv-item-list-placeholder').fadeIn('slow');
}
} else {
if (item.siblings().length < 2) {
item.siblings('.mvv-item-list-placeholder').fadeIn('slow');
}
}
item.remove();
},
editAnnotation(button) {
var this_button = jQuery(button),
item = this_button.closest('li'),
target_id = item.attr('id'),
target_name = target_id.slice(0, target_id.lastIndexOf('_')),
item_id = target_id.slice(target_id.lastIndexOf('_') + 1, target_id.length),
annotation = item.children('.mvv-item-list-properties').first(),
content = annotation.children('div').first();
content.hide('slow', function () {
jQuery('').attr('name', target_name + '_annotations['
+ item_id + ']').text(content.text()).hide().appendTo(annotation)
.fadeIn();
this_button.fadeOut();
});
},
editProperties(button) {
var this_button = jQuery(button),
item = this_button.closest('li');
STUDIP.MVV.EditForm.openRef(item);
},
loadRow(element) {
if (element.data('busy')) {
return false;
}
if (element.closest('tr').next().hasClass('loaded-details')) {
element.closest('tbody').toggleClass('collapsed not-collapsed');
return false;
}
element.data('busy', true);
jQuery.get(element.attr('href'), '', function (response) {
var row = jQuery('