noalyss Version-9
admin.js
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Dany De Bontridder <dany@alchimerys.be>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program 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 this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18/**
19 * @file
20 * contains the javascript for the administration page
21 */
22/**
23 * Display the forbidden folders if the request comes from a form
24 * with an input text (id:database_filter_input) then this text is
25 * used as a filter
26 * @param {type} p_user : the user id
27 * @returns nothing
28 */
29function folder_display(p_user)
30{
31 /**
32 * If form exist and there is something
33 *
34 */
35 var p_filter = "";
36 if ($('database_filter_input')) {
37 p_filter = $('database_filter_input').value;
38 }
39 /*
40 * Ajax request to display the folder
41 */
42 new Ajax.Request('ajax_misc.php', {
43 method: "get",
44 parameters: {"p_user": p_user, "op": "folder_display", "p_filter": p_filter, 'gDossier': 0},
45 onSuccess: function (p_xml) {
46 // table id = database_list
47 var folder = {};
48 var create = false;
49 if (!$('folder_list_div')) {
50 folder = create_div({'id': 'folder_list_div', 'cssclass': "inner_box", 'style': 'width:90%,right:5%;top:100px'});
51 create = true;
52 }
53 folder = $('folder_list_div');
54 // Analyze XML answer
55 var answer = p_xml.responseXML;
56 var a = answer.getElementsByTagName('status');
57 var html = answer.getElementsByTagName('content');
58 if (a.length == 0) {
59 var rec = req.responseText;
60 alert_box('erreur :' + rec);
61 }
62
63 var content = getNodeText(html[0]);
64 // fill up the div
65 folder.innerHTML = unescape_xml(content);
66 folder.innerHTML.evalScripts();
67 // show it
68 folder.show();
69 $('database_filter_input').focus();
70 }
71 });
72}
73/**
74 * Remove the grant for an user to the given database id
75 * @param {integer} p_user use_id id of the user
76 * @param {integer} p_dossier id of the database
77 * @returns nothing
78 */
79function folder_remove(p_user,p_dossier )
80{
81 smoke.confirm (content[50] ,
82 function (e) {
83 if (e ) {
84 waiting_box();
85 new Ajax.Request('ajax_misc.php', {
86 method: "get",
87 parameters: {"p_user": p_user, 'p_dossier': p_dossier, "op": "folder_remove", 'gDossier': 0},
88 onSuccess: function (p_xml) {
89 // table id = database_list
90 new Effect.Opacity('row'+p_dossier, { from: 1.0, to: 0.0, duration: 0.2 });
91 remove_waiting_box();
92 }
93
94 });
95 } else {
96 return ;
97 }
98 });
99}
100
101/**
102 * Grant the access to a folder for a given user and add a row in the table
103 * (id : database_list)
104 * @param {integer} p_user use_id id of the user
105 * @param {integer} p_dossier id of the database
106 * @returns {undefined}
107 */
108function folder_add(p_user, p_dossier)
109{
110 waiting_box();
111 new Ajax.Request('ajax_misc.php', {
112 method: "get",
113 parameters: {"p_user": p_user, 'p_dossier': p_dossier, "op": "folder_add", 'gDossier': 0},
114 onSuccess: function (p_xml) {
115 // table id = database_list
116 // Analyze XML answer
117 var answer = p_xml.responseXML;
118 var a = answer.getElementsByTagName('status');
119 var html = answer.getElementsByTagName('content');
120 if (a.length == 0) {
121 var rec = req.responseText;
122 alert_box('FOLDERADD-'+content[48] + rec);
123 }
124
125 var content = getNodeText(html[0]);
126 var nb = $('database_list').rows.length + 1;
127 var row = new Element('tr', {'id': 'row' + p_dossier});
128 if (nb % 2 == 0) {
129 row.addClassName('even');
130 } else {
131 row.addClassName('odd');
132 }
133 row.innerHTML = unescape_xml(content);
134 $('database_list').appendChild(row);
135 $('row_db_'+p_dossier).hide();
136 remove_waiting_box();
137 }
138 });
139
140}
141function display_admin_answer(p_dossier,p_action)
142{
143 waiting_box();
144 new Ajax.Request ("ajax_misc.php",{
145 method:"get",
146 parameters:{"p_dossier":p_dossier,"op":p_action,'gDossier':0},
147 onSuccess : function (p_xml) {
148 try {
149 var div_display="folder_admin_div";
150 var answer = p_xml.responseXML;
151 var a = answer.getElementsByTagName('status');
152 var html = answer.getElementsByTagName('content');
153 if (a.length == 0) {
154 var rec = req.responseText;
155 alert_box('erreur :' + rec);
156 }
157
158 var folder;
159 var create = false;
160 if (!$(div_display)) {
161 folder = create_div({'id': div_display, 'cssclass': "inner_box", style: 'width:90%;right:5%;top:100px'});
162 create = true;
163 }
164 folder=$(div_display);
165
166 var content = getNodeText(html[0]);
167 folder.innerHTML=unescape_xml(content);
168 var pos=calcy(250);
169 $(div_display).setStyle({top:pos+'px'});
170
171 folder.show();
172 remove_waiting_box();
173 } catch (e) {
174 alert_box(e.message);
175 }
176 }
177 });
178}
179function folder_drop(p_dossier)
180{
181 display_admin_answer(p_dossier,'folder_drop');
182}
183
184function folder_modify(p_dossier)
185{
186 display_admin_answer(p_dossier,'folder_modify');
187}
188function modele_modify(p_dossier)
189{
190 display_admin_answer(p_dossier,'modele_modify');
191}
192function modele_drop(p_dossier)
193{
194 display_admin_answer(p_dossier,'modele_drop');
195}