| Total Complexity | 155 |
| Complexity/F | 1.87 |
| Lines of Code | 714 |
| Function Count | 83 |
| Duplicated Lines | 714 |
| Ratio | 100 % |
| Changes | 28 | ||
| Bugs | 5 | Features | 4 |
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/qucosa.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 | /** |
||
| 13 | View Code Duplication | $(document).ready(function() { |
|
|
|
|||
| 14 | jQuery('#new-document-form').trigger('reset'); |
||
| 15 | documentListConfirmDialog('#confirmDiscard'); |
||
| 16 | documentListConfirmDialog('#confirmPublish'); |
||
| 17 | documentListConfirmDialog('#confirmUpdate'); |
||
| 18 | documentListConfirmDialog('#confirmActivate'); |
||
| 19 | documentListConfirmDialog('#confirmInactivate'); |
||
| 20 | documentListConfirmDialog('#confirmRestore'); |
||
| 21 | documentListConfirmDialog('#confirmDelete'); |
||
| 22 | datepicker(); |
||
| 23 | jQuery('[data-toggle="tooltip"]').tooltip(); |
||
| 24 | var $disableForm = jQuery('form[data-disabled]').attr('data-disabled'); |
||
| 25 | if ($disableForm) { |
||
| 26 | jQuery('.input-field').each(function() { |
||
| 27 | jQuery(this).attr('disabled', 'disabled'); |
||
| 28 | }); |
||
| 29 | jQuery('.rem_file_group').each(function() { |
||
| 30 | jQuery(this).attr('disabled', 'disabled'); |
||
| 31 | }); |
||
| 32 | jQuery('.add_file_group').each(function() { |
||
| 33 | jQuery(this).attr('disabled', 'disabled'); |
||
| 34 | }); |
||
| 35 | jQuery('.input_file_upload').each(function() { |
||
| 36 | jQuery(this).attr('disabled', 'disabled'); |
||
| 37 | }); |
||
| 38 | jQuery('.add_field').each(function() { |
||
| 39 | jQuery(this).attr('disabled', 'disabled'); |
||
| 40 | }); |
||
| 41 | jQuery('.add_group').each(function() { |
||
| 42 | jQuery(this).attr('disabled', 'disabled'); |
||
| 43 | }); |
||
| 44 | jQuery('.rem_field').each(function() { |
||
| 45 | jQuery(this).attr('disabled', 'disabled'); |
||
| 46 | }); |
||
| 47 | jQuery('.rem_group').each(function() { |
||
| 48 | jQuery(this).attr('disabled', 'disabled'); |
||
| 49 | }); |
||
| 50 | jQuery('.fill_out_service_urn').each(function() { |
||
| 51 | jQuery(this).attr('disabled', 'disabled'); |
||
| 52 | }); |
||
| 53 | } |
||
| 54 | buttonFillOutServiceUrn(); |
||
| 55 | jQuery(".tx-dpf").on("click", ".rem_group", function() { |
||
| 56 | jQuery(this).parents('fieldset').fadeOut(300, function() { |
||
| 57 | jQuery(this).remove(); |
||
| 58 | }); |
||
| 59 | return false; |
||
| 60 | }); |
||
| 61 | jQuery(".tx-dpf").on("click", ".rem_file_group", deleteFile); |
||
| 62 | jQuery(".tx-dpf").on("click", ".rem_secondary_upload", function() { |
||
| 63 | var dataIndex = jQuery(this).data("index"); |
||
| 64 | jQuery(this).parents('.fs_file_group').fadeOut(300, function() { |
||
| 65 | jQuery(this).remove(); |
||
| 66 | }); |
||
| 67 | return false; |
||
| 68 | }); |
||
| 69 | jQuery(".tx-dpf").on("click", ".rem_field", function() { |
||
| 70 | var dataIndex = jQuery(this).data("index"); |
||
| 71 | var dataField = jQuery(this).data("field"); |
||
| 72 | jQuery(this).parents('.form-group').fadeOut(300, function() { |
||
| 73 | jQuery(this).remove(); |
||
| 74 | }); |
||
| 75 | return false; |
||
| 76 | }); |
||
| 77 | // Add metadata group |
||
| 78 | jQuery(".tx-dpf").on("click", ".add_group", addGroup); |
||
| 79 | jQuery(".tx-dpf").on("click", ".add_file_group", addGroup); |
||
| 80 | jQuery(".tx-dpf").on("click", ".add_field", addField); |
||
| 81 | jQuery(".tx-dpf").on("click", ".fill_out_service_urn", fillOutServiceUrn); |
||
| 82 | jQuery(".tx-dpf").on("keyup", "input.urn", buttonFillOutServiceUrn); |
||
| 83 | //jQuery(window).on("scroll", "", continuousScroll); |
||
| 84 | jQuery(".tx-dpf").on("click", "#next", continuousScroll); |
||
| 85 | // jQuery(".form-submit").on("click","#save", |
||
| 86 | jQuery(".form-submit").on("click", "#save", validateFormAndSave); |
||
| 87 | jQuery(".form-submit").on("click", "#validate", validateFormOnly); |
||
| 88 | |||
| 89 | // hide 'more results' link |
||
| 90 | var countResults = $('#search-results :not(thead) tr').length; |
||
| 91 | var resultCount = $('#next').data('resultCount'); |
||
| 92 | |||
| 93 | if (countResults < resultCount) { |
||
| 94 | jQuery("#next").hide(); |
||
| 95 | } |
||
| 96 | |||
| 97 | addRemoveFileButton(); |
||
| 98 | |||
| 99 | previousNextFormPage(); |
||
| 100 | |||
| 101 | var gnd = jQuery('.gnd'); |
||
| 102 | if(gnd.length > 0) { |
||
| 103 | gnd.each(function() { |
||
| 104 | setGndAutocomplete(jQuery(this).data("field"), jQuery(this).data("groupindex")); |
||
| 105 | }); |
||
| 106 | } |
||
| 107 | |||
| 108 | inputWithOptions(); |
||
| 109 | |||
| 110 | }); |
||
| 111 | |||
| 112 | var validateFormAndSave = function() { |
||
| 113 | jQuery("#validDocument").val("0"); |
||
| 114 | if (validateForm()) { |
||
| 115 | jQuery("#validDocument").val("1"); |
||
| 116 | |||
| 117 | jQuery("#new-document-form #save").prop("disabled", true); |
||
| 118 | |||
| 119 | jQuery('#new-document-form').submit(); |
||
| 120 | |||
| 121 | return true; |
||
| 122 | } |
||
| 123 | return false; |
||
| 124 | } |
||
| 125 | var validateFormOnly = function() { |
||
| 126 | if (validateForm()) { |
||
| 127 | showFormSuccess(); |
||
| 128 | } |
||
| 129 | return false; |
||
| 130 | } |
||
| 131 | var validateForm = function() { |
||
| 132 | var error = false; |
||
| 133 | jQuery('span.mandatory-error').remove(); |
||
| 134 | jQuery('div.alert').remove(); |
||
| 135 | jQuery('.tx-dpf-tabs li a').each(function() { |
||
| 136 | jQuery(this).removeClass('mandatory-error'); |
||
| 137 | }); |
||
| 138 | // check mandatory groups |
||
| 139 | jQuery('fieldset[data-mandatory=1]').each(function() { |
||
| 140 | var fieldset = jQuery(this); |
||
| 141 | if (hasMandatoryInputs(fieldset)) { |
||
| 142 | if (checkMandatoryInputs(fieldset)) { |
||
| 143 | jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_group_mandatory + '</div>').insertAfter(fieldset.find('legend').last()); |
||
| 144 | showFormError(); |
||
| 145 | error = true; |
||
| 146 | markPage(fieldset, true); |
||
| 147 | } |
||
| 148 | } else { |
||
| 149 | if (checkFilledInputs(fieldset)) { |
||
| 150 | jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_group_one_required + '</div>').insertAfter(fieldset.find('legend').last()); |
||
| 151 | showFormError(); |
||
| 152 | error = true; |
||
| 153 | markPage(fieldset, true); |
||
| 154 | error = true; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | }); |
||
| 158 | jQuery('fieldset[id=primary_file]').each(function() { |
||
| 159 | var fieldset = jQuery(this); |
||
| 160 | if (checkPrimaryFile(fieldset)) { |
||
| 161 | jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_group_mandatory + '</div>').insertBefore(fieldset.find('legend').last()); |
||
| 162 | showFormError(); |
||
| 163 | error = true; |
||
| 164 | markPage(fieldset, true); |
||
| 165 | } |
||
| 166 | }); |
||
| 167 | // check non mandatory groups |
||
| 168 | jQuery('fieldset[data-mandatory=""]').each(function() { |
||
| 169 | var fieldset = jQuery(this); |
||
| 170 | var filledInputs = 0; |
||
| 171 | jQuery(this).find('.input-field').each(function() { |
||
| 172 | if (jQuery(this).val() && jQuery(this).attr('data-default') != '1') { |
||
| 173 | filledInputs++; |
||
| 174 | } |
||
| 175 | jQuery(this).removeClass('mandatory-error'); |
||
| 176 | }); |
||
| 177 | // if there are fields with a value then mandatory fields |
||
| 178 | // are relevant. |
||
| 179 | if (filledInputs) { |
||
| 180 | if (checkMandatoryInputs(fieldset)) { |
||
| 181 | jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_group_mandatory + '</div>').insertAfter(fieldset.find('legend').last()); |
||
| 182 | showFormError(); |
||
| 183 | markPage(fieldset, true); |
||
| 184 | error = true; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | }); |
||
| 188 | jQuery('fieldset').each(function() { |
||
| 189 | var fieldset = jQuery(this); |
||
| 190 | fieldset.find('.input-field').each(function() { |
||
| 191 | jQuery(this).removeClass('invalid-error'); |
||
| 192 | var validation = jQuery(this).attr('data-regexp'); |
||
| 193 | if (jQuery(this).val() && jQuery(this).val().length > 0 && validation && validation.length > 0) { |
||
| 194 | try { |
||
| 195 | var regexp = new RegExp(validation); |
||
| 196 | var res = jQuery(this).val().match(regexp); |
||
| 197 | if (!(res && res.length == 1 && res[0] == jQuery(this).val())) { |
||
| 198 | jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr('data-label') + '</div>').insertAfter(fieldset.find('legend').last()); |
||
| 199 | jQuery(this).addClass('invalid-error'); |
||
| 200 | showFormError(); |
||
| 201 | markPage(fieldset, true); |
||
| 202 | error = true; |
||
| 203 | } |
||
| 204 | } catch (err) { |
||
| 205 | jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr('data-label') + '</div>').insertAfter(fieldset.find('legend').last()); |
||
| 206 | jQuery(this).addClass('invalid-error'); |
||
| 207 | showFormError(); |
||
| 208 | markPage(fieldset, true); |
||
| 209 | error = true; |
||
| 210 | } |
||
| 211 | } else { |
||
| 212 | var validateDate = jQuery(this).attr('data-datatype') == 'DATE'; |
||
| 213 | if (jQuery(this).val() && jQuery(this).val().length > 0 && validateDate && !isDate(jQuery(this).val())) { |
||
| 214 | jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>' + form_error_msg_field_invalid + ': ' + jQuery(this).attr('data-label') + '</div>').insertAfter(fieldset.find('legend').last()); |
||
| 215 | jQuery(this).addClass('invalid-error'); |
||
| 216 | showFormError(); |
||
| 217 | markPage(fieldset, true); |
||
| 218 | error = true; |
||
| 219 | } |
||
| 220 | } |
||
| 221 | }); |
||
| 222 | /* if (checkPrimaryFile(fieldset)) { |
||
| 223 | jQuery('<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-warning-sign pull-right"></span>'+form_error_msg_group_mandatory+'</div>').insertBefore(fieldset.find('legend').last()); |
||
| 224 | showFormError(); |
||
| 225 | error = true; |
||
| 226 | markPage(fieldset,true); |
||
| 227 | } |
||
| 228 | */ |
||
| 229 | }); |
||
| 230 | return !error; |
||
| 231 | } |
||
| 232 | var showFormError = function() { |
||
| 233 | jQuery('.tx-dpf div.alert-danger').remove(); |
||
| 234 | jQuery('<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon glyphicon-fire pull-right"></span>' + form_error_msg + '</div>').insertBefore(jQuery('.tx-dpf form').first()); |
||
| 235 | jQuery("html, body").animate({ |
||
| 236 | scrollTop: 0 |
||
| 237 | }, 200); |
||
| 238 | } |
||
| 239 | var showFormSuccess = function() { |
||
| 240 | jQuery('.tx-dpf div.alert-danger').remove(); |
||
| 241 | jQuery('<div class="alert alert-success" role="alert"><span class="glyphicon glyphicon glyphicon-fire pull-right"></span>' + form_success_msg + '</div>').insertBefore(jQuery('.tx-dpf form').first()); |
||
| 242 | jQuery("html, body").animate({ |
||
| 243 | scrollTop: 0 |
||
| 244 | }, 200); |
||
| 245 | } |
||
| 246 | var hasMandatoryInputs = function(fieldset) { |
||
| 247 | var inputs = fieldset.find(".input-field[data-mandatory=1]"); |
||
| 248 | return inputs.length > 0 |
||
| 249 | } |
||
| 250 | var markPage = function(fieldset, error) { |
||
| 251 | var pageId = fieldset.parent().attr('id'); |
||
| 252 | var page = jQuery('.tx-dpf-tabs li a[href=#' + pageId + ']'); |
||
| 253 | if (error) { |
||
| 254 | page.addClass('mandatory-error'); |
||
| 255 | } else { |
||
| 256 | page.removeClass('mandatory-error'); |
||
| 257 | } |
||
| 258 | } |
||
| 259 | var checkMandatoryInputs = function(fieldset) { |
||
| 260 | var mandatoryError = false; |
||
| 261 | fieldset.find(".input-field[data-mandatory=1]").each(function() { |
||
| 262 | var id = jQuery(this).attr('id'); |
||
| 263 | if ((jQuery(this).attr('type') != 'checkbox' && !jQuery(this).val()) || (jQuery(this).attr('type') == 'checkbox' && (jQuery("#" + id + ":checked").length != 1 || !jQuery("#" + id + ":checked")))) { |
||
| 264 | mandatoryError = mandatoryError || true; |
||
| 265 | jQuery(this).addClass('mandatory-error'); |
||
| 266 | } else { |
||
| 267 | jQuery(this).removeClass('mandatory-error'); |
||
| 268 | } |
||
| 269 | }); |
||
| 270 | //markPage(fieldset,mandatoryError); |
||
| 271 | return mandatoryError; |
||
| 272 | } |
||
| 273 | var checkPrimaryFile = function(fieldset) { |
||
| 274 | var mandatoryError = false; |
||
| 275 | fieldset.find("input#inp_primaryFile[data-virtual!=1]").each(function() { |
||
| 276 | if (!jQuery(this).val()) { |
||
| 277 | mandatoryError = mandatoryError || true; |
||
| 278 | jQuery(this).addClass('mandatory-error'); |
||
| 279 | } else { |
||
| 280 | jQuery(this).removeClass('mandatory-error'); |
||
| 281 | } |
||
| 282 | }); |
||
| 283 | // markPage(fieldset,mandatoryError); |
||
| 284 | return mandatoryError; |
||
| 285 | } |
||
| 286 | var checkFilledInputs = function(fieldset) { |
||
| 287 | var filledInputs = 0; |
||
| 288 | fieldset.find('.input-field').each(function() { |
||
| 289 | if (jQuery(this).val()) { |
||
| 290 | filledInputs++; |
||
| 291 | } |
||
| 292 | jQuery(this).removeClass('mandatory-error'); |
||
| 293 | }); |
||
| 294 | //markPage(fieldset,filledInputs < 1); |
||
| 295 | return filledInputs < 1; |
||
| 296 | } |
||
| 297 | var addGroup = function() { |
||
| 298 | var element = jQuery(this); |
||
| 299 | // Get the group uid |
||
| 300 | var dataGroup = jQuery(this).attr('data-group'); |
||
| 301 | // Number of the next group item |
||
| 302 | // var groupIndex = jQuery(this).parent().find('fieldset[data-group="'+dataGroup+'"]').length; |
||
| 303 | var groupIndex = parseInt(jQuery(this).attr('data-index')) + 1; |
||
| 304 | jQuery(this).attr('data-index', groupIndex); |
||
| 305 | var ajaxURL = jQuery(this).attr('data-ajax'); |
||
| 306 | var params = buildAjaxParams(ajaxURL, "groupIndex", groupIndex); |
||
| 307 | //do the ajax-call |
||
| 308 | jQuery.post(ajaxURL, params, function(group) { |
||
| 309 | var group = jQuery(group).find("fieldset"); |
||
| 310 | // add the new group |
||
| 311 | jQuery(group).css({ |
||
| 312 | 'display': 'none' |
||
| 313 | }).insertAfter(jQuery('fieldset[data-group="' + dataGroup + '"]').last()); |
||
| 314 | var height = jQuery('fieldset[data-group="' + dataGroup + '"]').last().outerHeight(true) |
||
| 315 | jQuery('html, body').animate({ |
||
| 316 | scrollTop: element.offset().top - height |
||
| 317 | }, 400, function() { |
||
| 318 | jQuery(group).fadeIn(); |
||
| 319 | }); |
||
| 320 | buttonFillOutServiceUrn(); |
||
| 321 | datepicker(); |
||
| 322 | addRemoveFileButton(); |
||
| 323 | |||
| 324 | // gnd autocomplete for new groups |
||
| 325 | var gndField = jQuery(group).find('.gnd'); |
||
| 326 | if (gndField.length != 0) { |
||
| 327 | setGndAutocomplete(gndField.data('field'),gndField.data('groupindex')); |
||
| 328 | } |
||
| 329 | }); |
||
| 330 | return false; |
||
| 331 | } |
||
| 332 | var addField = function() { |
||
| 333 | var addButton = jQuery(this); |
||
| 334 | // Get the field uid |
||
| 335 | var dataField = jQuery(this).attr('data-field'); |
||
| 336 | // Number of the next field item |
||
| 337 | var fieldIndex = parseInt(jQuery(this).attr('data-index')) + 1; |
||
| 338 | jQuery(this).attr('data-index', fieldIndex); |
||
| 339 | var ajaxURL = jQuery(this).attr('data-ajax'); |
||
| 340 | var params = buildAjaxParams(ajaxURL, "fieldIndex", fieldIndex); |
||
| 341 | //do the ajax-call |
||
| 342 | jQuery.post(ajaxURL, params, function(element) { |
||
| 343 | var field = jQuery(element).find("#new-element").children(); |
||
| 344 | jQuery(field).css({ |
||
| 345 | 'display': 'none' |
||
| 346 | }).insertBefore(addButton).fadeIn(); |
||
| 347 | buttonFillOutServiceUrn(); |
||
| 348 | datepicker(); |
||
| 349 | |||
| 350 | // gnd autocomplete for new fields |
||
| 351 | var gndField = jQuery(element).find('.gnd'); |
||
| 352 | if (gndField.length != 0) { |
||
| 353 | setGndAutocomplete(gndField.data('field'),gndField.data('groupindex')); |
||
| 354 | } |
||
| 355 | // var height =jQuery('input[data-field="'+dataField+'"][data-index="'+fieldIndex+'"]').last().outerHeight(true) |
||
| 356 | // jQuery('html, body').animate({ |
||
| 357 | // scrollTop: element.offset().top - height |
||
| 358 | //}, 400); |
||
| 359 | }); |
||
| 360 | return false; |
||
| 361 | } |
||
| 362 | var deleteFile = function() { |
||
| 363 | var fileGroup = jQuery(this).parent().parent(); |
||
| 364 | //jQuery(this).parent().remove(); |
||
| 365 | var ajaxURL = jQuery(this).attr('data-ajax'); |
||
| 366 | //var params = buildAjaxParams(ajaxURL,"fileUid",fieldIndex); |
||
| 367 | var params = {} |
||
| 368 | //do the ajax-call |
||
| 369 | jQuery.post(ajaxURL, params, function(element) { |
||
| 370 | var field = jQuery(element).find("#new-element").children(); |
||
| 371 | jQuery(fileGroup).replaceWith(field); |
||
| 372 | }); |
||
| 373 | return false; |
||
| 374 | } |
||
| 375 | |||
| 376 | function buildAjaxParams(ajaxURL, indexName, index) { |
||
| 377 | var res = ajaxURL.match(/(tx\w+?)%/); // get param name |
||
| 378 | var params = {}; |
||
| 379 | var indexParam = {}; |
||
| 380 | if (res && res[1]) { |
||
| 381 | indexParam[indexName] = index; |
||
| 382 | params[res[1]] = indexParam; |
||
| 383 | } |
||
| 384 | return params; |
||
| 385 | } |
||
| 386 | var fillOutServiceUrn = function() { |
||
| 387 | // Get the field uid |
||
| 388 | var fieldUid = jQuery(this).attr('data-field'); |
||
| 389 | var fieldIndex = jQuery(this).attr('data-index'); |
||
| 390 | var groupUid = jQuery(this).attr('data-group'); |
||
| 391 | var groupIndex = jQuery(this).attr('data-groupindex'); |
||
| 392 | var ajaxURL = jQuery(this).attr('data-ajax'); |
||
| 393 | var qucosaId = jQuery('#qucosaid').val(); |
||
| 394 | var params = {}; |
||
| 395 | if (qucosaId) { |
||
| 396 | params = buildAjaxParams(ajaxURL, "qucosaId", qucosaId); |
||
| 397 | } else { |
||
| 398 | params = buildAjaxParams(ajaxURL, "qucosaId", ""); |
||
| 399 | } |
||
| 400 | //do the ajax-call |
||
| 401 | jQuery.getJSON(ajaxURL, params, function(element) { |
||
| 402 | jQuery('#qucosaid').val(element.qucosaId); |
||
| 403 | jQuery('#qucosaUrn').val(element.value); |
||
| 404 | //var inputField = jQuery('.input-field[data-field="'+ fieldUid +'"][data-index="'+ fieldIndex +'"]'); |
||
| 405 | var inputField = jQuery('.input-field[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"][data-group="' + groupUid + '"][data-groupindex="' + groupIndex + '"]'); |
||
| 406 | inputField.val(element.value); |
||
| 407 | //var fillOutButton = jQuery('.fill_out_service_urn[data-field="'+ fieldUid +'"][data-index="'+ fieldIndex +'"]'); |
||
| 408 | //fillOutButton.hide(); |
||
| 409 | buttonFillOutServiceUrn(); |
||
| 410 | }); |
||
| 411 | return false; |
||
| 412 | } |
||
| 413 | var buttonFillOutServiceUrn = function() { |
||
| 414 | jQuery('input.urn').each(function() { |
||
| 415 | var fieldUid = jQuery(this).attr('data-field'); |
||
| 416 | var fieldIndex = jQuery(this).attr('data-index'); |
||
| 417 | var groupUid = jQuery(this).attr('data-group'); |
||
| 418 | var groupIndex = jQuery(this).attr('data-groupindex'); |
||
| 419 | var fillOutButton = jQuery('.fill_out_service_urn[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"]'); |
||
| 420 | if ((jQuery(this).val() && jQuery(this).val().length > 0) || hasQucosaUrn()) { |
||
| 421 | fillOutButton.hide(); |
||
| 422 | } else { |
||
| 423 | fillOutButton.show(); |
||
| 424 | } |
||
| 425 | }); |
||
| 426 | return false; |
||
| 427 | } |
||
| 428 | var hasQucosaUrn = function() { |
||
| 429 | var result = false; |
||
| 430 | var qucosaUrn = jQuery('#qucosaUrn').val(); |
||
| 431 | jQuery('input.urn').each(function() { |
||
| 432 | var currentUrn = jQuery(this).val(); |
||
| 433 | if (currentUrn && qucosaUrn && (currentUrn == qucosaUrn)) { |
||
| 434 | result = result || true; |
||
| 435 | } |
||
| 436 | }); |
||
| 437 | return result; |
||
| 438 | } |
||
| 439 | var continuousScroll = function() { |
||
| 440 | var ajaxURL = jQuery("#next").attr('href'); |
||
| 441 | jQuery.ajax({ |
||
| 442 | url: ajaxURL, |
||
| 443 | success: function(html) { |
||
| 444 | if (html) { |
||
| 445 | jQuery(html).find("table tbody tr").each(function() { |
||
| 446 | jQuery("#search-results tbody tr").last().parent().append(this); |
||
| 447 | }); |
||
| 448 | if (jQuery(html).find("table tbody tr").length <= 0) { |
||
| 449 | jQuery("#next").hide(); |
||
| 450 | } |
||
| 451 | } else { |
||
| 452 | jQuery("#next").hide(); |
||
| 453 | } |
||
| 454 | } |
||
| 455 | }); |
||
| 456 | return false; |
||
| 457 | } |
||
| 458 | $(window).scroll(function() { |
||
| 459 | if ($(this).scrollTop() > 330) { |
||
| 460 | $(".tx-dpf-tab-container").addClass("sticky"); |
||
| 461 | } else { |
||
| 462 | $(".tx-dpf-tab-container").removeClass("sticky"); |
||
| 463 | } |
||
| 464 | }); |
||
| 465 | var datepicker = function() { |
||
| 466 | var language = jQuery('div.tx-dpf[data-language]').first().attr('data-language'); |
||
| 467 | if (!language) language = "en"; |
||
| 468 | jQuery('.datetimepicker').datetimepicker({ |
||
| 469 | useCurrent: false, |
||
| 470 | format: 'DD.MM.YYYY', |
||
| 471 | locale: language, |
||
| 472 | keepInvalid: true |
||
| 473 | }).on("keydown", function(e){ |
||
| 474 | if (e.which == 13) { |
||
| 475 | $('.datetimepicker').closest('form').submit(); |
||
| 476 | } |
||
| 477 | }); |
||
| 478 | } |
||
| 479 | var isDate = function(value) { |
||
| 480 | if (value == '') return false; |
||
| 481 | var rxDatePattern = /^(\d{1,2})(\.)(\d{1,2})(\.)(\d{4})$/; //Declare Regex |
||
| 482 | var dtArray = value.match(rxDatePattern); // is format OK? |
||
| 483 | if (dtArray == null) return false; |
||
| 484 | //Checks for mm/dd/yyyy format. |
||
| 485 | var dtMonth = dtArray[3]; |
||
| 486 | var dtDay = dtArray[1]; |
||
| 487 | var dtYear = dtArray[5]; |
||
| 488 | if (dtMonth < 1 || dtMonth > 12) { |
||
| 489 | return false; |
||
| 490 | } else if (dtDay < 1 || dtDay > 31) { |
||
| 491 | return false; |
||
| 492 | } else if ((dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) && dtDay == 31) { |
||
| 493 | return false; |
||
| 494 | } else if (dtMonth == 2) { |
||
| 495 | var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0)); |
||
| 496 | if (dtDay > 29 || (dtDay == 29 && !isleap)) return false; |
||
| 497 | } |
||
| 498 | return true; |
||
| 499 | } |
||
| 500 | var documentListConfirmDialog = function(dialogId) { |
||
| 501 | jQuery(dialogId).modal({ |
||
| 502 | show: false, |
||
| 503 | backdrop: 'static' |
||
| 504 | }); |
||
| 505 | jQuery(dialogId).on('show.bs.modal', function(e) { |
||
| 506 | jQuery(this).find('#discardDocument').attr('href', jQuery(e.relatedTarget).attr('href')); |
||
| 507 | var bodyText = jQuery(this).find('.modal-body p').html(); |
||
| 508 | var title = jQuery(e.relatedTarget).attr('data-documenttitle'); |
||
| 509 | jQuery(this).find('.modal-body p').html(bodyText.replace('%s', title)); |
||
| 510 | jQuery(e.relatedTarget).parent().parent().addClass('danger marked-for-removal'); |
||
| 511 | }); |
||
| 512 | jQuery(dialogId).on('hidden.bs.modal', function(e) { |
||
| 513 | jQuery('.marked-for-removal').removeClass('danger marked-for-removal'); |
||
| 514 | }); |
||
| 515 | } |
||
| 516 | |||
| 517 | function addRemoveFileButton() { |
||
| 518 | $('.rem_file').unbind('click'); |
||
| 519 | $('.rem_file').bind('click', function (evt) { |
||
| 520 | evt.preventDefault(); |
||
| 521 | $(this).siblings('.input_file_upload').val(''); |
||
| 522 | }) |
||
| 523 | } |
||
| 524 | |||
| 525 | |||
| 526 | function gndNothingFound(fieldId, groupIndex) { |
||
| 527 | var gndInputField = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]'); |
||
| 528 | |||
| 529 | if (gndInputField.data('old_gnd_field_value')) { |
||
| 530 | gndInputField.val(gndInputField.data('old_gnd_field_value')); |
||
| 531 | } else { |
||
| 532 | gndInputField.val(); |
||
| 533 | } |
||
| 534 | |||
| 535 | var gndFieldId = gndInputField.data('gndfield'); |
||
| 536 | var linkedGroupIndex = gndInputField.data('groupindex'); |
||
| 537 | var gndLinkedInputField = $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]'); |
||
| 538 | |||
| 539 | if (gndLinkedInputField.data('old_gnd_field_id')) { |
||
| 540 | gndLinkedInputField.val(gndLinkedInputField.data('old_gnd_field_id')); |
||
| 541 | } else { |
||
| 542 | gndLinkedInputField.val(); |
||
| 543 | } |
||
| 544 | |||
| 545 | /** global: form_error_msg_nothing_found */ |
||
| 546 | jQuery('<div id="gnd-nothing-found" class="alert alert-warning" role="alert"><span class="glyphicon glyphicon glyphicon-fire pull-right"></span>' + form_error_msg_nothing_found + '</div>').insertBefore(gndInputField.closest('.form-container')); |
||
| 547 | |||
| 548 | gndInputField.bind("keypress click", function () { |
||
| 549 | jQuery("#gnd-nothing-found").remove(); |
||
| 550 | }); |
||
| 551 | |||
| 552 | gndLinkedInputField.bind("keypress click", function () { |
||
| 553 | jQuery("#gnd-nothing-found").remove(); |
||
| 554 | }); |
||
| 555 | |||
| 556 | } |
||
| 557 | |||
| 558 | function setGndAutocomplete(fieldId, groupIndex) { |
||
| 559 | // GND autocomplete |
||
| 560 | var ajaxURL = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]').attr('data-ajax'); |
||
| 561 | |||
| 562 | var gndInputField = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]'); |
||
| 563 | var gndFieldId = gndInputField.data('gndfield'); |
||
| 564 | var linkedGroupIndex = gndInputField.data('groupindex'); |
||
| 565 | var gndLinkedInputField = $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]'); |
||
| 566 | |||
| 567 | gndInputField.attr('data-old_gnd_field_value',gndInputField.val()); |
||
| 568 | gndLinkedInputField.attr('data-old_gnd_field_id',gndLinkedInputField.val()); |
||
| 569 | |||
| 570 | // Get the name of the parameter array (tx_dpf_...), |
||
| 571 | // the name depends on whether the call is from the frontend or the backend |
||
| 572 | var res = ajaxURL.match(/(tx_dpf\w+?)%/); |
||
| 573 | var paramName = "tx_dpf_qucosaform[search]"; |
||
| 574 | if (res && res[1]) { |
||
| 575 | paramName = res[1]+"[search]"; |
||
| 576 | } |
||
| 577 | |||
| 578 | $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]').autocomplete({ |
||
| 579 | source: function (request, response) { |
||
| 580 | |||
| 581 | $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]').val(''); |
||
| 582 | |||
| 583 | var requestData = {}; |
||
| 584 | requestData[paramName] = request.term.replace(" ", "+"); |
||
| 585 | $.ajax({ |
||
| 586 | type: 'POST', |
||
| 587 | url: ajaxURL, |
||
| 588 | data: requestData, |
||
| 589 | dataType: 'json', |
||
| 590 | timeout: 10000, |
||
| 591 | success: function (data) { |
||
| 592 | if (data) { |
||
| 593 | response(data); |
||
| 594 | } else { |
||
| 595 | gndNothingFound(fieldId, groupIndex); |
||
| 596 | response([]); |
||
| 597 | } |
||
| 598 | }, |
||
| 599 | error: function () { |
||
| 600 | gndNothingFound(fieldId, groupIndex); |
||
| 601 | response([]); |
||
| 602 | } |
||
| 603 | }); |
||
| 604 | }, |
||
| 605 | minLength: 3, |
||
| 606 | select: function (event, ui) { |
||
| 607 | gndFieldId = jQuery(event.target).data('gndfield'); |
||
| 608 | linkedGroupIndex = jQuery(event.target).data('groupindex'); |
||
| 609 | $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]').val(ui.item.gnd); |
||
| 610 | }, |
||
| 611 | }).autocomplete( "instance" )._renderItem = function( ul, item ) { |
||
| 612 | return $( "<li>" ) |
||
| 613 | .append( "<div class='gnd-autocomplete'><span class='gnd-value' style='display:none;'>" + item.value + "</span>" + |
||
| 614 | "<span class='gnd-label'>" + item.label + "</span></div>" |
||
| 615 | ) |
||
| 616 | .appendTo( ul ); |
||
| 617 | }; |
||
| 618 | } |
||
| 619 | |||
| 620 | var previousNextFormPage = function() { |
||
| 621 | |||
| 622 | $('.prev-next-buttons button').click(function (e) { |
||
| 623 | var activePage = $('.tx-dpf-tabs').find('li.active'); |
||
| 624 | var newActivePage = activePage; |
||
| 625 | |||
| 626 | if ($(this).attr('id') == 'next-form-page') { |
||
| 627 | newActivePage = activePage.next(); |
||
| 628 | } else { |
||
| 629 | newActivePage = activePage.prev(); |
||
| 630 | } |
||
| 631 | |||
| 632 | if (newActivePage.length > 0) { |
||
| 633 | activePage.removeClass('active'); |
||
| 634 | activePage.find('a').attr('aria-expanded', 'false'); |
||
| 635 | $('.tab-content').find('div.active').removeClass('active'); |
||
| 636 | |||
| 637 | newActivePage.addClass('active'); |
||
| 638 | newActivePage.find('a').attr('aria-expanded', 'true'); |
||
| 639 | $('.tab-content').find(newActivePage.find('a').attr('href')).addClass('active'); |
||
| 640 | |||
| 641 | updatePrevNextButtons(newActivePage); |
||
| 642 | |||
| 643 | $('html, body').animate({ |
||
| 644 | scrollTop:$('.tx-dpf').offset().top |
||
| 645 | },'fast'); |
||
| 646 | } |
||
| 647 | |||
| 648 | e.preventDefault(); |
||
| 649 | |||
| 650 | }); |
||
| 651 | |||
| 652 | updatePrevNextButtons($('.tx-dpf-tabs li.active')); |
||
| 653 | |||
| 654 | $('.tx-dpf-tabs li').click(function(){ |
||
| 655 | updatePrevNextButtons($(this)); |
||
| 656 | }); |
||
| 657 | |||
| 658 | } |
||
| 659 | |||
| 660 | var updatePrevNextButtons = function(activePage) { |
||
| 661 | |||
| 662 | if (activePage.prev().length < 1) { |
||
| 663 | $('#prev-form-page').addClass('disabled'); |
||
| 664 | } else { |
||
| 665 | $('#prev-form-page').removeClass('disabled'); |
||
| 666 | } |
||
| 667 | if (activePage.next().length < 1) { |
||
| 668 | $('#next-form-page').addClass('disabled'); |
||
| 669 | } else { |
||
| 670 | $('#next-form-page').removeClass('disabled'); |
||
| 671 | } |
||
| 672 | } |
||
| 673 | |||
| 674 | var inputWithOptions = function() { |
||
| 675 | |||
| 676 | $.widget( "custom.dropdownoptions", { |
||
| 677 | _create: function() { |
||
| 678 | |||
| 679 | var availableTags = []; |
||
| 680 | var test = this.element |
||
| 681 | .closest(".dropdown-options") |
||
| 682 | .find(".dropdown-options-values li") |
||
| 683 | .each(function(){ |
||
| 684 | if (jQuery(this).text().length > 0) { |
||
| 685 | availableTags.push(jQuery(this).text()); |
||
| 686 | } |
||
| 687 | }); |
||
| 688 | |||
| 689 | this.element |
||
| 690 | .addClass( ".dropdown-options-input" ) |
||
| 691 | .autocomplete({ |
||
| 692 | minLength: 0, |
||
| 693 | source: availableTags |
||
| 694 | }); |
||
| 695 | |||
| 696 | this._createShowAllButton(); |
||
| 697 | }, |
||
| 698 | _createShowAllButton: function() { |
||
| 699 | |||
| 700 | var input = this.element; |
||
| 701 | |||
| 702 | wasOpen = false; |
||
| 703 | |||
| 704 | input |
||
| 705 | .closest(".dropdown-options") |
||
| 706 | .find(".dropdown-options-toggle") |
||
| 707 | .on( "mousedown", function() { |
||
| 708 | wasOpen = input.autocomplete( "widget" ).is( ":visible" ); |
||
| 709 | }) |
||
| 710 | .on( "click", function() { |
||
| 711 | input.trigger( "focus" ); |
||
| 712 | if ( wasOpen ) { |
||
| 713 | return; |
||
| 714 | } |
||
| 715 | input.autocomplete( "search", "" ); |
||
| 716 | |||
| 717 | }); |
||
| 718 | input |
||
| 719 | .on( "click", function() { |
||
| 720 | input.autocomplete( "search", "" ); |
||
| 721 | }); |
||
| 722 | } |
||
| 723 | }); |
||
| 724 | |||
| 725 | $( ".dropdown-options-input" ).dropdownoptions(); |
||
| 726 | } |