Passed
Pull Request — master (#90)
by
unknown
03:42
created

ield.bind(ꞌkeypress clickꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
/**
2
 * This file is part of the TYPO3 CMS project.
3
 *
4
 * It is free software; you can redistribute it and/or modify it under
5
 * the terms of the GNU General Public License, either version 2
6
 * of the License, or any later version.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 *
11
 * The TYPO3 project - inspiring people to share!
12
 */
13
$(document).ready(function() {
14
    documentListConfirmDialog('#confirmDiscard');
15
    documentListConfirmDialog('#confirmPublish');
16
    documentListConfirmDialog('#confirmUpdate');
17
    documentListConfirmDialog('#confirmActivate');
18
    documentListConfirmDialog('#confirmInactivate');
19
    documentListConfirmDialog('#confirmRestore');
20
    documentListConfirmDialog('#confirmDelete');
21
    datepicker();
22
    jQuery('[data-toggle="tooltip"]').tooltip();
23
    $disableForm = jQuery('form[data-disabled]').attr('data-disabled');
0 ignored issues
show
Bug introduced by
The variable $disableForm seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$disableForm.
Loading history...
24
    if ($disableForm) {
25
        jQuery('.input-field').each(function() {
26
            jQuery(this).attr('disabled', 'disabled');
27
        });
28
        jQuery('.rem_file_group').each(function() {
29
            jQuery(this).attr('disabled', 'disabled');
30
        });
31
        jQuery('.add_file_group').each(function() {
32
            jQuery(this).attr('disabled', 'disabled');
33
        });
34
        jQuery('.input_file_upload').each(function() {
35
            jQuery(this).attr('disabled', 'disabled');
36
        });
37
        jQuery('.add_field').each(function() {
38
            jQuery(this).attr('disabled', 'disabled');
39
        });
40
        jQuery('.add_group').each(function() {
41
            jQuery(this).attr('disabled', 'disabled');
42
        });
43
        jQuery('.rem_field').each(function() {
44
            jQuery(this).attr('disabled', 'disabled');
45
        });
46
        jQuery('.rem_group').each(function() {
47
            jQuery(this).attr('disabled', 'disabled');
48
        });
49
        jQuery('.fill_out_service_urn').each(function() {
50
            jQuery(this).attr('disabled', 'disabled');
51
        });
52
    }
53
    buttonFillOutServiceUrn();
54
    jQuery(".tx-dpf").on("click", ".rem_group", function() {
55
        jQuery(this).parents('fieldset').fadeOut(300, function() {
56
            jQuery(this).remove();
57
        });
58
        return false;
59
    });
60
    jQuery(".tx-dpf").on("click", ".rem_file_group", deleteFile);
61
    jQuery(".tx-dpf").on("click", ".rem_secondary_upload", function() {
62
        var dataIndex = jQuery(this).data("index");
0 ignored issues
show
Unused Code introduced by
The variable dataIndex seems to be never used. Consider removing it.
Loading history...
63
        jQuery(this).parents('.fs_file_group').fadeOut(300, function() {
64
            jQuery(this).remove();
65
        });
66
        return false;
67
    });
68
    jQuery(".tx-dpf").on("click", ".rem_field", function() {
69
        var dataIndex = jQuery(this).data("index");
0 ignored issues
show
Unused Code introduced by
The variable dataIndex seems to be never used. Consider removing it.
Loading history...
70
        var dataField = jQuery(this).data("field");
0 ignored issues
show
Unused Code introduced by
The variable dataField seems to be never used. Consider removing it.
Loading history...
71
        jQuery(this).parents('.form-group').fadeOut(300, function() {
72
            jQuery(this).remove();
73
        });
74
        return false;
75
    });
76
    // Add metadata group
77
    jQuery(".tx-dpf").on("click", ".add_group", addGroup);
78
    jQuery(".tx-dpf").on("click", ".add_file_group", addGroup);
79
    jQuery(".tx-dpf").on("click", ".add_field", addField);
80
    jQuery(".tx-dpf").on("click", ".fill_out_service_urn", fillOutServiceUrn);
81
    jQuery(".tx-dpf").on("keyup", "input.urn", buttonFillOutServiceUrn);
82
    //jQuery(window).on("scroll", "", continuousScroll);
83
    jQuery(".tx-dpf").on("click", "#next", continuousScroll);
84
    // jQuery(".form-submit").on("click","#save",
85
    jQuery(".form-submit").on("click", "#save", validateFormAndSave);
86
    jQuery(".form-submit").on("click", "#validate", validateFormOnly);
87
88
    // hide 'more results' link
89
    var countResults = $('#search-results :not(thead) tr').length;
90
    var resultCount = $('#next').data('resultCount');
91
92
    if (countResults < resultCount) {
93
        jQuery("#next").hide();
94
    }
95
96
    addRemoveFileButton();
97
98
    gnd = jQuery('.gnd');
0 ignored issues
show
Bug introduced by
The variable gnd seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.gnd.
Loading history...
99
    if(gnd.length > 0) {
100
        gnd.each(function() {
101
            setGndAutocomplete(jQuery(this).data("field"),  jQuery(this).data("groupindex"));
102
        });
103
    }
104
    
105
});
106
var validateFormAndSave = function() {
107
    jQuery("#validDocument").val("0");
108
    if (validateForm()) {
109
        jQuery("#validDocument").val("1");
110
        return true;
111
    }
112
    return false;
113
}
114
var validateFormOnly = function() {
115
    if (validateForm()) {
116
        showFormSuccess();
117
    }
118
    return false;
119
}
120
var validateForm = function() {
121
    var error = false;
122
    jQuery('span.mandatory-error').remove();
123
    jQuery('div.alert').remove();
124
    jQuery('.tx-dpf-tabs li a').each(function() {
125
        jQuery(this).removeClass('mandatory-error');
126
    });
127
    // check mandatory groups
128
    jQuery('fieldset[data-mandatory=1]').each(function() {
129
        var fieldset = jQuery(this);
130
        if (hasMandatoryInputs(fieldset)) {
131
            if (checkMandatoryInputs(fieldset)) {
132
                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());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_mandatory seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_mandatory */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
133
                showFormError();
134
                error = true;
135
                markPage(fieldset, true);
136
            }
137
        } else {
138
            if (checkFilledInputs(fieldset)) {
139
                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());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_one_required seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_one_required */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
140
                showFormError();
141
                error = true;
142
                markPage(fieldset, true);
143
                error = true;
144
            }
145
        }
146
    });
147
    jQuery('fieldset[id=primary_file]').each(function() {
148
        var fieldset = jQuery(this);
149
        if (checkPrimaryFile(fieldset)) {
150
            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());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_mandatory seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_mandatory */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
151
            showFormError();
152
            error = true;
153
            markPage(fieldset, true);
154
        }
155
    });
156
    // check non mandatory groups
157
    jQuery('fieldset[data-mandatory=""]').each(function() {
158
        var fieldset = jQuery(this);
159
        var filledInputs = 0;
160
        jQuery(this).find('.input-field').each(function() {
161
            if (jQuery(this).val() && jQuery(this).attr('data-default') != '1') {
162
                filledInputs++;
163
            }
164
            jQuery(this).removeClass('mandatory-error');
165
        });
166
        // if there are fields with a value then mandatory fields
167
        // are relevant.
168
        if (filledInputs) {
169
            if (checkMandatoryInputs(fieldset)) {
170
                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());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_group_mandatory seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_group_mandatory */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
171
                showFormError();
172
                markPage(fieldset, true);
173
                error = true;
174
            }
175
        }
176
    });
177
    jQuery('fieldset').each(function() {
178
        var fieldset = jQuery(this);
179
        fieldset.find('.input-field').each(function() {
180
            jQuery(this).removeClass('invalid-error');
181
            var validation = jQuery(this).attr('data-regexp');
182
            if (jQuery(this).val() && jQuery(this).val().length > 0 && validation && validation.length > 0) {
183
                try {
184
                    var regexp = new RegExp(validation);
185
                    var res = jQuery(this).val().match(regexp);
186
                    if (!(res && res.length == 1 && res[0] == jQuery(this).val())) {
187
                        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());
0 ignored issues
show
Bug introduced by
The variable form_error_msg_field_invalid seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_field_invalid */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
188
                        jQuery(this).addClass('invalid-error');
189
                        showFormError();
190
                        markPage(fieldset, true);
191
                        error = true;
192
                    }
193
                } catch (err) {
194
                    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());
195
                    jQuery(this).addClass('invalid-error');
196
                    showFormError();
197
                    markPage(fieldset, true);
198
                    error = true;
199
                }
200
            } else {
201
                var validateDate = jQuery(this).attr('data-datatype') == 'DATE';
202
                if (jQuery(this).val() && jQuery(this).val().length > 0 && validateDate && !isDate(jQuery(this).val())) {
203
                    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());
204
                    jQuery(this).addClass('invalid-error');
205
                    showFormError();
206
                    markPage(fieldset, true);
207
                    error = true;
208
                }
209
            }
210
        });
211
        /*        if (checkPrimaryFile(fieldset)) {
212
                  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());
213
                  showFormError();   
214
                  error = true;
215
                  markPage(fieldset,true);        
216
                }
217
          */
218
    });
219
    return !error;
220
}
221
var showFormError = function() {
222
    jQuery('.tx-dpf div.alert-danger').remove();
223
    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());
0 ignored issues
show
Bug introduced by
The variable form_error_msg seems to be never declared. If this is a global, consider adding a /** global: form_error_msg */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
224
    jQuery("html, body").animate({
225
        scrollTop: 0
226
    }, 200);
227
}
228
var showFormSuccess = function() {
229
    jQuery('.tx-dpf div.alert-danger').remove();
230
    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());
0 ignored issues
show
Bug introduced by
The variable form_success_msg seems to be never declared. If this is a global, consider adding a /** global: form_success_msg */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
231
    jQuery("html, body").animate({
232
        scrollTop: 0
233
    }, 200);
234
}
235
var hasMandatoryInputs = function(fieldset) {
236
    var inputs = fieldset.find(".input-field[data-mandatory=1]");
237
    return inputs.length > 0
238
}
239
var markPage = function(fieldset, error) {
240
    var pageId = fieldset.parent().attr('id');
241
    var page = jQuery('.tx-dpf-tabs li a[href=#' + pageId + ']');
242
    if (error) {
243
        page.addClass('mandatory-error');
244
    } else {
245
        page.removeClass('mandatory-error');
246
    }
247
}
248
var checkMandatoryInputs = function(fieldset) {
249
    var mandatoryError = false;
250
    fieldset.find(".input-field[data-mandatory=1]").each(function() {
251
        var id = jQuery(this).attr('id');
252
        if ((jQuery(this).attr('type') != 'checkbox' && !jQuery(this).val()) || (jQuery(this).attr('type') == 'checkbox' && (jQuery("#" + id + ":checked").length != 1 || !jQuery("#" + id + ":checked")))) {
253
            mandatoryError = mandatoryError || true;
254
            jQuery(this).addClass('mandatory-error');
255
        } else {
256
            jQuery(this).removeClass('mandatory-error');
257
        }
258
    });
259
    //markPage(fieldset,mandatoryError);
260
    return mandatoryError;
261
}
262
var checkPrimaryFile = function(fieldset) {
263
    var mandatoryError = false;
264
    fieldset.find("input#inp_primaryFile[data-virtual!=1]").each(function() {
265
        if (!jQuery(this).val()) {
266
            mandatoryError = mandatoryError || true;
267
            jQuery(this).addClass('mandatory-error');
268
        } else {
269
            jQuery(this).removeClass('mandatory-error');
270
        }
271
    });
272
    //  markPage(fieldset,mandatoryError);
273
    return mandatoryError;
274
}
275
var checkFilledInputs = function(fieldset) {
276
    var filledInputs = 0;
277
    fieldset.find('.input-field').each(function() {
278
        if (jQuery(this).val()) {
279
            filledInputs++;
280
        }
281
        jQuery(this).removeClass('mandatory-error');
282
    });
283
    //markPage(fieldset,filledInputs < 1);    
284
    return filledInputs < 1;
285
}
286
var addGroup = function() {
287
    var element = jQuery(this);
288
    // Get the group uid
289
    var dataGroup = jQuery(this).attr('data-group');
290
    // Number of the next group item
291
    // var groupIndex = jQuery(this).parent().find('fieldset[data-group="'+dataGroup+'"]').length;
292
    var groupIndex = parseInt(jQuery(this).attr('data-index')) + 1;
293
    jQuery(this).attr('data-index', groupIndex);
294
    var ajaxURL = jQuery(this).attr('data-ajax');
295
    var params = buildAjaxParams(ajaxURL, "groupIndex", groupIndex);
296
    //do the ajax-call
297
    jQuery.post(ajaxURL, params, function(group) {
298
        var group = jQuery(group).find("fieldset");
299
        // add the new group
300
        jQuery(group).css({
301
            'display': 'none'
302
        }).insertAfter(jQuery('fieldset[data-group="' + dataGroup + '"]').last());
303
        var height = jQuery('fieldset[data-group="' + dataGroup + '"]').last().outerHeight(true)
304
        jQuery('html, body').animate({
305
            scrollTop: element.offset().top - height
306
        }, 400, function() {
307
            jQuery(group).fadeIn();
308
        });
309
        buttonFillOutServiceUrn();
310
        datepicker();
311
        addRemoveFileButton();
312
313
        // gnd autocomplete for new groups
314
        gndField = jQuery(group).find('.gnd');
0 ignored issues
show
Bug introduced by
The variable gndField seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.gndField.
Loading history...
315
        if (gndField.length != 0) {
316
            setGndAutocomplete(gndField.data('field'),gndField.data('groupindex'));
317
        }
318
    });
319
    return false;
320
}
321
var addField = function() {
322
    var addButton = jQuery(this);
323
    // Get the field uid
324
    var dataField = jQuery(this).attr('data-field');
0 ignored issues
show
Unused Code introduced by
The variable dataField seems to be never used. Consider removing it.
Loading history...
325
    // Number of the next field item      
326
    var fieldIndex = parseInt(jQuery(this).attr('data-index')) + 1;
327
    jQuery(this).attr('data-index', fieldIndex);
328
    var ajaxURL = jQuery(this).attr('data-ajax');
329
    var params = buildAjaxParams(ajaxURL, "fieldIndex", fieldIndex);
330
    //do the ajax-call       
331
    jQuery.post(ajaxURL, params, function(element) {
332
        var field = jQuery(element).find("#new-element").children();
333
        jQuery(field).css({
334
            'display': 'none'
335
        }).insertBefore(addButton).fadeIn();
336
        buttonFillOutServiceUrn();
337
        datepicker();
338
339
        // gnd autocomplete for new fields
340
        gndField = jQuery(group).find('.gnd');
0 ignored issues
show
Bug introduced by
The variable group seems to be never declared. If this is a global, consider adding a /** global: group */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable gndField seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.gndField.
Loading history...
341
        if (gndField.length != 0) {
342
            setGndAutocomplete(gndField.data('field'),gndField.data('groupindex'));
343
        }
344
        //  var height =jQuery('input[data-field="'+dataField+'"][data-index="'+fieldIndex+'"]').last().outerHeight(true)
345
        // jQuery('html, body').animate({
346
        //   scrollTop: element.offset().top - height
347
        //}, 400);
348
    });
349
    return false;
350
}
351
var deleteFile = function() {
352
    var fileGroup = jQuery(this).parent().parent();
353
    //jQuery(this).parent().remove();
354
    var ajaxURL = jQuery(this).attr('data-ajax');
355
    //var params = buildAjaxParams(ajaxURL,"fileUid",fieldIndex);
356
    var params = {}
357
        //do the ajax-call       
358
    jQuery.post(ajaxURL, params, function(element) {
359
        var field = jQuery(element).find("#new-element").children();
360
        jQuery(fileGroup).replaceWith(field);
361
    });
362
    return false;
363
}
364
365
function buildAjaxParams(ajaxURL, indexName, index) {
366
    var res = ajaxURL.match(/(tx\w+?)%/); // get param name
367
    var params = {};
368
    var indexParam = {};
369
    if (res && res[1]) {
370
        indexParam[indexName] = index;
371
        params[res[1]] = indexParam;
372
    }
373
    return params;
374
}
375
var fillOutServiceUrn = function() {
376
    // Get the field uid
377
    var fieldUid = jQuery(this).attr('data-field');
378
    var fieldIndex = jQuery(this).attr('data-index');
379
    var groupUid = jQuery(this).attr('data-group');
380
    var groupIndex = jQuery(this).attr('data-groupindex');
381
    var ajaxURL = jQuery(this).attr('data-ajax');
382
    var qucosaId = jQuery('#qucosaid').val();
383
    var params = {};
0 ignored issues
show
Unused Code introduced by
The assignment to variable params seems to be never used. Consider removing it.
Loading history...
384
    if (qucosaId) {
385
        params = buildAjaxParams(ajaxURL, "qucosaId", qucosaId);
386
    } else {
387
        params = buildAjaxParams(ajaxURL, "qucosaId", "");
388
    }
389
    //do the ajax-call       
390
    jQuery.getJSON(ajaxURL, params, function(element) {
391
        jQuery('#qucosaid').val(element.qucosaId);
392
        jQuery('#qucosaUrn').val(element.value);
393
        //var inputField = jQuery('.input-field[data-field="'+ fieldUid +'"][data-index="'+ fieldIndex +'"]');                  
394
        var inputField = jQuery('.input-field[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"][data-group="' + groupUid + '"][data-groupindex="' + groupIndex + '"]');
395
        inputField.val(element.value);
396
        //var fillOutButton = jQuery('.fill_out_service_urn[data-field="'+ fieldUid +'"][data-index="'+ fieldIndex +'"]');           
397
        //fillOutButton.hide();           
398
        buttonFillOutServiceUrn();
399
    });
400
    return false;
401
}
402
var buttonFillOutServiceUrn = function() {
403
    jQuery('input.urn').each(function() {
404
        var fieldUid = jQuery(this).attr('data-field');
405
        var fieldIndex = jQuery(this).attr('data-index');
406
        var groupUid = jQuery(this).attr('data-group');
0 ignored issues
show
Unused Code introduced by
The variable groupUid seems to be never used. Consider removing it.
Loading history...
407
        var groupIndex = jQuery(this).attr('data-groupindex');
0 ignored issues
show
Unused Code introduced by
The variable groupIndex seems to be never used. Consider removing it.
Loading history...
408
        var fillOutButton = jQuery('.fill_out_service_urn[data-field="' + fieldUid + '"][data-index="' + fieldIndex + '"]');
409
        if ((jQuery(this).val() && jQuery(this).val().length > 0) || hasQucosaUrn()) {
410
            fillOutButton.hide();
411
        } else {
412
            fillOutButton.show();
413
        }
414
    });
415
    return false;
416
}
417
var hasQucosaUrn = function() {
418
    var result = false;
419
    var qucosaUrn = jQuery('#qucosaUrn').val();
420
    jQuery('input.urn').each(function() {
421
        var currentUrn = jQuery(this).val();
422
        if (currentUrn && qucosaUrn && (currentUrn == qucosaUrn)) {
423
            result = result || true;
424
        }
425
    });
426
    return result;
427
}
428
var continuousScroll = function() {
429
    var ajaxURL = jQuery("#next").attr('href');
430
    jQuery.ajax({
431
        url: ajaxURL,
432
        success: function(html) {
433
            if (html) {
434
                jQuery(html).find("table tbody tr").each(function() {
435
                    jQuery("#search-results tbody tr").last().parent().append(this);
436
                });
437
                if (jQuery(html).find("table tbody tr").length <= 0) {
438
                    jQuery("#next").hide();
439
                }
440
            } else {
441
                jQuery("#next").hide();
442
            }
443
        }
444
    });
445
    return false;
446
}
447
$(window).scroll(function() {
448
    if ($(this).scrollTop() > 330) {
449
        $(".tx-dpf-tab-container").addClass("sticky");
450
    } else {
451
        $(".tx-dpf-tab-container").removeClass("sticky");
452
    }
453
});
454
var datepicker = function() {
455
    var language = jQuery('div.tx-dpf[data-language]').first().attr('data-language');
456
    if (!language) language = "en";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
457
    jQuery('.datetimepicker').datetimepicker({
458
        useCurrent: false,
459
        format: 'DD.MM.YYYY',
460
        locale: language,
461
        keepInvalid: true
462
    });
463
}
464
var isDate = function(value) {
465
    if (value == '') return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
466
    var rxDatePattern = /^(\d{1,2})(\.)(\d{1,2})(\.)(\d{4})$/; //Declare Regex
467
    var dtArray = value.match(rxDatePattern); // is format OK?
468
    if (dtArray == null) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
469
    //Checks for mm/dd/yyyy format.
470
    dtMonth = dtArray[3];
0 ignored issues
show
Bug introduced by
The variable dtMonth seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dtMonth.
Loading history...
471
    dtDay = dtArray[1];
0 ignored issues
show
Bug introduced by
The variable dtDay seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dtDay.
Loading history...
472
    dtYear = dtArray[5];
0 ignored issues
show
Bug introduced by
The variable dtYear seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.dtYear.
Loading history...
473
    if (dtMonth < 1 || dtMonth > 12) {
474
        return false;
475
    } else if (dtDay < 1 || dtDay > 31) {
476
        return false;
477
    } else if ((dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) && dtDay == 31) {
478
        return false;
479
    } else if (dtMonth == 2) {
480
        var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
481
        if (dtDay > 29 || (dtDay == 29 && !isleap)) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
482
    }
483
    return true;
484
}
485
var documentListConfirmDialog = function(dialogId) {
486
    jQuery(dialogId).modal({
487
        show: false,
488
        backdrop: 'static'
489
    });
490
    jQuery(dialogId).on('show.bs.modal', function(e) {
491
        jQuery(this).find('#discardDocument').attr('href', jQuery(e.relatedTarget).attr('href'));
492
        var bodyText = jQuery(this).find('.modal-body p').html();
493
        var title = jQuery(e.relatedTarget).attr('data-documenttitle');
494
        jQuery(this).find('.modal-body p').html(bodyText.replace('%s', title));
495
        jQuery(e.relatedTarget).parent().parent().addClass('danger marked-for-removal');
496
    });
497
    jQuery(dialogId).on('hidden.bs.modal', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
498
        jQuery('.marked-for-removal').removeClass('danger marked-for-removal');
499
    });
500
}
501
502
function addRemoveFileButton() {
503
    $('.rem_file').unbind('click');
504
    $('.rem_file').bind('click', function (evt) {
505
        evt.preventDefault();
506
        $(this).siblings('.input_file_upload').val('');
507
    })
508
}
509
510
511
function gndNothingFound(fieldId, groupIndex) {
512
    var gndInputField = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]');
513
514
    if (gndInputField.data('old_gnd_field_value')) {
515
        gndInputField.val(gndInputField.data('old_gnd_field_value'));
516
    } else {
517
        gndInputField.val();
518
    }
519
520
    gndFieldId = gndInputField.data('gndfield');
0 ignored issues
show
Bug introduced by
The variable gndFieldId seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.gndFieldId.
Loading history...
521
    linkedGroupIndex = gndInputField.data('groupindex');
0 ignored issues
show
Bug introduced by
The variable linkedGroupIndex seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.linkedGroupIndex.
Loading history...
522
    gndLinkedInputField = $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]');
0 ignored issues
show
Bug introduced by
The variable gndLinkedInputField seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.gndLinkedInputField.
Loading history...
523
524
    if (gndLinkedInputField.data('old_gnd_field_id')) {
525
        gndLinkedInputField.val(gndLinkedInputField.data('old_gnd_field_id'));
526
    } else {
527
        gndLinkedInputField.val();
528
    }
529
530
    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'));
0 ignored issues
show
Bug introduced by
The variable form_error_msg_nothing_found seems to be never declared. If this is a global, consider adding a /** global: form_error_msg_nothing_found */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
531
532
    gndInputField.bind("keypress click", function () {
533
        jQuery("#gnd-nothing-found").remove();
534
    });
535
536
    gndLinkedInputField.bind("keypress click", function () {
537
        jQuery("#gnd-nothing-found").remove();
538
    });
539
540
}
541
542
function setGndAutocomplete(fieldId, groupIndex) {
543
    // GND autocomplete
544
    var ajaxURL = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]').attr('data-ajax');
545
546
    var gndInputField = $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]');
547
    var gndFieldId = gndInputField.data('gndfield');
548
    var linkedGroupIndex = gndInputField.data('groupindex');
549
    var gndLinkedInputField = $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]');
550
551
    gndInputField.attr('data-old_gnd_field_value',gndInputField.val());
552
    gndLinkedInputField.attr('data-old_gnd_field_id',gndLinkedInputField.val());
553
554
    // Get the name of the parameter array (tx_dpf_...),
555
    // the name depends on whether the call is from the frontend or the backend
556
    var res = ajaxURL.match(/(tx_dpf\w+?)%/);
557
    var paramName = "tx_dpf_qucosaform[search]";
558
    if (res && res[1]) {
559
        paramName = res[1]+"[search]";
560
    }
561
562
    $('.gnd[data-field="' + fieldId + '"][data-groupindex="' + groupIndex + '"]').autocomplete({
563
        source: function (request, response) {
564
            var requestData = {};
565
            requestData[paramName] = request.term;
566
            $.ajax({
567
                type: 'POST',
568
                url: ajaxURL,
569
                data: requestData,
570
                dataType: 'json',
571
                timeout: 10000,
572
                success: function (data) {
573
                   if (data) {
574
                       response(data);
575
                   } else {
576
                       gndNothingFound(fieldId, groupIndex);
577
                       response([]);
578
                   }
579
                },
580
                error: function (xhr, ajaxOptions, thrownError) {
0 ignored issues
show
Unused Code introduced by
The parameter thrownError is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter ajaxOptions is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter xhr is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
581
                    gndNothingFound(fieldId, groupIndex);
582
                    response([]);
583
                }
584
            });
585
        },
586
        minLength: 3,
587
        select: function (event, ui) {
588
            gndFieldId = jQuery(event.target).data('gndfield');
589
            linkedGroupIndex = jQuery(event.target).data('groupindex');
590
591
            $('input[data-field="' + gndFieldId + '"][data-groupindex="' + linkedGroupIndex + '"]').val(ui.item.gnd);
592
        }
593
    }).autocomplete( "instance" )._renderItem = function( ul, item ) {
594
        return $( "<li>" )
595
            .append( "<div class='gnd-autocomplete'><span class='gnd-type'>" + item.typ + "</span><span class='gnd-value'>" + item.value + "</span></div>" )
596
            .appendTo( ul );
597
    };
598
}