1 | /** |
---|
2 | * ----------------------------------------------------------------------------- |
---|
3 | * file: criteriaBuilderSearch.js |
---|
4 | * file version: 1.1.1 |
---|
5 | * date: 2011-05-15 |
---|
6 | * |
---|
7 | * JS file provided by the piwigo's plugin "GrumPluginClasses" |
---|
8 | * |
---|
9 | * ----------------------------------------------------------------------------- |
---|
10 | * Author : Grum |
---|
11 | * email : grum@piwigo.com |
---|
12 | * website : http://www.grum.fr |
---|
13 | * |
---|
14 | * << May the Little SpaceFrog be with you ! >> |
---|
15 | * ----------------------------------------------------------------------------- |
---|
16 | * |
---|
17 | * used to manage the requestBuilder search interface |
---|
18 | * |
---|
19 | * :: HISTORY :: |
---|
20 | * |
---|
21 | * | release | date | |
---|
22 | * | 1.0.0 | 2010/04/27 | * start to coding |
---|
23 | * | | | |
---|
24 | * | 1.1.0 | 2010/10/21 | * change ajax methods |
---|
25 | * | | | |
---|
26 | * | | | * fix bug : if there is no criteria, don't send |
---|
27 | * | | | request |
---|
28 | * | | | |
---|
29 | * | 1.1.1 | 2011/05/15 | * fix some incompatibilities with IE7 |
---|
30 | * | | | |
---|
31 | * | | | |
---|
32 | * | | | |
---|
33 | * | | | |
---|
34 | * |
---|
35 | */ |
---|
36 | |
---|
37 | var cb=null; |
---|
38 | |
---|
39 | var interfaceManager = function(optionsToSet) |
---|
40 | { |
---|
41 | var pn=null, |
---|
42 | requestNumber=0, |
---|
43 | options = |
---|
44 | { |
---|
45 | requestCriterionsVisible:'', |
---|
46 | requestCriterionsHidden:'', |
---|
47 | requestResult:'', |
---|
48 | requestResultContent:'', |
---|
49 | requestResultNfo:'', |
---|
50 | requestResultPagesNavigator:'', |
---|
51 | requestResultRequestNumber:0, |
---|
52 | onPageChange:null, |
---|
53 | numberPerPage:30, |
---|
54 | token:'' |
---|
55 | }; |
---|
56 | |
---|
57 | /** |
---|
58 | * |
---|
59 | */ |
---|
60 | this.doAction = function(fct) |
---|
61 | { |
---|
62 | switch(fct) |
---|
63 | { |
---|
64 | case 'queryResult': |
---|
65 | /* function 'queryResult' : when query is executed, prepare the interface |
---|
66 | */ |
---|
67 | if(arguments.length==3) |
---|
68 | { |
---|
69 | displayQueryResult(arguments[1], arguments[2]); |
---|
70 | } |
---|
71 | break; |
---|
72 | case 'queryPage': |
---|
73 | /* function 'queryPage' : display returned page |
---|
74 | */ |
---|
75 | if(arguments.length==3) |
---|
76 | { |
---|
77 | displayQueryPage(arguments[1], arguments[2]); |
---|
78 | } |
---|
79 | break; |
---|
80 | case 'show': |
---|
81 | /* function 'show' : show/hide the query/result |
---|
82 | */ |
---|
83 | if(arguments.length==2) |
---|
84 | { |
---|
85 | show(arguments[1]); |
---|
86 | } |
---|
87 | break; |
---|
88 | case 'setOptions': |
---|
89 | /* function 'setOptions' : allows to set options after the object was |
---|
90 | * created |
---|
91 | */ |
---|
92 | if(arguments.length==2) |
---|
93 | { |
---|
94 | setOptions(arguments[1]); |
---|
95 | } |
---|
96 | break; |
---|
97 | case 'fillCaddie': |
---|
98 | /* function 'fillCaddie' : allows to fill the caddie with the search result |
---|
99 | * |
---|
100 | */ |
---|
101 | if(arguments.length==2) |
---|
102 | { |
---|
103 | fillCaddie(arguments[1], this.getRequestNumber()); |
---|
104 | } |
---|
105 | break; |
---|
106 | } |
---|
107 | }; |
---|
108 | |
---|
109 | /** |
---|
110 | * returns the current request number |
---|
111 | */ |
---|
112 | this.getRequestNumber = function () |
---|
113 | { |
---|
114 | return(requestNumber); |
---|
115 | }; |
---|
116 | |
---|
117 | /** |
---|
118 | * returns the number of items per page |
---|
119 | */ |
---|
120 | this.getNumberPerPage = function () |
---|
121 | { |
---|
122 | return(options.numberPerPage); |
---|
123 | }; |
---|
124 | |
---|
125 | /** |
---|
126 | * this function show/hide the different panels |
---|
127 | * 'buildQuery' : hide the result panel and display the panel to build query |
---|
128 | * 'resultQuery' : hide the panel to build query and display the result panel |
---|
129 | */ |
---|
130 | var show = function(mode) |
---|
131 | { |
---|
132 | switch(mode) |
---|
133 | { |
---|
134 | case 'buildQuery': |
---|
135 | $('.'+options.requestCriterionsVisible).css('display', 'block'); |
---|
136 | $('.'+options.requestCriterionsHidden).css('display', 'none'); |
---|
137 | $('.'+options.requestResult).css('display', 'none'); |
---|
138 | break; |
---|
139 | case 'resultQuery': |
---|
140 | $('#iResultQueryContent').html("<br><img class='waitingResult' src='./plugins/GrumPluginClasses/icons/processing.gif'>"); |
---|
141 | $('.'+options.requestCriterionsVisible).css('display', 'none'); |
---|
142 | $('.'+options.requestCriterionsHidden).css('display', 'block'); |
---|
143 | $('.'+options.requestResult).css('display', 'block'); |
---|
144 | break; |
---|
145 | } |
---|
146 | }, |
---|
147 | |
---|
148 | /** |
---|
149 | * this function display the number of items found and prepare the page |
---|
150 | * navigator |
---|
151 | * |
---|
152 | * @param String nfo : 2 information separated with a semi-colon ';' |
---|
153 | * requestNumber;numberOfItems |
---|
154 | */ |
---|
155 | displayQueryResult = function (isSuccess, nfo) |
---|
156 | { |
---|
157 | if(isSuccess) |
---|
158 | { |
---|
159 | nfo=nfo.split(';'); |
---|
160 | |
---|
161 | requestNumber=nfo[0]; |
---|
162 | $('#iResultQueryNfo').html(nfo[1]); |
---|
163 | pn.doAction('setOptions', { numberItem:nfo[1], defaultPage:1 } ); |
---|
164 | show('resultQuery'); |
---|
165 | } |
---|
166 | else |
---|
167 | { |
---|
168 | //$('#'+options.requestResultContent).html(""); |
---|
169 | show('buildQuery'); |
---|
170 | alert(requestBuilderOptions.textSomethingWrong); |
---|
171 | } |
---|
172 | }, |
---|
173 | |
---|
174 | |
---|
175 | /** |
---|
176 | * this function display the number of items found and prepare the page |
---|
177 | * navigator |
---|
178 | * |
---|
179 | * @param String nfo : 2 information separated with a semi-colon ';' |
---|
180 | * requestNumber;numberOfItems |
---|
181 | */ |
---|
182 | displayQueryPage = function (isSuccess, nfo) |
---|
183 | { |
---|
184 | if(isSuccess) |
---|
185 | { |
---|
186 | $('#iResultQueryContent').html(nfo); |
---|
187 | } |
---|
188 | else |
---|
189 | { |
---|
190 | alert(requestBuilderOptions.textSomethingWrong); |
---|
191 | } |
---|
192 | }, |
---|
193 | |
---|
194 | |
---|
195 | /** |
---|
196 | * |
---|
197 | * @param Object optionsToSet : set the given options |
---|
198 | */ |
---|
199 | setOptions = function(optionsToSet) |
---|
200 | { |
---|
201 | if(typeof optionsToSet=='object') |
---|
202 | { |
---|
203 | options = jQuery.extend(options, optionsToSet); |
---|
204 | } |
---|
205 | }, |
---|
206 | |
---|
207 | /** |
---|
208 | * initialize the object |
---|
209 | */ |
---|
210 | init = function (optionsToSet) |
---|
211 | { |
---|
212 | setOptions(optionsToSet); |
---|
213 | |
---|
214 | pn = new pagesNavigator(options.requestResultPagesNavigator, |
---|
215 | { |
---|
216 | itemPerPage:options.numberPerPage, |
---|
217 | displayNumPage:9, |
---|
218 | classActive:'pnActive', |
---|
219 | classInactive:'pnInactive', |
---|
220 | onPageChange: function (page) |
---|
221 | { |
---|
222 | if(options.onPageChange!=null && jQuery.isFunction(options.onPageChange)) |
---|
223 | { |
---|
224 | options.onPageChange(requestNumber, page, options.numberPerPage); |
---|
225 | } |
---|
226 | } |
---|
227 | } |
---|
228 | ); |
---|
229 | |
---|
230 | requestNumber=options.requestResultRequestNumber; |
---|
231 | }, |
---|
232 | |
---|
233 | /** |
---|
234 | * fill the caddie with the search results |
---|
235 | * @param String mode : 'add' or 'fill' |
---|
236 | */ |
---|
237 | fillCaddie = function (mode, requestNumber) |
---|
238 | { |
---|
239 | $('#iMenuCaddieImg').css('display', 'inline-block'); |
---|
240 | $('#iMenuCaddieItems ul').css('display', 'none'); |
---|
241 | |
---|
242 | $.ajax( |
---|
243 | { |
---|
244 | type: "POST", |
---|
245 | url: "plugins/GrumPluginClasses/gpc_ajax.php", |
---|
246 | async: true, |
---|
247 | data: { |
---|
248 | ajaxfct:"admin.rbuilder.fillCaddie", |
---|
249 | fillMode:mode, |
---|
250 | requestNumber:requestNumber, |
---|
251 | token:options.token |
---|
252 | }, |
---|
253 | success: |
---|
254 | function(msg) |
---|
255 | { |
---|
256 | $('#iMenuCaddieImg').css('display', 'none'); |
---|
257 | $('#iMenuCaddieItems ul').css('display', 'block'); |
---|
258 | alert(requestBuilderOptions.textCaddieUpdated); |
---|
259 | }, |
---|
260 | error: |
---|
261 | function(msg) |
---|
262 | { |
---|
263 | $('#iMenuCaddieImg').css('display', 'none'); |
---|
264 | $('#iMenuCaddieItems ul').css('display', 'block'); |
---|
265 | alert(requestBuilderOptions.textSomethingWrong); |
---|
266 | } |
---|
267 | } |
---|
268 | ); |
---|
269 | }; |
---|
270 | |
---|
271 | init(optionsToSet); |
---|
272 | }; |
---|
273 | |
---|
274 | |
---|
275 | function init() |
---|
276 | { |
---|
277 | im = new interfaceManager( |
---|
278 | { |
---|
279 | requestCriterionsVisible:'cRequestCriterions', |
---|
280 | requestCriterionsHidden:'cModifyRequest', |
---|
281 | requestResult:'cResultQuery', |
---|
282 | requestResultContent:'iResultQueryContent', |
---|
283 | requestResultNfo:'iResultQueryNfo', |
---|
284 | requestResultPagesNavigator:'iPagesNavigator' |
---|
285 | } |
---|
286 | ); |
---|
287 | |
---|
288 | requestBuilderOptions.classGroup='gcBorderInput gcTextInput'; |
---|
289 | requestBuilderOptions.classItem='gcBgInput gcTextInput'; |
---|
290 | requestBuilderOptions.classOperator='cbOperator cbOperatorBg gcLinkHover'; |
---|
291 | requestBuilderOptions.onRequestSuccess = function (msg) { im.doAction('queryResult', true, msg); cb.doAction('getPage', im.getRequestNumber(), 1, im.getNumberPerPage()); }; |
---|
292 | requestBuilderOptions.onRequestError = function (msg) { im.doAction('queryResult', false, msg); }; |
---|
293 | requestBuilderOptions.onGetPageSuccess = function (msg) { im.doAction('queryPage', true, msg); }; |
---|
294 | requestBuilderOptions.onGetPageError = function (msg) { im.doAction('queryPage', false, msg); }; |
---|
295 | |
---|
296 | cb = new criteriaBuilder('iListSelectedCriterions', requestBuilderOptions); |
---|
297 | |
---|
298 | im.doAction('setOptions', |
---|
299 | { |
---|
300 | onPageChange: |
---|
301 | function (requestNumber, page, numberPerPage) |
---|
302 | { |
---|
303 | $('#iResultQueryContent').html("<br><img class='waitingResult' src='./plugins/GrumPluginClasses/icons/processing.gif'>"); |
---|
304 | cb.doAction('getPage', requestNumber, page, numberPerPage); |
---|
305 | } |
---|
306 | } |
---|
307 | ); |
---|
308 | } |
---|