2 * This file is part of NOALYSS.
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.
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.
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
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
24 * javascript script, always added to every page
28// tag_choose Element which contains all the selected tags
30var aDraggableElement = new Array();
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;
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}
43function in_child(p_element, name_child) {
44 var element = p_element
45 if (typeof p_element !== "object") {
46 element = document.getElementById(p_element);
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];
58 * callback function when we just need to update a hidden div with an info
60 * @see removeOperation , reverseOperation
62function infodiv(req, json) {
65 var answer = req.responseXML;
66 var a = answer.getElementsByTagName('ctl');
67 var html = answer.getElementsByTagName('code');
69 var rec = req.responseText;
70 alert_box('erreur :' + rec);
72 var name_ctl = a[0].firstChild.nodeValue;
73 var code_html = getNodeText(html[0]);
75 code_html = unescape_xml(code_html);
76 g(name_ctl + "info").innerHTML = code_html;
78 alert_box("success_box" + e.message);
81 code_html.evalScripts();
83 alert_box(content[53] + "\n" + e.message);
89 * delete a row from a table (tb) the input button send the this
92function deleteRow(tb, obj) {
93 smoke.confirm(content[50], function (e) {
95 var td = obj.parentNode;
96 var tr = td.parentNode;
97 var lidx = tr.rowIndex;
98 g(tb).deleteRow(lidx);
106function deleteRowRec(tb, obj) {
108 var lidx = tr.rowIndex;
109 g(tb).deleteRow(lidx);
112/*!\brief remove trailing and heading space
113 * \param the string to modify
114 * \return string without heading and trailing space
117 return s.replace(/^\s+/, '').replace(/\s+$/, '');
121 * retrieve an element thanks its ID
122 * @param ID is a string
123 * @return the found object of undefined if not found
126 if (document.getElementById) {
127 return this.document.getElementById(ID);
128 } else if (document.all) {
129 return document.all[ID];
136 * enable the type of periode
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();
146 $('from_periode').disable();
147 $('to_periode').disable();
148 $('from_date').enable();
149 $('to_date').enable();
150 $('p_step').disable();
155 * will reload the window but it is dangerous if we have submitted
158function refresh_window() {
159 window.location.reload();
164 * we receive a json object as parameter and the function returns the string
165 * with the format variable=value&var2=val2...
167function encodeJSON(obj) {
168 if (typeof obj != 'object') {
169 alert_box('encodeParameter obj n\'est pas un objet');
181 str += '=' + encodeURI(obj[i]);
185 alert_box('encodeParameter ' + e.message);
190function hide(p_param) {
191 g(p_param).style.display = 'none';
194function show(p_param) {
195 g(p_param).style.display = 'block';
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
203function SetFocus(Field, SelectIt) {
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
217function set_inparent(p_ctl, p_value, p_add) {
218 self.opener.set_value(p_ctl, p_value, p_add);
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
228function set_value(p_ctl, p_value, p_add) {
230 var g_ctrl = g(p_ctl);
231 if (p_add != undefined && p_add === 1) {
233 p_value = g_ctrl.value + ',' + p_value;
236 if (g_ctrl.tagName === 'INPUT') {
237 g(p_ctl).value = p_value;
239 if (g_ctrl.tagName === 'SPAN') {
240 g(p_ctl).innerHTML = p_value;
242 if (g_ctrl.tagName === 'SELECT') {
243 g(p_ctl).value = p_value;
249 * compute small math in numeric cells
250 * @param string value
253function compute_number(value) {
256 var exp = new RegExp("^[0-9/*+-.()]+$", "g");
257 /*pour éviter un eval() mal intentionné*/
258 var res = exp.test(value);
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*/
264 retval = eval(value);
266 return parseFloat(value);
268 /*pour gérer les divisions par 0*/
269 if (retval == Infinity) {
280 * format the number change comma to point
283function format_number(obj, p_prec) {
285 if (p_prec === undefined) {
290 var value = obj.value;
291 value = value.replace(/ /g, '');
292 value = value.replace(/,/g, '.');
295 value = compute_number(value);
297 value = parseFloat(value);
301 var arrondi = Math.pow(10, precision);
303 value = Math.round(value * arrondi) / arrondi;
305 $(obj).value = value;
309 * Replace slash , space and minus by dot
310 * @param p_object DOM Element date to check
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];
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]) {
328 new Effect.Highlight(p_object.id, {startcolor: "#ff0000"});
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
342function toggleHideShow(p_obj, p_button, rotate) {
343 var div_obj = g(p_obj);
344 var stat = div_obj.style.display;
346 var str = (g(p_button)) ? g(p_button).value : "";
348 if (stat === 'none') {
349 // specific for the DIV id search_form
350 if (div_obj.id == 'search_form') {
355 str = str.replace(/Afficher/, content[62]);
356 g(p_button).value = str;
358 // specific for the DIV di search_form
359 if (!div_obj.id == 'search_form') {
364 str = str.replace(/Cacher/, content[63]);
365 g(p_button).value = str;
368 if (stat == "none") {
369 g(p_button).addClassName("icon-up-open-1")
370 g(p_button).removeClassName(" icon-down-open-2")
372 g(p_button).removeClassName("icon-up-open-1")
373 g(p_button).addClassName(" icon-down-open-2")
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
384function popup_recherche(p_dossier) {
385 var w = window.open("recherche.php?gDossier=" + p_dossier + "&ac=SEARCH", '', 'statusbar=no,scrollbars=yes,toolbar=no');
390 * replace the special characters (><'") by their HTML representation
391 *@return a string without the offending char.
393function unescape_xml(code_html) {
394 code_html = code_html.replace(/\</, '<');
395 code_html = code_html.replace(/\>/, '>');
396 code_html = code_html.replace(/\"/, '"');
397 code_html = code_html.replace(/\'/, "'");
398 code_html = code_html.replace(/\&/, '&');
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
408function getNodeText(xmlNode) {
411 if (typeof (xmlNode.textContent) != "undefined") {
412 return xmlNode.textContent;
414 if (xmlNode.firstChild && xmlNode.firstChild.nodeValue)
415 return xmlNode.firstChild.nodeValue;
420 * change the periode in the calendar of the dashboard
421 *@param object select
423function change_month(obj) {
424 var action = new Ajax.Request(
429 gDossier: obj.gDossier,
435 onFailure: ajax_misc_failure,
436 onSuccess: success_misc
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
451function success_misc(req) {
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);
459 var nodeXml = html[0];
460 var code_html = getNodeText(nodeXml);
461 code_html = unescape_xml(code_html);
462 $("user_cal").innerHTML = code_html;
464 alert_box(e.message);
467 code_html.evalScripts();
469 alert_box(content[53] + "\n" + e.message);
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>';
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>';
495function ajax_misc_failure() {
496 alert_box(content[53]);
500 * remove a document_modele
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(
507 parameters: queryString,
508 onFailure: ajax_misc_failure,
509 onSuccess: function (req) {
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);
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);
526 $('row' + row_id).style.textDecoration = "line-through";
527 $('X' + row_id).style.display = 'none';
528 $('M' + row_id).style.display = 'none';
530 alert_box(e.message);
538 * change a document_modele
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);
544 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:50em;height:auto";
546 removeDiv('change_doc_div');
548 var action = new Ajax.Request(
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;
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,
568function popup_select_tva(obj, p_function_callback) {
570 if ($('tva_select')) {
571 removeDiv('tva_select');
574 var queryString = "gDossier=" + obj.gDossier + "&op=dsp_tva" + "&ctl=" + obj.ctl + '&popup=' + 'tva_select';
576 queryString += '&code=' + obj.jcode;
578 queryString += '&compute=' + obj.compute;
580 queryString += '&filter=' + obj.filter;
582 var action = new Ajax.Request(
586 parameters: queryString,
587 onFailure: ajax_misc_failure,
588 onSuccess: function (req) {
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);
596 var html = answer.getElementsByTagName('code');
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);
603 var nTop = posY - 200;
605 var str_style = "top:" + nTop + "px;left:" + nLeft + ";right:" + nLeft + ";width:55em;height:auto";
609 'cssclass': 'inner_box',
615 $('lk_tva_select_table').focus();
616 sorttable.makeSortable($('tva_select_table'));
617 if (p_function_callback) {
618 p_function_callback.call(null);
621 alert_box("success_popup_select_tva " + e.message);
627 alert_box("popup_select_tva " + e.message);
633 * display the popup with vat and explanation
634 *@param obj with 4 attributes gdossier, ctl,popup
636function set_tva_label(obj) {
638 var queryString = "gDossier=" + obj.gDossier + "&op=label_tva" + "&id=" + obj.value;
640 queryString += '&code=' + obj.jcode;
641 else if ( obj.getAttribute("jcode") )
642 queryString += '&code=' + obj.getAttribute("jcode") ;
643 var action = new Ajax.Request(
647 parameters: queryString,
648 onFailure: ajax_misc_failure,
649 onSuccess: success_set_tva_label
653 alert_box("set_tva_label " + e.message);
658 * display the popup with vat and explanations
659 *@param string req answer from ajax
661function success_set_tva_label(req) {
663 var answer = req.responseXML;
664 var code = answer.getElementsByTagName('code');
665 var value = answer.getElementsByTagName('value');
667 if (code.length === 0) {
668 var rec = req.responseText;
669 alert_box('erreur :' + rec);
672 var label_code = code[0].firstChild.nodeValue;
673 var label_value = value[0].firstChild.nodeValue;
674 set_value(label_code, label_value);
676 alert_box("success_set_tva_label " + e.message);
682 * Create a div without showing it
685 * - style to add style
687 * - cssclass to add a class
688 * - html is the content
689 * - drag is the div can be moved
690 * @returns html dom element
693function create_div(obj) {
698 elt = top.createElement('div');
703 elt.setAttribute('id', obj.id);
706 if (elt.style.setAttribute) { /* IE7 bug */
707 elt.style.setAttribute('cssText', obj.style);
708 } else { /* good Browser */
709 elt.setAttribute('style', obj.style);
713 elt.setAttribute('class', obj.cssclass); /* FF */
714 elt.setAttribute('className', obj.cssclass); /* IE */
717 elt.innerHTML = obj.html;
720 var bottom_div = document.body;
722 bottom_div.appendChild(elt);
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}); }*/
727 aDraggableElement[obj.id] = new Draggable(obj.id, {
728 starteffect: function () {
729 new Effect.Highlight(obj.id, {scroll: window, queue: 'end'});
738 error_message("create_div " + e.message);
743 * add dynamically a object for AJAX
746 * - style to add style
748 * - cssclass to add a class
749 * - html is the content
750 * - drag is the div can be moved
752function add_div(obj) {
754 var elt = create_div(obj);
755 /* elt.setStyle({visibility:'visible'}); */
756 elt.style.visibility = 'visible';
760 alert_box("add_div " + e.message);
765 * remove a object created with add_div
766 * @param elt id of the elt
768function removeDiv(elt) {
770 document.body.removeChild(g(elt));
772 // if reloaded if asked the window will be reloaded when
774 if (ask_reload === 1) {
775 // avoid POST window.location = window.location.href;
776 window.location.reload();
780function waiting_node() {
781 $('info_div').innerHTML = 'Un instant';
782 $('info_div').style.display = "block";
786 *show a box while loading
787 *must be remove when ajax is successfull
790function waiting_box() {
792 id: 'wait_box', html: loading() + '<p>' + content[65] + '</p>'
794 var y = fixed_position(10, 250)
795 obj.style = y + ";width:20%;margin-left:40%;";
797 removeDiv('wait_box');
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
817function show_box(obj) {
820 g(obj.id).style.top = calcy(40) + "px";
826 var action = new Ajax.Request(
831 onFailure: eval(obj.js_error),
832 onSuccess: eval(obj.js_success)
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
842function success_box(req, json) {
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);
851 var name_ctl = a[0].firstChild.nodeValue;
852 var code_html = getNodeText(html[0]);
854 code_html = unescape_xml(code_html);
855 g(name_ctl).innerHTML = code_html;
856 g(name_ctl).style.height = 'auto';
858 if (name_ctl == 'popup')
859 g(name_ctl).style.width = 'auto';
861 alert_box("success_box" + e.message);
864 code_html.evalScripts();
866 alert_box(content[53] + "\n" + e.message);
870function error_box() {
871 alert_box(content[53]);
875 * show the ledger choice
877function show_ledger_choice(json_obj) {
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;
887 query = encodeURI(query);
888 var action = new Ajax.Request(
893 onFailure: ajax_misc_failure,
894 onSuccess: function (req, json) {
896 if (req.responseText === 'NOCONX') {
901 id: json_obj.div + 'jrn_search',
902 cssclass: 'inner_box',
903 style: ';position:absolute;width:auto;z-index:20;margin-left:20%',
909 obj.style = "top:" + y + 'px;' + obj.style;
910 /* if ( json_obj.class )
912 obj.cssclass=json_obj.class;
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);
924 var name_ctl = a[0].firstChild.nodeValue;
925 var code_html = getNodeText(html[0]);
927 code_html = unescape_xml(code_html);
928 remove_waiting_box();
929 g(obj.id).innerHTML = code_html;
932 alert_box("show_ledger_callback" + e.message);
935 code_html.evalScripts();
937 alert_box(content[53] + "\n" + e.message);
945 alert_box('show_ledger_choice' + e.message);
950 * hide the ledger choice
952function hide_ledger_choice(p_frm_search) {
954 var nb = $(p_frm_search).nb_jrn.value;
956 if ($(p_frm_search).div) {
957 div = $(p_frm_search).div.value;
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 + '">';
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');
977 alert_box('hide_ledger_choice' + e.message);
984 * show the cat of ledger choice
986function show_cat_choice() {
987 g('div_cat').style.visibility = 'visible';
991 * hide the cat of ledger choice
993function hide_cat_choice() {
994 g('div_cat').style.visibility = 'hidden';
998 * add a row for the forecast item
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();
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";
1030 * toggle all the checkbox in a given form
1031 * @param form_id id of the form
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) {
1048 * select all the checkbox in a given form
1049 * @param form_id id of the form
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') {
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
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) {
1079 * unselect all the checkbox in a given form
1080 * @param form_id id of the form
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') {
1093 * show the calculator
1095function show_calc() {
1097 this.document.getElementById('inp').value = "";
1098 this.document.getElementById('inp').focus();
1103 shtml += "<div class=\"bxbutton\">";
1104 shtml += '<a class="icon" onclick="pin(\'calc1\')" id="pin_calc1"></a> <a onclick="removeDiv(\'calc1\');" href="javascript:void(0)" title="" class="icon">⨉</a>';
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>';
1111 id: sid, html: shtml,
1112 drag: false, style: 'z-index:98'
1115 this.document.getElementById('inp').focus();
1118function display_periode(p_dossier, p_id) {
1121 var queryString = "gDossier=" + p_dossier + "&op=input_per" + "&p_id=" + p_id;
1123 'id': 'mod_periode',
1124 'cssclass': 'inner_box',
1126 'style': 'width:30em',
1129 if (!$('mod_periode')) {
1132 var action = new Ajax.Request(
1136 parameters: queryString,
1137 onFailure: ajax_misc_failure,
1138 onSuccess: success_display_periode
1141 $('mod_periode').style.top = (posY - 70) + "px";
1142 $('mod_periode').style.left = (posX - 70) + "px";
1144 alert_box("display_periode " + e.message);
1149function success_display_periode(req) {
1152 var answer = req.responseXML;
1153 var html = answer.getElementsByTagName('data');
1155 if (html.length === 0) {
1156 var rec = req.responseText;
1157 alert_box('erreur :' + rec);
1160 var code_html = getNodeText(html[0]);
1161 code_html = unescape_xml(code_html);
1163 $('mod_periode').innerHTML = code_html;
1165 alert_box("success_display_periode".e.message);
1168 code_html.evalScripts();
1170 alert_box(content[53] + "\n" + e.message);
1175function save_periode(obj) {
1177 var queryString = $(obj).serialize() + "&op=save_per";
1179 var action = new Ajax.Request(
1183 parameters: queryString,
1184 onFailure: ajax_misc_failure,
1185 onSuccess: success_display_periode
1190 alert_box("display_periode " + e.message);
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
1204function fill_box(req) {
1206 if (req.responseText == 'NOCONX') {
1210 remove_waiting_box();
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);
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;
1224 alert_box(e.message);
1227 console.error("log answer = " + req.responseText);
1231 code_html.evalScripts();
1235 console.error("log answer = " + req.responseText);
1237 alert_box(content[53] + "\n" + e.message);
1244 *display a popin to let you modified a predefined operation
1246 *@param od_id from table op_predef
1248function mod_predf_op(dossier_id, od_id, p_ledger) {
1249 var target = "mod_predf_op";
1251 var str_style = "top:10%;left:2%;width:96%";
1253 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1257 var qs = "gDossier=" + dossier_id + '&op=mod_predf&id=' + od_id + '&ledger_id=' + p_ledger;
1259 var action = new Ajax.Request('ajax_misc.php',
1270function save_predf_op(obj) {
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',
1277 parameters: querystring,
1279 onSuccess: refresh_window
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}
1297function search_reconcile(dossier, ctl_concern, amount_id, ledger, p_id_target, p_tiers) {
1298 if (amount_id === undefined) {
1300 } else if ($(amount_id)) {
1301 if ($(amount_id).value) {
1302 amount_id = $(amount_id).value;
1304 ($(amount_id).innerHTML) {
1305 amount_id = $(amount_id).innerHTML;
1312 if (p_id_target != "") {
1313 target = p_id_target;
1315 target = "search" + layer;
1318 var str_style = fixed_position(77, 99);
1319 str_style += ";width:92%;overflow:auto;";
1321 var hide_operation = $(ctl_concern).getAttribute("hide_operation");
1322 var single_operation = $(ctl_concern).getAttribute("single_operation");
1329 amount_id: amount_id,
1333 hide_operation: hide_operation,
1334 single_operation: single_operation
1337 var qs = encodeJSON(param_send);
1339 var action = new Ajax.Request('ajax_misc.php',
1344 onSuccess: function (req) {
1345 remove_waiting_box();
1346 var div = {id: target, cssclass: 'inner_box', style: str_style, drag: 0};
1348 $(target).innerHTML = req.responseText;
1349 req.responseText.evalScripts();
1356 * search in a popin obj if the object form
1358function search_operation(obj) {
1360 var dossier = g('gDossier').value;
1362 var target = "search" + layer;
1363 if ($(obj)["target"]) {
1364 target = $(obj)["target"].value;
1366 var qs = Form.serialize('search_form_ajx') + "&op=search_op";
1367 var action = new Ajax.Request('ajax_misc.php',
1372 onSuccess: function (req) {
1373 remove_waiting_box();
1374 $(target).innerHTML = req.responseText;
1375 req.responseText.evalScripts();
1380 remove_waiting_box();
1381 alert_box(e.message);
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
1390 * @returns {undefined}
1392function set_reconcile(obj) {
1395 var ctlc = obj.elements['ctlc'];
1396 var tiers = obj.elements['tiers'];
1397 if (!obj.elements['target'])
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++) {
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 += ',';
1413 if (tiers && tiers.value != "") {
1414 $(tiers.value).value = elmt.value;
1416 new Ajax.Request("fid.php", {
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"];
1431 if (single_operation == 0) {
1432 $(ctlc.value).value += nValue;
1434 $(ctlc.value).value = nValue;
1440 removeDiv(obj.elements['target'].value);
1442 alert_box(e.message)
1446function remove_waiting_node() {
1447 $('info_div').innerHTML = "";
1448 $('info_div').style.display = "none";
1452function remove_waiting_box() {
1453 if ($('wait_box')) {
1454 Effect.Fade('wait_box', {duration: 0.6});
1457 remove_waiting_node();
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}
1467function get_profile_detail(gDossier, profile_id) {
1469 var qs = "op=display_profile&gDossier=" + gDossier + "&p_id=" + profile_id + "&ctl=detail_profile";
1470 var action = new Ajax.Request('ajax_misc.php',
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');
1488function get_profile_detail_success_obsolete(xml) {
1489 remove_waiting_box();
1494 * compute the string to position a div in a fixed way
1497function fixed_position(p_sx, p_sy) {
1499 var sy = calcy(p_sy);
1501 var str_style = "top:" + sy + "px;left:" + sx + "px;position:absolute";
1507 * compute Y even if the windows has scrolled down or up
1508 *@return the correct Y position
1510function calcy(p_sy) {
1512 if (window.pageYOffset) {
1513 sy = window.pageYOffset + p_sy;
1515 sy = document.documentElement.scrollTop + p_sy;
1523 * display a box with the menu option
1524 * @param {type} gdossier
1525 * @param {type} pm_id
1526 * @returns {undefined}
1528function mod_menu(gdossier, pm_id) {
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',
1538 onSuccess: function (req) {
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;
1544 alert_box(e.message);
1552 * Display the submenu of a menu or a module, used in setting the menu
1554 * @param {type} p_dossier
1555 * @param {type} p_profile
1556 * @param {type} p_dep
1557 * @returns {undefined}
1559function display_sub_menu(p_dossier, p_profile, p_dep, p_level) {
1561 new Ajax.Request('ajax_misc.php',
1565 op: 'display_submenu',
1566 gDossier: p_dossier,
1568 p_profile: p_profile,
1571 onSuccess: function (req) {
1573 remove_waiting_box();
1574 if ($('menu_table').rows.length > p_level) {
1575 $('menu_table').rows[1].remove();
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);
1582 alert_box(e.message);
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}
1594function remove_sub_menu(p_dossier, profile_menu_id) {
1595 confirm_box(null, content[47],
1598 new Ajax.Request('ajax_misc.php',
1602 op: 'remove_submenu', gDossier: p_dossier,
1603 p_profile_menu_id: profile_menu_id
1605 onSuccess: function (req) {
1607 remove_waiting_box();
1608 $('sub' + profile_menu_id).remove();
1609 if ($('menu_table').rows.length > 1) {
1610 $('menu_table').rows[1].remove();
1614 alert_box(e.message);
1624 * add a menu to a profile, propose only the available menu
1625 * @param obj json object
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)
1633function add_menu(obj) {
1634 var pdossier = obj.dossier;
1635 var p_id = obj.p_id;
1636 var p_type = obj.type;
1639 removeDiv('divdm' + p_id);
1640 var pos = fixed_position(250, 150) + ";width:50%;";
1641 var action = new Ajax.Request('ajax_misc.php',
1646 'gDossier': pdossier,
1648 'ctl': 'divdm' + p_id,
1651 'p_level': obj.p_level
1654 onSuccess: function (req) {
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;
1660 alert_box(e.message);
1668 * Display a box to enter data for adding a new plugin from
1670 * @param {type} p_dossier
1671 * @returns {undefined}
1673function add_plugin(p_dossier) {
1675 removeDiv('divplugin');
1676 var qs = "op=add_plugin&gDossier=" + p_dossier + "&ctl=divplugin";
1678 var action = new Ajax.Request('ajax_misc.php',
1683 onSuccess: function (req) {
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;
1690 alert_box(e.message);
1699 * @param {type} p_dossier
1700 * @param {type} me_code
1701 * @returns {undefined}
1703function mod_plugin(p_dossier, me_code) {
1705 removeDiv('divplugin');
1706 var qs = "op=mod_plugin&gDossier=" + p_dossier + "&ctl=divplugin&me_code=" + me_code;
1708 var action = new Ajax.Request('ajax_misc.php',
1713 onSuccess: function (req) {
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;
1721 alert_box(e.message);
1728function create_menu(p_dossier) {
1730 removeDiv('divmenu');
1731 var qs = "op=create_menu&gDossier=" + p_dossier + "&ctl=divmenu";
1733 var action = new Ajax.Request('ajax_misc.php',
1738 onSuccess: function (req) {
1740 remove_waiting_box();
1741 var pos = fixed_position(250, 150) + ";width:30%";
1745 cssclass: "inner_box",
1748 $('divmenu').innerHTML = req.responseText;
1750 alert_box(e.message);
1757function modify_menu(p_dossier, me_code) {
1759 removeDiv('divmenu');
1760 var qs = "op=modify_menu&gDossier=" + p_dossier + "&ctl=divmenu&me_code=" + me_code;
1762 var action = new Ajax.Request('ajax_misc.php',
1767 onSuccess: function (req) {
1769 remove_waiting_box();
1770 var pos = fixed_position(250, 150) + ";width:30%";
1774 cssclass: "inner_box",
1777 $('divmenu').innerHTML = req.responseText;
1780 alert_box(e.message);
1787function get_properties(obj) {
1789 var s_type = "[" + typeof obj + "]";
1790 for (var m in obj) {
1793 alert_box(s_type + a_array.join(","));
1797 * add a line in the form for the report
1798 * @param p_dossier dossier id to connect
1800function rapport_add_row(p_dossier) {
1801 style = 'style="border: 1px solid blue;"';
1802 var table = $("rap1");
1803 var line = table.rows.length;
1805 var row = table.insertRow(line);
1807 var cellPos = row.insertCell(0);
1808 cellPos.innerHTML = '<input type="text" ' + style + ' size="3" id="pos' + line + '" name="pos' + line + '" value="' + line + '">';
1811 var cellName = row.insertCell(1);
1812 cellName.innerHTML = '<input type="text" ' + style + ' size="40" id="text' + line + '" name="text' + line + '">';
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();
1821 g('form' + line).value = '';
1825 * Search an action in an inner box
1827function search_action(dossier, ctl_concern) {
1830 var dossier = g('gDossier').value;
1832 var target = "search_action_div";
1834 var str_style = fixed_position(77, 99);
1836 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1842 op: 'search_action',
1846 var qs = encodeJSON(target);
1848 var action = new Ajax.Request('ajax_misc.php',
1853 onSuccess: function (req) {
1855 remove_waiting_box();
1857 $('search_action_div').innerHTML = req.responseText;
1858 req.responseText.evalScripts();
1860 alert_box(e.message);
1866 alert_box(e.message);
1870function result_search_action(obj) {
1872 var queryString = $(obj).serialize() + "&op=search_action";
1873 var action = new Ajax.Request(
1877 parameters: queryString,
1878 onFailure: ajax_misc_failure,
1879 onSuccess: function (req) {
1881 remove_waiting_box();
1882 $('search_action_div').innerHTML = req.responseText;
1883 req.responseText.evalScripts();
1885 alert_box(e.message);
1892 alert_box("display_periode " + e.message);
1898function set_action_related(p_obj) {
1902 var ctlc = obj.elements['ctlc'];
1904 for (var e = 0; e < obj.elements.length; e++) {
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 += ',';
1914 $(ctlc.value).value += nValue;
1918 removeDiv('search_action_div');
1921 alert_box(e.message);
1927 * Show a form to modify or add a new repository
1929 *@param r_id : repository id
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";
1937 removeDiv('change_stock_repo_div');
1939 var action = new Ajax.Request(
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;
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);
1958 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:80%;";
1960 removeDiv('view_mod_stock_div');
1962 var action = new Ajax.Request(
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();
1977function show_fin_chdate(obj_id) {
1979 var ch = $(obj_id).options[$(obj_id).selectedIndex].value;
1981 $('chdate_ext').hide();
1985 $('chdate_ext').show();
1988 var nb = $('nb_item').value;
1989 for (i = 0; i < nb; i++) {
1990 if ($('tdchdate' + i)) {
1992 $('tdchdate' + i).show();
1995 $('tdchdate' + i).hide();
2001 alert_box(e.message);
2006 * tab menu for the profile parameter
2008function profile_show(p_div) {
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++) {
2016 alert_box(e.message);
2020function detail_category_show(p_div, p_dossier, p_id) {
2023 $('detail_category_div').innerHTML = "";
2024 var queryString = "gDossier=" + p_dossier + "&id=" + p_id + "&op=fddetail";
2025 var action = new Ajax.Request(
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();
2042 * check that the form is correct for a new category of card
2044function check_new_category()
2046 if ( $('nom_mod_id').value.trim()=="") {
2047 new Effect.Highlight('nom_mod_id',{startcolor:"#ff0000"});
2048 smoke.alert('Nom catégorie obligatoire');
2051 var TemplateCard= document.getElementsByName('FICHE_REF');
2052 for (i = 0;i< TemplateCard.length;i++) {
2053 if (TemplateCard[i].checked) return true;
2055 new Effect.Highlight('template_category_ck',{startcolor:"#ff0000"});
2056 smoke.alert('Choisissez une catégorie');
2060 * check if the parameter is a valid a valid date or not, returns true if it is valid otherwise
2062 * @param p_str_date the string of the date (format DD.MM.YYYY)
2064function check_date(p_str_date) {
2065 var format = /^\d{2}\.\d{2}\.\d{4}$/;
2066 if (!format.test(p_str_date)) {
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]) {
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
2087function check_date_id(p_id_date) {
2088 var str_date = $(p_id_date).value;
2089 return check_date(str_date);
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
2098function view_action(ag_id, dossier, modify) {
2101 id = 'action' + layer;
2103 querystring = 'gDossier=' + dossier + '&op=vw_action&ag_id=' + ag_id + '&div=' + id + '&mod=' + modify;
2104 var action = new Ajax.Request(
2108 parameters: querystring,
2109 onFailure: error_box,
2110 onSuccess: function (req) {
2112 if (req.responseText === 'NOCONX') {
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';
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';
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;
2133 cssclass: "inner_box",
2136 $(id).innerHTML = code_html;
2137 if (ctl_txt == 'ok') {
2139 var detail = in_child(id, "follow_up_detail");
2141 compute_all_ledger();
2146 code_html.evalScripts();
2148 alert_box('view_action' + e.message);
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)
2162 * @see HtmlInput::filter_table
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);
2170 // if colnr contains a comma then check several columns
2171 var aCol = new Array();
2172 if (colnr.indexOf(',') >= 0) {
2173 aCol = colnr.split(',');
2180 for (var r = start_row; r < table.rows.length; r++) {
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) {
2195 table.rows[r].style.display = '';
2197 table.rows[r].style.display = 'none';
2199 $('info_div').style.display = "none";
2200 $('info_div').innerHTML = "";
2202 if (tot_found == 0) {
2203 if ($('info_' + _id)) {
2204 $('info_' + _id).innerHTML = content[69];
2207 if ($('info_' + _id)) {
2208 $('info_' + _id).innerHTML = " ";
2211 $('info_div').style.display = "none";
2212 $('info_div').innerHTML = "";
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
2220 * @see HtmlInput::filter_list
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);
2231 for (var r = 0; r < l_list.childNodes.length; r++) {
2234 if (l_list.childNodes[r].nodeType != 1) {
2238 let la_content = l_list.childNodes[r].getElementsByClassName("search-content");
2241 for (e = 0; e < la_content.length; e++) {
2242 ele += la_content[e].innerText;
2245 console.debug(`ele = ${ele}`);
2246 if (ele.toLowerCase().indexOf(words) >= 0) {
2248 l_list.childNodes[r].style.display = 'block';
2250 l_list.childNodes[r].style.display = 'none';
2254 if (tot_found == 0) {
2255 if ($('info_' + _id)) {
2256 $('info_' + _id).innerHTML = content[69];
2259 if ($('info_' + _id)) {
2260 $('info_' + _id).innerHTML = " ";
2263 $('info_div').style.display = "none";
2264 $('info_div').innerHTML = "";
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
2272 * @see HtmlInput::filter_list
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);
2282 for (var r = 0; r < l_list.options.length; r++) {
2284 var ele = l_list.options[r].text;
2286 if (ele.toLowerCase().indexOf(words) >= 0) {
2288 l_list.options[r].style.display = 'block';
2290 l_list.options[r].style.display = 'none';
2292 $('info_div').style.display = "none";
2293 $('info_div').innerHTML = "";
2295 if (tot_found == 0) {
2296 if ($('info_' + _id)) {
2297 $('info_' + _id).innerHTML = content[69];
2300 if ($('info_' + _id)) {
2301 $('info_' + _id).innerHTML = " ";
2308 * Display the task late or for today in dashboard
2310function display_task(p_id) {
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';
2321 * Set a message in the info
2323function info_message(p_message) {
2324 $('info_div').innerHTML = p_message;
2325 $('info_div').style.display = "block";
2331function info_hide() {
2332 $('info_div').style.display = "none";
2336 * Show the navigator in a internal window
2337 * @returns {undefined}
2339function ask_navigator(p_dossier) {
2342 removeDiv('navi_div')
2343 var queryString = "gDossier=" + p_dossier + "&op=navigator";
2344 var action = new Ajax.Request(
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;
2354 req.responseText.evalScripts();
2355 sorttable.makeSortable($("navi_tb"));
2357 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2364 info_message(e.message);
2370 * Display an internal windows to set the user's preference
2373function set_preference(p_dossier) {
2376 removeDiv('preference_div')
2377 var queryString = "gDossier=" + p_dossier + "&op=preference";
2378 var action = new Ajax.Request(
2381 method: 'get', parameters: queryString,
2382 onFailure: ajax_misc_failure,
2383 onSuccess: function (req) {
2384 remove_waiting_box();
2385 if (req.responseText === 'NOCONX') {
2389 add_div({id: 'preference_div', drag: 1});
2390 $('preference_div').innerHTML = req.responseText;
2392 req.responseText.evalScripts();
2394 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2401 info_message(e.message);
2407 * Display user's bookmark
2410function show_bookmark(p_dossier) {
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(
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;
2427 req.responseText.evalScripts();
2429 alert_box(content[53] + "\n" + e.message);
2436 info_message(e.message);
2444function save_bookmark() {
2447 var queryString = "op=bookmark&" + $("bookmark_frm").serialize();
2448 var action = new Ajax.Request(
2451 method: 'get', parameters: queryString,
2452 onFailure: ajax_misc_failure,
2453 onSuccess: function (req) {
2454 remove_waiting_box();
2455 // removeDiv('bookmark_div');
2457 $('bookmark_div').innerHTML = req.responseText;
2459 req.responseText.evalScripts();
2461 alert_box(content[53] + "\n" + e.message);
2468 info_message(e.message);
2474 * remove selected bookmark
2476function remove_bookmark() {
2479 var queryString = "op=bookmark&" + $("bookmark_del_frm").serialize();
2480 var action = new Ajax.Request(
2483 method: 'get', parameters: queryString,
2484 onFailure: ajax_misc_failure,
2485 onSuccess: function (req) {
2486 remove_waiting_box();
2487 $('bookmark_div').innerHTML = req.responseText;
2489 req.responseText.evalScripts();
2491 alert_box(content[53] + "\n" + e.message);
2498 error_message(e.message);
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
2508function error_message(message) {
2509 $('error_content_div').innerHTML = message;
2510 $('error_div').style.visibility = 'visible';
2514 * show the detail of a tag and propose to save it
2516function show_tag(p_dossier, p_ac, p_tag_id, p_post) {
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(
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);
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;
2539 code_html.evalScripts();
2541 alert_box(content[53] + "\n" + e.message);
2548 error_message(e.message);
2553 * save the modified tag
2555function save_tag() {
2558 var queryString = "op=tag_save&" + $("tag_detail_frm").serialize();
2559 var action = new Ajax.Request(
2563 parameters: queryString,
2564 onFailure: ajax_misc_failure,
2565 onSuccess: function (req, j) {
2566 remove_waiting_box();
2567 removeDiv('tag_div');
2572 error_message(e.message);
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}
2585function action_tag_select(p_dossier, ag_id) {
2588 var queryString = "ag_id=" + ag_id + "&op=tag_list&gDossier=" + p_dossier;
2589 var action = new Ajax.Request(
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);
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});
2606 remove_waiting_box();
2607 $('tag_div').innerHTML = code_html;
2612 error_message(e.message);
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}
2623function action_tag_add(p_dossier, ag_id, t_id, p_isgroup) {
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(
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);
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');
2648 error_message(e.message);
2653 * remove the current tag to the current ag_id
2654 * @param {type} p_dossier
2655 * @param {type} ag_id
2656 * @returns {undefined}
2658function action_tag_remove(p_dossier, ag_id, t_id) {
2659 confirm_box(null, content[50], function () {
2662 var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_remove&gDossier=" + p_dossier;
2663 var action = new Ajax.Request(
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);
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;
2684 error_message(e.message);
2691 * @param int p_dossier
2692 * @param int p_tag_id
2694function activate_tag(p_dossier, p_tag_id) {
2696 new Ajax.Request("ajax_misc.php",
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();
2712 * Display a div with available tags, this div can update the cell
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}
2720function search_display_tag(p_dossier, p_prefix, p_object) {
2723 var queryString = {op: "search_display_tag", gDossier: p_dossier, pref: p_prefix, caller_obj: p_object};
2724 var action = new Ajax.Request(
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);
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();
2749 error_message(e.message);
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
2761function search_add_tag(p_dossier, p_tag_id, p_prefix, p_obj) {
2763 var clear_button = 0;
2764 if (tag_choose === '' && p_prefix === 'search') {
2765 tag_choose = $(p_prefix + 'tag_choose_td').innerHTML;
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(
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);
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');
2791 error_message(e.message);
2796 * Clear the tags in the cell tag_choose_td of the search screen
2797 * @returns {undefined}
2799function search_clear_tag(p_dossier, p_prefix) {
2800 if (p_prefix != 'search') {
2801 $(p_prefix + 'tag_choose_td').innerHTML = "";
2805 var queryString = "op=search_clear_tag&gDossier=" + p_dossier + "&pref=" + p_prefix;
2806 var action = new Ajax.Request(
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);
2818 var code_html = getNodeText(html[0]);
2819 code_html = unescape_xml(code_html);
2820 $(p_prefix + 'tag_choose_td').innerHTML = code_html;
2826 error_message(e.message);
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';
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';
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)
2853function calendar_zoom(obj) {
2856 var per_periode = null;
2859 if ($(obj.invalue)) {
2860 per_periode = $(obj.invalue).value;
2862 if (obj.notitle && obj.notitle == 1) {
2865 var action = new Ajax.Request(
2871 "op": 'calendar_zoom',
2873 'gDossier': obj.gDossier,
2876 'distype': obj.distype
2878 onFailure: ajax_misc_failure,
2879 onSuccess: function (req, j) {
2880 if (req.responseText === 'NOCONX') {
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);
2890 var code_html = getNodeText(html[0]);
2891 code_html = unescape_xml(code_html);
2893 // if the target doesn't exist
2895 if (obj.outdiv === undefined) {
2896 obj.outdiv = 'calendar_zoom_div';
2898 if ($(obj.outdiv) == undefined) {
2899 var str_style = 'top:10%;min-height:60rem';
2900// var str_style = fixed_position(0, 120);
2903 style: 'width:94%;' + str_style,
2904 cssclass: "inner_box",
2908 remove_waiting_box();
2909 $(obj.outdiv).innerHTML = code_html;
2910 $(obj.outdiv).show();
2915 error_message('calendar_zoom ' + e.message);
2922 * add a line in the form for the stock
2924function stock_add_row() {
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);
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");
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();
2947 g("sg_code" + nb.value).innerHTML = ' ';
2948 g("sg_code" + nb.value).value = '';
2949 g("label" + nb.value).innerHTML = '';
2950 g("sg_quantity" + nb.value).value = '0';
2954 new_tt.evalScripts();
2956 alert_box(e.message);
2961function show_description(p_id) {
2962 $('print_desc' + p_id).hide();
2963 $('input_desc' + p_id).show();
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
2972function select_cat(pn_fiche_card_id, pn_dossier_id, ps_element_id) {
2974 "ctl": "div_new_card",
2975 "fd_id": pn_fiche_card_id,
2978 gDossier: pn_dossier_id,
2979 "elementId": ps_element_id
2981 removeDiv('select_card_div');
2985 * Show the DIV and hide the other, the array of possible DIV are
2987 * @param {array} a_tabs name of possible tabs
2988 * @param {strng} p_display_tab tab to display
2990function show_tabs(a_tabs, p_display_tab) {
2992 if (a_tabs.length == 0) {
2993 console.error('a_tabs in empty');
2994 throw ("a_tabs empty");
2998 for (i = 0; i < a_tabs.length; i++) {
2999 $(a_tabs[i]).hide();
3001 $(p_display_tab).show();
3003 alert_box(e.message);
3009 * Change the class of all the "LI" element of a UL or OL
3010 * @param node of ul (this)
3012function unselect_other_tab(p_tab) {
3014 var other = p_tab.getElementsByTagName("li");
3017 for (i = 0; i < other.length; i++) {
3019 tab.className = "tabs";
3023 console.error(e.message);
3024 alert_box('unselect_other_tab ' + e.message);
3029 * logout function call from ajax
3030 * @see ajax_disconnected
3031 * @returns {undefined}
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;
3042 * Create a div which can be used in a anchor
3043 * @returns {undefined}
3045function create_anchor_up() {
3046 if (document.getElementById('up_top'))
3049 var newElt = document.createElement('div');
3050 newElt.setAttribute('id', 'up_top');
3051 newElt.innerHTML = '<a id="up_top"></a>';
3053 var parent = $('info_div').parentNode;
3054 parent.insertBefore(newElt, $('info_div'));
3059 * Initialize the window to show the button "UP" if the window is scrolled
3061 * @returns {undefined}
3063function init_scroll() {
3064 var up = new Element('div', {
3066 "style": "padding:5px;left:auto;width:auto;height: auto;display:none;position:fixed;bottom:30%;right:50px;text-align:center;font-size:20px",
3069 up.innerHTML = '<a class="icon" onclick="document.getElementById(\'go_up\').hide()" style="float:right;font-size:70%"></a> <a class="icon" href="#up_top" ></a><a href="javascript:show_calc()" class="icon"></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"})
3076 if (document.viewport.getScrollOffsets().top > 0) {
3077 if ($('go_up').visible() == false) {
3078 $('go_up').setOpacity(0.65);
3080 $('go_up').style.zIndex = 99;
3088function loading_page() {
3089 var id_page = new Element('div', {
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" +
3098 " text-align: center;\n" +
3099 " animation-name: fill_up_loading;\n" +
3100 " animation-duration: 8s;\n" +
3101 " animation-iteration-count: infinite;"+
3103 "border-radius: 5px;"+
3105 "animation-timing-function: linear;",
3106 id: "loading_page_div"
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);
3112 * Confirm a form thanks a modal dialog Box, it returns true if we agree otherwise
3115 <form onsubmit="return confirm_box(this,'message')">
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
3124function confirm_box(p_obj, p_message, p_callback_true, p_waiting) {
3127 // Find id of the end
3129 if (p_obj != null) {
3130 if (typeof (p_obj) === "object") {
3137 // execute the callback function or submit the form
3138 if (!p_callback_true) {
3140 smoke.confirm(p_message, function (e) {
3149 smoke.confirm(p_message, function (e) {
3151 p_callback_true.apply();
3156 alert_box(e.message);
3158 remove_waiting_box();
3163 * Alert box in CSS and HTML to replace the common javascript alert
3164 * @param p_message message to display
3167function alert_box(p_message) {
3168 smoke.alert(p_message, undefined, {ok: 'ok', classname: "inner_box"});
3173 * Colorize the rows of the table
3174 * @param string p_table id of the table
3176function alternate_row_color(p_table) {
3177 var table_colored = $(p_table);
3178 if (!table_colored.tBodies[0]) return;
3180 var len = table_colored.tBodies[0].rows.length;
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");
3188 if (table_colored.tBodies[0].rows[i].hasClassName("even")) {
3189 table_colored.tBodies[0].rows[i].removeClassName("even");
3191 table_colored.tBodies[0].rows[i].addClassName(localClass);
3196 * Colorize the rows of the list
3197 * @param p_list {string} DOM id of the list
3199function alternate_row_color_list(p_list) {
3200 var list_colored = $(p_list);
3201 if ( list_colored.children.length==0 ) return;
3203 var len = list_colored.children.length;
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");
3211 if (list_colored.children[i].hasClassName("even")) {
3212 list_colored.children[i].removeClassName("even");
3214 list_colored.children[i].addClassName(localClass);
3221 * Make an DOM element draggable or not
3222 * @param object_id DOM id
3224function pin(object_id) {
3225 if (aDraggableElement[object_id]) {
3226 aDraggableElement[object_id].destroy();
3227 aDraggableElement[object_id] = undefined;
3228 $('pin_' + object_id).innerHTML = "";
3230 aDraggableElement[object_id] = new Draggable(object_id, {
3231 starteffect: function () {
3232 new Effect.Highlight(object_id, {scroll: window, queue: 'end'});
3236 $('pin_' + object_id).innerHTML = "";
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
3247function show_only_row(p_table_id, p_attribute_name, p_attribute_value) {
3248 if (!$(p_table_id)) {
3249 throw "Invalide table id"
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) {
3264 * Show all the rows into the table (p_table_id)
3265 * @param p_table_id table id
3267function show_all_row(p_table_id) {
3268 if (!$(p_table_id)) {
3269 throw "Invalide table id"
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];
3284 * - id of the row of the periode row_per_(p_periode_id) , attribute exercice =per_exercice,periode_id=p_id
3286 * - id of the table with the rows : periode_tbl
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}
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
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';
3304 this.js_obj_name = "";
3305 this.ajax_test = "";
3306 this.set_callback = function (p_phpfile) {
3307 this.pcallback = p_phpfile;
3309 this.set_dossier = function (p_dosid) {
3310 this.dossier = p_dosid;
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
3318 this.set_js_obj_name = function (p_js_obj_name) {
3319 this.js_obj_name = p_js_obj_name;
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
3327 this.remove = function (p_periode_id) {
3330 "gDossier": this.dossier,
3333 "p_id": p_periode_id,
3335 "js_var": this.js_obj_name
3337 if (this.ajax_test != "") {
3338 js_param["TestAjaxFile"] = this.ajax_test;
3341 smoke.confirm("Confirmer ?", function (e) {
3344 new Ajax.Request(here.pcallback,
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");
3355 smoke.alert(answer.content);
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
3370 this.box_display = function (p_periode_id) {
3371 if (this.js_obj_name == "") {
3372 smoke.alert("ERROR BOX_ADD")
3376 "gDossier": this.dossier,
3379 "p_id": p_periode_id,
3380 "ledger_id": this.p_ledger,
3381 "js_var": this.js_obj_name
3383 if (this.ajax_test != "") {
3384 js_param["TestAjaxFile"] = this.ajax_test;
3387 new Ajax.Request(here.pcallback,
3390 parameters: js_param,
3391 onSuccess: function (req) {
3392 remove_waiting_box();
3393 var json = req.responseText.evalJSON();
3396 "id": "mod_periode",
3397 "style": "position:fixed;top:" + y + "px;width:50%",
3398 "cssclass": "inner_box",
3401 $('mod_periode').update(json.content);
3406 * close the periode, call ajax and receive a json object with the attribute
3408 * @parameter p_periode_id is the id of periode
3410 this.close_periode = function (p_periode_id) {
3411 if (this.js_obj_name == "") {
3412 smoke.alert("ERROR BOX_ADD")
3415 if (this.ajax_test != "") {
3416 js_param["TestAjaxFile"] = this.ajax_test;
3419 smoke.confirm("Confirmer ?", function (e) {
3421 here._close(p_periode_id);
3426 * Internal function to close without confirming
3427 * @param {type} p_periode_id
3428 * @returns {undefined}
3430 this._close = function (p_periode_id) {
3431 if (this.js_obj_name == "") {
3432 smoke.alert("ERROR BOX_ADD")
3435 "gDossier": this.dossier,
3438 "ledger_id": this.p_ledger,
3439 "p_id": p_periode_id,
3440 "js_var": this.js_obj_name
3442 if (this.ajax_test != "") {
3443 js_param["TestAjaxFile"] = this.ajax_test;
3447 new Ajax.Request(here.pcallback,
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'});
3458 smoke.alert(json.content);
3464 * reopen the periode
3465 * @parameter p_periode_id is the SQL id of parm_periode or the id of
3468 this.open_periode = function (p_periode_id) {
3469 if (this.js_obj_name == "") {
3470 smoke.alert("ERROR BOX_ADD")
3473 "gDossier": this.dossier,
3476 "ledger_id": this.p_ledger,
3477 "p_id": p_periode_id,
3478 "js_var": this.js_obj_name
3480 if (this.ajax_test != "") {
3481 js_param["TestAjaxFile"] = this.ajax_test;
3484 smoke.confirm("Confirmer ?", function (e) {
3487 new Ajax.Request(here.pcallback,
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',
3501 smoke.alert(json.content);
3509 * This DOMID of the DIV containing the form is mod_periode
3510 * @param {type} p_frm
3511 * @returns {Boolean}
3513 this.save = function (p_frm) {
3514 var js_param = $(p_frm).serialize(true);
3516 js_param["js_var"] = this.js_obj_name;
3517 js_param["act"] = "save";
3518 js_param["op"] = "periode";
3520 new Ajax.Request(this.pcallback, {
3522 parameters: js_param,
3523 onSuccess: function (req) {
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',
3535 smoke.alert(answer.content);
3542 * Thanks the object DOMID sel_per_closed[] the selected periodes are
3544 * @see Periode._close
3546 this.close_selected = function () {
3548 var a_selected = document.getElementsByName('sel_per_close[]');
3551 for (i = 0; i < a_selected.length; i++) {
3552 if (a_selected[i].checked == true) {
3553 // Close the selected periode
3558 smoke.signal("Sélectionner au moins une période", function () {
3559 }, {duration: 1500});
3562 smoke.confirm("Confirmer fermeture de " + count + " periode", function (e) {
3564 var a_selected = document.getElementsByName('sel_per_close[]');
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);
3577 * Insert a periode into the list, always at the bottom !
3579 * # FORM id :insert_periode_frm
3580 * # DIV id = periode_add
3581 * # table id = periode_tbl
3583 this.insert_periode = function () {
3584 var p_frm = 'insert_periode_frm';
3585 var js_param = $(p_frm).serialize(true);
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";
3593 new Ajax.Request(this.pcallback, {
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);
3605 $('periode_add').hide();
3606 new Effect.Highlight('row_per_' + answer.p_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3607 alternate_row_color('periode_tbl');
3609 smoke.alert(answer.content);
3618 * Show the periodes from the exercice contained into the id (p_exercice_sel)
3619 * @param p_table_id DOM ID of the table
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) {
3628 } else if (selected_value == exercice) {
3637// keep track of progress bar
3638var progressBar = [];
3639// idx of progress bar
3643 * Start the progress bar
3644 * @param {string} p_taskid id to monitor
3645 * @param {int} p_message
3647function progress_bar_start(p_taskid, p_message) {
3652 var message = '<p>' + content[70] + '</p>';
3654 message = p_message;
3657 add_div({id: "blocking" + progressIdx, cssclass: "smoke-base smoke-visible "});
3660 id: "message" + progressIdx,
3661 cssclass: "inner_box",
3662 style: "z-index:1000;position:fixed;top:30%;width:40%;left:30%"
3664 $("message" + progressIdx).update('<h3>' + content[65] + '</h3>' + message);
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);
3670 console.error(e.message);
3675 * Check every second the status
3676 * @param {integer} p_idx idx of progressbar
3677 * @param {string} p_taskid id to monitor
3679function progress_bar_check(p_idx, p_taskid) {
3682 new Ajax.Request("ajax_misc.php", {
3683 parameters: {gDossier: 0, task_id: p_taskid, op: "progressBar"},
3685 onSuccess: function (req) {
3687 var answer = req.responseText.evalJSON();
3688 var progress_div = $("progressDiv" + progressIdx);
3689 var a_child = progress_div.childNodes;
3691 for (i = 0; i < a_child.length; i++) {
3692 if (a_child[i].id = "progressValue") {
3693 var progressValue = a_child[i];
3696 var progress = parseFloat(progressValue.innerHTML);
3697 if (answer.value <= progress) {
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
3714 clearInterval(progressBar[p_idx]);
3715 document.getElementById("progressValue").innerHTML = req.responseText;
3716 console.error(e.message);
3721 clearInterval(progressBar[p_idx]);
3722 console.error(e.message);
3727 * In the user's setting box, update the period list with the choosen exercice
3728 * @param {int} p_dossier
3730function updatePeriodePreference(p_dossier) {
3732 var exercice = $('exercice_setting').value;
3733 new Ajax.Updater('setting_period', "ajax_misc.php", {
3735 parameters: {"op": "pref_exercice", "gDossier": p_dossier, "exercice": exercice}
3737 remove_waiting_box();
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
3748function updatePeriode(p_dossier, p_exercice, p_periode_from, p_periode_to, p_last) {
3750 var exercice = $(p_exercice).value;
3751 new Ajax.Updater(p_periode_from, "ajax_misc.php",
3755 op: "periode_change", "gDossier": p_dossier, "exercice": exercice,
3756 field: p_periode_from, "type": "from", "last": p_last
3759 if (p_periode_to && p_last) {
3760 new Ajax.Updater(p_periode_to, "ajax_misc.php",
3764 op: "periode_change", "gDossier": p_dossier, "exercice": exercice,
3765 field: p_periode_to, "type": "to", "last": p_last
3769 remove_waiting_box();
3774 * @param {string} p_domid DOM id of the span containing the padlock icon
3777function toggle_lock(p_domid) {
3778 var padlock = document.getElementById(p_domid);
3779 if (padlock == null) {
3780 console.error("domid invalid");
3782 var status = padlock.getAttribute("is_locked");
3784 padlock.innerHTML = "";
3785 padlock.setAttribute("is_locked", 0);
3786 } else if (status == 0) {
3787 padlock.innerHTML = "";
3788 padlock.setAttribute("is_locked", 1);
3790 throw "toggle_lock failed";
3798 * @returns {undefined}
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",
3807 parameters: {"op": "currencyCode", "gDossier": dossier, "ledger": ledger}
3812 * Update Preference, applied the new CSS
3814function updatePreference() {
3817 var param = $('preference_frm').serialize() + "&op=preference&action=save";
3819 new Ajax.Request("ajax_misc.php", {
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']);
3828 removeDiv('preference_div');
3833 smoke.alert(content[48] + e.message);
3835 remove_waiting_box();
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
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 = '';
3849 $(icon_domid).style = 'color:green';
3851 $(p_value_domid).value = 0;
3852 $(icon_domid).innerHTML = '';
3853 $(icon_domid).style = 'color:red';
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
3863function toggle_checkbox_onoff(icon_domid, p_value_domid) {
3865 if ($(p_value_domid).value == 0) {
3866 $(p_value_domid).value = 1;
3867 $(icon_domid).innerHTML = '';
3869 $(p_value_domid).value = 0;
3870 $(icon_domid).innerHTML = '';
3875 * in C0JRN show or hide the row depending if the warning is enable or not
3877 * @param {type} p_enable
3878 * @param {type} p_row
3879 * @returns {undefined}
3881function toggle_row_warning_enable(p_enable, p_row) {
3882 var warning = document.getElementsByName('negative_amount')[0].value
3883 if ( warning == 1) {
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
3897function json_concat(p_json1, p_json2) {
3900 for (var key in p_json1) {
3901 result[key] = p_json1[key];
3903 for (var key in p_json2) {
3904 result[key] = p_json2[key];
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
3916function uncheck_other(p_click, p_name) {
3917 var aCheckbox = document.getElementsByName(p_name);
3918 if (aCheckbox.length == 0) return;
3920 for (i = 0; i < aCheckbox.length; i++) {
3921 aCheckbox[i].checked = false;
3923 p_click.checked = true;
3927 * @class operation Tag Manage the tag with operations
3928 * @returns {undefined}
3930var operation_tag = function (p_div) {
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}
3938 this.select = function (p_dossier, p_jrn_id) {
3941 var queryString = {jrn_id: p_jrn_id, op: "operation_tag_select", gDossier: p_dossier, ctl: this.ctl};
3942 var action = new Ajax.Request(
3946 parameters: queryString,
3947 onFailure: ajax_misc_failure,
3948 onSuccess: function (req, j) {
3949 remove_waiting_box();
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);
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});
3962 remove_waiting_box();
3963 $('tag_div').innerHTML = code_html;
3968 error_message(e.message);
3973 * Add the current tag to the current ag_id
3974 * @param {int} p_dossier
3976 * @param p_isgroup g it is a group , t is a single tag
3979 this.add = function (p_dossier, p_jrn_id, t_id, p_isgroup) {
3983 t_id: t_id, jrn_id: p_jrn_id, op: "operation_tag_add",
3984 gDossier: p_dossier, ctl: this.ctl, isgroup: p_isgroup
3987 var action = new Ajax.Request(
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);
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');
4008 error_message(e.message);
4012 * remove the current tag to the current ag_id
4013 * @param {int} p_dossier
4014 * @param {int} ag_id
4017 this.remove = function (p_dossier, p_jrn_id, t_id) {
4019 confirm_box(null, content[50], function () {
4025 op: "operation_tag_remove",
4026 gDossier: p_dossier,
4029 var action = new Ajax.Request(
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);
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;
4051 error_message(e.message);
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
4063function check_file_size(p_object, p_max_size) {
4065 for (var i = 0; i < p_object.elements.length; i++) {
4066 var a = p_object.elements[i];
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]) {
4072 sum_file += p_object.elements[i].files[x].size;
4077 if (sum_file > p_max_size) {
4078 alert_box(content[78]);
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
4091function check_receipt_size(p_max_size, p_info) {
4092 document.getElementById(p_info).style.display = "inline";
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";
4100 document.getElementById("receipt_info_id").innerHTML = "";
4101 document.getElementById("form_file").submit();
4106 * toggle size of a div : fullsize or normal
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 = '';
4116 div_dom.addClassName('fullsize');
4117 $('size_' + p_div).innerHTML = '';
4123 * download a document from an url
4125function download_document(p_url) {
4127 document.location = p_url;
4128 remove_waiting_box();
4132 * download a document from a form
4134function download_document_form(p_form_id) {
4136 var url = "export.php?" + $(p_form_id).serialize();
4137 document.location = url;
4138 remove_waiting_box();
4143 * Pause a javascript
4145function pausecomp(millis) {
4146 var date = new Date();
4149 curDate = new Date();
4151 while (curDate - date < millis);
4155 * propose to reconnect
4156 * @returns {undefined}
4158function reconnect() {
4159 remove_waiting_box();
4160 new Ajax.Request('ajax_misc.php', {
4162 parameters: {op: "disconnect"},
4163 onSuccess: function (req) {
4164 var pos = "position:fixed;top:0px;width:95%;height:95%";
4166 'id': "reconnect_bx",
4167 cssclass: "inner_box",
4170 div.innerHTML = req.responseText;
4176 * enlarge an INPUT TEXT
4179function enlarge_text(p_domid, p_size) {
4181 var element = document.getElementById(p_domid);
4183 console.error(`enlarge text doesn't exist [${p_domid}]`)
4185 var current_size = parseInt(element.getAttribute('size'));
4186 element.setAttribute('size', current_size + parseInt(p_size));
4188 console.error(`enlarge text fails with ${p_domid} ${p_size} `);
4189 console.error(e.message);
4196 * @brief display a box with the customer , supplier or event for today or late
4197 * @param p_detail , what to do
4199function event_display_detail(p_dossier, p_detail) {
4202 // create div if not exists
4203 var dgbox = "situation_detail_div";
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(
4212 parameters: queryString,
4213 onFailure: ajax_misc_failure,
4214 onSuccess: function (req) {
4215 remove_waiting_box();
4216 if (req.responseText == 'NOCONX') {
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});
4226 $(dgbox).update(req.responseText)
4231 event_display_main(p_dossier);
4233 alert_box(e.message);
4238 * @brief refresh the main display in the dashboard to reflect possible changes
4241function event_display_main(p_dossier) {
4244 var dgbox = "situation_div";
4245 var queryString = {gDossier: p_dossier, op: 'event_display_detail', 'what': "main_display"};
4246 var action = new Ajax.Request(
4250 parameters: queryString,
4251 onFailure: ajax_misc_failure,
4252 onSuccess: function (req) {
4253 remove_waiting_box();
4254 if (req.responseText == 'NOCONX') {
4259 $(dgbox).update(req.responseText)
4265 alert_box(e.message);
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
4274function check_password_strength(p_pass_domid, p_result_domid, details) {
4276 if ($(p_pass_domid).value == "") {
4277 $(p_result_domid).update("");
4281 'op': "password_chk"
4282 , pass: $(p_pass_domid).value
4284 var action = new Ajax.Request(
4288 parameters: queryString,
4289 onFailure: ajax_misc_failure,
4290 onSuccess: function (req) {
4291 remove_waiting_box();
4292 if (req.responseText == 'NOCONX') {
4295 var answer = req.responseJSON;
4296 console.debug(answer);
4297 if (answer['password'] == 'nok') {
4299 $(p_pass_domid).setStyle("background-color:red");
4301 $(p_result_domid).update(answer['msg'])
4305 $(p_pass_domid).setStyle("background-color: lightgreen");
4306 $(p_result_domid).update("")
4311 alert_box(e.message);
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)
4320function activate_plugin(elt)
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
4334 var action = new Ajax.Request(
4338 parameters:queryString,
4339 onFailure:ajax_misc_failure,
4340 onSuccess:function(req){
4341 remove_waiting_box();
4342 if (req.responseText == 'NOCONX') {
4347 if (req.responseText != 'OK') {
4348 smoke.alert(req.responseText)
4356 alert_box(e.message);
4359/**********************************************************************************************************************/
4363/**********************************************************************************************************************/
4365Widget = function(dossier_id) {
4366 this.dossier_id=dossier_id;
4369 * Display the widget in the elt box
4370 * @param box DOMID of the target
4372 * @param user_widget_id
4373 * @param widget_code
4375Widget.prototype.display = function (box,user_widget_id,widget_code) {
4379 gDossier: this.dossier_id,
4381 'user_widget_id': user_widget_id,
4382 'widget_code': widget_code,
4383 'action': 'widget.display'
4385 var action = new Ajax.Request(
4389 parameters: queryString,
4390 onFailure: ajax_misc_failure,
4391 onSuccess: function (req) {
4392 if (req.responseText == 'NOCONX') {
4396 $(box).replace(req.responseText);
4402 alert_box(e.message);
4410 * @returns {boolean}
4412Widget.prototype.manage = function () {
4415 var box = 'widget_box_id';
4417 gDossier: this.dossier_id,
4419 'action': 'widget.manage'
4421 var action = new Ajax.Request(
4425 parameters: queryString,
4426 onFailure: ajax_misc_failure,
4427 onSuccess: function (req) {
4428 if (req.responseText == 'NOCONX') {
4432 var style = 'position:absolute;';
4434 style = style + ' ;top : ' + y + 'px';
4436 add_div({id: box, cssclass: 'inner_box', html: loading(), style: style,drag:false})
4438 $(box).update(req.responseText);
4443 alert_box(e.message);
4444 console.error("widget_manage" + e.message);
4449 * create a list of sortable elements
4451Widget.prototype.create_sortable=function() {
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');
4457 * Save the order of widget
4459Widget.prototype.save = function () {
4463 var dgbox="widget_box_id";
4466 // For form , most of the parameters are in the FORM
4467 // method is then POST
4468 //var queryString=$(p_form_id).serialize(true);
4472 action : 'widget.save',
4473 gDossier: this.dossier_id,
4474 param : Sortable.serialize('contain_widget')
4476 var action = new Ajax.Request(
4480 parameters:queryString,
4481 onFailure:ajax_misc_failure,
4482 onSuccess:function(req){
4483 remove_waiting_box();
4484 if (req.responseText == 'NOCONX') {
4496 alert_box(e.message);
4498 this.remove_ident();
4501 * refresh the DASHBOARD (dashboard_div_id)
4503Widget.prototype.refresh = function () {
4506 var dgbox='dashboard_div_id'
4509 action : 'widget.refresh',
4510 gDossier: this.dossier_id
4512 var action = new Ajax.Request(
4516 parameters:queryString,
4517 onFailure:ajax_misc_failure,
4518 onSuccess:function(req){
4519 if (req.responseText == 'NOCONX') {
4524 $(dgbox).replace(req.responseText);
4530 console.error("widget.refresh "+e.message)
4534 * delete a widget : remove from the list
4535 * @param user_widget_id {integer}
4537Widget.prototype.delete=function (user_widget_id) {
4538 $('elt_'+user_widget_id).remove()
4539 $('order_widget_hidden').value=Sortable.serialize('contain_widget');
4542 * display list widget we can add
4544Widget.prototype.input = function () {
4546 var box="widget_box_select_id";
4550 action: 'widget.input',
4551 gDossier: this.dossier_id
4553 var action = new Ajax.Request(
4557 parameters: queryString,
4558 onFailure: ajax_misc_failure,
4559 onSuccess: function (req) {
4560 remove_waiting_box();
4561 if (req.responseText == 'NOCONX') {
4565 var style = 'position:absolute;';
4567 style = style + ' ;top : ' + y + 'px';
4569 add_div({id: box, cssclass: 'inner_box', html: loading(), style: style})
4571 $(box).update(req.responseText);
4578 alert_box(e.message);
4582 * add a widget for the user , refresh the dashboard afterward
4583 * @param widget_code {string}
4585Widget.prototype.add=function (widget_code) {
4590 if ($(widget_code+"_param")) {
4591 param=$(widget_code+"_param").serialize()
4595 action : 'widget.insert',
4596 gDossier: this.dossier_id,
4598 widget_code:widget_code
4600 var action = new Ajax.Request(
4605 onFailure:ajax_misc_failure,
4606 onSuccess:function(req){
4607 if (req.responseText == 'NOCONX') {
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()
4622 alert_box(e.message);
4627 * Show the number in the widget to improve the ergonomy
4629Widget.prototype.show_ident = function ()
4631 var aBox = document.getElementsByClassName('widget-box') ;
4634 for (var e=0;e <nb; e++) {
4635 if (aBox[e].visible)
4637 var spanx=new Element('span');
4638 spanx.addClassName("box_ident");
4639 aBox[e].insertBefore(spanx,aBox[e].firstChild);
4646 * Hide the number of the widget
4648Widget.prototype.remove_ident = function ()
4651 var elt=document.getElementsByClassName("box_ident");
4652 if ( elt.length == 0) break;
4658 * Put the widget in full size
4659 * @param widget_domid {string} dom id of the widget to toggle the size
4661Widget.prototype.toggle_full_size=function (widget_domid) {
4662 if ( $(widget_domid).hasClassName('widget-full_size')) {
4663 $(widget_domid).removeClassName('widget-full_size');
4665 $(widget_domid).addClassName('widget-full_size');
4668 $(widget_domid).style.zIndex=layer;
4676(function(){window.addEventListener("beforeunload", (event) => {waiting_box()});})();
4678(function(){window.addEventListener("onload", (event) => {remove_waiting_box()});})();