traclightningのリポジトリ
Revision | 6f571ca629ac98a6b94752a17469d67f2399cf25 (tree) |
---|---|
Time | 2011-05-29 15:03:53 |
Author | kanu_orz |
Commiter | kanu_orz |
マージ
@@ -1,1482 +1,1482 @@ | ||
1 | -;(function ($) { | |
2 | -/* | |
3 | - * jqGrid 3.3.2 - jQuery Grid | |
4 | - * Copyright (c) 2008, Tony Tomov, tony@trirand.com | |
5 | - * Dual licensed under the MIT and GPL licenses | |
6 | - * http://www.opensource.org/licenses/mit-license.php | |
7 | - * http://www.gnu.org/licenses/gpl.html | |
8 | - * Date: 2008-12-14 rev 74 | |
9 | - */ | |
10 | -$.fn.jqGrid = function( p ) { | |
11 | - p = $.extend(true,{ | |
12 | - url: "", | |
13 | - height: 150, | |
14 | - page: 1, | |
15 | - rowNum: 20, | |
16 | - records: 0, | |
17 | - pager: "", | |
18 | - pgbuttons: true, | |
19 | - pginput: true, | |
20 | - colModel: [], | |
21 | - rowList: [], | |
22 | - colNames: [], | |
23 | - sortorder: "asc", | |
24 | - sortname: "", | |
25 | - datatype: "xml", | |
26 | - mtype: "GET", | |
27 | - imgpath: "", | |
28 | - sortascimg: "sort_asc.gif", | |
29 | - sortdescimg: "sort_desc.gif", | |
30 | - firstimg: "first.gif", | |
31 | - previmg: "prev.gif", | |
32 | - nextimg: "next.gif", | |
33 | - lastimg: "last.gif", | |
34 | - altRows: true, | |
35 | - selarrrow: [], | |
36 | - savedRow: [], | |
37 | - shrinkToFit: true, | |
38 | - xmlReader: {}, | |
39 | - jsonReader: {}, | |
40 | - subGrid: false, | |
41 | - subGridModel :[], | |
42 | - lastpage: 0, | |
43 | - lastsort: 0, | |
44 | - selrow: null, | |
45 | - beforeSelectRow: null, | |
46 | - onSelectRow: null, | |
47 | - onSortCol: null, | |
48 | - ondblClickRow: null, | |
49 | - onRightClickRow: null, | |
50 | - onPaging: null, | |
51 | - onSelectAll: null, | |
52 | - loadComplete: null, | |
53 | - gridComplete: null, | |
54 | - loadError: null, | |
55 | - loadBeforeSend: null, | |
56 | - afterInsertRow: null, | |
57 | - beforeRequest: null, | |
58 | - onHeaderClick: null, | |
59 | - viewrecords: false, | |
60 | - loadonce: false, | |
61 | - multiselect: false, | |
62 | - multikey: false, | |
63 | - editurl: null, | |
64 | - search: false, | |
65 | - searchdata: {}, | |
66 | - caption: "", | |
67 | - hidegrid: true, | |
68 | - hiddengrid: false, | |
69 | - postData: {}, | |
70 | - userData: {}, | |
71 | - treeGrid : false, | |
72 | - treeANode: 0, | |
73 | - treedatatype: null, | |
74 | - treeReader: {level_field: "level", | |
75 | - left_field:"lft", | |
76 | - right_field: "rgt", | |
77 | - leaf_field: "isLeaf", | |
78 | - expanded_field: "expanded" | |
79 | - }, | |
80 | - tree_root_level: 0, | |
81 | - ExpandColumn: null, | |
82 | - sortclass: "grid_sort", | |
83 | - resizeclass: "grid_resize", | |
84 | - forceFit : false, | |
85 | - gridstate : "visible", | |
86 | - cellEdit: false, | |
87 | - cellsubmit: "remote", | |
88 | - nv:0, | |
89 | - loadui: "enable", | |
90 | - toolbar: [false,""] | |
91 | - }, $.jgrid.defaults, p || {}); | |
92 | - var grid={ | |
93 | - headers:[], | |
94 | - cols:[], | |
95 | - dragStart: function(i,x) { | |
96 | - this.resizing = { idx: i, startX: x}; | |
97 | - this.hDiv.style.cursor = "e-resize"; | |
98 | - }, | |
99 | - dragMove: function(x) { | |
100 | - if(this.resizing) { | |
101 | - var diff = x-this.resizing.startX; | |
102 | - var h = this.headers[this.resizing.idx]; | |
103 | - var newWidth = h.width + diff; | |
104 | - var msie = $.browser.msie; | |
105 | - if(newWidth > 25) { | |
106 | - if(p.forceFit===true ){ | |
107 | - var hn = this.headers[this.resizing.idx+p.nv]; | |
108 | - var nWn = hn.width - diff; | |
109 | - if(nWn >25) { | |
110 | - h.el.style.width = newWidth+"px"; | |
111 | - h.newWidth = newWidth; | |
112 | - this.cols[this.resizing.idx].style.width = newWidth+"px"; | |
113 | - hn.el.style.width = nWn +"px"; | |
114 | - hn.newWidth = nWn; | |
115 | - this.cols[this.resizing.idx+p.nv].style.width = nWn+"px"; | |
116 | - this.newWidth = this.width; | |
117 | - } | |
118 | - } else { | |
119 | - h.el.style.width = newWidth+"px"; | |
120 | - h.newWidth = newWidth; | |
121 | - this.cols[this.resizing.idx].style.width = newWidth+"px"; | |
122 | - this.newWidth = this.width+diff; | |
123 | - $('table:first',this.bDiv).css("width",this.newWidth +"px"); | |
124 | - $('table:first',this.hDiv).css("width",this.newWidth +"px"); | |
125 | - var scrLeft = this.bDiv.scrollLeft; | |
126 | - this.hDiv.scrollLeft = this.bDiv.scrollLeft; | |
127 | - if(msie) { | |
128 | - if(scrLeft - this.hDiv.scrollLeft >= 5) {this.bDiv.scrollLeft = this.bDiv.scrollLeft - 17;} | |
129 | - } | |
130 | - } | |
131 | - } | |
132 | - } | |
133 | - }, | |
134 | - dragEnd: function() { | |
135 | - this.hDiv.style.cursor = "default"; | |
136 | - if(this.resizing) { | |
137 | - var idx = this.resizing.idx; | |
138 | - this.headers[idx].width = this.headers[idx].newWidth || this.headers[idx].width; | |
139 | - this.cols[idx].style.width = this.headers[idx].newWidth || this.headers[idx].width; | |
140 | - if(p.forceFit===true){ | |
141 | - this.headers[idx+p.nv].width = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width; | |
142 | - this.cols[idx+p.nv].style.width = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width; | |
143 | - } | |
144 | - if(this.newWidth) {this.width = this.newWidth;} | |
145 | - this.resizing = false; | |
146 | - } | |
147 | - }, | |
148 | - scrollGrid: function() { | |
149 | - var scrollLeft = this.bDiv.scrollLeft; | |
150 | - this.hDiv.scrollLeft = this.bDiv.scrollLeft; | |
151 | - if(scrollLeft - this.hDiv.scrollLeft > 5) {this.bDiv.scrollLeft = this.bDiv.scrollLeft - 17;} | |
152 | - } | |
153 | - }; | |
154 | - $.fn.getGridParam = function(pName) { | |
155 | - var $t = this[0]; | |
156 | - if (!$t.grid) {return;} | |
157 | - if (!pName) { return $t.p; } | |
158 | - else {return $t.p[pName] ? $t.p[pName] : null;} | |
159 | - }; | |
160 | - $.fn.setGridParam = function (newParams){ | |
161 | - return this.each(function(){ | |
162 | - if (this.grid && typeof(newParams) === 'object') {$.extend(true,this.p,newParams);} | |
163 | - }); | |
164 | - }; | |
165 | - $.fn.getDataIDs = function () { | |
166 | - var ids=[]; | |
167 | - this.each(function(){ | |
168 | - $(this.rows).slice(1).each(function(i){ | |
169 | - ids[i]=this.id; | |
170 | - }); | |
171 | - }); | |
172 | - return ids; | |
173 | - }; | |
174 | - $.fn.setSortName = function (newsort) { | |
175 | - return this.each(function(){ | |
176 | - var $t = this; | |
177 | - for(var i=0;i< $t.p.colModel.length;i++){ | |
178 | - if($t.p.colModel[i].name===newsort || $t.p.colModel[i].index===newsort){ | |
179 | - $("tr th:eq("+$t.p.lastsort+") div img",$t.grid.hDiv).remove(); | |
180 | - $t.p.lastsort = i; | |
181 | - $t.p.sortname=newsort; | |
182 | - break; | |
183 | - } | |
184 | - } | |
185 | - }); | |
186 | - }; | |
187 | - $.fn.setSelection = function(selection,sd) { | |
188 | - return this.each(function(){ | |
189 | - var $t = this, stat,pt; | |
190 | - if(selection===false) {pt = sd;} | |
191 | - else { var ind = $($t).getInd($t.rows,selection); pt=$($t.rows[ind]);} | |
192 | - selection = $(pt).attr("id"); | |
193 | - if (!pt.html()) {return;} | |
194 | - if(!$t.p.multiselect) { | |
195 | - if($(pt).attr("class") !== "subgrid") { | |
196 | - if( $t.p.selrow ) {$("tr#"+$t.p.selrow+":first",$t.grid.bDiv).removeClass("selected");} | |
197 | - $t.p.selrow = selection; | |
198 | - $(pt).addClass("selected"); | |
199 | - if( $t.p.onSelectRow ) { $t.p.onSelectRow($t.p.selrow, true); } | |
200 | - } | |
201 | - } else { | |
202 | - $t.p.selrow = selection; | |
203 | - var ia = $.inArray($t.p.selrow,$t.p.selarrrow); | |
204 | - if ( ia === -1 ){ | |
205 | - if($(pt).attr("class") !== "subgrid") { $(pt).addClass("selected");} | |
206 | - stat = true; | |
207 | - $("#jqg_"+$t.p.selrow,$t.rows).attr("checked",stat); | |
208 | - $t.p.selarrrow.push($t.p.selrow); | |
209 | - if( $t.p.onSelectRow ) { $t.p.onSelectRow($t.p.selrow, stat); } | |
210 | - } else { | |
211 | - if($(pt).attr("class") !== "subgrid") { $(pt).removeClass("selected");} | |
212 | - stat = false; | |
213 | - $("#jqg_"+$t.p.selrow,$t.rows).attr("checked",stat); | |
214 | - $t.p.selarrrow.splice(ia,1); | |
215 | - if( $t.p.onSelectRow ) { $t.p.onSelectRow($t.p.selrow, stat); } | |
216 | - var tpsr = $t.p.selarrrow[0]; | |
217 | - $t.p.selrow = (tpsr=='undefined') ? null : tpsr; | |
218 | - } | |
219 | - } | |
220 | - }); | |
221 | - }; | |
222 | - $.fn.resetSelection = function(){ | |
223 | - return this.each(function(){ | |
224 | - var t = this; | |
225 | - if(!t.p.multiselect) { | |
226 | - if(t.p.selrow) { | |
227 | - $("tr#"+t.p.selrow+":first",t.grid.bDiv).removeClass("selected"); | |
228 | - t.p.selrow = null; | |
229 | - } | |
230 | - } else { | |
231 | - $(t.p.selarrrow).each(function(i,n){ | |
232 | - var ind = $(t).getInd(t.rows,n); | |
233 | - $(t.rows[ind]).removeClass("selected"); | |
234 | - $("#jqg_"+n,t.rows[ind]).attr("checked",false); | |
235 | - }); | |
236 | - $("#cb_jqg",t.grid.hDiv).attr("checked",false); | |
237 | - t.p.selarrrow = []; | |
238 | - } | |
239 | - }); | |
240 | - }; | |
241 | - $.fn.getRowData = function( rowid ) { | |
242 | - var res = {}; | |
243 | - if (rowid){ | |
244 | - this.each(function(){ | |
245 | - var $t = this,nm,ind; | |
246 | - ind = $($t).getInd($t.rows,rowid); | |
247 | - if (!ind) {return res;} | |
248 | - $('td', $t.rows[ind]).each( function(i) { | |
249 | - nm = $t.p.colModel[i].name; | |
250 | - if ( nm !== 'cb' && nm !== 'subgrid') { | |
251 | - res[nm] = $(this).html().replace(/\ \;/ig,'').replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"'); | |
252 | - } | |
253 | - }); | |
254 | - }); | |
255 | - } | |
256 | - return res; | |
257 | - }; | |
258 | - $.fn.delRowData = function(rowid) { | |
259 | - var success = false, rowInd; | |
260 | - if(rowid) { | |
261 | - this.each(function() { | |
262 | - var $t = this; | |
263 | - rowInd = $($t).getInd($t.rows,rowid); | |
264 | - if(!rowInd) {return success;} | |
265 | - else { | |
266 | - $($t.rows[rowInd]).remove(); | |
267 | - $t.p.records--; | |
268 | - $t.updatepager(); | |
269 | - success=true; | |
270 | - } | |
271 | - if(rowInd == 1 && success && ($.browser.opera || $.browser.safari)) { | |
272 | - $($t.rows[1]).each( function( k ) { | |
273 | - $(this).css("width",$t.grid.headers[k].width+"px"); | |
274 | - $t.grid.cols[k] = this; | |
275 | - }); | |
276 | - } | |
277 | - if( $t.p.altRows === true && success) { | |
278 | - $($t.rows).slice(1).each(function(i){ | |
279 | - if(i % 2 ==1) {$(this).addClass('alt');} | |
280 | - else {$(this).removeClass('alt');} | |
281 | - }); | |
282 | - } | |
283 | - }); | |
284 | - } | |
285 | - return success; | |
286 | - }; | |
287 | - $.fn.setRowData = function(rowid, data) { | |
288 | - var nm, success=false; | |
289 | - this.each(function(){ | |
290 | - var t = this; | |
291 | - if(!t.grid) {return false;} | |
292 | - if( data ) { | |
293 | - var ind = $(t).getInd(t.rows,rowid); | |
294 | - if(!ind) {return success;} | |
295 | - success=true; | |
296 | - $(this.p.colModel).each(function(i){ | |
297 | - nm = this.name; | |
298 | - if(data[nm] !== 'undefined') { | |
299 | - $("td:eq("+i+")",t.rows[ind]).html(data[nm]); | |
300 | - success = true; | |
301 | - } | |
302 | - }); | |
303 | - } | |
304 | - }); | |
305 | - return success; | |
306 | - }; | |
307 | - $.fn.addRowData = function(rowid,data,pos,src) { | |
308 | - if(!pos) {pos = "last";} | |
309 | - var success = false; | |
310 | - var nm, row, td, gi=0, si=0,sind; | |
311 | - if(data) { | |
312 | - this.each(function() { | |
313 | - var t = this; | |
314 | - row = document.createElement("tr"); | |
315 | - row.id = rowid || t.p.records+1; | |
316 | - $(row).addClass("jqgrow"); | |
317 | - if(t.p.multiselect) { | |
318 | - td = $('<td></td>'); | |
319 | - $(td[0],t.grid.bDiv).html("<input type='checkbox'"+" id='jqg_"+rowid+"' class='cbox'/>"); | |
320 | - row.appendChild(td[0]); | |
321 | - gi = 1; | |
322 | - } | |
323 | - if(t.p.subGrid ) { try {$(t).addSubGrid(t.grid.bDiv,row,gi);} catch(e){} si=1;} | |
324 | - for(var i = gi+si; i < this.p.colModel.length;i++){ | |
325 | - nm = this.p.colModel[i].name; | |
326 | - td = $('<td></td>'); | |
327 | - $(td[0]).html(' '); | |
328 | - if(data[nm] !== 'undefined') { | |
329 | - $(td[0]).html(data[nm]); | |
330 | - } | |
331 | - t.formatCol($(td[0],t.grid.bDiv),i); | |
332 | - row.appendChild(td[0]); | |
333 | - } | |
334 | - switch (pos) { | |
335 | - case 'last': | |
336 | - $(t.rows[t.rows.length-1]).after(row); | |
337 | - break; | |
338 | - case 'first': | |
339 | - $(t.rows[0]).after(row); | |
340 | - break; | |
341 | - case 'after': | |
342 | - sind = $(t).getInd(t.rows,src); | |
343 | - sind >= 0 ? $(t.rows[sind]).after(row): ""; | |
344 | - break; | |
345 | - case 'before': | |
346 | - sind = $(t).getInd(t.rows,src); | |
347 | - sind > 0 ? $(t.rows[sind-1]).after(row): ""; | |
348 | - break; | |
349 | - } | |
350 | - t.p.records++; | |
351 | - if($.browser.safari || $.browser.opera) { | |
352 | - t.scrollLeft = t.scrollLeft; | |
353 | - $("td",t.rows[1]).each( function( k ) { | |
354 | - $(this).css("width",t.grid.headers[k].width+"px"); | |
355 | - t.grid.cols[k] = this; | |
356 | - }); | |
357 | - } | |
358 | - if( t.p.altRows === true ) { | |
359 | - if (pos == "last") { | |
360 | - if (t.rows.length % 2 == 1) {$(row).addClass('alt');} | |
361 | - } else { | |
362 | - $(t.rows).slice(1).each(function(i){ | |
363 | - if(i % 2 ==1) {$(this).addClass('alt');} | |
364 | - else {$(this).removeClass('alt');} | |
365 | - }); | |
366 | - } | |
367 | - } | |
368 | - try {t.p.afterInsertRow(row.id,data); } catch(e){} | |
369 | - t.updatepager(); | |
370 | - success = true; | |
371 | - }); | |
372 | - } | |
373 | - return success; | |
374 | - }; | |
375 | - $.fn.hideCol = function(colname) { | |
376 | - return this.each(function() { | |
377 | - var $t = this,w=0, fndh=false; | |
378 | - if (!$t.grid ) {return;} | |
379 | - if( typeof colname == 'string') {colname=[colname];} | |
380 | - $(this.p.colModel).each(function(i) { | |
381 | - if ($.inArray(this.name,colname) != -1 && !this.hidden) { | |
382 | - var w = parseInt($("tr th:eq("+i+")",$t.grid.hDiv).css("width"),10); | |
383 | - $("tr th:eq("+i+")",$t.grid.hDiv).css({display:"none"}); | |
384 | - $($t.rows).each(function(j){ | |
385 | - $("td:eq("+i+")",$t.rows[j]).css({display:"none"}); | |
386 | - }); | |
387 | - $t.grid.cols[i].style.width = 0; | |
388 | - $t.grid.headers[i].width = 0; | |
389 | - $t.grid.width -= w; | |
390 | - this.hidden=true; | |
391 | - fndh=true; | |
392 | - } | |
393 | - }); | |
394 | - if(fndh===true) { | |
395 | - var gtw = Math.min($t.p._width,$t.grid.width); | |
396 | - $("table:first",$t.grid.hDiv).width(gtw); | |
397 | - $("table:first",$t.grid.bDiv).width(gtw); | |
398 | - $($t.grid.hDiv).width(gtw); | |
399 | - $($t.grid.bDiv).width(gtw); | |
400 | - if($t.p.pager && $($t.p.pager).hasClass("scroll") ) { | |
401 | - $($t.p.pager).width(gtw); | |
402 | - } | |
403 | - if($t.p.caption) {$($t.grid.cDiv).width(gtw);} | |
404 | - if($t.p.toolbar[0]) {$($t.grid.uDiv).width(gtw);} | |
405 | - $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; | |
406 | - } | |
407 | - }); | |
408 | - }; | |
409 | - $.fn.showCol = function(colname) { | |
410 | - return this.each(function() { | |
411 | - var $t = this; var w = 0, fdns=false; | |
412 | - if (!$t.grid ) {return;} | |
413 | - if( typeof colname == 'string') {colname=[colname];} | |
414 | - $($t.p.colModel).each(function(i) { | |
415 | - if ($.inArray(this.name,colname) != -1 && this.hidden) { | |
416 | - var w = parseInt($("tr th:eq("+i+")",$t.grid.hDiv).css("width"),10); | |
417 | - $("tr th:eq("+i+")",$t.grid.hDiv).css("display",""); | |
418 | - $($t.rows).each(function(j){ | |
419 | - $("td:eq("+i+")",$t.rows[j]).css("display","").width(w); | |
420 | - }); | |
421 | - this.hidden=false; | |
422 | - $t.grid.cols[i].style.width = w; | |
423 | - $t.grid.headers[i].width = w; | |
424 | - $t.grid.width += w; | |
425 | - fdns=true; | |
426 | - } | |
427 | - }); | |
428 | - if(fdns===true) { | |
429 | - var gtw = Math.min($t.p._width,$t.grid.width); | |
430 | - var ofl = ($t.grid.width <= $t.p._width) ? "hidden" : "auto"; | |
431 | - $("table:first",$t.grid.hDiv).width(gtw); | |
432 | - $("table:first",$t.grid.bDiv).width(gtw); | |
433 | - $($t.grid.hDiv).width(gtw); | |
434 | - $($t.grid.bDiv).width(gtw).css("overflow-x",ofl); | |
435 | - if($t.p.pager && $($t.p.pager).hasClass("scroll") ) { | |
436 | - $($t.p.pager).width(gtw); | |
437 | - } | |
438 | - if($t.p.caption) {$($t.grid.cDiv).width(gtw);} | |
439 | - if($t.p.toolbar[0]) {$($t.grid.uDiv).width(gtw);} | |
440 | - $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; | |
441 | - } | |
442 | - }); | |
443 | - }; | |
444 | - $.fn.setGridWidth = function(nwidth, shrink) { | |
445 | - return this.each(function(){ | |
446 | - var $t = this, chw=0,w,cw,ofl; | |
447 | - if (!$t.grid ) {return;} | |
448 | - if(typeof shrink != 'boolean') {shrink=true;} | |
449 | - var testdata = getScale(); | |
450 | - if(shrink !== true) {testdata[0] = Math.min($t.p._width,$t.grid.width); testdata[2]=0;} | |
451 | - else {testdata[2]= testdata[1]} | |
452 | - $.each($t.p.colModel,function(i,v){ | |
453 | - if(!this.hidden && this.name != 'cb' && this.name!='subgrid') { | |
454 | - cw = shrink !== true ? $("tr:first th:eq("+i+")",$t.grid.hDiv).css("width") : this.width; | |
455 | - w = Math.round((IENum(nwidth)-IENum(testdata[2]))/IENum(testdata[0])*IENum(cw)); | |
456 | - chw += w; | |
457 | - $("table thead tr:first th:eq("+i+")",$t.grid.hDiv).css("width",w+"px"); | |
458 | - $("table:first tbody tr:first td:eq("+i+")",$t.grid.bDiv).css("width",w+"px"); | |
459 | - $t.grid.cols[i].style.width = w; | |
460 | - $t.grid.headers[i].width = w; | |
461 | - } | |
462 | - if(this.name=='cb' || this.name == 'subgrid'){chw += IENum(this.width);} | |
463 | - }); | |
464 | - if(chw + testdata[1] <= nwidth || $t.p.forceFit === true){ ofl = "hidden"; tw = nwidth;} | |
465 | - else { ofl= "auto"; tw = chw + testdata[1];} | |
466 | - $("table:first",$t.grid.hDiv).width(tw); | |
467 | - $("table:first",$t.grid.bDiv).width(tw); | |
468 | - $($t.grid.hDiv).width(nwidth); | |
469 | - $($t.grid.bDiv).width(nwidth).css("overflow-x",ofl); | |
470 | - if($t.p.pager && $($t.p.pager).hasClass("scroll") ) { | |
471 | - $($t.p.pager).width(nwidth); | |
472 | - } | |
473 | - if($t.p.caption) {$($t.grid.cDiv).width(nwidth);} | |
474 | - if($t.p.toolbar[0]) {$($t.grid.uDiv).width(nwidth);} | |
475 | - $t.p._width = nwidth; $t.grid.width = tw; | |
476 | - if($.browser.safari || $.browser.opera ) { | |
477 | - $("table tbody tr:eq(1) td",$t.grid.bDiv).each( function( k ) { | |
478 | - $(this).css("width",$t.grid.headers[k].width+"px"); | |
479 | - $t.grid.cols[k] = this; | |
480 | - }); | |
481 | - } | |
482 | - $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; | |
483 | - function IENum(val) { | |
484 | - val = parseInt(val,10); | |
485 | - return isNaN(val) ? 0 : val; | |
486 | - } | |
487 | - function getScale(){ | |
488 | - var testcell = $("table tr:first th:eq(1)", $t.grid.hDiv); | |
489 | - var addpix = IENum($(testcell).css("padding-left")) + | |
490 | - IENum($(testcell).css("padding-right"))+ | |
491 | - IENum($(testcell).css("border-left-width"))+ | |
492 | - IENum($(testcell).css("border-right-width")); | |
493 | - var w =0,ap=0; | |
494 | - $.each($t.p.colModel,function(i,v){ | |
495 | - if(!this.hidden) { | |
496 | - w += parseInt(this.width); | |
497 | - ap += addpix; | |
498 | - } | |
499 | - }); | |
500 | - return [w,ap,0]; | |
501 | - } | |
502 | - }); | |
503 | - }; | |
504 | - $.fn.setGridHeight = function (nh) { | |
505 | - return this.each(function (){ | |
506 | - var ovfl, ovfl2, $t = this; | |
507 | - if(!$t.grid) {return;} | |
508 | - if($t.p.forceFit === true) { ovfl2='hidden'; } else {ovfl2=$($t.grid.bDiv).css("overflow-x");} | |
509 | - ovfl = (isNaN(nh) && $.browser.mozilla && (nh.indexOf("%")!=-1 || nh=="auto")) ? "hidden" : "auto"; | |
510 | - $($t.grid.bDiv).css({height: nh+(isNaN(nh)?"":"px"),"overflow-y":ovfl,"overflow-x": ovfl2}); | |
511 | - $t.p.height = nh; | |
512 | - }); | |
513 | - }; | |
514 | - $.fn.setCaption = function (newcap){ | |
515 | - return this.each(function(){ | |
516 | - this.p.caption=newcap; | |
517 | - $("table:first th",this.grid.cDiv).html(newcap); | |
518 | - $(this.grid.cDiv).show(); | |
519 | - }); | |
520 | - }; | |
521 | - $.fn.setLabel = function(colname, nData, prop ){ | |
522 | - return this.each(function(){ | |
523 | - var $t = this, pos=-1; | |
524 | - if(!$t.grid) {return;} | |
525 | - if(isNaN(colname)) { | |
526 | - $($t.p.colModel).each(function(i){ | |
527 | - if (this.name == colname) { | |
528 | - pos = i;return false; | |
529 | - } | |
530 | - }); | |
531 | - } else {pos = parseInt(colname,10);} | |
532 | - if(pos>=0) { | |
533 | - var thecol = $("table:first th:eq("+pos+")",$t.grid.hDiv); | |
534 | - if (nData){ | |
535 | - $("div",thecol).html(nData); | |
536 | - } | |
537 | - if (prop) { | |
538 | - if(typeof prop == 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);} | |
539 | - } | |
540 | - } | |
541 | - }); | |
542 | - }; | |
543 | - $.fn.setCell = function(rowid,colname,nData,prop) { | |
544 | - return this.each(function(){ | |
545 | - var $t = this, pos =-1; | |
546 | - if(!$t.grid) {return;} | |
547 | - if(isNaN(colname)) { | |
548 | - $($t.p.colModel).each(function(i){ | |
549 | - if (this.name == colname) { | |
550 | - pos = i;return false; | |
551 | - } | |
552 | - }); | |
553 | - } else {pos = parseInt(colname,10);} | |
554 | - if(pos>=0) { | |
555 | - var ind = $($t).getInd($t.rows,rowid); | |
556 | - if (ind){ | |
557 | - var tcell = $("td:eq("+pos+")",$t.rows[ind]); | |
558 | - if(nData) {$(tcell).html(nData);} | |
559 | - if (prop){ | |
560 | - if(typeof prop == 'string') {$(tcell).addClass(prop);} else {$(tcell).css(prop);} | |
561 | - } | |
562 | - } | |
563 | - } | |
564 | - }); | |
565 | - }; | |
566 | - $.fn.getCell = function(rowid,iCol) { | |
567 | - var ret = false; | |
568 | - this.each(function(){ | |
569 | - var $t=this; | |
570 | - if(!$t.grid) {return;} | |
571 | - if(rowid && iCol>=0) { | |
572 | - var ind = $($t).getInd($t.rows,rowid); | |
573 | - if(ind) { | |
574 | - ret = $("td:eq("+iCol+")",$t.rows[ind]).html().replace(/\ \;/ig,''); | |
575 | - } | |
576 | - } | |
577 | - }); | |
578 | - return ret; | |
579 | - }; | |
580 | - $.fn.clearGridData = function() { | |
581 | - return this.each(function(){ | |
582 | - var $t = this; | |
583 | - if(!$t.grid) {return;} | |
584 | - $("tbody tr:gt(0)", $t.grid.bDiv).remove(); | |
585 | - $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = []; | |
586 | - $t.p.records = '0';$t.p.page='0';$t.p.lastpage='0'; | |
587 | - $t.updatepager(); | |
588 | - }); | |
589 | - }; | |
590 | - $.fn.getInd = function(obj,rowid,rc){ | |
591 | - var ret =false; | |
592 | - $(obj).each(function(i){ | |
593 | - if(this.id==rowid) { | |
594 | - ret = rc===true ? this : i; | |
595 | - return false; | |
596 | - } | |
597 | - }); | |
598 | - return ret; | |
599 | - }; | |
600 | - return this.each( function() { | |
601 | - if(this.grid) {return;} | |
602 | - this.p = p ; | |
603 | - if( this.p.colNames.length === 0 || this.p.colNames.length !== this.p.colModel.length ) { | |
604 | - alert("Length of colNames <> colModel or 0!"); | |
605 | - return; | |
606 | - } | |
607 | - if(this.p.imgpath !== "" ) {this.p.imgpath += "/";} | |
608 | - var ts = this; | |
609 | - $("<div class='loadingui' id=lui_"+this.id+"/>").insertBefore(this); | |
610 | - $(this).attr({cellSpacing:"0",cellPadding:"0",border:"0"}); | |
611 | - var bSR = $.isFunction(this.p.beforeSelectRow) ? this.p.beforeSelectRow :false; | |
612 | - var onSelectRow = $.isFunction(this.p.onSelectRow) ? this.p.onSelectRow :false; | |
613 | - var ondblClickRow = $.isFunction(this.p.ondblClickRow) ? this.p.ondblClickRow :false; | |
614 | - var onSortCol = $.isFunction(this.p.onSortCol) ? this.p.onSortCol : false; | |
615 | - var loadComplete = $.isFunction(this.p.loadComplete) ? this.p.loadComplete : false; | |
616 | - var loadError = $.isFunction(this.p.loadError) ? this.p.loadError : false; | |
617 | - var loadBeforeSend = $.isFunction(this.p.loadBeforeSend) ? this.p.loadBeforeSend : false; | |
618 | - var onRightClickRow = $.isFunction(this.p.onRightClickRow) ? this.p.onRightClickRow : false; | |
619 | - var afterInsRow = $.isFunction(this.p.afterInsertRow) ? this.p.afterInsertRow : false; | |
620 | - var onHdCl = $.isFunction(this.p.onHeaderClick) ? this.p.onHeaderClick : false; | |
621 | - var beReq = $.isFunction(this.p.beforeRequest) ? this.p.beforeRequest : false; | |
622 | - var onSC = $.isFunction(this.p.onCellSelect) ? this.p.onCellSelect : false; | |
623 | - var sortkeys = ["shiftKey","altKey","ctrlKey"]; | |
624 | - if ($.inArray(ts.p.multikey,sortkeys) == -1 ) {ts.p.multikey = false;} | |
625 | - var IntNum = function(val,defval) { | |
626 | - val = parseInt(val,10); | |
627 | - if (isNaN(val)) { return (defval) ? defval : 0;} | |
628 | - else {return val;} | |
629 | - }; | |
630 | - var formatCol = function (elem, pos){ | |
631 | - var rowalgn = ts.p.colModel[pos].align; | |
632 | - if(rowalgn) { $(elem).css("text-align",rowalgn);} | |
633 | - if(ts.p.colModel[pos].hidden) {$(elem).css("display","none");} | |
634 | - }; | |
635 | - var resizeFirstRow = function (t,er){ | |
636 | - $("tbody tr:eq("+er+") td",t).each( function( k ) { | |
637 | - $(this).css("width",grid.headers[k].width+"px"); | |
638 | - grid.cols[k] = this; | |
639 | - }); | |
640 | - }; | |
641 | - var addCell = function(t,row,cell,pos) { | |
642 | - var td; | |
643 | - td = document.createElement("td"); | |
644 | - $(td).html(cell); | |
645 | - row.appendChild(td); | |
646 | - formatCol($(td,t), pos); | |
647 | - }; | |
648 | - var addMulti = function(t,row){ | |
649 | - var cbid,td; | |
650 | - td = document.createElement("td"); | |
651 | - cbid = "jqg_"+row.id; | |
652 | - $(td,t).html("<input type='checkbox'"+" id='"+cbid+"' class='cbox'/>"); | |
653 | - formatCol($(td,t), 0); | |
654 | - row.appendChild(td); | |
655 | - }; | |
656 | - var reader = function (datatype) { | |
657 | - var field, f=[], j=0; | |
658 | - for(var i =0; i<ts.p.colModel.length; i++){ | |
659 | - field = ts.p.colModel[i]; | |
660 | - if (field.name !== 'cb' && field.name !=='subgrid') { | |
661 | - f[j] = (datatype=="xml") ? field.xmlmap || field.name : field.jsonmap || field.name; | |
662 | - j++; | |
663 | - } | |
664 | - } | |
665 | - return f; | |
666 | - }; | |
667 | - var addXmlData = function addXmlData (xml,t) { | |
668 | - if(xml) { var fpos = ts.p.treeANode; if(fpos===0) {$("tbody tr:gt(0)", t).remove();} } else { return; } | |
669 | - var row,gi=0,si=0,cbid,idn, getId,f=[],rd =[],cn=(ts.p.altRows === true) ? 'alt':''; | |
670 | - if(!ts.p.xmlReader.repeatitems) {f = reader("xml");} | |
671 | - if( ts.p.keyIndex===false) { | |
672 | - idn = ts.p.xmlReader.id; | |
673 | - if( idn.indexOf("[") === -1 ) { | |
674 | - getId = function( trow, k) {return $(idn,trow).text() || k;}; | |
675 | - } | |
676 | - else { | |
677 | - getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;}; | |
678 | - } | |
679 | - } else { | |
680 | - getId = function(trow) { return (f.length - 1 >= ts.p.keyIndex) ? $(f[ts.p.keyIndex],trow).text() : $(ts.p.xmlReader.cell+":eq("+ts.p.keyIndex+")",trow).text(); }; | |
681 | - } | |
682 | - $(ts.p.xmlReader.page,xml).each(function() {ts.p.page = this.textContent || this.text ; }); | |
683 | - $(ts.p.xmlReader.total,xml).each(function() {ts.p.lastpage = this.textContent || this.text ; } ); | |
684 | - $(ts.p.xmlReader.records,xml).each(function() {ts.p.records = this.textContent || this.text ; } ); | |
685 | - $(ts.p.xmlReader.userdata,xml).each(function() {ts.p.userData[this.getAttribute("name")]=this.textContent || this.text;}); | |
686 | - $(ts.p.xmlReader.root+" "+ts.p.xmlReader.row,xml).each( function( j ) { | |
687 | - row = document.createElement("tr"); | |
688 | - row.id = getId(this,j+1); | |
689 | - if(ts.p.multiselect) { | |
690 | - addMulti(t,row); | |
691 | - gi = 1; | |
692 | - } | |
693 | - if (ts.p.subGrid) { | |
694 | - try {$(ts).addSubGrid(t,row,gi,this);} catch (e){} | |
695 | - si= 1; | |
696 | - } | |
697 | - var v; | |
698 | - if(ts.p.xmlReader.repeatitems===true){ | |
699 | - $(ts.p.xmlReader.cell,this).each( function (i) { | |
700 | - v = this.textContent || this.text; | |
701 | - addCell(t,row,v || ' ',i+gi+si); | |
702 | - rd[ts.p.colModel[i+gi+si].name] = v; | |
703 | - }); | |
704 | - } else { | |
705 | - for(var i = 0; i < f.length;i++) { | |
706 | - v = $(f[i],this).text(); | |
707 | - addCell(t, row, v || ' ', i+gi+si); | |
708 | - rd[ts.p.colModel[i+gi+si].name] = v; | |
709 | - } | |
710 | - } | |
711 | - if(j%2 == 1) {row.className = cn;} $(row).addClass("jqgrow"); | |
712 | - if( ts.p.treeGrid === true) { | |
713 | - try {$(ts).setTreeNode(rd,row);} catch (e) {} | |
714 | - } | |
715 | - $(ts.rows[j+fpos]).after(row); | |
716 | - if(afterInsRow) {ts.p.afterInsertRow(row.id,rd,this);} | |
717 | - rd=[]; | |
718 | - }); | |
719 | - xml = null; | |
720 | - if(isSafari || isOpera) {resizeFirstRow(t,1);} | |
721 | - if(!ts.p.treeGrid) {ts.grid.bDiv.scrollTop = 0;} | |
722 | - endReq(); | |
723 | - updatepager(); | |
724 | - }; | |
725 | - var addJSONData = function(data,t) { | |
726 | - if(data) { var fpos = ts.p.treeANode; if(fpos===0) {$("tbody tr:gt(0)", t).remove();} } else { return; } | |
727 | - var row,f=[],cur,gi=0,si=0,drows,idn,rd=[],cn=(ts.p.altRows===true) ? 'alt':''; | |
728 | - ts.p.page = data[ts.p.jsonReader.page]; | |
729 | - ts.p.lastpage= data[ts.p.jsonReader.total]; | |
730 | - ts.p.records= data[ts.p.jsonReader.records]; | |
731 | - ts.p.userData = data[ts.p.jsonReader.userdata] || {}; | |
732 | - if(!ts.p.jsonReader.repeatitems) {f = reader("json");} | |
733 | - if( ts.p.keyIndex===false ) { | |
734 | - idn = ts.p.jsonReader.id; | |
735 | - if(f.length>0 && !isNaN(idn)) {idn=f[idn];} | |
736 | - } else { | |
737 | - idn = f.length>0 ? f[ts.p.keyIndex] : ts.p.keyIndex; | |
738 | - } | |
739 | - drows = data[ts.p.jsonReader.root]; | |
740 | - if (drows) { | |
741 | - for (var i=0;i<drows.length;i++) { | |
742 | - cur = drows[i]; | |
743 | - row = document.createElement("tr"); | |
744 | - row.id = cur[idn] || ""; | |
745 | - if(row.id === "") { | |
746 | - if(f.length===0){ | |
747 | - if(ts.p.jsonReader.cell){ | |
748 | - var ccur = cur[ts.p.jsonReader.cell]; | |
749 | - row.id = ccur[idn] || i+1; | |
750 | - ccur=null; | |
751 | - } else {row.id=i+1;} | |
752 | - } else { | |
753 | - row.id=i+1; | |
754 | - } | |
755 | - } | |
756 | - if(ts.p.multiselect){ | |
757 | - addMulti(t,row); | |
758 | - gi = 1; | |
759 | - } | |
760 | - if (ts.p.subGrid) { | |
761 | - try { $(ts).addSubGrid(t,row,gi,drows[i]);} catch (e){} | |
762 | - si= 1; | |
763 | - } | |
764 | - if (ts.p.jsonReader.repeatitems === true) { | |
765 | - if(ts.p.jsonReader.cell) {cur = cur[ts.p.jsonReader.cell];} | |
766 | - for (var j=0;j<cur.length;j++) { | |
767 | - addCell(t,row,cur[j] || ' ',j+gi+si); | |
768 | - rd[ts.p.colModel[j+gi+si].name] = cur[j]; | |
769 | - } | |
770 | - } else { | |
771 | - for (var j=0;j<f.length;j++) { | |
772 | - addCell(t,row,cur[f[j]] || ' ',j+gi+si); | |
773 | - rd[ts.p.colModel[j+gi+si].name] = cur[f[j]]; | |
774 | - } | |
775 | - } | |
776 | - if(i%2 == 1) {row.className = cn;} $(row).addClass("jqgrow"); | |
777 | - if( ts.p.treeGrid === true) { | |
778 | - try {$(ts).setTreeNode(rd,row);} catch (e) {} | |
779 | - } | |
780 | - $(ts.rows[i+fpos]).after(row); | |
781 | - if(afterInsRow) {ts.p.afterInsertRow(row.id,rd,drows[i]);} | |
782 | - rd=[]; | |
783 | - } | |
784 | - } | |
785 | - data = null; | |
786 | - if(isSafari || isOpera) {resizeFirstRow(t,1);} | |
787 | - if(!ts.p.treeGrid) {ts.grid.bDiv.scrollTop = 0;} | |
788 | - endReq(); | |
789 | - updatepager(); | |
790 | - }; | |
791 | - var updatepager = function() { | |
792 | - if(ts.p.pager) { | |
793 | - var cp, last,imp = ts.p.imgpath; | |
794 | - if (ts.p.loadonce) { | |
795 | - cp = last = 1; | |
796 | - ts.p.lastpage = ts.page =1; | |
797 | - $(".selbox",ts.p.pager).attr("disabled",true); | |
798 | - } else { | |
799 | - cp = IntNum(ts.p.page); | |
800 | - last = IntNum(ts.p.lastpage); | |
801 | - $(".selbox",ts.p.pager).attr("disabled",false); | |
802 | - } | |
803 | - if(ts.p.pginput===true) { | |
804 | - $('input.selbox',ts.p.pager).val(ts.p.page); | |
805 | - } | |
806 | - if (ts.p.viewrecords){ | |
807 | - if(ts.p.pgtext) { | |
808 | - $('#sp_1',ts.p.pager).html(ts.p.pgtext+" "+ts.p.lastpage ); | |
809 | - } | |
810 | - $('#sp_2',ts.p.pager).html(ts.p.records+" "+ts.p.recordtext+" "); | |
811 | - } | |
812 | - if(ts.p.pgbuttons===true) { | |
813 | - if(cp<=0) {cp = last = 1;} | |
814 | - if(cp==1) {$("#first",ts.p.pager).attr({src:imp+"off-"+ts.p.firstimg,disabled:true});} else {$("#first",ts.p.pager).attr({src:imp+ts.p.firstimg,disabled:false});} | |
815 | - if(cp==1) {$("#prev",ts.p.pager).attr({src:imp+"off-"+ts.p.previmg,disabled:true});} else {$("#prev",ts.p.pager).attr({src:imp+ts.p.previmg,disabled:false});} | |
816 | - if(cp==last) {$("#next",ts.p.pager).attr({src:imp+"off-"+ts.p.nextimg,disabled:true});} else {$("#next",ts.p.pager).attr({src:imp+ts.p.nextimg,disabled:false});} | |
817 | - if(cp==last) {$("#last",ts.p.pager).attr({src:imp+"off-"+ts.p.lastimg,disabled:true});} else {$("#last",ts.p.pager).attr({src:imp+ts.p.lastimg,disabled:false});} | |
818 | - } | |
819 | - } | |
820 | - if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete();} | |
821 | - }; | |
822 | - var populate = function () { | |
823 | - if(!grid.hDiv.loading) { | |
824 | - beginReq(); | |
825 | - var gdata = $.extend(ts.p.postData,{page: ts.p.page, rows: ts.p.rowNum, sidx: ts.p.sortname, sord:ts.p.sortorder, nd: (new Date().getTime()), _search:ts.p.search}); | |
826 | - if (ts.p.search ===true) {gdata =$.extend(gdata,ts.p.searchdata);} | |
827 | - if ($.isFunction(ts.p.datatype)) {ts.p.datatype(gdata);endReq();} | |
828 | - switch(ts.p.datatype) | |
829 | - { | |
830 | - case "json": | |
831 | - $.ajax({url:ts.p.url,type:ts.p.mtype,dataType:"json",data: gdata, complete:function(JSON,st) { if(st=="success") {addJSONData(eval("("+JSON.responseText+")"),ts.grid.bDiv); if(loadComplete) {loadComplete();}}}, error:function(xhr,st,err){if(loadError) {loadError(xhr,st,err);}endReq();}, beforeSend: function(xhr){if(loadBeforeSend) {loadBeforeSend(xhr);}}}); | |
832 | - if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";} | |
833 | - break; | |
834 | - case "xml": | |
835 | - $.ajax({url:ts.p.url,type:ts.p.mtype,dataType:"xml",data: gdata , complete:function(xml,st) {if(st=="success") {addXmlData(xml.responseXML,ts.grid.bDiv); if(loadComplete) {loadComplete();}}}, error:function(xhr,st,err){if(loadError) {loadError(xhr,st,err);}endReq();}, beforeSend: function(xhr){if(loadBeforeSend) {loadBeforeSend(xhr);}}}); | |
836 | - if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";} | |
837 | - break; | |
838 | - case "xmlstring": | |
839 | - addXmlData(stringToDoc(ts.p.datastr),ts.grid.bDiv); | |
840 | - ts.p.datastr = null; | |
841 | - ts.p.datatype = "local"; | |
842 | - if(loadComplete) {loadComplete();} | |
843 | - break; | |
844 | - case "jsonstring": | |
845 | - addJSONData(eval("("+ts.p.datastr+")"),ts.grid.bDiv); | |
846 | - ts.p.datastr = null; | |
847 | - ts.p.datatype = "local"; | |
848 | - if(loadComplete) {loadComplete();} | |
849 | - break; | |
850 | - case "local": | |
851 | - case "clientSide": | |
852 | - sortArrayData(); | |
853 | - break; | |
854 | - } | |
855 | - } | |
856 | - }; | |
857 | - var beginReq = function() { | |
858 | - if(beReq) {ts.p.beforeRequest();} | |
859 | - grid.hDiv.loading = true; | |
860 | - switch(ts.p.loadui) { | |
861 | - case "disable": | |
862 | - break; | |
863 | - case "enable": | |
864 | - $("div.loading",grid.hDiv).fadeIn("fast"); | |
865 | - break; | |
866 | - case "block": | |
867 | - $("div.loading",grid.hDiv).fadeIn("fast"); | |
868 | - $("#lui_"+ts.id).width($(grid.bDiv).width()).height(IntNum($(grid.bDiv).height())+IntNum(ts.p._height)).show(); | |
869 | - break; | |
870 | - } | |
871 | - }; | |
872 | - var endReq = function() { | |
873 | - grid.hDiv.loading = false; | |
874 | - switch(ts.p.loadui) { | |
875 | - case "disable": | |
876 | - break; | |
877 | - case "enable": | |
878 | - $("div.loading",grid.hDiv).fadeOut("fast"); | |
879 | - break; | |
880 | - case "block": | |
881 | - $("div.loading",grid.hDiv).fadeOut("fast"); | |
882 | - $("#lui_"+ts.id).hide(); | |
883 | - break; | |
884 | - } | |
885 | - }; | |
886 | - var stringToDoc = function (xmlString) { | |
887 | - var xmlDoc; | |
888 | - try { | |
889 | - var parser = new DOMParser(); | |
890 | - xmlDoc = parser.parseFromString(xmlString,"text/xml"); | |
891 | - } | |
892 | - catch(e) { | |
893 | - xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); | |
894 | - xmlDoc.async=false; | |
895 | - xmlDoc["loadXM"+"L"](xmlString); | |
896 | - } | |
897 | - return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null; | |
898 | - }; | |
899 | - var sortArrayData = function() { | |
900 | - var stripNum = /[\$,%]/g; | |
901 | - var col=0,st,findSortKey,newDir = (ts.p.sortorder == "asc") ? 1 :-1; | |
902 | - $.each(ts.p.colModel,function(i,v){ | |
903 | - if(this.index == ts.p.sortname || this.name == ts.p.sortname){ | |
904 | - col = ts.p.lastsort= i; | |
905 | - st = this.sorttype; | |
906 | - return false; | |
907 | - } | |
908 | - }); | |
909 | - if (st == 'float') { | |
910 | - findSortKey = function($cell) { | |
911 | - var key = parseFloat($cell.text().replace(stripNum, '')); | |
912 | - return isNaN(key) ? 0 : key; | |
913 | - }; | |
914 | - } else if (st=='int') { | |
915 | - findSortKey = function($cell) { | |
916 | - return IntNum($cell.text().replace(stripNum, '')); | |
917 | - }; | |
918 | - } else if(st == 'date') { | |
919 | - findSortKey = function($cell) { | |
920 | - var fd = ts.p.colModel[col].datefmt || "Y-m-d"; | |
921 | - return parseDate(fd,$cell.text()).getTime(); | |
922 | - }; | |
923 | - } else { | |
924 | - findSortKey = function($cell) { | |
925 | - return $cell.text().toUpperCase(); | |
926 | - }; | |
927 | - } | |
928 | - var rows=[]; | |
929 | - $.each(ts.rows, function(index, row) { | |
930 | - if (index > 0) { | |
931 | - row.sortKey = findSortKey($(row).children('td').eq(col)); | |
932 | - rows[index-1] = this; | |
933 | - } | |
934 | - }); | |
935 | - if(ts.p.treeGrid) { | |
936 | - $(ts).SortTree( newDir); | |
937 | - } else { | |
938 | - rows.sort(function(a, b) { | |
939 | - if (a.sortKey < b.sortKey) {return -newDir;} | |
940 | - if (a.sortKey > b.sortKey) {return newDir;} | |
941 | - return 0; | |
942 | - }); | |
943 | - $.each(rows, function(index, row) { | |
944 | - $('tbody',ts.grid.bDiv).append(row); | |
945 | - row.sortKey = null; | |
946 | - }); | |
947 | - } | |
948 | - if(isSafari || isOpera) {resizeFirstRow(ts.grid.bDiv,1);} | |
949 | - if(ts.p.multiselect) { | |
950 | - $("tbody tr:gt(0)", ts.grid.bDiv).removeClass("selected"); | |
951 | - $("[@id^=jqg_]",ts.rows).attr("checked",false); | |
952 | - $("#cb_jqg",ts.grid.hDiv).attr("checked",false); | |
953 | - ts.p.selarrrow = []; | |
954 | - } | |
955 | - if( ts.p.altRows === true ) { | |
956 | - $("tbody tr:gt(0)", ts.grid.bDiv).removeClass("alt"); | |
957 | - $("tbody tr:odd", ts.grid.bDiv).addClass("alt"); | |
958 | - } | |
959 | - ts.grid.bDiv.scrollTop = 0; | |
960 | - endReq(); | |
961 | - }; | |
962 | - var parseDate = function(format, date) { | |
963 | - var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0}; | |
964 | - format = format.toLowerCase(); | |
965 | - date = date.split(/[\\\/:_;.\s-]/); | |
966 | - format = format.split(/[\\\/:_;.\s-]/); | |
967 | - for(var i=0;i<format.length;i++){ | |
968 | - tsp[format[i]] = IntNum(date[i],tsp[format[i]]); | |
969 | - } | |
970 | - tsp.m = parseInt(tsp.m,10)-1; | |
971 | - var ty = tsp.y; | |
972 | - if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;} | |
973 | - else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;} | |
974 | - return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s,0); | |
975 | - }; | |
976 | - var setPager = function (){ | |
977 | - var inpt = "<img class='pgbuttons' src='"+ts.p.imgpath+"spacer.gif'"; | |
978 | - var pginp = (ts.p.pginput===true) ? "<input class='selbox' type='text' size='3' maxlength='5' value='0'/>" : ""; | |
979 | - if(ts.p.viewrecords===true) {pginp += "<span id='sp_1'></span> ";} | |
980 | - var pgl="", pgr=""; | |
981 | - if(ts.p.pgbuttons===true) { | |
982 | - pgl = inpt+" id='first'/>  "+inpt+" id='prev'/> "; | |
983 | - pgr = inpt+" id='next' />  "+inpt+" id='last'/>"; | |
984 | - } | |
985 | - $(ts.p.pager).append(pgl+pginp+pgr); | |
986 | - if(ts.p.rowList.length >0){ | |
987 | - var str="<SELECT class='selbox'>"; | |
988 | - for(var i=0;i<ts.p.rowList.length;i++){ | |
989 | - str +="<OPTION value="+ts.p.rowList[i]+((ts.p.rowNum == ts.p.rowList[i])?' selected':'')+">"+ts.p.rowList[i]; | |
990 | - } | |
991 | - str +="</SELECT>"; | |
992 | - $(ts.p.pager).append(" "+str+" <span id='sp_2'></span>"); | |
993 | - $(ts.p.pager).find("select").bind('change',function() { | |
994 | - ts.p.rowNum = (this.value>0) ? this.value : ts.p.rowNum; | |
995 | - if (typeof ts.p.onPaging =='function') {ts.p.onPaging('records');} | |
996 | - populate(); | |
997 | - ts.p.selrow = null; | |
998 | - }); | |
999 | - } else { $(ts.p.pager).append(" <span id='sp_2'></span>");} | |
1000 | - if(ts.p.pgbuttons===true) { | |
1001 | - $(".pgbuttons",ts.p.pager).mouseover(function(e){ | |
1002 | - this.style.cursor= "pointer"; | |
1003 | - return false; | |
1004 | - }).mouseout(function(e) { | |
1005 | - this.style.cursor= "normal"; | |
1006 | - return false; | |
1007 | - }); | |
1008 | - $("#first, #prev, #next, #last",ts.p.pager).click( function(e) { | |
1009 | - var cp = IntNum(ts.p.page); | |
1010 | - var last = IntNum(ts.p.lastpage), selclick = false; | |
1011 | - var fp=true; var pp=true; var np=true; var lp=true; | |
1012 | - if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; } | |
1013 | - else if( last>1 && cp >=1) { | |
1014 | - if( cp === 1) { fp=false; pp=false; } | |
1015 | - else if( cp>1 && cp <last){ } | |
1016 | - else if( cp===last){ np=false;lp=false; } | |
1017 | - } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;} | |
1018 | - if( this.id === 'first' && fp ) { ts.p.page=1; selclick=true;} | |
1019 | - if( this.id === 'prev' && pp) { ts.p.page=(cp-1); selclick=true;} | |
1020 | - if( this.id === 'next' && np) { ts.p.page=(cp+1); selclick=true;} | |
1021 | - if( this.id === 'last' && lp) { ts.p.page=last; selclick=true;} | |
1022 | - if(selclick) { | |
1023 | - if (typeof ts.p.onPaging =='function') {ts.p.onPaging(this.id);} | |
1024 | - populate(); | |
1025 | - ts.p.selrow = null; | |
1026 | - if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_jqg',ts.grid.hDiv).attr("checked",false);} | |
1027 | - ts.p.savedRow = []; | |
1028 | - } | |
1029 | - e.stopPropagation(); | |
1030 | - return false; | |
1031 | - }); | |
1032 | - } | |
1033 | - if(ts.p.pginput===true) { | |
1034 | - $('input.selbox',ts.p.pager).keypress( function(e) { | |
1035 | - var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; | |
1036 | - if(key == 13) { | |
1037 | - ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page; | |
1038 | - if (typeof ts.p.onPaging =='function') {ts.p.onPaging( 'user');} | |
1039 | - populate(); | |
1040 | - ts.p.selrow = null; | |
1041 | - return false; | |
1042 | - } | |
1043 | - return this; | |
1044 | - }); | |
1045 | - } | |
1046 | - }; | |
1047 | - var sortData = function (index, idxcol,reload){ | |
1048 | - if(!reload) { | |
1049 | - if( ts.p.lastsort === idxcol ) { | |
1050 | - if( ts.p.sortorder === 'asc') { | |
1051 | - ts.p.sortorder = 'desc'; | |
1052 | - } else if(ts.p.sortorder === 'desc') { ts.p.sortorder='asc';} | |
1053 | - } else { ts.p.sortorder='asc';} | |
1054 | - ts.p.page = 1; | |
1055 | - } | |
1056 | - var imgs = (ts.p.sortorder==='asc') ? ts.p.sortascimg : ts.p.sortdescimg; | |
1057 | - imgs = "<img src='"+ts.p.imgpath+imgs+"'>"; | |
1058 | - var thd= $("thead:first",grid.hDiv).get(0); | |
1059 | - $("tr th div#jqgh_"+ts.p.colModel[ts.p.lastsort].name+" img",thd).remove(); | |
1060 | - $("tr th div#jqgh_"+ts.p.colModel[ts.p.lastsort].name,thd).parent().removeClass(ts.p.sortclass); | |
1061 | - $("tr th div#"+index,thd).append(imgs).parent().addClass(ts.p.sortclass); | |
1062 | - ts.p.lastsort = idxcol; | |
1063 | - index = index.substring(5); | |
1064 | - ts.p.sortname = ts.p.colModel[idxcol].index || index; | |
1065 | - var so = ts.p.sortorder; | |
1066 | - if(onSortCol) {onSortCol(index,idxcol,so);} | |
1067 | - if(ts.p.selrow && ts.p.datatype == "local" && !ts.p.multiselect){ $('#'+ts.p.selrow,grid.bDiv).removeClass("selected");} | |
1068 | - ts.p.selrow = null; | |
1069 | - if(ts.p.multiselect && ts.p.datatype !== "local"){ts.p.selarrrow =[]; $("#cb_jqg",ts.grid.hDiv).attr("checked",false);} | |
1070 | - ts.p.savedRow =[]; | |
1071 | - populate(); | |
1072 | - if(ts.p.sortname != index && idxcol) {ts.p.lastsort = idxcol;} | |
1073 | - }; | |
1074 | - var setColWidth = function () { | |
1075 | - var initwidth = 0; | |
1076 | - for(var l=0;l<ts.p.colModel.length;l++){ | |
1077 | - if(!ts.p.colModel[l].hidden){ | |
1078 | - initwidth += IntNum(ts.p.colModel[l].width); | |
1079 | - } | |
1080 | - } | |
1081 | - var tblwidth = ts.p.width ? ts.p.width : initwidth; | |
1082 | - for(l=0;l<ts.p.colModel.length;l++) { | |
1083 | - if(!ts.p.shrinkToFit){ | |
1084 | - ts.p.colModel[l].owidth = ts.p.colModel[l].width; | |
1085 | - } | |
1086 | - ts.p.colModel[l].width = Math.round(tblwidth/initwidth*ts.p.colModel[l].width); | |
1087 | - } | |
1088 | - }; | |
1089 | - var nextVisible= function(iCol) { | |
1090 | - var ret = iCol, j=iCol; | |
1091 | - for (var i = iCol+1;i<ts.p.colModel.length;i++){ | |
1092 | - if(ts.p.colModel[i].hidden !== true ) { | |
1093 | - j=i; break; | |
1094 | - } | |
1095 | - } | |
1096 | - return j-ret; | |
1097 | - }; | |
1098 | - this.p.id = this.id; | |
1099 | - if(this.p.treeGrid === true) { | |
1100 | - this.p.subGrid = false; this.p.altRows =false; | |
1101 | - this.p.pgbuttons = false; this.p.pginput = false; | |
1102 | - this.p.multiselect = false; this.p.rowList = []; | |
1103 | - this.p.treedatatype = this.p.datatype; | |
1104 | - $.each(this.p.treeReader,function(i,n){ | |
1105 | - if(n){ | |
1106 | - ts.p.colNames.push(n); | |
1107 | - ts.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false}); | |
1108 | - } | |
1109 | - }); | |
1110 | - } | |
1111 | - ts.p.keyIndex=false; | |
1112 | - for (var i=0; i<ts.p.colModel.length;i++) { | |
1113 | - if (ts.p.colModel[i].key===true) { | |
1114 | - ts.p.keyIndex = i; | |
1115 | - break; | |
1116 | - } | |
1117 | - } | |
1118 | - if(this.p.subGrid) { | |
1119 | - this.p.colNames.unshift(""); | |
1120 | - this.p.colModel.unshift({name:'subgrid',width:25,sortable: false,resizable:false,hidedlg:true,search:false}); | |
1121 | - } | |
1122 | - if(this.p.multiselect) { | |
1123 | - this.p.colNames.unshift("<input id='cb_jqg' class='cbox' type='checkbox'/>"); | |
1124 | - this.p.colModel.unshift({name:'cb',width:27,sortable:false,resizable:false,hidedlg:true,search:false}); | |
1125 | - } | |
1126 | - var xReader = { | |
1127 | - root: "rows", | |
1128 | - row: "row", | |
1129 | - page: "rows>page", | |
1130 | - total: "rows>total", | |
1131 | - records : "rows>records", | |
1132 | - repeatitems: true, | |
1133 | - cell: "cell", | |
1134 | - id: "[id]", | |
1135 | - userdata: "userdata", | |
1136 | - subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"} | |
1137 | - }; | |
1138 | - var jReader = { | |
1139 | - root: "rows", | |
1140 | - page: "page", | |
1141 | - total: "total", | |
1142 | - records: "records", | |
1143 | - repeatitems: true, | |
1144 | - cell: "cell", | |
1145 | - id: "id", | |
1146 | - userdata: "userdata", | |
1147 | - subgrid: {root:"rows", repeatitems: true, cell:"cell"} | |
1148 | - }; | |
1149 | - ts.p.xmlReader = $.extend(xReader, ts.p.xmlReader); | |
1150 | - ts.p.jsonReader = $.extend(jReader, ts.p.jsonReader); | |
1151 | - $.each(ts.p.colModel, function(i){if(!this.width) {this.width=150;}}); | |
1152 | - if (ts.p.width) {setColWidth();} | |
1153 | - var thead = document.createElement("thead"); | |
1154 | - var trow = document.createElement("tr"); | |
1155 | - thead.appendChild(trow); | |
1156 | - var i=0, th, idn, thdiv; | |
1157 | - if(ts.p.shrinkToFit===true && ts.p.forceFit===true) { | |
1158 | - for (i=ts.p.colModel.length-1;i>=0;i--){ | |
1159 | - if(!ts.p.colModel[i].hidden) { | |
1160 | - ts.p.colModel[i].resizable=false; | |
1161 | - break; | |
1162 | - } | |
1163 | - } | |
1164 | - } | |
1165 | - for(i=0;i<this.p.colNames.length;i++){ | |
1166 | - th = document.createElement("th"); | |
1167 | - idn = ts.p.colModel[i].name; | |
1168 | - thdiv = document.createElement("div"); | |
1169 | - $(thdiv).html(ts.p.colNames[i]+" "); | |
1170 | - if (idn == ts.p.sortname) { | |
1171 | - var imgs = (ts.p.sortorder==='asc') ? ts.p.sortascimg : ts.p.sortdescimg; | |
1172 | - imgs = "<img src='"+ts.p.imgpath+imgs+"'>"; | |
1173 | - $(thdiv).append(imgs); | |
1174 | - ts.p.lastsort = i; | |
1175 | - $(th).addClass(ts.p.sortclass); | |
1176 | - } | |
1177 | - thdiv.id = "jqgh_"+idn; | |
1178 | - th.appendChild(thdiv); | |
1179 | - trow.appendChild(th); | |
1180 | - } | |
1181 | - if(this.p.multiselect) { | |
1182 | - var onSA = true; | |
1183 | - if(typeof ts.p.onSelectAll !== 'function') {onSA=false;} | |
1184 | - $('#cb_jqg',trow).click(function(){ | |
1185 | - var chk; | |
1186 | - if (this.checked) { | |
1187 | - $("[@id^=jqg_]",ts.rows).attr("checked",true); | |
1188 | - $(ts.rows).slice(1).each(function(i) { | |
1189 | - if(!$(this).hasClass("subgrid")){ | |
1190 | - $(this).addClass("selected"); | |
1191 | - ts.p.selarrrow[i]= ts.p.selrow = this.id; | |
1192 | - } | |
1193 | - }); | |
1194 | - chk=true; | |
1195 | - } | |
1196 | - else { | |
1197 | - $("[@id^=jqg_]",ts.rows).attr("checked",false); | |
1198 | - $(ts.rows).slice(1).each(function(i) { | |
1199 | - if(!$(this).hasClass("subgrid")){ | |
1200 | - $(this).removeClass("selected"); | |
1201 | - } | |
1202 | - }); | |
1203 | - ts.p.selarrrow = []; ts.p.selrow = null; | |
1204 | - chk=false; | |
1205 | - } | |
1206 | - if(onSA) {ts.p.onSelectAll(ts.p.selarrrow,chk);} | |
1207 | - }); | |
1208 | - } | |
1209 | - this.appendChild(thead); | |
1210 | - thead = $("thead:first",ts).get(0); | |
1211 | - var w, res, sort; | |
1212 | - $("tr:first th",thead).each(function ( j ) { | |
1213 | - w = ts.p.colModel[j].width; | |
1214 | - if(typeof ts.p.colModel[j].resizable === 'undefined') {ts.p.colModel[j].resizable = true;} | |
1215 | - res = document.createElement("span"); | |
1216 | - $(res).html(" "); | |
1217 | - if(ts.p.colModel[j].resizable){ | |
1218 | - $(this).addClass(ts.p.resizeclass); | |
1219 | - $(res).mousedown(function (e) { | |
1220 | - if(ts.p.forceFit===true) {ts.p.nv= nextVisible(j);} | |
1221 | - grid.dragStart( j ,e.clientX); | |
1222 | - e.preventDefault(); | |
1223 | - return false; | |
1224 | - }); | |
1225 | - } else {$(res).css("cursor","default");} | |
1226 | - $(this).css("width",w+"px").prepend(res); | |
1227 | - if( ts.p.colModel[j].hidden) {$(this).css("display","none");} | |
1228 | - grid.headers[j] = { width: w, el: this }; | |
1229 | - sort = ts.p.colModel[j].sortable; | |
1230 | - if( typeof sort !== 'boolean') {sort = true;} | |
1231 | - if(sort) { | |
1232 | - $("div",this).css("cursor","pointer") | |
1233 | - .click(function(){sortData(this.id,j);return false;}); | |
1234 | - } | |
1235 | - }); | |
1236 | - var isMSIE = $.browser.msie ? true:false; | |
1237 | - var isMoz = $.browser.mozilla ? true:false; | |
1238 | - var isOpera = $.browser.opera ? true:false; | |
1239 | - var isSafari = $.browser.safari ? true : false; | |
1240 | - var tbody = document.createElement("tbody"); | |
1241 | - trow = document.createElement("tr"); | |
1242 | - trow.id = "_empty"; | |
1243 | - tbody.appendChild(trow); | |
1244 | - var td, ptr; | |
1245 | - for(i=0;i<ts.p.colNames.length;i++){ | |
1246 | - td = document.createElement("td"); | |
1247 | - trow.appendChild(td); | |
1248 | - } | |
1249 | - this.appendChild(tbody); | |
1250 | - var gw=0,hdc=0; | |
1251 | - $("tbody tr:first td",ts).each(function(ii) { | |
1252 | - w = ts.p.colModel[ii].width; | |
1253 | - $(this).css({width:w+"px",height:"0px"}); | |
1254 | - w += IntNum($(this).css("padding-left")) + | |
1255 | - IntNum($(this).css("padding-right"))+ | |
1256 | - IntNum($(this).css("border-left-width"))+ | |
1257 | - IntNum($(this).css("border-right-width")); | |
1258 | - if( ts.p.colModel[ii].hidden===true) { | |
1259 | - $(this).css("display","none"); | |
1260 | - hdc += w; | |
1261 | - } | |
1262 | - grid.cols[ii] = this; | |
1263 | - gw += w; | |
1264 | - }); | |
1265 | - if(isMoz) {$(trow).css({visibility:"collapse"});} | |
1266 | - else if( isSafari || isOpera ) {$(trow).css({display:"none"});} | |
1267 | - grid.width = IntNum(gw)-IntNum(hdc); | |
1268 | - ts.p._width = grid.width; | |
1269 | - grid.hTable = document.createElement("table"); | |
1270 | - grid.hTable.appendChild(thead); | |
1271 | - $(grid.hTable).addClass("scroll") | |
1272 | - .attr({cellSpacing:"0",cellPadding:"0",border:"0"}) | |
1273 | - .css({width:grid.width+"px"}); | |
1274 | - grid.hDiv = document.createElement("div"); | |
1275 | - var hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false; | |
1276 | - $(grid.hDiv) | |
1277 | - .css({ width: grid.width+"px", overflow: "hidden"}) | |
1278 | - .prepend('<div class="loading">'+ts.p.loadtext+'</div>') | |
1279 | - .append(grid.hTable) | |
1280 | - .bind("selectstart", function () { return false; }); | |
1281 | - if(hg) {$(grid.hDiv).hide(); ts.p.gridstate = 'hidden'} | |
1282 | - if(ts.p.pager){ | |
1283 | - if(typeof ts.p.pager == "string") {ts.p.pager = "#"+ts.p.pager;} | |
1284 | - if( $(ts.p.pager).hasClass("scroll")) { $(ts.p.pager).css({ width: grid.width+"px", overflow: "hidden"}).show(); ts.p._height= parseInt($(ts.p.pager).height(),10); if(hg) {$(ts.p.pager).hide();}} | |
1285 | - setPager(); | |
1286 | - } | |
1287 | - if( ts.p.cellEdit === false) { | |
1288 | - $(ts).mouseover(function(e) { | |
1289 | - td = (e.target || e.srcElement); | |
1290 | - ptr = $(td,ts.rows).parents("tr:first"); | |
1291 | - if($(ptr).hasClass("jqgrow")) { | |
1292 | - $(ptr).addClass("over"); | |
1293 | - if(!$(td).hasClass("editable")){ | |
1294 | - td.title = $(td).text(); | |
1295 | - } | |
1296 | - } | |
1297 | - return false; | |
1298 | - }).mouseout(function(e) { | |
1299 | - td = (e.target || e.srcElement); | |
1300 | - ptr = $(td,ts.rows).parents("tr:first"); | |
1301 | - $(ptr).removeClass("over"); | |
1302 | - if(!$(td).hasClass("editable")){ | |
1303 | - td.title = ""; | |
1304 | - } | |
1305 | - return false; | |
1306 | - }); | |
1307 | - } | |
1308 | - var ri,ci; | |
1309 | - | |
1310 | - $(ts).before(grid.hDiv).css("width", grid.width+"px").click(function(e) { | |
1311 | - td = (e.target || e.srcElement); | |
1312 | - if (td.href) { return true; } | |
1313 | - var scb = $(td).hasClass("cbox"); | |
1314 | - ptr = $(td,ts.rows).parent("tr"); | |
1315 | - if($(ptr).length === 0 ){ | |
1316 | - ptr = $(td,ts.rows).parents("tr:first"); | |
1317 | - td = $(td).parents("td:first")[0]; | |
1318 | - } | |
1319 | - var cSel = true; | |
1320 | - if(bSR) { cSel = bSR(ptr.attr("id"));} | |
1321 | - if(cSel === true) { | |
1322 | - if(ts.p.cellEdit === true) { | |
1323 | - if(ts.p.multiselect && scb){ | |
1324 | - $(ts).setSelection(false,ptr); | |
1325 | - } else { | |
1326 | - ri = ptr[0].rowIndex; | |
1327 | - ci = td.cellIndex; | |
1328 | - try {$(ts).editCell(ri,ci,true,true);} catch (e) {} | |
1329 | - } | |
1330 | - } else | |
1331 | - if ( !ts.p.multikey ) { | |
1332 | - $(ts).setSelection(false,ptr); | |
1333 | - if(onSC) { | |
1334 | - ri = ptr[0].id; | |
1335 | - ci = td.cellIndex; | |
1336 | - onSC(ri,ci,$(td).html()); | |
1337 | - } | |
1338 | - } else { | |
1339 | - if(e[ts.p.multikey]) { | |
1340 | - $(ts).setSelection(false,ptr); | |
1341 | - } else if(ts.p.multiselect) { | |
1342 | - if(scb) { scb = $("[@id^=jqg_]",ptr).attr("checked"); | |
1343 | - $("[@id^=jqg_]",ptr).attr("checked",!scb); | |
1344 | - } | |
1345 | - } | |
1346 | - } | |
1347 | - } | |
1348 | - e.stopPropagation(); | |
1349 | - }).bind('reloadGrid', function(e) { | |
1350 | - if(!ts.p.treeGrid) {ts.p.selrow=null;} | |
1351 | - if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_jqg',ts.grid.hDiv).attr("checked",false);} | |
1352 | - if(ts.p.cellEdit) {ts.p.savedRow = []; } | |
1353 | - populate(); | |
1354 | - }); | |
1355 | - | |
1356 | - if( ondblClickRow ) { | |
1357 | - $(this).dblclick(function(e) { | |
1358 | - td = (e.target || e.srcElement); | |
1359 | - ptr = $(td,ts.rows).parent("tr"); | |
1360 | - if($(ptr).length === 0 ){ | |
1361 | - ptr = $(td,ts.rows).parents("tr:first"); | |
1362 | - } | |
1363 | - ts.p.ondblClickRow($(ptr).attr("id")); | |
1364 | - return false; | |
1365 | - }); | |
1366 | - } | |
1367 | - if (onRightClickRow) { | |
1368 | - $(this).bind('contextmenu', function(e) { | |
1369 | - td = (e.target || e.srcElement); | |
1370 | - ptr = $(td,ts).parents("tr:first"); | |
1371 | - if($(ptr).length === 0 ){ | |
1372 | - ptr = $(td,ts.rows).parents("tr:first"); | |
1373 | - } | |
1374 | - $(ts).setSelection(false,ptr); | |
1375 | - ts.p.onRightClickRow($(ptr).attr("id")); | |
1376 | - return false; | |
1377 | - }); | |
1378 | - } | |
1379 | - grid.bDiv = document.createElement("div"); | |
1380 | - var ofl2 = (isNaN(ts.p.height) && isMoz && (ts.p.height.indexOf("%")!=-1 || ts.p.height=="auto")) ? "hidden" : "auto"; | |
1381 | - $(grid.bDiv) | |
1382 | - .scroll(function (e) {grid.scrollGrid();}) | |
1383 | - .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), padding: "0px", margin: "0px", overflow: ofl2,width: (grid.width)+"px"} ).css("overflow-x","hidden") | |
1384 | - .append(this); | |
1385 | - $("table:first",grid.bDiv).css({width:grid.width+"px",marginRight:"20px"}); | |
1386 | - if( isMSIE ) { | |
1387 | - if( $("tbody",this).size() === 2 ) { $("tbody:first",this).remove();} | |
1388 | - if( ts.p.multikey) {$(grid.bDiv).bind("selectstart",function(){return false;});} | |
1389 | - if(ts.p.treeGrid) {$(grid.bDiv).css("position","relative");} | |
1390 | - } else { | |
1391 | - if( ts.p.multikey) {$(grid.bDiv).bind("mousedown",function(){return false;});} | |
1392 | - } | |
1393 | - if(hg) {$(grid.bDiv).hide();} | |
1394 | - grid.cDiv = document.createElement("div"); | |
1395 | - $(grid.cDiv).append("<table class='Header' cellspacing='0' cellpadding='0' border='0'><tr><td class='HeaderLeft'><img src='"+ts.p.imgpath+"spacer.gif' border='0' /></td><th>"+ts.p.caption+"</th>"+ ((ts.p.hidegrid===true) ? "<td class='HeaderButton'><img src='"+ts.p.imgpath+"up.gif' border='0'/></td>" :"") +"<td class='HeaderRight'><img src='"+ts.p.imgpath+"spacer.gif' border='0' /></td></tr></table>").addClass("GridHeader"); | |
1396 | - $(grid.cDiv).insertBefore(grid.hDiv); | |
1397 | - if( ts.p.toolbar[0] ) { | |
1398 | - grid.uDiv = document.createElement("div"); | |
1399 | - if(ts.p.toolbar[1] == "top") {$(grid.uDiv).insertBefore(grid.hDiv);} | |
1400 | - else {$(grid.uDiv).insertAfter(grid.hDiv);} | |
1401 | - $(grid.uDiv,ts).width(grid.width).addClass("userdata").attr("id","t_"+this.id); | |
1402 | - ts.p._height += parseInt($(grid.uDiv,ts).height(),10); | |
1403 | - if(hg) {$(grid.uDiv,ts).hide();} | |
1404 | - } | |
1405 | - if(ts.p.caption) { | |
1406 | - $(grid.cDiv,ts).width(grid.width).css("text-align","center").show("fast"); | |
1407 | - ts.p._height += parseInt($(grid.cDiv,ts).height(),10); | |
1408 | - var tdt = ts.p.datatype; | |
1409 | - if(ts.p.hidegrid===true) { | |
1410 | - $(".HeaderButton",grid.cDiv).toggle( function(){ | |
1411 | - if(ts.p.pager) {$(ts.p.pager).fadeOut("slow");} | |
1412 | - if(ts.p.toolbar[0]) {$(grid.uDiv,ts).fadeOut("slow");} | |
1413 | - $(grid.bDiv,ts).fadeOut("slow"); | |
1414 | - $(grid.hDiv,ts).fadeOut("slow"); | |
1415 | - $("img",this).attr("src",ts.p.imgpath+"down.gif"); | |
1416 | - ts.p.gridstate = 'hidden'; | |
1417 | - if(onHdCl) {if(!hg) {ts.p.onHeaderClick(ts.p.gridstate);}} | |
1418 | - }, | |
1419 | - function() { | |
1420 | - $(grid.hDiv ,ts).fadeIn("slow"); | |
1421 | - $(grid.bDiv,ts).fadeIn("slow"); | |
1422 | - if(ts.p.pager) {$(ts.p.pager).fadeIn("slow");} | |
1423 | - if(ts.p.toolbar[0]) {$(grid.uDiv).fadeIn("slow");} | |
1424 | - $("img",this).attr("src",ts.p.imgpath+"up.gif"); | |
1425 | - if(hg) {ts.p.datatype = tdt;populate();hg=false;} | |
1426 | - ts.p.gridstate = 'visible'; | |
1427 | - if(onHdCl) {ts.p.onHeaderClick(ts.p.gridstate)} | |
1428 | - } | |
1429 | - ); | |
1430 | - if(hg) { $(".HeaderButton",grid.cDiv).trigger("click"); ts.p.datatype="local";} | |
1431 | - } | |
1432 | - } | |
1433 | - ts.p._height += parseInt($(grid.hDiv,ts).height(),10); | |
1434 | - $(grid.hDiv).mousemove(function (e) {grid.dragMove(e.clientX); return false;}).after(grid.bDiv); | |
1435 | - $(document).mouseup(function (e) { | |
1436 | - if(grid.resizing) { | |
1437 | - grid.dragEnd(); | |
1438 | - if(grid.newWidth && ts.p.forceFit===false){ | |
1439 | - var gwdt = (grid.width <= ts.p._width) ? grid.width: ts.p._width; | |
1440 | - var overfl = (grid.width <= ts.p._width) ? "hidden" : "auto"; | |
1441 | - if(ts.p.pager && $(ts.p.pager).hasClass("scroll") ) { | |
1442 | - $(ts.p.pager).width(gwdt); | |
1443 | - } | |
1444 | - if(ts.p.caption) {$(grid.cDiv).width(gwdt);} | |
1445 | - if(ts.p.toolbar[0]) {$(grid.uDiv).width(gwdt);} | |
1446 | - $(grid.bDiv).width(gwdt).css("overflow-x",overfl); | |
1447 | - $(grid.hDiv).width(gwdt); | |
1448 | - } | |
1449 | - } | |
1450 | - return false; | |
1451 | - }); | |
1452 | - ts.formatCol = function(a,b) {formatCol(a,b);}; | |
1453 | - ts.sortData = function(a,b,c){sortData(a,b,c);}; | |
1454 | - ts.updatepager = function(){updatepager();}; | |
1455 | - this.grid = grid; | |
1456 | - ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);}; | |
1457 | - ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);}; | |
1458 | - populate(); | |
1459 | - if (!ts.p.shrinkToFit) { | |
1460 | - ts.p.forceFit = false; | |
1461 | - $("tr:first th", thead).each(function(j){ | |
1462 | - var w = ts.p.colModel[j].owidth; | |
1463 | - var diff = w - ts.p.colModel[j].width; | |
1464 | - if (diff > 0 && !ts.p.colModel[j].hidden) { | |
1465 | - grid.headers[j].width = w; | |
1466 | - $(this).add(grid.cols[j]).width(w); | |
1467 | - $('table:first',grid.bDiv).add(grid.hTable).width(ts.grid.width); | |
1468 | - ts.grid.width += diff; | |
1469 | - grid.hDiv.scrollLeft = grid.bDiv.scrollLeft; | |
1470 | - } | |
1471 | - }); | |
1472 | - ofl2 = (grid.width <= ts.p._width) ? "hidden" : "auto"; | |
1473 | - $(grid.bDiv).css({"overflow-x":ofl2}); | |
1474 | - } | |
1475 | - $(window).unload(function () { | |
1476 | - $(this).unbind("*"); | |
1477 | - this.grid = null; | |
1478 | - this.p = null; | |
1479 | - }); | |
1480 | - }); | |
1481 | -}; | |
1482 | -})(jQuery); | |
1 | +;(function ($) { | |
2 | +/* | |
3 | + * jqGrid 3.3.2 - jQuery Grid | |
4 | + * Copyright (c) 2008, Tony Tomov, tony@trirand.com | |
5 | + * Dual licensed under the MIT and GPL licenses | |
6 | + * http://www.opensource.org/licenses/mit-license.php | |
7 | + * http://www.gnu.org/licenses/gpl.html | |
8 | + * Date: 2008-12-14 rev 74 | |
9 | + */ | |
10 | +$.fn.jqGrid = function( p ) { | |
11 | + p = $.extend(true,{ | |
12 | + url: "", | |
13 | + height: 150, | |
14 | + page: 1, | |
15 | + rowNum: 20, | |
16 | + records: 0, | |
17 | + pager: "", | |
18 | + pgbuttons: true, | |
19 | + pginput: true, | |
20 | + colModel: [], | |
21 | + rowList: [], | |
22 | + colNames: [], | |
23 | + sortorder: "asc", | |
24 | + sortname: "", | |
25 | + datatype: "xml", | |
26 | + mtype: "GET", | |
27 | + imgpath: "", | |
28 | + sortascimg: "sort_asc.gif", | |
29 | + sortdescimg: "sort_desc.gif", | |
30 | + firstimg: "first.gif", | |
31 | + previmg: "prev.gif", | |
32 | + nextimg: "next.gif", | |
33 | + lastimg: "last.gif", | |
34 | + altRows: true, | |
35 | + selarrrow: [], | |
36 | + savedRow: [], | |
37 | + shrinkToFit: true, | |
38 | + xmlReader: {}, | |
39 | + jsonReader: {}, | |
40 | + subGrid: false, | |
41 | + subGridModel :[], | |
42 | + lastpage: 0, | |
43 | + lastsort: 0, | |
44 | + selrow: null, | |
45 | + beforeSelectRow: null, | |
46 | + onSelectRow: null, | |
47 | + onSortCol: null, | |
48 | + ondblClickRow: null, | |
49 | + onRightClickRow: null, | |
50 | + onPaging: null, | |
51 | + onSelectAll: null, | |
52 | + loadComplete: null, | |
53 | + gridComplete: null, | |
54 | + loadError: null, | |
55 | + loadBeforeSend: null, | |
56 | + afterInsertRow: null, | |
57 | + beforeRequest: null, | |
58 | + onHeaderClick: null, | |
59 | + viewrecords: false, | |
60 | + loadonce: false, | |
61 | + multiselect: false, | |
62 | + multikey: false, | |
63 | + editurl: null, | |
64 | + search: false, | |
65 | + searchdata: {}, | |
66 | + caption: "", | |
67 | + hidegrid: true, | |
68 | + hiddengrid: false, | |
69 | + postData: {}, | |
70 | + userData: {}, | |
71 | + treeGrid : false, | |
72 | + treeANode: 0, | |
73 | + treedatatype: null, | |
74 | + treeReader: {level_field: "level", | |
75 | + left_field:"lft", | |
76 | + right_field: "rgt", | |
77 | + leaf_field: "isLeaf", | |
78 | + expanded_field: "expanded" | |
79 | + }, | |
80 | + tree_root_level: 0, | |
81 | + ExpandColumn: null, | |
82 | + sortclass: "grid_sort", | |
83 | + resizeclass: "grid_resize", | |
84 | + forceFit : false, | |
85 | + gridstate : "visible", | |
86 | + cellEdit: false, | |
87 | + cellsubmit: "remote", | |
88 | + nv:0, | |
89 | + loadui: "enable", | |
90 | + toolbar: [false,""] | |
91 | + }, $.jgrid.defaults, p || {}); | |
92 | + var grid={ | |
93 | + headers:[], | |
94 | + cols:[], | |
95 | + dragStart: function(i,x) { | |
96 | + this.resizing = { idx: i, startX: x}; | |
97 | + this.hDiv.style.cursor = "e-resize"; | |
98 | + }, | |
99 | + dragMove: function(x) { | |
100 | + if(this.resizing) { | |
101 | + var diff = x-this.resizing.startX; | |
102 | + var h = this.headers[this.resizing.idx]; | |
103 | + var newWidth = h.width + diff; | |
104 | + var msie = $.browser.msie; | |
105 | + if(newWidth > 25) { | |
106 | + if(p.forceFit===true ){ | |
107 | + var hn = this.headers[this.resizing.idx+p.nv]; | |
108 | + var nWn = hn.width - diff; | |
109 | + if(nWn >25) { | |
110 | + h.el.style.width = newWidth+"px"; | |
111 | + h.newWidth = newWidth; | |
112 | + this.cols[this.resizing.idx].style.width = newWidth+"px"; | |
113 | + hn.el.style.width = nWn +"px"; | |
114 | + hn.newWidth = nWn; | |
115 | + this.cols[this.resizing.idx+p.nv].style.width = nWn+"px"; | |
116 | + this.newWidth = this.width; | |
117 | + } | |
118 | + } else { | |
119 | + h.el.style.width = newWidth+"px"; | |
120 | + h.newWidth = newWidth; | |
121 | + this.cols[this.resizing.idx].style.width = newWidth+"px"; | |
122 | + this.newWidth = this.width+diff; | |
123 | + $('table:first',this.bDiv).css("width",this.newWidth +"px"); | |
124 | + $('table:first',this.hDiv).css("width",this.newWidth +"px"); | |
125 | + var scrLeft = this.bDiv.scrollLeft; | |
126 | + this.hDiv.scrollLeft = this.bDiv.scrollLeft; | |
127 | + if(msie) { | |
128 | + if(scrLeft - this.hDiv.scrollLeft >= 5) {this.bDiv.scrollLeft = this.bDiv.scrollLeft - 17;} | |
129 | + } | |
130 | + } | |
131 | + } | |
132 | + } | |
133 | + }, | |
134 | + dragEnd: function() { | |
135 | + this.hDiv.style.cursor = "default"; | |
136 | + if(this.resizing) { | |
137 | + var idx = this.resizing.idx; | |
138 | + this.headers[idx].width = this.headers[idx].newWidth || this.headers[idx].width; | |
139 | + this.cols[idx].style.width = this.headers[idx].newWidth || this.headers[idx].width; | |
140 | + if(p.forceFit===true){ | |
141 | + this.headers[idx+p.nv].width = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width; | |
142 | + this.cols[idx+p.nv].style.width = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width; | |
143 | + } | |
144 | + if(this.newWidth) {this.width = this.newWidth;} | |
145 | + this.resizing = false; | |
146 | + } | |
147 | + }, | |
148 | + scrollGrid: function() { | |
149 | + var scrollLeft = this.bDiv.scrollLeft; | |
150 | + this.hDiv.scrollLeft = this.bDiv.scrollLeft; | |
151 | + if(scrollLeft - this.hDiv.scrollLeft > 5) {this.bDiv.scrollLeft = this.bDiv.scrollLeft - 17;} | |
152 | + } | |
153 | + }; | |
154 | + $.fn.getGridParam = function(pName) { | |
155 | + var $t = this[0]; | |
156 | + if (!$t.grid) {return;} | |
157 | + if (!pName) { return $t.p; } | |
158 | + else {return $t.p[pName] ? $t.p[pName] : null;} | |
159 | + }; | |
160 | + $.fn.setGridParam = function (newParams){ | |
161 | + return this.each(function(){ | |
162 | + if (this.grid && typeof(newParams) === 'object') {$.extend(true,this.p,newParams);} | |
163 | + }); | |
164 | + }; | |
165 | + $.fn.getDataIDs = function () { | |
166 | + var ids=[]; | |
167 | + this.each(function(){ | |
168 | + $(this.rows).slice(1).each(function(i){ | |
169 | + ids[i]=this.id; | |
170 | + }); | |
171 | + }); | |
172 | + return ids; | |
173 | + }; | |
174 | + $.fn.setSortName = function (newsort) { | |
175 | + return this.each(function(){ | |
176 | + var $t = this; | |
177 | + for(var i=0;i< $t.p.colModel.length;i++){ | |
178 | + if($t.p.colModel[i].name===newsort || $t.p.colModel[i].index===newsort){ | |
179 | + $("tr th:eq("+$t.p.lastsort+") div img",$t.grid.hDiv).remove(); | |
180 | + $t.p.lastsort = i; | |
181 | + $t.p.sortname=newsort; | |
182 | + break; | |
183 | + } | |
184 | + } | |
185 | + }); | |
186 | + }; | |
187 | + $.fn.setSelection = function(selection,sd) { | |
188 | + return this.each(function(){ | |
189 | + var $t = this, stat,pt; | |
190 | + if(selection===false) {pt = sd;} | |
191 | + else { var ind = $($t).getInd($t.rows,selection); pt=$($t.rows[ind]);} | |
192 | + selection = $(pt).attr("id"); | |
193 | + if (!pt.html()) {return;} | |
194 | + if(!$t.p.multiselect) { | |
195 | + if($(pt).attr("class") !== "subgrid") { | |
196 | + if( $t.p.selrow ) {$("tr#"+$t.p.selrow+":first",$t.grid.bDiv).removeClass("selected");} | |
197 | + $t.p.selrow = selection; | |
198 | + $(pt).addClass("selected"); | |
199 | + if( $t.p.onSelectRow ) { $t.p.onSelectRow($t.p.selrow, true); } | |
200 | + } | |
201 | + } else { | |
202 | + $t.p.selrow = selection; | |
203 | + var ia = $.inArray($t.p.selrow,$t.p.selarrrow); | |
204 | + if ( ia === -1 ){ | |
205 | + if($(pt).attr("class") !== "subgrid") { $(pt).addClass("selected");} | |
206 | + stat = true; | |
207 | + $("#jqg_"+$t.p.selrow,$t.rows).attr("checked",stat); | |
208 | + $t.p.selarrrow.push($t.p.selrow); | |
209 | + if( $t.p.onSelectRow ) { $t.p.onSelectRow($t.p.selrow, stat); } | |
210 | + } else { | |
211 | + if($(pt).attr("class") !== "subgrid") { $(pt).removeClass("selected");} | |
212 | + stat = false; | |
213 | + $("#jqg_"+$t.p.selrow,$t.rows).attr("checked",stat); | |
214 | + $t.p.selarrrow.splice(ia,1); | |
215 | + if( $t.p.onSelectRow ) { $t.p.onSelectRow($t.p.selrow, stat); } | |
216 | + var tpsr = $t.p.selarrrow[0]; | |
217 | + $t.p.selrow = (tpsr=='undefined') ? null : tpsr; | |
218 | + } | |
219 | + } | |
220 | + }); | |
221 | + }; | |
222 | + $.fn.resetSelection = function(){ | |
223 | + return this.each(function(){ | |
224 | + var t = this; | |
225 | + if(!t.p.multiselect) { | |
226 | + if(t.p.selrow) { | |
227 | + $("tr#"+t.p.selrow+":first",t.grid.bDiv).removeClass("selected"); | |
228 | + t.p.selrow = null; | |
229 | + } | |
230 | + } else { | |
231 | + $(t.p.selarrrow).each(function(i,n){ | |
232 | + var ind = $(t).getInd(t.rows,n); | |
233 | + $(t.rows[ind]).removeClass("selected"); | |
234 | + $("#jqg_"+n,t.rows[ind]).attr("checked",false); | |
235 | + }); | |
236 | + $("#cb_jqg",t.grid.hDiv).attr("checked",false); | |
237 | + t.p.selarrrow = []; | |
238 | + } | |
239 | + }); | |
240 | + }; | |
241 | + $.fn.getRowData = function( rowid ) { | |
242 | + var res = {}; | |
243 | + if (rowid){ | |
244 | + this.each(function(){ | |
245 | + var $t = this,nm,ind; | |
246 | + ind = $($t).getInd($t.rows,rowid); | |
247 | + if (!ind) {return res;} | |
248 | + $('td:nth-child',$t.rows[ind]).each( function(i) { | |
249 | + nm = $t.p.colModel[i].name; | |
250 | + if ( nm !== 'cb' && nm !== 'subgrid') { | |
251 | + res[nm] = $(this).html().replace(/\ \;/ig,'').replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"'); | |
252 | + } | |
253 | + }); | |
254 | + }); | |
255 | + } | |
256 | + return res; | |
257 | + }; | |
258 | + $.fn.delRowData = function(rowid) { | |
259 | + var success = false, rowInd; | |
260 | + if(rowid) { | |
261 | + this.each(function() { | |
262 | + var $t = this; | |
263 | + rowInd = $($t).getInd($t.rows,rowid); | |
264 | + if(!rowInd) {return success;} | |
265 | + else { | |
266 | + $($t.rows[rowInd]).remove(); | |
267 | + $t.p.records--; | |
268 | + $t.updatepager(); | |
269 | + success=true; | |
270 | + } | |
271 | + if(rowInd == 1 && success && ($.browser.opera || $.browser.safari)) { | |
272 | + $($t.rows[1]).each( function( k ) { | |
273 | + $(this).css("width",$t.grid.headers[k].width+"px"); | |
274 | + $t.grid.cols[k] = this; | |
275 | + }); | |
276 | + } | |
277 | + if( $t.p.altRows === true && success) { | |
278 | + $($t.rows).slice(1).each(function(i){ | |
279 | + if(i % 2 ==1) {$(this).addClass('alt');} | |
280 | + else {$(this).removeClass('alt');} | |
281 | + }); | |
282 | + } | |
283 | + }); | |
284 | + } | |
285 | + return success; | |
286 | + }; | |
287 | + $.fn.setRowData = function(rowid, data) { | |
288 | + var nm, success=false; | |
289 | + this.each(function(){ | |
290 | + var t = this; | |
291 | + if(!t.grid) {return false;} | |
292 | + if( data ) { | |
293 | + var ind = $(t).getInd(t.rows,rowid); | |
294 | + if(!ind) {return success;} | |
295 | + success=true; | |
296 | + $(this.p.colModel).each(function(i){ | |
297 | + nm = this.name; | |
298 | + if(data[nm] !== 'undefined') { | |
299 | + $("td:eq("+i+")",t.rows[ind]).html(data[nm]); | |
300 | + success = true; | |
301 | + } | |
302 | + }); | |
303 | + } | |
304 | + }); | |
305 | + return success; | |
306 | + }; | |
307 | + $.fn.addRowData = function(rowid,data,pos,src) { | |
308 | + if(!pos) {pos = "last";} | |
309 | + var success = false; | |
310 | + var nm, row, td, gi=0, si=0,sind; | |
311 | + if(data) { | |
312 | + this.each(function() { | |
313 | + var t = this; | |
314 | + row = document.createElement("tr"); | |
315 | + row.id = rowid || t.p.records+1; | |
316 | + $(row).addClass("jqgrow"); | |
317 | + if(t.p.multiselect) { | |
318 | + td = $('<td></td>'); | |
319 | + $(td[0],t.grid.bDiv).html("<input type='checkbox'"+" id='jqg_"+rowid+"' class='cbox'/>"); | |
320 | + row.appendChild(td[0]); | |
321 | + gi = 1; | |
322 | + } | |
323 | + if(t.p.subGrid ) { try {$(t).addSubGrid(t.grid.bDiv,row,gi);} catch(e){} si=1;} | |
324 | + for(var i = gi+si; i < this.p.colModel.length;i++){ | |
325 | + nm = this.p.colModel[i].name; | |
326 | + td = $('<td></td>'); | |
327 | + $(td[0]).html(' '); | |
328 | + if(data[nm] !== 'undefined') { | |
329 | + $(td[0]).html(data[nm]); | |
330 | + } | |
331 | + t.formatCol($(td[0],t.grid.bDiv),i); | |
332 | + row.appendChild(td[0]); | |
333 | + } | |
334 | + switch (pos) { | |
335 | + case 'last': | |
336 | + $(t.rows[t.rows.length-1]).after(row); | |
337 | + break; | |
338 | + case 'first': | |
339 | + $(t.rows[0]).after(row); | |
340 | + break; | |
341 | + case 'after': | |
342 | + sind = $(t).getInd(t.rows,src); | |
343 | + sind >= 0 ? $(t.rows[sind]).after(row): ""; | |
344 | + break; | |
345 | + case 'before': | |
346 | + sind = $(t).getInd(t.rows,src); | |
347 | + sind > 0 ? $(t.rows[sind-1]).after(row): ""; | |
348 | + break; | |
349 | + } | |
350 | + t.p.records++; | |
351 | + if($.browser.safari || $.browser.opera) { | |
352 | + t.scrollLeft = t.scrollLeft; | |
353 | + $("td",t.rows[1]).each( function( k ) { | |
354 | + $(this).css("width",t.grid.headers[k].width+"px"); | |
355 | + t.grid.cols[k] = this; | |
356 | + }); | |
357 | + } | |
358 | + if( t.p.altRows === true ) { | |
359 | + if (pos == "last") { | |
360 | + if (t.rows.length % 2 == 1) {$(row).addClass('alt');} | |
361 | + } else { | |
362 | + $(t.rows).slice(1).each(function(i){ | |
363 | + if(i % 2 ==1) {$(this).addClass('alt');} | |
364 | + else {$(this).removeClass('alt');} | |
365 | + }); | |
366 | + } | |
367 | + } | |
368 | + try {t.p.afterInsertRow(row.id,data); } catch(e){} | |
369 | + t.updatepager(); | |
370 | + success = true; | |
371 | + }); | |
372 | + } | |
373 | + return success; | |
374 | + }; | |
375 | + $.fn.hideCol = function(colname) { | |
376 | + return this.each(function() { | |
377 | + var $t = this,w=0, fndh=false; | |
378 | + if (!$t.grid ) {return;} | |
379 | + if( typeof colname == 'string') {colname=[colname];} | |
380 | + $(this.p.colModel).each(function(i) { | |
381 | + if ($.inArray(this.name,colname) != -1 && !this.hidden) { | |
382 | + var w = parseInt($("tr th:eq("+i+")",$t.grid.hDiv).css("width"),10); | |
383 | + $("tr th:eq("+i+")",$t.grid.hDiv).css({display:"none"}); | |
384 | + $($t.rows).each(function(j){ | |
385 | + $("td:eq("+i+")",$t.rows[j]).css({display:"none"}); | |
386 | + }); | |
387 | + $t.grid.cols[i].style.width = 0; | |
388 | + $t.grid.headers[i].width = 0; | |
389 | + $t.grid.width -= w; | |
390 | + this.hidden=true; | |
391 | + fndh=true; | |
392 | + } | |
393 | + }); | |
394 | + if(fndh===true) { | |
395 | + var gtw = Math.min($t.p._width,$t.grid.width); | |
396 | + $("table:first",$t.grid.hDiv).width(gtw); | |
397 | + $("table:first",$t.grid.bDiv).width(gtw); | |
398 | + $($t.grid.hDiv).width(gtw); | |
399 | + $($t.grid.bDiv).width(gtw); | |
400 | + if($t.p.pager && $($t.p.pager).hasClass("scroll") ) { | |
401 | + $($t.p.pager).width(gtw); | |
402 | + } | |
403 | + if($t.p.caption) {$($t.grid.cDiv).width(gtw);} | |
404 | + if($t.p.toolbar[0]) {$($t.grid.uDiv).width(gtw);} | |
405 | + $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; | |
406 | + } | |
407 | + }); | |
408 | + }; | |
409 | + $.fn.showCol = function(colname) { | |
410 | + return this.each(function() { | |
411 | + var $t = this; var w = 0, fdns=false; | |
412 | + if (!$t.grid ) {return;} | |
413 | + if( typeof colname == 'string') {colname=[colname];} | |
414 | + $($t.p.colModel).each(function(i) { | |
415 | + if ($.inArray(this.name,colname) != -1 && this.hidden) { | |
416 | + var w = parseInt($("tr th:eq("+i+")",$t.grid.hDiv).css("width"),10); | |
417 | + $("tr th:eq("+i+")",$t.grid.hDiv).css("display",""); | |
418 | + $($t.rows).each(function(j){ | |
419 | + $("td:eq("+i+")",$t.rows[j]).css("display","").width(w); | |
420 | + }); | |
421 | + this.hidden=false; | |
422 | + $t.grid.cols[i].style.width = w; | |
423 | + $t.grid.headers[i].width = w; | |
424 | + $t.grid.width += w; | |
425 | + fdns=true; | |
426 | + } | |
427 | + }); | |
428 | + if(fdns===true) { | |
429 | + var gtw = Math.min($t.p._width,$t.grid.width); | |
430 | + var ofl = ($t.grid.width <= $t.p._width) ? "hidden" : "auto"; | |
431 | + $("table:first",$t.grid.hDiv).width(gtw); | |
432 | + $("table:first",$t.grid.bDiv).width(gtw); | |
433 | + $($t.grid.hDiv).width(gtw); | |
434 | + $($t.grid.bDiv).width(gtw).css("overflow-x",ofl); | |
435 | + if($t.p.pager && $($t.p.pager).hasClass("scroll") ) { | |
436 | + $($t.p.pager).width(gtw); | |
437 | + } | |
438 | + if($t.p.caption) {$($t.grid.cDiv).width(gtw);} | |
439 | + if($t.p.toolbar[0]) {$($t.grid.uDiv).width(gtw);} | |
440 | + $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; | |
441 | + } | |
442 | + }); | |
443 | + }; | |
444 | + $.fn.setGridWidth = function(nwidth, shrink) { | |
445 | + return this.each(function(){ | |
446 | + var $t = this, chw=0,w,cw,ofl; | |
447 | + if (!$t.grid ) {return;} | |
448 | + if(typeof shrink != 'boolean') {shrink=true;} | |
449 | + var testdata = getScale(); | |
450 | + if(shrink !== true) {testdata[0] = Math.min($t.p._width,$t.grid.width); testdata[2]=0;} | |
451 | + else {testdata[2]= testdata[1]} | |
452 | + $.each($t.p.colModel,function(i,v){ | |
453 | + if(!this.hidden && this.name != 'cb' && this.name!='subgrid') { | |
454 | + cw = shrink !== true ? $("tr:first th:eq("+i+")",$t.grid.hDiv).css("width") : this.width; | |
455 | + w = Math.round((IENum(nwidth)-IENum(testdata[2]))/IENum(testdata[0])*IENum(cw)); | |
456 | + chw += w; | |
457 | + $("table thead tr:first th:eq("+i+")",$t.grid.hDiv).css("width",w+"px"); | |
458 | + $("table:first tbody tr:first td:eq("+i+")",$t.grid.bDiv).css("width",w+"px"); | |
459 | + $t.grid.cols[i].style.width = w; | |
460 | + $t.grid.headers[i].width = w; | |
461 | + } | |
462 | + if(this.name=='cb' || this.name == 'subgrid'){chw += IENum(this.width);} | |
463 | + }); | |
464 | + if(chw + testdata[1] <= nwidth || $t.p.forceFit === true){ ofl = "hidden"; tw = nwidth;} | |
465 | + else { ofl= "auto"; tw = chw + testdata[1];} | |
466 | + $("table:first",$t.grid.hDiv).width(tw); | |
467 | + $("table:first",$t.grid.bDiv).width(tw); | |
468 | + $($t.grid.hDiv).width(nwidth); | |
469 | + $($t.grid.bDiv).width(nwidth).css("overflow-x",ofl); | |
470 | + if($t.p.pager && $($t.p.pager).hasClass("scroll") ) { | |
471 | + $($t.p.pager).width(nwidth); | |
472 | + } | |
473 | + if($t.p.caption) {$($t.grid.cDiv).width(nwidth);} | |
474 | + if($t.p.toolbar[0]) {$($t.grid.uDiv).width(nwidth);} | |
475 | + $t.p._width = nwidth; $t.grid.width = tw; | |
476 | + if($.browser.safari || $.browser.opera ) { | |
477 | + $("table tbody tr:eq(1) td",$t.grid.bDiv).each( function( k ) { | |
478 | + $(this).css("width",$t.grid.headers[k].width+"px"); | |
479 | + $t.grid.cols[k] = this; | |
480 | + }); | |
481 | + } | |
482 | + $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; | |
483 | + function IENum(val) { | |
484 | + val = parseInt(val,10); | |
485 | + return isNaN(val) ? 0 : val; | |
486 | + } | |
487 | + function getScale(){ | |
488 | + var testcell = $("table tr:first th:eq(1)", $t.grid.hDiv); | |
489 | + var addpix = IENum($(testcell).css("padding-left")) + | |
490 | + IENum($(testcell).css("padding-right"))+ | |
491 | + IENum($(testcell).css("border-left-width"))+ | |
492 | + IENum($(testcell).css("border-right-width")); | |
493 | + var w =0,ap=0; | |
494 | + $.each($t.p.colModel,function(i,v){ | |
495 | + if(!this.hidden) { | |
496 | + w += parseInt(this.width); | |
497 | + ap += addpix; | |
498 | + } | |
499 | + }); | |
500 | + return [w,ap,0]; | |
501 | + } | |
502 | + }); | |
503 | + }; | |
504 | + $.fn.setGridHeight = function (nh) { | |
505 | + return this.each(function (){ | |
506 | + var ovfl, ovfl2, $t = this; | |
507 | + if(!$t.grid) {return;} | |
508 | + if($t.p.forceFit === true) { ovfl2='hidden'; } else {ovfl2=$($t.grid.bDiv).css("overflow-x");} | |
509 | + ovfl = (isNaN(nh) && $.browser.mozilla && (nh.indexOf("%")!=-1 || nh=="auto")) ? "hidden" : "auto"; | |
510 | + $($t.grid.bDiv).css({height: nh+(isNaN(nh)?"":"px"),"overflow-y":ovfl,"overflow-x": ovfl2}); | |
511 | + $t.p.height = nh; | |
512 | + }); | |
513 | + }; | |
514 | + $.fn.setCaption = function (newcap){ | |
515 | + return this.each(function(){ | |
516 | + this.p.caption=newcap; | |
517 | + $("table:first th",this.grid.cDiv).html(newcap); | |
518 | + $(this.grid.cDiv).show(); | |
519 | + }); | |
520 | + }; | |
521 | + $.fn.setLabel = function(colname, nData, prop ){ | |
522 | + return this.each(function(){ | |
523 | + var $t = this, pos=-1; | |
524 | + if(!$t.grid) {return;} | |
525 | + if(isNaN(colname)) { | |
526 | + $($t.p.colModel).each(function(i){ | |
527 | + if (this.name == colname) { | |
528 | + pos = i;return false; | |
529 | + } | |
530 | + }); | |
531 | + } else {pos = parseInt(colname,10);} | |
532 | + if(pos>=0) { | |
533 | + var thecol = $("table:first th:eq("+pos+")",$t.grid.hDiv); | |
534 | + if (nData){ | |
535 | + $("div",thecol).html(nData); | |
536 | + } | |
537 | + if (prop) { | |
538 | + if(typeof prop == 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);} | |
539 | + } | |
540 | + } | |
541 | + }); | |
542 | + }; | |
543 | + $.fn.setCell = function(rowid,colname,nData,prop) { | |
544 | + return this.each(function(){ | |
545 | + var $t = this, pos =-1; | |
546 | + if(!$t.grid) {return;} | |
547 | + if(isNaN(colname)) { | |
548 | + $($t.p.colModel).each(function(i){ | |
549 | + if (this.name == colname) { | |
550 | + pos = i;return false; | |
551 | + } | |
552 | + }); | |
553 | + } else {pos = parseInt(colname,10);} | |
554 | + if(pos>=0) { | |
555 | + var ind = $($t).getInd($t.rows,rowid); | |
556 | + if (ind){ | |
557 | + var tcell = $("td:eq("+pos+")",$t.rows[ind]); | |
558 | + if(nData) {$(tcell).html(nData);} | |
559 | + if (prop){ | |
560 | + if(typeof prop == 'string') {$(tcell).addClass(prop);} else {$(tcell).css(prop);} | |
561 | + } | |
562 | + } | |
563 | + } | |
564 | + }); | |
565 | + }; | |
566 | + $.fn.getCell = function(rowid,iCol) { | |
567 | + var ret = false; | |
568 | + this.each(function(){ | |
569 | + var $t=this; | |
570 | + if(!$t.grid) {return;} | |
571 | + if(rowid && iCol>=0) { | |
572 | + var ind = $($t).getInd($t.rows,rowid); | |
573 | + if(ind) { | |
574 | + ret = $("td:eq("+iCol+")",$t.rows[ind]).html().replace(/\ \;/ig,''); | |
575 | + } | |
576 | + } | |
577 | + }); | |
578 | + return ret; | |
579 | + }; | |
580 | + $.fn.clearGridData = function() { | |
581 | + return this.each(function(){ | |
582 | + var $t = this; | |
583 | + if(!$t.grid) {return;} | |
584 | + $("tbody tr:gt(0)", $t.grid.bDiv).remove(); | |
585 | + $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = []; | |
586 | + $t.p.records = '0';$t.p.page='0';$t.p.lastpage='0'; | |
587 | + $t.updatepager(); | |
588 | + }); | |
589 | + }; | |
590 | + $.fn.getInd = function(obj,rowid,rc){ | |
591 | + var ret =false; | |
592 | + $(obj).each(function(i){ | |
593 | + if(this.id==rowid) { | |
594 | + ret = rc===true ? this : i; | |
595 | + return false; | |
596 | + } | |
597 | + }); | |
598 | + return ret; | |
599 | + }; | |
600 | + return this.each( function() { | |
601 | + if(this.grid) {return;} | |
602 | + this.p = p ; | |
603 | + if( this.p.colNames.length === 0 || this.p.colNames.length !== this.p.colModel.length ) { | |
604 | + alert("Length of colNames <> colModel or 0!"); | |
605 | + return; | |
606 | + } | |
607 | + if(this.p.imgpath !== "" ) {this.p.imgpath += "/";} | |
608 | + var ts = this; | |
609 | + $("<div class='loadingui' id=lui_"+this.id+"/>").insertBefore(this); | |
610 | + $(this).attr({cellSpacing:"0",cellPadding:"0",border:"0"}); | |
611 | + var bSR = $.isFunction(this.p.beforeSelectRow) ? this.p.beforeSelectRow :false; | |
612 | + var onSelectRow = $.isFunction(this.p.onSelectRow) ? this.p.onSelectRow :false; | |
613 | + var ondblClickRow = $.isFunction(this.p.ondblClickRow) ? this.p.ondblClickRow :false; | |
614 | + var onSortCol = $.isFunction(this.p.onSortCol) ? this.p.onSortCol : false; | |
615 | + var loadComplete = $.isFunction(this.p.loadComplete) ? this.p.loadComplete : false; | |
616 | + var loadError = $.isFunction(this.p.loadError) ? this.p.loadError : false; | |
617 | + var loadBeforeSend = $.isFunction(this.p.loadBeforeSend) ? this.p.loadBeforeSend : false; | |
618 | + var onRightClickRow = $.isFunction(this.p.onRightClickRow) ? this.p.onRightClickRow : false; | |
619 | + var afterInsRow = $.isFunction(this.p.afterInsertRow) ? this.p.afterInsertRow : false; | |
620 | + var onHdCl = $.isFunction(this.p.onHeaderClick) ? this.p.onHeaderClick : false; | |
621 | + var beReq = $.isFunction(this.p.beforeRequest) ? this.p.beforeRequest : false; | |
622 | + var onSC = $.isFunction(this.p.onCellSelect) ? this.p.onCellSelect : false; | |
623 | + var sortkeys = ["shiftKey","altKey","ctrlKey"]; | |
624 | + if ($.inArray(ts.p.multikey,sortkeys) == -1 ) {ts.p.multikey = false;} | |
625 | + var IntNum = function(val,defval) { | |
626 | + val = parseInt(val,10); | |
627 | + if (isNaN(val)) { return (defval) ? defval : 0;} | |
628 | + else {return val;} | |
629 | + }; | |
630 | + var formatCol = function (elem, pos){ | |
631 | + var rowalgn = ts.p.colModel[pos].align; | |
632 | + if(rowalgn) { $(elem).css("text-align",rowalgn);} | |
633 | + if(ts.p.colModel[pos].hidden) {$(elem).css("display","none");} | |
634 | + }; | |
635 | + var resizeFirstRow = function (t,er){ | |
636 | + $("tbody tr:eq("+er+") td",t).each( function( k ) { | |
637 | + $(this).css("width",grid.headers[k].width+"px"); | |
638 | + grid.cols[k] = this; | |
639 | + }); | |
640 | + }; | |
641 | + var addCell = function(t,row,cell,pos) { | |
642 | + var td; | |
643 | + td = document.createElement("td"); | |
644 | + $(td).html(cell); | |
645 | + row.appendChild(td); | |
646 | + formatCol($(td,t), pos); | |
647 | + }; | |
648 | + var addMulti = function(t,row){ | |
649 | + var cbid,td; | |
650 | + td = document.createElement("td"); | |
651 | + cbid = "jqg_"+row.id; | |
652 | + $(td,t).html("<input type='checkbox'"+" id='"+cbid+"' class='cbox'/>"); | |
653 | + formatCol($(td,t), 0); | |
654 | + row.appendChild(td); | |
655 | + }; | |
656 | + var reader = function (datatype) { | |
657 | + var field, f=[], j=0; | |
658 | + for(var i =0; i<ts.p.colModel.length; i++){ | |
659 | + field = ts.p.colModel[i]; | |
660 | + if (field.name !== 'cb' && field.name !=='subgrid') { | |
661 | + f[j] = (datatype=="xml") ? field.xmlmap || field.name : field.jsonmap || field.name; | |
662 | + j++; | |
663 | + } | |
664 | + } | |
665 | + return f; | |
666 | + }; | |
667 | + var addXmlData = function addXmlData (xml,t) { | |
668 | + if(xml) { var fpos = ts.p.treeANode; if(fpos===0) {$("tbody tr:gt(0)", t).remove();} } else { return; } | |
669 | + var row,gi=0,si=0,cbid,idn, getId,f=[],rd =[],cn=(ts.p.altRows === true) ? 'alt':''; | |
670 | + if(!ts.p.xmlReader.repeatitems) {f = reader("xml");} | |
671 | + if( ts.p.keyIndex===false) { | |
672 | + idn = ts.p.xmlReader.id; | |
673 | + if( idn.indexOf("[") === -1 ) { | |
674 | + getId = function( trow, k) {return $(idn,trow).text() || k;}; | |
675 | + } | |
676 | + else { | |
677 | + getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;}; | |
678 | + } | |
679 | + } else { | |
680 | + getId = function(trow) { return (f.length - 1 >= ts.p.keyIndex) ? $(f[ts.p.keyIndex],trow).text() : $(ts.p.xmlReader.cell+":eq("+ts.p.keyIndex+")",trow).text(); }; | |
681 | + } | |
682 | + $(ts.p.xmlReader.page,xml).each(function() {ts.p.page = this.textContent || this.text ; }); | |
683 | + $(ts.p.xmlReader.total,xml).each(function() {ts.p.lastpage = this.textContent || this.text ; } ); | |
684 | + $(ts.p.xmlReader.records,xml).each(function() {ts.p.records = this.textContent || this.text ; } ); | |
685 | + $(ts.p.xmlReader.userdata,xml).each(function() {ts.p.userData[this.getAttribute("name")]=this.textContent || this.text;}); | |
686 | + $(ts.p.xmlReader.root+" "+ts.p.xmlReader.row,xml).each( function( j ) { | |
687 | + row = document.createElement("tr"); | |
688 | + row.id = getId(this,j+1); | |
689 | + if(ts.p.multiselect) { | |
690 | + addMulti(t,row); | |
691 | + gi = 1; | |
692 | + } | |
693 | + if (ts.p.subGrid) { | |
694 | + try {$(ts).addSubGrid(t,row,gi,this);} catch (e){} | |
695 | + si= 1; | |
696 | + } | |
697 | + var v; | |
698 | + if(ts.p.xmlReader.repeatitems===true){ | |
699 | + $(ts.p.xmlReader.cell,this).each( function (i) { | |
700 | + v = this.textContent || this.text; | |
701 | + addCell(t,row,v || ' ',i+gi+si); | |
702 | + rd[ts.p.colModel[i+gi+si].name] = v; | |
703 | + }); | |
704 | + } else { | |
705 | + for(var i = 0; i < f.length;i++) { | |
706 | + v = $(f[i],this).text(); | |
707 | + addCell(t, row, v || ' ', i+gi+si); | |
708 | + rd[ts.p.colModel[i+gi+si].name] = v; | |
709 | + } | |
710 | + } | |
711 | + if(j%2 == 1) {row.className = cn;} $(row).addClass("jqgrow"); | |
712 | + if( ts.p.treeGrid === true) { | |
713 | + try {$(ts).setTreeNode(rd,row);} catch (e) {} | |
714 | + } | |
715 | + $(ts.rows[j+fpos]).after(row); | |
716 | + if(afterInsRow) {ts.p.afterInsertRow(row.id,rd,this);} | |
717 | + rd=[]; | |
718 | + }); | |
719 | + xml = null; | |
720 | + if(isSafari || isOpera) {resizeFirstRow(t,1);} | |
721 | + if(!ts.p.treeGrid) {ts.grid.bDiv.scrollTop = 0;} | |
722 | + endReq(); | |
723 | + updatepager(); | |
724 | + }; | |
725 | + var addJSONData = function(data,t) { | |
726 | + if(data) { var fpos = ts.p.treeANode; if(fpos===0) {$("tbody tr:gt(0)", t).remove();} } else { return; } | |
727 | + var row,f=[],cur,gi=0,si=0,drows,idn,rd=[],cn=(ts.p.altRows===true) ? 'alt':''; | |
728 | + ts.p.page = data[ts.p.jsonReader.page]; | |
729 | + ts.p.lastpage= data[ts.p.jsonReader.total]; | |
730 | + ts.p.records= data[ts.p.jsonReader.records]; | |
731 | + ts.p.userData = data[ts.p.jsonReader.userdata] || {}; | |
732 | + if(!ts.p.jsonReader.repeatitems) {f = reader("json");} | |
733 | + if( ts.p.keyIndex===false ) { | |
734 | + idn = ts.p.jsonReader.id; | |
735 | + if(f.length>0 && !isNaN(idn)) {idn=f[idn];} | |
736 | + } else { | |
737 | + idn = f.length>0 ? f[ts.p.keyIndex] : ts.p.keyIndex; | |
738 | + } | |
739 | + drows = data[ts.p.jsonReader.root]; | |
740 | + if (drows) { | |
741 | + for (var i=0;i<drows.length;i++) { | |
742 | + cur = drows[i]; | |
743 | + row = document.createElement("tr"); | |
744 | + row.id = cur[idn] || ""; | |
745 | + if(row.id === "") { | |
746 | + if(f.length===0){ | |
747 | + if(ts.p.jsonReader.cell){ | |
748 | + var ccur = cur[ts.p.jsonReader.cell]; | |
749 | + row.id = ccur[idn] || i+1; | |
750 | + ccur=null; | |
751 | + } else {row.id=i+1;} | |
752 | + } else { | |
753 | + row.id=i+1; | |
754 | + } | |
755 | + } | |
756 | + if(ts.p.multiselect){ | |
757 | + addMulti(t,row); | |
758 | + gi = 1; | |
759 | + } | |
760 | + if (ts.p.subGrid) { | |
761 | + try { $(ts).addSubGrid(t,row,gi,drows[i]);} catch (e){} | |
762 | + si= 1; | |
763 | + } | |
764 | + if (ts.p.jsonReader.repeatitems === true) { | |
765 | + if(ts.p.jsonReader.cell) {cur = cur[ts.p.jsonReader.cell];} | |
766 | + for (var j=0;j<cur.length;j++) { | |
767 | + addCell(t,row,cur[j] || ' ',j+gi+si); | |
768 | + rd[ts.p.colModel[j+gi+si].name] = cur[j]; | |
769 | + } | |
770 | + } else { | |
771 | + for (var j=0;j<f.length;j++) { | |
772 | + addCell(t,row,cur[f[j]] || ' ',j+gi+si); | |
773 | + rd[ts.p.colModel[j+gi+si].name] = cur[f[j]]; | |
774 | + } | |
775 | + } | |
776 | + if(i%2 == 1) {row.className = cn;} $(row).addClass("jqgrow"); | |
777 | + if( ts.p.treeGrid === true) { | |
778 | + try {$(ts).setTreeNode(rd,row);} catch (e) {} | |
779 | + } | |
780 | + $(ts.rows[i+fpos]).after(row); | |
781 | + if(afterInsRow) {ts.p.afterInsertRow(row.id,rd,drows[i]);} | |
782 | + rd=[]; | |
783 | + } | |
784 | + } | |
785 | + data = null; | |
786 | + if(isSafari || isOpera) {resizeFirstRow(t,1);} | |
787 | + if(!ts.p.treeGrid) {ts.grid.bDiv.scrollTop = 0;} | |
788 | + endReq(); | |
789 | + updatepager(); | |
790 | + }; | |
791 | + var updatepager = function() { | |
792 | + if(ts.p.pager) { | |
793 | + var cp, last,imp = ts.p.imgpath; | |
794 | + if (ts.p.loadonce) { | |
795 | + cp = last = 1; | |
796 | + ts.p.lastpage = ts.page =1; | |
797 | + $(".selbox",ts.p.pager).attr("disabled",true); | |
798 | + } else { | |
799 | + cp = IntNum(ts.p.page); | |
800 | + last = IntNum(ts.p.lastpage); | |
801 | + $(".selbox",ts.p.pager).attr("disabled",false); | |
802 | + } | |
803 | + if(ts.p.pginput===true) { | |
804 | + $('input.selbox',ts.p.pager).val(ts.p.page); | |
805 | + } | |
806 | + if (ts.p.viewrecords){ | |
807 | + if(ts.p.pgtext) { | |
808 | + $('#sp_1',ts.p.pager).html(ts.p.pgtext+" "+ts.p.lastpage ); | |
809 | + } | |
810 | + $('#sp_2',ts.p.pager).html(ts.p.records+" "+ts.p.recordtext+" "); | |
811 | + } | |
812 | + if(ts.p.pgbuttons===true) { | |
813 | + if(cp<=0) {cp = last = 1;} | |
814 | + if(cp==1) {$("#first",ts.p.pager).attr({src:imp+"off-"+ts.p.firstimg,disabled:true});} else {$("#first",ts.p.pager).attr({src:imp+ts.p.firstimg,disabled:false});} | |
815 | + if(cp==1) {$("#prev",ts.p.pager).attr({src:imp+"off-"+ts.p.previmg,disabled:true});} else {$("#prev",ts.p.pager).attr({src:imp+ts.p.previmg,disabled:false});} | |
816 | + if(cp==last) {$("#next",ts.p.pager).attr({src:imp+"off-"+ts.p.nextimg,disabled:true});} else {$("#next",ts.p.pager).attr({src:imp+ts.p.nextimg,disabled:false});} | |
817 | + if(cp==last) {$("#last",ts.p.pager).attr({src:imp+"off-"+ts.p.lastimg,disabled:true});} else {$("#last",ts.p.pager).attr({src:imp+ts.p.lastimg,disabled:false});} | |
818 | + } | |
819 | + } | |
820 | + if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete();} | |
821 | + }; | |
822 | + var populate = function () { | |
823 | + if(!grid.hDiv.loading) { | |
824 | + beginReq(); | |
825 | + var gdata = $.extend(ts.p.postData,{page: ts.p.page, rows: ts.p.rowNum, sidx: ts.p.sortname, sord:ts.p.sortorder, nd: (new Date().getTime()), _search:ts.p.search}); | |
826 | + if (ts.p.search ===true) {gdata =$.extend(gdata,ts.p.searchdata);} | |
827 | + if ($.isFunction(ts.p.datatype)) {ts.p.datatype(gdata);endReq();} | |
828 | + switch(ts.p.datatype) | |
829 | + { | |
830 | + case "json": | |
831 | + $.ajax({url:ts.p.url,type:ts.p.mtype,dataType:"json",data: gdata, complete:function(JSON,st) { if(st=="success") {addJSONData(eval("("+JSON.responseText+")"),ts.grid.bDiv); if(loadComplete) {loadComplete();}}}, error:function(xhr,st,err){if(loadError) {loadError(xhr,st,err);}endReq();}, beforeSend: function(xhr){if(loadBeforeSend) {loadBeforeSend(xhr);}}}); | |
832 | + if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";} | |
833 | + break; | |
834 | + case "xml": | |
835 | + $.ajax({url:ts.p.url,type:ts.p.mtype,dataType:"xml",data: gdata , complete:function(xml,st) {if(st=="success") {addXmlData(xml.responseXML,ts.grid.bDiv); if(loadComplete) {loadComplete();}}}, error:function(xhr,st,err){if(loadError) {loadError(xhr,st,err);}endReq();}, beforeSend: function(xhr){if(loadBeforeSend) {loadBeforeSend(xhr);}}}); | |
836 | + if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";} | |
837 | + break; | |
838 | + case "xmlstring": | |
839 | + addXmlData(stringToDoc(ts.p.datastr),ts.grid.bDiv); | |
840 | + ts.p.datastr = null; | |
841 | + ts.p.datatype = "local"; | |
842 | + if(loadComplete) {loadComplete();} | |
843 | + break; | |
844 | + case "jsonstring": | |
845 | + addJSONData(eval("("+ts.p.datastr+")"),ts.grid.bDiv); | |
846 | + ts.p.datastr = null; | |
847 | + ts.p.datatype = "local"; | |
848 | + if(loadComplete) {loadComplete();} | |
849 | + break; | |
850 | + case "local": | |
851 | + case "clientSide": | |
852 | + sortArrayData(); | |
853 | + break; | |
854 | + } | |
855 | + } | |
856 | + }; | |
857 | + var beginReq = function() { | |
858 | + if(beReq) {ts.p.beforeRequest();} | |
859 | + grid.hDiv.loading = true; | |
860 | + switch(ts.p.loadui) { | |
861 | + case "disable": | |
862 | + break; | |
863 | + case "enable": | |
864 | + $("div.loading",grid.hDiv).fadeIn("fast"); | |
865 | + break; | |
866 | + case "block": | |
867 | + $("div.loading",grid.hDiv).fadeIn("fast"); | |
868 | + $("#lui_"+ts.id).width($(grid.bDiv).width()).height(IntNum($(grid.bDiv).height())+IntNum(ts.p._height)).show(); | |
869 | + break; | |
870 | + } | |
871 | + }; | |
872 | + var endReq = function() { | |
873 | + grid.hDiv.loading = false; | |
874 | + switch(ts.p.loadui) { | |
875 | + case "disable": | |
876 | + break; | |
877 | + case "enable": | |
878 | + $("div.loading",grid.hDiv).fadeOut("fast"); | |
879 | + break; | |
880 | + case "block": | |
881 | + $("div.loading",grid.hDiv).fadeOut("fast"); | |
882 | + $("#lui_"+ts.id).hide(); | |
883 | + break; | |
884 | + } | |
885 | + }; | |
886 | + var stringToDoc = function (xmlString) { | |
887 | + var xmlDoc; | |
888 | + try { | |
889 | + var parser = new DOMParser(); | |
890 | + xmlDoc = parser.parseFromString(xmlString,"text/xml"); | |
891 | + } | |
892 | + catch(e) { | |
893 | + xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); | |
894 | + xmlDoc.async=false; | |
895 | + xmlDoc["loadXM"+"L"](xmlString); | |
896 | + } | |
897 | + return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null; | |
898 | + }; | |
899 | + var sortArrayData = function() { | |
900 | + var stripNum = /[\$,%]/g; | |
901 | + var col=0,st,findSortKey,newDir = (ts.p.sortorder == "asc") ? 1 :-1; | |
902 | + $.each(ts.p.colModel,function(i,v){ | |
903 | + if(this.index == ts.p.sortname || this.name == ts.p.sortname){ | |
904 | + col = ts.p.lastsort= i; | |
905 | + st = this.sorttype; | |
906 | + return false; | |
907 | + } | |
908 | + }); | |
909 | + if (st == 'float') { | |
910 | + findSortKey = function($cell) { | |
911 | + var key = parseFloat($cell.text().replace(stripNum, '')); | |
912 | + return isNaN(key) ? 0 : key; | |
913 | + }; | |
914 | + } else if (st=='int') { | |
915 | + findSortKey = function($cell) { | |
916 | + return IntNum($cell.text().replace(stripNum, '')); | |
917 | + }; | |
918 | + } else if(st == 'date') { | |
919 | + findSortKey = function($cell) { | |
920 | + var fd = ts.p.colModel[col].datefmt || "Y-m-d"; | |
921 | + return parseDate(fd,$cell.text()).getTime(); | |
922 | + }; | |
923 | + } else { | |
924 | + findSortKey = function($cell) { | |
925 | + return $cell.text().toUpperCase(); | |
926 | + }; | |
927 | + } | |
928 | + var rows=[]; | |
929 | + $.each(ts.rows, function(index, row) { | |
930 | + if (index > 0) { | |
931 | + row.sortKey = findSortKey($(row).children('td').eq(col)); | |
932 | + rows[index-1] = this; | |
933 | + } | |
934 | + }); | |
935 | + if(ts.p.treeGrid) { | |
936 | + $(ts).SortTree( newDir); | |
937 | + } else { | |
938 | + rows.sort(function(a, b) { | |
939 | + if (a.sortKey < b.sortKey) {return -newDir;} | |
940 | + if (a.sortKey > b.sortKey) {return newDir;} | |
941 | + return 0; | |
942 | + }); | |
943 | + $.each(rows, function(index, row) { | |
944 | + $('tbody',ts.grid.bDiv).append(row); | |
945 | + row.sortKey = null; | |
946 | + }); | |
947 | + } | |
948 | + if(isSafari || isOpera) {resizeFirstRow(ts.grid.bDiv,1);} | |
949 | + if(ts.p.multiselect) { | |
950 | + $("tbody tr:gt(0)", ts.grid.bDiv).removeClass("selected"); | |
951 | + $("[@id^=jqg_]",ts.rows).attr("checked",false); | |
952 | + $("#cb_jqg",ts.grid.hDiv).attr("checked",false); | |
953 | + ts.p.selarrrow = []; | |
954 | + } | |
955 | + if( ts.p.altRows === true ) { | |
956 | + $("tbody tr:gt(0)", ts.grid.bDiv).removeClass("alt"); | |
957 | + $("tbody tr:odd", ts.grid.bDiv).addClass("alt"); | |
958 | + } | |
959 | + ts.grid.bDiv.scrollTop = 0; | |
960 | + endReq(); | |
961 | + }; | |
962 | + var parseDate = function(format, date) { | |
963 | + var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0}; | |
964 | + format = format.toLowerCase(); | |
965 | + date = date.split(/[\\\/:_;.\s-]/); | |
966 | + format = format.split(/[\\\/:_;.\s-]/); | |
967 | + for(var i=0;i<format.length;i++){ | |
968 | + tsp[format[i]] = IntNum(date[i],tsp[format[i]]); | |
969 | + } | |
970 | + tsp.m = parseInt(tsp.m,10)-1; | |
971 | + var ty = tsp.y; | |
972 | + if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;} | |
973 | + else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;} | |
974 | + return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s,0); | |
975 | + }; | |
976 | + var setPager = function (){ | |
977 | + var inpt = "<img class='pgbuttons' src='"+ts.p.imgpath+"spacer.gif'"; | |
978 | + var pginp = (ts.p.pginput===true) ? "<input class='selbox' type='text' size='3' maxlength='5' value='0'/>" : ""; | |
979 | + if(ts.p.viewrecords===true) {pginp += "<span id='sp_1'></span> ";} | |
980 | + var pgl="", pgr=""; | |
981 | + if(ts.p.pgbuttons===true) { | |
982 | + pgl = inpt+" id='first'/>  "+inpt+" id='prev'/> "; | |
983 | + pgr = inpt+" id='next' />  "+inpt+" id='last'/>"; | |
984 | + } | |
985 | + $(ts.p.pager).append(pgl+pginp+pgr); | |
986 | + if(ts.p.rowList.length >0){ | |
987 | + var str="<SELECT class='selbox'>"; | |
988 | + for(var i=0;i<ts.p.rowList.length;i++){ | |
989 | + str +="<OPTION value="+ts.p.rowList[i]+((ts.p.rowNum == ts.p.rowList[i])?' selected':'')+">"+ts.p.rowList[i]; | |
990 | + } | |
991 | + str +="</SELECT>"; | |
992 | + $(ts.p.pager).append(" "+str+" <span id='sp_2'></span>"); | |
993 | + $(ts.p.pager).find("select").bind('change',function() { | |
994 | + ts.p.rowNum = (this.value>0) ? this.value : ts.p.rowNum; | |
995 | + if (typeof ts.p.onPaging =='function') {ts.p.onPaging('records');} | |
996 | + populate(); | |
997 | + ts.p.selrow = null; | |
998 | + }); | |
999 | + } else { $(ts.p.pager).append(" <span id='sp_2'></span>");} | |
1000 | + if(ts.p.pgbuttons===true) { | |
1001 | + $(".pgbuttons",ts.p.pager).mouseover(function(e){ | |
1002 | + this.style.cursor= "pointer"; | |
1003 | + return false; | |
1004 | + }).mouseout(function(e) { | |
1005 | + this.style.cursor= "normal"; | |
1006 | + return false; | |
1007 | + }); | |
1008 | + $("#first, #prev, #next, #last",ts.p.pager).click( function(e) { | |
1009 | + var cp = IntNum(ts.p.page); | |
1010 | + var last = IntNum(ts.p.lastpage), selclick = false; | |
1011 | + var fp=true; var pp=true; var np=true; var lp=true; | |
1012 | + if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; } | |
1013 | + else if( last>1 && cp >=1) { | |
1014 | + if( cp === 1) { fp=false; pp=false; } | |
1015 | + else if( cp>1 && cp <last){ } | |
1016 | + else if( cp===last){ np=false;lp=false; } | |
1017 | + } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;} | |
1018 | + if( this.id === 'first' && fp ) { ts.p.page=1; selclick=true;} | |
1019 | + if( this.id === 'prev' && pp) { ts.p.page=(cp-1); selclick=true;} | |
1020 | + if( this.id === 'next' && np) { ts.p.page=(cp+1); selclick=true;} | |
1021 | + if( this.id === 'last' && lp) { ts.p.page=last; selclick=true;} | |
1022 | + if(selclick) { | |
1023 | + if (typeof ts.p.onPaging =='function') {ts.p.onPaging(this.id);} | |
1024 | + populate(); | |
1025 | + ts.p.selrow = null; | |
1026 | + if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_jqg',ts.grid.hDiv).attr("checked",false);} | |
1027 | + ts.p.savedRow = []; | |
1028 | + } | |
1029 | + e.stopPropagation(); | |
1030 | + return false; | |
1031 | + }); | |
1032 | + } | |
1033 | + if(ts.p.pginput===true) { | |
1034 | + $('input.selbox',ts.p.pager).keypress( function(e) { | |
1035 | + var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; | |
1036 | + if(key == 13) { | |
1037 | + ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page; | |
1038 | + if (typeof ts.p.onPaging =='function') {ts.p.onPaging( 'user');} | |
1039 | + populate(); | |
1040 | + ts.p.selrow = null; | |
1041 | + return false; | |
1042 | + } | |
1043 | + return this; | |
1044 | + }); | |
1045 | + } | |
1046 | + }; | |
1047 | + var sortData = function (index, idxcol,reload){ | |
1048 | + if(!reload) { | |
1049 | + if( ts.p.lastsort === idxcol ) { | |
1050 | + if( ts.p.sortorder === 'asc') { | |
1051 | + ts.p.sortorder = 'desc'; | |
1052 | + } else if(ts.p.sortorder === 'desc') { ts.p.sortorder='asc';} | |
1053 | + } else { ts.p.sortorder='asc';} | |
1054 | + ts.p.page = 1; | |
1055 | + } | |
1056 | + var imgs = (ts.p.sortorder==='asc') ? ts.p.sortascimg : ts.p.sortdescimg; | |
1057 | + imgs = "<img src='"+ts.p.imgpath+imgs+"'>"; | |
1058 | + var thd= $("thead:first",grid.hDiv).get(0); | |
1059 | + $("tr th div#jqgh_"+ts.p.colModel[ts.p.lastsort].name+" img",thd).remove(); | |
1060 | + $("tr th div#jqgh_"+ts.p.colModel[ts.p.lastsort].name,thd).parent().removeClass(ts.p.sortclass); | |
1061 | + $("tr th div#"+index,thd).append(imgs).parent().addClass(ts.p.sortclass); | |
1062 | + ts.p.lastsort = idxcol; | |
1063 | + index = index.substring(5); | |
1064 | + ts.p.sortname = ts.p.colModel[idxcol].index || index; | |
1065 | + var so = ts.p.sortorder; | |
1066 | + if(onSortCol) {onSortCol(index,idxcol,so);} | |
1067 | + if(ts.p.selrow && ts.p.datatype == "local" && !ts.p.multiselect){ $('#'+ts.p.selrow,grid.bDiv).removeClass("selected");} | |
1068 | + ts.p.selrow = null; | |
1069 | + if(ts.p.multiselect && ts.p.datatype !== "local"){ts.p.selarrrow =[]; $("#cb_jqg",ts.grid.hDiv).attr("checked",false);} | |
1070 | + ts.p.savedRow =[]; | |
1071 | + populate(); | |
1072 | + if(ts.p.sortname != index && idxcol) {ts.p.lastsort = idxcol;} | |
1073 | + }; | |
1074 | + var setColWidth = function () { | |
1075 | + var initwidth = 0; | |
1076 | + for(var l=0;l<ts.p.colModel.length;l++){ | |
1077 | + if(!ts.p.colModel[l].hidden){ | |
1078 | + initwidth += IntNum(ts.p.colModel[l].width); | |
1079 | + } | |
1080 | + } | |
1081 | + var tblwidth = ts.p.width ? ts.p.width : initwidth; | |
1082 | + for(l=0;l<ts.p.colModel.length;l++) { | |
1083 | + if(!ts.p.shrinkToFit){ | |
1084 | + ts.p.colModel[l].owidth = ts.p.colModel[l].width; | |
1085 | + } | |
1086 | + ts.p.colModel[l].width = Math.round(tblwidth/initwidth*ts.p.colModel[l].width); | |
1087 | + } | |
1088 | + }; | |
1089 | + var nextVisible= function(iCol) { | |
1090 | + var ret = iCol, j=iCol; | |
1091 | + for (var i = iCol+1;i<ts.p.colModel.length;i++){ | |
1092 | + if(ts.p.colModel[i].hidden !== true ) { | |
1093 | + j=i; break; | |
1094 | + } | |
1095 | + } | |
1096 | + return j-ret; | |
1097 | + }; | |
1098 | + this.p.id = this.id; | |
1099 | + if(this.p.treeGrid === true) { | |
1100 | + this.p.subGrid = false; this.p.altRows =false; | |
1101 | + this.p.pgbuttons = false; this.p.pginput = false; | |
1102 | + this.p.multiselect = false; this.p.rowList = []; | |
1103 | + this.p.treedatatype = this.p.datatype; | |
1104 | + $.each(this.p.treeReader,function(i,n){ | |
1105 | + if(n){ | |
1106 | + ts.p.colNames.push(n); | |
1107 | + ts.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false}); | |
1108 | + } | |
1109 | + }); | |
1110 | + } | |
1111 | + ts.p.keyIndex=false; | |
1112 | + for (var i=0; i<ts.p.colModel.length;i++) { | |
1113 | + if (ts.p.colModel[i].key===true) { | |
1114 | + ts.p.keyIndex = i; | |
1115 | + break; | |
1116 | + } | |
1117 | + } | |
1118 | + if(this.p.subGrid) { | |
1119 | + this.p.colNames.unshift(""); | |
1120 | + this.p.colModel.unshift({name:'subgrid',width:25,sortable: false,resizable:false,hidedlg:true,search:false}); | |
1121 | + } | |
1122 | + if(this.p.multiselect) { | |
1123 | + this.p.colNames.unshift("<input id='cb_jqg' class='cbox' type='checkbox'/>"); | |
1124 | + this.p.colModel.unshift({name:'cb',width:27,sortable:false,resizable:false,hidedlg:true,search:false}); | |
1125 | + } | |
1126 | + var xReader = { | |
1127 | + root: "rows", | |
1128 | + row: "row", | |
1129 | + page: "rows>page", | |
1130 | + total: "rows>total", | |
1131 | + records : "rows>records", | |
1132 | + repeatitems: true, | |
1133 | + cell: "cell", | |
1134 | + id: "[id]", | |
1135 | + userdata: "userdata", | |
1136 | + subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"} | |
1137 | + }; | |
1138 | + var jReader = { | |
1139 | + root: "rows", | |
1140 | + page: "page", | |
1141 | + total: "total", | |
1142 | + records: "records", | |
1143 | + repeatitems: true, | |
1144 | + cell: "cell", | |
1145 | + id: "id", | |
1146 | + userdata: "userdata", | |
1147 | + subgrid: {root:"rows", repeatitems: true, cell:"cell"} | |
1148 | + }; | |
1149 | + ts.p.xmlReader = $.extend(xReader, ts.p.xmlReader); | |
1150 | + ts.p.jsonReader = $.extend(jReader, ts.p.jsonReader); | |
1151 | + $.each(ts.p.colModel, function(i){if(!this.width) {this.width=150;}}); | |
1152 | + if (ts.p.width) {setColWidth();} | |
1153 | + var thead = document.createElement("thead"); | |
1154 | + var trow = document.createElement("tr"); | |
1155 | + thead.appendChild(trow); | |
1156 | + var i=0, th, idn, thdiv; | |
1157 | + if(ts.p.shrinkToFit===true && ts.p.forceFit===true) { | |
1158 | + for (i=ts.p.colModel.length-1;i>=0;i--){ | |
1159 | + if(!ts.p.colModel[i].hidden) { | |
1160 | + ts.p.colModel[i].resizable=false; | |
1161 | + break; | |
1162 | + } | |
1163 | + } | |
1164 | + } | |
1165 | + for(i=0;i<this.p.colNames.length;i++){ | |
1166 | + th = document.createElement("th"); | |
1167 | + idn = ts.p.colModel[i].name; | |
1168 | + thdiv = document.createElement("div"); | |
1169 | + $(thdiv).html(ts.p.colNames[i]+" "); | |
1170 | + if (idn == ts.p.sortname) { | |
1171 | + var imgs = (ts.p.sortorder==='asc') ? ts.p.sortascimg : ts.p.sortdescimg; | |
1172 | + imgs = "<img src='"+ts.p.imgpath+imgs+"'>"; | |
1173 | + $(thdiv).append(imgs); | |
1174 | + ts.p.lastsort = i; | |
1175 | + $(th).addClass(ts.p.sortclass); | |
1176 | + } | |
1177 | + thdiv.id = "jqgh_"+idn; | |
1178 | + th.appendChild(thdiv); | |
1179 | + trow.appendChild(th); | |
1180 | + } | |
1181 | + if(this.p.multiselect) { | |
1182 | + var onSA = true; | |
1183 | + if(typeof ts.p.onSelectAll !== 'function') {onSA=false;} | |
1184 | + $('#cb_jqg',trow).click(function(){ | |
1185 | + var chk; | |
1186 | + if (this.checked) { | |
1187 | + $("[@id^=jqg_]",ts.rows).attr("checked",true); | |
1188 | + $(ts.rows).slice(1).each(function(i) { | |
1189 | + if(!$(this).hasClass("subgrid")){ | |
1190 | + $(this).addClass("selected"); | |
1191 | + ts.p.selarrrow[i]= ts.p.selrow = this.id; | |
1192 | + } | |
1193 | + }); | |
1194 | + chk=true; | |
1195 | + } | |
1196 | + else { | |
1197 | + $("[@id^=jqg_]",ts.rows).attr("checked",false); | |
1198 | + $(ts.rows).slice(1).each(function(i) { | |
1199 | + if(!$(this).hasClass("subgrid")){ | |
1200 | + $(this).removeClass("selected"); | |
1201 | + } | |
1202 | + }); | |
1203 | + ts.p.selarrrow = []; ts.p.selrow = null; | |
1204 | + chk=false; | |
1205 | + } | |
1206 | + if(onSA) {ts.p.onSelectAll(ts.p.selarrrow,chk);} | |
1207 | + }); | |
1208 | + } | |
1209 | + this.appendChild(thead); | |
1210 | + thead = $("thead:first",ts).get(0); | |
1211 | + var w, res, sort; | |
1212 | + $("tr:first th",thead).each(function ( j ) { | |
1213 | + w = ts.p.colModel[j].width; | |
1214 | + if(typeof ts.p.colModel[j].resizable === 'undefined') {ts.p.colModel[j].resizable = true;} | |
1215 | + res = document.createElement("span"); | |
1216 | + $(res).html(" "); | |
1217 | + if(ts.p.colModel[j].resizable){ | |
1218 | + $(this).addClass(ts.p.resizeclass); | |
1219 | + $(res).mousedown(function (e) { | |
1220 | + if(ts.p.forceFit===true) {ts.p.nv= nextVisible(j);} | |
1221 | + grid.dragStart( j ,e.clientX); | |
1222 | + e.preventDefault(); | |
1223 | + return false; | |
1224 | + }); | |
1225 | + } else {$(res).css("cursor","default");} | |
1226 | + $(this).css("width",w+"px").prepend(res); | |
1227 | + if( ts.p.colModel[j].hidden) {$(this).css("display","none");} | |
1228 | + grid.headers[j] = { width: w, el: this }; | |
1229 | + sort = ts.p.colModel[j].sortable; | |
1230 | + if( typeof sort !== 'boolean') {sort = true;} | |
1231 | + if(sort) { | |
1232 | + $("div",this).css("cursor","pointer") | |
1233 | + .click(function(){sortData(this.id,j);return false;}); | |
1234 | + } | |
1235 | + }); | |
1236 | + var isMSIE = $.browser.msie ? true:false; | |
1237 | + var isMoz = $.browser.mozilla ? true:false; | |
1238 | + var isOpera = $.browser.opera ? true:false; | |
1239 | + var isSafari = $.browser.safari ? true : false; | |
1240 | + var tbody = document.createElement("tbody"); | |
1241 | + trow = document.createElement("tr"); | |
1242 | + trow.id = "_empty"; | |
1243 | + tbody.appendChild(trow); | |
1244 | + var td, ptr; | |
1245 | + for(i=0;i<ts.p.colNames.length;i++){ | |
1246 | + td = document.createElement("td"); | |
1247 | + trow.appendChild(td); | |
1248 | + } | |
1249 | + this.appendChild(tbody); | |
1250 | + var gw=0,hdc=0; | |
1251 | + $("tbody tr:first td",ts).each(function(ii) { | |
1252 | + w = ts.p.colModel[ii].width; | |
1253 | + $(this).css({width:w+"px",height:"0px"}); | |
1254 | + w += IntNum($(this).css("padding-left")) + | |
1255 | + IntNum($(this).css("padding-right"))+ | |
1256 | + IntNum($(this).css("border-left-width"))+ | |
1257 | + IntNum($(this).css("border-right-width")); | |
1258 | + if( ts.p.colModel[ii].hidden===true) { | |
1259 | + $(this).css("display","none"); | |
1260 | + hdc += w; | |
1261 | + } | |
1262 | + grid.cols[ii] = this; | |
1263 | + gw += w; | |
1264 | + }); | |
1265 | + if(isMoz) {$(trow).css({visibility:"collapse"});} | |
1266 | + else if( isSafari || isOpera ) {$(trow).css({display:"none"});} | |
1267 | + grid.width = IntNum(gw)-IntNum(hdc); | |
1268 | + ts.p._width = grid.width; | |
1269 | + grid.hTable = document.createElement("table"); | |
1270 | + grid.hTable.appendChild(thead); | |
1271 | + $(grid.hTable).addClass("scroll") | |
1272 | + .attr({cellSpacing:"0",cellPadding:"0",border:"0"}) | |
1273 | + .css({width:grid.width+"px"}); | |
1274 | + grid.hDiv = document.createElement("div"); | |
1275 | + var hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false; | |
1276 | + $(grid.hDiv) | |
1277 | + .css({ width: grid.width+"px", overflow: "hidden"}) | |
1278 | + .prepend('<div class="loading">'+ts.p.loadtext+'</div>') | |
1279 | + .append(grid.hTable) | |
1280 | + .bind("selectstart", function () { return false; }); | |
1281 | + if(hg) {$(grid.hDiv).hide(); ts.p.gridstate = 'hidden'} | |
1282 | + if(ts.p.pager){ | |
1283 | + if(typeof ts.p.pager == "string") {ts.p.pager = "#"+ts.p.pager;} | |
1284 | + if( $(ts.p.pager).hasClass("scroll")) { $(ts.p.pager).css({ width: grid.width+"px", overflow: "hidden"}).show(); ts.p._height= parseInt($(ts.p.pager).height(),10); if(hg) {$(ts.p.pager).hide();}} | |
1285 | + setPager(); | |
1286 | + } | |
1287 | + if( ts.p.cellEdit === false) { | |
1288 | + $(ts).mouseover(function(e) { | |
1289 | + td = (e.target || e.srcElement); | |
1290 | + ptr = $(td,ts.rows).parents("tr:first"); | |
1291 | + if($(ptr).hasClass("jqgrow")) { | |
1292 | + $(ptr).addClass("over"); | |
1293 | + if(!$(td).hasClass("editable")){ | |
1294 | + td.title = $(td).text(); | |
1295 | + } | |
1296 | + } | |
1297 | + return false; | |
1298 | + }).mouseout(function(e) { | |
1299 | + td = (e.target || e.srcElement); | |
1300 | + ptr = $(td,ts.rows).parents("tr:first"); | |
1301 | + $(ptr).removeClass("over"); | |
1302 | + if(!$(td).hasClass("editable")){ | |
1303 | + td.title = ""; | |
1304 | + } | |
1305 | + return false; | |
1306 | + }); | |
1307 | + } | |
1308 | + var ri,ci; | |
1309 | + | |
1310 | + $(ts).before(grid.hDiv).css("width", grid.width+"px").click(function(e) { | |
1311 | + td = (e.target || e.srcElement); | |
1312 | + if (td.href) { return true; } | |
1313 | + var scb = $(td).hasClass("cbox"); | |
1314 | + ptr = $(td,ts.rows).parent("tr"); | |
1315 | + if($(ptr).length === 0 ){ | |
1316 | + ptr = $(td,ts.rows).parents("tr:first"); | |
1317 | + td = $(td).parents("td:first")[0]; | |
1318 | + } | |
1319 | + var cSel = true; | |
1320 | + if(bSR) { cSel = bSR(ptr.attr("id"));} | |
1321 | + if(cSel === true) { | |
1322 | + if(ts.p.cellEdit === true) { | |
1323 | + if(ts.p.multiselect && scb){ | |
1324 | + $(ts).setSelection(false,ptr); | |
1325 | + } else { | |
1326 | + ri = ptr[0].rowIndex; | |
1327 | + ci = td.cellIndex; | |
1328 | + try {$(ts).editCell(ri,ci,true,true);} catch (e) {} | |
1329 | + } | |
1330 | + } else | |
1331 | + if ( !ts.p.multikey ) { | |
1332 | + $(ts).setSelection(false,ptr); | |
1333 | + if(onSC) { | |
1334 | + ri = ptr[0].id; | |
1335 | + ci = td.cellIndex; | |
1336 | + onSC(ri,ci,$(td).html()); | |
1337 | + } | |
1338 | + } else { | |
1339 | + if(e[ts.p.multikey]) { | |
1340 | + $(ts).setSelection(false,ptr); | |
1341 | + } else if(ts.p.multiselect) { | |
1342 | + if(scb) { scb = $("[@id^=jqg_]",ptr).attr("checked"); | |
1343 | + $("[@id^=jqg_]",ptr).attr("checked",!scb); | |
1344 | + } | |
1345 | + } | |
1346 | + } | |
1347 | + } | |
1348 | + e.stopPropagation(); | |
1349 | + }).bind('reloadGrid', function(e) { | |
1350 | + if(!ts.p.treeGrid) {ts.p.selrow=null;} | |
1351 | + if(ts.p.multiselect) {ts.p.selarrrow =[];$('#cb_jqg',ts.grid.hDiv).attr("checked",false);} | |
1352 | + if(ts.p.cellEdit) {ts.p.savedRow = []; } | |
1353 | + populate(); | |
1354 | + }); | |
1355 | + | |
1356 | + if( ondblClickRow ) { | |
1357 | + $(this).dblclick(function(e) { | |
1358 | + td = (e.target || e.srcElement); | |
1359 | + ptr = $(td,ts.rows).parent("tr"); | |
1360 | + if($(ptr).length === 0 ){ | |
1361 | + ptr = $(td,ts.rows).parents("tr:first"); | |
1362 | + } | |
1363 | + ts.p.ondblClickRow($(ptr).attr("id")); | |
1364 | + return false; | |
1365 | + }); | |
1366 | + } | |
1367 | + if (onRightClickRow) { | |
1368 | + $(this).bind('contextmenu', function(e) { | |
1369 | + td = (e.target || e.srcElement); | |
1370 | + ptr = $(td,ts).parents("tr:first"); | |
1371 | + if($(ptr).length === 0 ){ | |
1372 | + ptr = $(td,ts.rows).parents("tr:first"); | |
1373 | + } | |
1374 | + $(ts).setSelection(false,ptr); | |
1375 | + ts.p.onRightClickRow($(ptr).attr("id")); | |
1376 | + return false; | |
1377 | + }); | |
1378 | + } | |
1379 | + grid.bDiv = document.createElement("div"); | |
1380 | + var ofl2 = (isNaN(ts.p.height) && isMoz && (ts.p.height.indexOf("%")!=-1 || ts.p.height=="auto")) ? "hidden" : "auto"; | |
1381 | + $(grid.bDiv) | |
1382 | + .scroll(function (e) {grid.scrollGrid();}) | |
1383 | + .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), padding: "0px", margin: "0px", overflow: ofl2,width: (grid.width)+"px"} ).css("overflow-x","hidden") | |
1384 | + .append(this); | |
1385 | + $("table:first",grid.bDiv).css({width:grid.width+"px",marginRight:"20px"}); | |
1386 | + if( isMSIE ) { | |
1387 | + if( $("tbody",this).size() === 2 ) { $("tbody:first",this).remove();} | |
1388 | + if( ts.p.multikey) {$(grid.bDiv).bind("selectstart",function(){return false;});} | |
1389 | + if(ts.p.treeGrid) {$(grid.bDiv).css("position","relative");} | |
1390 | + } else { | |
1391 | + if( ts.p.multikey) {$(grid.bDiv).bind("mousedown",function(){return false;});} | |
1392 | + } | |
1393 | + if(hg) {$(grid.bDiv).hide();} | |
1394 | + grid.cDiv = document.createElement("div"); | |
1395 | + $(grid.cDiv).append("<table class='Header' cellspacing='0' cellpadding='0' border='0'><tr><td class='HeaderLeft'><img src='"+ts.p.imgpath+"spacer.gif' border='0' /></td><th>"+ts.p.caption+"</th>"+ ((ts.p.hidegrid===true) ? "<td class='HeaderButton'><img src='"+ts.p.imgpath+"up.gif' border='0'/></td>" :"") +"<td class='HeaderRight'><img src='"+ts.p.imgpath+"spacer.gif' border='0' /></td></tr></table>").addClass("GridHeader"); | |
1396 | + $(grid.cDiv).insertBefore(grid.hDiv); | |
1397 | + if( ts.p.toolbar[0] ) { | |
1398 | + grid.uDiv = document.createElement("div"); | |
1399 | + if(ts.p.toolbar[1] == "top") {$(grid.uDiv).insertBefore(grid.hDiv);} | |
1400 | + else {$(grid.uDiv).insertAfter(grid.hDiv);} | |
1401 | + $(grid.uDiv,ts).width(grid.width).addClass("userdata").attr("id","t_"+this.id); | |
1402 | + ts.p._height += parseInt($(grid.uDiv,ts).height(),10); | |
1403 | + if(hg) {$(grid.uDiv,ts).hide();} | |
1404 | + } | |
1405 | + if(ts.p.caption) { | |
1406 | + $(grid.cDiv,ts).width(grid.width).css("text-align","center").show("fast"); | |
1407 | + ts.p._height += parseInt($(grid.cDiv,ts).height(),10); | |
1408 | + var tdt = ts.p.datatype; | |
1409 | + if(ts.p.hidegrid===true) { | |
1410 | + $(".HeaderButton",grid.cDiv).toggle( function(){ | |
1411 | + if(ts.p.pager) {$(ts.p.pager).fadeOut("slow");} | |
1412 | + if(ts.p.toolbar[0]) {$(grid.uDiv,ts).fadeOut("slow");} | |
1413 | + $(grid.bDiv,ts).fadeOut("slow"); | |
1414 | + $(grid.hDiv,ts).fadeOut("slow"); | |
1415 | + $("img",this).attr("src",ts.p.imgpath+"down.gif"); | |
1416 | + ts.p.gridstate = 'hidden'; | |
1417 | + if(onHdCl) {if(!hg) {ts.p.onHeaderClick(ts.p.gridstate);}} | |
1418 | + }, | |
1419 | + function() { | |
1420 | + $(grid.hDiv ,ts).fadeIn("slow"); | |
1421 | + $(grid.bDiv,ts).fadeIn("slow"); | |
1422 | + if(ts.p.pager) {$(ts.p.pager).fadeIn("slow");} | |
1423 | + if(ts.p.toolbar[0]) {$(grid.uDiv).fadeIn("slow");} | |
1424 | + $("img",this).attr("src",ts.p.imgpath+"up.gif"); | |
1425 | + if(hg) {ts.p.datatype = tdt;populate();hg=false;} | |
1426 | + ts.p.gridstate = 'visible'; | |
1427 | + if(onHdCl) {ts.p.onHeaderClick(ts.p.gridstate)} | |
1428 | + } | |
1429 | + ); | |
1430 | + if(hg) { $(".HeaderButton",grid.cDiv).trigger("click"); ts.p.datatype="local";} | |
1431 | + } | |
1432 | + } | |
1433 | + ts.p._height += parseInt($(grid.hDiv,ts).height(),10); | |
1434 | + $(grid.hDiv).mousemove(function (e) {grid.dragMove(e.clientX); return false;}).after(grid.bDiv); | |
1435 | + $(document).mouseup(function (e) { | |
1436 | + if(grid.resizing) { | |
1437 | + grid.dragEnd(); | |
1438 | + if(grid.newWidth && ts.p.forceFit===false){ | |
1439 | + var gwdt = (grid.width <= ts.p._width) ? grid.width: ts.p._width; | |
1440 | + var overfl = (grid.width <= ts.p._width) ? "hidden" : "auto"; | |
1441 | + if(ts.p.pager && $(ts.p.pager).hasClass("scroll") ) { | |
1442 | + $(ts.p.pager).width(gwdt); | |
1443 | + } | |
1444 | + if(ts.p.caption) {$(grid.cDiv).width(gwdt);} | |
1445 | + if(ts.p.toolbar[0]) {$(grid.uDiv).width(gwdt);} | |
1446 | + $(grid.bDiv).width(gwdt).css("overflow-x",overfl); | |
1447 | + $(grid.hDiv).width(gwdt); | |
1448 | + } | |
1449 | + } | |
1450 | + return false; | |
1451 | + }); | |
1452 | + ts.formatCol = function(a,b) {formatCol(a,b);}; | |
1453 | + ts.sortData = function(a,b,c){sortData(a,b,c);}; | |
1454 | + ts.updatepager = function(){updatepager();}; | |
1455 | + this.grid = grid; | |
1456 | + ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);}; | |
1457 | + ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);}; | |
1458 | + populate(); | |
1459 | + if (!ts.p.shrinkToFit) { | |
1460 | + ts.p.forceFit = false; | |
1461 | + $("tr:first th", thead).each(function(j){ | |
1462 | + var w = ts.p.colModel[j].owidth; | |
1463 | + var diff = w - ts.p.colModel[j].width; | |
1464 | + if (diff > 0 && !ts.p.colModel[j].hidden) { | |
1465 | + grid.headers[j].width = w; | |
1466 | + $(this).add(grid.cols[j]).width(w); | |
1467 | + $('table:first',grid.bDiv).add(grid.hTable).width(ts.grid.width); | |
1468 | + ts.grid.width += diff; | |
1469 | + grid.hDiv.scrollLeft = grid.bDiv.scrollLeft; | |
1470 | + } | |
1471 | + }); | |
1472 | + ofl2 = (grid.width <= ts.p._width) ? "hidden" : "auto"; | |
1473 | + $(grid.bDiv).css({"overflow-x":ofl2}); | |
1474 | + } | |
1475 | + $(window).unload(function () { | |
1476 | + $(this).unbind("*"); | |
1477 | + this.grid = null; | |
1478 | + this.p = null; | |
1479 | + }); | |
1480 | + }); | |
1481 | +}; | |
1482 | +})(jQuery); |
@@ -155,7 +155,9 @@ | ||
155 | 155 | var so = options.value.split(";"),sv, ov; |
156 | 156 | elem = document.createElement("select"); |
157 | 157 | var msl = options.multiple === true ? true : false; |
158 | - jQuery(elem).attr({id:options.id,name:options.name,size:Math.min(options.size,so.length), multiple:msl }); | |
158 | + jQuery(elem).attr({ | |
159 | + id: options.id, name: options.name, multiple: msl, | |
160 | + size: Math.min(options.size, so.length) || undefined }); | |
159 | 161 | for(var i=0; i<so.length;i++){ |
160 | 162 | sv = so[i].split(":"); |
161 | 163 | ov = document.createElement("option"); |
@@ -1,700 +1,700 @@ | ||
1 | -var workfloweditor; | |
2 | -if (!workfloweditor) workfloweditor = {}; | |
3 | - | |
4 | -/** | |
5 | - * i18n | |
6 | - */ | |
7 | -workfloweditor.Localizer = function() { | |
8 | - this.strings = {}; | |
9 | - this.lang = ""; | |
10 | - | |
11 | - var htmlTag = document.getElementsByTagName("html")[0]; | |
12 | - this.lang = htmlTag.getAttribute("xml:lang") || htmlTag.getAttribute("lang"); | |
13 | - | |
14 | - // If there isn't the lang attribute, use browser language. | |
15 | - if (this.lang == null || this.lang == "") { | |
16 | - var currentLanguage; | |
17 | - if (navigator.browserLanguage) { | |
18 | - currentLanguage = navigator.browserLanguage; | |
19 | - } else if (navigator.language) { | |
20 | - currentLanguage = navigator.language; | |
21 | - } else if (navigator.userLanguage) { | |
22 | - currentLanguage = navigator.userLanguage; | |
23 | - } | |
24 | - | |
25 | - if (currentLanguage && currentLanguage.length >= 2) { | |
26 | - this.lang = currentLanguage.substr(0,2); | |
27 | - } | |
28 | - } | |
29 | - | |
30 | - var self = this; | |
31 | - this.getLocalizedString = function(str) { | |
32 | - if (!workfloweditor.Localizer.strings) | |
33 | - { | |
34 | - return str; | |
35 | - } | |
36 | - | |
37 | - var message = workfloweditor.Localizer.strings[str]; | |
38 | - if (!message || message == "") { | |
39 | - message = str; | |
40 | - } | |
41 | - return message; | |
42 | - }; | |
43 | - | |
44 | - return this; | |
45 | -} | |
46 | - | |
47 | -workfloweditor.Localizer = new workfloweditor.Localizer(); | |
48 | -_ = workfloweditor.Localizer.getLocalizedString; | |
49 | - | |
50 | -/** | |
51 | - * Workflow Editor onload action. | |
52 | - */ | |
53 | -jQuery(document).ready(function(){ | |
54 | - var context = new workfloweditor.WorkflowContext(); | |
55 | - | |
56 | - // display grid | |
57 | - context.updateModelByText("#workflowText"); | |
58 | - context.initGrid("#workflowGrid"); | |
59 | - context.initStatusGrid("#workflowStatusGrid"); | |
60 | - | |
61 | - // display tab layout | |
62 | - var tabsElem = $("#workflowTabs > ul").tabs(); | |
63 | - var currentTab = "gridTab"; | |
64 | - | |
65 | - tabsElem.tabs("select", 0); | |
66 | - tabsElem.bind("tabsselect", function(event, origEvent, ui) { | |
67 | - currentTab = ui.panel.id; | |
68 | - | |
69 | - if (!ui.panel.id) { | |
70 | - // do nothing | |
71 | - } else if (ui.panel.id == "gridTab") { | |
72 | - context.updateModelByText("#workflowText"); | |
73 | - context.refreshGrid(); | |
74 | - } else if (ui.panel.id == "textTab") { | |
75 | - context.updateModelByGrid("#workflowGrid"); | |
76 | - context.refreshText(); | |
77 | - } else { | |
78 | - // do nothing | |
79 | - } | |
80 | - }); | |
81 | - | |
82 | - // Save button action | |
83 | - // The workflow is updated before saving. | |
84 | - jQuery("#doChanges").click( function() { | |
85 | - try | |
86 | - { | |
87 | - if (currentTab == "textTab") { | |
88 | - currentTab = tabsElem.tabs().data('selected.tabs') | |
89 | - if (currentTab == "1") { | |
90 | - context.updateModelByText("#workflowText"); | |
91 | - context.refreshGrid(); | |
92 | - } | |
93 | - } | |
94 | - | |
95 | - context.updateModelByGrid("#workflowGrid"); | |
96 | - context.refreshText(); | |
97 | - } | |
98 | - catch(ex) | |
99 | - { | |
100 | - alert(_("Error: Please fix the workflow text.") | |
101 | - + "\n(error code = " + ex.number + ")"); | |
102 | - return false; | |
103 | - } | |
104 | - }); | |
105 | - | |
106 | - $("#workflowTabs").show(); | |
107 | - | |
108 | -}); | |
109 | - | |
110 | -/** | |
111 | - * Workflow Editor | |
112 | - */ | |
113 | -workfloweditor.WorkflowContext = function() { | |
114 | - this.DEFAULT_OPERATIONS = { | |
115 | - "" : "", | |
116 | - "set_owner" : _("set owner"), | |
117 | - "del_owner" : _("del owner"), | |
118 | - "set_owner_to_self" : _("set owner to self"), | |
119 | - "set_resolution" : _("set resolution"), | |
120 | - "del_resolution" : _("del resolution"), | |
121 | - "leave_status" : _("leave status") | |
122 | - }; | |
123 | - this.DEFAULT_PERMISSIONS = { | |
124 | - "" : "", | |
125 | - "TICKET_VIEW" : "TICKET_VIEW", | |
126 | - "TICKET_CREATE" : "TICKET_CREATE", | |
127 | - "TICKET_MODIFY" : "TICKET_MODIFY", | |
128 | - "TICKET_ADMIN" : "TICKET_ADMIN" | |
129 | - }; | |
130 | - this.DEFAULT_STATUS = ["new", "assigned", "accepted", "reopened", "closed"]; | |
131 | - this.HIDDEN_COL = ["operations", "permissions"]; | |
132 | - this.STATUS_PREFIX = "status_"; | |
133 | - this.IMAGE_PATH = "../../chrome/workfloweditor/images"; | |
134 | - this.EDIT_URL = document.location + "/edit"; | |
135 | - | |
136 | - this.model = {}; | |
137 | - this.status = [].concat(this.DEFAULT_STATUS); | |
138 | - | |
139 | - this.textId; | |
140 | - this.gridId; | |
141 | - this.statusGridId; | |
142 | -} | |
143 | - | |
144 | -/** | |
145 | - * The workflow text is converted to the workflow model. | |
146 | - * | |
147 | - * @param textId workflow textarea field ID | |
148 | - */ | |
149 | -workfloweditor.WorkflowContext.prototype.updateModelByText = function(textId) { | |
150 | - this.textId = textId; | |
151 | - | |
152 | - var text = $(textId).val(); | |
153 | - if (!text) { | |
154 | - return; | |
155 | - } | |
156 | - | |
157 | - var lines = text.split("\n"); | |
158 | - var model = {}; | |
159 | - var status = this.status; | |
160 | - for (var index = 0; index < lines.length; index++) { | |
161 | - var line = lines[index]; | |
162 | - var pos = lines[index].indexOf("="); | |
163 | - var param = jQuery.trim(line.substring(0, pos)); | |
164 | - var value = jQuery.trim(line.substring(pos + 1, line.length)); | |
165 | - | |
166 | - // skip line | |
167 | - if (!param || param.length <= 0) { | |
168 | - continue; | |
169 | - } | |
170 | - | |
171 | - // parse workflow text | |
172 | - if (param.indexOf(".") < 0) { | |
173 | - // parse action | |
174 | - var action = param; | |
175 | - var elems = value.split("->"); | |
176 | - var oldStatus = jQuery.trim(elems[0]); | |
177 | - var newStatus = jQuery.trim(elems[1]); | |
178 | - | |
179 | - var workflow = model[action]; | |
180 | - if (!workflow) { | |
181 | - workflow = {}; | |
182 | - model[action] = workflow; | |
183 | - } | |
184 | - workflow["action"] = action; | |
185 | - workflow["oldStatus"] = oldStatus; | |
186 | - workflow["newStatus"] = newStatus; | |
187 | - | |
188 | - if ((newStatus != "*") && ($.inArray(newStatus, status) < 0)) { | |
189 | - status.push(newStatus); | |
190 | - } | |
191 | - } else { | |
192 | - // parse options | |
193 | - var elems = param.split("."); | |
194 | - var action = elems[0]; | |
195 | - var attribute = elems[1]; | |
196 | - | |
197 | - var workflow = model[action]; | |
198 | - if (!workflow) { | |
199 | - workflow = {}; | |
200 | - model[action] = workflow; | |
201 | - } | |
202 | - workflow[attribute] = value; | |
203 | - } | |
204 | - } | |
205 | - | |
206 | - workfloweditor.WorkflowContext.normalizeModel(model); | |
207 | - | |
208 | - this.model = model; | |
209 | - this.status = status; | |
210 | -} | |
211 | - | |
212 | -/** | |
213 | - * The workflow grid data is converted to the workflow model. | |
214 | - * | |
215 | - * @param gridId workflow grid ID. | |
216 | - */ | |
217 | -workfloweditor.WorkflowContext.prototype.updateModelByGrid = function(gridId) { | |
218 | - this.gridId = gridId; | |
219 | - | |
220 | - var dataIds = jQuery(gridId).getDataIDs(); | |
221 | - if (!dataIds || dataIds.length <= 0) { | |
222 | - return; | |
223 | - } | |
224 | - | |
225 | - var model = {}; | |
226 | - var status = this.status; | |
227 | - var rowNum = dataIds.length; | |
228 | - for (var index = 0; index < rowNum; index++) { | |
229 | - var rowData = jQuery(gridId).getRowData(dataIds[index]); | |
230 | - var action = rowData["action"]; | |
231 | - | |
232 | - if (!action) { | |
233 | - continue; | |
234 | - } | |
235 | - | |
236 | - var oldStatus = []; | |
237 | - for (col in rowData) { | |
238 | - var pos = col.indexOf(this.STATUS_PREFIX); | |
239 | - if ((pos == 0) && (rowData[col] == "Yes")) { | |
240 | - var tempStatus = col.substring(this.STATUS_PREFIX.length, col.length); | |
241 | - oldStatus.push(tempStatus); | |
242 | - } | |
243 | - } | |
244 | - | |
245 | - var defaultVal = rowNum - rowData["order"] + 1; | |
246 | - if (defaultVal < 0) { | |
247 | - defaultVal = 0; | |
248 | - } | |
249 | - | |
250 | - var operations; | |
251 | - for (ope in this.DEFAULT_OPERATIONS) { | |
252 | - if (rowData["operations"] == this.DEFAULT_OPERATIONS[ope]) { | |
253 | - operations = ope; | |
254 | - break; | |
255 | - } | |
256 | - } | |
257 | - | |
258 | - var permissions; | |
259 | - for (perm in this.DEFAULT_PERMISSIONS) { | |
260 | - if (rowData["permissions"] == this.DEFAULT_PERMISSIONS[perm]) { | |
261 | - permissions = perm; | |
262 | - break; | |
263 | - } | |
264 | - } | |
265 | - | |
266 | - workflow = {}; | |
267 | - workflow["action"] = action; | |
268 | - workflow["oldStatus"] = oldStatus.join(","); | |
269 | - workflow["newStatus"] = rowData["status"]; | |
270 | - workflow["name"] = rowData["name"]; | |
271 | - workflow["default"] = defaultVal; | |
272 | - workflow["operations"] = operations; | |
273 | - workflow["permissions"] = permissions; | |
274 | - | |
275 | - model[action] = workflow; | |
276 | - | |
277 | - var newStatus = workflow["newStatus"]; | |
278 | - if ((newStatus != "*") && ($.inArray(newStatus, status) < 0)) { | |
279 | - status.push(newStatus); | |
280 | - } | |
281 | - } | |
282 | - | |
283 | - workfloweditor.WorkflowContext.normalizeModel(model); | |
284 | - | |
285 | - this.model = model; | |
286 | - this.status = status; | |
287 | -} | |
288 | - | |
289 | -/** | |
290 | - * Normalize the workflow model. | |
291 | - * | |
1 | +var workfloweditor; | |
2 | +if (!workfloweditor) workfloweditor = {}; | |
3 | + | |
4 | +/** | |
5 | + * i18n | |
6 | + */ | |
7 | +workfloweditor.Localizer = function() { | |
8 | + this.strings = {}; | |
9 | + this.lang = ""; | |
10 | + | |
11 | + var htmlTag = document.getElementsByTagName("html")[0]; | |
12 | + this.lang = htmlTag.getAttribute("xml:lang") || htmlTag.getAttribute("lang"); | |
13 | + | |
14 | + // If there isn't the lang attribute, use browser language. | |
15 | + if (this.lang == null || this.lang == "") { | |
16 | + var currentLanguage; | |
17 | + if (navigator.browserLanguage) { | |
18 | + currentLanguage = navigator.browserLanguage; | |
19 | + } else if (navigator.language) { | |
20 | + currentLanguage = navigator.language; | |
21 | + } else if (navigator.userLanguage) { | |
22 | + currentLanguage = navigator.userLanguage; | |
23 | + } | |
24 | + | |
25 | + if (currentLanguage && currentLanguage.length >= 2) { | |
26 | + this.lang = currentLanguage.substr(0,2); | |
27 | + } | |
28 | + } | |
29 | + | |
30 | + var self = this; | |
31 | + this.getLocalizedString = function(str) { | |
32 | + if (!workfloweditor.Localizer.strings) | |
33 | + { | |
34 | + return str; | |
35 | + } | |
36 | + | |
37 | + var message = workfloweditor.Localizer.strings[str]; | |
38 | + if (!message || message == "") { | |
39 | + message = str; | |
40 | + } | |
41 | + return message; | |
42 | + }; | |
43 | + | |
44 | + return this; | |
45 | +} | |
46 | + | |
47 | +workfloweditor.Localizer = new workfloweditor.Localizer(); | |
48 | +_ = workfloweditor.Localizer.getLocalizedString; | |
49 | + | |
50 | +/** | |
51 | + * Workflow Editor onload action. | |
52 | + */ | |
53 | +jQuery(document).ready(function(){ | |
54 | + var context = new workfloweditor.WorkflowContext(); | |
55 | + | |
56 | + // display grid | |
57 | + context.updateModelByText("#workflowText"); | |
58 | + context.initGrid("#workflowGrid"); | |
59 | + context.initStatusGrid("#workflowStatusGrid"); | |
60 | + | |
61 | + // display tab layout | |
62 | + var tabsElem = $("#workflowTabs > ul").tabs(); | |
63 | + var currentTab = "gridTab"; | |
64 | + | |
65 | + tabsElem.tabs("select", 0); | |
66 | + $("#workflowTabs").bind("tabsselect", function(event, ui) { | |
67 | + currentTab = ui.panel.id; | |
68 | + | |
69 | + if (!ui.panel.id) { | |
70 | + // do nothing | |
71 | + } else if (ui.panel.id == "gridTab") { | |
72 | + context.updateModelByText("#workflowText"); | |
73 | + context.refreshGrid(); | |
74 | + } else if (ui.panel.id == "textTab") { | |
75 | + context.updateModelByGrid("#workflowGrid"); | |
76 | + context.refreshText(); | |
77 | + } else { | |
78 | + // do nothing | |
79 | + } | |
80 | + }); | |
81 | + | |
82 | + // Save button action | |
83 | + // The workflow is updated before saving. | |
84 | + jQuery("#doChanges").click( function() { | |
85 | + try | |
86 | + { | |
87 | + if (currentTab == "textTab") { | |
88 | + currentTab = tabsElem.tabs().data('selected.tabs') | |
89 | + if (currentTab == "1") { | |
90 | + context.updateModelByText("#workflowText"); | |
91 | + context.refreshGrid(); | |
92 | + } | |
93 | + } | |
94 | + | |
95 | + context.updateModelByGrid("#workflowGrid"); | |
96 | + context.refreshText(); | |
97 | + } | |
98 | + catch(ex) | |
99 | + { | |
100 | + alert(_("Error: Please fix the workflow text.") | |
101 | + + "\n(error code = " + ex.number + ")"); | |
102 | + return false; | |
103 | + } | |
104 | + }); | |
105 | + | |
106 | + $("#workflowTabs").show(); | |
107 | + | |
108 | +}); | |
109 | + | |
110 | +/** | |
111 | + * Workflow Editor | |
112 | + */ | |
113 | +workfloweditor.WorkflowContext = function() { | |
114 | + this.DEFAULT_OPERATIONS = { | |
115 | + "" : "", | |
116 | + "set_owner" : _("set owner"), | |
117 | + "del_owner" : _("del owner"), | |
118 | + "set_owner_to_self" : _("set owner to self"), | |
119 | + "set_resolution" : _("set resolution"), | |
120 | + "del_resolution" : _("del resolution"), | |
121 | + "leave_status" : _("leave status") | |
122 | + }; | |
123 | + this.DEFAULT_PERMISSIONS = { | |
124 | + "" : "", | |
125 | + "TICKET_VIEW" : "TICKET_VIEW", | |
126 | + "TICKET_CREATE" : "TICKET_CREATE", | |
127 | + "TICKET_MODIFY" : "TICKET_MODIFY", | |
128 | + "TICKET_ADMIN" : "TICKET_ADMIN" | |
129 | + }; | |
130 | + this.DEFAULT_STATUS = ["new", "assigned", "accepted", "reopened", "closed"]; | |
131 | + this.HIDDEN_COL = ["operations", "permissions"]; | |
132 | + this.STATUS_PREFIX = "status_"; | |
133 | + this.IMAGE_PATH = "../../chrome/workfloweditor/images"; | |
134 | + this.EDIT_URL = document.location + "/edit"; | |
135 | + | |
136 | + this.model = []; | |
137 | + this.status = [].concat(this.DEFAULT_STATUS); | |
138 | + | |
139 | + this.textId; | |
140 | + this.gridId; | |
141 | + this.statusGridId; | |
142 | +} | |
143 | + | |
144 | +/** | |
145 | + * The workflow text is converted to the workflow model. | |
146 | + * | |
147 | + * @param textId workflow textarea field ID | |
148 | + */ | |
149 | +workfloweditor.WorkflowContext.prototype.updateModelByText = function(textId) { | |
150 | + this.textId = textId; | |
151 | + | |
152 | + var text = $(textId).val(); | |
153 | + if (!text) { | |
154 | + return; | |
155 | + } | |
156 | + | |
157 | + var lines = text.split("\n"); | |
158 | + var model = []; | |
159 | + var status = this.status; | |
160 | + for (var index = 0; index < lines.length; index++) { | |
161 | + var line = lines[index]; | |
162 | + var pos = lines[index].indexOf("="); | |
163 | + var param = jQuery.trim(line.substring(0, pos)); | |
164 | + var value = jQuery.trim(line.substring(pos + 1, line.length)); | |
165 | + | |
166 | + // skip line | |
167 | + if (!param || param.length <= 0) { | |
168 | + continue; | |
169 | + } | |
170 | + | |
171 | + // parse workflow text | |
172 | + if (param.indexOf(".") < 0) { | |
173 | + // parse action | |
174 | + var action = param; | |
175 | + var elems = value.split("->"); | |
176 | + var oldStatus = jQuery.trim(elems[0]); | |
177 | + var newStatus = jQuery.trim(elems[1]); | |
178 | + | |
179 | + var workflow = model[action]; | |
180 | + if (!workflow) { | |
181 | + workflow = {}; | |
182 | + model[action] = workflow; | |
183 | + } | |
184 | + workflow["action"] = action; | |
185 | + workflow["oldStatus"] = oldStatus; | |
186 | + workflow["newStatus"] = newStatus; | |
187 | + | |
188 | + if ((newStatus != "*") && ($.inArray(newStatus, status) < 0)) { | |
189 | + status.push(newStatus); | |
190 | + } | |
191 | + } else { | |
192 | + // parse options | |
193 | + var elems = param.split("."); | |
194 | + var action = elems[0]; | |
195 | + var attribute = elems[1]; | |
196 | + | |
197 | + var workflow = model[action]; | |
198 | + if (!workflow) { | |
199 | + workflow = {}; | |
200 | + model[action] = workflow; | |
201 | + } | |
202 | + workflow[attribute] = value; | |
203 | + } | |
204 | + } | |
205 | + | |
206 | + workfloweditor.WorkflowContext.normalizeModel(model); | |
207 | + | |
208 | + this.model = model; | |
209 | + this.status = status; | |
210 | +} | |
211 | + | |
212 | +/** | |
213 | + * The workflow grid data is converted to the workflow model. | |
214 | + * | |
215 | + * @param gridId workflow grid ID. | |
216 | + */ | |
217 | +workfloweditor.WorkflowContext.prototype.updateModelByGrid = function(gridId) { | |
218 | + this.gridId = gridId; | |
219 | + | |
220 | + var dataIds = jQuery(gridId).getDataIDs(); | |
221 | + if (!dataIds || dataIds.length <= 0) { | |
222 | + return; | |
223 | + } | |
224 | + | |
225 | + var model = []; | |
226 | + var status = this.status; | |
227 | + var rowNum = dataIds.length; | |
228 | + for (var index = 0; index < rowNum; index++) { | |
229 | + var rowData = jQuery(gridId).getRowData(dataIds[index]); | |
230 | + var action = rowData["action"]; | |
231 | + | |
232 | + if (!action) { | |
233 | + continue; | |
234 | + } | |
235 | + | |
236 | + var oldStatus = []; | |
237 | + for (col in rowData) { | |
238 | + var pos = col.indexOf(this.STATUS_PREFIX); | |
239 | + if ((pos == 0) && (rowData[col] == "Yes")) { | |
240 | + var tempStatus = col.substring(this.STATUS_PREFIX.length, col.length); | |
241 | + oldStatus.push(tempStatus); | |
242 | + } | |
243 | + } | |
244 | + | |
245 | + var defaultVal = rowNum - rowData["order"] + 1; | |
246 | + if (defaultVal < 0) { | |
247 | + defaultVal = 0; | |
248 | + } | |
249 | + | |
250 | + var operations; | |
251 | + for (ope in this.DEFAULT_OPERATIONS) { | |
252 | + if (rowData["operations"] == this.DEFAULT_OPERATIONS[ope]) { | |
253 | + operations = ope; | |
254 | + break; | |
255 | + } | |
256 | + } | |
257 | + | |
258 | + var permissions; | |
259 | + for (perm in this.DEFAULT_PERMISSIONS) { | |
260 | + if (rowData["permissions"] == this.DEFAULT_PERMISSIONS[perm]) { | |
261 | + permissions = perm; | |
262 | + break; | |
263 | + } | |
264 | + } | |
265 | + | |
266 | + workflow = {}; | |
267 | + workflow["action"] = action; | |
268 | + workflow["oldStatus"] = oldStatus.join(","); | |
269 | + workflow["newStatus"] = rowData["status"]; | |
270 | + workflow["name"] = rowData["name"]; | |
271 | + workflow["default"] = defaultVal; | |
272 | + workflow["operations"] = operations; | |
273 | + workflow["permissions"] = permissions; | |
274 | + | |
275 | + model[action] = workflow; | |
276 | + | |
277 | + var newStatus = workflow["newStatus"]; | |
278 | + if ((newStatus != "*") && ($.inArray(newStatus, status) < 0)) { | |
279 | + status.push(newStatus); | |
280 | + } | |
281 | + } | |
282 | + | |
283 | + workfloweditor.WorkflowContext.normalizeModel(model); | |
284 | + | |
285 | + this.model = model; | |
286 | + this.status = status; | |
287 | +} | |
288 | + | |
289 | +/** | |
290 | + * Normalize the workflow model. | |
291 | + * | |
292 | 292 | * @param model workflow model |
293 | - */ | |
294 | -workfloweditor.WorkflowContext.normalizeModel = function(model) { | |
295 | - for (var action in model) { | |
296 | - var workflow = model[action]; | |
297 | - | |
298 | - // set the default value. | |
299 | - if (!workflow["name"]) { | |
300 | - workflow["name"] = action; | |
301 | - } | |
302 | - if (!workflow["default"]) { | |
303 | - workflow["default"] = 0; | |
304 | - } | |
305 | - if (!workflow["operations"]) { | |
306 | - workflow["operations"] = ""; | |
307 | - } | |
308 | - if (!workflow["permissions"]) { | |
309 | - workflow["permissions"] = ""; | |
310 | - } | |
311 | - | |
312 | - var oldStatus = workflow["oldStatus"].split(","); | |
313 | - for (var index = 0; index < oldStatus.length; index++) { | |
314 | - var tempStatus = jQuery.trim(oldStatus[index]); | |
315 | - oldStatus[index] = tempStatus; | |
316 | - } | |
317 | - workflow["oldStatus"] = oldStatus.join(","); | |
318 | - } | |
319 | -} | |
320 | - | |
321 | - | |
322 | -/** | |
323 | - * Refresh the grid. | |
324 | - * If this method is called, the workflow model must be updated. | |
325 | - */ | |
326 | -workfloweditor.WorkflowContext.prototype.refreshGrid = function() { | |
327 | - // remove the grid table and the grid edit layout. | |
328 | - jQuery(this.gridId).GridUnload(); | |
329 | - jQuery("#editmod" + this.gridId.replace("#", "")).remove(); | |
330 | - | |
331 | - this.initGrid(this.gridId); | |
332 | -} | |
333 | - | |
334 | -/** | |
335 | - * Refresh the text. | |
336 | - * If this method is called, the workflow model must be updated. | |
337 | - */ | |
338 | -workfloweditor.WorkflowContext.prototype.refreshText = function() { | |
339 | - var text = this.createWorkflowText(); | |
340 | - $(this.textId).val(text); | |
341 | -} | |
342 | - | |
343 | - | |
344 | -/** | |
345 | - * Initialize the workflow grid. | |
346 | - * | |
347 | - * @param gridId grid element ID | |
348 | - */ | |
349 | -workfloweditor.WorkflowContext.prototype.initGrid = function(gridId) { | |
350 | - var isFirst; | |
351 | - if (!this.gridId) { | |
352 | - isFirst = true; | |
353 | - } else { | |
354 | - isFirst = false; | |
355 | - } | |
356 | - | |
357 | - this.gridId = gridId; | |
358 | - | |
359 | - var colNames = this.createGridColNames(); | |
360 | - var colModel = this.createGridColModel(); | |
361 | - | |
362 | - jQuery(gridId).jqGrid({ | |
363 | - datatype : "local", | |
364 | - height : 200, | |
365 | - width : 750, | |
366 | - colNames : colNames, | |
367 | - colModel : colModel, | |
368 | - shrinkToFit : false, | |
369 | - imgpath : this.IMAGE_PATH, | |
370 | - editurl : this.EDIT_URL | |
371 | - }); | |
372 | - | |
373 | - var gridData = this.createGridData(); | |
374 | - for(var index = 0; index < gridData.length; index++) { | |
375 | - jQuery(gridId).addRowData(index + 1, gridData[index]); | |
376 | - } | |
377 | - | |
378 | - jQuery(gridId).sortGrid("order", false); | |
379 | - | |
380 | - if (isFirst) { | |
381 | - var self = this; | |
382 | - var showGridCol = function() { | |
383 | - jQuery(gridId).showCol(self.HIDDEN_COL); | |
384 | - } | |
385 | - var hideGridCol = function() { | |
386 | - $("#pData").hide(); | |
387 | - $("#nData").hide(); | |
388 | - jQuery(gridId).hideCol(self.HIDDEN_COL); | |
389 | - } | |
390 | - | |
391 | - // add action setting | |
392 | - $(gridId + "ItemAdd").click(function(){ | |
393 | - jQuery(gridId).editGridRow( | |
394 | - "new", | |
395 | - { | |
396 | - top : 50, | |
397 | - left : 200, | |
398 | - height : 400, | |
399 | - width : 300, | |
400 | - mtype : "GET", | |
401 | - closeAfterAdd : true, | |
402 | - reloadAfterSubmit : false, | |
403 | - beforeInitData : showGridCol, | |
404 | - afterShowForm : hideGridCol | |
405 | - } | |
406 | - ); | |
407 | - }); | |
408 | - | |
409 | - // modify action setting | |
410 | - $(gridId + "ItemMod").click(function(){ | |
411 | - var gr = jQuery(gridId).getGridParam("selrow"); | |
412 | - if( gr != null ) { | |
413 | - jQuery(gridId).editGridRow( | |
414 | - gr, | |
415 | - { | |
416 | - top : 50, | |
417 | - left : 200, | |
418 | - height : 400, | |
419 | - width : 300, | |
420 | - mtype : "GET", | |
421 | - closeAfterEdit : true, | |
422 | - reloadAfterSubmit : false, | |
423 | - beforeInitData : showGridCol, | |
424 | - afterShowForm : hideGridCol | |
425 | - } | |
426 | - ); | |
427 | - } else { | |
428 | - alert(_("Please select row.")); | |
429 | - } | |
430 | - }); | |
431 | - | |
432 | - // delete action setting | |
433 | - $(gridId + "ItemDel").click(function(){ | |
434 | - var gr = jQuery(gridId).getGridParam("selrow"); | |
435 | - if( gr != null ) { | |
436 | - jQuery(gridId).delGridRow( | |
437 | - gr, | |
438 | - { | |
439 | - top : 50, | |
440 | - left : 200, | |
441 | - mtype : "GET", | |
442 | - closeAfterEdit : true, | |
443 | - reloadAfterSubmit : false | |
444 | - } | |
445 | - ); | |
446 | - } else { | |
447 | - alert(_("Please select row.")); | |
448 | - } | |
449 | - }); | |
450 | - | |
451 | - } // isFirst end | |
452 | -} | |
453 | - | |
454 | -/** | |
455 | - * Create the array of the grid column name. | |
456 | - * | |
457 | - * @param colNames the array of the grid column name | |
458 | - */ | |
459 | -workfloweditor.WorkflowContext.prototype.createGridColNames = function() { | |
460 | - // for IE6 | |
461 | - // Localization function isn't initialized in the local function. | |
462 | - if (!_) { | |
463 | - _ = workfloweditor.Localizer.getLocalizedString; | |
464 | - } | |
465 | - | |
466 | - var colNames = [_('action'), _('name'), _('operation'), _('permission'), _('order'), _('next status'), '']; | |
467 | - colNames = colNames.concat(this.status); | |
468 | - | |
469 | - return colNames; | |
470 | -} | |
471 | - | |
472 | -/** | |
473 | - * Create the array of the grid column model. | |
474 | - * | |
475 | - * @param colModel the array of the grid column model | |
476 | - */ | |
477 | -workfloweditor.WorkflowContext.prototype.createGridColModel = function() { | |
478 | - var statusValue = "*:*;"; | |
479 | - for (var index = 0; index < this.status.length; index++) { | |
480 | - statusValue += this.status[index] + ":" + this.status[index] + ";"; | |
481 | - } | |
482 | - statusValue = statusValue.substring(0, statusValue.length - 1); | |
483 | - | |
484 | - var opeValue = ""; | |
485 | - for (ope in this.DEFAULT_OPERATIONS) { | |
486 | - opeValue += ope + ":" + this.DEFAULT_OPERATIONS[ope] + ";"; | |
487 | - } | |
488 | - opeValue = opeValue.substring(0, opeValue.length - 1); | |
489 | - | |
490 | - var permValue = ""; | |
491 | - for (perm in this.DEFAULT_PERMISSIONS) { | |
492 | - permValue += perm + ":" + this.DEFAULT_PERMISSIONS[perm] + ";"; | |
493 | - } | |
494 | - permValue = permValue.substring(0, permValue.length - 1); | |
495 | - | |
496 | - var colModel = [ | |
497 | - {name:'action', index:'action', width:75, editable:true, editrules:{required:true, edithidden:false}}, | |
498 | - {name:'name', index:'name', width:100, editable:true, editrules:{required:true}}, | |
499 | - {name:'operations', index:'operations', width:100, editable:true, edittype:"select", editoptions:{value:opeValue}, hidden:true}, | |
500 | - {name:'permissions', index:'permissions', width:100, editable:true, edittype:"select", editoptions:{value:permValue}, hidden:true}, | |
501 | - {name:'order', index:'order', width:45, editable:true, align:"right", sorttype:"int", editrules:{integer:true}}, | |
502 | - {name:'status', index:'status', width:100, editable:true, edittype:"select", editoptions:{value:statusValue}}, | |
503 | - {name:'blank', index:'blank', width:22, editable:false, align:"center"} | |
504 | - ]; | |
505 | - | |
506 | - for (var index = 0; index < this.status.length; index++) { | |
507 | - var statusColModel = { | |
508 | - name : this.STATUS_PREFIX + this.status[index], | |
509 | - index : this.STATUS_PREFIX + this.status[index], | |
510 | - width : 75, | |
511 | - editable : true, | |
512 | - align : "center", | |
513 | - edittype : "checkbox", | |
514 | - editoptions : {value:"Yes:No"} | |
515 | - }; | |
516 | - | |
517 | - colModel.push(statusColModel); | |
518 | - } | |
519 | - | |
520 | - return colModel; | |
521 | -} | |
522 | - | |
523 | -/** | |
524 | - * Create the grid data from the workflow model. | |
525 | - * | |
526 | - * @return grid data | |
527 | - */ | |
528 | -workfloweditor.WorkflowContext.prototype.createGridData = function() { | |
529 | - var model = this.model; | |
530 | - var status = this.status; | |
531 | - | |
532 | - var modelSize = 0; | |
533 | - for (var key in model) { | |
534 | - modelSize++; | |
535 | - } | |
536 | - | |
537 | - var gridData = []; | |
538 | - for (var action in model) { | |
539 | - var workflow = model[action]; | |
540 | - var rowData = {}; | |
541 | - | |
542 | - var operations; | |
543 | - if (this.DEFAULT_OPERATIONS[workflow["operations"]]) { | |
544 | - operations = this.DEFAULT_OPERATIONS[workflow["operations"]]; | |
545 | - } else { | |
546 | - operations = ""; | |
547 | - } | |
548 | - | |
549 | - var permissions; | |
550 | - if (this.DEFAULT_PERMISSIONS[workflow["permissions"]]) { | |
551 | - permissions = this.DEFAULT_PERMISSIONS[workflow["permissions"]]; | |
552 | - } else { | |
553 | - permissions = ""; | |
554 | - } | |
555 | - | |
556 | - rowData["action"] = workflow["action"]; | |
557 | - rowData["name"] = workflow["name"]; | |
558 | - rowData["status"] = workflow["newStatus"]; | |
559 | - rowData["operations"] = operations; | |
560 | - rowData["permissions"] = permissions; | |
561 | - rowData["order"] = modelSize - workflow["default"] + 1; | |
562 | - rowData["blank"] = "<--"; | |
563 | - | |
564 | - var oldStatus = workflow["oldStatus"] + ","; | |
565 | - for (var index = 0; index < status.length; index++) { | |
566 | - var tempStatus = status[index]; | |
567 | - var match; | |
568 | - if ((oldStatus == "*,") || (oldStatus.indexOf(tempStatus + ",") >= 0)) { | |
569 | - match = "Yes"; | |
570 | - } else { | |
571 | - match = "No"; | |
572 | - } | |
573 | - rowData[this.STATUS_PREFIX + tempStatus] = match; | |
574 | - } | |
575 | - | |
576 | - gridData.push(rowData); | |
577 | - } | |
578 | - | |
579 | - return gridData; | |
580 | -} | |
581 | - | |
582 | -/** | |
583 | - * Initialize the status grid. | |
584 | - * | |
585 | - * @param gridId status grid element ID | |
586 | - */ | |
587 | -workfloweditor.WorkflowContext.prototype.initStatusGrid = function(statusGridId) { | |
588 | - var isFirst; | |
589 | - if (!this.statusGridId) { | |
590 | - isFirst = true; | |
591 | - } else { | |
592 | - isFirst = false; | |
593 | - } | |
594 | - | |
595 | - this.statusGridId = statusGridId; | |
596 | - | |
597 | - jQuery(statusGridId).hide(); | |
598 | - | |
599 | - jQuery(statusGridId).jqGrid({ | |
600 | - datatype : "local", | |
601 | - height : 0, | |
602 | - width : 0, | |
603 | - colNames : [_("status")], | |
604 | - colModel : [{ | |
605 | - name:'editableStatus', index:'status', width:100, editable:true, | |
606 | - edittype:"textarea", editrules:{required:true}, editoptions: {rows:"10",cols:"15"}, | |
607 | - hidden:true | |
608 | - }], | |
609 | - imgpath : this.IMAGE_PATH, | |
610 | - editurl : this.EDIT_URL, | |
611 | - loadui : "disable" | |
612 | - }); | |
613 | - | |
614 | - jQuery(statusGridId).addRowData(1, {editableStatus : this.status.join(" ")}); | |
615 | - | |
616 | - if (isFirst) { | |
617 | - var self = this; | |
618 | - var showGridCol = function() { | |
619 | - jQuery(statusGridId).showCol(["editableStatus"]); | |
620 | - } | |
621 | - var dataSplit = function() { | |
622 | - $("#pData").hide(); | |
623 | - $("#nData").hide(); | |
624 | - var statusValue = $("#editableStatus").val(); | |
625 | - statusValue = statusValue.replace(/ /g, "\n"); | |
626 | - $("#editableStatus").val(statusValue); | |
627 | - jQuery(statusGridId).hideCol(["editableStatus"]); | |
628 | - } | |
629 | - var updateStatus = function() { | |
630 | - var statusValue = $("#editableStatus").val(); | |
631 | - var statusArray = statusValue.split("\n"); | |
632 | - | |
633 | - // update status | |
634 | - self.status = []; | |
635 | - for (var index = 0; index < statusArray.length; index++) { | |
636 | - var tempStatus = jQuery.trim(statusArray[index]); | |
637 | - if (tempStatus.length > 0) { | |
638 | - self.status.push(tempStatus); | |
639 | - } | |
640 | - } | |
641 | - | |
642 | - self.updateModelByGrid(self.gridId); | |
643 | - self.refreshGrid(); | |
644 | - } | |
645 | - | |
646 | - // modify action setting | |
647 | - $(statusGridId + "ItemMod").click(function(){ | |
648 | - jQuery(statusGridId).editGridRow( | |
649 | - 1, | |
650 | - { | |
651 | - top : 50, | |
652 | - left : 200, | |
653 | - height : 250, | |
654 | - width : 350, | |
655 | - mtype : "GET", | |
656 | - closeAfterEdit : true, | |
657 | - reloadAfterSubmit : false, | |
658 | - beforeInitData : showGridCol, | |
659 | - afterShowForm : dataSplit, | |
660 | - onclickSubmit : updateStatus | |
661 | - } | |
662 | - ); | |
663 | - }); | |
664 | - | |
665 | - } // isFirst end | |
666 | -} | |
667 | - | |
668 | -/** | |
669 | - * Create the workflow text from the workflow model. | |
670 | - */ | |
671 | -workfloweditor.WorkflowContext.prototype.createWorkflowText = function() { | |
672 | - | |
673 | - var textArray = []; | |
674 | - for (var action in this.model) { | |
675 | - | |
676 | - var workflow = this.model[action]; | |
677 | - | |
678 | - if (!workflow) { | |
679 | - continue; | |
680 | - } | |
681 | - | |
682 | - var operations = workflow["operations"]; | |
683 | - var permissions = workflow["permissions"]; | |
684 | - | |
685 | - // create each workflow define. | |
686 | - textArray.push(action + " = " + workflow["oldStatus"] + " -> " + workflow["newStatus"]); | |
687 | - textArray.push(action + ".name = " + workflow["name"]); | |
688 | - textArray.push(action + ".default = " + workflow["default"]); | |
689 | - if (operations && operations.length > 0) { | |
690 | - textArray.push(action + ".operations = " + operations); | |
691 | - } | |
692 | - if (permissions && permissions.length > 0) { | |
693 | - textArray.push(action + ".permissions = " + permissions); | |
694 | - } | |
695 | - } | |
696 | - | |
697 | - var text = textArray.join("\n"); | |
698 | - return text; | |
699 | -} | |
700 | - | |
293 | + */ | |
294 | +workfloweditor.WorkflowContext.normalizeModel = function(model) { | |
295 | + for (var action in model) { | |
296 | + var workflow = model[action]; | |
297 | + | |
298 | + // set the default value. | |
299 | + if (!workflow["name"]) { | |
300 | + workflow["name"] = action; | |
301 | + } | |
302 | + if (!workflow["default"]) { | |
303 | + workflow["default"] = 0; | |
304 | + } | |
305 | + if (!workflow["operations"]) { | |
306 | + workflow["operations"] = ""; | |
307 | + } | |
308 | + if (!workflow["permissions"]) { | |
309 | + workflow["permissions"] = ""; | |
310 | + } | |
311 | + | |
312 | + var oldStatus = workflow["oldStatus"].split(","); | |
313 | + for (var index = 0; index < oldStatus.length; index++) { | |
314 | + var tempStatus = jQuery.trim(oldStatus[index]); | |
315 | + oldStatus[index] = tempStatus; | |
316 | + } | |
317 | + workflow["oldStatus"] = oldStatus.join(","); | |
318 | + } | |
319 | +} | |
320 | + | |
321 | + | |
322 | +/** | |
323 | + * Refresh the grid. | |
324 | + * If this method is called, the workflow model must be updated. | |
325 | + */ | |
326 | +workfloweditor.WorkflowContext.prototype.refreshGrid = function() { | |
327 | + // remove the grid table and the grid edit layout. | |
328 | + jQuery(this.gridId).GridUnload(); | |
329 | + jQuery("#editmod" + this.gridId.replace("#", "")).remove(); | |
330 | + | |
331 | + this.initGrid(this.gridId); | |
332 | +} | |
333 | + | |
334 | +/** | |
335 | + * Refresh the text. | |
336 | + * If this method is called, the workflow model must be updated. | |
337 | + */ | |
338 | +workfloweditor.WorkflowContext.prototype.refreshText = function() { | |
339 | + var text = this.createWorkflowText(); | |
340 | + $(this.textId).val(text); | |
341 | +} | |
342 | + | |
343 | + | |
344 | +/** | |
345 | + * Initialize the workflow grid. | |
346 | + * | |
347 | + * @param gridId grid element ID | |
348 | + */ | |
349 | +workfloweditor.WorkflowContext.prototype.initGrid = function(gridId) { | |
350 | + var isFirst; | |
351 | + if (!this.gridId) { | |
352 | + isFirst = true; | |
353 | + } else { | |
354 | + isFirst = false; | |
355 | + } | |
356 | + | |
357 | + this.gridId = gridId; | |
358 | + | |
359 | + var colNames = this.createGridColNames(); | |
360 | + var colModel = this.createGridColModel(); | |
361 | + | |
362 | + jQuery(gridId).jqGrid({ | |
363 | + datatype : "local", | |
364 | + height : 200, | |
365 | + width : 750, | |
366 | + colNames : colNames, | |
367 | + colModel : colModel, | |
368 | + shrinkToFit : false, | |
369 | + imgpath : this.IMAGE_PATH, | |
370 | + editurl : this.EDIT_URL | |
371 | + }); | |
372 | + | |
373 | + var gridData = this.createGridData(); | |
374 | + for(var index = 0; index < gridData.length; index++) { | |
375 | + jQuery(gridId).addRowData(index + 1, gridData[index]); | |
376 | + } | |
377 | + | |
378 | + jQuery(gridId).sortGrid("order", false); | |
379 | + | |
380 | + if (isFirst) { | |
381 | + var self = this; | |
382 | + var showGridCol = function() { | |
383 | + jQuery(gridId).showCol(self.HIDDEN_COL); | |
384 | + } | |
385 | + var hideGridCol = function() { | |
386 | + $("#pData").hide(); | |
387 | + $("#nData").hide(); | |
388 | + jQuery(gridId).hideCol(self.HIDDEN_COL); | |
389 | + } | |
390 | + | |
391 | + // add action setting | |
392 | + $(gridId + "ItemAdd").click(function(){ | |
393 | + jQuery(gridId).editGridRow( | |
394 | + "new", | |
395 | + { | |
396 | + top : 50, | |
397 | + left : 200, | |
398 | + height : 400, | |
399 | + width : 300, | |
400 | + mtype : "GET", | |
401 | + closeAfterAdd : true, | |
402 | + reloadAfterSubmit : false, | |
403 | + beforeInitData : showGridCol, | |
404 | + afterShowForm : hideGridCol | |
405 | + } | |
406 | + ); | |
407 | + }); | |
408 | + | |
409 | + // modify action setting | |
410 | + $(gridId + "ItemMod").click(function(){ | |
411 | + var gr = jQuery(gridId).getGridParam("selrow"); | |
412 | + if( gr != null ) { | |
413 | + jQuery(gridId).editGridRow( | |
414 | + gr, | |
415 | + { | |
416 | + top : 50, | |
417 | + left : 200, | |
418 | + height : 400, | |
419 | + width : 300, | |
420 | + mtype : "GET", | |
421 | + closeAfterEdit : true, | |
422 | + reloadAfterSubmit : false, | |
423 | + beforeInitData : showGridCol, | |
424 | + afterShowForm : hideGridCol | |
425 | + } | |
426 | + ); | |
427 | + } else { | |
428 | + alert(_("Please select row.")); | |
429 | + } | |
430 | + }); | |
431 | + | |
432 | + // delete action setting | |
433 | + $(gridId + "ItemDel").click(function(){ | |
434 | + var gr = jQuery(gridId).getGridParam("selrow"); | |
435 | + if( gr != null ) { | |
436 | + jQuery(gridId).delGridRow( | |
437 | + gr, | |
438 | + { | |
439 | + top : 50, | |
440 | + left : 200, | |
441 | + mtype : "GET", | |
442 | + closeAfterEdit : true, | |
443 | + reloadAfterSubmit : false | |
444 | + } | |
445 | + ); | |
446 | + } else { | |
447 | + alert(_("Please select row.")); | |
448 | + } | |
449 | + }); | |
450 | + | |
451 | + } // isFirst end | |
452 | +} | |
453 | + | |
454 | +/** | |
455 | + * Create the array of the grid column name. | |
456 | + * | |
457 | + * @param colNames the array of the grid column name | |
458 | + */ | |
459 | +workfloweditor.WorkflowContext.prototype.createGridColNames = function() { | |
460 | + // for IE6 | |
461 | + // Localization function isn't initialized in the local function. | |
462 | + if (!_) { | |
463 | + _ = workfloweditor.Localizer.getLocalizedString; | |
464 | + } | |
465 | + | |
466 | + var colNames = [_('action'), _('name'), _('operation'), _('permission'), _('order'), _('next status'), '']; | |
467 | + colNames = colNames.concat(this.status); | |
468 | + | |
469 | + return colNames; | |
470 | +} | |
471 | + | |
472 | +/** | |
473 | + * Create the array of the grid column model. | |
474 | + * | |
475 | + * @param colModel the array of the grid column model | |
476 | + */ | |
477 | +workfloweditor.WorkflowContext.prototype.createGridColModel = function() { | |
478 | + var statusValue = "*:*;"; | |
479 | + for (var index = 0; index < this.status.length; index++) { | |
480 | + statusValue += this.status[index] + ":" + this.status[index] + ";"; | |
481 | + } | |
482 | + statusValue = statusValue.substring(0, statusValue.length - 1); | |
483 | + | |
484 | + var opeValue = ""; | |
485 | + for (ope in this.DEFAULT_OPERATIONS) { | |
486 | + opeValue += ope + ":" + this.DEFAULT_OPERATIONS[ope] + ";"; | |
487 | + } | |
488 | + opeValue = opeValue.substring(0, opeValue.length - 1); | |
489 | + | |
490 | + var permValue = ""; | |
491 | + for (perm in this.DEFAULT_PERMISSIONS) { | |
492 | + permValue += perm + ":" + this.DEFAULT_PERMISSIONS[perm] + ";"; | |
493 | + } | |
494 | + permValue = permValue.substring(0, permValue.length - 1); | |
495 | + | |
496 | + var colModel = [ | |
497 | + {name:'action', index:'action', width:75, editable:true, editrules:{required:true, edithidden:false}}, | |
498 | + {name:'name', index:'name', width:100, editable:true, editrules:{required:true}}, | |
499 | + {name:'operations', index:'operations', width:100, editable:true, edittype:"select", editoptions:{value:opeValue}, hidden:true}, | |
500 | + {name:'permissions', index:'permissions', width:100, editable:true, edittype:"select", editoptions:{value:permValue}, hidden:true}, | |
501 | + {name:'order', index:'order', width:45, editable:true, align:"right", sorttype:"int", editrules:{integer:true}}, | |
502 | + {name:'status', index:'status', width:100, editable:true, edittype:"select", editoptions:{value:statusValue}}, | |
503 | + {name:'blank', index:'blank', width:22, editable:false, align:"center"} | |
504 | + ]; | |
505 | + | |
506 | + for (var index = 0; index < this.status.length; index++) { | |
507 | + var statusColModel = { | |
508 | + name : this.STATUS_PREFIX + this.status[index], | |
509 | + index : this.STATUS_PREFIX + this.status[index], | |
510 | + width : 75, | |
511 | + editable : true, | |
512 | + align : "center", | |
513 | + edittype : "checkbox", | |
514 | + editoptions : {value:"Yes:No"} | |
515 | + }; | |
516 | + | |
517 | + colModel.push(statusColModel); | |
518 | + } | |
519 | + | |
520 | + return colModel; | |
521 | +} | |
522 | + | |
523 | +/** | |
524 | + * Create the grid data from the workflow model. | |
525 | + * | |
526 | + * @return grid data | |
527 | + */ | |
528 | +workfloweditor.WorkflowContext.prototype.createGridData = function() { | |
529 | + var model = this.model; | |
530 | + var status = this.status; | |
531 | + | |
532 | + var modelSize = 0; | |
533 | + for (var key in model) { | |
534 | + modelSize++; | |
535 | + } | |
536 | + | |
537 | + var gridData = []; | |
538 | + for (var action in model) { | |
539 | + var workflow = model[action]; | |
540 | + var rowData = {}; | |
541 | + | |
542 | + var operations; | |
543 | + if (this.DEFAULT_OPERATIONS[workflow["operations"]]) { | |
544 | + operations = this.DEFAULT_OPERATIONS[workflow["operations"]]; | |
545 | + } else { | |
546 | + operations = ""; | |
547 | + } | |
548 | + | |
549 | + var permissions; | |
550 | + if (this.DEFAULT_PERMISSIONS[workflow["permissions"]]) { | |
551 | + permissions = this.DEFAULT_PERMISSIONS[workflow["permissions"]]; | |
552 | + } else { | |
553 | + permissions = ""; | |
554 | + } | |
555 | + | |
556 | + rowData["action"] = workflow["action"]; | |
557 | + rowData["name"] = workflow["name"]; | |
558 | + rowData["status"] = workflow["newStatus"]; | |
559 | + rowData["operations"] = operations; | |
560 | + rowData["permissions"] = permissions; | |
561 | + rowData["order"] = modelSize - workflow["default"] + 1; | |
562 | + rowData["blank"] = "<--"; | |
563 | + | |
564 | + var oldStatus = workflow["oldStatus"] + ","; | |
565 | + for (var index = 0; index < status.length; index++) { | |
566 | + var tempStatus = status[index]; | |
567 | + var match; | |
568 | + if ((oldStatus == "*,") || (oldStatus.indexOf(tempStatus + ",") >= 0)) { | |
569 | + match = "Yes"; | |
570 | + } else { | |
571 | + match = "No"; | |
572 | + } | |
573 | + rowData[this.STATUS_PREFIX + tempStatus] = match; | |
574 | + } | |
575 | + | |
576 | + gridData.push(rowData); | |
577 | + } | |
578 | + | |
579 | + return gridData; | |
580 | +} | |
581 | + | |
582 | +/** | |
583 | + * Initialize the status grid. | |
584 | + * | |
585 | + * @param gridId status grid element ID | |
586 | + */ | |
587 | +workfloweditor.WorkflowContext.prototype.initStatusGrid = function(statusGridId) { | |
588 | + var isFirst; | |
589 | + if (!this.statusGridId) { | |
590 | + isFirst = true; | |
591 | + } else { | |
592 | + isFirst = false; | |
593 | + } | |
594 | + | |
595 | + this.statusGridId = statusGridId; | |
596 | + | |
597 | + jQuery(statusGridId).hide(); | |
598 | + | |
599 | + jQuery(statusGridId).jqGrid({ | |
600 | + datatype : "local", | |
601 | + height : 0, | |
602 | + width : 0, | |
603 | + colNames : [_("status")], | |
604 | + colModel : [{ | |
605 | + name:'editableStatus', index:'status', width:100, editable:true, | |
606 | + edittype:"textarea", editrules:{required:true}, editoptions: {rows:"10",cols:"15"}, | |
607 | + hidden:true | |
608 | + }], | |
609 | + imgpath : this.IMAGE_PATH, | |
610 | + editurl : this.EDIT_URL, | |
611 | + loadui : "disable" | |
612 | + }); | |
613 | + | |
614 | + jQuery(statusGridId).addRowData(1, {editableStatus : this.status.join(" ")}); | |
615 | + | |
616 | + if (isFirst) { | |
617 | + var self = this; | |
618 | + var showGridCol = function() { | |
619 | + jQuery(statusGridId).showCol(["editableStatus"]); | |
620 | + } | |
621 | + var dataSplit = function() { | |
622 | + $("#pData").hide(); | |
623 | + $("#nData").hide(); | |
624 | + var statusValue = $("#editableStatus").val(); | |
625 | + statusValue = statusValue.replace(/ /g, "\n"); | |
626 | + $("#editableStatus").val(statusValue); | |
627 | + jQuery(statusGridId).hideCol(["editableStatus"]); | |
628 | + } | |
629 | + var updateStatus = function() { | |
630 | + var statusValue = $("#editableStatus").val(); | |
631 | + var statusArray = statusValue.split("\n"); | |
632 | + | |
633 | + // update status | |
634 | + self.status = []; | |
635 | + for (var index = 0; index < statusArray.length; index++) { | |
636 | + var tempStatus = jQuery.trim(statusArray[index]); | |
637 | + if (tempStatus.length > 0) { | |
638 | + self.status.push(tempStatus); | |
639 | + } | |
640 | + } | |
641 | + | |
642 | + self.updateModelByGrid(self.gridId); | |
643 | + self.refreshGrid(); | |
644 | + } | |
645 | + | |
646 | + // modify action setting | |
647 | + $(statusGridId + "ItemMod").click(function(){ | |
648 | + jQuery(statusGridId).editGridRow( | |
649 | + 1, | |
650 | + { | |
651 | + top : 50, | |
652 | + left : 200, | |
653 | + height : 250, | |
654 | + width : 350, | |
655 | + mtype : "GET", | |
656 | + closeAfterEdit : true, | |
657 | + reloadAfterSubmit : false, | |
658 | + beforeInitData : showGridCol, | |
659 | + afterShowForm : dataSplit, | |
660 | + onclickSubmit : updateStatus | |
661 | + } | |
662 | + ); | |
663 | + }); | |
664 | + | |
665 | + } // isFirst end | |
666 | +} | |
667 | + | |
668 | +/** | |
669 | + * Create the workflow text from the workflow model. | |
670 | + */ | |
671 | +workfloweditor.WorkflowContext.prototype.createWorkflowText = function() { | |
672 | + | |
673 | + var textArray = []; | |
674 | + for (var action in this.model) { | |
675 | + | |
676 | + var workflow = this.model[action]; | |
677 | + | |
678 | + if (!workflow) { | |
679 | + continue; | |
680 | + } | |
681 | + | |
682 | + var operations = workflow["operations"]; | |
683 | + var permissions = workflow["permissions"]; | |
684 | + | |
685 | + // create each workflow define. | |
686 | + textArray.push(action + " = " + workflow["oldStatus"] + " -> " + workflow["newStatus"]); | |
687 | + textArray.push(action + ".name = " + workflow["name"]); | |
688 | + textArray.push(action + ".default = " + workflow["default"]); | |
689 | + if (operations && operations.length > 0) { | |
690 | + textArray.push(action + ".operations = " + operations); | |
691 | + } | |
692 | + if (permissions && permissions.length > 0) { | |
693 | + textArray.push(action + ".permissions = " + permissions); | |
694 | + } | |
695 | + } | |
696 | + | |
697 | + var text = textArray.join("\n"); | |
698 | + return text; | |
699 | +} | |
700 | + |
@@ -38,7 +38,18 @@ | ||
38 | 38 | # IAdminPanelProvider method |
39 | 39 | def render_admin_panel(self, req, cat, page, path_info): |
40 | 40 | req.perm.assert_permission('TRAC_ADMIN') |
41 | - add_script(req, 'workfloweditor/js/jquery.jqGrid.js') | |
41 | + add_script(req, 'workfloweditor/js/grid/grid.locale-en.js') | |
42 | + add_script(req, 'workfloweditor/js/grid/grid.base.js') | |
43 | + add_script(req, 'workfloweditor/js/grid/grid.common.js') | |
44 | + add_script(req, 'workfloweditor/js/grid/grid.formedit.js') | |
45 | + add_script(req, 'workfloweditor/js/grid/grid.inlinedit.js') | |
46 | + add_script(req, 'workfloweditor/js/grid/grid.celledit.js') | |
47 | + add_script(req, 'workfloweditor/js/grid/grid.subgrid.js') | |
48 | + add_script(req, 'workfloweditor/js/grid/grid.treegrid.js') | |
49 | + add_script(req, 'workfloweditor/js/grid/grid.custom.js') | |
50 | + add_script(req, 'workfloweditor/js/grid/grid.postext.js') | |
51 | + add_script(req, 'workfloweditor/js/grid/grid.tbltogrid.js') | |
52 | + add_script(req, 'workfloweditor/js/grid/grid.setcolumns.js') | |
42 | 53 | add_script(req, 'workfloweditor/js/grid/jqModal.js') |
43 | 54 | add_script(req, 'workfloweditor/js/grid/jqDnR.js') |
44 | 55 | add_script(req, 'workfloweditor/js/grid/jquery.tablednd.js') |