rails_jq_grid 0.0.3.pre2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/VERSION +1 -1
  2. data/public/javascripts/rails-jqgrid/Changes.txt +0 -0
  3. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg.js +132 -1
  4. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg1251.js +132 -1
  5. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cat.js +128 -1
  6. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cn.js +132 -1
  7. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cs.js +128 -1
  8. data/public/javascripts/rails-jqgrid/i18n/grid.locale-da.js +128 -0
  9. data/public/javascripts/rails-jqgrid/i18n/grid.locale-de.js +133 -1
  10. data/public/javascripts/rails-jqgrid/i18n/grid.locale-el.js +126 -1
  11. data/public/javascripts/rails-jqgrid/i18n/grid.locale-en.js +128 -1
  12. data/public/javascripts/rails-jqgrid/i18n/grid.locale-es.js +128 -1
  13. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fa.js +145 -1
  14. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fi.js +130 -1
  15. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fr.js +126 -1
  16. data/public/javascripts/rails-jqgrid/i18n/grid.locale-gl.js +126 -0
  17. data/public/javascripts/rails-jqgrid/i18n/grid.locale-he.js +127 -1
  18. data/public/javascripts/rails-jqgrid/i18n/grid.locale-hu.js +129 -1
  19. data/public/javascripts/rails-jqgrid/i18n/grid.locale-is.js +126 -1
  20. data/public/javascripts/rails-jqgrid/i18n/grid.locale-it.js +1 -1
  21. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ja.js +155 -1
  22. data/public/javascripts/rails-jqgrid/i18n/grid.locale-nl.js +149 -1
  23. data/public/javascripts/rails-jqgrid/i18n/grid.locale-no.js +1 -1
  24. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pl.js +127 -1
  25. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt-br.js +127 -1
  26. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt.js +125 -1
  27. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ro.js +139 -1
  28. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ru.js +127 -1
  29. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sk.js +127 -1
  30. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sr.js +128 -0
  31. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sv.js +127 -1
  32. data/public/javascripts/rails-jqgrid/i18n/grid.locale-tr.js +126 -1
  33. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ua.js +127 -1
  34. data/public/javascripts/rails-jqgrid/install.txt +0 -0
  35. data/public/javascripts/rails-jqgrid/jquery.jqGrid.min.js +445 -432
  36. data/public/javascripts/rails-jqgrid/src/JsonXml.js +329 -329
  37. data/public/javascripts/rails-jqgrid/src/css/ellipsis-xbl.xml +0 -0
  38. data/public/javascripts/rails-jqgrid/src/css/ui.jqgrid.css +139 -129
  39. data/public/javascripts/rails-jqgrid/src/css/ui.multiselect.css +0 -0
  40. data/public/javascripts/rails-jqgrid/src/grid.base.js +3078 -3003
  41. data/public/javascripts/rails-jqgrid/src/grid.celledit.js +486 -486
  42. data/public/javascripts/rails-jqgrid/src/grid.common.js +646 -636
  43. data/public/javascripts/rails-jqgrid/src/grid.custom.js +820 -817
  44. data/public/javascripts/rails-jqgrid/src/grid.formedit.js +1954 -1872
  45. data/public/javascripts/rails-jqgrid/src/grid.grouping.js +250 -0
  46. data/public/javascripts/rails-jqgrid/src/grid.import.js +200 -200
  47. data/public/javascripts/rails-jqgrid/src/grid.inlinedit.js +255 -250
  48. data/public/javascripts/rails-jqgrid/src/grid.jqueryui.js +504 -503
  49. data/public/javascripts/rails-jqgrid/src/grid.loader.js +1 -0
  50. data/public/javascripts/rails-jqgrid/src/grid.postext.js +63 -63
  51. data/public/javascripts/rails-jqgrid/src/grid.setcolumns.js +125 -125
  52. data/public/javascripts/rails-jqgrid/src/grid.subgrid.js +260 -260
  53. data/public/javascripts/rails-jqgrid/src/grid.tbltogrid.js +106 -106
  54. data/public/javascripts/rails-jqgrid/src/grid.treegrid.js +489 -482
  55. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg.js +132 -132
  56. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg1251.js +132 -132
  57. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cat.js +128 -128
  58. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cn.js +132 -132
  59. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cs.js +128 -128
  60. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-da.js +128 -0
  61. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-de.js +132 -127
  62. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-dk.js +0 -0
  63. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-el.js +126 -126
  64. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-en.js +128 -128
  65. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-es.js +128 -128
  66. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fa.js +145 -125
  67. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fi.js +130 -130
  68. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fr.js +2 -2
  69. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-gl.js +126 -0
  70. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-he.js +127 -127
  71. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-hu.js +129 -129
  72. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-is.js +126 -126
  73. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-it.js +0 -0
  74. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ja.js +155 -155
  75. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-nl.js +148 -148
  76. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-no.js +0 -0
  77. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pl.js +126 -126
  78. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt-br.js +127 -127
  79. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt.js +125 -125
  80. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ro.js +139 -139
  81. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ru.js +127 -127
  82. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sk.js +127 -127
  83. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sr.js +128 -0
  84. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sv.js +127 -127
  85. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-tr.js +126 -126
  86. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ua.js +127 -127
  87. data/public/javascripts/rails-jqgrid/src/jqDnR.js +68 -67
  88. data/public/javascripts/rails-jqgrid/src/jqModal.js +68 -68
  89. data/public/javascripts/rails-jqgrid/src/jquery.fmatter.js +563 -541
  90. data/public/javascripts/rails-jqgrid/src/jquery.searchFilter.js +1 -1
  91. data/public/javascripts/rails-jqgrid/src/ui.multiselect.js +0 -0
  92. data/public/stylesheets/rails-jqgrid/ellipsis-xbl.xml +0 -0
  93. data/public/stylesheets/rails-jqgrid/ui.jqgrid.css +139 -2
  94. data/rails_jq_grid.gemspec +10 -3
  95. metadata +15 -11
@@ -1,1872 +1,1954 @@
1
- ;(function($){
2
- /**
3
- * jqGrid extension for form editing Grid Data
4
- * Tony Tomov tony@trirand.com
5
- * http://trirand.com/blog/
6
- * Dual licensed under the MIT and GPL licenses:
7
- * http://www.opensource.org/licenses/mit-license.php
8
- * http://www.gnu.org/licenses/gpl-2.0.html
9
- **/
10
- var rp_ge = null;
11
- $.jgrid.extend({
12
- searchGrid : function (p) {
13
- p = $.extend({
14
- recreateFilter: false,
15
- drag: true,
16
- sField:'searchField',
17
- sValue:'searchString',
18
- sOper: 'searchOper',
19
- sFilter: 'filters',
20
- loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
21
- beforeShowSearch: null,
22
- afterShowSearch : null,
23
- onInitializeSearch: null,
24
- closeAfterSearch : false,
25
- closeAfterReset: false,
26
- closeOnEscape : false,
27
- multipleSearch : false,
28
- cloneSearchRowOnAdd: true,
29
- // translation
30
- // if you want to change or remove the order change it in sopt
31
- // ['bw','eq','ne','lt','le','gt','ge','ew','cn']
32
- sopt: null,
33
- // Note: stringResult is intentionally declared "undefined by default".
34
- // you are velcome to define stringResult expressly in the options you pass to searchGrid()
35
- // stringResult is a "safeguard" measure to insure we post sensible data when communicated as form-encoded
36
- // see http://github.com/tonytomov/jqGrid/issues/#issue/36
37
- //
38
- // If this value is not expressly defined in the incoming options,
39
- // lower in the code we will infer the value based on value of multipleSearch
40
- stringResult: undefined,
41
- onClose : null,
42
- // useDataProxy allows ADD, EDIT and DEL code to bypass calling $.ajax
43
- // directly when grid's 'dataProxy' property (grid.p.dataProxy) is a function.
44
- // Used for "editGridRow" and "delGridRow" below and automatically flipped to TRUE
45
- // when ajax setting's 'url' (grid's 'editurl') property is undefined.
46
- // When 'useDataProxy' is true, instead of calling $.ajax.call(gridDOMobj, o, i) we call
47
- // gridDOMobj.p.dataProxy.call(gridDOMobj, o, i)
48
- //
49
- // Behavior is extremely similar to when 'datatype' is a function, but arguments are slightly different.
50
- // Normally the following is fed to datatype.call(a, b, c):
51
- // a = Pointer to grid's table DOM element, b = grid.p.postdata, c = "load_"+grid's ID
52
- // In cases of "edit" and "del" the following is fed:
53
- // a = Pointer to grid's table DOM element (same),
54
- // b = extended Ajax Options including postdata in "data" property. (different object type)
55
- // c = "set_"+grid's ID in case of "edit" and "del_"+grid's ID in case of "del" (same type, different content)
56
- // The major difference is that complete ajax options object, with attached "complete" and "error"
57
- // callback functions is fed instead of only post data.
58
- // This allows you to emulate a $.ajax call (including calling "complete"/"error"),
59
- // while retrieving the data locally in the browser.
60
- useDataProxy: false,
61
- overlay : true
62
- }, $.jgrid.search, p || {});
63
- return this.each(function() {
64
- var $t = this;
65
- if(!$t.grid) {return;}
66
- function applyDefaultFilters(gridDOMobj, filterSettings) {
67
- /*
68
- gridDOMobj = ointer to grid DOM object ( $(#list)[0] )
69
- What we need from gridDOMobj:
70
- gridDOMobj.SearchFilter is the pointer to the Search box, once it's created.
71
- gridDOMobj.p.postData - dictionary of post settings. These can be overriden at grid creation to
72
- contain default filter settings. We will parse these and will populate the search with defaults.
73
- filterSettings - same settings object you (would) pass to $().jqGrid('searchGrid', filterSettings);
74
- */
75
-
76
- // Pulling default filter settings out of postData property of grid's properties.:
77
- var defaultFilters = gridDOMobj.p.postData[filterSettings.sFilter];
78
- // example of what we might get: {"groupOp":"and","rules":[{"field":"amount","op":"eq","data":"100"}]}
79
- // suppose we have imported this with grid import, the this is a string.
80
- if(typeof(defaultFilters) == "string") {
81
- defaultFilters = $.jgrid.parse(defaultFilters);
82
- }
83
- if (defaultFilters) {
84
- if (defaultFilters.groupOp) {
85
- gridDOMobj.SearchFilter.setGroupOp(defaultFilters.groupOp);
86
- }
87
- if (defaultFilters.rules) {
88
- var f
89
- , i = 0
90
- , li = defaultFilters.rules.length
91
- , success = false;
92
- for (; i < li; i++) {
93
- f = defaultFilters.rules[i];
94
- // we are not trying to counter all issues with filter declaration here. Just the basics to avoid lookup exceptions.
95
- if (f.field !== undefined && f.op !== undefined && f.data !== undefined) {
96
- success = gridDOMobj.SearchFilter.setFilter({
97
- 'sfref':gridDOMobj.SearchFilter.$.find(".sf:last"),
98
- 'filter':$.extend({},f)
99
- });
100
- if (success) { gridDOMobj.SearchFilter.add(); }
101
- }
102
- }
103
- }
104
- }
105
- } // end of applyDefaultFilters
106
-
107
- if($.fn.searchFilter) {
108
- var fid = "fbox_"+$t.p.id;
109
- if(p.recreateFilter===true) {$("#"+fid).remove();}
110
- if( $("#"+fid).html() != null ) {
111
- if ( $.isFunction(p.beforeShowSearch) ) { p.beforeShowSearch($("#"+fid)); }
112
- showFilter();
113
- if( $.isFunction(p.afterShowSearch) ) { p.afterShowSearch($("#"+fid)); }
114
- } else {
115
- var fields = [],
116
- colNames = $("#"+$t.p.id).jqGrid("getGridParam","colNames"),
117
- colModel = $("#"+$t.p.id).jqGrid("getGridParam","colModel"),
118
- stempl = ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'],
119
- j,pos,k,oprtr=[];
120
- if (p.sopt !==null) {
121
- k=0;
122
- for(j=0;j<p.sopt.length;j++) {
123
- if( (pos= $.inArray(p.sopt[j],stempl)) != -1 ){
124
- oprtr[k] = {op:p.sopt[j],text: p.odata[pos]};
125
- k++;
126
- }
127
- }
128
- } else {
129
- for(j=0;j<stempl.length;j++) {
130
- oprtr[j] = {op:stempl[j],text: p.odata[j]};
131
- }
132
- }
133
- var searchable;
134
- $.each(colModel, function(i, v) {
135
- var searchable = (typeof v.search === 'undefined') ? true: v.search ,
136
- hidden = (v.hidden === true),
137
- soptions = $.extend({}, {text: colNames[i], itemval: v.index || v.name}, this.searchoptions),
138
- ignoreHiding = (soptions.searchhidden === true);
139
- if(typeof soptions.sopt !== 'undefined') {
140
- k=0;
141
- soptions.ops =[];
142
- if(soptions.sopt.length>0) {
143
- for(j=0;j<soptions.sopt.length;j++) {
144
- if( (pos= $.inArray(soptions.sopt[j],stempl)) != -1 ){
145
- soptions.ops[k] = {op:soptions.sopt[j],text: p.odata[pos]};
146
- k++;
147
- }
148
- }
149
- }
150
- }
151
- if(typeof(this.stype) === 'undefined') { this.stype='text'; }
152
- if(this.stype == 'select') {
153
- if ( soptions.dataUrl !== undefined) {}
154
- else {
155
- var eov;
156
- if(soptions.value) {
157
- eov = soptions.value;
158
- } else if(this.editoptions) {
159
- eov = this.editoptions.value;
160
- }
161
- if(eov) {
162
- soptions.dataValues =[];
163
- if(typeof(eov) === 'string') {
164
- var so = eov.split(";"),sv;
165
- for(j=0;j<so.length;j++) {
166
- sv = so[j].split(":");
167
- soptions.dataValues[j] ={value:sv[0],text:sv[1]};
168
- }
169
- } else if (typeof(eov) === 'object') {
170
- j=0;
171
- for (var key in eov) {
172
- if(eov.hasOwnProperty(key)) {
173
- soptions.dataValues[j] ={value:key,text:eov[key]};
174
- j++;
175
- }
176
- }
177
- }
178
- }
179
- }
180
- }
181
- if ((ignoreHiding && searchable) || (searchable && !hidden)) {
182
- fields.push(soptions);
183
- }
184
- });
185
- if(fields.length>0){
186
- $("<div id='"+fid+"' role='dialog' tabindex='-1'></div>").insertBefore("#gview_"+$t.p.id);
187
- // Before we create searchFilter we need to decide if we want to get back a string or a JS object.
188
- // see http://github.com/tonytomov/jqGrid/issues/#issue/36 for background on the issue.
189
- // If p.stringResult is defined, it was explisitly passed to us by user. Honor the choice, whatever it is.
190
- if (p.stringResult===undefined) {
191
- // to provide backward compatibility, inferring stringResult value from multipleSearch
192
- p.stringResult = p.multipleSearch;
193
- }
194
- // we preserve the return value here to retain access to .add() and other good methods of search form.
195
- $t.SearchFilter = $("#"+fid).searchFilter(fields, { groupOps: p.groupOps, operators: oprtr, onClose:hideFilter, resetText: p.Reset, searchText: p.Find, windowTitle: p.caption, rulesText:p.rulesText, matchText:p.matchText, onSearch: searchFilters, onReset: resetFilters,stringResult:p.stringResult, ajaxSelectOptions: $.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions ||{}), clone: p.cloneSearchRowOnAdd });
196
- $(".ui-widget-overlay","#"+fid).remove();
197
- if($t.p.direction=="rtl") { $(".ui-closer","#"+fid).css("float","left"); }
198
- if (p.drag===true) {
199
- $("#"+fid+" table thead tr:first td:first").css('cursor','move');
200
- if(jQuery.fn.jqDrag) {
201
- $("#"+fid).jqDrag($("#"+fid+" table thead tr:first td:first"));
202
- } else {
203
- try {
204
- $("#"+fid).draggable({handle: $("#"+fid+" table thead tr:first td:first")});
205
- } catch (e) {}
206
- }
207
- }
208
- if(p.multipleSearch === false) {
209
- $(".ui-del, .ui-add, .ui-del, .ui-add-last, .matchText, .rulesText", "#"+fid).hide();
210
- $("select[name='groupOp']","#"+fid).hide();
211
- }
212
- if (p.multipleSearch === true && p.loadDefaults === true) {
213
- applyDefaultFilters($t, p);
214
- }
215
- if ( $.isFunction(p.onInitializeSearch) ) { p.onInitializeSearch( $("#"+fid) ); }
216
- if ( $.isFunction(p.beforeShowSearch) ) { p.beforeShowSearch($("#"+fid)); }
217
- showFilter();
218
- if( $.isFunction(p.afterShowSearch) ) { p.afterShowSearch($("#"+fid)); }
219
- if(p.closeOnEscape===true){
220
- $("#"+fid).keydown( function( e ) {
221
- if( e.which == 27 ) {
222
- hideFilter($("#"+fid));
223
- }
224
- });
225
- }
226
- }
227
- }
228
- }
229
- function searchFilters(filters) {
230
- var hasFilters = (filters !== undefined),
231
- grid = $("#"+$t.p.id), sdata={};
232
- if(p.multipleSearch===false) {
233
- sdata[p.sField] = filters.rules[0].field;
234
- sdata[p.sValue] = filters.rules[0].data;
235
- sdata[p.sOper] = filters.rules[0].op;
236
- } else {
237
- sdata[p.sFilter] = filters;
238
- }
239
- grid[0].p.search = hasFilters;
240
- $.extend(grid[0].p.postData,sdata);
241
- grid.trigger("reloadGrid",[{page:1}]);
242
- if(p.closeAfterSearch) { hideFilter($("#"+fid)); }
243
- }
244
- function resetFilters(op) {
245
- var reload = op && op.hasOwnProperty("reload") ? op.reload : true;
246
- grid = $("#"+$t.p.id), sdata=[];
247
- grid[0].p.search = false;
248
- if(p.multipleSearch===false) {
249
- sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
250
- } else {
251
- sdata[p.sFilter] = "";
252
- }
253
- $.extend(grid[0].p.postData,sdata);
254
- if(reload) {
255
- grid.trigger("reloadGrid",[{page:1}]);
256
- }
257
- if(p.closeAfterReset) { hideFilter($("#"+fid)); }
258
- }
259
- function hideFilter(selector) {
260
- if(p.onClose){
261
- var fclm = p.onClose(selector);
262
- if(typeof fclm == 'boolean' && !fclm) { return; }
263
- }
264
- selector.hide();
265
- if(p.overlay === true) {
266
- $(".jqgrid-overlay:first","#gbox_"+$t.p.id).hide();
267
- }
268
- }
269
- function showFilter(){
270
- var fl = $(".ui-searchFilter").length;
271
- if(fl > 1) {
272
- var zI = $("#"+fid).css("zIndex");
273
- $("#"+fid).css({zIndex:parseInt(zI,10)+fl});
274
- }
275
- $("#"+fid).show();
276
- if(p.overlay === true) {
277
- $(".jqgrid-overlay:first","#gbox_"+$t.p.id).show();
278
- }
279
- try{$(':input:visible',"#"+fid)[0].focus();}catch(_){}
280
- }
281
- });
282
- },
283
- editGridRow : function(rowid, p){
284
- p = $.extend({
285
- top : 0,
286
- left: 0,
287
- width: 300,
288
- height: 'auto',
289
- dataheight: 'auto',
290
- modal: false,
291
- drag: true,
292
- resize: true,
293
- url: null,
294
- mtype : "POST",
295
- clearAfterAdd :true,
296
- closeAfterEdit : false,
297
- reloadAfterSubmit : true,
298
- onInitializeForm: null,
299
- beforeInitData: null,
300
- beforeShowForm: null,
301
- afterShowForm: null,
302
- beforeSubmit: null,
303
- afterSubmit: null,
304
- onclickSubmit: null,
305
- afterComplete: null,
306
- onclickPgButtons : null,
307
- afterclickPgButtons: null,
308
- editData : {},
309
- recreateForm : false,
310
- jqModal : true,
311
- closeOnEscape : false,
312
- addedrow : "first",
313
- topinfo : '',
314
- bottominfo: '',
315
- saveicon : [],
316
- closeicon : [],
317
- savekey: [false,13],
318
- navkeys: [false,38,40],
319
- checkOnSubmit : false,
320
- checkOnUpdate : false,
321
- _savedData : {},
322
- processing : false,
323
- onClose : null,
324
- ajaxEditOptions : {},
325
- serializeEditData : null,
326
- viewPagerButtons : true
327
- }, $.jgrid.edit, p || {});
328
- rp_ge = p;
329
- return this.each(function(){
330
- var $t = this;
331
- if (!$t.grid || !rowid) { return; }
332
- var gID = $t.p.id,
333
- frmgr = "FrmGrid_"+gID,frmtb = "TblGrid_"+gID,
334
- IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr},
335
- onBeforeShow = $.isFunction(rp_ge.beforeShowForm) ? rp_ge.beforeShowForm : false,
336
- onAfterShow = $.isFunction(rp_ge.afterShowForm) ? rp_ge.afterShowForm : false,
337
- onBeforeInit = $.isFunction(rp_ge.beforeInitData) ? rp_ge.beforeInitData : false,
338
- onInitializeForm = $.isFunction(rp_ge.onInitializeForm) ? rp_ge.onInitializeForm : false,
339
- copydata = null,
340
- maxCols = 1, maxRows=0, gurl, postdata, ret, extpost, newData, diff;
341
- if (rowid=="new") {
342
- rowid = "_empty";
343
- p.caption=p.addCaption;
344
- } else {
345
- p.caption=p.editCaption;
346
- }
347
- if(p.recreateForm===true && $("#"+IDs.themodal).html() != null) {
348
- $("#"+IDs.themodal).remove();
349
- }
350
- var closeovrl = true;
351
- if(p.checkOnUpdate && p.jqModal && !p.modal) {
352
- closeovrl = false;
353
- }
354
- if ( $("#"+IDs.themodal).html() != null ) {
355
- $(".ui-jqdialog-title","#"+IDs.modalhead).html(p.caption);
356
- $("#FormError","#"+frmtb).hide();
357
- if(rp_ge.topinfo) {
358
- $(".topinfo","#"+frmtb+"_2").html(rp_ge.topinfo);
359
- $(".tinfo","#"+frmtb+"_2").show();
360
- } else {
361
- $(".tinfo","#"+frmtb+"_2").hide();
362
- }
363
- if(rp_ge.bottominfo) {
364
- $(".bottominfo","#"+frmtb+"_2").html(rp_ge.bottominfo);
365
- $(".binfo","#"+frmtb+"_2").show();
366
- } else {
367
- $(".binfo","#"+frmtb+"_2").hide();
368
- }
369
- if(onBeforeInit) { onBeforeInit($("#"+frmgr)); }
370
- // filldata
371
- fillData(rowid,$t,frmgr);
372
- ///
373
- if(rowid=="_empty" || !rp_ge.viewPagerButtons) {
374
- $("#pData, #nData","#"+frmtb+"_2").hide();
375
- } else {
376
- $("#pData, #nData","#"+frmtb+"_2").show();
377
- }
378
- if(rp_ge.processing===true) {
379
- rp_ge.processing=false;
380
- $("#sData", "#"+frmtb+"_2").removeClass('ui-state-active');
381
- }
382
- if($("#"+frmgr).data("disabled")===true) {
383
- $(".confirm","#"+IDs.themodal).hide();
384
- $("#"+frmgr).data("disabled",false);
385
- }
386
- if(onBeforeShow) { onBeforeShow($("#"+frmgr)); }
387
- $("#"+IDs.themodal).data("onClose",rp_ge.onClose);
388
- viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM: false, closeoverlay: closeovrl, modal:p.modal});
389
- if(!closeovrl) {
390
- $(".jqmOverlay").click(function(){
391
- if(!checkUpdates()) { return false; }
392
- hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge.onClose});
393
- return false;
394
- });
395
- }
396
- if(onAfterShow) { onAfterShow($("#"+frmgr)); }
397
- } else {
398
- $($t.p.colModel).each( function(i) {
399
- var fmto = this.formoptions;
400
- maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
401
- maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
402
- });
403
- var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
404
- var flr, frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:100%;overflow:auto;position:relative;height:"+dh+";'></form>").data("disabled",false),
405
- tbl =$("<table id='"+frmtb+"' class='EditTable' cellspacing='0' cellpading='0' border='0'><tbody></tbody></table>");
406
- $(frm).append(tbl);
407
- flr = $("<tr id='FormError' style='display:none'><td class='ui-state-error' colspan='"+(maxCols*2)+"'></td></tr>");
408
- flr[0].rp = 0;
409
- $(tbl).append(flr);
410
- //topinfo
411
- flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='"+(maxCols*2)+"'>"+rp_ge.topinfo+"</td></tr>");
412
- flr[0].rp = 0;
413
- $(tbl).append(flr);
414
- // set the id.
415
- // use carefull only to change here colproperties.
416
- if(onBeforeInit) { onBeforeInit($("#"+frmgr)); }
417
- // create data
418
- var rtlb = $t.p.direction == "rtl" ? true :false,
419
- bp = rtlb ? "nData" : "pData",
420
- bn = rtlb ? "pData" : "nData",
421
- valref = createData(rowid,$t,tbl,maxCols),
422
- // buttons at footer
423
- bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></div>",
424
- bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></div>",
425
- bS ="<a href='javascript:void(0)' id='sData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
426
- bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
427
- var bt = "<table border='0' class='EditTable' id='"+frmtb+"_2'><tbody><tr id='Act_Buttons'><td class='navButton ui-widget-content'>"+(rtlb ? bN+bP : bP+bN)+"</td><td class='EditButton ui-widget-content'>"+bS+bC+"</td></tr>";
428
- bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge.bottominfo+"</td></tr>";
429
- bt += "</tbody></table>";
430
- if(maxRows > 0) {
431
- var sd=[];
432
- $.each($(tbl)[0].rows,function(i,r){
433
- sd[i] = r;
434
- });
435
- sd.sort(function(a,b){
436
- if(a.rp > b.rp) {return 1;}
437
- if(a.rp < b.rp) {return -1;}
438
- return 0;
439
- });
440
- $.each(sd, function(index, row) {
441
- $('tbody',tbl).append(row);
442
- });
443
- }
444
- p.gbox = "#gbox_"+gID;
445
- var cle = false;
446
- if(p.closeOnEscape===true){
447
- p.closeOnEscape = false;
448
- cle = true;
449
- }
450
- var tms = $("<span></span>").append(frm).append(bt);
451
- createModal(IDs,tms,p,"#gview_"+$t.p.id,$("#gbox_"+$t.p.id)[0]);
452
- if(rtlb) {
453
- $("#pData, #nData","#"+frmtb+"_2").css("float","right");
454
- $(".EditButton","#"+frmtb+"_2").css("text-align","left");
455
- }
456
- if(rp_ge.topinfo) { $(".tinfo","#"+frmtb+"_2").show(); }
457
- if(rp_ge.bottominfo) { $(".binfo","#"+frmtb+"_2").show(); }
458
- tms = null; bt=null;
459
- $("#"+IDs.themodal).keydown( function( e ) {
460
- var wkey = e.target;
461
- if ($("#"+frmgr).data("disabled")===true ) { return false; }//??
462
- if(rp_ge.savekey[0] === true && e.which == rp_ge.savekey[1]) { // save
463
- if(wkey.tagName != "TEXTAREA") {
464
- $("#sData", "#"+frmtb+"_2").trigger("click");
465
- return false;
466
- }
467
- }
468
- if(e.which === 27) {
469
- if(!checkUpdates()) { return false; }
470
- if(cle) { hideModal(this,{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge.onClose}); }
471
- return false;
472
- }
473
- if(rp_ge.navkeys[0]===true) {
474
- if($("#id_g","#"+frmtb).val() == "_empty") { return true; }
475
- if(e.which == rp_ge.navkeys[1]){ //up
476
- $("#pData", "#"+frmtb+"_2").trigger("click");
477
- return false;
478
- }
479
- if(e.which == rp_ge.navkeys[2]){ //down
480
- $("#nData", "#"+frmtb+"_2").trigger("click");
481
- return false;
482
- }
483
- }
484
- });
485
- if(p.checkOnUpdate) {
486
- $("a.ui-jqdialog-titlebar-close span","#"+IDs.themodal).removeClass("jqmClose");
487
- $("a.ui-jqdialog-titlebar-close","#"+IDs.themodal).unbind("click")
488
- .click(function(){
489
- if(!checkUpdates()) { return false; }
490
- hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose});
491
- return false;
492
- });
493
- }
494
- p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon);
495
- p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
496
- // beforeinitdata after creation of the form
497
- if(p.saveicon[0]===true) {
498
- $("#sData","#"+frmtb+"_2").addClass(p.saveicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
499
- .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
500
- }
501
- if(p.closeicon[0]===true) {
502
- $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
503
- .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
504
- }
505
- if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) {
506
- bS ="<a href='javascript:void(0)' id='sNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bYes+"</a>";
507
- bN ="<a href='javascript:void(0)' id='nNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bNo+"</a>";
508
- bC ="<a href='javascript:void(0)' id='cNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bExit+"</a>";
509
- var ii, zI = p.zIndex || 999; zI ++;
510
- if ($.browser.msie && $.browser.version ==6) {
511
- ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
512
- } else { ii="";}
513
- $("<div class='ui-widget-overlay jqgrid-overlay confirm' style='z-index:"+zI+";display:none;'>&#160;"+ii+"</div><div class='confirm ui-widget-content ui-jqconfirm' style='z-index:"+(zI+1)+"'>"+p.saveData+"<br/><br/>"+bS+bN+bC+"</div>").insertAfter("#"+frmgr);
514
- $("#sNew","#"+IDs.themodal).click(function(){
515
- postIt();
516
- $("#"+frmgr).data("disabled",false);
517
- $(".confirm","#"+IDs.themodal).hide();
518
- return false;
519
- });
520
- $("#nNew","#"+IDs.themodal).click(function(){
521
- $(".confirm","#"+IDs.themodal).hide();
522
- $("#"+frmgr).data("disabled",false);
523
- setTimeout(function(){$(":input","#"+frmgr)[0].focus();},0);
524
- return false;
525
- });
526
- $("#cNew","#"+IDs.themodal).click(function(){
527
- $(".confirm","#"+IDs.themodal).hide();
528
- $("#"+frmgr).data("disabled",false);
529
- hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose});
530
- return false;
531
- });
532
- }
533
- // here initform - only once
534
- if(onInitializeForm) { onInitializeForm($("#"+frmgr)); }
535
- if(rowid=="_empty" || !rp_ge.viewPagerButtons) { $("#pData,#nData","#"+frmtb+"_2").hide(); } else { $("#pData,#nData","#"+frmtb+"_2").show(); }
536
- if(onBeforeShow) { onBeforeShow($("#"+frmgr)); }
537
- $("#"+IDs.themodal).data("onClose",rp_ge.onClose);
538
- viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal,closeoverlay:closeovrl,modal:p.modal});
539
- if(!closeovrl) {
540
- $(".jqmOverlay").click(function(){
541
- if(!checkUpdates()) { return false; }
542
- hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge.onClose});
543
- return false;
544
- });
545
- }
546
- if(onAfterShow) { onAfterShow($("#"+frmgr)); }
547
- $(".fm-button","#"+IDs.themodal).hover(
548
- function(){$(this).addClass('ui-state-hover');},
549
- function(){$(this).removeClass('ui-state-hover');}
550
- );
551
- $("#sData", "#"+frmtb+"_2").click(function(e){
552
- postdata = {}; extpost={};
553
- $("#FormError","#"+frmtb).hide();
554
- // all depend on ret array
555
- //ret[0] - succes
556
- //ret[1] - msg if not succes
557
- //ret[2] - the id that will be set if reload after submit false
558
- getFormData();
559
- if(postdata[$t.p.id+"_id"] == "_empty") { postIt(); }
560
- else if(p.checkOnSubmit===true ) {
561
- newData = $.extend({},postdata,extpost);
562
- diff = compareData(newData,rp_ge._savedData);
563
- if(diff) {
564
- $("#"+frmgr).data("disabled",true);
565
- $(".confirm","#"+IDs.themodal).show();
566
- } else {
567
- postIt();
568
- }
569
- } else {
570
- postIt();
571
- }
572
- return false;
573
- });
574
- $("#cData", "#"+frmtb+"_2").click(function(e){
575
- if(!checkUpdates()) { return false; }
576
- hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose});
577
- return false;
578
- });
579
- $("#nData", "#"+frmtb+"_2").click(function(e){
580
- if(!checkUpdates()) { return false; }
581
- $("#FormError","#"+frmtb).hide();
582
- var npos = getCurrPos();
583
- npos[0] = parseInt(npos[0],10);
584
- if(npos[0] != -1 && npos[1][npos[0]+1]) {
585
- if($.isFunction(p.onclickPgButtons)) {
586
- p.onclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]]);
587
- }
588
- fillData(npos[1][npos[0]+1],$t,frmgr);
589
- $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
590
- if($.isFunction(p.afterclickPgButtons)) {
591
- p.afterclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]+1]);
592
- }
593
- updateNav(npos[0]+1,npos[1].length-1);
594
- }
595
- return false;
596
- });
597
- $("#pData", "#"+frmtb+"_2").click(function(e){
598
- if(!checkUpdates()) { return false; }
599
- $("#FormError","#"+frmtb).hide();
600
- var ppos = getCurrPos();
601
- if(ppos[0] != -1 && ppos[1][ppos[0]-1]) {
602
- if($.isFunction(p.onclickPgButtons)) {
603
- p.onclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]]);
604
- }
605
- fillData(ppos[1][ppos[0]-1],$t,frmgr);
606
- $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
607
- if($.isFunction(p.afterclickPgButtons)) {
608
- p.afterclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
609
- }
610
- updateNav(ppos[0]-1,ppos[1].length-1);
611
- }
612
- return false;
613
- });
614
- }
615
- var posInit =getCurrPos();
616
- updateNav(posInit[0],posInit[1].length-1);
617
- function updateNav(cr,totr,rid){
618
- if (cr===0) { $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled'); } else { $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled'); }
619
- if (cr==totr) { $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled'); } else { $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled'); }
620
- }
621
- function getCurrPos() {
622
- var rowsInGrid = $($t).jqGrid("getDataIDs"),
623
- selrow = $("#id_g","#"+frmtb).val(),
624
- pos = $.inArray(selrow,rowsInGrid);
625
- return [pos,rowsInGrid];
626
- }
627
- function checkUpdates () {
628
- var stat = true;
629
- $("#FormError","#"+frmtb).hide();
630
- if(rp_ge.checkOnUpdate) {
631
- postdata = {}; extpost={};
632
- getFormData();
633
- newData = $.extend({},postdata,extpost);
634
- diff = compareData(newData,rp_ge._savedData);
635
- if(diff) {
636
- $("#"+frmgr).data("disabled",true);
637
- $(".confirm","#"+IDs.themodal).show();
638
- stat = false;
639
- }
640
- }
641
- return stat;
642
- }
643
- function getFormData(){
644
- $(".FormElement", "#"+frmtb).each(function(i) {
645
- var celm = $(".customelement", this);
646
- if (celm.length) {
647
- var elem = celm[0], nm = $(elem).attr('name');
648
- $.each($t.p.colModel, function(i,n){
649
- if(this.name == nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) {
650
- try {
651
- postdata[nm] = this.editoptions.custom_value($("#"+nm,"#"+frmtb),'get');
652
- if (postdata[nm] === undefined) { throw "e1"; }
653
- } catch (e) {
654
- if (e=="e1") { info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose);}
655
- else { info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); }
656
- }
657
- return true;
658
- }
659
- });
660
- } else {
661
- switch ($(this).get(0).type) {
662
- case "checkbox":
663
- if($(this).attr("checked")) {
664
- postdata[this.name]= $(this).val();
665
- }else {
666
- var ofv = $(this).attr("offval");
667
- postdata[this.name]= ofv;
668
- }
669
- break;
670
- case "select-one":
671
- postdata[this.name]= $("option:selected",this).val();
672
- extpost[this.name]= $("option:selected",this).text();
673
- break;
674
- case "select-multiple":
675
- postdata[this.name]= $(this).val();
676
- if(postdata[this.name]) { postdata[this.name] = postdata[this.name].join(","); }
677
- else { postdata[this.name] =""; }
678
- var selectedText = [];
679
- $("option:selected",this).each(
680
- function(i,selected){
681
- selectedText[i] = $(selected).text();
682
- }
683
- );
684
- extpost[this.name]= selectedText.join(",");
685
- break;
686
- case "password":
687
- case "text":
688
- case "textarea":
689
- case "button":
690
- postdata[this.name] = $(this).val();
691
-
692
- break;
693
- }
694
- if($t.p.autoencode) { postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]); }
695
- }
696
- });
697
- return true;
698
- }
699
- function createData(rowid,obj,tb,maxcols){
700
- var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false,
701
- tdtmpl = "<td class='CaptionTD ui-widget-content'>&#160;</td><td class='DataTD ui-widget-content' style='white-space:pre'>&#160;</td>", tmpl=""; //*2
702
- for (var i =1;i<=maxcols;i++) {
703
- tmpl += tdtmpl;
704
- }
705
- if(rowid != '_empty') {
706
- ind = $(obj).jqGrid("getInd",rowid);
707
- }
708
- $(obj.p.colModel).each( function(i) {
709
- nm = this.name;
710
- // hidden fields are included in the form
711
- if(this.editrules && this.editrules.edithidden === true) {
712
- hc = false;
713
- } else {
714
- hc = this.hidden === true ? true : false;
715
- }
716
- dc = hc ? "style='display:none'" : "";
717
- if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') {
718
- if(ind === false) {
719
- tmp = "";
720
- } else {
721
- if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
722
- tmp = $("td:eq("+i+")",obj.rows[ind]).text();
723
- } else {
724
- try {
725
- tmp = $.unformat($("td:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
726
- } catch (_) {
727
- tmp = $("td:eq("+i+")",obj.rows[ind]).html();
728
- }
729
- }
730
- }
731
- var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}),
732
- frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}),
733
- rp = parseInt(frmopt.rowpos,10) || cnt+1,
734
- cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
735
- if(rowid == "_empty" && opt.defaultValue ) {
736
- tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue;
737
- }
738
- if(!this.edittype) { this.edittype = "text"; }
739
- if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
740
- elc = createEl(this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
741
- if(tmp == "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
742
- if(tmp == "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
743
- if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) { rp_ge._savedData[nm] = tmp; }
744
- $(elc).addClass("FormElement");
745
- trdata = $(tb).find("tr[rowpos="+rp+"]");
746
- if(frmopt.rowabove) {
747
- var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
748
- $(tb).append(newdata);
749
- newdata[0].rp = rp;
750
- }
751
- if ( trdata.length===0 ) {
752
- trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm);
753
- $(trdata).append(tmpl);
754
- $(tb).append(trdata);
755
- trdata[0].rp = rp;
756
- }
757
- $("td:eq("+(cp-2)+")",trdata[0]).html( typeof frmopt.label === 'undefined' ? obj.p.colNames[i]: frmopt.label);
758
- $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix);
759
- retpos[cnt] = i;
760
- cnt++;
761
- }
762
- });
763
- if( cnt > 0) {
764
- var idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+ (maxcols*2-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='"+obj.p.id+"_id' value='"+rowid+"'/></td></tr>");
765
- idrow[0].rp = cnt+999;
766
- $(tb).append(idrow);
767
- if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) { rp_ge._savedData[obj.p.id+"_id"] = rowid; }
768
- }
769
- return retpos;
770
- }
771
- function fillData(rowid,obj,fmid){
772
- var nm,cnt=0,tmp, fld,opt,vl,vlc;
773
- if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) {rp_ge._savedData = {};rp_ge._savedData[obj.p.id+"_id"]=rowid;}
774
- var cm = obj.p.colModel;
775
- if(rowid == '_empty') {
776
- $(cm).each(function(i){
777
- nm = this.name;
778
- opt = $.extend({}, this.editoptions || {} );
779
- fld = $("#"+$.jgrid.jqID(nm),"#"+fmid);
780
- if(fld[0] != null) {
781
- vl = "";
782
- if(opt.defaultValue ) {
783
- vl = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue;
784
- if(fld[0].type=='checkbox') {
785
- vlc = vl.toLowerCase();
786
- if(vlc.search(/(false|0|no|off|undefined)/i)<0 && vlc!=="") {
787
- fld[0].checked = true;
788
- fld[0].defaultChecked = true;
789
- fld[0].value = vl;
790
- } else {
791
- fld.attr({checked:"",defaultChecked:""});
792
- }
793
- } else {fld.val(vl); }
794
- } else {
795
- if( fld[0].type=='checkbox' ) {
796
- fld[0].checked = false;
797
- fld[0].defaultChecked = false;
798
- vl = $(fld).attr("offval");
799
- } else if (fld[0].type && fld[0].type.substr(0,6)=='select') {
800
- fld[0].selectedIndex = 0;
801
- } else {
802
- fld.val(vl);
803
- }
804
- }
805
- if(rp_ge.checkOnSubmit===true || rp_ge.checkOnUpdate) { rp_ge._savedData[nm] = vl; }
806
- }
807
- });
808
- $("#id_g","#"+fmid).val(rowid);
809
- return;
810
- }
811
- var tre = $(obj).jqGrid("getInd",rowid,true);
812
- if(!tre) { return; }
813
- $('td',tre).each( function(i) {
814
- nm = cm[i].name;
815
- // hidden fields are included in the form
816
- if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) {
817
- if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
818
- tmp = $(this).text();
819
- } else {
820
- try {
821
- tmp = $.unformat(this,{rowId:rowid, colModel:cm[i]},i);
822
- } catch (_) {
823
- tmp = $(this).html();
824
- }
825
- }
826
- if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
827
- if(rp_ge.checkOnSubmit===true || rp_ge.checkOnUpdate) { rp_ge._savedData[nm] = tmp; }
828
- nm = $.jgrid.jqID(nm);
829
- switch (cm[i].edittype) {
830
- case "password":
831
- case "text":
832
- case "button" :
833
- case "image":
834
- $("#"+nm,"#"+fmid).val(tmp);
835
- break;
836
- case "textarea":
837
- if(tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
838
- $("#"+nm,"#"+fmid).val(tmp);
839
- break;
840
- case "select":
841
- var opv = tmp.split(",");
842
- opv = $.map(opv,function(n){return $.trim(n);});
843
- $("#"+nm+" option","#"+fmid).each(function(j){
844
- if (!cm[i].editoptions.multiple && (opv[0] == $.trim($(this).text()) || opv[0] == $.trim($(this).val())) ){
845
- this.selected= true;
846
- } else if (cm[i].editoptions.multiple){
847
- if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){
848
- this.selected = true;
849
- }else{
850
- this.selected = false;
851
- }
852
- } else {
853
- this.selected = false;
854
- }
855
- });
856
- break;
857
- case "checkbox":
858
- tmp = tmp+"";
859
- if(cm[i].editoptions && cm[i].editoptions.value) {
860
- var cb = cm[i].editoptions.value.split(":");
861
- if(cb[0] == tmp) {
862
- $("#"+nm,"#"+fmid).attr("checked",true);
863
- $("#"+nm,"#"+fmid).attr("defaultChecked",true); //ie
864
- } else {
865
- $("#"+nm,"#"+fmid).attr("checked",false);
866
- $("#"+nm,"#"+fmid).attr("defaultChecked",""); //ie
867
- }
868
- } else {
869
- tmp = tmp.toLowerCase();
870
- if(tmp.search(/(false|0|no|off|undefined)/i)<0 && tmp!=="") {
871
- $("#"+nm,"#"+fmid).attr("checked",true);
872
- $("#"+nm,"#"+fmid).attr("defaultChecked",true); //ie
873
- } else {
874
- $("#"+nm,"#"+fmid).attr("checked",false);
875
- $("#"+nm,"#"+fmid).attr("defaultChecked",""); //ie
876
- }
877
- }
878
- break;
879
- case 'custom' :
880
- try {
881
- if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
882
- var dummy = cm[i].editoptions.custom_value($("#"+nm,"#"+fmid),'set',tmp);
883
- } else { throw "e1"; }
884
- } catch (e) {
885
- if (e=="e1") { info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose);}
886
- else { info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); }
887
- }
888
- break;
889
- }
890
- cnt++;
891
- }
892
- });
893
- if(cnt>0) { $("#id_g","#"+frmtb).val(rowid); }
894
- }
895
- function postIt() {
896
- var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper;
897
- if($.isFunction(rp_ge.beforeCheckValues)) {
898
- var retvals = rp_ge.beforeCheckValues(postdata,$("#"+frmgr),postdata[$t.p.id+"_id"] == "_empty" ? opers.addoper : opers.editoper);
899
- if(retvals && typeof(retvals) === 'object') { postdata = retvals; }
900
- }
901
- for( var key in postdata ){
902
- if(postdata.hasOwnProperty(key)) {
903
- ret = checkValues(postdata[key],key,$t);
904
- if(ret[0] === false) { break; }
905
- }
906
- }
907
- if(ret[0]) {
908
- if( $.isFunction( rp_ge.onclickSubmit)) { onCS = rp_ge.onclickSubmit(rp_ge,postdata) || {}; }
909
- if( $.isFunction(rp_ge.beforeSubmit)) { ret = rp_ge.beforeSubmit(postdata,$("#"+frmgr)); }
910
- }
911
-
912
- if(ret[0] && !rp_ge.processing) {
913
- rp_ge.processing = true;
914
- $("#sData", "#"+frmtb+"_2").addClass('ui-state-active');
915
- oper = opers.oper;
916
- idname = opers.id;
917
- // we add to pos data array the action - the name is oper
918
- postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) == "_empty") ? opers.addoper : opers.editoper;
919
- if(postdata[oper] != opers.addoper) {
920
- postdata[idname] = postdata[$t.p.id+"_id"];
921
- } else {
922
- // check to see if we have allredy this field in the form and if yes lieve it
923
- if( postdata[idname] === undefined ) { postdata[idname] = postdata[$t.p.id+"_id"]; }
924
- }
925
- delete postdata[$t.p.id+"_id"];
926
- postdata = $.extend(postdata,rp_ge.editData,onCS);
927
-
928
- var ajaxOptions = $.extend({
929
- url: rp_ge.url ? rp_ge.url : $($t).jqGrid('getGridParam','editurl'),
930
- type: rp_ge.mtype,
931
- data: $.isFunction(rp_ge.serializeEditData) ? rp_ge.serializeEditData(postdata) : postdata,
932
- complete:function(data,Status){
933
- if(Status != "success") {
934
- ret[0] = false;
935
- if ($.isFunction(rp_ge.errorTextFormat)) {
936
- ret[1] = rp_ge.errorTextFormat(data);
937
- } else {
938
- ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status;
939
- }
940
- } else {
941
- // data is posted successful
942
- // execute aftersubmit with the returned data from server
943
- if( $.isFunction(rp_ge.afterSubmit) ) {
944
- ret = rp_ge.afterSubmit(data,postdata);
945
- }
946
- }
947
- if(ret[0] === false) {
948
- $("#FormError>td","#"+frmtb).html(ret[1]);
949
- $("#FormError","#"+frmtb).show();
950
- } else {
951
- // remove some values if formattaer select or checkbox
952
- $.each($t.p.colModel, function(i,n){
953
- if(extpost[this.name] && this.formatter && this.formatter=='select') {
954
- try {delete extpost[this.name];} catch (e) {}
955
- }
956
- });
957
- postdata = $.extend(postdata,extpost);
958
- if($t.p.autoencode) {
959
- $.each(postdata,function(n,v){
960
- postdata[n] = $.jgrid.htmlDecode(v);
961
- });
962
- }
963
- rp_ge.reloadAfterSubmit = rp_ge.reloadAfterSubmit && $t.p.datatype != "local";
964
- // the action is add
965
- if(postdata[oper] == opers.addoper ) {
966
- //id processing
967
- // user not set the id ret[2]
968
- if(!ret[2]) { ret[2] = (parseInt($t.p.records,10)+1)+""; }
969
- postdata[idname] = ret[2];
970
- if(rp_ge.closeAfterAdd) {
971
- if(rp_ge.reloadAfterSubmit) { $($t).trigger("reloadGrid"); }
972
- else {
973
- $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
974
- $($t).jqGrid("setSelection",ret[2]);
975
- }
976
- hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose});
977
- } else if (rp_ge.clearAfterAdd) {
978
- if(rp_ge.reloadAfterSubmit) { $($t).trigger("reloadGrid"); }
979
- else { $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow); }
980
- fillData("_empty",$t,frmgr);
981
- } else {
982
- if(rp_ge.reloadAfterSubmit) { $($t).trigger("reloadGrid"); }
983
- else { $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow); }
984
- }
985
- } else {
986
- // the action is update
987
- if(rp_ge.reloadAfterSubmit) {
988
- $($t).trigger("reloadGrid");
989
- if( !rp_ge.closeAfterEdit ) { setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000); }
990
- } else {
991
- if($t.p.treeGrid === true) {
992
- $($t).jqGrid("setTreeRow",postdata[idname],postdata);
993
- } else {
994
- $($t).jqGrid("setRowData",postdata[idname],postdata);
995
- }
996
- }
997
- if(rp_ge.closeAfterEdit) { hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose}); }
998
- }
999
- if($.isFunction(rp_ge.afterComplete)) {
1000
- copydata = data;
1001
- setTimeout(function(){rp_ge.afterComplete(copydata,postdata,$("#"+frmgr));copydata=null;},500);
1002
- }
1003
- }
1004
- rp_ge.processing=false;
1005
- if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) {
1006
- $("#"+frmgr).data("disabled",false);
1007
- if(rp_ge._savedData[$t.p.id+"_id"] !="_empty"){
1008
- for(var key in rp_ge._savedData) {
1009
- if(postdata[key]) {
1010
- rp_ge._savedData[key] = postdata[key];
1011
- }
1012
- }
1013
- }
1014
- }
1015
- $("#sData", "#"+frmtb+"_2").removeClass('ui-state-active');
1016
- try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){}
1017
- },
1018
- error:function(xhr,st,err){
1019
- $("#FormError>td","#"+frmtb).html(st+ " : "+err);
1020
- $("#FormError","#"+frmtb).show();
1021
- rp_ge.processing=false;
1022
- $("#"+frmgr).data("disabled",false);
1023
- $("#sData", "#"+frmtb+"_2").removeClass('ui-state-active');
1024
- }
1025
- }, $.jgrid.ajaxOptions, rp_ge.ajaxEditOptions )
1026
-
1027
- if (!ajaxOptions['url'] && !rp_ge['useDataProxy']) {
1028
- if ($.isFunction($t.p.dataProxy)) {
1029
- rp_ge['useDataProxy'] = true;
1030
- } else {
1031
- ret[0]=false; ret[1] += " "+$.jgrid.errors.nourl;
1032
- }
1033
- }
1034
- if (ret[0]) {
1035
- if (rp_ge['useDataProxy']) { $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id) }
1036
- else { $.ajax(ajaxOptions) }
1037
- }
1038
- }
1039
- if(ret[0] === false) {
1040
- $("#FormError>td","#"+frmtb).html(ret[1]);
1041
- $("#FormError","#"+frmtb).show();
1042
- // return;
1043
- }
1044
- }
1045
- function compareData(nObj, oObj ) {
1046
- var ret = false,key;
1047
- for (key in nObj) {
1048
- if(nObj[key] != oObj[key]) {
1049
- ret = true;
1050
- break;
1051
- }
1052
- }
1053
- return ret;
1054
- }
1055
- });
1056
- },
1057
- viewGridRow : function(rowid, p){
1058
- p = $.extend({
1059
- top : 0,
1060
- left: 0,
1061
- width: 0,
1062
- height: 'auto',
1063
- dataheight: 'auto',
1064
- modal: false,
1065
- drag: true,
1066
- resize: true,
1067
- jqModal: true,
1068
- closeOnEscape : false,
1069
- labelswidth: '30%',
1070
- closeicon: [],
1071
- navkeys: [false,38,40],
1072
- onClose: null,
1073
- beforeShowForm : null,
1074
- viewPagerButtons : true
1075
- }, $.jgrid.view, p || {});
1076
- return this.each(function(){
1077
- var $t = this;
1078
- if (!$t.grid || !rowid) { return; }
1079
- if(!p.imgpath) { p.imgpath= $t.p.imgpath; }
1080
- // I hate to rewrite code, but ...
1081
- var gID = $t.p.id,
1082
- frmgr = "ViewGrid_"+gID , frmtb = "ViewTbl_"+gID,
1083
- IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr},
1084
- maxCols = 1, maxRows=0;
1085
- if ( $("#"+IDs.themodal).html() != null ) {
1086
- $(".ui-jqdialog-title","#"+IDs.modalhead).html(p.caption);
1087
- $("#FormError","#"+frmtb).hide();
1088
- fillData(rowid,$t);
1089
- if($.isFunction(p.beforeShowForm)) { p.beforeShowForm($("#"+frmgr)); }
1090
- viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM: false, modal:p.modal});
1091
- focusaref();
1092
- } else {
1093
- $($t.p.colModel).each( function(i) {
1094
- var fmto = this.formoptions;
1095
- maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
1096
- maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
1097
- });
1098
- var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
1099
- var flr, frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' style='width:100%;overflow:auto;position:relative;height:"+dh+";'></form>"),
1100
- tbl =$("<table id='"+frmtb+"' class='EditTable' cellspacing='1' cellpading='2' border='0' style='table-layout:fixed'><tbody></tbody></table>");
1101
- // set the id.
1102
- $(frm).append(tbl);
1103
- var valref = createData(rowid, $t, tbl, maxCols),
1104
- rtlb = $t.p.direction == "rtl" ? true :false,
1105
- bp = rtlb ? "nData" : "pData",
1106
- bn = rtlb ? "pData" : "nData",
1107
-
1108
- // buttons at footer
1109
- bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></div>",
1110
- bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></div>",
1111
- bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bClose+"</a>";
1112
- if(maxRows > 0) {
1113
- var sd=[];
1114
- $.each($(tbl)[0].rows,function(i,r){
1115
- sd[i] = r;
1116
- });
1117
- sd.sort(function(a,b){
1118
- if(a.rp > b.rp) {return 1;}
1119
- if(a.rp < b.rp) {return -1;}
1120
- return 0;
1121
- });
1122
- $.each(sd, function(index, row) {
1123
- $('tbody',tbl).append(row);
1124
- });
1125
- }
1126
- p.gbox = "#gbox_"+gID;
1127
- var cle = false;
1128
- if(p.closeOnEscape===true){
1129
- p.closeOnEscape = false;
1130
- cle = true;
1131
- }
1132
- var bt = $("<span></span>").append(frm).append("<table border='0' class='EditTable' id='"+frmtb+"_2'><tbody><tr id='Act_Buttons'><td class='navButton ui-widget-content' width='"+p.labelswidth+"'>"+(rtlb ? bN+bP : bP+bN)+"</td><td class='EditButton ui-widget-content'>"+bC+"</td></tr></tbody></table>");
1133
- createModal(IDs,bt,p,"#gview_"+$t.p.id,$("#gview_"+$t.p.id)[0]);
1134
- if(rtlb) {
1135
- $("#pData, #nData","#"+frmtb+"_2").css("float","right");
1136
- $(".EditButton","#"+frmtb+"_2").css("text-align","left");
1137
- }
1138
- if(!p.viewPagerButtons) { $("#pData, #nData","#"+frmtb+"_2").hide(); }
1139
- bt = null;
1140
- $("#"+IDs.themodal).keydown( function( e ) {
1141
- if(e.which === 27) {
1142
- if(cle) { hideModal(this,{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose}); }
1143
- return false;
1144
- }
1145
- if(p.navkeys[0]===true) {
1146
- if(e.which === p.navkeys[1]){ //up
1147
- $("#pData", "#"+frmtb+"_2").trigger("click");
1148
- return false;
1149
- }
1150
- if(e.which === p.navkeys[2]){ //down
1151
- $("#nData", "#"+frmtb+"_2").trigger("click");
1152
- return false;
1153
- }
1154
- }
1155
- });
1156
- p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
1157
- if(p.closeicon[0]===true) {
1158
- $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
1159
- .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
1160
- }
1161
- if($.isFunction(p.beforeShowForm)) { p.beforeShowForm($("#"+frmgr)); }
1162
- viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, modal:p.modal});
1163
- $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover(
1164
- function(){$(this).addClass('ui-state-hover');},
1165
- function(){$(this).removeClass('ui-state-hover');}
1166
- );
1167
- focusaref();
1168
- $("#cData", "#"+frmtb+"_2").click(function(e){
1169
- hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: p.onClose});
1170
- return false;
1171
- });
1172
- $("#nData", "#"+frmtb+"_2").click(function(e){
1173
- $("#FormError","#"+frmtb).hide();
1174
- var npos = getCurrPos();
1175
- npos[0] = parseInt(npos[0],10);
1176
- if(npos[0] != -1 && npos[1][npos[0]+1]) {
1177
- if($.isFunction(p.onclickPgButtons)) {
1178
- p.onclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]]);
1179
- }
1180
- fillData(npos[1][npos[0]+1],$t);
1181
- $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
1182
- if($.isFunction(p.afterclickPgButtons)) {
1183
- p.afterclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]+1]);
1184
- }
1185
- updateNav(npos[0]+1,npos[1].length-1);
1186
- }
1187
- focusaref();
1188
- return false;
1189
- });
1190
- $("#pData", "#"+frmtb+"_2").click(function(e){
1191
- $("#FormError","#"+frmtb).hide();
1192
- var ppos = getCurrPos();
1193
- if(ppos[0] != -1 && ppos[1][ppos[0]-1]) {
1194
- if($.isFunction(p.onclickPgButtons)) {
1195
- p.onclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]]);
1196
- }
1197
- fillData(ppos[1][ppos[0]-1],$t);
1198
- $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
1199
- if($.isFunction(p.afterclickPgButtons)) {
1200
- p.afterclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
1201
- }
1202
- updateNav(ppos[0]-1,ppos[1].length-1);
1203
- }
1204
- focusaref();
1205
- return false;
1206
- });
1207
- }
1208
- function focusaref(){ //Sfari 3 issues
1209
- if(p.closeOnEscape===true || p.navkeys[0]===true) {
1210
- setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+IDs.modalhead).focus();},0);
1211
- }
1212
- }
1213
- var posInit =getCurrPos();
1214
- updateNav(posInit[0],posInit[1].length-1);
1215
- function updateNav(cr,totr,rid){
1216
- if (cr===0) { $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled'); } else { $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled'); }
1217
- if (cr==totr) { $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled'); } else { $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled'); }
1218
- }
1219
- function getCurrPos() {
1220
- var rowsInGrid = $($t).jqGrid("getDataIDs"),
1221
- selrow = $("#id_g","#"+frmtb).val(),
1222
- pos = $.inArray(selrow,rowsInGrid);
1223
- return [pos,rowsInGrid];
1224
- }
1225
- function createData(rowid,obj,tb,maxcols){
1226
- var nm, hc,trdata, tdl, tde, cnt=0,tmp, dc, retpos=[], ind=false,
1227
- tdtmpl = "<td class='CaptionTD form-view-label ui-widget-content' width='"+p.labelswidth+"'>&#160;</td><td class='DataTD form-view-data ui-helper-reset ui-widget-content'>&#160;</td>", tmpl="",
1228
- tdtmpl2 = "<td class='CaptionTD form-view-label ui-widget-content'>&#160;</td><td class='DataTD form-view-data ui-widget-content'>&#160;</td>",
1229
- fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld;
1230
- for (var i =1;i<=maxcols;i++) {
1231
- tmpl += i == 1 ? tdtmpl : tdtmpl2;
1232
- }
1233
- // find max number align rigth with property formatter
1234
- $(obj.p.colModel).each( function(i) {
1235
- if(this.editrules && this.editrules.edithidden === true) {
1236
- hc = false;
1237
- } else {
1238
- hc = this.hidden === true ? true : false;
1239
- }
1240
- if(!hc && this.align==='right') {
1241
- if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) {
1242
- max1 = Math.max(max1,parseInt(this.width,10));
1243
- } else {
1244
- max2 = Math.max(max2,parseInt(this.width,10));
1245
- }
1246
- }
1247
- });
1248
- maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0;
1249
- ind = $(obj).jqGrid("getInd",rowid);
1250
- $(obj.p.colModel).each( function(i) {
1251
- nm = this.name;
1252
- setme = false;
1253
- // hidden fields are included in the form
1254
- if(this.editrules && this.editrules.edithidden === true) {
1255
- hc = false;
1256
- } else {
1257
- hc = this.hidden === true ? true : false;
1258
- }
1259
- dc = hc ? "style='display:none'" : "";
1260
- viewfld = (typeof this.viewable != 'boolean') ? true : this.viewable;
1261
- if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) {
1262
- if(ind === false) {
1263
- tmp = "";
1264
- } else {
1265
- if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
1266
- tmp = $("td:eq("+i+")",obj.rows[ind]).text();
1267
- } else {
1268
- tmp = $("td:eq("+i+")",obj.rows[ind]).html();
1269
- }
1270
- }
1271
- setme = this.align === 'right' && maxw !==0 ? true : false;
1272
- var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}),
1273
- frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}),
1274
- rp = parseInt(frmopt.rowpos,10) || cnt+1,
1275
- cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
1276
- if(frmopt.rowabove) {
1277
- var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
1278
- $(tb).append(newdata);
1279
- newdata[0].rp = rp;
1280
- }
1281
- trdata = $(tb).find("tr[rowpos="+rp+"]");
1282
- if ( trdata.length===0 ) {
1283
- trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm);
1284
- $(trdata).append(tmpl);
1285
- $(tb).append(trdata);
1286
- trdata[0].rp = rp;
1287
- }
1288
- $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (typeof frmopt.label === 'undefined' ? obj.p.colNames[i]: frmopt.label)+'</b>');
1289
- $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm);
1290
- if(setme){
1291
- $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"});
1292
- }
1293
- retpos[cnt] = i;
1294
- cnt++;
1295
- }
1296
- });
1297
- if( cnt > 0) {
1298
- var idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+ (maxcols*2-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='id' value='"+rowid+"'/></td></tr>");
1299
- idrow[0].rp = cnt+99;
1300
- $(tb).append(idrow);
1301
- }
1302
- return retpos;
1303
- }
1304
- function fillData(rowid,obj){
1305
- var nm, hc,cnt=0,tmp, opt,trv;
1306
- trv = $(obj).jqGrid("getInd",rowid,true);
1307
- if(!trv) { return; }
1308
- $('td',trv).each( function(i) {
1309
- nm = obj.p.colModel[i].name;
1310
- // hidden fields are included in the form
1311
- if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) {
1312
- hc = false;
1313
- } else {
1314
- hc = obj.p.colModel[i].hidden === true ? true : false;
1315
- }
1316
- if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
1317
- if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
1318
- tmp = $(this).text();
1319
- } else {
1320
- tmp = $(this).html();
1321
- }
1322
- opt = $.extend({},obj.p.colModel[i].editoptions || {});
1323
- nm = $.jgrid.jqID("v_"+nm);
1324
- $("#"+nm+" span","#"+frmtb).html(tmp);
1325
- if (hc) { $("#"+nm,"#"+frmtb).parents("tr:first").hide(); }
1326
- cnt++;
1327
- }
1328
- });
1329
- if(cnt>0) { $("#id_g","#"+frmtb).val(rowid); }
1330
- }
1331
- });
1332
- },
1333
- delGridRow : function(rowids,p) {
1334
- p = $.extend({
1335
- top : 0,
1336
- left: 0,
1337
- width: 240,
1338
- height: 'auto',
1339
- dataheight : 'auto',
1340
- modal: false,
1341
- drag: true,
1342
- resize: true,
1343
- url : '',
1344
- mtype : "POST",
1345
- reloadAfterSubmit: true,
1346
- beforeShowForm: null,
1347
- afterShowForm: null,
1348
- beforeSubmit: null,
1349
- onclickSubmit: null,
1350
- afterSubmit: null,
1351
- jqModal : true,
1352
- closeOnEscape : false,
1353
- delData: {},
1354
- delicon : [],
1355
- cancelicon : [],
1356
- onClose : null,
1357
- ajaxDelOptions : {},
1358
- processing : false,
1359
- serializeDelData : null,
1360
- useDataProxy : false
1361
- }, $.jgrid.del, p ||{});
1362
- rp_ge = p;
1363
- return this.each(function(){
1364
- var $t = this;
1365
- if (!$t.grid ) { return; }
1366
- if(!rowids) { return; }
1367
- var onBeforeShow = typeof p.beforeShowForm === 'function' ? true: false,
1368
- onAfterShow = typeof p.afterShowForm === 'function' ? true: false,
1369
- gID = $t.p.id, onCS = {},
1370
- dtbl = "DelTbl_"+gID,postd, idname, opers, oper,
1371
- IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl};
1372
- if (jQuery.isArray(rowids)) { rowids = rowids.join(); }
1373
- if ( $("#"+IDs.themodal).html() != null ) {
1374
- $("#DelData>td","#"+dtbl).text(rowids);
1375
- $("#DelError","#"+dtbl).hide();
1376
- if( rp_ge.processing === true) {
1377
- rp_ge.processing=false;
1378
- $("#dData", "#"+dtbl).removeClass('ui-state-active');
1379
- }
1380
- if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
1381
- viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal,jqM: false, modal:p.modal});
1382
- if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
1383
- } else {
1384
- var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
1385
- var tbl = "<div id='"+dtbl+"' class='formdata' style='width:100%;overflow:auto;position:relative;height:"+dh+";'>";
1386
- tbl += "<table class='DelTable'><tbody>";
1387
- // error data
1388
- tbl += "<tr id='DelError' style='display:none'><td class='ui-state-error'></td></tr>";
1389
- tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>";
1390
- tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+p.msg+"</td></tr><tr><td >&#160;</td></tr>";
1391
- // buttons at footer
1392
- tbl += "</tbody></table></div>";
1393
- var bS = "<a href='javascript:void(0)' id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
1394
- bC = "<a href='javascript:void(0)' id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
1395
- tbl += "<table cellspacing='0' cellpadding='0' border='0' class='EditTable' id='"+dtbl+"_2'><tbody><tr><td class='DataTD ui-widget-content'></td></tr><tr style='display:block;height:3px;'><td></td></tr><tr><td class='DelButton EditButton'>"+bS+"&#160;"+bC+"</td></tr></tbody></table>";
1396
- p.gbox = "#gbox_"+gID;
1397
- createModal(IDs,tbl,p,"#gview_"+$t.p.id,$("#gview_"+$t.p.id)[0]);
1398
- $(".fm-button","#"+dtbl+"_2").hover(
1399
- function(){$(this).addClass('ui-state-hover');},
1400
- function(){$(this).removeClass('ui-state-hover');}
1401
- );
1402
- p.delicon = $.extend([true,"left","ui-icon-scissors"],p.delicon);
1403
- p.cancelicon = $.extend([true,"left","ui-icon-cancel"],p.cancelicon);
1404
- if(p.delicon[0]===true) {
1405
- $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
1406
- .append("<span class='ui-icon "+p.delicon[2]+"'></span>");
1407
- }
1408
- if(p.cancelicon[0]===true) {
1409
- $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
1410
- .append("<span class='ui-icon "+p.cancelicon[2]+"'></span>");
1411
- }
1412
- $("#dData","#"+dtbl+"_2").click(function(e){
1413
- var ret=[true,""]; onCS = {};
1414
- var postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
1415
- if( typeof p.onclickSubmit === 'function' ) { onCS = p.onclickSubmit(rp_ge, postdata) || {}; }
1416
- if( typeof p.beforeSubmit === 'function' ) { ret = p.beforeSubmit(postdata); }
1417
- if(ret[0] && !rp_ge.processing) {
1418
- rp_ge.processing = true;
1419
- $(this).addClass('ui-state-active');
1420
- opers = $t.p.prmNames;
1421
- postd = $.extend({},rp_ge.delData, onCS);
1422
- oper = opers.oper;
1423
- postd[oper] = opers.deloper;
1424
- idname = opers.id;
1425
- postd[idname] = postdata;
1426
-
1427
- var ajaxOptions = $.extend({
1428
- url: rp_ge.url ? rp_ge.url : $($t).jqGrid('getGridParam','editurl'),
1429
- type: p.mtype,
1430
- data: $.isFunction(p.serializeDelData) ? p.serializeDelData(postd) : postd,
1431
- complete:function(data,Status){
1432
- if(Status != "success") {
1433
- ret[0] = false;
1434
- if ($.isFunction(rp_ge.errorTextFormat)) {
1435
- ret[1] = rp_ge.errorTextFormat(data);
1436
- } else {
1437
- ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status;
1438
- }
1439
- } else {
1440
- // data is posted successful
1441
- // execute aftersubmit with the returned data from server
1442
- if( typeof rp_ge.afterSubmit === 'function' ) {
1443
- ret = rp_ge.afterSubmit(data,postd);
1444
- }
1445
- }
1446
- if(ret[0] === false) {
1447
- $("#DelError>td","#"+dtbl).html(ret[1]);
1448
- $("#DelError","#"+dtbl).show();
1449
- } else {
1450
- if(rp_ge.reloadAfterSubmit && $t.p.datatype != "local") {
1451
- $($t).trigger("reloadGrid");
1452
- } else {
1453
- var toarr = [];
1454
- toarr = postdata.split(",");
1455
- if($t.p.treeGrid===true){
1456
- try {$($t).jqGrid("delTreeNode",toarr[0]);} catch(e){}
1457
- } else {
1458
- for(var i=0;i<toarr.length;i++) {
1459
- $($t).jqGrid("delRowData",toarr[i]);
1460
- }
1461
- }
1462
- $t.p.selrow = null;
1463
- $t.p.selarrrow = [];
1464
- }
1465
- if($.isFunction(rp_ge.afterComplete)) {
1466
- setTimeout(function(){rp_ge.afterComplete(data,postdata);},500);
1467
- }
1468
- }
1469
- rp_ge.processing=false;
1470
- $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
1471
- if(ret[0]) { hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge.onClose}); }
1472
- },
1473
- error:function(xhr,st,err){
1474
- $("#DelError>td","#"+dtbl).html(st+ " : "+err);
1475
- $("#DelError","#"+dtbl).show();
1476
- rp_ge.processing=false;
1477
- $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
1478
- }
1479
- }, $.jgrid.ajaxOptions, p.ajaxDelOptions);
1480
-
1481
-
1482
- if (!ajaxOptions['url'] && !rp_ge['useDataProxy']) {
1483
- if ($.isFunction($t.p.dataProxy)) {
1484
- rp_ge['useDataProxy'] = true;
1485
- } else {
1486
- ret[0]=false; ret[1] += " "+$.jgrid.errors.nourl;
1487
- }
1488
- }
1489
- if (ret[0]) {
1490
- if (rp_ge['useDataProxy']) { $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id) }
1491
- else { $.ajax(ajaxOptions) }
1492
- }
1493
- }
1494
-
1495
- if(ret[0] === false) {
1496
- $("#DelError>td","#"+dtbl).html(ret[1]);
1497
- $("#DelError","#"+dtbl).show();
1498
- }
1499
- return false;
1500
- });
1501
- $("#eData", "#"+dtbl+"_2").click(function(e){
1502
- hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge.onClose});
1503
- return false;
1504
- });
1505
- if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
1506
- viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal,modal:p.modal});
1507
- if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
1508
- }
1509
- if(p.closeOnEscape===true) {
1510
- setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+IDs.modalhead).focus();},0);
1511
- }
1512
- });
1513
- },
1514
- navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) {
1515
- o = $.extend({
1516
- edit: true,
1517
- editicon: "ui-icon-pencil",
1518
- add: true,
1519
- addicon:"ui-icon-plus",
1520
- del: true,
1521
- delicon:"ui-icon-trash",
1522
- search: true,
1523
- searchicon:"ui-icon-search",
1524
- refresh: true,
1525
- refreshicon:"ui-icon-refresh",
1526
- refreshstate: 'firstpage',
1527
- view: false,
1528
- viewicon : "ui-icon-document",
1529
- position : "left",
1530
- closeOnEscape : true,
1531
- beforeRefresh : null,
1532
- afterRefresh : null,
1533
- cloneToTop : false
1534
- }, $.jgrid.nav, o ||{});
1535
- return this.each(function() {
1536
- var alertIDs = {themodal:'alertmod',modalhead:'alerthd',modalcontent:'alertcnt'},
1537
- $t = this, vwidth, vheight, twd, tdw;
1538
- if(!$t.grid || typeof elem != 'string') { return; }
1539
- if ($("#"+alertIDs.themodal).html() === null) {
1540
- if (typeof window.innerWidth != 'undefined') {
1541
- vwidth = window.innerWidth;
1542
- vheight = window.innerHeight;
1543
- } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth !== 0) {
1544
- vwidth = document.documentElement.clientWidth;
1545
- vheight = document.documentElement.clientHeight;
1546
- } else {
1547
- vwidth=1024;
1548
- vheight=768;
1549
- }
1550
- createModal(alertIDs,"<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",{gbox:"#gbox_"+$t.p.id,jqModal:true,drag:true,resize:true,caption:o.alertcap,top:vheight/2-25,left:vwidth/2-100,width:200,height:'auto',closeOnEscape:o.closeOnEscape},"","",true);
1551
- }
1552
- var clone = 1;
1553
- if(o.cloneToTop && $t.p.toppager) { clone = 2; }
1554
- for(var i = 0; i<clone; i++) {
1555
- var tbd,
1556
- navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"),
1557
- sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
1558
- pgid, elemids;
1559
- if(i===0) {
1560
- pgid = elem;
1561
- elemids = $t.p.id;
1562
- if(pgid == $t.p.toppager) {
1563
- elemids += "_top";
1564
- clone = 1;
1565
- }
1566
- } else {
1567
- pgid = $t.p.toppager;
1568
- elemids = $t.p.id+"_top";
1569
- }
1570
- if($t.p.direction == "rtl") { $(navtbl).attr("dir","rtl").css("float","right"); }
1571
- if (o.add) {
1572
- pAdd = pAdd || {};
1573
- tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1574
- $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.addicon+"'></span>"+o.addtext+"</div>");
1575
- $("tr",navtbl).append(tbd);
1576
- $(tbd,navtbl)
1577
- .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids})
1578
- .click(function(){
1579
- if (!$(this).hasClass('ui-state-disabled')) {
1580
- if (typeof o.addfunc == 'function') {
1581
- o.addfunc();
1582
- } else {
1583
- $($t).jqGrid("editGridRow","new",pAdd);
1584
- }
1585
- }
1586
- return false;
1587
- }).hover(
1588
- function () {
1589
- if (!$(this).hasClass('ui-state-disabled')) {
1590
- $(this).addClass("ui-state-hover");
1591
- }
1592
- },
1593
- function () {$(this).removeClass("ui-state-hover");}
1594
- );
1595
- tbd = null;
1596
- }
1597
- if (o.edit) {
1598
- tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1599
- pEdit = pEdit || {};
1600
- $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.editicon+"'></span>"+o.edittext+"</div>");
1601
- $("tr",navtbl).append(tbd);
1602
- $(tbd,navtbl)
1603
- .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids})
1604
- .click(function(){
1605
- if (!$(this).hasClass('ui-state-disabled')) {
1606
- var sr = $t.p.selrow;
1607
- if (sr) {
1608
- if(typeof o.editfunc == 'function') {
1609
- o.editfunc(sr);
1610
- } else {
1611
- $($t).jqGrid("editGridRow",sr,pEdit);
1612
- }
1613
- } else {
1614
- viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$t.p.id,jqm:true});
1615
- $("#jqg_alrt").focus();
1616
- }
1617
- }
1618
- return false;
1619
- }).hover(
1620
- function () {
1621
- if (!$(this).hasClass('ui-state-disabled')) {
1622
- $(this).addClass("ui-state-hover");
1623
- }
1624
- },
1625
- function () {$(this).removeClass("ui-state-hover");}
1626
- );
1627
- tbd = null;
1628
- }
1629
- if (o.view) {
1630
- tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1631
- pView = pView || {};
1632
- $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.viewicon+"'></span>"+o.viewtext+"</div>");
1633
- $("tr",navtbl).append(tbd);
1634
- $(tbd,navtbl)
1635
- .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids})
1636
- .click(function(){
1637
- if (!$(this).hasClass('ui-state-disabled')) {
1638
- var sr = $t.p.selrow;
1639
- if (sr) {
1640
- $($t).jqGrid("viewGridRow",sr,pView);
1641
- } else {
1642
- viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$t.p.id,jqm:true});
1643
- $("#jqg_alrt").focus();
1644
- }
1645
- }
1646
- return false;
1647
- }).hover(
1648
- function () {
1649
- if (!$(this).hasClass('ui-state-disabled')) {
1650
- $(this).addClass("ui-state-hover");
1651
- }
1652
- },
1653
- function () {$(this).removeClass("ui-state-hover");}
1654
- );
1655
- tbd = null;
1656
- }
1657
- if (o.del) {
1658
- tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1659
- pDel = pDel || {};
1660
- $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>");
1661
- $("tr",navtbl).append(tbd);
1662
- $(tbd,navtbl)
1663
- .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
1664
- .click(function(){
1665
- if (!$(this).hasClass('ui-state-disabled')) {
1666
- var dr;
1667
- if($t.p.multiselect) {
1668
- dr = $t.p.selarrrow;
1669
- if(dr.length===0) { dr = null; }
1670
- } else {
1671
- dr = $t.p.selrow;
1672
- }
1673
- if(dr){
1674
- if("function" == typeof o.delfunc){
1675
- o.delfunc(dr);
1676
- }else{
1677
- $($t).jqGrid("delGridRow",dr,pDel);
1678
- }
1679
- } else {
1680
- viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$t.p.id,jqm:true}); $("#jqg_alrt").focus();
1681
- }
1682
- }
1683
- return false;
1684
- }).hover(
1685
- function () {
1686
- if (!$(this).hasClass('ui-state-disabled')) {
1687
- $(this).addClass("ui-state-hover");
1688
- }
1689
- },
1690
- function () {$(this).removeClass("ui-state-hover");}
1691
- );
1692
- tbd = null;
1693
- }
1694
- if(o.add || o.edit || o.del || o.view) { $("tr",navtbl).append(sep); }
1695
- if (o.search) {
1696
- tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1697
- pSearch = pSearch || {};
1698
- $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.searchicon+"'></span>"+o.searchtext+"</div>");
1699
- $("tr",navtbl).append(tbd);
1700
- $(tbd,navtbl)
1701
- .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids})
1702
- .click(function(){
1703
- if (!$(this).hasClass('ui-state-disabled')) {
1704
- $($t).jqGrid("searchGrid",pSearch);
1705
- }
1706
- return false;
1707
- }).hover(
1708
- function () {
1709
- if (!$(this).hasClass('ui-state-disabled')) {
1710
- $(this).addClass("ui-state-hover");
1711
- }
1712
- },
1713
- function () {$(this).removeClass("ui-state-hover");}
1714
- );
1715
- tbd = null;
1716
- }
1717
- if (o.refresh) {
1718
- tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1719
- $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.refreshicon+"'></span>"+o.refreshtext+"</div>");
1720
- $("tr",navtbl).append(tbd);
1721
- $(tbd,navtbl)
1722
- .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
1723
- .click(function(){
1724
- if (!$(this).hasClass('ui-state-disabled')) {
1725
- if($.isFunction(o.beforeRefresh)) { o.beforeRefresh(); }
1726
- $t.p.search = false;
1727
- try {
1728
- var gID = $t.p.id;
1729
- $("#fbox_"+gID).searchFilter().reset({"reload":false});
1730
- if($.isFunction($t.clearToolbar)) { $t.clearToolbar(false); }
1731
- } catch (e) {}
1732
- switch (o.refreshstate) {
1733
- case 'firstpage':
1734
- $($t).trigger("reloadGrid", [{page:1}]);
1735
- break;
1736
- case 'current':
1737
- $($t).trigger("reloadGrid", [{current:true}]);
1738
- break;
1739
- }
1740
- if($.isFunction(o.afterRefresh)) { o.afterRefresh(); }
1741
- }
1742
- return false;
1743
- }).hover(
1744
- function () {
1745
- if (!$(this).hasClass('ui-state-disabled')) {
1746
- $(this).addClass("ui-state-hover");
1747
- }
1748
- },
1749
- function () {$(this).removeClass("ui-state-hover");}
1750
- );
1751
- tbd = null;
1752
- }
1753
- tdw = $(".ui-jqgrid").css("font-size") || "11px";
1754
- $('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
1755
- twd = $(navtbl).clone().appendTo("#testpg2").width();
1756
- $("#testpg2").remove();
1757
- $(pgid+"_"+o.position,pgid).append(navtbl);
1758
- if($t.p._nvtd) {
1759
- if(twd > $t.p._nvtd[0] ) {
1760
- $(pgid+"_"+o.position,pgid).width(twd);
1761
- $t.p._nvtd[0] = twd;
1762
- }
1763
- $t.p._nvtd[1] = twd;
1764
- }
1765
- tdw =null; twd=null; navtbl =null;
1766
- }
1767
- });
1768
- },
1769
- navButtonAdd : function (elem, p) {
1770
- p = $.extend({
1771
- caption : "newButton",
1772
- title: '',
1773
- buttonicon : 'ui-icon-newwin',
1774
- onClickButton: null,
1775
- position : "last",
1776
- cursor : 'pointer'
1777
- }, p ||{});
1778
- return this.each(function() {
1779
- if( !this.grid) { return; }
1780
- if( elem.indexOf("#") !== 0) { elem = "#"+elem; }
1781
- var findnav = $(".navtable",elem)[0], $t = this;
1782
- if (findnav) {
1783
- var tbd = $("<td></td>");
1784
- if(p.buttonicon.toString().toUpperCase() == "NONE") {
1785
- $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>"+p.caption+"</div>");
1786
- } else {
1787
- $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><span class='ui-icon "+p.buttonicon+"'></span>"+p.caption+"</div>");
1788
- }
1789
- if(p.id) {$(tbd).attr("id",p.id);}
1790
- if(p.position=='first'){
1791
- if(findnav.rows[0].cells.length ===0 ) {
1792
- $("tr",findnav).append(tbd);
1793
- } else {
1794
- $("tr td:eq(0)",findnav).before(tbd);
1795
- }
1796
- } else {
1797
- $("tr",findnav).append(tbd);
1798
- }
1799
- $(tbd,findnav)
1800
- .attr("title",p.title || "")
1801
- .click(function(e){
1802
- if (!$(this).hasClass('ui-state-disabled')) {
1803
- if ($.isFunction(p.onClickButton) ) { p.onClickButton.call($t,e); }
1804
- }
1805
- return false;
1806
- })
1807
- .hover(
1808
- function () {
1809
- if (!$(this).hasClass('ui-state-disabled')) {
1810
- $(this).addClass('ui-state-hover');
1811
- }
1812
- },
1813
- function () {$(this).removeClass("ui-state-hover");}
1814
- );
1815
- }
1816
- });
1817
- },
1818
- navSeparatorAdd:function (elem,p) {
1819
- p = $.extend({
1820
- sepclass : "ui-separator",
1821
- sepcontent: ''
1822
- }, p ||{});
1823
- return this.each(function() {
1824
- if( !this.grid) { return; }
1825
- if( elem.indexOf("#") !== 0) { elem = "#"+elem; }
1826
- var findnav = $(".navtable",elem)[0];
1827
- if(findnav) {
1828
- var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>";
1829
- $("tr",findnav).append(sep);
1830
- }
1831
- });
1832
- },
1833
- GridToForm : function( rowid, formid ) {
1834
- return this.each(function(){
1835
- var $t = this;
1836
- if (!$t.grid) { return; }
1837
- var rowdata = $($t).jqGrid("getRowData",rowid);
1838
- if (rowdata) {
1839
- for(var i in rowdata) {
1840
- if ( $("[name="+i+"]",formid).is("input:radio") || $("[name="+i+"]",formid).is("input:checkbox")) {
1841
- $("[name="+i+"]",formid).each( function() {
1842
- if( $(this).val() == rowdata[i] ) {
1843
- $(this).attr("checked","checked");
1844
- } else {
1845
- $(this).attr("checked","");
1846
- }
1847
- });
1848
- } else {
1849
- // this is very slow on big table and form.
1850
- $("[name="+i+"]",formid).val(rowdata[i]);
1851
- }
1852
- }
1853
- }
1854
- });
1855
- },
1856
- FormToGrid : function(rowid, formid, mode, position){
1857
- return this.each(function() {
1858
- var $t = this;
1859
- if(!$t.grid) { return; }
1860
- if(!mode) { mode = 'set'; }
1861
- if(!position) { position = 'first'; }
1862
- var fields = $(formid).serializeArray();
1863
- var griddata = {};
1864
- $.each(fields, function(i, field){
1865
- griddata[field.name] = field.value;
1866
- });
1867
- if(mode=='add') { $($t).jqGrid("addRowData",rowid,griddata, position); }
1868
- else if(mode=='set') { $($t).jqGrid("setRowData",rowid,griddata); }
1869
- });
1870
- }
1871
- });
1872
- })(jQuery);
1
+ ;(function($){
2
+ /**
3
+ * jqGrid extension for form editing Grid Data
4
+ * Tony Tomov tony@trirand.com
5
+ * http://trirand.com/blog/
6
+ * Dual licensed under the MIT and GPL licenses:
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ * http://www.gnu.org/licenses/gpl-2.0.html
9
+ **/
10
+ var rp_ge = null;
11
+ $.jgrid.extend({
12
+ searchGrid : function (p) {
13
+ p = $.extend({
14
+ recreateFilter: false,
15
+ drag: true,
16
+ sField:'searchField',
17
+ sValue:'searchString',
18
+ sOper: 'searchOper',
19
+ sFilter: 'filters',
20
+ loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
21
+ beforeShowSearch: null,
22
+ afterShowSearch : null,
23
+ onInitializeSearch: null,
24
+ closeAfterSearch : false,
25
+ closeAfterReset: false,
26
+ closeOnEscape : false,
27
+ multipleSearch : false,
28
+ cloneSearchRowOnAdd: true,
29
+ // translation
30
+ // if you want to change or remove the order change it in sopt
31
+ // ['bw','eq','ne','lt','le','gt','ge','ew','cn']
32
+ sopt: null,
33
+ // Note: stringResult is intentionally declared "undefined by default".
34
+ // you are velcome to define stringResult expressly in the options you pass to searchGrid()
35
+ // stringResult is a "safeguard" measure to insure we post sensible data when communicated as form-encoded
36
+ // see http://github.com/tonytomov/jqGrid/issues/#issue/36
37
+ //
38
+ // If this value is not expressly defined in the incoming options,
39
+ // lower in the code we will infer the value based on value of multipleSearch
40
+ stringResult: undefined,
41
+ onClose : null,
42
+ // useDataProxy allows ADD, EDIT and DEL code to bypass calling $.ajax
43
+ // directly when grid's 'dataProxy' property (grid.p.dataProxy) is a function.
44
+ // Used for "editGridRow" and "delGridRow" below and automatically flipped to TRUE
45
+ // when ajax setting's 'url' (grid's 'editurl') property is undefined.
46
+ // When 'useDataProxy' is true, instead of calling $.ajax.call(gridDOMobj, o, i) we call
47
+ // gridDOMobj.p.dataProxy.call(gridDOMobj, o, i)
48
+ //
49
+ // Behavior is extremely similar to when 'datatype' is a function, but arguments are slightly different.
50
+ // Normally the following is fed to datatype.call(a, b, c):
51
+ // a = Pointer to grid's table DOM element, b = grid.p.postdata, c = "load_"+grid's ID
52
+ // In cases of "edit" and "del" the following is fed:
53
+ // a = Pointer to grid's table DOM element (same),
54
+ // b = extended Ajax Options including postdata in "data" property. (different object type)
55
+ // c = "set_"+grid's ID in case of "edit" and "del_"+grid's ID in case of "del" (same type, different content)
56
+ // The major difference is that complete ajax options object, with attached "complete" and "error"
57
+ // callback functions is fed instead of only post data.
58
+ // This allows you to emulate a $.ajax call (including calling "complete"/"error"),
59
+ // while retrieving the data locally in the browser.
60
+ useDataProxy: false,
61
+ overlay : true
62
+ }, $.jgrid.search, p || {});
63
+ return this.each(function() {
64
+ var $t = this;
65
+ if(!$t.grid) {return;}
66
+ var fid = "fbox_"+$t.p.id,
67
+ showFrm = true;
68
+ function applyDefaultFilters(gridDOMobj, filterSettings) {
69
+ /*
70
+ gridDOMobj = ointer to grid DOM object ( $(#list)[0] )
71
+ What we need from gridDOMobj:
72
+ gridDOMobj.SearchFilter is the pointer to the Search box, once it's created.
73
+ gridDOMobj.p.postData - dictionary of post settings. These can be overriden at grid creation to
74
+ contain default filter settings. We will parse these and will populate the search with defaults.
75
+ filterSettings - same settings object you (would) pass to $().jqGrid('searchGrid', filterSettings);
76
+ */
77
+
78
+ // Pulling default filter settings out of postData property of grid's properties.:
79
+ var defaultFilters = gridDOMobj.p.postData[filterSettings.sFilter];
80
+ // example of what we might get: {"groupOp":"and","rules":[{"field":"amount","op":"eq","data":"100"}]}
81
+ // suppose we have imported this with grid import, the this is a string.
82
+ if(typeof(defaultFilters) == "string") {
83
+ defaultFilters = $.jgrid.parse(defaultFilters);
84
+ }
85
+ if (defaultFilters) {
86
+ if (defaultFilters.groupOp) {
87
+ gridDOMobj.SearchFilter.setGroupOp(defaultFilters.groupOp);
88
+ }
89
+ if (defaultFilters.rules) {
90
+ var f, i = 0, li = defaultFilters.rules.length, success = false;
91
+ for (; i < li; i++) {
92
+ f = defaultFilters.rules[i];
93
+ // we are not trying to counter all issues with filter declaration here. Just the basics to avoid lookup exceptions.
94
+ if (f.field !== undefined && f.op !== undefined && f.data !== undefined) {
95
+ success = gridDOMobj.SearchFilter.setFilter({
96
+ 'sfref':gridDOMobj.SearchFilter.$.find(".sf:last"),
97
+ 'filter':$.extend({},f)
98
+ });
99
+ if (success) { gridDOMobj.SearchFilter.add(); }
100
+ }
101
+ }
102
+ }
103
+ }
104
+ } // end of applyDefaultFilters
105
+ function hideFilter(selector) {
106
+ if(p.onClose){
107
+ var fclm = p.onClose(selector);
108
+ if(typeof fclm == 'boolean' && !fclm) { return; }
109
+ }
110
+ selector.hide();
111
+ if(p.overlay === true) {
112
+ $(".jqgrid-overlay:first","#gbox_"+$t.p.id).hide();
113
+ }
114
+ }
115
+ function showFilter(){
116
+ var fl = $(".ui-searchFilter").length;
117
+ if(fl > 1) {
118
+ var zI = $("#"+fid).css("zIndex");
119
+ $("#"+fid).css({zIndex:parseInt(zI,10)+fl});
120
+ }
121
+ $("#"+fid).show();
122
+ if(p.overlay === true) {
123
+ $(".jqgrid-overlay:first","#gbox_"+$t.p.id).show();
124
+ }
125
+ try{$(':input:visible',"#"+fid)[0].focus();}catch(_){}
126
+ }
127
+ function searchFilters(filters) {
128
+ var hasFilters = (filters !== undefined),
129
+ grid = $("#"+$t.p.id),
130
+ sdata={};
131
+ if(p.multipleSearch===false) {
132
+ sdata[p.sField] = filters.rules[0].field;
133
+ sdata[p.sValue] = filters.rules[0].data;
134
+ sdata[p.sOper] = filters.rules[0].op;
135
+ } else {
136
+ sdata[p.sFilter] = filters;
137
+ }
138
+ grid[0].p.search = hasFilters;
139
+ $.extend(grid[0].p.postData,sdata);
140
+ grid.trigger("reloadGrid",[{page:1}]);
141
+ if(p.closeAfterSearch) { hideFilter($("#"+fid)); }
142
+ }
143
+ function resetFilters(op) {
144
+ var reload = op && op.hasOwnProperty("reload") ? op.reload : true,
145
+ grid = $("#"+$t.p.id),
146
+ sdata={};
147
+ grid[0].p.search = false;
148
+ if(p.multipleSearch===false) {
149
+ sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
150
+ } else {
151
+ sdata[p.sFilter] = "";
152
+ }
153
+ $.extend(grid[0].p.postData,sdata);
154
+ if(reload) {
155
+ grid.trigger("reloadGrid",[{page:1}]);
156
+ }
157
+ if(p.closeAfterReset) { hideFilter($("#"+fid)); }
158
+ }
159
+ if($.fn.searchFilter) {
160
+ if(p.recreateFilter===true) {$("#"+fid).remove();}
161
+ if( $("#"+fid).html() != null ) {
162
+ if ( $.isFunction(p.beforeShowSearch) ) {
163
+ showFrm = p.beforeShowSearch($("#"+fid));
164
+ if(typeof(showFrm) == "undefined") {
165
+ showFrm = true;
166
+ }
167
+ }
168
+ if(showFrm === false) { return; }
169
+ showFilter();
170
+ if( $.isFunction(p.afterShowSearch) ) { p.afterShowSearch($("#"+fid)); }
171
+ } else {
172
+ var fields = [],
173
+ colNames = $("#"+$t.p.id).jqGrid("getGridParam","colNames"),
174
+ colModel = $("#"+$t.p.id).jqGrid("getGridParam","colModel"),
175
+ stempl = ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'],
176
+ j,pos,k,oprtr=[];
177
+ if (p.sopt !==null) {
178
+ k=0;
179
+ for(j=0;j<p.sopt.length;j++) {
180
+ if( (pos= $.inArray(p.sopt[j],stempl)) != -1 ){
181
+ oprtr[k] = {op:p.sopt[j],text: p.odata[pos]};
182
+ k++;
183
+ }
184
+ }
185
+ } else {
186
+ for(j=0;j<stempl.length;j++) {
187
+ oprtr[j] = {op:stempl[j],text: p.odata[j]};
188
+ }
189
+ }
190
+ $.each(colModel, function(i, v) {
191
+ var searchable = (typeof v.search === 'undefined') ? true: v.search ,
192
+ hidden = (v.hidden === true),
193
+ soptions = $.extend({}, {text: colNames[i], itemval: v.index || v.name}, this.searchoptions),
194
+ ignoreHiding = (soptions.searchhidden === true);
195
+ if(typeof soptions.sopt !== 'undefined') {
196
+ k=0;
197
+ soptions.ops =[];
198
+ if(soptions.sopt.length>0) {
199
+ for(j=0;j<soptions.sopt.length;j++) {
200
+ if( (pos= $.inArray(soptions.sopt[j],stempl)) != -1 ){
201
+ soptions.ops[k] = {op:soptions.sopt[j],text: p.odata[pos]};
202
+ k++;
203
+ }
204
+ }
205
+ }
206
+ }
207
+ if(typeof(this.stype) === 'undefined') { this.stype='text'; }
208
+ if(this.stype == 'select') {
209
+ if ( soptions.dataUrl !== undefined) {}
210
+ else {
211
+ var eov;
212
+ if(soptions.value) {
213
+ eov = soptions.value;
214
+ } else if(this.editoptions) {
215
+ eov = this.editoptions.value;
216
+ }
217
+ if(eov) {
218
+ soptions.dataValues =[];
219
+ if(typeof(eov) === 'string') {
220
+ var so = eov.split(";"),sv;
221
+ for(j=0;j<so.length;j++) {
222
+ sv = so[j].split(":");
223
+ soptions.dataValues[j] ={value:sv[0],text:sv[1]};
224
+ }
225
+ } else if (typeof(eov) === 'object') {
226
+ j=0;
227
+ for (var key in eov) {
228
+ if(eov.hasOwnProperty(key)) {
229
+ soptions.dataValues[j] ={value:key,text:eov[key]};
230
+ j++;
231
+ }
232
+ }
233
+ }
234
+ }
235
+ }
236
+ }
237
+ if ((ignoreHiding && searchable) || (searchable && !hidden)) {
238
+ fields.push(soptions);
239
+ }
240
+ });
241
+ if(fields.length>0){
242
+ $("<div id='"+fid+"' role='dialog' tabindex='-1'></div>").insertBefore("#gview_"+$t.p.id);
243
+ // Before we create searchFilter we need to decide if we want to get back a string or a JS object.
244
+ // see http://github.com/tonytomov/jqGrid/issues/#issue/36 for background on the issue.
245
+ // If p.stringResult is defined, it was explisitly passed to us by user. Honor the choice, whatever it is.
246
+ if (p.stringResult===undefined) {
247
+ // to provide backward compatibility, inferring stringResult value from multipleSearch
248
+ p.stringResult = p.multipleSearch;
249
+ }
250
+ // we preserve the return value here to retain access to .add() and other good methods of search form.
251
+ $t.SearchFilter = $("#"+fid).searchFilter(fields, { groupOps: p.groupOps, operators: oprtr, onClose:hideFilter, resetText: p.Reset, searchText: p.Find, windowTitle: p.caption, rulesText:p.rulesText, matchText:p.matchText, onSearch: searchFilters, onReset: resetFilters,stringResult:p.stringResult, ajaxSelectOptions: $.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions ||{}), clone: p.cloneSearchRowOnAdd });
252
+ $(".ui-widget-overlay","#"+fid).remove();
253
+ if($t.p.direction=="rtl") { $(".ui-closer","#"+fid).css("float","left"); }
254
+ if (p.drag===true) {
255
+ $("#"+fid+" table thead tr:first td:first").css('cursor','move');
256
+ if(jQuery.fn.jqDrag) {
257
+ $("#"+fid).jqDrag($("#"+fid+" table thead tr:first td:first"));
258
+ } else {
259
+ try {
260
+ $("#"+fid).draggable({handle: $("#"+fid+" table thead tr:first td:first")});
261
+ } catch (e) {}
262
+ }
263
+ }
264
+ if(p.multipleSearch === false) {
265
+ $(".ui-del, .ui-add, .ui-del, .ui-add-last, .matchText, .rulesText", "#"+fid).hide();
266
+ $("select[name='groupOp']","#"+fid).hide();
267
+ }
268
+ if (p.multipleSearch === true && p.loadDefaults === true) {
269
+ applyDefaultFilters($t, p);
270
+ }
271
+ if ( $.isFunction(p.onInitializeSearch) ) { p.onInitializeSearch( $("#"+fid) ); }
272
+ if ( $.isFunction(p.beforeShowSearch) ) {
273
+ showFrm = p.beforeShowSearch($("#"+fid));
274
+ if(typeof(showFrm) == "undefined") {
275
+ showFrm = true;
276
+ }
277
+ }
278
+ if(showFrm === false) { return; }
279
+ showFilter();
280
+ if( $.isFunction(p.afterShowSearch) ) { p.afterShowSearch($("#"+fid)); }
281
+ if(p.closeOnEscape===true){
282
+ $("#"+fid).keydown( function( e ) {
283
+ if( e.which == 27 ) {
284
+ hideFilter($("#"+fid));
285
+ }
286
+ if (e.which == 13) {
287
+ $(".ui-search", this).click();
288
+ }
289
+ });
290
+ }
291
+ }
292
+ }
293
+ }
294
+ });
295
+ },
296
+ editGridRow : function(rowid, p){
297
+ p = $.extend({
298
+ top : 0,
299
+ left: 0,
300
+ width: 300,
301
+ height: 'auto',
302
+ dataheight: 'auto',
303
+ modal: false,
304
+ overlay : 10,
305
+ drag: true,
306
+ resize: true,
307
+ url: null,
308
+ mtype : "POST",
309
+ clearAfterAdd :true,
310
+ closeAfterEdit : false,
311
+ reloadAfterSubmit : true,
312
+ onInitializeForm: null,
313
+ beforeInitData: null,
314
+ beforeShowForm: null,
315
+ afterShowForm: null,
316
+ beforeSubmit: null,
317
+ afterSubmit: null,
318
+ onclickSubmit: null,
319
+ afterComplete: null,
320
+ onclickPgButtons : null,
321
+ afterclickPgButtons: null,
322
+ editData : {},
323
+ recreateForm : false,
324
+ jqModal : true,
325
+ closeOnEscape : false,
326
+ addedrow : "first",
327
+ topinfo : '',
328
+ bottominfo: '',
329
+ saveicon : [],
330
+ closeicon : [],
331
+ savekey: [false,13],
332
+ navkeys: [false,38,40],
333
+ checkOnSubmit : false,
334
+ checkOnUpdate : false,
335
+ _savedData : {},
336
+ processing : false,
337
+ onClose : null,
338
+ ajaxEditOptions : {},
339
+ serializeEditData : null,
340
+ viewPagerButtons : true
341
+ }, $.jgrid.edit, p || {});
342
+ rp_ge = p;
343
+ return this.each(function(){
344
+ var $t = this;
345
+ if (!$t.grid || !rowid) { return; }
346
+ var gID = $t.p.id,
347
+ frmgr = "FrmGrid_"+gID,frmtb = "TblGrid_"+gID,
348
+ IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr},
349
+ onBeforeShow = $.isFunction(rp_ge.beforeShowForm) ? rp_ge.beforeShowForm : false,
350
+ onAfterShow = $.isFunction(rp_ge.afterShowForm) ? rp_ge.afterShowForm : false,
351
+ onBeforeInit = $.isFunction(rp_ge.beforeInitData) ? rp_ge.beforeInitData : false,
352
+ onInitializeForm = $.isFunction(rp_ge.onInitializeForm) ? rp_ge.onInitializeForm : false,
353
+ copydata = null,
354
+ showFrm = true,
355
+ maxCols = 1, maxRows=0, postdata, extpost, newData, diff;
356
+ if (rowid=="new") {
357
+ rowid = "_empty";
358
+ p.caption=p.addCaption;
359
+ } else {
360
+ p.caption=p.editCaption;
361
+ }
362
+ if(p.recreateForm===true && $("#"+IDs.themodal).html() != null) {
363
+ $("#"+IDs.themodal).remove();
364
+ }
365
+ var closeovrl = true;
366
+ if(p.checkOnUpdate && p.jqModal && !p.modal) {
367
+ closeovrl = false;
368
+ }
369
+ function getFormData(){
370
+ $(".FormElement", "#"+frmtb).each(function(i) {
371
+ var celm = $(".customelement", this);
372
+ if (celm.length) {
373
+ var elem = celm[0], nm = $(elem).attr('name');
374
+ $.each($t.p.colModel, function(i,n){
375
+ if(this.name == nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) {
376
+ try {
377
+ postdata[nm] = this.editoptions.custom_value($("#"+nm,"#"+frmtb),'get');
378
+ if (postdata[nm] === undefined) { throw "e1"; }
379
+ } catch (e) {
380
+ if (e=="e1") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose);}
381
+ else { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); }
382
+ }
383
+ return true;
384
+ }
385
+ });
386
+ } else {
387
+ switch ($(this).get(0).type) {
388
+ case "checkbox":
389
+ if($(this).attr("checked")) {
390
+ postdata[this.name]= $(this).val();
391
+ }else {
392
+ var ofv = $(this).attr("offval");
393
+ postdata[this.name]= ofv;
394
+ }
395
+ break;
396
+ case "select-one":
397
+ postdata[this.name]= $("option:selected",this).val();
398
+ extpost[this.name]= $("option:selected",this).text();
399
+ break;
400
+ case "select-multiple":
401
+ postdata[this.name]= $(this).val();
402
+ if(postdata[this.name]) { postdata[this.name] = postdata[this.name].join(","); }
403
+ else { postdata[this.name] =""; }
404
+ var selectedText = [];
405
+ $("option:selected",this).each(
406
+ function(i,selected){
407
+ selectedText[i] = $(selected).text();
408
+ }
409
+ );
410
+ extpost[this.name]= selectedText.join(",");
411
+ break;
412
+ case "password":
413
+ case "text":
414
+ case "textarea":
415
+ case "button":
416
+ postdata[this.name] = $(this).val();
417
+
418
+ break;
419
+ }
420
+ if($t.p.autoencode) { postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]); }
421
+ }
422
+ });
423
+ return true;
424
+ }
425
+ function createData(rowid,obj,tb,maxcols){
426
+ var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false,
427
+ tdtmpl = "<td class='CaptionTD'>&#160;</td><td class='DataTD'>&#160;</td>", tmpl=""; //*2
428
+ for (var i =1;i<=maxcols;i++) {
429
+ tmpl += tdtmpl;
430
+ }
431
+ if(rowid != '_empty') {
432
+ ind = $(obj).jqGrid("getInd",rowid);
433
+ }
434
+ $(obj.p.colModel).each( function(i) {
435
+ nm = this.name;
436
+ // hidden fields are included in the form
437
+ if(this.editrules && this.editrules.edithidden === true) {
438
+ hc = false;
439
+ } else {
440
+ hc = this.hidden === true ? true : false;
441
+ }
442
+ dc = hc ? "style='display:none'" : "";
443
+ if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') {
444
+ if(ind === false) {
445
+ tmp = "";
446
+ } else {
447
+ if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
448
+ tmp = $("td:eq("+i+")",obj.rows[ind]).text();
449
+ } else {
450
+ try {
451
+ tmp = $.unformat($("td:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
452
+ } catch (_) {
453
+ tmp = $("td:eq("+i+")",obj.rows[ind]).html();
454
+ }
455
+ }
456
+ }
457
+ var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}),
458
+ frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}),
459
+ rp = parseInt(frmopt.rowpos,10) || cnt+1,
460
+ cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
461
+ if(rowid == "_empty" && opt.defaultValue ) {
462
+ tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue;
463
+ }
464
+ if(!this.edittype) { this.edittype = "text"; }
465
+ if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
466
+ elc = $.jgrid.createEl(this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
467
+ if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
468
+ if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
469
+ if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) { rp_ge._savedData[nm] = tmp; }
470
+ $(elc).addClass("FormElement");
471
+ if(this.edittype == 'text' || this.edittype == 'textarea') {
472
+ $(elc).addClass("ui-widget-content ui-corner-all");
473
+ }
474
+ trdata = $(tb).find("tr[rowpos="+rp+"]");
475
+ if(frmopt.rowabove) {
476
+ var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
477
+ $(tb).append(newdata);
478
+ newdata[0].rp = rp;
479
+ }
480
+ if ( trdata.length===0 ) {
481
+ trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm);
482
+ $(trdata).append(tmpl);
483
+ $(tb).append(trdata);
484
+ trdata[0].rp = rp;
485
+ }
486
+ $("td:eq("+(cp-2)+")",trdata[0]).html( typeof frmopt.label === 'undefined' ? obj.p.colNames[i]: frmopt.label);
487
+ $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix);
488
+ retpos[cnt] = i;
489
+ cnt++;
490
+ }
491
+ });
492
+ if( cnt > 0) {
493
+ var idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+ (maxcols*2-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='"+obj.p.id+"_id' value='"+rowid+"'/></td></tr>");
494
+ idrow[0].rp = cnt+999;
495
+ $(tb).append(idrow);
496
+ if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) { rp_ge._savedData[obj.p.id+"_id"] = rowid; }
497
+ }
498
+ return retpos;
499
+ }
500
+ function fillData(rowid,obj,fmid){
501
+ var nm,cnt=0,tmp, fld,opt,vl,vlc;
502
+ if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) {rp_ge._savedData = {};rp_ge._savedData[obj.p.id+"_id"]=rowid;}
503
+ var cm = obj.p.colModel;
504
+ if(rowid == '_empty') {
505
+ $(cm).each(function(i){
506
+ nm = this.name;
507
+ opt = $.extend({}, this.editoptions || {} );
508
+ fld = $("#"+$.jgrid.jqID(nm),"#"+fmid);
509
+ if(fld[0] != null) {
510
+ vl = "";
511
+ if(opt.defaultValue ) {
512
+ vl = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue;
513
+ if(fld[0].type=='checkbox') {
514
+ vlc = vl.toLowerCase();
515
+ if(vlc.search(/(false|0|no|off|undefined)/i)<0 && vlc!=="") {
516
+ fld[0].checked = true;
517
+ fld[0].defaultChecked = true;
518
+ fld[0].value = vl;
519
+ } else {
520
+ fld.attr({checked:"",defaultChecked:""});
521
+ }
522
+ } else {fld.val(vl); }
523
+ } else {
524
+ if( fld[0].type=='checkbox' ) {
525
+ fld[0].checked = false;
526
+ fld[0].defaultChecked = false;
527
+ vl = $(fld).attr("offval");
528
+ } else if (fld[0].type && fld[0].type.substr(0,6)=='select') {
529
+ fld[0].selectedIndex = 0;
530
+ } else {
531
+ fld.val(vl);
532
+ }
533
+ }
534
+ if(rp_ge.checkOnSubmit===true || rp_ge.checkOnUpdate) { rp_ge._savedData[nm] = vl; }
535
+ }
536
+ });
537
+ $("#id_g","#"+fmid).val(rowid);
538
+ return;
539
+ }
540
+ var tre = $(obj).jqGrid("getInd",rowid,true);
541
+ if(!tre) { return; }
542
+ $('td',tre).each( function(i) {
543
+ nm = cm[i].name;
544
+ // hidden fields are included in the form
545
+ if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) {
546
+ if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
547
+ tmp = $(this).text();
548
+ } else {
549
+ try {
550
+ tmp = $.unformat($(this),{rowId:rowid, colModel:cm[i]},i);
551
+ } catch (_) {
552
+ tmp = $(this).html();
553
+ }
554
+ }
555
+ if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
556
+ if(rp_ge.checkOnSubmit===true || rp_ge.checkOnUpdate) { rp_ge._savedData[nm] = tmp; }
557
+ nm = $.jgrid.jqID(nm);
558
+ switch (cm[i].edittype) {
559
+ case "password":
560
+ case "text":
561
+ case "button" :
562
+ case "image":
563
+ $("#"+nm,"#"+fmid).val(tmp);
564
+ break;
565
+ case "textarea":
566
+ if(tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
567
+ $("#"+nm,"#"+fmid).val(tmp);
568
+ break;
569
+ case "select":
570
+ var opv = tmp.split(",");
571
+ opv = $.map(opv,function(n){return $.trim(n);});
572
+ $("#"+nm+" option","#"+fmid).each(function(j){
573
+ if (!cm[i].editoptions.multiple && (opv[0] == $.trim($(this).text()) || opv[0] == $.trim($(this).val())) ){
574
+ this.selected= true;
575
+ } else if (cm[i].editoptions.multiple){
576
+ if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){
577
+ this.selected = true;
578
+ }else{
579
+ this.selected = false;
580
+ }
581
+ } else {
582
+ this.selected = false;
583
+ }
584
+ });
585
+ break;
586
+ case "checkbox":
587
+ tmp = tmp+"";
588
+ if(cm[i].editoptions && cm[i].editoptions.value) {
589
+ var cb = cm[i].editoptions.value.split(":");
590
+ if(cb[0] == tmp) {
591
+ $("#"+nm,"#"+fmid).attr("checked",true);
592
+ $("#"+nm,"#"+fmid).attr("defaultChecked",true); //ie
593
+ } else {
594
+ $("#"+nm,"#"+fmid).attr("checked",false);
595
+ $("#"+nm,"#"+fmid).attr("defaultChecked",""); //ie
596
+ }
597
+ } else {
598
+ tmp = tmp.toLowerCase();
599
+ if(tmp.search(/(false|0|no|off|undefined)/i)<0 && tmp!=="") {
600
+ $("#"+nm,"#"+fmid).attr("checked",true);
601
+ $("#"+nm,"#"+fmid).attr("defaultChecked",true); //ie
602
+ } else {
603
+ $("#"+nm,"#"+fmid).attr("checked",false);
604
+ $("#"+nm,"#"+fmid).attr("defaultChecked",""); //ie
605
+ }
606
+ }
607
+ break;
608
+ case 'custom' :
609
+ try {
610
+ if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
611
+ cm[i].editoptions.custom_value($("#"+nm,"#"+fmid),'set',tmp);
612
+ } else { throw "e1"; }
613
+ } catch (e) {
614
+ if (e=="e1") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose);}
615
+ else { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); }
616
+ }
617
+ break;
618
+ }
619
+ cnt++;
620
+ }
621
+ });
622
+ if(cnt>0) { $("#id_g","#"+frmtb).val(rowid); }
623
+ }
624
+ function postIt() {
625
+ var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper;
626
+ if($.isFunction(rp_ge.beforeCheckValues)) {
627
+ var retvals = rp_ge.beforeCheckValues(postdata,$("#"+frmgr),postdata[$t.p.id+"_id"] == "_empty" ? opers.addoper : opers.editoper);
628
+ if(retvals && typeof(retvals) === 'object') { postdata = retvals; }
629
+ }
630
+ for( var key in postdata ){
631
+ if(postdata.hasOwnProperty(key)) {
632
+ ret = $.jgrid.checkValues(postdata[key],key,$t);
633
+ if(ret[0] === false) { break; }
634
+ }
635
+ }
636
+ if(ret[0]) {
637
+ if( $.isFunction( rp_ge.onclickSubmit)) { onCS = rp_ge.onclickSubmit(rp_ge,postdata) || {}; }
638
+ if( $.isFunction(rp_ge.beforeSubmit)) { ret = rp_ge.beforeSubmit(postdata,$("#"+frmgr)); }
639
+ }
640
+
641
+ if(ret[0] && !rp_ge.processing) {
642
+ rp_ge.processing = true;
643
+ $("#sData", "#"+frmtb+"_2").addClass('ui-state-active');
644
+ oper = opers.oper;
645
+ idname = opers.id;
646
+ // we add to pos data array the action - the name is oper
647
+ postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) == "_empty") ? opers.addoper : opers.editoper;
648
+ if(postdata[oper] != opers.addoper) {
649
+ postdata[idname] = postdata[$t.p.id+"_id"];
650
+ } else {
651
+ // check to see if we have allredy this field in the form and if yes lieve it
652
+ if( postdata[idname] === undefined ) { postdata[idname] = postdata[$t.p.id+"_id"]; }
653
+ }
654
+ delete postdata[$t.p.id+"_id"];
655
+ postdata = $.extend(postdata,rp_ge.editData,onCS);
656
+
657
+ var ajaxOptions = $.extend({
658
+ url: rp_ge.url ? rp_ge.url : $($t).jqGrid('getGridParam','editurl'),
659
+ type: rp_ge.mtype,
660
+ data: $.isFunction(rp_ge.serializeEditData) ? rp_ge.serializeEditData(postdata) : postdata,
661
+ complete:function(data,Status){
662
+ if(Status != "success") {
663
+ ret[0] = false;
664
+ if ($.isFunction(rp_ge.errorTextFormat)) {
665
+ ret[1] = rp_ge.errorTextFormat(data);
666
+ } else {
667
+ ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status;
668
+ }
669
+ } else {
670
+ // data is posted successful
671
+ // execute aftersubmit with the returned data from server
672
+ if( $.isFunction(rp_ge.afterSubmit) ) {
673
+ ret = rp_ge.afterSubmit(data,postdata);
674
+ }
675
+ }
676
+ if(ret[0] === false) {
677
+ $("#FormError>td","#"+frmtb).html(ret[1]);
678
+ $("#FormError","#"+frmtb).show();
679
+ } else {
680
+ // remove some values if formattaer select or checkbox
681
+ $.each($t.p.colModel, function(i,n){
682
+ if(extpost[this.name] && this.formatter && this.formatter=='select') {
683
+ try {delete extpost[this.name];} catch (e) {}
684
+ }
685
+ });
686
+ postdata = $.extend(postdata,extpost);
687
+ if($t.p.autoencode) {
688
+ $.each(postdata,function(n,v){
689
+ postdata[n] = $.jgrid.htmlDecode(v);
690
+ });
691
+ }
692
+ rp_ge.reloadAfterSubmit = rp_ge.reloadAfterSubmit && $t.p.datatype != "local";
693
+ // the action is add
694
+ if(postdata[oper] == opers.addoper ) {
695
+ //id processing
696
+ // user not set the id ret[2]
697
+ if(!ret[2]) { ret[2] = (parseInt($t.p.records,10)+1)+""; }
698
+ postdata[idname] = ret[2];
699
+ if(rp_ge.closeAfterAdd) {
700
+ if(rp_ge.reloadAfterSubmit) { $($t).trigger("reloadGrid"); }
701
+ else {
702
+ $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
703
+ $($t).jqGrid("setSelection",ret[2]);
704
+ }
705
+ $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose});
706
+ } else if (rp_ge.clearAfterAdd) {
707
+ if(rp_ge.reloadAfterSubmit) { $($t).trigger("reloadGrid"); }
708
+ else { $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow); }
709
+ fillData("_empty",$t,frmgr);
710
+ } else {
711
+ if(rp_ge.reloadAfterSubmit) { $($t).trigger("reloadGrid"); }
712
+ else { $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow); }
713
+ }
714
+ } else {
715
+ // the action is update
716
+ if(rp_ge.reloadAfterSubmit) {
717
+ $($t).trigger("reloadGrid");
718
+ if( !rp_ge.closeAfterEdit ) { setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000); }
719
+ } else {
720
+ if($t.p.treeGrid === true) {
721
+ $($t).jqGrid("setTreeRow",postdata[idname],postdata);
722
+ } else {
723
+ $($t).jqGrid("setRowData",postdata[idname],postdata);
724
+ }
725
+ }
726
+ if(rp_ge.closeAfterEdit) { $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose}); }
727
+ }
728
+ if($.isFunction(rp_ge.afterComplete)) {
729
+ copydata = data;
730
+ setTimeout(function(){rp_ge.afterComplete(copydata,postdata,$("#"+frmgr));copydata=null;},500);
731
+ }
732
+ }
733
+ rp_ge.processing=false;
734
+ if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) {
735
+ $("#"+frmgr).data("disabled",false);
736
+ if(rp_ge._savedData[$t.p.id+"_id"] !="_empty"){
737
+ for(var key in rp_ge._savedData) {
738
+ if(postdata[key]) {
739
+ rp_ge._savedData[key] = postdata[key];
740
+ }
741
+ }
742
+ }
743
+ }
744
+ $("#sData", "#"+frmtb+"_2").removeClass('ui-state-active');
745
+ try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){}
746
+ },
747
+ error:function(xhr,st,err){
748
+ $("#FormError>td","#"+frmtb).html(st+ " : "+err);
749
+ $("#FormError","#"+frmtb).show();
750
+ rp_ge.processing=false;
751
+ $("#"+frmgr).data("disabled",false);
752
+ $("#sData", "#"+frmtb+"_2").removeClass('ui-state-active');
753
+ }
754
+ }, $.jgrid.ajaxOptions, rp_ge.ajaxEditOptions );
755
+
756
+ if (!ajaxOptions.url && !rp_ge.useDataProxy) {
757
+ if ($.isFunction($t.p.dataProxy)) {
758
+ rp_ge.useDataProxy = true;
759
+ } else {
760
+ ret[0]=false; ret[1] += " "+$.jgrid.errors.nourl;
761
+ }
762
+ }
763
+ if (ret[0]) {
764
+ if (rp_ge.useDataProxy) { $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id); }
765
+ else { $.ajax(ajaxOptions); }
766
+ }
767
+ }
768
+ if(ret[0] === false) {
769
+ $("#FormError>td","#"+frmtb).html(ret[1]);
770
+ $("#FormError","#"+frmtb).show();
771
+ // return;
772
+ }
773
+ }
774
+ function compareData(nObj, oObj ) {
775
+ var ret = false,key;
776
+ for (key in nObj) {
777
+ if(nObj[key] != oObj[key]) {
778
+ ret = true;
779
+ break;
780
+ }
781
+ }
782
+ return ret;
783
+ }
784
+ function checkUpdates () {
785
+ var stat = true;
786
+ $("#FormError","#"+frmtb).hide();
787
+ if(rp_ge.checkOnUpdate) {
788
+ postdata = {}; extpost={};
789
+ getFormData();
790
+ newData = $.extend({},postdata,extpost);
791
+ diff = compareData(newData,rp_ge._savedData);
792
+ if(diff) {
793
+ $("#"+frmgr).data("disabled",true);
794
+ $(".confirm","#"+IDs.themodal).show();
795
+ stat = false;
796
+ }
797
+ }
798
+ return stat;
799
+ }
800
+ function restoreInline()
801
+ {
802
+ if (rowid !== "_empty" && typeof($t.p.savedRow) !== "undefined" && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid['restoreRow'])) {
803
+ for (var i=0;i<$t.p.savedRow.length;i++) {
804
+ if ($t.p.savedRow[i].id == rowid) {
805
+ $($t).jqGrid('restoreRow',rowid);
806
+ break;
807
+ }
808
+ }
809
+ }
810
+ }
811
+ if ( $("#"+IDs.themodal).html() != null ) {
812
+ if(onBeforeInit) {
813
+ showFrm = onBeforeInit($("#"+frmgr));
814
+ if(typeof(showFrm) == "undefined") {
815
+ showFrm = true;
816
+ }
817
+ }
818
+ if(showFrm === false) { return; }
819
+ restoreInline();
820
+ $(".ui-jqdialog-title","#"+IDs.modalhead).html(p.caption);
821
+ $("#FormError","#"+frmtb).hide();
822
+ if(rp_ge.topinfo) {
823
+ $(".topinfo","#"+frmtb+"_2").html(rp_ge.topinfo);
824
+ $(".tinfo","#"+frmtb+"_2").show();
825
+ } else {
826
+ $(".tinfo","#"+frmtb+"_2").hide();
827
+ }
828
+ if(rp_ge.bottominfo) {
829
+ $(".bottominfo","#"+frmtb+"_2").html(rp_ge.bottominfo);
830
+ $(".binfo","#"+frmtb+"_2").show();
831
+ } else {
832
+ $(".binfo","#"+frmtb+"_2").hide();
833
+ }
834
+ // filldata
835
+ fillData(rowid,$t,frmgr);
836
+ ///
837
+ if(rowid=="_empty" || !rp_ge.viewPagerButtons) {
838
+ $("#pData, #nData","#"+frmtb+"_2").hide();
839
+ } else {
840
+ $("#pData, #nData","#"+frmtb+"_2").show();
841
+ }
842
+ if(rp_ge.processing===true) {
843
+ rp_ge.processing=false;
844
+ $("#sData", "#"+frmtb+"_2").removeClass('ui-state-active');
845
+ }
846
+ if($("#"+frmgr).data("disabled")===true) {
847
+ $(".confirm","#"+IDs.themodal).hide();
848
+ $("#"+frmgr).data("disabled",false);
849
+ }
850
+ if(onBeforeShow) { onBeforeShow($("#"+frmgr)); }
851
+ $("#"+IDs.themodal).data("onClose",rp_ge.onClose);
852
+ $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal});
853
+ if(!closeovrl) {
854
+ $(".jqmOverlay").click(function(){
855
+ if(!checkUpdates()) { return false; }
856
+ $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge.onClose});
857
+ return false;
858
+ });
859
+ }
860
+ if(onAfterShow) { onAfterShow($("#"+frmgr)); }
861
+ } else {
862
+ var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px",
863
+ frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:100%;overflow:auto;position:relative;height:"+dh+";'></form>").data("disabled",false),
864
+ tbl = $("<table id='"+frmtb+"' class='EditTable' cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>");
865
+ if(onBeforeInit) {
866
+ showFrm = onBeforeInit($("#"+frmgr));
867
+ if(typeof(showFrm) == "undefined") {
868
+ showFrm = true;
869
+ }
870
+ }
871
+ if(showFrm === false) { return; }
872
+ restoreInline();
873
+ $($t.p.colModel).each( function(i) {
874
+ var fmto = this.formoptions;
875
+ maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
876
+ maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
877
+ });
878
+ $(frm).append(tbl);
879
+ var flr = $("<tr id='FormError' style='display:none'><td class='ui-state-error' colspan='"+(maxCols*2)+"'></td></tr>");
880
+ flr[0].rp = 0;
881
+ $(tbl).append(flr);
882
+ //topinfo
883
+ flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='"+(maxCols*2)+"'>"+rp_ge.topinfo+"</td></tr>");
884
+ flr[0].rp = 0;
885
+ $(tbl).append(flr);
886
+ // set the id.
887
+ // use carefull only to change here colproperties.
888
+ // create data
889
+ var rtlb = $t.p.direction == "rtl" ? true :false,
890
+ bp = rtlb ? "nData" : "pData",
891
+ bn = rtlb ? "pData" : "nData";
892
+ createData(rowid,$t,tbl,maxCols);
893
+ // buttons at footer
894
+ var bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></div>",
895
+ bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></div>",
896
+ bS ="<a href='javascript:void(0)' id='sData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
897
+ bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
898
+ var bt = "<table border='0' cellspacing='0' cellpadding='0' class='EditTable' id='"+frmtb+"_2'><tbody><tr><td colspan='2'><hr class='ui-widget-content' style='margin:1px'/></td></tr><tr id='Act_Buttons'><td class='navButton'>"+(rtlb ? bN+bP : bP+bN)+"</td><td class='EditButton'>"+bS+bC+"</td></tr>";
899
+ bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge.bottominfo+"</td></tr>";
900
+ bt += "</tbody></table>";
901
+ if(maxRows > 0) {
902
+ var sd=[];
903
+ $.each($(tbl)[0].rows,function(i,r){
904
+ sd[i] = r;
905
+ });
906
+ sd.sort(function(a,b){
907
+ if(a.rp > b.rp) {return 1;}
908
+ if(a.rp < b.rp) {return -1;}
909
+ return 0;
910
+ });
911
+ $.each(sd, function(index, row) {
912
+ $('tbody',tbl).append(row);
913
+ });
914
+ }
915
+ p.gbox = "#gbox_"+gID;
916
+ var cle = false;
917
+ if(p.closeOnEscape===true){
918
+ p.closeOnEscape = false;
919
+ cle = true;
920
+ }
921
+ var tms = $("<span></span>").append(frm).append(bt);
922
+ $.jgrid.createModal(IDs,tms,p,"#gview_"+$t.p.id,$("#gbox_"+$t.p.id)[0]);
923
+ if(rtlb) {
924
+ $("#pData, #nData","#"+frmtb+"_2").css("float","right");
925
+ $(".EditButton","#"+frmtb+"_2").css("text-align","left");
926
+ }
927
+ if(rp_ge.topinfo) { $(".tinfo","#"+frmtb+"_2").show(); }
928
+ if(rp_ge.bottominfo) { $(".binfo","#"+frmtb+"_2").show(); }
929
+ tms = null; bt=null;
930
+ $("#"+IDs.themodal).keydown( function( e ) {
931
+ var wkey = e.target;
932
+ if ($("#"+frmgr).data("disabled")===true ) { return false; }//??
933
+ if(rp_ge.savekey[0] === true && e.which == rp_ge.savekey[1]) { // save
934
+ if(wkey.tagName != "TEXTAREA") {
935
+ $("#sData", "#"+frmtb+"_2").trigger("click");
936
+ return false;
937
+ }
938
+ }
939
+ if(e.which === 27) {
940
+ if(!checkUpdates()) { return false; }
941
+ if(cle) { $.jgrid.hideModal(this,{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge.onClose}); }
942
+ return false;
943
+ }
944
+ if(rp_ge.navkeys[0]===true) {
945
+ if($("#id_g","#"+frmtb).val() == "_empty") { return true; }
946
+ if(e.which == rp_ge.navkeys[1]){ //up
947
+ $("#pData", "#"+frmtb+"_2").trigger("click");
948
+ return false;
949
+ }
950
+ if(e.which == rp_ge.navkeys[2]){ //down
951
+ $("#nData", "#"+frmtb+"_2").trigger("click");
952
+ return false;
953
+ }
954
+ }
955
+ });
956
+ if(p.checkOnUpdate) {
957
+ $("a.ui-jqdialog-titlebar-close span","#"+IDs.themodal).removeClass("jqmClose");
958
+ $("a.ui-jqdialog-titlebar-close","#"+IDs.themodal).unbind("click")
959
+ .click(function(){
960
+ if(!checkUpdates()) { return false; }
961
+ $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose});
962
+ return false;
963
+ });
964
+ }
965
+ p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon);
966
+ p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
967
+ // beforeinitdata after creation of the form
968
+ if(p.saveicon[0]===true) {
969
+ $("#sData","#"+frmtb+"_2").addClass(p.saveicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
970
+ .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
971
+ }
972
+ if(p.closeicon[0]===true) {
973
+ $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
974
+ .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
975
+ }
976
+ if(rp_ge.checkOnSubmit || rp_ge.checkOnUpdate) {
977
+ bS ="<a href='javascript:void(0)' id='sNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bYes+"</a>";
978
+ bN ="<a href='javascript:void(0)' id='nNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bNo+"</a>";
979
+ bC ="<a href='javascript:void(0)' id='cNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bExit+"</a>";
980
+ var ii, zI = p.zIndex || 999; zI ++;
981
+ if ($.browser.msie && $.browser.version ==6) {
982
+ ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
983
+ } else { ii="";}
984
+ $("<div class='ui-widget-overlay jqgrid-overlay confirm' style='z-index:"+zI+";display:none;'>&#160;"+ii+"</div><div class='confirm ui-widget-content ui-jqconfirm' style='z-index:"+(zI+1)+"'>"+p.saveData+"<br/><br/>"+bS+bN+bC+"</div>").insertAfter("#"+frmgr);
985
+ $("#sNew","#"+IDs.themodal).click(function(){
986
+ postIt();
987
+ $("#"+frmgr).data("disabled",false);
988
+ $(".confirm","#"+IDs.themodal).hide();
989
+ return false;
990
+ });
991
+ $("#nNew","#"+IDs.themodal).click(function(){
992
+ $(".confirm","#"+IDs.themodal).hide();
993
+ $("#"+frmgr).data("disabled",false);
994
+ setTimeout(function(){$(":input","#"+frmgr)[0].focus();},0);
995
+ return false;
996
+ });
997
+ $("#cNew","#"+IDs.themodal).click(function(){
998
+ $(".confirm","#"+IDs.themodal).hide();
999
+ $("#"+frmgr).data("disabled",false);
1000
+ $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose});
1001
+ return false;
1002
+ });
1003
+ }
1004
+ // here initform - only once
1005
+ if(onInitializeForm) { onInitializeForm($("#"+frmgr)); }
1006
+ if(rowid=="_empty" || !rp_ge.viewPagerButtons) { $("#pData,#nData","#"+frmtb+"_2").hide(); } else { $("#pData,#nData","#"+frmtb+"_2").show(); }
1007
+ if(onBeforeShow) { onBeforeShow($("#"+frmgr)); }
1008
+ $("#"+IDs.themodal).data("onClose",rp_ge.onClose);
1009
+ $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, overlay: p.overlay,modal:p.modal});
1010
+ if(!closeovrl) {
1011
+ $(".jqmOverlay").click(function(){
1012
+ if(!checkUpdates()) { return false; }
1013
+ $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge.onClose});
1014
+ return false;
1015
+ });
1016
+ }
1017
+ if(onAfterShow) { onAfterShow($("#"+frmgr)); }
1018
+ $(".fm-button","#"+IDs.themodal).hover(
1019
+ function(){$(this).addClass('ui-state-hover');},
1020
+ function(){$(this).removeClass('ui-state-hover');}
1021
+ );
1022
+ $("#sData", "#"+frmtb+"_2").click(function(e){
1023
+ postdata = {}; extpost={};
1024
+ $("#FormError","#"+frmtb).hide();
1025
+ // all depend on ret array
1026
+ //ret[0] - succes
1027
+ //ret[1] - msg if not succes
1028
+ //ret[2] - the id that will be set if reload after submit false
1029
+ getFormData();
1030
+ if(postdata[$t.p.id+"_id"] == "_empty") { postIt(); }
1031
+ else if(p.checkOnSubmit===true ) {
1032
+ newData = $.extend({},postdata,extpost);
1033
+ diff = compareData(newData,rp_ge._savedData);
1034
+ if(diff) {
1035
+ $("#"+frmgr).data("disabled",true);
1036
+ $(".confirm","#"+IDs.themodal).show();
1037
+ } else {
1038
+ postIt();
1039
+ }
1040
+ } else {
1041
+ postIt();
1042
+ }
1043
+ return false;
1044
+ });
1045
+ $("#cData", "#"+frmtb+"_2").click(function(e){
1046
+ if(!checkUpdates()) { return false; }
1047
+ $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal,onClose: rp_ge.onClose});
1048
+ return false;
1049
+ });
1050
+ $("#nData", "#"+frmtb+"_2").click(function(e){
1051
+ if(!checkUpdates()) { return false; }
1052
+ $("#FormError","#"+frmtb).hide();
1053
+ var npos = getCurrPos();
1054
+ npos[0] = parseInt(npos[0],10);
1055
+ if(npos[0] != -1 && npos[1][npos[0]+1]) {
1056
+ if($.isFunction(p.onclickPgButtons)) {
1057
+ p.onclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]]);
1058
+ }
1059
+ fillData(npos[1][npos[0]+1],$t,frmgr);
1060
+ $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
1061
+ if($.isFunction(p.afterclickPgButtons)) {
1062
+ p.afterclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]+1]);
1063
+ }
1064
+ updateNav(npos[0]+1,npos[1].length-1);
1065
+ }
1066
+ return false;
1067
+ });
1068
+ $("#pData", "#"+frmtb+"_2").click(function(e){
1069
+ if(!checkUpdates()) { return false; }
1070
+ $("#FormError","#"+frmtb).hide();
1071
+ var ppos = getCurrPos();
1072
+ if(ppos[0] != -1 && ppos[1][ppos[0]-1]) {
1073
+ if($.isFunction(p.onclickPgButtons)) {
1074
+ p.onclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]]);
1075
+ }
1076
+ fillData(ppos[1][ppos[0]-1],$t,frmgr);
1077
+ $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
1078
+ if($.isFunction(p.afterclickPgButtons)) {
1079
+ p.afterclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
1080
+ }
1081
+ updateNav(ppos[0]-1,ppos[1].length-1);
1082
+ }
1083
+ return false;
1084
+ });
1085
+ }
1086
+ function updateNav(cr,totr,rid){
1087
+ if (cr===0) { $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled'); } else { $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled'); }
1088
+ if (cr==totr) { $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled'); } else { $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled'); }
1089
+ }
1090
+ function getCurrPos() {
1091
+ var rowsInGrid = $($t).jqGrid("getDataIDs"),
1092
+ selrow = $("#id_g","#"+frmtb).val(),
1093
+ pos = $.inArray(selrow,rowsInGrid);
1094
+ return [pos,rowsInGrid];
1095
+ }
1096
+
1097
+ var posInit =getCurrPos();
1098
+ updateNav(posInit[0],posInit[1].length-1);
1099
+
1100
+ });
1101
+ },
1102
+ viewGridRow : function(rowid, p){
1103
+ p = $.extend({
1104
+ top : 0,
1105
+ left: 0,
1106
+ width: 0,
1107
+ height: 'auto',
1108
+ dataheight: 'auto',
1109
+ modal: false,
1110
+ overlay: 10,
1111
+ drag: true,
1112
+ resize: true,
1113
+ jqModal: true,
1114
+ closeOnEscape : false,
1115
+ labelswidth: '30%',
1116
+ closeicon: [],
1117
+ navkeys: [false,38,40],
1118
+ onClose: null,
1119
+ beforeShowForm : null,
1120
+ beforeInitData : null,
1121
+ viewPagerButtons : true
1122
+ }, $.jgrid.view, p || {});
1123
+ return this.each(function(){
1124
+ var $t = this;
1125
+ if (!$t.grid || !rowid) { return; }
1126
+ if(!p.imgpath) { p.imgpath= $t.p.imgpath; }
1127
+ // I hate to rewrite code, but ...
1128
+ var gID = $t.p.id,
1129
+ frmgr = "ViewGrid_"+gID , frmtb = "ViewTbl_"+gID,
1130
+ IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr},
1131
+ onBeforeInit = $.isFunction(p.beforeInitData) ? p.beforeInitData : false,
1132
+ showFrm = true,
1133
+ maxCols = 1, maxRows=0;
1134
+ function focusaref(){ //Sfari 3 issues
1135
+ if(p.closeOnEscape===true || p.navkeys[0]===true) {
1136
+ setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+IDs.modalhead).focus();},0);
1137
+ }
1138
+ }
1139
+ function createData(rowid,obj,tb,maxcols){
1140
+ var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false,
1141
+ tdtmpl = "<td class='CaptionTD form-view-label ui-widget-content' width='"+p.labelswidth+"'>&#160;</td><td class='DataTD form-view-data ui-helper-reset ui-widget-content'>&#160;</td>", tmpl="",
1142
+ tdtmpl2 = "<td class='CaptionTD form-view-label ui-widget-content'>&#160;</td><td class='DataTD form-view-data ui-widget-content'>&#160;</td>",
1143
+ fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld;
1144
+ for (var i =1;i<=maxcols;i++) {
1145
+ tmpl += i == 1 ? tdtmpl : tdtmpl2;
1146
+ }
1147
+ // find max number align rigth with property formatter
1148
+ $(obj.p.colModel).each( function(i) {
1149
+ if(this.editrules && this.editrules.edithidden === true) {
1150
+ hc = false;
1151
+ } else {
1152
+ hc = this.hidden === true ? true : false;
1153
+ }
1154
+ if(!hc && this.align==='right') {
1155
+ if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) {
1156
+ max1 = Math.max(max1,parseInt(this.width,10));
1157
+ } else {
1158
+ max2 = Math.max(max2,parseInt(this.width,10));
1159
+ }
1160
+ }
1161
+ });
1162
+ maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0;
1163
+ ind = $(obj).jqGrid("getInd",rowid);
1164
+ $(obj.p.colModel).each( function(i) {
1165
+ nm = this.name;
1166
+ setme = false;
1167
+ // hidden fields are included in the form
1168
+ if(this.editrules && this.editrules.edithidden === true) {
1169
+ hc = false;
1170
+ } else {
1171
+ hc = this.hidden === true ? true : false;
1172
+ }
1173
+ dc = hc ? "style='display:none'" : "";
1174
+ viewfld = (typeof this.viewable != 'boolean') ? true : this.viewable;
1175
+ if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) {
1176
+ if(ind === false) {
1177
+ tmp = "";
1178
+ } else {
1179
+ if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
1180
+ tmp = $("td:eq("+i+")",obj.rows[ind]).text();
1181
+ } else {
1182
+ tmp = $("td:eq("+i+")",obj.rows[ind]).html();
1183
+ }
1184
+ }
1185
+ setme = this.align === 'right' && maxw !==0 ? true : false;
1186
+ var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}),
1187
+ frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}),
1188
+ rp = parseInt(frmopt.rowpos,10) || cnt+1,
1189
+ cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
1190
+ if(frmopt.rowabove) {
1191
+ var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
1192
+ $(tb).append(newdata);
1193
+ newdata[0].rp = rp;
1194
+ }
1195
+ trdata = $(tb).find("tr[rowpos="+rp+"]");
1196
+ if ( trdata.length===0 ) {
1197
+ trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm);
1198
+ $(trdata).append(tmpl);
1199
+ $(tb).append(trdata);
1200
+ trdata[0].rp = rp;
1201
+ }
1202
+ $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (typeof frmopt.label === 'undefined' ? obj.p.colNames[i]: frmopt.label)+'</b>');
1203
+ $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm);
1204
+ if(setme){
1205
+ $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"});
1206
+ }
1207
+ retpos[cnt] = i;
1208
+ cnt++;
1209
+ }
1210
+ });
1211
+ if( cnt > 0) {
1212
+ var idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+ (maxcols*2-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='id' value='"+rowid+"'/></td></tr>");
1213
+ idrow[0].rp = cnt+99;
1214
+ $(tb).append(idrow);
1215
+ }
1216
+ return retpos;
1217
+ }
1218
+ function fillData(rowid,obj){
1219
+ var nm, hc,cnt=0,tmp, opt,trv;
1220
+ trv = $(obj).jqGrid("getInd",rowid,true);
1221
+ if(!trv) { return; }
1222
+ $('td',trv).each( function(i) {
1223
+ nm = obj.p.colModel[i].name;
1224
+ // hidden fields are included in the form
1225
+ if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) {
1226
+ hc = false;
1227
+ } else {
1228
+ hc = obj.p.colModel[i].hidden === true ? true : false;
1229
+ }
1230
+ if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
1231
+ if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
1232
+ tmp = $(this).text();
1233
+ } else {
1234
+ tmp = $(this).html();
1235
+ }
1236
+ opt = $.extend({},obj.p.colModel[i].editoptions || {});
1237
+ nm = $.jgrid.jqID("v_"+nm);
1238
+ $("#"+nm+" span","#"+frmtb).html(tmp);
1239
+ if (hc) { $("#"+nm,"#"+frmtb).parents("tr:first").hide(); }
1240
+ cnt++;
1241
+ }
1242
+ });
1243
+ if(cnt>0) { $("#id_g","#"+frmtb).val(rowid); }
1244
+ }
1245
+ if ( $("#"+IDs.themodal).html() != null ) {
1246
+ if(onBeforeInit) {
1247
+ showFrm = onBeforeInit($("#"+frmgr));
1248
+ if(typeof(showFrm) == "undefined") {
1249
+ showFrm = true;
1250
+ }
1251
+ }
1252
+ if(showFrm === false) { return; }
1253
+ $(".ui-jqdialog-title","#"+IDs.modalhead).html(p.caption);
1254
+ $("#FormError","#"+frmtb).hide();
1255
+ fillData(rowid,$t);
1256
+ if($.isFunction(p.beforeShowForm)) { p.beforeShowForm($("#"+frmgr)); }
1257
+ $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal});
1258
+ focusaref();
1259
+ } else {
1260
+ var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
1261
+ var frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' style='width:100%;overflow:auto;position:relative;height:"+dh+";'></form>"),
1262
+ tbl =$("<table id='"+frmtb+"' class='EditTable' cellspacing='1' cellpadding='2' border='0' style='table-layout:fixed'><tbody></tbody></table>");
1263
+ if(onBeforeInit) {
1264
+ showFrm = onBeforeInit($("#"+frmgr));
1265
+ if(typeof(showFrm) == "undefined") {
1266
+ showFrm = true;
1267
+ }
1268
+ }
1269
+ if(showFrm === false) { return; }
1270
+ $($t.p.colModel).each( function(i) {
1271
+ var fmto = this.formoptions;
1272
+ maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
1273
+ maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
1274
+ });
1275
+ // set the id.
1276
+ $(frm).append(tbl);
1277
+ createData(rowid, $t, tbl, maxCols);
1278
+ var rtlb = $t.p.direction == "rtl" ? true :false,
1279
+ bp = rtlb ? "nData" : "pData",
1280
+ bn = rtlb ? "pData" : "nData",
1281
+
1282
+ // buttons at footer
1283
+ bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
1284
+ bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
1285
+ bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bClose+"</a>";
1286
+ if(maxRows > 0) {
1287
+ var sd=[];
1288
+ $.each($(tbl)[0].rows,function(i,r){
1289
+ sd[i] = r;
1290
+ });
1291
+ sd.sort(function(a,b){
1292
+ if(a.rp > b.rp) {return 1;}
1293
+ if(a.rp < b.rp) {return -1;}
1294
+ return 0;
1295
+ });
1296
+ $.each(sd, function(index, row) {
1297
+ $('tbody',tbl).append(row);
1298
+ });
1299
+ }
1300
+ p.gbox = "#gbox_"+gID;
1301
+ var cle = false;
1302
+ if(p.closeOnEscape===true){
1303
+ p.closeOnEscape = false;
1304
+ cle = true;
1305
+ }
1306
+ var bt = $("<span></span>").append(frm).append("<table border='0' class='EditTable' id='"+frmtb+"_2'><tbody><tr id='Act_Buttons'><td class='navButton' width='"+p.labelswidth+"'>"+(rtlb ? bN+bP : bP+bN)+"</td><td class='EditButton'>"+bC+"</td></tr></tbody></table>");
1307
+ $.jgrid.createModal(IDs,bt,p,"#gview_"+$t.p.id,$("#gview_"+$t.p.id)[0]);
1308
+ if(rtlb) {
1309
+ $("#pData, #nData","#"+frmtb+"_2").css("float","right");
1310
+ $(".EditButton","#"+frmtb+"_2").css("text-align","left");
1311
+ }
1312
+ if(!p.viewPagerButtons) { $("#pData, #nData","#"+frmtb+"_2").hide(); }
1313
+ bt = null;
1314
+ $("#"+IDs.themodal).keydown( function( e ) {
1315
+ if(e.which === 27) {
1316
+ if(cle) { $.jgrid.hideModal(this,{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose}); }
1317
+ return false;
1318
+ }
1319
+ if(p.navkeys[0]===true) {
1320
+ if(e.which === p.navkeys[1]){ //up
1321
+ $("#pData", "#"+frmtb+"_2").trigger("click");
1322
+ return false;
1323
+ }
1324
+ if(e.which === p.navkeys[2]){ //down
1325
+ $("#nData", "#"+frmtb+"_2").trigger("click");
1326
+ return false;
1327
+ }
1328
+ }
1329
+ });
1330
+ p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
1331
+ if(p.closeicon[0]===true) {
1332
+ $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
1333
+ .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
1334
+ }
1335
+ if($.isFunction(p.beforeShowForm)) { p.beforeShowForm($("#"+frmgr)); }
1336
+ $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, modal:p.modal});
1337
+ $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover(
1338
+ function(){$(this).addClass('ui-state-hover');},
1339
+ function(){$(this).removeClass('ui-state-hover');}
1340
+ );
1341
+ focusaref();
1342
+ $("#cData", "#"+frmtb+"_2").click(function(e){
1343
+ $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: p.onClose});
1344
+ return false;
1345
+ });
1346
+ $("#nData", "#"+frmtb+"_2").click(function(e){
1347
+ $("#FormError","#"+frmtb).hide();
1348
+ var npos = getCurrPos();
1349
+ npos[0] = parseInt(npos[0],10);
1350
+ if(npos[0] != -1 && npos[1][npos[0]+1]) {
1351
+ if($.isFunction(p.onclickPgButtons)) {
1352
+ p.onclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]]);
1353
+ }
1354
+ fillData(npos[1][npos[0]+1],$t);
1355
+ $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
1356
+ if($.isFunction(p.afterclickPgButtons)) {
1357
+ p.afterclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]+1]);
1358
+ }
1359
+ updateNav(npos[0]+1,npos[1].length-1);
1360
+ }
1361
+ focusaref();
1362
+ return false;
1363
+ });
1364
+ $("#pData", "#"+frmtb+"_2").click(function(e){
1365
+ $("#FormError","#"+frmtb).hide();
1366
+ var ppos = getCurrPos();
1367
+ if(ppos[0] != -1 && ppos[1][ppos[0]-1]) {
1368
+ if($.isFunction(p.onclickPgButtons)) {
1369
+ p.onclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]]);
1370
+ }
1371
+ fillData(ppos[1][ppos[0]-1],$t);
1372
+ $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
1373
+ if($.isFunction(p.afterclickPgButtons)) {
1374
+ p.afterclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
1375
+ }
1376
+ updateNav(ppos[0]-1,ppos[1].length-1);
1377
+ }
1378
+ focusaref();
1379
+ return false;
1380
+ });
1381
+ }
1382
+ function updateNav(cr,totr,rid){
1383
+ if (cr===0) { $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled'); } else { $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled'); }
1384
+ if (cr==totr) { $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled'); } else { $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled'); }
1385
+ }
1386
+ function getCurrPos() {
1387
+ var rowsInGrid = $($t).jqGrid("getDataIDs"),
1388
+ selrow = $("#id_g","#"+frmtb).val(),
1389
+ pos = $.inArray(selrow,rowsInGrid);
1390
+ return [pos,rowsInGrid];
1391
+ }
1392
+
1393
+ var posInit =getCurrPos();
1394
+ updateNav(posInit[0],posInit[1].length-1);
1395
+ });
1396
+ },
1397
+ delGridRow : function(rowids,p) {
1398
+ p = $.extend({
1399
+ top : 0,
1400
+ left: 0,
1401
+ width: 240,
1402
+ height: 'auto',
1403
+ dataheight : 'auto',
1404
+ modal: false,
1405
+ overlay: 10,
1406
+ drag: true,
1407
+ resize: true,
1408
+ url : '',
1409
+ mtype : "POST",
1410
+ reloadAfterSubmit: true,
1411
+ beforeShowForm: null,
1412
+ beforeInitData : null,
1413
+ afterShowForm: null,
1414
+ beforeSubmit: null,
1415
+ onclickSubmit: null,
1416
+ afterSubmit: null,
1417
+ jqModal : true,
1418
+ closeOnEscape : false,
1419
+ delData: {},
1420
+ delicon : [],
1421
+ cancelicon : [],
1422
+ onClose : null,
1423
+ ajaxDelOptions : {},
1424
+ processing : false,
1425
+ serializeDelData : null,
1426
+ useDataProxy : false
1427
+ }, $.jgrid.del, p ||{});
1428
+ rp_ge = p;
1429
+ return this.each(function(){
1430
+ var $t = this;
1431
+ if (!$t.grid ) { return; }
1432
+ if(!rowids) { return; }
1433
+ var onBeforeShow = typeof p.beforeShowForm === 'function' ? true: false,
1434
+ onAfterShow = typeof p.afterShowForm === 'function' ? true: false,
1435
+ onBeforeInit = $.isFunction(p.beforeInitData) ? p.beforeInitData : false,
1436
+ gID = $t.p.id, onCS = {},
1437
+ showFrm = true,
1438
+ dtbl = "DelTbl_"+gID,postd, idname, opers, oper,
1439
+ IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl};
1440
+ if (jQuery.isArray(rowids)) { rowids = rowids.join(); }
1441
+ if ( $("#"+IDs.themodal).html() != null ) {
1442
+ if(onBeforeInit) {
1443
+ showFrm = onBeforeInit();
1444
+ if(typeof(showFrm) == "undefined") {
1445
+ showFrm = true;
1446
+ }
1447
+ }
1448
+ if(showFrm === false) { return; }
1449
+ $("#DelData>td","#"+dtbl).text(rowids);
1450
+ $("#DelError","#"+dtbl).hide();
1451
+ if( rp_ge.processing === true) {
1452
+ rp_ge.processing=false;
1453
+ $("#dData", "#"+dtbl).removeClass('ui-state-active');
1454
+ }
1455
+ if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
1456
+ $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal,jqM: false, overlay: p.overlay, modal:p.modal});
1457
+ if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
1458
+ } else {
1459
+ if(onBeforeInit) {
1460
+ showFrm = onBeforeInit();
1461
+ if(typeof(showFrm) == "undefined") {
1462
+ showFrm = true;
1463
+ }
1464
+ }
1465
+ if(showFrm === false) { return; }
1466
+ var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
1467
+ var tbl = "<div id='"+dtbl+"' class='formdata' style='width:100%;overflow:auto;position:relative;height:"+dh+";'>";
1468
+ tbl += "<table class='DelTable'><tbody>";
1469
+ // error data
1470
+ tbl += "<tr id='DelError' style='display:none'><td class='ui-state-error'></td></tr>";
1471
+ tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>";
1472
+ tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+p.msg+"</td></tr><tr><td >&#160;</td></tr>";
1473
+ // buttons at footer
1474
+ tbl += "</tbody></table></div>";
1475
+ var bS = "<a href='javascript:void(0)' id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
1476
+ bC = "<a href='javascript:void(0)' id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
1477
+ tbl += "<table cellspacing='0' cellpadding='0' border='0' class='EditTable' id='"+dtbl+"_2'><tbody><tr><td><hr class='ui-widget-content' style='margin:1px'/></td></tr></tr><tr><td class='DelButton EditButton'>"+bS+"&#160;"+bC+"</td></tr></tbody></table>";
1478
+ p.gbox = "#gbox_"+gID;
1479
+ $.jgrid.createModal(IDs,tbl,p,"#gview_"+$t.p.id,$("#gview_"+$t.p.id)[0]);
1480
+ $(".fm-button","#"+dtbl+"_2").hover(
1481
+ function(){$(this).addClass('ui-state-hover');},
1482
+ function(){$(this).removeClass('ui-state-hover');}
1483
+ );
1484
+ p.delicon = $.extend([true,"left","ui-icon-scissors"],p.delicon);
1485
+ p.cancelicon = $.extend([true,"left","ui-icon-cancel"],p.cancelicon);
1486
+ if(p.delicon[0]===true) {
1487
+ $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
1488
+ .append("<span class='ui-icon "+p.delicon[2]+"'></span>");
1489
+ }
1490
+ if(p.cancelicon[0]===true) {
1491
+ $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
1492
+ .append("<span class='ui-icon "+p.cancelicon[2]+"'></span>");
1493
+ }
1494
+ $("#dData","#"+dtbl+"_2").click(function(e){
1495
+ var ret=[true,""]; onCS = {};
1496
+ var postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
1497
+ if( typeof p.onclickSubmit === 'function' ) { onCS = p.onclickSubmit(rp_ge, postdata) || {}; }
1498
+ if( typeof p.beforeSubmit === 'function' ) { ret = p.beforeSubmit(postdata); }
1499
+ if(ret[0] && !rp_ge.processing) {
1500
+ rp_ge.processing = true;
1501
+ $(this).addClass('ui-state-active');
1502
+ opers = $t.p.prmNames;
1503
+ postd = $.extend({},rp_ge.delData, onCS);
1504
+ oper = opers.oper;
1505
+ postd[oper] = opers.deloper;
1506
+ idname = opers.id;
1507
+ postd[idname] = postdata;
1508
+
1509
+ var ajaxOptions = $.extend({
1510
+ url: rp_ge.url ? rp_ge.url : $($t).jqGrid('getGridParam','editurl'),
1511
+ type: p.mtype,
1512
+ data: $.isFunction(p.serializeDelData) ? p.serializeDelData(postd) : postd,
1513
+ complete:function(data,Status){
1514
+ if(Status != "success") {
1515
+ ret[0] = false;
1516
+ if ($.isFunction(rp_ge.errorTextFormat)) {
1517
+ ret[1] = rp_ge.errorTextFormat(data);
1518
+ } else {
1519
+ ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status;
1520
+ }
1521
+ } else {
1522
+ // data is posted successful
1523
+ // execute aftersubmit with the returned data from server
1524
+ if( typeof rp_ge.afterSubmit === 'function' ) {
1525
+ ret = rp_ge.afterSubmit(data,postd);
1526
+ }
1527
+ }
1528
+ if(ret[0] === false) {
1529
+ $("#DelError>td","#"+dtbl).html(ret[1]);
1530
+ $("#DelError","#"+dtbl).show();
1531
+ } else {
1532
+ if(rp_ge.reloadAfterSubmit && $t.p.datatype != "local") {
1533
+ $($t).trigger("reloadGrid");
1534
+ } else {
1535
+ var toarr = [];
1536
+ toarr = postdata.split(",");
1537
+ if($t.p.treeGrid===true){
1538
+ try {$($t).jqGrid("delTreeNode",toarr[0]);} catch(e){}
1539
+ } else {
1540
+ for(var i=0;i<toarr.length;i++) {
1541
+ $($t).jqGrid("delRowData",toarr[i]);
1542
+ }
1543
+ }
1544
+ $t.p.selrow = null;
1545
+ $t.p.selarrrow = [];
1546
+ }
1547
+ if($.isFunction(rp_ge.afterComplete)) {
1548
+ setTimeout(function(){rp_ge.afterComplete(data,postdata);},500);
1549
+ }
1550
+ }
1551
+ rp_ge.processing=false;
1552
+ $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
1553
+ if(ret[0]) { $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge.onClose}); }
1554
+ },
1555
+ error:function(xhr,st,err){
1556
+ $("#DelError>td","#"+dtbl).html(st+ " : "+err);
1557
+ $("#DelError","#"+dtbl).show();
1558
+ rp_ge.processing=false;
1559
+ $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
1560
+ }
1561
+ }, $.jgrid.ajaxOptions, p.ajaxDelOptions);
1562
+
1563
+
1564
+ if (!ajaxOptions.url && !rp_ge.useDataProxy) {
1565
+ if ($.isFunction($t.p.dataProxy)) {
1566
+ rp_ge.useDataProxy = true;
1567
+ } else {
1568
+ ret[0]=false; ret[1] += " "+$.jgrid.errors.nourl;
1569
+ }
1570
+ }
1571
+ if (ret[0]) {
1572
+ if (rp_ge.useDataProxy) { $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id); }
1573
+ else { $.ajax(ajaxOptions); }
1574
+ }
1575
+ }
1576
+
1577
+ if(ret[0] === false) {
1578
+ $("#DelError>td","#"+dtbl).html(ret[1]);
1579
+ $("#DelError","#"+dtbl).show();
1580
+ }
1581
+ return false;
1582
+ });
1583
+ $("#eData", "#"+dtbl+"_2").click(function(e){
1584
+ $.jgrid.hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: rp_ge.onClose});
1585
+ return false;
1586
+ });
1587
+ if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
1588
+ $.jgrid.viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, overlay: p.overlay, modal:p.modal});
1589
+ if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
1590
+ }
1591
+ if(p.closeOnEscape===true) {
1592
+ setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+IDs.modalhead).focus();},0);
1593
+ }
1594
+ });
1595
+ },
1596
+ navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) {
1597
+ o = $.extend({
1598
+ edit: true,
1599
+ editicon: "ui-icon-pencil",
1600
+ add: true,
1601
+ addicon:"ui-icon-plus",
1602
+ del: true,
1603
+ delicon:"ui-icon-trash",
1604
+ search: true,
1605
+ searchicon:"ui-icon-search",
1606
+ refresh: true,
1607
+ refreshicon:"ui-icon-refresh",
1608
+ refreshstate: 'firstpage',
1609
+ view: false,
1610
+ viewicon : "ui-icon-document",
1611
+ position : "left",
1612
+ closeOnEscape : true,
1613
+ beforeRefresh : null,
1614
+ afterRefresh : null,
1615
+ cloneToTop : false
1616
+ }, $.jgrid.nav, o ||{});
1617
+ return this.each(function() {
1618
+ var alertIDs = {themodal:'alertmod',modalhead:'alerthd',modalcontent:'alertcnt'},
1619
+ $t = this, vwidth, vheight, twd, tdw;
1620
+ if(!$t.grid || typeof elem != 'string') { return; }
1621
+ if ($("#"+alertIDs.themodal).html() === null) {
1622
+ if (typeof window.innerWidth != 'undefined') {
1623
+ vwidth = window.innerWidth;
1624
+ vheight = window.innerHeight;
1625
+ } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth !== 0) {
1626
+ vwidth = document.documentElement.clientWidth;
1627
+ vheight = document.documentElement.clientHeight;
1628
+ } else {
1629
+ vwidth=1024;
1630
+ vheight=768;
1631
+ }
1632
+ $.jgrid.createModal(alertIDs,"<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",{gbox:"#gbox_"+$t.p.id,jqModal:true,drag:true,resize:true,caption:o.alertcap,top:vheight/2-25,left:vwidth/2-100,width:200,height:'auto',closeOnEscape:o.closeOnEscape},"","",true);
1633
+ }
1634
+ var clone = 1;
1635
+ if(o.cloneToTop && $t.p.toppager) { clone = 2; }
1636
+ for(var i = 0; i<clone; i++) {
1637
+ var tbd,
1638
+ navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"),
1639
+ sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
1640
+ pgid, elemids;
1641
+ if(i===0) {
1642
+ pgid = elem;
1643
+ elemids = $t.p.id;
1644
+ if(pgid == $t.p.toppager) {
1645
+ elemids += "_top";
1646
+ clone = 1;
1647
+ }
1648
+ } else {
1649
+ pgid = $t.p.toppager;
1650
+ elemids = $t.p.id+"_top";
1651
+ }
1652
+ if($t.p.direction == "rtl") { $(navtbl).attr("dir","rtl").css("float","right"); }
1653
+ if (o.add) {
1654
+ pAdd = pAdd || {};
1655
+ tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1656
+ $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.addicon+"'></span>"+o.addtext+"</div>");
1657
+ $("tr",navtbl).append(tbd);
1658
+ $(tbd,navtbl)
1659
+ .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids})
1660
+ .click(function(){
1661
+ if (!$(this).hasClass('ui-state-disabled')) {
1662
+ if (typeof o.addfunc == 'function') {
1663
+ o.addfunc();
1664
+ } else {
1665
+ $($t).jqGrid("editGridRow","new",pAdd);
1666
+ }
1667
+ }
1668
+ return false;
1669
+ }).hover(
1670
+ function () {
1671
+ if (!$(this).hasClass('ui-state-disabled')) {
1672
+ $(this).addClass("ui-state-hover");
1673
+ }
1674
+ },
1675
+ function () {$(this).removeClass("ui-state-hover");}
1676
+ );
1677
+ tbd = null;
1678
+ }
1679
+ if (o.edit) {
1680
+ tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1681
+ pEdit = pEdit || {};
1682
+ $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.editicon+"'></span>"+o.edittext+"</div>");
1683
+ $("tr",navtbl).append(tbd);
1684
+ $(tbd,navtbl)
1685
+ .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids})
1686
+ .click(function(){
1687
+ if (!$(this).hasClass('ui-state-disabled')) {
1688
+ var sr = $t.p.selrow;
1689
+ if (sr) {
1690
+ if(typeof o.editfunc == 'function') {
1691
+ o.editfunc(sr);
1692
+ } else {
1693
+ $($t).jqGrid("editGridRow",sr,pEdit);
1694
+ }
1695
+ } else {
1696
+ $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$t.p.id,jqm:true});
1697
+ $("#jqg_alrt").focus();
1698
+ }
1699
+ }
1700
+ return false;
1701
+ }).hover(
1702
+ function () {
1703
+ if (!$(this).hasClass('ui-state-disabled')) {
1704
+ $(this).addClass("ui-state-hover");
1705
+ }
1706
+ },
1707
+ function () {$(this).removeClass("ui-state-hover");}
1708
+ );
1709
+ tbd = null;
1710
+ }
1711
+ if (o.view) {
1712
+ tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1713
+ pView = pView || {};
1714
+ $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.viewicon+"'></span>"+o.viewtext+"</div>");
1715
+ $("tr",navtbl).append(tbd);
1716
+ $(tbd,navtbl)
1717
+ .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids})
1718
+ .click(function(){
1719
+ if (!$(this).hasClass('ui-state-disabled')) {
1720
+ var sr = $t.p.selrow;
1721
+ if (sr) {
1722
+ $($t).jqGrid("viewGridRow",sr,pView);
1723
+ } else {
1724
+ $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$t.p.id,jqm:true});
1725
+ $("#jqg_alrt").focus();
1726
+ }
1727
+ }
1728
+ return false;
1729
+ }).hover(
1730
+ function () {
1731
+ if (!$(this).hasClass('ui-state-disabled')) {
1732
+ $(this).addClass("ui-state-hover");
1733
+ }
1734
+ },
1735
+ function () {$(this).removeClass("ui-state-hover");}
1736
+ );
1737
+ tbd = null;
1738
+ }
1739
+ if (o.del) {
1740
+ tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1741
+ pDel = pDel || {};
1742
+ $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>");
1743
+ $("tr",navtbl).append(tbd);
1744
+ $(tbd,navtbl)
1745
+ .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
1746
+ .click(function(){
1747
+ if (!$(this).hasClass('ui-state-disabled')) {
1748
+ var dr;
1749
+ if($t.p.multiselect) {
1750
+ dr = $t.p.selarrrow;
1751
+ if(dr.length===0) { dr = null; }
1752
+ } else {
1753
+ dr = $t.p.selrow;
1754
+ }
1755
+ if(dr){
1756
+ if("function" == typeof o.delfunc){
1757
+ o.delfunc(dr);
1758
+ }else{
1759
+ $($t).jqGrid("delGridRow",dr,pDel);
1760
+ }
1761
+ } else {
1762
+ $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$t.p.id,jqm:true}); $("#jqg_alrt").focus();
1763
+ }
1764
+ }
1765
+ return false;
1766
+ }).hover(
1767
+ function () {
1768
+ if (!$(this).hasClass('ui-state-disabled')) {
1769
+ $(this).addClass("ui-state-hover");
1770
+ }
1771
+ },
1772
+ function () {$(this).removeClass("ui-state-hover");}
1773
+ );
1774
+ tbd = null;
1775
+ }
1776
+ if(o.add || o.edit || o.del || o.view) { $("tr",navtbl).append(sep); }
1777
+ if (o.search) {
1778
+ tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1779
+ pSearch = pSearch || {};
1780
+ $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.searchicon+"'></span>"+o.searchtext+"</div>");
1781
+ $("tr",navtbl).append(tbd);
1782
+ $(tbd,navtbl)
1783
+ .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids})
1784
+ .click(function(){
1785
+ if (!$(this).hasClass('ui-state-disabled')) {
1786
+ $($t).jqGrid("searchGrid",pSearch);
1787
+ }
1788
+ return false;
1789
+ }).hover(
1790
+ function () {
1791
+ if (!$(this).hasClass('ui-state-disabled')) {
1792
+ $(this).addClass("ui-state-hover");
1793
+ }
1794
+ },
1795
+ function () {$(this).removeClass("ui-state-hover");}
1796
+ );
1797
+ tbd = null;
1798
+ }
1799
+ if (o.refresh) {
1800
+ tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
1801
+ $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.refreshicon+"'></span>"+o.refreshtext+"</div>");
1802
+ $("tr",navtbl).append(tbd);
1803
+ $(tbd,navtbl)
1804
+ .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
1805
+ .click(function(){
1806
+ if (!$(this).hasClass('ui-state-disabled')) {
1807
+ if($.isFunction(o.beforeRefresh)) { o.beforeRefresh(); }
1808
+ $t.p.search = false;
1809
+ try {
1810
+ var gID = $t.p.id;
1811
+ $("#fbox_"+gID).searchFilter().reset({"reload":false});
1812
+ if($.isFunction($t.clearToolbar)) { $t.clearToolbar(false); }
1813
+ } catch (e) {}
1814
+ switch (o.refreshstate) {
1815
+ case 'firstpage':
1816
+ $($t).trigger("reloadGrid", [{page:1}]);
1817
+ break;
1818
+ case 'current':
1819
+ $($t).trigger("reloadGrid", [{current:true}]);
1820
+ break;
1821
+ }
1822
+ if($.isFunction(o.afterRefresh)) { o.afterRefresh(); }
1823
+ }
1824
+ return false;
1825
+ }).hover(
1826
+ function () {
1827
+ if (!$(this).hasClass('ui-state-disabled')) {
1828
+ $(this).addClass("ui-state-hover");
1829
+ }
1830
+ },
1831
+ function () {$(this).removeClass("ui-state-hover");}
1832
+ );
1833
+ tbd = null;
1834
+ }
1835
+ tdw = $(".ui-jqgrid").css("font-size") || "11px";
1836
+ $('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
1837
+ twd = $(navtbl).clone().appendTo("#testpg2").width();
1838
+ $("#testpg2").remove();
1839
+ $(pgid+"_"+o.position,pgid).append(navtbl);
1840
+ if($t.p._nvtd) {
1841
+ if(twd > $t.p._nvtd[0] ) {
1842
+ $(pgid+"_"+o.position,pgid).width(twd);
1843
+ $t.p._nvtd[0] = twd;
1844
+ }
1845
+ $t.p._nvtd[1] = twd;
1846
+ }
1847
+ tdw =null; twd=null; navtbl =null;
1848
+ }
1849
+ });
1850
+ },
1851
+ navButtonAdd : function (elem, p) {
1852
+ p = $.extend({
1853
+ caption : "newButton",
1854
+ title: '',
1855
+ buttonicon : 'ui-icon-newwin',
1856
+ onClickButton: null,
1857
+ position : "last",
1858
+ cursor : 'pointer'
1859
+ }, p ||{});
1860
+ return this.each(function() {
1861
+ if( !this.grid) { return; }
1862
+ if( elem.indexOf("#") !== 0) { elem = "#"+elem; }
1863
+ var findnav = $(".navtable",elem)[0], $t = this;
1864
+ if (findnav) {
1865
+ var tbd = $("<td></td>");
1866
+ if(p.buttonicon.toString().toUpperCase() == "NONE") {
1867
+ $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>"+p.caption+"</div>");
1868
+ } else {
1869
+ $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><span class='ui-icon "+p.buttonicon+"'></span>"+p.caption+"</div>");
1870
+ }
1871
+ if(p.id) {$(tbd).attr("id",p.id);}
1872
+ if(p.position=='first'){
1873
+ if(findnav.rows[0].cells.length ===0 ) {
1874
+ $("tr",findnav).append(tbd);
1875
+ } else {
1876
+ $("tr td:eq(0)",findnav).before(tbd);
1877
+ }
1878
+ } else {
1879
+ $("tr",findnav).append(tbd);
1880
+ }
1881
+ $(tbd,findnav)
1882
+ .attr("title",p.title || "")
1883
+ .click(function(e){
1884
+ if (!$(this).hasClass('ui-state-disabled')) {
1885
+ if ($.isFunction(p.onClickButton) ) { p.onClickButton.call($t,e); }
1886
+ }
1887
+ return false;
1888
+ })
1889
+ .hover(
1890
+ function () {
1891
+ if (!$(this).hasClass('ui-state-disabled')) {
1892
+ $(this).addClass('ui-state-hover');
1893
+ }
1894
+ },
1895
+ function () {$(this).removeClass("ui-state-hover");}
1896
+ );
1897
+ }
1898
+ });
1899
+ },
1900
+ navSeparatorAdd:function (elem,p) {
1901
+ p = $.extend({
1902
+ sepclass : "ui-separator",
1903
+ sepcontent: ''
1904
+ }, p ||{});
1905
+ return this.each(function() {
1906
+ if( !this.grid) { return; }
1907
+ if( elem.indexOf("#") !== 0) { elem = "#"+elem; }
1908
+ var findnav = $(".navtable",elem)[0];
1909
+ if(findnav) {
1910
+ var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>";
1911
+ $("tr",findnav).append(sep);
1912
+ }
1913
+ });
1914
+ },
1915
+ GridToForm : function( rowid, formid ) {
1916
+ return this.each(function(){
1917
+ var $t = this;
1918
+ if (!$t.grid) { return; }
1919
+ var rowdata = $($t).jqGrid("getRowData",rowid);
1920
+ if (rowdata) {
1921
+ for(var i in rowdata) {
1922
+ if ( $("[name="+i+"]",formid).is("input:radio") || $("[name="+i+"]",formid).is("input:checkbox")) {
1923
+ $("[name="+i+"]",formid).each( function() {
1924
+ if( $(this).val() == rowdata[i] ) {
1925
+ $(this).attr("checked","checked");
1926
+ } else {
1927
+ $(this).attr("checked","");
1928
+ }
1929
+ });
1930
+ } else {
1931
+ // this is very slow on big table and form.
1932
+ $("[name="+i+"]",formid).val(rowdata[i]);
1933
+ }
1934
+ }
1935
+ }
1936
+ });
1937
+ },
1938
+ FormToGrid : function(rowid, formid, mode, position){
1939
+ return this.each(function() {
1940
+ var $t = this;
1941
+ if(!$t.grid) { return; }
1942
+ if(!mode) { mode = 'set'; }
1943
+ if(!position) { position = 'first'; }
1944
+ var fields = $(formid).serializeArray();
1945
+ var griddata = {};
1946
+ $.each(fields, function(i, field){
1947
+ griddata[field.name] = field.value;
1948
+ });
1949
+ if(mode=='add') { $($t).jqGrid("addRowData",rowid,griddata, position); }
1950
+ else if(mode=='set') { $($t).jqGrid("setRowData",rowid,griddata); }
1951
+ });
1952
+ }
1953
+ });
1954
+ })(jQuery);