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
23 * \brief javascript script, always added to every page
27 // tag_choose Element which contains all the selected tags
29 var aDraggableElement = new Array();
31 // document.viewport depends of prototype.js
32 var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
33 var width = viewport.width; // Usable window width
34 var height = viewport.height;
36 * return undefined if nothing is found , otherwise return the DOM elemnt
37 * @param {type} p_name_dom
38 * @param {type} name_child
39 * @returns {undefined}
41 function in_child(p_element,name_child) {
43 if ( typeof p_element !== "object" ) {
44 element=document.getElementById(p_element);
47 if ( ! element ) return undefined;
48 for ( var e=0; e < element.childElementCount;e++) {
49 if ( element.childNodes[e].id == name_child) {
50 return element.childNodes[e];
55 * callback function when we just need to update a hidden div with an info
58 function infodiv(req, json)
63 var answer = req.responseXML;
64 var a = answer.getElementsByTagName('ctl');
65 var html = answer.getElementsByTagName('code');
68 var rec = req.responseText;
69 alert_box('erreur :' + rec);
71 var name_ctl = a[0].firstChild.nodeValue;
72 var code_html = getNodeText(html[0]);
74 code_html = unescape_xml(code_html);
75 g(name_ctl + "info").innerHTML = code_html;
78 alert_box("success_box" + e.message);
82 code_html.evalScripts();
85 alert_box(content[53] + "\n" + e.message);
90 *@brief delete a row from a table (tb) the input button send the this
93 function deleteRow(tb, obj)
95 smoke.confirm(content[50], function (e)
98 var td = obj.parentNode;
99 var tr = td.parentNode;
100 var lidx = tr.rowIndex;
101 g(tb).deleteRow(lidx);
108 function deleteRowRec(tb, obj)
111 var lidx = tr.rowIndex;
112 g(tb).deleteRow(lidx);
114 /*!\brief remove trailing and heading space
115 * \param the string to modify
116 * \return string without heading and trailing space
120 return s.replace(/^\s+/, '').replace(/\s+$/, '');
124 * @brief retrieve an element thanks its ID
125 * @param ID is a string
126 * @return the found object of undefined if not found
130 if (document.getElementById)
132 return this.document.getElementById(ID);
133 } else if (document.all)
135 return document.all[ID];
142 *@brief enable the type of periode
144 function enable_type_periode()
146 if ($("type_periode").options[$("type_periode").selectedIndex].value == 0)
148 $('from_periode').enable();
149 $('to_periode').enable();
150 $('from_date').disable();
151 $('to_date').disable();
152 $('p_step').enable();
155 $('from_periode').disable();
156 $('to_periode').disable();
157 $('from_date').enable();
158 $('to_date').enable();
159 $('p_step').disable();
164 *@brief will reload the window but it is dangerous if we have submitted
167 function refresh_window()
169 window.location.reload();
174 *@brief we receive a json object as parameter and the function returns the string
175 * with the format variable=value&var2=val2...
177 function encodeJSON(obj)
179 if (typeof obj != 'object')
181 alert_box('encodeParameter obj n\'est pas un objet');
197 str += '=' + encodeURI(obj[i]);
202 alert_box('encodeParameter ' + e.message);
206 function hide(p_param)
208 g(p_param).style.display = 'none';
210 function show(p_param)
212 g(p_param).style.display = 'block';
216 *@brief set the focus on the selected field
217 *@param Field id of the control
218 *@param selectIt : the value selected in case of Field is a object select, numeric
220 function SetFocus(Field, SelectIt)
230 * @brief set a DOM id with a value in the parent window (the caller),
231 @param p_ctl is the name of the control
232 @param p_value is the value to set in
233 @param p_add if we don't replace the current value but we add something
235 function set_inparent(p_ctl, p_value, p_add)
237 self.opener.set_value(p_ctl, p_value, p_add);
241 * @brief set a DOM id with a value, it will consider if it the attribute
242 value or innerHTML has be used
243 @param p_ctl is the name of the control
244 @param p_value is the value to set in
245 @param p_add if we don't replace the current value but we add something
247 function set_value(p_ctl, p_value, p_add)
251 var g_ctrl = g(p_ctl);
252 if (p_add != undefined && p_add === 1)
256 p_value = g_ctrl.value + ',' + p_value;
259 if (g_ctrl.tagName === 'INPUT')
261 g(p_ctl).value = p_value;
263 if (g_ctrl.tagName === 'SPAN')
265 g(p_ctl).innerHTML = p_value;
267 if (g_ctrl.tagName === 'SELECT')
269 g(p_ctl).value = p_value;
274 * @brief compute small math in numeric cells
275 * @param string value
278 function compute_number(value)
282 var exp = new RegExp("^[0-9/*+-.()]+$", "g");
283 /*pour éviter un eval() mal intentionné*/
284 var res = exp.test(value);
287 /*pour gérer un nombre non valide comme 5..36 ou 5.3.6
288 parce qu'il est possible d'entrer plusieurs
289 points dans le nombre et eval() lève une exception*/
292 console.debug("value = "+value);
293 retval = eval(value);
296 return parseFloat(value);
298 /*pour gérer les divisions par 0*/
299 if (retval == Infinity)
311 *@brief format the number change comma to point
314 function format_number(obj, p_prec)
317 if (p_prec === undefined)
323 var value = obj.value;
324 value = value.replace(/,/g, '.');
326 value=compute_number(value);
328 value = parseFloat(value);
333 var arrondi = Math.pow(10, precision);
335 value = Math.round(value * arrondi) / arrondi;
337 $(obj).value = value;
341 * Replace slash and minus by dot
344 function format_date(p_object)
346 p_object.value=p_object.value.replace(/\//g,'.');
347 p_object.value=p_object.value.replace(/-/g,'.');
350 *@brief check if the object is hidden or show and perform the opposite,
351 * show the hidden obj or hide the shown one
352 *@param name of the object
354 function toggleHideShow(p_obj, p_button)
356 var stat = g(p_obj).style.display;
357 var str = g(p_button).value;
361 str = str.replace(/Afficher/, content[62]);
362 g(p_button).value = str;
366 str = str.replace(/Cacher/, content[63]);
367 g(p_button).value = str;
371 *@brief open popup with the search windows
372 *@param p_dossier the dossier where to search
373 *@param p_style style of the detail value are E for expert or S for simple
375 function popup_recherche(p_dossier)
377 var w = window.open("recherche.php?gDossier=" + p_dossier + "&ac=SEARCH", '', 'statusbar=no,scrollbars=yes,toolbar=no');
381 *@brief replace the special characters (><'") by their HTML representation
382 *@return a string without the offending char.
384 function unescape_xml(code_html)
386 code_html = code_html.replace(/\</, '<');
387 code_html = code_html.replace(/\>/, '>');
388 code_html = code_html.replace(/\"/, '"');
389 code_html = code_html.replace(/\'/, "'");
390 code_html = code_html.replace(/\&/, '&');
394 *@brief Firefox splits the XML into 4K chunk, so to retrieve everything we need
395 * to get the different parts thanks textContent
396 *@param xmlNode a node (result of var data = =answer.getElementsByTagName('code'))
397 *@return all the content of the XML node
399 function getNodeText(xmlNode)
403 if (typeof (xmlNode.textContent) != "undefined")
405 return xmlNode.textContent;
407 if (xmlNode.firstChild && xmlNode.firstChild.nodeValue)
408 return xmlNode.firstChild.nodeValue;
412 *@brief change the periode in the calendar of the dashboard
413 *@param object select
415 function change_month(obj)
417 var action = new Ajax.Request(
421 parameters: {gDossier: obj.gDossier, op: 'cal', "per": obj.value, t: obj.type_display, notitle: obj.notitle},
422 onFailure: ajax_misc_failure,
423 onSuccess: success_misc
429 *@brief basic answer to ajax on success, it will fill the DOMID code with
430 * the code. In that case, you need to create the object before the Ajax.Request
431 *The difference with success box is that
432 *@see add_div removeDiv success_box is that the width and height are not changed ajax_misc.php
433 *@param code is the ID of the object containing the html (div, button...)
434 *@param value is the html code, with it you fill the ctl element
437 function success_misc(req)
441 var answer = req.responseXML;
442 var html = answer.getElementsByTagName('code');
443 if (html.length === 0)
445 var rec = req.responseText;
446 alert_box('erreur :' + rec);
448 var nodeXml = html[0];
449 var code_html = getNodeText(nodeXml);
450 code_html = unescape_xml(code_html);
451 $("user_cal").innerHTML = code_html;
454 alert_box(e.message);
458 code_html.evalScripts();
461 alert_box(content[53] + "\n" + e.message);
468 var str = '<p>' + content[64] + '</p>';
469 str = str + '<image src="image/loading.gif" alt="chargement"></image>';
473 function ajax_misc_failure()
475 alert_box(content[53]);
478 *@brief remove a document_modele
480 function cat_doc_remove(p_dt_id, p_dossier)
482 var queryString = "gDossier=" + p_dossier + "&op=rem_cat_doc" + "&dt_id=" + p_dt_id;
483 var action = new Ajax.Request(
484 "ajax_misc.php", {method: 'get',
485 parameters: queryString,
486 onFailure: ajax_misc_failure,
487 onSuccess: function (req)
491 var answer = req.responseXML;
492 var html = answer.getElementsByTagName('dtid');
493 if (html.length === 0)
495 var rec = req.responseText;
496 alert_box('erreur <br>' + rec);
499 var nodeXML = html[0];
500 var row_id = getNodeText(nodeXML);
501 if (row_id === 'nok')
503 var message_node = answer.getElementsByTagName('message');
504 var message_text = getNodeText(message_node[0]);
505 alert_box('erreur <br>' + message_text);
508 $('row' + row_id).style.textDecoration = "line-through";
509 $('X' + row_id).style.display = 'none';
510 $('M' + row_id).style.display = 'none';
513 alert_box(e.message);
520 *@brief change a document_modele
522 function cat_doc_change(p_dt_id, p_dossier)
524 var queryString = "gDossier=" + p_dossier + "&op=mod_cat_doc" + "&dt_id=" + p_dt_id;
525 var nTop = calcy(posY);
527 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:50em;height:auto";
529 removeDiv('change_doc_div');
531 var action = new Ajax.Request(
534 method: 'get', parameters: queryString,
535 onFailure: ajax_misc_failure,
536 onSuccess: function (req) {
537 remove_waiting_box();
538 add_div({id: 'change_doc_div', style: str_style, cssclass: 'inner_box', drag: "1"});
539 $('change_doc_div').innerHTML = req.responseText;
547 *@brief display the popup with vat and explanation
548 *@param obj with 4 attributes gdossier, ctl,popup
550 function popup_select_tva(obj)
554 if ($('tva_select')) {
555 removeDiv('tva_select');
558 var queryString = "gDossier=" + obj.gDossier + "&op=dsp_tva" + "&ctl=" + obj.ctl + '&popup=' + 'tva_select';
560 queryString += '&code=' + obj.jcode;
562 queryString += '&compute=' + obj.compute;
564 queryString += '&filter=' + obj.filter;
566 var action = new Ajax.Request(
569 parameters: queryString,
570 onFailure: ajax_misc_failure,
571 onSuccess: function (req)
575 var answer = req.responseXML;
576 var popup = answer.getElementsByTagName('popup');
577 if (popup.length === 0)
579 var rec = req.responseText;
580 alert_box('erreur :' + rec);
582 var html = answer.getElementsByTagName('code');
584 var name_ctl = popup[0].firstChild.nodeValue;
585 var nodeXml = html[0];
586 var code_html = getNodeText(nodeXml);
587 code_html = unescape_xml(code_html);
589 var nTop = posY - 200;
591 var str_style = "top:" + nTop + "px;left:" + nLeft + ";right:" + nLeft + ";width:55em;height:auto";
593 var popup = {'id': 'tva_select', 'cssclass': 'inner_box', 'style': str_style, 'html': code_html, 'drag': false};
595 $('lk_tva_select_table').focus();
598 alert_box("success_popup_select_tva " + e.message);
605 alert_box("popup_select_tva " + e.message);
611 *@brief display the popup with vat and explanation
612 *@param obj with 4 attributes gdossier, ctl,popup
614 function set_tva_label(obj)
618 var queryString = "gDossier=" + obj.gDossier + "&op=label_tva" + "&id=" + obj.value;
620 queryString += '&code=' + obj.jcode;
621 var action = new Ajax.Request(
624 parameters: queryString,
625 onFailure: ajax_misc_failure,
626 onSuccess: success_set_tva_label
631 alert_box("set_tva_label " + e.message);
635 *@brief display the popup with vat and explanations
636 *@param string req answer from ajax
638 function success_set_tva_label(req)
642 var answer = req.responseXML;
643 var code = answer.getElementsByTagName('code');
644 var value = answer.getElementsByTagName('value');
646 if (code.length === 0)
648 var rec = req.responseText;
649 alert_box('erreur :' + rec);
652 var label_code = code[0].firstChild.nodeValue;
653 var label_value = value[0].firstChild.nodeValue;
654 set_value(label_code, label_value);
657 alert_box("success_set_tva_label " + e.message);
663 * Create a div without showing it
666 * - style to add style
668 * - cssclass to add a class
669 * - html is the content
670 * - drag is the div can be moved
671 * @returns html dom element
674 function create_div(obj)
681 elt = top.createElement('div');
687 elt.setAttribute('id', obj.id);
691 if (elt.style.setAttribute)
693 elt.style.setAttribute('cssText', obj.style);
696 elt.setAttribute('style', obj.style);
701 elt.setAttribute('class', obj.cssclass); /* FF */
702 elt.setAttribute('className', obj.cssclass); /* IE */
706 elt.innerHTML = obj.html;
709 var bottom_div = document.body;
711 bottom_div.appendChild(elt);
713 /* if ( obj.effect && obj.effect != 'none' ) { Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }
714 else if ( ! obj.effect ){ Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }*/
717 aDraggableElement[obj.id] = new Draggable(obj.id, {starteffect: function ()
719 new Effect.Highlight(obj.id, {scroll: window, queue: 'end'});
728 error_message("create_div " + e.message);
732 *@brief add dynamically a object for AJAX
735 * - style to add style
737 * - cssclass to add a class
738 * - html is the content
739 * - drag is the div can be moved
741 function add_div(obj)
744 var elt = create_div(obj);
745 /* elt.setStyle({visibility:'visible'}); */
746 elt.style.visibility = 'visible';
751 alert_box("add_div " + e.message);
755 * remove a object created with add_div
756 * @param elt id of the elt
758 function removeDiv(elt)
762 document.body.removeChild(g(elt));
764 // if reloaded if asked the window will be reloaded when
766 if (ask_reload === 1)
768 // avoid POST window.location = window.location.href;
769 window.location.reload();
772 function waiting_node()
774 $('info_div').innerHTML = 'Un instant';
775 $('info_div').style.display = "block";
778 *show a box while loading
779 *must be remove when ajax is successfull
782 function waiting_box()
785 id: 'wait_box', html: '<h2 class="title">' + content[65] + '</h2>' + loading()
787 var y = fixed_position(10, 250)
788 obj.style = y + ";width:20%;margin-left:40%;";
790 removeDiv('wait_box');
798 *@brief call add_div to add a DIV and after call the ajax
799 * the queryString, the callback for function for success and error management
800 * the method is always GET
801 *@param obj, the mandatory attributes are
802 * - obj.qs querystring
803 * - obj.js_success callback function in javascript for handling the xml answer
804 * - obj.js_error callback function for error
805 * - obj.callback the php file to call
806 * - obj.fixed optional let you determine the position, otherwise works like IPopup
809 function show_box(obj)
814 g(obj.id).style.top = calcy(40) + "px";
821 var action = new Ajax.Request(
826 onFailure: eval(obj.js_error),
827 onSuccess: eval(obj.js_success)
831 *@brief receive answer from ajax and just display it into the IBox
832 * XML must contains at least 2 fields : ctl is the ID of the IBOX and
833 * code is the HTML to put in it
836 function success_box(req, json)
840 var answer = req.responseXML;
841 var a = answer.getElementsByTagName('ctl');
842 var html = answer.getElementsByTagName('code');
845 var rec = req.responseText;
846 alert_box(content[48] + rec);
848 var name_ctl = a[0].firstChild.nodeValue;
849 var code_html = getNodeText(html[0]);
851 code_html = unescape_xml(code_html);
852 g(name_ctl).innerHTML = code_html;
853 g(name_ctl).style.height = 'auto';
855 if (name_ctl == 'popup')
856 g(name_ctl).style.width = 'auto';
859 alert_box("success_box" + e.message);
863 code_html.evalScripts();
866 alert_box(content[53] + "\n" + e.message);
872 alert_box(content[53]);
875 * show the ledger choice
877 function show_ledger_choice(json_obj)
883 var query = "gDossier=" + json_obj.dossier + '&type=' + json_obj.type + '&div=' + json_obj.div + '&op=ledger_show';
884 query = query + '&nbjrn=' + $(json_obj.div + 'nb_jrn').value;
885 query = query + '&all_type=' + json_obj.all_type;
886 for (i = 0; i < $(json_obj.div + 'nb_jrn').value; i++) {
887 query = query + "&r_jrn[]=" + $(json_obj.div + 'r_jrn[' + i + ']').value;
889 query = encodeURI(query);
890 var action = new Ajax.Request(
894 onFailure: ajax_misc_failure,
895 onSuccess: function (req, json) {
898 id: json_obj.div + 'jrn_search',
899 cssclass: 'inner_box',
900 style: ';position:absolute;width:auto;z-index:20;margin-left:20%',
906 obj.style = "top:" + y + 'px;' + obj.style;
907 /* if ( json_obj.class )
909 obj.cssclass=json_obj.class;
914 var answer = req.responseXML;
915 var a = answer.getElementsByTagName('ctl');
916 var html = answer.getElementsByTagName('code');
917 if (a.length === 0) {
918 var rec = req.responseText;
919 alert_box('erreur :' + rec);
921 var name_ctl = a[0].firstChild.nodeValue;
922 var code_html = getNodeText(html[0]);
924 code_html = unescape_xml(code_html);
925 remove_waiting_box();
926 g(obj.id).innerHTML = code_html;
929 alert_box("show_ledger_callback" + e.message);
932 code_html.evalScripts();
934 alert_box(content[53] + "\n" + e.message);
942 alert_box('show_ledger_choice' + e.message);
946 * hide the ledger choice
948 function hide_ledger_choice(p_frm_search)
952 var nb = $(p_frm_search).nb_jrn.value;
954 if ($(p_frm_search).div) {
955 div = $(p_frm_search).div.value;
962 for (i = 0; i < nb; i++) {
963 n_name = div + "r_jrn[" + sel + "]";
964 name = div + "r_jrn" + i;
965 if ($(name).checked) {
966 str += '<input type="hidden" id="' + n_name + '" name="' + n_name + '" value="' + $(name).value + '">';
970 str += '<input type="hidden" name="' + div + 'nb_jrn" id="' + div + 'nb_jrn" value="' + sel + '">';
971 $('ledger_id' + div).innerHTML = str;
972 removeDiv(div + 'jrn_search');
975 alert_box('hide_ledger_choice' + e.message);
981 * show the cat of ledger choice
983 function show_cat_choice()
985 g('div_cat').style.visibility = 'visible';
988 * hide the cat of ledger choice
990 function hide_cat_choice()
992 g('div_cat').style.visibility = 'hidden';
995 * add a row for the forecast item
997 function for_add_row(tableid)
999 style = 'class="input_text"';
1000 var mytable = g(tableid).tBodies[0];
1001 var nNumberRow = mytable.rows.length;
1002 var oRow = mytable.insertRow(nNumberRow);
1003 var rowToCopy = mytable.rows[1];
1004 var nNumberCell = rowToCopy.cells.length;
1005 var nb = g("nbrow");
1006 var oNewRow = mytable.insertRow(nNumberRow);
1007 for (var e = 0; e < nNumberCell; e++)
1009 var newCell = oRow.insertCell(e);
1010 var tt = rowToCopy.cells[e].innerHTML;
1011 new_tt = tt.replace(/an_cat0/g, "an_cat" + nb.value);
1012 new_tt = new_tt.replace(/an_cat_acc0/g, "an_cat_acc" + nb.value);
1013 new_tt = new_tt.replace(/an_qc0/g, "an_qc" + nb.value);
1014 new_tt = new_tt.replace(/an_label0/g, "an_label" + nb.value);
1015 new_tt = new_tt.replace(/month0/g, "month" + nb.value);
1016 new_tt = new_tt.replace(/an_cat_amount0/g, "an_cat_amount" + nb.value);
1017 new_tt = new_tt.replace(/an_deb0/g, "an_deb" + nb.value);
1018 newCell.innerHTML = new_tt;
1019 new_tt.evalScripts();
1021 $("an_cat_acc" + nb.value).value = "";
1022 $("an_qc" + nb.value).value = "";
1023 $("an_label" + nb.value).value = "";
1024 $("an_cat_amount" + nb.value).value = "0";
1028 * toggle all the checkbox in a given form
1029 * @param form_id id of the form
1031 function toggle_checkbox(form_id)
1033 var form = g(form_id);
1034 for (var i = 0; i < form.length; i++)
1036 var e = form.elements[i];
1037 if (e.type === 'checkbox')
1039 if (e.checked === true)
1050 * select all the checkbox in a given form
1051 * @param form_id id of the form
1053 function select_checkbox(form_id)
1055 var form = $(form_id);
1056 for (var i = 0; i < form.length; i++)
1058 var e = form.elements[i];
1059 if (e.type === 'checkbox')
1066 * select all the checkbox in a given form if the specific attribute
1067 * has the given value
1068 * @param form_id id of the form
1069 * @param attribute name
1070 * @param attribute value
1072 function select_checkbox_attribute(form_id, p_attribute_name, p_attribute_value)
1074 var form = $(form_id);
1075 for (var i = 0; i < form.length; i++)
1077 var e = form.elements[i];
1078 if (e.type === 'checkbox' && e.getAttribute(p_attribute_name) == p_attribute_value)
1085 * unselect all the checkbox in a given form
1086 * @param form_id id of the form
1088 function unselect_checkbox(form_id)
1090 var form = $(form_id);
1091 for (var i = 0; i < form.length; i++)
1093 var e = form.elements[i];
1094 if (e.type === 'checkbox')
1101 * show the calculator
1103 function show_calc()
1107 this.document.getElementById('inp').value = "";
1108 this.document.getElementById('inp').focus();
1113 shtml += "<div class=\"bxbutton\">";
1114 shtml += '<a class="icon" onclick="pin(\'calc1\')" id="pin_calc1"></a> <a onclick="removeDiv(\'calc1\');" href="javascript:void(0)" title="" class="icon">⨉</a>';
1116 shtml += ' <h2 class="title">' + content[66] + '</h2>';
1117 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\')" >';
1118 shtml += '</form><span class="highligth" style="display:block" id="sub_total"> ' + content[67] + ' </span><span style="display:block" id="listing"> </span>';
1120 var obj = {id: sid, html: shtml,
1121 drag: false, style: 'z-index:98'
1124 this.document.getElementById('inp').focus();
1126 function display_periode(p_dossier, p_id)
1131 var queryString = "gDossier=" + p_dossier + "&op=input_per" + "&p_id=" + p_id;
1132 var popup = {'id': 'mod_periode', 'cssclass': 'inner_box', 'html': loading(), 'style': 'width:30em', 'drag': true};
1133 if (!$('mod_periode')) {
1136 var action = new Ajax.Request(
1139 parameters: queryString,
1140 onFailure: ajax_misc_failure,
1141 onSuccess: success_display_periode
1144 $('mod_periode').style.top = (posY - 70) + "px";
1145 $('mod_periode').style.left = (posX - 70) + "px";
1148 alert_box("display_periode " + e.message);
1152 function success_display_periode(req)
1157 var answer = req.responseXML;
1158 var html = answer.getElementsByTagName('data');
1160 if (html.length === 0)
1162 var rec = req.responseText;
1163 alert_box('erreur :' + rec);
1166 var code_html = getNodeText(html[0]);
1167 code_html = unescape_xml(code_html);
1169 $('mod_periode').innerHTML = code_html;
1172 alert_box("success_display_periode".e.message);
1176 code_html.evalScripts();
1179 alert_box(content[53] + "\n" + e.message);
1183 function save_periode(obj)
1187 var queryString = $(obj).serialize() + "&op=save_per";
1189 var action = new Ajax.Request(
1192 parameters: queryString,
1193 onFailure: ajax_misc_failure,
1194 onSuccess: success_display_periode
1200 alert_box("display_periode " + e.message);
1206 *@brief basic answer to ajax on success, it will fill the ctl with
1207 * the code. In that case, you need to create the object before the Ajax.Request
1208 *The difference with success box is that
1209 *@see add_div removeDiv success_box is that the width and height are not changed
1210 *@param ctl is the ID of the object containing the html (div, button...)
1211 *@param code is the html code, with it you fill the ctl element
1213 function fill_box(req)
1217 remove_waiting_box();
1219 var answer = req.responseXML;
1220 var a = answer.getElementsByTagName('ctl');
1221 var html = answer.getElementsByTagName('code');
1222 if (a.length === 0) {
1223 var rec = req.responseText;
1224 alert_box('erreur :' + rec);
1226 var name_ctl = a[0].firstChild.nodeValue;
1227 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
1228 code_html = unescape_xml(code_html);
1229 $(name_ctl).innerHTML = code_html;
1231 alert_box(e.message);
1234 console.error("log answer = " + req.responseText);
1238 code_html.evalScripts();
1242 console.error("log answer = " + req.responseText);
1244 alert_box(content[53] + "\n" + e.message);
1250 *display a popin to let you modified a predefined operation
1252 *@param od_id from table op_predef
1254 function mod_predf_op(dossier_id, od_id,p_ledger)
1256 var target = "mod_predf_op";
1258 var str_style = "top:10%;left:2%;width:96%";
1260 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1264 var qs = "gDossier=" + dossier_id + '&op=mod_predf&id=' + od_id+'&ledger_id='+p_ledger;
1266 var action = new Ajax.Request('ajax_misc.php',
1277 function save_predf_op(obj)
1280 var querystring = $(obj).serialize() + '&op=save_predf';
1281 // Create a ajax request to get all the person
1282 var action = new Ajax.Request('ajax_misc.php',
1285 parameters: querystring,
1287 onSuccess: refresh_window
1295 *ctl_concern is the widget to update
1296 *amount_id is either a html obj. or an amount and the field tiers if given
1297 * @param {type} dossier
1298 * @param {type} ctl_concern
1299 * @param {float or string} amount_id Amount or DOM Id of the element containing the amount
1300 * @param {float} ledger
1301 * @param {type} p_id_targetDom Element (div) where to display the search result
1302 * @param p_tiers id of the Tiers
1303 * @returns {undefined}
1305 function search_reconcile(dossier, ctl_concern, amount_id, ledger, p_id_target, p_tiers)
1307 if (amount_id === undefined)
1310 } else if ($(amount_id))
1312 if ($(amount_id).value)
1314 amount_id = $(amount_id).value;
1316 ($(amount_id).innerHTML) {
1317 amount_id = $(amount_id).innerHTML;
1324 if (p_id_target != "") {
1325 target = p_id_target;
1327 target = "search" + layer;
1330 var str_style = fixed_position(77, 99);
1331 str_style += ";width:92%;overflow:auto;";
1333 var hide_operation = $(ctl_concern).getAttribute("hide_operation");
1334 var single_operation = $(ctl_concern).getAttribute("single_operation");
1336 var param_send = {gDossier: dossier,
1340 amount_id: amount_id,
1344 hide_operation: hide_operation,
1345 single_operation:single_operation
1348 var qs = encodeJSON(param_send);
1350 var action = new Ajax.Request('ajax_misc.php',
1355 onSuccess: function (req) {
1356 remove_waiting_box();
1357 var div = {id: target, cssclass: 'inner_box', style: str_style, drag: 0};
1359 $(target).innerHTML = req.responseText;
1360 req.responseText.evalScripts();
1366 * search in a popin obj if the object form
1368 function search_operation(obj)
1371 var dossier = g('gDossier').value;
1373 var target = "search" + layer;
1374 if ($(obj)["target"]) {
1375 target = $(obj)["target"].value;
1377 var qs = Form.serialize('search_form_ajx') + "&op=search_op";
1378 var action = new Ajax.Request('ajax_misc.php',
1383 onSuccess: function (req) {
1384 remove_waiting_box();
1385 $(target).innerHTML = req.responseText;
1386 req.responseText.evalScripts();
1392 remove_waiting_box();
1393 alert_box(e.message);
1397 * Update the field e_concerned, from class_iconcerned
1398 * Value is the field where to put the quick-code but only if one checkbox has been
1401 * @returns {undefined}
1403 function set_reconcile(obj)
1408 var ctlc = obj.elements['ctlc'];
1409 var tiers = obj.elements['tiers'];
1410 if (!obj.elements['target'])
1412 var target = obj.elements['target'].value;
1413 var single_operation = obj.elements['single_operation'].value;
1414 for (var e = 0; e < obj.elements.length; e++)
1417 var elmt = obj.elements[e];
1418 if (elmt.type === "checkbox")
1420 if (elmt.checked === true)
1422 var str_name = elmt.name;
1423 var nValue = str_name.replace("jr_concerned", "");
1424 if ($(ctlc.value).value != '') {
1425 $(ctlc.value).value += ',';
1429 if (tiers && tiers.value != "") {
1430 $(tiers.value).value = elmt.value;
1432 new Ajax.Request("fid.php",{
1434 parameters:{gDossier:obj.elements['gDossier'].value,"FID":elmt.value},
1435 onSuccess:function(req){
1436 // find the row number
1437 //tiers.value = e_othern
1438 var tiers_card=new String(tiers.value);
1439 var num=tiers_card.replace("e_other","");
1440 var tiers_name_id="e_other"+"_name"+num;
1441 var answer = req.responseText.evalJSON();
1442 $(tiers_name_id).value=answer["name"];
1447 if (single_operation==0) {
1448 $(ctlc.value).value += nValue;
1450 $(ctlc.value).value = nValue;
1456 removeDiv(obj.elements['target'].value);
1459 alert_box(e.message)
1462 function remove_waiting_node()
1464 $('info_div').innerHTML = "";
1465 $('info_div').style.display = "none";
1468 function remove_waiting_box()
1470 if ($('wait_box')) {
1471 Effect.Fade('wait_box', {duration: 0.6});
1474 remove_waiting_node();
1477 * Show all the detail of a profile : Menu, Management, Repository and
1478 * let the user to modify it
1479 * @param {type} gDossier
1480 * @param {type} profile_id
1481 * @returns {undefined}
1483 function get_profile_detail(gDossier, profile_id)
1486 var qs = "op=display_profile&gDossier=" + gDossier + "&p_id=" + profile_id + "&ctl=detail_profile";
1487 var action = new Ajax.Request('ajax_misc.php',
1492 onSuccess: function (req) {
1493 remove_waiting_box();
1494 $('list_profile').hide();
1495 $('detail_profile').innerHTML = req.responseText;
1496 req.responseText.evalScripts();
1497 $('detail_profile').show();
1498 if (profile_id != "-1")
1499 profile_show('profile_gen_div');
1504 function get_profile_detail_success_obsolete(xml)
1506 remove_waiting_box();
1510 * @brief compute the string to position a div in a fixed way
1513 function fixed_position(p_sx, p_sy)
1516 var sy = calcy(p_sy);
1518 var str_style = "top:" + sy + "px;left:" + sx + "px;position:absolute";
1523 *@brief compute Y even if the windows has scrolled down or up
1524 *@return the correct Y position
1526 function calcy(p_sy)
1529 if (window.pageYOffset)
1531 sy = window.pageYOffset + p_sy;
1534 sy = document.documentElement.scrollTop + p_sy;
1541 * @brief display a box with the menu option
1542 * @param {type} gdossier
1543 * @param {type} pm_id
1544 * @returns {undefined}
1546 function mod_menu(gdossier, pm_id)
1549 removeDiv('divdm' + pm_id);
1550 var qs = "op=det_menu&gDossier=" + gdossier + "&pm_id=" + pm_id + "&ctl=divdm" + pm_id;
1551 var pos = fixed_position(50, 250);
1552 var action = new Ajax.Request('ajax_misc.php',
1557 onSuccess: function (req) {
1559 remove_waiting_box();
1560 add_div({id: "divdm" + pm_id, drag: 1, cssclass: "inner_box", style: pos});
1561 $('divdm' + pm_id).innerHTML = req.responseText;
1563 alert_box(e.message);
1570 * Display the submenu of a menu or a module, used in setting the menu
1572 * @param {type} p_dossier
1573 * @param {type} p_profile
1574 * @param {type} p_dep
1575 * @returns {undefined}
1577 function display_sub_menu(p_dossier, p_profile, p_dep, p_level)
1580 new Ajax.Request('ajax_misc.php',
1583 parameters: {op: 'display_submenu',
1584 gDossier: p_dossier,
1586 p_profile: p_profile,
1589 onSuccess: function (req) {
1591 remove_waiting_box();
1592 if ($('menu_table').rows.length > p_level) {
1593 $('menu_table').rows[1].remove();
1595 $('sub' + p_dep).addClassName("selectedmenu");
1596 var new_row = document.createElement('TR');
1597 new_row.innerHTML = req.responseText;
1598 $('menu_table').appendChild(new_row);
1600 alert_box(e.message);
1606 * in CFGPRO, ask to confirm before removing a submenu and its children
1607 * @param {type} p_dossier
1608 * @param {type} profile_menu_id
1609 * @returns {undefined}
1611 function remove_sub_menu(p_dossier, profile_menu_id)
1613 confirm_box(null, content[47],
1616 new Ajax.Request('ajax_misc.php',
1619 parameters: {op: 'remove_submenu', gDossier: p_dossier,
1620 p_profile_menu_id: profile_menu_id},
1621 onSuccess: function (req) {
1623 remove_waiting_box();
1624 $('sub' + profile_menu_id).remove();
1625 if ($('menu_table').rows.length > 1) {
1626 $('menu_table').rows[1].remove();
1631 alert_box(e.message);
1640 * @brief add a menu to a profile, propose only the available menu
1641 * @param obj json object
1643 * - p_id : profile id ,
1644 * - type : Type of menu are "pr" for Printing "me" for plain menu
1645 * - p_level : level of menu (0 -> module,1-> top menu, 2->submenu)
1646 * - dep : the parent menu id (pm_id)
1649 function add_menu(obj)
1651 var pdossier = obj.dossier;
1652 var p_id = obj.p_id;
1653 var p_type = obj.type;
1656 removeDiv('divdm' + p_id);
1657 var pos = fixed_position(250, 150) + ";width:50%;";
1658 var action = new Ajax.Request('ajax_misc.php',
1661 parameters: {op: 'add_menu',
1662 'gDossier': pdossier,
1664 'ctl': 'divdm' + p_id,
1667 'p_level': obj.p_level},
1669 onSuccess: function (req) {
1671 remove_waiting_box();
1672 add_div({id: "divdm" + p_id, drag: 1, "cssclass": "inner_box", "style": pos});
1673 $('divdm' + p_id).innerHTML = req.responseText;
1675 alert_box(e.message);
1682 * @brief Display a box to enter data for adding a new plugin from
1684 * @param {type} p_dossier
1685 * @returns {undefined}
1687 function add_plugin(p_dossier)
1690 removeDiv('divplugin');
1691 var qs = "op=add_plugin&gDossier=" + p_dossier + "&ctl=divplugin";
1693 var action = new Ajax.Request('ajax_misc.php',
1698 onSuccess: function (req) {
1700 remove_waiting_box();
1701 var pos = fixed_position(250, 150) + ";width:30%";
1702 add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1703 $('divplugin').innerHTML = req.responseText;
1705 alert_box(e.message);
1713 * @param {type} p_dossier
1714 * @param {type} me_code
1715 * @returns {undefined}
1717 function mod_plugin(p_dossier, me_code)
1720 removeDiv('divplugin');
1721 var qs = "op=mod_plugin&gDossier=" + p_dossier + "&ctl=divplugin&me_code=" + me_code;
1723 var action = new Ajax.Request('ajax_misc.php',
1728 onSuccess: function (req) {
1730 remove_waiting_box();
1731 var pos = fixed_position(250, 150) + ";width:30%";
1732 add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1733 $('divplugin').innerHTML = req.responseText;
1736 alert_box(e.message);
1742 function create_menu(p_dossier)
1745 removeDiv('divmenu');
1746 var qs = "op=create_menu&gDossier=" + p_dossier + "&ctl=divmenu";
1748 var action = new Ajax.Request('ajax_misc.php',
1753 onSuccess: function (req) {
1755 remove_waiting_box();
1756 var pos = fixed_position(250, 150) + ";width:30%";
1760 cssclass: "inner_box",
1763 $('divmenu').innerHTML = req.responseText;
1765 alert_box(e.message);
1771 function modify_menu(p_dossier, me_code)
1774 removeDiv('divmenu');
1775 var qs = "op=modify_menu&gDossier=" + p_dossier + "&ctl=divmenu&me_code=" + me_code;
1777 var action = new Ajax.Request('ajax_misc.php',
1782 onSuccess: function (req) {
1784 remove_waiting_box();
1785 var pos = fixed_position(250, 150) + ";width:30%";
1789 cssclass: "inner_box",
1792 $('divmenu').innerHTML = req.responseText;
1795 alert_box(e.message);
1801 function get_properties(obj)
1804 var s_type = "[" + typeof obj + "]";
1809 alert_box(s_type + a_array.join(","));
1812 * @brief add a line in the form for the report
1813 * @param p_dossier dossier id to connect
1815 function rapport_add_row(p_dossier)
1817 style = 'style="border: 1px solid blue;"';
1818 var table = $("rap1");
1819 var line = table.rows.length;
1821 var row = table.insertRow(line);
1823 var cellPos = row.insertCell(0);
1824 cellPos.innerHTML = '<input type="text" ' + style + ' size="3" id="pos' + line + '" name="pos' + line + '" value="' + line + '">';
1827 var cellName = row.insertCell(1);
1828 cellName.innerHTML = '<input type="text" ' + style + ' size="40" id="text' + line + '" name="text' + line + '">';
1831 var cellbutton = row.insertCell(2);
1832 var but_html = table.rows[1].cells[2].innerHTML;
1833 but_html = but_html.replace(/form0/g, "form" + line);
1834 cellbutton.innerHTML = but_html;
1835 but_html.evalScripts();
1837 g('form' + line).value = '';
1840 * Search an action in an inner box
1842 function search_action(dossier, ctl_concern)
1847 var dossier = g('gDossier').value;
1849 var target = "search_action_div";
1851 var str_style = fixed_position(77, 99);
1853 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1856 var target = {gDossier: dossier,
1858 op: 'search_action',
1862 var qs = encodeJSON(target);
1864 var action = new Ajax.Request('ajax_misc.php',
1869 onSuccess: function (req) {
1871 remove_waiting_box();
1873 $('search_action_div').innerHTML = req.responseText;
1874 req.responseText.evalScripts();
1876 alert_box(e.message);
1882 alert_box(e.message);
1886 function result_search_action(obj)
1890 var queryString = $(obj).serialize() + "&op=search_action";
1891 var action = new Ajax.Request(
1894 parameters: queryString,
1895 onFailure: ajax_misc_failure,
1896 onSuccess: function (req) {
1898 remove_waiting_box();
1899 $('search_action_div').innerHTML = req.responseText;
1900 req.responseText.evalScripts();
1902 alert_box(e.message);
1910 alert_box("display_periode " + e.message);
1916 function set_action_related(p_obj)
1922 var ctlc = obj.elements['ctlc'];
1924 for (var e = 0; e < obj.elements.length; e++)
1927 var elmt = obj.elements[e];
1928 if (elmt.type === "checkbox")
1930 if (elmt.checked === true)
1932 var str_name = elmt.name;
1933 var nValue = elmt.value;
1934 if ($(ctlc.value).value != '') {
1935 $(ctlc.value).value += ',';
1937 $(ctlc.value).value += nValue;
1941 removeDiv('search_action_div');
1945 alert_box(e.message);
1950 *@brief Show a form to modify or add a new repository
1952 *@param r_id : repository id
1954 function stock_repo_change(p_dossier, r_id)
1956 var queryString = "gDossier=" + p_dossier + "&op=mod_stock_repo" + "&r_id=" + r_id;
1957 var nTop = calcy(posY);
1958 var nLeft = "10.1562%";
1959 var str_style = "top:" + nTop + "px;left:" + nLeft + ";height:auto;width:auto";
1961 removeDiv('change_stock_repo_div');
1963 var action = new Ajax.Request(
1966 method: 'get', parameters: queryString,
1967 onFailure: ajax_misc_failure,
1968 onSuccess: function (req) {
1969 remove_waiting_box();
1970 add_div({id: 'change_stock_repo_div', style: str_style, cssclass: 'inner_box', drag: "1"});
1971 $('change_stock_repo_div').innerHTML = req.responseText;
1977 function stock_inv_detail(p_dossier, p_id)
1979 var queryString = "gDossier=" + p_dossier + "&op=view_mod_stock" + "&c_id=" + p_id + "&ctl=view_mod_stock_div";
1980 var nTop = calcy(posY);
1982 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:80%;";
1984 removeDiv('view_mod_stock_div');
1986 var action = new Ajax.Request(
1989 method: 'get', parameters: queryString,
1990 onFailure: ajax_misc_failure,
1991 onSuccess: function (req) {
1992 remove_waiting_box();
1993 add_div({id: 'view_mod_stock_div', style: str_style, cssclass: 'inner_box', drag: "1"});
1994 $('view_mod_stock_div').innerHTML = req.responseText;
1995 req.responseText.evalScripts();
2000 function show_fin_chdate(obj_id)
2004 var ch = $(obj_id).options[$(obj_id).selectedIndex].value;
2006 $('chdate_ext').hide();
2010 $('chdate_ext').show();
2013 var nb = $('nb_item').value;
2014 for (i = 0; i < nb; i++) {
2015 if ($('tdchdate' + i)) {
2017 $('tdchdate' + i).show();
2020 $('tdchdate' + i).hide();
2026 alert_box(e.message);
2030 * tab menu for the profile parameter
2032 function profile_show(p_div)
2035 var div = ['profile_gen_div', 'profile_menu_div', 'profile_print_div', 'profile_gestion_div', 'profile_repo_div'];
2036 for (var r = 0; r < div.length; r++) {
2042 alert_box(e.message);
2045 function detail_category_show(p_div, p_dossier, p_id)
2049 $('detail_category_div').innerHTML = "";
2050 var queryString = "gDossier=" + p_dossier + "&id=" + p_id + "&op=fddetail";
2051 var action = new Ajax.Request(
2054 method: 'get', parameters: queryString,
2055 onFailure: ajax_misc_failure,
2056 onSuccess: function (req) {
2057 remove_waiting_box();
2058 $('list_cat_div').hide();
2059 $('detail_category_div').innerHTML = req.responseText;
2060 $('detail_category_div').show();
2061 req.responseText.evalScripts();
2067 * @brief check if the parameter is a valid a valid date or not, returns true if it is valid otherwise
2069 * @param p_str_date the string of the date (format DD.MM.YYYY)
2071 function check_date(p_str_date)
2073 var format = /^\d{2}\.\d{2}\.\d{4}$/;
2074 if (!format.test(p_str_date)) {
2077 var date_temp = p_str_date.split('.');
2078 var nMonth = parseFloat(date_temp[1]) - 1;
2079 var ma_date = new Date(date_temp[2], nMonth, date_temp[0]);
2080 if (ma_date.getFullYear() == date_temp[2] && ma_date.getMonth() == nMonth && ma_date.getDate() == date_temp[0]) {
2089 * @brief get the string in the id and check if the date is valid
2090 * @param p_id_date is the id of the element to check
2091 * @return true if the date is valid
2094 function check_date_id(p_id_date)
2096 var str_date = $(p_id_date).value;
2097 return check_date(str_date);
2101 * @param ag_id to view
2102 * @param dossier is the folder
2103 * @param modify : show the modify button values : 0 for no 1 for yes
2105 function view_action(ag_id, dossier, modify)
2109 id = 'action' + layer;
2111 querystring = 'gDossier=' + dossier + '&op=vw_action&ag_id=' + ag_id + '&div=' + id + '&mod=' + modify;
2112 var action = new Ajax.Request(
2116 parameters: querystring,
2117 onFailure: error_box,
2118 onSuccess: function (req) {
2120 remove_waiting_box();
2121 var answer = req.responseXML;
2122 var ctl = answer.getElementsByTagName('ctl');
2123 if (ctl.length == 0) {
2124 throw 'ajax failed ctl view_action';
2126 var ctl_txt = getNodeText(ctl[0]);
2127 var html = answer.getElementsByTagName('code');
2128 if (html.length === 0)
2130 var rec = req.responseText;
2131 throw 'ajax failed html view_action';
2133 var code_html = getNodeText(html[0]);
2134 code_html = unescape_xml(code_html);
2135 var pos = fixed_position(0, 50) + ";width:90%;left:5%;";
2138 cssclass: "inner_box",
2141 $(id).innerHTML = code_html;
2142 if (ctl_txt == 'ok') {
2144 var detail=in_child(id,"follow_up_detail");
2146 compute_all_ledger();
2151 code_html.evalScripts();
2153 alert_box('view_action' + e.message);
2160 * @brief filter quickly a table
2161 * @param phrase : phrase to seach
2162 * @param _id : id of the table
2163 * @param colnr : string containing the column number where you're searching separated by a comma
2164 * @param start_row : first row (1 if you have table header)
2166 * @see HtmlInput::filter_table
2168 function filter_table(phrase, _id, colnr, start_row) {
2169 $('info_div').innerHTML = content[65];
2170 $('info_div').style.display = "block";
2171 var words = $(phrase).value.toLowerCase();
2172 var table = document.getElementById(_id);
2174 // if colnr contains a comma then check several columns
2175 var aCol = new Array();
2176 if (colnr.indexOf(',') >= 0) {
2177 aCol = colnr.split(',');
2184 for (var r = start_row; r < table.rows.length; r++) {
2186 for (var col = 0; col < aCol.length; col++)
2188 var idx = aCol[col];
2189 if (table.rows[r].cells[idx])
2191 ele = table.rows[r].cells[idx].innerHTML.replace(/<[^>]+>/g, "");
2192 //var displayStyle = 'none';
2193 if (ele.toLowerCase().indexOf(words) >= 0) {
2201 table.rows[r].style.display = '';
2203 table.rows[r].style.display = 'none';
2205 $('info_div').style.display = "none";
2206 $('info_div').innerHTML = "";
2208 if (tot_found == 0) {
2209 if ($('info_' + _id)) {
2210 $('info_' + _id).innerHTML = content[69];
2213 if ($('info_' + _id)) {
2214 $('info_' + _id).innerHTML = " ";
2219 * @brief filter quickly a list
2220 * @param phrase : DOM id of the input text where we find the word to seach
2221 * @param _id : id of the list
2223 * @see HtmlInput::filter_list
2225 function filter_list(phrase, _id) {
2226 $('info_div').innerHTML = content[65];
2227 $('info_div').style.display = "block";
2228 var words = $(phrase).value.toLowerCase();
2229 var l_list = document.getElementById(_id);
2234 for (var r = 0; r < l_list.childNodes.length; r++) {
2236 if (l_list.childNodes[r].nodeType != 1 ){
2239 if (l_list.childNodes[r].childElementCount == 0)
2241 ele = l_list.childNodes[r].innerHTML;
2243 ele = l_list.childNodes[r].childNodes[0].innerHTML;
2245 if (ele.toLowerCase().indexOf(words) >= 0) {
2247 l_list.childNodes[r].style.display = 'block';
2249 l_list.childNodes[r].style.display = 'none';
2251 $('info_div').style.display = "none";
2252 $('info_div').innerHTML = "";
2254 if (tot_found == 0) {
2255 if ($('info_' + _id)) {
2256 $('info_' + _id).innerHTML = content[69];
2259 if ($('info_' + _id)) {
2260 $('info_' + _id).innerHTML = " ";
2266 * @brief filter quickly a select
2267 * @param phrase : DOM id of the input text where we find the word to seach
2268 * @param _id : id of the list
2270 * @see HtmlInput::filter_list
2272 function filter_multiselect(phrase, _id) {
2273 $('info_div').innerHTML = content[65];
2274 $('info_div').style.display = "block";
2275 var words = $(phrase).value.toLowerCase();
2276 var l_list = document.getElementById(_id);
2280 for (var r = 0; r < l_list.options.length; r++) {
2282 var ele = l_list.options[r].text;
2284 if (ele.toLowerCase().indexOf(words) >= 0) {
2286 l_list.options[r].style.display = 'block';
2288 l_list.options[r].style.display = 'none';
2290 $('info_div').style.display = "none";
2291 $('info_div').innerHTML = "";
2293 if (tot_found == 0) {
2294 if ($('info_' + _id)) {
2295 $('info_' + _id).innerHTML = content[69];
2298 if ($('info_' + _id)) {
2299 $('info_' + _id).innerHTML = " ";
2305 * Display the task late or for today in dashboard
2307 function display_task(p_id)
2310 $(p_id).style.top = posY + 'px';
2311 $(p_id).style.left = "10%";
2312 $(p_id).style.width = "80%";
2313 $(p_id).style.display = 'block';
2318 * Set a message in the info
2320 function info_message(p_message)
2322 $('info_div').innerHTML = p_message;
2323 $('info_div').style.display = "block";
2326 * @brief hide the info box
2328 function info_hide()
2330 $('info_div').style.display = "none";
2333 * Show the navigator in a internal window
2334 * @returns {undefined}
2336 function ask_navigator(p_dossier) {
2339 removeDiv('navi_div')
2340 var queryString = "gDossier=" + p_dossier + "&op=navigator";
2341 var action = new Ajax.Request(
2344 method: 'get', parameters: queryString,
2345 onFailure: ajax_misc_failure,
2346 onSuccess: function (req) {
2347 remove_waiting_box();
2348 add_div({id: 'navi_div', style: 'top:2em;', cssclass: 'inner_box'});
2349 $('navi_div').innerHTML = req.responseText;
2352 req.responseText.evalScripts();
2353 sorttable.makeSortable($("navi_tb"));
2356 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2363 info_message(e.message);
2368 * @brief Display an internal windows to set the user's preference
2371 function set_preference(p_dossier) {
2374 removeDiv('preference_div')
2375 var queryString = "gDossier=" + p_dossier + "&op=preference";
2376 var action = new Ajax.Request(
2379 method: 'get', parameters: queryString,
2380 onFailure: ajax_misc_failure,
2381 onSuccess: function (req) {
2382 remove_waiting_box();
2383 add_div({id: 'preference_div', drag: 1});
2384 $('preference_div').innerHTML = req.responseText;
2387 req.responseText.evalScripts();
2390 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2397 info_message(e.message);
2402 * @brief Display user's bookmark
2405 function show_bookmark(p_dossier) {
2408 removeDiv('bookmark_div');
2409 var param = window.location.search;
2410 param = param.gsub('?', '');
2411 var queryString = "gDossier=" + p_dossier + "&op=bookmark&" + param;
2412 var action = new Ajax.Request(
2415 method: 'get', parameters: queryString,
2416 onFailure: ajax_misc_failure,
2417 onSuccess: function (req) {
2418 remove_waiting_box();
2419 add_div({id: 'bookmark_div', cssclass: 'inner_box', drag: 1});
2420 $('bookmark_div').innerHTML = req.responseText;
2423 req.responseText.evalScripts();
2426 alert_box(content[53] + "\n" + e.message);
2433 info_message(e.message);
2438 * @brief save the bookmark
2440 function save_bookmark() {
2443 var queryString = "op=bookmark&" + $("bookmark_frm").serialize();
2444 var action = new Ajax.Request(
2447 method: 'get', parameters: queryString,
2448 onFailure: ajax_misc_failure,
2449 onSuccess: function (req) {
2450 remove_waiting_box();
2451 // removeDiv('bookmark_div');
2453 $('bookmark_div').innerHTML = req.responseText;
2456 req.responseText.evalScripts();
2459 alert_box(content[53] + "\n" + e.message);
2466 info_message(e.message);
2471 * @brief remove selected bookmark
2473 function remove_bookmark() {
2476 var queryString = "op=bookmark&" + $("bookmark_del_frm").serialize();
2477 var action = new Ajax.Request(
2480 method: 'get', parameters: queryString,
2481 onFailure: ajax_misc_failure,
2482 onSuccess: function (req) {
2483 remove_waiting_box();
2484 $('bookmark_div').innerHTML = req.responseText;
2487 req.responseText.evalScripts();
2490 alert_box(content[53] + "\n" + e.message);
2497 error_message(e.message);
2502 *@brief display the error message into the div error_content_div (included into error_div)
2503 *@param message message to display
2504 *@note there is no protection
2506 function error_message(message)
2508 $('error_content_div').innerHTML = message;
2509 $('error_div').style.visibility = 'visible';
2512 * @brief show the detail of a tag and propose to save it
2514 function show_tag(p_dossier, p_ac, p_tag_id, p_post)
2518 var queryString = "op=tag_detail&tag=" + p_tag_id + "&gDossier=" + p_dossier + "&ac=" + p_ac + '&form=' + p_post;
2519 var action = new Ajax.Request(
2522 method: 'get', parameters: queryString,
2523 onFailure: ajax_misc_failure,
2524 onSuccess: function (req) {
2525 var answer = req.responseXML;
2526 var html = answer.getElementsByTagName('code');
2527 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;
2540 code_html.evalScripts();
2543 alert_box(content[53] + "\n" + e.message);
2550 error_message(e.message);
2555 * @brief save the modified tag
2561 var queryString = "op=tag_save&" + $("tag_detail_frm").serialize();
2562 var action = new Ajax.Request(
2566 parameters: queryString,
2567 onFailure: ajax_misc_failure,
2568 onSuccess: function (req, j) {
2569 remove_waiting_box();
2570 removeDiv('tag_div');
2575 error_message(e.message);
2582 * Show a list of tag which can be added to the current followup document
2583 * @param {type} p_dossier
2584 * @param {type} ag_id
2585 * @returns {undefined}
2587 function action_tag_select(p_dossier, ag_id)
2591 var queryString = "ag_id=" + ag_id + "&op=tag_list&gDossier=" + p_dossier;
2592 var action = new Ajax.Request(
2595 method: 'get', parameters: queryString,
2596 onFailure: ajax_misc_failure,
2597 onSuccess: function (req, j) {
2598 var answer = req.responseXML;
2599 var html = answer.getElementsByTagName('code');
2600 if (html.length === 0)
2602 var rec = unescape_xml(req.responseText);
2603 error_message('erreur :' + rec);
2605 var code_html = getNodeText(html[0]);
2606 code_html = unescape_xml(code_html);
2607 var pos = fixed_position(35, 229);
2608 add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
2610 remove_waiting_box();
2611 $('tag_div').innerHTML = code_html;
2616 error_message(e.message);
2620 * @brief Add the current tag to the current ag_id
2621 * @param {type} p_dossier
2622 * @param {type} ag_id
2623 * @param p_isgroup g it is a group , t is a single tag
2624 * @returns {undefined}
2626 function action_tag_add(p_dossier, ag_id, t_id,p_isgroup)
2630 var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_add&gDossier=" + p_dossier+"&isgroup="+p_isgroup;
2631 var action = new Ajax.Request(
2634 method: 'get', parameters: queryString,
2635 onFailure: ajax_misc_failure,
2636 onSuccess: function (req, j) {
2637 var answer = req.responseXML;
2638 var html = answer.getElementsByTagName('code');
2639 if (html.length === 0)
2641 var rec = unescape_xml(req.responseText);
2642 error_message('erreur :' + rec);
2644 var code_html = getNodeText(html[0]);
2645 code_html = unescape_xml(code_html);
2646 remove_waiting_box();
2647 $('action_tag_td').innerHTML = code_html;
2648 removeDiv('tag_div');
2653 error_message(e.message);
2657 * @brief remove the current tag to the current ag_id
2658 * @param {type} p_dossier
2659 * @param {type} ag_id
2660 * @returns {undefined}
2662 function action_tag_remove(p_dossier, ag_id, t_id)
2664 confirm_box(null, content[50], function () {
2667 var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_remove&gDossier=" + p_dossier;
2668 var action = new Ajax.Request(
2671 method: 'get', parameters: queryString,
2672 onFailure: ajax_misc_failure,
2673 onSuccess: function (req) {
2674 var answer = req.responseXML;
2675 var html = answer.getElementsByTagName('code');
2676 if (html.length === 0)
2678 var rec = unescape_xml(req.responseText);
2679 error_message('erreur :' + rec);
2681 var code_html = getNodeText(html[0]);
2682 code_html = unescape_xml(code_html);
2683 remove_waiting_box();
2684 $('action_tag_td').innerHTML = code_html;
2690 error_message(e.message);
2697 * @param int p_dossier
2698 * @param int p_tag_id
2700 function activate_tag(p_dossier, p_tag_id) {
2702 new Ajax.Request("ajax_misc.php",
2705 parameters: {gDossier: p_dossier, op: 'tag_activate', t_id: p_tag_id},
2706 onSuccess: function (req) {
2707 remove_waiting_box();
2708 var answer = req.responseText.evalJSON();
2709 var tagId = "tag_onoff" + p_tag_id;
2710 $(tagId).update(answer.code);
2711 $(tagId).setStyle(answer.style);
2712 remove_waiting_box();
2717 * Display a div with available tags, this div can update the cell
2719 * @param {type} p_dossier
2720 * @param {string} p_prefix is the prefix of the div
2721 * @param {string} Calling object either Tag_Operation or Tag_Action
2722 * @returns {undefined}
2725 function search_display_tag(p_dossier, p_prefix,p_object)
2729 var queryString = { op : "search_display_tag",gDossier:p_dossier,pref:p_prefix,caller_obj:p_object};
2730 var action = new Ajax.Request(
2733 method: 'get', parameters: queryString,
2734 onFailure: ajax_misc_failure,
2735 onSuccess: function (req, j) {
2736 var answer = req.responseXML;
2737 var html = answer.getElementsByTagName('code');
2738 if (html.length === 0)
2740 var rec = unescape_xml(req.responseText);
2741 error_message('erreur :' + rec);
2743 var code_html = getNodeText(html[0]);
2744 code_html = unescape_xml(code_html);
2745 remove_waiting_box();
2746 add_div({id: p_prefix + 'tag_div', style: 'left:10%;width:70%', cssclass: 'inner_box', drag: 1});
2747 $(p_prefix + 'tag_div').style.top = calcy(200)+"px"
2748 $(p_prefix + 'tag_div').style.left = 20+ "%";
2749 remove_waiting_box();
2750 $(p_prefix + 'tag_div').innerHTML = code_html;
2751 code_html.evalScripts();
2756 error_message(e.message);
2760 * @brief Add the selected tag (p_tag_id) to the cell of tag_choose_td in the search screen
2761 * in the search screen
2762 * @param {type} p_dossier
2763 * @param {type} p_tag_id
2764 * @param p_prefix is the prefix of the widget
2765 * @param p_obj is either g for group of tag or t for a single tag
2767 function search_add_tag(p_dossier, p_tag_id, p_prefix,p_obj)
2770 var clear_button = 0;
2771 if (tag_choose === '' && p_prefix === 'search') {
2772 tag_choose = $(p_prefix + 'tag_choose_td').innerHTML;
2776 var queryString = "op=search_add_tag&gDossier=" + p_dossier + "&id=" + p_tag_id + "&clear=" + clear_button + '&pref=' + p_prefix+"&obj="+p_obj;
2777 var action = new Ajax.Request(
2780 method: 'get', parameters: queryString,
2781 onFailure: ajax_misc_failure,
2782 onSuccess: function (req, j) {
2783 var answer = req.responseXML;
2784 var html = answer.getElementsByTagName('html');
2785 if (html.length === 0)
2787 var rec = unescape_xml(req.responseText);
2788 error_message('erreur :' + rec);
2790 var code_html = getNodeText(html[0]);
2791 code_html = unescape_xml(code_html);
2792 remove_waiting_box();
2793 $(p_prefix + 'tag_choose_td').innerHTML = $(p_prefix + 'tag_choose_td').innerHTML + code_html;
2794 removeDiv(p_prefix + 'tag_div');
2799 error_message(e.message);
2803 * Clear the tags in the cell tag_choose_td of the search screen
2804 * @returns {undefined}
2806 function search_clear_tag(p_dossier, p_prefix)
2808 if (p_prefix != 'search') {
2809 $(p_prefix + 'tag_choose_td').innerHTML = "";
2813 var queryString = "op=search_clear_tag&gDossier=" + p_dossier + "&pref=" + p_prefix;
2814 var action = new Ajax.Request(
2817 method: 'get', parameters: queryString,
2818 onFailure: ajax_misc_failure,
2819 onSuccess: function (req, j) {
2820 var answer = req.responseXML;
2821 var html = answer.getElementsByTagName('html');
2822 if (html.length === 0)
2824 var rec = unescape_xml(req.responseText);
2825 error_message('erreur :' + rec);
2827 var code_html = getNodeText(html[0]);
2828 code_html = unescape_xml(code_html);
2829 $(p_prefix + 'tag_choose_td').innerHTML = code_html;
2835 error_message(e.message);
2838 function action_show_checkbox()
2840 var a = document.getElementsByName('ag_id_td');
2841 for (var i = 0; i < a.length; i++) {
2842 a[i].style.display = 'block';
2845 function action_hide_checkbox()
2847 var a = document.getElementsByName('ag_id_td');
2848 for (var i = 0; i < a.length; i++) {
2849 a[i].style.display = 'none';
2855 * object attribute : g
2856 * - Dossier dossier_id,
2857 * - invalue DOM Element where you can find the periode to zoom
2858 * - outdiv ID of the target (DIV)
2861 function calendar_zoom(obj)
2865 var per_periode = null;
2868 if ($(obj.invalue)) {
2869 per_periode = $(obj.invalue).value;
2871 if (obj.notitle && obj.notitle == 1) {
2874 var action = new Ajax.Request(
2878 parameters: {"notitle": notitle, "op": 'calendar_zoom', 'from': from, 'gDossier': obj.gDossier, 'in': per_periode, 'out': obj.outdiv, 'distype': obj.distype},
2879 onFailure: ajax_misc_failure,
2880 onSuccess: function (req, j) {
2881 var answer = req.responseXML;
2882 var html = answer.getElementsByTagName('html');
2883 if (html.length === 0)
2885 var rec = unescape_xml(req.responseText);
2886 error_message('erreur :' + rec);
2888 var code_html = getNodeText(html[0]);
2889 code_html = unescape_xml(code_html);
2891 // if the target doesn't exist
2893 if (obj.outdiv === undefined) {
2894 obj.outdiv = 'calendar_zoom_div';
2896 if ($(obj.outdiv) == undefined) {
2897 var str_style = 'top:10%;margin-left:2%;';
2898 // var str_style = fixed_position(0, 120);
2899 add_div({id: obj.outdiv, style: 'margin-left:3%;width:94%;' + str_style, cssclass: "inner_box", drag: 0});
2901 remove_waiting_box();
2902 $(obj.outdiv).innerHTML = code_html;
2903 $(obj.outdiv).show();
2908 error_message('calendar_zoom ' + e.message);
2914 * @brief add a line in the form for the stock
2916 function stock_add_row()
2919 style = 'class="input_text"';
2920 var mytable = g("stock_tb").tBodies[0];
2921 var ofirstRow = mytable.rows[1];
2922 var line = mytable.rows.length;
2923 var nCell = mytable.rows[1].cells.length;
2924 var row = mytable.insertRow(line);
2926 for (var e = 0; e < nCell; e++)
2928 var newCell = row.insertCell(e);
2929 if (mytable.rows[1].cells[e].hasClassName('num')) {
2930 newCell.addClassName("num");
2933 var tt = ofirstRow.cells[e].innerHTML;
2934 var new_tt = tt.replace(/sg_code0/g, "sg_code" + nb.value);
2935 new_tt = new_tt.replace(/sg_quantity0/g, "sg_quantity" + nb.value);
2936 new_tt = new_tt.replace(/label0/g, "label" + nb.value);
2937 newCell.innerHTML = new_tt;
2938 new_tt.evalScripts();
2941 g("sg_code" + nb.value).innerHTML = ' ';
2942 g("sg_code" + nb.value).value = '';
2943 g("label" + nb.value).innerHTML = '';
2944 g("sg_quantity" + nb.value).value = '0';
2948 new_tt.evalScripts();
2950 alert_box(e.message);
2954 function show_description(p_id)
2956 $('print_desc' + p_id).hide();
2957 $('input_desc' + p_id).show();
2961 * Display an empty card to fill , with the right card category
2962 * @param pn_fiche_card_id : fiche_def.fd_id
2963 * @param pn_dossier_id
2965 function select_cat(pn_fiche_card_id, pn_dossier_id, ps_element_id)
2967 dis_blank_card({"ctl": "div_new_card", "fd_id": pn_fiche_card_id, "op2": "bc", "op": "card", gDossier: pn_dossier_id, "elementId": ps_element_id});
2968 removeDiv('select_card_div');
2971 * Show the DIV and hide the other, the array of possible DIV are
2973 * @param {array} a_tabs name of possible tabs
2974 * @param {strng} p_display_tab tab to display
2976 function show_tabs(a_tabs, p_display_tab)
2980 if (a_tabs.length == 0) {
2981 console.error('a_tabs in empty');
2982 throw ("a_tabs empty");
2986 for (i = 0; i < a_tabs.length; i++) {
2987 $(a_tabs[i]).hide();
2989 $(p_display_tab).show();
2991 alert_box(e.message);
2996 * Change the class of all the "LI" element of a UL or OL
2997 * @param node of ul (this)
2999 function unselect_other_tab(p_tab)
3002 var other = p_tab.getElementsByTagName("li");
3005 for (i = 0; i < other.length; i++) {
3007 tab.className = "tabs";
3011 console.log(e.message);
3012 alert_box('unselect_other_tab ' + e.message);
3016 * logout function call from ajax
3017 * @see ajax_disconnected
3018 * @returns {undefined}
3022 var tmp_place = window.location.href
3023 var tmp_b = tmp_place.split('/')
3024 var tmp_last = tmp_b.length - 1
3025 var place_logout = tmp_place.replace(tmp_b[tmp_last], 'logout.php');
3026 window.location.href = place_logout;
3029 * Create a div which can be used in a anchor
3030 * @returns {undefined}
3032 function create_anchor_up()
3034 if (document.getElementById('up_top'))
3037 var newElt = document.createElement('div');
3038 newElt.setAttribute('id', 'up_top');
3039 newElt.innerHTML = '<a id="up_top"></a>';
3041 var parent = $('info_div').parentNode;
3042 parent.insertBefore(newElt, $('info_div'));
3046 * Initialize the window to show the button "UP" if the window is scrolled
3048 * @returns {undefined}
3050 function init_scroll()
3052 var up = new Element('div', {"class": "inner_box",
3053 "style": "padding:5px;left:auto;width:auto;height: auto;display:none;position:fixed;bottom:30%;right:50px;text-align:center;font-size:20px",
3056 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>';
3057 document.body.appendChild(up);
3058 window.onscroll = function () {
3059 if ( document.getElementById("select_box_content") )
3060 { document.getElementById("select_box_content").setStyle({display:"none"})};
3061 if (document.viewport.getScrollOffsets().top > 0) {
3062 if ($('go_up').visible() == false) {
3063 $('go_up').setOpacity(0.65);
3065 $('go_up').style.zIndex = 99;
3074 * Confirm a form thanks a modal dialog Box, it returns true if we agree otherwise
3077 <form onsubmit="return confirm_box(this,'message')">
3080 * @param p_obj form element (object) or element id (string)
3081 * @param p_message message to display
3082 * @returns true or false
3084 function confirm_box(p_obj, p_message, p_callback_true)
3088 // Find id of the end
3092 if (typeof (p_obj) === "object") {
3099 // execute the callback function or submit the form
3100 if (p_callback_true == undefined || p_callback_true == null)
3102 smoke.confirm(p_message, function (e) {
3108 smoke.confirm(p_message, function (e)
3111 p_callback_true.apply();
3116 alert_box(e.message);
3118 remove_waiting_box();
3122 * Alert box in CSS and HTML to replace the common javascript alert
3123 * @param p_message message to display
3126 function alert_box(p_message)
3128 smoke.alert(p_message, undefined, {ok: 'ok', classname: "inner_box"});
3133 * @brief Colorize the rows of the table
3134 * @param string p_table id of the table
3136 function alternate_row_color(p_table)
3138 var table_colored=$(p_table);
3139 if (! table_colored.tBodies[0] ) return;
3141 var len = table_colored.tBodies[0].rows.length;
3143 var localClass = "";
3144 for (i = 1; i < len; i++) {
3145 localClass = (i % 2 == 0) ? "even" : "odd";
3146 if ( table_colored.tBodies[0].rows[i].hasClassName("odd"))
3148 table_colored.tBodies[0].rows[i].removeClassName("odd");
3150 if (table_colored.tBodies[0].rows[i].hasClassName("even"))
3152 table_colored.tBodies[0].rows[i].removeClassName("even");
3154 table_colored.tBodies[0].rows[i].addClassName(localClass);
3159 * Make an DOM element draggable or not
3160 * @param object_id DOM id
3162 function pin(object_id) {
3163 if (aDraggableElement[object_id]) {
3164 aDraggableElement[object_id].destroy();
3165 aDraggableElement[object_id] = undefined;
3166 $('pin_' + object_id).innerHTML = "";
3168 aDraggableElement[object_id] = new Draggable(object_id, {starteffect: function ()
3170 new Effect.Highlight(object_id, {scroll: window, queue: 'end'});
3173 $('pin_' + object_id).innerHTML = "";
3177 * Show only the rows into the table (p_table_id) with the attribute (p_attribute_name) and if this attribute
3178 * has the value of (attribut_value)
3179 * @param p_table_id table id
3180 * @param p_attribute_name the name of the attribute
3181 * @param p_attribute_value the value of the attribute we want to show
3183 function show_only_row(p_table_id, p_attribute_name, p_attribute_value)
3185 if (!$(p_table_id)) {
3186 throw "Invalide table id"
3188 var mTable = $(p_table_id);
3189 var ncount = mTable.rows.length
3190 for (var i = 0; i < ncount; i++) {
3191 var mRow = mTable.rows[i];
3192 if (mRow.getAttribute(p_attribute_name) != undefined && mRow.getAttribute(p_attribute_name) != p_attribute_value) {
3200 * Show all the rows into the table (p_table_id)
3201 * @param p_table_id table id
3203 function show_all_row(p_table_id)
3205 if (!$(p_table_id)) {
3206 throw "Invalide table id"
3208 var mTable = $(p_table_id);
3209 var ncount = mTable.rows.length
3210 for (var i = 0; i < ncount; i++) {
3211 var mRow = mTable.rows[i];
3220 * - id of the row of the periode row_per_(p_periode_id) , attribute exercice =per_exercice,periode_id=p_id
3222 * - id of the table with the rows : periode_tbl
3225 * - periode_id the concerned Periode , 0 none
3226 * - p_ledger : the id of ledger (jrn_def.jrn_def_id), 0 for global
3227 * - pcallback : default ajax_misc.php (this.callback) with the parameter { op:'periode',gDossier,[action:display,remove,save],p_id:p_periode_id}
3229 * - js_obj_name : name of the js object (this.js_obj_name)
3230 * - ajax_test : file to include for debugging
3231 * - dialog : id of the dialog box (update / add ) periode_box
3234 var Periode = function (p_ledger) {
3235 this.periode_id = 0;
3236 this.p_ledger = p_ledger;
3237 this.dialog = 'periode_box';
3238 this.pcallback = 'ajax_misc.php';
3240 this.js_obj_name = "";
3241 this.ajax_test = "";
3242 this.set_callback = function (p_phpfile) {
3243 this.pcallback = p_phpfile;
3245 this.set_dossier = function (p_dosid) {
3246 this.dossier = p_dosid;
3249 * set_js_obj_name (p_js_obj_name)
3250 * We need to know the javascript variable name , to pass it to ajax and
3251 * create a HTML containing the right variable
3252 * @param p_js_obj_name name of the variable js we use on caller side
3254 this.set_js_obj_name = function (p_js_obj_name) {
3255 this.js_obj_name = p_js_obj_name;
3259 * Remove the periode , so call new Ajax and hide the row if successful
3260 * otherwise show dialog box.
3261 * @parameter p_periode_id is the id of periode
3263 this.remove = function (p_periode_id) {
3265 var js_param = {"gDossier": this.dossier,
3268 "p_id": p_periode_id,
3270 "js_var": this.js_obj_name};
3271 if (this.ajax_test != "") {
3272 js_param["TestAjaxFile"] = this.ajax_test;
3275 smoke.confirm("Confirmer ?", function (e) {
3278 new Ajax.Request(here.pcallback,
3281 parameters: js_param,
3282 onSuccess: function (req) {
3283 var answer = req.responseText.evalJSON();
3284 remove_waiting_box();
3285 if (answer.status == "OK")
3287 $("row_per_" + p_periode_id).remove();
3288 alternate_row_color("periode_tbl");
3290 smoke.alert(answer.content);
3299 * display a dialog box to update a periode, call save either display
3300 * an error box or update the row.
3301 * the name of variable is requested
3302 * to build the right button , javascript in the html of answer
3303 * @parameter p_periode_id is the id of periode
3305 this.box_display = function (p_periode_id) {
3306 if (this.js_obj_name == "") {
3307 smoke.alert("ERROR BOX_ADD")
3310 var js_param = {"gDossier": this.dossier,
3313 "p_id": p_periode_id,
3314 "ledger_id": this.p_ledger,
3315 "js_var": this.js_obj_name};
3316 if (this.ajax_test != "") {
3317 js_param["TestAjaxFile"] = this.ajax_test;
3320 new Ajax.Request(here.pcallback,
3323 parameters: js_param,
3324 onSuccess: function (req) {
3325 remove_waiting_box();
3326 var json = req.responseText.evalJSON();
3328 add_div({"id": "mod_periode", "style": "position:fixed;top:" + y + "px;width:50%", "cssclass": "inner_box", 'html': "wait"});
3329 $('mod_periode').update(json.content);
3334 * close the periode, call ajax and receive a json object with the attribute
3336 * @parameter p_periode_id is the id of periode
3338 this.close_periode = function (p_periode_id) {
3339 if (this.js_obj_name == "") {
3340 smoke.alert("ERROR BOX_ADD")
3343 if (this.ajax_test != "") {
3344 js_param["TestAjaxFile"] = this.ajax_test;
3347 smoke.confirm("Confirmer ?", function (e) {
3349 here._close(p_periode_id);
3354 * Internal function to close without confirming
3355 * @param {type} p_periode_id
3356 * @returns {undefined}
3358 this._close = function (p_periode_id) {
3359 if (this.js_obj_name == "") {
3360 smoke.alert("ERROR BOX_ADD")
3362 var js_param = {"gDossier": this.dossier,
3365 "ledger_id": this.p_ledger,
3366 "p_id": p_periode_id,
3367 "js_var": this.js_obj_name
3369 if (this.ajax_test != "") {
3370 js_param["TestAjaxFile"] = this.ajax_test;
3374 new Ajax.Request(here.pcallback,
3377 parameters: js_param,
3378 onSuccess: function (req) {
3379 remove_waiting_box();
3380 var json = req.responseText.evalJSON();
3381 if (json.status == 'OK')
3383 $('row_per_' + p_periode_id).update(json.content);
3384 new Effect.Highlight('row_per_' + p_periode_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3386 smoke.alert(json.content);
3392 * reopen the periode
3393 * @parameter p_periode_id is the SQL id of parm_periode or the id of
3396 this.open_periode = function (p_periode_id) {
3397 if (this.js_obj_name == "") {
3398 smoke.alert("ERROR BOX_ADD")
3400 var js_param = {"gDossier": this.dossier,
3403 "ledger_id": this.p_ledger,
3404 "p_id": p_periode_id,
3405 "js_var": this.js_obj_name
3407 if (this.ajax_test != "") {
3408 js_param["TestAjaxFile"] = this.ajax_test;
3411 smoke.confirm("Confirmer ?", function (e) {
3414 new Ajax.Request(here.pcallback,
3417 parameters: js_param,
3418 onSuccess: function (req) {
3419 remove_waiting_box();
3420 var json = req.responseText.evalJSON();
3421 if (json.status == 'OK')
3423 $('row_per_' + p_periode_id).update(json.content);
3424 new Effect.Highlight('row_per_' + p_periode_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3426 smoke.alert(json.content);
3434 * This DOMID of the DIV containing the form is mod_periode
3435 * @param {type} p_frm
3436 * @returns {Boolean}
3438 this.save = function (p_frm) {
3439 var js_param = $(p_frm).serialize(true);
3441 js_param["js_var"] = this.js_obj_name;
3442 js_param["act"] = "save";
3443 js_param["op"] = "periode";
3445 new Ajax.Request(this.pcallback, {
3447 parameters: js_param,
3448 onSuccess: function (req) {
3450 var answer = req.responseText.evalJSON();
3451 remove_waiting_box();
3452 if (answer.status == "OK") {
3453 $('row_per_' + js_param['periode_id']).update(answer.content);
3454 removeDiv('mod_periode');
3455 new Effect.Highlight('row_per_' + js_param['periode_id'], {startcolor: '#FAD4D4', endcolor: '#F78082'});
3457 smoke.alert(answer.content);
3464 * Thanks the object DOMID sel_per_closed[] the selected periodes are
3466 * @see Periode._close
3468 this.close_selected = function () {
3470 var a_selected = document.getElementsByName('sel_per_close[]');
3473 for (i = 0; i < a_selected.length; i++) {
3474 if (a_selected[i].checked == true) {
3475 // Close the selected periode
3480 smoke.signal("Sélectionner au moins une période", function () {}, {duration: 1500});
3483 smoke.confirm("Confirmer fermeture de " + count + " periode", function (e) {
3485 var a_selected = document.getElementsByName('sel_per_close[]');
3487 for (i = 0; i < a_selected.length; i++) {
3488 if (a_selected[i].checked == true) {
3489 // Close the selected periode
3490 here._close(a_selected[i].value);
3498 * @brief Insert a periode into the list, always at the bottom !
3500 * # FORM id :insert_periode_frm
3501 * # DIV id = periode_add
3502 * # table id = periode_tbl
3504 this.insert_periode = function () {
3505 var p_frm = 'insert_periode_frm';
3506 var js_param = $(p_frm).serialize(true);
3508 js_param["js_var"] = this.js_obj_name;
3509 js_param["act"] = "insert_periode";
3510 js_param["op"] = "periode";
3511 js_param["p_id"] = "-1";
3512 js_param["ledger_id"] = "0";
3514 new Ajax.Request(this.pcallback, {
3516 parameters: js_param,
3517 onSuccess: function (req) {
3518 var answer = req.responseText.evalJSON();
3519 remove_waiting_box();
3520 if (answer.status == "OK") {
3521 var new_row = document.createElement("tr");
3522 $('periode_tbl').append(new_row);
3523 new_row.replace(answer.content);
3526 $('periode_add').hide();
3527 new Effect.Highlight('row_per_' + answer.p_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3528 alternate_row_color('periode_tbl');
3530 smoke.alert(answer.content);
3539 * Show the periodes from the exercice contained into the id (p_exercice_sel)
3540 * @param p_table_id DOM ID of the table
3542 Periode.filter_exercice = function (p_table_id) {
3543 var rows = $(p_table_id).rows;
3544 var selected_value = $('p_exercice_sel').value;
3545 for (var i = 1; i < rows.length; i++) {
3546 var exercice = rows[i].getAttribute("per_exercice");
3547 if (selected_value == -1) {
3549 } else if (selected_value == exercice) {
3558 // keep track of progress bar
3559 var progressBar = [];
3560 // idx of progress bar
3561 var progressIdx = 0;
3564 * Start the progress bar
3565 * @param {string} p_taskid id to monitor
3566 * @param {int} p_message
3568 function progress_bar_start(p_taskid, p_message)
3574 var message = '<p>' + content[70] + '</p>';
3576 message = p_message;
3579 add_div({id: "blocking" + progressIdx, cssclass: "smoke-base smoke-visible "});
3581 add_div({id: "message" + progressIdx, cssclass: "inner_box", style: "z-index:1000;position:fixed;top:30%;width:40%;left:30%"});
3582 $("message" + progressIdx).update('<h3>' + content[65] + '</h3>' + message);
3584 add_div({id: "progressDiv" + progressIdx, cssclass: "progressbar", html: '<span id="progressValue">0</span>'});
3585 // Check status every sec.
3586 progressBar[progressIdx] = setInterval(progress_bar_check.bind(null, progressIdx, p_taskid), 1000);
3588 console.error(e.message);
3593 * Check every second the status
3594 * @param {integer} p_idx idx of progressbar
3595 * @param {string} p_taskid id to monitor
3597 function progress_bar_check(p_idx, p_taskid)
3601 new Ajax.Request("ajax_misc.php", {
3602 parameters: {gDossier: 0, task_id: p_taskid, op: "progressBar"},
3604 onSuccess: function (req) {
3607 var answer = req.responseText.evalJSON();
3608 var progress_div = $("progressDiv" + progressIdx);
3609 var a_child = progress_div.childNodes;
3611 for (i = 0; i < a_child.length; i++) {
3612 if (a_child[i].id = "progressValue") {
3613 var progressValue = a_child[i];
3616 var progress = parseFloat(progressValue.innerHTML);
3617 if (answer.value <= progress) {
3621 progressValue.innerHTML = answer.value;
3622 progressValue.setStyle("width:" + answer.value + "%");
3623 if (answer.value == 100) {
3624 clearInterval(progressBar[p_idx]);
3625 progressValue.innerHTML = "Success";
3626 Effect.BlindUp("progressDiv" + p_idx, {duration: 1.0, scaleContent: false})
3627 $("message" + p_idx).remove();
3628 $("blocking" + p_idx).remove();
3629 setTimeout(function () {
3630 $("progressDiv" + progressIdx).remove
3634 clearInterval(progressBar[p_idx]);
3635 document.getElementById("progressValue").innerHTML = req.responseText;
3636 console.error(e.message);
3641 clearInterval(progressBar[p_idx]);
3642 console.error(e.message);
3647 * In the user's setting box, update the period list with the choosen exercice
3648 * @param {int} p_dossier
3650 function updatePeriodePreference(p_dossier)
3653 var exercice = $('exercice_setting').value;
3654 new Ajax.Updater('setting_period', "ajax_misc.php", {method: "get", parameters: {"op": "pref_exercice", "gDossier": p_dossier, "exercice": exercice}});
3655 remove_waiting_box();
3658 * Update the from and to periode list when changing the exercice
3659 * @param {int} p_dossier
3660 * @param {string} p_exercice id of the exercice
3661 * @param {type} p_periode_from id of the starting periode
3662 * @param {type} p_periode_to id of the ending periode
3663 * @param {type} p_last possible value = 1 to show last periode or 0 the first
3665 function updatePeriode(p_dossier, p_exercice, p_periode_from, p_periode_to, p_last)
3668 var exercice = $(p_exercice).value;
3669 new Ajax.Updater(p_periode_from, "ajax_misc.php", {method: "get", parameters: {op: "periode_change", "gDossier": p_dossier, "exercice": exercice, field: p_periode_from, "type": "from", "last": p_last}});
3670 new Ajax.Updater(p_periode_to, "ajax_misc.php", {method: "get", parameters: {op: "periode_change", "gDossier": p_dossier, "exercice": exercice, field: p_periode_to, "type": "to", "last": p_last}});
3671 remove_waiting_box();
3675 * @param {string} p_domid DOM id of the span containing the padlock icon
3678 function toggle_lock(p_domid)
3680 var padlock = document.getElementById(p_domid);
3681 if (padlock == null) {
3682 console.error("domid invalid");
3684 var status = padlock.getAttribute("is_locked");
3686 padlock.innerHTML = "";
3687 padlock.setAttribute("is_locked", 0);
3688 } else if (status == 0) {
3689 padlock.innerHTML = "";
3690 padlock.setAttribute("is_locked", 1);
3692 throw "toggle_lock failed";
3699 * @returns {undefined}
3701 function show_ledger_fin_currency()
3703 var ledger=$('p_jrn').value;
3704 var dossier=$('gDossier').value;
3705 // $('ledger_currency').
3706 var a=new Ajax.Updater("ledger_currency",
3709 parameters: {"op":"currencyCode","gDossier":dossier,"ledger":ledger}
3714 * Update Preference, applied the new CSS
3716 function updatePreference()
3720 var param = $('preference_frm').serialize() + "&op=preference&action=save";
3722 new Ajax.Request("ajax_misc.php", {
3725 onSuccess: function (req) {
3726 var style = req.responseText.evalJSON();
3727 // $('pagestyle').setAttribute('href', style.style);
3728 removeDiv('preference_div');
3733 smoke.alert(content[48] + e.message);
3735 remove_waiting_box();
3740 * turn on or off , set an domElement to 1 or 0 and change the icon
3741 * @param string icon_domid : id of the domElement which must be changed
3742 * @param string p_value_domid : id of domElement containing 1 or 0
3743 * @see param_jrn.php
3745 function toggle_onoff(icon_domid, p_value_domid)
3747 if ($(p_value_domid).value == 0) {
3748 $(p_value_domid).value = 1;
3749 $(icon_domid).innerHTML = '';
3750 $(icon_domid).style = 'color:green';
3752 $(p_value_domid).value = 0;
3753 $(icon_domid).innerHTML = '';
3754 $(icon_domid).style = 'color:red';
3758 * turn on or off , set an domElement to 1 or 0 and change the icon
3759 * @param string icon_domid : id of the domElement which must be changed
3760 * @param string p_value_domid : id of domElement containing 1 or 0
3761 * @see param_jrn.php
3763 function toggle_checkbox_onoff(icon_domid, p_value_domid)
3765 console.log("toggle_checkbox_onoff");
3766 console.log("icon_domid"+icon_domid);
3767 console.log("p_value_domid"+p_value_domid);
3769 if ($(p_value_domid).value == 0) {
3770 $(p_value_domid).value = 1;
3771 $(icon_domid).innerHTML = '';
3773 $(p_value_domid).value = 0;
3774 $(icon_domid).innerHTML = '';
3778 * in CFGLED show or hide the row depending if the warning is enable or not
3780 * @param {type} p_enable
3781 * @param {type} p_row
3782 * @returns {undefined}
3784 function toggle_row_warning_enable(p_enable, p_row)
3786 if ($(p_enable).value == 1) {
3794 * return a json object which is the merge of the 2 json objects
3795 * from 2015 : Object.assign(obj1, obj2);
3796 * @param p_json1 object 1 to merge
3797 * @param p_json2 object 2 to merge
3798 * @returns new json object
3800 function json_concat(p_json1,p_json2)
3804 for (var key in p_json1) {
3805 result[key] = p_json1[key];
3807 for (var key in p_json2) {
3808 result[key] = p_json2[key];
3815 * return a json object which is the merge of the 2 json objects
3816 * from 2015 : Object.assign(obj1, obj2);
3817 * @param p_json1 object 1 to merge
3818 * @param p_json2 object 2 to merge
3819 * @returns new json object
3821 function json_concat(p_json1,p_json2)
3825 for (var key in p_json1) {
3826 result[key] = p_json1[key];
3828 for (var key in p_json2) {
3829 result[key] = p_json2[key];
3835 * this function unchecks other checkbox , it mimics the way a radio behaves
3836 * @param string p_click is the DOM id of the checkbox you clicked
3837 * @param string p_name is the name of all the checkbox to uncheck
3839 function uncheck_other(p_click,p_name)
3841 var aCheckbox=document.getElementsByName(p_name);
3842 if (aCheckbox.length == 0) return;
3844 for (i=0;i<aCheckbox.length;i++) {
3845 aCheckbox[i].checked=false;
3847 p_click.checked=true;
3850 * Manage the tag with operations
3851 * @returns {undefined}
3853 var operation_tag = function (p_div)
3856 console.log("ctl "+p_div);
3858 * Show a list of tag which can be added to the current followup document
3859 * @param {type} p_dossier
3860 * @param {type} jrn_id
3861 * @returns {undefined}
3863 this.select = function (p_dossier, p_jrn_id)
3867 var queryString = {jrn_id:p_jrn_id,op:"operation_tag_select",gDossier:p_dossier,ctl:this.ctl};
3868 var action = new Ajax.Request(
3872 parameters: queryString,
3873 onFailure: ajax_misc_failure,
3874 onSuccess: function (req, j) {
3875 remove_waiting_box();
3877 var answer = req.responseXML;
3878 var html = answer.getElementsByTagName('code');
3879 if (html.length === 0)
3881 var rec = unescape_xml(req.responseText);
3882 error_message('erreur :' + rec);
3884 var code_html = getNodeText(html[0]);
3885 code_html = unescape_xml(code_html);
3886 var pos = fixed_position(35, 229);
3887 add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
3889 remove_waiting_box();
3890 $('tag_div').innerHTML = code_html;
3895 error_message(e.message);
3900 * @brief Add the current tag to the current ag_id
3901 * @param {type} p_dossier
3902 * @param {type} ag_id
3903 * @param p_isgroup g it is a group , t is a single tag
3904 * @returns {undefined}
3906 this.add = function (p_dossier, p_jrn_id, t_id, p_isgroup)
3910 var queryString = {t_id:t_id,jrn_id:p_jrn_id,op:"operation_tag_add",
3911 gDossier:p_dossier,ctl:this.ctl,isgroup:p_isgroup};
3913 var action = new Ajax.Request(
3916 method: 'get', parameters: queryString,
3917 onFailure: ajax_misc_failure,
3918 onSuccess: function (req, j) {
3919 var answer = req.responseXML;
3920 console.log("1-ctl "+ctl);
3921 var html = answer.getElementsByTagName('code');
3922 if (html.length === 0)
3924 var rec = unescape_xml(req.responseText);
3925 error_message('erreur :' + rec);
3927 var code_html = getNodeText(html[0]);
3928 code_html = unescape_xml(code_html);
3929 remove_waiting_box();
3930 $('operation_tag_td'+ctl).innerHTML = code_html;
3931 removeDiv('tag_div');
3936 error_message(e.message);
3940 * @brief remove the current tag to the current ag_id
3941 * @param {type} p_dossier
3942 * @param {type} ag_id
3943 * @returns {undefined}
3945 this.remove = function (p_dossier, p_jrn_id, t_id)
3948 console.log("remove-1.ctl "+ctl);
3949 confirm_box(null, content[50], function () {
3952 var queryString = {t_id:t_id,jrn_id:p_jrn_id,op:"operation_tag_remove",gDossier:p_dossier,ctl:ctl};
3953 var action = new Ajax.Request(
3957 parameters: queryString,
3958 onFailure: ajax_misc_failure,
3959 onSuccess: function (req, j) {
3960 var answer = req.responseXML;
3961 var html = answer.getElementsByTagName('code');
3962 if (html.length === 0)
3964 var rec = unescape_xml(req.responseText);
3965 error_message('erreur :' + rec);
3967 var code_html = getNodeText(html[0]);
3968 code_html = unescape_xml(code_html);
3969 remove_waiting_box();
3970 console.log("remove-2.ctl "+ctl);
3971 $('operation_tag_td'+ctl).innerHTML = code_html;
3977 error_message(e.message);
3984 * Check the sum of size of all the FILES to upload
3985 * @param p_object the form DOM object,
3986 * @param p_max_size MAX_FILE_SIZE constant (see config.inc.php or constant.php)
3987 * @returns true if the sum of filesize is greater than the limit
3989 function check_file_size(p_object,p_max_size)
3992 for(var i=0;i<p_object.elements.length;i++) {
3993 var a=p_object.elements[i];
3994 if ( p_object.elements[i].getAttribute('type')=="file" )
3996 if( p_object.elements[i].files[0]){
3998 sum_file+=p_object.elements[i].files[0].size;
4002 if ( sum_file > p_max_size) {alert_box(content[78]);return false;}
4007 * Check that the receipt file is not too big
4008 * @see ajax_ledger.php , ledger_detail_file
4009 * @param int p_max_size maximum size
4010 * @param p_info name of the waiting box
4011 * @returns true if file size is less than the maximum
4013 function check_receipt_size(p_max_size,p_info)
4015 document.getElementById(p_info).style.display="inline";
4016 console.debug ("param p_max_file_size"+p_max_size);
4017 var f=document.getElementById("receipt_id");
4018 if ( f && f.files[0] && f.files[0].size > parseFloat(p_max_size)) {
4019 document.getElementById("receipt_info_id").innerHTML=content[78];
4020 document.getElementById(p_info).style.display="none";
4023 document.getElementById("receipt_info_id").innerHTML="";
4024 document.getElementById("form_file").submit();
4028 * @brief toggle size of a div : fullsize or normal
4031 function full_size(p_div) {
4032 div_dom=document.getElementById(p_div);
4033 if ( ! div_dom ) return;
4034 if ( div_dom.hasClassName('fullsize')) {
4035 div_dom.removeClassName('fullsize');$('size_'+p_div).innerHTML='';
4037 div_dom.addClassName('fullsize');$('size_'+p_div).innerHTML='';
4043 * @brief download a document from an url
4045 function download_document(p_url)
4048 document.location=p_url;
4049 remove_waiting_box();
4052 * @brief download a document from a form
4054 function download_document_form(p_form_id)
4057 var url="export.php?"+$(p_form_id).serialize();
4058 document.location=url;
4059 remove_waiting_box();
4063 * Search an account or an analytic account or a card, used in REPORT
4064 * @param {json} p_obj ,
4065 * property : - op for ajax_misc ,
4067 * - target DOM element to update with the result
4068 * - query for the search
4071 function search_account_card(p_obj)
4073 p_obj['op']=p_obj['op']||"search_account_card";
4075 if (p_obj.tagName && p_obj.tagName=='FORM') {
4076 query=p_obj.serialize(true);
4080 new Ajax.Request("ajax_misc.php",{method:"get",parameters:query,
4081 onSuccess: function (req){
4084 var obj={id:"search_account_div",cssclass:"inner_box",style:"top:"+pos+"px",
4085 html:req.responseText};
4087 remove_waiting_box();