noalyss Version-9
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
27var card_layer=1;
28/**
29 * search a card an display the result into a inner box
30 */
31function boxsearch_card(p_dossier)
32{
33 try
34 {
35 waiting_box();
36 removeDiv('boxsearch_card_div');
37 var queryString="gDossier="+p_dossier+"&op=cardsearch"+"&card="+encodeURI($("card_search").value);
38 var action = new Ajax.Request(
39 "ajax_misc.php" ,
40 {
41 method:'get', parameters:queryString,
42 onFailure:ajax_misc_failure,
43 onSuccess:function(req){
44 remove_waiting_box();
45 if (req.responseText == 'NOCONX') {
46 reconnect();
47 return;
48 }
49 var y=calcy(15);
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'));
54 }
55 }
56 );
57 }catch( e)
58 {
59 alert_box(e.message);
60 }
61}
62/**
63 * show the ipopup with the form to search a card
64 * the properties
65 * @param obj
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
74 */
75function search_card(obj)
76{
77 try
78 {
79 var gDossier=$('gDossier').value;
80 var inp=obj.inp;
81 var string_to_search=$(inp).value;
82 var label=obj.label;
83 var typecard=obj.typecard;
84 var price=obj.price;
85 var tvaid=obj.tvaid;
86 var jrn=obj.jrn;
87 var inactive_card=0;
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;
92
93 }
94 if ( jrn==undefined)
95 {
96 if ( g('p_jrn')) {
97 jrn=$('p_jrn').value;
98 }
99 else {
100 jrn=-1;
101 }
102 }
103 var accvis=obj.accvis;
104 if ( accvis == undefined ) {
105 accvis=0;
106 } else {
107 accvis=obj.accvis;
108 }
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',
113 'accvis':accvis,
114 'amount_from_type':amount_from_type,
115 'inactive_card':inactive_card
116 });
117 if ( $('search_card') ) {
118 removeDiv('search_card');
119 }
120
121
122 waiting_box();
123
124
125 var action=new Ajax.Request ( 'ajax_misc.php',
126 {
127 method:'get',
128 parameters:query,
129 onFailure:errorFid,
130 onSuccess:result_card_search
131 }
132 );
133 }
134 catch(e)
135 {
136 alert_box('search_card failed'+e.message);
137 }
138}
139/**
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
143 */
144function action_concerned_save_card(obj)
145{
146 try {
147 waiting_box();
148 // get all data from FORM
149 var query = obj.serialize();
150 new Ajax.Request("ajax_misc.php", {
151 method: "POST",
152 parameters: query,
153 onSuccess: function (req) {
154 remove_waiting_box();
155 var answer = req.responseXML;
156 var a = answer.getElementsByTagName('ctl');
157 if (a.length == 0)
158 {
159 var rec = req.responseText;
160 alert_box('erreur :' + rec);
161 }
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});
172 }
173
174 }
175 });
176 } catch (e)
177 {
178
179 alert_box('action_concerned_save_card' + e.message);
180 return false;
181 }
182 return false;
183}
184/**
185 * Display the list of other card from a followup action
186 * @returns {undefined}
187 */
188function action_concerned_list(p_obj) {
189 try {
190 var action = new Ajax.Request('ajax_misc.php',
191 {
192 method: 'get',
193 parameters: {gDossier: p_obj.dossier, op: 'card', 'op2': "action_concerned_list", "ag_id": p_obj.ag_id
194 ,"ctl":'action_concerned_list_dv'},
195 onFailure: errorFid,
196 onSuccess: function (req, txt)
197 {
198 try {
199 var sx = 0;
200 if (window.scrollY)
201 {
202 sx = window.scrollY + 40;
203 } else
204 {
205 sx = document.body.scrollTop + 60;
206 }
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');
213 if (a.length == 0)
214 {
215 var rec = req.responseText;
216 alert_box('erreur :' + rec);
217 }
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);
223
224
225 $('action_concerned_list_dv').innerHTML = code_html;
226 } catch (e) {
227 alert_box(e.message);
228 }
229 }
230 }
231 );
232 } catch (e) {
233 alert_box("action_concerned_list" + e.message);
234 }
235}
236/**
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
243 */
244function action_concerned_search_card(obj)
245{
246 try
247 {
248 var dossier = 0;
249 var inp="";
250 var ag_id=0;
251 var search_in=-1;
252 var inactive_card=0;
253 var search_cat=-1;
254
255 if (obj.dossier) {
256 dossier = obj.dossier; /* From the button */
257 }
258 if (obj.ag_id) {
259 ag_id=obj.ag_id;
260 }
261 /* from the form */
262 if (obj.elements) {
263 if (obj.elements['gDossier'])
264 {
265 dossier = obj.elements['gDossier'].value;
266 }
267
268 if (obj.elements['query']) {
269 inp = obj.elements['query'].value;
270 }
271
272 if (obj.elements['ag_id']) {
273 ag_id = obj.elements['ag_id'].value;
274 }
275 if (obj.elements['search_in']) {
276 search_in = obj.elements['search_in'].value;
277 }
278 if ( obj.elements['inactive_card']) {
279 inactive_card=obj.elements['inactive_card'].value;
280 }
281 if ( obj.elements['search_cat']) {
282 search_cat=obj.elements['search_cat'].value;
283 }
284 }
285 if (dossier == 0) {
286 throw "obj.dossier not found";
287 }
288 if (ag_id == 0) {
289 throw "obj.ag_id not found";
290 }
291 var query = encodeJSON({
292 'gDossier': dossier,
293 'op2': 'action_add_concerned_card',
294 'query' : inp,
295 'ctl' : 'unused',
296 'ag_id' : ag_id,
297 'op':'card',
298 'accvis':0,
299 'search_in':search_in,
300 'inactive_card':inactive_card,
301 'search_cat':search_cat
302 });
303
304 waiting_box();
305
306
307 var action = new Ajax.Request('ajax_misc.php',
308 {
309 method: 'get',
310 parameters: query,
311 onFailure: errorFid,
312 onSuccess: function (req, txt)
313 {
314 try {
315 remove_waiting_box();
316 var answer = req.responseXML;
317 var a = answer.getElementsByTagName('ctl');
318 if (a.length == 0)
319 {
320 var rec = req.responseText;
321 alert_box('erreur :' + rec);
322 }
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);
328
329 var sx = 0;
330 if (window.scrollY)
331 {
332 sx = window.scrollY + 40;
333 }
334 else
335 {
336 sx = document.body.scrollTop + 60;
337 }
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;
341 $('query').focus();
342 activate_checkbox_range('select_card_ck');
343 }catch (e) {
344 alert_box(e.message);
345 }
346 }
347 }
348 );
349 }
350 catch (e)
351 {
352 alert_box('search_card failed' + e.message);
353 return false;
354 }
355 return false;
356}
357
358/**
359 * when you submit the form for searching a card
360 *@param obj form
361 *@note the same as search_card, except it answer to a FORM and not
362 * to a click event
363 */
364function search_get_card(obj)
365{
366 var dossier=$('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 $('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 *@param answer in XML
434 */
435function result_card_search(req)
436{
437 try
438 {
439
440 remove_waiting_box();
441 if ( req.responseText == 'NOCONX') { reconnect();return;}
442 var answer=req.responseXML;
443 var a=answer.getElementsByTagName('ctl');
444 if ( a.length == 0 )
445 {
446 var rec=req.responseText;
447 alert_box ('erreur :'+rec);
448 }
449 var html=answer.getElementsByTagName('code');
450
451 var name_ctl=a[0].firstChild.nodeValue;
452 var nodeXml=html[0];
453 var code_html=getNodeText(nodeXml);
454 code_html=unescape_xml(code_html);
455
456 var sx=0;
457 if ( window.scrollY)
458 {
459 sx=window.scrollY+40;
460 }
461 else
462 {
463 sx=document.body.scrollTop+60;
464 }
465
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'});
468
469 $('search_card').innerHTML=code_html;
470
471 if ($('query')) { $('query').focus();}
472 }
473 catch (e)
474 {
475 alert_box(e.message);
476 }
477 try
478 {
479 code_html.evalScripts();
480 }
481 catch(e)
482 {
483 alert_box(content[53]+"\n"+e.message);
484 }
485
486}
487
488
489
490/**
491 * Set the value of 2 input fields
492*
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
495*
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
500*/
501function setCtrl(p_ctrl,p_quickcode,p_ctrlname,p_label)
502{
503 var ctrl=g(p_ctrl);
504 if ( ctrl )
505 {
506 ctrl.value=p_quickcode;
507 }
508 var ctrl_name=g(p_ctrlname);
509 if ( ctrl_name )
510 {
511 ctrl_name.value=p_label;
512 }
513}
514
515
516
517/**
518 * clean the row (the label, price and vat)
519 * @param p_ctl the calling ctrl
520 */
521function clean_Fid(p_ctl)
522{
523 nSell=p_ctl+"_price";
524 nBuy=p_ctl+"_price";
525 nTva_id=p_ctl+"_tva_id";
526 if ( $(nSell) )
527 {
528 $(nSell).value="";
529 }
530 if ( $(nBuy) )
531 {
532 $(nBuy).value="";
533 }
534 if ( $(nTva_id) )
535 {
536 $(nTva_id).value="-1";
537 }
538
539}
540function errorFid(request,json)
541{
542 alert_box(content[53]);
543}
544function update_value(text,li)
545{
546 ajaxFid(text);
547}
548/**
549 * is called when something change in ICard
550 *@param the input field
551 *@see ICard
552 */
553function fill_data_onchange(ctl)
554{
555 ajaxFid(ctl);
556
557}
558/**
559 * is called when something change in ICard
560 *@param the input field
561 *@see ICard
562 */
563function fill_data(text,li)
564{
565 ajaxFid(text);
566
567}
568/**
569 * is called when something change in ICard
570 *@param the input field
571 *@see ICard
572 */
573function fill_fin_data_onchange(ctl)
574{
575 ajaxFid(ctl);
576 ajax_saldo(ctl.id);
577}
578/**
579 * is called when something change in ICard
580 *@param the input field
581 *@see ICard
582 */
583function fill_fin_data(text,li)
584{
585 ajaxFid(text);
586 ajax_saldo($(text.id));
587}
588/**
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
594 *
595 *@see ajax_card.php
596 */
597function fill_ipopcard(obj)
598{
599
600 card_layer++;
601
602 var content='card_'+card_layer;
603 var nTop=170+card_layer;
604 if ( nTop > 300 ) {
605 nTop=170;
606 }
607 var str_top="top:"+calcy(nTop)+"px";
608
609 var str_style=str_top+";height:auto;position:absolute";
610 waiting_box();
611 var popup={'id': content,'cssclass':'inner_box2','style':str_style,'html':"",'drag':false};
612
613 add_div(popup);
614 var dossier=$('gDossier').value;
615 var qcode='';
616 if ( $(obj).qcode != undefined )
617 {
618 qcode=obj.qcode;
619 }
620 else
621 {
622 qcode=$(obj).value;
623 }
624 // ctl=$(obj).id;
625
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) {
632 queryString+='&ro';
633 }
634
635 if ( obj.nohistory != undefined) {
636 queryString+='&nohistory';
637 }
638 if ( obj.nofollowup != undefined) {
639 queryString+='&nofollowup';
640 }
641 queryString=encodeURI(queryString);
642 var action=new Ajax.Request ( 'ajax_misc.php',
643 {
644 method:'get',
645 parameters:queryString,
646 onFailure:errorFid,
647 onSuccess:fill_box
648 }
649 );
650}
651/**
652 *
653 * @param request : object request
654 * @param json : json answer
655*/
656function successFill_ipopcard(req,json)
657{
658 try
659 {
660 if (req.responseText=='NOCONX') { reconnect();return; }
661 var answer=req.responseXML;
662 var a=answer.getElementsByTagName('ctl');
663 var html=answer.getElementsByTagName('code');
664
665 if ( a.length == 0 )
666 {
667 var rec=req.responseText;
668 alert_box ('erreur :'+rec);
669 }
670 var name_ctl=a[0].firstChild.nodeValue;
671 var code_html=getNodeText(html[0]);
672 code_html=unescape_xml(code_html);
673
674 $(name_ctl).innerHTML=code_html;
675 }
676 catch (e)
677 {
678 alert_box(e.message);
679 }
680 try
681 {
682 code_html.evalScripts();
683 }
684 catch(e)
685 {
686 alert_box(content[53]+"\n"+e.message);
687 }
688}
689/**
690 * show the ipopup for selecting a card type, it is a needed step before adding
691 * a card
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...)
697 *@see ajax_card.php
698 */
699function select_card_type(obj)
700{
701 var dossier=$('gDossier').value;
702 var elementId="";
703 // give a filter, -1 if not
704 var filter=$(obj).filter;
705 if ( filter==undefined)
706 {
707 filter=-1;
708 }
709 var content="select_card_div";
710 if ( $(content)){removeDiv(content);}
711 var sx=0;
712 sx=calcy(160);
713
714 var str_style="top:"+sx+"px;height:auto";
715 waiting_box();
716 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':"",'drag':false};
717
718
719
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)
725 {
726 queryString+='&ref';
727 }
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;
732 }
733 queryString+='&fil='+filter;
734 // filter on the ledger, -1 if not
735 var oledger=$(obj).jrn;
736 if (oledger==undefined)
737 {
738 ledger=-1;
739 }
740 else
741 {
742 ledger=$(obj).jrn;
743 }
744
745 queryString+='&ledger='+ledger;
746
747 if ( obj.type_cat)
748 {
749 queryString+='&cat='+obj.type_cat;
750 }
751
752 var action=new Ajax.Request ( 'ajax_misc.php',
753 {
754 method:'get',
755 parameters:queryString,
756 onFailure:errorFid,
757 onSuccess:function(req) {
758 if (req.responseText=='NOCONX') { reconnect(); return;}
759 add_div(popup);
760 // Get all the category,
761 var answer=req.responseXML.getElementsByTagName("fiche_cat_item");
762 if (answer.length == 0) {
763 removeDiv(content);
764 remove_waiting_box();
765 alert_box(getNodeText(req.responseXML.getElementsByTagName("code")[0]));
766 return;
767 }
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});
771 removeDiv(content);
772 remove_waiting_box();
773 return;
774 }
775 fill_box(req);
776 $('lk_cat_card_table').focus();
777 }
778 }
779 );
780}
781/**
782 * Show a blank card
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});
789 *@see ajax_card.php
790 */
791function dis_blank_card(obj)
792{
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;}
797
798 var ref="";
799 if ( obj.elements && obj.elements['ref'] )
800 {
801 ref='&ref';
802 }
803 var content='div_new_card';
804 var nTop=calcy(150);
805 var nLeft=posX;
806 var str_style="top:"+nTop+"px;right:"+nLeft+"px;height:auto;width:45rem;";
807
808 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':false};
809
810 add_div(popup);
811
812 if ( obj.gDossier.value != undefined ) {
813 var dossier=$('gDossier').value;
814 } else {
815 var dossier=obj.gDossier;
816 }
817 var queryString='gDossier='+dossier;
818 queryString+='&ctl='+content;
819 queryString+='&fd_id='+fd_id;
820 queryString+=ref;
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;
825 }
826
827 if ( obj.elementId) queryString+="&eltid="+obj.elementId;
828 var action=new Ajax.Request ( 'ajax_misc.php',
829 {
830 method:'get',
831 parameters:queryString,
832 onFailure:errorFid,
833 onSuccess: function (req,json) {
834
835
836 successFill_ipopcard(req,json);
837 }
838 }
839 );
840}
841function form_blank_card(obj)
842{
843 // first we have to take the form elt we need
844 var fd_id=obj.fd_id;
845 var content='div_new_card';
846 var nTop=posY-40;
847 var nLeft=posX-20;
848 var str_style="top:"+nTop+"px;left:"+nLeft+"px;width:60em;height:auto";
849
850 var popup={'id': content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':true};
851 if ( $(content)) {removeDiv(content);}
852 add_div(popup);
853
854
855 var dossier=$('gDossier').value;
856
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
862
863 var action=new Ajax.Request ( 'ajax_misc.php',
864 {
865 method:'get',
866 parameters:queryString,
867 onFailure:errorFid,
868 onSuccess:successFill_ipopcard
869 }
870 );
871}
872
873/**
874 * save the data contained into the form 'save_card'
875 *@param input field (obj) it must have the attribute ipopup
876 * possible attribute :
877 *@see ajax_card.php
878 */
879function save_card(obj)
880{
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');
885 return false;
886 }
887
888 // Data must be taken here
889
890 var data=$('save_card').serialize(false);
891 waiting_box();
892 var dossier=$('gDossier').value;
893 var queryString='gDossier='+dossier;
894 queryString+='&ctl='+content;
895 queryString+=data;
896 queryString+='&op2=sc'; // sc for save card
897 queryString+='&op=card'; // sc for save card
898
899 var action=new Ajax.Request ( 'ajax_misc.php',
900 {
901 method:'post',
902 parameters:queryString,
903 onFailure:errorFid,
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");
909 var after_save=0;
910 if ( status.length !=0) {
911 status_value=getNodeText(status[0]);
912 }
913 if ( after_savetag.length !=0 ) {
914 after_save=getNodeText(after_savetag[0]);
915 }
916 // if status == OK and after_save == 0
917 // then update the box
918 if ( status_value == 'OK' && after_save == 0) {
919 fill_box(req,json);
920 }
921
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' });
932 //
933 if ( table_card.tBodies[0].rows.length % 2 == 0 ) {
934 row.addClassName("odd");
935 } else {
936 row.addClassName("even");
937
938 }
939 }
940
941 remove_waiting_box();
942 if ( elt.length != 0) {
943 var eltid=getNodeText(elt[0]);
944 if ( eltid !="") {
945 var eltvalue=req.responseXML.getElementsByTagName("elt_value");
946 $(eltid).value=getNodeText(eltvalue[0]);
947 fill_data_onchange(eltid);
948 $(eltid).focus();
949 }
950 }
951 if (status_value == "OK") {
952 Effect.SlideUp(content, { duration: 1.0 });
953 }
954 if ( status_value == 'NOK') {
955 var xml_message=req.responseXML.getElementsByTagName("code");
956 var message=getNodeText(xml_message[0]);
957 smoke.alert(message);
958 }
959
960
961 }
962 }
963 );
964}
965/**
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
970 */
971function add_category(obj)
972{
973 var sx=0;
974 if ( window.scrollY)
975 {
976 sx=window.scrollY+120;
977 }
978 else
979 {
980 sx=document.body.scrollTop+120;
981 }
982
983 var div_style="top:"+sx+"px;width:60%;height:80%";
984 // show ipopup
985 var div={id:obj.ipopup,
986 cssclass:"inner_box",drag:1,style:div_style};
987 if ( $(div) ) {
988 removeDiv(div);
989 }
990 add_div(div);
991 waiting_box();
992 var dossier=$('gDossier').value;
993 var queryString='gDossier='+dossier;
994 queryString+='&op2=ac';
995 queryString+='&op=card';
996 queryString+='&ctl='+obj.ipopup;
997 if ( obj.type_cat)
998 {
999 queryString+='&cat='+obj.type_cat;
1000 }
1001 var action=new Ajax.Request ( 'ajax_misc.php',
1002 {
1003 method:'get',
1004 parameters:queryString,
1005 onFailure:errorFid,
1006 onSuccess:fill_box
1007 }
1008 );
1009
1010}
1011/**
1012 * save the form and add a new category of card
1013 * @param obj if the form object
1014 */
1015function save_card_category(obj)
1016{
1017 if ( ! $(obj).ipopup)
1018 {
1019 alert_box('Erreur pas d\' attribut ipopup '+obj.id);
1020 return;
1021 };
1022try {
1023 // Data must be taken here
1024 data=$('newcat').serialize(false);
1025 var dossier=$('gDossier').value;
1026 var queryString='ctl='+obj.ipopup+'&';
1027 queryString+=data;
1028 queryString+='&op2=scc'; // sc for save card
1029 queryString+='&op=card'; // sc for save card
1030
1031 var action=new Ajax.Request ( 'ajax_misc.php',
1032 {
1033 method:'get',
1034 parameters:queryString,
1035 onFailure:errorFid,
1036 onSuccess:fill_box
1037 }
1038 );
1039 } catch(e)
1040 {
1041 alert_box(e.message);
1042 return false;
1043 }
1044 return false;
1045}
1046/**
1047 * Remove a definition of an attribut
1048 *@param attr_def.ad_id
1049 *@param gDossier
1050 *@param table_id to rm the row
1051 *@param special this pointer of the row
1052 */
1053
1054function removeCardAttribut(ad_id,gDossier,table_id,row)
1055{
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',
1062 {
1063 method:'get',
1064 parameters:queryString,
1065 onFailure:null,
1066 onSuccess:null
1067 }
1068 );
1069 deleteRowRec(table_id,row);
1070
1071
1072}
1073/**
1074* update a card in ajax
1075*/
1076function update_card(obj)
1077{
1078try {
1079 var name=obj.id;
1080
1081 var qs=Form.serialize(name)+'&op2=upc&op=card';
1082 var action=new Ajax.Request ( 'ajax_misc.php',
1083 {
1084 method:'get',
1085 parameters:qs,
1086 onFailure:errorFid,
1087 onSuccess:successFill_ipopcard
1088 }
1089 );
1090 } catch (e) {
1091 alert_box(e.message);
1092 return false;
1093 }
1094}
1095/***
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
1102 */
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',
1106 {
1107 method: 'get',
1108 parameters: query,
1109 onFailure: errorFid,
1110 onSuccess: function (req, txt)
1111 {
1112 try {
1113 remove_waiting_box();
1114 var answer = req.responseXML;
1115 var a = answer.getElementsByTagName('ctl');
1116 if (a.length == 0)
1117 {
1118 var rec = req.responseText;
1119 alert_box('erreur :' + rec);
1120 }
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;
1128 } catch (e) {
1129
1130 }
1131 }
1132 }
1133 );
1134 }
1135function action_remove_concerned(p_dossier,p_fiche_id,p_action_id)
1136{
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',
1139 {
1140 method: 'get',
1141 parameters: query,
1142 onFailure: errorFid,
1143 onSuccess: function (req, txt)
1144 {
1145 try {
1146 remove_waiting_box();
1147 var answer = req.responseXML;
1148 var a = answer.getElementsByTagName('ctl');
1149 if (a.length == 0)
1150 {
1151 var rec = req.responseText;
1152 alert_box('erreur :' + rec);
1153 }
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');
1161
1162 $(namectl).remove();
1163
1164 } catch (e) {
1165 if ( console) { console.log('Erreur ') + e.message;}
1166 alert_box('action_remove_concerned '+e.message);
1167 }
1168 }
1169 }
1170 );
1171 }
1172/**
1173 * Remove a card after checking it is not used
1174 * @param obj {json} = gDossier,op,op2:rm_card,ctl,f_id
1175 */
1176function delete_card(obj) {
1177 smoke.confirm("Confirmez ? ", function (e) {
1178 if (e) {
1179 waiting_box();
1180 new Ajax.Request("ajax_misc.php", {
1181 "method": "get",
1182 parameters: obj,
1183 onSuccess: function (req) {
1184 remove_waiting_box();
1185 var answer = req.responseXML;
1186 var a = answer.getElementsByTagName('ctl');
1187 if (a.length == 0)
1188 {
1189 var rec = req.responseText;
1190 alert_box('erreur :' + rec);
1191 }
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 });
1199 } else {
1200 smoke.alert(code_html);
1201 }
1202 }
1203
1204 });
1205 }
1206 });
1207}
1208/**
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}
1213 */
1214function modify_card(p_fiche_id)
1215{
1216 /* window with result */
1217 card_layer++;
1218
1219 var content = 'card_' + card_layer;
1220 var nTop = 170 + card_layer;
1221 if (nTop > 300) {
1222 nTop = 170;
1223 }
1224 var str_top = fixed_position(250, nTop)
1225 var str_style = str_top + ";width:45em;height:auto;position:absolute";
1226
1227 var popup = {'id': content, 'cssclass': 'inner_box', 'style': str_style, 'html': loading(), 'drag': false};
1228
1229 add_div(popup);
1230
1231 /* dossier id */
1232 if ( ! document.getElementById("card_gdossier")) {
1233
1234 console.error("card_gdossier error");
1235 throw ("card_gdossier not set");
1236 }
1237 var dossier = $('card_gdossier').value;
1238
1239
1240 var action = new Ajax.Request('ajax_misc.php',
1241 {
1242 method: 'get',
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) {
1246 fill_box(respTxt);
1247 }
1248 }
1249 );
1250}
1251/**
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}
1256 */
1257function delete_card_id(p_fiche_id)
1258{
1259 var row="row_card"+p_fiche_id;
1260 if ( ! document.getElementById("card_gdossier")) {
1261
1262 console.error("card_gdossier error");
1263 throw ("card_gdossier not set");
1264 }
1265 $(row).addClassName("background-selected");
1266 var dossier = $('card_gdossier').value;
1267 smoke.confirm(content[47], function (e) {
1268 if (e) {
1269 waiting_box();
1270 new Ajax.Request("ajax_misc.php", {
1271 "method": "get",
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');
1278 if (a.length == 0)
1279 {
1280 var rec = req.responseText;
1281 alert_box('erreur :' + rec);
1282 }
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);
1288
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");
1293 } else {
1294 smoke.alert(code_html);
1295
1296 }
1297 }
1298
1299 });
1300 } else{
1301 $(row).removeClassName("background-selected");
1302
1303 }
1304 });
1305
1306}
1307
1308/**
1309* update a card in ajax , and update a row
1310*
1311*/
1312function card_update_row(obj)
1313{
1314 try {
1315 var name = obj.id;
1316
1317 var qs = Form.serialize(name) + '&op2=upr&op=card';
1318 var action = new Ajax.Request('ajax_misc.php',
1319 {
1320 method: 'get',
1321 parameters: qs,
1322 onFailure: errorFid,
1323 onSuccess: function (req) {
1324 try {
1325
1326 remove_waiting_box();
1327
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);
1334 }
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);
1338
1339 if ( document.getElementById(name_ctl)) {
1340 // update the row
1341 $(name_ctl).innerHTML = code_html;
1342 new Effect.Highlight(name_ctl ,{startcolor: '#FAD4D4',endcolor: '#F78082' });
1343
1344 }
1345 $(a[0].firstChild.nodeValue).remove();
1346
1347
1348 } catch (e) {
1349 alert_box(e.message);
1350 if (console) {
1351 console.error(e);
1352 console.error("log answer = " + req.responseText);
1353 }
1354 }
1355 try {
1356 code_html.evalScripts();
1357 } catch (e) {
1358 if (console) {
1359 console.error(e);
1360 console.error("log answer = " + req.responseText);
1361 }
1362 alert_box(content[53] + "\n" + e.message);
1363 }
1364
1365
1366 }
1367 }
1368 );
1369 } catch (e) {
1370 alert_box(e.message);
1371 return false;
1372 }
1373}
1374/**
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
1378 */
1379function linked_card_option(p_action_person_id,p_dossier) {
1380 try {
1381 waiting_box();
1382 new Ajax.Request("ajax_misc.php",{
1383 method:"get",
1384 parameters: {
1385 ap_id:p_action_person_id,
1386 gDossier:p_dossier,
1387 op:"card",
1388 op2:"display_card_option",
1389 ctl:"notused"
1390 },
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);
1395
1396 }
1397 });
1398 } catch (e) {
1399 console.error(e.message);
1400 }
1401}
1402/**
1403 * Save option for the contact
1404 * @param {object} obj form
1405 * @see card_multiple_display_option.php
1406 * @returns {undefined}
1407 */
1408function save_linked_card_option(obj)
1409{
1410 waiting_box();
1411 new Ajax.Request("ajax_misc.php",{
1412 method:"post",
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' });
1419 }
1420 });
1421 return false;
1422}
1423
1424/**
1425 * @class
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
1429 */
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';
1436}
1437/**
1438 * save the order + new attributes, remove old ones
1439 */
1440CategoryCardDefinition.prototype.save = function () {
1441
1442 try {
1443 var here = this;
1444 var aAttribut=Sortable.serialize(this.existing_list);
1445 var queryString = {
1446 gDossier: this.dossier_id,
1447 fiche_def_id: this.fiche_def_id,
1448 op: this.op,
1449 op2: 'save',
1450 attribut:aAttribut
1451 };
1452 var action = new Ajax.Request(
1453 "ajax_misc.php",
1454 {
1455 method: 'POST',
1456 parameters: queryString,
1457 onFailure: ajax_misc_failure,
1458 onSuccess: function (req) {
1459 if (req.responseText == 'NOCONX') {
1460 reconnect();
1461 return;
1462 }
1463 if ( req.responseText == 'OK') {
1464 smoke.signal('Sauvé',function(e){},{duration:500});
1465 }
1466
1467
1468 }
1469 }
1470 );
1471 } catch (e) {
1472 alert_box("CategoryCardDefinition.save" + e.message);
1473 }
1474};
1475/**
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
1478 */
1479CategoryCardDefinition.prototype.add_attribut = function (attribut_id) {
1480
1481
1482 try {
1483 var here = this;
1484 var queryString = {
1485 gDossier: this.dossier_id,
1486 fiche_def_id: this.fiche_def_id,
1487 op: this.op,
1488 op2: 'add',
1489 ad_id: attribut_id
1490 };
1491 var action = new Ajax.Request(
1492 "ajax_misc.php",
1493 {
1494 method: 'GET',
1495 parameters: queryString,
1496 onFailure: ajax_misc_failure,
1497 onSuccess: function (req) {
1498 if (req.responseText == 'NOCONX') {
1499 reconnect();
1500 return;
1501 }
1502
1503 // if successfull add id on existing_list and remove from available_list
1504
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',
1512 endcolor: '#F78082'
1513 });
1514 Sortable.create('attribut_card', {tag: 'li'});
1515 alternate_row_color_list(here.available_list);
1516 }
1517 }
1518 );
1519 } catch (e) {
1520 alert_box("CategoryCardDefinition.add_attribut" + e.message);
1521 }
1522};
1523/**
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
1526 */
1527CategoryCardDefinition.prototype.remove_attribut = function (attribut_id) {
1528
1529 var here = this;
1530 try {
1531
1532 var queryString = {
1533 gDossier: this.dossier_id,
1534 fiche_def_id: this.fiche_def_id,
1535 op: this.op,
1536 op2: 'remove',
1537 ad_id: attribut_id
1538 };
1539 var action = new Ajax.Request(
1540 "ajax_misc.php",
1541 {
1542 method: 'GET',
1543 parameters: queryString,
1544 onFailure: ajax_misc_failure,
1545 onSuccess: function (req) {
1546 if (req.responseText == 'NOCONX') {
1547 reconnect();
1548 return;
1549 }
1550
1551 // if successfull add id on existing_list and remove from available_list
1552
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);
1558
1559 alternate_row_color_list(here.available_list);
1560 Sortable.create('attribut_card', {tag: 'li', hoverclass: inner_box});
1561 }
1562 }
1563 );
1564 } catch (e) {
1565 alert_box("CategoryCardDefinition.remove_attribut" + e.message);
1566 }
1567};