forked from glpi-project/glpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
858 lines (720 loc) · 20.6 KB
/
script.js
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
/**
* This array is used to remember mark status of rows in browse mode
*/
var marked_row = new Array;
var timeoutglobalvar;
/**
* modifier la propriete display d'un element
*
* @param objet
* @param statut
**/
function setdisplay(objet, statut) {
var e = objet;
if (e.style.display != statut) {
e.style.display = statut;
}
return true;
}
/**
* tester le type de navigateur
**/
function isIe() {
var ie = false;
var appVer = navigator.appVersion.toLowerCase();
var iePos = appVer.indexOf('msie');
if (iePos != -1) {
var is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
var is_major = parseInt(is_minor);
}
if (navigator.appName.substring(0,9) == "Microsoft") {
// Check if IE version is 6 or older
if (is_major <= 6) {
ie = true;
}
}
return ie;
}
/**
* @param id
**/
function cleandisplay(id) {
var e = document.getElementById(id);
if (e) {
setdisplay(e,'block');
if (isIe()) {
doHideSelect(e);
}
}
}
/**
* @param id
**/
function cleanhide(id) {
var e = document.getElementById(id);
if (e) {
if (isIe()) {
doShowSelect(e);
}
setdisplay(e,'none');
}
}
/**
* @param id
**/
function completecleandisplay(id) {
var e = document.getElementById(id);
if (e) {
setdisplay(e,'block');
/* if(document.getElementById('show_entities')){
var oneTime=0;
var divHeight = document.getElementById('show_entities').offsetHeight;
var divWidth = document.getElementById('show_entities').offsetWidth;
if (divHeight>300){
document.getElementById('show_entities').style.overflow = 'auto';
document.getElementById('show_entities').style.height = '400px';
// document.getElementById('show_entities').style.width = divWidth + 'px';
document.getElementById('show_entities').style.width = '300px';
}
}
*/
if (isIe()) {
e.onmouseleave = function(){ completecleanhide(id) };
hideSelect(0,0,document.documentElement.clientWidth,document.documentElement.clientHeight);
} else {
e.onmouseout = function(){ completecleanhide(id) };
}
}
}
/**
* @param id
**/
function completecleanhide(id) {
var e = document.getElementById(id);
if (e) {
setdisplay(e,'none');
if (isIe()) {
showSelect(0,0,document.documentElement.clientWidth,document.documentElement.clientHeight);
}
}
}
/**
* effacer tous les menus du menu principal
* afficher les select du document
*
* @param idMenu
**/
function hidemenu(idMenu) {
var e = document.getElementById(idMenu);
var e = e.getElementsByTagName('ul');
for (var i=0 ; i<e.length ; i++) {
if (e[i]) {
if (isIe()) {
doShowSelect(e[i]);
}
setdisplay(e[i],'none');
}
}
}
/**
* masquer le menu actif par timeout
*
* @param idMenu
**/
function afterView(idMenu) {
setdisplay(idMenu,'none');
if (isIe()) {
doShowSelect(idMenu);
}
}
/**
* execute la fonction showSelect
*
* @param objet
**/
function doShowSelect(objet) {
if (objet) {
//correction du bugg sur IE
if (isIe()) {
if (setdisplay(objet,'block')) {
var selx = 0;
var sely = 0;
var selp;
selx = getLeft(objet);
sely = getTop(objet);
selw = objet.offsetWidth;
selh = objet.offsetHeight;
showSelect(selx,sely,selw,selh);
}
if (setdisplay(objet,'none')){
return true;
}
}
}
}
/**
* affiche les select du document
*
* @param x
* @param y
* @param w
* @param h
**/
function showSelect(x,y,w,h) {
var selx,sely,selw,selh;
var sel = document.getElementsByTagName("SELECT");
for (var i=0 ; i<sel.length ; i++) {
selx = 0;
sely = 0;
var selp;
selx = getLeft(sel[i]);
sely = getTop(sel[i]);
selw = sel[i].offsetWidth;
selh = sel[i].offsetHeight;
// || Manage position error computation
if ((((selx + selw) > x)
&& (selx < (x + w))
&& ((sely + selh) > y)
&& (sely < (y + h)))
|| (selx < 0)
|| (sely < 0)) {
sel[i].style.visibility="visible";
}
}
return true;
}
/**
* execute la fonction hideMenu
*
* @param objet
**/
function doHideSelect(object) {
var e = object;
if (isIe()) {
var selx = 0;
var sely = 0;
var selp;
selx = getLeft(e);
sely = getTop(e);
selw = e.offsetWidth;
selh = e.offsetHeight;
hideSelect(selx,sely,selw,selh);
}
return true;
}
/**
* masque les select du document
*
* @param x
* @param y
* @param w
* @param h
**/
function hideSelect(x,y,w,h) {
var selx,sely,selw,selh,i;
var sel = document.getElementsByTagName("SELECT");
for (i=0 ; i<sel.length ; i++) {
selx = 0;
sely = 0;
var selp;
selx = getLeft(sel[i]);
sely = getTop(sel[i]);
selw = sel[i].offsetWidth;
selh = sel[i].offsetHeight;
// || Manage position error computation
if ((((selx + selw) > x)
&& (selx < (x + w))
&& ((sely + selh) > y)
&& (sely < (y + h)))
|| (selx < 0)
|| (sely < 0 )) {
sel[i].style.visibility="hidden";
}
}
return true;
}
/**
* @param id
* @param idMenu
**/
function menuAff(id,idMenu){
var m = document.getElementById(idMenu);
var item = m.getElementsByTagName('li');
for (var i=0 ; i<item.length ; i++) {
if (item[i].id == id) {
var ssmenu = item[i];
}
}
var m = m.getElementsByTagName('ul');
if (isIe()) {
//masquage des elements select du document
if (m) {
for (var i=1 ; i<10 ; i++) { //probleme dans le listage et le nomage des menus xhtml
//listage des elements li nommes du type smenu + i
var e = document.getElementById('menu'+i);
if (e) {
var smenu = e.getElementsByTagName('ul');
doShowSelect(smenu[0]);
}
}
}
}
if (ssmenu) {
var smenu = ssmenu.getElementsByTagName('ul');
if (smenu) {
//masquer tous les menus ouverts
for (var i=0 ; i<m.length ; i++) {
setdisplay(m[i],'none');
}
setdisplay(smenu[0],'block');
clearTimeout(timeoutglobalvar);
//timeoutglobalvar = setTimeout(function(){afterView(smenu[0])},1000);
if (isIe()) {
ssmenu.onmouseleave = function(){ timeoutglobalvar = setTimeout(function(){afterView(smenu[0])},300); };
doHideSelect(smenu[0]);
} else {
ssmenu.onmouseout = function(){ timeoutglobalvar = setTimeout(function(){afterView(smenu[0])},300); };
}
}
}
}
/**
* @param URL_List
**/
function jumpTo(URL_List) {
var URL = URL_List.options[URL_List.selectedIndex].value; window.location.href = URL;
}
browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if (((browserName == "Netscape") && (browserVer >= 3))
|| ((browserName == "Microsoft Internet Explorer") && (browserVer >= 4))){
version = "n3";
} else {
version = "n2";
}
function historyback() {
history.back();
}
function historyforward() {
history.forward();
}
/**
* @param Type
* @param Id
**/
function fillidfield(Type,Id) {
window.opener.document.forms["helpdeskform"].elements["items_id"].value = Id;
window.opener.document.forms["helpdeskform"].elements["itemtype"].value = Type;
window.close();
}
/**
* marks all checkboxes inside the given element
* the given element is usaly a table or a div containing the table or tables
*
* @param container_id DOM element
**/
function markCheckboxes(container_id) {
var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
for (var j=0 ; j<checkboxes.length ; j++ ) {
checkbox = checkboxes[j];
if (checkbox && (checkbox.type == 'checkbox')) {
if (checkbox.disabled == false ) {
checkbox.checked = true;
}
}
}
return true;
}
/**
* marks all checkboxes inside the given element
* the given element is usaly a table or a div containing the table or tables
*
* @param container_id DOM element
**/
function unMarkCheckboxes(container_id) {
var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
for (var j=0 ; j<checkboxes.length ; j++ ) {
checkbox = checkboxes[j];
if (checkbox && (checkbox.type == 'checkbox')) {
checkbox.checked = false;
}
}
return true;
}
/**
* toggle all checkboxes inside the given element
* the given element is usaly a table or a div containing the table or tables
*
* @param container_id DOM element
**/
function toggleCheckboxes( container_id ) {
var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
for (var j=0 ; j<checkboxes.length ; j++ ) {
checkbox = checkboxes[j];
if (checkbox && (checkbox.type == 'checkbox')) {
if (checkbox.disabled == false) {
if (checkbox.checked == false) {
checkbox.checked = true;
} else {
checkbox.checked = false;
}
}
}
}
return true;
}
/**
* display "other" text input field in case of selecting "other" option
*
* @since version 0.84
*
* @param select_object DOM select object
* @param other_option_name the name of both the option and the text input field
**/
function displayOtherSelectOptions(select_object, other_option_name) {
var SelIndex = select_object.selectedIndex;
if (select_object.options[select_object.selectedIndex].value == other_option_name) {
document.getElementById(other_option_name).style.display = "inline";
} else {
document.getElementById(other_option_name).style.display = "none";
}
return true;
}
/**
* Check all checkboxes inside the given element as the same state as a reference one (toggle this one before)
* the given element is usaly a table or a div containing the table or tables
*
* @param reference_id DOM element
* @param container_id DOM element
**/
function checkAsCheckboxes( reference_id, container_id ) {
var ref = document.getElementById(reference_id);
var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
for (var j=0 ; j<checkboxes.length ; j++ ) {
checkbox = checkboxes[j];
if (checkbox && (checkbox.type == 'checkbox')) {
if (checkbox.disabled == false) {
checkbox.checked = ref.checked;
}
}
}
return true;
}
/**
* @param text
* @param where
**/
function confirmAction(text, where){
if (confirm(text)) {
window.location = where;
}
}
/**
* Fonction permettant de connaître la position d'un objet par rapport au bord gauche de la page.
* Cet objet peut être à l'intérieur d'un autre objet.
*
* @param MyObject
*
* @returns la distance par rapport au bord gauche de la page
**/
function getLeft(MyObject){
if (MyObject.offsetParent) {
return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
}
return (MyObject.offsetLeft);
}
/**
* Fonction permettant de connaître la position d'un objet par rapport au bord haut de la page.
* Cet objet peut être à l'intérieur d'un autre objet.
*
* @param MyObject
*
* @returns la distance par rapport au bord haut de la page
**/
function getTop(MyObject){
if (MyObject.offsetParent) {
return (MyObject.offsetTop + getTop(MyObject.offsetParent));
}
return (MyObject.offsetTop);
}
/**
* safe function to hide an element with a specified id
*
* @param id id of the dive
* @param img_name name attribut of the img item
* @param img_src_close url of the close img
* @param img_src_open url of the open img
**/
function showHideDiv(id, img_name, img_src_close, img_src_open) {
if (document.getElementById) { // DOM3 = IE5, NS6
if (document.getElementById(id).style.display == 'none') {
document.getElementById(id).style.display = 'block';
if (img_name!='') {
document[img_name].src=img_src_open;
}
} else {
document.getElementById(id).style.display = 'none';
if (img_name!='') {
document[img_name].src=img_src_close;
}
}
} else {
if (document.layers) { // Netscape 4
if (document.id.display == 'none') {
document.id.display = 'block';
if (img_name != '') {
document[img_name].src=img_src_open;
}
} else {
document.id.display = 'none';
if (img_name != ''){
document[img_name].src=img_src_close;
}
}
} else { // IE 4
if (document.all.id.style.display == 'none') {
document.all.id.style.display = 'block';
if (img_name != '') {
document[img_name].src=img_src_close;
}
} else {
document.all.id.style.display = 'none';
if (img_name != '') {
document[img_name].src=img_src_close;
}
}
}
}
}
/**
* safe function to hide an element with a specified id
*
* @param id
* @param img_name
* @param img_src_yes
* @param img_src_no
**/
function toogle(id, img_name, img_src_yes, img_src_no) {
if (document.getElementById) { // DOM3 = IE5, NS6
if (document.getElementById(id).value == '0') {
document.getElementById(id).value = '1';
if (img_name != '') {
document[img_name].src=img_src_yes;
}
} else {
document.getElementById(id).value = '0';
if (img_name != '') {
document[img_name].src=img_src_no;
}
}
}
}
/**
* @since version 0.84
*
* @param tbl
* @param img_name
* @param img_src_close
* @param img_src_open
*/
function toggleTableDisplay(tbl,img_name,img_src_close,img_src_open) {
var tblRows = document.getElementById(tbl).rows;
for (i=0 ; i < tblRows.length ; i++) {
if (tblRows[i].className.indexOf("headerRow") == -1) {
if (tblRows[i].style.display == 'none') {
tblRows[i].style.display = "table-row";
if (img_name != ''){
document[img_name].src = img_src_open;
}
} else {
tblRows[i].style.display = "none";
if (img_name != ''){
document[img_name].src = img_src_close;
}
}
}
}
if (document.getElementById(tbl+'2')) {
toggleTableDisplay(tbl+'2','');
}
if (document.getElementById(tbl+'3')) {
toggleTableDisplay(tbl+'3','');
}
if (document.getElementById(tbl+'4')) {
toggleTableDisplay(tbl+'4','');
}
if (document.getElementById(tbl+'5')) {
toggleTableDisplay(tbl+'5','');
}
}
/**
* @since version 0.84
*
* @param target
* @param fields
**/
function submitGetLink(target,fields) {
var myForm = document.createElement("form");
myForm.method = "post" ;
myForm.action = target ;
for (var name in fields) {
var myInput = document.createElement("input") ;
myInput.setAttribute("name", name) ;
myInput.setAttribute("value", fields[name]);
myForm.appendChild(myInput) ;
}
document.body.appendChild(myForm) ;
myForm.submit() ;
document.body.removeChild(myForm) ;
}
/**
* @since version 0.85
*
* @param id
**/
function selectAll(id) {
var element =$('#'+id);var selected = [];
element.find('option').each(function(i,e){
selected[selected.length]=$(e).attr('value');
});
element.select2('val', selected);
}
/**
* @since version 0.85
*
* @param id
**/
function deselectAll(id) {
$('#'+id).val('').trigger('change');
}
/**
* Set all the checkbox that refere to the criterion
*
* @since version 0.85
*
* @param criterion jquery criterion
* @param reference the new reference object, boolean, id ... (default toggle)
*
**/
function massiveUpdateCheckbox(criterion, reference) {
if (typeof(reference) == 'undefined') {
var value = null;
} else if (typeof(reference) == 'boolean') {
var value = reference;
} else if (typeof(reference) == 'string') {
var value = $('#' + reference).prop('checked');
} else if (typeof(reference) == 'object') {
var value = $(reference).prop('checked');
}
if (typeof(value) == 'undefined') {
return false;
}
$(criterion).each(function() {
if (typeof(reference) == 'undefined') {
value = !$(this).prop('checked');
}
$(this).prop('checked', value);
});
return true;
}
$(function(){
$("body").delegate('td','mouseover mouseleave', function(e) {
var col = $(this).closest('tr').children().index($(this));
var tr = $(this).closest('tr');
if (!$(this).closest('tr').hasClass('noHover')) {
if (e.type == 'mouseover') {
tr.addClass("rowHover");
// If rowspan
if (tr.has('td[rowspan]').length == 0) {
tr.prevAll('tr:has(td[rowspan]):first').find('td[rowspan]').addClass("rowHover");
}
$(this).closest('table').find('tr:not(.noHover) th:nth-child('+(col+1)+')').addClass("headHover");
} else {
tr.removeClass("rowHover");
// remove rowspan
tr.removeClass("rowHover").prevAll('tr:has(td[rowspan]):first').find('td[rowspan]').removeClass("rowHover");
$(this).closest('table').find('tr:not(.noHover) th:nth-child('+(col+1)+')').removeClass("headHover");
}
}
});
});
//Hack for Jquery Ui Date picker
var _gotoToday = jQuery.datepicker._gotoToday;
jQuery.datepicker._gotoToday = function(a){
var target = jQuery(a);
var inst = this._getInst(target[0]);
_gotoToday.call(this, a);
jQuery.datepicker._selectDate(a, jQuery.datepicker._formatDate(inst,inst.selectedDay, inst.selectedMonth, inst.selectedYear));
};
/* TImeline for itiobjects */
filter_timeline = function() {
$(document).on("click", '.filter_timeline li a', function(event) {
//hide all elements in timeline
$('.h_item').addClass('h_hidden');
//reset all elements
if ($(this).hasClass('reset')) {
$('.filter_timeline li a img').each(function(el2) {
$(this).attr('src', $(this).attr('src').replace('_active', ''));
})
$('.h_item').removeClass('h_hidden');
return;
}
//activate clicked element
var current_el = $(this).children('img');
$(this).toggleClass('h_active');
if (current_el.attr('src').indexOf('active') > 0) {
current_el.attr('src', current_el.attr('src').replace('_active', ''));
} else {
current_el.attr('src', current_el.attr('src').replace(/\.(png)$/, '_active.$1'));
}
//find active classname
active_classnames = [];
$('.filter_timeline .h_active').each(function(index) {
active_classnames.push(".h_content."+$(this).attr('class').replace(' h_active', ''));
})
$(active_classnames.join(', ')).each(function(index){
$(this).parent().removeClass('h_hidden');
})
//show all items when no active filter
if (active_classnames.length == 0) {
$('.h_item').removeClass('h_hidden');
}
});
}
read_more = function() {
$(document).on("click", ".long_text .read_more a", function(event) {
$(this).parents('.long_text').removeClass('long_text');
$(this).parent('.read_more').remove();
return false;
});
}
split_button = function() {
var splitBtn = $('#x-split-button');
// unfold status list
$(document).on("click", '.x-button-drop', function(event) {
splitBtn.toggleClass('open');
});
$(document).on("click", '.x-split-button', function(event) {
event.stopPropagation();
});
//click on an element of status list
$(document).on("click", '.x-button-drop-menu li', function(event) {
if (event.target.children.length) {
//clean old status class
$('.x-button-drop').attr('class','x-button x-button-drop');
//find status
match = event.target.children[0].src.match(/.*\/(.*)\.png/);
cstatus = match[1];
//add status to dropdown button
$('.x-button-drop').addClass(cstatus);
//fold status list
splitBtn.removeClass('open');
}
});
//fold status list on click on document
$(document).on("click", function(event) {
if (splitBtn.hasClass('open')) {
splitBtn.removeClass('open');
}
});
}