noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
gestion.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 scripts for the gestion
25 *
26 */
27
28
29
30/**
31 * remove an attached document of an action
32 *@param {int} dossier
33 *@param {int} dt_id id of the document (pk document:d_id)
34*/
35function remove_document(p_dossier,p_id)
36{
37 var queryString={
38 "gDossier":p_dossier,
39 "a":"rm",
40 "d_id":p_id,
41 'act':'RAW:document'
42 };
43 var action=new Ajax.Request (
44 "export.php",
45 {
46 method:'get',
47 parameters:queryString,
48 onFailure:errorRemoveDoc,
49 onSuccess:successRemoveDoc
50 }
51
52 );
53
54}
55
56
57/**
58 * remove the concerned operation of an action
59 *@param dossier
60 *@param p_id id pk action_comment_operation
61*/
62function remove_operation(p_dossier,p_id)
63{
64 var queryString={
65 "gDossier":p_dossier,
66 "a":"rmop",
67 "id":p_id,
68 'act':'RAW:document'
69 };
70 var action=new Ajax.Request (
71 "export.php",
72 {
73 method:'get',
74 parameters:queryString,
75 onFailure:errorRemoveDoc,
76 onSuccess:successRemoveOp
77 }
78
79 );
80
81}
82function successRemoveOp(request,json)
83{
84 try{
85 var answer=request.responseText.evalJSON(true);
86 if ( answer.ago_id == -1 ) { alert_box (content[59]);return;}
87
88 var action="acop"+answer.ago_id;
89 $(action).innerHTML="";
90 var doc="op"+answer.ago_id;
91 $(doc).style.color="red";
92 $(doc).href="javascript:alert_box(content[60])";
93 $(doc).style.textDecoration="line-through";
94 }catch(e){
95 alert_box(e.message);
96 }
97}
98/**
99 * remove the concerned operation of an action
100 *@param dossier
101 *@param p_id id pk action_comment_operation
102*/
103function remove_action(p_dossier,p_id,ag_id)
104{
105 var queryString={
106 "gDossier":p_dossier,
107 "a":"rmaction",
108 "id":p_id,
109 "ag_id":ag_id,
110 'act':'RAW:document'
111 };
112 var action=new Ajax.Request (
113 "export.php",
114 {
115 method:'get',
116 parameters:queryString,
117 onFailure:ajax_misc_failure,
118 onSuccess:function(request,json) {
119 try{
120 var answer=request.responseText.evalJSON(true);
121 if ( answer.act_id == -1 ) { alert_box (content[59]);return;}
122 var action="acact"+answer.act_id;
123 $(action).innerHTML="";
124 var doc="act"+answer.act_id;
125 $(doc).style.color="red";
126 $(doc).href="javascript:alert_box(content[60])";
127 $(doc).style.textDecoration="line-through";
128 } catch (e){ alert_box(e.message);}
129 }
130 }
131
132 );
133
134}
135/**
136 * remove comment of an action
137 *@param dossier
138 *@param p_id pk action_gestion_comment
139*/
140function remove_comment(p_dossier,p_id)
141{
142 var queryString={
143 "gDossier":p_dossier,
144 "a":"rmcomment",
145 "id":p_id,
146 'act':'RAW:document'
147 };
148 var action=new Ajax.Request (
149 "export.php",
150 {
151 method:'get',
152 parameters:queryString,
153 onFailure:errorRemoveDoc,
154 onSuccess:successRemoveComment
155 }
156
157 );
158
159}
160function successRemoveComment(request,json)
161{
162 var answer=request.responseText.evalJSON(true);
163 if ( answer.agc_id == -1 ) { alert_box (content[59]);return;}
164 var action="accom"+answer.agc_id;
165 $(action).innerHTML="";
166 var doc="com"+answer.agc_id;
167 $(doc).style.color="red";
168 $(doc).href="javascript:alert_box(content[60])";
169 $(doc).style.textDecoration="line-through";
170
171}
172/**
173 * error if a document if removed
174 */
175function errorRemoveDoc()
176{
177 alert_box('Impossible d\'effacer ce document');
178}
179/**
180 * success when removing a document
181 */
182function successRemoveDoc(request,json)
183{
184 var answer=request.responseText.evalJSON(true);
185 if ( answer.d_id == -1 ) { alert_box ('Effacement non autorisé');return;}
186 var action="ac"+answer.d_id;
187 $(action).innerHTML="";
188 var doc="doc"+answer.d_id;
189 $(doc).style.color="red";
190 $(doc).href="javascript:alert_box(content[60])";
191 $(doc).style.textDecoration="line-through";
192 $('desc'+answer.d_id).innerHTML="";
193
194}
195/**
196* check the format of the hour
197* @param p_ctl is the control where the hour is encoded
198*/
199function check_hour(p_ctl)
200{
201 try
202 {
203 var h=document.getElementById(p_ctl);
204 var re = /^\d{1,2}:\d{2}$/;
205 if ( trim(h.value) !='' && ! h.value.match(re))
206 alert_box("HH:MM ")
207 }
208 catch (erreur)
209 {
210 alert_box('fct : check_hour '+erreur);
211 }
212
213}
214/**
215 * remove an attached document of an action
216 *@param dossier
217 *@param dt_id id of the document (pk document:d_id)
218*/
219
220function removeStock(s_id,p_dossier)
221{
222 smoke.confirm(content[50],
223 function (a) {
224 if (a)
225 {
226 queryString="gDossier="+p_dossier+"&op=rm_stock&s_id="+s_id;
227 var action=new Ajax.Request (
228 "ajax_misc.php",
229 {
230 method:'get',
231 parameters:queryString,
232 onFailure:errorRemoveStock,
233 onSuccess:successRemoveStock
234 }
235 );
236
237 }
238 else {
239 return ;
240 }
241 });
242}
243/**
244 * error if a document if removed
245 */
246function errorRemoveStock()
247{
248 alert_box(content[60]);
249}
250/**
251 * success when removing a document
252 */
253function successRemoveStock(request,json)
254{
255 try
256 {
257 var answer=request.responseText.evalJSON(true);
258 var doc="stock"+answer.d_id;
259 var href="href"+answer.d_id;
260 $(href).innerHTML='';
261
262 $(doc).style.color="red";
263 // $(doc).href="javascript:alert_box('Stock Effacé')";
264 $(doc).style.textDecoration="line-through";
265 } catch (e)
266{
267 alert_box("success_box"+e.message);
268 }
269}
270/**
271 * display details of the last actions in management
272 * called from dashboard
273 * @param p_dossier : dossier id
274 */
275function action_show(p_dossier)
276{
277 try {
278 waiting_box();
279 var action = new Ajax.Request('ajax_misc.php',
280 {
281 method:'get',
282 parameters : {gDossier:p_dossier,'op':'action_show'},
283 onSuccess : function(p_xml, p_text) {
284 remove_waiting_box();
285 add_div({id: 'action_list_div', style:"position:fixed;top:1%;width:90%;left:5%" , cssclass: 'inner_box'});
286 $('action_list_div').innerHTML=p_xml.responseText;
287 var table_followup=document.getElementById('event_followup');
288 if ( table_followup) { sorttable.makeSortable(table_followup); }
289 }
290 });
291 } catch (e)
292 {
293 alert_box('action_show '+e.message);
294 }
295}
296/**
297 * Display a box for adding a new event
298 * @param {type} p_dossier
299 * @returns {undefined}
300 */
301function action_add(p_dossier) {
302 try {
303 if ( $('action_add_div')) {
304 alert_box(content[61]);
305 return;
306 }
307 waiting_box();
308 var action = new Ajax.Request('ajax_misc.php',
309 {
310 method:'get',
311 parameters : {gDossier:p_dossier,'op':'action_add'},
312 onSuccess : function(p_xml, p_text) {
313 if (p_xml.responseText === 'NOCONX') { reconnect();return;}
314 remove_waiting_box();
315 add_div({id: 'action_add_div',style:'top:25px',
316 cssclass: 'inner_box'});
317 $('action_add_div').innerHTML=p_xml.responseText;
318 p_xml.responseText.evalScripts();
319 }
320 });
321 } catch (e)
322 {
323 alert_box('action_add '+e.message);
324 }
325}
326/**
327 * The new event is entered into the div action_add_div, we try
328 * to save and receive as answer a XML file with a code of success and possibly
329 * a message
330 * If the message is OK then the div is fading out, otherwise the reason of
331 * failure is shown and the div remains
332 */
333function action_save_short()
334{
335 try {
336 $('action_add_frm_info').innerHTML="";
337 $('action_add_frm')['date_event_action_short'].parentNode.className="";
338 $('action_add_frm')['title_event'].parentNode.className="";
339 $('action_add_frm')['type_event'].parentNode.className="";
340 $('action_add_frm')['hour_event'].parentNode.className="";
341
342 if ( $('action_add_frm')['date_event_action_short'].value.trim() == '') {
343 $('action_add_frm')['date_event_action_short'].parentNode.className="notice";
344 return false;
345 }
346
347 if ( $('action_add_frm')['title_event'].value.trim()=="") {
348 $('action_add_frm')['title_event'].parentNode.className="notice";
349 return false;
350 }
351 var str_hour=new String($('action_add_frm')['hour_event'].value);
352 str_hour=str_hour.trim();
353
354 if ( str_hour.trim() != ""
355 && str_hour.search(/^[0-9]{2}:[0-9]{2}$/) == -1 &&
356 str_hour.search(/^[0-9]{2}.[0-9]{2}$/) == -1)
357 {
358 $('action_add_frm')['hour_event'].parentNode.className="notice";
359 alert_box('HH:MM or HH.MM');
360 return false;
361 }
362
363 if ( $('action_add_frm')['type_event'].options[$('action_add_frm')['type_event'].selectedIndex].value == -1 )
364 {
365 $('action_add_frm')['type_event'].parentNode.className="notice";
366 return false;
367 }
368 var form=$('action_add_frm').serialize();
369 waiting_box();
370 var action = new Ajax.Request('ajax_misc.php',
371 {
372 method: 'get',
373 parameters: form,
374 onSuccess: function (p_xml, p_text) {
375 remove_waiting_box();
376 var answer=p_xml.responseXML;
377 var code_tags=answer.getElementsByTagName('status');
378 var code=getNodeText(code_tags[0]);
379 var message_tags=answer.getElementsByTagName('content');
380 var message=getNodeText(message_tags[0]);
381
382 if ( code == 'OK') {
383 // Successfully saved
384 $('action_add_frm_info').innerHTML=message;
385 $('action_add_div').remove();
386
387 }
388 else if (code == 'NOK') {
389 // issue while saving
390 $('action_add_frm_info').innerHTML=message;
391 alert_box(message);
392 }
393
394
395 }
396 });
397 } catch (e)
398 {
399 alert_box('action_add ' + e.message);
400 }
401 return false;
402}
403
404/**
405 * list of filter for follow up
406 * @param p_dossier int dossier id
407 * @param access_code string access_code
408 */
409function list_filter_followup(p_dossier,access_code)
410{
411 var queryString={
412 "gDossier":p_dossier,
413 "op":"list_filter_followup",
414 "ctl":"filter_followup_id",
415 "ac":access_code
416 };
417 var action=new Ajax.Request (
418 "ajax_misc.php",
419 {
420 method:'get',
421 parameters:queryString,
422 onSuccess:function(responseHtml)
423 {
424 var posy=calcy(250)
425 var div = create_div({"id":"filter_followup_id",
426 'cssclass': "inner_box2", 'style': 'top:'+posy+"px"});
427 div.update(responseHtml.responseText);
428 div.show();
429 }
430 }
431
432 );
433}
434
435/**
436 * @brief delete a filter of follow-up
437 * @param p_dossier int dossier id
438 * @param filter_id int table: action_gestion_comment.af_id
439 */
440function delete_filter_followup(p_dossier,filter_id)
441{
442 smoke.confirm(content[47], function (e) {
443 if (e) {
444
445 var queryString = {
446 "gDossier": p_dossier,
447 "op": "delete_filter_followup",
448 "ctl": "filter_followup_id",
449 "filter_id": filter_id
450 };
451 var action = new Ajax.Request(
452 "ajax_misc.php",
453 {
454 method: 'get',
455 parameters: queryString,
456 onSuccess: function (responseHtml) {
457 $('item_fu' + filter_id).remove();
458 }
459 }
460 );
461 }
462 }
463 );
464}