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, it is the first script and
25 * should contain all the global variables
29// tag_choose Element which contains all the selected tags
31var aDraggableElement = new Array();
32// Layer for z-index , see function get_next_layer , must be used in PHP and JS
34// document.viewport depends of prototype.js
35var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
36var width = viewport.width; // Usable window width
37var height = viewport.height;
38var g_enable_tinymce=true;
40 * if browser < 2021, function window.crypto.randomUUID is not implemented
41 * so we tinyMCE cannot work
43if ( ! window.crypto.randomUUID) {
44 console.info("too old browser: implement function randomUUID")
45 window.crypto.randomUUID=function()
47 let myArray = new Uint32Array(4);
48 crypto.getRandomValues(myArray);
49 let result="";let and="";
61 * return undefined if nothing is found , otherwise return the DOM elemnt, try to find an DOM Element inside p_element
62 * @param {type} p_name_dom
63 * @param {type} name_child
64 * @returns {undefined}
66function in_child(p_element, name_child) {
67 var element = p_element
68 if (typeof p_element !== "object") {
69 element = document.getElementById(p_element);
72 if (!element) return undefined;
73 for (var e = 0; e < element.childElementCount; e++) {
74 if (element.childNodes[e].id == name_child) {
75 return element.childNodes[e];
81 * callback function when we just need to update a hidden div with an info
83 * @see removeOperation , reverseOperation
85function infodiv(req, json) {
88 var answer = req.responseXML;
89 var a = answer.getElementsByTagName('ctl');
90 var html = answer.getElementsByTagName('code');
92 var rec = req.responseText;
93 alert_box('erreur :' + rec);
95 var name_ctl = a[0].firstChild.nodeValue;
96 var code_html = getNodeText(html[0]);
98 code_html = unescape_xml(code_html);
99 id$(name_ctl + "info").innerHTML = code_html;
101 alert_box("success_box" + e.message);
104 code_html.evalScripts();
106 alert_box(content[53] + "\n" + e.message);
112 * delete a row from a table (tb) the input button send the this
113 * as second parameter
115function deleteRow(tb, obj) {
116 smoke.confirm(content[50], function (e) {
118 var td = obj.parentNode;
119 var tr = td.parentNode;
120 var lidx = tr.rowIndex;
121 id$(tb).deleteRow(lidx);
129function deleteRowRec(tb, obj) {
131 var lidx = tr.rowIndex;
132 id$(tb).deleteRow(lidx);
135/*!\brief remove trailing and heading space
136 * \param the string to modify
137 * \return string without heading and trailing space
140 return s.replace(/^\s+/, '').replace(/\s+$/, '');
144 * retrieve an element thanks its ID
145 * @param ID is a string
146 * @return the found object of undefined if not found
149 if (ID instanceof Object ) return ID;
150 if (document.getElementById(ID)) {
151 return document.getElementById(ID);
152 } else if (document.all) {
153 return document.all[ID];
155 document.debug_noalyss&&console.error(`id$ ${ID} not found`)
161 * this function is deprecated and replaced by id$
167 document.debug_noalyss&& console.warn(`g(${ID} is deprecated, use id$`);
170function get_next_layer(){
171 return global_layer++;
174 * enable the type of periode
176function enable_type_periode() {
177 if (document.getElementById("type_periode").options[id$("type_periode").selectedIndex].value == 0) {
178 id$('from_periode').enable();
179 id$('to_periode').enable();
180 id$('from_date').disable();
181 id$('to_date').disable();
182 id$('p_step').enable();
184 id$('from_periode').disable();
185 id$('to_periode').disable();
186 id$('from_date').enable();
187 id$('to_date').enable();
188 id$('p_step').disable();
193 * will reload the window but it is dangerous if we have submitted
196function refresh_window() {
197 window.location.reload();
202 * we receive a json object as parameter and the function returns the string
203 * with the format variable=value&var2=val2...
205function encodeJSON(obj) {
206 if (typeof obj != 'object') {
207 alert_box('encodeParameter obj n\'est pas un objet');
219 str += '=' + encodeURI(obj[i]);
223 alert_box('encodeParameter ' + e.message);
228function hide(p_param) {
229 id$(p_param).style.display = 'none';
232function show(p_param) {
233 id$(p_param).style.display = 'block';
237 * set the focus on the selected field
238 *@param Field id of the control
239 *@param selectIt : the value selected in case of Field is a object select, numeric
241function SetFocus(Field, SelectIt) {
242 var elem = id$(Field);
250 * set a DOM id with a value in the parent window (the caller),
251 @param p_ctl is the name of the control
252 @param p_value is the value to set in
253 @param p_add if we don't replace the current value but we add something
255function set_inparent(p_ctl, p_value, p_add) {
256 self.opener.set_value(p_ctl, p_value, p_add);
260 * set a DOM id with a value, it will consider if it the attribute
261 value or innerHTML has be used
262 @param p_ctl is the name of the control
263 @param p_value is the value to set in
264 @param p_add if we don't replace the current value but we add something
266function set_value(p_ctl, p_value, p_add) {
267 if (document.getElementById(p_ctl)) {
268 var g_ctrl = id$(p_ctl);
269 if (p_add != undefined && p_add === 1) {
271 p_value = g_ctrl.value + ',' + p_value;
274 if (g_ctrl.tagName === 'INPUT') {
275 id$(p_ctl).value = p_value;
277 if (g_ctrl.tagName === 'SPAN') {
278 id$(p_ctl).innerHTML = p_value;
280 if (g_ctrl.tagName === 'SELECT') {
281 id$(p_ctl).value = p_value;
287 * compute small math in numeric cells
288 * @param string value
291function compute_number(value) {
294 var exp = new RegExp("^[0-9/*+-.()]+$", "g");
295 /*pour éviter un eval() mal intentionné*/
296 var res = exp.test(value);
298 /*pour gérer un nombre non valide comme 5..36 ou 5.3.6
299 parce qu'il est possible d'entrer plusieurs
300 points dans le nombre et eval() lève une exception*/
302 retval = eval(value);
304 return parseFloat(value);
306 /*pour gérer les divisions par 0*/
307 if (retval == Infinity) {
318 * format the number change comma to point
321function format_number(obj, p_prec) {
323 if (p_prec === undefined) {
328 var value = obj.value;
329 value = value.replace(/ /g, '');
330 value = value.replace(/,/g, '.');
333 value = compute_number(value);
335 value = parseFloat(value);
339 var arrondi = Math.pow(10, precision);
341 value = Math.round(value * arrondi) / arrondi;
343 id$(obj).value = value;
347 * Replace slash , space and minus by dot
348 * @param p_object DOM Element date to check
350function format_date(p_object) {
351 p_object.value = p_object.value.replace(/\//g, '.');
352 p_object.value = p_object.value.replace(/-/g, '.');
353 p_object.value = p_object.value.replace(/ /g, '.');
354 p_object.value = p_object.value.replace(/\.\./g, '.');
355 var tmp_value = p_object.value;
356 a_split = tmp_value.split('.');
357 if (a_split[2] && a_split[2].match(/[0-9]{2}/) && a_split[2].length == 2) {
358 a_split[2] = "20" + a_split[2];
359 p_object.value = a_split[0] + "." + a_split[1] + "." + a_split[2];
361 var nMonth = parseFloat(a_split[1]) - 1;
362 var ma_date = new Date(a_split[2], nMonth, a_split[0]);
363 if (ma_date.getFullYear() == a_split[2] && ma_date.getMonth() == nMonth && ma_date.getDate() == a_split[0]) {
366 new Effect.Highlight(p_object.id, {startcolor: "#ff0000"});
374 * check if the object is hidden or show and perform the opposite,
375 * show the hidden obj or hide the shown one. With display : flex,
376 *@param name of the object
377 * @param button id of the button
378 * @param rotate : if true with rotate the object of p_button otherwise
380function toggleHideShow(p_obj, p_button, rotate) {
381 var div_obj = id$(p_obj);
382 var stat = div_obj.style.display;
384 var str = (id$(p_button)) ? id$(p_button).value : "";
386 if (stat === 'none') {
387 // specific for the DIV id search_form
388 if (div_obj.id == 'search_form') {
393 str = str.replace(/Afficher/, content[62]);
394 id$(p_button).value = str;
396 // specific for the DIV di search_form
397 if (!div_obj.id == 'search_form') {
402 str = str.replace(/Cacher/, content[63]);
403 id$(p_button).value = str;
406 if (stat == "none") {
407 id$(p_button).addClassName("icon-up-open-1")
408 id$(p_button).removeClassName(" icon-down-open-2")
410 id$(p_button).removeClassName("icon-up-open-1")
411 id$(p_button).addClassName(" icon-down-open-2")
418 * open popup with the search windows
419 *@param p_dossier the dossier where to search
420 *@param p_style style of the detail value are E for expert or S for simple
422function popup_recherche(p_dossier) {
423 var w = window.open("recherche.php?gDossier=" + p_dossier + "&ac=SEARCH", '', 'statusbar=no,scrollbars=yes,toolbar=no');
428 * replace the special characters (><'") by their HTML representation
429 *@return a string without the offending char.
431function unescape_xml(code_html) {
432 code_html = code_html.replace(/\</, '<');
433 code_html = code_html.replace(/\>/, '>');
434 code_html = code_html.replace(/\"/, '"');
435 code_html = code_html.replace(/\'/, "'");
436 code_html = code_html.replace(/\&/, '&');
441 * Firefox splits the XML into 4K chunk, so to retrieve everything we need
442 * to get the different parts thanks textContent
443 *@param xmlNode a node (result of var data = =answer.getElementsByTagName('code'))
444 *@return all the content of the XML node
446function getNodeText(xmlNode) {
449 if (typeof (xmlNode.textContent) != "undefined") {
450 return xmlNode.textContent;
452 if (xmlNode.firstChild && xmlNode.firstChild.nodeValue)
453 return xmlNode.firstChild.nodeValue;
458 * change the periode in the calendar of the dashboard
459 *@param object select
461function change_month(obj) {
462 var action = new Ajax.Request(
467 gDossier: obj.gDossier,
473 onFailure: ajax_misc_failure,
474 onSuccess: success_misc
481 * basic answer to ajax on success, it will fill the DOMID code with
482 * the code. In that case, you need to create the object before the Ajax.Request
483 *The difference with success box is that
484 *@see add_div removeDiv success_box is that the width and height are not changed ajax_misc.php
485 *@param code is the ID of the object containing the html (div, button...)
486 *@param value is the html code, with it you fill the ctl element
489function success_misc(req) {
491 var answer = req.responseXML;
492 var html = answer.getElementsByTagName('code');
493 if (html.length === 0) {
494 var rec = req.responseText;
495 alert_box('erreur :' + rec);
497 var nodeXml = html[0];
498 var code_html = getNodeText(nodeXml);
499 code_html = unescape_xml(code_html);
500 id$("user_cal").innerHTML = code_html;
502 alert_box(e.message);
505 code_html.evalScripts();
507 alert_box(content[53] + "\n" + e.message);
515 var str ='<div style="animation-duration:6s;animation-name:fill_up_loading;animation-iteration-count: infinite;animation-timing-function: linear;align-items: center">';
516 str += '<div class="loading_msg"></div>';
517 str += '<div class="loading_msg"></div>';
518 str += '<div class="loading_msg"></div>';
519 str += '<div class="loading_msg"></div>';
520 str += '<div class="loading_msg"></div>';
523 var str2 = '<div style="animation-duration:6s;animation-name:fill_up_loading;animation-iteration-count: infinite;animation-timing-function: linear;position:relative;top:-50px;animation-delay: 0.7s;">';
524 str2 += '<div class="loading_msg"></div>';
525 str2 += '<div class="loading_msg"></div>';
526 str2 += '<div class="loading_msg"></div>';
527 str2 += '<div class="loading_msg"></div>';
528 str2 += '<div class="loading_msg"></div>';
533function ajax_misc_failure() {
534 alert_box(content[53]);
538 * remove a document_modele
540function cat_doc_remove(p_dt_id, p_dossier) {
541 var queryString = "gDossier=" + p_dossier + "&op=rem_cat_doc" + "&dt_id=" + p_dt_id;
542 var action = new Ajax.Request(
545 parameters: queryString,
546 onFailure: ajax_misc_failure,
547 onSuccess: function (req) {
549 var answer = req.responseXML;
550 var html = answer.getElementsByTagName('dtid');
551 if (html.length === 0) {
552 var rec = req.responseText;
553 alert_box('erreur <br>' + rec);
556 var nodeXML = html[0];
557 var row_id = getNodeText(nodeXML);
558 if (row_id === 'nok') {
559 var message_node = answer.getElementsByTagName('message');
560 var message_text = getNodeText(message_node[0]);
561 alert_box('erreur <br>' + message_text);
564 id$('row' + row_id).style.textDecoration = "line-through";
565 id$('X' + row_id).style.display = 'none';
566 id$('M' + row_id).style.display = 'none';
568 alert_box(e.message);
576 * change a document_modele
578function cat_doc_change(p_dt_id, p_dossier) {
579 var queryString = "gDossier=" + p_dossier + "&op=mod_cat_doc" + "&dt_id=" + p_dt_id;
580 var nTop = calcy(posY);
582 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:50em;height:auto";
584 removeDiv('change_doc_div');
586 var action = new Ajax.Request(
589 method: 'get', parameters: queryString,
590 onFailure: ajax_misc_failure,
591 onSuccess: function (req) {
592 remove_waiting_box();
593 add_div({id: 'change_doc_div', style: str_style, cssclass: 'inner_box', drag: "1"});
594 id$('change_doc_div').innerHTML = req.responseText;
602 * display the popup with vat and explanation
603 *@param obj with 4 attributes gdossier, ctl,popup
604 *@param p_function_callback callback function to be called after,
606function popup_select_tva(obj, p_function_callback) {
608 if (document.getElementById('tva_select')) {
609 removeDiv('tva_select');
611 var gDossier=(obj.gDossier)?obj.gDossier:obj.getAttribute("gdossier");
612 var ctl=(obj.ctl)?obj.ctl:obj.getAttribute("ctl");
614 var queryString = "gDossier=" + gDossier + "&op=dsp_tva" + "&ctl=" + ctl + '&popup=' + 'tva_select';
616 var jcode=(obj.jcode)?obj.jcode:obj.getAttribute("jcode");
618 queryString += '&code=' + jcode;
619 var compute=(obj.compute)?obj.compute:obj.getAttribute("compute");
620 if (compute) queryString += '&compute=' + compute;
621 var filter=(obj.filter)?obj.filter:obj.getAttribute("filter");
623 if (filter) queryString += '&filter=' + filter;
625 var action = new Ajax.Request(
629 parameters: queryString,
630 onFailure: ajax_misc_failure,
631 onSuccess: function (req) {
633 var answer = req.responseXML;
634 var popup = answer.getElementsByTagName('popup');
635 if (popup.length === 0) {
636 var rec = req.responseText;
637 alert_box('erreur :' + rec);
639 var html = answer.getElementsByTagName('code');
641 var name_ctl = popup[0].firstChild.nodeValue;
642 var nodeXml = html[0];
643 var code_html = getNodeText(nodeXml);
644 code_html = unescape_xml(code_html);
646 var nTop = posY - 200;
648 var str_style = "top:" + nTop + "px;left:" + nLeft + ";right:" + nLeft + ";width:55em;height:auto;z-index:"+get_next_layer()+';';
652 'cssclass': 'inner_box',
658 id$('lk_tva_select_table').focus();
659 sorttable.makeSortable(id$('tva_select_table'));
660 if (p_function_callback) {
661 p_function_callback.call(null);
664 alert_box("success_popup_select_tva " + e.message);
670 alert_box("popup_select_tva " + e.message);
676 * display the popup with vat and explanation
677 *@param obj with 4 attributes gdossier, ctl,popup
679function set_tva_label(obj) {
681 var queryString = "gDossier=" + obj.gDossier + "&op=label_tva" + "&id=" + obj.value;
683 queryString += '&code=' + obj.jcode;
684 else if ( obj.getAttribute("jcode") )
685 queryString += '&code=' + obj.getAttribute("jcode") ;
686 var action = new Ajax.Request(
690 parameters: queryString,
691 onFailure: ajax_misc_failure,
692 onSuccess: success_set_tva_label
696 alert_box("set_tva_label " + e.message);
701 * display the popup with vat and explanations
702 *@param string req answer from ajax
704function success_set_tva_label(req) {
706 var answer = req.responseXML;
707 var code = answer.getElementsByTagName('code');
708 var value = answer.getElementsByTagName('value');
710 if (code.length === 0) {
711 var rec = req.responseText;
712 alert_box('erreur :' + rec);
715 var label_code = code[0].firstChild.nodeValue;
716 var label_value = value[0].firstChild.nodeValue;
717 set_value(label_code, label_value);
719 alert_box("success_set_tva_label " + e.message);
725 * Create a div without showing it
728 * - style to add style
730 * - cssclass to add a class
731 * - html is the content
732 * - drag is the div can be moved
733 * @returns html dom element
736function create_div(obj) {
740 if (!document.getElementById(obj.id)) {
741 elt = top.createElement('div');
746 elt.setAttribute('id', obj.id);
749 if (elt.style.setAttribute) { /* IE7 bug */
750 elt.style.setAttribute('cssText', obj.style);
751 } else { /* good Browser */
752 elt.setAttribute('style', obj.style);
756 elt.setAttribute('class', obj.cssclass); /* FF */
757 elt.setAttribute('className', obj.cssclass); /* IE */
760 elt.innerHTML = obj.html;
763 var bottom_div = document.body;
765 bottom_div.appendChild(elt);
767 /* if ( obj.effect && obj.effect != 'none' ) { Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }
768 else if ( ! obj.effect ){ Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }*/
770 aDraggableElement[obj.id] = new Draggable(obj.id, {
771 starteffect: function () {
772 new Effect.Highlight(obj.id, {scroll: window, queue: 'end'});
781 error_message("create_div " + e.message);
786 * add dynamically a object for AJAX
789 * - style to add style
791 * - cssclass to add a class
792 * - html is the content
793 * - drag is the div can be moved
795function add_div(obj) {
797 var elt = create_div(obj);
798 /* elt.setStyle({visibility:'visible'}); */
799 elt.style.visibility = 'visible';
803 alert_box("add_div " + e.message);
808 * remove a object created with add_div
809 * @param str_elt string id of the elt
811function removeDiv(str_elt) {
812 if (document.getElementById(str_elt)) {
813 document.body.removeChild(id$(str_elt));
815 // if reloaded if asked the window will be reloaded when
817 if (ask_reload === 1) {
818 // avoid POST window.location = window.location.href;
819 window.location.reload();
823function waiting_node() {
824 id$('info_div').innerHTML = 'Un instant';
825 id$('info_div').style.display = "block";
829 *show a box while loading
830 *must be remove when ajax is successfull
833function waiting_box() {
835 id: 'wait_box', html: loading() + '<p>' + content[65] + '</p>'
837 if (document.getElementById('wait_box')) {
838 removeDiv('wait_box');
840 var y = fixed_position(10, 250)
841 obj.style = y + ";width:281px;margin-left:40%;z-index:"+get_next_layer();
849 * call add_div to add a DIV and after call the ajax
850 * the queryString, the callback for function for success and error management
851 * the method is always GET
852 *@param obj, the mandatory attributes are
853 * - obj.qs querystring
854 * - obj.js_success callback function in javascript for handling the xml answer
855 * - obj.js_error callback function for error
856 * - obj.callback the php file to call
857 * - obj.fixed optional let you determine the position, otherwise works like IPopup
860function show_box(obj) {
863 id$(obj.id).style.top = calcy(40) + "px";
869 var action = new Ajax.Request(
874 onFailure: eval(obj.js_error),
875 onSuccess: eval(obj.js_success)
880 * receive answer from ajax and just display it into the IBox
881 * XML must contains at least 2 fields : ctl is the ID of the IBOX and
882 * code is the HTML to put in it
885function success_box(req, json) {
887 var answer = req.responseXML;
888 var a = answer.getElementsByTagName('ctl');
889 var html = answer.getElementsByTagName('code');
890 if (a.length === 0) {
891 var rec = req.responseText;
892 alert_box(content[48] + rec);
894 var name_ctl = a[0].firstChild.nodeValue;
895 var code_html = getNodeText(html[0]);
897 code_html = unescape_xml(code_html);
898 id$(name_ctl).innerHTML = code_html;
899 id$(name_ctl).style.height = 'auto';
901 if (name_ctl == 'popup')
902 id$(name_ctl).style.width = 'auto';
904 alert_box("success_box" + e.message);
907 code_html.evalScripts();
909 alert_box(content[53] + "\n" + e.message);
913function error_box() {
914 alert_box(content[53]);
918 * show the ledger choice
920function show_ledger_choice(json_obj) {
924 var query = "gDossier=" + json_obj.dossier + '&type=' + json_obj.type + '&div=' + json_obj.div + '&op=ledger_show';
925 query = query + '&nbjrn=' + id$(json_obj.div + 'nb_jrn').value;
926 query = query + '&all_type=' + json_obj.all_type;
927 for (i = 0; i < id$(json_obj.div + 'nb_jrn').value; i++) {
928 query = query + "&r_jrn[]=" + id$(json_obj.div + 'r_jrn[' + i + ']').value;
930 query = encodeURI(query);
931 var action = new Ajax.Request(
936 onFailure: ajax_misc_failure,
937 onSuccess: function (req, json) {
939 if (req.responseText === 'NOCONX') {
944 id: json_obj.div + 'jrn_search',
945 cssclass: 'inner_box',
946 style: ';position:absolute;width:auto;z-index:'+get_next_layer()+';margin-left:20%',
952 obj.style = "top:" + y + 'px;' + obj.style;
953 /* if ( json_obj.class )
955 obj.cssclass=json_obj.class;
960 var answer = req.responseXML;
961 var a = answer.getElementsByTagName('ctl');
962 var html = answer.getElementsByTagName('code');
963 if (a.length === 0) {
964 var rec = req.responseText;
965 alert_box('erreur :' + rec);
967 var name_ctl = a[0].firstChild.nodeValue;
968 var code_html = getNodeText(html[0]);
970 code_html = unescape_xml(code_html);
971 remove_waiting_box();
972 id$(obj.id).innerHTML = code_html;
975 alert_box("show_ledger_callback" + e.message);
978 code_html.evalScripts();
980 alert_box(content[53] + "\n" + e.message);
988 alert_box('show_ledger_choice' + e.message);
993 * hide the ledger choice
995function hide_ledger_choice(p_frm_search) {
997 var nb = id$(p_frm_search).nb_jrn.value;
999 if (document.getElementById(p_frm_search).div) {
1000 div = id$(p_frm_search).div.value;
1007 for (i = 0; i < nb; i++) {
1008 n_name = div + "r_jrn[" + sel + "]";
1009 name = div + "r_jrn" + i;
1010 if (document.getElementById(name).checked) {
1011 str += '<input type="hidden" id="' + n_name + '" name="' + n_name + '" value="' + id$(name).value + '">';
1015 str += '<input type="hidden" name="' + div + 'nb_jrn" id="' + div + 'nb_jrn" value="' + sel + '">';
1016 id$('ledger_id' + div).innerHTML = str;
1017 removeDiv(div + 'jrn_search');
1020 alert_box('hide_ledger_choice' + e.message);
1027 * show the cat of ledger choice
1029function show_cat_choice() {
1030 id$('div_cat').style.visibility = 'visible';
1034 * hide the cat of ledger choice
1036function hide_cat_choice() {
1037 id$('div_cat').style.visibility = 'hidden';
1041 * add a row for the forecast item
1043function for_add_row(tableid) {
1044 style = 'class="input_text"';
1045 var mytable = id$(tableid).tBodies[0];
1046 var nNumberRow = mytable.rows.length;
1047 var oRow = mytable.insertRow(nNumberRow);
1048 var rowToCopy = mytable.rows[1];
1049 var nNumberCell = rowToCopy.cells.length;
1050 var nb = id$("nbrow");
1051 var oNewRow = mytable.insertRow(nNumberRow);
1052 for (var e = 0; e < nNumberCell; e++) {
1053 var newCell = oRow.insertCell(e);
1054 var tt = rowToCopy.cells[e].innerHTML;
1055 new_tt = tt.replace(/an_cat0/g, "an_cat" + nb.value);
1056 new_tt = new_tt.replace(/an_cat_acc0/g, "an_cat_acc" + nb.value);
1057 new_tt = new_tt.replace(/an_qc0/g, "an_qc" + nb.value);
1058 new_tt = new_tt.replace(/an_label0/g, "an_label" + nb.value);
1059 new_tt = new_tt.replace(/month0/g, "month" + nb.value);
1060 new_tt = new_tt.replace(/an_cat_amount0/g, "an_cat_amount" + nb.value);
1061 new_tt = new_tt.replace(/an_deb0/g, "an_deb" + nb.value);
1062 newCell.innerHTML = new_tt;
1063 new_tt.evalScripts();
1065 id$("an_cat_acc" + nb.value).value = "";
1066 id$("an_qc" + nb.value).value = "";
1067 id$("an_label" + nb.value).value = "";
1068 id$("an_cat_amount" + nb.value).value = "0";
1073 * toggle all the checkbox in a given form
1074 * @param form_id id of the form
1076function toggle_checkbox(form_id) {
1077 var form = id$(form_id);
1078 for (var i = 0; i < form.length; i++) {
1079 var e = form.elements[i];
1080 if (e.type === 'checkbox') {
1081 if (e.checked === true) {
1091 * select all the checkbox in a given form
1092 * @param form_id id of the form
1094function select_checkbox(form_id) {
1095 var form = id$(form_id);
1096 for (var i = 0; i < form.length; i++) {
1097 var e = form.elements[i];
1098 if (e.type === 'checkbox') {
1105 * select all the checkbox in a given form if the specific attribute
1106 * has the given value
1107 * @param form_id id of the form
1108 * @param attribute name
1109 * @param attribute value
1111function select_checkbox_attribute(form_id, p_attribute_name, p_attribute_value) {
1112 var form = id$(form_id);
1113 for (var i = 0; i < form.length; i++) {
1114 var e = form.elements[i];
1115 if (e.type === 'checkbox' && e.getAttribute(p_attribute_name) == p_attribute_value) {
1122 * unselect all the checkbox in a given form
1123 * @param form_id id of the form
1125function unselect_checkbox(form_id) {
1126 var form = id$(form_id);
1127 for (var i = 0; i < form.length; i++) {
1128 var e = form.elements[i];
1129 if (e.type === 'checkbox') {
1136 * show the calculator
1138function show_calc() {
1139 if (document.getElementById('calc1')) {
1140 this.document.getElementById('inp').value = "";
1141 this.document.getElementById('inp').focus();
1142 document.getElementById("calc1").setStyle({ 'z-index':get_next_layer()});
1148 shtml += "<div class=\"bxbutton\">";
1149 shtml += '<a class="icon" onclick="pin(\'calc1\')" id="pin_calc1"></a> <a onclick="removeDiv(\'calc1\');" href="javascript:void(0)" title="" class="icon">⨉</a>';
1151 shtml += ' <h2 class="title">' + content[66] + '</h2>';
1152 shtml += '<form name="calc_line" method="GET" onSubmit="cal();return false;" >' + content[68] + '<input class="input_text" type="text" id="inp" name="calculator"> <input type="button" value="Efface" class="button" onClick="Clean();return false;" > <input type="button" value="Efface historique" class="button" onClick="CleanHistory();return false;" > <input type="button" class="button" value="Fermer" onClick="removeDiv(\'calc1\')" >';
1153 shtml += '</form><span class="highligth" style="display:block" id="sub_total"> ' + content[67] + ' </span><span style="display:block" id="listing"> </span>';
1159 style: 'z-index:'+get_next_layer()
1162 this.document.getElementById('inp').focus();
1165function display_periode(p_dossier, p_id) {
1168 var queryString = "gDossier=" + p_dossier + "&op=input_per" + "&p_id=" + p_id;
1170 'id': 'mod_periode',
1171 'cssclass': 'inner_box',
1173 'style': 'width:30em',
1176 if (!document.getElementById('mod_periode')) {
1179 var action = new Ajax.Request(
1183 parameters: queryString,
1184 onFailure: ajax_misc_failure,
1185 onSuccess: success_display_periode
1188 id$('mod_periode').style.top = (posY - 70) + "px";
1189 id$('mod_periode').style.left = (posX - 70) + "px";
1191 alert_box("display_periode " + e.message);
1196function success_display_periode(req) {
1199 var answer = req.responseXML;
1200 var html = answer.getElementsByTagName('data');
1202 if (html.length === 0) {
1203 var rec = req.responseText;
1204 alert_box('erreur :' + rec);
1207 var code_html = getNodeText(html[0]);
1208 code_html = unescape_xml(code_html);
1210 id$('mod_periode').innerHTML = code_html;
1212 alert_box("success_display_periode".e.message);
1215 code_html.evalScripts();
1217 alert_box(content[53] + "\n" + e.message);
1222function save_periode(obj) {
1224 var queryString = id$(obj).serialize() + "&op=save_per";
1226 var action = new Ajax.Request(
1230 parameters: queryString,
1231 onFailure: ajax_misc_failure,
1232 onSuccess: success_display_periode
1237 alert_box("display_periode " + e.message);
1244 * basic answer to ajax on success, it will fill the ctl with
1245 * the code. In that case, you need to create the object before the Ajax.Request
1246 *The difference with success box is that
1247 *@see add_div removeDiv success_box is that the width and height are not changed
1248 *@param ctl is the ID of the object containing the html (div, button...)
1249 *@param code is the html code, with it you fill the ctl element
1251function fill_box(req) {
1253 if (req.responseText == 'NOCONX') {
1257 remove_waiting_box();
1259 var answer = req.responseXML;
1260 var a = answer.getElementsByTagName('ctl');
1261 var html = answer.getElementsByTagName('code');
1262 if (a.length === 0) {
1263 var rec = req.responseText;
1264 alert_box('erreur :' + rec);
1266 var name_ctl = a[0].firstChild.nodeValue;
1267 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
1268 code_html = unescape_xml(code_html);
1269 id$(name_ctl).innerHTML = code_html;
1271 alert_box(e.message);
1274 console.error("log answer = " + req.responseText);
1278 code_html.evalScripts();
1282 console.error("log answer = " + req.responseText);
1284 alert_box(content[53] + "\n" + e.message);
1291 *display a popin to let you modified a predefined operation
1293 *@param od_id from table op_predef
1295function mod_predf_op(dossier_id, od_id, p_ledger) {
1296 var target = "mod_predf_op";
1298 var str_style = "top:10%;left:2%;width:96%";
1300 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1304 var qs = "gDossier=" + dossier_id + '&op=mod_predf&id=' + od_id + '&ledger_id=' + p_ledger;
1306 var action = new Ajax.Request('ajax_misc.php',
1317function save_predf_op(obj) {
1319 var querystring = id$(obj).serialize() + '&op=save_predf';
1320 // Create a ajax request to get all the person
1321 var action = new Ajax.Request('ajax_misc.php',
1324 parameters: querystring,
1326 onSuccess: refresh_window
1334 *ctl_concern is the widget to update
1335 *amount_id is either a html obj. or an amount and the field tiers if given
1336 * @param {int} dossier
1337 * @param {string} ctl_concern DOM id that receive the number
1338 * @param {float or string} amount_id Amount or DOM Id of the element containing the amount
1339 * @param {float} ledger
1340 * @param {type} p_id_targetDom Element (div) where to display the search result
1341 * @param p_tiers id of the Tiers
1342 * @returns {undefined}
1344function search_reconcile(dossier, ctl_concern, amount_id, ledger, p_id_target, p_tiers) {
1345 if (amount_id === undefined) {
1347 } else if (document.getElementById(amount_id)) {
1348 if (id$(amount_id).value) {
1349 amount_id = id$(amount_id).value;
1351 (id$(amount_id).innerHTML) {
1352 amount_id = id$(amount_id).innerHTML;
1359 if (p_id_target != "") {
1360 target = p_id_target;
1362 target = "search" + layer;
1365 var str_style = fixed_position(77, 99);
1366 str_style += ";width:92%;overflow:auto;z-index:"+get_next_layer();
1368 var hide_operation = id$(ctl_concern).getAttribute("hide_operation");
1369 var single_operation = id$(ctl_concern).getAttribute("single_operation");
1376 amount_id: amount_id,
1380 hide_operation: hide_operation,
1381 single_operation: single_operation
1384 var qs = encodeJSON(param_send);
1386 var action = new Ajax.Request('ajax_misc.php',
1391 onSuccess: function (req) {
1392 remove_waiting_box();
1393 var div = {id: target, cssclass: 'inner_box', style: str_style, drag: 0};
1395 id$(target).innerHTML = req.responseText;
1396 req.responseText.evalScripts();
1403 * search in a popin obj if the object form,
1404 * @param obj DOM of the FORM
1406function search_operation(obj) {
1408 var dossier = id$('gDossier').value;
1410 var target = "search" + layer;
1411 if (obj["target"]) {
1412 target = obj["target"].value;
1414 var qs = Form.serialize('search_form_ajx') + "&op=search_op";
1415 var action = new Ajax.Request('ajax_misc.php',
1420 onSuccess: function (req) {
1421 remove_waiting_box();
1422 id$(target).innerHTML = req.responseText;
1423 id$(target).setStyle({ 'z-index':get_next_layer()});
1424 req.responseText.evalScripts();
1429 remove_waiting_box();
1430 alert_box(e.message);
1435 * Update the field e_concerned, from class_iconcerned
1436 * Value is the field where to put the quick-code but only if one checkbox has been
1438 * @param {DOM Element} obj : DOM FORM ,
1439 * - element : ctlc : will contain the JRN.JR_ID ,
1440 * - tiers : the name of the counterparty
1441 * - target : DGBOX displaying the search result
1443 * @returns {undefined}
1445function set_reconcile(obj) {
1448 var ctlc = obj.elements['ctlc'];
1449 var tiers = obj.elements['tiers'];
1450 if (!obj.elements['target'])
1452 var target = obj.elements['target'].value;
1453 var single_operation = obj.elements['single_operation'].value;
1454 for (var e = 0; e < obj.elements.length; e++) {
1456 var elmt = obj.elements[e];
1457 if (elmt.type === "checkbox") {
1458 if (elmt.checked === true) {
1459 var str_name = elmt.name;
1460 var nValue = str_name.replace("jr_concerned", "");
1461 if (id$(ctlc.value).value != '') {
1462 id$(ctlc.value).value += ',';
1466 if (tiers && tiers.value != "") {
1467 id$(tiers.value).value = elmt.value;
1469 new Ajax.Request("fid.php", {
1471 parameters: {gDossier: obj.elements['gDossier'].value, "FID": elmt.value},
1472 onSuccess: function (req) {
1473 // find the row number
1474 //tiers.value = e_othern
1475 var tiers_card = new String(tiers.value);
1476 var num = tiers_card.replace("e_other", "");
1477 var tiers_name_id = "e_other" + "_name" + num;
1478 var answer = req.responseText.evalJSON();
1479 id$(tiers_name_id).value = answer["name"];
1484 if (single_operation == 0) {
1485 id$(ctlc.value).value += nValue;
1487 id$(ctlc.value).value = nValue;
1493 removeDiv(obj.elements['target'].value);
1495 alert_box(e.message)
1499function remove_waiting_node() {
1500 id$('info_div').innerHTML = "";
1501 id$('info_div').style.display = "none";
1505function remove_waiting_box() {
1506 if (document.getElementById('wait_box')) {
1507 Effect.Fade('wait_box', {duration: 0.6});
1510 remove_waiting_node();
1514 * Show all the detail of a profile : Menu, Management, Repository and
1515 * let the user to modify it
1516 * @param {type} gDossier
1517 * @param {type} profile_id
1518 * @returns {undefined}
1520function get_profile_detail(gDossier, profile_id) {
1522 var qs = "op=display_profile&gDossier=" + gDossier + "&p_id=" + profile_id + "&ctl=detail_profile";
1523 var action = new Ajax.Request('ajax_misc.php',
1528 onSuccess: function (req) {
1529 remove_waiting_box();
1530 id$('list_profile').hide();
1531 id$('detail_profile').innerHTML = req.responseText;
1532 req.responseText.evalScripts();
1533 id$('detail_profile').show();
1534 if (profile_id != "-1")
1535 profile_show('profile_gen_div');
1541function get_profile_detail_success_obsolete(xml) {
1542 remove_waiting_box();
1547 * compute the string to position a div in a fixed way
1550function fixed_position(p_sx, p_sy) {
1552 var sy = calcy(p_sy);
1554 var str_style = "top:" + sy + "px;left:" + sx + "px;position:absolute";
1560 * compute Y even if the windows has scrolled down or up
1561 *@return the correct Y position
1563function calcy(p_sy) {
1565 if (window.pageYOffset) {
1566 sy = window.pageYOffset + p_sy;
1568 sy = document.documentElement.scrollTop + p_sy;
1576 * display a box with the menu option
1577 * @param {type} gdossier
1578 * @param {type} pm_id
1579 * @returns {undefined}
1581function mod_menu(gdossier, pm_id) {
1583 removeDiv('divdm' + pm_id);
1584 var qs = "op=det_menu&gDossier=" + gdossier + "&pm_id=" + pm_id + "&ctl=divdm" + pm_id;
1585 var pos = fixed_position(50, 250);
1586 var action = new Ajax.Request('ajax_misc.php',
1591 onSuccess: function (req) {
1593 remove_waiting_box();
1594 add_div({id: "divdm" + pm_id, drag: 1, cssclass: "inner_box", style: pos});
1595 id$('divdm' + pm_id).innerHTML = req.responseText;
1597 alert_box(e.message);
1605 * Display the submenu of a menu or a module, used in setting the menu
1607 * @param {type} p_dossier
1608 * @param {type} p_profile
1609 * @param {type} p_dep
1610 * @returns {undefined}
1612function display_sub_menu(p_dossier, p_profile, p_dep, p_level) {
1614 new Ajax.Request('ajax_misc.php',
1618 op: 'display_submenu',
1619 gDossier: p_dossier,
1621 p_profile: p_profile,
1624 onSuccess: function (req) {
1626 remove_waiting_box();
1627 if (id$('menu_table').rows.length > p_level) {
1628 id$('menu_table').rows[1].remove();
1630 id$('sub' + p_dep).addClassName("selectedmenu");
1631 var new_row = document.createElement('TR');
1632 new_row.innerHTML = req.responseText;
1633 id$('menu_table').appendChild(new_row);
1635 alert_box(e.message);
1642 * in C0PROFL, ask to confirm before removing a submenu and its children
1643 * @param {type} p_dossier
1644 * @param {type} profile_menu_id
1645 * @returns {undefined}
1647function remove_sub_menu(p_dossier, profile_menu_id) {
1648 confirm_box(null, content[47],
1651 new Ajax.Request('ajax_misc.php',
1655 op: 'remove_submenu', gDossier: p_dossier,
1656 p_profile_menu_id: profile_menu_id
1658 onSuccess: function (req) {
1660 remove_waiting_box();
1661 id$('sub' + profile_menu_id).remove();
1662 if (id$('menu_table').rows.length > 1) {
1663 id$('menu_table').rows[1].remove();
1667 alert_box(e.message);
1677 * add a menu to a profile, propose only the available menu
1678 * @param obj json object
1680 * - p_id : profile id ,
1681 * - type : Type of menu are "pr" for Printing "me" for plain menu
1682 * - p_level : level of menu (0 -> module,1-> top menu, 2->submenu)
1683 * - dep : the parent menu id (pm_id)
1686function add_menu(obj) {
1687 var pdossier = obj.dossier;
1688 var p_id = obj.p_id;
1689 var p_type = obj.type;
1692 removeDiv('divdm' + p_id);
1693 var pos = fixed_position(250, 150) + ";width:50%;";
1694 var action = new Ajax.Request('ajax_misc.php',
1699 'gDossier': pdossier,
1701 'ctl': 'divdm' + p_id,
1704 'p_level': obj.p_level
1707 onSuccess: function (req) {
1709 remove_waiting_box();
1710 add_div({id: "divdm" + p_id, drag: 1, "cssclass": "inner_box", "style": pos});
1711 id$('divdm' + p_id).innerHTML = req.responseText;
1713 alert_box(e.message);
1721 * Display a box to enter data for adding a new plugin from
1723 * @param {type} p_dossier
1724 * @returns {undefined}
1726function add_plugin(p_dossier) {
1728 removeDiv('divplugin');
1729 var qs = "op=add_plugin&gDossier=" + p_dossier + "&ctl=divplugin";
1731 var action = new Ajax.Request('ajax_misc.php',
1736 onSuccess: function (req) {
1738 remove_waiting_box();
1739 var pos = fixed_position(250, 150) + ";width:30%";
1740 add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1741 id$('divplugin').innerHTML = req.responseText;
1743 alert_box(e.message);
1752 * @param {type} p_dossier
1753 * @param {type} me_code
1754 * @returns {undefined}
1756function mod_plugin(p_dossier, me_code) {
1758 removeDiv('divplugin');
1759 var qs = "op=mod_plugin&gDossier=" + p_dossier + "&ctl=divplugin&me_code=" + me_code;
1761 var action = new Ajax.Request('ajax_misc.php',
1766 onSuccess: function (req) {
1768 remove_waiting_box();
1769 var pos = fixed_position(250, 150) + ";width:30%";
1770 add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1771 id$('divplugin').innerHTML = req.responseText;
1774 alert_box(e.message);
1781function create_menu(p_dossier) {
1783 removeDiv('divmenu');
1784 var qs = "op=create_menu&gDossier=" + p_dossier + "&ctl=divmenu";
1786 var action = new Ajax.Request('ajax_misc.php',
1791 onSuccess: function (req) {
1793 remove_waiting_box();
1794 var pos = fixed_position(250, 150) + ";width:30%";
1798 cssclass: "inner_box",
1801 id$('divmenu').innerHTML = req.responseText;
1803 alert_box(e.message);
1810function modify_menu(p_dossier, me_code) {
1812 removeDiv('divmenu');
1813 var qs = "op=modify_menu&gDossier=" + p_dossier + "&ctl=divmenu&me_code=" + me_code;
1815 var action = new Ajax.Request('ajax_misc.php',
1820 onSuccess: function (req) {
1822 remove_waiting_box();
1823 var pos = fixed_position(250, 150) + ";width:30%";
1827 cssclass: "inner_box",
1830 id$('divmenu').innerHTML = req.responseText;
1833 alert_box(e.message);
1840function get_properties(obj) {
1842 var s_type = "[" + typeof obj + "]";
1843 for (var m in obj) {
1846 alert_box(s_type + a_array.join(","));
1850 * add a line in the form for the report
1851 * @param p_dossier dossier id to connect
1853function rapport_add_row(p_dossier) {
1854 style = 'style="border: 1px solid blue;"';
1855 var table = id$("rap1");
1856 var line = table.rows.length;
1858 var row = table.insertRow(line);
1860 var cellPos = row.insertCell(0);
1861 cellPos.innerHTML = '<input type="text" ' + style + ' size="3" id="pos' + line + '" name="pos' + line + '" value="' + line + '">';
1864 var cellName = row.insertCell(1);
1865 cellName.innerHTML = '<input type="text" ' + style + ' size="40" id="text' + line + '" name="text' + line + '">';
1868 var cellbutton = row.insertCell(2);
1869 var but_html = table.rows[1].cells[2].innerHTML;
1870 but_html = but_html.replace(/form0/g, "form" + line);
1871 cellbutton.innerHTML = but_html;
1872 but_html.evalScripts();
1874 id$('form' + line).value = '';
1878 * Search an action in an inner box
1880function search_action(dossier, ctl_concern) {
1883 var dossier = id$('gDossier').value;
1885 var target = "search_action_div";
1887 var str_style = fixed_position(77, 99)+";z-index:"+get_next_layer();
1889 var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1895 op: 'search_action',
1899 var qs = encodeJSON(target);
1901 var action = new Ajax.Request('ajax_misc.php',
1906 onSuccess: function (req) {
1908 remove_waiting_box();
1910 id$('search_action_div').innerHTML = req.responseText;
1911 req.responseText.evalScripts();
1913 alert_box(e.message);
1919 alert_box(e.message);
1923function result_search_action(obj) {
1925 var queryString = id$(obj).serialize() + "&op=search_action";
1926 var action = new Ajax.Request(
1930 parameters: queryString,
1931 onFailure: ajax_misc_failure,
1932 onSuccess: function (req) {
1934 remove_waiting_box();
1935 id$('search_action_div').innerHTML = req.responseText;
1936 req.responseText.evalScripts();
1938 alert_box(e.message);
1945 alert_box("display_periode " + e.message);
1951function set_action_related(p_obj) {
1954 var obj = id$(p_obj);
1955 var ctlc = obj.elements['ctlc'];
1957 for (var e = 0; e < obj.elements.length; e++) {
1959 var elmt = obj.elements[e];
1960 if (elmt.type === "checkbox") {
1961 if (elmt.checked === true) {
1962 var str_name = elmt.name;
1963 var nValue = elmt.value;
1964 if (id$(ctlc.value).value != '') {
1965 id$(ctlc.value).value += ',';
1967 id$(ctlc.value).value += nValue;
1971 removeDiv('search_action_div');
1974 alert_box(e.message);
1980 * Show a form to modify or add a new repository
1982 *@param r_id : repository id
1984function stock_repo_change(p_dossier, r_id) {
1985 var queryString = "gDossier=" + p_dossier + "&op=mod_stock_repo" + "&r_id=" + r_id;
1986 var nTop = calcy(posY);
1987 var nLeft = "10.1562%";
1988 var str_style = "top:" + nTop + "px;left:" + nLeft + ";height:auto;width:auto";
1990 removeDiv('change_stock_repo_div');
1992 var action = new Ajax.Request(
1995 method: 'get', parameters: queryString,
1996 onFailure: ajax_misc_failure,
1997 onSuccess: function (req) {
1998 remove_waiting_box();
1999 add_div({id: 'change_stock_repo_div', style: str_style, cssclass: 'inner_box', drag: "1"});
2000 id$('change_stock_repo_div').innerHTML = req.responseText;
2007function stock_inv_detail(p_dossier, p_id) {
2008 var queryString = "gDossier=" + p_dossier + "&op=view_mod_stock" + "&c_id=" + p_id + "&ctl=view_mod_stock_div";
2009 var nTop = calcy(posY);
2011 var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:80%;";
2013 removeDiv('view_mod_stock_div');
2015 var action = new Ajax.Request(
2018 method: 'get', parameters: queryString,
2019 onFailure: ajax_misc_failure,
2020 onSuccess: function (req) {
2021 remove_waiting_box();
2022 add_div({id: 'view_mod_stock_div', style: str_style, cssclass: 'inner_box', drag: "1"});
2023 id$('view_mod_stock_div').innerHTML = req.responseText;
2024 req.responseText.evalScripts();
2030function show_fin_chdate(obj_id) {
2032 var ch = id$(obj_id).options[id$(obj_id).selectedIndex].value;
2034 id$('chdate_ext').hide();
2035 id$('thdate').show();
2038 id$('chdate_ext').show();
2039 id$('thdate').hide();
2041 var nb = id$('nb_item').value;
2042 for (i = 0; i < nb; i++) {
2043 if (document.getElementById('tdchdate' + i)) {
2045 id$('tdchdate' + i).show();
2048 id$('tdchdate' + i).hide();
2054 alert_box(e.message);
2059 * tab menu for the profile parameter
2061function profile_show(p_div) {
2063 var div = ['profile_gen_div', 'profile_menu_div', 'profile_print_div', 'profile_gestion_div', 'profile_repo_div', 'profile_menu_mobile_div'];
2064 for (var r = 0; r < div.length; r++) {
2069 alert_box(e.message);
2073function detail_category_show(p_div, p_dossier, p_id) {
2076 id$('detail_category_div').innerHTML = "";
2077 var queryString = "gDossier=" + p_dossier + "&id=" + p_id + "&op=fddetail";
2078 var action = new Ajax.Request(
2081 method: 'get', parameters: queryString,
2082 onFailure: ajax_misc_failure,
2083 onSuccess: function (req) {
2084 remove_waiting_box();
2085 id$('list_cat_div').hide();
2086 id$('detail_category_div').innerHTML = req.responseText;
2087 id$('detail_category_div').show();
2088 req.responseText.evalScripts();
2095 * check that the form is correct for a new category of card
2097function check_new_category()
2099 if ( id$('nom_mod_id').value.trim()=="") {
2100 new Effect.Highlight('nom_mod_id',{startcolor:"#ff0000"});
2101 smoke.alert('Nom catégorie obligatoire');
2104 var TemplateCard= document.getElementsByName('FICHE_REF');
2105 for (i = 0;i< TemplateCard.length;i++) {
2106 if (TemplateCard[i].checked) return true;
2108 new Effect.Highlight('template_category_ck',{startcolor:"#ff0000"});
2109 smoke.alert('Choisissez une catégorie');
2113 * check if the parameter is a valid a valid date or not, returns true if it is valid otherwise
2115 * @param p_str_date the string of the date (format DD.MM.YYYY)
2117function check_date(p_str_date) {
2118 var format = /^\d{2}\.\d{2}\.\d{4}$/;
2119 if (!format.test(p_str_date)) {
2122 var date_temp = p_str_date.split('.');
2123 var nMonth = parseFloat(date_temp[1]) - 1;
2124 var ma_date = new Date(date_temp[2], nMonth, date_temp[0]);
2125 if (ma_date.getFullYear() == date_temp[2] && ma_date.getMonth() == nMonth && ma_date.getDate() == date_temp[0]) {
2135 * get the string in the id and check if the date is valid
2136 * @param p_id_date is the id of the element to check
2137 * @return true if the date is valid
2140function check_date_id(p_id_date) {
2141 var str_date = id$(p_id_date).value;
2142 return check_date(str_date);
2147 * @param ag_id to view
2148 * @param dossier is the folder
2149 * @param modify : show the modify button values : 0 for no 1 for yes
2151function view_action(ag_id, dossier, modify) {
2153 var layer=get_next_layer();
2154 id = 'action' + layer;
2156 querystring = 'gDossier=' + dossier + '&op=vw_action&ag_id=' + ag_id + '&div=' + id + '&mod=' + modify;
2157 var action = new Ajax.Request(
2161 parameters: querystring,
2162 onFailure: error_box,
2163 onSuccess: function (req) {
2165 if (req.responseText === 'NOCONX') {
2169 remove_waiting_box();
2170 var answer = req.responseXML;
2171 var ctl = answer.getElementsByTagName('ctl');
2172 if (ctl.length == 0) {
2173 throw 'ajax failed ctl view_action';
2175 var ctl_txt = getNodeText(ctl[0]);
2176 var html = answer.getElementsByTagName('code');
2177 if (html.length === 0) {
2178 var rec = req.responseText;
2179 throw 'ajax failed html view_action';
2181 var code_html = getNodeText(html[0]);
2182 code_html = unescape_xml(code_html);
2183 var pos = fixed_position(0, 50) + ";width:90%;left:5%;z-index:"+layer+";";
2186 cssclass: "inner_box",
2189 id$(id).innerHTML = code_html;
2190 if (ctl_txt == 'ok') {
2192 var detail = in_child(id, "follow_up_detail");
2194 compute_all_ledger();
2199 code_html.evalScripts();
2201 alert_box('view_action' + e.message);
2209 * filter quickly a table
2210 * @param phrase : phrase to seach
2211 * @param _id : id of the table
2212 * @param colnr : string containing the column number where you're searching separated by a comma
2213 * @param start_row : first row (1 if you have table header)
2214 * @param class 2nd filter on the CSS CLASS of the row (TR), domid of the TAG containing the classname (TagName: SELECT, HIDDEN, TEXT )
2216 * @see HtmlInput::filter_table
2218function filter_table(phrase, _id, colnr, start_row,classname) {
2219 id$('info_div').innerHTML = content[65];
2220 id$('info_div').style.display = "block";
2221 var words = id$(phrase).value.toLowerCase();
2222 var table = document.getElementById(_id);
2224 // if colnr contains a comma then check several columns
2225 var aCol = new Array();
2226 if (colnr.indexOf(',') >= 0) {
2227 aCol = colnr.split(',');
2234 if ( classname ) row_class=id$(classname).value;
2236 for (var r = start_row; r < table.rows.length; r++)
2238 if ( row_class != "" && ! table.rows[r].hasClassName(row_class)) {
2242 for (var col = 0; col < aCol.length; col++) {
2243 var idx = aCol[col];
2244 if (table.rows[r].cells[idx]) {
2245 ele = table.rows[r].cells[idx].innerHTML.replace(/<[^>]+>/g, "");
2246 //var displayStyle = 'none';
2247 if (ele.toLowerCase().indexOf(words) >= 0) {
2255 table.rows[r].style.display = '';
2257 table.rows[r].style.display = 'none';
2259 id$('info_div').style.display = "none";
2260 id$('info_div').innerHTML = "";
2262 if (tot_found == 0) {
2263 if (document.getElementById('info_' + _id)) {
2264 id$('info_' + _id).innerHTML = content[69];
2265 id$('info_' + _id).style.display = 'inline-block';
2268 if (document.getElementById('info_' + _id)) {
2269 id$('info_' + _id).innerHTML = " ";
2270 id$('info_' + _id).style.display = 'none';
2273 id$('info_div').style.display = "none";
2274 id$('info_div').innerHTML = "";
2278 * filter quickly a list, the content to check must be inside a SPAN with the CLASS "search-content"
2279 * @param phrase : DOM id of the input text where we find the word to seach, the searchable content use the className searchContent
2280 * @param _id : id of the list
2282 * @see HtmlInput::filter_list
2284function filter_list(phrase, _id) {
2285 id$('info_div').innerHTML = content[65];
2286 id$('info_div').style.display = "block";
2287 var words = id$(phrase).value.toLowerCase();
2288 var l_list = document.getElementById(_id);
2293 for (var r = 0; r < l_list.childNodes.length; r++) {
2296 if (l_list.childNodes[r].nodeType != 1) {
2300 let la_content = l_list.childNodes[r].getElementsByClassName("search-content");
2303 for (e = 0; e < la_content.length; e++) {
2304 ele += la_content[e].innerText;
2308 if (ele.toLowerCase().indexOf(words) >= 0) {
2310 l_list.childNodes[r].style.display = 'block';
2312 l_list.childNodes[r].style.display = 'none';
2316 if (tot_found == 0) {
2317 if (document.getElementById('info_' + _id)) {
2318 id$('info_' + _id).innerHTML = content[69];
2321 if (document.getElementById('info_' + _id)) {
2322 id$('info_' + _id).innerHTML = " ";
2325 id$('info_div').style.display = "none";
2326 id$('info_div').innerHTML = "";
2330 * filter quickly a select
2331 * @param phrase : DOM id of the input text where we find the word to seach
2332 * @param _id : id of the list
2334 * @see HtmlInput::filter_list
2336function filter_multiselect(phrase, _id) {
2337 id$('info_div').innerHTML = content[65];
2338 id$('info_div').style.display = "block";
2339 var words = id$(phrase).value.toLowerCase();
2340 var l_list = document.getElementById(_id);
2344 for (var r = 0; r < l_list.options.length; r++) {
2346 var ele = l_list.options[r].text;
2348 if (ele.toLowerCase().indexOf(words) >= 0) {
2350 l_list.options[r].style.display = 'block';
2352 l_list.options[r].style.display = 'none';
2354 id$('info_div').style.display = "none";
2355 id$('info_div').innerHTML = "";
2357 if (tot_found == 0) {
2358 if (document.getElementById('info_' + _id)) {
2359 id$('info_' + _id).innerHTML = content[69];
2362 if (document.getElementById('info_' + _id)) {
2363 id$('info_' + _id).innerHTML = " ";
2370 * Display the task late or for today in dashboard
2372function display_task(p_id) {
2374 id$(p_id).style.top = posY + 'px';
2375 id$(p_id).style.left = "10%";
2376 id$(p_id).style.width = "80%";
2377 id$(p_id).style.display = 'block';
2383 * Set a message in the info
2385function info_message(p_message) {
2386 id$('info_div').innerHTML = p_message;
2387 id$('info_div').style.display = "block";
2393function info_hide() {
2394 id$('info_div').style.display = "none";
2398 * Show the navigator in a internal window
2399 * @returns {undefined}
2401function ask_navigator(p_dossier) {
2404 removeDiv('navi_div')
2405 var queryString = "gDossier=" + p_dossier + "&op=navigator";
2406 var action = new Ajax.Request(
2409 method: 'get', parameters: queryString,
2410 onFailure: ajax_misc_failure,
2411 onSuccess: function (req) {
2412 remove_waiting_box();
2413 add_div({id: 'navi_div', style: 'top:2em;z-index:'+get_next_layer(), cssclass: 'inner_box'});
2414 id$('navi_div').innerHTML = req.responseText;
2416 req.responseText.evalScripts();
2417 sorttable.makeSortable(id$("navi_tb"));
2419 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2426 info_message(e.message);
2432 * Display an internal windows to set the user's preference
2435function set_preference(p_dossier) {
2438 removeDiv('preference_div')
2439 var queryString = "gDossier=" + p_dossier + "&op=preference";
2440 var action = new Ajax.Request(
2443 method: 'get', parameters: queryString,
2444 onFailure: ajax_misc_failure,
2445 onSuccess: function (req) {
2446 remove_waiting_box();
2447 if (req.responseText === 'NOCONX') {
2451 add_div({id: 'preference_div', style: 'z-index:'+get_next_layer(), drag: 1});
2452 id$('preference_div').innerHTML = req.responseText;
2454 req.responseText.evalScripts();
2456 alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2463 info_message(e.message);
2467////////////////////////////////////////////////////////
2472////////////////////////////////////////////////////////
2473var Bookmark = function() {
2477 * Display user's bookmark
2478 * @param p_dossier {int} Dossier id
2480 Bookmark.prototype.show = function (p_dossier) {
2483 removeDiv('bookmark_div');
2484 var param = window.location.search;
2485 param = param.gsub('?', '');
2486 var queryString = "gDossier=" + p_dossier + "&op=bookmark&" + param;
2487 var action = new Ajax.Request(
2490 method: 'get', parameters: queryString,
2491 onFailure: ajax_misc_failure,
2492 onSuccess: function (req) {
2493 remove_waiting_box();
2494 add_div({id: 'bookmark_div', cssclass: 'inner_box',style: 'z-index:'+get_next_layer(), drag: 1});
2495 id$('bookmark_div').innerHTML = req.responseText;
2497 req.responseText.evalScripts();
2499 alert_box(content[53] + "\n" + e.message);
2501 id$('lk_bookmark_tb').focus();
2507 info_message(e.message);
2514Bookmark.prototype.save = function () {
2517 var queryString = "op=bookmark&" + id$("bookmark_frm").serialize();
2518 var action = new Ajax.Request(
2521 method: 'get', parameters: queryString,
2522 onFailure: ajax_misc_failure,
2523 onSuccess: function (req) {
2524 remove_waiting_box();
2525 // removeDiv('bookmark_div');
2527 id$('bookmark_div').innerHTML = req.responseText;
2529 req.responseText.evalScripts();
2531 alert_box(content[53] + "\n" + e.message);
2538 info_message(e.message);
2544 * remove selected bookmark
2546Bookmark.prototype.remove= function () {
2549 var queryString = "op=bookmark&" + id$("bookmark_del_frm").serialize();
2550 var action = new Ajax.Request(
2553 method: 'get', parameters: queryString,
2554 onFailure: ajax_misc_failure,
2555 onSuccess: function (req) {
2556 remove_waiting_box();
2557 id$('bookmark_div').innerHTML = req.responseText;
2559 req.responseText.evalScripts();
2561 alert_box(content[53] + "\n" + e.message);
2568 error_message(e.message);
2574 * display the error message into the div error_content_div (included into error_div)
2575 *@param message message to display
2576 *@note there is no protection
2578function error_message(message) {
2579 id$('error_content_div').innerHTML = message;
2580 id$('error_div').style.visibility = 'visible';
2584 * show the detail of a tag and propose to save it
2586function show_tag(p_dossier, p_ac, p_tag_id, p_post) {
2589 var queryString = "op=tag_detail&tag=" + p_tag_id + "&gDossier=" + p_dossier + "&ac=" + p_ac + '&form=' + p_post;
2590 var action = new Ajax.Request(
2593 method: 'get', parameters: queryString,
2594 onFailure: ajax_misc_failure,
2595 onSuccess: function (req) {
2596 var answer = req.responseXML;
2597 var html = answer.getElementsByTagName('code');
2598 if (html.length === 0) {
2599 var rec = req.responseText;
2600 alert_box('erreur :' + rec);
2602 var code_html = getNodeText(html[0]);
2603 code_html = unescape_xml(code_html);
2604 remove_waiting_box();
2605 var posy = calcy(250);
2606 add_div({id: 'tag_div', cssclass: 'inner_box', drag: 0, style: "position:fixed;top:15%;"});
2607 id$('tag_div').innerHTML = code_html;
2609 code_html.evalScripts();
2611 alert_box(content[53] + "\n" + e.message);
2618 error_message(e.message);
2623 * save the modified tag
2625function save_tag() {
2628 var queryString = "op=tag_save&" + id$("tag_detail_frm").serialize();
2629 var action = new Ajax.Request(
2633 parameters: queryString,
2634 onFailure: ajax_misc_failure,
2635 onSuccess: function (req, j) {
2636 remove_waiting_box();
2637 removeDiv('tag_div');
2642 error_message(e.message);
2650 * Show a list of tag which can be added to the current followup document
2651 * @param {type} p_dossier
2652 * @param {type} ag_id
2653 * @returns {undefined}
2655function action_tag_select(p_dossier, ag_id) {
2658 var queryString = "ag_id=" + ag_id + "&op=tag_list&gDossier=" + p_dossier;
2659 var action = new Ajax.Request(
2662 method: 'get', parameters: queryString,
2663 onFailure: ajax_misc_failure,
2664 onSuccess: function (req, j) {
2665 var answer = req.responseXML;
2666 var html = answer.getElementsByTagName('code');
2667 if (html.length === 0) {
2668 var rec = unescape_xml(req.responseText);
2669 error_message('erreur :' + rec);
2671 var code_html = getNodeText(html[0]);
2672 code_html = unescape_xml(code_html);
2673 var pos = fixed_position(35, 229);
2674 add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
2676 remove_waiting_box();
2677 id$('tag_div').innerHTML = code_html;
2682 error_message(e.message);
2687 * Add the current tag to the current ag_id
2688 * @param {type} p_dossier
2689 * @param {type} ag_id
2690 * @param p_isgroup g it is a group , t is a single tag
2691 * @returns {undefined}
2693function action_tag_add(p_dossier, ag_id, t_id, p_isgroup) {
2696 var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_add&gDossier=" + p_dossier + "&isgroup=" + p_isgroup;
2697 var action = new Ajax.Request(
2700 method: 'get', parameters: queryString,
2701 onFailure: ajax_misc_failure,
2702 onSuccess: function (req, j) {
2703 var answer = req.responseXML;
2704 var html = answer.getElementsByTagName('code');
2705 if (html.length === 0) {
2706 var rec = unescape_xml(req.responseText);
2707 error_message('erreur :' + rec);
2709 var code_html = getNodeText(html[0]);
2710 code_html = unescape_xml(code_html);
2711 remove_waiting_box();
2712 id$('action_tag_td').innerHTML = code_html;
2713 removeDiv('tag_div');
2718 error_message(e.message);
2723 * remove the current tag to the current ag_id
2724 * @param {type} p_dossier
2725 * @param {type} ag_id
2726 * @returns {undefined}
2728function action_tag_remove(p_dossier, ag_id, t_id) {
2729 confirm_box(null, content[50], function () {
2732 var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_remove&gDossier=" + p_dossier;
2733 var action = new Ajax.Request(
2736 method: 'get', parameters: queryString,
2737 onFailure: ajax_misc_failure,
2738 onSuccess: function (req) {
2739 var answer = req.responseXML;
2740 var html = answer.getElementsByTagName('code');
2741 if (html.length === 0) {
2742 var rec = unescape_xml(req.responseText);
2743 error_message('erreur :' + rec);
2745 var code_html = getNodeText(html[0]);
2746 code_html = unescape_xml(code_html);
2747 remove_waiting_box();
2748 id$('action_tag_td').innerHTML = code_html;
2754 error_message(e.message);
2761 * @param int p_dossier
2762 * @param int p_tag_id
2764function activate_tag(p_dossier, p_tag_id) {
2766 new Ajax.Request("ajax_misc.php",
2769 parameters: {gDossier: p_dossier, op: 'tag_activate', t_id: p_tag_id},
2770 onSuccess: function (req) {
2771 remove_waiting_box();
2772 var answer = req.responseText.evalJSON();
2773 var tagId = "tag_onoff" + p_tag_id;
2774 id$(tagId).update(answer.code);
2775 id$(tagId).setStyle(answer.style);
2776 remove_waiting_box();
2782 * Display a div with available tags, this div can update the cell
2784 * @param {type} p_dossier
2785 * @param {string} p_prefix is the prefix of the div
2786 * @param {string} Calling object either Tag_Operation or Tag_Action
2787 * @returns {undefined}
2790function search_display_tag(p_dossier, p_prefix, p_object) {
2793 var queryString = {op: "search_display_tag", gDossier: p_dossier, pref: p_prefix, caller_obj: p_object};
2794 var action = new Ajax.Request(
2797 method: 'get', parameters: queryString,
2798 onFailure: ajax_misc_failure,
2799 onSuccess: function (req, j) {
2800 var answer = req.responseXML;
2801 var html = answer.getElementsByTagName('code');
2802 if (html.length === 0) {
2803 var rec = unescape_xml(req.responseText);
2804 error_message('erreur :' + rec);
2806 var code_html = getNodeText(html[0]);
2807 code_html = unescape_xml(code_html);
2808 remove_waiting_box();
2809 add_div({id: p_prefix + 'tag_div', style: 'left:10%;width:70%', cssclass: 'inner_box', drag: 1});
2810 id$(p_prefix + 'tag_div').style.top = calcy(200) + "px"
2811 id$(p_prefix + 'tag_div').style.left = 20 + "%";
2812 remove_waiting_box();
2813 id$(p_prefix + 'tag_div').innerHTML = code_html;
2814 code_html.evalScripts();
2819 error_message(e.message);
2824 * Add the selected tag (p_tag_id) to the cell of tag_choose_td in the search screen
2825 * in the search screen
2826 * @param {type} p_dossier
2827 * @param {type} p_tag_id
2828 * @param p_prefix is the prefix of the widget
2829 * @param p_obj is either g for group of tag or t for a single tag
2831function search_add_tag(p_dossier, p_tag_id, p_prefix, p_obj) {
2833 var clear_button = 0;
2834 if (tag_choose === '' && p_prefix === 'search') {
2835 tag_choose = id$(p_prefix + 'tag_choose_td').innerHTML;
2839 var queryString = "op=search_add_tag&gDossier=" + p_dossier + "&id=" + p_tag_id + "&clear=" + clear_button + '&pref=' + p_prefix + "&obj=" + p_obj;
2840 var action = new Ajax.Request(
2843 method: 'get', parameters: queryString,
2844 onFailure: ajax_misc_failure,
2845 onSuccess: function (req, j) {
2846 var answer = req.responseXML;
2847 var html = answer.getElementsByTagName('html');
2848 if (html.length === 0) {
2849 var rec = unescape_xml(req.responseText);
2850 error_message('erreur :' + rec);
2852 var code_html = getNodeText(html[0]);
2853 code_html = unescape_xml(code_html);
2854 remove_waiting_box();
2855 id$(p_prefix + 'tag_choose_td').innerHTML = id$(p_prefix + 'tag_choose_td').innerHTML + code_html;
2856 removeDiv(p_prefix + 'tag_div');
2861 error_message(e.message);
2866 * Clear the tags in the cell tag_choose_td of the search screen
2867 * @returns {undefined}
2869function search_clear_tag(p_dossier, p_prefix) {
2870 if (p_prefix != 'search') {
2871 id$(p_prefix + 'tag_choose_td').innerHTML = "";
2875 var queryString = "op=search_clear_tag&gDossier=" + p_dossier + "&pref=" + p_prefix;
2876 var action = new Ajax.Request(
2879 method: 'get', parameters: queryString,
2880 onFailure: ajax_misc_failure,
2881 onSuccess: function (req, j) {
2882 var answer = req.responseXML;
2883 var html = answer.getElementsByTagName('html');
2884 if (html.length === 0) {
2885 var rec = unescape_xml(req.responseText);
2886 error_message('erreur :' + rec);
2888 var code_html = getNodeText(html[0]);
2889 code_html = unescape_xml(code_html);
2890 id$(p_prefix + 'tag_choose_td').innerHTML = code_html;
2896 error_message(e.message);
2900function action_show_checkbox() {
2901 var a = document.getElementsByName('ag_id_td');
2902 for (var i = 0; i < a.length; i++) {
2903 a[i].style.display = 'block';
2907function action_hide_checkbox() {
2908 var a = document.getElementsByName('ag_id_td');
2909 for (var i = 0; i < a.length; i++) {
2910 a[i].style.display = 'none';
2917 * object attribute : g
2918 * - Dossier dossier_id,
2919 * - invalue DOM Element where you can find the periode to zoom
2920 * - outdiv ID of the target (DIV)
2923function calendar_zoom(obj) {
2926 var per_periode = null;
2929 if (id$(obj.invalue)) {
2930 per_periode = id$(obj.invalue).value;
2932 if (obj.notitle && obj.notitle == 1) {
2935 var action = new Ajax.Request(
2941 "op": 'calendar_zoom',
2943 'gDossier': obj.gDossier,
2946 'distype': obj.distype
2948 onFailure: ajax_misc_failure,
2949 onSuccess: function (req, j) {
2950 if (req.responseText === 'NOCONX') {
2954 var answer = req.responseXML;
2955 var html = answer.getElementsByTagName('html');
2956 if (html.length === 0) {
2957 var rec = unescape_xml(req.responseText);
2958 error_message('erreur :' + rec);
2960 var code_html = getNodeText(html[0]);
2961 code_html = unescape_xml(code_html);
2963 // if the target doesn't exist
2965 if (obj.outdiv === undefined) {
2966 obj.outdiv = 'calendar_zoom_div';
2968 if (id$(obj.outdiv) == undefined) {
2969 var str_style = 'top:10%;min-height:60rem';
2970// var str_style = fixed_position(0, 120);
2973 style: 'width:94%;' + str_style,
2974 cssclass: "inner_box",
2978 remove_waiting_box();
2979 id$(obj.outdiv).innerHTML = code_html;
2980 id$(obj.outdiv).show();
2985 error_message('calendar_zoom ' + e.message);
2992 * add a line in the form for the stock
2994function stock_add_row() {
2996 style = 'class="input_text"';
2997 var mytable = id$("stock_tb").tBodies[0];
2998 var ofirstRow = mytable.rows[1];
2999 var line = mytable.rows.length;
3000 var nCell = mytable.rows[1].cells.length;
3001 var row = mytable.insertRow(line);
3002 var nb = id$("row");
3003 for (var e = 0; e < nCell; e++) {
3004 var newCell = row.insertCell(e);
3005 if (mytable.rows[1].cells[e].hasClassName('num')) {
3006 newCell.addClassName("num");
3009 var tt = ofirstRow.cells[e].innerHTML;
3010 var new_tt = tt.replace(/sg_code0/g, "sg_code" + nb.value);
3011 new_tt = new_tt.replace(/sg_quantity0/g, "sg_quantity" + nb.value);
3012 new_tt = new_tt.replace(/label0/g, "label" + nb.value);
3013 newCell.innerHTML = new_tt;
3014 new_tt.evalScripts();
3017 id$("sg_code" + nb.value).innerHTML = ' ';
3018 id$("sg_code" + nb.value).value = '';
3019 id$("label" + nb.value).innerHTML = '';
3020 id$("sg_quantity" + nb.value).value = '0';
3024 new_tt.evalScripts();
3026 alert_box(e.message);
3031function show_description(p_id) {
3032 id$('print_desc' + p_id).hide();
3033 id$('input_desc' + p_id).show();
3038 * Display an empty card to fill , with the right card category
3039 * @param pn_fiche_card_id : fiche_def.fd_id
3040 * @param pn_dossier_id
3042function select_cat(pn_fiche_card_id, pn_dossier_id, ps_element_id) {
3044 "ctl": "div_new_card",
3045 "fd_id": pn_fiche_card_id,
3048 gDossier: pn_dossier_id,
3049 "elementId": ps_element_id
3051 removeDiv('select_card_div');
3055 * Show the DIV and hide the other, the array of possible DIV are
3057 * @param {array} a_tabs name of possible tabs
3058 * @param {strng} p_display_tab tab to display
3060function show_tabs(a_tabs, p_display_tab) {
3062 if (a_tabs.length == 0) {
3063 console.error('a_tabs in empty');
3064 throw ("a_tabs empty");
3068 for (i = 0; i < a_tabs.length; i++) {
3069 id$(a_tabs[i]).hide();
3071 id$(p_display_tab).show();
3073 alert_box(e.message);
3079 * Change the class of all the "LI" element of a UL or OL
3080 * @param node of ul (this)
3082function unselect_other_tab(p_tab) {
3084 var other = p_tab.getElementsByTagName("li");
3087 for (i = 0; i < other.length; i++) {
3089 tab.className = "tabs";
3093 console.error(e.message);
3094 alert_box('unselect_other_tab ' + e.message);
3099 * logout function call from ajax
3100 * @see ajax_disconnected
3101 * @returns {undefined}
3104 var tmp_place = window.location.href
3105 var tmp_b = tmp_place.split('/')
3106 var tmp_last = tmp_b.length - 1
3107 var place_logout = tmp_place.replace(tmp_b[tmp_last], 'logout.php');
3108 window.location.href = place_logout;
3112 * Create a div which can be used in a anchor
3113 * @returns {undefined}
3115function create_anchor_up() {
3116 if (document.getElementById('up_top'))
3119 var newElt = document.createElement('div');
3120 newElt.setAttribute('id', 'up_top');
3121 newElt.innerHTML = '<a id="up_top"></a>';
3123 var parent = id$('info_div').parentNode;
3124 parent.insertBefore(newElt, id$('info_div'));
3129 * Initialize the window to show the button "UP" if the window is scrolled
3131 * @returns {undefined}
3133function init_scroll() {
3134 var up = new Element('div', {
3136 "style": "padding:5px;left:auto;width:auto;height: auto;display:none;position:fixed;bottom:30%;right:50px;text-align:center;font-size:20px",
3139 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>';
3140 document.body.appendChild(up);
3141 window.onscroll = function () {
3142 if (document.getElementById("select_box_content")) {
3143 document.getElementById("select_box_content").setStyle({display: "none"})
3146 if (document.viewport.getScrollOffsets().top > 0) {
3147 if (id$('go_up').visible() == false) {
3148 id$('go_up').setOpacity(0.65);
3149 id$('go_up').show();
3150 id$('go_up').style.zIndex = 99;
3153 id$('go_up').hide();
3158function loading_page() {
3159 var id_page = new Element('div', {
3161 "style": "padding: 5px;\n" +
3162 " width: 300px;\n" +
3163 " height: 60px;\n" +
3164 " display: block;\n" +
3165 " position: fixed;\n" +
3166 " bottom: 50px;\n" +
3168 " text-align: center;\n" +
3169 " animation-name: fill_up_loading;\n" +
3170 " animation-duration: 8s;\n" +
3171 " animation-iteration-count: infinite;"+
3173 "border-radius: 5px;"+
3175 "animation-timing-function: linear;",
3176 id: "loading_page_div"
3178 id_page.update('<div class="loading_msg"></div><div class="loading_msg"></div><div class="loading_msg"></div><div class="loading_msg"></div><div class="loading_msg"></div>');
3179 document.body.appendChild(id_page);
3182 * Confirm a form thanks a modal dialog Box, it returns true if we agree otherwise
3185 <form onsubmit="return confirm_box(this,'message')">
3188 * @param p_obj form element (object) or element id (string)
3189 * @param p_message message to display
3190 * @param p_callback_true callback function or null
3191 * @param p_waiting if true display a waiting box
3192 * @returns true or false
3194function confirm_box(p_obj, p_message, p_callback_true, p_waiting) {
3197 // Find id of the end
3199 if (p_obj != null) {
3200 if (typeof (p_obj) === "object") {
3207 // execute the callback function or submit the form
3208 if (!p_callback_true) {
3210 smoke.confirm(p_message, function (e) {
3219 smoke.confirm(p_message, function (e) {
3221 p_callback_true.apply();
3226 alert_box(e.message);
3228 remove_waiting_box();
3233 * Alert box in CSS and HTML to replace the common javascript alert
3234 * @param p_message message to display
3237function alert_box(p_message) {
3238 smoke.alert(p_message, undefined, {ok: 'ok', classname: "inner_box",title:'ATTENTION'});
3243 * Colorize the rows of the table
3244 * @param string p_table id of the table
3246function alternate_row_color(p_table) {
3247 var table_colored = id$(p_table);
3248 if (!table_colored.tBodies[0]) return;
3250 var len = table_colored.tBodies[0].rows.length;
3252 var localClass = "";
3253 for (i = 1; i < len; i++) {
3254 localClass = (i % 2 == 0) ? "even" : "odd";
3255 if (table_colored.tBodies[0].rows[i].hasClassName("odd")) {
3256 table_colored.tBodies[0].rows[i].removeClassName("odd");
3258 if (table_colored.tBodies[0].rows[i].hasClassName("even")) {
3259 table_colored.tBodies[0].rows[i].removeClassName("even");
3261 table_colored.tBodies[0].rows[i].addClassName(localClass);
3266 * Colorize the rows of the list
3267 * @param p_list {string} DOM id of the list
3269function alternate_row_color_list(p_list) {
3270 var list_colored = id$(p_list);
3271 if ( list_colored.children.length==0 ) return;
3273 var len = list_colored.children.length;
3275 var localClass = "";
3276 for (i = 1; i < len; i++) {
3277 localClass = (i % 2 == 0) ? "even" : "odd";
3278 if (list_colored.children[i].hasClassName("odd")) {
3279 list_colored.children[i].removeClassName("odd");
3281 if (list_colored.children[i].hasClassName("even")) {
3282 list_colored.children[i].removeClassName("even");
3284 list_colored.children[i].addClassName(localClass);
3291 * Make an DOM element draggable or not
3292 * @param object_id DOM id
3294function pin(object_id) {
3295 if (aDraggableElement[object_id]) {
3296 aDraggableElement[object_id].destroy();
3297 aDraggableElement[object_id] = undefined;
3298 id$('pin_' + object_id).innerHTML = "";
3300 aDraggableElement[object_id] = new Draggable(object_id, {
3301 starteffect: function () {
3302 new Effect.Highlight(object_id, {scroll: window, queue: 'end'});
3306 id$('pin_' + object_id).innerHTML = "";
3311 * Show only the rows into the table (p_table_id) with the attribute (p_attribute_name) and if this attribute
3312 * has the value of (attribut_value)
3313 * @param p_table_id table id
3314 * @param p_attribute_name the name of the attribute
3315 * @param p_attribute_value the value of the attribute we want to show
3317function show_only_row(p_table_id, p_attribute_name, p_attribute_value) {
3318 if (!id$(p_table_id)) {
3319 throw "Invalide table id"
3321 var mTable = id$(p_table_id);
3322 var ncount = mTable.rows.length
3323 for (var i = 0; i < ncount; i++) {
3324 var mRow = mTable.rows[i];
3325 if (mRow.getAttribute(p_attribute_name) != undefined && mRow.getAttribute(p_attribute_name) != p_attribute_value) {
3334 * Show all the rows into the table (p_table_id)
3335 * @param p_table_id table id
3337function show_all_row(p_table_id) {
3338 if (!id$(p_table_id)) {
3339 throw "Invalide table id"
3341 var mTable = id$(p_table_id);
3342 var ncount = mTable.rows.length
3343 for (var i = 0; i < ncount; i++) {
3344 var mRow = mTable.rows[i];
3354 * id of the row of the periode row_per_(p_periode_id) , attribute exercice =per_exercice,periode_id=p_id
3356 * # id of the table with the rows : periode_tbl
3359 * - periode_id the concerned Periode , 0 none
3360 * - p_ledger : the id of ledger (jrn_def.jrn_def_id), 0 for global
3361 * - pcallback : default ajax_misc.php (this.callback) with the parameter { op:'periode',gDossier,[action:display,remove,save],p_id:p_periode_id}
3363 * - js_obj_name : name of the js object (this.js_obj_name)
3364 * - ajax_test : file to include for debugging
3365 * - dialog : id of the dialog box (update / add ) periode_box
3368var Periode = function (p_ledger) {
3369 this.periode_id = 0;
3370 this.p_ledger = p_ledger;
3371 this.dialog = 'periode_box';
3372 this.pcallback = 'ajax_misc.php';
3374 this.js_obj_name = "";
3375 this.ajax_test = "";
3376 this.set_callback = function (p_phpfile) {
3377 this.pcallback = p_phpfile;
3379 this.set_dossier = function (p_dosid) {
3380 this.dossier = p_dosid;
3383 * set_js_obj_name (p_js_obj_name)
3384 * We need to know the javascript variable name , to pass it to ajax and
3385 * create a HTML containing the right variable
3386 * @param p_js_obj_name name of the variable js we use on caller side
3388 this.set_js_obj_name = function (p_js_obj_name) {
3389 this.js_obj_name = p_js_obj_name;
3393 * Remove the periode , so call new Ajax and hide the row if successful
3394 * otherwise show dialog box.
3395 * @parameter p_periode_id is the id of periode
3397 this.remove = function (p_periode_id) {
3400 "gDossier": this.dossier,
3403 "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 var answer = req.responseText.evalJSON();
3420 remove_waiting_box();
3421 if (answer.status == "OK") {
3422 id$("row_per_" + p_periode_id).remove();
3423 alternate_row_color("periode_tbl");
3425 smoke.alert(answer.content);
3434 * display a dialog box to update a periode, call save either display
3435 * an error box or update the row.
3436 * the name of variable is requested
3437 * to build the right button , javascript in the html of answer
3438 * @parameter p_periode_id is the id of periode
3440 this.box_display = function (p_periode_id) {
3441 if (this.js_obj_name == "") {
3442 smoke.alert("ERROR BOX_ADD")
3446 "gDossier": this.dossier,
3449 "p_id": p_periode_id,
3450 "ledger_id": this.p_ledger,
3451 "js_var": this.js_obj_name
3453 if (this.ajax_test != "") {
3454 js_param["TestAjaxFile"] = this.ajax_test;
3457 new Ajax.Request(here.pcallback,
3460 parameters: js_param,
3461 onSuccess: function (req) {
3462 remove_waiting_box();
3463 var json = req.responseText.evalJSON();
3466 "id": "mod_periode",
3467 "style": "position:fixed;top:" + y + "px;width:50%",
3468 "cssclass": "inner_box",
3471 id$('mod_periode').update(json.content);
3476 * close the periode, call ajax and receive a json object with the attribute
3478 * @parameter p_periode_id is the id of periode
3480 this.close_periode = function (p_periode_id) {
3481 if (this.js_obj_name == "") {
3482 smoke.alert("ERROR BOX_ADD")
3485 if (this.ajax_test != "") {
3486 js_param["TestAjaxFile"] = this.ajax_test;
3489 smoke.confirm("Confirmer ?", function (e) {
3491 here._close(p_periode_id);
3496 * Internal function to close without confirming
3497 * @param {type} p_periode_id
3498 * @returns {undefined}
3500 this._close = function (p_periode_id) {
3501 if (this.js_obj_name == "") {
3502 smoke.alert("ERROR BOX_ADD")
3505 "gDossier": this.dossier,
3508 "ledger_id": this.p_ledger,
3509 "p_id": p_periode_id,
3510 "js_var": this.js_obj_name
3512 if (this.ajax_test != "") {
3513 js_param["TestAjaxFile"] = this.ajax_test;
3517 new Ajax.Request(here.pcallback,
3520 parameters: js_param,
3521 onSuccess: function (req) {
3522 remove_waiting_box();
3523 var json = req.responseText.evalJSON();
3524 if (json.status == 'OK') {
3525 id$('row_per_' + p_periode_id).update(json.content);
3526 new Effect.Highlight('row_per_' + p_periode_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3528 smoke.alert(json.content);
3534 * reopen the periode
3535 * @parameter p_periode_id is the SQL id of parm_periode or the id of
3538 this.open_periode = function (p_periode_id) {
3539 if (this.js_obj_name == "") {
3540 smoke.alert("ERROR BOX_ADD")
3543 "gDossier": this.dossier,
3546 "ledger_id": this.p_ledger,
3547 "p_id": p_periode_id,
3548 "js_var": this.js_obj_name
3550 if (this.ajax_test != "") {
3551 js_param["TestAjaxFile"] = this.ajax_test;
3554 smoke.confirm("Confirmer ?", function (e) {
3557 new Ajax.Request(here.pcallback,
3560 parameters: js_param,
3561 onSuccess: function (req) {
3562 remove_waiting_box();
3563 var json = req.responseText.evalJSON();
3564 if (json.status == 'OK') {
3565 id$('row_per_' + p_periode_id).update(json.content);
3566 new Effect.Highlight('row_per_' + p_periode_id, {
3567 startcolor: '#FAD4D4',
3571 smoke.alert(json.content);
3579 * This DOMID of the DIV containing the form is mod_periode
3580 * @param {type} p_frm
3581 * @returns {Boolean}
3583 this.save = function (p_frm) {
3584 var js_param = id$(p_frm).serialize(true);
3586 js_param["js_var"] = this.js_obj_name;
3587 js_param["act"] = "save";
3588 js_param["op"] = "periode";
3590 new Ajax.Request(this.pcallback, {
3592 parameters: js_param,
3593 onSuccess: function (req) {
3595 var answer = req.responseText.evalJSON();
3596 remove_waiting_box();
3597 if (answer.status == "OK") {
3598 id$('row_per_' + js_param['periode_id']).update(answer.content);
3599 removeDiv('mod_periode');
3600 new Effect.Highlight('row_per_' + js_param['periode_id'], {
3601 startcolor: '#FAD4D4',
3605 smoke.alert(answer.content);
3612 * Thanks the object DOMID sel_per_closed[] the selected periodes are
3614 * @see Periode._close
3616 this.close_selected = function () {
3618 var a_selected = document.getElementsByName('sel_per_close[]');
3621 for (i = 0; i < a_selected.length; i++) {
3622 if (a_selected[i].checked == true) {
3623 // Close the selected periode
3628 smoke.signal("Sélectionner au moins une période", function () {
3629 }, {duration: 1500});
3632 smoke.confirm("Confirmer fermeture de " + count + " periode", function (e) {
3634 var a_selected = document.getElementsByName('sel_per_close[]');
3636 for (i = 0; i < a_selected.length; i++) {
3637 if (a_selected[i].checked == true) {
3638 // Close the selected periode
3639 here._close(a_selected[i].value);
3647 * Insert a periode into the list, always at the bottom !
3649 * # FORM id :insert_periode_frm
3650 * # DIV id = periode_add
3651 * # table id = periode_tbl
3653 this.insert_periode = function () {
3654 var p_frm = 'insert_periode_frm';
3655 var js_param = id$(p_frm).serialize(true);
3657 js_param["js_var"] = this.js_obj_name;
3658 js_param["act"] = "insert_periode";
3659 js_param["op"] = "periode";
3660 js_param["p_id"] = "-1";
3661 js_param["ledger_id"] = "0";
3663 new Ajax.Request(this.pcallback, {
3665 parameters: js_param,
3666 onSuccess: function (req) {
3667 var answer = req.responseText.evalJSON();
3668 remove_waiting_box();
3669 if (answer.status == "OK") {
3670 var new_row = document.createElement("tr");
3671 id$('periode_tbl').append(new_row);
3672 new_row.replace(answer.content);
3675 id$('periode_add').hide();
3676 new Effect.Highlight('row_per_' + answer.p_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3677 alternate_row_color('periode_tbl');
3679 smoke.alert(answer.content);
3688 * Show the periodes from the exercice contained into the id (p_exercice_sel)
3689 * @param p_table_id DOM ID of the table
3691Periode.filter_exercice = function (p_table_id) {
3692 var rows = id$(p_table_id).rows;
3693 var selected_value = id$('p_exercice_sel').value;
3694 for (var i = 1; i < rows.length; i++) {
3695 var exercice = rows[i].getAttribute("per_exercice");
3696 if (selected_value == -1) {
3698 } else if (selected_value == exercice) {
3707// keep track of progress bar
3708var progressBar = [];
3709// idx of progress bar
3713 * Start the progress bar
3714 * @param {string} p_taskid id to monitor
3715 * @param {int} p_message
3717function progress_bar_start(p_taskid, p_message) {
3722 var message = '<p>' + content[70] + '</p>';
3724 message = p_message;
3727 add_div({id: "blocking" + progressIdx, cssclass: "smoke-base smoke-visible "});
3730 id: "message" + progressIdx,
3731 cssclass: "inner_box",
3732 style: "z-index:"+get_next_layer()+";position:fixed;top:30%;width:40%;left:30%"
3734 id$("message" + progressIdx).update('<h3>' + content[65] + '</h3>' + message);
3736 add_div({id: "progressDiv" + progressIdx, cssclass: "progressbar", html: '<span id="progressValue">0</span>'});
3737 // Check status every sec.
3738 progressBar[progressIdx] = setInterval(progress_bar_check.bind(null, progressIdx, p_taskid), 1000);
3740 console.error(e.message);
3745 * Check every second the status
3746 * @param {integer} p_idx idx of progressbar
3747 * @param {string} p_taskid id to monitor
3749function progress_bar_check(p_idx, p_taskid) {
3752 new Ajax.Request("ajax_misc.php", {
3753 parameters: {gDossier: 0, task_id: p_taskid, op: "progressBar"},
3755 onSuccess: function (req) {
3757 var answer = req.responseText.evalJSON();
3758 var progress_div = id$("progressDiv" + progressIdx);
3759 var a_child = progress_div.childNodes;
3761 for (i = 0; i < a_child.length; i++) {
3762 if (a_child[i].id = "progressValue") {
3763 var progressValue = a_child[i];
3766 var progress = parseFloat(progressValue.innerHTML);
3767 if (answer.value <= progress) {
3771 progressValue.innerHTML = answer.value;
3772 progressValue.setStyle("width:" + answer.value + "%");
3773 if (answer.value == 100) {
3774 clearInterval(progressBar[p_idx]);
3775 progressValue.innerHTML = "Success";
3776 Effect.BlindUp("progressDiv" + p_idx, {duration: 1.0, scaleContent: false})
3777 id$("message" + p_idx).remove();
3778 id$("blocking" + p_idx).remove();
3779 setTimeout(function () {
3780 id$("progressDiv" + progressIdx).remove
3784 clearInterval(progressBar[p_idx]);
3785 document.getElementById("progressValue").innerHTML = req.responseText;
3786 console.error(e.message);
3791 clearInterval(progressBar[p_idx]);
3792 console.error(e.message);
3797 * In the user's setting box, update the period list with the choosen exercice
3798 * @param {int} p_dossier
3800function updatePeriodePreference(p_dossier) {
3802 var exercice = id$('exercice_setting').value;
3803 new Ajax.Updater('setting_period', "ajax_misc.php", {
3805 parameters: {"op": "pref_exercice", "gDossier": p_dossier, "exercice": exercice}
3807 remove_waiting_box();
3811 * Update the from and to periode list when changing the exercice
3812 * @param {int} p_dossier
3813 * @param {string} p_exercice dom id of the exercice (SELECT)
3814 * @param {type} p_periode_from id of the starting periode
3815 * @param {type} p_periode_to id of the ending periode
3816 * @param {type} p_last possible value = 1 to show last date or 0 the first
3818function updatePeriode(p_dossier, p_exercice, p_periode_from, p_periode_to, p_last) {
3820 var exercice = id$(p_exercice).value;
3821 new Ajax.Updater(p_periode_from, "ajax_misc.php",
3825 op: "periode_change", "gDossier": p_dossier, "exercice": exercice,
3826 field: p_periode_from, "type": "from", "last": p_last
3829 if (p_periode_to && p_last) {
3830 new Ajax.Updater(p_periode_to, "ajax_misc.php",
3834 op: "periode_change", "gDossier": p_dossier, "exercice": exercice,
3835 field: p_periode_to, "type": "to", "last": p_last
3839 remove_waiting_box();
3844 * @param {string} p_domid DOM id of the span containing the padlock icon
3847function toggle_lock(p_domid) {
3848 var padlock = document.getElementById(p_domid);
3849 if (padlock == null) {
3850 console.error("domid invalid");
3852 var status = padlock.getAttribute("is_locked");
3854 padlock.innerHTML = "";
3855 padlock.setAttribute("is_locked", 0);
3856 } else if (status == 0) {
3857 padlock.innerHTML = "";
3858 padlock.setAttribute("is_locked", 1);
3860 throw "toggle_lock failed";
3868 * @returns {undefined}
3870function show_ledger_fin_currency() {
3871 var ledger = id$('p_jrn').value;
3872 var dossier = id$('gDossier').value;
3873 // id$('ledger_currency').
3874 var a = new Ajax.Updater("ledger_currency",
3877 parameters: {"op": "currencyCode", "gDossier": dossier, "ledger": ledger}
3882 * Update Preference, applied the new CSS
3884function updatePreference() {
3887 var param = id$('preference_frm').serialize() + "&op=preference&action=save";
3889 new Ajax.Request("ajax_misc.php", {
3892 onSuccess: function (req) {
3893 var answer = req.responseText.evalJSON();
3894 // id$('pagestyle').setAttribute('href', style.style);
3895 if (answer['psw'] == 'NOK') {
3896 smoke.alert(answer['msg']);
3898 removeDiv('preference_div');
3903 smoke.alert(content[48] + e.message);
3905 remove_waiting_box();
3910 * turn on or off , set an domElement to 1 or 0 and change the icon
3911 * @param string icon_domid : id of the domElement which must be changed
3912 * @param string p_value_domid : id of domElement containing 1 or 0
3913 * @see param_jrn.php
3915function toggle_onoff(icon_domid, p_value_domid) {
3916 if (id$(p_value_domid).value == 0) {
3917 id$(p_value_domid).value = 1;
3918 id$(icon_domid).innerHTML = '';
3919 id$(icon_domid).style = 'color:green';
3921 id$(p_value_domid).value = 0;
3922 id$(icon_domid).innerHTML = '';
3923 id$(icon_domid).style = 'color:red';
3928 * turn on or off , set an domElement to 1 or 0 and change the icon
3929 * @param string icon_domid : id of the domElement which must be changed
3930 * @param string p_value_domid : id of domElement containing 1 or 0
3931 * @see param_jrn.php
3933function toggle_checkbox_onoff(icon_domid, p_value_domid) {
3935 if (id$(p_value_domid).value == 0) {
3936 id$(p_value_domid).value = 1;
3937 id$(icon_domid).innerHTML = '';
3939 id$(p_value_domid).value = 0;
3940 id$(icon_domid).innerHTML = '';
3945 * in C0JRN show or hide the row depending if the warning is enable or not
3947 * @param {type} p_enable
3948 * @param {type} p_row
3949 * @returns {undefined}
3951function toggle_row_warning_enable(p_enable, p_row) {
3952 var warning = document.getElementsByName('negative_amount')[0].value
3953 if ( warning == 1) {
3961 * return a json object which is the merge of the 2 json objects
3962 * from 2015 : Object.assign(obj1, obj2);
3963 * @param p_json1 object 1 to merge
3964 * @param p_json2 object 2 to merge
3965 * @returns new json object
3967function json_concat(p_json1, p_json2) {
3970 for (var key in p_json1) {
3971 result[key] = p_json1[key];
3973 for (var key in p_json2) {
3974 result[key] = p_json2[key];
3982 * this function unchecks other checkbox , it mimics the way a radio behaves
3983 * @param string p_click is the DOM id of the checkbox you clicked
3984 * @param string p_name is the name of all the checkbox to uncheck
3986function uncheck_other(p_click, p_name) {
3987 var aCheckbox = document.getElementsByName(p_name);
3988 if (aCheckbox.length == 0) return;
3990 for (i = 0; i < aCheckbox.length; i++) {
3991 aCheckbox[i].checked = false;
3993 p_click.checked = true;
3997 * @class operation Tag Manage the tag with operations
3998 * @returns {undefined}
4000var operation_tag = function (p_div) {
4003 * Show a list of tag which can be added to the current followup document
4004 * @param {type} p_dossier
4005 * @param {type} jrn_id
4006 * @returns {undefined}
4008 this.select = function (p_dossier, p_jrn_id) {
4011 var queryString = {jrn_id: p_jrn_id, op: "operation_tag_select", gDossier: p_dossier, ctl: this.ctl};
4012 var action = new Ajax.Request(
4016 parameters: queryString,
4017 onFailure: ajax_misc_failure,
4018 onSuccess: function (req, j) {
4019 remove_waiting_box();
4021 var answer = req.responseXML;
4022 var html = answer.getElementsByTagName('code');
4023 if (html.length === 0) {
4024 var rec = unescape_xml(req.responseText);
4025 error_message('erreur :' + rec);
4027 var code_html = getNodeText(html[0]);
4028 code_html = unescape_xml(code_html);
4029 var pos = fixed_position(35, 229);
4030 add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
4032 remove_waiting_box();
4033 id$('tag_div').innerHTML = code_html;
4038 error_message(e.message);
4043 * Add the current tag to the current ag_id
4044 * @param {int} p_dossier
4046 * @param p_isgroup g it is a group , t is a single tag
4049 this.add = function (p_dossier, p_jrn_id, t_id, p_isgroup) {
4053 t_id: t_id, jrn_id: p_jrn_id, op: "operation_tag_add",
4054 gDossier: p_dossier, ctl: this.ctl, isgroup: p_isgroup
4057 var action = new Ajax.Request(
4060 method: 'get', parameters: queryString,
4061 onFailure: ajax_misc_failure,
4062 onSuccess: function (req, j) {
4063 var answer = req.responseXML;
4064 var html = answer.getElementsByTagName('code');
4065 if (html.length === 0) {
4066 var rec = unescape_xml(req.responseText);
4067 error_message('erreur :' + rec);
4069 var code_html = getNodeText(html[0]);
4070 code_html = unescape_xml(code_html);
4071 remove_waiting_box();
4072 id$('operation_tag_td' + ctl).innerHTML = code_html;
4073 removeDiv('tag_div');
4078 error_message(e.message);
4082 * remove the current tag to the current ag_id
4083 * @param {int} p_dossier
4084 * @param {int} ag_id
4087 this.remove = function (p_dossier, p_jrn_id, t_id) {
4089 confirm_box(null, content[50], function () {
4095 op: "operation_tag_remove",
4096 gDossier: p_dossier,
4099 var action = new Ajax.Request(
4103 parameters: queryString,
4104 onFailure: ajax_misc_failure,
4105 onSuccess: function (req, j) {
4106 var answer = req.responseXML;
4107 var html = answer.getElementsByTagName('code');
4108 if (html.length === 0) {
4109 var rec = unescape_xml(req.responseText);
4110 error_message('erreur :' + rec);
4112 var code_html = getNodeText(html[0]);
4113 code_html = unescape_xml(code_html);
4114 remove_waiting_box();
4115 id$('operation_tag_td' + ctl).innerHTML = code_html;
4121 error_message(e.message);
4128 * Check the sum of size of all the FILES to upload
4129 * @param p_object the form DOM object,
4130 * @param p_max_size MAX_FILE_SIZE constant (see config.inc.php or constant.php)
4131 * @returns true if the sum of filesize is greater than the limit
4133function check_file_size(p_object, p_max_size) {
4135 for (var i = 0; i < p_object.elements.length; i++) {
4136 var a = p_object.elements[i];
4138 if (p_object.elements[i].getAttribute('type') == "file") {
4139 for (let x = 0; x < p_object.elements[i].files.length; x++) {
4140 if (p_object.elements[i].files[x]) {
4142 sum_file += p_object.elements[i].files[x].size;
4147 if (sum_file > p_max_size) {
4148 alert_box(content[78]);
4155 * Check that the receipt file is not too big
4156 * @see ajax_ledger.php , ledger_detail_file
4157 * @param int p_max_size maximum size
4158 * @param p_info name of the waiting box
4159 * @returns true if file size is less than the maximum
4161function check_receipt_size(p_max_size, p_info) {
4162 document.getElementById(p_info).style.display = "inline";
4164 var f = document.getElementById("receipt_id");
4165 if (f && f.files[0] && f.files[0].size > parseFloat(p_max_size)) {
4166 document.getElementById("receipt_info_id").innerHTML = content[78];
4167 document.getElementById(p_info).style.display = "none";
4168 $('receipt_info_id').addClassName('error');
4171 document.getElementById("receipt_info_id").innerHTML = "";
4172 $('receipt_info_id').removeClassName('error');
4173 document.getElementById("form_file").submit();
4178 * toggle size of a div : fullsize or normal
4181function full_size(p_div) {
4182 div_dom = document.getElementById(p_div);
4183 if (!div_dom) return;
4184 if (div_dom.hasClassName('fullsize')) {
4185 div_dom.removeClassName('fullsize');
4186 id$('size_' + p_div).innerHTML = '';
4188 div_dom.addClassName('fullsize');
4189 id$('size_' + p_div).innerHTML = '';
4195 * download a document from an url
4197function download_document(p_url) {
4199 document.location = p_url;
4200 remove_waiting_box();
4204 * download a document from a form
4206function download_document_form(p_form_id) {
4208 var url = "export.php?" + id$(p_form_id).serialize();
4209 document.location = url;
4210 remove_waiting_box();
4215 * Pause a javascript
4217function pausecomp(millis) {
4218 var date = new Date();
4221 curDate = new Date();
4223 while (curDate - date < millis);
4227 * propose to reconnect
4228 * @returns {undefined}
4230function reconnect() {
4231 remove_waiting_box();
4232 new Ajax.Request('ajax_misc.php', {
4234 parameters: {op: "disconnect"},
4235 onSuccess: function (req) {
4236 var pos = "position:fixed;top:0px;width:95%;height:95%";
4238 'id': "reconnect_bx",
4239 cssclass: "inner_box",
4242 div.innerHTML = req.responseText;
4248 * enlarge an INPUT TEXT
4251function enlarge_text(p_domid, p_size) {
4253 var element = document.getElementById(p_domid);
4255 console.error(`enlarge text doesn't exist [${p_domid}]`)
4257 var current_size = parseInt(element.getAttribute('size'));
4258 element.setAttribute('size', current_size + parseInt(p_size));
4260 console.error(`enlarge text fails with ${p_domid} ${p_size} `);
4261 console.error(e.message);
4268 * @brief display a box with the customer , supplier or event for today or late
4269 * @param p_detail , what to do
4271function event_display_detail(p_dossier, p_detail) {
4274 // create div if not exists
4275 var dgbox = "situation_detail_div";
4278 var queryString = {gDossier: p_dossier, op: 'event_display_detail', 'what': p_detail};
4279 // call ajax and update content of the div
4280 var action = new Ajax.Request(
4284 parameters: queryString,
4285 onFailure: ajax_misc_failure,
4286 onSuccess: function (req) {
4287 remove_waiting_box();
4288 if (req.responseText == 'NOCONX') {
4292 if (!document.getElementById(dgbox)) {
4293 var div_style = "position:fixed;" + ";top:30%;z-index:"+get_next_layer();
4294 add_div({id: dgbox, cssclass: 'inner_box2', html: loading(), style: div_style, drag: true});
4298 id$(dgbox).update(req.responseText)
4303 event_display_main(p_dossier);
4305 alert_box(e.message);
4310 * @brief refresh the main display in the dashboard to reflect possible changes
4313function event_display_main(p_dossier) {
4316 var dgbox = "situation_div";
4317 var queryString = {gDossier: p_dossier, op: 'event_display_detail', 'what': "main_display"};
4318 var action = new Ajax.Request(
4322 parameters: queryString,
4323 onFailure: ajax_misc_failure,
4324 onSuccess: function (req) {
4325 remove_waiting_box();
4326 if (req.responseText == 'NOCONX') {
4331 id$(dgbox).update(req.responseText)
4337 alert_box(e.message);
4342 * @brief check if password is strong or not, update a DIV element
4343 * @param p_pass_domid DOM ID of the INPUT element with the password
4344 * @param p_result_domid DOM ID of the element to update
4346function check_password_strength(p_pass_domid, p_result_domid, details) {
4348 if (id$(p_pass_domid).value == "") {
4349 id$(p_result_domid).update("");
4353 'op': "password_chk"
4354 , pass: id$(p_pass_domid).value
4356 var action = new Ajax.Request(
4360 parameters: queryString,
4361 onFailure: ajax_misc_failure,
4362 onSuccess: function (req) {
4363 remove_waiting_box();
4364 if (req.responseText == 'NOCONX') {
4367 var answer = req.responseJSON;
4369 if (answer['password'] == 'nok') {
4371 id$(p_pass_domid).setStyle("background-color:red");
4373 id$(p_result_domid).update(answer['msg'])
4377 id$(p_pass_domid).setStyle("background-color: lightgreen");
4378 id$(p_result_domid).update("")
4383 alert_box(e.message);
4388 * activate a plugin , must comes from C0PLG
4389 * @param elt {string} DOMID of the element, must have the attribute gDossier, plugin and pr_id (for the profile)
4392function activate_plugin(elt)
4398 op:'activate_plugin',
4399 gDossier:elt.getAttribute('gDossier'),
4400 mecode:elt.getAttribute('me_code'),
4401 prid:elt.getAttribute('pr_id'),
4402 dep:elt.getAttribute('dep'),
4403 ord:elt.getAttribute('order'),
4404 activate:elt.checked
4406 var action = new Ajax.Request(
4410 parameters:queryString,
4411 onFailure:ajax_misc_failure,
4412 onSuccess:function(req){
4413 remove_waiting_box();
4414 if (req.responseText == 'NOCONX') {
4419 if (req.responseText != 'OK') {
4420 smoke.alert(req.responseText)
4428 alert_box(e.message);
4431/**********************************************************************************************/
4435*************************************************************************************************************/
4437Widget = function(dossier_id) {
4438 this.dossier_id=dossier_id;
4441 * Display the widget in the elt box
4442 * @param box DOMID of the target
4444 * @param user_widget_id int
4445 * @param widget_code string
4446 * @param var_name string name of the variable
4448Widget.prototype.display = function (box,user_widget_id,widget_code,var_name) {
4452 gDossier: this.dossier_id,
4454 'user_widget_id': user_widget_id,
4455 'widget_code': widget_code,
4456 'var_name':var_name,
4457 'action': 'widget.display'
4459 var action = new Ajax.Request(
4463 parameters: queryString,
4464 onFailure: ajax_misc_failure,
4465 onSuccess: function (req) {
4466 if (req.responseText == 'NOCONX') {
4470 id$(box).replace(req.responseText);
4476 alert_box(e.message);
4484 * @returns {boolean}
4486Widget.prototype.manage = function () {
4489 var box = 'widget_box_id';
4491 gDossier: this.dossier_id,
4493 'action': 'widget.manage'
4495 var action = new Ajax.Request(
4499 parameters: queryString,
4500 onFailure: ajax_misc_failure,
4501 onSuccess: function (req) {
4502 if (req.responseText == 'NOCONX') {
4506 var style = 'position:absolute;';
4508 style = style + ' ;top : ' + y + 'px';
4510 add_div({id: box, cssclass: 'inner_box', html: loading(), style: style,drag:false})
4512 id$(box).update(req.responseText);
4517 alert_box(e.message);
4518 console.error("widget_manage" + e.message);
4523 * create a list of sortable elements
4525Widget.prototype.create_sortable=function() {
4527 Sortable.create('contain_widget',{tag:'li',onUpdate:function(){ id$('order_widget_hidden').value=Sortable.serialize('contain_widget')}})
4528 id$('order_widget_hidden').value=Sortable.serialize('contain_widget');
4531 * Save the order of widget
4533Widget.prototype.save = function () {
4537 var dgbox="widget_box_id";
4540 // For form , most of the parameters are in the FORM
4541 // method is then POST
4542 //var queryString=id$(p_form_id).serialize(true);
4546 action : 'widget.save',
4547 gDossier: this.dossier_id,
4548 param : Sortable.serialize('contain_widget')
4550 var action = new Ajax.Request(
4554 parameters:queryString,
4555 onFailure:ajax_misc_failure,
4556 onSuccess:function(req){
4557 remove_waiting_box();
4558 if (req.responseText == 'NOCONX') {
4570 alert_box(e.message);
4572 this.remove_ident();
4575 * refresh the DASHBOARD (dashboard_div_id)
4577Widget.prototype.refresh = function () {
4580 var dgbox='dashboard_div_id'
4583 action : 'widget.refresh',
4584 gDossier: this.dossier_id
4586 var action = new Ajax.Request(
4590 parameters:queryString,
4591 onFailure:ajax_misc_failure,
4592 onSuccess:function(req){
4593 if (req.responseText == 'NOCONX') {
4598 id$(dgbox).replace(req.responseText);
4604 console.error("widget.refresh "+e.message)
4608 * delete a widget : remove from the list
4609 * @param user_widget_id {integer}
4611Widget.prototype.delete=function (user_widget_id) {
4612 id$('elt_'+user_widget_id).remove()
4613 id$('order_widget_hidden').value=Sortable.serialize('contain_widget');
4616 * display list widget we can add
4618Widget.prototype.input = function () {
4620 var box="widget_box_select_id";
4624 action: 'widget.input',
4625 gDossier: this.dossier_id
4627 var action = new Ajax.Request(
4631 parameters: queryString,
4632 onFailure: ajax_misc_failure,
4633 onSuccess: function (req) {
4634 remove_waiting_box();
4635 if (req.responseText == 'NOCONX') {
4639 var style = 'position:absolute;';
4641 style = style + ' ;top : ' + y + 'px';
4643 add_div({id: box, cssclass: 'inner_box', html: loading(), style: style})
4645 id$(box).update(req.responseText);
4652 alert_box(e.message);
4656 * add a widget for the user , refresh the dashboard afterward
4657 * @param widget_code {string}
4659Widget.prototype.add=function (widget_code) {
4664 if (document.getElementById(widget_code+"_param")) {
4665 param=id$(widget_code+"_param").serialize()
4669 action : 'widget.insert',
4670 gDossier: this.dossier_id,
4672 widget_code:widget_code
4674 var action = new Ajax.Request(
4679 onFailure:ajax_misc_failure,
4680 onSuccess:function(req){
4681 if (req.responseText == 'NOCONX') {
4685 var new_element=new Element("li");
4686 id$('contain_widget').appendChild(new_element);
4687 new_element.replace(req.responseText)
4688 removeDiv('widget_box_select_id')
4689 here.create_sortable()
4696 alert_box(e.message);
4701 * Show the number in the widget to improve the ergonomy
4703Widget.prototype.show_ident = function ()
4705 var aBox = document.getElementsByClassName('widget-box') ;
4708 for (var e=0;e <nb; e++) {
4709 if (aBox[e].visible)
4711 var spanx=new Element('span');
4712 spanx.addClassName("box_ident");
4713 aBox[e].insertBefore(spanx,aBox[e].firstChild);
4720 * Hide the number of the widget
4722Widget.prototype.remove_ident = function ()
4725 var elt=document.getElementsByClassName("box_ident");
4726 if ( elt.length == 0) break;
4732 * Put the widget in full size
4733 * @param widget_domid {string} dom id of the widget to toggle the size
4735Widget.prototype.toggle_full_size=function (widget_domid) {
4736 if ( id$(widget_domid).hasClassName('widget-full_size')) {
4737 id$(widget_domid).removeClassName('widget-full_size');
4739 id$(widget_domid).addClassName('widget-full_size');
4741 var layer=get_next_layer();
4742 id$(widget_domid).style.zIndex=layer;
4750(function(){window.addEventListener("beforeunload", (event) => {waiting_box()});})();
4752(function(){window.addEventListener("onload", (event) => {remove_waiting_box()});})();
4755//var bookmark=new Bookmark();
4757Noalyss = function () {
4762 * @param {string} domid id of the dom element
4763 * @param {string} mode min for minimum or full , gives an error if the mode doesn't exist
4764 * @returns {undefined}
4767Noalyss.prototype.activate_tinymce=function (domid,mode,p_height) {
4768 if ( ! g_enable_tinymce ) return;
4769 tinymce.remove('#'+domid);
4770 if (! p_height) p_height=500;
4771 if ( mode == 'minimal' || ! mode )
4774 selector: 'textarea#'+domid,
4775 plugins:'link quickbars ',
4778 toolbar: 'undo redo | ' +
4779 'bold italic underline forecolor backcolor |fontsize ' +
4780 ' | bullist numlist | ' +
4781 'removeformat | help',
4782 content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
4783 quickbars_insert_toolbar:false,
4785 quickbars_selection_toolbar:' bold italic underline forecolor backcolor ',
4790 } else if ( mode == "full")
4793 toolbar: 'undo redo ' +
4794 'bold italic underline strikethrough | hr quickimage | forecolor backcolor|emoticons |fontsize styles ' +
4795 ' table tabledelete |' +
4796 ' | link unlink bullist numlist | ' +
4797 'removeformat | help',
4798 content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
4801 selector: 'textarea#'+domid,
4804 plugins:'link lists emoticons quickbars pagebreak table',
4805 toolbar: 'undo redo ' +
4806 'bold italic underline strikethrough | hr quickimage | forecolor backcolor|emoticons |fontsize styles fontfamily ' +
4807 ' table tabledelete |' +
4808 ' | link unlink bullist numlist | ' +
4809 'removeformat | help',
4810 content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
4811 quickbars_insert_toolbar:false,
4813 quickbars_selection_toolbar:' bold italic underline forecolor backcolor ',
4819 }else if ( mode == 'no-toolbar' )
4822 selector: 'textarea#'+domid,
4824 plugins:' quickbars',
4827 quickbars_selection_toolbar:' bold italic underline forecolor backcolor hide',
4828 content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
4832 toolbar_mode: 'hide',
4833 quickbars_insert_toolbar:false,
4838 console.error(`Noalyss.activate_tinymce unknow mode`);
4843 * @deprecated not used
4844 * Input NOTE on operation from Detail Operation
4845 * @param {int} dossier_id
4846 * @param {int} jrn_id
4847 * @param {string} div_prefix
4848 * @returns {undefined}
4850Noalyss.prototype.input_note=function (dossier_id,jrn_id,div_prefix)
4855 var dgbox = "box_input_note"+div_prefix;
4863 ,gDossier:dossier_id
4864 ,tinymce:g_enable_tinymce
4866 var action = new Ajax.Request(
4870 parameters: queryString,
4871 onFailure: ajax_misc_failure,
4872 onSuccess: function (req) {
4873 remove_waiting_box();
4874 if (req.responseText == 'NOCONX') {
4879 var div_style = "position:absolute;" + ";top:" + y + "px";
4880 add_div({id: dgbox, cssclass: 'inner_box2', html: loading(), style: div_style, drag: true});
4881 let response=req.responseXML;
4882 let html=getNodeText(response.getElementsByTagName("code")[0])
4883 let ctl=getNodeText(response.getElementsByTagName("ctl")[0]);
4884 $(dgbox).update(html);
4891 alert_box(e.message);
4895Noalyss.prototype.refresh_note=function(jrn_id,dossier_id)
4897 if ( document.getElementById("als_note"+jrn_id)) {
4898 new Ajax.Updater('als_note'+jrn_id,'ajax_misc.php',{
4902 ,'act':'note_refresh'
4904 ,gDossier:dossier_id
4908 } else if ( document.getElementById("jrn_note_td")) {
4909 new Ajax.Updater('jrn_note_td','ajax_misc.php',{
4913 ,'act':'note_refresh'
4915 ,gDossier:dossier_id
4926 * save parameter for SMPT , menu C0ML
4929Noalyss.prototype.save_config_smtp = function ()
4934 var queryString = $("form_config_smtp").serialize(true);
4935 queryString['op'] = "email_setting";
4936 queryString['op2'] = "save_config_smtp";
4937 var action = new Ajax.Request(
4941 parameters: queryString,
4942 onFailure: ajax_misc_failure,
4943 onSuccess: function (req) {
4944 remove_waiting_box();
4945 if (req.responseText == 'NOCONX') {
4949 let json = req.evalJSON();
4957 console.error(e.message);
4961Noalyss.prototype.parameter_display_smtp = function ()
4963 if ($F("smtp_type") == 'smtp') {
4964 $("smtp_config_div").style.display = "grid";
4965 $('btn_save1').hide();
4967 $("smtp_config_div").hide();
4968 $('btn_save1').show();
4972Noalyss.prototype.parameter_test_smtp = function ()
4976 var parameter = $('form_config_smtp').serialize(true);
4977 parameter['op'] = "email_setting";
4978 parameter['op2'] = "parameter_test_smtp";
4979 var email = {email_test: $F('email_test_input')};
4980 if ($F('email_test_input') == '') {
4981 smoke.alert("Aucun email")
4985 var action = new Ajax.Request(
4989 parameters: Object.assign(parameter, email),
4990 onSuccess: function (req) {
4991 remove_waiting_box();
4992 if (req.responseText == 'NOCONX') {
4996 $('result_test_div').update(req.responseText);
5004 remove_waiting_box();
5005 console.error("parameter_test_smtp" + e.message);
5010VAT_Code = function (dossier_id) {
5011 this.dossier_id=dossier_id;
5014VAT_Code.prototype.list_vatex=function ()
5019 var dgbox = "search_vatex_div";
5024 gDossier:this.dossier_id,
5027 var action = new Ajax.Request(
5031 parameters: queryString,
5032 onSuccess: function (req) {
5033 remove_waiting_box();
5034 if (req.responseText == 'NOCONX') {
5039 var div_style = "position:absolute;" + ";top:" + y + "px"+";z-index:"+get_next_layer();
5040 add_div({id: dgbox, cssclass: 'inner_box', html: loading(), style: div_style, drag: false});
5041 $(dgbox).update(req.responseText);
5042 here.filter_country();
5049 alert_box(e.message);
5054VAT_Code.prototype.select_value=function(vx_code)
5058 var dgbox = "search_vatex_div";
5062 gDossier:this.dossier_id,
5063 select_code:vx_code,
5067 var action = new Ajax.Request(
5071 parameters: queryString,
5072 onSuccess: function (req) {
5073 remove_waiting_box();
5074 if (req.responseText == 'NOCONX') {
5079 var answer=req.responseJSON
5080 $("vx_code").value=answer.vx_code;
5081 $("vx_value").update(answer.vx_value);
5082 $('vx_code_description').update(answer.vx_description)
5090 alert_box(e.message);
5094VAT_Code.prototype.filter_country=function()
5097 var to_show=id$("filter_country").value;
5098 let a_row=id$("code_vatex_tb").rows;
5099 // show all rows, then hide
5100 for (let i=1;i< a_row.length;i++) {
5102 if (id$("filter_country").value == 0 || a_row[i].hasClassName(to_show)){
5109 $('lk_code_vatex_tb').value="";
5112 console.error(e.message);
5116noalyss=new Noalyss();
5118bookmark=new Bookmark();