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,486 +1,486 @@
1
- ;(function($){
2
- /*
3
- **
4
- * jqGrid extension for cellediting Grid Data
5
- * Tony Tomov tony@trirand.com
6
- * http://trirand.com/blog/
7
- * Dual licensed under the MIT and GPL licenses:
8
- * http://www.opensource.org/licenses/mit-license.php
9
- * http://www.gnu.org/licenses/gpl-2.0.html
10
- **/
11
- /**
12
- * all events and options here are aded anonynous and not in the base grid
13
- * since the array is to big. Here is the order of execution.
14
- * From this point we use jQuery isFunction
15
- * formatCell
16
- * beforeEditCell,
17
- * onSelectCell (used only for noneditable cels)
18
- * afterEditCell,
19
- * beforeSaveCell, (called before validation of values if any)
20
- * beforeSubmitCell (if cellsubmit remote (ajax))
21
- * afterSubmitCell(if cellsubmit remote (ajax)),
22
- * afterSaveCell,
23
- * errorCell,
24
- * serializeCellData - new
25
- * Options
26
- * cellsubmit (remote,clientArray) (added in grid options)
27
- * cellurl
28
- * ajaxCellOptions
29
- * */
30
- $.jgrid.extend({
31
- editCell : function (iRow,iCol, ed){
32
- return this.each(function (){
33
- var $t = this, nm, tmp,cc;
34
- if (!$t.grid || $t.p.cellEdit !== true) {return;}
35
- iCol = parseInt(iCol,10);
36
- // select the row that can be used for other methods
37
- $t.p.selrow = $t.rows[iRow].id;
38
- if (!$t.p.knv) {$($t).jqGrid("GridNav");}
39
- // check to see if we have already edited cell
40
- if ($t.p.savedRow.length>0) {
41
- // prevent second click on that field and enable selects
42
- if (ed===true ) {
43
- if(iRow == $t.p.iRow && iCol == $t.p.iCol){
44
- return;
45
- }
46
- }
47
- // save the cell
48
- $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
49
- } else {
50
- window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
51
- }
52
- nm = $t.p.colModel[iCol].name;
53
- if (nm=='subgrid' || nm=='cb' || nm=='rn') {return;}
54
- cc = $("td:eq("+iCol+")",$t.rows[iRow]);
55
- if ($t.p.colModel[iCol].editable===true && ed===true && !cc.hasClass("not-editable-cell")) {
56
- if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
57
- $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
58
- $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
59
- }
60
- $(cc).addClass("edit-cell ui-state-highlight");
61
- $($t.rows[iRow]).addClass("selected-row ui-state-hover");
62
- try {
63
- tmp = $.unformat(cc,{rowId: $t.rows[iRow].id, colModel:$t.p.colModel[iCol]},iCol);
64
- } catch (_) {
65
- tmp = $(cc).html();
66
- }
67
- if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
68
- if (!$t.p.colModel[iCol].edittype) {$t.p.colModel[iCol].edittype = "text";}
69
- $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
70
- if($.isFunction($t.p.formatCell)) {
71
- var tmp2 = $t.p.formatCell($t.rows[iRow].id,nm,tmp,iRow,iCol);
72
- if(tmp2 !== undefined ) {tmp = tmp2;}
73
- }
74
- var opt = $.extend({}, $t.p.colModel[iCol].editoptions || {} ,{id:iRow+"_"+nm,name:nm});
75
- var elc = createEl($t.p.colModel[iCol].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
76
- if ($.isFunction($t.p.beforeEditCell)) {
77
- $t.p.beforeEditCell($t.rows[iRow].id,nm,tmp,iRow,iCol);
78
- }
79
- $(cc).html("").append(elc).attr("tabindex","0");
80
- window.setTimeout(function () { $(elc).focus();},0);
81
- $("input, select, textarea",cc).bind("keydown",function(e) {
82
- if (e.keyCode === 27) {
83
- if($("input.hasDatepicker",cc).length >0) {
84
- if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
85
- else { $("input.hasDatepicker",cc).datepicker('hide'); }
86
- } else {
87
- $($t).jqGrid("restoreCell",iRow,iCol);
88
- }
89
- } //ESC
90
- if (e.keyCode === 13) {$($t).jqGrid("saveCell",iRow,iCol);}//Enter
91
- if (e.keyCode == 9) {
92
- if(!$t.grid.hDiv.loading ) {
93
- if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
94
- else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
95
- } else {
96
- return false;
97
- }
98
- }
99
- e.stopPropagation();
100
- });
101
- if ($.isFunction($t.p.afterEditCell)) {
102
- $t.p.afterEditCell($t.rows[iRow].id,nm,tmp,iRow,iCol);
103
- }
104
- } else {
105
- if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
106
- $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
107
- $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
108
- }
109
- cc.addClass("edit-cell ui-state-highlight");
110
- $($t.rows[iRow]).addClass("selected-row ui-state-hover");
111
- if ($.isFunction($t.p.onSelectCell)) {
112
- tmp = cc.html().replace(/\&#160\;/ig,'');
113
- $t.p.onSelectCell($t.rows[iRow].id,nm,tmp,iRow,iCol);
114
- }
115
- }
116
- $t.p.iCol = iCol; $t.p.iRow = iRow;
117
- });
118
- },
119
- saveCell : function (iRow, iCol){
120
- return this.each(function(){
121
- var $t= this, fr;
122
- if (!$t.grid || $t.p.cellEdit !== true) {return;}
123
- if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
124
- if(fr !== null) {
125
- var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
126
- cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ;
127
- switch (cm.edittype) {
128
- case "select":
129
- if(!cm.editoptions.multiple) {
130
- v = $("#"+iRow+"_"+nmjq+">option:selected",$t.rows[iRow]).val();
131
- v2 = $("#"+iRow+"_"+nmjq+">option:selected",$t.rows[iRow]).text();
132
- } else {
133
- var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
134
- v = $(sel).val();
135
- if(v) { v.join(",");} else { v=""; }
136
- $("option:selected",sel).each(
137
- function(i,selected){
138
- selectedText[i] = $(selected).text();
139
- }
140
- );
141
- v2 = selectedText.join(",");
142
- }
143
- if(cm.formatter) { v2 = v; }
144
- break;
145
- case "checkbox":
146
- var cbv = ["Yes","No"];
147
- if(cm.editoptions){
148
- cbv = cm.editoptions.value.split(":");
149
- }
150
- v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).attr("checked") ? cbv[0] : cbv[1];
151
- v2=v;
152
- break;
153
- case "password":
154
- case "text":
155
- case "textarea":
156
- case "button" :
157
- v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
158
- v2=v;
159
- break;
160
- case 'custom' :
161
- try {
162
- if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
163
- v = cm.editoptions.custom_value($(".customelement",cc),'get');
164
- if (v===undefined) { throw "e2";} else { v2=v; }
165
- } else { throw "e1"; }
166
- } catch (e) {
167
- if (e=="e1") { info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose); }
168
- if (e=="e2") { info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose); }
169
- else {info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); }
170
- }
171
- break;
172
- }
173
- // The common approach is if nothing changed do not do anything
174
- if (v2 != $t.p.savedRow[fr].v){
175
- if ($.isFunction($t.p.beforeSaveCell)) {
176
- var vv = $t.p.beforeSaveCell($t.rows[iRow].id,nm, v, iRow,iCol);
177
- if (vv) {v = vv;}
178
- }
179
- var cv = checkValues(v,iCol,$t);
180
- if(cv[0] === true) {
181
- var addpost = {};
182
- if ($.isFunction($t.p.beforeSubmitCell)) {
183
- addpost = $t.p.beforeSubmitCell($t.rows[iRow].id,nm, v, iRow,iCol);
184
- if (!addpost) {addpost={};}
185
- }
186
- if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
187
- if ($t.p.cellsubmit == 'remote') {
188
- if ($t.p.cellurl) {
189
- var postdata = {};
190
- if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
191
- postdata[nm] = v;
192
- var idname,oper, opers;
193
- opers = $t.p.prmNames;
194
- idname = opers.id;
195
- oper = opers.oper;
196
- postdata[idname] = $t.rows[iRow].id;
197
- postdata[oper] = opers.editoper;
198
- postdata = $.extend(addpost,postdata);
199
- $("#lui_"+$t.p.id).show();
200
- $t.grid.hDiv.loading = true;
201
- $.ajax( $.extend( {
202
- url: $t.p.cellurl,
203
- data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData(postdata) : postdata,
204
- type: "POST",
205
- complete: function (result, stat) {
206
- $("#lui_"+$t.p.id).hide();
207
- $t.grid.hDiv.loading = false;
208
- if (stat == 'success') {
209
- if ($.isFunction($t.p.afterSubmitCell)) {
210
- var ret = $t.p.afterSubmitCell(result,postdata.id,nm,v,iRow,iCol);
211
- if(ret[0] === true) {
212
- $(cc).empty();
213
- $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
214
- $(cc).addClass("dirty-cell");
215
- $($t.rows[iRow]).addClass("edited");
216
- if ($.isFunction($t.p.afterSaveCell)) {
217
- $t.p.afterSaveCell($t.rows[iRow].id,nm, v, iRow,iCol);
218
- }
219
- $t.p.savedRow.splice(0,1);
220
- } else {
221
- info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose);
222
- $($t).jqGrid("restoreCell",iRow,iCol);
223
- }
224
- } else {
225
- $(cc).empty();
226
- $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
227
- $(cc).addClass("dirty-cell");
228
- $($t.rows[iRow]).addClass("edited");
229
- if ($.isFunction($t.p.afterSaveCell)) {
230
- $t.p.afterSaveCell($t.rows[iRow].id,nm, v, iRow,iCol);
231
- }
232
- $t.p.savedRow.splice(0,1);
233
- }
234
- }
235
- },
236
- error:function(res,stat) {
237
- $("#lui_"+$t.p.id).hide();
238
- $t.grid.hDiv.loading = false;
239
- if ($.isFunction($t.p.errorCell)) {
240
- $t.p.errorCell(res,stat);
241
- $($t).jqGrid("restoreCell",iRow,iCol);
242
- } else {
243
- info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose);
244
- $($t).jqGrid("restoreCell",iRow,iCol);
245
- }
246
- }
247
- }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
248
- } else {
249
- try {
250
- info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose);
251
- $($t).jqGrid("restoreCell",iRow,iCol);
252
- } catch (e) {}
253
- }
254
- }
255
- if ($t.p.cellsubmit == 'clientArray') {
256
- $(cc).empty();
257
- $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
258
- $(cc).addClass("dirty-cell");
259
- $($t.rows[iRow]).addClass("edited");
260
- if ($.isFunction($t.p.afterSaveCell)) {
261
- $t.p.afterSaveCell($t.rows[iRow].id,nm, v, iRow,iCol);
262
- }
263
- $t.p.savedRow.splice(0,1);
264
- }
265
- } else {
266
- try {
267
- window.setTimeout(function(){info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100);
268
- $($t).jqGrid("restoreCell",iRow,iCol);
269
- } catch (e) {}
270
- }
271
- } else {
272
- $($t).jqGrid("restoreCell",iRow,iCol);
273
- }
274
- }
275
- if ($.browser.opera) {
276
- $("#"+$t.p.knv).attr("tabindex","-1").focus();
277
- } else {
278
- window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
279
- }
280
- });
281
- },
282
- restoreCell : function(iRow, iCol) {
283
- return this.each(function(){
284
- var $t= this, fr;
285
- if (!$t.grid || $t.p.cellEdit !== true ) {return;}
286
- if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
287
- if(fr !== null) {
288
- var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
289
- // datepicker fix
290
- if($.isFunction($.fn.datepicker)) {
291
- try {
292
- $("input.hasDatepicker",cc).datepicker('hide');
293
- } catch (e) {}
294
- }
295
- $(cc).empty().attr("tabindex","-1");
296
- $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
297
- if ($.isFunction($t.p.afterRestoreCell)) {
298
- $t.p.afterRestoreCell($t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
299
- }
300
- $t.p.savedRow.splice(0,1);
301
- }
302
- window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
303
- });
304
- },
305
- nextCell : function (iRow,iCol) {
306
- return this.each(function (){
307
- var $t = this, nCol=false;
308
- if (!$t.grid || $t.p.cellEdit !== true) {return;}
309
- // try to find next editable cell
310
- for (var i=iCol+1; i<$t.p.colModel.length; i++) {
311
- if ( $t.p.colModel[i].editable ===true) {
312
- nCol = i; break;
313
- }
314
- }
315
- if(nCol !== false) {
316
- $($t).jqGrid("editCell",iRow,nCol,true);
317
- } else {
318
- if ($t.p.savedRow.length >0) {
319
- $($t).jqGrid("saveCell",iRow,iCol);
320
- }
321
- }
322
- });
323
- },
324
- prevCell : function (iRow,iCol) {
325
- return this.each(function (){
326
- var $t = this, nCol=false;
327
- if (!$t.grid || $t.p.cellEdit !== true) {return;}
328
- // try to find next editable cell
329
- for (var i=iCol-1; i>=0; i--) {
330
- if ( $t.p.colModel[i].editable ===true) {
331
- nCol = i; break;
332
- }
333
- }
334
- if(nCol !== false) {
335
- $($t).jqGrid("editCell",iRow,nCol,true);
336
- } else {
337
- if ($t.p.savedRow.length >0) {
338
- $($t).jqGrid("saveCell",iRow,iCol);
339
- }
340
- }
341
- });
342
- },
343
- GridNav : function() {
344
- return this.each(function () {
345
- var $t = this;
346
- if (!$t.grid || $t.p.cellEdit !== true ) {return;}
347
- // trick to process keydown on non input elements
348
- $t.p.knv = $t.p.id + "_kn";
349
- var selection = $("<span style='width:0px;height:0px;background-color:black;' tabindex='0'><span tabindex='-1' style='width:0px;height:0px;background-color:grey' id='"+$t.p.knv+"'></span></span>"),
350
- i, kdir;
351
- $(selection).insertBefore($t.grid.cDiv);
352
- $("#"+$t.p.knv)
353
- .focus()
354
- .keydown(function (e){
355
- kdir = e.keyCode;
356
- if($t.p.direction == "rtl") {
357
- if(kdir==37) { kdir = 39;}
358
- else if (kdir==39) { kdir = 37; }
359
- }
360
- switch (kdir) {
361
- case 38:
362
- if ($t.p.iRow-1 >=0 ) {
363
- scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
364
- $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
365
- }
366
- break;
367
- case 40 :
368
- if ($t.p.iRow+1 <= $t.rows.length-1) {
369
- scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
370
- $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
371
- }
372
- break;
373
- case 37 :
374
- if ($t.p.iCol -1 >= 0) {
375
- i = findNextVisible($t.p.iCol-1,'lft');
376
- scrollGrid($t.p.iRow, i,'h');
377
- $($t).jqGrid("editCell",$t.p.iRow, i,false);
378
- }
379
- break;
380
- case 39 :
381
- if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
382
- i = findNextVisible($t.p.iCol+1,'rgt');
383
- scrollGrid($t.p.iRow,i,'h');
384
- $($t).jqGrid("editCell",$t.p.iRow,i,false);
385
- }
386
- break;
387
- case 13:
388
- if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
389
- $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
390
- }
391
- break;
392
- }
393
- return false;
394
- });
395
- function scrollGrid(iR, iC, tp){
396
- if (tp.substr(0,1)=='v') {
397
- var ch = $($t.grid.bDiv)[0].clientHeight,
398
- st = $($t.grid.bDiv)[0].scrollTop,
399
- nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
400
- pROT = $t.rows[iR].offsetTop;
401
- if(tp == 'vd') {
402
- if(nROT >= ch) {
403
- $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
404
- }
405
- }
406
- if(tp == 'vu'){
407
- if (pROT < st) {
408
- $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
409
- }
410
- }
411
- }
412
- if(tp=='h') {
413
- var cw = $($t.grid.bDiv)[0].clientWidth,
414
- sl = $($t.grid.bDiv)[0].scrollLeft,
415
- nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
416
- pCOL = $t.rows[iR].cells[iC].offsetLeft;
417
- if(nCOL >= cw+parseInt(sl,10)) {
418
- $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
419
- } else if (pCOL < sl) {
420
- $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
421
- }
422
- }
423
- }
424
- function findNextVisible(iC,act){
425
- var ind, i;
426
- if(act == 'lft') {
427
- ind = iC+1;
428
- for (i=iC;i>=0;i--){
429
- if ($t.p.colModel[i].hidden !== true) {
430
- ind = i;
431
- break;
432
- }
433
- }
434
- }
435
- if(act == 'rgt') {
436
- ind = iC-1;
437
- for (i=iC; i<$t.p.colModel.length;i++){
438
- if ($t.p.colModel[i].hidden !== true) {
439
- ind = i;
440
- break;
441
- }
442
- }
443
- }
444
- return ind;
445
- }
446
- });
447
- },
448
- getChangedCells : function (mthd) {
449
- var ret=[];
450
- if (!mthd) {mthd='all';}
451
- this.each(function(){
452
- var $t= this,nm;
453
- if (!$t.grid || $t.p.cellEdit !== true ) {return;}
454
- $($t.rows).each(function(j){
455
- var res = {};
456
- if ($(this).hasClass("edited")) {
457
- $('td',this).each( function(i) {
458
- nm = $t.p.colModel[i].name;
459
- if ( nm !== 'cb' && nm !== 'subgrid') {
460
- if (mthd=='dirty') {
461
- if ($(this).hasClass('dirty-cell')) {
462
- try {
463
- res[nm] = $.unformat(this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
464
- } catch (e){
465
- res[nm] = $.jgrid.htmlDecode($(this).html());
466
- }
467
- }
468
- } else {
469
- try {
470
- res[nm] = $.unformat(this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
471
- } catch (e) {
472
- res[nm] = $.jgrid.htmlDecode($(this).html());
473
- }
474
- }
475
- }
476
- });
477
- res.id = this.id;
478
- ret.push(res);
479
- }
480
- });
481
- });
482
- return ret;
483
- }
484
- /// end cell editing
485
- });
486
- })(jQuery);
1
+ ;(function($){
2
+ /*
3
+ **
4
+ * jqGrid extension for cellediting Grid Data
5
+ * Tony Tomov tony@trirand.com
6
+ * http://trirand.com/blog/
7
+ * Dual licensed under the MIT and GPL licenses:
8
+ * http://www.opensource.org/licenses/mit-license.php
9
+ * http://www.gnu.org/licenses/gpl-2.0.html
10
+ **/
11
+ /**
12
+ * all events and options here are aded anonynous and not in the base grid
13
+ * since the array is to big. Here is the order of execution.
14
+ * From this point we use jQuery isFunction
15
+ * formatCell
16
+ * beforeEditCell,
17
+ * onSelectCell (used only for noneditable cels)
18
+ * afterEditCell,
19
+ * beforeSaveCell, (called before validation of values if any)
20
+ * beforeSubmitCell (if cellsubmit remote (ajax))
21
+ * afterSubmitCell(if cellsubmit remote (ajax)),
22
+ * afterSaveCell,
23
+ * errorCell,
24
+ * serializeCellData - new
25
+ * Options
26
+ * cellsubmit (remote,clientArray) (added in grid options)
27
+ * cellurl
28
+ * ajaxCellOptions
29
+ * */
30
+ $.jgrid.extend({
31
+ editCell : function (iRow,iCol, ed){
32
+ return this.each(function (){
33
+ var $t = this, nm, tmp,cc;
34
+ if (!$t.grid || $t.p.cellEdit !== true) {return;}
35
+ iCol = parseInt(iCol,10);
36
+ // select the row that can be used for other methods
37
+ $t.p.selrow = $t.rows[iRow].id;
38
+ if (!$t.p.knv) {$($t).jqGrid("GridNav");}
39
+ // check to see if we have already edited cell
40
+ if ($t.p.savedRow.length>0) {
41
+ // prevent second click on that field and enable selects
42
+ if (ed===true ) {
43
+ if(iRow == $t.p.iRow && iCol == $t.p.iCol){
44
+ return;
45
+ }
46
+ }
47
+ // save the cell
48
+ $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
49
+ } else {
50
+ window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
51
+ }
52
+ nm = $t.p.colModel[iCol].name;
53
+ if (nm=='subgrid' || nm=='cb' || nm=='rn') {return;}
54
+ cc = $("td:eq("+iCol+")",$t.rows[iRow]);
55
+ if ($t.p.colModel[iCol].editable===true && ed===true && !cc.hasClass("not-editable-cell")) {
56
+ if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
57
+ $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
58
+ $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
59
+ }
60
+ $(cc).addClass("edit-cell ui-state-highlight");
61
+ $($t.rows[iRow]).addClass("selected-row ui-state-hover");
62
+ try {
63
+ tmp = $.unformat(cc,{rowId: $t.rows[iRow].id, colModel:$t.p.colModel[iCol]},iCol);
64
+ } catch (_) {
65
+ tmp = $(cc).html();
66
+ }
67
+ if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
68
+ if (!$t.p.colModel[iCol].edittype) {$t.p.colModel[iCol].edittype = "text";}
69
+ $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
70
+ if($.isFunction($t.p.formatCell)) {
71
+ var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
72
+ if(tmp2 !== undefined ) {tmp = tmp2;}
73
+ }
74
+ var opt = $.extend({}, $t.p.colModel[iCol].editoptions || {} ,{id:iRow+"_"+nm,name:nm});
75
+ var elc = $.jgrid.createEl($t.p.colModel[iCol].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
76
+ if ($.isFunction($t.p.beforeEditCell)) {
77
+ $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
78
+ }
79
+ $(cc).html("").append(elc).attr("tabindex","0");
80
+ window.setTimeout(function () { $(elc).focus();},0);
81
+ $("input, select, textarea",cc).bind("keydown",function(e) {
82
+ if (e.keyCode === 27) {
83
+ if($("input.hasDatepicker",cc).length >0) {
84
+ if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
85
+ else { $("input.hasDatepicker",cc).datepicker('hide'); }
86
+ } else {
87
+ $($t).jqGrid("restoreCell",iRow,iCol);
88
+ }
89
+ } //ESC
90
+ if (e.keyCode === 13) {$($t).jqGrid("saveCell",iRow,iCol);}//Enter
91
+ if (e.keyCode == 9) {
92
+ if(!$t.grid.hDiv.loading ) {
93
+ if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
94
+ else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
95
+ } else {
96
+ return false;
97
+ }
98
+ }
99
+ e.stopPropagation();
100
+ });
101
+ if ($.isFunction($t.p.afterEditCell)) {
102
+ $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
103
+ }
104
+ } else {
105
+ if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
106
+ $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
107
+ $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
108
+ }
109
+ cc.addClass("edit-cell ui-state-highlight");
110
+ $($t.rows[iRow]).addClass("selected-row ui-state-hover");
111
+ if ($.isFunction($t.p.onSelectCell)) {
112
+ tmp = cc.html().replace(/\&#160\;/ig,'');
113
+ $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
114
+ }
115
+ }
116
+ $t.p.iCol = iCol; $t.p.iRow = iRow;
117
+ });
118
+ },
119
+ saveCell : function (iRow, iCol){
120
+ return this.each(function(){
121
+ var $t= this, fr;
122
+ if (!$t.grid || $t.p.cellEdit !== true) {return;}
123
+ if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
124
+ if(fr !== null) {
125
+ var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
126
+ cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ;
127
+ switch (cm.edittype) {
128
+ case "select":
129
+ if(!cm.editoptions.multiple) {
130
+ v = $("#"+iRow+"_"+nmjq+">option:selected",$t.rows[iRow]).val();
131
+ v2 = $("#"+iRow+"_"+nmjq+">option:selected",$t.rows[iRow]).text();
132
+ } else {
133
+ var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
134
+ v = $(sel).val();
135
+ if(v) { v.join(",");} else { v=""; }
136
+ $("option:selected",sel).each(
137
+ function(i,selected){
138
+ selectedText[i] = $(selected).text();
139
+ }
140
+ );
141
+ v2 = selectedText.join(",");
142
+ }
143
+ if(cm.formatter) { v2 = v; }
144
+ break;
145
+ case "checkbox":
146
+ var cbv = ["Yes","No"];
147
+ if(cm.editoptions){
148
+ cbv = cm.editoptions.value.split(":");
149
+ }
150
+ v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).attr("checked") ? cbv[0] : cbv[1];
151
+ v2=v;
152
+ break;
153
+ case "password":
154
+ case "text":
155
+ case "textarea":
156
+ case "button" :
157
+ v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
158
+ v2=v;
159
+ break;
160
+ case 'custom' :
161
+ try {
162
+ if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
163
+ v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get');
164
+ if (v===undefined) { throw "e2";} else { v2=v; }
165
+ } else { throw "e1"; }
166
+ } catch (e) {
167
+ if (e=="e1") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose); }
168
+ if (e=="e2") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose); }
169
+ else {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); }
170
+ }
171
+ break;
172
+ }
173
+ // The common approach is if nothing changed do not do anything
174
+ if (v2 != $t.p.savedRow[fr].v){
175
+ if ($.isFunction($t.p.beforeSaveCell)) {
176
+ var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
177
+ if (vv) {v = vv; v2=vv;}
178
+ }
179
+ var cv = $.jgrid.checkValues(v,iCol,$t);
180
+ if(cv[0] === true) {
181
+ var addpost = {};
182
+ if ($.isFunction($t.p.beforeSubmitCell)) {
183
+ addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
184
+ if (!addpost) {addpost={};}
185
+ }
186
+ if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
187
+ if ($t.p.cellsubmit == 'remote') {
188
+ if ($t.p.cellurl) {
189
+ var postdata = {};
190
+ if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
191
+ postdata[nm] = v;
192
+ var idname,oper, opers;
193
+ opers = $t.p.prmNames;
194
+ idname = opers.id;
195
+ oper = opers.oper;
196
+ postdata[idname] = $t.rows[iRow].id;
197
+ postdata[oper] = opers.editoper;
198
+ postdata = $.extend(addpost,postdata);
199
+ $("#lui_"+$t.p.id).show();
200
+ $t.grid.hDiv.loading = true;
201
+ $.ajax( $.extend( {
202
+ url: $t.p.cellurl,
203
+ data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata,
204
+ type: "POST",
205
+ complete: function (result, stat) {
206
+ $("#lui_"+$t.p.id).hide();
207
+ $t.grid.hDiv.loading = false;
208
+ if (stat == 'success') {
209
+ if ($.isFunction($t.p.afterSubmitCell)) {
210
+ var ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol);
211
+ if(ret[0] === true) {
212
+ $(cc).empty();
213
+ $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
214
+ $(cc).addClass("dirty-cell");
215
+ $($t.rows[iRow]).addClass("edited");
216
+ if ($.isFunction($t.p.afterSaveCell)) {
217
+ $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
218
+ }
219
+ $t.p.savedRow.splice(0,1);
220
+ } else {
221
+ $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose);
222
+ $($t).jqGrid("restoreCell",iRow,iCol);
223
+ }
224
+ } else {
225
+ $(cc).empty();
226
+ $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
227
+ $(cc).addClass("dirty-cell");
228
+ $($t.rows[iRow]).addClass("edited");
229
+ if ($.isFunction($t.p.afterSaveCell)) {
230
+ $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
231
+ }
232
+ $t.p.savedRow.splice(0,1);
233
+ }
234
+ }
235
+ },
236
+ error:function(res,stat) {
237
+ $("#lui_"+$t.p.id).hide();
238
+ $t.grid.hDiv.loading = false;
239
+ if ($.isFunction($t.p.errorCell)) {
240
+ $t.p.errorCell.call($t, res,stat);
241
+ $($t).jqGrid("restoreCell",iRow,iCol);
242
+ } else {
243
+ $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose);
244
+ $($t).jqGrid("restoreCell",iRow,iCol);
245
+ }
246
+ }
247
+ }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
248
+ } else {
249
+ try {
250
+ $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose);
251
+ $($t).jqGrid("restoreCell",iRow,iCol);
252
+ } catch (e) {}
253
+ }
254
+ }
255
+ if ($t.p.cellsubmit == 'clientArray') {
256
+ $(cc).empty();
257
+ $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
258
+ $(cc).addClass("dirty-cell");
259
+ $($t.rows[iRow]).addClass("edited");
260
+ if ($.isFunction($t.p.afterSaveCell)) {
261
+ $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
262
+ }
263
+ $t.p.savedRow.splice(0,1);
264
+ }
265
+ } else {
266
+ try {
267
+ window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100);
268
+ $($t).jqGrid("restoreCell",iRow,iCol);
269
+ } catch (e) {}
270
+ }
271
+ } else {
272
+ $($t).jqGrid("restoreCell",iRow,iCol);
273
+ }
274
+ }
275
+ if ($.browser.opera) {
276
+ $("#"+$t.p.knv).attr("tabindex","-1").focus();
277
+ } else {
278
+ window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
279
+ }
280
+ });
281
+ },
282
+ restoreCell : function(iRow, iCol) {
283
+ return this.each(function(){
284
+ var $t= this, fr;
285
+ if (!$t.grid || $t.p.cellEdit !== true ) {return;}
286
+ if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
287
+ if(fr !== null) {
288
+ var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
289
+ // datepicker fix
290
+ if($.isFunction($.fn.datepicker)) {
291
+ try {
292
+ $("input.hasDatepicker",cc).datepicker('hide');
293
+ } catch (e) {}
294
+ }
295
+ $(cc).empty().attr("tabindex","-1");
296
+ $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
297
+ if ($.isFunction($t.p.afterRestoreCell)) {
298
+ $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
299
+ }
300
+ $t.p.savedRow.splice(0,1);
301
+ }
302
+ window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
303
+ });
304
+ },
305
+ nextCell : function (iRow,iCol) {
306
+ return this.each(function (){
307
+ var $t = this, nCol=false;
308
+ if (!$t.grid || $t.p.cellEdit !== true) {return;}
309
+ // try to find next editable cell
310
+ for (var i=iCol+1; i<$t.p.colModel.length; i++) {
311
+ if ( $t.p.colModel[i].editable ===true) {
312
+ nCol = i; break;
313
+ }
314
+ }
315
+ if(nCol !== false) {
316
+ $($t).jqGrid("editCell",iRow,nCol,true);
317
+ } else {
318
+ if ($t.p.savedRow.length >0) {
319
+ $($t).jqGrid("saveCell",iRow,iCol);
320
+ }
321
+ }
322
+ });
323
+ },
324
+ prevCell : function (iRow,iCol) {
325
+ return this.each(function (){
326
+ var $t = this, nCol=false;
327
+ if (!$t.grid || $t.p.cellEdit !== true) {return;}
328
+ // try to find next editable cell
329
+ for (var i=iCol-1; i>=0; i--) {
330
+ if ( $t.p.colModel[i].editable ===true) {
331
+ nCol = i; break;
332
+ }
333
+ }
334
+ if(nCol !== false) {
335
+ $($t).jqGrid("editCell",iRow,nCol,true);
336
+ } else {
337
+ if ($t.p.savedRow.length >0) {
338
+ $($t).jqGrid("saveCell",iRow,iCol);
339
+ }
340
+ }
341
+ });
342
+ },
343
+ GridNav : function() {
344
+ return this.each(function () {
345
+ var $t = this;
346
+ if (!$t.grid || $t.p.cellEdit !== true ) {return;}
347
+ // trick to process keydown on non input elements
348
+ $t.p.knv = $t.p.id + "_kn";
349
+ var selection = $("<span style='width:0px;height:0px;background-color:black;' tabindex='0'><span tabindex='-1' style='width:0px;height:0px;background-color:grey' id='"+$t.p.knv+"'></span></span>"),
350
+ i, kdir;
351
+ $(selection).insertBefore($t.grid.cDiv);
352
+ $("#"+$t.p.knv)
353
+ .focus()
354
+ .keydown(function (e){
355
+ kdir = e.keyCode;
356
+ if($t.p.direction == "rtl") {
357
+ if(kdir==37) { kdir = 39;}
358
+ else if (kdir==39) { kdir = 37; }
359
+ }
360
+ switch (kdir) {
361
+ case 38:
362
+ if ($t.p.iRow-1 >0 ) {
363
+ scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
364
+ $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
365
+ }
366
+ break;
367
+ case 40 :
368
+ if ($t.p.iRow+1 <= $t.rows.length-1) {
369
+ scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
370
+ $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
371
+ }
372
+ break;
373
+ case 37 :
374
+ if ($t.p.iCol -1 >= 0) {
375
+ i = findNextVisible($t.p.iCol-1,'lft');
376
+ scrollGrid($t.p.iRow, i,'h');
377
+ $($t).jqGrid("editCell",$t.p.iRow, i,false);
378
+ }
379
+ break;
380
+ case 39 :
381
+ if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
382
+ i = findNextVisible($t.p.iCol+1,'rgt');
383
+ scrollGrid($t.p.iRow,i,'h');
384
+ $($t).jqGrid("editCell",$t.p.iRow,i,false);
385
+ }
386
+ break;
387
+ case 13:
388
+ if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
389
+ $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
390
+ }
391
+ break;
392
+ }
393
+ return false;
394
+ });
395
+ function scrollGrid(iR, iC, tp){
396
+ if (tp.substr(0,1)=='v') {
397
+ var ch = $($t.grid.bDiv)[0].clientHeight,
398
+ st = $($t.grid.bDiv)[0].scrollTop,
399
+ nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
400
+ pROT = $t.rows[iR].offsetTop;
401
+ if(tp == 'vd') {
402
+ if(nROT >= ch) {
403
+ $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
404
+ }
405
+ }
406
+ if(tp == 'vu'){
407
+ if (pROT < st ) {
408
+ $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
409
+ }
410
+ }
411
+ }
412
+ if(tp=='h') {
413
+ var cw = $($t.grid.bDiv)[0].clientWidth,
414
+ sl = $($t.grid.bDiv)[0].scrollLeft,
415
+ nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
416
+ pCOL = $t.rows[iR].cells[iC].offsetLeft;
417
+ if(nCOL >= cw+parseInt(sl,10)) {
418
+ $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
419
+ } else if (pCOL < sl) {
420
+ $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
421
+ }
422
+ }
423
+ }
424
+ function findNextVisible(iC,act){
425
+ var ind, i;
426
+ if(act == 'lft') {
427
+ ind = iC+1;
428
+ for (i=iC;i>=0;i--){
429
+ if ($t.p.colModel[i].hidden !== true) {
430
+ ind = i;
431
+ break;
432
+ }
433
+ }
434
+ }
435
+ if(act == 'rgt') {
436
+ ind = iC-1;
437
+ for (i=iC; i<$t.p.colModel.length;i++){
438
+ if ($t.p.colModel[i].hidden !== true) {
439
+ ind = i;
440
+ break;
441
+ }
442
+ }
443
+ }
444
+ return ind;
445
+ }
446
+ });
447
+ },
448
+ getChangedCells : function (mthd) {
449
+ var ret=[];
450
+ if (!mthd) {mthd='all';}
451
+ this.each(function(){
452
+ var $t= this,nm;
453
+ if (!$t.grid || $t.p.cellEdit !== true ) {return;}
454
+ $($t.rows).each(function(j){
455
+ var res = {};
456
+ if ($(this).hasClass("edited")) {
457
+ $('td',this).each( function(i) {
458
+ nm = $t.p.colModel[i].name;
459
+ if ( nm !== 'cb' && nm !== 'subgrid') {
460
+ if (mthd=='dirty') {
461
+ if ($(this).hasClass('dirty-cell')) {
462
+ try {
463
+ res[nm] = $.unformat(this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
464
+ } catch (e){
465
+ res[nm] = $.jgrid.htmlDecode($(this).html());
466
+ }
467
+ }
468
+ } else {
469
+ try {
470
+ res[nm] = $.unformat(this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
471
+ } catch (e) {
472
+ res[nm] = $.jgrid.htmlDecode($(this).html());
473
+ }
474
+ }
475
+ }
476
+ });
477
+ res.id = this.id;
478
+ ret.push(res);
479
+ }
480
+ });
481
+ });
482
+ return ret;
483
+ }
484
+ /// end cell editing
485
+ });
486
+ })(jQuery);