noalyss Version-9
card.js
Go to the documentation of this file.
1/*
2 * This file is part of NOALYSS.
3 *
4 * NOALYSS is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * NOALYSS is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with NOALYSS; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18/* $Revision$ */
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/** \file
23 * \brief javascript for searching a card
24 */
25
26var card_layer=1;
27/**
28 * search a card an display the result into a inner box
29 */
30function boxsearch_card(p_dossier)
31{
32 try
33 {
34 waiting_box();
35 removeDiv('boxsearch_card_div');
36 var queryString="gDossier="+p_dossier+"&op=cardsearch"+"&card="+encodeURI($("card_search").value);
37 var action = new Ajax.Request(
38 "ajax_misc.php" ,
39 {
40 method:'get', parameters:queryString,
41 onFailure:ajax_misc_failure,
42 onSuccess:function(req){
43 remove_waiting_box();
44 if (req.responseText == 'NOCONX') {
45 reconnect();
46 return;
47 }
48 var y=calcy(15);
49 var div_style="position:absolute;"+";top:"+y+"px";
50 add_div({id:'boxsearch_card_div',cssclass:'inner_box',html:loading(),style:div_style,drag:true});
51 $('boxsearch_card_div').innerHTML=req.responseText;
52 sorttable.makeSortable($('tb_fiche'));
53 }
54 }
55 );
56 }catch( e)
57 {
58 alert_box(e.message);
59 }
60}
61/**
62 * show the ipopup with the form to search a card
63 * the properties
64 * @param obj
65 * @param {int} obj.jrn for the ledger
66 * @param {int} obj.fs route to the action
67 * @param {string} obj.price for the price of the card (field to update)
68 * @param {string} obj.tvaid for the tvaid of the card (field to update)
69 * @param {string} obj.inp input text to update with the quickcode
70 * @param {string} obj.label field to update with the name
71 * @param {string} obj.ctl the id to fill with the HTML answer (ending with _content)
72 * @param {int} obj.acc 1 if accounting are visible
73 */
74function search_card(obj)
75{
76 try
77 {
78 var gDossier=$('gDossier').value;
79 var inp=obj.inp;
80 var string_to_search=$(inp).value;
81 var label=obj.label;
82 var typecard=obj.typecard;
83 var price=obj.price;
84 var tvaid=obj.tvaid;
85 var jrn=obj.jrn;
86 var inactive_card=0;
87 if ( obj.inactive_card) {inactive_card=obj.inactive_card.value;}
88 var amount_from_type=0;
89 if ( obj.amount_from_type) {
90 amount_from_type=obj.amount_from_type;
91
92 }
93 if ( jrn==undefined)
94 {
95 if ( g('p_jrn')) {
96 jrn=$('p_jrn').value;
97 }
98 else {
99 jrn=-1;
100 }
101 }
102 var accvis=obj.accvis;
103 if ( accvis == undefined ) {
104 accvis=0;
105 } else {
106 accvis=obj.accvis;
107 }
108 var query=encodeJSON({'gDossier':gDossier,
109 'inp':inp,'label':label,'price':price,'tvaid':tvaid,
110 'ctl':'search_card','op2':'fs','jrn':jrn,
111 'typecard':typecard,'query':string_to_search,'op':'card',
112 'accvis':accvis,
113 'amount_from_type':amount_from_type,
114 'inactive_card':inactive_card
115 });
116 if ( $('search_card') ) {
117 removeDiv('search_card');
118 }
119
120
121 waiting_box();
122
123
124 var action=new Ajax.Request ( 'ajax_misc.php',
125 {
126 method:'get',
127 parameters:query,
128 onFailure:errorFid,
129 onSuccess:result_card_search
130 }
131 );
132 }
133 catch(e)
134 {
135 alert_box('search_card failed'+e.message);
136 }
137}
138/**
139 * Display found card and let you select several to link them to an action-followup
140 * @param {obj} obj form object
141 * @param {obj} obj form object
142 */
143function action_concerned_save_card(obj)
144{
145 try {
146 waiting_box();
147 // get all data from FORM
148 var query = obj.serialize();
149 new Ajax.Request("ajax_misc.php", {
150 method: "POST",
151 parameters: query,
152 onSuccess: function (req) {
153 remove_waiting_box();
154 var answer = req.responseXML;
155 var a = answer.getElementsByTagName('ctl');
156 if (a.length == 0)
157 {
158 var rec = req.responseText;
159 alert_box('erreur :' + rec);
160 }
161 var html = answer.getElementsByTagName('code');
162 var namectl = a[0].firstChild.nodeValue;
163 var nodeXml = html[0];
164 var code_html = getNodeText(nodeXml);
165 code_html = unescape_xml(code_html);
166 $(namectl).update(code_html);
167 removeDiv('search_card');
168 /* if dialog box exist with list other card, then refresh it */
169 if ( document.getElementById("action_concerned_list_dv") ) {
170 action_concerned_list({ag_id:obj.ag_id.value,dossier:obj.gDossier.value});
171 }
172
173 }
174 });
175 } catch (e)
176 {
177
178 alert_box('action_concerned_save_card' + e.message);
179 return false;
180 }
181 return false;
182}
183/**
184 * Display the list of other card from a followup action
185 * @returns {undefined}
186 */
187function action_concerned_list(p_obj) {
188 try {
189 var action = new Ajax.Request('ajax_misc.php',
190 {
191 method: 'get',
192 parameters: {gDossier: p_obj.dossier, op: 'card', 'op2': "action_concerned_list", "ag_id": p_obj.ag_id
193 ,"ctl":'action_concerned_list_dv'},
194 onFailure: errorFid,
195 onSuccess: function (req, txt)
196 {
197 try {
198 var sx = 0;
199 if (window.scrollY)
200 {
201 sx = window.scrollY + 40;
202 } else
203 {
204 sx = document.body.scrollTop + 60;
205 }
206 var div_style = "top:" + sx + "px;";
207 add_div({id: 'action_concerned_list_dv', cssclass: 'inner_box', html: "",
208 style: div_style, drag: true});
209 remove_waiting_box();
210 var answer = req.responseXML;
211 var a = answer.getElementsByTagName('ctl');
212 if (a.length == 0)
213 {
214 var rec = req.responseText;
215 alert_box('erreur :' + rec);
216 }
217 var html = answer.getElementsByTagName('code');
218 var namectl = a[0].firstChild.nodeValue;
219 var nodeXml = html[0];
220 var code_html = getNodeText(nodeXml);
221 code_html = unescape_xml(code_html);
222
223
224 $('action_concerned_list_dv').innerHTML = code_html;
225 } catch (e) {
226 alert_box(e.message);
227 }
228 }
229 }
230 );
231 } catch (e) {
232 alert_box("action_concerned_list" + e.message);
233 }
234}
235/**
236 * Display form for searching cards to add to action-follow-up
237 *@see ajax_add_concerned_card.php
238 *@param {object} obj form object
239 *@param obj.elements.ag_id id of the action (elements)
240 *@param obj.elements.gDossier folder id
241 *@param obj.elements.query
242 */
243function action_concerned_search_card(obj)
244{
245 try
246 {
247 var dossier = 0;
248 var inp="";
249 var ag_id=0;
250 var search_in=-1;
251 var inactive_card=0;
252 var search_cat=-1;
253
254 if (obj.dossier) {
255 dossier = obj.dossier; /* From the button */
256 }
257 if (obj.ag_id) {
258 ag_id=obj.ag_id;
259 }
260 /* from the form */
261 if (obj.elements) {
262 if (obj.elements['gDossier'])
263 {
264 dossier = obj.elements['gDossier'].value;
265 }
266
267 if (obj.elements['query']) {
268 inp = obj.elements['query'].value;
269 }
270
271 if (obj.elements['ag_id']) {
272 ag_id = obj.elements['ag_id'].value;
273 }
274 if (obj.elements['search_in']) {
275 search_in = obj.elements['search_in'].value;
276 }
277 if ( obj.elements['inactive_card']) {
278 inactive_card=obj.elements['inactive_card'].value;
279 }
280 if ( obj.elements['search_cat']) {
281 search_cat=obj.elements['search_cat'].value;
282 }
283 }
284 if (dossier == 0) {
285 throw "obj.dossier not found";
286 }
287 if (ag_id == 0) {
288 throw "obj.ag_id not found";
289 }
290 var query = encodeJSON({
291 'gDossier': dossier,
292 'op2': 'action_add_concerned_card',
293 'query' : inp,
294 'ctl' : 'unused',
295 'ag_id' : ag_id,
296 'op':'card',
297 'accvis':0,
298 'search_in':search_in,
299 'inactive_card':inactive_card,
300 'search_cat':search_cat
301 });
302
303 waiting_box();
304
305
306 var action = new Ajax.Request('ajax_misc.php',
307 {
308 method: 'get',
309 parameters: query,
310 onFailure: errorFid,
311 onSuccess: function (req, txt)
312 {
313 try {
314 remove_waiting_box();
315 var answer = req.responseXML;
316 var a = answer.getElementsByTagName('ctl');
317 if (a.length == 0)
318 {
319 var rec = req.responseText;
320 alert_box('erreur :' + rec);
321 }
322 var html = answer.getElementsByTagName('code');
323 var namectl = a[0].firstChild.nodeValue;
324 var nodeXml = html[0];
325 var code_html = getNodeText(nodeXml);
326 code_html = unescape_xml(code_html);
327
328 var sx = 0;
329 if (window.scrollY)
330 {
331 sx = window.scrollY + 40;
332 }
333 else
334 {
335 sx = document.body.scrollTop + 60;
336 }
337 var div_style = "top:" + sx + "px;height:52rem";
338 if ( ! $('search_card')) { add_div({id: 'search_card', cssclass: 'inner_box', html: "", style: div_style, drag: true}); }
339 $('search_card').innerHTML = code_html;
340 $('query').focus();
341 activate_checkbox_range('select_card_ck');
342 }catch (e) {
343 alert_box(e.message);
344 }
345 }
346 }
347 );
348 }
349 catch (e)
350 {
351 alert_box('search_card failed' + e.message);
352 return false;
353 }
354 return false;
355}
356
357/**
358 * when you submit the form for searching a card
359 *@param obj form
360 *@note the same as search_card, except it answer to a FORM and not
361 * to a click event
362 */
363function search_get_card(obj)
364{
365 var dossier=$('gDossier').value;
366
367 var queryString="gDossier="+dossier;
368 queryString+="&op2=fs&op=card";
369
370 if ( obj.elements['inp'] )
371 {
372 queryString+="&inp="+$F('inp');
373 }
374 if ( obj.elements['typecard'] )
375 {
376 queryString+="&typecard="+$F('typecard');
377 }
378 if ( obj.elements['jrn'] )
379 {
380 queryString+="&jrn="+$F('jrn');
381 }
382 if ( obj.elements['label'])
383 {
384 queryString+="&label="+$F('label');
385 }
386 if ( obj.elements['price'])
387 {
388 queryString+="&price="+$F('price');
389 }
390 if ( obj.elements['tvaid'])
391 {
392 queryString+="&tvaid="+$F('tvaid');
393 }
394 if( obj.elements['query'])
395 {
396 queryString+="&query="+$F('query');
397 }
398 if (obj.ctl )
399 {
400 queryString+="&ctl="+obj.ctl;
401 }
402 if ( obj.elements['accvis'] )
403 {
404 queryString+="&accvis="+$F('accvis');
405 } else {
406 queryString+="&accvis=0";
407 }
408 if ( obj.elements['amount_from_type']) {
409 queryString+="&amount_from_type="+obj.elements['amount_from_type'].value;
410 }
411 if (obj.elements['page_card']) {
412 queryString+="&page_card="+obj.elements["page_card"].value;
413 }
414 if ( obj.elements["inactive_card"]) {
415 queryString+="&inactive_card="+obj.elements["inactive_card"].value;
416 }
417
418 queryString=encodeURI(queryString);
419 $('asearch').innerHTML=loading();
420
421 var action=new Ajax.Request ( 'ajax_misc.php',
422 {
423 method:'get',
424 parameters:queryString,
425 onFailure:errorFid,
426 onSuccess:result_card_search
427 }
428 );
429}
430/**
431 * show the answer of ajax request
432 *@param answer in XML
433 */
434function result_card_search(req)
435{
436 try
437 {
438
439 remove_waiting_box();
440 if ( req.responseText == 'NOCONX') { reconnect();return;}
441 var answer=req.responseXML;
442 var a=answer.getElementsByTagName('ctl');
443 if ( a.length == 0 )
444 {
445 var rec=req.responseText;
446 alert_box ('erreur :'+rec);
447 }
448 var html=answer.getElementsByTagName('code');
449
450 var name_ctl=a[0].firstChild.nodeValue;
451 var nodeXml=html[0];
452 var code_html=getNodeText(nodeXml);
453 code_html=unescape_xml(code_html);
454
455 var sx=0;
456 if ( window.scrollY)
457 {
458 sx=window.scrollY+40;
459 }
460 else
461 {
462 sx=document.body.scrollTop+60;
463 }
464
465 var div_style="top:"+sx+"px;min-height:80%;height:auto";
466 add_div({id:'search_card',cssclass:'inner_box',html:"",style:div_style,drag:false,effect:'blinddown'});
467
468 $('search_card').innerHTML=code_html;
469
470 if ($('query')) { $('query').focus();}
471 }
472 catch (e)
473 {
474 alert_box(e.message);
475 }
476 try
477 {
478 code_html.evalScripts();
479 }
480 catch(e)
481 {
482 alert_box(content[53]+"\n"+e.message);
483 }
484
485}
486
487
488
489/**
490 * Set the value of 2 input fields
491*
492* 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
493* some specific need. This function is called if the caller is searchcardCtrl
494*
495*@param p_ctrl the input with the name of the quick code
496*@param p_quickcode the found quick_code
497*@param p_ctrlname the name of the input field with the label
498*@param p_label the label of the quickcode
499*/
500function setCtrl(p_ctrl,p_quickcode,p_ctrlname,p_label)
501{
502 var ctrl=g(p_ctrl);
503 if ( ctrl )
504 {
505 ctrl.value=p_quickcode;
506 }
507 var ctrl_name=g(p_ctrlname);
508 if ( ctrl_name )
509 {
510 ctrl_name.value=p_label;
511 }
512}
513
514
515
516/**
517 * clean the row (the label, price and vat)
518 * @param p_ctl the calling ctrl
519 */
520function clean_Fid(p_ctl)
521{
522 nSell=p_ctl+"_price";
523 nBuy=p_ctl+"_price";
524 nTva_id=p_ctl+"_tva_id";
525 if ( $(nSell) )
526 {
527 $(nSell).value="";
528 }
529 if ( $(nBuy) )
530 {
531 $(nBuy).value="";
532 }
533 if ( $(nTva_id) )
534 {
535 $(nTva_id).value="-1";
536 }
537
538}
539function errorFid(request,json)
540{
541 alert_box(content[53]);
542}
543function update_value(text,li)
544{
545 ajaxFid(text);
546}
547/**
548 * is called when something change in ICard
549 *@param the input field
550 *@see ICard
551 */
552function fill_data_onchange(ctl)
553{
554 ajaxFid(ctl);
555
556}
557/**
558 * is called when something change in ICard
559 *@param the input field
560 *@see ICard
561 */
562function fill_data(text,li)
563{
564 ajaxFid(text);
565
566}
567/**
568 * is called when something change in ICard
569 *@param the input field
570 *@see ICard
571 */
572function fill_fin_data_onchange(ctl)
573{
574 ajaxFid(ctl);
575 ajax_saldo(ctl.id);
576}
577/**
578 * is called when something change in ICard
579 *@param the input field
580 *@see ICard
581 */
582function fill_fin_data(text,li)
583{
584 ajaxFid(text);
585 ajax_saldo($(text.id));
586}
587/**
588 * show the ipopup window and display the details of a card,
589 * to work some attribute must be set
590 *@param obj.qcode is the qcode, obj.nohistory if you don't want to display
591 * the history button, obj.ro is the popin is readonly
592 *@note you must the gDossier as hidden in the calling page
593 *
594 *@see ajax_card.php
595 */
596function fill_ipopcard(obj)
597{
598
599 card_layer++;
600
601 var content='card_'+card_layer;
602 var nTop=170+card_layer;
603 if ( nTop > 300 ) {
604 nTop=170;
605 }
606 var str_top="top:"+calcy(nTop)+"px";
607
608 var str_style=str_top+";width:45em;height:auto;position:absolute";
609 waiting_box();
610 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':"",'drag':false};
611
612 add_div(popup);
613 var dossier=$('gDossier').value;
614 var qcode='';
615 if ( $(obj).qcode != undefined )
616 {
617 qcode=obj.qcode;
618 }
619 else
620 {
621 qcode=$(obj).value;
622 }
623 // ctl=$(obj).id;
624
625 var queryString='gDossier='+dossier;
626 queryString+='&qcode='+qcode;
627 queryString+='&ctl='+content;
628 queryString+='&op2=dc'; // dc for detail card
629 queryString+='&op=card'; // dc for detail card
630 if ( obj.readonly != undefined) {
631 queryString+='&ro';
632 }
633
634 if ( obj.nohistory != undefined) {
635 queryString+='&nohistory';
636 }
637 if ( obj.nofollowup != undefined) {
638 queryString+='&nofollowup';
639 }
640 queryString=encodeURI(queryString);
641 var action=new Ajax.Request ( 'ajax_misc.php',
642 {
643 method:'get',
644 parameters:queryString,
645 onFailure:errorFid,
646 onSuccess:fill_box
647 }
648 );
649}
650/**
651 *
652 * @param request : object request
653 * @param json : json answer
654*/
655function successFill_ipopcard(req,json)
656{
657 try
658 {
659 if (req.responseText=='NOCONX') { reconnect();return; }
660 var answer=req.responseXML;
661 var a=answer.getElementsByTagName('ctl');
662 var html=answer.getElementsByTagName('code');
663
664 if ( a.length == 0 )
665 {
666 var rec=req.responseText;
667 alert_box ('erreur :'+rec);
668 }
669 var name_ctl=a[0].firstChild.nodeValue;
670 var code_html=getNodeText(html[0]);
671 code_html=unescape_xml(code_html);
672
673 $(name_ctl).innerHTML=code_html;
674 }
675 catch (e)
676 {
677 alert_box(e.message);
678 }
679 try
680 {
681 code_html.evalScripts();
682 }
683 catch(e)
684 {
685 alert_box(content[53]+"\n"+e.message);
686 }
687}
688/**
689 * show the ipopup for selecting a card type, it is a needed step before adding
690 * a card
691 *@param input field (obj) it must have the attribute ipopup
692 * possible attribute :
693 * - filter possible values are deb, cred, fd_id list, -1 means there is no filter
694 * - ref if we want to refresh the window after adding a card
695 * - type type of card (supplier, customer...)
696 *@see ajax_card.php
697 */
698function select_card_type(obj)
699{
700 var dossier=$('gDossier').value;
701 var elementId="";
702 // give a filter, -1 if not
703 var filter=$(obj).filter;
704 if ( filter==undefined)
705 {
706 filter=-1;
707 }
708 var content="select_card_div";
709 if ( $(content)){removeDiv(content);}
710 var sx=0;
711 sx=calcy(160);
712
713 var str_style="top:"+sx+"px;height:auto";
714 waiting_box();
715 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':"",'drag':false};
716
717
718
719 var queryString='gDossier='+dossier;
720 queryString+='&ctl='+content;
721 queryString+='&op2=st'; // st for selecting type
722 queryString+='&op=card'; // st for selecting type
723 if ( $(obj).win_refresh!=undefined)
724 {
725 queryString+='&ref';
726 }
727 /* if an element id must be updated after creating a new card */
728 if ( $(obj).elementId) {
729 var elementId=$(obj).elementId;
730 queryString+="&eltid="+elementId;
731 }
732 queryString+='&fil='+filter;
733 // filter on the ledger, -1 if not
734 var oledger=$(obj).jrn;
735 if (oledger==undefined)
736 {
737 ledger=-1;
738 }
739 else
740 {
741 ledger=$(obj).jrn;
742 }
743
744 queryString+='&ledger='+ledger;
745
746 if ( obj.type_cat)
747 {
748 queryString+='&cat='+obj.type_cat;
749 }
750
751 var action=new Ajax.Request ( 'ajax_misc.php',
752 {
753 method:'get',
754 parameters:queryString,
755 onFailure:errorFid,
756 onSuccess:function(req) {
757 if (req.responseText=='NOCONX') { reconnect(); return;}
758 add_div(popup);
759 // Get all the category,
760 var answer=req.responseXML.getElementsByTagName("fiche_cat_item");
761 if (answer.length == 0) {
762 removeDiv(content);
763 remove_waiting_box();
764 alert_box(getNodeText(req.responseXML.getElementsByTagName("code")[0]));
765 return;
766 }
767 if ( answer.length == 1) {
768 // There is only one category of card
769 dis_blank_card({"ctl":"div_new_card","fd_id":answer[0].firstChild.nodeValue,"op2":"bc","op":"card",gDossier:dossier,"elementId":elementId});
770 removeDiv(content);
771 remove_waiting_box();
772 return;
773 }
774 fill_box(req);
775 $('lk_cat_card_table').focus();
776 }
777 }
778 );
779}
780/**
781 * Show a blank card
782 *@param obj Form object (obj)
783 * possible attribute :
784 * - filter is the filter but with a fd_id list, -1 means there is no filter
785 * - ref : reload the window after adding card
786 * - content : name of the div
787 *@note dis_blank_card({gDossier:15,fd_id:12,ref:1});
788 *@see ajax_card.php
789 */
790function dis_blank_card(obj)
791{
792 // first we have to take the form elt we need
793 if ( obj.fd_id.value != undefined )
794 { var fd_id=$F('fd_id'); }
795 else {fd_id=obj.fd_id;}
796
797 var ref="";
798 if ( obj.elements && obj.elements['ref'] )
799 {
800 ref='&ref';
801 }
802 var content='div_new_card';
803 var nTop=calcy(150);
804 var nLeft=posX;
805 var str_style="top:"+nTop+"px;right:"+nLeft+"px;height:auto";
806
807 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':false};
808
809 add_div(popup);
810
811 if ( obj.gDossier.value != undefined ) {
812 var dossier=$('gDossier').value;
813 } else {
814 var dossier=obj.gDossier;
815 }
816 var queryString='gDossier='+dossier;
817 queryString+='&ctl='+content;
818 queryString+='&fd_id='+fd_id;
819 queryString+=ref;
820 queryString+='&op2=bc'; // bc for blank card
821 queryString+='&op=card'; // bc for blank card
822 if (obj.after_save) {
823 queryString+='&after_save='+obj.after_save;
824 }
825
826 if ( obj.elementId) queryString+="&eltid="+obj.elementId;
827 var action=new Ajax.Request ( 'ajax_misc.php',
828 {
829 method:'get',
830 parameters:queryString,
831 onFailure:errorFid,
832 onSuccess: function (req,json) {
833
834
835 successFill_ipopcard(req,json);
836 }
837 }
838 );
839}
840function form_blank_card(obj)
841{
842 // first we have to take the form elt we need
843 var fd_id=obj.fd_id;
844 var content='div_new_card';
845 var nTop=posY-40;
846 var nLeft=posX-20;
847 var str_style="top:"+nTop+"px;left:"+nLeft+"px;width:60em;height:auto";
848
849 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':true};
850 if ( $(content)) {removeDiv(content);}
851 add_div(popup);
852
853
854 var dossier=$('gDossier').value;
855
856 var queryString='gDossier='+dossier;
857 queryString+='&ctl='+content;
858 queryString+='&fd_id='+fd_id;
859 queryString+='&op2=bc'; // bc for blank card
860 queryString+='&op=card'; // bc for blank card
861
862 var action=new Ajax.Request ( 'ajax_misc.php',
863 {
864 method:'get',
865 parameters:queryString,
866 onFailure:errorFid,
867 onSuccess:successFill_ipopcard
868 }
869 );
870}
871
872/**
873 * save the data contained into the form 'save_card'
874 *@param input field (obj) it must have the attribute ipopup
875 * possible attribute :
876 *@see ajax_card.php
877 */
878function save_card(obj)
879{
880 var content=$(obj).ipopup;
881 var accounting= $(obj)['av_text5'];
882 if ( accounting && accounting.value.length > 40 ) {
883 smoke.alert('Poste comptable trop grand');
884 return false;
885 }
886
887 // Data must be taken here
888
889 var data=$('save_card').serialize(false);
890 waiting_box();
891 var dossier=$('gDossier').value;
892 var queryString='gDossier='+dossier;
893 queryString+='&ctl='+content;
894 queryString+=data;
895 queryString+='&op2=sc'; // sc for save card
896 queryString+='&op=card'; // sc for save card
897
898 var action=new Ajax.Request ( 'ajax_misc.php',
899 {
900 method:'post',
901 parameters:queryString,
902 onFailure:errorFid,
903 onSuccess:function (req,json) {
904 var elt=req.responseXML.getElementsByTagName("eltid");
905 var status=req.responseXML.getElementsByTagName("status");
906 var status_value='OK';
907 var after_savetag=req.responseXML.getElementsByTagName("after_save");
908 var after_save=0;
909 if ( status.length !=0) {
910 status_value=getNodeText(status[0]);
911 }
912 if ( after_savetag.length !=0 ) {
913 after_save=getNodeText(after_savetag[0]);
914 }
915 // if status == OK and after_save == 0
916 // then update the box
917 if ( status_value == 'OK' && after_save == 0) {
918 fill_box(req,json);
919 }
920
921 // if status == OK and after_save == 1
922 // then add a row to the table
923 if ( status_value == 'OK' && after_save == 1) {
924 var table_card=$('fiche_tb_id');
925 f_id=getNodeText(req.responseXML.getElementsByTagName("f_id")[0]);
926 var row=new Element('tr');
927 row.id="row_card"+f_id;
928 row.innerHTML=getNodeText(req.responseXML.getElementsByTagName("code")[0]);
929 table_card.tBodies[0].appendChild(row);
930 new Effect.Highlight(row.id ,{startcolor: '#FAD4D4',endcolor: '#F78082' });
931 //
932 if ( table_card.tBodies[0].rows.length % 2 == 0 ) {
933 row.addClassName("odd");
934 } else {
935 row.addClassName("even");
936
937 }
938 }
939
940 remove_waiting_box();
941 if ( elt.length != 0) {
942 var eltid=getNodeText(elt[0]);
943 if ( eltid !="") {
944 var eltvalue=req.responseXML.getElementsByTagName("elt_value");
945 $(eltid).value=getNodeText(eltvalue[0]);
946 fill_data_onchange(eltid);
947 $(eltid).focus();
948 }
949 }
950 if (status_value == "OK") {
951 Effect.SlideUp(content, { duration: 1.0 });
952 }
953 if ( status_value == 'NOK') {
954 var xml_message=req.responseXML.getElementsByTagName("code");
955 var message=getNodeText(xml_message[0]);
956 smoke.alert(message);
957 }
958
959
960 }
961 }
962 );
963}
964/**
965 * add a category of card,
966 *@param obj with the attribute
967 * - ipopup the ipopup to show
968 * - type_cat the category of card we want to add
969 */
970function add_category(obj)
971{
972 var sx=0;
973 if ( window.scrollY)
974 {
975 sx=window.scrollY+120;
976 }
977 else
978 {
979 sx=document.body.scrollTop+120;
980 }
981
982 var div_style="top:"+sx+"px;width:60%;height:80%";
983 // show ipopup
984 var div={id:obj.ipopup,
985 cssclass:"inner_box",drag:1,style:div_style};
986 if ( $(div) ) {
987 removeDiv(div);
988 }
989 add_div(div);
990 waiting_box();
991 var dossier=$('gDossier').value;
992 var queryString='gDossier='+dossier;
993 queryString+='&op2=ac';
994 queryString+='&op=card';
995 queryString+='&ctl='+obj.ipopup;
996 if ( obj.type_cat)
997 {
998 queryString+='&cat='+obj.type_cat;
999 }
1000 var action=new Ajax.Request ( 'ajax_misc.php',
1001 {
1002 method:'get',
1003 parameters:queryString,
1004 onFailure:errorFid,
1005 onSuccess:fill_box
1006 }
1007 );
1008
1009}
1010/**
1011 * save the form and add a new category of card
1012 * @param obj if the form object
1013 */
1014function save_card_category(obj)
1015{
1016 if ( ! $(obj).ipopup)
1017 {
1018 alert_box('Erreur pas d\' attribut ipopup '+obj.id);
1019 return;
1020 };
1021try {
1022 // Data must be taken here
1023 data=$('newcat').serialize(false);
1024 var dossier=$('gDossier').value;
1025 var queryString='ctl='+obj.ipopup+'&';
1026 queryString+=data;
1027 queryString+='&op2=scc'; // sc for save card
1028 queryString+='&op=card'; // sc for save card
1029
1030 var action=new Ajax.Request ( 'ajax_misc.php',
1031 {
1032 method:'get',
1033 parameters:queryString,
1034 onFailure:errorFid,
1035 onSuccess:fill_box
1036 }
1037 );
1038 } catch(e)
1039 {
1040 alert_box(e.message);
1041 return false;
1042 }
1043 return false;
1044}
1045/**
1046 * Remove a definition of an attribut
1047 *@param attr_def.ad_id
1048 *@param gDossier
1049 *@param table_id to rm the row
1050 *@param special this pointer of the row
1051 */
1052
1053function removeCardAttribut(ad_id,gDossier,table_id,row)
1054{
1055 var queryString='gDossier='+gDossier;
1056 queryString+='&op=card';
1057 queryString+='&op2=rmfa';
1058 queryString+='&ctl=debug'; // debug id
1059 queryString+='&ad_id='+ad_id;
1060 var action=new Ajax.Request ( 'ajax_misc.php',
1061 {
1062 method:'get',
1063 parameters:queryString,
1064 onFailure:null,
1065 onSuccess:null
1066 }
1067 );
1068 deleteRowRec(table_id,row);
1069
1070
1071}
1072/**
1073* update a card in ajax
1074*/
1075function update_card(obj)
1076{
1077try {
1078 var name=obj.id;
1079
1080 var qs=Form.serialize(name)+'&op2=upc&op=card';
1081 var action=new Ajax.Request ( 'ajax_misc.php',
1082 {
1083 method:'get',
1084 parameters:qs,
1085 onFailure:errorFid,
1086 onSuccess:successFill_ipopcard
1087 }
1088 );
1089 } catch (e) {
1090 alert_box(e.message);
1091 return false;
1092 }
1093}
1094/***
1095 * In Follow-up, update, it is possible to add several card as concerned person or company
1096 * this function save it into the database, display the result and remove the search_card div
1097 * @param {type} p_dossier dossier
1098 * @param {type} p_fiche_id fiche.f_id
1099 * @param {type} p_action_id action_gestion.ag_id
1100 * @returns {undefined} nothing
1101 */
1102function action_save_concerned(p_form_id) {
1103 var query = encodeJSON({'gDossier': p_dossier, 'f_id': p_fiche_id, 'ag_id': p_action_id,'op':'card','op2':'action_save_concerned','ctl':'unused'});
1104 var a=new Ajax.Request('ajax_misc.php',
1105 {
1106 method: 'get',
1107 parameters: query,
1108 onFailure: errorFid,
1109 onSuccess: function (req, txt)
1110 {
1111 try {
1112 remove_waiting_box();
1113 var answer = req.responseXML;
1114 var a = answer.getElementsByTagName('ctl');
1115 if (a.length == 0)
1116 {
1117 var rec = req.responseText;
1118 alert_box('erreur :' + rec);
1119 }
1120 var html = answer.getElementsByTagName('code');
1121 var namectl = a[0].firstChild.nodeValue;
1122 var nodeXml=html[0];
1123 var code_html = getNodeText(nodeXml);
1124 code_html = unescape_xml(code_html);
1125 removeDiv('search_card');
1126 $('concerned_card_td').innerHTML = code_html;
1127 } catch (e) {
1128
1129 }
1130 }
1131 }
1132 );
1133 }
1134function action_remove_concerned(p_dossier,p_fiche_id,p_action_id)
1135{
1136 var query = encodeJSON({'gDossier': p_dossier, 'f_id': p_fiche_id, 'ag_id': p_action_id,'op':'card','op2':'action_remove_concerned','ctl':'unused'});
1137 var a=new Ajax.Request('ajax_misc.php',
1138 {
1139 method: 'get',
1140 parameters: query,
1141 onFailure: errorFid,
1142 onSuccess: function (req, txt)
1143 {
1144 try {
1145 remove_waiting_box();
1146 var answer = req.responseXML;
1147 var a = answer.getElementsByTagName('ctl');
1148 if (a.length == 0)
1149 {
1150 var rec = req.responseText;
1151 alert_box('erreur :' + rec);
1152 }
1153 var html = answer.getElementsByTagName('code');
1154 var namectl = a[0].firstChild.nodeValue;
1155 var nodeXml=html[0];
1156 var code_html = getNodeText(nodeXml);
1157 code_html = unescape_xml(code_html);
1158 $('concerned_card_td').innerHTML = code_html;
1159 removeDiv('search_card');
1160
1161 $(namectl).remove();
1162
1163 } catch (e) {
1164 if ( console) { console.log('Erreur ') + e.message;}
1165 alert_box('action_remove_concerned '+e.message);
1166 }
1167 }
1168 }
1169 );
1170 }
1171/**
1172 * Remove a card after checking it is not used
1173 * @param object obj {gDossier,op,op2:rm_card,ctl,f_id}
1174 */
1175function delete_card(obj) {
1176 smoke.confirm("Confirmez ? ", function (e) {
1177 if (e) {
1178 waiting_box();
1179 new Ajax.Request("ajax_misc.php", {
1180 "method": "get",
1181 parameters: obj,
1182 onSuccess: function (req) {
1183 remove_waiting_box();
1184 var answer = req.responseXML;
1185 var a = answer.getElementsByTagName('ctl');
1186 if (a.length == 0)
1187 {
1188 var rec = req.responseText;
1189 alert_box('erreur :' + rec);
1190 }
1191 var html = answer.getElementsByTagName('code');
1192 var namectl = a[0].firstChild.nodeValue;
1193 var nodeXml = html[0];
1194 var code_html = getNodeText(nodeXml);
1195 code_html = unescape_xml(code_html);
1196 if ( code_html == "OK") {
1197 Effect.Fade(obj['ctl'], { duration: 1.5 });
1198 } else {
1199 smoke.alert(code_html);
1200 }
1201 }
1202
1203 });
1204 }
1205 });
1206}
1207/**
1208 * Display a card , modify it , redraw the row
1209 * before calling this function , it it neeed to have in the web page a hidden card_gdossier with the dossier id
1210 * @param {type} p_fiche_id
1211 * @returns {undefined}
1212 */
1213function modify_card(p_fiche_id)
1214{
1215 /* window with result */
1216 card_layer++;
1217
1218 var content = 'card_' + card_layer;
1219 var nTop = 170 + card_layer;
1220 if (nTop > 300) {
1221 nTop = 170;
1222 }
1223 var str_top = fixed_position(250, nTop)
1224 var str_style = str_top + ";width:45em;height:auto;position:absolute";
1225
1226 var popup = {'id': content, 'cssclass': 'inner_box', 'style': str_style, 'html': loading(), 'drag': false};
1227
1228 add_div(popup);
1229
1230 /* dossier id */
1231 if ( ! document.getElementById("card_gdossier")) {
1232
1233 console.error("card_gdossier error");
1234 throw ("card_gdossier not set");
1235 }
1236 var dossier = $('card_gdossier').value;
1237
1238
1239 var action = new Ajax.Request('ajax_misc.php',
1240 {
1241 method: 'get',
1242 parameters: {'gDossier':dossier,"op":'card',"op2":"dc","f_id":p_fiche_id,'ctl':content,after_save:2} ,
1243 onFailure: errorFid,
1244 onSuccess: function (respTxt) {
1245 fill_box(respTxt);
1246 }
1247 }
1248 );
1249}
1250/**
1251 * Delete a card and remove the row
1252 * before calling this function , it it neeed to have in the web page a hidden card_gdossier with the dossier id
1253 * @param {type} p_fiche_id
1254 * @returns {undefined}
1255 */
1256function delete_card_id(p_fiche_id)
1257{
1258 var row="row_card"+p_fiche_id;
1259 if ( ! document.getElementById("card_gdossier")) {
1260
1261 console.error("card_gdossier error");
1262 throw ("card_gdossier not set");
1263 }
1264 $(row).addClassName("background-selected");
1265 var dossier = $('card_gdossier').value;
1266 smoke.confirm(content[47], function (e) {
1267 if (e) {
1268 waiting_box();
1269 new Ajax.Request("ajax_misc.php", {
1270 "method": "get",
1271 parameters: {'gDossier':dossier,"op":'card',"op2":"rm_card","f_id":p_fiche_id,'ctl':row} ,
1272 onSuccess: function (req) {
1273 remove_waiting_box();
1274 var table_card=$('fiche_tb_id');
1275 var answer = req.responseXML;
1276 var a = answer.getElementsByTagName('ctl');
1277 if (a.length == 0)
1278 {
1279 var rec = req.responseText;
1280 alert_box('erreur :' + rec);
1281 }
1282 var html = answer.getElementsByTagName('code');
1283 var namectl = a[0].firstChild.nodeValue;
1284 var nodeXml = html[0];
1285 var code_html = getNodeText(nodeXml);
1286 code_html = unescape_xml(code_html);
1287
1288 if ((code_html) == "OK") {
1289 Effect.Fade(row, {duration: 0.1});
1290 table_card.tBodies[0].removeChild($(row));
1291 alternate_row_color("fiche_tb_id");
1292 } else {
1293 smoke.alert(code_html);
1294
1295 }
1296 }
1297
1298 });
1299 } else{
1300 $(row).removeClassName("background-selected");
1301
1302 }
1303 });
1304
1305}
1306
1307/**
1308* update a card in ajax , and update a row
1309*
1310*/
1311function card_update_row(obj)
1312{
1313 try {
1314 var name = obj.id;
1315
1316 var qs = Form.serialize(name) + '&op2=upr&op=card';
1317 var action = new Ajax.Request('ajax_misc.php',
1318 {
1319 method: 'get',
1320 parameters: qs,
1321 onFailure: errorFid,
1322 onSuccess: function (req) {
1323 try {
1324
1325 remove_waiting_box();
1326
1327 var answer = req.responseXML;
1328 var a = answer.getElementsByTagName('ctl');
1329 var html = answer.getElementsByTagName('code');
1330 if (a.length === 0) {
1331 var rec = req.responseText;
1332 alert_box('erreur :' + rec);
1333 }
1334 var name_ctl = "row_card" + obj.f_id.value;
1335 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
1336 code_html = unescape_xml(code_html);
1337
1338 if ( document.getElementById(name_ctl)) {
1339 // update the row
1340 $(name_ctl).innerHTML = code_html;
1341 new Effect.Highlight(name_ctl ,{startcolor: '#FAD4D4',endcolor: '#F78082' });
1342
1343 }
1344 $(a[0].firstChild.nodeValue).remove();
1345
1346
1347 } catch (e) {
1348 alert_box(e.message);
1349 if (console) {
1350 console.error(e);
1351 console.error("log answer = " + req.responseText);
1352 }
1353 }
1354 try {
1355 code_html.evalScripts();
1356 } catch (e) {
1357 if (console) {
1358 console.error(e);
1359 console.error("log answer = " + req.responseText);
1360 }
1361 alert_box(content[53] + "\n" + e.message);
1362 }
1363
1364
1365 }
1366 }
1367 );
1368 } catch (e) {
1369 alert_box(e.message);
1370 return false;
1371 }
1372}
1373/**
1374 * Display the option of a contact linked in a action-followup
1375 * @param {int} p_action_person_id action_person.ap_id
1376 * @param {int} p_dossier current folder
1377 */
1378function linked_card_option(p_action_person_id,p_dossier) {
1379 try {
1380 waiting_box();
1381 new Ajax.Request("ajax_misc.php",{
1382 method:"get",
1383 parameters: {
1384 ap_id:p_action_person_id,
1385 gDossier:p_dossier,
1386 op:"card",
1387 op2:"display_card_option",
1388 ctl:"notused"
1389 },
1390 onSuccess:function(req) {
1391 remove_waiting_box();
1392 add_div({ "id":"d_linked_card_option",cssclass:"inner_box",style:"position:fixed;top:30%;min-width:20rem;width:auto;",drag:0});
1393 $("d_linked_card_option").update(req.responseText);
1394
1395 }
1396 });
1397 } catch (e) {
1398 console.error(e.message);
1399 }
1400}
1401/**
1402 * Save option for the contact
1403 * @param {object} obj form
1404 * @see card_multiple_display_option.php
1405 * @returns {undefined}
1406 */
1407function save_linked_card_option(obj)
1408{
1409 waiting_box();
1410 new Ajax.Request("ajax_misc.php",{
1411 method:"post",
1412 parameters:obj.serialize(),
1413 onSuccess:function(req) {
1414 remove_waiting_box();
1415 removeDiv("d_linked_card_option");
1416 $("other_"+obj.action_person_id.value).update(req.responseText);
1417 new Effect.Highlight("other_"+obj.action_person_id.value,{startcolor: '#FAD4D4',endcolor: '#F78082' });
1418 }
1419 });
1420 return false;
1421}