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,201 @@
1
+ ;(function($){
2
+ /*
3
+ * jqGrid extension for constructing Grid Data from external file
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
+ $.jgrid.extend({
11
+ jqGridImport : function(o) {
12
+ o = $.extend({
13
+ imptype : "xml", // xml, json, xmlstring, jsonstring
14
+ impstring: "",
15
+ impurl: "",
16
+ mtype: "GET",
17
+ impData : {},
18
+ xmlGrid :{
19
+ config : "roots>grid",
20
+ data: "roots>rows"
21
+ },
22
+ jsonGrid :{
23
+ config : "grid",
24
+ data: "data"
25
+ },
26
+ ajaxOptions :{}
27
+ }, o || {});
28
+ return this.each(function(){
29
+ var $t = this;
30
+ var XmlConvert = function (xml,o) {
31
+ var cnfg = $(o.xmlGrid.config,xml)[0];
32
+ var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1;
33
+ if(xmlJsonClass.xml2json && $.jgrid.parse) {
34
+ jstr = xmlJsonClass.xml2json(cnfg," ");
35
+ jstr = $.jgrid.parse(jstr);
36
+ for(var key in jstr) {
37
+ if(jstr.hasOwnProperty(key)) {
38
+ jstr1=jstr[key];
39
+ }
40
+ }
41
+ if(xmldata) {
42
+ // save the datatype
43
+ var svdatatype = jstr.grid.datatype;
44
+ jstr.grid.datatype = 'xmlstring';
45
+ jstr.grid.datastr = xml;
46
+ $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
47
+ } else {
48
+ $($t).jqGrid( jstr1 );
49
+ }
50
+ jstr = null;jstr1=null;
51
+ } else {
52
+ alert("xml2json or parse are not present");
53
+ }
54
+ };
55
+ var JsonConvert = function (jsonstr,o){
56
+ if (jsonstr && typeof jsonstr == 'string') {
57
+ var json = $.jgrid.parse(jsonstr);
58
+ var gprm = json[o.jsonGrid.config];
59
+ var jdata = json[o.jsonGrid.data];
60
+ if(jdata) {
61
+ var svdatatype = gprm.datatype;
62
+ gprm.datatype = 'jsonstring';
63
+ gprm.datastr = jdata;
64
+ $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
65
+ } else {
66
+ $($t).jqGrid( gprm );
67
+ }
68
+ }
69
+ };
70
+ switch (o.imptype){
71
+ case 'xml':
72
+ $.ajax($.extend({
73
+ url:o.impurl,
74
+ type:o.mtype,
75
+ data: o.impData,
76
+ dataType:"xml",
77
+ complete: function(xml,stat) {
78
+ if(stat == 'success') {
79
+ XmlConvert(xml.responseXML,o);
80
+ if($.isFunction(o.importComplete)) {
81
+ o.importComplete(xml);
82
+ }
83
+ }
84
+ xml=null;
85
+ }
86
+ }, o.ajaxOptions));
87
+ break;
88
+ case 'xmlstring' :
89
+ // we need to make just the conversion and use the same code as xml
90
+ if(o.impstring && typeof o.impstring == 'string') {
91
+ var xmld = $.jgrid.stringToDoc(o.impstring);
92
+ if(xmld) {
93
+ XmlConvert(xmld,o);
94
+ if($.isFunction(o.importComplete)) {
95
+ o.importComplete(xmld);
96
+ }
97
+ o.impstring = null;
98
+ }
99
+ xmld = null;
100
+ }
101
+ break;
102
+ case 'json':
103
+ $.ajax($.extend({
104
+ url:o.impurl,
105
+ type:o.mtype,
106
+ data: o.impData,
107
+ dataType:"json",
108
+ complete: function(json,stat) {
109
+ if(stat == 'success') {
110
+ JsonConvert(json.responseText,o );
111
+ if($.isFunction(o.importComplete)) {
112
+ o.importComplete(json);
113
+ }
114
+ }
115
+ json=null;
116
+ }
117
+ }, o.ajaxOptions ));
118
+ break;
119
+ case 'jsonstring' :
120
+ if(o.impstring && typeof o.impstring == 'string') {
121
+ JsonConvert(o.impstring,o );
122
+ if($.isFunction(o.importComplete)) {
123
+ o.importComplete(o.impstring);
124
+ }
125
+ o.impstring = null;
126
+ }
127
+ break;
128
+ }
129
+ });
130
+ },
131
+ jqGridExport : function(o) {
132
+ o = $.extend({
133
+ exptype : "xmlstring",
134
+ root: "grid",
135
+ ident: "\t"
136
+ }, o || {});
137
+ var ret = null;
138
+ this.each(function () {
139
+ if(!this.grid) { return;}
140
+ var gprm = $.extend({},$(this).jqGrid("getGridParam"));
141
+ // we need to check for:
142
+ // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
143
+ if(gprm.rownumbers) {
144
+ gprm.colNames.splice(0,1);
145
+ gprm.colModel.splice(0,1);
146
+ }
147
+ if(gprm.multiselect) {
148
+ gprm.colNames.splice(0,1);
149
+ gprm.colModel.splice(0,1);
150
+ }
151
+ if(gprm.subGrid) {
152
+ gprm.colNames.splice(0,1);
153
+ gprm.colModel.splice(0,1);
154
+ }
155
+ gprm.knv = null;
156
+ if(gprm.treeGrid) {
157
+ for (var key in gprm.treeReader) {
158
+ if(gprm.treeReader.hasOwnProperty(key)) {
159
+ gprm.colNames.splice(gprm.colNames.length-1);
160
+ gprm.colModel.splice(gprm.colModel.length-1);
161
+ }
162
+ }
163
+ }
164
+ switch (o.exptype) {
165
+ case 'xmlstring' :
166
+ ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
167
+ break;
168
+ case 'jsonstring' :
169
+ ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident)+"}";
170
+ if(gprm.postData.filters !== undefined) {
171
+ ret=ret.replace(/filters":"/,'filters":');
172
+ ret=ret.replace(/}]}"/,'}]}');
173
+ }
174
+ break;
175
+ }
176
+ });
177
+ return ret;
178
+ },
179
+ excelExport : function(o) {
180
+ o = $.extend({
181
+ exptype : "remote",
182
+ url : null,
183
+ oper: "oper",
184
+ tag: "excel",
185
+ exportOptions : {}
186
+ }, o || {});
187
+ return this.each(function(){
188
+ if(!this.grid) { return;}
189
+ var url;
190
+ if(o.exptype == "remote") {
191
+ var pdata = $.extend({},this.p.postData);
192
+ pdata[o.oper] = o.tag;
193
+ var params = jQuery.param(pdata);
194
+ if(o.url.indexOf("?") != -1) { url = o.url+"&"+params; }
195
+ else { url = o.url+"?"+params; }
196
+ window.location = url;
197
+ }
198
+ });
199
+ }
200
+ });
201
+ })(jQuery);
@@ -0,0 +1,250 @@
1
+ ;(function($){
2
+ /**
3
+ * jqGrid extension for manipulating 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
+ $.jgrid.extend({
11
+ //Editing
12
+ editRow : function(rowid,keys,oneditfunc,succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
13
+ return this.each(function(){
14
+ var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm;
15
+ if (!$t.grid ) { return; }
16
+ ind = $($t).jqGrid("getInd",rowid,true);
17
+ if( ind === false ) {return;}
18
+ editable = $(ind).attr("editable") || "0";
19
+ if (editable == "0" && !$(ind).hasClass("not-editable-row")) {
20
+ cm = $t.p.colModel;
21
+ $('td',ind).each( function(i) {
22
+ nm = cm[i].name;
23
+ var treeg = $t.p.treeGrid===true && nm == $t.p.ExpandColumn;
24
+ if(treeg) { tmp = $("span:first",this).html();}
25
+ else {
26
+ try {
27
+ tmp = $.unformat(this,{rowId:rowid, colModel:cm[i]},i);
28
+ } catch (_) {
29
+ tmp = $(this).html();
30
+ }
31
+ }
32
+ if ( nm != 'cb' && nm != 'subgrid' && nm != 'rn') {
33
+ if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
34
+ svr[nm]=tmp;
35
+ if(cm[i].editable===true) {
36
+ if(focus===null) { focus = i; }
37
+ if (treeg) { $("span:first",this).html(""); }
38
+ else { $(this).html(""); }
39
+ var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm});
40
+ if(!cm[i].edittype) { cm[i].edittype = "text"; }
41
+ var elc = createEl(cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
42
+ $(elc).addClass("editable");
43
+ if(treeg) { $("span:first",this).append(elc); }
44
+ else { $(this).append(elc); }
45
+ //Again IE
46
+ if(cm[i].edittype == "select" && cm[i].editoptions.multiple===true && $.browser.msie) {
47
+ $(elc).width($(elc).width());
48
+ }
49
+ cnt++;
50
+ }
51
+ }
52
+ });
53
+ if(cnt > 0) {
54
+ svr.id = rowid; $t.p.savedRow.push(svr);
55
+ $(ind).attr("editable","1");
56
+ $("td:eq("+focus+") input",ind).focus();
57
+ if(keys===true) {
58
+ $(ind).bind("keydown",function(e) {
59
+ if (e.keyCode === 27) {$($t).jqGrid("restoreRow",rowid, afterrestorefunc);}
60
+ if (e.keyCode === 13) {
61
+ var ta = e.target;
62
+ if(ta.tagName == 'TEXTAREA') { return true; }
63
+ $($t).jqGrid("saveRow",rowid,succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc );
64
+ return false;
65
+ }
66
+ e.stopPropagation();
67
+ });
68
+ }
69
+ if( $.isFunction(oneditfunc)) { oneditfunc(rowid); }
70
+ }
71
+ }
72
+ });
73
+ },
74
+ saveRow : function(rowid, succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
75
+ return this.each(function(){
76
+ var $t = this, nm, tmp={}, tmp2={}, editable, fr, cv, ind;
77
+ if (!$t.grid ) { return; }
78
+ ind = $($t).jqGrid("getInd",rowid,true);
79
+ if(ind === false) {return;}
80
+ editable = $(ind).attr("editable");
81
+ url = url ? url : $t.p.editurl;
82
+ if (editable==="1") {
83
+ var cm;
84
+ $("td",ind).each(function(i) {
85
+ cm = $t.p.colModel[i];
86
+ nm = cm.name;
87
+ if ( nm != 'cb' && nm != 'subgrid' && cm.editable===true && nm != 'rn') {
88
+ switch (cm.edittype) {
89
+ case "checkbox":
90
+ var cbv = ["Yes","No"];
91
+ if(cm.editoptions ) {
92
+ cbv = cm.editoptions.value.split(":");
93
+ }
94
+ tmp[nm]= $("input",this).attr("checked") ? cbv[0] : cbv[1];
95
+ break;
96
+ case 'text':
97
+ case 'password':
98
+ case 'textarea':
99
+ case "button" :
100
+ tmp[nm]=$("input, textarea",this).val();
101
+ break;
102
+ case 'select':
103
+ if(!cm.editoptions.multiple) {
104
+ tmp[nm] = $("select>option:selected",this).val();
105
+ tmp2[nm] = $("select>option:selected", this).text();
106
+ } else {
107
+ var sel = $("select",this), selectedText = [];
108
+ tmp[nm] = $(sel).val();
109
+ if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
110
+ $("select > option:selected",this).each(
111
+ function(i,selected){
112
+ selectedText[i] = $(selected).text();
113
+ }
114
+ );
115
+ tmp2[nm] = selectedText.join(",");
116
+ }
117
+ if(cm.formatter && cm.formatter == 'select') { tmp2={}; }
118
+ break;
119
+ case 'custom' :
120
+ try {
121
+ if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
122
+ tmp[nm] = cm.editoptions.custom_value($(".customelement",this),'get');
123
+ if (tmp[nm] === undefined) { throw "e2"; }
124
+ } else { throw "e1"; }
125
+ } catch (e) {
126
+ if (e=="e1") { info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose); }
127
+ if (e=="e2") { info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose); }
128
+ else { info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); }
129
+ }
130
+ break;
131
+ }
132
+ cv = checkValues(tmp[nm],i,$t);
133
+ if(cv[0] === false) {
134
+ cv[1] = tmp[nm] + " " + cv[1];
135
+ return false;
136
+ }
137
+ if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); }
138
+ }
139
+ });
140
+ if (cv[0] === false){
141
+ try {
142
+ var positions = findPos($("#"+$.jgrid.jqID(rowid), $t.grid.bDiv)[0]);
143
+ info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]});
144
+ } catch (e) {
145
+ alert(cv[1]);
146
+ }
147
+ return;
148
+ }
149
+ if(tmp) {
150
+ var idname, opers, oper;
151
+ opers = $t.p.prmNames;
152
+ oper = opers.oper;
153
+ idname = opers.id;
154
+ tmp[oper] = opers.editoper;
155
+ tmp[idname] = rowid;
156
+ if(typeof($t.p.inlineData) == 'undefined') { $t.p.inlineData ={}; }
157
+ if(typeof(extraparam) == 'undefined') { extraparam ={}; }
158
+ tmp = $.extend({},tmp,$t.p.inlineData,extraparam);
159
+ }
160
+ if (url == 'clientArray') {
161
+ tmp = $.extend({},tmp, tmp2);
162
+ if($t.p.autoencode) {
163
+ $.each(tmp,function(n,v){
164
+ tmp[n] = $.jgrid.htmlDecode(v);
165
+ });
166
+ }
167
+ var resp = $($t).jqGrid("setRowData",rowid,tmp);
168
+ $(ind).attr("editable","0");
169
+ for( var k=0;k<$t.p.savedRow.length;k++) {
170
+ if( $t.p.savedRow[k].id == rowid) {fr = k; break;}
171
+ }
172
+ if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
173
+ if( $.isFunction(aftersavefunc) ) { aftersavefunc(rowid,resp); }
174
+ } else {
175
+ $("#lui_"+$t.p.id).show();
176
+ $.ajax($.extend({
177
+ url:url,
178
+ data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData(tmp) : tmp,
179
+ type: "POST",
180
+ complete: function(res,stat){
181
+ $("#lui_"+$t.p.id).hide();
182
+ if (stat === "success"){
183
+ var ret;
184
+ if( $.isFunction(succesfunc)) { ret = succesfunc(res);}
185
+ else { ret = true; }
186
+ if (ret===true) {
187
+ if($t.p.autoencode) {
188
+ $.each(tmp,function(n,v){
189
+ tmp[n] = $.jgrid.htmlDecode(v);
190
+ });
191
+ }
192
+ tmp = $.extend({},tmp, tmp2);
193
+ $($t).jqGrid("setRowData",rowid,tmp);
194
+ $(ind).attr("editable","0");
195
+ for( var k=0;k<$t.p.savedRow.length;k++) {
196
+ if( $t.p.savedRow[k].id == rowid) {fr = k; break;}
197
+ }
198
+ if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
199
+ if( $.isFunction(aftersavefunc) ) { aftersavefunc(rowid,res); }
200
+ } else { $($t).jqGrid("restoreRow",rowid, afterrestorefunc); }
201
+ }
202
+ },
203
+ error:function(res,stat){
204
+ $("#lui_"+$t.p.id).hide();
205
+ if($.isFunction(errorfunc) ) {
206
+ errorfunc(rowid, res, stat);
207
+ } else {
208
+ alert("Error Row: "+rowid+" Result: " +res.status+":"+res.statusText+" Status: "+stat);
209
+ }
210
+ $($t).jqGrid("restoreRow",rowid, afterrestorefunc);
211
+ }
212
+ }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {}));
213
+ }
214
+ $(ind).unbind("keydown");
215
+ }
216
+ });
217
+ },
218
+ restoreRow : function(rowid, afterrestorefunc) {
219
+ return this.each(function(){
220
+ var $t= this, fr, ind, ares={};
221
+ if (!$t.grid ) { return; }
222
+ ind = $($t).jqGrid("getInd",rowid,true);
223
+ if(ind === false) {return;}
224
+ for( var k=0;k<$t.p.savedRow.length;k++) {
225
+ if( $t.p.savedRow[k].id == rowid) {fr = k; break;}
226
+ }
227
+ if(fr >= 0) {
228
+ if($.isFunction($.fn.datepicker)) {
229
+ try {
230
+ $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
231
+ } catch (e) {}
232
+ }
233
+ $.each($t.p.colModel, function(i,n){
234
+ if(this.editable === true && this.name in $t.p.savedRow[fr]) {
235
+ ares[this.name] = $t.p.savedRow[fr][this.name];
236
+ }
237
+ });
238
+ $($t).jqGrid("setRowData",rowid,ares);
239
+ $(ind).attr("editable","0").unbind("keydown");
240
+ $t.p.savedRow.splice(fr,1);
241
+ }
242
+ if ($.isFunction(afterrestorefunc))
243
+ {
244
+ afterrestorefunc(rowid);
245
+ }
246
+ });
247
+ }
248
+ //end inline edit
249
+ });
250
+ })(jQuery);