rails_jq_grid 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/COPYRIGHT.txt +17 -0
  2. data/GPL-LICENSE +675 -0
  3. data/README.rdoc +176 -0
  4. data/Rakefile +47 -0
  5. data/VERSION +1 -0
  6. data/app/helpers/rails_jq_grid/jq_grid_css_helper.rb +29 -0
  7. data/app/helpers/rails_jq_grid/jq_grid_helper.rb +21 -0
  8. data/app/helpers/rails_jq_grid/jq_grid_js_helper.rb +30 -0
  9. data/app/models/rails_jq_grid/jq_grid.rb +315 -0
  10. data/app/models/rails_jq_grid/jq_grid_column.rb +33 -0
  11. data/app/models/rails_jq_grid/jq_grid_method_missing.rb +50 -0
  12. data/app/models/rails_jq_grid/jq_grid_option_or_method.rb +46 -0
  13. data/lib/rails_jq_grid/acts_as_jq_grid_able.rb +76 -0
  14. data/lib/rails_jq_grid/acts_as_jq_grid_data_source.rb +34 -0
  15. data/lib/rails_jq_grid/engine.rb +23 -0
  16. data/lib/rails_jq_grid.rb +7 -0
  17. data/lib/tasks/rails_jq_grid.rake +1 -0
  18. data/public/javascripts/rails-jqgrid/Changes.txt +1160 -0
  19. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg.js +1 -0
  20. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg1251.js +1 -0
  21. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cat.js +1 -0
  22. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cn.js +1 -0
  23. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cs.js +1 -0
  24. data/public/javascripts/rails-jqgrid/i18n/grid.locale-de.js +1 -0
  25. data/public/javascripts/rails-jqgrid/i18n/grid.locale-dk.js +1 -0
  26. data/public/javascripts/rails-jqgrid/i18n/grid.locale-el.js +1 -0
  27. data/public/javascripts/rails-jqgrid/i18n/grid.locale-en.js +1 -0
  28. data/public/javascripts/rails-jqgrid/i18n/grid.locale-es.js +1 -0
  29. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fa.js +1 -0
  30. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fi.js +1 -0
  31. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fr.js +1 -0
  32. data/public/javascripts/rails-jqgrid/i18n/grid.locale-he.js +1 -0
  33. data/public/javascripts/rails-jqgrid/i18n/grid.locale-hu.js +1 -0
  34. data/public/javascripts/rails-jqgrid/i18n/grid.locale-is.js +1 -0
  35. data/public/javascripts/rails-jqgrid/i18n/grid.locale-it.js +1 -0
  36. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ja.js +1 -0
  37. data/public/javascripts/rails-jqgrid/i18n/grid.locale-nl.js +1 -0
  38. data/public/javascripts/rails-jqgrid/i18n/grid.locale-no.js +1 -0
  39. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pl.js +1 -0
  40. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt-br.js +1 -0
  41. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt.js +1 -0
  42. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ro.js +1 -0
  43. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ru.js +1 -0
  44. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sk.js +1 -0
  45. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sv.js +1 -0
  46. data/public/javascripts/rails-jqgrid/i18n/grid.locale-tr.js +1 -0
  47. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ua.js +1 -0
  48. data/public/javascripts/rails-jqgrid/install.txt +43 -0
  49. data/public/javascripts/rails-jqgrid/jquery-1.4.2.min.js +154 -0
  50. data/public/javascripts/rails-jqgrid/jquery-ui-1.8.4.custom.min.js +763 -0
  51. data/public/javascripts/rails-jqgrid/jquery.jqGrid.min.js +445 -0
  52. data/public/javascripts/rails-jqgrid/src/JsonXml.js +330 -0
  53. data/public/javascripts/rails-jqgrid/src/css/ellipsis-xbl.xml +13 -0
  54. data/public/javascripts/rails-jqgrid/src/css/jquery.searchFilter.css +7 -0
  55. data/public/javascripts/rails-jqgrid/src/css/ui.jqgrid.css +129 -0
  56. data/public/javascripts/rails-jqgrid/src/css/ui.multiselect.css +30 -0
  57. data/public/javascripts/rails-jqgrid/src/grid.base.js +3003 -0
  58. data/public/javascripts/rails-jqgrid/src/grid.celledit.js +486 -0
  59. data/public/javascripts/rails-jqgrid/src/grid.common.js +636 -0
  60. data/public/javascripts/rails-jqgrid/src/grid.custom.js +818 -0
  61. data/public/javascripts/rails-jqgrid/src/grid.formedit.js +1872 -0
  62. data/public/javascripts/rails-jqgrid/src/grid.import.js +201 -0
  63. data/public/javascripts/rails-jqgrid/src/grid.inlinedit.js +250 -0
  64. data/public/javascripts/rails-jqgrid/src/grid.jqueryui.js +503 -0
  65. data/public/javascripts/rails-jqgrid/src/grid.loader.js +47 -0
  66. data/public/javascripts/rails-jqgrid/src/grid.postext.js +64 -0
  67. data/public/javascripts/rails-jqgrid/src/grid.setcolumns.js +126 -0
  68. data/public/javascripts/rails-jqgrid/src/grid.subgrid.js +260 -0
  69. data/public/javascripts/rails-jqgrid/src/grid.tbltogrid.js +106 -0
  70. data/public/javascripts/rails-jqgrid/src/grid.treegrid.js +483 -0
  71. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg.js +132 -0
  72. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg1251.js +132 -0
  73. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cat.js +128 -0
  74. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cn.js +132 -0
  75. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cs.js +128 -0
  76. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-de.js +128 -0
  77. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-dk.js +128 -0
  78. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-el.js +126 -0
  79. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-en.js +128 -0
  80. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-es.js +128 -0
  81. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fa.js +125 -0
  82. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fi.js +130 -0
  83. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fr.js +126 -0
  84. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-he.js +127 -0
  85. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-hu.js +129 -0
  86. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-is.js +126 -0
  87. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-it.js +1 -0
  88. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ja.js +155 -0
  89. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-nl.js +149 -0
  90. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-no.js +1 -0
  91. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pl.js +127 -0
  92. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt-br.js +127 -0
  93. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt.js +125 -0
  94. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ro.js +139 -0
  95. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ru.js +127 -0
  96. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sk.js +127 -0
  97. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sv.js +127 -0
  98. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-tr.js +126 -0
  99. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ua.js +127 -0
  100. data/public/javascripts/rails-jqgrid/src/jqDnR.js +68 -0
  101. data/public/javascripts/rails-jqgrid/src/jqModal.js +69 -0
  102. data/public/javascripts/rails-jqgrid/src/jquery.fmatter.js +542 -0
  103. data/public/javascripts/rails-jqgrid/src/jquery.searchFilter.js +716 -0
  104. data/public/javascripts/rails-jqgrid/src/ui.multiselect.js +314 -0
  105. data/public/stylesheets/rails-jqgrid/ellipsis-xbl.xml +13 -0
  106. data/public/stylesheets/rails-jqgrid/themes/AUTHORS.txt +30 -0
  107. data/public/stylesheets/rails-jqgrid/themes/GPL-LICENSE.txt +278 -0
  108. data/public/stylesheets/rails-jqgrid/themes/MIT-LICENSE.txt +25 -0
  109. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  110. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  111. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  112. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  113. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  114. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  115. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  116. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  117. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_222222_256x240.png +0 -0
  118. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  119. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_454545_256x240.png +0 -0
  120. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_888888_256x240.png +0 -0
  121. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  122. data/public/stylesheets/rails-jqgrid/themes/smoothness/jquery-ui-1.8.4.custom.css +572 -0
  123. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_flat_55_999999_40x100.png +0 -0
  124. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_flat_75_aaaaaa_40x100.png +0 -0
  125. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_glass_45_0078ae_1x400.png +0 -0
  126. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_glass_55_f8da4e_1x400.png +0 -0
  127. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_glass_75_79c9ec_1x400.png +0 -0
  128. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_gloss-wave_45_e14f1c_500x100.png +0 -0
  129. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_gloss-wave_50_6eac2c_500x100.png +0 -0
  130. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_gloss-wave_75_2191c0_500x100.png +0 -0
  131. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
  132. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_0078ae_256x240.png +0 -0
  133. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_056b93_256x240.png +0 -0
  134. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_d8e7f3_256x240.png +0 -0
  135. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_e0fdff_256x240.png +0 -0
  136. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_f5e175_256x240.png +0 -0
  137. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_f7a50d_256x240.png +0 -0
  138. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_fcd113_256x240.png +0 -0
  139. data/public/stylesheets/rails-jqgrid/themes/start/jquery-ui-1.8.4.custom.css +573 -0
  140. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_flat_30_cccccc_40x100.png +0 -0
  141. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_flat_50_5c5c5c_40x100.png +0 -0
  142. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_glass_20_555555_1x400.png +0 -0
  143. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_glass_40_0078a3_1x400.png +0 -0
  144. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_glass_40_ffc73d_1x400.png +0 -0
  145. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png +0 -0
  146. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_highlight-soft_80_eeeeee_1x100.png +0 -0
  147. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_inset-soft_25_000000_1x100.png +0 -0
  148. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_inset-soft_30_f58400_1x100.png +0 -0
  149. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_222222_256x240.png +0 -0
  150. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_4b8e0b_256x240.png +0 -0
  151. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_a83300_256x240.png +0 -0
  152. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_cccccc_256x240.png +0 -0
  153. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_ffffff_256x240.png +0 -0
  154. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/jquery-ui-1.8.4.custom.css +572 -0
  155. data/public/stylesheets/rails-jqgrid/themes/version.txt +1 -0
  156. data/public/stylesheets/rails-jqgrid/ui.jqgrid.css +2 -0
  157. data/rails_jq_grid.gemspec +200 -0
  158. data/spec/spec.opts +1 -0
  159. data/spec/spec_helper.rb +8 -0
  160. metadata +240 -0
@@ -0,0 +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);