noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
card.js
Go to the documentation of this file.
00001 /*
00002  *   This file is part of NOALYSS.
00003  *
00004  *   NOALYSS is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation; either version 2 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   NOALYSS is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with NOALYSS; if not, write to the Free Software
00016  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 */
00018 /* $Revision$ */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*! \file
00023  * \brief javascript for searching a card
00024  */
00025 
00026 var card_layer=1;
00027 /**
00028  *@brief search a card an display the result into a inner box
00029  */
00030 function boxsearch_card(p_dossier)
00031 {
00032         try
00033         {
00034         waiting_box();
00035         removeDiv('boxsearch_card_div');
00036         var queryString="gDossier="+p_dossier+"&op=cardsearch"+"&card="+$(card_search).value;
00037         var action = new Ajax.Request(
00038                                   "ajax_misc.php" ,
00039                                   {
00040                                       method:'get', parameters:queryString,
00041                                       onFailure:ajax_misc_failure,
00042                                       onSuccess:function(req){
00043                                                 remove_waiting_box();
00044                                                 var y=posY+15;
00045                                                 var div_style="left:10%;width:80%;"+";top:"+y+"px";
00046                                                 add_div({id:'boxsearch_card_div',cssclass:'inner_box',html:loading(),style:div_style,drag:true});
00047                                                 $('boxsearch_card_div').innerHTML=req.responseText;
00048                                                 sorttable.makeSortable($('tb_fiche'));
00049                                       }
00050                                   }
00051                                   );
00052         }catch( e)
00053         {
00054                 alert(e.getMessage);
00055         }
00056 }
00057 /**
00058  *@brief show the ipopup with the form to search a card
00059  * the properties
00060  *  - jrn for the ledger
00061  *  - fs for the action
00062  *  - price for the price of the card (field to update)
00063  *  - tvaid for the tvaid of the card (field to update)
00064  *  - inp input text to update with the quickcode
00065  *  - label field to update with the name
00066  *  - ctl the id to fill with the HTML answer (ending with _content)
00067  */
00068 function search_card(obj)
00069 {
00070     try
00071     {
00072         var gDossier=$('gDossier').value;
00073         var inp=obj.inp;
00074         var string_to_search=$(inp).value;
00075         var label=obj.label;
00076         var typecard=obj.typecard;
00077         var price=obj.price;
00078         var tvaid=obj.tvaid;
00079         var jrn=obj.jrn;
00080         if ( jrn==undefined)
00081         {
00082             if ( g('p_jrn'))   {
00083                 jrn=$('p_jrn').value;
00084             }
00085             else            {
00086                 jrn=-1;
00087             }
00088         }
00089         var query=encodeJSON({'gDossier':gDossier,
00090                       'inp':inp,'label':label,'price':price,'tvaid':tvaid,
00091                       'ctl':'search_card','op':'fs','jrn':jrn,
00092                       'typecard':typecard,'query':string_to_search
00093                              });
00094         if (  $('search_card') ) {
00095             removeDiv('search_card');
00096         }
00097         var sx=0;
00098         if ( window.scrollY)
00099         {
00100             sx=window.scrollY+40;
00101         }
00102         else
00103         {
00104             sx=document.body.scrollTop+60;
00105         }
00106 
00107         var div_style="top:"+sx+"px;height:80%";
00108         add_div({id:'search_card',cssclass:'inner_box',html:loading(),style:div_style,drag:true});
00109 
00110         var action=new Ajax.Request ( 'ajax_card.php',
00111                                       {
00112                                   method:'get',
00113                                   parameters:query,
00114                                   onFailure:errorFid,
00115                                   onSuccess:result_card_search
00116                                       }
00117                                     );
00118     }
00119     catch(e)
00120     {
00121         alert('search_card failed'+e.message);
00122     }
00123 }
00124 /**
00125  *@brief when you submit the form for searching a card
00126  *@param obj form
00127  *@note the same as search_card, except it answer to a FORM and not
00128  * to a click event
00129  */
00130 function search_get_card(obj)
00131 {
00132     var dossier=$('gDossier').value;
00133 
00134     var queryString="gDossier="+dossier;
00135     queryString+="&op=fs";
00136 
00137     if ( obj.elements['inp'] )
00138     {
00139         queryString+="&inp="+$F('inp');
00140     }
00141     if ( obj.elements['typecard'] )
00142     {
00143         queryString+="&typecard="+$F('typecard');
00144     }
00145     if ( obj.elements['jrn'] )
00146     {
00147         queryString+="&jrn="+$F('jrn');
00148     }
00149     if ( obj.elements['label'])
00150     {
00151         queryString+="&label="+$F('label');
00152     }
00153     if ( obj.elements['price'])
00154     {
00155         queryString+="&price="+$F('price');
00156     }
00157     if ( obj.elements['tvaid'])
00158     {
00159         queryString+="&tvaid="+$F('tvaid');
00160     }
00161     if( obj.elements['query'])
00162     {
00163         queryString+="&query="+$F('query');
00164     }
00165     if (obj.ctl )
00166     {
00167         queryString+="&ctl="+obj.ctl;
00168     }
00169     $('asearch').innerHTML=loading();
00170     var action=new Ajax.Request ( 'ajax_card.php',
00171                                   {
00172                                   method:'get',
00173                                   parameters:queryString,
00174                                   onFailure:errorFid,
00175                                   onSuccess:result_card_search
00176                                   }
00177                                 );
00178 }
00179 /**
00180  *@brief show the answer of ajax request
00181  *@param  answer in XML
00182  */
00183 function result_card_search(req)
00184 {
00185     try
00186     {
00187         var answer=req.responseXML;
00188         var a=answer.getElementsByTagName('ctl');
00189         if ( a.length == 0 )
00190         {
00191             var rec=req.responseText;
00192             alert ('erreur :'+rec);
00193         }
00194         var html=answer.getElementsByTagName('code');
00195 
00196         var name_ctl=a[0].firstChild.nodeValue;
00197         var nodeXml=html[0];
00198         var code_html=getNodeText(nodeXml);
00199         code_html=unescape_xml(code_html);
00200         $('search_card').innerHTML=code_html;
00201     }
00202     catch (e)
00203     {
00204         alert(e.message);
00205     }
00206     try
00207     {
00208         code_html.evalScripts();
00209     }
00210     catch(e)
00211     {
00212         alert("Impossible executer script de la reponse\n"+e.message);
00213     }
00214 
00215 }
00216 
00217 
00218 
00219 /*!\brief Set the value of 2 input fields
00220 *
00221 * 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
00222 * some specific need.  This function is called if the caller is searchcardCtrl
00223 *
00224 *\param p_ctrl the input with the name of the quick code
00225 *\param  p_quickcode the found quick_code
00226 *\param p_ctrlname the name of the input field with the label
00227 *\param p_label the label of the quickcode
00228 */
00229 function setCtrl(p_ctrl,p_quickcode,p_ctrlname,p_label)
00230 {
00231     var ctrl=g(p_ctrl);
00232     if ( ctrl )
00233     {
00234         ctrl.value=p_quickcode;
00235     }
00236     var ctrl_name=g(p_ctrlname);
00237     if ( ctrl_name )
00238     {
00239         ctrl_name.value=p_label;
00240     }
00241 }
00242 
00243 
00244 
00245 /*!\brief clean the row (the label, price and vat)
00246  * \param p_ctl the calling ctrl
00247  */
00248 function clean_Fid(p_ctl)
00249 {
00250     nSell=p_ctl+"_price";
00251     nBuy=p_ctl+"_price";
00252     nTva_id=p_ctl+"_tva_id";
00253     if ( $(nSell) )
00254     {
00255         $(nSell).value="";
00256     }
00257     if ( $(nBuy) )
00258     {
00259         $(nBuy).value="";
00260     }
00261     if ( $(nTva_id) )
00262     {
00263         $(nTva_id).value="-1";
00264     }
00265 
00266 }
00267 function errorFid(request,json)
00268 {
00269     alert('erreur : ajax fiche');
00270 }
00271 function update_value(text,li)
00272 {
00273            ajaxFid(text);
00274 }
00275 /**
00276  *@brief is called when something change in ICard
00277  *@param the input field
00278  *@see ICard
00279  */
00280 function fill_data_onchange(ctl)
00281 {
00282     ajaxFid(ctl);
00283 
00284 }
00285 /**
00286  *@brief is called when something change in ICard
00287  *@param the input field
00288  *@see ICard
00289  */
00290 function fill_data(text,li)
00291 {
00292     ajaxFid(text);
00293 
00294 }
00295 /**
00296  *@brief is called when something change in ICard
00297  *@param the input field
00298  *@see ICard
00299  */
00300 function fill_fin_data_onchange(ctl)
00301 {
00302     ajaxFid(ctl);
00303     ajax_saldo(ctl.id);
00304 }
00305 /**
00306  *@brief is called when something change in ICard
00307  *@param the input field
00308  *@see ICard
00309  */
00310 function fill_fin_data(text,li)
00311 {
00312     ajaxFid(text);
00313     ajax_saldo($(text.id));
00314 }
00315 /**
00316  *@brief show the ipopup window and display the details of a card,
00317  * to work some attribute must be set
00318  *@parameter obj.qcode is the qcode, obj.nohistory if you don't want to  display
00319  * the history button, obj.ro is the popin is readonly
00320  *@note you must the gDossier as hidden in the calling page
00321  *
00322  *@see ajax_card.php
00323  */
00324 function fill_ipopcard(obj)
00325 {
00326 
00327     card_layer++;
00328 
00329     var content='card_'+card_layer;
00330     var nTop=posY-40;
00331     //var nLeft=posX-20;
00332         var nLeft="20%";
00333     var str_style="top:"+nTop+"px;left:"+nLeft+"px;width:45em;height:auto";
00334 
00335     var popup={'id':  content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':true};
00336 
00337     add_div(popup);
00338     var dossier=$('gDossier').value;
00339     var qcode='';
00340     if ( $(obj).qcode != undefined )
00341     {
00342         qcode=obj.qcode;
00343     }
00344     else
00345     {
00346         qcode=$(obj).value;
00347     }
00348     //    ctl=$(obj).id;
00349 
00350     var queryString='gDossier='+dossier;
00351     queryString+='&qcode='+qcode;
00352     queryString+='&ctl='+content;
00353     queryString+='&op=dc';      // dc for detail card
00354     if ( obj.readonly != undefined) {
00355      queryString+='&ro';
00356     }
00357 
00358     if ( obj.nohistory != undefined) {
00359      queryString+='&nohistory';
00360     }
00361 
00362     var action=new Ajax.Request ( 'ajax_card.php',
00363                                   {
00364                                   method:'get',
00365                                   parameters:queryString,
00366                                   onFailure:errorFid,
00367                                   onSuccess:fill_box
00368                                   }
00369                                 );
00370 }
00371 /**
00372  *@brief
00373  * \param request : object request
00374  * \param json : json answer
00375 \code
00376 \endcode
00377 */
00378 function  successFill_ipopcard(req,json)
00379 {
00380     try
00381     {
00382         var answer=req.responseXML;
00383         var a=answer.getElementsByTagName('ctl');
00384         var html=answer.getElementsByTagName('code');
00385 
00386         if ( a.length == 0 )
00387         {
00388             var rec=req.responseText;
00389             alert ('erreur :'+rec);
00390         }
00391         var name_ctl=a[0].firstChild.nodeValue;
00392         var code_html=getNodeText(html[0]);
00393         code_html=unescape_xml(code_html);
00394 
00395         $(name_ctl).innerHTML=code_html;
00396     }
00397     catch (e)
00398     {
00399         alert(e.message);
00400     }
00401     try
00402     {
00403         code_html.evalScripts();
00404     }
00405     catch(e)
00406     {
00407         alert("Impossible executer script de la reponse\n"+e.message);
00408     }
00409 }
00410 /**
00411  *@brief show the ipopup for selecting a card type, it is a needed step before adding
00412  * a card
00413  *@param input field (obj) it must have the attribute ipopup
00414  *       possible attribute :
00415  *        - filter is the filter but with a  fd_id list, -1 means there  is no filter
00416  *        - ref if we want to refresh the window after adding a card
00417  *        - type type of card (supplier, customer...)
00418  *@see ajax_card.php
00419  */
00420 function select_card_type(obj)
00421 {
00422 
00423     var dossier=$('gDossier').value;
00424 
00425     // give a filter, -1 if not
00426     var filter=$(obj).filter;
00427     if ( filter==undefined)
00428     {
00429         filter=-1;
00430     }
00431     var content="select_card_div";
00432     if ( $(content)){removeDiv(content);}
00433     var sx=0;
00434     if ( window.scrollY)
00435     {
00436             sx=window.scrollY+40;
00437     }
00438     else
00439     {
00440         sx=document.body.scrollTop+60;
00441     }
00442 
00443     var str_style="top:"+sx+"px;left:25%;height:30%";
00444 
00445     var popup={'id':  content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':true};
00446 
00447     add_div(popup);
00448 
00449     var queryString='gDossier='+dossier;
00450     queryString+='&ctl='+content;
00451     queryString+='&op=st';      // st for selecting type
00452     if ( $(obj).win_refresh!=undefined)
00453     {
00454         queryString+='&ref';
00455     }
00456     queryString+='&fil='+filter;
00457     // filter on the ledger, -1 if not
00458     var oledger=$(obj).jrn;
00459     if (oledger==undefined)
00460     {
00461         ledger=-1;
00462     }
00463     else
00464     {
00465         ledger=$(obj).jrn;
00466     }
00467 
00468     queryString+='&ledger='+ledger;
00469 
00470     if ( obj.type_cat)
00471     {
00472         queryString+='&cat='+obj.type_cat;
00473     }
00474 
00475     var action=new Ajax.Request ( 'ajax_card.php',
00476                                   {
00477                                   method:'get',
00478                                   parameters:queryString,
00479                                   onFailure:errorFid,
00480                                   onSuccess:fill_box
00481                                   }
00482                                 );
00483 }
00484 /**
00485  *@brief Show a blank card
00486  *@param Form object (obj)
00487  *       possible attribute :
00488  *        - filter is the filter but with a  fd_id list, -1 means there  is no filter
00489  *        - ref : reload the window after adding card
00490  *        - content : name of the div
00491  *@example dis_blank_card({gDossier:15,fd_id:12,ref:1});
00492  *@see ajax_card.php
00493  */
00494 function dis_blank_card(obj)
00495 {
00496     // first we have to take the form elt we need
00497     if ( obj.fd_id.value != undefined )
00498                 { var fd_id=$F('fd_id'); }
00499         else {fd_id=obj.fd_id;}
00500 
00501     var ref="";
00502     if ( obj.elements &&  obj.elements['ref'] )
00503     {
00504         ref='&ref';
00505     }
00506     var content='div_new_card';
00507     var nTop=calcy(30);
00508     var nLeft=posX;
00509     var str_style="top:"+nTop+"px;right:"+nLeft+"px;height:auto";
00510 
00511     var popup={'id':  content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':true};
00512     if ( $(content)) {removeDiv(content);}
00513     add_div(popup);
00514 
00515         if ( obj.gDossier.value != undefined ) {
00516     var dossier=$('gDossier').value;} else {
00517         var dossier=obj.gDossier;
00518         }
00519 
00520     var queryString='gDossier='+dossier;
00521     queryString+='&ctl='+content;
00522     queryString+='&fd_id='+fd_id;
00523     queryString+=ref;
00524     queryString+='&op=bc';      // bc for blank card
00525 
00526     var action=new Ajax.Request ( 'ajax_card.php',
00527                                   {
00528                                   method:'get',
00529                                   parameters:queryString,
00530                                   onFailure:errorFid,
00531                                   onSuccess:successFill_ipopcard
00532                                   }
00533                                 );
00534 }
00535 function form_blank_card(obj)
00536 {
00537     // first we have to take the form elt we need
00538     var fd_id=obj.fd_id;
00539     var content='div_new_card';
00540     var nTop=posY-40;
00541     var nLeft=posX-20;
00542     var str_style="top:"+nTop+"px;left:"+nLeft+"px;width:60em;height:auto";
00543 
00544     var popup={'id':  content,'cssclass':'inner_box','style':str_style,'html':loading(),'drag':true};
00545     if ( $(content)) {removeDiv(content);}
00546     add_div(popup);
00547 
00548 
00549     var dossier=$('gDossier').value;
00550 
00551     var queryString='gDossier='+dossier;
00552     queryString+='&ctl='+content;
00553     queryString+='&fd_id='+fd_id;
00554     queryString+='&op=bc';      // bc for blank card
00555 
00556     var action=new Ajax.Request ( 'ajax_card.php',
00557                                   {
00558                                   method:'get',
00559                                   parameters:queryString,
00560                                   onFailure:errorFid,
00561                                   onSuccess:successFill_ipopcard
00562                                   }
00563                                 );
00564 }
00565 
00566 /**
00567  *@brief save the data contained into the form 'save_card'
00568  *@param input field (obj) it must have the attribute ipopup
00569  *       possible attribute :
00570  *@see ajax_card.php
00571  */
00572 function save_card(obj)
00573 {
00574     var content=$(obj).ipopup;
00575     // Data must be taken here
00576     data=$('save_card').serialize(false);
00577     $(content).innerHTML=loading();
00578 
00579     var dossier=$('gDossier').value;
00580     var queryString='gDossier='+dossier;
00581     queryString+='&ctl='+content;
00582     queryString+=data;
00583     queryString+='&op=sc';      // sc for save card
00584 
00585     var action=new Ajax.Request ( 'ajax_card.php',
00586                                   {
00587                                   method:'post',
00588                                   parameters:queryString,
00589                                   onFailure:errorFid,
00590                                   onSuccess:fill_box
00591                                   }
00592                                 );
00593 }
00594 /**
00595  *@brief add a category of card,
00596  *@param obj with the attribute
00597  * - ipopup the ipopup to show
00598  * - type_cat the category of card we want to add
00599  */
00600 function add_category(obj)
00601 {
00602     var sx=0;
00603         if ( window.scrollY)
00604         {
00605             sx=window.scrollY+120;
00606         }
00607         else
00608         {
00609             sx=document.body.scrollTop+120;
00610         }
00611 
00612         var div_style="top:"+sx+"px;width:60%;height:80%";
00613     // show ipopup
00614         var div={id:obj.ipopup,
00615                         cssclass:"inner_box",drag:1,style:div_style};
00616         if ( $(div) ) {
00617                 removeDiv(div);
00618         }
00619         add_div(div);
00620         waiting_box();
00621     var dossier=$('gDossier').value;
00622     var queryString='gDossier='+dossier;
00623     queryString+='&op=ac';
00624     queryString+='&ctl='+obj.ipopup;
00625     if ( obj.type_cat)
00626     {
00627         queryString+='&cat='+obj.type_cat;
00628     }
00629     var action=new Ajax.Request ( 'ajax_card.php',
00630                                   {
00631                                   method:'get',
00632                                   parameters:queryString,
00633                                   onFailure:errorFid,
00634                                   onSuccess:fill_box
00635                                   }
00636                                 );
00637 
00638 }
00639 /**
00640  * @brief save the form and add a new category of card
00641  * @param obj if the form object
00642  */
00643 function save_card_category(obj)
00644 {
00645     if ( ! $(obj).ipopup)
00646     {
00647         alert('Erreur pas d\' attribut ipopup '+obj.id);
00648         return;
00649     };
00650         try {
00651                 // Data must be taken here
00652 
00653     data=$('newcat').serialize(false);
00654     var dossier=$('gDossier').value;
00655     queryString='ctl='+obj.ipopup+'&';
00656     queryString+=data;
00657     queryString+='&op=scc';     // sc for save card
00658 
00659     var action=new Ajax.Request ( 'ajax_card.php',
00660                                   {
00661                                   method:'get',
00662                                   parameters:queryString,
00663                                   onFailure:errorFid,
00664                                   onSuccess:fill_box
00665                                   }
00666                                 );
00667         } catch(e)
00668         {
00669                 alert(e.message);
00670                 return false;
00671         }
00672         return false;
00673 }
00674 /**
00675  *@brief Remove a definition of an  attribut
00676  *@param attr_def.ad_id
00677  *@param gDossier
00678  *@param table_id to rm the row
00679  *@param special this pointer of the row
00680  */
00681 
00682 function removeCardAttribut(ad_id,gDossier,table_id,row)
00683 {
00684     var queryString='gDossier='+gDossier;
00685     queryString+='&op=rmfa';
00686     queryString+='&ctl=debug';  // debug id
00687     queryString+='&ad_id='+ad_id;
00688     var action=new Ajax.Request ( 'ajax_card.php',
00689                                   {
00690                                   method:'get',
00691                                   parameters:queryString,
00692                                   onFailure:null,
00693                                   onSuccess:null
00694                                   }
00695                                 );
00696     deleteRowRec(table_id,row);
00697 
00698 
00699 }
00700 /**
00701 * update a card in ajax
00702 */
00703 function update_card(obj)
00704 {
00705 try {
00706     var name=obj.id;
00707     var qs=Form.serialize(name)+'&op=upc';
00708     var action=new Ajax.Request ( 'ajax_card.php',
00709                                   {
00710                                       method:'get',
00711                                       parameters:qs,
00712                                       onFailure:errorFid,
00713                                       onSuccess:successFill_ipopcard
00714                                   }
00715                                 );
00716     } catch (e) {
00717         alert(e.message);
00718         return false;
00719     }
00720 }
 All Data Structures Namespaces Files Functions Variables Enumerations