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