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