Total Complexity | 374 |
Complexity/F | 1.74 |
Lines of Code | 2104 |
Function Count | 215 |
Duplicated Lines | 26 |
Ratio | 1.24 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Resources/Public/JavaScript/kitodopublication.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | /** |
||
14 | var userNotifcationSettings = { |
||
15 | init: function() { |
||
16 | |||
17 | if (!jQuery("#notifyOnChanges").prop("checked")) { |
||
18 | jQuery(".notifyOnChanges-child").prop("disabled","true"); |
||
19 | } |
||
20 | |||
21 | jQuery("#notifyOnChanges").on("click", function(){ |
||
22 | if (jQuery(this).prop("checked")) { |
||
23 | jQuery(this).parent().find(".notifyOnChanges-child").prop("disabled",false); |
||
24 | } else { |
||
25 | jQuery(this).parent().find(".notifyOnChanges-child").prop("disabled",true); |
||
26 | } |
||
27 | }); |
||
28 | } |
||
29 | } |
||
30 | var documentFormGroupSelector = { |
||
31 | init() { |
||
32 | var form = jQuery(".document-form-main"); |
||
33 | if (typeof form !== "undefined" && form.length > 0) { |
||
34 | |||
35 | var activeGroup = form.data("activegroup"); |
||
36 | var activeGroupIndex = form.data("activegroupindex"); |
||
37 | |||
38 | var tab = jQuery('fieldset[data-group="' + activeGroup + '"]').parent().attr("id"); |
||
39 | |||
40 | if (typeof tab !== "undefined" && tab.length > 0) { |
||
41 | jQuery('.nav-link').removeClass("active"); |
||
42 | jQuery('.tab-pane').removeClass("active"); |
||
43 | jQuery('.nav-link[href="#' + tab + '"]').addClass("active"); |
||
44 | jQuery('fieldset[data-group="' + activeGroup + '"]').parent().addClass("active"); |
||
45 | |||
46 | if (activeGroupIndex >= 0) { |
||
47 | var group = jQuery('fieldset[data-group="' + activeGroup + '"]:eq(' + activeGroupIndex + ')'); |
||
48 | jQuery('html, body').animate({ |
||
49 | scrollTop: jQuery(group).offset().top - 150 |
||
50 | }, 0); |
||
51 | } else { |
||
52 | var emptyGroupElement = jQuery('fieldset[data-group="' + activeGroup + '"][data-emptygroup="1"]').first(); |
||
53 | |||
54 | if (emptyGroupElement.length > 0) { |
||
55 | activeGroupIndex = emptyGroupElement.data('groupindex'); |
||
56 | } else { |
||
57 | activeGroupIndex = jQuery('fieldset[data-group="' + activeGroup + '"]').size(); |
||
58 | } |
||
59 | |||
60 | if (activeGroupIndex > 0) { |
||
61 | addGroup(jQuery('button.add_group[data-group="' + activeGroup + '"]')); |
||
62 | } |
||
63 | |||
64 | if (form.data("addcurrentfeuser")) { |
||
65 | isGroupLoaded( |
||
66 | 'fieldset[data-group="' + activeGroup + '"][data-groupindex="' + activeGroupIndex + '"]', |
||
67 | function () { |
||
68 | jQuery('.addMyData').hide(); |
||
69 | var activeGroupElement = jQuery('fieldset[data-group="' + activeGroup + '"][data-groupindex="' + activeGroupIndex + '"]'); |
||
70 | //var context = jQuery('#userSearchModal-'+activeGroupIndex).find('input'); |
||
71 | var context = activeGroupElement.find('.addMyData').first(); |
||
72 | setDataRequest(context.data('ajax'), jQuery('form').data('fispersid'), context); |
||
73 | jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_info_msg_personid_added + '</div>').insertAfter(activeGroupElement.find('legend').last()); |
||
|
|||
74 | jQuery('html, body').animate({ |
||
75 | scrollTop: jQuery(activeGroupElement).offset().top - 150 |
||
76 | }, 0); |
||
77 | }); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | |||
85 | var isGroupLoaded = function (element, callback, counter = 0) { |
||
86 | if (jQuery(element).length) { |
||
87 | callback(jQuery(element)); |
||
88 | } else { |
||
89 | if (counter < 10) { |
||
90 | setTimeout(function () { |
||
91 | isGroupLoaded(element, callback, counter++) |
||
92 | }, 500); |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
97 | var toggleBulkImportRecord = function() { |
||
98 | jQuery(".bulk-import-checkbox").on("click", function() { |
||
99 | var ajaxURL = jQuery(this).closest("tr").data('ajax'); |
||
100 | var params = {}; |
||
101 | jQuery.post(ajaxURL, params, function(data) { |
||
102 | }); |
||
103 | }); |
||
104 | } |
||
105 | |||
106 | var toggleBulkImportAuthorSearch = function() { |
||
107 | jQuery(".bulkImportAuthorSearch").on("click", function() { |
||
108 | var ajaxURL = jQuery(this).data('ajax'); |
||
109 | var params = {}; |
||
110 | jQuery.post(ajaxURL, params, function(data) { |
||
111 | }); |
||
112 | }); |
||
113 | } |
||
114 | |||
115 | var doctypeChange = { |
||
116 | |||
117 | init() { |
||
118 | var _this = this; |
||
119 | |||
120 | jQuery("#confirmDoctypeChange .saveDocumentSummary").on("click", function (e) { |
||
121 | |||
122 | var copyText = jQuery("#confirmDoctypeChange .modal-body .details-view").html(); |
||
123 | |||
124 | copyText = "<!DOCTYPE html>" + |
||
125 | "<html lang=\"de\" dir=\"ltr\" class=\"no-js\">"+ |
||
126 | "<head>" + |
||
127 | "<style>" + |
||
128 | ".details-group-name, .details-field-name {font-weight: bold;} " + |
||
129 | ".details-group-name {margin: 20px 0 5px 0; font-size: 18px} " + |
||
130 | ".details-field-name {font-size: 16px;} " + |
||
131 | ".details-group {list-style: none;}" + |
||
132 | "</style>" + |
||
133 | "</head>" + |
||
134 | "<body>" + copyText + "</body>" + |
||
135 | "</html>"; |
||
136 | |||
137 | var publication = new Blob([copyText], {type: "text/html;charset=utf-8"}); |
||
138 | saveAs(publication, "publication.html"); |
||
139 | |||
140 | e.preventDefault(); |
||
141 | }); |
||
142 | |||
143 | jQuery("#confirmDoctypeChange .submitChangeDocumentType").on("click", function (e) { |
||
144 | var documentType = jQuery('#changeDocumentTypeForm').find('select').val(); |
||
145 | if (documentType <= 0) { |
||
146 | jQuery('#changeDocumentTypeForm').find('select').addClass('mandatory-error'); |
||
147 | |||
148 | jQuery('.modal-body').animate({ |
||
149 | scrollTop:jQuery(jQuery('#changeDocumentTypeForm').find('select')).offset() |
||
150 | }, 100); |
||
151 | |||
152 | e.preventDefault(); |
||
153 | } |
||
154 | }); |
||
155 | |||
156 | jQuery("#changeDocumentTypeForm select").on("change", function (e) { |
||
157 | var documentType = jQuery('#changeDocumentTypeForm').find('select').val(); |
||
158 | if (documentType > 0) { |
||
159 | jQuery('#changeDocumentTypeForm').find('select').removeClass('mandatory-error'); |
||
160 | e.preventDefault(); |
||
161 | } |
||
162 | }); |
||
163 | |||
164 | jQuery("#confirmDoctypeChange").on("show.bs.modal", function(e) { |
||
165 | jQuery(this).find("#changeDocumentTypeForm").attr("action", jQuery(e.relatedTarget).attr("href")); |
||
166 | }); |
||
167 | |||
168 | jQuery("#confirmDoctypeChange").on("hidden.bs.modal", function(e) { |
||
169 | jQuery('#changeDocumentTypeForm').find('select').removeClass('mandatory-error'); |
||
170 | }); |
||
171 | } |
||
172 | } |
||
173 | |||
174 | var documentFormGroupSelector = { |
||
175 | init() { |
||
176 | var form = jQuery(".document-form-main"); |
||
177 | if (typeof form !== "undefined" && form.length > 0) { |
||
178 | |||
179 | var activeGroup = form.data("activegroup"); |
||
180 | var activeGroupIndex = form.data("activegroupindex"); |
||
181 | |||
182 | var tab = jQuery('fieldset[data-group="' + activeGroup + '"]').parent().attr("id"); |
||
183 | |||
184 | if (typeof tab !== "undefined" && tab.length > 0) { |
||
185 | jQuery('.nav-link').removeClass("active"); |
||
186 | jQuery('.tab-pane').removeClass("active"); |
||
187 | jQuery('.nav-link[href="#' + tab + '"]').addClass("active"); |
||
188 | jQuery('fieldset[data-group="' + activeGroup + '"]').parent().addClass("active"); |
||
189 | |||
190 | if (activeGroupIndex >= 0) { |
||
191 | group = jQuery('fieldset[data-group="' + activeGroup + '"]:eq(' + activeGroupIndex + ')'); |
||
192 | jQuery('html, body').animate({ |
||
193 | scrollTop: jQuery(group).offset().top - 150 |
||
194 | }, 0); |
||
195 | } else { |
||
196 | addGroup(jQuery('button.add_group[data-group="' + activeGroup + '"]')); |
||
197 | } |
||
198 | } |
||
199 | } |
||
200 | } |
||
201 | } |
||
202 | |||
203 | var saveExtendedSearch = { |
||
204 | |||
205 | init: function () { |
||
206 | this.show(); |
||
207 | this.save(); |
||
208 | |||
209 | jQuery("button").on("click", function () { |
||
210 | jQuery(".alert-save-extended-search-success").hide(); |
||
211 | }); |
||
212 | |||
213 | }, |
||
214 | |||
215 | show: function() { |
||
216 | jQuery("#save-extended-search").on("click", function (e) { |
||
217 | jQuery('.alert-save-extended-search').hide(); |
||
218 | jQuery("#save-extended-search-dialog #extended-search-name").val(""); |
||
219 | jQuery("#save-extended-search-dialog").modal('show'); |
||
220 | e.preventDefault(); |
||
221 | }); |
||
222 | }, |
||
223 | |||
224 | save: function() { |
||
225 | jQuery("#save-extended-search-dialog .modal-submit-button").on("click", function (e) { |
||
226 | var name = jQuery("#save-extended-search-dialog #extended-search-name").val(); |
||
227 | var query = jQuery("#extended-search-query").val(); |
||
228 | var ajaxURL = jQuery(this).data('ajax'); |
||
229 | |||
230 | if (query.length < 1 || name.length < 1) { |
||
231 | jQuery('.alert-save-extended-search').show(); |
||
232 | return; |
||
233 | } |
||
234 | |||
235 | var res = ajaxURL.match(/(tx\w+?)%/); // get param name |
||
236 | var params = {}; |
||
237 | var indexParam = {}; |
||
238 | if (res && res[1]) { |
||
239 | indexParam['name'] = name; |
||
240 | indexParam['query'] = query; |
||
241 | params[res[1]] = indexParam; |
||
242 | } |
||
243 | |||
244 | jQuery.post(ajaxURL, params, function(data) { |
||
245 | jQuery("#save-extended-search-dialog").modal('hide'); |
||
246 | jQuery(".alert-save-extended-search-success").show(); |
||
247 | openExtendedSearch.loadList(); |
||
248 | }).fail(function() { |
||
249 | |||
250 | }) |
||
251 | }); |
||
252 | } |
||
253 | } |
||
254 | |||
255 | |||
256 | var openExtendedSearch = { |
||
257 | |||
258 | init: function () { |
||
259 | this.loadList(); |
||
260 | }, |
||
261 | |||
262 | loadList: function() { |
||
263 | var _this = this; |
||
264 | |||
265 | if (jQuery("#load-extended-search").length) { |
||
266 | var ajaxURL = jQuery("#load-extended-search-select").data('ajax'); |
||
267 | var params = {}; |
||
268 | jQuery.post(ajaxURL, params, function(data) { |
||
269 | jQuery("#load-extended-search-select").length |
||
270 | |||
271 | jQuery("#load-extended-search-select .dropdown-item").remove(); |
||
272 | |||
273 | data.forEach(function(item){ |
||
274 | if (item.name.length) { |
||
275 | jQuery( |
||
276 | '<a class="dropdown-item" ' + |
||
277 | 'data-search-id="' + item.uid + '" ' + |
||
278 | 'href="#">' + item.name + '</a>' |
||
279 | ).appendTo("#load-extended-search-select"); |
||
280 | } |
||
281 | }); |
||
282 | |||
283 | if (data.length) { |
||
284 | jQuery("#load-extended-search").removeAttr("disabled"); |
||
285 | } else { |
||
286 | jQuery("#load-extended-search").attr("disabled","disabled"); |
||
287 | } |
||
288 | |||
289 | _this.onLoadSearch(); |
||
290 | |||
291 | }, "json"); |
||
292 | } |
||
293 | }, |
||
294 | |||
295 | onLoadSearch: function() { |
||
296 | jQuery("#load-extended-search-select .dropdown-item").on("click", function (e) { |
||
297 | var ajaxURL = jQuery("#load-extended-search-select").data('ajax-load'); |
||
298 | var res = ajaxURL.match(/(tx\w+?)%/); |
||
299 | var params = {}; |
||
300 | var indexParam = {}; |
||
301 | if (res && res[1]) { |
||
302 | indexParam['id'] = jQuery(this).data("search-id"); |
||
303 | params[res[1]] = indexParam; |
||
304 | } |
||
305 | |||
306 | jQuery.post(ajaxURL, params, function(data) { |
||
307 | jQuery("#extended-search-query").val(data); |
||
308 | }); |
||
309 | |||
310 | e.preventDefault(); |
||
311 | }); |
||
312 | } |
||
313 | } |
||
314 | |||
315 | |||
316 | var extendedSearch = { |
||
317 | |||
318 | init: function () { |
||
319 | this.showAddFieldDialog(); |
||
320 | this.addField(); |
||
321 | }, |
||
322 | |||
323 | showAddFieldDialog: function () { |
||
324 | jQuery("#extended-search-add-field .dropdown-item").on("click", function (e) { |
||
325 | var field = jQuery(this).data("field"); |
||
326 | var formGroup = jQuery(this).data("form-group"); |
||
327 | var fieldType = jQuery(this).data("type"); |
||
328 | var fieldName = jQuery(this).text(); |
||
329 | |||
330 | jQuery("#add-searchfield-dialog .modal-field-name").text(fieldName); |
||
331 | jQuery("#add-searchfield-dialog .modal-submit-button").data("field", field); |
||
332 | jQuery("#add-searchfield-dialog .modal-submit-button").data("form-group", formGroup); |
||
333 | jQuery("#add-searchfield-dialog .modal-submit-button").data("type", fieldType); |
||
334 | |||
335 | jQuery("#add-searchfield-dialog").find(".search-field").addClass("d-none"); |
||
336 | jQuery("#add-searchfield-dialog").find(".search-field-" + formGroup).removeClass("d-none"); |
||
337 | |||
338 | // Reset operators |
||
339 | jQuery("#add-searchfield-dialog #search-field-operator-binary option[value='AND']").prop('selected', true); |
||
340 | jQuery("#add-searchfield-dialog #search-field-operator-unary option[value='']").prop('selected', true); |
||
341 | |||
342 | // Reset field values |
||
343 | jQuery("#add-searchfield-dialog .search-field-value").val(""); |
||
344 | |||
345 | jQuery(".modal-footer").find("[data-target='#FisSearchModal-persons']").hide(); |
||
346 | jQuery(".modal-footer").find("[data-target='#FisSearchModal-affiliation']").hide(); |
||
347 | |||
348 | if (field == 'persons') { |
||
349 | jQuery(".modal-footer").find("[data-target='#FisSearchModal-persons']").show(); |
||
350 | } |
||
351 | |||
352 | if (field == 'affiliation') { |
||
353 | jQuery(".modal-footer").find("[data-target='#FisSearchModal-affiliation']").show(); |
||
354 | } |
||
355 | |||
356 | jQuery("#add-searchfield-dialog").modal('show'); |
||
357 | |||
358 | e.preventDefault(); |
||
359 | }); |
||
360 | }, |
||
361 | |||
362 | addField: function () { |
||
363 | |||
364 | var _this = this; |
||
365 | |||
366 | jQuery("#add-searchfield-dialog .modal-submit-button").on("click", function (e) { |
||
367 | var field = jQuery(this).data("field"); |
||
368 | var fieldType = jQuery(this).data("type"); |
||
369 | var formGroup = jQuery(this).data("form-group"); |
||
370 | |||
371 | var operatorBinary = jQuery("#search-field-operator-binary").val(); |
||
372 | var operatorUnary = jQuery("#search-field-operator-unary").val(); |
||
373 | |||
374 | var fieldPart = ""; |
||
375 | |||
376 | switch(fieldType) { |
||
377 | case "date-range": |
||
378 | fieldPart = _this.dateRangeField(formGroup, field); |
||
379 | break; |
||
380 | case "year-range": |
||
381 | fieldPart = _this.yearRangeField(formGroup, field); |
||
382 | break; |
||
383 | case "phrase": |
||
384 | fieldPart = _this.valueField(formGroup, field, true); |
||
385 | break; |
||
386 | default: |
||
387 | fieldPart = _this.valueField(formGroup, field); |
||
388 | break; |
||
389 | } |
||
390 | |||
391 | if (fieldPart.length > 0) { |
||
392 | |||
393 | var query = jQuery("#extended-search-query").val(); |
||
394 | |||
395 | if (query.length > 0) { |
||
396 | query += (operatorBinary) ? " " + operatorBinary + " " : " AND "; |
||
397 | } |
||
398 | |||
399 | if (operatorUnary == "NOT") { |
||
400 | fieldPart = "NOT(" + fieldPart + ")"; |
||
401 | } |
||
402 | |||
403 | query += fieldPart; |
||
404 | |||
405 | jQuery("#extended-search-query").val(query); |
||
406 | } |
||
407 | |||
408 | jQuery("#add-searchfield-dialog").modal('hide'); |
||
409 | e.preventDefault(); |
||
410 | }); |
||
411 | }, |
||
412 | |||
413 | valueField: function(group, field, phrase = false) { |
||
414 | |||
415 | var value = jQuery(".search-field-"+group+" .search-field-value").val(); |
||
416 | |||
417 | if (phrase) { |
||
418 | value = '"'+value+'"'; |
||
419 | } |
||
420 | |||
421 | var fieldPart = ""; |
||
422 | |||
423 | if (value.length > 0) { |
||
424 | |||
425 | fieldPart += field + ":" + value; |
||
426 | } |
||
427 | |||
428 | return fieldPart; |
||
429 | }, |
||
430 | |||
431 | yearRangeField: function(group, field) { |
||
432 | |||
433 | var from = jQuery(".search-field-"+group+" .search-field-from").val(); |
||
434 | var to = jQuery(".search-field-"+group+" .search-field-to").val(); |
||
435 | |||
436 | var fieldPart = ""; |
||
437 | |||
438 | View Code Duplication | if (from.length > 0 && to.length > 0) { |
|
439 | fieldPart = field+":["+from+" TO "+to+"]"; |
||
440 | } else { |
||
441 | if (from.length == 0 && to.length == 0) { |
||
442 | return ""; |
||
443 | } |
||
444 | |||
445 | from = (from.length > 0)? from : "*"; |
||
446 | to = (to.length > 0)? to : "*"; |
||
447 | fieldPart = field+":["+from+" TO "+to+"]"; |
||
448 | } |
||
449 | |||
450 | return fieldPart; |
||
451 | }, |
||
452 | |||
453 | |||
454 | dateRangeField: function(group, field) { |
||
455 | |||
456 | var from = jQuery(".search-field-"+group+" .search-field-from").val(); |
||
457 | var to = jQuery(".search-field-"+group+" .search-field-to").val(); |
||
458 | |||
459 | var fieldPart = ""; |
||
460 | |||
461 | var fromDate = moment(from, "DD.MM.YYYY"); |
||
462 | if (fromDate.format("DD.MM.YYYY") == from) { |
||
463 | from = fromDate.format("YYYY-MM-DD"); |
||
464 | } else { |
||
465 | from = ""; |
||
466 | } |
||
467 | |||
468 | var toDate = moment(to, "DD.MM.YYYY"); |
||
469 | if (toDate.format("DD.MM.YYYY") == to) { |
||
470 | to = toDate.format("YYYY-MM-DD"); |
||
471 | } else { |
||
472 | to = ""; |
||
473 | } |
||
474 | |||
475 | View Code Duplication | if (from.length > 0 && to.length > 0) { |
|
476 | fieldPart = field+":["+from+" TO "+to+"]"; |
||
477 | } else { |
||
478 | if (from.length == 0 && to.length == 0) { |
||
479 | return ""; |
||
480 | } |
||
481 | |||
482 | from = (from.length > 0)? from : "*"; |
||
483 | to = (to.length > 0)? to : "*"; |
||
484 | fieldPart = field+":["+from+" TO "+to+"]"; |
||
485 | } |
||
486 | |||
487 | return fieldPart; |
||
488 | } |
||
489 | } |
||
490 | |||
491 | function getWorkspaceListAction() { |
||
492 | return jQuery("#batchForm").attr("data-workspace-list-action"); |
||
493 | } |
||
494 | |||
495 | |||
496 | var selectFilter = function(selectFilterId, searchInput = false) { |
||
497 | selectFilterId = '#'+selectFilterId; |
||
498 | |||
499 | var options = {}; |
||
500 | if (!searchInput) { |
||
501 | options['minimumResultsForSearch'] = 'Infinity'; |
||
502 | } |
||
503 | |||
504 | jQuery(selectFilterId).select2(options); |
||
505 | |||
506 | jQuery(selectFilterId).on("select2:select", function(e) { |
||
507 | var data = e.params.data; |
||
508 | |||
509 | |||
510 | var filterName = jQuery(selectFilterId).attr('name'); |
||
511 | var filterValue = []; |
||
512 | if (e.params.data.id) { |
||
513 | filterValue = [e.params.data.id]; |
||
514 | } |
||
515 | var ajaxURL = jQuery(selectFilterId).parent().data('ajax'); |
||
516 | |||
517 | var res = ajaxURL.match(/(tx\w+?)%/); // get param name |
||
518 | var params = {}; |
||
519 | var indexParam = {}; |
||
520 | if (res && res[1]) { |
||
521 | indexParam['name'] = filterName; |
||
522 | indexParam['values'] = filterValue; |
||
523 | params[res[1]] = indexParam; |
||
524 | } |
||
525 | |||
526 | jQuery.post(ajaxURL, params, function(data) { |
||
527 | window.location.href = getWorkspaceListAction(); |
||
528 | }); |
||
529 | |||
530 | }); |
||
531 | } |
||
532 | |||
533 | |||
534 | var toggleDiscardedFilter = function() { |
||
535 | jQuery("#hideDiscarded").on("click", function() { |
||
536 | var ajaxURL = jQuery(this).data('ajax'); |
||
537 | var params = {}; |
||
538 | jQuery.post(ajaxURL, params, function(data) { |
||
539 | window.location.href = getWorkspaceListAction(); |
||
540 | }); |
||
541 | |||
542 | }); |
||
543 | } |
||
544 | |||
545 | var toggleBookmarksOnly = function() { |
||
546 | jQuery("#bookmarksOnly").on("click", function() { |
||
547 | var ajaxURL = jQuery(this).data('ajax'); |
||
548 | var params = {}; |
||
549 | jQuery.post(ajaxURL, params, function(data) { |
||
550 | window.location.href = getWorkspaceListAction(); |
||
551 | }); |
||
552 | |||
553 | }); |
||
554 | } |
||
555 | |||
556 | |||
557 | var selectSort = function() { |
||
558 | jQuery(".sort-button").on("click", function(element){ |
||
559 | |||
560 | var field = jQuery(this).attr('data-field'); |
||
561 | var order = jQuery(this).attr('data-order'); |
||
562 | var ajaxURL = jQuery(this).parent().data('ajax'); |
||
563 | |||
564 | var res = ajaxURL.match(/(tx\w+?)%/); // get param name |
||
565 | var params = {}; |
||
566 | var indexParam = {}; |
||
567 | if (res && res[1]) { |
||
568 | indexParam['field'] = field; |
||
569 | indexParam['order'] = order; |
||
570 | params[res[1]] = indexParam; |
||
571 | } |
||
572 | |||
573 | jQuery.post(ajaxURL, params, function(data) { |
||
574 | window.location.href = getWorkspaceListAction(); |
||
575 | }); |
||
576 | }) |
||
577 | } |
||
578 | |||
579 | |||
580 | var batchConfirmDialog = function(actionName) { |
||
581 | |||
582 | jQuery("#batchButton"+actionName).on("click", function(e) { |
||
583 | jQuery("#batchAction"+actionName).removeAttr("disabled") |
||
584 | jQuery("#confirmWorkspace"+actionName).modal('show'); |
||
585 | e.preventDefault(); |
||
586 | }); |
||
587 | |||
588 | jQuery("#confirmWorkspace"+actionName).on('hidden.bs.modal', function(){ |
||
589 | jQuery(".batchAction").attr("disabled","disabled") |
||
590 | }); |
||
591 | } |
||
592 | |||
593 | var addBookmarkHandler = { |
||
594 | init() { |
||
595 | jQuery(".add-bookmark").on("click", function(e) { |
||
596 | var button = jQuery(this); |
||
597 | var ajaxURL = jQuery(this).data('ajax'); |
||
598 | var identifier = jQuery(this).data('id'); |
||
599 | |||
600 | var res = ajaxURL.match(/(tx\w+?)%/); // get param name |
||
601 | var params = {}; |
||
602 | var indexParam = {}; |
||
603 | if (res && res[1]) { |
||
604 | indexParam['identifier'] = identifier; |
||
605 | params[res[1]] = indexParam; |
||
606 | } |
||
607 | |||
608 | jQuery.post(ajaxURL, params, function(data) { |
||
609 | button.find("span").removeClass("d-none"); |
||
610 | }).done(function() { |
||
611 | setTimeout(function() { |
||
612 | button.find("span").addClass("d-none"); |
||
613 | button.addClass("disabled"); |
||
614 | }, 500); |
||
615 | }).fail(function() { |
||
616 | }).always(function() { |
||
617 | }); |
||
618 | |||
619 | e.preventDefault(); |
||
620 | }); |
||
621 | |||
622 | } |
||
623 | } |
||
624 | |||
625 | var removeBookmarkHandler = { |
||
626 | init() { |
||
627 | jQuery(".remove-bookmark").on("click", function(e) { |
||
628 | |||
629 | var identifier = jQuery(this).attr("data-id"); |
||
630 | |||
631 | jQuery("#confirmWorkspaceRemoveBookmark .documentIdentifier").val(identifier); |
||
632 | jQuery("tr[data-id='"+identifier+"']").addClass("table-danger"); |
||
633 | jQuery("#confirmWorkspaceRemoveBookmark").modal('show'); |
||
634 | |||
635 | jQuery("#confirmWorkspaceRemoveBookmark").on('hidden.bs.modal', function(){ |
||
636 | jQuery("tr[data-id='"+identifier+"']").removeClass("table-danger"); |
||
637 | }); |
||
638 | |||
639 | e.preventDefault(); |
||
640 | }); |
||
641 | } |
||
642 | } |
||
643 | |||
644 | var batchSelectHandler = { |
||
645 | |||
646 | init() { |
||
647 | var _this = this; |
||
648 | |||
649 | this.refreshToggleButtons(); |
||
650 | |||
651 | jQuery(".workspace-select-toggle").removeClass("d-none"); |
||
652 | |||
653 | jQuery(".workspace-select-toggle").on("click", function(e){ |
||
654 | |||
655 | if (jQuery(".batch-checkbox:checked").length) { |
||
656 | jQuery(".batch-checkbox").each(function() { |
||
657 | jQuery(this).prop("checked", false); |
||
658 | }); |
||
659 | } else { |
||
660 | jQuery(".batch-checkbox").each(function() { |
||
661 | jQuery(this).prop("checked", true); |
||
662 | }); |
||
663 | } |
||
664 | |||
665 | _this.refreshToggleButtons(); |
||
666 | |||
667 | e.preventDefault(); |
||
668 | }); |
||
669 | |||
670 | jQuery(".batch-checkbox").on("click", function() { |
||
671 | _this.refreshToggleButtons(); |
||
672 | }); |
||
673 | }, |
||
674 | refreshToggleButtons() { |
||
675 | this.toggleSelectButton(); |
||
676 | this.toggleRegisterButton(); |
||
677 | this.toggleSetInProgressButton(); |
||
678 | this.toggleBatchRemoveButton(); |
||
679 | this.toggleBatchReleaseButton(); |
||
680 | this.toggleBatchBookmarkButton(); |
||
681 | }, |
||
682 | toggleSelectButton() { |
||
683 | if (jQuery(".batch-checkbox:checked").length > 0) { |
||
684 | jQuery(".workspace-select-all").show(); |
||
685 | jQuery(".workspace-unselect-all").hide(); |
||
686 | } else { |
||
687 | jQuery(".workspace-select-all").hide(); |
||
688 | jQuery(".workspace-unselect-all").show(); |
||
689 | } |
||
690 | }, |
||
691 | toggleRegisterButton() { |
||
692 | if (jQuery('#workspace-list [data-alias-state="new"] .batch-checkbox:checked').length > 0) { |
||
693 | jQuery("#batchButtonBatchRegister").removeClass("disabled"); |
||
694 | } else { |
||
695 | jQuery("#batchButtonBatchRegister").addClass("disabled"); |
||
696 | } |
||
697 | }, |
||
698 | toggleSetInProgressButton() { |
||
699 | var numNew = jQuery('#workspace-list tbody tr td[data-alias-state="new"]:first-child .batch-checkbox:checked').length; |
||
700 | var numInProgress = jQuery('#workspace-list tbody tr td[data-alias-state="in_progress"]:first-child .batch-checkbox:checked').length; |
||
701 | var numChecked = jQuery(".batch-checkbox:checked").length; |
||
702 | |||
703 | if (numNew + numInProgress < numChecked) { |
||
704 | jQuery("#batchButtonBatchSetInProgress").removeClass("disabled"); |
||
705 | } else { |
||
706 | jQuery("#batchButtonBatchSetInProgress").addClass("disabled"); |
||
707 | } |
||
708 | }, |
||
709 | toggleBatchRemoveButton() { |
||
710 | if (jQuery('#workspace-list [data-bookmark="1"] .batch-checkbox:checked').length > 0) { |
||
711 | jQuery("#batchButtonBatchRemove").removeClass("disabled"); |
||
712 | } else { |
||
713 | jQuery("#batchButtonBatchRemove").addClass("disabled"); |
||
714 | } |
||
715 | }, |
||
716 | toggleBatchBookmarkButton: function() { |
||
717 | |||
718 | if (jQuery('#workspace-list .batch-checkbox:checked').length < 1) { |
||
719 | jQuery("#batchButtonBatchBookmark").addClass("disabled"); |
||
720 | } |
||
721 | |||
722 | jQuery('#workspace-list .batch-checkbox:checked').each(function(){ |
||
723 | if (jQuery(this).parent().data("alias-state") != "new") { |
||
724 | jQuery("#batchButtonBatchBookmark").removeClass("disabled"); |
||
725 | } |
||
726 | }); |
||
727 | }, |
||
728 | toggleBatchReleaseButton() { |
||
729 | var countChecked = jQuery('#workspace-list .batch-checkbox:checked').length; |
||
730 | var countCheckedNew = jQuery('#workspace-list [data-alias-state="new"] .batch-checkbox:checked').length; |
||
731 | var countCheckedReleased = jQuery('#workspace-list [data-alias-state="released"] .batch-checkbox:checked').length; |
||
732 | |||
733 | if (countChecked - (countCheckedNew + countCheckedReleased) > 0) { |
||
734 | jQuery("#batchButtonBatchReleaseUnvalidated").removeClass("disabled"); |
||
735 | jQuery("#batchButtonBatchReleaseValidated").removeClass("disabled"); |
||
736 | } else { |
||
737 | jQuery("#batchButtonBatchReleaseUnvalidated").addClass("disabled"); |
||
738 | jQuery("#batchButtonBatchReleaseValidated").addClass("disabled"); |
||
739 | } |
||
740 | } |
||
741 | } |
||
742 | |||
743 | var itemsPerPageHandler = { |
||
744 | init() { |
||
745 | |||
746 | jQuery("#items-up").on("click", function(e) { |
||
747 | var itemsPerPage = jQuery("#items-per-page").val(); |
||
748 | var items = parseInt(itemsPerPage, 10); |
||
749 | |||
750 | if (itemsPerPage == items) { |
||
751 | items += 10; |
||
752 | } else { |
||
753 | items = 10; |
||
754 | } |
||
755 | jQuery("#items-per-page").val(items); |
||
756 | }); |
||
757 | |||
758 | jQuery("#items-down").on("click", function(e) { |
||
759 | var itemsPerPage = jQuery("#items-per-page").val(); |
||
760 | var items = parseInt(itemsPerPage, 10); |
||
761 | |||
762 | if (itemsPerPage === items.toString()) { |
||
763 | items = (items <= 10)? items : items-10; |
||
764 | } else { |
||
765 | items = 10; |
||
766 | } |
||
767 | jQuery("#items-per-page").val(items); |
||
768 | }); |
||
769 | |||
770 | jQuery("#items-per-page-save").on("click", function(e) { |
||
771 | var button = jQuery(this); |
||
772 | var ajaxURL = jQuery(this).data('ajax'); |
||
773 | var itemsPerPage = jQuery("#items-per-page").val(); |
||
774 | |||
775 | var items = parseInt(itemsPerPage, 10); |
||
776 | |||
777 | if (itemsPerPage !== items.toString() || items < 1) { |
||
778 | items = 10; |
||
779 | } |
||
780 | |||
781 | var res = ajaxURL.match(/(tx\w+?)%/); // get param name |
||
782 | var params = {}; |
||
783 | var indexParam = {}; |
||
784 | if (res && res[1]) { |
||
785 | indexParam['itemsPerPage'] = items; |
||
786 | params[res[1]] = indexParam; |
||
787 | } |
||
788 | |||
789 | jQuery.post(ajaxURL, params, function(data) { |
||
790 | window.location.href = getWorkspaceListAction(); |
||
791 | }); |
||
792 | |||
793 | }); |
||
794 | |||
795 | } |
||
796 | } |
||
797 | |||
798 | var validateFormAndSave = function() { |
||
799 | jQuery("#validDocument").val("0"); |
||
800 | if (validateForm()) { |
||
801 | jQuery("#validDocument").val("1"); |
||
802 | |||
803 | jQuery("#new-document-form #save").prop("disabled", true); |
||
804 | |||
805 | jQuery("#new-document-form").submit(); |
||
806 | |||
807 | return true; |
||
808 | } |
||
809 | return false; |
||
810 | } |
||
811 | var validateFormOnly = function() { |
||
812 | if (validateForm()) { |
||
813 | showFormSuccess(); |
||
814 | } |
||
815 | return false; |
||
816 | } |
||
817 | |||
818 | var changeMandatory = function (selector, newValue, oldValue) { |
||
819 | var groupSelector = 'fieldset:not([data-' + selector + '=""])'; |
||
820 | |||
821 | $(groupSelector).each(function () { |
||
822 | var currentFieldset = $(this); |
||
823 | var value = ''; |
||
824 | if (checkFilledInputs(currentFieldset)) { |
||
825 | value = newValue; |
||
826 | } else { |
||
827 | value = oldValue; |
||
828 | } |
||
829 | var groupIds = String(currentFieldset.data(selector)).split(','); |
||
830 | groupIds.forEach(function (entry) { |
||
831 | $('fieldset[data-group="' + entry + '"]').attr('data-mandatory', value); |
||
832 | }); |
||
833 | }); |
||
834 | } |
||
835 | |||
836 | var validateForm = function() { |
||
837 | var error = false; |
||
838 | jQuery("span.mandatory-error").remove(); |
||
839 | jQuery("div.alert").remove(); |
||
840 | jQuery(".tx-dpf-tabs li a").each(function() { |
||
841 | jQuery(this).removeClass("mandatory-error"); |
||
842 | }); |
||
843 | jQuery(".input-field[data-mandatory]").each(function() { |
||
844 | jQuery(this).removeClass("mandatory-error"); |
||
845 | }); |
||
846 | |||
847 | // change mandatory if configuration is set |
||
848 | changeMandatory('optionalgroups', 1, 0); |
||
849 | changeMandatory('requiredgroups', 0, 1); |
||
850 | |||
851 | // check mandatory groups |
||
852 | var search = 'fieldset[data-mandatory="'+constants['mandatory']+'"]'; |
||
853 | if (hasFiles()) { |
||
854 | search = search + ',fieldset[data-mandatory="'+constants['mandatory_file_only']+'"]'; |
||
855 | } |
||
856 | jQuery(search).each(function() { |
||
857 | var fieldset = jQuery(this); |
||
858 | if (hasMandatoryInputs(fieldset)) { |
||
859 | if (checkMandatoryInputs(fieldset)) { |
||
860 | jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_group_mandatory + '</div>').insertAfter(fieldset.find("legend").last()); |
||
861 | showFormError(); |
||
862 | error = true; |
||
863 | markPage(fieldset, true); |
||
864 | } |
||
865 | } else { |
||
866 | if (checkFilledInputs(fieldset)) { |
||
867 | jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_group_one_required + '</div>').insertAfter(fieldset.find("legend").last()); |
||
868 | showFormError(); |
||
869 | error = true; |
||
870 | markPage(fieldset, true); |
||
871 | error = true; |
||
872 | } |
||
873 | } |
||
874 | }); |
||
875 | jQuery("fieldset[id=primary_file]").each(function() { |
||
876 | var fieldset = jQuery(this); |
||
877 | if (checkPrimaryFile(fieldset)) { |
||
878 | jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_group_mandatory + '</div>').insertBefore(fieldset.find("legend").last()); |
||
879 | showFormError(); |
||
880 | error = true; |
||
881 | markPage(fieldset, true); |
||
882 | } |
||
883 | }); |
||
884 | // check non mandatory groups |
||
885 | jQuery('fieldset[data-mandatory=""],fieldset[data-mandatory="0"]').each(function() { |
||
886 | var fieldset = jQuery(this); |
||
887 | var filledInputs = 0; |
||
888 | jQuery(this).find(".input-field").each(function() { |
||
889 | var id = jQuery(this).attr("id"); |
||
890 | if ( |
||
891 | ((jQuery(this).attr("type") != "checkbox" && jQuery(this).val()) || (jQuery(this).attr("type") == "checkbox" && (jQuery("#" + id + ":checked").length > 0))) && |
||
892 | jQuery(this).attr("data-default") != "1" |
||
893 | ) { |
||
894 | filledInputs++; |
||
895 | } |
||
896 | //if (jQuery(this).val() && jQuery(this).attr("data-default") != "1") { |
||
897 | // filledInputs++; |
||
898 | //} |
||
899 | jQuery(this).removeClass("mandatory-error"); |
||
900 | }); |
||
901 | // if there are fields with a value then mandatory fields |
||
902 | // are relevant. |
||
903 | if (filledInputs) { |
||
904 | if (checkMandatoryInputs(fieldset)) { |
||
905 | jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_group_mandatory + '</div>').insertAfter(fieldset.find("legend").last()); |
||
906 | showFormError(); |
||
907 | markPage(fieldset, true); |
||
908 | error = true; |
||
909 | } |
||
910 | } |
||
911 | }); |
||
912 | jQuery("fieldset").each(function() { |
||
913 | var fieldset = jQuery(this); |
||
914 | fieldset.find(".input-field").each(function() { |
||
915 | jQuery(this).removeClass("invalid-error"); |
||
916 | var validation = jQuery(this).attr("data-regexp"); |
||
917 | if (jQuery(this).val() && jQuery(this).val().length > 0 && validation && validation.length > 0) { |
||
918 | try { |
||
919 | var regexp = new RegExp(validation); |
||
920 | var res = jQuery(this).val().match(regexp); |
||
921 | if (!(res && res.length == 1 && res[0] == jQuery(this).val())) { |
||
922 | jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr("data-label") + '</div>').insertAfter(fieldset.find("legend").last()); |
||
923 | jQuery(this).addClass("invalid-error"); |
||
924 | showFormError(); |
||
925 | markPage(fieldset, true); |
||
926 | error = true; |
||
927 | } |
||
928 | } catch (err) { |
||
929 | jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr("data-label") + '</div>').insertAfter(fieldset.find("legend").last()); |
||
930 | jQuery(this).addClass("invalid-error"); |
||
931 | showFormError(); |
||
932 | markPage(fieldset, true); |
||
933 | error = true; |
||
934 | } |
||
935 | } else { |
||
936 | var validateDate = jQuery(this).attr("data-datatype") == 'DATE'; |
||
937 | if (jQuery(this).val() && jQuery(this).val().length > 0 && validateDate && !isDate(jQuery(this).val())) { |
||
938 | jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr("data-label") + '</div>').insertAfter(fieldset.find("legend").last()); |
||
939 | jQuery(this).addClass("invalid-error"); |
||
940 | showFormError(); |
||
941 | markPage(fieldset, true); |
||
942 | error = true; |
||
943 | } |
||
944 | } |
||
945 | |||
946 | var maxLength = jQuery(this).attr("data-maxlength"); |
||
947 | if (maxLength && maxLength > 0) { |
||
948 | if (jQuery(this).val().length > maxLength) { |
||
949 | var max_lengrth_msg = form_error_msg_field_max_length.replace(/%s/gi, maxLength); |
||
950 | jQuery('<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle pull-right"></i>' + max_lengrth_msg + jQuery(this).attr("data-label") + '</div>').insertAfter(fieldset.find("legend").last()); |
||
951 | jQuery(this).addClass("invalid-error"); |
||
952 | showFormError(); |
||
953 | markPage(fieldset, true); |
||
954 | error = true; |
||
955 | } |
||
956 | } |
||
957 | }); |
||
958 | }); |
||
959 | |||
960 | return !error; |
||
961 | } |
||
962 | var showFormError = function() { |
||
963 | jQuery(".tx-dpf div.alert-danger").remove(); |
||
964 | jQuery('<div class="alert alert-danger" role="alert"><i class="fab fa-gripfire pull-right"></i>' + form_error_msg + '</div>').insertBefore(jQuery(".tx-dpf form.document-form-main").first()); |
||
965 | jQuery("html, body").animate({ |
||
966 | scrollTop: 0 |
||
967 | }, 200); |
||
968 | } |
||
969 | var showFormSuccess = function() { |
||
970 | jQuery(".tx-dpf div.alert-danger").remove(); |
||
971 | jQuery('<div class="alert alert-success" role="alert"><i class="fab fa-gripfire pull-right"></i>' + form_success_msg + '</div>').insertBefore(jQuery(".tx-dpf form.document-form-main").first()); |
||
972 | jQuery("html, body").animate({ |
||
973 | scrollTop: 0 |
||
974 | }, 200); |
||
975 | } |
||
976 | |||
977 | |||
978 | var hasFiles = function() { |
||
979 | var $hasFiles = 0; |
||
980 | jQuery(".input_file_upload").each(function() { |
||
981 | if (jQuery(this).val()) { |
||
982 | $hasFiles++; |
||
983 | } |
||
984 | }); |
||
985 | jQuery(".fs_file_group .file_link").each(function() { |
||
986 | if (jQuery(this).attr("href")) { |
||
987 | $hasFiles++; |
||
988 | } |
||
989 | }); |
||
990 | |||
991 | return $hasFiles > 0; |
||
992 | } |
||
993 | |||
994 | var hasMandatoryInputs = function(fieldset) { |
||
995 | var search = '.input-field[data-mandatory="'+constants['mandatory']+'"]'; |
||
996 | if (hasFiles()) { |
||
997 | search = search + ',.input-field[data-mandatory="'+constants['mandatory_file_only']+'"]'; |
||
998 | } |
||
999 | var inputs = fieldset.find(search); |
||
1000 | return inputs.length > 0 |
||
1001 | } |
||
1002 | var markPage = function(fieldset, error) { |
||
1003 | var pageId = fieldset.parent().attr("id"); |
||
1004 | var page = jQuery('.tx-dpf-tabs li a[href="#' + pageId + '"]'); |
||
1005 | if (error) { |
||
1006 | page.addClass("mandatory-error"); |
||
1007 | } else { |
||
1008 | page.removeClass("mandatory-error"); |
||
1009 | } |
||
1010 | } |
||
1011 | var checkMandatoryInputs = function(fieldset) { |
||
1012 | var mandatoryError = false; |
||
1013 | var search = '.input-field[data-mandatory="'+constants['mandatory']+'"]'; |
||
1014 | if (hasFiles()) { |
||
1015 | search = search + ',.input-field[data-mandatory="'+constants['mandatory_file_only']+'"]'; |
||
1016 | } |
||
1017 | fieldset.find(search).each(function() { |
||
1018 | var id = jQuery(this).attr("id"); |
||
1019 | if ((jQuery(this).attr("type") != "checkbox" && !jQuery(this).val()) || (jQuery(this).attr("type") == "checkbox" && (jQuery("#" + id + ":checked").length != 1 || !jQuery("#" + id + ":checked")))) { |
||
1020 | mandatoryError = mandatoryError || true; |
||
1021 | jQuery(this).addClass("mandatory-error"); |
||
1022 | } else { |
||
1023 | jQuery(this).removeClass("mandatory-error"); |
||
1024 | } |
||
1025 | }); |
||
1026 | return mandatoryError; |
||
1027 | } |
||
1028 | var checkPrimaryFile = function(fieldset) { |
||
1029 | var mandatoryError = false; |
||
1030 | fieldset.find("input#inp_primaryFile[data-primaryfilemandatory=1]").each(function() { |
||
1031 | if (!jQuery(this).val()) { |
||
1032 | mandatoryError = mandatoryError || true; |
||
1033 | jQuery(this).addClass("mandatory-error"); |
||
1034 | } else { |
||
1035 | jQuery(this).removeClass("mandatory-error"); |
||
1036 | } |
||
1037 | }); |
||
1038 | return mandatoryError; |
||
1039 | } |
||
1040 | var checkFilledInputs = function(fieldset) { |
||
1041 | var filledInputs = 0; |
||
1042 | fieldset.find(".input-field").each(function() { |
||
1043 | var id = jQuery(this).attr("id"); |
||
1044 | if ( |
||
1045 | ((jQuery(this).attr("type") != "checkbox" && jQuery(this).val()) || (jQuery(this).attr("type") == "checkbox" && (jQuery("#" + id + ":checked").length > 0))) && |
||
1046 | jQuery(this).attr("data-default") != "1" |
||
1047 | ) { |
||
1048 | filledInputs++; |
||
1049 | } |
||
1050 | //if (jQuery(this).val()) { |
||
1051 | // filledInputs++; |
||
1052 | //} |
||
1053 | jQuery(this).removeClass("mandatory-error"); |
||
1054 | }); |
||
1055 | return filledInputs < 1; |
||
1056 | } |
||
1057 | var addGroup = function(target, fileGroup = false) { |
||
1058 | |||
1059 | var element = jQuery(target); |
||
1060 | |||
1061 | var dataGroup = jQuery(target).attr("data-group"); |
||
1062 | |||
1063 | // Number of the next group item |
||
1064 | var groupIndex = parseInt(jQuery(target).attr("data-groupIndex")) + 1; |
||
1065 | |||
1066 | jQuery(target).attr("data-groupIndex", groupIndex); |
||
1067 | var ajaxURL = jQuery(target).attr("data-ajax"); |
||
1068 | var params = buildAjaxParams(ajaxURL, "groupIndex", groupIndex); |
||
1069 | //do the ajax-call |
||
1070 | jQuery.post(ajaxURL, params, function(group) { |
||
1071 | var group = jQuery(group).find("fieldset"); |
||
1072 | // add the new group |
||
1073 | jQuery(group).css({ |
||
1074 | 'display': 'none' |
||
1075 | }).insertAfter(jQuery('fieldset[data-group="' + dataGroup + '"]').last()); |
||
1076 | var height = jQuery('fieldset[data-group="' + dataGroup + '"]').last().outerHeight(true); |
||
1077 | |||
1078 | jQuery(group).fadeIn(); |
||
1079 | |||
1080 | jQuery("html, body").animate({ |
||
1081 | scrollTop: jQuery(group).offset().top - 150 |
||
1082 | }, 100); |
||
1083 | |||
1084 | buttonFillOutServiceUrn(); |
||
1085 | datepicker(); |
||
1086 | addRemoveFileButton(); |
||
1087 | userSearch(group); |
||
1088 | userSearchModalFillout(); |
||
1089 | addMyUserData(); |
||
1090 | |||
1091 | // gnd autocomplete for new groups |
||
1092 | var gndField = jQuery(group).find(".gnd"); |
||
1093 | if (gndField.length != 0) { |
||
1094 | setGndAutocomplete(gndField.data("field"),gndField.data("groupindex")); |
||
1095 | } |
||
1096 | loadMdEditor(); |
||
1097 | |||
1098 | if (fileGroup) { |
||
1099 | jQuery(target).remove(); |
||
1100 | //jQuery(".tx-dpf").on("click", ".rem_file_group", deleteFile); |
||
1101 | } |
||
1102 | }); |
||
1103 | return false; |
||
1104 | } |
||
1105 | var addField = function() { |
||
1106 | var addButton = jQuery(this); |
||
1107 | // Get the field uid |
||
1108 | var dataField = jQuery(this).attr("data-field"); |
||
1109 | // Number of the next field item |
||
1110 | var fieldIndex = parseInt(jQuery(this).attr("data-index")) + 1; |
||
1111 | jQuery(this).attr("data-index", fieldIndex); |
||
1112 | var ajaxURL = jQuery(this).attr("data-ajax"); |
||
1113 | var params = buildAjaxParams(ajaxURL, "fieldIndex", fieldIndex); |
||
1114 | |||
1115 | //do the ajax-call |
||
1116 | jQuery.post(ajaxURL, params, function(element) { |
||
1117 | var field = jQuery(element).find("#new-element").children(); |
||
1118 | jQuery(field).css({ |
||
1119 | "display": "none" |
||
1120 | }).insertBefore(addButton).fadeIn(); |
||
1121 | buttonFillOutServiceUrn(); |
||
1122 | datepicker(); |
||
1123 | |||
1124 | // gnd autocomplete for new fields |
||
1125 | var gndField = jQuery(element).find(".gnd"); |
||
1126 | if (gndField.length != 0) { |
||
1127 | setGndAutocomplete(gndField.data("field"),gndField.data("groupindex")); |
||
1128 | } |
||
1129 | loadMdEditor(); |
||
1130 | }); |
||
1131 | return false; |
||
1132 | } |
||
1133 | |||
1134 | var deleteFile = function() { |
||
1135 | var fileGroup = jQuery(this).parents(".fs_file_group"); |
||
1136 | |||
1137 | var dataGroup = fileGroup.attr("data-group"); |
||
1138 | var dataPage = fileGroup.parent().attr("data-page"); |
||
1139 | |||
1140 | var numFileGroups = fileGroup.parent().children('.fs_file_group[data-group=' + dataGroup + ']').length; |
||
1141 | |||
1142 | var groupIndex = fileGroup.attr("data-groupIndex"); |
||
1143 | |||
1144 | if (numFileGroups == 1) { |
||
1145 | addGroup(fileGroup, true); |
||
1146 | } else { |
||
1147 | fileGroup.fadeOut(300, function () { |
||
1148 | jQuery(this).remove(); |
||
1149 | }); |
||
1150 | } |
||
1151 | |||
1152 | //var dataIndex = jQuery(this).data("index"); |
||
1153 | return false; |
||
1154 | } |
||
1155 | |||
1156 | /* |
||
1157 | var deleteFile = function() { |
||
1158 | |||
1159 | var fileGroup = jQuery(this).parent().parent(); |
||
1160 | var ajaxURL = jQuery(this).attr("data-ajax"); |
||
1161 | var params = {} |
||
1162 | //do the ajax-call |
||
1163 | jQuery.post(ajaxURL, params, function(element) { |
||
1164 | var field = jQuery(element).find("#new-element").children(); |
||
1165 | jQuery(fileGroup).replaceWith(field); |
||
1166 | }); |
||
1167 | return false; |
||
1168 | } |
||
1169 | */ |
||
1170 | function buildAjaxParams(ajaxURL, indexName, index) { |
||
1171 | var res = ajaxURL.match(/(tx\w+?)%/); // get param name |
||
1172 | var params = {}; |
||
1173 | var indexParam = {}; |
||
1174 | if (res && res[1]) { |
||
1175 | indexParam[indexName] = index; |
||
1176 | params[res[1]] = indexParam; |
||
1177 | } |
||
1178 | return params; |
||
1179 | } |
||
1180 | var fillOutServiceUrn = function() { |
||
1181 | // Get the field uid |
||
1182 | var fieldUid = jQuery(this).attr("data-field"); |
||
1183 | var fieldIndex = jQuery(this).attr("data-index"); |
||
1184 | var groupUid = jQuery(this).attr("data-group"); |
||
1185 | var groupIndex = jQuery(this).attr("data-groupindex"); |
||
1186 | var ajaxURL = jQuery(this).attr("data-ajax"); |
||
1187 | var fedoraPid = jQuery("#fedorapid").val(); |
||
1188 | var params = {}; |
||
1189 | if (fedoraPid) { |
||
1190 | params = buildAjaxParams(ajaxURL, "fedoraPid", fedoraPid); |
||
1191 | } else { |
||
1192 | params = buildAjaxParams(ajaxURL, "fedoraPid", ""); |
||
1193 | } |
||
1194 | |||
1195 | var group = $(this).closest(".fs_group"); |
||
1196 | |||
1197 | //do the ajax-call |
||
1198 | jQuery.post(ajaxURL, params, function(element) { |
||
1199 | |||
1200 | group.find(".alert-filloutservice-urn").remove(); |
||
1201 | |||
1202 | if (element.error) { |
||
1203 | var errorMsg = $('<div class="alert alert-danger alert-filloutservice-urn" role="alert"><i class="fab fa-gripfire pull-right"></i>' + form_error_msg_filloutservice + '</div>'); |
||
1204 | errorMsg.insertAfter(group.find("legend")); |
||
1205 | $("html, body").animate({scrollTop: group.offset().top}, 200); |
||
1206 | } else { |
||
1207 | jQuery("#fedorapid").val(element.fedoraPid); |
||
1208 | jQuery("#primaryUrn").val(element.value); |
||
1209 | var inputField = jQuery('.input-field[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"][data-group="' + groupUid + '"][data-groupindex="' + groupIndex + '"]'); |
||
1210 | inputField.val(element.value); |
||
1211 | buttonFillOutServiceUrn(); |
||
1212 | } |
||
1213 | }, "json"); |
||
1214 | |||
1215 | return false; |
||
1216 | } |
||
1217 | var buttonFillOutServiceUrn = function() { |
||
1218 | jQuery("input.urn").each(function() { |
||
1219 | var fieldUid = jQuery(this).attr("data-field"); |
||
1220 | var fieldIndex = jQuery(this).attr("data-index"); |
||
1221 | var groupUid = jQuery(this).attr("data-group"); |
||
1222 | var groupIndex = jQuery(this).attr("data-groupindex"); |
||
1223 | var fillOutButton = jQuery('.fill_out_service_urn[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"]'); |
||
1224 | if ((jQuery(this).val() && jQuery(this).val().length > 0) || hasPrimaryUrn()) { |
||
1225 | fillOutButton.hide(); |
||
1226 | } else { |
||
1227 | fillOutButton.show(); |
||
1228 | } |
||
1229 | }); |
||
1230 | return false; |
||
1231 | } |
||
1232 | var hasPrimaryUrn = function() { |
||
1233 | var result = false; |
||
1234 | var primaryUrn = jQuery("#primaryUrn").val(); |
||
1235 | jQuery("input.urn").each(function() { |
||
1236 | var currentUrn = jQuery(this).val(); |
||
1237 | if (currentUrn && primaryUrn && (currentUrn == primaryUrn)) { |
||
1238 | result = result || true; |
||
1239 | } |
||
1240 | }); |
||
1241 | return result; |
||
1242 | } |
||
1243 | var continuousScroll = function() { |
||
1244 | var ajaxURL = jQuery("#next").attr("href"); |
||
1245 | jQuery.ajax({ |
||
1246 | url: ajaxURL, |
||
1247 | success: function(html) { |
||
1248 | if (html) { |
||
1249 | jQuery(html).find("table tbody tr").each(function() { |
||
1250 | jQuery("#search-results tbody tr").last().parent().append(this); |
||
1251 | }); |
||
1252 | if (jQuery(html).find("table tbody tr").length <= 0) { |
||
1253 | jQuery("#next").hide(); |
||
1254 | } |
||
1255 | } else { |
||
1256 | jQuery("#next").hide(); |
||
1257 | } |
||
1258 | } |
||
1259 | }); |
||
1260 | return false; |
||
1261 | } |
||
1262 | $(window).scroll(function() { |
||
1263 | if ($(this).scrollTop() > 330) { |
||
1264 | $(".tx-dpf-tab-container").addClass("sticky"); |
||
1265 | } else { |
||
1266 | $(".tx-dpf-tab-container").removeClass("sticky"); |
||
1267 | } |
||
1268 | }); |
||
1269 | |||
1270 | |||
1271 | var datepicker = function() { |
||
1272 | var language = jQuery("div.tx-dpf[data-language]").first().attr("data-language"); |
||
1273 | if (!language) language = "en"; |
||
1274 | jQuery(".datetimepicker").datetimepicker({ |
||
1275 | icons: { |
||
1276 | time: 'far fa-clock', |
||
1277 | date: 'fas fa-calendar-alt', |
||
1278 | up: 'fas fa-chevron-up', |
||
1279 | down: 'fas fa-chevron-down', |
||
1280 | previous: 'fas fa-chevron-left', |
||
1281 | next: 'fas fa-chevron-right', |
||
1282 | today: 'glyphicon glyphicon-screenshot', |
||
1283 | clear: 'far fa-trash-alt', |
||
1284 | close: 'fas fa-times' |
||
1285 | }, |
||
1286 | useCurrent: false, |
||
1287 | format: "DD.MM.YYYY", |
||
1288 | locale: language, |
||
1289 | keepInvalid: true, |
||
1290 | }).on("keydown", function(e){ |
||
1291 | if (e.which == 13) { |
||
1292 | $(".datetimepicker").closest("form").submit(); |
||
1293 | } |
||
1294 | }); |
||
1295 | } |
||
1296 | var isDate = function(value) { |
||
1297 | if (value == "") return false; |
||
1298 | var rxDatePattern = /^(\d{1,2})(\.)(\d{1,2})(\.)(\d{4})$/; //Declare Regex |
||
1299 | var dtArray = value.match(rxDatePattern); // is format OK? |
||
1300 | if (dtArray == null) return false; |
||
1301 | //Checks for mm/dd/yyyy format. |
||
1302 | var dtMonth = dtArray[3]; |
||
1303 | var dtDay = dtArray[1]; |
||
1304 | var dtYear = dtArray[5]; |
||
1305 | if (dtMonth < 1 || dtMonth > 12) { |
||
1306 | return false; |
||
1307 | } else if (dtDay < 1 || dtDay > 31) { |
||
1308 | return false; |
||
1309 | } else if ((dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) && dtDay == 31) { |
||
1310 | return false; |
||
1311 | View Code Duplication | } else if (dtMonth == 2) { |
|
1312 | var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0)); |
||
1313 | if (dtDay > 29 || (dtDay == 29 && !isleap)) return false; |
||
1314 | } |
||
1315 | return true; |
||
1316 | } |
||
1317 | var documentListConfirmDialog = function(dialogId) { |
||
1318 | |||
1319 | var title = '%s'; |
||
1320 | |||
1321 | jQuery(dialogId).modal({ |
||
1322 | show: false, |
||
1323 | backdrop: 'static' |
||
1324 | }); |
||
1325 | jQuery(dialogId).on("show.bs.modal", function(e) { |
||
1326 | //jQuery(this).find(dialogId+"Document").attr("href", jQuery(e.relatedTarget).attr("href")); |
||
1327 | jQuery(this).find(dialogId+"Document").attr("action", jQuery(e.relatedTarget).attr("href")); |
||
1328 | var bodyText = jQuery(this).find(".modal-body p").html(); |
||
1329 | title = jQuery(e.relatedTarget).attr("data-documenttitle"); |
||
1330 | jQuery(this).find(".modal-body p").html(bodyText.replace("%s", title)); |
||
1331 | jQuery(e.relatedTarget).parent().parent().addClass("danger marked-for-removal"); |
||
1332 | }); |
||
1333 | jQuery(dialogId).on("hidden.bs.modal", function(e) { |
||
1334 | var bodyText = jQuery(this).find(".modal-body p").html(); |
||
1335 | jQuery(this).find(".modal-body p").html(bodyText.replace(title, "%s")); |
||
1336 | jQuery(".marked-for-removal").removeClass("danger marked-for-removal"); |
||
1337 | }); |
||
1338 | |||
1339 | /* |
||
1340 | //make reason mandatory |
||
1341 | jQuery(dialogId+"Document").submit(function(e) { |
||
1342 | var reason = jQuery(dialogId+"Document").find("textarea"); |
||
1343 | if (typeof reason !== 'undefined' && reason.length > 0) { |
||
1344 | if (reason.val().trim().length == 0) { |
||
1345 | reason.val(""); |
||
1346 | e.preventDefault(); |
||
1347 | } |
||
1348 | } |
||
1349 | }); |
||
1350 | */ |
||
1351 | |||
1352 | jQuery(dialogId+"ReasonSelect").on("change", function(e){ |
||
1353 | jQuery(dialogId+"Reason").val(jQuery(this).val()); |
||
1354 | }); |
||
1355 | |||
1356 | |||
1357 | |||
1358 | } |
||
1359 | |||
1360 | function addRemoveFileButton() { |
||
1361 | $(".rem_file").unbind("click"); |
||
1362 | $(".rem_file").bind("click", function (evt) { |
||
1363 | evt.preventDefault(); |
||
1364 | $(this).siblings(".input_file_upload").val(""); |
||
1365 | }) |
||
1366 | } |
||
1367 | |||
1368 | |||
1369 | function gndNothingFound(fieldId, groupIndex) { |
||
1370 | var gndInputField = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]'); |
||
1371 | |||
1372 | if (gndInputField.data("old_gnd_field_value")) { |
||
1373 | gndInputField.val(gndInputField.data("old_gnd_field_value")); |
||
1374 | } else { |
||
1375 | gndInputField.val(); |
||
1376 | } |
||
1377 | |||
1378 | var gndFieldId = gndInputField.data("gndfield"); |
||
1379 | var linkedGroupIndex = gndInputField.data("groupindex"); |
||
1380 | var gndLinkedInputField = $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]'); |
||
1381 | |||
1382 | if (gndLinkedInputField.data("old_gnd_field_id")) { |
||
1383 | gndLinkedInputField.val(gndLinkedInputField.data("old_gnd_field_id")); |
||
1384 | } else { |
||
1385 | gndLinkedInputField.val(); |
||
1386 | } |
||
1387 | |||
1388 | /** global: form_error_msg_nothing_found */ |
||
1389 | jQuery('<div id="gnd-nothing-found" class="alert alert-warning" role="alert"><i class="fab fa-gripfire pull-right"></i>' + form_error_msg_nothing_found + '</div>').insertBefore(gndInputField.closest(".form-container")); |
||
1390 | |||
1391 | gndInputField.bind("keypress click", function () { |
||
1392 | jQuery("#gnd-nothing-found").remove(); |
||
1393 | }); |
||
1394 | |||
1395 | gndLinkedInputField.bind("keypress click", function () { |
||
1396 | jQuery("#gnd-nothing-found").remove(); |
||
1397 | }); |
||
1398 | |||
1399 | } |
||
1400 | |||
1401 | function setGndAutocomplete(fieldId, groupIndex) { |
||
1402 | // GND autocomplete |
||
1403 | var ajaxURL = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]').attr("data-ajax"); |
||
1404 | |||
1405 | var gndInputField = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]'); |
||
1406 | var gndFieldId = gndInputField.data("gndfield"); |
||
1407 | var linkedGroupIndex = gndInputField.data("groupindex"); |
||
1408 | var gndLinkedInputField = $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]'); |
||
1409 | |||
1410 | gndInputField.attr("data-old_gnd_field_value",gndInputField.val()); |
||
1411 | gndLinkedInputField.attr("data-old_gnd_field_id",gndLinkedInputField.val()); |
||
1412 | |||
1413 | // Get the name of the parameter array (tx_dpf_...), |
||
1414 | // the name depends on whether the call is from the frontend or the backend |
||
1415 | var res = ajaxURL.match(/(tx_dpf\w+?)%/); |
||
1416 | var paramName = "tx_dpf_kitodopublicationform[search]"; |
||
1417 | if (res && res[1]) { |
||
1418 | paramName = res[1]+"[search]"; |
||
1419 | } |
||
1420 | |||
1421 | $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]').autocomplete({ |
||
1422 | source: function (request, response) { |
||
1423 | |||
1424 | $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]').val(""); |
||
1425 | |||
1426 | var requestData = {}; |
||
1427 | requestData[paramName] = request.term.replace(" ", "+"); |
||
1428 | $.ajax({ |
||
1429 | type: 'POST', |
||
1430 | url: ajaxURL, |
||
1431 | data: requestData, |
||
1432 | dataType: 'json', |
||
1433 | timeout: 10000, |
||
1434 | success: function (data) { |
||
1435 | if (data) { |
||
1436 | response(data); |
||
1437 | } else { |
||
1438 | gndNothingFound(fieldId, groupIndex); |
||
1439 | response([]); |
||
1440 | } |
||
1441 | }, |
||
1442 | error: function () { |
||
1443 | gndNothingFound(fieldId, groupIndex); |
||
1444 | response([]); |
||
1445 | } |
||
1446 | }); |
||
1447 | }, |
||
1448 | minLength: 3, |
||
1449 | select: function (event, ui) { |
||
1450 | gndFieldId = jQuery(event.target).data("gndfield"); |
||
1451 | linkedGroupIndex = jQuery(event.target).data("groupindex"); |
||
1452 | $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]').val(ui.item.gnd); |
||
1453 | }, |
||
1454 | }).autocomplete( "instance" )._renderItem = function( ul, item ) { |
||
1455 | return $( "<li>" ) |
||
1456 | .append( "<div class='gnd-autocomplete'><span class='gnd-value' style='display:none;'>" + item.value + "</span>" + |
||
1457 | "<span class='gnd-label'>" + item.label + "</span></div>" |
||
1458 | ) |
||
1459 | .appendTo( ul ); |
||
1460 | }; |
||
1461 | } |
||
1462 | |||
1463 | var previousNextFormPage = function() { |
||
1464 | |||
1465 | $(".prev-next-buttons button").click(function (e) { |
||
1466 | var activePage = $(".tx-dpf-tabs").find("li a.active").parent(); |
||
1467 | var newActivePage = activePage; |
||
1468 | |||
1469 | if ($(this).attr("id") == "next-form-page") { |
||
1470 | newActivePage = activePage.next(); |
||
1471 | } else { |
||
1472 | newActivePage = activePage.prev(); |
||
1473 | } |
||
1474 | |||
1475 | if (newActivePage.length > 0) { |
||
1476 | activePage.find("a").removeClass("active"); |
||
1477 | activePage.find("a").attr("aria-expanded", "false"); |
||
1478 | $(".tab-content").find("div.active").removeClass("active"); |
||
1479 | |||
1480 | newActivePage.find("a").addClass("active"); |
||
1481 | newActivePage.find("a").attr("aria-expanded", "true"); |
||
1482 | $(".tab-content").find(newActivePage.find("a").attr("href")).addClass("active"); |
||
1483 | |||
1484 | updatePrevNextButtons(newActivePage); |
||
1485 | |||
1486 | $("html, body").animate({ |
||
1487 | scrollTop:$(".tx-dpf").offset().top |
||
1488 | },"fast"); |
||
1489 | } |
||
1490 | |||
1491 | e.preventDefault(); |
||
1492 | |||
1493 | }); |
||
1494 | |||
1495 | updatePrevNextButtons($(".tx-dpf-tabs a.active").parent()); |
||
1496 | |||
1497 | $(".tx-dpf-tabs a").click(function(){ |
||
1498 | updatePrevNextButtons($(this).parent()); |
||
1499 | }); |
||
1500 | |||
1501 | } |
||
1502 | |||
1503 | var updatePrevNextButtons = function(activePage) { |
||
1504 | |||
1505 | if (activePage !== undefined) { |
||
1506 | if (activePage.prev().length < 1) { |
||
1507 | $("#prev-form-page").addClass("disabled"); |
||
1508 | } else { |
||
1509 | $("#prev-form-page").removeClass("disabled"); |
||
1510 | } |
||
1511 | if (activePage.next().length < 1) { |
||
1512 | $("#next-form-page").addClass("disabled"); |
||
1513 | } else { |
||
1514 | $("#next-form-page").removeClass("disabled"); |
||
1515 | } |
||
1516 | } |
||
1517 | } |
||
1518 | |||
1519 | var inputWithOptions = function() { |
||
1520 | |||
1521 | $.widget( "custom.dropdownoptions", { |
||
1522 | _create() { |
||
1523 | |||
1524 | var availableTags = []; |
||
1525 | var test = this.element |
||
1526 | .closest(".dropdown-options") |
||
1527 | .find(".dropdown-options-values li") |
||
1528 | .each(function(){ |
||
1529 | if (jQuery(this).text().length > 0) { |
||
1530 | availableTags.push(jQuery(this).text()); |
||
1531 | } |
||
1532 | }); |
||
1533 | |||
1534 | this.element |
||
1535 | .addClass( ".dropdown-options-input" ) |
||
1536 | .autocomplete({ |
||
1537 | minLength: 0, |
||
1538 | source: availableTags |
||
1539 | }); |
||
1540 | |||
1541 | this._createShowAllButton(); |
||
1542 | }, |
||
1543 | _createShowAllButton() { |
||
1544 | |||
1545 | var input = this.element; |
||
1546 | |||
1547 | wasOpen = false; |
||
1548 | |||
1549 | input |
||
1550 | .closest(".dropdown-options") |
||
1551 | .find(".dropdown-options-toggle") |
||
1552 | .on( "mousedown", function() { |
||
1553 | wasOpen = input.autocomplete( "widget" ).is( ":visible" ); |
||
1554 | }) |
||
1555 | .on( "click", function() { |
||
1556 | input.trigger( "focus" ); |
||
1557 | if ( wasOpen ) { |
||
1558 | return; |
||
1559 | } |
||
1560 | input.autocomplete( "search", "" ); |
||
1561 | |||
1562 | }); |
||
1563 | input |
||
1564 | .on( "click", function() { |
||
1565 | input.autocomplete( "search", "" ); |
||
1566 | }); |
||
1567 | } |
||
1568 | }); |
||
1569 | |||
1570 | $( ".dropdown-options-input" ).dropdownoptions(); |
||
1571 | } |
||
1572 | |||
1573 | var userSearch = function(group) { |
||
1574 | if (group) { |
||
1575 | $(group.find('.fis-user-search-input')).on('focus', delay(searchInputKeyupHandler, 500)); |
||
1576 | $(group.find('.fis-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1577 | $(group.find('.fis-orga-search-input')).on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1578 | $(group.find('.gnd-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1579 | $(group.find('.ror-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1580 | $(group.find('.zdb-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1581 | $(group.find('.unpaywall-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1582 | $(group.find('.orcid-user-search-input')).on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1583 | } else { |
||
1584 | $('.fis-user-search-input').on('focus', delay(searchInputKeyupHandler, 500)); |
||
1585 | $('.fis-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1586 | $('.fis-orga-search-input').on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1587 | $('.gnd-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1588 | $('.ror-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1589 | $('.zdb-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1590 | $('.unpaywall-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1591 | $('.orcid-user-search-input').on('keyup', delay(searchInputKeyupHandler, 500)); |
||
1592 | } |
||
1593 | } |
||
1594 | |||
1595 | function delay(callback, ms) { |
||
1596 | var timer = 0; |
||
1597 | return function() { |
||
1598 | var context = this, args = arguments; |
||
1599 | clearTimeout(timer); |
||
1600 | timer = setTimeout(function () { |
||
1601 | callback.apply(context, args); |
||
1602 | }, ms || 0); |
||
1603 | }; |
||
1604 | } |
||
1605 | |||
1606 | var searchInputKeyupHandler = function() { |
||
1607 | var searchValue = $(this).val(); |
||
1608 | var groupIndex = $(this).data("groupindex"); |
||
1609 | if (searchValue.length >= 3) { |
||
1610 | let url = $(this).data("searchrequest"); |
||
1611 | let params = {}; |
||
1612 | params['tx_dpf_backoffice[searchTerm]'] = searchValue; |
||
1613 | // type person or organisation |
||
1614 | params['tx_dpf_backoffice[type]'] = $(this).closest('.modal').find("input[name^='searchTypeRadio']:checked").val(); |
||
1615 | |||
1616 | var radioType = $(this).closest('.modal').find("input[name^='searchTypeRadio']:checked").val(); |
||
1617 | |||
1618 | $.ajax({ |
||
1619 | type: "POST", |
||
1620 | url: url, |
||
1621 | data: params, |
||
1622 | context: this, |
||
1623 | success: function (data) { |
||
1624 | var that = this; |
||
1625 | var dataObject = JSON.parse(data); |
||
1626 | var groupIndex = $(this).data("groupindex") |
||
1627 | var hitListElement = $(this).parent().parent().find('.'+$(this).data("api").toLowerCase()+'-search-list-' + groupIndex + ' ul').html(''); |
||
1628 | |||
1629 | $.each(dataObject.entries, function (key, value) { |
||
1630 | var type = $(that).data("api").toLowerCase(); |
||
1631 | var allData = value; |
||
1632 | |||
1633 | if ($(that).attr('class') === 'fis-user-search-input') { |
||
1634 | if (radioType == 'person') { |
||
1635 | if (value.organisationalUnits && value.organisationalUnits.length > 0) { |
||
1636 | var optionalText = value.organisationalUnits[0].titleDe; |
||
1637 | if (value.organisationalUnits[1]) { |
||
1638 | optionalText = optionalText +', '+ value.organisationalUnits[1].titleDe |
||
1639 | } |
||
1640 | } |
||
1641 | hitListElement.append(listHtml(value.fullName, value.fisPersid, allData, optionalText)); |
||
1642 | } else if (radioType == 'organisation'){ |
||
1643 | hitListElement.append(listHtml(value.titleDe + ' (' + value.parentOrgaName + ')', value.id, allData)); |
||
1644 | } |
||
1645 | } else if ($(that).attr('class') === 'fis-orga-search-input') { |
||
1646 | hitListElement.append(listHtml(value.titleDe, value.id, allData)); |
||
1647 | } else if ($(that).attr('class') === 'gnd-user-search-input') { |
||
1648 | if (radioType == 'person') { |
||
1649 | var professions = ''; |
||
1650 | var date = ''; |
||
1651 | |||
1652 | if (value.professionOrOccupation !== undefined) { |
||
1653 | $.each(value.professionOrOccupation, function (key, value) { |
||
1654 | professions += value.label + ', '; |
||
1655 | }); |
||
1656 | professions = professions.slice(0, -2); |
||
1657 | } |
||
1658 | if (value.dateOfBirth) { |
||
1659 | date = value.dateOfBirth; |
||
1660 | } |
||
1661 | if (value.dateOfDeath) { |
||
1662 | date += ' - ' + value.dateOfDeath; |
||
1663 | } |
||
1664 | var optionalText = ''; |
||
1665 | if (date) { |
||
1666 | optionalText = date; |
||
1667 | } |
||
1668 | if (professions) { |
||
1669 | if (date) { |
||
1670 | optionalText += ', '; |
||
1671 | } |
||
1672 | optionalText += professions.trim(); |
||
1673 | } |
||
1674 | } |
||
1675 | |||
1676 | hitListElement.append(listHtml(value.preferredName, value.gndIdentifier, allData, optionalText)); |
||
1677 | } else if ($(that).attr('class') === 'ror-user-search-input') { |
||
1678 | var optionalText = ''; |
||
1679 | |||
1680 | if (allData.type) { |
||
1681 | optionalText += allData.type; |
||
1682 | } |
||
1683 | if (allData.aliases) { |
||
1684 | optionalText += allData.aliases; |
||
1685 | } |
||
1686 | |||
1687 | hitListElement.append(listHtml(value.name, value.id, allData, optionalText)); |
||
1688 | } else if ($(that).attr('class') === 'zdb-user-search-input') { |
||
1689 | hitListElement.append(listHtml(value.title, value.identifier, allData, value.publisher)); |
||
1690 | } else if ($(that).attr('class') === 'unpaywall-user-search-input') { |
||
1691 | hitListElement.append(listHtml(value.title, value.doi, allData, value.best_oa_location.url_for_landing_page, value.oa_status)); |
||
1692 | } else if ($(that).attr('class') === 'orcid-user-search-input') { |
||
1693 | hitListElement.append(listHtml(value["given-names"] + ' ' + value["family-names"], value["orcid-id"], allData, value["orcid-id"])); |
||
1694 | } |
||
1695 | |||
1696 | }); |
||
1697 | addFoundUserData(); |
||
1698 | } |
||
1699 | }); |
||
1700 | } |
||
1701 | } |
||
1702 | |||
1703 | var listHtml = function (name, id, all = '', optionalText = '', color = '') { |
||
1704 | JSON.stringify(all).replace(/"/g, ''); |
||
1705 | |||
1706 | if (color) { |
||
1707 | colorHtml = '('+color+')'; |
||
1708 | } else { |
||
1709 | colorHtml = ''; |
||
1710 | } |
||
1711 | |||
1712 | var text = ''; |
||
1713 | if (optionalText) { |
||
1714 | var text = ' (' + optionalText + ') '; |
||
1715 | } |
||
1716 | var orgaName = ''; |
||
1717 | if (all.organisationalUnits !== undefined) { |
||
1718 | $.each(all.organisationalUnits, function(key, value) { |
||
1719 | orgaName += value.titleDe + ', '; |
||
1720 | }); |
||
1721 | orgaName = orgaName.slice(0, -2); |
||
1722 | } |
||
1723 | |||
1724 | return '<li style="margin-bottom:1rem;" class="container">' + |
||
1725 | '<div class="row">' + |
||
1726 | '<div class="col"><button style="margin-right:1rem;" class="btn btn-s btn-info found-user-add" type="button" data-id="' + id + '" data-surname="'+all.surname+'" data-givenname="'+all.givenName+'" data-organame="'+orgaName+'">' + |
||
1727 | 'Übernehmen' + |
||
1728 | '</button></div>' + |
||
1729 | '<div class="col-6">' + |
||
1730 | name + text + colorHtml + |
||
1731 | '</div>' + |
||
1732 | '</div>' + |
||
1733 | '</li>'; |
||
1734 | } |
||
1735 | |||
1736 | var addFoundUserData = function () { |
||
1737 | $('.found-user-add').on('click', function () { |
||
1738 | var input = $(this).closest('.modal-body').find('input'); |
||
1739 | |||
1740 | // user setting modal |
||
1741 | if (input.data('usersettings') == '1') { |
||
1742 | $('#fisPersId').val($(this).data('id')); |
||
1743 | $('#firstName').val($(this).data('givenname')); |
||
1744 | $('#lastName').val($(this).data('surname')); |
||
1745 | $('#orgaName').val($(this).data('organame')); |
||
1746 | $(this).closest('.modal').modal('hide'); |
||
1747 | } else if (input.data('usersettings') == 'extSearch') { |
||
1748 | $('#search-field-default-value').val($(this).data('id')); |
||
1749 | $(this).closest('.modal').modal('hide'); |
||
1750 | } else { |
||
1751 | setDataRequest(input.data('datarequest'), $(this).data('id'), input); |
||
1752 | } |
||
1753 | |||
1754 | }); |
||
1755 | } |
||
1756 | |||
1757 | var setDataRequest = function(url, dataId, context) { |
||
1758 | |||
1759 | let params = {}; |
||
1760 | params['tx_dpf_backoffice[dataId]'] = dataId; |
||
1761 | params['tx_dpf_backoffice[groupId]'] = context.data('group'); |
||
1762 | params['tx_dpf_backoffice[groupIndex]'] = context.data('groupindex'); |
||
1763 | params['tx_dpf_backoffice[fieldIndex]'] = 0; |
||
1764 | params['tx_dpf_backoffice[pageId]'] = context.data('page'); |
||
1765 | params['tx_dpf_backoffice[type]'] = context.closest('.modal').find("input[name^='searchTypeRadio']:checked").val(); |
||
1766 | |||
1767 | $.ajax({ |
||
1768 | type: "POST", |
||
1769 | url: url, |
||
1770 | data: params, |
||
1771 | dataType: 'json', |
||
1772 | success: function (data) { |
||
1773 | var newKeyMapping = new Map(); |
||
1774 | // fill out data for each key |
||
1775 | for (var key in data) { |
||
1776 | var splitId = key.split("-"); |
||
1777 | // key without the last index (field index) |
||
1778 | var keyWithoutFieldIndex = splitId[0] + '-' + splitId[1] + '-' + splitId[2] + '-' + splitId[3]; |
||
1779 | var isFieldRepeatable = $('.' + keyWithoutFieldIndex + '-' + '0').parent().parent().find('.add_field').length; |
||
1780 | |||
1781 | if($('.' + key).length != 0 && $('.' + key).val() == '' || $('.' + key).length != 0 && $('.' + key).val() != '' && !isFieldRepeatable) { |
||
1782 | // form field is empty and exists or form field is not empty and not repeatable, overwrite! |
||
1783 | $('.' + key).val(data[key]).change(); |
||
1784 | } else if ($('.' + key).length != 0 && $('.' + key).val() != '' && isFieldRepeatable) { |
||
1785 | // form field exists and is not empty |
||
1786 | // add new form input |
||
1787 | $('.' + keyWithoutFieldIndex + '-' + '0').parent().parent().find('.add_field').click(); |
||
1788 | |||
1789 | // count repeated fields if not counted already |
||
1790 | var k = newKeyMapping.get(keyWithoutFieldIndex); |
||
1791 | if (typeof k == 'undefined') { |
||
1792 | var i = 0; |
||
1793 | while ($('.' + keyWithoutFieldIndex + '-' + i).length) { |
||
1794 | i++; |
||
1795 | } |
||
1796 | } else { |
||
1797 | i = k + 1; |
||
1798 | } |
||
1799 | |||
1800 | var newKey = keyWithoutFieldIndex + '-' + i; |
||
1801 | newKeyMapping.set(keyWithoutFieldIndex, i); |
||
1802 | |||
1803 | isElementLoaded('.' + newKey, key, function (element, fieldKey) { |
||
1804 | $(element).val(data[fieldKey]).change(); |
||
1805 | }); |
||
1806 | |||
1807 | } else { |
||
1808 | // if key does not exist check if field is repeatable |
||
1809 | splitId = key.split("-"); |
||
1810 | var datakey = key; |
||
1811 | if (splitId[4] > 0) { |
||
1812 | var k = newKeyMapping.get(keyWithoutFieldIndex); |
||
1813 | if (typeof k != 'undefined') { |
||
1814 | datakey = key; |
||
1815 | key = keyWithoutFieldIndex + '-' + (k + 1); |
||
1816 | newKeyMapping.set(keyWithoutFieldIndex, (k + 1)); |
||
1817 | } |
||
1818 | // add new form input |
||
1819 | $('.' + keyWithoutFieldIndex + '-' + '0').parent().parent().find('.add_field').click(); |
||
1820 | isElementLoaded('.' + key, datakey, function (element, fieldKey) { |
||
1821 | $(element).val(data[fieldKey]).change(); |
||
1822 | }); |
||
1823 | } |
||
1824 | } |
||
1825 | } |
||
1826 | } |
||
1827 | }); |
||
1828 | context.closest('.modal').modal('hide'); |
||
1829 | } |
||
1830 | |||
1831 | var isElementLoaded = function (element, fieldKey, callback, counter = 0) { |
||
1832 | if ($(element).length) { |
||
1833 | callback($(element), fieldKey); |
||
1834 | } else { |
||
1835 | if (counter < 5) { |
||
1836 | setTimeout(function () { |
||
1837 | isElementLoaded(element, fieldKey, callback, counter++) |
||
1838 | }, 500); |
||
1839 | } else { |
||
1840 | console.error("Field not repeatable or doesnt exist"); |
||
1841 | } |
||
1842 | } |
||
1843 | } |
||
1844 | |||
1845 | var addMyUserData = function() { |
||
1846 | $('.addMyData').on('click', function () { |
||
1847 | setDataRequest($(this).data('ajax'), $(this).data('personid'), $(this)); |
||
1848 | }); |
||
1849 | |||
1850 | jQuery("[data-objecttype='fispersonid']").on('change', function() { |
||
1851 | var fisPersonIdentifiers = getFisPersonIdentifiers(); |
||
1852 | toggleAddMyUserDataButton(fisPersonIdentifiers); |
||
1853 | }); |
||
1854 | |||
1855 | var fisPersonIdentifiers = getFisPersonIdentifiers(); |
||
1856 | toggleAddMyUserDataButton(fisPersonIdentifiers); |
||
1857 | |||
1858 | jQuery("[data-objecttype='fispersonid']").on('keyup', function() { |
||
1859 | var fisPersonIdentifiers = getFisPersonIdentifiers(); |
||
1860 | toggleAddMyUserDataButton(fisPersonIdentifiers); |
||
1861 | }); |
||
1862 | } |
||
1863 | |||
1864 | var getFisPersonIdentifiers = function() { |
||
1865 | fisPersonIdentifiers = []; |
||
1866 | jQuery("[data-objecttype='fispersonid']").each(function() { |
||
1867 | fisPersonIdentifiers.push(jQuery(this).val()); |
||
1868 | }); |
||
1869 | |||
1870 | return fisPersonIdentifiers; |
||
1871 | } |
||
1872 | |||
1873 | var toggleAddMyUserDataButton = function(fisPersonIdentifiers) { |
||
1874 | var fisPersonId = jQuery('.addMyData').data('personid'); |
||
1875 | if (fisPersonIdentifiers.includes(fisPersonId)) { |
||
1876 | jQuery('button.addMyData').hide(); |
||
1877 | } else { |
||
1878 | jQuery('button.addMyData').show(); |
||
1879 | } |
||
1880 | } |
||
1881 | |||
1882 | var searchAgain = function (context) { |
||
1883 | searchInputKeyupHandler.call(context); |
||
1884 | } |
||
1885 | |||
1886 | var userSearchModalFillout = function() { |
||
1887 | |||
1888 | $('.FisSearchModal').on('hidden.bs.modal', function() { |
||
1889 | jQuery(this).find('.fis-user-search-input').val(''); |
||
1890 | jQuery(this).find('.fis-search-results').html(''); |
||
1891 | }); |
||
1892 | |||
1893 | $('.FisSearchModal').on('shown.bs.modal', function () { |
||
1894 | //jQuery(this).find("#orgaRadio").prop('checked', false); |
||
1895 | //jQuery(this).find("#personRadio").prop('checked', true); |
||
1896 | var surname = jQuery(this).closest('fieldset').find('[data-objecttype=surname]').val(); |
||
1897 | if (typeof surname !== 'undefined') { |
||
1898 | if (surname.length > 0) { |
||
1899 | jQuery(this).find('.fis-user-search-input').val(surname); |
||
1900 | } |
||
1901 | } |
||
1902 | }); |
||
1903 | |||
1904 | $('.UnpaywallSearchModal').on('shown.bs.modal', function () { |
||
1905 | var doiValue = $(this).closest('fieldset').find('*[data-objecttype="unpaywallDoi"]').val(); |
||
1906 | $(this).find('.unpaywall-user-search-input').val(doiValue); |
||
1907 | searchAgain($(this).closest('.modal').find("input[type=text]")[0]); |
||
1908 | }); |
||
1909 | } |
||
1910 | |||
1911 | // Call methods for API Token generation |
||
1912 | var apiTokenEvents = function() { |
||
1913 | $('#apiTokenGenerate').on('click', function () { |
||
1914 | var url = $(this).data('generatetoken'); |
||
1915 | $.ajax({ |
||
1916 | type: "GET", |
||
1917 | url: url, |
||
1918 | dataType: 'json', |
||
1919 | success: function (data) { |
||
1920 | $('#showApiToken').text(data.apiToken); |
||
1921 | } |
||
1922 | }); |
||
1923 | }); |
||
1924 | |||
1925 | $('#apiTokenRemove').on('click', function () { |
||
1926 | var url = $(this).data('removetoken'); |
||
1927 | $.ajax({ |
||
1928 | type: "GET", |
||
1929 | url: url, |
||
1930 | dataType: 'json', |
||
1931 | success: function (data) { |
||
1932 | if (data.success) { |
||
1933 | $('#apiTokenRemove').hide(); |
||
1934 | } |
||
1935 | } |
||
1936 | }); |
||
1937 | }); |
||
1938 | } |
||
1939 | |||
1940 | // ------------------------------------------------------- |
||
1941 | // Document ready |
||
1942 | // ------------------------------------------------------- |
||
1943 | $(document).ready(function() { |
||
1944 | |||
1945 | bsCustomFileInput.init(); |
||
1946 | |||
1947 | jQuery("#new-document-form").trigger("reset"); |
||
1948 | documentListConfirmDialog("#confirmDiscard"); |
||
1949 | documentListConfirmDialog("#confirmReleasePublish"); |
||
1950 | documentListConfirmDialog("#confirmReleaseActivate"); |
||
1951 | documentListConfirmDialog("#confirmActivate"); |
||
1952 | documentListConfirmDialog("#confirmInactivate"); |
||
1953 | documentListConfirmDialog("#confirmRestore"); |
||
1954 | documentListConfirmDialog("#confirmDelete"); |
||
1955 | documentListConfirmDialog("#confirmDeleteLocally"); |
||
1956 | documentListConfirmDialog("#confirmDeleteLocallySuggestion"); |
||
1957 | documentListConfirmDialog("#confirmDeleteWorkingCopy"); |
||
1958 | documentListConfirmDialog("#confirmRegister"); |
||
1959 | documentListConfirmDialog("#confirmPostpone"); |
||
1960 | |||
1961 | batchConfirmDialog("BatchSetInProgress"); |
||
1962 | batchConfirmDialog("BatchRegister"); |
||
1963 | batchConfirmDialog("BatchRemove"); |
||
1964 | batchConfirmDialog("BatchReleaseValidated"); |
||
1965 | batchConfirmDialog("BatchReleaseUnvalidated"); |
||
1966 | batchConfirmDialog("BatchBookmark"); |
||
1967 | |||
1968 | removeBookmarkHandler.init(); |
||
1969 | addBookmarkHandler.init(); |
||
1970 | batchSelectHandler.init(); |
||
1971 | |||
1972 | itemsPerPageHandler.init(); |
||
1973 | |||
1974 | extendedSearch.init(); |
||
1975 | saveExtendedSearch.init(); |
||
1976 | openExtendedSearch.init(); |
||
1977 | |||
1978 | userNotifcationSettings.init(); |
||
1979 | |||
1980 | documentFormGroupSelector.init(); |
||
1981 | |||
1982 | doctypeChange.init(); |
||
1983 | |||
1984 | datepicker(); |
||
1985 | jQuery('[data-toggle="tooltip"]').tooltip(); |
||
1986 | var $disableForm = jQuery("form[data-disabled]").attr("data-disabled"); |
||
1987 | if ($disableForm) { |
||
1988 | jQuery(".input-field").each(function() { |
||
1989 | jQuery(this).attr("disabled", "disabled"); |
||
1990 | }); |
||
1991 | jQuery(".rem_file_group").each(function() { |
||
1992 | jQuery(this).attr("disabled", "disabled"); |
||
1993 | }); |
||
1994 | jQuery(".add_file_group").each(function() { |
||
1995 | jQuery(this).attr("disabled", "disabled"); |
||
1996 | }); |
||
1997 | jQuery(".input_file_upload").each(function() { |
||
1998 | jQuery(this).attr("disabled", "disabled"); |
||
1999 | }); |
||
2000 | jQuery(".add_field").each(function() { |
||
2001 | jQuery(this).attr("disabled", "disabled"); |
||
2002 | }); |
||
2003 | jQuery(".add_group").each(function() { |
||
2004 | jQuery(this).attr("disabled", "disabled"); |
||
2005 | }); |
||
2006 | jQuery(".rem_field").each(function() { |
||
2007 | jQuery(this).attr("disabled", "disabled"); |
||
2008 | }); |
||
2009 | jQuery(".rem_group").each(function() { |
||
2010 | jQuery(this).attr("disabled", "disabled"); |
||
2011 | }); |
||
2012 | jQuery(".fill_out_service_urn").each(function() { |
||
2013 | jQuery(this).attr("disabled", "disabled"); |
||
2014 | }); |
||
2015 | } |
||
2016 | buttonFillOutServiceUrn(); |
||
2017 | jQuery(".tx-dpf").on("click", ".rem_group", function() { |
||
2018 | jQuery(this).parents("fieldset").fadeOut(300, function() { |
||
2019 | jQuery(this).remove(); |
||
2020 | var fisPersonIdentifiers = getFisPersonIdentifiers(); |
||
2021 | toggleAddMyUserDataButton(fisPersonIdentifiers); |
||
2022 | }); |
||
2023 | return false; |
||
2024 | }); |
||
2025 | jQuery(".tx-dpf").on("click", ".rem_file_group", deleteFile); |
||
2026 | jQuery(".tx-dpf").on("click", ".rem_field", function() { |
||
2027 | var dataIndex = jQuery(this).data("index"); |
||
2028 | var dataField = jQuery(this).data("field"); |
||
2029 | jQuery(this).parents(".form-group").fadeOut(300, function() { |
||
2030 | jQuery(this).remove(); |
||
2031 | }); |
||
2032 | return false; |
||
2033 | }); |
||
2034 | // Add metadata group |
||
2035 | jQuery(".tx-dpf").on("click", ".add_group", function(e) { |
||
2036 | addGroup(e.target); |
||
2037 | return false; |
||
2038 | }); |
||
2039 | jQuery(".tx-dpf").on("click", ".add_file_group", function(e) { |
||
2040 | addGroup(e.target); |
||
2041 | return false; |
||
2042 | }); |
||
2043 | |||
2044 | jQuery(".tx-dpf").on("click", ".add_field", addField); |
||
2045 | jQuery(".tx-dpf").on("click", ".fill_out_service_urn", fillOutServiceUrn); |
||
2046 | jQuery(".tx-dpf").on("keyup", "input.urn", buttonFillOutServiceUrn); |
||
2047 | jQuery(".tx-dpf").on("click", "#next", continuousScroll); |
||
2048 | jQuery(".form-submit").on("click", "#save", validateFormAndSave); |
||
2049 | |||
2050 | if ( |
||
2051 | typeof(deactivate_mandatory_check_on_save_locally) == "undefined" |
||
2052 | || deactivate_mandatory_check_on_save_locally.length == 0 |
||
2053 | ) { |
||
2054 | jQuery(".form-submit").on("click", "#saveLocalDocument", validateFormAndSave); |
||
2055 | jQuery(".form-submit").on("click", "#saveCreate", validateFormAndSave); |
||
2056 | } |
||
2057 | |||
2058 | jQuery(".form-submit").on("click", "#validate", validateFormOnly); |
||
2059 | |||
2060 | // hide 'more results' link |
||
2061 | var countResults = $("#search-results :not(thead) tr").length; |
||
2062 | var resultCount = $("#next").data("resultCount"); |
||
2063 | |||
2064 | if (countResults < resultCount) { |
||
2065 | jQuery("#next").hide(); |
||
2066 | } |
||
2067 | |||
2068 | addRemoveFileButton(); |
||
2069 | |||
2070 | previousNextFormPage(); |
||
2071 | |||
2072 | var gnd = jQuery(".gnd"); |
||
2073 | if(gnd.length > 0) { |
||
2074 | gnd.each(function() { |
||
2075 | setGndAutocomplete(jQuery(this).data("field"), jQuery(this).data("groupindex")); |
||
2076 | }); |
||
2077 | } |
||
2078 | |||
2079 | selectFilter('doctype-filter'); |
||
2080 | selectFilter('persons-filter', true); |
||
2081 | selectFilter('aliasState-filter'); |
||
2082 | selectFilter('year-filter', true); |
||
2083 | selectFilter('hasFiles-filter'); |
||
2084 | selectFilter('universityCollection-filter'); |
||
2085 | selectFilter('creatorRole-filter'); |
||
2086 | |||
2087 | // Remove the title hover for the filter elements. |
||
2088 | jQuery(".select2-selection__rendered").each(function(){ |
||
2089 | jQuery(this).removeAttr("title"); |
||
2090 | }); |
||
2091 | |||
2092 | selectSort(); |
||
2093 | |||
2094 | toggleBulkImportRecord(); |
||
2095 | toggleBulkImportAuthorSearch(); |
||
2096 | toggleDiscardedFilter(); |
||
2097 | toggleBookmarksOnly(); |
||
2098 | inputWithOptions(); |
||
2099 | |||
2100 | apiTokenEvents(); |
||
2101 | |||
2102 | userSearch(); |
||
2103 | addMyUserData(); |
||
2104 | userSearchModalFillout(); |
||
2105 | $('.modal').on('shown.bs.modal', function() { |
||
2106 | $(this).find('[autofocus]').focus(); |
||
2107 | // new search if checkbox has changed |
||
2108 | $(this).find("#orgaRadio").on('change', function () { |
||
2109 | searchAgain($(this).closest('.modal').find("input[type=text]")[0]); |
||
2110 | }); |
||
2111 | $(this).find("#personRadio").on('change', function () { |
||
2112 | searchAgain($(this).closest('.modal').find("input[type=text]")[0]); |
||
2113 | }); |
||
2114 | }); |
||
2115 | |||
2116 | $('.double-scroll').doubleScroll(); |
||
2117 | }); |
||
2118 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.