noalyss Version-9
ajax_fiche.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 * This file permit to use the AJAX function to fill up
24 * info from fiche
25 *
26 */
27
28/**
29 * clean the row (the label, price and vat)
30 * @param p_ctl the calling ctrl
31 */
32function clean_Fid(p_ctl)
33{
34 nSell=p_ctl+"_price";
35 nTvaAmount=p_ctl+"_tva_amount";
36 nBuy=p_ctl+"_price";
37 nTva_id=p_ctl+"_tva_id";
38 if ( $(nSell) )
39 {
40 $(nSell).value="";
41 }
42 if ( $(nBuy) )
43 {
44 $(nBuy).value="";
45 }
46 if ( $(nTva_id) )
47 {
48 $(nTva_id).value="-1";
49 }
50 if ( $(nTvaAmount))
51 {
52 $(nTvaAmount).value=0;
53 }
54}
55function errorFid(request,json)
56{
57 alert_box('ERRFID'+content[48]);
58}
59/**
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
68 */
69function ajaxFid(p_ctl)
70{
71 try
72 {
73 var gDossier=$('gDossier').value;
74 var jrn=$(p_ctl).jrn;
75 $(p_ctl).value=$(p_ctl).value.toUpperCase();
76 if ( jrn == undefined )
77 {
78 if ($('p_jrn')!=undefined)
79 {
80 jrn=$('p_jrn').value;
81 }
82 }
83 if ( jrn == undefined )
84 {
85 jrn=-1;
86 }
87 if ( trim($(p_ctl).value)=="" )
88 {
89 nLabel=$(p_ctl).label;
90 if ($(nLabel) )
91 {
92 $(nLabel).value="";
93 $(nLabel).innerHTML=" ";
94 clean_Fid(p_ctl);
95 return;
96 }
97 }
98 var queryString="FID="+trim($(p_ctl).value);
99 if ( $(p_ctl).label)
100 {
101 queryString+='&l='+$(p_ctl).label;
102 }
103 if ( $(p_ctl).tvaid)
104 {
105 queryString+='&t='+$(p_ctl).tvaid;
106 }
107 if ( $(p_ctl).price)
108 {
109 queryString+='&p='+$(p_ctl).price;
110 }
111 if ( $(p_ctl).purchase)
112 {
113 queryString+='&b='+$(p_ctl).purchase;
114 }
115 if ( $(p_ctl).typecard)
116 {
117 queryString+='&d='+$(p_ctl).typecard;
118 }
119 queryString=queryString+"&j="+jrn+'&gDossier='+gDossier;
120 queryString=queryString+'&ctl='+p_ctl.id;
121 queryString=encodeURI(queryString);
122
123 var action=new Ajax.Request (
124 "fid.php",
125 {
126 method:'get',
127 parameters:queryString,
128 onFailure:errorFid,
129 onSuccess:successFid
130 }
131
132 );
133 }catch (e) {
134 alert_box(e.message);
135 alert_box(p_ctl);
136 }
137
138}
139/**
140 callback function for ajax
141 * @param request : object request
142 * @param json : json answer
143@verbatim
144 {"answer":"ok",
145 "flabel":"none",
146 "name":"Chambre de commerce",
147 "ftva_id":"none",
148 "tva_id":" ",
149 "fPrice_sale":"none",
150 "sell":" ",
151 "fPrice_purchase":"none",
152 "buy":" "}
153@endverbatim
154 */
155function successFid(request,json)
156{
157 if (request.responseText === 'NOCONX') { reconnect();return;}
158
159 var answer=request.responseText.evalJSON(true);
160 var flabel=answer.flabel;
161 if ( answer.answer=='nok' )
162 {
163 set_value(flabel," Fiche inexistante");
164 return;
165 }
166
167 var ftva_id=answer.ftva_id;
168 var fsale=answer.fPrice_sale;
169 var fpurchase=answer.fPrice_purchase;
170
171 if ( ftva_id != 'none')
172 {
173 set_value(ftva_id,answer.tva_id);
174 }
175 if ( flabel != 'none')
176 {
177 set_value(flabel,answer.name);
178 }
179 if ( fsale != 'none')
180 {
181 set_value(fsale,answer.sell);
182 }
183 if ( fpurchase != 'none')
184 {
185 set_value(fpurchase,answer.buy);
186 }
187
188
189}
190function ajax_error_saldo(request,json)
191{
192 alert_box('ERRSAL'+content[48]);
193}
194/*!\brief this function get the saldo
195 * \param p_ctl the ctrl where we take the quick_code
196 */
197function ajax_saldo(p_ctl)
198{
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 (
207 "ajax_misc.php",
208 {
209 method:'get',
210 parameters:queryString,
211 onFailure:ajax_error_saldo,
212 onSuccess:ajax_success_saldo
213 }
214
215 );
216
217}
218/*!\brief callback function for ajax
219 * \param request : object request
220 * \param json : json answer */
221function ajax_success_saldo(request,json)
222{
223 var answer=request.responseText.evalJSON(true);
224 $('first_sold').value=answer.saldo;
225
226}
227
228/**
229 * callback function for ajax_get when successuf
230*/
231function ajax_get_success(request,json)
232{
233 var answer=request.responseText.evalJSON(false);
234 $(answer.ctl).show();
235 $(answer.ctl).innerHTML=answer.html;
236}
237/*!\brief callback function for ajax_get when fails
238*/
239function ajax_get_failure(request,json)
240{
241 alert_box(content[53]);
242
243}
244
245var category_card={};
246
247/**
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
253 */
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",{
258 method:"post",
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
265 },
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);
274 } else {
275 smoke.alert(answer.message);
276 }
277 }
278 });
279};
280/**
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
287 */
288category_card.remove_attribut=function (p_dossier,p_fiche_def_ref,p_object_name,p_attribute_id) {
289 new Ajax.Request("ajax_misc.php",{
290 method:"post",
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
297 },
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);
306 } else {
307 smoke.alert(answer.message);
308 }
309 }
310 });
311};
312
313//-->