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