2 * This file is part of NOALYSS.
4 * NOALYSS is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * NOALYSS is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with NOALYSS; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
23 * This file permit to use the AJAX function to fill up
29 * clean the row (the label, price and vat)
30 * @param p_ctl the calling ctrl
32function clean_Fid(p_ctl)
35 nTvaAmount=p_ctl+"_tva_amount";
37 nTva_id=p_ctl+"_tva_id";
48 $(nTva_id).value="-1";
52 $(nTvaAmount).value=0;
55function errorFid(request,json)
57 alert_box('ERRFID'+content[48]);
60 * this function fills the data from fid.php,
61 * @param {object} p_ctl : field of the input,
62 * possible object member
63 * - label field to update with the card's name
64 * - price field to update with the card's price
65 * - tvaid field to update with the card's tva_id
66 * - jrn field to force the ledger
67 *@see successFid errorFid fid.php
69function ajaxFid(p_ctl)
73 var gDossier=$('gDossier').value;
75 $(p_ctl).value=$(p_ctl).value.toUpperCase();
76 if ( jrn == undefined )
78 if ($('p_jrn')!=undefined)
83 if ( jrn == undefined )
87 if ( trim($(p_ctl).value)=="" )
89 nLabel=$(p_ctl).label;
93 $(nLabel).innerHTML=" ";
98 var queryString="FID="+trim($(p_ctl).value);
101 queryString+='&l='+$(p_ctl).label;
105 queryString+='&t='+$(p_ctl).tvaid;
109 queryString+='&p='+$(p_ctl).price;
111 if ( $(p_ctl).purchase)
113 queryString+='&b='+$(p_ctl).purchase;
115 if ( $(p_ctl).typecard)
117 queryString+='&d='+$(p_ctl).typecard;
119 queryString=queryString+"&j="+jrn+'&gDossier='+gDossier;
120 queryString=queryString+'&ctl='+p_ctl.id;
121 queryString=encodeURI(queryString);
123 var action=new Ajax.Request (
127 parameters:queryString,
134 alert_box(e.message);
140 callback function for ajax
141 * @param request : object request
142 * @param json : json answer
146 "name":"Chambre de commerce",
149 "fPrice_sale":"none",
151 "fPrice_purchase":"none",
155function successFid(request,json)
157 if (request.responseText === 'NOCONX') { reconnect();return;}
159 var answer=request.responseText.evalJSON(true);
160 var flabel=answer.flabel;
161 if ( answer.answer=='nok' )
163 set_value(flabel," Fiche inexistante");
167 var ftva_id=answer.ftva_id;
168 var fsale=answer.fPrice_sale;
169 var fpurchase=answer.fPrice_purchase;
171 if ( ftva_id != 'none')
173 set_value(ftva_id,answer.tva_id);
175 if ( flabel != 'none')
177 set_value(flabel,answer.name);
179 if ( fsale != 'none')
181 set_value(fsale,answer.sell);
183 if ( fpurchase != 'none')
185 set_value(fpurchase,answer.buy);
190function ajax_error_saldo(request,json)
192 alert_box('ERRSAL'+content[48]);
194/*!\brief this function get the saldo
195 * \param p_ctl the ctrl where we take the quick_code
197function ajax_saldo(p_ctl)
199 var gDossier=$('gDossier').value;
200 var ctl_value=trim($(p_ctl).value);
201 var jrn=$('p_jrn').value;
202 queryString="FID="+ctl_value+"&op=saldo";
203 queryString=queryString+'&gDossier='+gDossier+'&j='+jrn;
204 queryString=queryString+'&ctl='+ctl_value;
205 /* alert_box(queryString); */
206 var action=new Ajax.Request (
210 parameters:queryString,
211 onFailure:ajax_error_saldo,
212 onSuccess:ajax_success_saldo
218/*!\brief callback function for ajax
219 * \param request : object request
220 * \param json : json answer */
221function ajax_success_saldo(request,json)
223 var answer=request.responseText.evalJSON(true);
224 $('first_sold').value=answer.saldo;
229 * callback function for ajax_get when successuf
231function ajax_get_success(request,json)
233 var answer=request.responseText.evalJSON(false);
234 $(answer.ctl).show();
235 $(answer.ctl).innerHTML=answer.html;
237/*!\brief callback function for ajax_get when fails
239function ajax_get_failure(request,json)
241 alert_box(content[53]);
248 * Add an attribute selected in "sel"+p_object_name into the list (id:p_object_name+"_list")
249 * this attribut will have the ID:p_object_name+"_elt"+ad_id (ad_id = attr_def.ad_id)
250 * @param int p_dossier dossier nb
251 * @param int p_fiche_def_ref is the frd_id
252 * @param string p_object_name , name of the prefix for id
254category_card.add_attribut=function (p_dossier,p_fiche_def_ref,p_object_name) {
255 var select=$("sel"+p_object_name);
256 var selected_attr=select.value;
257 new Ajax.Request("ajax_misc.php",{
259 parameters:{"gDossier":p_dossier,
260 "objname":p_object_name,
261 "op":"template_cat_category",
262 "action":"add_attribute",
263 "frd_id":p_fiche_def_ref,
264 "ad_id":selected_attr
266 onSuccess:function(req) {
267 var answer=req.responseText.evalJSON();
268 if ( answer.status == 'OK') {
269 var newli=document.createElement("li")
270 newli.setAttribute("id",p_object_name+"_elt"+selected_attr);
271 newli.innerHTML=answer.content
272 $(p_object_name+"_list").append(newli);
273 select.remove(select.selectedIndex);
275 smoke.alert(answer.message);
281 * Remove an attribute (id:p_object_name+"_elt"+ad_id (ad_id = attr_def.ad_id))
282 * from the list (id:p_object_name+"list")
283 * @param {int} p_dossier dossier nb
284 * @param {string} p_object_name , name of the prefix for id
285 * @param {int} p_fiche_def_ref is the frd_id
286 * @param {type} p_attribute_id
288category_card.remove_attribut=function (p_dossier,p_fiche_def_ref,p_object_name,p_attribute_id) {
289 new Ajax.Request("ajax_misc.php",{
291 parameters:{"gDossier":p_dossier,
292 "objname":p_object_name,
293 "op":"template_cat_category",
294 "action":"remove_attribute",
295 "frd_id":p_fiche_def_ref,
296 "ad_id":p_attribute_id
298 onSuccess:function(req) {
299 var answer=req.responseText.evalJSON();
300 if ( answer.status == 'OK') {
301 $(p_object_name+"_elt"+p_attribute_id).remove();
302 var option=document.createElement("option");
303 option.text=answer['content'];
304 option.value=p_attribute_id;
305 $('sel'+p_object_name).add(option);
307 smoke.alert(answer.message);