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 for searching a card
29 * search a card an display the result into a inner box
31function boxsearch_card(p_dossier)
36 removeDiv('boxsearch_card_div');
37 var queryString="gDossier="+p_dossier+"&op=cardsearch"+"&card="+encodeURI($("card_search").value);
38 var action = new Ajax.Request(
41 method:'get', parameters:queryString,
42 onFailure:ajax_misc_failure,
43 onSuccess:function(req){
45 if (req.responseText == 'NOCONX') {
50 var div_style="position:absolute;"+";top:"+y+"px";
51 add_div({id:'boxsearch_card_div',cssclass:'inner_box',html:loading(),style:div_style,drag:true});
52 $('boxsearch_card_div').innerHTML=req.responseText;
53 sorttable.makeSortable($('tb_fiche'));
63 * show the ipopup with the form to search a card
66 * @param {int} obj.jrn for the ledger
67 * @param {int} obj.fs route to the action
68 * @param {string} obj.price for the price of the card (field to update)
69 * @param {string} obj.tvaid for the tvaid of the card (field to update)
70 * @param {string} obj.inp input text to update with the quickcode
71 * @param {string} obj.label field to update with the name
72 * @param {string} obj.ctl the id to fill with the HTML answer (ending with _content)
73 * @param {int} obj.acc 1 if accounting are visible
75function search_card(obj)
79 var gDossier=$('gDossier').value;
81 var string_to_search=$(inp).value;
83 var typecard=obj.typecard;
88 if ( obj.inactive_card) {inactive_card=obj.inactive_card.value;}
89 var amount_from_type=0;
90 if ( obj.amount_from_type) {
91 amount_from_type=obj.amount_from_type;
103 var accvis=obj.accvis;
104 if ( accvis == undefined ) {
109 var query=encodeJSON({'gDossier':gDossier,
110 'inp':inp,'label':label,'price':price,'tvaid':tvaid,
111 'ctl':'search_card','op2':'fs','jrn':jrn,
112 'typecard':typecard,'query':string_to_search,'op':'card',
114 'amount_from_type':amount_from_type,
115 'inactive_card':inactive_card
117 if ( $('search_card') ) {
118 removeDiv('search_card');
125 var action=new Ajax.Request ( 'ajax_misc.php',
130 onSuccess:result_card_search
136 alert_box('search_card failed'+e.message);
140 * Display found card and let you select several to link them to an action-followup
141 * @param {obj} obj form object
142 * @param {obj} obj form object
144function action_concerned_save_card(obj)
148 // get all data from FORM
149 var query = obj.serialize();
150 new Ajax.Request("ajax_misc.php", {
153 onSuccess: function (req) {
154 remove_waiting_box();
155 var answer = req.responseXML;
156 var a = answer.getElementsByTagName('ctl');
159 var rec = req.responseText;
160 alert_box('erreur :' + rec);
162 var html = answer.getElementsByTagName('code');
163 var namectl = a[0].firstChild.nodeValue;
164 var nodeXml = html[0];
165 var code_html = getNodeText(nodeXml);
166 code_html = unescape_xml(code_html);
167 $(namectl).update(code_html);
168 removeDiv('search_card');
169 /* if dialog box exist with list other card, then refresh it */
170 if ( document.getElementById("action_concerned_list_dv") ) {
171 action_concerned_list({ag_id:obj.ag_id.value,dossier:obj.gDossier.value});
179 alert_box('action_concerned_save_card' + e.message);
185 * Display the list of other card from a followup action
186 * @returns {undefined}
188function action_concerned_list(p_obj) {
190 var action = new Ajax.Request('ajax_misc.php',
193 parameters: {gDossier: p_obj.dossier, op: 'card', 'op2': "action_concerned_list", "ag_id": p_obj.ag_id
194 ,"ctl":'action_concerned_list_dv'},
196 onSuccess: function (req, txt)
202 sx = window.scrollY + 40;
205 sx = document.body.scrollTop + 60;
207 var div_style = "top:" + sx + "px;";
208 add_div({id: 'action_concerned_list_dv', cssclass: 'inner_box', html: "",
209 style: div_style, drag: true});
210 remove_waiting_box();
211 var answer = req.responseXML;
212 var a = answer.getElementsByTagName('ctl');
215 var rec = req.responseText;
216 alert_box('erreur :' + rec);
218 var html = answer.getElementsByTagName('code');
219 var namectl = a[0].firstChild.nodeValue;
220 var nodeXml = html[0];
221 var code_html = getNodeText(nodeXml);
222 code_html = unescape_xml(code_html);
225 $('action_concerned_list_dv').innerHTML = code_html;
227 alert_box(e.message);
233 alert_box("action_concerned_list" + e.message);
237 * Display form for searching cards to add to action-follow-up
238 *@see ajax_add_concerned_card.php
239 *@param {object} obj form object
240 *@param obj.elements.ag_id id of the action (elements)
241 *@param obj.elements.gDossier folder id
242 *@param obj.elements.query
244function action_concerned_search_card(obj)
256 dossier = obj.dossier; /* From the button */
263 if (obj.elements['gDossier'])
265 dossier = obj.elements['gDossier'].value;
268 if (obj.elements['query']) {
269 inp = obj.elements['query'].value;
272 if (obj.elements['ag_id']) {
273 ag_id = obj.elements['ag_id'].value;
275 if (obj.elements['search_in']) {
276 search_in = obj.elements['search_in'].value;
278 if ( obj.elements['inactive_card']) {
279 inactive_card=obj.elements['inactive_card'].value;
281 if ( obj.elements['search_cat']) {
282 search_cat=obj.elements['search_cat'].value;
286 throw "obj.dossier not found";
289 throw "obj.ag_id not found";
291 var query = encodeJSON({
293 'op2': 'action_add_concerned_card',
299 'search_in':search_in,
300 'inactive_card':inactive_card,
301 'search_cat':search_cat
307 var action = new Ajax.Request('ajax_misc.php',
312 onSuccess: function (req, txt)
315 remove_waiting_box();
316 var answer = req.responseXML;
317 var a = answer.getElementsByTagName('ctl');
320 var rec = req.responseText;
321 alert_box('erreur :' + rec);
323 var html = answer.getElementsByTagName('code');
324 var namectl = a[0].firstChild.nodeValue;
325 var nodeXml = html[0];
326 var code_html = getNodeText(nodeXml);
327 code_html = unescape_xml(code_html);
332 sx = window.scrollY + 40;
336 sx = document.body.scrollTop + 60;
338 var div_style = "top:" + sx + "px;height:52rem";
339 if ( ! $('search_card')) { add_div({id: 'search_card', cssclass: 'inner_box', html: "", style: div_style, drag: true}); }
340 $('search_card').innerHTML = code_html;
342 activate_checkbox_range('select_card_ck');
344 alert_box(e.message);
352 alert_box('search_card failed' + e.message);
359 * when you submit the form for searching a card
361 *@note the same as search_card, except it answer to a FORM and not
364function search_get_card(obj)
366 var dossier=$('gDossier').value;
368 var queryString="gDossier="+dossier;
369 queryString+="&op2=fs&op=card";
371 if ( obj.elements['inp'] )
373 queryString+="&inp="+$F('inp');
375 if ( obj.elements['typecard'] )
377 queryString+="&typecard="+$F('typecard');
379 if ( obj.elements['jrn'] )
381 queryString+="&jrn="+$F('jrn');
383 if ( obj.elements['label'])
385 queryString+="&label="+$F('label');
387 if ( obj.elements['price'])
389 queryString+="&price="+$F('price');
391 if ( obj.elements['tvaid'])
393 queryString+="&tvaid="+$F('tvaid');
395 if( obj.elements['query'])
397 queryString+="&query="+$F('query');
401 queryString+="&ctl="+obj.ctl;
403 if ( obj.elements['accvis'] )
405 queryString+="&accvis="+$F('accvis');
407 queryString+="&accvis=0";
409 if ( obj.elements['amount_from_type']) {
410 queryString+="&amount_from_type="+obj.elements['amount_from_type'].value;
412 if (obj.elements['page_card']) {
413 queryString+="&page_card="+obj.elements["page_card"].value;
415 if ( obj.elements["inactive_card"]) {
416 queryString+="&inactive_card="+obj.elements["inactive_card"].value;
419 queryString=encodeURI(queryString);
420 $('asearch').innerHTML=loading();
422 var action=new Ajax.Request ( 'ajax_misc.php',
425 parameters:queryString,
427 onSuccess:result_card_search
432 * show the answer of ajax request
433 *@param answer in XML
435function result_card_search(req)
440 remove_waiting_box();
441 if ( req.responseText == 'NOCONX') { reconnect();return;}
442 var answer=req.responseXML;
443 var a=answer.getElementsByTagName('ctl');
446 var rec=req.responseText;
447 alert_box ('erreur :'+rec);
449 var html=answer.getElementsByTagName('code');
451 var name_ctl=a[0].firstChild.nodeValue;
453 var code_html=getNodeText(nodeXml);
454 code_html=unescape_xml(code_html);
459 sx=window.scrollY+40;
463 sx=document.body.scrollTop+60;
466 var div_style="top:"+sx+"px;min-height:80%;height:auto";
467 add_div({id:'search_card',cssclass:'inner_box',html:"",style:div_style,drag:false,effect:'blinddown'});
469 $('search_card').innerHTML=code_html;
471 if ($('query')) { $('query').focus();}
475 alert_box(e.message);
479 code_html.evalScripts();
483 alert_box(content[53]+"\n"+e.message);
491 * Set the value of 2 input fields
493* Set the quick code in the first ctrl and the label of the quickcode in the second one. This function is a variant of SetData for
494* some specific need. This function is called if the caller is searchcardCtrl
496*@param p_ctrl the input with the name of the quick code
497*@param p_quickcode the found quick_code
498*@param p_ctrlname the name of the input field with the label
499*@param p_label the label of the quickcode
501function setCtrl(p_ctrl,p_quickcode,p_ctrlname,p_label)
506 ctrl.value=p_quickcode;
508 var ctrl_name=g(p_ctrlname);
511 ctrl_name.value=p_label;
518 * clean the row (the label, price and vat)
519 * @param p_ctl the calling ctrl
521function clean_Fid(p_ctl)
523 nSell=p_ctl+"_price";
525 nTva_id=p_ctl+"_tva_id";
536 $(nTva_id).value="-1";
540function errorFid(request,json)
542 alert_box(content[53]);
544function update_value(text,li)
549 * is called when something change in ICard
550 *@param the input field
553function fill_data_onchange(ctl)
559 * is called when something change in ICard
560 *@param the input field
563function fill_data(text,li)
569 * is called when something change in ICard
570 *@param the input field
573function fill_fin_data_onchange(ctl)
579 * is called when something change in ICard
580 *@param the input field
583function fill_fin_data(text,li)
586 ajax_saldo($(text.id));
589 * show the ipopup window and display the details of a card,
590 * to work some attribute must be set
591 *@param obj.qcode is the qcode, obj.nohistory if you don't want to display
592 * the history button, obj.ro is the popin is readonly
593 *@note you must the gDossier as hidden in the calling page
597function fill_ipopcard(obj)
602 var content='card_'+card_layer;
603 var nTop=170+card_layer;
607 var str_top="top:"+calcy(nTop)+"px";
609 var str_style=str_top+";height:auto;position:absolute";
611 var popup={'id': content,'cssclass':'inner_box2','style':str_style,'html':"",'drag':false};
614 var dossier=$('gDossier').value;
616 if ( $(obj).qcode != undefined )
626 var queryString='gDossier='+dossier;
627 queryString+='&qcode='+qcode;
628 queryString+='&ctl='+content;
629 queryString+='&op2=dc'; // dc for detail card
630 queryString+='&op=card'; // dc for detail card
631 if ( obj.readonly != undefined) {
635 if ( obj.nohistory != undefined) {
636 queryString+='&nohistory';
638 if ( obj.nofollowup != undefined) {
639 queryString+='&nofollowup';
641 queryString=encodeURI(queryString);
642 var action=new Ajax.Request ( 'ajax_misc.php',
645 parameters:queryString,
653 * @param request : object request
654 * @param json : json answer
656function successFill_ipopcard(req,json)
660 if (req.responseText=='NOCONX') { reconnect();return; }
661 var answer=req.responseXML;
662 var a=answer.getElementsByTagName('ctl');
663 var html=answer.getElementsByTagName('code');
667 var rec=req.responseText;
668 alert_box ('erreur :'+rec);
670 var name_ctl=a[0].firstChild.nodeValue;
671 var code_html=getNodeText(html[0]);
672 code_html=unescape_xml(code_html);
674 $(name_ctl).innerHTML=code_html;
678 alert_box(e.message);
682 code_html.evalScripts();
686 alert_box(content[53]+"\n"+e.message);
690 * show the ipopup for selecting a card type, it is a needed step before adding
692 *@param input field (obj) it must have the attribute ipopup
693 * possible attribute :
694 * - filter possible values are deb, cred, fd_id list, -1 means there is no filter
695 * - ref if we want to refresh the window after adding a card
696 * - type type of card (supplier, customer...)
699function select_card_type(obj)
701 var dossier=$('gDossier').value;
703 // give a filter, -1 if not
704 var filter=$(obj).filter;
705 if ( filter==undefined)
709 var content="select_card_div";
710 if ( $(content)){removeDiv(content);}
714 var str_style="top:"+sx+"px;height:auto";
716 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':"",'drag':false};
720 var queryString='gDossier='+dossier;
721 queryString+='&ctl='+content;
722 queryString+='&op2=st'; // st for selecting type
723 queryString+='&op=card'; // st for selecting type
724 if ( $(obj).win_refresh!=undefined)
728 /* if an element id must be updated after creating a new card */
729 if ( $(obj).elementId) {
730 var elementId=$(obj).elementId;
731 queryString+="&eltid="+elementId;
733 queryString+='&fil='+filter;
734 // filter on the ledger, -1 if not
735 var oledger=$(obj).jrn;
736 if (oledger==undefined)
745 queryString+='&ledger='+ledger;
749 queryString+='&cat='+obj.type_cat;
752 var action=new Ajax.Request ( 'ajax_misc.php',
755 parameters:queryString,
757 onSuccess:function(req) {
758 if (req.responseText=='NOCONX') { reconnect(); return;}
760 // Get all the category,
761 var answer=req.responseXML.getElementsByTagName("fiche_cat_item");
762 if (answer.length == 0) {
764 remove_waiting_box();
765 alert_box(getNodeText(req.responseXML.getElementsByTagName("code")[0]));
768 if ( answer.length == 1) {
769 // There is only one category of card
770 dis_blank_card({"ctl":"div_new_card","fd_id":answer[0].firstChild.nodeValue,"op2":"bc","op":"card",gDossier:dossier,"elementId":elementId});
772 remove_waiting_box();
776 $('lk_cat_card_table').focus();
783 *@param obj Form object (obj)
784 * possible attribute :
785 * - filter is the filter but with a fd_id list, -1 means there is no filter
786 * - ref : reload the window after adding card
787 * - content : name of the div
788 *@note dis_blank_card({gDossier:15,fd_id:12,ref:1});
791function dis_blank_card(obj)
793 // first we have to take the form elt we need
794 if ( obj.fd_id.value != undefined )
795 { var fd_id=$F('fd_id'); }
796 else {fd_id=obj.fd_id;}
799 if ( obj.elements && obj.elements['ref'] )
803 var content='div_new_card';
806 var str_style="top:"+nTop+"px;right:"+nLeft+"px;height:auto;width:45rem;";
808 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':false};
812 if ( obj.gDossier.value != undefined ) {
813 var dossier=$('gDossier').value;
815 var dossier=obj.gDossier;
817 var queryString='gDossier='+dossier;
818 queryString+='&ctl='+content;
819 queryString+='&fd_id='+fd_id;
821 queryString+='&op2=bc'; // bc for blank card
822 queryString+='&op=card'; // bc for blank card
823 if (obj.after_save) {
824 queryString+='&after_save='+obj.after_save;
827 if ( obj.elementId) queryString+="&eltid="+obj.elementId;
828 var action=new Ajax.Request ( 'ajax_misc.php',
831 parameters:queryString,
833 onSuccess: function (req,json) {
836 successFill_ipopcard(req,json);
841function form_blank_card(obj)
843 // first we have to take the form elt we need
845 var content='div_new_card';
848 var str_style="top:"+nTop+"px;left:"+nLeft+"px;width:60em;height:auto";
850 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':true};
851 if ( $(content)) {removeDiv(content);}
855 var dossier=$('gDossier').value;
857 var queryString='gDossier='+dossier;
858 queryString+='&ctl='+content;
859 queryString+='&fd_id='+fd_id;
860 queryString+='&op2=bc'; // bc for blank card
861 queryString+='&op=card'; // bc for blank card
863 var action=new Ajax.Request ( 'ajax_misc.php',
866 parameters:queryString,
868 onSuccess:successFill_ipopcard
874 * save the data contained into the form 'save_card'
875 *@param input field (obj) it must have the attribute ipopup
876 * possible attribute :
879function save_card(obj)
881 var content=$(obj).ipopup;
882 var accounting= $(obj)['av_text5'];
883 if ( accounting && accounting.value.length > 40 ) {
884 smoke.alert('Poste comptable trop grand');
888 // Data must be taken here
890 var data=$('save_card').serialize(false);
892 var dossier=$('gDossier').value;
893 var queryString='gDossier='+dossier;
894 queryString+='&ctl='+content;
896 queryString+='&op2=sc'; // sc for save card
897 queryString+='&op=card'; // sc for save card
899 var action=new Ajax.Request ( 'ajax_misc.php',
902 parameters:queryString,
904 onSuccess:function (req,json) {
905 var elt=req.responseXML.getElementsByTagName("eltid");
906 var status=req.responseXML.getElementsByTagName("status");
907 var status_value='OK';
908 var after_savetag=req.responseXML.getElementsByTagName("after_save");
910 if ( status.length !=0) {
911 status_value=getNodeText(status[0]);
913 if ( after_savetag.length !=0 ) {
914 after_save=getNodeText(after_savetag[0]);
916 // if status == OK and after_save == 0
917 // then update the box
918 if ( status_value == 'OK' && after_save == 0) {
922 // if status == OK and after_save == 1
923 // then add a row to the table
924 if ( status_value == 'OK' && after_save == 1) {
925 var table_card=$('fiche_tb_id');
926 f_id=getNodeText(req.responseXML.getElementsByTagName("f_id")[0]);
927 var row=new Element('tr');
928 row.id="row_card"+f_id;
929 row.innerHTML=getNodeText(req.responseXML.getElementsByTagName("code")[0]);
930 table_card.tBodies[0].appendChild(row);
931 new Effect.Highlight(row.id ,{startcolor: '#FAD4D4',endcolor: '#F78082' });
933 if ( table_card.tBodies[0].rows.length % 2 == 0 ) {
934 row.addClassName("odd");
936 row.addClassName("even");
941 remove_waiting_box();
942 if ( elt.length != 0) {
943 var eltid=getNodeText(elt[0]);
945 var eltvalue=req.responseXML.getElementsByTagName("elt_value");
946 $(eltid).value=getNodeText(eltvalue[0]);
947 fill_data_onchange(eltid);
951 if (status_value == "OK") {
952 Effect.SlideUp(content, { duration: 1.0 });
954 if ( status_value == 'NOK') {
955 var xml_message=req.responseXML.getElementsByTagName("code");
956 var message=getNodeText(xml_message[0]);
957 smoke.alert(message);
966 * add a category of card,
967 *@param obj with the attribute
968 * - ipopup the ipopup to show
969 * - type_cat the category of card we want to add
971function add_category(obj)
976 sx=window.scrollY+120;
980 sx=document.body.scrollTop+120;
983 var div_style="top:"+sx+"px;width:60%;height:80%";
985 var div={id:obj.ipopup,
986 cssclass:"inner_box",drag:1,style:div_style};
992 var dossier=$('gDossier').value;
993 var queryString='gDossier='+dossier;
994 queryString+='&op2=ac';
995 queryString+='&op=card';
996 queryString+='&ctl='+obj.ipopup;
999 queryString+='&cat='+obj.type_cat;
1001 var action=new Ajax.Request ( 'ajax_misc.php',
1004 parameters:queryString,
1012 * save the form and add a new category of card
1013 * @param obj if the form object
1015function save_card_category(obj)
1017 if ( ! $(obj).ipopup)
1019 alert_box('Erreur pas d\' attribut ipopup '+obj.id);
1023 // Data must be taken here
1024 data=$('newcat').serialize(false);
1025 var dossier=$('gDossier').value;
1026 var queryString='ctl='+obj.ipopup+'&';
1028 queryString+='&op2=scc'; // sc for save card
1029 queryString+='&op=card'; // sc for save card
1031 var action=new Ajax.Request ( 'ajax_misc.php',
1034 parameters:queryString,
1041 alert_box(e.message);
1047 * Remove a definition of an attribut
1048 *@param attr_def.ad_id
1050 *@param table_id to rm the row
1051 *@param special this pointer of the row
1054function removeCardAttribut(ad_id,gDossier,table_id,row)
1056 var queryString='gDossier='+gDossier;
1057 queryString+='&op=card';
1058 queryString+='&op2=rmfa';
1059 queryString+='&ctl=debug'; // debug id
1060 queryString+='&ad_id='+ad_id;
1061 var action=new Ajax.Request ( 'ajax_misc.php',
1064 parameters:queryString,
1069 deleteRowRec(table_id,row);
1074* update a card in ajax
1076function update_card(obj)
1081 var qs=Form.serialize(name)+'&op2=upc&op=card';
1082 var action=new Ajax.Request ( 'ajax_misc.php',
1087 onSuccess:successFill_ipopcard
1091 alert_box(e.message);
1096 * In Follow-up, update, it is possible to add several card as concerned person or company
1097 * this function save it into the database, display the result and remove the search_card div
1098 * @param {type} p_dossier dossier
1099 * @param {type} p_fiche_id fiche.f_id
1100 * @param {type} p_action_id action_gestion.ag_id
1101 * @returns {undefined} nothing
1103function action_save_concerned(p_form_id) {
1104 var query = encodeJSON({'gDossier': p_dossier, 'f_id': p_fiche_id, 'ag_id': p_action_id,'op':'card','op2':'action_save_concerned','ctl':'unused'});
1105 var a=new Ajax.Request('ajax_misc.php',
1109 onFailure: errorFid,
1110 onSuccess: function (req, txt)
1113 remove_waiting_box();
1114 var answer = req.responseXML;
1115 var a = answer.getElementsByTagName('ctl');
1118 var rec = req.responseText;
1119 alert_box('erreur :' + rec);
1121 var html = answer.getElementsByTagName('code');
1122 var namectl = a[0].firstChild.nodeValue;
1123 var nodeXml=html[0];
1124 var code_html = getNodeText(nodeXml);
1125 code_html = unescape_xml(code_html);
1126 removeDiv('search_card');
1127 $('concerned_card_td').innerHTML = code_html;
1135function action_remove_concerned(p_dossier,p_fiche_id,p_action_id)
1137 var query = encodeJSON({'gDossier': p_dossier, 'f_id': p_fiche_id, 'ag_id': p_action_id,'op':'card','op2':'action_remove_concerned','ctl':'unused'});
1138 var a=new Ajax.Request('ajax_misc.php',
1142 onFailure: errorFid,
1143 onSuccess: function (req, txt)
1146 remove_waiting_box();
1147 var answer = req.responseXML;
1148 var a = answer.getElementsByTagName('ctl');
1151 var rec = req.responseText;
1152 alert_box('erreur :' + rec);
1154 var html = answer.getElementsByTagName('code');
1155 var namectl = a[0].firstChild.nodeValue;
1156 var nodeXml=html[0];
1157 var code_html = getNodeText(nodeXml);
1158 code_html = unescape_xml(code_html);
1159 $('concerned_card_td').innerHTML = code_html;
1160 removeDiv('search_card');
1162 $(namectl).remove();
1165 if ( console) { console.log('Erreur ') + e.message;}
1166 alert_box('action_remove_concerned '+e.message);
1173 * Remove a card after checking it is not used
1174 * @param obj {json} = gDossier,op,op2:rm_card,ctl,f_id
1176function delete_card(obj) {
1177 smoke.confirm("Confirmez ? ", function (e) {
1180 new Ajax.Request("ajax_misc.php", {
1183 onSuccess: function (req) {
1184 remove_waiting_box();
1185 var answer = req.responseXML;
1186 var a = answer.getElementsByTagName('ctl');
1189 var rec = req.responseText;
1190 alert_box('erreur :' + rec);
1192 var html = answer.getElementsByTagName('code');
1193 var namectl = a[0].firstChild.nodeValue;
1194 var nodeXml = html[0];
1195 var code_html = getNodeText(nodeXml);
1196 code_html = unescape_xml(code_html);
1197 if ( code_html == "OK") {
1198 Effect.Fade(obj['ctl'], { duration: 1.5 });
1200 smoke.alert(code_html);
1209 * Display a card , modify it , redraw the row
1210 * before calling this function , it it neeed to have in the web page a hidden card_gdossier with the dossier id
1211 * @param {type} p_fiche_id
1212 * @returns {undefined}
1214function modify_card(p_fiche_id)
1216 /* window with result */
1219 var content = 'card_' + card_layer;
1220 var nTop = 170 + card_layer;
1224 var str_top = fixed_position(250, nTop)
1225 var str_style = str_top + ";width:45em;height:auto;position:absolute";
1227 var popup = {'id': content, 'cssclass': 'inner_box', 'style': str_style, 'html': loading(), 'drag': false};
1232 if ( ! document.getElementById("card_gdossier")) {
1234 console.error("card_gdossier error");
1235 throw ("card_gdossier not set");
1237 var dossier = $('card_gdossier').value;
1240 var action = new Ajax.Request('ajax_misc.php',
1243 parameters: {'gDossier':dossier,"op":'card',"op2":"dc","f_id":p_fiche_id,'ctl':content,after_save:2} ,
1244 onFailure: errorFid,
1245 onSuccess: function (respTxt) {
1252 * Delete a card and remove the row
1253 * before calling this function , it it neeed to have in the web page a hidden card_gdossier with the dossier id
1254 * @param {type} p_fiche_id
1255 * @returns {undefined}
1257function delete_card_id(p_fiche_id)
1259 var row="row_card"+p_fiche_id;
1260 if ( ! document.getElementById("card_gdossier")) {
1262 console.error("card_gdossier error");
1263 throw ("card_gdossier not set");
1265 $(row).addClassName("background-selected");
1266 var dossier = $('card_gdossier').value;
1267 smoke.confirm(content[47], function (e) {
1270 new Ajax.Request("ajax_misc.php", {
1272 parameters: {'gDossier':dossier,"op":'card',"op2":"rm_card","f_id":p_fiche_id,'ctl':row} ,
1273 onSuccess: function (req) {
1274 remove_waiting_box();
1275 var table_card=$('fiche_tb_id');
1276 var answer = req.responseXML;
1277 var a = answer.getElementsByTagName('ctl');
1280 var rec = req.responseText;
1281 alert_box('erreur :' + rec);
1283 var html = answer.getElementsByTagName('code');
1284 var namectl = a[0].firstChild.nodeValue;
1285 var nodeXml = html[0];
1286 var code_html = getNodeText(nodeXml);
1287 code_html = unescape_xml(code_html);
1289 if ((code_html) == "OK") {
1290 Effect.Fade(row, {duration: 0.1});
1291 table_card.tBodies[0].removeChild($(row));
1292 alternate_row_color("fiche_tb_id");
1294 smoke.alert(code_html);
1301 $(row).removeClassName("background-selected");
1309* update a card in ajax , and update a row
1312function card_update_row(obj)
1317 var qs = Form.serialize(name) + '&op2=upr&op=card';
1318 var action = new Ajax.Request('ajax_misc.php',
1322 onFailure: errorFid,
1323 onSuccess: function (req) {
1326 remove_waiting_box();
1328 var answer = req.responseXML;
1329 var a = answer.getElementsByTagName('ctl');
1330 var html = answer.getElementsByTagName('code');
1331 if (a.length === 0) {
1332 var rec = req.responseText;
1333 alert_box('erreur :' + rec);
1335 var name_ctl = "row_card" + obj.f_id.value;
1336 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
1337 code_html = unescape_xml(code_html);
1339 if ( document.getElementById(name_ctl)) {
1341 $(name_ctl).innerHTML = code_html;
1342 new Effect.Highlight(name_ctl ,{startcolor: '#FAD4D4',endcolor: '#F78082' });
1345 $(a[0].firstChild.nodeValue).remove();
1349 alert_box(e.message);
1352 console.error("log answer = " + req.responseText);
1356 code_html.evalScripts();
1360 console.error("log answer = " + req.responseText);
1362 alert_box(content[53] + "\n" + e.message);
1370 alert_box(e.message);
1375 * Display the option of a contact linked in a action-followup
1376 * @param {int} p_action_person_id action_person.ap_id
1377 * @param {int} p_dossier current folder
1379function linked_card_option(p_action_person_id,p_dossier) {
1382 new Ajax.Request("ajax_misc.php",{
1385 ap_id:p_action_person_id,
1388 op2:"display_card_option",
1391 onSuccess:function(req) {
1392 remove_waiting_box();
1393 add_div({ "id":"d_linked_card_option",cssclass:"inner_box",style:"position:fixed;top:30%;min-width:20rem;width:auto;",drag:0});
1394 $("d_linked_card_option").update(req.responseText);
1399 console.error(e.message);
1403 * Save option for the contact
1404 * @param {object} obj form
1405 * @see card_multiple_display_option.php
1406 * @returns {undefined}
1408function save_linked_card_option(obj)
1411 new Ajax.Request("ajax_misc.php",{
1413 parameters:obj.serialize(),
1414 onSuccess:function(req) {
1415 remove_waiting_box();
1416 removeDiv("d_linked_card_option");
1417 $("other_"+obj.action_person_id.value).update(req.responseText);
1418 new Effect.Highlight("other_"+obj.action_person_id.value,{startcolor: '#FAD4D4',endcolor: '#F78082' });
1426 * Manage adding, removing and ordering attributs of a card template (FICHE_DEF), used in the module CCARD
1427 * @param dossier_id {int} Folder
1428 * @param fiche_def_id {int} SQL : FICHE_DEF.FD_ID
1430var CategoryCardDefinition = function (dossier_id, fiche_def_id) {
1431 this.dossier_id = dossier_id;
1432 this.fiche_def_id = fiche_def_id;
1433 this.available_list = 'avail_attribut_id';
1434 this.existing_list = 'attribut_card';
1435 this.op = 'category_card_definition';
1438 * save the order + new attributes, remove old ones
1440CategoryCardDefinition.prototype.save = function () {
1444 var aAttribut=Sortable.serialize(this.existing_list);
1446 gDossier: this.dossier_id,
1447 fiche_def_id: this.fiche_def_id,
1452 var action = new Ajax.Request(
1456 parameters: queryString,
1457 onFailure: ajax_misc_failure,
1458 onSuccess: function (req) {
1459 if (req.responseText == 'NOCONX') {
1463 if ( req.responseText == 'OK') {
1464 smoke.signal('Sauvé',function(e){},{duration:500});
1472 alert_box("CategoryCardDefinition.save" + e.message);
1476 * add an attribut from the DOM Element avail_attribut_id , do add an element in attribut_card and remove from avail_attribut_id
1477 * @param attribut_id {int} attr_def.ad_id , ad_id of attribute
1479CategoryCardDefinition.prototype.add_attribut = function (attribut_id) {
1485 gDossier: this.dossier_id,
1486 fiche_def_id: this.fiche_def_id,
1491 var action = new Ajax.Request(
1495 parameters: queryString,
1496 onFailure: ajax_misc_failure,
1497 onSuccess: function (req) {
1498 if (req.responseText == 'NOCONX') {
1503 // if successfull add id on existing_list and remove from available_list
1505 // remove from available_list
1506 $('avail_attr_' + attribut_id).remove();
1507 var parser = new DOMParser();
1508 var element = parser.parseFromString(req.responseText, 'text/html');
1509 $(here.existing_list).appendChild(element.body.firstChild);
1510 new Effect.Highlight('existing_attr_' + attribut_id, {
1511 startcolor: '#FAD4D4',
1514 Sortable.create('attribut_card', {tag: 'li'});
1515 alternate_row_color_list(here.available_list);
1520 alert_box("CategoryCardDefinition.add_attribut" + e.message);
1524 * remove an attribut from the DOM Element attribut_card , do add an element in avail_attribut_id and remove from attribut_card
1525 * @param attribut_id {int} attr_def.ad_id , ad_id of attribute
1527CategoryCardDefinition.prototype.remove_attribut = function (attribut_id) {
1533 gDossier: this.dossier_id,
1534 fiche_def_id: this.fiche_def_id,
1539 var action = new Ajax.Request(
1543 parameters: queryString,
1544 onFailure: ajax_misc_failure,
1545 onSuccess: function (req) {
1546 if (req.responseText == 'NOCONX') {
1551 // if successfull add id on existing_list and remove from available_list
1553 // remove from available_list
1554 $('existing_attr_' + attribut_id).remove();
1555 var parser = new DOMParser();
1556 var element = parser.parseFromString(req.responseText, 'text/html');
1557 $(here.available_list).appendChild(element.body.firstChild);
1559 alternate_row_color_list(here.available_list);
1560 Sortable.create('attribut_card', {tag: 'li', hoverclass: inner_box});
1565 alert_box("CategoryCardDefinition.remove_attribut" + e.message);