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,126 @@
1
+ ;(function($){
2
+ /**
3
+ * jqGrid extension for manipulating columns properties
4
+ * Piotr Roznicki roznicki@o2.pl
5
+ * http://www.roznicki.prv.pl
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
+ setColumns : function(p) {
12
+ p = $.extend({
13
+ top : 0,
14
+ left: 0,
15
+ width: 200,
16
+ height: 'auto',
17
+ dataheight: 'auto',
18
+ modal: false,
19
+ drag: true,
20
+ beforeShowForm: null,
21
+ afterShowForm: null,
22
+ afterSubmitForm: null,
23
+ closeOnEscape : true,
24
+ ShrinkToFit : false,
25
+ jqModal : false,
26
+ saveicon: [true,"left","ui-icon-disk"],
27
+ closeicon: [true,"left","ui-icon-close"],
28
+ onClose : null,
29
+ colnameview : true,
30
+ closeAfterSubmit : true,
31
+ updateAfterCheck : false,
32
+ recreateForm : false
33
+ }, $.jgrid.col, p ||{});
34
+ return this.each(function(){
35
+ var $t = this;
36
+ if (!$t.grid ) { return; }
37
+ var onBeforeShow = typeof p.beforeShowForm === 'function' ? true: false;
38
+ var onAfterShow = typeof p.afterShowForm === 'function' ? true: false;
39
+ var onAfterSubmit = typeof p.afterSubmitForm === 'function' ? true: false;
40
+ var gID = $t.p.id,
41
+ dtbl = "ColTbl_"+gID,
42
+ IDs = {themodal:'colmod'+gID,modalhead:'colhd'+gID,modalcontent:'colcnt'+gID, scrollelm: dtbl};
43
+ if(p.recreateForm===true && $("#"+IDs.themodal).html() != null) {
44
+ $("#"+IDs.themodal).remove();
45
+ }
46
+ if ( $("#"+IDs.themodal).html() != null ) {
47
+ if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
48
+ viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM:false, modal:p.modal});
49
+ if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
50
+ } else {
51
+ var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
52
+ var formdata = "<div id='"+dtbl+"' class='formdata' style='width:100%;overflow:auto;position:relative;height:"+dh+";'>";
53
+ formdata += "<table class='ColTable' cellspacing='1' cellpading='2' border='0'><tbody>";
54
+ for(i=0;i<this.p.colNames.length;i++){
55
+ if(!$t.p.colModel[i].hidedlg) { // added from T. Tomov
56
+ formdata += "<tr><td style='white-space: pre;'><input type='checkbox' style='margin-right:5px;' id='col_" + this.p.colModel[i].name + "' class='cbox' value='T' " +
57
+ ((this.p.colModel[i].hidden===false)?"checked":"") + "/>" + "<label for='col_" + this.p.colModel[i].name + "'>" + this.p.colNames[i] + ((p.colnameview) ? " (" + this.p.colModel[i].name + ")" : "" )+ "</label></td></tr>";
58
+ }
59
+ }
60
+ formdata += "</tbody></table></div>"
61
+ var bS = !p.updateAfterCheck ? "<a href='javascript:void(0)' id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>" : "",
62
+ bC ="<a href='javascript:void(0)' id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
63
+ formdata += "<table border='0' class='EditTable' id='"+dtbl+"_2'><tbody><tr style='display:block;height:3px;'><td></td></tr><tr><td class='DataTD ui-widget-content'></td></tr><tr><td class='ColButton EditButton'>"+bS+"&#160;"+bC+"</td></tr></tbody></table>";
64
+ p.gbox = "#gbox_"+gID;
65
+ createModal(IDs,formdata,p,"#gview_"+$t.p.id,$("#gview_"+$t.p.id)[0]);
66
+ if(p.saveicon[0]==true) {
67
+ $("#dData","#"+dtbl+"_2").addClass(p.saveicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
68
+ .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
69
+ }
70
+ if(p.closeicon[0]==true) {
71
+ $("#eData","#"+dtbl+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
72
+ .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
73
+ }
74
+ if(!p.updateAfterCheck) {
75
+ $("#dData","#"+dtbl+"_2").click(function(e){
76
+ for(i=0;i<$t.p.colModel.length;i++){
77
+ if(!$t.p.colModel[i].hidedlg) { // added from T. Tomov
78
+ var nm = $t.p.colModel[i].name.replace(".", "\\.");
79
+ if($("#col_" + nm,"#"+dtbl).attr("checked")) {
80
+ $($t).jqGrid("showCol",$t.p.colModel[i].name);
81
+ $("#col_" + nm,"#"+dtbl).attr("defaultChecked",true); // Added from T. Tomov IE BUG
82
+ } else {
83
+ $($t).jqGrid("hideCol",$t.p.colModel[i].name);
84
+ $("#col_" + nm,"#"+dtbl).attr("defaultChecked",""); // Added from T. Tomov IE BUG
85
+ }
86
+ }
87
+ }
88
+ if(p.ShrinkToFit===true) {
89
+ $($t).jqGrid("setGridWidth",$t.grid.width-0.001,true);
90
+ }
91
+ if(p.closeAfterSubmit) hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: p.onClose});
92
+ if (onAfterSubmit) { p.afterSubmitForm($("#"+dtbl)); }
93
+ return false;
94
+ });
95
+ } else {
96
+ $(":input","#"+dtbl).click(function(e){
97
+ var cn = this.id.substr(4);
98
+ if(cn){
99
+ if(this.checked) {
100
+ $($t).jqGrid("showCol",cn);
101
+ } else {
102
+ $($t).jqGrid("hideCol",cn);
103
+ }
104
+ if(p.ShrinkToFit===true) {
105
+ $($t).jqGrid("setGridWidth",$t.grid.width-0.001,true);
106
+ }
107
+ }
108
+ return this;
109
+ });
110
+ }
111
+ $("#eData", "#"+dtbl+"_2").click(function(e){
112
+ hideModal("#"+IDs.themodal,{gb:"#gbox_"+gID,jqm:p.jqModal, onClose: p.onClose});
113
+ return false;
114
+ });
115
+ $("#dData, #eData","#"+dtbl+"_2").hover(
116
+ function(){$(this).addClass('ui-state-hover');},
117
+ function(){$(this).removeClass('ui-state-hover');}
118
+ );
119
+ if(onBeforeShow) { p.beforeShowForm($("#"+dtbl)); }
120
+ viewModal("#"+IDs.themodal,{gbox:"#gbox_"+gID,jqm:p.jqModal, jqM: true, modal:p.modal});
121
+ if(onAfterShow) { p.afterShowForm($("#"+dtbl)); }
122
+ }
123
+ });
124
+ }
125
+ });
126
+ })(jQuery);
@@ -0,0 +1,260 @@
1
+ ;(function($){
2
+ /**
3
+ * jqGrid extension for SubGrid 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
+ setSubGrid : function () {
12
+ return this.each(function (){
13
+ var $t = this, cm;
14
+ $t.p.colNames.unshift("");
15
+ $t.p.colModel.unshift({name:'subgrid',width: $.browser.safari ? $t.p.subGridWidth+$t.p.cellLayout : $t.p.subGridWidth,sortable: false,resizable:false,hidedlg:true,search:false,fixed:true});
16
+ cm = $t.p.subGridModel;
17
+ if(cm[0]) {
18
+ cm[0].align = $.extend([],cm[0].align || []);
19
+ for(var i=0;i<cm[0].name.length;i++) { cm[0].align[i] = cm[0].align[i] || 'left';}
20
+ }
21
+ });
22
+ },
23
+ addSubGridCell :function (pos,iRow) {
24
+ var prp='',gv,sid;
25
+ this.each(function(){
26
+ prp = this.formatCol(pos,iRow);
27
+ gv = this.p.gridview;
28
+ sid= this.p.id;
29
+ });
30
+ if( gv === false ){
31
+ return "<td role=\"grid\" aria-describedby=\""+sid+"_subgrid\" class=\"ui-sgcollapsed sgcollapsed\" "+prp+"><a href='javascript:void(0);'><span class='ui-icon ui-icon-plus'></span></a></td>";
32
+ } else {
33
+ return "<td role=\"grid\" aria-describedby=\""+sid+"_subgrid\" " +prp +"></td>";
34
+ }
35
+ },
36
+ addSubGrid : function(t,pos) {
37
+ return this.each(function(){
38
+ var ts = this;
39
+ if (!ts.grid ) { return; }
40
+ var res,_id, pID,atd, nhc, subdata, bfsc;
41
+ $("td:eq("+pos+")",t).click( function(e) {
42
+ if($(this).hasClass("sgcollapsed")) {
43
+ pID = ts.p.id;
44
+ res = $(this).parent();
45
+ atd = pos >=1 ? "<td colspan='"+pos+"'>&#160;</td>":"";
46
+ _id = $(res).attr("id");
47
+ bfsc =true;
48
+ if($.isFunction(ts.p.subGridBeforeExpand)) {
49
+ bfsc = ts.p.subGridBeforeExpand(pID+"_"+_id,_id);
50
+ }
51
+ if(bfsc === false) {return false;}
52
+ nhc = 0;
53
+ $.each(ts.p.colModel,function(i,v){
54
+ if(this.hidden === true || this.name == 'rn' || this.name == 'cb') {nhc++;}
55
+ });
56
+ subdata = "<tr role='row' class='ui-subgrid'>"+atd+"<td class='ui-widget-content subgrid-cell'><span class='ui-icon ui-icon-carat-1-sw'/></td><td colspan='"+parseInt(ts.p.colNames.length-1-nhc,10)+"' class='ui-widget-content subgrid-data'><div id="+pID+"_"+_id+" class='tablediv'>";
57
+ $(this).parent().after( subdata+ "</div></td></tr>" );
58
+ if( $.isFunction(ts.p.subGridRowExpanded)) {
59
+ ts.p.subGridRowExpanded(pID+"_"+ _id,_id);
60
+ } else {
61
+ populatesubgrid(res);
62
+ }
63
+ $(this).html("<a href='javascript:void(0);'><span class='ui-icon ui-icon-minus'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded");
64
+ } else if($(this).hasClass("sgexpanded")) {
65
+ bfsc = true;
66
+ if( $.isFunction(ts.p.subGridRowColapsed)) {
67
+ res = $(this).parent();
68
+ _id = $(res).attr("id");
69
+ bfsc = ts.p.subGridRowColapsed(pID+"_"+_id,_id );
70
+ }
71
+ if(bfsc===false) {return false;}
72
+ $(this).parent().next().remove(".ui-subgrid");
73
+ $(this).html("<a href='javascript:void(0);'><span class='ui-icon ui-icon-plus'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
74
+ }
75
+ return false;
76
+ });
77
+ //-------------------------
78
+ var populatesubgrid = function( rd ) {
79
+ var res,sid,dp, i, j;
80
+ sid = $(rd).attr("id");
81
+ dp = {nd_: (new Date().getTime())};
82
+ dp[ts.p.prmNames.subgridid]=sid;
83
+ if(!ts.p.subGridModel[0]) { return false; }
84
+ if(ts.p.subGridModel[0].params) {
85
+ for(j=0; j < ts.p.subGridModel[0].params.length; j++) {
86
+ for(i=0; i<ts.p.colModel.length; i++) {
87
+ if(ts.p.colModel[i].name == ts.p.subGridModel[0].params[j]) {
88
+ dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\&#160\;/ig,'');
89
+ }
90
+ }
91
+ }
92
+ }
93
+ if(!ts.grid.hDiv.loading) {
94
+ ts.grid.hDiv.loading = true;
95
+ $("#load_"+ts.p.id).show();
96
+ if(!ts.p.subgridtype) { ts.p.subgridtype = ts.p.datatype; }
97
+ if($.isFunction(ts.p.subgridtype)) {
98
+ ts.p.subgridtype(dp);
99
+ } else {
100
+ ts.p.subgridtype = ts.p.subgridtype.toLowerCase();
101
+ }
102
+ switch(ts.p.subgridtype) {
103
+ case "xml":
104
+ case "json":
105
+ $.ajax($.extend({
106
+ type:ts.p.mtype,
107
+ url: ts.p.subGridUrl,
108
+ dataType:ts.p.subgridtype,
109
+ data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData(dp) : dp,
110
+ complete: function(sxml) {
111
+ if(ts.p.subgridtype == "xml") {
112
+ subGridXml(sxml.responseXML, sid);
113
+ } else {
114
+ subGridJson($.jgrid.parse(sxml.responseText),sid);
115
+ }
116
+ sxml=null;
117
+ }
118
+ }, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {}));
119
+ break;
120
+ }
121
+ }
122
+ return false;
123
+ };
124
+ var subGridCell = function(trdiv,cell,pos){
125
+ var tddiv = $("<td align='"+ts.p.subGridModel[0].align[pos]+"'></td>").html(cell);
126
+ $(trdiv).append(tddiv);
127
+ };
128
+ var subGridXml = function(sjxml, sbid){
129
+ var tddiv, i, cur, sgmap,
130
+ dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
131
+ trdiv = $("<tr></tr>");
132
+ for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
133
+ tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
134
+ $(tddiv).html(ts.p.subGridModel[0].name[i]);
135
+ $(tddiv).width( ts.p.subGridModel[0].width[i]);
136
+ $(trdiv).append(tddiv);
137
+ }
138
+ $(dummy).append(trdiv);
139
+ if (sjxml){
140
+ sgmap = ts.p.xmlReader.subgrid;
141
+ $(sgmap.root+" "+sgmap.row, sjxml).each( function(){
142
+ trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
143
+ if(sgmap.repeatitems === true) {
144
+ $(sgmap.cell,this).each( function(i) {
145
+ subGridCell(trdiv, $(this).text() || '&#160;',i);
146
+ });
147
+ } else {
148
+ var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
149
+ if (f) {
150
+ for (i=0;i<f.length;i++) {
151
+ subGridCell(trdiv, $(f[i],this).text() || '&#160;',i);
152
+ }
153
+ }
154
+ }
155
+ $(dummy).append(trdiv);
156
+ });
157
+ }
158
+ var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
159
+ $("#"+pID+sbid).append(dummy);
160
+ ts.grid.hDiv.loading = false;
161
+ $("#load_"+ts.p.id).hide();
162
+ return false;
163
+ };
164
+ var subGridJson = function(sjxml, sbid){
165
+ var tddiv,result , i,cur, sgmap,j,
166
+ dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
167
+ trdiv = $("<tr></tr>");
168
+ for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
169
+ tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
170
+ $(tddiv).html(ts.p.subGridModel[0].name[i]);
171
+ $(tddiv).width( ts.p.subGridModel[0].width[i]);
172
+ $(trdiv).append(tddiv);
173
+ }
174
+ $(dummy).append(trdiv);
175
+ if (sjxml){
176
+ sgmap = ts.p.jsonReader.subgrid;
177
+ result = sjxml[sgmap.root];
178
+ if ( typeof result !== 'undefined' ) {
179
+ for (i=0;i<result.length;i++) {
180
+ cur = result[i];
181
+ trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
182
+ if(sgmap.repeatitems === true) {
183
+ if(sgmap.cell) { cur=cur[sgmap.cell]; }
184
+ for (j=0;j<cur.length;j++) {
185
+ subGridCell(trdiv, cur[j] || '&#160;',j);
186
+ }
187
+ } else {
188
+ var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
189
+ if(f.length) {
190
+ for (j=0;j<f.length;j++) {
191
+ subGridCell(trdiv, cur[f[j]] || '&#160;',j);
192
+ }
193
+ }
194
+ }
195
+ $(dummy).append(trdiv);
196
+ }
197
+ }
198
+ }
199
+ var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
200
+ $("#"+pID+sbid).append(dummy);
201
+ ts.grid.hDiv.loading = false;
202
+ $("#load_"+ts.p.id).hide();
203
+ return false;
204
+ };
205
+ ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);};
206
+ ts.subGridJson = function(json,sid) {subGridJson(json,sid);};
207
+ });
208
+ },
209
+ expandSubGridRow : function(rowid) {
210
+ return this.each(function () {
211
+ var $t = this;
212
+ if(!$t.grid && !rowid) {return;}
213
+ if($t.p.subGrid===true) {
214
+ var rc = $(this).jqGrid("getInd",rowid,true);
215
+ if(rc) {
216
+ var sgc = $("td.sgcollapsed",rc)[0];
217
+ if(sgc) {
218
+ $(sgc).trigger("click");
219
+ }
220
+ }
221
+ }
222
+ });
223
+ },
224
+ collapseSubGridRow : function(rowid) {
225
+ return this.each(function () {
226
+ var $t = this;
227
+ if(!$t.grid && !rowid) {return;}
228
+ if($t.p.subGrid===true) {
229
+ var rc = $(this).jqGrid("getInd",rowid,true);
230
+ if(rc) {
231
+ var sgc = $("td.sgexpanded",rc)[0];
232
+ if(sgc) {
233
+ $(sgc).trigger("click");
234
+ }
235
+ }
236
+ }
237
+ });
238
+ },
239
+ toggleSubGridRow : function(rowid) {
240
+ return this.each(function () {
241
+ var $t = this;
242
+ if(!$t.grid && !rowid) {return;}
243
+ if($t.p.subGrid===true) {
244
+ var rc = $(this).jqGrid("getInd",rowid,true);
245
+ if(rc) {
246
+ var sgc = $("td.sgcollapsed",rc)[0];
247
+ if(sgc) {
248
+ $(sgc).trigger("click");
249
+ } else {
250
+ sgc = $("td.sgexpanded",rc)[0];
251
+ if(sgc) {
252
+ $(sgc).trigger("click");
253
+ }
254
+ }
255
+ }
256
+ }
257
+ });
258
+ }
259
+ });
260
+ })(jQuery);
@@ -0,0 +1,106 @@
1
+ /*
2
+ Transform a table to a jqGrid.
3
+ Peter Romianowski <peter.romianowski@optivo.de>
4
+ If the first column of the table contains checkboxes or
5
+ radiobuttons then the jqGrid is made selectable.
6
+ */
7
+ // Addition - selector can be a class or id
8
+ function tableToGrid(selector, options) {
9
+ jQuery(selector).each(function() {
10
+ if(this.grid) {return;} //Adedd from Tony Tomov
11
+ // This is a small "hack" to make the width of the jqGrid 100%
12
+ jQuery(this).width("99%");
13
+ var w = jQuery(this).width();
14
+
15
+ // Text whether we have single or multi select
16
+ var inputCheckbox = jQuery('input[type=checkbox]:first', jQuery(this));
17
+ var inputRadio = jQuery('input[type=radio]:first', jQuery(this));
18
+ var selectMultiple = inputCheckbox.length > 0;
19
+ var selectSingle = !selectMultiple && inputRadio.length > 0;
20
+ var selectable = selectMultiple || selectSingle;
21
+ var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
22
+
23
+ // Build up the columnModel and the data
24
+ var colModel = [];
25
+ var colNames = [];
26
+ jQuery('th', jQuery(this)).each(function() {
27
+ if (colModel.length === 0 && selectable) {
28
+ colModel.push({
29
+ name: '__selection__',
30
+ index: '__selection__',
31
+ width: 0,
32
+ hidden: true
33
+ });
34
+ colNames.push('__selection__');
35
+ } else {
36
+ colModel.push({
37
+ name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
38
+ index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
39
+ width: jQuery(this).width() || 150
40
+ });
41
+ colNames.push(jQuery(this).html());
42
+ }
43
+ });
44
+ var data = [];
45
+ var rowIds = [];
46
+ var rowChecked = [];
47
+ jQuery('tbody > tr', jQuery(this)).each(function() {
48
+ var row = {};
49
+ var rowPos = 0;
50
+ jQuery('td', jQuery(this)).each(function() {
51
+ if (rowPos === 0 && selectable) {
52
+ var input = jQuery('input', jQuery(this));
53
+ var rowId = input.attr("value");
54
+ rowIds.push(rowId || data.length);
55
+ if (input.attr("checked")) {
56
+ rowChecked.push(rowId);
57
+ }
58
+ row[colModel[rowPos].name] = input.attr("value");
59
+ } else {
60
+ row[colModel[rowPos].name] = jQuery(this).html();
61
+ }
62
+ rowPos++;
63
+ });
64
+ if(rowPos >0) { data.push(row); }
65
+ });
66
+
67
+ // Clear the original HTML table
68
+ jQuery(this).empty();
69
+
70
+ // Mark it as jqGrid
71
+ jQuery(this).addClass("scroll");
72
+
73
+ jQuery(this).jqGrid(jQuery.extend({
74
+ datatype: "local",
75
+ width: w,
76
+ colNames: colNames,
77
+ colModel: colModel,
78
+ multiselect: selectMultiple
79
+ //inputName: inputName,
80
+ //inputValueCol: imputName != null ? "__selection__" : null
81
+ }, options || {}));
82
+
83
+ // Add data
84
+ var a;
85
+ for (a = 0; a < data.length; a++) {
86
+ var id = null;
87
+ if (rowIds.length > 0) {
88
+ id = rowIds[a];
89
+ if (id && id.replace) {
90
+ // We have to do this since the value of a checkbox
91
+ // or radio button can be anything
92
+ id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
93
+ }
94
+ }
95
+ if (id === null) {
96
+ id = a + 1;
97
+ }
98
+ jQuery(this).jqGrid("addRowData",id, data[a]);
99
+ }
100
+
101
+ // Set the selection
102
+ for (a = 0; a < rowChecked.length; a++) {
103
+ jQuery(this).jqGrid("setSelection",rowChecked[a]);
104
+ }
105
+ });
106
+ };