-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
lib_head.js.php
1155 lines (1048 loc) · 35.7 KB
/
lib_head.js.php
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
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* Copyright (C) 2005-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/js/lib_head.js.php
* \brief File that include javascript functions (included if option use_javascript activated)
*/
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1);
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1);
if (! defined('NOLOGIN')) define('NOLOGIN',1);
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1);
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
session_cache_limiter(FALSE);
require_once '../../main.inc.php';
// Define javascript type
top_httphead('text/javascript; charset=UTF-8');
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate');
else header('Cache-Control: no-cache');
?>
/*
* =================================================================
* Purpose:
* Pour la saisie des dates par calendrier Input: base "/theme/eldy" dateFieldID
* "dateo" Nom du champ format "dd/MM/yyyy" Format issu de Dolibarr de
* SimpleDateFormat a utiliser pour retour
* ==================================================================
*/
function showDP(base,dateFieldID,format,codelang)
{
// check to see if another box is already showing
var alreadybox=getObjectFromID("DPCancel");
if (alreadybox) closeDPBox(); // This erase value of showDP.datefieldID
// alert("showDP "+codelang);
showDP.datefieldID=dateFieldID; // Must be after the close
var dateField=getObjectFromID(dateFieldID);
// get positioning
var thetop=getTop(dateField)+dateField.offsetHeight;
// var xxx=getObjectFromID('bottompage');
// alert(xxx.style.pixelTop);
// alert(document.body.clientHeight);
// alert(document.body.style.offsetTop);
// alert(thetop);
// alert(window.innerHeight);
if (thetop+160 > window.innerHeight)
thetop=thetop-160-20;
var theleft=getLeft(dateField);
if (theleft+140 > window.innerWidth)
theleft= theleft-140+dateField.offsetWidth-15;
showDP.box=document.createElement("div");
showDP.box.className="bodyline";
showDP.box.style.display="block";
showDP.box.style.zIndex="1000";
showDP.box.style.position="absolute";
showDP.box.style.top=thetop + "px";
showDP.box.style.left=theleft + "px";
if (dateField.value) // Si il y avait valeur initiale dans champ
{
selDate=getDateFromFormat(dateField.value,format);
if (selDate)
{
// Success to parse value in field according to format
year=selDate.getFullYear();
month=selDate.getMonth()+1;
day=selDate.getDate();
datetime=selDate.getTime();
ymd=formatDate(selDate,'yyyyMMdd');
}
else
{
// Failed to parse value in field according to format
selDate=new Date();
year=selDate.getFullYear();
month=selDate.getUTCMonth()+1;
day=selDate.getDate();
datetime=selDate.getTime();
ymd=formatDate(selDate,'yyyyMMdd');
}
}
else
{
selDate=new Date();
year=selDate.getFullYear();
month=selDate.getUTCMonth()+1;
day=selDate.getDate();
datetime=selDate.getTime();
ymd=formatDate(selDate,'yyyyMMdd');
}
loadMonth(base,month,year,ymd,codelang);
hideSelectBoxes();
document.body.appendChild(showDP.box);
}
function resetDP(base,dateFieldID,format,codelang)
{
var dateField=getObjectFromID(dateFieldID);
dateField.value = formatDate(new Date(), format);
dpChangeDay(dateFieldID,format);
var alreadybox=getObjectFromID("DPCancel");
if (alreadybox) showDP(base,dateFieldID,format,codelang);
}
function loadMonth(base,month,year,ymd,codelang)
{
/* showDP.box.innerHTML="Loading..."; */
// alert(codelang);
var theURL=base+"datepicker.php?cm=shw&lang="+codelang;
theURL+="&m="+encodeURIComponent(month);
theURL+="&y="+encodeURIComponent(year);
if (selDate)
{
theURL+="&sd="+ymd;
}
var req=null;
req=loadXMLDoc(theURL,null,false);
if (req.responseText == '') alert('Failed to get URL '.theURL);
// alert(theURL+' - '+req.responseText); // L'url doit avoir la meme racine
// que la pages et elements sinon pb de securite.
showDP.box.innerHTML=req.responseText;
}
function closeDPBox()
{
document.body.removeChild(showDP.box);
displaySelectBoxes();
showDP.box=null;
showDP.datefieldID=null;
}
function dpChangeDay(dateFieldID,format)
{
showDP.datefieldID=dateFieldID;
var thefield=getObjectFromID(showDP.datefieldID);
var thefieldday=getObjectFromID(showDP.datefieldID+"day");
var thefieldmonth=getObjectFromID(showDP.datefieldID+"month");
var thefieldyear=getObjectFromID(showDP.datefieldID+"year");
var date=getDateFromFormat(thefield.value,format);
if (date)
{
thefieldday.value=date.getDate();
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
thefieldmonth.value=date.getMonth()+1;
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
thefieldyear.value=date.getFullYear();
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
}
else
{
thefieldday.value='';
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
thefieldmonth.value='';
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
thefieldyear.value='';
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
}
}
function dpClickDay(year,month,day,format)
{
var thefield=getObjectFromID(showDP.datefieldID);
var thefieldday=getObjectFromID(showDP.datefieldID+"day");
var thefieldmonth=getObjectFromID(showDP.datefieldID+"month");
var thefieldyear=getObjectFromID(showDP.datefieldID+"year");
var dt = new Date(year, month-1, day);
thefield.value=formatDate(dt,format);
if(thefield.onchange) thefield.onchange.call(thefield);
thefieldday.value=day;
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
thefieldmonth.value=month;
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
thefieldyear.value=year;
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
closeDPBox();
}
function dpHighlightDay(year,month,day,months){
var displayinfo=getObjectFromID("dpExp");
displayinfo.innerHTML=months[month-1]+" "+day+", "+year;
}
// Returns an object given an id
function getObjectFromID(id){
var theObject;
if(document.getElementById)
theObject=document.getElementById(id);
else
theObject=document.all[id];
return theObject;
}
// This Function returns the top position of an object
function getTop(theitem){
var offsetTrail = theitem;
var offsetTop = 0;
while (offsetTrail) {
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined")
offsetTop += document.body.TopMargin;
return offsetTop;
}
// This Function returns the left position of an object
function getLeft(theitem){
var offsetTrail = theitem;
var offsetLeft = 0;
while (offsetTrail) {
offsetLeft += offsetTrail.offsetLeft;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined")
offsetLeft += document.body.leftMargin;
return offsetLeft;
}
// Create XMLHttpRequest object and load url
// Used by calendar or other ajax processes
// Return req built or false if error
function loadXMLDoc(url,readyStateFunction,async)
{
// req must be defined by caller with
// var req = false;
// branch for native XMLHttpRequest object (Mozilla, Safari...)
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
// if (req.overrideMimeType) {
// req.overrideMimeType('text/xml');
// }
}
// branch for IE/Windows ActiveX version
else if (window.ActiveXObject)
{
try
{
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
// If XMLHttpRequestObject req is ok, call URL
if (! req)
{
alert('Cannot create XMLHTTP instance');
return false;
}
if (readyStateFunction) req.onreadystatechange = readyStateFunction;
// Exemple of function for readyStateFuncyion:
// function ()
// {
// if ( (req.readyState == 4) && (req.status == 200) ) {
// if (req.responseText == 1) { newStatus = 'AAA'; }
// if (req.responseText == 0) { newStatus = 'BBB'; }
// if (currentStatus != newStatus) {
// if (newStatus == "AAA") { obj.innerHTML = 'AAA'; }
// else { obj.innerHTML = 'BBB'; }
// currentStatus = newStatus;
// }
// }
// }
req.open("GET", url, async);
req.send(null);
return req;
}
/* To hide/show select Boxes with IE6 (and only IE6 because IE6 has a bug and
* not put popup completely on the front)
* Used only bu popup calendar
*/
function hideSelectBoxes() {
var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE 6") > -1)
{
for(var i = 0; i < document.all.length; i++)
{
if(document.all[i].tagName)
if(document.all[i].tagName == "SELECT")
document.all[i].style.visibility="hidden";
}
}
}
/* To hide/show select Boxes with IE6 (and only IE6 because IE6 has a bug and
* not put popup completely on the front)
* Used only bu popup calendar
*/
function displaySelectBoxes() {
var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE 6") > -1)
{
for(var i = 0; i < document.all.length; i++)
{
if(document.all[i].tagName)
if(document.all[i].tagName == "SELECT")
document.all[i].style.visibility="visible";
}
}
}
/*
* =================================================================
* Function:
* formatDate (javascript object Date(), format) Purpose: Returns a date in the
* output format specified. The format string can use the following tags: Field |
* Tags -------------+------------------------------- Year | yyyy (4 digits), yy
* (2 digits) Month | MM (2 digits) Day of Month | dd (2 digits) Hour (1-12) |
* hh (2 digits) Hour (0-23) | HH (2 digits) Minute | mm (2 digits) Second | ss
* (2 digits) Author: Laurent Destailleur Author: Matelli (see
* http://matelli.fr/showcases/patchs-dolibarr/update-date-input-in-action-form.html)
* Licence: GPL
* ==================================================================
*/
function formatDate(date,format)
{
// alert('formatDate date='+date+' format='+format);
// Force parametres en chaine
format=format+"";
var result="";
var year=date.getYear()+""; if (year.length < 4) { year=""+(year-0+1900); }
var month=date.getMonth()+1;
var day=date.getDate();
var hour=date.getHours();
var minute=date.getMinutes();
var seconde=date.getSeconds();
var i=0;
while (i < format.length)
{
c=format.charAt(i); // Recupere char du format
substr="";
j=i;
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char successif identiques
{
substr += format.charAt(j++);
}
// alert('substr='+substr);
if (substr == 'yyyy') { result=result+year; }
else if (substr == 'yy') { result=result+year.substring(2,4); }
else if (substr == 'M') { result=result+month; }
else if (substr == 'MM') { result=result+(month<1||month>9?"":"0")+month; }
else if (substr == 'd') { result=result+day; }
else if (substr == 'dd') { result=result+(day<1||day>9?"":"0")+day; }
else if (substr == 'hh') { if (hour > 12) hour-=12; result=result+(hour<0||hour>9?"":"0")+hour; }
else if (substr == 'HH') { result=result+(hour<0||hour>9?"":"0")+hour; }
else if (substr == 'mm') { result=result+(minute<0||minute>9?"":"0")+minute; }
else if (substr == 'ss') { result=result+(seconde<0||seconde>9?"":"0")+seconde; }
else { result=result+substr; }
i+=substr.length;
}
// alert(result);
return result;
}
/*
* =================================================================
* Function:
* getDateFromFormat(date_string, format_string) Purpose: This function takes a
* date string and a format string. It parses the date string with format and it
* returns the date as a javascript Date() object. If date does not match
* format, it returns 0. The format string can use the following tags:
* Field | Tags
* -------------+-----------------------------------
* Year | yyyy (4 digits), yy (2 digits)
* Month | MM (2 digits)
* Day of Month | dd (2 digits)
* Hour (1-12) | hh (2 digits)
* Hour (0-23) | HH (2 digits)
* Minute | mm (2 digits)
* Second | ss (2 digits)
* Author: Laurent Destailleur
* Licence: GPL
* ==================================================================
*/
function getDateFromFormat(val,format)
{
// alert('getDateFromFormat val='+val+' format='+format);
// Force parametres en chaine
val=val+"";
format=format+"";
if (val == '') return 0;
var now=new Date();
var year=now.getYear(); if (year.length < 4) { year=""+(year-0+1900); }
var month=now.getMonth()+1;
var day=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var seconde=now.getSeconds();
var i=0;
var d=0; // -d- follows the date string while -i- follows the format
// string
while (i < format.length)
{
c=format.charAt(i); // Recupere char du format
substr="";
j=i;
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char
// successif
// identiques
{
substr += format.charAt(j++);
}
// alert('substr='+substr);
if (substr == "yyyy") year=getIntegerInString(val,d,4,4);
if (substr == "yy") year=""+(getIntegerInString(val,d,2,2)-0+1900);
if (substr == "MM" ||substr == "M")
{
month=getIntegerInString(val,d,1,2);
d -= 2- month.length;
}
if (substr == "dd")
{
day=getIntegerInString(val,d,1,2);
d -= 2- day.length;
}
if (substr == "HH" ||substr == "hh" )
{
hour=getIntegerInString(val,d,1,2);
d -= 2- hour.length;
}
if (substr == "mm"){
minute=getIntegerInString(val,d,1,2);
d -= 2- minute.length;
}
if (substr == "ss")
{
seconde=getIntegerInString(val,d,1,2);
d -= 2- seconde.length;
}
i+=substr.length;
d+=substr.length;
}
// Check if format param are ok
if (year==null||year<1) { return 0; }
if (month==null||(month<1)||(month>12)) { return 0; }
if (day==null||(day<1)||(day>31)) { return 0; }
if (hour==null||(hour<0)||(hour>24)) { return 0; }
if (minute==null||(minute<0)||(minute>60)) { return 0; }
if (seconde==null||(seconde<0)||(seconde>60)) { return 0; }
// alert(year+' '+month+' '+day+' '+hour+' '+minute+' '+seconde);
return new Date(year,month-1,day,hour,minute,seconde);
}
/*
* =================================================================
* Function:
* stringIsInteger(string)
* Purpose: Return true if string is an integer
* ==================================================================
*/
function stringIsInteger(str)
{
var digits="1234567890";
for (var i=0; i < str.length; i++)
{
if (digits.indexOf(str.charAt(i))==-1)
{
return false;
}
}
return true;
}
/*
* =================================================================
* Function:
* getIntegerInString(string,pos,minlength,maxlength)
* Purpose: Return part of string from position i that is integer
* ==================================================================
*/
function getIntegerInString(str,i,minlength,maxlength)
{
for (var x=maxlength; x>=minlength; x--)
{
var substr=str.substring(i,i+x);
if (substr.length < minlength) { return null; }
if (stringIsInteger(substr)) { return substr; }
}
return null;
}
/*
* =================================================================
* Purpose:
* Clean string to have it url encoded
* Input: s
* Author: Laurent Destailleur
* Licence: GPL
* ==================================================================
*/
function urlencode(s) {
news=s;
news=news.replace(/\+/gi,'%2B');
news=news.replace(/&/gi,'%26');
return news;
}
/*
* =================================================================
* Purpose:
* Applique un delai avant execution. Used for autocompletion of companies.
* Input: funct, delay
* Author: Regis Houssin
* Licence: GPL
* ==================================================================
*/
function ac_delay(funct,delay) {
// delay before start of action
setTimeout(funct,delay);
}
/*
* =================================================================
* Purpose:
* Clean values of a "Sortable.serialize". Used by drag and drop.
* Input: expr
* Author: Regis Houssin
* Licence: GPL
* ==================================================================
*/
function cleanSerialize(expr) {
if (typeof(expr) != 'string') return '';
var reg = new RegExp("(&)", "g");
var reg2 = new RegExp("[^A-Z0-9,]", "g");
var liste1 = expr.replace(reg, ",");
return liste1.replace(reg2, "");
}
/*
* =================================================================
* Purpose: Display a temporary message in input text fields (For showing help message on
* input field).
* Input: fieldId
* Input: message
* Author: Regis Houssin
* Licence: GPL
* ==================================================================
*/
function displayMessage(fieldId,message) {
var textbox = document.getElementById(fieldId);
if (textbox.value == '') {
textbox.style.color = 'grey';
textbox.value = message;
}
}
/*
* =================================================================
* Purpose: Hide a temporary message in input text fields (For showing help message on
* input field).
* Input: fiedId
* Input: message
* Author: Regis Houssin
* Licence: GPL
* ==================================================================
*/
function hideMessage(fieldId,message) {
var textbox = document.getElementById(fieldId);
textbox.style.color = 'black';
if (textbox.value == message) textbox.value = '';
}
/*
* Used by button to set on/off
*
* @param string url Url
* @param string code Code
* @param string intput Input
* @param int entity Entity
* @param int strict Strict
*/
function setConstant(url, code, input, entity, strict) {
$.get( url, {
action: "set",
name: code,
entity: entity
},
function() {
$("#set_" + code).hide();
$("#del_" + code).show();
$.each(input, function(type, data) {
// Enable another element
if (type == "disabled" && strict != 1) {
$.each(data, function(key, value) {
var newvalue=((value.search("^#") < 0 && value.search("^\.") < 0) ? "#" : "") + value;
$(newvalue).removeAttr("disabled");
if ($(newvalue).hasClass("butActionRefused") == true) {
$(newvalue).removeClass("butActionRefused");
$(newvalue).addClass("butAction");
}
});
} else if (type == "enabled") {
$.each(data, function(key, value) {
var newvalue=((value.search("^#") < 0 && value.search("^\.") < 0) ? "#" : "") + value;
if (strict == 1)
$(newvalue).removeAttr("disabled");
else
$(newvalue).attr("disabled", true);
if ($(newvalue).hasClass("butAction") == true) {
$(newvalue).removeClass("butAction");
$(newvalue).addClass("butActionRefused");
}
});
// Show another element
} else if (type == "showhide" || type == "show") {
$.each(data, function(key, value) {
var newvalue=((value.search("^#") < 0 && value.search("^\.") < 0) ? "#" : "") + value;
$(newvalue).show();
});
// Set another constant
} else if (type == "set") {
$.each(data, function(key, value) {
$("#set_" + key).hide();
$("#del_" + key).show();
$.get( url, {
action: "set",
name: key,
value: value,
entity: entity
});
});
}
});
});
}
/*
* Used by button to set on/off
*
* @param string url Url
* @param string code Code
* @param string intput Input
* @param int entity Entity
* @param int strict Strict
*/
function delConstant(url, code, input, entity, strict) {
$.get( url, {
action: "del",
name: code,
entity: entity
},
function() {
$("#del_" + code).hide();
$("#set_" + code).show();
$.each(input, function(type, data) {
// Disable another element
if (type == "disabled") {
$.each(data, function(key, value) {
var newvalue=((value.search("^#") < 0 && value.search("^\.") < 0) ? "#" : "") + value;
$(newvalue).attr("disabled", true);
if ($(newvalue).hasClass("butAction") == true) {
$(newvalue).removeClass("butAction");
$(newvalue).addClass("butActionRefused");
}
});
} else if (type == "enabled" && strict != 1) {
$.each(data, function(key, value) {
var newvalue=((value.search("^#") < 0 && value.search("^\.") < 0) ? "#" : "") + value;
$(newvalue).removeAttr("disabled");
if ($(newvalue).hasClass("butActionRefused") == true) {
$(newvalue).removeClass("butActionRefused");
$(newvalue).addClass("butAction");
}
});
// Hide another element
} else if (type == "showhide" || type == "hide") {
$.each(data, function(key, value) {
var newvalue=((value.search("^#") < 0 && value.search("^\.") < 0) ? "#" : "") + value;
$(newvalue).hide();
});
// Delete another constant
} else if (type == "del") {
$.each(data, function(key, value) {
$("#del_" + value).hide();
$("#set_" + value).show();
$.get( url, {
action: "del",
name: value,
entity: entity
});
});
}
});
});
}
/*
* Used by button to set on/off
*
* @param string action Action
* @param string url Url
* @param string code Code
* @param string intput Input
* @param string box Box
* @param int entity Entity
* @param int yesButton yesButton
* @param int noButton noButton
* @param int strict Strict
*/
function confirmConstantAction(action, url, code, input, box, entity, yesButton, noButton, strict) {
var boxConfirm = box;
$("#confirm_" + code)
.attr("title", boxConfirm.title)
.html(boxConfirm.content)
.dialog({
resizable: false,
height: 170,
width: 500,
modal: true,
buttons: [
{
id : 'yesButton_' + code,
text : yesButton,
click : function() {
if (action == "set") {
setConstant(url, code, input, entity, strict);
} else if (action == "del") {
delConstant(url, code, input, entity, strict);
}
// Close dialog
$(this).dialog("close");
// Execute another method
if (boxConfirm.method) {
var fnName = boxConfirm.method;
if (window.hasOwnProperty(fnName)) {
window[fnName]();
}
}
}
},
{
id : 'noButton_' + code,
text : noButton,
click : function() {
$(this).dialog("close");
}
}
]
});
// For information dialog box only, hide the noButton
if (boxConfirm.info) {
$("#noButton_" + code).button().hide();
}
}
/*
* =================================================================
* This is to allow to transform all select box into ajax autocomplete box
* with just one line:
* $(function() { $( "#idofmylist" ).combobox(); });
* Do not use it on large combo boxes
* =================================================================
*/
(function( $ ) {
$.widget( "ui.combobox", {
options: {
minLengthToAutocomplete: 0
},
_create: function() {
var savMinLengthToAutocomplete = this.options.minLengthToAutocomplete;
var self = this,
select = this.element.hide(),
selected = select.children( ":selected" ),
value = selected.val() ? selected.text() : "";
var input = this.input = $( "<input>" )
.insertAfter( select )
.val( value )
.attr('id', 'inputautocomplete'+select.attr('id'))
.autocomplete({
delay: 0,
minLength: this.options.minLengthToAutocomplete,
source: function( request, response ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( select.children( "option:enabled" ).map(function() {
var text = $( this ).text();
if ( this.value && ( !request.term || matcher.test(text) ) )
return {
label: text.replace(
new RegExp(
"(?![^&;]+;)(?!<[^<>]*)(" +
$.ui.autocomplete.escapeRegex(request.term) +
")(?![^<>]*>)(?![^&;]+;)", "gi"
), "<strong>$1</strong>" ),
value: text,
option: this
};
}) );
},
select: function( event, ui ) {
ui.item.option.selected = true;
self._trigger( "selected", event, {
item: ui.item.option
});
},
change: function( event, ui ) {
if ( !ui.item ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
valid = false;
select.children( "option" ).each(function() {
if ( $( this ).text().match( matcher ) ) {
this.selected = valid = true;
return false;
}
});
if ( !valid ) {
// remove invalid value, as it didnt match anything
$( this ).val( "" );
select.val( "" );
input.data("ui-autocomplete").term = "";
return false;
}
}
}
})
.addClass( "ui-widget ui-widget-content ui-corner-left dolibarrcombobox" );
input.data("ui-autocomplete")._renderItem = function( ul, item ) {
return $("<li>")
.data( "ui-autocomplete-item", item ) // jQuery UI > 1.10.0
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
};
this.button = $( "<button type=\'button\'> </button>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.insertAfter( input )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "ui-corner-right ui-button-icon" )
.click(function() {
// close if already visible
if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
input.autocomplete( "close" );
return;
}
// pass empty string as value to search for, displaying all results
input.autocomplete({ minLength: 0 });
input.autocomplete( "search", "" );
input.autocomplete({ minLength: savMinLengthToAutocomplete });
input.focus();
});
},
destroy: function() {
this.input.remove();
this.button.remove();
this.element.show();
$.Widget.prototype.destroy.call( this );
}
});
})( jQuery );
/**
* Function to output a dialog bog for copy/paste
*
* @param string text Text to put into copy/paste area
* @param string text2 Text to put under the copy/paste area
*/
function copyToClipboard(text,text2)
{
text = text.replace(/<br>/g,"\n");
var newElem = '<textarea id="coordsforpopup" style="border: none; width: 90%; height: 120px;">'+text+'</textarea><br><br>'+text2;
/* alert(newElem); */
$("#dialogforpopup").html(newElem);
$("#dialogforpopup").dialog();
$("#coordsforpopup").select();
return false;
}
/**
* Show a popup HTML page. Use the "window.open" function.
*
* @param string url Url
* @param string title Title of popup
* @return boolean False
* @see document_preview
*/
function newpopup(url,title) {
var argv = newpopup.arguments;
var argc = newpopup.arguments.length;
tmp=url;
var l = (argc > 2) ? argv[2] : 600;
var h = (argc > 3) ? argv[3] : 400;
var left = (screen.width - l)/2;
var top = (screen.height - h)/2;
var wfeatures = "directories=0,menubar=0,status=0,resizable=0,scrollbars=1,toolbar=0,width=" + l +",height=" + h + ",left=" + left + ",top=" + top;
fen=window.open(tmp,title,wfeatures);
return false;
}
/**
* Function show document preview. Use the "dialog" function.
*
* @param string file Url
* @param string type Mime file type ("image/jpeg", "application/pdf", "text/html")
* @param string title Title of popup
* @return void
* @see newpopup
*/
function document_preview(file, type, title)
{
var ValidImageTypes = ["image/gif", "image/jpeg", "image/png"];
console.log("document_preview A click was done. file="+file+", type="+type);
if ($.inArray(type, ValidImageTypes) < 0) {
var width='85%';
var object_width='100%';
var height = $( window ).height()*0.90;
var object_height='98%';
show_preview();
} else {
var object_width=0;
var object_height=0;
var img = new Image();