noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
noalyss_script.js
Go to the documentation of this file.
1/*
2 * This file is part of NOALYSS.
3 *
4 * NOALYSS is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * NOALYSS is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with NOALYSS; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18/* $Revision$ */
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/**
23 *
24 * javascript script, always added to every page, it is the first script and
25 * should contain all the global variables
26 *
27 */
28var ask_reload = 0;
29// tag_choose Element which contains all the selected tags
30var tag_choose = '';
31var aDraggableElement = new Array();
32// Layer for z-index , see function get_next_layer , must be used in PHP and JS
33var global_layer=10;
34// document.viewport depends of prototype.js
35var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
36var width = viewport.width; // Usable window width
37var height = viewport.height;
38var g_enable_tinymce=true;
39/**
40 * if browser < 2021, function window.crypto.randomUUID is not implemented
41 * so we tinyMCE cannot work
42*/
43if ( ! window.crypto.randomUUID) {
44 console.info("too old browser: implement function randomUUID")
45 window.crypto.randomUUID=function()
46 {
47 let myArray = new Uint32Array(4);
48 crypto.getRandomValues(myArray);
49 let result="";let and="";
50 for(a of myArray)
51 {
52 result+=and.a;
53 and="-";
54 }
55 return result;
56 }
57}
58
59
60/**
61 * return undefined if nothing is found , otherwise return the DOM elemnt, try to find an DOM Element inside p_element
62 * @param {type} p_name_dom
63 * @param {type} name_child
64 * @returns {undefined}
65 */
66function in_child(p_element, name_child) {
67 var element = p_element
68 if (typeof p_element !== "object") {
69 element = document.getElementById(p_element);
70
71 }
72 if (!element) return undefined;
73 for (var e = 0; e < element.childElementCount; e++) {
74 if (element.childNodes[e].id == name_child) {
75 return element.childNodes[e];
76 }
77 }
78}
79
80/**
81 * callback function when we just need to update a hidden div with an info
82 * message
83 * @see removeOperation , reverseOperation
84 */
85function infodiv(req, json) {
86 try {
87 remove_waiting_box();
88 var answer = req.responseXML;
89 var a = answer.getElementsByTagName('ctl');
90 var html = answer.getElementsByTagName('code');
91 if (a.length === 0) {
92 var rec = req.responseText;
93 alert_box('erreur :' + rec);
94 }
95 var name_ctl = a[0].firstChild.nodeValue;
96 var code_html = getNodeText(html[0]);
97
98 code_html = unescape_xml(code_html);
99 id$(name_ctl + "info").innerHTML = code_html;
100 } catch (e) {
101 alert_box("success_box" + e.message);
102 }
103 try {
104 code_html.evalScripts();
105 } catch (e) {
106 alert_box(content[53] + "\n" + e.message);
107 }
108
109}
110
111/**
112 * delete a row from a table (tb) the input button send the this
113 * as second parameter
114 */
115function deleteRow(tb, obj) {
116 smoke.confirm(content[50], function (e) {
117 if (e) {
118 var td = obj.parentNode;
119 var tr = td.parentNode;
120 var lidx = tr.rowIndex;
121 id$(tb).deleteRow(lidx);
122
123 } else {
124 return;
125 }
126 });
127}
128
129function deleteRowRec(tb, obj) {
130 var tr = obj;
131 var lidx = tr.rowIndex;
132 id$(tb).deleteRow(lidx);
133}
134
135/*!\brief remove trailing and heading space
136 * \param the string to modify
137 * \return string without heading and trailing space
138 */
139function trim(s) {
140 return s.replace(/^\s+/, '').replace(/\s+$/, '');
141}
142
143/**
144 * retrieve an element thanks its ID
145 * @param ID is a string
146 * @return the found object of undefined if not found
147 */
148function id$(ID) {
149 if (ID instanceof Object ) return ID;
150 if (document.getElementById(ID)) {
151 return document.getElementById(ID);
152 } else if (document.all) {
153 return document.all[ID];
154 } else {
155 document.debug_noalyss&&console.error(`id$ ${ID} not found`)
156 return undefined;
157 }
158}
159
160/**
161 * this function is deprecated and replaced by id$
162 * @deprecated
163 * @param ID
164 * @returns {*}
165 */
166function g(ID) {
167 document.debug_noalyss&& console.warn(`g(${ID} is deprecated, use id$`);
168 return id$(ID);
169}
170function get_next_layer(){
171 return global_layer++;
172}
173/**
174 * enable the type of periode
175 */
176function enable_type_periode() {
177 if (document.getElementById("type_periode").options[id$("type_periode").selectedIndex].value == 0) {
178 id$('from_periode').enable();
179 id$('to_periode').enable();
180 id$('from_date').disable();
181 id$('to_date').disable();
182 id$('p_step').enable();
183 } else {
184 id$('from_periode').disable();
185 id$('to_periode').disable();
186 id$('from_date').enable();
187 id$('to_date').enable();
188 id$('p_step').disable();
189 }
190}
191
192/**
193 * will reload the window but it is dangerous if we have submitted
194 * a form with POST
195 */
196function refresh_window() {
197 window.location.reload();
198}
199
200/**
201 *@fn encodeJSON(obj)
202 * we receive a json object as parameter and the function returns the string
203 * with the format variable=value&var2=val2...
204 */
205function encodeJSON(obj) {
206 if (typeof obj != 'object') {
207 alert_box('encodeParameter obj n\'est pas un objet');
208 }
209 try {
210 var str = '';
211 var e = 0;
212 for (var i in obj) {
213 if (e !== 0) {
214 str += '&';
215 } else {
216 e = 1;
217 }
218 str += i;
219 str += '=' + encodeURI(obj[i]);
220 }
221 return str;
222 } catch (e) {
223 alert_box('encodeParameter ' + e.message);
224 return "";
225 }
226}
227
228function hide(p_param) {
229 id$(p_param).style.display = 'none';
230}
231
232function show(p_param) {
233 id$(p_param).style.display = 'block';
234}
235
236/**
237 * set the focus on the selected field
238 *@param Field id of the control
239 *@param selectIt : the value selected in case of Field is a object select, numeric
240 */
241function SetFocus(Field, SelectIt) {
242 var elem = id$(Field);
243 if (elem) {
244 elem.focus();
245 }
246 return true;
247}
248
249/**
250 * set a DOM id with a value in the parent window (the caller),
251 @param p_ctl is the name of the control
252 @param p_value is the value to set in
253 @param p_add if we don't replace the current value but we add something
254 */
255function set_inparent(p_ctl, p_value, p_add) {
256 self.opener.set_value(p_ctl, p_value, p_add);
257}
258
259/**
260 * set a DOM id with a value, it will consider if it the attribute
261 value or innerHTML has be used
262 @param p_ctl is the name of the control
263 @param p_value is the value to set in
264 @param p_add if we don't replace the current value but we add something
265 */
266function set_value(p_ctl, p_value, p_add) {
267 if (document.getElementById(p_ctl)) {
268 var g_ctrl = id$(p_ctl);
269 if (p_add != undefined && p_add === 1) {
270 if (g_ctrl.value) {
271 p_value = g_ctrl.value + ',' + p_value;
272 }
273 }
274 if (g_ctrl.tagName === 'INPUT') {
275 id$(p_ctl).value = p_value;
276 }
277 if (g_ctrl.tagName === 'SPAN') {
278 id$(p_ctl).innerHTML = p_value;
279 }
280 if (g_ctrl.tagName === 'SELECT') {
281 id$(p_ctl).value = p_value;
282 }
283 }
284}
285
286/**
287 * compute small math in numeric cells
288 * @param string value
289 * @returns float
290 */
291function compute_number(value) {
292 var retval = 0;
293
294 var exp = new RegExp("^[0-9/*+-.()]+$", "g");
295 /*pour éviter un eval() mal intentionné*/
296 var res = exp.test(value);
297 if (res) {
298 /*pour gérer un nombre non valide comme 5..36 ou 5.3.6
299 parce qu'il est possible d'entrer plusieurs
300 points dans le nombre et eval() lève une exception*/
301 try {
302 retval = eval(value);
303 } catch (e) {
304 return parseFloat(value);
305 }
306 /*pour gérer les divisions par 0*/
307 if (retval == Infinity) {
308 return 0;
309 } else {
310 return retval;
311 }
312 } else {
313 return 0;
314 }
315}
316
317/**
318 * format the number change comma to point
319 *@param HTML obj
320 */
321function format_number(obj, p_prec) {
322 var precision = 2;
323 if (p_prec === undefined) {
324 precision = 2;
325 } else {
326 precision = p_prec;
327 }
328 var value = obj.value;
329 value = value.replace(/ /g, '');
330 value = value.replace(/,/g, '.');
331
332
333 value = compute_number(value);
334
335 value = parseFloat(value);
336 if (isNaN(value)) {
337 value = 0;
338 }
339 var arrondi = Math.pow(10, precision);
340
341 value = Math.round(value * arrondi) / arrondi;
342
343 id$(obj).value = value;
344}
345
346/**
347 * Replace slash , space and minus by dot
348 * @param p_object DOM Element date to check
349 */
350function format_date(p_object) {
351 p_object.value = p_object.value.replace(/\//g, '.');
352 p_object.value = p_object.value.replace(/-/g, '.');
353 p_object.value = p_object.value.replace(/ /g, '.');
354 p_object.value = p_object.value.replace(/\.\./g, '.');
355 var tmp_value = p_object.value;
356 a_split = tmp_value.split('.');
357 if (a_split[2] && a_split[2].match(/[0-9]{2}/) && a_split[2].length == 2) {
358 a_split[2] = "20" + a_split[2];
359 p_object.value = a_split[0] + "." + a_split[1] + "." + a_split[2];
360 }
361 var nMonth = parseFloat(a_split[1]) - 1;
362 var ma_date = new Date(a_split[2], nMonth, a_split[0]);
363 if (ma_date.getFullYear() == a_split[2] && ma_date.getMonth() == nMonth && ma_date.getDate() == a_split[0]) {
364 return;
365 } else {
366 new Effect.Highlight(p_object.id, {startcolor: "#ff0000"});
367 p_object.value = "";
368 }
369
370
371}
372
373/**
374 * check if the object is hidden or show and perform the opposite,
375 * show the hidden obj or hide the shown one. With display : flex,
376 *@param name of the object
377 * @param button id of the button
378 * @param rotate : if true with rotate the object of p_button otherwise
379 */
380function toggleHideShow(p_obj, p_button, rotate) {
381 var div_obj = id$(p_obj);
382 var stat = div_obj.style.display;
383
384 var str = (id$(p_button)) ? id$(p_button).value : "";
385
386 if (stat === 'none') {
387 // specific for the DIV id search_form
388 if (div_obj.id == 'search_form') {
389 show(p_obj);
390 } else {
391 id$(p_obj).show()
392 }
393 str = str.replace(/Afficher/, content[62]);
394 id$(p_button).value = str;
395 } else {
396 // specific for the DIV di search_form
397 if (!div_obj.id == 'search_form') {
398 hide(p_obj);
399 } else {
400 id$(p_obj).hide()
401 }
402 str = str.replace(/Cacher/, content[63]);
403 id$(p_button).value = str;
404 }
405 if (!rotate) return;
406 if (stat == "none") {
407 id$(p_button).addClassName("icon-up-open-1")
408 id$(p_button).removeClassName(" icon-down-open-2")
409 } else {
410 id$(p_button).removeClassName("icon-up-open-1")
411 id$(p_button).addClassName(" icon-down-open-2")
412
413 }
414
415}
416
417/**
418 * open popup with the search windows
419 *@param p_dossier the dossier where to search
420 *@param p_style style of the detail value are E for expert or S for simple
421 */
422function popup_recherche(p_dossier) {
423 var w = window.open("recherche.php?gDossier=" + p_dossier + "&ac=SEARCH", '', 'statusbar=no,scrollbars=yes,toolbar=no');
424 w.focus();
425}
426
427/**
428 * replace the special characters (><'") by their HTML representation
429 *@return a string without the offending char.
430 */
431function unescape_xml(code_html) {
432 code_html = code_html.replace(/\&lt;/, '<');
433 code_html = code_html.replace(/\&gt;/, '>');
434 code_html = code_html.replace(/\&quot;/, '"');
435 code_html = code_html.replace(/\&apos;/, "'");
436 code_html = code_html.replace(/\&amp;/, '&');
437 return code_html;
438}
439
440/**
441 * Firefox splits the XML into 4K chunk, so to retrieve everything we need
442 * to get the different parts thanks textContent
443 *@param xmlNode a node (result of var data = =answer.getElementsByTagName('code'))
444 *@return all the content of the XML node
445 */
446function getNodeText(xmlNode) {
447 if (!xmlNode)
448 return '';
449 if (typeof (xmlNode.textContent) != "undefined") {
450 return xmlNode.textContent;
451 }
452 if (xmlNode.firstChild && xmlNode.firstChild.nodeValue)
453 return xmlNode.firstChild.nodeValue;
454 return "";
455}
456
457/**
458 * change the periode in the calendar of the dashboard
459 *@param object select
460 */
461function change_month(obj) {
462 var action = new Ajax.Request(
463 "ajax_misc.php",
464 {
465 method: 'get',
466 parameters: {
467 gDossier: obj.gDossier,
468 op: 'cal',
469 "per": obj.value,
470 t: obj.type_display,
471 notitle: obj.notitle
472 },
473 onFailure: ajax_misc_failure,
474 onSuccess: success_misc
475 }
476 );
477
478}
479
480/**
481 * basic answer to ajax on success, it will fill the DOMID code with
482 * the code. In that case, you need to create the object before the Ajax.Request
483 *The difference with success box is that
484 *@see add_div removeDiv success_box is that the width and height are not changed ajax_misc.php
485 *@param code is the ID of the object containing the html (div, button...)
486 *@param value is the html code, with it you fill the ctl element
487 */
488
489function success_misc(req) {
490 try {
491 var answer = req.responseXML;
492 var html = answer.getElementsByTagName('code');
493 if (html.length === 0) {
494 var rec = req.responseText;
495 alert_box('erreur :' + rec);
496 }
497 var nodeXml = html[0];
498 var code_html = getNodeText(nodeXml);
499 code_html = unescape_xml(code_html);
500 id$("user_cal").innerHTML = code_html;
501 } catch (e) {
502 alert_box(e.message);
503 }
504 try {
505 code_html.evalScripts();
506 } catch (e) {
507 alert_box(content[53] + "\n" + e.message);
508 }
509
510
511}
512
513function loading() {
514
515 var str ='<div style="animation-duration:6s;animation-name:fill_up_loading;animation-iteration-count: infinite;animation-timing-function: linear;align-items: center">';
516 str += '<div class="loading_msg"></div>';
517 str += '<div class="loading_msg"></div>';
518 str += '<div class="loading_msg"></div>';
519 str += '<div class="loading_msg"></div>';
520 str += '<div class="loading_msg"></div>';
521 str +='</div>';
522
523 var str2 = '<div style="animation-duration:6s;animation-name:fill_up_loading;animation-iteration-count: infinite;animation-timing-function: linear;position:relative;top:-50px;animation-delay: 0.7s;">';
524 str2 += '<div class="loading_msg"></div>';
525 str2 += '<div class="loading_msg"></div>';
526 str2 += '<div class="loading_msg"></div>';
527 str2 += '<div class="loading_msg"></div>';
528 str2 += '<div class="loading_msg"></div>';
529 str2 +='</div>';
530 return str+str2;
531}
532
533function ajax_misc_failure() {
534 alert_box(content[53]);
535}
536
537/**
538 * remove a document_modele
539 */
540function cat_doc_remove(p_dt_id, p_dossier) {
541 var queryString = "gDossier=" + p_dossier + "&op=rem_cat_doc" + "&dt_id=" + p_dt_id;
542 var action = new Ajax.Request(
543 "ajax_misc.php", {
544 method: 'get',
545 parameters: queryString,
546 onFailure: ajax_misc_failure,
547 onSuccess: function (req) {
548 try {
549 var answer = req.responseXML;
550 var html = answer.getElementsByTagName('dtid');
551 if (html.length === 0) {
552 var rec = req.responseText;
553 alert_box('erreur <br>' + rec);
554 return;
555 }
556 var nodeXML = html[0];
557 var row_id = getNodeText(nodeXML);
558 if (row_id === 'nok') {
559 var message_node = answer.getElementsByTagName('message');
560 var message_text = getNodeText(message_node[0]);
561 alert_box('erreur <br>' + message_text);
562 return;
563 }
564 id$('row' + row_id).style.textDecoration = "line-through";
565 id$('X' + row_id).style.display = 'none';
566 id$('M' + row_id).style.display = 'none';
567 } catch (e) {
568 alert_box(e.message);
569 }
570 }
571 }
572 );
573}
574
575/**
576 * change a document_modele
577 */
578function cat_doc_change(p_dt_id, p_dossier) {
579 var queryString = "gDossier=" + p_dossier + "&op=mod_cat_doc" + "&dt_id=" + p_dt_id;
580 var nTop = calcy(posY);
581 var nLeft = "200px";
582 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:50em;height:auto";
583
584 removeDiv('change_doc_div');
585 waiting_box();
586 var action = new Ajax.Request(
587 "ajax_misc.php",
588 {
589 method: 'get', parameters: queryString,
590 onFailure: ajax_misc_failure,
591 onSuccess: function (req) {
592 remove_waiting_box();
593 add_div({id: 'change_doc_div', style: str_style, cssclass: 'inner_box', drag: "1"});
594 id$('change_doc_div').innerHTML = req.responseText;
595
596 }
597 }
598 );
599}
600
601/**
602 * display the popup with vat and explanation
603 *@param obj with 4 attributes gdossier, ctl,popup
604 *@param p_function_callback callback function to be called after,
605 */
606function popup_select_tva(obj, p_function_callback) {
607 try {
608 if (document.getElementById('tva_select')) {
609 removeDiv('tva_select');
610 }
611 var gDossier=(obj.gDossier)?obj.gDossier:obj.getAttribute("gdossier");
612 var ctl=(obj.ctl)?obj.ctl:obj.getAttribute("ctl");
613
614 var queryString = "gDossier=" + gDossier + "&op=dsp_tva" + "&ctl=" + ctl + '&popup=' + 'tva_select';
615
616 var jcode=(obj.jcode)?obj.jcode:obj.getAttribute("jcode");
617 if (jcode)
618 queryString += '&code=' + jcode;
619 var compute=(obj.compute)?obj.compute:obj.getAttribute("compute");
620 if (compute) queryString += '&compute=' + compute;
621 var filter=(obj.filter)?obj.filter:obj.getAttribute("filter");
622
623 if (filter) queryString += '&filter=' + filter;
624
625 var action = new Ajax.Request(
626 "ajax_misc.php",
627 {
628 method: 'get',
629 parameters: queryString,
630 onFailure: ajax_misc_failure,
631 onSuccess: function (req) {
632 try {
633 var answer = req.responseXML;
634 var popup = answer.getElementsByTagName('popup');
635 if (popup.length === 0) {
636 var rec = req.responseText;
637 alert_box('erreur :' + rec);
638 }
639 var html = answer.getElementsByTagName('code');
640
641 var name_ctl = popup[0].firstChild.nodeValue;
642 var nodeXml = html[0];
643 var code_html = getNodeText(nodeXml);
644 code_html = unescape_xml(code_html);
645
646 var nTop = posY - 200;
647 var nLeft = "15%";
648 var str_style = "top:" + nTop + "px;left:" + nLeft + ";right:" + nLeft + ";width:55em;height:auto;z-index:"+get_next_layer()+';';
649
650 var popup = {
651 'id': 'tva_select',
652 'cssclass': 'inner_box',
653 'style': str_style,
654 'html': code_html,
655 'drag': false
656 };
657 add_div(popup);
658 id$('lk_tva_select_table').focus();
659 sorttable.makeSortable(id$('tva_select_table'));
660 if (p_function_callback) {
661 p_function_callback.call(null);
662 }
663 } catch (e) {
664 alert_box("success_popup_select_tva " + e.message);
665 }
666 }
667 }
668 );
669 } catch (e) {
670 alert_box("popup_select_tva " + e.message);
671 }
672}
673
674
675/**
676 * display the popup with vat and explanation
677 *@param obj with 4 attributes gdossier, ctl,popup
678 */
679function set_tva_label(obj) {
680 try {
681 var queryString = "gDossier=" + obj.gDossier + "&op=label_tva" + "&id=" + obj.value;
682 if (obj.jcode )
683 queryString += '&code=' + obj.jcode;
684 else if ( obj.getAttribute("jcode") )
685 queryString += '&code=' + obj.getAttribute("jcode") ;
686 var action = new Ajax.Request(
687 "ajax_misc.php",
688 {
689 method: 'get',
690 parameters: queryString,
691 onFailure: ajax_misc_failure,
692 onSuccess: success_set_tva_label
693 }
694 );
695 } catch (e) {
696 alert_box("set_tva_label " + e.message);
697 }
698}
699
700/**
701 * display the popup with vat and explanations
702 *@param string req answer from ajax
703 */
704function success_set_tva_label(req) {
705 try {
706 var answer = req.responseXML;
707 var code = answer.getElementsByTagName('code');
708 var value = answer.getElementsByTagName('value');
709
710 if (code.length === 0) {
711 var rec = req.responseText;
712 alert_box('erreur :' + rec);
713 }
714
715 var label_code = code[0].firstChild.nodeValue;
716 var label_value = value[0].firstChild.nodeValue;
717 set_value(label_code, label_value);
718 } catch (e) {
719 alert_box("success_set_tva_label " + e.message);
720 }
721
722}
723
724/**
725 * Create a div without showing it
726 * @param {type} obj
727 * the attributes are
728 * - style to add style
729 * - id to add an id
730 * - cssclass to add a class
731 * - html is the content
732 * - drag is the div can be moved
733 * @returns html dom element
734 * @see add_div
735 */
736function create_div(obj) {
737 try {
738 var top = document;
739 var elt = null;
740 if (!document.getElementById(obj.id)) {
741 elt = top.createElement('div');
742 } else {
743 elt = id$(obj.id);
744 }
745 if (obj.id) {
746 elt.setAttribute('id', obj.id);
747 }
748 if (obj.style) {
749 if (elt.style.setAttribute) { /* IE7 bug */
750 elt.style.setAttribute('cssText', obj.style);
751 } else { /* good Browser */
752 elt.setAttribute('style', obj.style);
753 }
754 }
755 if (obj.cssclass) {
756 elt.setAttribute('class', obj.cssclass); /* FF */
757 elt.setAttribute('className', obj.cssclass); /* IE */
758 }
759 if (obj.html) {
760 elt.innerHTML = obj.html;
761 }
762
763 var bottom_div = document.body;
764 elt.hide();
765 bottom_div.appendChild(elt);
766
767 /* if ( obj.effect && obj.effect != 'none' ) { Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }
768 else if ( ! obj.effect ){ Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }*/
769 if (obj.drag) {
770 aDraggableElement[obj.id] = new Draggable(obj.id, {
771 starteffect: function () {
772 new Effect.Highlight(obj.id, {scroll: window, queue: 'end'});
773 }
774 }
775 );
776
777
778 }
779 return elt;
780 } catch (e) {
781 error_message("create_div " + e.message);
782 }
783}
784
785/**
786 * add dynamically a object for AJAX
787 *@param obj.
788 * the attributes are
789 * - style to add style
790 * - id to add an id
791 * - cssclass to add a class
792 * - html is the content
793 * - drag is the div can be moved
794 */
795function add_div(obj) {
796 try {
797 var elt = create_div(obj);
798 /* elt.setStyle({visibility:'visible'}); */
799 elt.style.visibility = 'visible';
800 elt.show();
801 return elt;
802 } catch (e) {
803 alert_box("add_div " + e.message);
804 }
805}
806
807/**
808 * remove a object created with add_div
809 * @param str_elt string id of the elt
810 */
811function removeDiv(str_elt) {
812 if (document.getElementById(str_elt)) {
813 document.body.removeChild(id$(str_elt));
814 }
815 // if reloaded if asked the window will be reloaded when
816 // the box is closed
817 if (ask_reload === 1) {
818 // avoid POST window.location = window.location.href;
819 window.location.reload();
820 }
821}
822
823function waiting_node() {
824 id$('info_div').innerHTML = 'Un instant';
825 id$('info_div').style.display = "block";
826}
827
828/**
829 *show a box while loading
830 *must be remove when ajax is successfull
831 * the id is wait_box
832 */
833function waiting_box() {
834 var obj = {
835 id: 'wait_box', html: loading() + '<p>' + content[65] + '</p>'
836 };
837 if (document.getElementById('wait_box')) {
838 removeDiv('wait_box');
839 }
840 var y = fixed_position(10, 250)
841 obj.style = y + ";width:281px;margin-left:40%;z-index:"+get_next_layer();
842 waiting_node();
843 add_div(obj);
844
845
846}
847
848/**
849 * call add_div to add a DIV and after call the ajax
850 * the queryString, the callback for function for success and error management
851 * the method is always GET
852 *@param obj, the mandatory attributes are
853 * - obj.qs querystring
854 * - obj.js_success callback function in javascript for handling the xml answer
855 * - obj.js_error callback function for error
856 * - obj.callback the php file to call
857 * - obj.fixed optional let you determine the position, otherwise works like IPopup
858 *@see add_div IBox
859 */
860function show_box(obj) {
861 add_div(obj);
862 if (!obj.fixed) {
863 id$(obj.id).style.top = calcy(40) + "px";
864 show(obj.id);
865 } else {
866 show(obj.id);
867 }
868
869 var action = new Ajax.Request(
870 obj.callback,
871 {
872 method: 'GET',
873 parameters: obj.qs,
874 onFailure: eval(obj.js_error),
875 onSuccess: eval(obj.js_success)
876 });
877}
878
879/**
880 * receive answer from ajax and just display it into the IBox
881 * XML must contains at least 2 fields : ctl is the ID of the IBOX and
882 * code is the HTML to put in it
883 *@see fill_box
884 */
885function success_box(req, json) {
886 try {
887 var answer = req.responseXML;
888 var a = answer.getElementsByTagName('ctl');
889 var html = answer.getElementsByTagName('code');
890 if (a.length === 0) {
891 var rec = req.responseText;
892 alert_box(content[48] + rec);
893 }
894 var name_ctl = a[0].firstChild.nodeValue;
895 var code_html = getNodeText(html[0]);
896
897 code_html = unescape_xml(code_html);
898 id$(name_ctl).innerHTML = code_html;
899 id$(name_ctl).style.height = 'auto';
900
901 if (name_ctl == 'popup')
902 id$(name_ctl).style.width = 'auto';
903 } catch (e) {
904 alert_box("success_box" + e.message);
905 }
906 try {
907 code_html.evalScripts();
908 } catch (e) {
909 alert_box(content[53] + "\n" + e.message);
910 }
911}
912
913function error_box() {
914 alert_box(content[53]);
915}
916
917/**
918 * show the ledger choice
919 */
920function show_ledger_choice(json_obj) {
921 try {
922 waiting_box();
923 var i = 0;
924 var query = "gDossier=" + json_obj.dossier + '&type=' + json_obj.type + '&div=' + json_obj.div + '&op=ledger_show';
925 query = query + '&nbjrn=' + id$(json_obj.div + 'nb_jrn').value;
926 query = query + '&all_type=' + json_obj.all_type;
927 for (i = 0; i < id$(json_obj.div + 'nb_jrn').value; i++) {
928 query = query + "&r_jrn[]=" + id$(json_obj.div + 'r_jrn[' + i + ']').value;
929 }
930 query = encodeURI(query);
931 var action = new Ajax.Request(
932 "ajax_misc.php",
933 {
934 method: 'get',
935 parameters: query,
936 onFailure: ajax_misc_failure,
937 onSuccess: function (req, json) {
938 try {
939 if (req.responseText === 'NOCONX') {
940 reconnect();
941 return;
942 }
943 var obj = {
944 id: json_obj.div + 'jrn_search',
945 cssclass: 'inner_box',
946 style: ';position:absolute;width:auto;z-index:'+get_next_layer()+';margin-left:20%',
947 drag: 1
948 };
949 //var y=calcy(posY);
950 var y = posY;
951
952 obj.style = "top:" + y + 'px;' + obj.style;
953 /* if ( json_obj.class )
954 {
955 obj.cssclass=json_obj.class;
956 }*/
957 add_div(obj);
958
959
960 var answer = req.responseXML;
961 var a = answer.getElementsByTagName('ctl');
962 var html = answer.getElementsByTagName('code');
963 if (a.length === 0) {
964 var rec = req.responseText;
965 alert_box('erreur :' + rec);
966 }
967 var name_ctl = a[0].firstChild.nodeValue;
968 var code_html = getNodeText(html[0]);
969
970 code_html = unescape_xml(code_html);
971 remove_waiting_box();
972 id$(obj.id).innerHTML = code_html;
973
974 } catch (e) {
975 alert_box("show_ledger_callback" + e.message);
976 }
977 try {
978 code_html.evalScripts();
979 } catch (e) {
980 alert_box(content[53] + "\n" + e.message);
981 }
982
983 }
984
985 }
986 );
987 } catch (e) {
988 alert_box('show_ledger_choice' + e.message);
989 }
990}
991
992/**
993 * hide the ledger choice
994 */
995function hide_ledger_choice(p_frm_search) {
996 try {
997 var nb = id$(p_frm_search).nb_jrn.value;
998 var div = "";
999 if (document.getElementById(p_frm_search).div) {
1000 div = id$(p_frm_search).div.value;
1001 }
1002 var i = 0;
1003 var str = "";
1004 var name = "";
1005 var n_name = "";
1006 var sel = 0;
1007 for (i = 0; i < nb; i++) {
1008 n_name = div + "r_jrn[" + sel + "]";
1009 name = div + "r_jrn" + i;
1010 if (document.getElementById(name).checked) {
1011 str += '<input type="hidden" id="' + n_name + '" name="' + n_name + '" value="' + id$(name).value + '">';
1012 sel++;
1013 }
1014 }
1015 str += '<input type="hidden" name="' + div + 'nb_jrn" id="' + div + 'nb_jrn" value="' + sel + '">';
1016 id$('ledger_id' + div).innerHTML = str;
1017 removeDiv(div + 'jrn_search');
1018 return false;
1019 } catch (e) {
1020 alert_box('hide_ledger_choice' + e.message);
1021 return false;
1022 }
1023
1024}
1025
1026/**
1027 * show the cat of ledger choice
1028 */
1029function show_cat_choice() {
1030 id$('div_cat').style.visibility = 'visible';
1031}
1032
1033/**
1034 * hide the cat of ledger choice
1035 */
1036function hide_cat_choice() {
1037 id$('div_cat').style.visibility = 'hidden';
1038}
1039
1040/**
1041 * add a row for the forecast item
1042 */
1043function for_add_row(tableid) {
1044 style = 'class="input_text"';
1045 var mytable = id$(tableid).tBodies[0];
1046 var nNumberRow = mytable.rows.length;
1047 var oRow = mytable.insertRow(nNumberRow);
1048 var rowToCopy = mytable.rows[1];
1049 var nNumberCell = rowToCopy.cells.length;
1050 var nb = id$("nbrow");
1051 var oNewRow = mytable.insertRow(nNumberRow);
1052 for (var e = 0; e < nNumberCell; e++) {
1053 var newCell = oRow.insertCell(e);
1054 var tt = rowToCopy.cells[e].innerHTML;
1055 new_tt = tt.replace(/an_cat0/g, "an_cat" + nb.value);
1056 new_tt = new_tt.replace(/an_cat_acc0/g, "an_cat_acc" + nb.value);
1057 new_tt = new_tt.replace(/an_qc0/g, "an_qc" + nb.value);
1058 new_tt = new_tt.replace(/an_label0/g, "an_label" + nb.value);
1059 new_tt = new_tt.replace(/month0/g, "month" + nb.value);
1060 new_tt = new_tt.replace(/an_cat_amount0/g, "an_cat_amount" + nb.value);
1061 new_tt = new_tt.replace(/an_deb0/g, "an_deb" + nb.value);
1062 newCell.innerHTML = new_tt;
1063 new_tt.evalScripts();
1064 }
1065 id$("an_cat_acc" + nb.value).value = "";
1066 id$("an_qc" + nb.value).value = "";
1067 id$("an_label" + nb.value).value = "";
1068 id$("an_cat_amount" + nb.value).value = "0";
1069 nb.value++;
1070}
1071
1072/**
1073 * toggle all the checkbox in a given form
1074 * @param form_id id of the form
1075 */
1076function toggle_checkbox(form_id) {
1077 var form = id$(form_id);
1078 for (var i = 0; i < form.length; i++) {
1079 var e = form.elements[i];
1080 if (e.type === 'checkbox') {
1081 if (e.checked === true) {
1082 e.checked = false;
1083 } else {
1084 e.checked = true;
1085 }
1086 }
1087 }
1088}
1089
1090/**
1091 * select all the checkbox in a given form
1092 * @param form_id id of the form
1093 */
1094function select_checkbox(form_id) {
1095 var form = id$(form_id);
1096 for (var i = 0; i < form.length; i++) {
1097 var e = form.elements[i];
1098 if (e.type === 'checkbox') {
1099 e.checked = true;
1100 }
1101 }
1102}
1103
1104/**
1105 * select all the checkbox in a given form if the specific attribute
1106 * has the given value
1107 * @param form_id id of the form
1108 * @param attribute name
1109 * @param attribute value
1110 */
1111function select_checkbox_attribute(form_id, p_attribute_name, p_attribute_value) {
1112 var form = id$(form_id);
1113 for (var i = 0; i < form.length; i++) {
1114 var e = form.elements[i];
1115 if (e.type === 'checkbox' && e.getAttribute(p_attribute_name) == p_attribute_value) {
1116 e.checked = true;
1117 }
1118 }
1119}
1120
1121/**
1122 * unselect all the checkbox in a given form
1123 * @param form_id id of the form
1124 */
1125function unselect_checkbox(form_id) {
1126 var form = id$(form_id);
1127 for (var i = 0; i < form.length; i++) {
1128 var e = form.elements[i];
1129 if (e.type === 'checkbox') {
1130 e.checked = false;
1131 }
1132 }
1133}
1134
1135/**
1136 * show the calculator
1137 */
1138function show_calc() {
1139 if (document.getElementById('calc1')) {
1140 this.document.getElementById('inp').value = "";
1141 this.document.getElementById('inp').focus();
1142 document.getElementById("calc1").setStyle({ 'z-index':get_next_layer()});
1143
1144 return;
1145 }
1146 var sid = 'calc1';
1147 var shtml = '';
1148 shtml += "<div class=\"bxbutton\">";
1149 shtml += '<a class="icon" onclick="pin(\'calc1\')" id="pin_calc1">&#xf047;</a> <a onclick="removeDiv(\'calc1\');" href="javascript:void(0)" title="" class="icon">&#10761;</a>';
1150 shtml += "</div>";
1151 shtml += ' <h2 class="title">' + content[66] + '</h2>';
1152 shtml += '<form name="calc_line" method="GET" onSubmit="cal();return false;" >' + content[68] + '<input class="input_text" type="text" id="inp" name="calculator"> <input type="button" value="Efface" class="button" onClick="Clean();return false;" > <input type="button" value="Efface historique" class="button" onClick="CleanHistory();return false;" > <input type="button" class="button" value="Fermer" onClick="removeDiv(\'calc1\')" >';
1153 shtml += '</form><span class="highligth" style="display:block" id="sub_total"> ' + content[67] + ' </span><span style="display:block" id="listing"> </span>';
1154
1155 var obj = {
1156 id: sid,
1157 html: shtml,
1158 drag: false,
1159 style: 'z-index:'+get_next_layer()
1160 };
1161 add_div(obj);
1162 this.document.getElementById('inp').focus();
1163}
1164
1165function display_periode(p_dossier, p_id) {
1166
1167 try {
1168 var queryString = "gDossier=" + p_dossier + "&op=input_per" + "&p_id=" + p_id;
1169 var popup = {
1170 'id': 'mod_periode',
1171 'cssclass': 'inner_box',
1172 'html': loading(),
1173 'style': 'width:30em',
1174 'drag': true
1175 };
1176 if (!document.getElementById('mod_periode')) {
1177 add_div(popup);
1178 }
1179 var action = new Ajax.Request(
1180 "ajax_misc.php",
1181 {
1182 method: 'get',
1183 parameters: queryString,
1184 onFailure: ajax_misc_failure,
1185 onSuccess: success_display_periode
1186 }
1187 );
1188 id$('mod_periode').style.top = (posY - 70) + "px";
1189 id$('mod_periode').style.left = (posX - 70) + "px";
1190 } catch (e) {
1191 alert_box("display_periode " + e.message);
1192 }
1193
1194}
1195
1196function success_display_periode(req) {
1197 try {
1198
1199 var answer = req.responseXML;
1200 var html = answer.getElementsByTagName('data');
1201
1202 if (html.length === 0) {
1203 var rec = req.responseText;
1204 alert_box('erreur :' + rec);
1205 }
1206
1207 var code_html = getNodeText(html[0]);
1208 code_html = unescape_xml(code_html);
1209
1210 id$('mod_periode').innerHTML = code_html;
1211 } catch (e) {
1212 alert_box("success_display_periode".e.message);
1213 }
1214 try {
1215 code_html.evalScripts();
1216 } catch (e) {
1217 alert_box(content[53] + "\n" + e.message);
1218 }
1219
1220}
1221
1222function save_periode(obj) {
1223 try {
1224 var queryString = id$(obj).serialize() + "&op=save_per";
1225
1226 var action = new Ajax.Request(
1227 "ajax_misc.php",
1228 {
1229 method: 'post',
1230 parameters: queryString,
1231 onFailure: ajax_misc_failure,
1232 onSuccess: success_display_periode
1233 }
1234 );
1235
1236 } catch (e) {
1237 alert_box("display_periode " + e.message);
1238 }
1239
1240 return false;
1241}
1242
1243/**
1244 * basic answer to ajax on success, it will fill the ctl with
1245 * the code. In that case, you need to create the object before the Ajax.Request
1246 *The difference with success box is that
1247 *@see add_div removeDiv success_box is that the width and height are not changed
1248 *@param ctl is the ID of the object containing the html (div, button...)
1249 *@param code is the html code, with it you fill the ctl element
1250 */
1251function fill_box(req) {
1252 try {
1253 if (req.responseText == 'NOCONX') {
1254 reconnect();
1255 return;
1256 }
1257 remove_waiting_box();
1258
1259 var answer = req.responseXML;
1260 var a = answer.getElementsByTagName('ctl');
1261 var html = answer.getElementsByTagName('code');
1262 if (a.length === 0) {
1263 var rec = req.responseText;
1264 alert_box('erreur :' + rec);
1265 }
1266 var name_ctl = a[0].firstChild.nodeValue;
1267 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
1268 code_html = unescape_xml(code_html);
1269 id$(name_ctl).innerHTML = code_html;
1270 } catch (e) {
1271 alert_box(e.message);
1272 if (console) {
1273 console.error(e);
1274 console.error("log answer = " + req.responseText);
1275 }
1276 }
1277 try {
1278 code_html.evalScripts();
1279 } catch (e) {
1280 if (console) {
1281 console.error(e);
1282 console.error("log answer = " + req.responseText);
1283 }
1284 alert_box(content[53] + "\n" + e.message);
1285 }
1286
1287
1288}
1289
1290/**
1291 *display a popin to let you modified a predefined operation
1292 *@param dossier_id
1293 *@param od_id from table op_predef
1294 */
1295function mod_predf_op(dossier_id, od_id, p_ledger) {
1296 var target = "mod_predf_op";
1297 removeDiv(target);
1298 var str_style = "top:10%;left:2%;width:96%";
1299
1300 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1301
1302 add_div(div);
1303
1304 var qs = "gDossier=" + dossier_id + '&op=mod_predf&id=' + od_id + '&ledger_id=' + p_ledger;
1305
1306 var action = new Ajax.Request('ajax_misc.php',
1307 {
1308 method: 'get',
1309 parameters: qs,
1310 onFailure: null,
1311 onSuccess: fill_box
1312 }
1313 );
1314
1315}
1316
1317function save_predf_op(obj) {
1318 waiting_box();
1319 var querystring = id$(obj).serialize() + '&op=save_predf';
1320 // Create a ajax request to get all the person
1321 var action = new Ajax.Request('ajax_misc.php',
1322 {
1323 method: 'post',
1324 parameters: querystring,
1325 onFailure: null,
1326 onSuccess: refresh_window
1327 }
1328 );
1329
1330 return false;
1331}
1332
1333/**
1334 *ctl_concern is the widget to update
1335 *amount_id is either a html obj. or an amount and the field tiers if given
1336 * @param {int} dossier
1337 * @param {string} ctl_concern DOM id that receive the number
1338 * @param {float or string} amount_id Amount or DOM Id of the element containing the amount
1339 * @param {float} ledger
1340 * @param {type} p_id_targetDom Element (div) where to display the search result
1341 * @param p_tiers id of the Tiers
1342 * @returns {undefined}
1343 */
1344function search_reconcile(dossier, ctl_concern, amount_id, ledger, p_id_target, p_tiers) {
1345 if (amount_id === undefined) {
1346 amount_id = 0;
1347 } else if (document.getElementById(amount_id)) {
1348 if (id$(amount_id).value) {
1349 amount_id = id$(amount_id).value;
1350 } else if
1351 (id$(amount_id).innerHTML) {
1352 amount_id = id$(amount_id).innerHTML;
1353 }
1354 }
1355 var tiers = "";
1356 if (p_tiers)
1357 tiers = p_tiers;
1358 var target = "";
1359 if (p_id_target != "") {
1360 target = p_id_target;
1361 } else {
1362 target = "search" + layer;
1363 removeDiv(target);
1364 }
1365 var str_style = fixed_position(77, 99);
1366 str_style += ";width:92%;overflow:auto;z-index:"+get_next_layer();
1367 waiting_box();
1368 var hide_operation = id$(ctl_concern).getAttribute("hide_operation");
1369 var single_operation = id$(ctl_concern).getAttribute("single_operation");
1370
1371 var param_send = {
1372 gDossier: dossier,
1373 ctlc: ctl_concern,
1374 op: 'search_op',
1375 ac: 'JSSEARCH',
1376 amount_id: amount_id,
1377 ledger: ledger,
1378 target: target,
1379 tiers: tiers,
1380 hide_operation: hide_operation,
1381 single_operation: single_operation
1382 };
1383
1384 var qs = encodeJSON(param_send);
1385
1386 var action = new Ajax.Request('ajax_misc.php',
1387 {
1388 method: 'get',
1389 parameters: qs,
1390 onFailure: null,
1391 onSuccess: function (req) {
1392 remove_waiting_box();
1393 var div = {id: target, cssclass: 'inner_box', style: str_style, drag: 0};
1394 add_div(div);
1395 id$(target).innerHTML = req.responseText;
1396 req.responseText.evalScripts();
1397 }
1398 }
1399 );
1400}
1401
1402/**
1403 * search in a popin obj if the object form,
1404 * @param obj DOM of the FORM
1405 */
1406function search_operation(obj) {
1407 try {
1408 var dossier = id$('gDossier').value;
1409 waiting_box();
1410 var target = "search" + layer;
1411 if (obj["target"]) {
1412 target = obj["target"].value;
1413 }
1414 var qs = Form.serialize('search_form_ajx') + "&op=search_op";
1415 var action = new Ajax.Request('ajax_misc.php',
1416 {
1417 method: 'get',
1418 parameters: qs,
1419 onFailure: null,
1420 onSuccess: function (req) {
1421 remove_waiting_box();
1422 id$(target).innerHTML = req.responseText;
1423 id$(target).setStyle({ 'z-index':get_next_layer()});
1424 req.responseText.evalScripts();
1425 }
1426 }
1427 );
1428 } catch (e) {
1429 remove_waiting_box();
1430 alert_box(e.message);
1431 }
1432}
1433
1434/**
1435 * Update the field e_concerned, from class_iconcerned
1436 * Value is the field where to put the quick-code but only if one checkbox has been
1437 * selected
1438 * @param {DOM Element} obj : DOM FORM ,
1439 * - element : ctlc : will contain the JRN.JR_ID ,
1440 * - tiers : the name of the counterparty
1441 * - target : DGBOX displaying the search result
1442 *
1443 * @returns {undefined}
1444 */
1445function set_reconcile(obj) {
1446
1447 try {
1448 var ctlc = obj.elements['ctlc'];
1449 var tiers = obj.elements['tiers'];
1450 if (!obj.elements['target'])
1451 return;
1452 var target = obj.elements['target'].value;
1453 var single_operation = obj.elements['single_operation'].value;
1454 for (var e = 0; e < obj.elements.length; e++) {
1455
1456 var elmt = obj.elements[e];
1457 if (elmt.type === "checkbox") {
1458 if (elmt.checked === true) {
1459 var str_name = elmt.name;
1460 var nValue = str_name.replace("jr_concerned", "");
1461 if (id$(ctlc.value).value != '') {
1462 id$(ctlc.value).value += ',';
1463
1464 } else {
1465
1466 if (tiers && tiers.value != "") {
1467 id$(tiers.value).value = elmt.value;
1468 /* set the name */
1469 new Ajax.Request("fid.php", {
1470 method: "get",
1471 parameters: {gDossier: obj.elements['gDossier'].value, "FID": elmt.value},
1472 onSuccess: function (req) {
1473 // find the row number
1474 //tiers.value = e_othern
1475 var tiers_card = new String(tiers.value);
1476 var num = tiers_card.replace("e_other", "");
1477 var tiers_name_id = "e_other" + "_name" + num;
1478 var answer = req.responseText.evalJSON();
1479 id$(tiers_name_id).value = answer["name"];
1480 }
1481 });
1482 }
1483 }
1484 if (single_operation == 0) {
1485 id$(ctlc.value).value += nValue;
1486 } else {
1487 id$(ctlc.value).value = nValue;
1488
1489 }
1490 }
1491 }
1492 }
1493 removeDiv(obj.elements['target'].value);
1494 } catch (e) {
1495 alert_box(e.message)
1496 }
1497}
1498
1499function remove_waiting_node() {
1500 id$('info_div').innerHTML = "";
1501 id$('info_div').style.display = "none";
1502
1503}
1504
1505function remove_waiting_box() {
1506 if (document.getElementById('wait_box')) {
1507 Effect.Fade('wait_box', {duration: 0.6});
1508 }
1509
1510 remove_waiting_node();
1511}
1512
1513/**
1514 * Show all the detail of a profile : Menu, Management, Repository and
1515 * let the user to modify it
1516 * @param {type} gDossier
1517 * @param {type} profile_id
1518 * @returns {undefined}
1519 */
1520function get_profile_detail(gDossier, profile_id) {
1521 waiting_box();
1522 var qs = "op=display_profile&gDossier=" + gDossier + "&p_id=" + profile_id + "&ctl=detail_profile";
1523 var action = new Ajax.Request('ajax_misc.php',
1524 {
1525 method: 'get',
1526 parameters: qs,
1527 onFailure: null,
1528 onSuccess: function (req) {
1529 remove_waiting_box();
1530 id$('list_profile').hide();
1531 id$('detail_profile').innerHTML = req.responseText;
1532 req.responseText.evalScripts();
1533 id$('detail_profile').show();
1534 if (profile_id != "-1")
1535 profile_show('profile_gen_div');
1536 }
1537 }
1538 );
1539}
1540
1541function get_profile_detail_success_obsolete(xml) {
1542 remove_waiting_box();
1543
1544}
1545
1546/**
1547 * compute the string to position a div in a fixed way
1548 * @return string
1549 */
1550function fixed_position(p_sx, p_sy) {
1551 var sx = p_sx;
1552 var sy = calcy(p_sy);
1553
1554 var str_style = "top:" + sy + "px;left:" + sx + "px;position:absolute";
1555 return str_style;
1556
1557}
1558
1559/**
1560 * compute Y even if the windows has scrolled down or up
1561 *@return the correct Y position
1562 */
1563function calcy(p_sy) {
1564 var sy = p_sy;
1565 if (window.pageYOffset) {
1566 sy = window.pageYOffset + p_sy;
1567 } else {
1568 sy = document.documentElement.scrollTop + p_sy;
1569 }
1570
1571 return sy;
1572
1573}
1574
1575/**
1576 * display a box with the menu option
1577 * @param {type} gdossier
1578 * @param {type} pm_id
1579 * @returns {undefined}
1580 */
1581function mod_menu(gdossier, pm_id) {
1582 waiting_box();
1583 removeDiv('divdm' + pm_id);
1584 var qs = "op=det_menu&gDossier=" + gdossier + "&pm_id=" + pm_id + "&ctl=divdm" + pm_id;
1585 var pos = fixed_position(50, 250);
1586 var action = new Ajax.Request('ajax_misc.php',
1587 {
1588 method: 'get',
1589 parameters: qs,
1590 onFailure: null,
1591 onSuccess: function (req) {
1592 try {
1593 remove_waiting_box();
1594 add_div({id: "divdm" + pm_id, drag: 1, cssclass: "inner_box", style: pos});
1595 id$('divdm' + pm_id).innerHTML = req.responseText;
1596 } catch (e) {
1597 alert_box(e.message);
1598 }
1599 }
1600 }
1601 );
1602}
1603
1604/**
1605 * Display the submenu of a menu or a module, used in setting the menu
1606 *
1607 * @param {type} p_dossier
1608 * @param {type} p_profile
1609 * @param {type} p_dep
1610 * @returns {undefined}
1611 */
1612function display_sub_menu(p_dossier, p_profile, p_dep, p_level) {
1613 waiting_box();
1614 new Ajax.Request('ajax_misc.php',
1615 {
1616 method: 'get',
1617 parameters: {
1618 op: 'display_submenu',
1619 gDossier: p_dossier,
1620 dep: p_dep,
1621 p_profile: p_profile,
1622 p_level: p_level
1623 },
1624 onSuccess: function (req) {
1625 try {
1626 remove_waiting_box();
1627 if (id$('menu_table').rows.length > p_level) {
1628 id$('menu_table').rows[1].remove();
1629 }
1630 id$('sub' + p_dep).addClassName("selectedmenu");
1631 var new_row = document.createElement('TR');
1632 new_row.innerHTML = req.responseText;
1633 id$('menu_table').appendChild(new_row);
1634 } catch (e) {
1635 alert_box(e.message);
1636 }
1637 }
1638 })
1639}
1640
1641/**
1642 * in C0PROFL, ask to confirm before removing a submenu and its children
1643 * @param {type} p_dossier
1644 * @param {type} profile_menu_id
1645 * @returns {undefined}
1646 */
1647function remove_sub_menu(p_dossier, profile_menu_id) {
1648 confirm_box(null, content[47],
1649 function () {
1650 waiting_box();
1651 new Ajax.Request('ajax_misc.php',
1652 {
1653 method: 'get',
1654 parameters: {
1655 op: 'remove_submenu', gDossier: p_dossier,
1656 p_profile_menu_id: profile_menu_id
1657 },
1658 onSuccess: function (req) {
1659 try {
1660 remove_waiting_box();
1661 id$('sub' + profile_menu_id).remove();
1662 if (id$('menu_table').rows.length > 1) {
1663 id$('menu_table').rows[1].remove();
1664 }
1665
1666 } catch (e) {
1667 alert_box(e.message);
1668 }
1669 }
1670 }
1671 )
1672 });
1673
1674}
1675
1676/**
1677 * add a menu to a profile, propose only the available menu
1678 * @param obj json object
1679 * - dossier : ,
1680 * - p_id : profile id ,
1681 * - type : Type of menu are "pr" for Printing "me" for plain menu
1682 * - p_level : level of menu (0 -> module,1-> top menu, 2->submenu)
1683 * - dep : the parent menu id (pm_id)
1684 *
1685 */
1686function add_menu(obj) {
1687 var pdossier = obj.dossier;
1688 var p_id = obj.p_id;
1689 var p_type = obj.type;
1690
1691 waiting_box();
1692 removeDiv('divdm' + p_id);
1693 var pos = fixed_position(250, 150) + ";width:50%;";
1694 var action = new Ajax.Request('ajax_misc.php',
1695 {
1696 method: 'get',
1697 parameters: {
1698 op: 'add_menu',
1699 'gDossier': pdossier,
1700 'p_id': p_id,
1701 'ctl': 'divdm' + p_id,
1702 'type': p_type,
1703 'dep': obj.dep,
1704 'p_level': obj.p_level
1705 },
1706 onFailure: null,
1707 onSuccess: function (req) {
1708 try {
1709 remove_waiting_box();
1710 add_div({id: "divdm" + p_id, drag: 1, "cssclass": "inner_box", "style": pos});
1711 id$('divdm' + p_id).innerHTML = req.responseText;
1712 } catch (e) {
1713 alert_box(e.message);
1714 }
1715 }
1716 }
1717 );
1718}
1719
1720/**
1721 * Display a box to enter data for adding a new plugin from
1722 * the CFGMENU
1723 * @param {type} p_dossier
1724 * @returns {undefined}
1725 */
1726function add_plugin(p_dossier) {
1727 waiting_box();
1728 removeDiv('divplugin');
1729 var qs = "op=add_plugin&gDossier=" + p_dossier + "&ctl=divplugin";
1730
1731 var action = new Ajax.Request('ajax_misc.php',
1732 {
1733 method: 'get',
1734 parameters: qs,
1735 onFailure: null,
1736 onSuccess: function (req) {
1737 try {
1738 remove_waiting_box();
1739 var pos = fixed_position(250, 150) + ";width:30%";
1740 add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1741 id$('divplugin').innerHTML = req.responseText;
1742 } catch (e) {
1743 alert_box(e.message);
1744 }
1745 }
1746 }
1747 );
1748}
1749
1750/**
1751 * Modify a menu
1752 * @param {type} p_dossier
1753 * @param {type} me_code
1754 * @returns {undefined}
1755 */
1756function mod_plugin(p_dossier, me_code) {
1757 waiting_box();
1758 removeDiv('divplugin');
1759 var qs = "op=mod_plugin&gDossier=" + p_dossier + "&ctl=divplugin&me_code=" + me_code;
1760
1761 var action = new Ajax.Request('ajax_misc.php',
1762 {
1763 method: 'get',
1764 parameters: qs,
1765 onFailure: null,
1766 onSuccess: function (req) {
1767 try {
1768 remove_waiting_box();
1769 var pos = fixed_position(250, 150) + ";width:30%";
1770 add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1771 id$('divplugin').innerHTML = req.responseText;
1772
1773 } catch (e) {
1774 alert_box(e.message);
1775 }
1776 }
1777 }
1778 );
1779}
1780
1781function create_menu(p_dossier) {
1782 waiting_box();
1783 removeDiv('divmenu');
1784 var qs = "op=create_menu&gDossier=" + p_dossier + "&ctl=divmenu";
1785
1786 var action = new Ajax.Request('ajax_misc.php',
1787 {
1788 method: 'get',
1789 parameters: qs,
1790 onFailure: null,
1791 onSuccess: function (req) {
1792 try {
1793 remove_waiting_box();
1794 var pos = fixed_position(250, 150) + ";width:30%";
1795 add_div({
1796 id: "divmenu",
1797 drag: 1,
1798 cssclass: "inner_box",
1799 style: pos
1800 });
1801 id$('divmenu').innerHTML = req.responseText;
1802 } catch (e) {
1803 alert_box(e.message);
1804 }
1805 }
1806 }
1807 );
1808}
1809
1810function modify_menu(p_dossier, me_code) {
1811 waiting_box();
1812 removeDiv('divmenu');
1813 var qs = "op=modify_menu&gDossier=" + p_dossier + "&ctl=divmenu&me_code=" + me_code;
1814
1815 var action = new Ajax.Request('ajax_misc.php',
1816 {
1817 method: 'get',
1818 parameters: qs,
1819 onFailure: null,
1820 onSuccess: function (req) {
1821 try {
1822 remove_waiting_box();
1823 var pos = fixed_position(250, 150) + ";width:30%";
1824 add_div({
1825 id: "divmenu",
1826 drag: 1,
1827 cssclass: "inner_box",
1828 style: pos
1829 });
1830 id$('divmenu').innerHTML = req.responseText;
1831
1832 } catch (e) {
1833 alert_box(e.message);
1834 }
1835 }
1836 }
1837 );
1838}
1839
1840function get_properties(obj) {
1841 var a_array = [];
1842 var s_type = "[" + typeof obj + "]";
1843 for (var m in obj) {
1844 a_array.push(m);
1845 }
1846 alert_box(s_type + a_array.join(","));
1847}
1848
1849/**
1850 * add a line in the form for the report
1851 * @param p_dossier dossier id to connect
1852 */
1853function rapport_add_row(p_dossier) {
1854 style = 'style="border: 1px solid blue;"';
1855 var table = id$("rap1");
1856 var line = table.rows.length;
1857
1858 var row = table.insertRow(line);
1859 // left cell
1860 var cellPos = row.insertCell(0);
1861 cellPos.innerHTML = '<input type="text" ' + style + ' size="3" id="pos' + line + '" name="pos' + line + '" value="' + line + '">';
1862
1863 // right cell
1864 var cellName = row.insertCell(1);
1865 cellName.innerHTML = '<input type="text" ' + style + ' size="40" id="text' + line + '" name="text' + line + '">';
1866
1867 // button + formula
1868 var cellbutton = row.insertCell(2);
1869 var but_html = table.rows[1].cells[2].innerHTML;
1870 but_html = but_html.replace(/form0/g, "form" + line);
1871 cellbutton.innerHTML = but_html;
1872 but_html.evalScripts();
1873
1874 id$('form' + line).value = '';
1875}
1876
1877/**
1878 * Search an action in an inner box
1879 */
1880function search_action(dossier, ctl_concern) {
1881 try {
1882 waiting_box();
1883 var dossier = id$('gDossier').value;
1884
1885 var target = "search_action_div";
1886 removeDiv(target);
1887 var str_style = fixed_position(77, 99)+";z-index:"+get_next_layer();
1888
1889 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1890
1891
1892 var target = {
1893 gDossier: dossier,
1894 ctlc: ctl_concern,
1895 op: 'search_action',
1896 ctl: target
1897 };
1898
1899 var qs = encodeJSON(target);
1900
1901 var action = new Ajax.Request('ajax_misc.php',
1902 {
1903 method: 'get',
1904 parameters: qs,
1905 onFailure: null,
1906 onSuccess: function (req) {
1907 try {
1908 remove_waiting_box();
1909 add_div(div);
1910 id$('search_action_div').innerHTML = req.responseText;
1911 req.responseText.evalScripts();
1912 } catch (e) {
1913 alert_box(e.message);
1914 }
1915 }
1916 }
1917 );
1918 } catch (e) {
1919 alert_box(e.message);
1920 }
1921}
1922
1923function result_search_action(obj) {
1924 try {
1925 var queryString = id$(obj).serialize() + "&op=search_action";
1926 var action = new Ajax.Request(
1927 "ajax_misc.php",
1928 {
1929 method: 'get',
1930 parameters: queryString,
1931 onFailure: ajax_misc_failure,
1932 onSuccess: function (req) {
1933 try {
1934 remove_waiting_box();
1935 id$('search_action_div').innerHTML = req.responseText;
1936 req.responseText.evalScripts();
1937 } catch (e) {
1938 alert_box(e.message);
1939 }
1940 }
1941 }
1942 )
1943
1944 } catch (e) {
1945 alert_box("display_periode " + e.message);
1946 }
1947
1948 return false;
1949}
1950
1951function set_action_related(p_obj) {
1952
1953 try {
1954 var obj = id$(p_obj);
1955 var ctlc = obj.elements['ctlc'];
1956
1957 for (var e = 0; e < obj.elements.length; e++) {
1958
1959 var elmt = obj.elements[e];
1960 if (elmt.type === "checkbox") {
1961 if (elmt.checked === true) {
1962 var str_name = elmt.name;
1963 var nValue = elmt.value;
1964 if (id$(ctlc.value).value != '') {
1965 id$(ctlc.value).value += ',';
1966 }
1967 id$(ctlc.value).value += nValue;
1968 }
1969 }
1970 }
1971 removeDiv('search_action_div');
1972 return false;
1973 } catch (e) {
1974 alert_box(e.message);
1975 return false;
1976 }
1977}
1978
1979/**
1980 * Show a form to modify or add a new repository
1981 *@param p_dossier
1982 *@param r_id : repository id
1983 */
1984function stock_repo_change(p_dossier, r_id) {
1985 var queryString = "gDossier=" + p_dossier + "&op=mod_stock_repo" + "&r_id=" + r_id;
1986 var nTop = calcy(posY);
1987 var nLeft = "10.1562%";
1988 var str_style = "top:" + nTop + "px;left:" + nLeft + ";height:auto;width:auto";
1989
1990 removeDiv('change_stock_repo_div');
1991 waiting_box();
1992 var action = new Ajax.Request(
1993 "ajax_misc.php",
1994 {
1995 method: 'get', parameters: queryString,
1996 onFailure: ajax_misc_failure,
1997 onSuccess: function (req) {
1998 remove_waiting_box();
1999 add_div({id: 'change_stock_repo_div', style: str_style, cssclass: 'inner_box', drag: "1"});
2000 id$('change_stock_repo_div').innerHTML = req.responseText;
2001
2002 }
2003 }
2004 );
2005}
2006
2007function stock_inv_detail(p_dossier, p_id) {
2008 var queryString = "gDossier=" + p_dossier + "&op=view_mod_stock" + "&c_id=" + p_id + "&ctl=view_mod_stock_div";
2009 var nTop = calcy(posY);
2010 var nLeft = "10%";
2011 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:80%;";
2012
2013 removeDiv('view_mod_stock_div');
2014 waiting_box();
2015 var action = new Ajax.Request(
2016 "ajax_misc.php",
2017 {
2018 method: 'get', parameters: queryString,
2019 onFailure: ajax_misc_failure,
2020 onSuccess: function (req) {
2021 remove_waiting_box();
2022 add_div({id: 'view_mod_stock_div', style: str_style, cssclass: 'inner_box', drag: "1"});
2023 id$('view_mod_stock_div').innerHTML = req.responseText;
2024 req.responseText.evalScripts();
2025 }
2026 }
2027 );
2028}
2029
2030function show_fin_chdate(obj_id) {
2031 try {
2032 var ch = id$(obj_id).options[id$(obj_id).selectedIndex].value;
2033 if (ch == 2) {
2034 id$('chdate_ext').hide();
2035 id$('thdate').show();
2036 }
2037 if (ch == 1) {
2038 id$('chdate_ext').show();
2039 id$('thdate').hide();
2040 }
2041 var nb = id$('nb_item').value;
2042 for (i = 0; i < nb; i++) {
2043 if (document.getElementById('tdchdate' + i)) {
2044 if (ch == 2) {
2045 id$('tdchdate' + i).show();
2046 }
2047 if (ch == 1) {
2048 id$('tdchdate' + i).hide();
2049
2050 }
2051 }
2052 }
2053 } catch (e) {
2054 alert_box(e.message);
2055 }
2056}
2057
2058/**
2059 * tab menu for the profile parameter
2060 */
2061function profile_show(p_div) {
2062 try {
2063 var div = ['profile_gen_div', 'profile_menu_div', 'profile_print_div', 'profile_gestion_div', 'profile_repo_div', 'profile_menu_mobile_div'];
2064 for (var r = 0; r < div.length; r++) {
2065 id$(div[r]).hide();
2066 }
2067 id$(p_div).show();
2068 } catch (e) {
2069 alert_box(e.message);
2070 }
2071}
2072
2073function detail_category_show(p_div, p_dossier, p_id) {
2074 id$(p_div).show();
2075 waiting_box();
2076 id$('detail_category_div').innerHTML = "";
2077 var queryString = "gDossier=" + p_dossier + "&id=" + p_id + "&op=fddetail";
2078 var action = new Ajax.Request(
2079 "ajax_misc.php",
2080 {
2081 method: 'get', parameters: queryString,
2082 onFailure: ajax_misc_failure,
2083 onSuccess: function (req) {
2084 remove_waiting_box();
2085 id$('list_cat_div').hide();
2086 id$('detail_category_div').innerHTML = req.responseText;
2087 id$('detail_category_div').show();
2088 req.responseText.evalScripts();
2089 }
2090 }
2091 );
2092}
2093
2094/**
2095 * check that the form is correct for a new category of card
2096 */
2097function check_new_category()
2098{
2099 if ( id$('nom_mod_id').value.trim()=="") {
2100 new Effect.Highlight('nom_mod_id',{startcolor:"#ff0000"});
2101 smoke.alert('Nom catégorie obligatoire');
2102 return false;
2103 }
2104 var TemplateCard= document.getElementsByName('FICHE_REF');
2105 for (i = 0;i< TemplateCard.length;i++) {
2106 if (TemplateCard[i].checked) return true;
2107 }
2108 new Effect.Highlight('template_category_ck',{startcolor:"#ff0000"});
2109 smoke.alert('Choisissez une catégorie');
2110 return false;
2111}
2112/**
2113 * check if the parameter is a valid a valid date or not, returns true if it is valid otherwise
2114 * false
2115 * @param p_str_date the string of the date (format DD.MM.YYYY)
2116 */
2117function check_date(p_str_date) {
2118 var format = /^\d{2}\.\d{2}\.\d{4}$/;
2119 if (!format.test(p_str_date)) {
2120 return false;
2121 } else {
2122 var date_temp = p_str_date.split('.');
2123 var nMonth = parseFloat(date_temp[1]) - 1;
2124 var ma_date = new Date(date_temp[2], nMonth, date_temp[0]);
2125 if (ma_date.getFullYear() == date_temp[2] && ma_date.getMonth() == nMonth && ma_date.getDate() == date_temp[0]) {
2126 return true;
2127 } else {
2128 return false;
2129 }
2130 }
2131
2132}
2133
2134/**
2135 * get the string in the id and check if the date is valid
2136 * @param p_id_date is the id of the element to check
2137 * @return true if the date is valid
2138 * @see check_date
2139 */
2140function check_date_id(p_id_date) {
2141 var str_date = id$(p_id_date).value;
2142 return check_date(str_date);
2143}
2144
2145/**
2146 *
2147 * @param ag_id to view
2148 * @param dossier is the folder
2149 * @param modify : show the modify button values : 0 for no 1 for yes
2150 */
2151function view_action(ag_id, dossier, modify) {
2152 waiting_box();
2153 var layer=get_next_layer();
2154 id = 'action' + layer;
2155
2156 querystring = 'gDossier=' + dossier + '&op=vw_action&ag_id=' + ag_id + '&div=' + id + '&mod=' + modify;
2157 var action = new Ajax.Request(
2158 "ajax_misc.php",
2159 {
2160 method: 'get',
2161 parameters: querystring,
2162 onFailure: error_box,
2163 onSuccess: function (req) {
2164 try {
2165 if (req.responseText === 'NOCONX') {
2166 reconnect();
2167 return;
2168 }
2169 remove_waiting_box();
2170 var answer = req.responseXML;
2171 var ctl = answer.getElementsByTagName('ctl');
2172 if (ctl.length == 0) {
2173 throw 'ajax failed ctl view_action';
2174 }
2175 var ctl_txt = getNodeText(ctl[0]);
2176 var html = answer.getElementsByTagName('code');
2177 if (html.length === 0) {
2178 var rec = req.responseText;
2179 throw 'ajax failed html view_action';
2180 }
2181 var code_html = getNodeText(html[0]);
2182 code_html = unescape_xml(code_html);
2183 var pos = fixed_position(0, 50) + ";width:90%;left:5%;z-index:"+layer+";";
2184 add_div({
2185 id: id,
2186 cssclass: "inner_box",
2187 style: pos
2188 });
2189 id$(id).innerHTML = code_html;
2190 if (ctl_txt == 'ok') {
2191 // compute detail
2192 var detail = in_child(id, "follow_up_detail");
2193 if (detail) {
2194 compute_all_ledger();
2195 }
2196
2197
2198 }
2199 code_html.evalScripts();
2200 } catch (e) {
2201 alert_box('view_action' + e.message);
2202 }
2203 }
2204 }
2205 );
2206}
2207
2208/**
2209 * filter quickly a table
2210 * @param phrase : phrase to seach
2211 * @param _id : id of the table
2212 * @param colnr : string containing the column number where you're searching separated by a comma
2213 * @param start_row : first row (1 if you have table header)
2214 * @param class 2nd filter on the CSS CLASS of the row (TR), domid of the TAG containing the classname (TagName: SELECT, HIDDEN, TEXT )
2215 * @returns nothing
2216 * @see HtmlInput::filter_table
2217 */
2218function filter_table(phrase, _id, colnr, start_row,classname) {
2219 id$('info_div').innerHTML = content[65];
2220 id$('info_div').style.display = "block";
2221 var words = id$(phrase).value.toLowerCase();
2222 var table = document.getElementById(_id);
2223
2224 // if colnr contains a comma then check several columns
2225 var aCol = new Array();
2226 if (colnr.indexOf(',') >= 0) {
2227 aCol = colnr.split(',');
2228 } else {
2229 aCol[0] = colnr;
2230 }
2231 var ele;
2232 var tot_found = 0;
2233 var row_class="";
2234 if ( classname ) row_class=id$(classname).value;
2235
2236 for (var r = start_row; r < table.rows.length; r++)
2237 {
2238 if ( row_class != "" && ! table.rows[r].hasClassName(row_class)) {
2239 continue;
2240 }
2241 var found = 0;
2242 for (var col = 0; col < aCol.length; col++) {
2243 var idx = aCol[col];
2244 if (table.rows[r].cells[idx]) {
2245 ele = table.rows[r].cells[idx].innerHTML.replace(/<[^>]+>/g, "");
2246 //var displayStyle = 'none';
2247 if (ele.toLowerCase().indexOf(words) >= 0) {
2248 found = 1;
2249 }
2250 }
2251
2252 }
2253 if (found === 1) {
2254 tot_found++;
2255 table.rows[r].style.display = '';
2256 } else {
2257 table.rows[r].style.display = 'none';
2258 }
2259 id$('info_div').style.display = "none";
2260 id$('info_div').innerHTML = "";
2261 }
2262 if (tot_found == 0) {
2263 if (document.getElementById('info_' + _id)) {
2264 id$('info_' + _id).innerHTML = content[69];
2265 id$('info_' + _id).style.display = 'inline-block';
2266 }
2267 } else {
2268 if (document.getElementById('info_' + _id)) {
2269 id$('info_' + _id).innerHTML = " ";
2270 id$('info_' + _id).style.display = 'none';
2271 }
2272 }
2273 id$('info_div').style.display = "none";
2274 id$('info_div').innerHTML = "";
2275}
2276
2277/**
2278 * filter quickly a list, the content to check must be inside a SPAN with the CLASS "search-content"
2279 * @param phrase : DOM id of the input text where we find the word to seach, the searchable content use the className searchContent
2280 * @param _id : id of the list
2281 * @returns nothing
2282 * @see HtmlInput::filter_list
2283 */
2284function filter_list(phrase, _id) {
2285 id$('info_div').innerHTML = content[65];
2286 id$('info_div').style.display = "block";
2287 var words = id$(phrase).value.toLowerCase();
2288 var l_list = document.getElementById(_id);
2289
2290
2291 var tot_found = 0;
2292
2293 for (var r = 0; r < l_list.childNodes.length; r++) {
2294 var found = 0;
2295
2296 if (l_list.childNodes[r].nodeType != 1) {
2297 continue;
2298 }
2299 let ele = "";
2300 let la_content = l_list.childNodes[r].getElementsByClassName("search-content");
2301
2302 let e = 0;
2303 for (e = 0; e < la_content.length; e++) {
2304 ele += la_content[e].innerText;
2305 }
2306
2307
2308 if (ele.toLowerCase().indexOf(words) >= 0) {
2309 tot_found++;
2310 l_list.childNodes[r].style.display = 'block';
2311 } else {
2312 l_list.childNodes[r].style.display = 'none';
2313 }
2314
2315 }
2316 if (tot_found == 0) {
2317 if (document.getElementById('info_' + _id)) {
2318 id$('info_' + _id).innerHTML = content[69];
2319 }
2320 } else {
2321 if (document.getElementById('info_' + _id)) {
2322 id$('info_' + _id).innerHTML = " ";
2323 }
2324 }
2325 id$('info_div').style.display = "none";
2326 id$('info_div').innerHTML = "";
2327}
2328
2329/**
2330 * filter quickly a select
2331 * @param phrase : DOM id of the input text where we find the word to seach
2332 * @param _id : id of the list
2333 * @returns nothing
2334 * @see HtmlInput::filter_list
2335 */
2336function filter_multiselect(phrase, _id) {
2337 id$('info_div').innerHTML = content[65];
2338 id$('info_div').style.display = "block";
2339 var words = id$(phrase).value.toLowerCase();
2340 var l_list = document.getElementById(_id);
2341
2342 var tot_found = 0;
2343
2344 for (var r = 0; r < l_list.options.length; r++) {
2345 var found = 0;
2346 var ele = l_list.options[r].text;
2347
2348 if (ele.toLowerCase().indexOf(words) >= 0) {
2349 tot_found++;
2350 l_list.options[r].style.display = 'block';
2351 } else {
2352 l_list.options[r].style.display = 'none';
2353 }
2354 id$('info_div').style.display = "none";
2355 id$('info_div').innerHTML = "";
2356 }
2357 if (tot_found == 0) {
2358 if (document.getElementById('info_' + _id)) {
2359 id$('info_' + _id).innerHTML = content[69];
2360 }
2361 } else {
2362 if (document.getElementById('info_' + _id)) {
2363 id$('info_' + _id).innerHTML = " ";
2364 }
2365 }
2366}
2367
2368/**
2369 *
2370 * Display the task late or for today in dashboard
2371 */
2372function display_task(p_id) {
2373
2374 id$(p_id).style.top = posY + 'px';
2375 id$(p_id).style.left = "10%";
2376 id$(p_id).style.width = "80%";
2377 id$(p_id).style.display = 'block';
2378
2379}
2380
2381/**
2382 *
2383 * Set a message in the info
2384 */
2385function info_message(p_message) {
2386 id$('info_div').innerHTML = p_message;
2387 id$('info_div').style.display = "block";
2388}
2389
2390/**
2391 * hide the info box
2392 */
2393function info_hide() {
2394 id$('info_div').style.display = "none";
2395}
2396
2397/**
2398 * Show the navigator in a internal window
2399 * @returns {undefined}
2400 */
2401function ask_navigator(p_dossier) {
2402 try {
2403 waiting_box();
2404 removeDiv('navi_div')
2405 var queryString = "gDossier=" + p_dossier + "&op=navigator";
2406 var action = new Ajax.Request(
2407 "ajax_misc.php",
2408 {
2409 method: 'get', parameters: queryString,
2410 onFailure: ajax_misc_failure,
2411 onSuccess: function (req) {
2412 remove_waiting_box();
2413 add_div({id: 'navi_div', style: 'top:2em;z-index:'+get_next_layer(), cssclass: 'inner_box'});
2414 id$('navi_div').innerHTML = req.responseText;
2415 try {
2416 req.responseText.evalScripts();
2417 sorttable.makeSortable(id$("navi_tb"));
2418 } catch (e) {
2419 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2420 }
2421
2422 }
2423 }
2424 );
2425 } catch (e) {
2426 info_message(e.message);
2427 }
2428
2429}
2430
2431/**
2432 * Display an internal windows to set the user's preference
2433 *
2434 */
2435function set_preference(p_dossier) {
2436 try {
2437 waiting_box();
2438 removeDiv('preference_div')
2439 var queryString = "gDossier=" + p_dossier + "&op=preference";
2440 var action = new Ajax.Request(
2441 "ajax_misc.php",
2442 {
2443 method: 'get', parameters: queryString,
2444 onFailure: ajax_misc_failure,
2445 onSuccess: function (req) {
2446 remove_waiting_box();
2447 if (req.responseText === 'NOCONX') {
2448 reconnect();
2449 return;
2450 }
2451 add_div({id: 'preference_div', style: 'z-index:'+get_next_layer(), drag: 1});
2452 id$('preference_div').innerHTML = req.responseText;
2453 try {
2454 req.responseText.evalScripts();
2455 } catch (e) {
2456 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2457 }
2458
2459 }
2460 }
2461 );
2462 } catch (e) {
2463 info_message(e.message);
2464 }
2465
2466}
2467////////////////////////////////////////////////////////
2468/**
2469 *@class Bookmark
2470 */
2471
2472////////////////////////////////////////////////////////
2473var Bookmark = function() {
2474
2475}
2476/**
2477 * Display user's bookmark
2478 * @param p_dossier {int} Dossier id
2479 */
2480 Bookmark.prototype.show = function (p_dossier) {
2481 try {
2482 waiting_box();
2483 removeDiv('bookmark_div');
2484 var param = window.location.search;
2485 param = param.gsub('?', '');
2486 var queryString = "gDossier=" + p_dossier + "&op=bookmark&" + param;
2487 var action = new Ajax.Request(
2488 "ajax_misc.php",
2489 {
2490 method: 'get', parameters: queryString,
2491 onFailure: ajax_misc_failure,
2492 onSuccess: function (req) {
2493 remove_waiting_box();
2494 add_div({id: 'bookmark_div', cssclass: 'inner_box',style: 'z-index:'+get_next_layer(), drag: 1});
2495 id$('bookmark_div').innerHTML = req.responseText;
2496 try {
2497 req.responseText.evalScripts();
2498 } catch (e) {
2499 alert_box(content[53] + "\n" + e.message);
2500 }
2501 id$('lk_bookmark_tb').focus();
2502
2503 }
2504 }
2505 );
2506 } catch (e) {
2507 info_message(e.message);
2508 }
2509
2510}
2511/**
2512 * save the bookmark
2513 */
2514Bookmark.prototype.save = function () {
2515 try {
2516 waiting_box();
2517 var queryString = "op=bookmark&" + id$("bookmark_frm").serialize();
2518 var action = new Ajax.Request(
2519 "ajax_misc.php",
2520 {
2521 method: 'get', parameters: queryString,
2522 onFailure: ajax_misc_failure,
2523 onSuccess: function (req) {
2524 remove_waiting_box();
2525 // removeDiv('bookmark_div');
2526 //
2527 id$('bookmark_div').innerHTML = req.responseText;
2528 try {
2529 req.responseText.evalScripts();
2530 } catch (e) {
2531 alert_box(content[53] + "\n" + e.message);
2532 }
2533
2534 }
2535 }
2536 );
2537 } catch (e) {
2538 info_message(e.message);
2539 }
2540
2541}
2542
2543/**
2544 * remove selected bookmark
2545 */
2546Bookmark.prototype.remove= function () {
2547 try {
2548 waiting_box();
2549 var queryString = "op=bookmark&" + id$("bookmark_del_frm").serialize();
2550 var action = new Ajax.Request(
2551 "ajax_misc.php",
2552 {
2553 method: 'get', parameters: queryString,
2554 onFailure: ajax_misc_failure,
2555 onSuccess: function (req) {
2556 remove_waiting_box();
2557 id$('bookmark_div').innerHTML = req.responseText;
2558 try {
2559 req.responseText.evalScripts();
2560 } catch (e) {
2561 alert_box(content[53] + "\n" + e.message);
2562 }
2563
2564 }
2565 }
2566 );
2567 } catch (e) {
2568 error_message(e.message);
2569 }
2570
2571}
2572
2573/**
2574 * display the error message into the div error_content_div (included into error_div)
2575 *@param message message to display
2576 *@note there is no protection
2577 */
2578function error_message(message) {
2579 id$('error_content_div').innerHTML = message;
2580 id$('error_div').style.visibility = 'visible';
2581}
2582
2583/**
2584 * show the detail of a tag and propose to save it
2585 */
2586function show_tag(p_dossier, p_ac, p_tag_id, p_post) {
2587 try {
2588 waiting_box();
2589 var queryString = "op=tag_detail&tag=" + p_tag_id + "&gDossier=" + p_dossier + "&ac=" + p_ac + '&form=' + p_post;
2590 var action = new Ajax.Request(
2591 "ajax_misc.php",
2592 {
2593 method: 'get', parameters: queryString,
2594 onFailure: ajax_misc_failure,
2595 onSuccess: function (req) {
2596 var answer = req.responseXML;
2597 var html = answer.getElementsByTagName('code');
2598 if (html.length === 0) {
2599 var rec = req.responseText;
2600 alert_box('erreur :' + rec);
2601 }
2602 var code_html = getNodeText(html[0]);
2603 code_html = unescape_xml(code_html);
2604 remove_waiting_box();
2605 var posy = calcy(250);
2606 add_div({id: 'tag_div', cssclass: 'inner_box', drag: 0, style: "position:fixed;top:15%;"});
2607 id$('tag_div').innerHTML = code_html;
2608 try {
2609 code_html.evalScripts();
2610 } catch (e) {
2611 alert_box(content[53] + "\n" + e.message);
2612 }
2613
2614 }
2615 }
2616 );
2617 } catch (e) {
2618 error_message(e.message);
2619 }
2620}
2621
2622/**
2623 * save the modified tag
2624 */
2625function save_tag() {
2626 try {
2627 waiting_box();
2628 var queryString = "op=tag_save&" + id$("tag_detail_frm").serialize();
2629 var action = new Ajax.Request(
2630 "ajax_misc.php",
2631 {
2632 method: 'get',
2633 parameters: queryString,
2634 onFailure: ajax_misc_failure,
2635 onSuccess: function (req, j) {
2636 remove_waiting_box();
2637 removeDiv('tag_div');
2638 }
2639 }
2640 );
2641 } catch (e) {
2642 error_message(e.message);
2643 return false;
2644 }
2645 return false;
2646
2647}
2648
2649/**
2650 * Show a list of tag which can be added to the current followup document
2651 * @param {type} p_dossier
2652 * @param {type} ag_id
2653 * @returns {undefined}
2654 */
2655function action_tag_select(p_dossier, ag_id) {
2656 try {
2657 waiting_box();
2658 var queryString = "ag_id=" + ag_id + "&op=tag_list&gDossier=" + p_dossier;
2659 var action = new Ajax.Request(
2660 "ajax_misc.php",
2661 {
2662 method: 'get', parameters: queryString,
2663 onFailure: ajax_misc_failure,
2664 onSuccess: function (req, j) {
2665 var answer = req.responseXML;
2666 var html = answer.getElementsByTagName('code');
2667 if (html.length === 0) {
2668 var rec = unescape_xml(req.responseText);
2669 error_message('erreur :' + rec);
2670 }
2671 var code_html = getNodeText(html[0]);
2672 code_html = unescape_xml(code_html);
2673 var pos = fixed_position(35, 229);
2674 add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
2675
2676 remove_waiting_box();
2677 id$('tag_div').innerHTML = code_html;
2678 }
2679 }
2680 );
2681 } catch (e) {
2682 error_message(e.message);
2683 }
2684}
2685
2686/**
2687 * Add the current tag to the current ag_id
2688 * @param {type} p_dossier
2689 * @param {type} ag_id
2690 * @param p_isgroup g it is a group , t is a single tag
2691 * @returns {undefined}
2692 */
2693function action_tag_add(p_dossier, ag_id, t_id, p_isgroup) {
2694 try {
2695 waiting_box();
2696 var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_add&gDossier=" + p_dossier + "&isgroup=" + p_isgroup;
2697 var action = new Ajax.Request(
2698 "ajax_misc.php",
2699 {
2700 method: 'get', parameters: queryString,
2701 onFailure: ajax_misc_failure,
2702 onSuccess: function (req, j) {
2703 var answer = req.responseXML;
2704 var html = answer.getElementsByTagName('code');
2705 if (html.length === 0) {
2706 var rec = unescape_xml(req.responseText);
2707 error_message('erreur :' + rec);
2708 }
2709 var code_html = getNodeText(html[0]);
2710 code_html = unescape_xml(code_html);
2711 remove_waiting_box();
2712 id$('action_tag_td').innerHTML = code_html;
2713 removeDiv('tag_div');
2714 }
2715 }
2716 );
2717 } catch (e) {
2718 error_message(e.message);
2719 }
2720}
2721
2722/**
2723 * remove the current tag to the current ag_id
2724 * @param {type} p_dossier
2725 * @param {type} ag_id
2726 * @returns {undefined}
2727 */
2728function action_tag_remove(p_dossier, ag_id, t_id) {
2729 confirm_box(null, content[50], function () {
2730 try {
2731 waiting_box();
2732 var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_remove&gDossier=" + p_dossier;
2733 var action = new Ajax.Request(
2734 "ajax_misc.php",
2735 {
2736 method: 'get', parameters: queryString,
2737 onFailure: ajax_misc_failure,
2738 onSuccess: function (req) {
2739 var answer = req.responseXML;
2740 var html = answer.getElementsByTagName('code');
2741 if (html.length === 0) {
2742 var rec = unescape_xml(req.responseText);
2743 error_message('erreur :' + rec);
2744 }
2745 var code_html = getNodeText(html[0]);
2746 code_html = unescape_xml(code_html);
2747 remove_waiting_box();
2748 id$('action_tag_td').innerHTML = code_html;
2749
2750 }
2751 }
2752 );
2753 } catch (e) {
2754 error_message(e.message);
2755 }
2756 });
2757}
2758
2759/**
2760 * Activate a tag
2761 * @param int p_dossier
2762 * @param int p_tag_id
2763 */
2764function activate_tag(p_dossier, p_tag_id) {
2765 waiting_box();
2766 new Ajax.Request("ajax_misc.php",
2767 {
2768 method: "get",
2769 parameters: {gDossier: p_dossier, op: 'tag_activate', t_id: p_tag_id},
2770 onSuccess: function (req) {
2771 remove_waiting_box();
2772 var answer = req.responseText.evalJSON();
2773 var tagId = "tag_onoff" + p_tag_id;
2774 id$(tagId).update(answer.code);
2775 id$(tagId).setStyle(answer.style);
2776 remove_waiting_box();
2777 }
2778 })
2779}
2780
2781/**
2782 * Display a div with available tags, this div can update the cell
2783 * tag_choose_td
2784 * @param {type} p_dossier
2785 * @param {string} p_prefix is the prefix of the div
2786 * @param {string} Calling object either Tag_Operation or Tag_Action
2787 * @returns {undefined}
2788 *
2789 */
2790function search_display_tag(p_dossier, p_prefix, p_object) {
2791 try {
2792 waiting_box();
2793 var queryString = {op: "search_display_tag", gDossier: p_dossier, pref: p_prefix, caller_obj: p_object};
2794 var action = new Ajax.Request(
2795 "ajax_misc.php",
2796 {
2797 method: 'get', parameters: queryString,
2798 onFailure: ajax_misc_failure,
2799 onSuccess: function (req, j) {
2800 var answer = req.responseXML;
2801 var html = answer.getElementsByTagName('code');
2802 if (html.length === 0) {
2803 var rec = unescape_xml(req.responseText);
2804 error_message('erreur :' + rec);
2805 }
2806 var code_html = getNodeText(html[0]);
2807 code_html = unescape_xml(code_html);
2808 remove_waiting_box();
2809 add_div({id: p_prefix + 'tag_div', style: 'left:10%;width:70%', cssclass: 'inner_box', drag: 1});
2810 id$(p_prefix + 'tag_div').style.top = calcy(200) + "px"
2811 id$(p_prefix + 'tag_div').style.left = 20 + "%";
2812 remove_waiting_box();
2813 id$(p_prefix + 'tag_div').innerHTML = code_html;
2814 code_html.evalScripts();
2815 }
2816 }
2817 );
2818 } catch (e) {
2819 error_message(e.message);
2820 }
2821}
2822
2823/**
2824 * Add the selected tag (p_tag_id) to the cell of tag_choose_td in the search screen
2825 * in the search screen
2826 * @param {type} p_dossier
2827 * @param {type} p_tag_id
2828 * @param p_prefix is the prefix of the widget
2829 * @param p_obj is either g for group of tag or t for a single tag
2830 */
2831function search_add_tag(p_dossier, p_tag_id, p_prefix, p_obj) {
2832 try {
2833 var clear_button = 0;
2834 if (tag_choose === '' && p_prefix === 'search') {
2835 tag_choose = id$(p_prefix + 'tag_choose_td').innerHTML;
2836 clear_button = 1;
2837 }
2838 waiting_box();
2839 var queryString = "op=search_add_tag&gDossier=" + p_dossier + "&id=" + p_tag_id + "&clear=" + clear_button + '&pref=' + p_prefix + "&obj=" + p_obj;
2840 var action = new Ajax.Request(
2841 "ajax_misc.php",
2842 {
2843 method: 'get', parameters: queryString,
2844 onFailure: ajax_misc_failure,
2845 onSuccess: function (req, j) {
2846 var answer = req.responseXML;
2847 var html = answer.getElementsByTagName('html');
2848 if (html.length === 0) {
2849 var rec = unescape_xml(req.responseText);
2850 error_message('erreur :' + rec);
2851 }
2852 var code_html = getNodeText(html[0]);
2853 code_html = unescape_xml(code_html);
2854 remove_waiting_box();
2855 id$(p_prefix + 'tag_choose_td').innerHTML = id$(p_prefix + 'tag_choose_td').innerHTML + code_html;
2856 removeDiv(p_prefix + 'tag_div');
2857 }
2858 }
2859 );
2860 } catch (e) {
2861 error_message(e.message);
2862 }
2863}
2864
2865/**
2866 * Clear the tags in the cell tag_choose_td of the search screen
2867 * @returns {undefined}
2868 */
2869function search_clear_tag(p_dossier, p_prefix) {
2870 if (p_prefix != 'search') {
2871 id$(p_prefix + 'tag_choose_td').innerHTML = "";
2872 return;
2873 }
2874 try {
2875 var queryString = "op=search_clear_tag&gDossier=" + p_dossier + "&pref=" + p_prefix;
2876 var action = new Ajax.Request(
2877 "ajax_misc.php",
2878 {
2879 method: 'get', parameters: queryString,
2880 onFailure: ajax_misc_failure,
2881 onSuccess: function (req, j) {
2882 var answer = req.responseXML;
2883 var html = answer.getElementsByTagName('html');
2884 if (html.length === 0) {
2885 var rec = unescape_xml(req.responseText);
2886 error_message('erreur :' + rec);
2887 }
2888 var code_html = getNodeText(html[0]);
2889 code_html = unescape_xml(code_html);
2890 id$(p_prefix + 'tag_choose_td').innerHTML = code_html;
2891 tag_choose = "";
2892 }
2893 }
2894 );
2895 } catch (e) {
2896 error_message(e.message);
2897 }
2898}
2899
2900function action_show_checkbox() {
2901 var a = document.getElementsByName('ag_id_td');
2902 for (var i = 0; i < a.length; i++) {
2903 a[i].style.display = 'block';
2904 }
2905}
2906
2907function action_hide_checkbox() {
2908 var a = document.getElementsByName('ag_id_td');
2909 for (var i = 0; i < a.length; i++) {
2910 a[i].style.display = 'none';
2911 }
2912}
2913
2914/**
2915 *
2916 * @param {type} obj
2917 * object attribute : g
2918 * - Dossier dossier_id,
2919 * - invalue DOM Element where you can find the periode to zoom
2920 * - outdiv ID of the target (DIV)
2921 *
2922 */
2923function calendar_zoom(obj) {
2924 try {
2925 waiting_box();
2926 var per_periode = null;
2927 var notitle = 0;
2928 var from = 0;
2929 if (id$(obj.invalue)) {
2930 per_periode = id$(obj.invalue).value;
2931 }
2932 if (obj.notitle && obj.notitle == 1) {
2933 notitle = 1;
2934 }
2935 var action = new Ajax.Request(
2936 "ajax_misc.php",
2937 {
2938 method: 'get',
2939 parameters: {
2940 "notitle": notitle,
2941 "op": 'calendar_zoom',
2942 'from': from,
2943 'gDossier': obj.gDossier,
2944 'in': per_periode,
2945 'out': obj.outdiv,
2946 'distype': obj.distype
2947 },
2948 onFailure: ajax_misc_failure,
2949 onSuccess: function (req, j) {
2950 if (req.responseText === 'NOCONX') {
2951 reconnect();
2952 return;
2953 }
2954 var answer = req.responseXML;
2955 var html = answer.getElementsByTagName('html');
2956 if (html.length === 0) {
2957 var rec = unescape_xml(req.responseText);
2958 error_message('erreur :' + rec);
2959 }
2960 var code_html = getNodeText(html[0]);
2961 code_html = unescape_xml(code_html);
2962
2963 // if the target doesn't exist
2964 // then create it
2965 if (obj.outdiv === undefined) {
2966 obj.outdiv = 'calendar_zoom_div';
2967 }
2968 if (id$(obj.outdiv) == undefined) {
2969 var str_style = 'top:10%;min-height:60rem';
2970// var str_style = fixed_position(0, 120);
2971 add_div({
2972 id: obj.outdiv,
2973 style: 'width:94%;' + str_style,
2974 cssclass: "inner_box",
2975 drag: 0
2976 });
2977 }
2978 remove_waiting_box();
2979 id$(obj.outdiv).innerHTML = code_html;
2980 id$(obj.outdiv).show();
2981 }
2982 }
2983 );
2984 } catch (e) {
2985 error_message('calendar_zoom ' + e.message);
2986 }
2987
2988
2989}
2990
2991/**
2992 * add a line in the form for the stock
2993 */
2994function stock_add_row() {
2995 try {
2996 style = 'class="input_text"';
2997 var mytable = id$("stock_tb").tBodies[0];
2998 var ofirstRow = mytable.rows[1];
2999 var line = mytable.rows.length;
3000 var nCell = mytable.rows[1].cells.length;
3001 var row = mytable.insertRow(line);
3002 var nb = id$("row");
3003 for (var e = 0; e < nCell; e++) {
3004 var newCell = row.insertCell(e);
3005 if (mytable.rows[1].cells[e].hasClassName('num')) {
3006 newCell.addClassName("num");
3007 }
3008
3009 var tt = ofirstRow.cells[e].innerHTML;
3010 var new_tt = tt.replace(/sg_code0/g, "sg_code" + nb.value);
3011 new_tt = new_tt.replace(/sg_quantity0/g, "sg_quantity" + nb.value);
3012 new_tt = new_tt.replace(/label0/g, "label" + nb.value);
3013 newCell.innerHTML = new_tt;
3014 new_tt.evalScripts();
3015 }
3016
3017 id$("sg_code" + nb.value).innerHTML = '&nbsp;';
3018 id$("sg_code" + nb.value).value = '';
3019 id$("label" + nb.value).innerHTML = '';
3020 id$("sg_quantity" + nb.value).value = '0';
3021
3022 nb.value++;
3023
3024 new_tt.evalScripts();
3025 } catch (e) {
3026 alert_box(e.message);
3027 }
3028
3029}
3030
3031function show_description(p_id) {
3032 id$('print_desc' + p_id).hide();
3033 id$('input_desc' + p_id).show();
3034
3035}
3036
3037/**
3038 * Display an empty card to fill , with the right card category
3039 * @param pn_fiche_card_id : fiche_def.fd_id
3040 * @param pn_dossier_id
3041 */
3042function select_cat(pn_fiche_card_id, pn_dossier_id, ps_element_id) {
3043 dis_blank_card({
3044 "ctl": "div_new_card",
3045 "fd_id": pn_fiche_card_id,
3046 "op2": "bc",
3047 "op": "card",
3048 gDossier: pn_dossier_id,
3049 "elementId": ps_element_id
3050 });
3051 removeDiv('select_card_div');
3052}
3053
3054/**
3055 * Show the DIV and hide the other, the array of possible DIV are
3056 * in a_tabs,
3057 * @param {array} a_tabs name of possible tabs
3058 * @param {strng} p_display_tab tab to display
3059 */
3060function show_tabs(a_tabs, p_display_tab) {
3061 try {
3062 if (a_tabs.length == 0) {
3063 console.error('a_tabs in empty');
3064 throw ("a_tabs empty");
3065 return;
3066 }
3067 var i = 0;
3068 for (i = 0; i < a_tabs.length; i++) {
3069 id$(a_tabs[i]).hide();
3070 }
3071 id$(p_display_tab).show();
3072 } catch (e) {
3073 alert_box(e.message);
3074 }
3075
3076}
3077
3078/**
3079 * Change the class of all the "LI" element of a UL or OL
3080 * @param node of ul (this)
3081 */
3082function unselect_other_tab(p_tab) {
3083 try {
3084 var other = p_tab.getElementsByTagName("li");
3085 var i = 0;
3086 var tab = null;
3087 for (i = 0; i < other.length; i++) {
3088 tab = other[i];
3089 tab.className = "tabs";
3090 }
3091 } catch (e) {
3092 if (console)
3093 console.error(e.message);
3094 alert_box('unselect_other_tab ' + e.message);
3095 }
3096}
3097
3098/**
3099 * logout function call from ajax
3100 * @see ajax_disconnected
3101 * @returns {undefined}
3102 */
3103function logout() {
3104 var tmp_place = window.location.href
3105 var tmp_b = tmp_place.split('/')
3106 var tmp_last = tmp_b.length - 1
3107 var place_logout = tmp_place.replace(tmp_b[tmp_last], 'logout.php');
3108 window.location.href = place_logout;
3109}
3110
3111/**
3112 * Create a div which can be used in a anchor
3113 * @returns {undefined}
3114 */
3115function create_anchor_up() {
3116 if (document.getElementById('up_top'))
3117 return;
3118
3119 var newElt = document.createElement('div');
3120 newElt.setAttribute('id', 'up_top');
3121 newElt.innerHTML = '<a id="up_top"></a>';
3122
3123 var parent = id$('info_div').parentNode;
3124 parent.insertBefore(newElt, id$('info_div'));
3125
3126}
3127
3128/**
3129 * Initialize the window to show the button "UP" if the window is scrolled
3130 * vertically
3131 * @returns {undefined}
3132 */
3133function init_scroll() {
3134 var up = new Element('div', {
3135 "class": "",
3136 "style": "padding:5px;left:auto;width:auto;height: auto;display:none;position:fixed;bottom:30%;right:50px;text-align:center;font-size:20px",
3137 id: "go_up"
3138 });
3139 up.innerHTML = '<a class="icon" onclick="document.getElementById(\'go_up\').hide()" style="float:right;font-size:70%">&#xe816;</a> <a class="icon" href="#up_top" >&#xe81a;</a><a href="javascript:show_calc()" class="icon">&#xf1ec;</a>';
3140 document.body.appendChild(up);
3141 window.onscroll = function () {
3142 if (document.getElementById("select_box_content")) {
3143 document.getElementById("select_box_content").setStyle({display: "none"})
3144 }
3145 ;
3146 if (document.viewport.getScrollOffsets().top > 0) {
3147 if (id$('go_up').visible() == false) {
3148 id$('go_up').setOpacity(0.65);
3149 id$('go_up').show();
3150 id$('go_up').style.zIndex = 99;
3151 }
3152 } else {
3153 id$('go_up').hide();
3154 }
3155 }
3156
3157}
3158function loading_page() {
3159 var id_page = new Element('div', {
3160 "class": "",
3161 "style": "padding: 5px;\n" +
3162 " width: 300px;\n" +
3163 " height: 60px;\n" +
3164 " display: block;\n" +
3165 " position: fixed;\n" +
3166 " bottom: 50px;\n" +
3167 " left: 50px;\n" +
3168 " text-align: center;\n" +
3169 " animation-name: fill_up_loading;\n" +
3170 " animation-duration: 8s;\n" +
3171 " animation-iteration-count: infinite;"+
3172 "opacity: 0.7;"+
3173 "border-radius: 5px;"+
3174 "font-size: 300%;"+
3175 "animation-timing-function: linear;",
3176 id: "loading_page_div"
3177 });
3178 id_page.update('<div class="loading_msg"></div><div class="loading_msg"></div><div class="loading_msg"></div><div class="loading_msg"></div><div class="loading_msg"></div>');
3179 document.body.appendChild(id_page);
3180}
3181/**
3182 * Confirm a form thanks a modal dialog Box, it returns true if we agree otherwise
3183 * false
3184 * @code
3185 <form onsubmit="return confirm_box(this,'message')">
3186 </form>
3187 * @endcode
3188 * @param p_obj form element (object) or element id (string)
3189 * @param p_message message to display
3190 * @param p_callback_true callback function or null
3191 * @param p_waiting if true display a waiting box
3192 * @returns true or false
3193 */
3194function confirm_box(p_obj, p_message, p_callback_true, p_waiting) {
3195 waiting_box();
3196 try {
3197 // Find id of the end
3198 var name = "";
3199 if (p_obj != null) {
3200 if (typeof (p_obj) === "object") {
3201 name = p_obj.id;
3202 } else {
3203 name = p_obj;
3204 }
3205 }
3206
3207 // execute the callback function or submit the form
3208 if (!p_callback_true) {
3209
3210 smoke.confirm(p_message, function (e) {
3211 if (e) {
3212 if (p_waiting) {
3213 waiting_box();
3214 }
3215 id$(name).submit();
3216 }
3217 });
3218 } else {
3219 smoke.confirm(p_message, function (e) {
3220 if (e) {
3221 p_callback_true.apply();
3222 }
3223 });
3224 }
3225 } catch (e) {
3226 alert_box(e.message);
3227 }
3228 remove_waiting_box();
3229 return false;
3230}
3231
3232/**
3233 * Alert box in CSS and HTML to replace the common javascript alert
3234 * @param p_message message to display
3235 * @returns void
3236 */
3237function alert_box(p_message) {
3238 smoke.alert(p_message, undefined, {ok: 'ok', classname: "inner_box",title:'ATTENTION'});
3239}
3240
3241
3242/**
3243 * Colorize the rows of the table
3244 * @param string p_table id of the table
3245 */
3246function alternate_row_color(p_table) {
3247 var table_colored = id$(p_table);
3248 if (!table_colored.tBodies[0]) return;
3249
3250 var len = table_colored.tBodies[0].rows.length;
3251 var i = 0;
3252 var localClass = "";
3253 for (i = 1; i < len; i++) {
3254 localClass = (i % 2 == 0) ? "even" : "odd";
3255 if (table_colored.tBodies[0].rows[i].hasClassName("odd")) {
3256 table_colored.tBodies[0].rows[i].removeClassName("odd");
3257 }
3258 if (table_colored.tBodies[0].rows[i].hasClassName("even")) {
3259 table_colored.tBodies[0].rows[i].removeClassName("even");
3260 }
3261 table_colored.tBodies[0].rows[i].addClassName(localClass);
3262 }
3263
3264}
3265/**
3266 * Colorize the rows of the list
3267 * @param p_list {string} DOM id of the list
3268 */
3269function alternate_row_color_list(p_list) {
3270 var list_colored = id$(p_list);
3271 if ( list_colored.children.length==0 ) return;
3272
3273 var len = list_colored.children.length;
3274 var i = 0;
3275 var localClass = "";
3276 for (i = 1; i < len; i++) {
3277 localClass = (i % 2 == 0) ? "even" : "odd";
3278 if (list_colored.children[i].hasClassName("odd")) {
3279 list_colored.children[i].removeClassName("odd");
3280 }
3281 if (list_colored.children[i].hasClassName("even")) {
3282 list_colored.children[i].removeClassName("even");
3283 }
3284 list_colored.children[i].addClassName(localClass);
3285 }
3286
3287}
3288
3289
3290/**
3291 * Make an DOM element draggable or not
3292 * @param object_id DOM id
3293 */
3294function pin(object_id) {
3295 if (aDraggableElement[object_id]) {
3296 aDraggableElement[object_id].destroy();
3297 aDraggableElement[object_id] = undefined;
3298 id$('pin_' + object_id).innerHTML = "&#xf047;";
3299 } else {
3300 aDraggableElement[object_id] = new Draggable(object_id, {
3301 starteffect: function () {
3302 new Effect.Highlight(object_id, {scroll: window, queue: 'end'});
3303 }
3304 }
3305 );
3306 id$('pin_' + object_id).innerHTML = "&#xe809;";
3307 }
3308}
3309
3310/**
3311 * Show only the rows into the table (p_table_id) with the attribute (p_attribute_name) and if this attribute
3312 * has the value of (attribut_value)
3313 * @param p_table_id table id
3314 * @param p_attribute_name the name of the attribute
3315 * @param p_attribute_value the value of the attribute we want to show
3316 */
3317function show_only_row(p_table_id, p_attribute_name, p_attribute_value) {
3318 if (!id$(p_table_id)) {
3319 throw "Invalide table id"
3320 }
3321 var mTable = id$(p_table_id);
3322 var ncount = mTable.rows.length
3323 for (var i = 0; i < ncount; i++) {
3324 var mRow = mTable.rows[i];
3325 if (mRow.getAttribute(p_attribute_name) != undefined && mRow.getAttribute(p_attribute_name) != p_attribute_value) {
3326 mRow.hide();
3327 } else {
3328 mRow.show();
3329 }
3330 }
3331}
3332
3333/**
3334 * Show all the rows into the table (p_table_id)
3335 * @param p_table_id table id
3336 */
3337function show_all_row(p_table_id) {
3338 if (!id$(p_table_id)) {
3339 throw "Invalide table id"
3340 }
3341 var mTable = id$(p_table_id);
3342 var ncount = mTable.rows.length
3343 for (var i = 0; i < ncount; i++) {
3344 var mRow = mTable.rows[i];
3345 mRow.show();
3346 }
3347
3348}
3349
3350/**
3351 * @class
3352 * Periode handling
3353 * Variables :
3354 * id of the row of the periode row_per_(p_periode_id) , attribute exercice =per_exercice,periode_id=p_id
3355 * # (this.dialog)
3356 * # id of the table with the rows : periode_tbl
3357 *
3358 * Members :
3359 * - periode_id the concerned Periode , 0 none
3360 * - p_ledger : the id of ledger (jrn_def.jrn_def_id), 0 for global
3361 * - pcallback : default ajax_misc.php (this.callback) with the parameter { op:'periode',gDossier,[action:display,remove,save],p_id:p_periode_id}
3362 * - dossier
3363 * - js_obj_name : name of the js object (this.js_obj_name)
3364 * - ajax_test : file to include for debugging
3365 * - dialog : id of the dialog box (update / add ) periode_box
3366 *
3367 */
3368var Periode = function (p_ledger) {
3369 this.periode_id = 0;
3370 this.p_ledger = p_ledger;
3371 this.dialog = 'periode_box';
3372 this.pcallback = 'ajax_misc.php';
3373 this.dossier = 0;
3374 this.js_obj_name = "";
3375 this.ajax_test = "";
3376 this.set_callback = function (p_phpfile) {
3377 this.pcallback = p_phpfile;
3378 };
3379 this.set_dossier = function (p_dosid) {
3380 this.dossier = p_dosid;
3381 };
3382 /**
3383 * set_js_obj_name (p_js_obj_name)
3384 * We need to know the javascript variable name , to pass it to ajax and
3385 * create a HTML containing the right variable
3386 * @param p_js_obj_name name of the variable js we use on caller side
3387 */
3388 this.set_js_obj_name = function (p_js_obj_name) {
3389 this.js_obj_name = p_js_obj_name;
3390 };
3391
3392 /**
3393 * Remove the periode , so call new Ajax and hide the row if successful
3394 * otherwise show dialog box.
3395 * @parameter p_periode_id is the id of periode
3396 */
3397 this.remove = function (p_periode_id) {
3398
3399 var js_param = {
3400 "gDossier": this.dossier,
3401 "op": "periode",
3402 "act": "remove",
3403 "p_id": p_periode_id,
3404 "ledger_id": 0,
3405 "js_var": this.js_obj_name
3406 };
3407 if (this.ajax_test != "") {
3408 js_param["TestAjaxFile"] = this.ajax_test;
3409 }
3410 here = this;
3411 smoke.confirm("Confirmer ?", function (e) {
3412 if (e) {
3413 waiting_box();
3414 new Ajax.Request(here.pcallback,
3415 {
3416 method: "POST",
3417 parameters: js_param,
3418 onSuccess: function (req) {
3419 var answer = req.responseText.evalJSON();
3420 remove_waiting_box();
3421 if (answer.status == "OK") {
3422 id$("row_per_" + p_periode_id).remove();
3423 alternate_row_color("periode_tbl");
3424 } else {
3425 smoke.alert(answer.content);
3426 }
3427 }
3428 });
3429 }
3430 });
3431 };
3432
3433 /**
3434 * display a dialog box to update a periode, call save either display
3435 * an error box or update the row.
3436 * the name of variable is requested
3437 * to build the right button , javascript in the html of answer
3438 * @parameter p_periode_id is the id of periode
3439 */
3440 this.box_display = function (p_periode_id) {
3441 if (this.js_obj_name == "") {
3442 smoke.alert("ERROR BOX_ADD")
3443 }
3444
3445 var js_param = {
3446 "gDossier": this.dossier,
3447 "op": "periode",
3448 "act": "show",
3449 "p_id": p_periode_id,
3450 "ledger_id": this.p_ledger,
3451 "js_var": this.js_obj_name
3452 };
3453 if (this.ajax_test != "") {
3454 js_param["TestAjaxFile"] = this.ajax_test;
3455 }
3456 var here = this;
3457 new Ajax.Request(here.pcallback,
3458 {
3459 method: "POST",
3460 parameters: js_param,
3461 onSuccess: function (req) {
3462 remove_waiting_box();
3463 var json = req.responseText.evalJSON();
3464 var y = 100;
3465 add_div({
3466 "id": "mod_periode",
3467 "style": "position:fixed;top:" + y + "px;width:50%",
3468 "cssclass": "inner_box",
3469 'html': "wait"
3470 });
3471 id$('mod_periode').update(json.content);
3472 }
3473 });
3474 };
3475 /**
3476 * close the periode, call ajax and receive a json object with the attribute
3477 * status, content
3478 * @parameter p_periode_id is the id of periode
3479 */
3480 this.close_periode = function (p_periode_id) {
3481 if (this.js_obj_name == "") {
3482 smoke.alert("ERROR BOX_ADD")
3483 }
3484
3485 if (this.ajax_test != "") {
3486 js_param["TestAjaxFile"] = this.ajax_test;
3487 }
3488 var here = this;
3489 smoke.confirm("Confirmer ?", function (e) {
3490 if (e) {
3491 here._close(p_periode_id);
3492 }
3493 });
3494 };
3495 /**
3496 * Internal function to close without confirming
3497 * @param {type} p_periode_id
3498 * @returns {undefined}
3499 */
3500 this._close = function (p_periode_id) {
3501 if (this.js_obj_name == "") {
3502 smoke.alert("ERROR BOX_ADD")
3503 }
3504 var js_param = {
3505 "gDossier": this.dossier,
3506 "op": "periode",
3507 "act": "close",
3508 "ledger_id": this.p_ledger,
3509 "p_id": p_periode_id,
3510 "js_var": this.js_obj_name
3511 };
3512 if (this.ajax_test != "") {
3513 js_param["TestAjaxFile"] = this.ajax_test;
3514 }
3515 var here = this;
3516 waiting_box();
3517 new Ajax.Request(here.pcallback,
3518 {
3519 method: "POST",
3520 parameters: js_param,
3521 onSuccess: function (req) {
3522 remove_waiting_box();
3523 var json = req.responseText.evalJSON();
3524 if (json.status == 'OK') {
3525 id$('row_per_' + p_periode_id).update(json.content);
3526 new Effect.Highlight('row_per_' + p_periode_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3527 } else {
3528 smoke.alert(json.content);
3529 }
3530 }
3531 });
3532 };
3533 /**
3534 * reopen the periode
3535 * @parameter p_periode_id is the SQL id of parm_periode or the id of
3536 * jrn_periode
3537 */
3538 this.open_periode = function (p_periode_id) {
3539 if (this.js_obj_name == "") {
3540 smoke.alert("ERROR BOX_ADD")
3541 }
3542 var js_param = {
3543 "gDossier": this.dossier,
3544 "op": "periode",
3545 "act": "reopen",
3546 "ledger_id": this.p_ledger,
3547 "p_id": p_periode_id,
3548 "js_var": this.js_obj_name
3549 };
3550 if (this.ajax_test != "") {
3551 js_param["TestAjaxFile"] = this.ajax_test;
3552 }
3553 var here = this;
3554 smoke.confirm("Confirmer ?", function (e) {
3555 if (e) {
3556 waiting_box();
3557 new Ajax.Request(here.pcallback,
3558 {
3559 method: "POST",
3560 parameters: js_param,
3561 onSuccess: function (req) {
3562 remove_waiting_box();
3563 var json = req.responseText.evalJSON();
3564 if (json.status == 'OK') {
3565 id$('row_per_' + p_periode_id).update(json.content);
3566 new Effect.Highlight('row_per_' + p_periode_id, {
3567 startcolor: '#FAD4D4',
3568 endcolor: '#F78082'
3569 });
3570 } else {
3571 smoke.alert(json.content);
3572 }
3573 }
3574 });
3575 }
3576 });
3577 };
3578 /**
3579 * This DOMID of the DIV containing the form is mod_periode
3580 * @param {type} p_frm
3581 * @returns {Boolean}
3582 */
3583 this.save = function (p_frm) {
3584 var js_param = id$(p_frm).serialize(true);
3585 waiting_box();
3586 js_param["js_var"] = this.js_obj_name;
3587 js_param["act"] = "save";
3588 js_param["op"] = "periode";
3589 var here = this;
3590 new Ajax.Request(this.pcallback, {
3591 method: "POST",
3592 parameters: js_param,
3593 onSuccess: function (req) {
3594
3595 var answer = req.responseText.evalJSON();
3596 remove_waiting_box();
3597 if (answer.status == "OK") {
3598 id$('row_per_' + js_param['periode_id']).update(answer.content);
3599 removeDiv('mod_periode');
3600 new Effect.Highlight('row_per_' + js_param['periode_id'], {
3601 startcolor: '#FAD4D4',
3602 endcolor: '#F78082'
3603 });
3604 } else {
3605 smoke.alert(answer.content);
3606 }
3607 }
3608 });
3609 return false;
3610 };
3611 /**
3612 * Thanks the object DOMID sel_per_closed[] the selected periodes are
3613 * closed
3614 * @see Periode._close
3615 */
3616 this.close_selected = function () {
3617 var here = this;
3618 var a_selected = document.getElementsByName('sel_per_close[]');
3619 var count = 0;
3620 var i = 0;
3621 for (i = 0; i < a_selected.length; i++) {
3622 if (a_selected[i].checked == true) {
3623 // Close the selected periode
3624 count++;
3625 }
3626 }
3627 if (count == 0) {
3628 smoke.signal("Sélectionner au moins une période", function () {
3629 }, {duration: 1500});
3630 return;
3631 }
3632 smoke.confirm("Confirmer fermeture de " + count + " periode", function (e) {
3633 if (e) {
3634 var a_selected = document.getElementsByName('sel_per_close[]');
3635 var i = 0;
3636 for (i = 0; i < a_selected.length; i++) {
3637 if (a_selected[i].checked == true) {
3638 // Close the selected periode
3639 here._close(a_selected[i].value);
3640 }
3641 }
3642 }
3643 }
3644 );
3645 };
3646 /**
3647 * Insert a periode into the list, always at the bottom !
3648 * DomId :
3649 * # FORM id :insert_periode_frm
3650 * # DIV id = periode_add
3651 * # table id = periode_tbl
3652 */
3653 this.insert_periode = function () {
3654 var p_frm = 'insert_periode_frm';
3655 var js_param = id$(p_frm).serialize(true);
3656 waiting_box();
3657 js_param["js_var"] = this.js_obj_name;
3658 js_param["act"] = "insert_periode";
3659 js_param["op"] = "periode";
3660 js_param["p_id"] = "-1";
3661 js_param["ledger_id"] = "0";
3662 var here = this;
3663 new Ajax.Request(this.pcallback, {
3664 method: "POST",
3665 parameters: js_param,
3666 onSuccess: function (req) {
3667 var answer = req.responseText.evalJSON();
3668 remove_waiting_box();
3669 if (answer.status == "OK") {
3670 var new_row = document.createElement("tr");
3671 id$('periode_tbl').append(new_row);
3672 new_row.replace(answer.content);
3673
3674 // hide the form
3675 id$('periode_add').hide();
3676 new Effect.Highlight('row_per_' + answer.p_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3677 alternate_row_color('periode_tbl');
3678 } else {
3679 smoke.alert(answer.content);
3680 }
3681 }
3682 });
3683 return false;
3684 }
3685
3686}
3687/**
3688 * Show the periodes from the exercice contained into the id (p_exercice_sel)
3689 * @param p_table_id DOM ID of the table
3690 */
3691Periode.filter_exercice = function (p_table_id) {
3692 var rows = id$(p_table_id).rows;
3693 var selected_value = id$('p_exercice_sel').value;
3694 for (var i = 1; i < rows.length; i++) {
3695 var exercice = rows[i].getAttribute("per_exercice");
3696 if (selected_value == -1) {
3697 rows[i].show();
3698 } else if (selected_value == exercice) {
3699 rows[i].show();
3700 } else {
3701 rows[i].hide();
3702 }
3703
3704 }
3705};
3706
3707// keep track of progress bar
3708var progressBar = [];
3709// idx of progress bar
3710var progressIdx = 0;
3711
3712/**
3713 * Start the progress bar
3714 * @param {string} p_taskid id to monitor
3715 * @param {int} p_message
3716 */
3717function progress_bar_start(p_taskid, p_message) {
3718 try {
3719 progressIdx++;
3720 // block the window
3721
3722 var message = '<p>' + content[70] + '</p>';
3723 if (p_message) {
3724 message = p_message;
3725 }
3726
3727 add_div({id: "blocking" + progressIdx, cssclass: "smoke-base smoke-visible "});
3728
3729 add_div({
3730 id: "message" + progressIdx,
3731 cssclass: "inner_box",
3732 style: "z-index:"+get_next_layer()+";position:fixed;top:30%;width:40%;left:30%"
3733 });
3734 id$("message" + progressIdx).update('<h3>' + content[65] + '</h3>' + message);
3735 // Create a div
3736 add_div({id: "progressDiv" + progressIdx, cssclass: "progressbar", html: '<span id="progressValue">0</span>'});
3737 // Check status every sec.
3738 progressBar[progressIdx] = setInterval(progress_bar_check.bind(null, progressIdx, p_taskid), 1000);
3739 } catch (e) {
3740 console.error(e.message);
3741 }
3742}
3743
3744/**
3745 * Check every second the status
3746 * @param {integer} p_idx idx of progressbar
3747 * @param {string} p_taskid id to monitor
3748 */
3749function progress_bar_check(p_idx, p_taskid) {
3750 try {
3751
3752 new Ajax.Request("ajax_misc.php", {
3753 parameters: {gDossier: 0, task_id: p_taskid, op: "progressBar"},
3754 method: "get",
3755 onSuccess: function (req) {
3756 try {
3757 var answer = req.responseText.evalJSON();
3758 var progress_div = id$("progressDiv" + progressIdx);
3759 var a_child = progress_div.childNodes;
3760 var i = 0;
3761 for (i = 0; i < a_child.length; i++) {
3762 if (a_child[i].id = "progressValue") {
3763 var progressValue = a_child[i];
3764 }
3765 }
3766 var progress = parseFloat(progressValue.innerHTML);
3767 if (answer.value <= progress) {
3768 return;
3769 }
3770
3771 progressValue.innerHTML = answer.value;
3772 progressValue.setStyle("width:" + answer.value + "%");
3773 if (answer.value == 100) {
3774 clearInterval(progressBar[p_idx]);
3775 progressValue.innerHTML = "Success";
3776 Effect.BlindUp("progressDiv" + p_idx, {duration: 1.0, scaleContent: false})
3777 id$("message" + p_idx).remove();
3778 id$("blocking" + p_idx).remove();
3779 setTimeout(function () {
3780 id$("progressDiv" + progressIdx).remove
3781 }, 1100);
3782 }
3783 } catch (e) {
3784 clearInterval(progressBar[p_idx]);
3785 document.getElementById("progressValue").innerHTML = req.responseText;
3786 console.error(e.message);
3787 }
3788 }
3789 });
3790 } catch (e) {
3791 clearInterval(progressBar[p_idx]);
3792 console.error(e.message);
3793 }
3794}
3795
3796/**
3797 * In the user's setting box, update the period list with the choosen exercice
3798 * @param {int} p_dossier
3799 */
3800function updatePeriodePreference(p_dossier) {
3801 waiting_box();
3802 var exercice = id$('exercice_setting').value;
3803 new Ajax.Updater('setting_period', "ajax_misc.php", {
3804 method: "get",
3805 parameters: {"op": "pref_exercice", "gDossier": p_dossier, "exercice": exercice}
3806 });
3807 remove_waiting_box();
3808}
3809
3810/**
3811 * Update the from and to periode list when changing the exercice
3812 * @param {int} p_dossier
3813 * @param {string} p_exercice dom id of the exercice (SELECT)
3814 * @param {type} p_periode_from id of the starting periode
3815 * @param {type} p_periode_to id of the ending periode
3816 * @param {type} p_last possible value = 1 to show last date or 0 the first
3817 */
3818function updatePeriode(p_dossier, p_exercice, p_periode_from, p_periode_to, p_last) {
3819 waiting_box();
3820 var exercice = id$(p_exercice).value;
3821 new Ajax.Updater(p_periode_from, "ajax_misc.php",
3822 {
3823 method: "get",
3824 parameters: {
3825 op: "periode_change", "gDossier": p_dossier, "exercice": exercice,
3826 field: p_periode_from, "type": "from", "last": p_last
3827 }
3828 });
3829 if (p_periode_to && p_last) {
3830 new Ajax.Updater(p_periode_to, "ajax_misc.php",
3831 {
3832 method: "get",
3833 parameters: {
3834 op: "periode_change", "gDossier": p_dossier, "exercice": exercice,
3835 field: p_periode_to, "type": "to", "last": p_last
3836 }
3837 });
3838 }
3839 remove_waiting_box();
3840}
3841
3842/**
3843 *
3844 * @param {string} p_domid DOM id of the span containing the padlock icon
3845 * @returns none
3846 */
3847function toggle_lock(p_domid) {
3848 var padlock = document.getElementById(p_domid);
3849 if (padlock == null) {
3850 console.error("domid invalid");
3851 }
3852 var status = padlock.getAttribute("is_locked");
3853 if (status == 1) {
3854 padlock.innerHTML = "&#xe832;";
3855 padlock.setAttribute("is_locked", 0);
3856 } else if (status == 0) {
3857 padlock.innerHTML = "&#xe831;";
3858 padlock.setAttribute("is_locked", 1);
3859 } else {
3860 throw "toggle_lock failed";
3861 }
3862
3863
3864}
3865
3866/**
3867 *
3868 * @returns {undefined}
3869 */
3870function show_ledger_fin_currency() {
3871 var ledger = id$('p_jrn').value;
3872 var dossier = id$('gDossier').value;
3873 // id$('ledger_currency').
3874 var a = new Ajax.Updater("ledger_currency",
3875 "ajax_misc.php",
3876 {
3877 parameters: {"op": "currencyCode", "gDossier": dossier, "ledger": ledger}
3878 });
3879}
3880
3881/***
3882 * Update Preference, applied the new CSS
3883 */
3884function updatePreference() {
3885 try {
3886 waiting_box();
3887 var param = id$('preference_frm').serialize() + "&op=preference&action=save";
3888
3889 new Ajax.Request("ajax_misc.php", {
3890 method: "post",
3891 parameters: param,
3892 onSuccess: function (req) {
3893 var answer = req.responseText.evalJSON();
3894 // id$('pagestyle').setAttribute('href', style.style);
3895 if (answer['psw'] == 'NOK') {
3896 smoke.alert(answer['msg']);
3897 } else {
3898 removeDiv('preference_div');
3899 }
3900 }
3901 });
3902 } catch (e) {
3903 smoke.alert(content[48] + e.message);
3904 }
3905 remove_waiting_box();
3906
3907}
3908
3909/**
3910 * turn on or off , set an domElement to 1 or 0 and change the icon
3911 * @param string icon_domid : id of the domElement which must be changed
3912 * @param string p_value_domid : id of domElement containing 1 or 0
3913 * @see param_jrn.php
3914 */
3915function toggle_onoff(icon_domid, p_value_domid) {
3916 if (id$(p_value_domid).value == 0) {
3917 id$(p_value_domid).value = 1;
3918 id$(icon_domid).innerHTML = '&#xf205;';
3919 id$(icon_domid).style = 'color:green';
3920 } else {
3921 id$(p_value_domid).value = 0;
3922 id$(icon_domid).innerHTML = '&#xf204;';
3923 id$(icon_domid).style = 'color:red';
3924 }
3925}
3926
3927/**
3928 * turn on or off , set an domElement to 1 or 0 and change the icon
3929 * @param string icon_domid : id of the domElement which must be changed
3930 * @param string p_value_domid : id of domElement containing 1 or 0
3931 * @see param_jrn.php
3932 */
3933function toggle_checkbox_onoff(icon_domid, p_value_domid) {
3934
3935 if (id$(p_value_domid).value == 0) {
3936 id$(p_value_domid).value = 1;
3937 id$(icon_domid).innerHTML = '&#xe741;';
3938 } else {
3939 id$(p_value_domid).value = 0;
3940 id$(icon_domid).innerHTML = '&#xf096;';
3941 }
3942}
3943
3944/**
3945 * in C0JRN show or hide the row depending if the warning is enable or not
3946 *
3947 * @param {type} p_enable
3948 * @param {type} p_row
3949 * @returns {undefined}
3950 */
3951function toggle_row_warning_enable(p_enable, p_row) {
3952 var warning = document.getElementsByName('negative_amount')[0].value
3953 if ( warning == 1) {
3954 id$(p_row).show();
3955 } else {
3956 id$(p_row).hide();
3957 }
3958}
3959
3960/**
3961 * return a json object which is the merge of the 2 json objects
3962 * from 2015 : Object.assign(obj1, obj2);
3963 * @param p_json1 object 1 to merge
3964 * @param p_json2 object 2 to merge
3965 * @returns new json object
3966 */
3967function json_concat(p_json1, p_json2) {
3968
3969 var result = {};
3970 for (var key in p_json1) {
3971 result[key] = p_json1[key];
3972 }
3973 for (var key in p_json2) {
3974 result[key] = p_json2[key];
3975 }
3976 return result;
3977
3978}
3979
3980
3981/**
3982 * this function unchecks other checkbox , it mimics the way a radio behaves
3983 * @param string p_click is the DOM id of the checkbox you clicked
3984 * @param string p_name is the name of all the checkbox to uncheck
3985 */
3986function uncheck_other(p_click, p_name) {
3987 var aCheckbox = document.getElementsByName(p_name);
3988 if (aCheckbox.length == 0) return;
3989 var i = 0;
3990 for (i = 0; i < aCheckbox.length; i++) {
3991 aCheckbox[i].checked = false;
3992 }
3993 p_click.checked = true;
3994}
3995
3996/**
3997 * @class operation Tag Manage the tag with operations
3998 * @returns {undefined}
3999 */
4000var operation_tag = function (p_div) {
4001 this.ctl = p_div;
4002 /**
4003 * Show a list of tag which can be added to the current followup document
4004 * @param {type} p_dossier
4005 * @param {type} jrn_id
4006 * @returns {undefined}
4007 */
4008 this.select = function (p_dossier, p_jrn_id) {
4009 try {
4010 waiting_box();
4011 var queryString = {jrn_id: p_jrn_id, op: "operation_tag_select", gDossier: p_dossier, ctl: this.ctl};
4012 var action = new Ajax.Request(
4013 "ajax_misc.php",
4014 {
4015 method: 'get',
4016 parameters: queryString,
4017 onFailure: ajax_misc_failure,
4018 onSuccess: function (req, j) {
4019 remove_waiting_box();
4020
4021 var answer = req.responseXML;
4022 var html = answer.getElementsByTagName('code');
4023 if (html.length === 0) {
4024 var rec = unescape_xml(req.responseText);
4025 error_message('erreur :' + rec);
4026 }
4027 var code_html = getNodeText(html[0]);
4028 code_html = unescape_xml(code_html);
4029 var pos = fixed_position(35, 229);
4030 add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
4031
4032 remove_waiting_box();
4033 id$('tag_div').innerHTML = code_html;
4034 }
4035 }
4036 );
4037 } catch (e) {
4038 error_message(e.message);
4039 }
4040 };
4041
4042 /**
4043 * Add the current tag to the current ag_id
4044 * @param {int} p_dossier
4045 * @param int ag_id
4046 * @param p_isgroup g it is a group , t is a single tag
4047 * @returns void
4048 */
4049 this.add = function (p_dossier, p_jrn_id, t_id, p_isgroup) {
4050 try {
4051 waiting_box();
4052 var queryString = {
4053 t_id: t_id, jrn_id: p_jrn_id, op: "operation_tag_add",
4054 gDossier: p_dossier, ctl: this.ctl, isgroup: p_isgroup
4055 };
4056 var ctl = this.ctl;
4057 var action = new Ajax.Request(
4058 "ajax_misc.php",
4059 {
4060 method: 'get', parameters: queryString,
4061 onFailure: ajax_misc_failure,
4062 onSuccess: function (req, j) {
4063 var answer = req.responseXML;
4064 var html = answer.getElementsByTagName('code');
4065 if (html.length === 0) {
4066 var rec = unescape_xml(req.responseText);
4067 error_message('erreur :' + rec);
4068 }
4069 var code_html = getNodeText(html[0]);
4070 code_html = unescape_xml(code_html);
4071 remove_waiting_box();
4072 id$('operation_tag_td' + ctl).innerHTML = code_html;
4073 removeDiv('tag_div');
4074 }
4075 }
4076 );
4077 } catch (e) {
4078 error_message(e.message);
4079 }
4080 };
4081 /**
4082 * remove the current tag to the current ag_id
4083 * @param {int} p_dossier
4084 * @param {int} ag_id
4085 * @returns void
4086 */
4087 this.remove = function (p_dossier, p_jrn_id, t_id) {
4088 var ctl = this.ctl;
4089 confirm_box(null, content[50], function () {
4090 try {
4091 waiting_box();
4092 var queryString = {
4093 t_id: t_id,
4094 jrn_id: p_jrn_id,
4095 op: "operation_tag_remove",
4096 gDossier: p_dossier,
4097 ctl: ctl
4098 };
4099 var action = new Ajax.Request(
4100 "ajax_misc.php",
4101 {
4102 method: 'get',
4103 parameters: queryString,
4104 onFailure: ajax_misc_failure,
4105 onSuccess: function (req, j) {
4106 var answer = req.responseXML;
4107 var html = answer.getElementsByTagName('code');
4108 if (html.length === 0) {
4109 var rec = unescape_xml(req.responseText);
4110 error_message('erreur :' + rec);
4111 }
4112 var code_html = getNodeText(html[0]);
4113 code_html = unescape_xml(code_html);
4114 remove_waiting_box();
4115 id$('operation_tag_td' + ctl).innerHTML = code_html;
4116
4117 }
4118 }
4119 );
4120 } catch (e) {
4121 error_message(e.message);
4122 }
4123 });
4124 };
4125};
4126
4127/**
4128 * Check the sum of size of all the FILES to upload
4129 * @param p_object the form DOM object,
4130 * @param p_max_size MAX_FILE_SIZE constant (see config.inc.php or constant.php)
4131 * @returns true if the sum of filesize is greater than the limit
4132 */
4133function check_file_size(p_object, p_max_size) {
4134 var sum_file = 0;
4135 for (var i = 0; i < p_object.elements.length; i++) {
4136 var a = p_object.elements[i];
4137
4138 if (p_object.elements[i].getAttribute('type') == "file") {
4139 for (let x = 0; x < p_object.elements[i].files.length; x++) {
4140 if (p_object.elements[i].files[x]) {
4141
4142 sum_file += p_object.elements[i].files[x].size;
4143 }
4144 }
4145 }
4146 }
4147 if (sum_file > p_max_size) {
4148 alert_box(content[78]);
4149 return false;
4150 }
4151 return true;
4152}
4153
4154/**
4155 * Check that the receipt file is not too big
4156 * @see ajax_ledger.php , ledger_detail_file
4157 * @param int p_max_size maximum size
4158 * @param p_info name of the waiting box
4159 * @returns true if file size is less than the maximum
4160 */
4161function check_receipt_size(p_max_size, p_info) {
4162 document.getElementById(p_info).style.display = "inline";
4163
4164 var f = document.getElementById("receipt_id");
4165 if (f && f.files[0] && f.files[0].size > parseFloat(p_max_size)) {
4166 document.getElementById("receipt_info_id").innerHTML = content[78];
4167 document.getElementById(p_info).style.display = "none";
4168 $('receipt_info_id').addClassName('error');
4169 return false;
4170 }
4171 document.getElementById("receipt_info_id").innerHTML = "";
4172 $('receipt_info_id').removeClassName('error');
4173 document.getElementById("form_file").submit();
4174 return true;
4175}
4176
4177/**
4178 * toggle size of a div : fullsize or normal
4179 *
4180 */
4181function full_size(p_div) {
4182 div_dom = document.getElementById(p_div);
4183 if (!div_dom) return;
4184 if (div_dom.hasClassName('fullsize')) {
4185 div_dom.removeClassName('fullsize');
4186 id$('size_' + p_div).innerHTML = '&#xe80a;';
4187 } else {
4188 div_dom.addClassName('fullsize');
4189 id$('size_' + p_div).innerHTML = '&#xe83d;';
4190 }
4191
4192}
4193
4194/**
4195 * download a document from an url
4196 */
4197function download_document(p_url) {
4198 waiting_box();
4199 document.location = p_url;
4200 remove_waiting_box();
4201}
4202
4203/**
4204 * download a document from a form
4205 */
4206function download_document_form(p_form_id) {
4207 waiting_box();
4208 var url = "export.php?" + id$(p_form_id).serialize();
4209 document.location = url;
4210 remove_waiting_box();
4211 return false;
4212}
4213
4214/**
4215 * Pause a javascript
4216 */
4217function pausecomp(millis) {
4218 var date = new Date();
4219 var curDate = null;
4220 do {
4221 curDate = new Date();
4222 }
4223 while (curDate - date < millis);
4224}
4225
4226/**
4227 * propose to reconnect
4228 * @returns {undefined}
4229 */
4230function reconnect() {
4231 remove_waiting_box();
4232 new Ajax.Request('ajax_misc.php', {
4233 method: 'get',
4234 parameters: {op: "disconnect"},
4235 onSuccess: function (req) {
4236 var pos = "position:fixed;top:0px;width:95%;height:95%";
4237 var div = add_div({
4238 'id': "reconnect_bx",
4239 cssclass: "inner_box",
4240 style: pos
4241 });
4242 div.innerHTML = req.responseText;
4243 }
4244 });
4245}
4246
4247/**
4248 * enlarge an INPUT TEXT
4249 *
4250 */
4251function enlarge_text(p_domid, p_size) {
4252 try {
4253 var element = document.getElementById(p_domid);
4254 if (!element) {
4255 console.error(`enlarge text doesn't exist [${p_domid}]`)
4256 }
4257 var current_size = parseInt(element.getAttribute('size'));
4258 element.setAttribute('size', current_size + parseInt(p_size));
4259 } catch (e) {
4260 console.error(`enlarge text fails with ${p_domid} ${p_size} `);
4261 console.error(e.message);
4262 }
4263
4264
4265}
4266
4267/**
4268 * @brief display a box with the customer , supplier or event for today or late
4269 * @param p_detail , what to do
4270 */
4271function event_display_detail(p_dossier, p_detail) {
4272
4273 try {
4274 // create div if not exists
4275 var dgbox = "situation_detail_div";
4276 waiting_box();
4277
4278 var queryString = {gDossier: p_dossier, op: 'event_display_detail', 'what': p_detail};
4279 // call ajax and update content of the div
4280 var action = new Ajax.Request(
4281 "ajax_misc.php",
4282 {
4283 method: 'get',
4284 parameters: queryString,
4285 onFailure: ajax_misc_failure,
4286 onSuccess: function (req) {
4287 remove_waiting_box();
4288 if (req.responseText == 'NOCONX') {
4289 reconnect();
4290 return;
4291 }
4292 if (!document.getElementById(dgbox)) {
4293 var div_style = "position:fixed;" + ";top:30%;z-index:"+get_next_layer();
4294 add_div({id: dgbox, cssclass: 'inner_box2', html: loading(), style: div_style, drag: true});
4295
4296 }
4297
4298 id$(dgbox).update(req.responseText)
4299
4300 }
4301 }
4302 );
4303 event_display_main(p_dossier);
4304 } catch (e) {
4305 alert_box(e.message);
4306 }
4307}
4308
4309/**
4310 * @brief refresh the main display in the dashboard to reflect possible changes
4311 * @param p_dossier
4312 */
4313function event_display_main(p_dossier) {
4314 try {
4315 waiting_box();
4316 var dgbox = "situation_div";
4317 var queryString = {gDossier: p_dossier, op: 'event_display_detail', 'what': "main_display"};
4318 var action = new Ajax.Request(
4319 "ajax_misc.php",
4320 {
4321 method: 'GET',
4322 parameters: queryString,
4323 onFailure: ajax_misc_failure,
4324 onSuccess: function (req) {
4325 remove_waiting_box();
4326 if (req.responseText == 'NOCONX') {
4327 reconnect();
4328 return;
4329 }
4330
4331 id$(dgbox).update(req.responseText)
4332
4333 }
4334 }
4335 );
4336 } catch (e) {
4337 alert_box(e.message);
4338 }
4339}
4340
4341/**
4342 * @brief check if password is strong or not, update a DIV element
4343 * @param p_pass_domid DOM ID of the INPUT element with the password
4344 * @param p_result_domid DOM ID of the element to update
4345 */
4346function check_password_strength(p_pass_domid, p_result_domid, details) {
4347 try {
4348 if (id$(p_pass_domid).value == "") {
4349 id$(p_result_domid).update("");
4350 return;
4351 }
4352 var queryString = {
4353 'op': "password_chk"
4354 , pass: id$(p_pass_domid).value
4355 };
4356 var action = new Ajax.Request(
4357 "ajax_misc.php",
4358 {
4359 method: 'GET',
4360 parameters: queryString,
4361 onFailure: ajax_misc_failure,
4362 onSuccess: function (req) {
4363 remove_waiting_box();
4364 if (req.responseText == 'NOCONX') {
4365 return;
4366 }
4367 var answer = req.responseJSON;
4368
4369 if (answer['password'] == 'nok') {
4370
4371 id$(p_pass_domid).setStyle("background-color:red");
4372 if (details) {
4373 id$(p_result_domid).update(answer['msg'])
4374 }
4375 return;
4376 }
4377 id$(p_pass_domid).setStyle("background-color: lightgreen");
4378 id$(p_result_domid).update("")
4379 }
4380 }
4381 );
4382 } catch (e) {
4383 alert_box(e.message);
4384 }
4385}
4386
4387/**
4388 * activate a plugin , must comes from C0PLG
4389 * @param elt {string} DOMID of the element, must have the attribute gDossier, plugin and pr_id (for the profile)
4390 * @test
4391 */
4392function activate_plugin(elt)
4393{
4394 try
4395 {
4396 waiting_box();
4397 var queryString = {
4398 op:'activate_plugin',
4399 gDossier:elt.getAttribute('gDossier'),
4400 mecode:elt.getAttribute('me_code'),
4401 prid:elt.getAttribute('pr_id'),
4402 dep:elt.getAttribute('dep'),
4403 ord:elt.getAttribute('order'),
4404 activate:elt.checked
4405 };
4406 var action = new Ajax.Request(
4407 "ajax_misc.php" ,
4408 {
4409 method:'GET',
4410 parameters:queryString,
4411 onFailure:ajax_misc_failure,
4412 onSuccess:function(req){
4413 remove_waiting_box();
4414 if (req.responseText == 'NOCONX') {
4415 reconnect();
4416 return;
4417 }
4418
4419 if (req.responseText != 'OK') {
4420 smoke.alert(req.responseText)
4421 elt.checked=false;
4422 }
4423 }
4424 }
4425 );
4426 }catch( e)
4427 {
4428 alert_box(e.message);
4429 }
4430}
4431/**********************************************************************************************/
4432/**
4433 * @class Widget
4434 *
4435*************************************************************************************************************/
4436
4437Widget = function(dossier_id) {
4438 this.dossier_id=dossier_id;
4439}
4440/**
4441 * Display the widget in the elt box
4442 * @param box DOMID of the target
4443 * @param dossier_id
4444 * @param user_widget_id int
4445 * @param widget_code string
4446 * @param var_name string name of the variable
4447 */
4448Widget.prototype.display = function (box,user_widget_id,widget_code,var_name) {
4449 try {
4450
4451 var queryString = {
4452 gDossier: this.dossier_id,
4453 'op': 'widget',
4454 'user_widget_id': user_widget_id,
4455 'widget_code': widget_code,
4456 'var_name':var_name,
4457 'action': 'widget.display'
4458 }
4459 var action = new Ajax.Request(
4460 "ajax_misc.php",
4461 {
4462 method: 'GET',
4463 parameters: queryString,
4464 onFailure: ajax_misc_failure,
4465 onSuccess: function (req) {
4466 if (req.responseText == 'NOCONX') {
4467 reconnect();
4468 return;
4469 }
4470 id$(box).replace(req.responseText);
4471
4472 }
4473 }
4474 );
4475 } catch (e) {
4476 alert_box(e.message);
4477 }
4478
4479}
4480
4481/**
4482 * Manage the widget
4483 * @param dossier_id
4484 * @returns {boolean}
4485 */
4486Widget.prototype.manage = function () {
4487 try {
4488 this.show_ident();
4489 var box = 'widget_box_id';
4490 var queryString = {
4491 gDossier: this.dossier_id,
4492 'op': 'widget',
4493 'action': 'widget.manage'
4494 }
4495 var action = new Ajax.Request(
4496 "ajax_misc.php",
4497 {
4498 method: 'GET',
4499 parameters: queryString,
4500 onFailure: ajax_misc_failure,
4501 onSuccess: function (req) {
4502 if (req.responseText == 'NOCONX') {
4503 reconnect();
4504 return;
4505 }
4506 var style = 'position:absolute;';
4507 var y = calcy(200);
4508 style = style + ' ;top : ' + y + 'px';
4509
4510 add_div({id: box, cssclass: 'inner_box', html: loading(), style: style,drag:false})
4511
4512 id$(box).update(req.responseText);
4513 }
4514 }
4515 );
4516 } catch (e) {
4517 alert_box(e.message);
4518 console.error("widget_manage" + e.message);
4519 }
4520 return false;
4521}
4522/**
4523 * create a list of sortable elements
4524 */
4525Widget.prototype.create_sortable=function() {
4526
4527 Sortable.create('contain_widget',{tag:'li',onUpdate:function(){ id$('order_widget_hidden').value=Sortable.serialize('contain_widget')}})
4528 id$('order_widget_hidden').value=Sortable.serialize('contain_widget');
4529}
4530/**
4531 * Save the order of widget
4532 **/
4533Widget.prototype.save = function () {
4534 try
4535 {
4536 var here = this;
4537 var dgbox="widget_box_id";
4538 waiting_box();
4539
4540 // For form , most of the parameters are in the FORM
4541 // method is then POST
4542 //var queryString=id$(p_form_id).serialize(true);
4543
4544 var queryString = {
4545 op : 'widget',
4546 action : 'widget.save',
4547 gDossier: this.dossier_id,
4548 param : Sortable.serialize('contain_widget')
4549 };
4550 var action = new Ajax.Request(
4551 "ajax_misc.php" ,
4552 {
4553 method:'GET',
4554 parameters:queryString,
4555 onFailure:ajax_misc_failure,
4556 onSuccess:function(req){
4557 remove_waiting_box();
4558 if (req.responseText == 'NOCONX') {
4559 reconnect();
4560 return;
4561 }
4562 removeDiv(dgbox)
4563 here.refresh();
4564
4565 }
4566 }
4567 );
4568 }catch( e)
4569 {
4570 alert_box(e.message);
4571 }
4572 this.remove_ident();
4573}
4574/**
4575 * refresh the DASHBOARD (dashboard_div_id)
4576 */
4577Widget.prototype.refresh = function () {
4578 try {
4579 var here = this;
4580 var dgbox='dashboard_div_id'
4581 var queryString = {
4582 op : 'widget',
4583 action : 'widget.refresh',
4584 gDossier: this.dossier_id
4585 };
4586 var action = new Ajax.Request(
4587 "ajax_misc.php" ,
4588 {
4589 method:'GET',
4590 parameters:queryString,
4591 onFailure:ajax_misc_failure,
4592 onSuccess:function(req){
4593 if (req.responseText == 'NOCONX') {
4594 reconnect();
4595 return;
4596 }
4597
4598 id$(dgbox).replace(req.responseText);
4599
4600 }
4601 }
4602 );
4603 }catch( e) {
4604 console.error("widget.refresh "+e.message)
4605 }
4606}
4607/**
4608 * delete a widget : remove from the list
4609 * @param user_widget_id {integer}
4610 */
4611Widget.prototype.delete=function (user_widget_id) {
4612 id$('elt_'+user_widget_id).remove()
4613 id$('order_widget_hidden').value=Sortable.serialize('contain_widget');
4614}
4615/**
4616 * display list widget we can add
4617 */
4618Widget.prototype.input = function () {
4619 try {
4620 var box="widget_box_select_id";
4621
4622 var queryString = {
4623 op: 'widget',
4624 action: 'widget.input',
4625 gDossier: this.dossier_id
4626 };
4627 var action = new Ajax.Request(
4628 "ajax_misc.php",
4629 {
4630 method: 'GET',
4631 parameters: queryString,
4632 onFailure: ajax_misc_failure,
4633 onSuccess: function (req) {
4634 remove_waiting_box();
4635 if (req.responseText == 'NOCONX') {
4636 reconnect();
4637 return;
4638 }
4639 var style = 'position:absolute;';
4640 var y = calcy(200);
4641 style = style + ' ;top : ' + y + 'px';
4642
4643 add_div({id: box, cssclass: 'inner_box', html: loading(), style: style})
4644
4645 id$(box).update(req.responseText);
4646
4647
4648 }
4649 }
4650 );
4651 } catch (e) {
4652 alert_box(e.message);
4653 }
4654}
4655/**
4656 * add a widget for the user , refresh the dashboard afterward
4657 * @param widget_code {string}
4658 */
4659Widget.prototype.add=function (widget_code) {
4660 try
4661 {
4662 here=this;
4663 var param = {};
4664 if (document.getElementById(widget_code+"_param")) {
4665 param=id$(widget_code+"_param").serialize()
4666 }
4667 query = {
4668 op : 'widget',
4669 action : 'widget.insert',
4670 gDossier: this.dossier_id,
4671 param : param,
4672 widget_code:widget_code
4673 }
4674 var action = new Ajax.Request(
4675 "ajax_misc.php" ,
4676 {
4677 method:'GET',
4678 parameters:query,
4679 onFailure:ajax_misc_failure,
4680 onSuccess:function(req){
4681 if (req.responseText == 'NOCONX') {
4682 reconnect();
4683 return;
4684 }
4685 var new_element=new Element("li");
4686 id$('contain_widget').appendChild(new_element);
4687 new_element.replace(req.responseText)
4688 removeDiv('widget_box_select_id')
4689 here.create_sortable()
4690
4691 }
4692 }
4693 );
4694 }catch( e)
4695 {
4696 alert_box(e.message);
4697 }
4698
4699}
4700/**
4701 * Show the number in the widget to improve the ergonomy
4702 */
4703Widget.prototype.show_ident = function ()
4704{
4705 var aBox = document.getElementsByClassName('widget-box') ;
4706 var nb=aBox .length
4707 var idx=1;
4708 for (var e=0;e <nb; e++) {
4709 if (aBox[e].visible)
4710 {
4711 var spanx=new Element('span');
4712 spanx.addClassName("box_ident");
4713 aBox[e].insertBefore(spanx,aBox[e].firstChild);
4714 spanx.update(idx);
4715 idx++
4716 }
4717 }
4718}
4719/**
4720 * Hide the number of the widget
4721 */
4722Widget.prototype.remove_ident = function ()
4723{
4724 while (true) {
4725 var elt=document.getElementsByClassName("box_ident");
4726 if ( elt.length == 0) break;
4727 elt[0].remove()
4728 }
4729}
4730
4731/**
4732 * Put the widget in full size
4733 * @param widget_domid {string} dom id of the widget to toggle the size
4734 */
4735Widget.prototype.toggle_full_size=function (widget_domid) {
4736 if ( id$(widget_domid).hasClassName('widget-full_size')) {
4737 id$(widget_domid).removeClassName('widget-full_size');
4738 } else {
4739 id$(widget_domid).addClassName('widget-full_size');
4740
4741 var layer=get_next_layer();
4742 id$(widget_domid).style.zIndex=layer;
4743 }
4744
4745};
4746
4747
4748/**
4749 * EXPERIMENTAL
4750(function(){window.addEventListener("beforeunload", (event) => {waiting_box()});})();
4751
4752(function(){window.addEventListener("onload", (event) => {remove_waiting_box()});})();
4753*/
4754
4755//var bookmark=new Bookmark();
4756
4757Noalyss = function () {
4758
4759}
4760/**
4761 * Activate TinyMCE
4762 * @param {string} domid id of the dom element
4763 * @param {string} mode min for minimum or full , gives an error if the mode doesn't exist
4764 * @returns {undefined}
4765 */
4766
4767Noalyss.prototype.activate_tinymce=function (domid,mode,p_height) {
4768 if ( ! g_enable_tinymce ) return;
4769 tinymce.remove('#'+domid);
4770 if (! p_height) p_height=500;
4771 if ( mode == 'minimal' || ! mode )
4772 {
4773 tinymce.init({
4774 selector: 'textarea#'+domid,
4775 plugins:'link quickbars ',
4776 height: p_height,
4777 menubar: false,
4778 toolbar: 'undo redo | ' +
4779 'bold italic underline forecolor backcolor |fontsize ' +
4780 ' | bullist numlist | ' +
4781 'removeformat | help',
4782 content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
4783 quickbars_insert_toolbar:false,
4784 promotion: false,
4785 quickbars_selection_toolbar:' bold italic underline forecolor backcolor ',
4786 license_key:'gpl',
4787 statusbar: false,
4788 branding: false
4789 });
4790 } else if ( mode == "full")
4791 {
4792 /**
4793 toolbar: 'undo redo ' +
4794 'bold italic underline strikethrough | hr quickimage | forecolor backcolor|emoticons |fontsize styles ' +
4795 ' table tabledelete |' +
4796 ' | link unlink bullist numlist | ' +
4797 'removeformat | help',
4798 content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
4799 */
4800 tinymce.init({
4801 selector: 'textarea#'+domid,
4802 height: p_height,
4803 menubar: false,
4804 plugins:'link lists emoticons quickbars pagebreak table',
4805 toolbar: 'undo redo ' +
4806 'bold italic underline strikethrough | hr quickimage | forecolor backcolor|emoticons |fontsize styles fontfamily ' +
4807 ' table tabledelete |' +
4808 ' | link unlink bullist numlist | ' +
4809 'removeformat | help',
4810 content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
4811 quickbars_insert_toolbar:false,
4812 promotion: false,
4813 quickbars_selection_toolbar:' bold italic underline forecolor backcolor ',
4814 license_key:'gpl',
4815 statusbar: true,
4816 branding: false
4817 });
4818
4819 }else if ( mode == 'no-toolbar' )
4820 {
4821 tinymce.init({
4822 selector: 'textarea#'+domid,
4823 height: p_height,
4824 plugins:' quickbars',
4825 menubar:false,
4826 toolbar: false,
4827 quickbars_selection_toolbar:' bold italic underline forecolor backcolor hide',
4828 content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
4829 promotion: false,
4830 license_key:'gpl',
4831 statusbar: false,
4832 toolbar_mode: 'hide',
4833 quickbars_insert_toolbar:false,
4834 branding: false
4835 });
4836 } else {
4837
4838 console.error(`Noalyss.activate_tinymce unknow mode`);
4839 }
4840
4841}
4842/**
4843 * @deprecated not used
4844 * Input NOTE on operation from Detail Operation
4845 * @param {int} dossier_id
4846 * @param {int} jrn_id
4847 * @param {string} div_prefix
4848 * @returns {undefined}
4849 */
4850Noalyss.prototype.input_note=function (dossier_id,jrn_id,div_prefix)
4851{
4852
4853 try
4854 {
4855 var dgbox = "box_input_note"+div_prefix;
4856 waiting_box();
4857 removeDiv(dgbox);
4858 var queryString = {
4859 op:'ledger'
4860 ,act:'note_input'
4861 ,jr_id:jrn_id
4862 ,div:div_prefix
4863 ,gDossier:dossier_id
4864 ,tinymce:g_enable_tinymce
4865 };
4866 var action = new Ajax.Request(
4867 "ajax_misc.php",
4868 {
4869 method: 'get',
4870 parameters: queryString,
4871 onFailure: ajax_misc_failure,
4872 onSuccess: function (req) {
4873 remove_waiting_box();
4874 if (req.responseText == 'NOCONX') {
4875 reconnect();
4876 return;
4877 }
4878 var y = calcy(15);
4879 var div_style = "position:absolute;" + ";top:" + y + "px";
4880 add_div({id: dgbox, cssclass: 'inner_box2', html: loading(), style: div_style, drag: true});
4881 let response=req.responseXML;
4882 let html=getNodeText(response.getElementsByTagName("code")[0])
4883 let ctl=getNodeText(response.getElementsByTagName("ctl")[0]);
4884 $(dgbox).update(html);
4885
4886 }
4887 }
4888 );
4889 } catch (e)
4890 {
4891 alert_box(e.message);
4892 }
4893
4894}
4895Noalyss.prototype.refresh_note=function(jrn_id,dossier_id)
4896{
4897 if ( document.getElementById("als_note"+jrn_id)) {
4898 new Ajax.Updater('als_note'+jrn_id,'ajax_misc.php',{
4899 method:'get',
4900 parameters:{
4901 op:'ledger'
4902 ,'act':'note_refresh'
4903 ,jr_id:jrn_id
4904 ,gDossier:dossier_id
4905 ,div:'not-set'
4906 }
4907 })
4908 } else if ( document.getElementById("jrn_note_td")) {
4909 new Ajax.Updater('jrn_note_td','ajax_misc.php',{
4910 method:'get',
4911 parameters:{
4912 op:'ledger'
4913 ,'act':'note_refresh'
4914 ,jr_id:jrn_id
4915 ,gDossier:dossier_id
4916 ,div:'not-set'
4917 }
4918 })
4919 }
4920
4921}
4922
4923
4924
4925/**
4926 * save parameter for SMPT , menu C0ML
4927 *
4928 */
4929Noalyss.prototype.save_config_smtp = function ()
4930{
4931 try
4932 {
4933 waiting_box();
4934 var queryString = $("form_config_smtp").serialize(true);
4935 queryString['op'] = "email_setting";
4936 queryString['op2'] = "save_config_smtp";
4937 var action = new Ajax.Request(
4938 "ajax_misc.php",
4939 {
4940 method: 'POST',
4941 parameters: queryString,
4942 onFailure: ajax_misc_failure,
4943 onSuccess: function (req) {
4944 remove_waiting_box();
4945 if (req.responseText == 'NOCONX') {
4946 reconnect();
4947 return;
4948 }
4949 let json = req.evalJSON();
4950
4951
4952 }
4953 }
4954 );
4955
4956 } catch (e) {
4957 console.error(e.message);
4958 }
4959 return false;
4960};
4961Noalyss.prototype.parameter_display_smtp = function ()
4962{
4963 if ($F("smtp_type") == 'smtp') {
4964 $("smtp_config_div").style.display = "grid";
4965 $('btn_save1').hide();
4966 } else {
4967 $("smtp_config_div").hide();
4968 $('btn_save1').show();
4969
4970 }
4971};
4972Noalyss.prototype.parameter_test_smtp = function ()
4973{
4974 try
4975 {
4976 var parameter = $('form_config_smtp').serialize(true);
4977 parameter['op'] = "email_setting";
4978 parameter['op2'] = "parameter_test_smtp";
4979 var email = {email_test: $F('email_test_input')};
4980 if ($F('email_test_input') == '') {
4981 smoke.alert("Aucun email")
4982 return false;
4983 }
4984 waiting_box();
4985 var action = new Ajax.Request(
4986 "ajax_misc.php",
4987 {
4988 method: 'GET',
4989 parameters: Object.assign(parameter, email),
4990 onSuccess: function (req) {
4991 remove_waiting_box();
4992 if (req.responseText == 'NOCONX') {
4993 reconnect();
4994 return;
4995 }
4996 $('result_test_div').update(req.responseText);
4997
4998 }
4999 }
5000 );
5001
5002 } catch (e)
5003 {
5004 remove_waiting_box();
5005 console.error("parameter_test_smtp" + e.message);
5006 }
5007
5008}
5009
5010VAT_Code = function (dossier_id) {
5011 this.dossier_id=dossier_id;
5012}
5013
5014VAT_Code.prototype.list_vatex=function ()
5015{
5016 try
5017 {
5018 var here=this;
5019 var dgbox = "search_vatex_div";
5020 waiting_box();
5021 removeDiv(dgbox);
5022 var queryString = {
5023 op:'search_vatex',
5024 gDossier:this.dossier_id,
5025 dgbox:dgbox
5026 }
5027 var action = new Ajax.Request(
5028 "ajax_misc.php",
5029 {
5030 method: 'GET',
5031 parameters: queryString,
5032 onSuccess: function (req) {
5033 remove_waiting_box();
5034 if (req.responseText == 'NOCONX') {
5035 reconnect();
5036 return;
5037 }
5038 var y = calcy(15);
5039 var div_style = "position:absolute;" + ";top:" + y + "px"+";z-index:"+get_next_layer();
5040 add_div({id: dgbox, cssclass: 'inner_box', html: loading(), style: div_style, drag: false});
5041 $(dgbox).update(req.responseText);
5042 here.filter_country();
5043
5044 }
5045 }
5046 );
5047 } catch (e)
5048 {
5049 alert_box(e.message);
5050 }
5051
5052}
5053
5054VAT_Code.prototype.select_value=function(vx_code)
5055{
5056 try
5057 {
5058 var dgbox = "search_vatex_div";
5059 waiting_box();
5060 var queryString = {
5061 op:'search_vatex',
5062 gDossier:this.dossier_id,
5063 select_code:vx_code,
5064 dgbox:dgbox
5065
5066 }
5067 var action = new Ajax.Request(
5068 "ajax_misc.php",
5069 {
5070 method: 'GET',
5071 parameters: queryString,
5072 onSuccess: function (req) {
5073 remove_waiting_box();
5074 if (req.responseText == 'NOCONX') {
5075 reconnect();
5076 return;
5077 }
5078 removeDiv(dgbox);
5079 var answer=req.responseJSON
5080 $("vx_code").value=answer.vx_code;
5081 $("vx_value").update(answer.vx_value);
5082 $('vx_code_description').update(answer.vx_description)
5083
5084
5085 }
5086 }
5087 );
5088 } catch (e)
5089 {
5090 alert_box(e.message);
5091 }
5092
5093}
5094VAT_Code.prototype.filter_country=function()
5095{
5096 try {
5097 var to_show=id$("filter_country").value;
5098 let a_row=id$("code_vatex_tb").rows;
5099 // show all rows, then hide
5100 for (let i=1;i< a_row.length;i++) {
5101
5102 if (id$("filter_country").value == 0 || a_row[i].hasClassName(to_show)){
5103 a_row[i].show()
5104
5105 }else {
5106 a_row[i].hide()
5107 }
5108 }
5109 $('lk_code_vatex_tb').value="";
5110 }catch (e)
5111 {
5112 console.error(e.message);
5113 return false;
5114 }
5115}
5116noalyss=new Noalyss();
5117
5118bookmark=new Bookmark();