Marius Burkard
2016-07-01 49441bdd0f3ff75d5092d5b832b97ea722a66363
commit | author | age
9021d7 1 var ISPConfig = {
MC 2     pageFormChanged: false,
3     tabChangeWarningTxt: '',
4     tabChangeDiscardTxt: '',
5     tabChangeWarning: false,
6     tabChangeDiscard: false,
7     requestsRunning: 0,
8     indicatorCompleted: false,
9     registeredHooks: new Array(),
10     new_tpl_add_id: 0,
11     
12     options: {
13         useLoadIndicator: false,
b79c5b 14         useComboBox: false
9021d7 15     },
MC 16     
17     setOption: function(key, value) {
18         ISPConfig.options[key] = value;
19     },
20     
21     setOptions: function(opts) {
22         $.extend(ISPConfig.options, opts);
23     },
24     
25     reportError: function(request) {
844564 26         
9021d7 27     },
MC 28     
29     registerHook: function(name, callback) {
30         if(!ISPConfig.registeredHooks[name]) ISPConfig.registeredHooks[name] = new Array();
31         var newindex = ISPConfig.registeredHooks[name].length;
32         ISPConfig.registeredHooks[name][newindex] = callback;
33     },
34     
35     callHook: function(name, params) {
36         if(!ISPConfig.registeredHooks[name]) return;
37         for(var i = 0; i < ISPConfig.registeredHooks[name].length; i++) {
38             var callback = ISPConfig.registeredHooks[name][i];
39             callback(name, params);
40         }
41     },
42     
43     resetFormChanged: function() {
44         ISPConfig.pageFormChanged = false;
45     },
46
47     showLoadIndicator: function() {
48         document.body.style.cursor = 'wait';
49         
50         if(ISPConfig.options.useLoadIndicator == true) {
51             ISPConfig.requestsRunning += 1;
52
53             if(ISPConfig.requestsRunning < 2) {
54                 var indicator = $('#ajaxloader');
55                 if(indicator.length < 1) {
56                     indicator = $('<div id="ajaxloader" style="display: none;"></div>');
57                     indicator.appendTo('body');
58                 }
59                 var parent = $('#content');
60                 if(parent.length < 1) return;
61                 ISPConfig.indicatorCompleted = false;
62
63                 var atx = parent.offset().left + 150; //((parent.outerWidth(true) - indicator.outerWidth(true)) / 2);
64                 var aty = parent.offset().top + 150;
65                 indicator.css( {'left': atx, 'top': aty } ).fadeIn('fast', function() {
66                     // check if loader should be hidden immediately
67                     ISPConfig.indicatorCompleted = true;
68                     if(ISPConfig.requestsRunning < 1) $(this).fadeOut('fast', function() { $(this).hide();});
69                 });
70             }
71         }
72     },
73
74     hideLoadIndicator: function() {
75         document.body.style.cursor = '';
76
77         ISPConfig.requestsRunning -= 1;
78         if(ISPConfig.requestsRunning < 1) {
79             ISPConfig.requestsRunning = 0; // just for the case...
80             if(ISPConfig.indicatorCompleted == true) $('#ajaxloader').fadeOut('fast', function() { $('#ajaxloader').hide(); } );
81         }
82     },
83
84     onAfterSideNavLoaded: function() {
85         if(ISPConfig.options.useComboBox == true) {
86             $('#sidebar').find("select:not(.chosen-select)").select2({
87                 placeholder: '',
88                 width: 'element',
89                 selectOnBlur: true,
b79c5b 90                 allowClear: true
9021d7 91             });
MC 92         }
93     },
94
95     onAfterContentLoad: function(url, data) {
96         if(!data) data = '';
97         else data = '&' + data;
98         
99         if(ISPConfig.options.useComboBox == true) {
100             $('#pageContent').find("select:not(.chosen-select)").select2({
101                 placeholder: '',
102                 width: 'element',
103                 selectOnBlur: true,
104                 allowClear: true,
105                 formatResult: function(o) {
106                     if(o.id && $(o.element).parent().hasClass('flags')) return '<span class="flags flag-' + o.id.toLowerCase() + '">' + o.text + '</span>';
107                     else return o.text;
108                 },
109                 formatSelection: function(o) {
110                     if(o.id && $(o.element).parent().hasClass('flags')) return '<span class="flags flag-' + o.id.toLowerCase() + '">' + o.text + '</span>';
111                     else return o.text;
112                 }
113             }).on('change', function(e) {
114                 if ($("#pageForm .table #Filter").length > 0) {
115                     $("#pageForm .table #Filter").trigger('click');
116                 }
117             });
118         }
119         
43e5b6 120         $('input[data-input-element="date"]').datetimepicker({
MC 121             'language': 'en', // TODO
122             'todayHighlight': true,
123             'todayBtn': 'linked',
124             'bootcssVer': 3,
125             'fontAwesome': true,
126             'autoclose': true,
127             'minView': 'month'
128         });
129         $('input[data-input-element="datetime"]').datetimepicker({
130             'language': 'en', // TODO
131             'todayHighlight': true,
132             'todayBtn': 'linked',
133             'bootcssVer': 3,
134             'fontAwesome': true,
135             'autoclose': true
136         });
137         
9021d7 138         ISPConfig.callHook('onAfterContentLoad', {'url': url, 'data': data });
MC 139     },
140
141     submitForm: function(formname, target, confirmation) {
142         var successMessage = arguments[3];
143         if(!confirmation) confirmation = false;
144         
145         if(!confirmation || window.confirm(confirmation)) {
146             var submitFormObj = $.ajax({
147                 type: "POST",
148                 url: target,
149                 data: $('#'+formname).serialize(),
150                 dataType: "html",
151                 beforeSend: function() {
152                     ISPConfig.showLoadIndicator();
153                 },
154                 success: function(data, textStatus, jqXHR) {
155                     if(successMessage) alert(successMessage);
156                     if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
157                         var parts = jqXHR.responseText.split(':');
158                         ISPConfig.loadContent(parts[1]);
b79c5b 159                     } else if (jqXHR.responseText.indexOf('LOGIN_REDIRECT:') > -1) {
TB 160                         // Go to the login page
161                         document.location.href = '/index.php';
9021d7 162                     } else {
MC 163                         $('#pageContent').html(jqXHR.responseText);
164                         ISPConfig.onAfterContentLoad(target, $('#'+formname).serialize());
165                         ISPConfig.pageFormChanged = false;
166                     }
167                     ISPConfig.hideLoadIndicator();
168                 },
169                 error: function(jqXHR, textStatus, errorThrown) {
170                     ISPConfig.hideLoadIndicator();
171                     var parts = jqXHR.responseText.split(':');
172                     ISPConfig.reportError('Ajax Request was not successful. 111');
173                 }
174             });
175         }
176     },
177
178     submitUploadForm: function(formname, target) {
179         var handleResponse = function(loadedFrame) {
180             var response, responseStr = loadedFrame.contentWindow.document.body.innerHTML;
181
182             try {
183                 response = JSON.parse(responseStr);
184             } catch(e) {
185                 response = responseStr;
186             }
d82de9 187             var $response = $('<div></div>').html(response);
9021d7 188             var msg = '';
d82de9 189             var okmsg = $response.find('#OKMsg').html();
9021d7 190             if(okmsg){
MC 191                 msg = '<div id="OKMsg">'+okmsg+'</div>';
192             }
d82de9 193             var errormsg = $response.find('#errorMsg').html();
9021d7 194             if(errormsg){
MC 195                 msg = msg+'<div id="errorMsg">'+errormsg+'</div>';
196             }
d82de9 197             
MB 198             var csrf_key = $response.find('input[name="_csrf_key"]').val();
199             var csrf_id = $response.find('input[name="_csrf_id"]').val();
200             
201             msg = msg + '<input type="hidden" name="_csrf_id" value="' + csrf_id + '" /><input type="hidden" name="_csrf_key" value="' + csrf_key + '" />';
202             
9021d7 203             return msg;
MC 204
205         };
206
207         var frame_id = 'ajaxUploader-iframe-' + Math.round(new Date().getTime() / 1000);
d82de9 208         $('body').append('<iframe width="0" height="0" style="display:none;" name="'+frame_id+'" id="'+frame_id+'"/>');
9021d7 209         $('#'+frame_id).load(function() {
MC 210             var msg = handleResponse(this);
211             $('#errorMsg').remove();
212             $('#OKMsg').remove();
d82de9 213             $('input[name="_csrf_key"]').remove();
MB 214             $('input[name="_csrf_id"]').remove();
9021d7 215             $('input[name="id"]').before(msg);
MC 216             $(this).remove();
217           });
d82de9 218         $('input[type="file"]').closest("form").attr({target: frame_id, action: target}).submit();
9021d7 219     },
MC 220
221     capp: function(module, redirect) {
222         var submitFormObj = $.ajax({
223             type: "GET",
224             url: "capp.php",
225             data: "mod="+module+((redirect != undefined) ? '&redirect='+redirect : ''),
226             dataType: "html",
227             beforeSend: function() {
228                 ISPConfig.showLoadIndicator();
229             },
230             success: function(data, textStatus, jqXHR) {
231                 if(jqXHR.responseText != '') {
232                     if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
233                         var parts = jqXHR.responseText.split(':');
234                         ISPConfig.loadContent(parts[1]);
235                     } else if (jqXHR.responseText.indexOf('URL_REDIRECT:') > -1) {
236                         var newUrl= jqXHR.responseText.substr(jqXHR.responseText.indexOf('URL_REDIRECT:') + "URL_REDIRECT:".length);
237                         document.location.href = newUrl;
238                     } else {
239                         //alert(jqXHR.responseText);
240                     }
241                 }
242                 ISPConfig.loadMenus();
243                 ISPConfig.hideLoadIndicator();
244             },
245             error: function() {
246                 ISPConfig.hideLoadIndicator();
247                 ISPConfig.reportError('Ajax Request was not successful.'+module);
248             }
249         });
250     },
251     
252     loadContent: function(pagename) {
253         var params = arguments[1];
254         var pageContentObject2 = $.ajax({
255             type: "GET",
256             url: pagename,
257             data: (params ? params : null),
258             dataType: "html",
259             beforeSend: function() {
260                 ISPConfig.showLoadIndicator();
261             },
262             success: function(data, textStatus, jqXHR) {
263                 if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
264                     var parts = jqXHR.responseText.split(':');
265                     ISPConfig.loadContent(parts[1]);
266                 } else if (jqXHR.responseText.indexOf('URL_REDIRECT:') > -1) {
267                     var newUrl= jqXHR.responseText.substr(jqXHR.responseText.indexOf('URL_REDIRECT:') + "URL_REDIRECT:".length);
268                     document.location.href = newUrl;
269                 } else {
270                     $('#pageContent').html(jqXHR.responseText);
271                     ISPConfig.onAfterContentLoad(pagename, (params ? params : null));
272                     ISPConfig.pageFormChanged = false;
273                 }
274                 ISPConfig.hideLoadIndicator();
275             },
276             error: function() {
277                 ISPConfig.hideLoadIndicator();
278                 ISPConfig.reportError('Ajax Request was not successful. 113');
279             }
280         });
281     },
282
283     loadContentRefresh: function(pagename) {
284         if($('#refreshinterval').val() > 0) {
285             var pageContentObject2 = $.ajax({
286                 type: "GET",
287                 url: pagename,
288                 data: "refresh="+document.getElementById('refreshinterval').value,
289                 dataType: "html",
290                 beforeSend: function() {
291                     ISPConfig.showLoadIndicator();
292                 },
293                 success: function(data, textStatus, jqXHR) {
294                     ISPConfig.hideLoadIndicator();
295                     $('#pageContent').html(jqXHR.responseText);
296                     ISPConfig.onAfterContentLoad(pagename, "refresh="+document.getElementById('refreshinterval').value);
297                     ISPConfig.pageFormChanged = false;
298                 },
299                 error: function() {
300                     ISPConfig.hideLoadIndicator();
301                     ISPConfig.reportError('Ajax Request was not successful.'+pagename);
302                 }
303             });
304             setTimeout( "ISPConfig.loadContentRefresh('"+pagename+"&refresh="+document.getElementById('refreshinterval').value+"')", document.getElementById('refreshinterval').value*1000*60 );
305         }
306     },
307
308     loadInitContent: function() {
b2ba0d 309         var startpage = $('#pageContent').attr('data-startpage');
MB 310         if(!startpage) startpage = 'dashboard/dashboard.php';
9021d7 311         var pageContentObject = $.ajax({
MC 312             type: "GET",
b2ba0d 313             url: startpage,
b79c5b 314             data: "",
9021d7 315             dataType: "html",
MC 316             beforeSend: function() {
317                 ISPConfig.showLoadIndicator();
318             },
319             success: function(data, textStatus, jqXHR) {
320                 if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
321                     var parts = jqXHR.responseText.split(":");
322                     ISPConfig.loadContent(parts[1]);
323                 } else {
324                     $('#pageContent').html(jqXHR.responseText);
b79c5b 325                     ISPConfig.onAfterContentLoad('dashboard/dashboard.php', "");
9021d7 326                     ISPConfig.pageFormChanged = false;
MC 327                 }
328                 ISPConfig.hideLoadIndicator();
329             },
330             error: function() {
331                 ISPConfig.hideLoadIndicator();
332                 ISPConfig.reportError('Ajax Request was not successful. 114');
333             }
334         });
335         
336         ISPConfig.loadMenus();
337         ISPConfig.keepalive();
338         setTimeout(function() {
339             try {
340                 $('form#pageForm').find('input[name="username"]').focus();
341             } catch (e) {
342             
343             }
344         }, 1000);
345     },
346     
347     loadMenus: function() {
348         var sideNavObject = $.ajax({
349             type: "GET",
350             url: "nav.php",
351             data: "nav=side",
352             dataType: "html",
353             beforeSend: function() {
354                 ISPConfig.showLoadIndicator();
355             },
356             success: function(data, textStatus, jqXHR) {
357                 ISPConfig.hideLoadIndicator();
358                 $('#sidebar').html(jqXHR.responseText);
359                 ISPConfig.onAfterSideNavLoaded();
360                 ISPConfig.loadPushyMenu();
361             },
362             error: function() {
363                 ISPConfig.hideLoadIndicator();
364                 ISPConfig.reportError('Ajax Request was not successful. 115');
365             }
366         });
367
368         var topNavObject = $.ajax({
369             type: "GET",
370             url: "nav.php",
371             data: "nav=top",
372             dataType: "html",
373             beforeSend: function() {
374                 ISPConfig.showLoadIndicator();
375             },
376             success: function(data, textStatus, jqXHR) {
377                 ISPConfig.hideLoadIndicator();
378                 $('#topnav-container').html(jqXHR.responseText);
379                 ISPConfig.loadPushyMenu();
380             },
381             error: function(o) {
382                 ISPConfig.hideLoadIndicator();
383                 ISPConfig.reportError('Ajax Request was not successful. 116');
384             }
385         });
386     },
387
388     changeTab: function(tab, target, force) {
844564 389         if(ISPConfig.requestsRunning > 0) {
MB 390             console.log('tab change interrupted, request still running.');
391             return false;
392         }
9021d7 393     
MC 394         document.pageForm.next_tab.value = tab;
395
396         var idel = $('form#pageForm').find('[name="id"]');
397         var id = null;
398         if(idel.length > 0) id = idel.val();
399         if(ISPConfig.tabChangeDiscard == 'y' && !force) {
400             if((idel.length < 1 || id) && (ISPConfig.pageFormChanged == false || window.confirm(ISPConfig.tabChangeDiscardTxt))) {
401                 var next_tab = tab;
402                 if(id) ISPConfig.loadContent(target, {'next_tab': next_tab, 'id': id});
403                 else ISPConfig.loadContent(target, {'next_tab': next_tab});
404             } else {
405                 return false;
406             }
407         } else {
408             if(id && ISPConfig.tabChangeWarning == 'y' && ISPConfig.pageFormChanged == true) {
409                 if(window.confirm(ISPConfig.tabChangeWarningTxt)) {
410                     ISPConfig.submitForm('pageForm', target);
411                 } else {
412                     var next_tab = tab;
413                     if(id) ISPConfig.loadContent(target, {'next_tab': next_tab, 'id': id});
414                     else ISPConfig.loadContent(target, {'next_tab': next_tab});
415                 }
416             } else {
417                 ISPConfig.submitForm('pageForm',target);
418             }
419         }
420     },
421
422     confirm_action: function(link, confirmation) {
423         if(window.confirm(confirmation)) {
424             ISPConfig.loadContent(link);
425         }
426     },
427
428     loadContentInto: function(elementid,pagename) {
429         var pageContentObject2 = $.ajax({
430             type: "GET",
431             url: pagename,
432             dataType: "html",
433             beforeSend: function() {
434             },
435             success: function(data, textStatus, jqXHR) {
436                 $('#'+elementid).html(jqXHR.responseText);
437             },
438             error: function() {
439                 ISPConfig.reportError('Ajax Request was not successful. 118');
440             }
441         });
442     },
443
d5f2d5 444     loadOptionInto: function(elementid,pagename,callback) {
9021d7 445         var pageContentObject2 = $.ajax({
MC 446             type: "GET",
447             url: pagename,
448             dataType: "html",
449             beforeSend: function() {
450             },
451             success: function(data, textStatus, jqXHR) {
452                 var teste = jqXHR.responseText;
453                 var elemente = teste.split('#');
454                 el=document.getElementById(elementid);
455                 el.innerHTML='';
456                 for (var i = 0; i < elemente.length; ++i){
457                     var foo2 = document.createElement("option");
458                     foo2.appendChild(document.createTextNode(elemente[i]));
459                     foo2.value=elemente[i];
460                     el.appendChild(foo2);
461                 }
d5f2d5 462                 if (typeof(callback) != 'undefined') {
MC 463                     callback(elementid,pagename);
464                 }
9021d7 465             },
MC 466             error: function() {
467                 ISPConfig.reportError('Ajax Request was not successful. 119');
468             }
469         });
470     },
471     
472     keepalive: function() {
473         var pageContentObject3 = $.ajax({
474             type: "GET",
475             url: "keepalive.php",
476             dataType: "html",
477             success: function(data, textStatus, jqXHR) {
bbb85a 478                 setTimeout( function() { ISPConfig.keepalive(); }, 1000000 );
9021d7 479             },
MC 480             error: function() {
481                 ISPConfig.reportError('Session expired. Please login again.');
482             }
483         });
484     },
485     
486     addAdditionalTemplate: function(){
487         var tpl_add = $('#template_additional').val();
488         var addTemplate = $('#tpl_add_select').val().split('|',2);
489         var addTplId = addTemplate[0];
490         var addTplText = addTemplate[1];
491         if(addTplId > 0) {
492             var newVal = tpl_add.split('/');
493             ISPConfig.new_tpl_add_id += 1;
494             var delbtn = $('<a href="#"></a>').attr('class', 'button icons16 icoDelete').click(function(e) {
495                 e.preventDefault();
496                 ISPConfig.delAdditionalTemplate($(this).parent().attr('rel'));
497             });
498             newVal[newVal.length] = 'n' + ISPConfig.new_tpl_add_id + ':' + addTplId;
499             $('<li>' + addTplText + '</li>').attr('rel', 'n' + new_tpl_add_id).append(delbtn).appendTo('#template_additional_list ul');
500             $('#template_additional').val(newVal.join('/'));
501             alert('additional template ' + addTplText + ' added to customer');
502         } else {
503             alert('no additional template selcted');
504         }
505     },
506
507     delAdditionalTemplate: function(tpl_id) {
508         var tpl_add = $('#template_additional').val();
509         if(tpl_id) {
510             // new style
511             var $el = $('#template_additional_list ul').find('li[rel="' + tpl_id + '"]').eq(0); // only the first
512             var addTplText = $el.text();
513             $el.remove();
514
515             var oldVal = tpl_add.split('/');
516             var newVal = new Array();
517             for(var i = 0; i < oldVal.length; i++) {
518                 var tmp = oldVal[i].split(':', 2);
519                 if(tmp.length == 2 && tmp[0] == tpl_id) continue;
520                 newVal[newVal.length] = oldVal[i];
521             }
522             $('#template_additional').val(newVal.join('/'));
523             alert('additional template ' + addTplText + ' deleted from customer');
524         } else if(tpl_add != '') {
525             // old style
526             var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
527             var addTplId = addTemplate[0];
528             var addTplText = addTemplate[1];
529
530             $('#template_additional_list ul').find('li:not([rel])').each(function() {
531                 var text = $(this).text();
532                 if(text == addTplText) {
533                     $(this).remove();
534                     return false;
535                 }
536                 return this;
537             });
538
539             var newVal = tpl_add;
540             var repl = new RegExp('(^|\/)' + addTplId + '(\/|$)');
541             newVal = newVal.replace(repl, '');
542             newVal = newVal.replace('//', '/');
543             $('#template_additional').val(newVal);
544             alert('additional template ' + addTplText + ' deleted from customer');
545       } else {
546         alert('no additional template selcted');
547       }
548     }
549 };
550
551
552 $(document).on("change", function(event) {
553     var elName = event.target.localName;
554     if ($("#pageForm .table #Filter").length > 0 && elName == 'select') {
555         event.preventDefault();
556         $("#pageForm .table #Filter").trigger('click');
557     }
558     if(elName == 'select' || elName == 'input' || elName == 'textarea') {
559         if($(event.target).hasClass('no-page-form-change') == false) {
560             // set marker that something was changed
561             ISPConfig.pageFormChanged = true;
562         }
563     }
564 });
565
768b3f 566 var $page = $('html, body');
MB 567
9021d7 568 $(document).on('click', 'a[data-load-content],button[data-load-content]', function(e) {
37f2c2 569     e.preventDefault();
844564 570     if(ISPConfig.requestsRunning > 0) {
MB 571         console.log('preventing click because there is still a request running.');
572         return;
573     }
574     
768b3f 575     $page.on('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); });
MB 576     $page.animate({scrollTop: 0}, 1000, function() { $page.off('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); }); });
37f2c2 577     
9021d7 578     var content_to_load = $(this).attr('data-load-content');
MC 579     if(!content_to_load) return this;
580     
581     ISPConfig.loadContent(content_to_load);
582 });
583
584 $(document).on('click', 'a[data-capp],button[data-capp]', function(e) {
37f2c2 585     e.preventDefault();
844564 586     if(ISPConfig.requestsRunning > 0) {
MB 587         console.log('preventing click because there is still a request running.');
588         return;
589     }
590     
768b3f 591     $page.on('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); });
MB 592     $page.animate({scrollTop: 0}, 1000, function() { $page.off('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); }); });
37f2c2 593     
9021d7 594     var content_to_load = $(this).attr('data-capp');
MC 595     if(!content_to_load) return this;
596     
597     ISPConfig.capp(content_to_load);
598 });
599
600 $(document).on('click', 'a[data-submit-form],button[data-submit-form]', function(e) {
37f2c2 601     e.preventDefault();
844564 602     if(ISPConfig.requestsRunning > 0) {
MB 603         console.log('preventing click because there is still a request running.');
604         return;
605     }
606     
768b3f 607     $page.on('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); });
MB 608     $page.animate({scrollTop: 0}, 1000, function() { $page.off('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); }); });
9021d7 609     
MC 610     var $el = $(this);
611     var act = $el.attr('data-form-action');
612     var form = $el.attr('data-submit-form');
613     
614     if($el.attr('data-form-upload') == 'true') ISPConfig.submitUploadForm(form, act);
615     else ISPConfig.submitForm(form, act);
616 });
617
618 $(document).bind("keypress", function(event) {
619     //Use $ submit with keypress Enter in panel filterbar
620     if (event.which == '13' && $("#pageForm .table #Filter").length > 0 && $(event.target).hasClass('ui-autocomplete-input') == false ) {
621         event.preventDefault();
622         $("#pageForm .table #Filter").trigger('click');
623     }
624     //Use $ submit with keypress Enter in forms
eb610b 625     if (event.which == '13' && $(".tab-content button.formbutton-success").length > 0 && event.target.localName != 'textarea' && $(event.target).is(':input')) {
9021d7 626         event.preventDefault();
eb610b 627         $(".tab-content button.formbutton-success").not("[disabled='disabled']").trigger('click');
9021d7 628     }
MC 629 });
630
631 $(document).on('click', 'th[data-column]', function(e) {
632     var $self = $(this);
633     var column = $self.attr('data-column');
634     if(!column) return this;
635     
636     if($("#pageForm .table #Filter").length > 0 && $self.attr('data-sortable') != 'false') {
637         var $el = $('#Filter');
638         var act = $el.attr('data-form-action');
639         var form = $el.attr('data-submit-form');
640         
d76e2d 641         var dir = $self.attr('data-ordered');
MC 642         
024e13 643         var separator = '?';
MC 644         if(act.indexOf("?") >= 0){
645             separator = '&';
646         }
647         act = act + separator + 'orderby=' + column;
9021d7 648         ISPConfig.submitForm(form, act);
d76e2d 649         
MC 650         $(document).ajaxComplete(function() {
651             var $self = $('#pageForm .table th[data-column="' + column + '"]');
652             $self.parent().children('th[data-column]').removeAttr('data-ordered');
653             if(dir && dir == 'asc') $self.attr('data-ordered', 'desc');
654             else $self.attr('data-ordered', 'asc');
655         });
656         
9021d7 657     }
MC 658 });
659
660 $(document).on("click", ".addPlaceholder", function(){
661     var placeholderText = $(this).text();
662     var template = $(this).siblings(':input');
663     template.insertAtCaret(placeholderText);
664 });
665
666 $(document).on("click", ".addPlaceholderContent", function(){
667     var placeholderContentText = $(this).find('.addPlaceholderContent').text();
668     var template2 = $(this).siblings(':input');
669     template2.insertAtCaret(placeholderContentText);
670 });
671
af56b4 672 $(document).on("click", "[data-check-fields] > input[type='checkbox']", function() {
MB 673     if($(this).is(':checked')) {
674         var flds = $(this).parent().attr('data-check-fields');
675         var tmp = flds.split(/,/);
676         for(var i = 0; i < tmp.length; i++) {
677             var fname = tmp[i];
678             $('input[type="checkbox"][name="' + fname + '"]').prop('checked', true);
679         }
680     }
681 });
682
683 $(document).on("click", "[data-uncheck-fields] > input[type='checkbox']", function() {
684     if($(this).is(':checked') == false) {
685         var flds = $(this).parent().attr('data-uncheck-fields');
686         var tmp = flds.split(/,/);
687         for(var i = 0; i < tmp.length; i++) {
688             var fname = tmp[i];
689             $('input[type="checkbox"][name="' + fname + '"]').prop('checked', false);
690         }
691     }
692 });
693
694
01cec5 695 $(document).on('ready', function () {
9021d7 696     $.fn.extend({
MC 697         insertAtCaret: function(myValue){
698             return this.each(function(i) {
699                 if (document.selection) {
700                     //For browsers like Internet Explorer
701                     this.focus();
702                     sel = document.selection.createRange();
703                     sel.text = myValue;
704                     this.focus();
705                 } else if (this.selectionStart || this.selectionStart == '0') {
706                     //For browsers like Firefox and Webkit based
707                     var startPos = this.selectionStart;
708                     var endPos = this.selectionEnd;
709                     var scrollTop = this.scrollTop;
710                     this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
711                     this.focus();
712                     this.selectionStart = startPos + myValue.length;
713                     this.selectionEnd = startPos + myValue.length;
714                     this.scrollTop = scrollTop;
715                 } else {
716                     this.value += myValue;
717                     this.focus();
718                 }
719             })
720         }
721     });
722     
723     // Animierter Ladefortschritt
724     $('.progress .progress-bar').css('width', function () {
725         return $(this).attr('aria-valuenow') + '%';
726     });
727     
728     ISPConfig.loadInitContent();
729
730     $('#searchform').submit(function(e) {
731         e.preventDefault();
732     });
733     
734     $("#pageForm").submit(function(e){
735         //Prevent form submit: e.preventDefault() in lists
736         if ($("#pageForm .table #Filter").length > 0) {
737             e.preventDefault();
738         }
739     });
a6e530 740     
MB 741     $.fn.setCursorPosition = function(pos) {
742         var self = $(this).get(0);
743         if(self.setSelectionRange) {
744             self.setSelectionRange(pos, pos);
745         } else if(self.createTextRange) {
746             var range = self.createTextRange();
747             range.collapse(true);
748             if(pos < 0) {
749                 pos = $(this).val().length + pos;
750             }
751             range.moveEnd('character', pos);
752             range.moveStart('character', pos);
753             range.select();
754         }
755     };
756     
757     $.fn.getCursorPosition = function() {
758         var iCaretPos = 0;
759         var self = $(this).get(0);
760         
761         if(typeof self.selectionStart === 'number') {
762             iCaretPos = self.selectionDirection == 'backward' ? self.selectionStart : self.selectionEnd;
763         } else if(document.selection) {
764             this.focus();
765             var oSel = document.selection.createRange();
766             oSel.moveStart('character', -self.value.length);
767             iCaretPos = oSel.text.length;
768         }
769         return iCaretPos;
770     };
01cec5 771 });