1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
|
/*
** Zabbix
** Copyright (C) 2001-2018 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
jQuery.noConflict();
var overlays_stack = [];
function isset(key, obj) {
return (is_null(key) || is_null(obj)) ? false : (typeof(obj[key]) != 'undefined');
}
/**
* @deprecated use strict comparison instead
*
* @param obj
* @returns {*}
*/
function empty(obj) {
if (is_null(obj)) {
return true;
}
if (obj === false) {
return true;
}
if (is_string(obj) && obj === '') {
return true;
}
if (typeof(obj) == 'undefined') {
return true;
}
return is_array(obj) && obj.length == 0;
}
/**
* @deprecated use === null instead
*
* @param obj
* @returns {boolean}
*/
function is_null(obj) {
return (obj == null);
}
function is_number(obj) {
return isNaN(obj) ? false : (typeof(obj) === 'number');
}
function is_object(obj, instance) {
if (typeof(instance) === 'object' || typeof(instance) === 'function') {
if (typeof(obj) === 'object' && obj instanceof instance) {
return true;
}
}
else {
if (typeof(obj) === 'object') {
return true;
}
}
return false;
}
function is_string(obj) {
return (typeof(obj) === 'string');
}
function is_array(obj) {
return (obj != null) && (typeof obj == 'object') && ('splice' in obj) && ('join' in obj);
}
function addListener(element, eventname, expression, bubbling) {
bubbling = bubbling || false;
element = $(element);
if (element.addEventListener) {
element.addEventListener(eventname, expression, bubbling);
return true;
}
else if (element.attachEvent) {
element.attachEvent('on' + eventname, expression);
return true;
}
else {
return false;
}
}
function removeListener(element, eventname, expression, bubbling) {
bubbling = bubbling || false;
element = $(element);
if (element.removeEventListener) {
element.removeEventListener(eventname, expression, bubbling);
return true;
}
else if (element.detachEvent) {
element.detachEvent('on' + eventname, expression);
return true;
}
else {
return false;
}
}
function cancelEvent(e) {
if (!e) {
e = window.event;
}
e.stopPropagation();
e.preventDefault();
if (IE) {
e.cancelBubble = true;
e.returnValue = false;
}
return false;
}
function add_variable(o_el, s_name, x_value, s_formname, o_document) {
var form;
if (!o_document) {
o_document = document;
}
if (s_formname) {
if (!(form = o_document.forms[s_formname])) {
throw "Missing form with name '" + s_formname + "'.";
}
}
else if (o_el) {
if (!(form = o_el.form)) {
throw "Missing form in 'o_el' object";
}
}
else {
if (!(form = this.form)) {
throw "Missing form in 'this' object";
}
}
var o_variable = o_document.createElement('input');
if (!o_variable) {
throw "Can't create element";
}
o_variable.type = 'hidden';
o_variable.name = s_name;
o_variable.id = s_name;
o_variable.value = x_value;
form.appendChild(o_variable);
return true;
}
function checkAll(form_name, chkMain, shkName) {
var frmForm = document.forms[form_name],
value = frmForm.elements[chkMain].checked;
chkbxRange.checkObjectAll(shkName, value);
chkbxRange.update(shkName);
chkbxRange.saveCookies(shkName);
return true;
}
function checkLocalAll(form_name, chkMain, chkName) {
var frmForm = document.forms[form_name];
var checkboxes = $$('input[name=' + chkName + ']');
for (var i = 0; i < checkboxes.length; i++) {
if (isset('type', checkboxes[i]) && checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = frmForm.elements[chkMain].checked;
}
}
return true;
}
function close_window() {
window.setTimeout('window.close();', 500); // solve bug for Internet Explorer
return false;
}
function Confirm(msg) {
return confirm(msg);
}
/**
* Function removes input elements in specified form that matches given selector.
*
* @param {object}|{string} form_name Form element in which input elements will be selected. If given value is 'null',
* the DOM document object will be used.
* @param {string} selector String containing one or more commas separated CSS selectors.
*
* @returns {bool}
*/
function removeVarsBySelector(form_name, selector) {
if (form_name !== null) {
var source = is_string(form_name) ? document.forms[form_name] : form_name;
}
else {
var source = document;
}
if (!source) {
return false;
}
var inputs = source.querySelectorAll(selector);
if (inputs.length) {
for (var i in inputs) {
if (typeof inputs[i] === 'object') {
inputs[i].parentNode.removeChild(inputs[i]);
}
}
}
}
function create_var(form_name, var_name, var_value, doSubmit) {
var objForm = is_string(form_name) ? document.forms[form_name] : form_name;
if (!objForm) {
return false;
}
var objVar = (typeof(objForm[var_name]) != 'undefined') ? objForm[var_name] : null;
if (is_null(objVar)) {
objVar = document.createElement('input');
objVar.setAttribute('type', 'hidden');
if (!objVar) {
return false;
}
objVar.setAttribute('name', var_name);
objVar.setAttribute('id', var_name.replace(']', '').replace('[', '_'));
objForm.appendChild(objVar);
}
if (is_null(var_value)) {
objVar.parentNode.removeChild(objVar);
}
else {
objVar.value = var_value;
}
if (doSubmit) {
objForm.submit();
}
return false;
}
function getDimensions(obj) {
obj = $(obj);
var dim = {
left: 0,
top: 0,
right: 0,
bottom: 0,
width: 0,
height: 0,
offsetleft: 0
};
if (!is_null(obj) && typeof(obj.offsetParent) != 'undefined') {
var dim = {
left: parseInt(obj.style.left, 10),
top: parseInt(obj.style.top, 10),
width: parseInt(obj.style.width, 10),
height: parseInt(obj.style.height, 10),
offsetleft: parseInt(jQuery(obj).offset().left, 10)
};
if (!is_number(dim.top)) {
dim.top = parseInt(obj.offsetTop, 10);
}
if (!is_number(dim.left)) {
dim.left = parseInt(obj.offsetLeft, 10);
}
if (!is_number(dim.width)) {
dim.width = parseInt(obj.offsetWidth, 10);
}
if (!is_number(dim.height)) {
dim.height = parseInt(obj.offsetHeight, 10);
}
dim.right = dim.left + dim.width;
dim.bottom = dim.top + dim.height;
}
return dim;
}
function getPosition(obj) {
obj = $(obj);
var pos = {top: 0, left: 0};
if (!is_null(obj) && typeof(obj.offsetParent) != 'undefined') {
pos.left = obj.offsetLeft;
pos.top = obj.offsetTop;
try {
while (!is_null(obj.offsetParent)) {
obj = obj.offsetParent;
pos.left += obj.offsetLeft;
pos.top += obj.offsetTop;
if (IE && obj.offsetParent.toString() == 'unknown') {
break;
}
}
} catch(e) {
}
}
return pos;
}
function get_bodywidth() {
var w = parseInt(document.body.scrollWidth);
var w2 = parseInt(document.body.offsetWidth);
return (w2 < w) ? w2 : w;
}
function get_cursor_position(e) {
e = e || window.event;
var cursor = {x: 0, y: 0};
if (e.pageX || e.pageY) {
cursor.x = e.pageX;
cursor.y = e.pageY;
}
else {
var de = document.documentElement;
var b = document.body;
cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
}
return cursor;
}
function get_scroll_pos() {
var scrOfX = 0, scrOfY = 0;
// netscape compliant
if (typeof(window.pageYOffset) == 'number') {
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
}
// DOM compliant
else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
}
// IE6 standards compliant mode
else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}
return [scrOfX, scrOfY];
}
function openWinCentered(url, name, width, height, params) {
var top = Math.ceil((screen.height - height) / 2),
left = Math.ceil((screen.width - width) / 2);
if (params.length > 0) {
params = ', ' + params;
}
var windowObj = window.open(new Curl(url).getUrl(), name,
'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + params
);
windowObj.focus();
}
/**
* Opens popup content in overlay dialogue.
*
* @param {string} action Popup controller related action.
* @param {array} options Array with key/value pairs that will be used as query for popup request.
* @param {string} dialogueid (optional) id of overlay dialogue.
* @param {object} trigger_elmnt (optional) UI element which was clicked to open overlay dialogue.
*
* @returns false
*/
function PopUp(action, options, dialogueid, trigger_elmnt) {
var ovelay_properties = {
'title': '',
'content': jQuery('<div>')
.css({'height': '68px'})
.append(jQuery('<div>')
.addClass('preloader-container')
.append(jQuery('<div>').addClass('preloader'))
),
'class': 'modal-popup',
'buttons': [],
'dialogueid': (typeof dialogueid === 'undefined' || !dialogueid) ? getOverlayDialogueId() : dialogueid
};
var url = new Curl('zabbix.php');
url.setArgument('action', action);
jQuery.each(options, function(key, value) {
url.setArgument(key, value);
});
jQuery.ajax({
url: url.getUrl(),
type: 'get',
dataType: 'json',
beforeSend: function(jqXHR) {
overlayDialogue(ovelay_properties, trigger_elmnt, jqXHR);
},
success: function(resp) {
if (typeof resp.errors !== 'undefined') {
ovelay_properties['content'] = resp.errors;
}
else {
var buttons = resp.buttons !== null ? resp.buttons : [];
buttons.push({
'title': t('Cancel'),
'class': 'btn-alt',
'action': function() {}
});
ovelay_properties['title'] = resp.header;
ovelay_properties['content'] = resp.body;
ovelay_properties['controls'] = resp.controls;
ovelay_properties['buttons'] = buttons;
if (typeof resp.debug !== 'undefined') {
ovelay_properties['debug'] = resp.debug;
}
if (typeof resp.script_inline !== 'undefined') {
ovelay_properties['script_inline'] = resp.script_inline;
}
}
overlayDialogue(ovelay_properties);
}
});
return false;
}
/**
* Function to add details about overlay UI elements in global overlays_stack variable.
*
* @param {string} dialogueid Unique overlay element identifier.
* @param {object} element UI element which must be focused when overlay UI element will be closed.
* @param {object} type Type of overlay UI element.
* @param {object} xhr (optional) XHR request used to load content. Used to abort loading. Currently used with
* type 'popup' only.
*/
function addToOverlaysStack(id, element, type, xhr) {
var index = null,
id = id.toString();
jQuery(overlays_stack).each(function(i, item) {
if (item.dialogueid === id) {
index = i;
return;
}
});
if (index === null) {
// Add new overlay.
overlays_stack.push({
dialogueid: id,
element: element,
type: type,
xhr: xhr
});
}
else {
overlays_stack[index]['element'] = element;
// Move existing overlay to the end of array.
overlays_stack.push(overlays_stack[index]);
overlays_stack.splice(index, 1);
}
// Only one instance of handler should be present at any time.
jQuery(document)
.off('keydown', closeDialogHandler)
.on('keydown', closeDialogHandler);
}
// Keydown handler. Closes last opened overlay UI element.
function closeDialogHandler(event) {
if (event.which == 27) { // ESC
var dialog = overlays_stack[overlays_stack.length - 1];
if (typeof dialog !== 'undefined') {
switch (dialog.type) {
// Close overlay popup.
case 'popup':
overlayDialogueDestroy(dialog.dialogueid, dialog.xhr);
break;
// Close overlay hintbox.
case 'hintbox':
hintBox.hideHint(dialog.element, true);
break;
// Close context menu overlays.
case 'contextmenu':
jQuery('.action-menu.action-menu-top:visible').menuPopup('close', dialog.element);
break;
// Close overlay time picker.
case 'clndr':
CLNDR.clndrhide();
break;
// Close overlay message.
case 'message':
jQuery(ZBX_MESSAGES).each(function(i, msg) {
msg.closeAllMessages();
});
break;
// Close overlay color picker.
case 'color_picker':
jQuery.colorpicker('hide');
break;
}
}
}
}
/*
* Removed overlay from overlays stack and sets focus to source element.
*
* @param {string} dialogueid Id of dialogue, that is being closed.
* @param {boolean} return_focus If not FALSE, the element stored in overlay.element will be focused.
*/
function removeFromOverlaysStack(dialogueid, return_focus) {
var overlay = null,
index;
if (return_focus !== false) {
return_focus = true;
}
jQuery(overlays_stack).each(function(i, item) {
if (item.dialogueid === dialogueid) {
overlay = item,
index = i;
return;
}
});
if (overlay) {
// Focus UI element that was clicked to open an overlay.
if (return_focus) {
jQuery(overlay.element).focus();
}
// Remove dialogue from the stack.
overlays_stack.splice(index, 1);
}
// Remove event listener.
if (overlays_stack.length == 0) {
jQuery(document).off('keydown', closeDialogHandler);
}
}
/**
* Reload content of Modal Overlay dialogue without closing it.
*
* @param {object} form Filter form in which element has been changed. Assumed that form is inside Overlay Dialogue.
* @param {string} action (optional) action value that is used in CRouter. Default value is 'popup.generic'.
*/
function reloadPopup(form, action) {
var dialogueid = jQuery(form).closest('[data-dialogueid]').attr('data-dialogueid'),
action = action || 'popup.generic',
options = {};
jQuery(form.elements).each(function() {
options[this.name] = this.value;
});
PopUp(action, options, dialogueid);
}
/**
* Pass value to add.popup trigger.
*
* @param {string} object refers to destination object
* @param {string} single_value value passed to destination object
* @param {string} parentid parent id
*/
function addValue(object, single_value, parentid) {
var value = {};
if (isset(single_value, popup_reference)) {
value = popup_reference[single_value];
}
else {
value[object] = single_value;
}
if (typeof parentid === 'undefined') {
var parentid = null;
}
var data = {
object: object,
values: [value],
parentId: parentid
};
jQuery(document).trigger('add.popup', data);
}
/**
* Adds multiple values to destination form.
*
* @param {string} frame refers to destination form
* @param {object} values values added to destination form
* @param {boolean} submit_parent indicates that after adding values, form must be submitted
*/
function addValues(frame, values, submit_parent) {
var forms = document.getElementsByTagName('FORM')[frame],
submit_parent = submit_parent || false,
frm_storage = null;
for (var key in values) {
if (values[key] === null) {
continue;
}
if (typeof forms !== 'undefined') {
frm_storage = jQuery(forms).find('#' + key).get(0);
}
if (typeof frm_storage === 'undefined' || frm_storage === null) {
frm_storage = document.getElementById(key);
}
if (jQuery(frm_storage).is('span')) {
jQuery(frm_storage).html(values[key]);
}
else {
jQuery(frm_storage).val(values[key]).change();
}
}
if (frm_storage !== null && submit_parent) {
frm_storage.form.submit();
}
}
/**
* Collects checked values and passes them to add.popup trigger.
*
* @param {string} form source form where checkbox are collected
* @param {string} object refers to object that is selected from popup
* @param {string} parentid parent id
*/
function addSelectedValues(form, object, parentid) {
form = $(form);
if (typeof parentid === 'undefined') {
var parentid = null;
}
var data = {object: object, values: [], parentId: parentid};
var chk_boxes = form.getInputs('checkbox');
for (var i = 0; i < chk_boxes.length; i++) {
if (chk_boxes[i].checked && (chk_boxes[i].name.indexOf('all_') < 0)) {
var value = {};
if (isset(chk_boxes[i].value, popup_reference)) {
value = popup_reference[chk_boxes[i].value];
}
else {
value[object] = chk_boxes[i].value;
}
data['values'].push(value);
}
}
jQuery(document).trigger('add.popup', data);
}
/**
* Add media.
*
* @param {string} formname name of destination form
* @param {integer} media media id. If -1, then assumes that this is new media
* @param {integer} mediatypeid media type id
* @param {string} sendto media sendto value
* @param {string} period media period value
* @param {string} active media active value
* @param {string} severity media severity value
*
* @returns true
*/
function add_media(formname, media, mediatypeid, sendto, period, active, severity) {
var form = window.document.forms[formname];
var media_name = (media > -1) ? 'user_medias[' + media + ']' : 'new_media';
window.create_var(form, media_name + '[mediatypeid]', mediatypeid);
if (typeof sendto === "object") {
window.removeVarsBySelector(form, 'input[name^="'+media_name+'[sendto]"]');
jQuery(sendto).each(function(i, st) {
window.create_var(form, media_name + '[sendto]['+i+']', st);
});
}
else {
window.create_var(form, media_name + '[sendto]', sendto);
}
window.create_var(form, media_name + '[period]', period);
window.create_var(form, media_name + '[active]', active);
window.create_var(form, media_name + '[severity]', severity);
form.submit();
return true;
}
/**
* Send trigger expression form data to server for validation before adding it to trigger expression field.
*
* @param {string} formname form name that is sent to server for validation
* @param {string} dialogueid (optional) id of overlay dialogue.
*/
function validate_trigger_expression(formname, dialogueid) {
var form = window.document.forms[formname],
url = new Curl(jQuery(form).attr('action')),
dialogueid = dialogueid || null;
url.setArgument('add', 1);
jQuery.ajax({
url: url.getUrl(),
data: jQuery(form).serialize(),
success: function(ret) {
jQuery(window.document.forms[formname]).parent().find('.msg-bad, .msg-good').remove();
if (typeof ret.errors !== 'undefined') {
jQuery(ret.errors).insertBefore(jQuery(window.document.forms[formname]));
}
else {
var form = window.document.forms[ret.dstfrm];
var obj = (typeof form !== 'undefined')
? jQuery(form).find('#' + ret.dstfld1).get(0)
: document.getElementById(ret.dstfld1);
if (ret.dstfld1 === 'expression' || ret.dstfld1 === 'recovery_expression') {
jQuery(obj).val(jQuery(obj).val() + ret.expression);
}
else {
jQuery(obj).val(ret.expression);
}
if (dialogueid) {
overlayDialogueDestroy(dialogueid);
}
}
},
dataType: 'json',
type: 'post'
});
}
function redirect(uri, method, needle, invert_needle, add_sid) {
if (typeof add_sid === 'undefined') {
add_sid = true;
}
method = method || 'get';
var url = new Curl(uri, add_sid);
if (method.toLowerCase() == 'get') {
window.location = url.getUrl();
}
else {
// useless param just for easier loop
var action = '';
var domBody = document.getElementsByTagName('body')[0];
var postForm = document.createElement('form');
domBody.appendChild(postForm);
postForm.setAttribute('method', 'post');
invert_needle = (typeof(invert_needle) != 'undefined' && invert_needle);
var args = url.getArguments();
for (var key in args) {
if (empty(args[key])) {
continue;
}
var is_needle = (typeof(needle) != 'undefined' && key.indexOf(needle) > -1);
if ((is_needle && !invert_needle) || (!is_needle && invert_needle)) {
action += '&' + key + '=' + args[key];
continue;
}
var hInput = document.createElement('input');
hInput.setAttribute('type', 'hidden');
postForm.appendChild(hInput);
hInput.setAttribute('name', key);
hInput.setAttribute('value', args[key]);
}
postForm.setAttribute('action', url.getPath() + '?' + action.substr(1));
postForm.submit();
}
return false;
}
function showHide(obj) {
if (jQuery(obj).is(':hidden')) {
jQuery(obj).css('display', 'block');
}
else {
jQuery(obj).css('display', 'none');
}
}
function showHideVisible(obj) {
if (is_string(obj)) {
obj = document.getElementById(obj);
}
if (!obj) {
throw 'showHideVisible(): Object not found.';
}
if (obj.style.visibility != 'hidden') {
obj.style.visibility = 'hidden';
}
else {
obj.style.visibility = 'visible';
}
}
function showHideByName(name, style) {
if (typeof(style) == 'undefined') {
style = 'none';
}
var objs = $$('[name=' + name + ']');
if (empty(objs)) {
throw 'showHideByName(): Object not found.';
}
for (var i = 0; i < objs.length; i++) {
var obj = objs[i];
obj.style.display = style;
}
}
/**
* Switch element classes and return final class.
*
* @param object|string obj object or object id
* @param string class1
* @param string class2
*
* @return string
*/
function switchElementClass(obj, class1, class2) {
obj = (typeof obj === 'string') ? jQuery('#' + obj) : jQuery(obj);
if (obj.length > 0) {
if (obj.hasClass(class1)) {
obj.removeClass(class1);
obj.addClass(class2);
return class2;
}
else if (obj.hasClass(class2)) {
obj.removeClass(class2);
obj.addClass(class1);
return class1;
}
}
return null;
}
/**
* Returns the file name of the given path.
*
* @param string path
* @param string suffix
*
* @return string
*/
function basename(path, suffix) {
var name = path.replace(/^.*[\/\\]/g, '');
if (typeof suffix === 'string' && name.substr(name.length - suffix.length) == suffix) {
name = name.substr(0, name.length - suffix.length);
}
return name;
}
/**
* Transform datetime parts to two digits e.g., 2 becomes 02.
*
* @param int val
*
* @return string
*/
function appendZero(val) {
return val < 10 ? '0' + val : val;
}
/**
* Trims selected element values.
*
* @param array selectors
*/
jQuery.fn.trimValues = function(selectors) {
var form = this,
obj;
jQuery.each(selectors, function(i, value) {
obj = jQuery(value, form);
jQuery(obj).each(function() {
jQuery(this).val(jQuery.trim(jQuery(this).val()));
});
});
};
/**
* Inserts hidden input into a form
*
* @param string form_name
* @param string input_name
* @param string input_value
*/
function submitFormWithParam(form_name, input_name, input_value) {
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', input_name);
input.setAttribute('value', input_value);
document.forms[form_name].appendChild(input);
jQuery(document.forms[form_name]).trigger('submit');
}
|