noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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/**
23 * @file
24 * javascript for searching a card
25 */
26
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(id$("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;z-index:"+get_next_layer();
50 add_div({id:'boxsearch_card_div',cssclass:'inner_box',html:loading(),style:div_style,drag:true});
51 id$('boxsearch_card_div').innerHTML=req.responseText;
52 sorttable.makeSortable(id$('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=id$('gDossier').value;
79 var inp=obj.inp;
80 var string_to_search=id$(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 ( document.getElementById('p_jrn')) {
96 jrn=id$('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 ( document.getElementById('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 id$(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;z-index:"+get_next_layer();
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 id$('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;z-index:"+get_next_layer();
338 if ( ! document.getElementById('search_card')) { add_div({id: 'search_card', cssclass: 'inner_box', html: "", style: div_style, drag: true}); }
339 id$('search_card').innerHTML = code_html;
340 id$('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 * @see ajax_card.php
363 */
364function search_get_card(obj)
365{
366 var dossier=id$('gDossier').value;
367
368 var queryString="gDossier="+dossier;
369 queryString+="&op2=fs&op=card";
370
371 if ( obj.elements['inp'] )
372 {
373 queryString+="&inp="+$F('inp');
374 }
375 if ( obj.elements['typecard'] )
376 {
377 queryString+="&typecard="+$F('typecard');
378 }
379 if ( obj.elements['jrn'] )
380 {
381 queryString+="&jrn="+$F('jrn');
382 }
383 if ( obj.elements['label'])
384 {
385 queryString+="&label="+$F('label');
386 }
387 if ( obj.elements['price'])
388 {
389 queryString+="&price="+$F('price');
390 }
391 if ( obj.elements['tvaid'])
392 {
393 queryString+="&tvaid="+$F('tvaid');
394 }
395 if( obj.elements['query'])
396 {
397 queryString+="&query="+$F('query');
398 }
399 if (obj.ctl )
400 {
401 queryString+="&ctl="+obj.ctl;
402 }
403 if ( obj.elements['accvis'] )
404 {
405 queryString+="&accvis="+$F('accvis');
406 } else {
407 queryString+="&accvis=0";
408 }
409 if ( obj.elements['amount_from_type']) {
410 queryString+="&amount_from_type="+obj.elements['amount_from_type'].value;
411 }
412 if (obj.elements['page_card']) {
413 queryString+="&page_card="+obj.elements["page_card"].value;
414 }
415 if ( obj.elements["inactive_card"]) {
416 queryString+="&inactive_card="+obj.elements["inactive_card"].value;
417 }
418
419 queryString=encodeURI(queryString);
420 id$('asearch').innerHTML=loading();
421
422 var action=new Ajax.Request ( 'ajax_misc.php',
423 {
424 method:'get',
425 parameters:queryString,
426 onFailure:errorFid,
427 onSuccess:result_card_search
428 }
429 );
430}
431/**
432 * show the answer of ajax request
433 * @see search_get_card
434 *@param answer in XML
435 */
436function result_card_search(req)
437{
438 try
439 {
440
441 remove_waiting_box();
442 if ( req.responseText == 'NOCONX') { reconnect();return;}
443 var answer=req.responseXML;
444 var a=answer.getElementsByTagName('ctl');
445 if ( a.length == 0 )
446 {
447 var rec=req.responseText;
448 alert_box ('erreur :'+rec);
449 }
450 var html=answer.getElementsByTagName('code');
451
452 var name_ctl=a[0].firstChild.nodeValue;
453 var nodeXml=html[0];
454 var code_html=getNodeText(nodeXml);
455 code_html=unescape_xml(code_html);
456
457 var sx=0;
458 if ( window.scrollY)
459 {
460 sx=window.scrollY+40;
461 }
462 else
463 {
464 sx=document.body.scrollTop+60;
465 }
466
467 var div_style="top:"+sx+"px;min-height:80%;height:auto;z-index:"+get_next_layer();;
468 add_div({id:'search_card',cssclass:'inner_box',html:"",style:div_style,drag:false,effect:'blinddown'});
469
470 id$('search_card').innerHTML=code_html;
471
472 if (document.getElementById('query')) { id$('query').focus();}
473 }
474 catch (e)
475 {
476 alert_box(e.message);
477 }
478 try
479 {
480 code_html.evalScripts();
481 }
482 catch(e)
483 {
484 alert_box(content[53]+"\n"+e.message);
485 }
486
487}
488
489
490
491/**
492 * Set the value of 2 input fields
493*
494* 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
495* some specific need. This function is called if the caller is searchcardCtrl
496*
497*@param p_ctrl the input with the name of the quick code
498*@param p_quickcode the found quick_code
499*@param p_ctrlname the name of the input field with the label
500*@param p_label the label of the quickcode
501*/
502function setCtrl(p_ctrl,p_quickcode,p_ctrlname,p_label)
503{
504 var ctrl=id$(p_ctrl);
505 if ( ctrl )
506 {
507 ctrl.value=p_quickcode;
508 }
509 var ctrl_name=id$(p_ctrlname);
510 if ( ctrl_name )
511 {
512 ctrl_name.value=p_label;
513 }
514}
515
516
517
518
519function errorFid(request,json)
520{
521 alert_box(content[53]);
522}
523function update_value(text,li)
524{
525 ajaxFid(text);
526}
527/**
528 * is called when something change in ICard
529 *@param the input field
530 *@see ICard
531 */
532function fill_data_onchange(ctl)
533{
534 ajaxFid(ctl);
535
536}
537/**
538 * is called when something change in ICard
539 *@param the input field
540 *@see ICard
541 */
542function fill_data(text,li)
543{
544 ajaxFid(text);
545
546}
547/**
548 * is called when something change in ICard
549 *@param the input field
550 *@see ICard
551 */
552function fill_fin_data_onchange(ctl)
553{
554 ajaxFid(ctl);
555 ajax_saldo(ctl.id);
556}
557/**
558 * is called when something change in ICard
559 *@param the input field
560 *@see ICard
561 */
562function fill_fin_data(text,li)
563{
564 ajaxFid(text);
565 ajax_saldo(id$(text.id));
566}
567/**
568 * show the ipopup window and display the details of a card,
569 * to work some attribute must be set
570 *@param obj.qcode is the qcode, obj.nohistory if you don't want to display
571 * the history button, obj.ro is the popin is readonly
572 *@note you must the gDossier as hidden in the calling page
573 *
574 *@see ajax_card.php
575 */
576function fill_ipopcard(obj)
577{
578
579 var card_layer=get_next_layer();
580
581 var content='card_'+card_layer;
582 var nTop=170+card_layer;
583 if ( nTop > 300 ) {
584 nTop=170;
585 }
586 var str_top="top:"+calcy(nTop)+"px";
587
588 var str_style=str_top+";height:auto;position:absolute;z-index:"+get_next_layer();
589 waiting_box();
590 var popup={'id': content,'cssclass':'inner_box2','style':str_style,'html':"",'drag':false};
591
592 add_div(popup);
593 var dossier=id$('gDossier').value;
594 var qcode='';
595 if ( obj.qcode != undefined )
596 {
597 qcode=obj.qcode;
598 }
599 else
600 {
601 qcode=id$(obj).value;
602 }
603 // ctl=id$(obj).id;
604
605 var queryString='gDossier='+dossier;
606 queryString+='&qcode='+qcode;
607 queryString+='&ctl='+content;
608 queryString+='&op2=dc'; // dc for detail card
609 queryString+='&op=card'; // dc for detail card
610 if ( obj.readonly != undefined) {
611 queryString+='&ro';
612 }
613
614 if ( obj.nohistory != undefined) {
615 queryString+='&nohistory';
616 }
617 if ( obj.nofollowup != undefined) {
618 queryString+='&nofollowup';
619 }
620 queryString=encodeURI(queryString);
621 var action=new Ajax.Request ( 'ajax_misc.php',
622 {
623 method:'get',
624 parameters:queryString,
625 onFailure:errorFid,
626 onSuccess:fill_box
627 }
628 );
629}
630/**
631 *
632 * @param request : object request
633 * @param json : json answer
634*/
635function successFill_ipopcard(req,json)
636{
637 try
638 {
639 if (req.responseText=='NOCONX') { reconnect();return; }
640 var answer=req.responseXML;
641 var a=answer.getElementsByTagName('ctl');
642 var html=answer.getElementsByTagName('code');
643
644 if ( a.length == 0 )
645 {
646 var rec=req.responseText;
647 alert_box ('erreur :'+rec);
648 }
649 var name_ctl=a[0].firstChild.nodeValue;
650 var code_html=getNodeText(html[0]);
651 code_html=unescape_xml(code_html);
652
653 id$(name_ctl).innerHTML=code_html;
654 }
655 catch (e)
656 {
657 alert_box(e.message);
658 }
659 try
660 {
661 code_html.evalScripts();
662 }
663 catch(e)
664 {
665 alert_box(content[53]+"\n"+e.message);
666 }
667}
668/**
669 * show the ipopup for selecting a card type, it is a needed step before adding
670 * a card
671 *@param input field (obj) it must have the attribute ipopup
672 * possible attribute :
673 * - filter possible values are deb, cred, fd_id list, -1 means there is no filter
674 * - ref if we want to refresh the window after adding a card
675 * - type type of card (supplier, customer...)
676 *@see ajax_card.php
677 */
678function select_card_type(obj)
679{
680 var dossier=id$('gDossier').value;
681 var elementId="";
682 // give a filter, -1 if not
683 var filter=id$(obj).filter;
684 if ( filter==undefined)
685 {
686 filter=-1;
687 }
688 var content="select_card_div";
689 if ( document.getElementById(content)){removeDiv(content);}
690 var sx=0;
691 sx=calcy(160);
692
693 var str_style="top:"+sx+"px;height:auto;z-index:"+get_next_layer();
694 waiting_box();
695 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':"",'drag':false};
696
697
698
699 var queryString='gDossier='+dossier;
700 queryString+='&ctl='+content;
701 queryString+='&op2=st'; // st for selecting type
702 queryString+='&op=card'; // st for selecting type
703 if ( id$(obj).win_refresh!=undefined)
704 {
705 queryString+='&ref';
706 }
707 /* if an element id must be updated after creating a new card */
708 if ( id$(obj).elementId) {
709 var elementId=id$(obj).elementId;
710 queryString+="&eltid="+elementId;
711 }
712 queryString+='&fil='+filter;
713 // filter on the ledger, -1 if not
714 var oledger=id$(obj).jrn;
715 if (oledger==undefined)
716 {
717 ledger=-1;
718 }
719 else
720 {
721 ledger=id$(obj).jrn;
722 }
723
724 queryString+='&ledger='+ledger;
725
726 if ( obj.type_cat)
727 {
728 queryString+='&cat='+obj.type_cat;
729 }
730
731 var action=new Ajax.Request ( 'ajax_misc.php',
732 {
733 method:'get',
734 parameters:queryString,
735 onFailure:errorFid,
736 onSuccess:function(req) {
737 if (req.responseText=='NOCONX') { reconnect(); return;}
738 add_div(popup);
739 // Get all the category,
740 var answer=req.responseXML.getElementsByTagName("fiche_cat_item");
741 if (answer.length == 0) {
742 removeDiv(content);
743 remove_waiting_box();
744 alert_box(getNodeText(req.responseXML.getElementsByTagName("code")[0]));
745 return;
746 }
747 if ( answer.length == 1) {
748 // There is only one category of card
749 dis_blank_card({"ctl":"div_new_card","fd_id":answer[0].firstChild.nodeValue,"op2":"bc","op":"card",gDossier:dossier,"elementId":elementId});
750 removeDiv(content);
751 remove_waiting_box();
752 return;
753 }
754 fill_box(req);
755 id$('lk_cat_card_table').focus();
756 }
757 }
758 );
759}
760/**
761 * Show a blank card
762 *@param obj Form object (obj)
763 * possible attribute :
764 * - filter is the filter but with a fd_id list, -1 means there is no filter
765 * - ref : reload the window after adding card
766 * - content : name of the div
767 *@note dis_blank_card({gDossier:15,fd_id:12,ref:1});
768 *@see ajax_card.php
769 */
770function dis_blank_card(obj)
771{
772 // first we have to take the form elt we need
773 if ( obj.fd_id.value != undefined )
774 { var fd_id=$F('fd_id'); }
775 else {fd_id=obj.fd_id;}
776
777 var ref="";
778 if ( obj.elements && obj.elements['ref'] )
779 {
780 ref='&ref';
781 }
782 var content='div_new_card';
783 var nTop=calcy(150);
784 var nLeft=posX;
785 var str_style="top:"+nTop+"px;right:"+nLeft+"px;height:auto;width:45rem;z-index:"+get_next_layer();
786
787 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':false};
788
789 add_div(popup);
790
791 if ( obj.gDossier.value != undefined ) {
792 var dossier=id$('gDossier').value;
793 } else {
794 var dossier=obj.gDossier;
795 }
796 var queryString='gDossier='+dossier;
797 queryString+='&ctl='+content;
798 queryString+='&fd_id='+fd_id;
799 queryString+=ref;
800 queryString+='&op2=bc'; // bc for blank card
801 queryString+='&op=card'; // bc for blank card
802 if (obj.after_save) {
803 queryString+='&after_save='+obj.after_save;
804 }
805
806 if ( obj.elementId) queryString+="&eltid="+obj.elementId;
807 var action=new Ajax.Request ( 'ajax_misc.php',
808 {
809 method:'get',
810 parameters:queryString,
811 onFailure:errorFid,
812 onSuccess: function (req,json) {
813
814
815 successFill_ipopcard(req,json);
816 }
817 }
818 );
819}
820function form_blank_card(obj)
821{
822 // first we have to take the form elt we need
823 var fd_id=obj.fd_id;
824 var content='div_new_card';
825 var nTop=posY-40;
826 var nLeft=posX-20;
827 var str_style="top:"+nTop+"px;left:"+nLeft+"px;width:60em;height:auto;z-index:"+get_next_layer();
828
829 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':true};
830 if ( document.getElementById(content)) {removeDiv(content);}
831 add_div(popup);
832
833
834 var dossier=id$('gDossier').value;
835
836 var queryString='gDossier='+dossier;
837 queryString+='&ctl='+content;
838 queryString+='&fd_id='+fd_id;
839 queryString+='&op2=bc'; // bc for blank card
840 queryString+='&op=card'; // bc for blank card
841
842 var action=new Ajax.Request ( 'ajax_misc.php',
843 {
844 method:'get',
845 parameters:queryString,
846 onFailure:errorFid,
847 onSuccess:successFill_ipopcard
848 }
849 );
850}
851
852/**
853 * save the data contained into the form 'save_card'
854 *@param input field (obj) it must have the attribute ipopup
855 * possible attribute :
856 *@see ajax_card.php
857 */
858function save_card(obj)
859{
860 var content=id$(obj).ipopup;
861 var accounting= id$(obj)['av_text5'];
862 if ( accounting && accounting.value.length > 40 ) {
863 smoke.alert('Poste comptable trop grand');
864 return false;
865 }
866
867 // Data must be taken here
868
869 var data=id$('save_card').serialize(false);
870 waiting_box();
871 var dossier=id$('gDossier').value;
872 var queryString='gDossier='+dossier;
873 queryString+='&ctl='+content;
874 queryString+=data;
875 queryString+='&op2=sc'; // sc for save card
876 queryString+='&op=card'; // sc for save card
877
878 var action=new Ajax.Request ( 'ajax_misc.php',
879 {
880 method:'post',
881 parameters:queryString,
882 onFailure:errorFid,
883 onSuccess:function (req,json) {
884 var elt=req.responseXML.getElementsByTagName("eltid");
885 var status=req.responseXML.getElementsByTagName("status");
886 var status_value='OK';
887 var after_savetag=req.responseXML.getElementsByTagName("after_save");
888 var after_save=0;
889 if ( status.length !=0) {
890 status_value=getNodeText(status[0]);
891 }
892 if ( after_savetag.length !=0 ) {
893 after_save=getNodeText(after_savetag[0]);
894 }
895 // if status == OK and after_save == 0
896 // then update the box
897 if ( status_value == 'OK' && after_save == 0) {
898 fill_box(req,json);
899 }
900
901 // if status == OK and after_save == 1
902 // then add a row to the table
903 if ( status_value == 'OK' && after_save == 1) {
904 var table_card=id$('fiche_tb_id');
905 f_id=getNodeText(req.responseXML.getElementsByTagName("f_id")[0]);
906 var row=new Element('tr');
907 row.id="row_card"+f_id;
908 row.innerHTML=getNodeText(req.responseXML.getElementsByTagName("code")[0]);
909 table_card.tBodies[0].appendChild(row);
910 new Effect.Highlight(row.id ,{startcolor: '#FAD4D4',endcolor: '#F78082' });
911 //
912 if ( table_card.tBodies[0].rows.length % 2 == 0 ) {
913 row.addClassName("odd");
914 } else {
915 row.addClassName("even");
916
917 }
918 }
919
920 remove_waiting_box();
921 if ( elt.length != 0) {
922 var eltid=getNodeText(elt[0]);
923 if ( eltid !="") {
924 var eltvalue=req.responseXML.getElementsByTagName("elt_value");
925 id$(eltid).value=getNodeText(eltvalue[0]);
926 fill_data_onchange(eltid);
927 id$(eltid).focus();
928 }
929 }
930 if (status_value == "OK") {
931 Effect.SlideUp(content, { duration: 1.0 });
932 }
933 if ( status_value == 'NOK') {
934 var xml_message=req.responseXML.getElementsByTagName("code");
935 var message=getNodeText(xml_message[0]);
936 smoke.alert(message);
937 }
938
939
940 }
941 }
942 );
943}
944/**
945 * add a category of card,
946 *@param obj with the attribute
947 * - ipopup the ipopup to show
948 * - type_cat the category of card we want to add
949 */
950function add_category(obj)
951{
952 var sx=0;
953 if ( window.scrollY)
954 {
955 sx=window.scrollY+120;
956 }
957 else
958 {
959 sx=document.body.scrollTop+120;
960 }
961
962 var div_style="top:"+sx+"px;width:60%;height:80%;z-index:"+get_next_layer();
963 // show ipopup
964 var div={id:obj.ipopup,
965 cssclass:"inner_box",drag:1,style:div_style};
966 if ( document.getElementById(div) ) {
967 removeDiv(div);
968 }
969 add_div(div);
970 waiting_box();
971 var dossier=id$('gDossier').value;
972 var queryString='gDossier='+dossier;
973 queryString+='&op2=ac';
974 queryString+='&op=card';
975 queryString+='&ctl='+obj.ipopup;
976 if ( obj.type_cat)
977 {
978 queryString+='&cat='+obj.type_cat;
979 }
980 var action=new Ajax.Request ( 'ajax_misc.php',
981 {
982 method:'get',
983 parameters:queryString,
984 onFailure:errorFid,
985 onSuccess:fill_box
986 }
987 );
988
989}
990/**
991 * save the form and add a new category of card
992 * @param obj if the form object
993 */
994function save_card_category(obj)
995{
996 if ( ! $(obj).ipopup)
997 {
998 alert_box('Erreur pas d\' attribut ipopup '+obj.id);
999 return;
1000 };
1001try {
1002 // Data must be taken here
1003 data=id$('newcat').serialize(false);
1004 var dossier=id$('gDossier').value;
1005 var queryString='ctl='+obj.ipopup+'&';
1006 queryString+=data;
1007 queryString+='&op2=scc'; // sc for save card
1008 queryString+='&op=card'; // sc for save card
1009
1010 var action=new Ajax.Request ( 'ajax_misc.php',
1011 {
1012 method:'POST',
1013 parameters:queryString,
1014 onFailure:errorFid,
1015 onSuccess:function (req)
1016 {
1017 fill_box(req);
1018 // populate
1019 var answer = req.responseXML;
1020 var a = answer.getElementsByTagName('id');
1021 var b = answer.getElementsByTagName('name');
1022 if ( a.length == 1 && b.length == 1) {
1023 let option=new Element('option');
1024 option.value=getNodeText(a[0]);
1025 option.text=getNodeText(b[0]);
1026 id$('cat').add(option);
1027 }
1028 }
1029 }
1030 );
1031 } catch(e)
1032 {
1033
1034 alert_box(e.message);
1035 return false;
1036 }
1037 return false;
1038}
1039/**
1040 * Remove a definition of an attribut
1041 *@param attr_def.ad_id
1042 *@param gDossier
1043 *@param table_id to rm the row
1044 *@param special this pointer of the row
1045 */
1046
1047function removeCardAttribut(ad_id,gDossier,table_id,row)
1048{
1049 var queryString='gDossier='+gDossier;
1050 queryString+='&op=card';
1051 queryString+='&op2=rmfa';
1052 queryString+='&ctl=debug'; // debug id
1053 queryString+='&ad_id='+ad_id;
1054 var action=new Ajax.Request ( 'ajax_misc.php',
1055 {
1056 method:'get',
1057 parameters:queryString,
1058 onFailure:null,
1059 onSuccess:null
1060 }
1061 );
1062 deleteRowRec(table_id,row);
1063
1064
1065}
1066/**
1067* update a card in ajax
1068*/
1069function update_card(obj)
1070{
1071try {
1072 var name=obj.id;
1073
1074 var qs=Form.serialize(name)+'&op2=upc&op=card';
1075 var action=new Ajax.Request ( 'ajax_misc.php',
1076 {
1077 method:'get',
1078 parameters:qs,
1079 onFailure:errorFid,
1080 onSuccess:successFill_ipopcard
1081 }
1082 );
1083 } catch (e) {
1084 alert_box(e.message);
1085 return false;
1086 }
1087}
1088/***
1089 * In Follow-up, update, it is possible to add several card as concerned person or company
1090 * this function save it into the database, display the result and remove the search_card div
1091 * @param {type} p_dossier dossier
1092 * @param {type} p_fiche_id fiche.f_id
1093 * @param {type} p_action_id action_gestion.ag_id
1094 * @returns {undefined} nothing
1095 */
1096function action_save_concerned(p_form_id) {
1097 var query = encodeJSON({'gDossier': p_dossier, 'f_id': p_fiche_id, 'ag_id': p_action_id,'op':'card','op2':'action_save_concerned','ctl':'unused'});
1098 var a=new Ajax.Request('ajax_misc.php',
1099 {
1100 method: 'get',
1101 parameters: query,
1102 onFailure: errorFid,
1103 onSuccess: function (req, txt)
1104 {
1105 try {
1106 remove_waiting_box();
1107 var answer = req.responseXML;
1108 var a = answer.getElementsByTagName('ctl');
1109 if (a.length == 0)
1110 {
1111 var rec = req.responseText;
1112 alert_box('erreur :' + rec);
1113 }
1114 var html = answer.getElementsByTagName('code');
1115 var namectl = a[0].firstChild.nodeValue;
1116 var nodeXml=html[0];
1117 var code_html = getNodeText(nodeXml);
1118 code_html = unescape_xml(code_html);
1119 removeDiv('search_card');
1120 id$('concerned_card_td').innerHTML = code_html;
1121 } catch (e) {
1122
1123 }
1124 }
1125 }
1126 );
1127 }
1128function action_remove_concerned(p_dossier,p_fiche_id,p_action_id)
1129{
1130 var query = encodeJSON({'gDossier': p_dossier, 'f_id': p_fiche_id, 'ag_id': p_action_id,'op':'card','op2':'action_remove_concerned','ctl':'unused'});
1131 var a=new Ajax.Request('ajax_misc.php',
1132 {
1133 method: 'get',
1134 parameters: query,
1135 onFailure: errorFid,
1136 onSuccess: function (req, txt)
1137 {
1138 try {
1139 remove_waiting_box();
1140 var answer = req.responseXML;
1141 var a = answer.getElementsByTagName('ctl');
1142 if (a.length == 0)
1143 {
1144 var rec = req.responseText;
1145 alert_box('erreur :' + rec);
1146 }
1147 var html = answer.getElementsByTagName('code');
1148 var namectl = a[0].firstChild.nodeValue;
1149 var nodeXml=html[0];
1150 var code_html = getNodeText(nodeXml);
1151 code_html = unescape_xml(code_html);
1152 id$('concerned_card_td').innerHTML = code_html;
1153 removeDiv('search_card');
1154
1155 id$(namectl).remove();
1156
1157 } catch (e) {
1158 if ( console) { console.log('Erreur ') + e.message;}
1159 alert_box('action_remove_concerned '+e.message);
1160 }
1161 }
1162 }
1163 );
1164 }
1165/**
1166 * Remove a card after checking it is not used
1167 * @param obj {json} = gDossier,op,op2:rm_card,ctl,f_id
1168 */
1169function delete_card(obj) {
1170 smoke.confirm("Confirmez ? ", function (e) {
1171 if (e) {
1172 waiting_box();
1173 new Ajax.Request("ajax_misc.php", {
1174 "method": "get",
1175 parameters: obj,
1176 onSuccess: function (req) {
1177 remove_waiting_box();
1178 var answer = req.responseXML;
1179 var a = answer.getElementsByTagName('ctl');
1180 if (a.length == 0)
1181 {
1182 var rec = req.responseText;
1183 alert_box('erreur :' + rec);
1184 }
1185 var html = answer.getElementsByTagName('code');
1186 var namectl = a[0].firstChild.nodeValue;
1187 var nodeXml = html[0];
1188 var code_html = getNodeText(nodeXml);
1189 code_html = unescape_xml(code_html);
1190 if ( code_html == "OK") {
1191 Effect.Fade(obj['ctl'], { duration: 1.5 });
1192 } else {
1193 smoke.alert(code_html);
1194 }
1195 }
1196
1197 });
1198 }
1199 });
1200}
1201/**
1202 * Display a card , modify it , redraw the row
1203 * before calling this function , it it neeed to have in the web page a hidden card_gdossier with the dossier id
1204 * @param {type} p_fiche_id
1205 * @returns {undefined}
1206 */
1207function modify_card(p_fiche_id)
1208{
1209 /* window with result */
1210 var card_layer=get_next_layer();
1211
1212 var content = 'card_' + card_layer;
1213 var nTop = 170 + card_layer;
1214 if (nTop > 300) {
1215 nTop = 170;
1216 }
1217 var str_top = fixed_position(250, nTop)
1218 var str_style = str_top + ";width:45em;height:auto;position:absolute";
1219
1220 var popup = {'id': content, 'cssclass': 'inner_box', 'style': str_style, 'html': loading(), 'drag': false};
1221
1222 add_div(popup);
1223
1224 /* dossier id */
1225 if ( ! document.getElementById("card_gdossier")) {
1226
1227 console.error("card_gdossier error");
1228 throw ("card_gdossier not set");
1229 }
1230 var dossier = id$('card_gdossier').value;
1231
1232
1233 var action = new Ajax.Request('ajax_misc.php',
1234 {
1235 method: 'get',
1236 parameters: {'gDossier':dossier,"op":'card',"op2":"dc","f_id":p_fiche_id,'ctl':content,after_save:2} ,
1237 onFailure: errorFid,
1238 onSuccess: function (respTxt) {
1239 fill_box(respTxt);
1240 }
1241 }
1242 );
1243}
1244/**
1245 * Delete a card and remove the row
1246 * before calling this function , it it neeed to have in the web page a hidden card_gdossier with the dossier id
1247 * @param {type} p_fiche_id
1248 * @returns {undefined}
1249 */
1250function delete_card_id(p_fiche_id)
1251{
1252 var row="row_card"+p_fiche_id;
1253 if ( ! document.getElementById("card_gdossier")) {
1254
1255 console.error("card_gdossier error");
1256 throw ("card_gdossier not set");
1257 }
1258 id$(row).addClassName("background-selected");
1259 var dossier = id$('card_gdossier').value;
1260 smoke.confirm(content[47], function (e) {
1261 if (e) {
1262 waiting_box();
1263 new Ajax.Request("ajax_misc.php", {
1264 "method": "get",
1265 parameters: {'gDossier':dossier,"op":'card',"op2":"rm_card","f_id":p_fiche_id,'ctl':row} ,
1266 onSuccess: function (req) {
1267 remove_waiting_box();
1268 var table_card=id$('fiche_tb_id');
1269 var answer = req.responseXML;
1270 var a = answer.getElementsByTagName('ctl');
1271 if (a.length == 0)
1272 {
1273 var rec = req.responseText;
1274 alert_box('erreur :' + rec);
1275 }
1276 var html = answer.getElementsByTagName('code');
1277 var namectl = a[0].firstChild.nodeValue;
1278 var nodeXml = html[0];
1279 var code_html = getNodeText(nodeXml);
1280 code_html = unescape_xml(code_html);
1281
1282 if ((code_html) == "OK") {
1283 Effect.Fade(row, {duration: 0.1});
1284 table_card.tBodies[0].removeChild(id$(row));
1285 alternate_row_color("fiche_tb_id");
1286 } else {
1287 smoke.alert(code_html);
1288
1289 }
1290 }
1291
1292 });
1293 } else{
1294 id$(row).removeClassName("background-selected");
1295
1296 }
1297 });
1298
1299}
1300
1301/**
1302* update a card in ajax , and update a row
1303*
1304*/
1305function card_update_row(obj)
1306{
1307 try {
1308 var name = obj.id;
1309
1310 var qs = Form.serialize(name) + '&op2=upr&op=card';
1311 var action = new Ajax.Request('ajax_misc.php',
1312 {
1313 method: 'get',
1314 parameters: qs,
1315 onFailure: errorFid,
1316 onSuccess: function (req) {
1317 try {
1318
1319 remove_waiting_box();
1320
1321 var answer = req.responseXML;
1322 var a = answer.getElementsByTagName('ctl');
1323 var html = answer.getElementsByTagName('code');
1324 if (a.length === 0) {
1325 var rec = req.responseText;
1326 alert_box('erreur :' + rec);
1327 }
1328 var name_ctl = "row_card" + obj.f_id.value;
1329 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
1330 code_html = unescape_xml(code_html);
1331
1332 if ( document.getElementById(name_ctl)) {
1333 // update the row
1334 id$(name_ctl).innerHTML = code_html;
1335 new Effect.Highlight(name_ctl ,{startcolor: '#FAD4D4',endcolor: '#F78082' });
1336
1337 }
1338 id$(a[0].firstChild.nodeValue).remove();
1339
1340
1341 } catch (e) {
1342 alert_box(e.message);
1343 if (console) {
1344 console.error(e);
1345 console.error("log answer = " + req.responseText);
1346 }
1347 }
1348 try {
1349 code_html.evalScripts();
1350 } catch (e) {
1351 if (console) {
1352 console.error(e);
1353 console.error("log answer = " + req.responseText);
1354 }
1355 alert_box(content[53] + "\n" + e.message);
1356 }
1357
1358
1359 }
1360 }
1361 );
1362 } catch (e) {
1363 alert_box(e.message);
1364 return false;
1365 }
1366}
1367/**
1368 * Display the option of a contact linked in a action-followup
1369 * @param {int} p_action_person_id action_person.ap_id
1370 * @param {int} p_dossier current folder
1371 */
1372function linked_card_option(p_action_person_id,p_dossier) {
1373 try {
1374 waiting_box();
1375 new Ajax.Request("ajax_misc.php",{
1376 method:"get",
1377 parameters: {
1378 ap_id:p_action_person_id,
1379 gDossier:p_dossier,
1380 op:"card",
1381 op2:"display_card_option",
1382 ctl:"notused"
1383 },
1384 onSuccess:function(req) {
1385 remove_waiting_box();
1386 add_div({ "id":"d_linked_card_option",cssclass:"inner_box",style:"position:fixed;top:30%;min-width:20rem;width:auto;",drag:0});
1387 id$("d_linked_card_option").update(req.responseText);
1388
1389 }
1390 });
1391 } catch (e) {
1392 console.error(e.message);
1393 }
1394}
1395/**
1396 * Save option for the contact
1397 * @param {object} obj form
1398 * @see card_multiple_display_option.php
1399 * @returns {undefined}
1400 */
1401function save_linked_card_option(obj)
1402{
1403 waiting_box();
1404 new Ajax.Request("ajax_misc.php",{
1405 method:"post",
1406 parameters:obj.serialize(),
1407 onSuccess:function(req) {
1408 remove_waiting_box();
1409 removeDiv("d_linked_card_option");
1410 id$("other_"+obj.action_person_id.value).update(req.responseText);
1411 new Effect.Highlight("other_"+obj.action_person_id.value,{startcolor: '#FAD4D4',endcolor: '#F78082' });
1412 }
1413 });
1414 return false;
1415}
1416
1417/**
1418 * @class
1419 * Manage adding, removing and ordering attributs of a card template (FICHE_DEF), used in the module CCARD
1420 * @param dossier_id {int} Folder
1421 * @param fiche_def_id {int} SQL : FICHE_DEF.FD_ID
1422 */
1423var CategoryCardDefinition = function (dossier_id, fiche_def_id) {
1424 this.dossier_id = dossier_id;
1425 this.fiche_def_id = fiche_def_id;
1426 this.available_list = 'avail_attribut_id';
1427 this.existing_list = 'attribut_card';
1428 this.op = 'category_card_definition';
1429}
1430/**
1431 * save the order + new attributes, remove old ones
1432 */
1433CategoryCardDefinition.prototype.save = function () {
1434
1435 try {
1436 var here = this;
1437 var aAttribut=Sortable.serialize(this.existing_list);
1438 var queryString = {
1439 gDossier: this.dossier_id,
1440 fiche_def_id: this.fiche_def_id,
1441 op: this.op,
1442 op2: 'save',
1443 attribut:aAttribut
1444 };
1445 var action = new Ajax.Request(
1446 "ajax_misc.php",
1447 {
1448 method: 'POST',
1449 parameters: queryString,
1450 onFailure: ajax_misc_failure,
1451 onSuccess: function (req) {
1452 if (req.responseText == 'NOCONX') {
1453 reconnect();
1454 return;
1455 }
1456 if ( req.responseText == 'OK') {
1457 smoke.signal('Sauvé',function(e){},{duration:500});
1458 }
1459
1460
1461 }
1462 }
1463 );
1464 } catch (e) {
1465 alert_box("CategoryCardDefinition.save" + e.message);
1466 }
1467};
1468/**
1469 * add an attribut from the DOM Element avail_attribut_id , do add an element in attribut_card and remove from avail_attribut_id
1470 * @param attribut_id {int} attr_def.ad_id , ad_id of attribute
1471 */
1472CategoryCardDefinition.prototype.add_attribut = function (attribut_id) {
1473
1474
1475 try {
1476 var here = this;
1477 var queryString = {
1478 gDossier: this.dossier_id,
1479 fiche_def_id: this.fiche_def_id,
1480 op: this.op,
1481 op2: 'add',
1482 ad_id: attribut_id
1483 };
1484 var action = new Ajax.Request(
1485 "ajax_misc.php",
1486 {
1487 method: 'GET',
1488 parameters: queryString,
1489 onFailure: ajax_misc_failure,
1490 onSuccess: function (req) {
1491 if (req.responseText == 'NOCONX') {
1492 reconnect();
1493 return;
1494 }
1495
1496 // if successfull add id on existing_list and remove from available_list
1497
1498 // remove from available_list
1499 id$('avail_attr_' + attribut_id).remove();
1500 var parser = new DOMParser();
1501 var element = parser.parseFromString(req.responseText, 'text/html');
1502 id$(here.existing_list).appendChild(element.body.firstChild);
1503 new Effect.Highlight('existing_attr_' + attribut_id, {
1504 startcolor: '#FAD4D4',
1505 endcolor: '#F78082'
1506 });
1507 Sortable.create('attribut_card', {tag: 'li'});
1508 alternate_row_color_list(here.available_list);
1509 }
1510 }
1511 );
1512 } catch (e) {
1513 alert_box("CategoryCardDefinition.add_attribut" + e.message);
1514 }
1515};
1516/**
1517 * remove an attribut from the DOM Element attribut_card , do add an element in avail_attribut_id and remove from attribut_card
1518 * @param attribut_id {int} attr_def.ad_id , ad_id of attribute
1519 */
1520CategoryCardDefinition.prototype.remove_attribut = function (attribut_id) {
1521
1522 var here = this;
1523 try {
1524
1525 var queryString = {
1526 gDossier: this.dossier_id,
1527 fiche_def_id: this.fiche_def_id,
1528 op: this.op,
1529 op2: 'remove',
1530 ad_id: attribut_id
1531 };
1532 var action = new Ajax.Request(
1533 "ajax_misc.php",
1534 {
1535 method: 'GET',
1536 parameters: queryString,
1537 onFailure: ajax_misc_failure,
1538 onSuccess: function (req) {
1539 if (req.responseText == 'NOCONX') {
1540 reconnect();
1541 return;
1542 }
1543
1544 // if successfull add id on existing_list and remove from available_list
1545
1546 // remove from available_list
1547 id$('existing_attr_' + attribut_id).remove();
1548 var parser = new DOMParser();
1549 var element = parser.parseFromString(req.responseText, 'text/html');
1550 id$(here.available_list).appendChild(element.body.firstChild);
1551
1552 alternate_row_color_list(here.available_list);
1553 Sortable.create('attribut_card', {tag: 'li', hoverclass: inner_box});
1554 }
1555 }
1556 );
1557 } catch (e) {
1558 alert_box("CategoryCardDefinition.remove_attribut" + e.message);
1559 }
1560};