Class: RailsJqGrid::JqGridNavGrid
- Inherits:
-
Object
- Object
- RailsJqGrid::JqGridNavGrid
- Includes:
- JqGridMethodMissing
- Defined in:
- app/models/rails_jq_grid/jq_grid_nav_grid.rb
Overview
Handles the creation of JQGrid navigator
Constant Summary collapse
- DEFAULT_OPTIONS =
{:add => true, :del => true, :edit => true, :refresh => true, :search => true, }
- DEFAULT_PRM_OPTIONS =
{ :close_after_add => true, :close_after_edit => true, :close_on_escape => true }
Instance Attribute Summary collapse
-
#custom_buttons ⇒ Object
Returns the value of attribute custom_buttons.
-
#dom_id ⇒ Object
Returns the value of attribute dom_id.
-
#filter_toolbar_data ⇒ Object
Returns the value of attribute filter_toolbar_data.
-
#pager_id ⇒ Object
Returns the value of attribute pager_id.
-
#prm_add_data ⇒ Object
Returns the value of attribute prm_add_data.
-
#prm_del_data ⇒ Object
Returns the value of attribute prm_del_data.
-
#prm_edit_data ⇒ Object
Returns the value of attribute prm_edit_data.
-
#prm_search_data ⇒ Object
Returns the value of attribute prm_search_data.
-
#prm_view_data ⇒ Object
Returns the value of attribute prm_view_data.
-
#restfull ⇒ Object
Returns the value of attribute restfull.
Attributes included from JqGridMethodMissing
Instance Method Summary collapse
-
#custom_button {|custom_button| ... } ⇒ Object
Creates a custom button for the navigator.
-
#filter_toolbar(create_clear_button = true) {|filter_toolbar, toggle_button, clear_button| ... } ⇒ Object
Creates a custom button for the navigator.
-
#initialize(dom_id, pager_id, &option_block) ⇒ JqGridNavGrid
constructor
A new instance of JqGridNavGrid.
- #is_restfull? ⇒ Boolean
- #nav_grid_parameters ⇒ Object
- #prm_add(&block) ⇒ Object
- #prm_del(&block) ⇒ Object
- #prm_edit(&block) ⇒ Object
- #prm_search(&block) ⇒ Object
- #prm_view(&block) ⇒ Object
- #restful_param_add ⇒ Object
- #restful_param_delete ⇒ Object
- #restful_param_edit ⇒ Object
- #set_nav_grid_restful_extensions ⇒ Object
-
#to_js ⇒ String
Creates the js for a navigator.
Methods included from JqGridMethodMissing
#get_jq_grid_js_options, #init_jq_grid_js_options, #method_missing, #options_to_jqgrid_options, #raw, #set_jqgrid_options
Constructor Details
#initialize(dom_id, pager_id, &option_block) ⇒ JqGridNavGrid
Returns a new instance of JqGridNavGrid.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 34 def initialize(dom_id, pager_id , &option_block) self.dom_id = dom_id self.pager_id = pager_id self.prm_edit_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS) self.prm_add_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS) self.prm_del_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS) self.prm_search_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS) self.prm_view_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS) self. = [] self. = nil self. DEFAULT_OPTIONS option_block.call(self) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RailsJqGrid::JqGridMethodMissing
Instance Attribute Details
#custom_buttons ⇒ Object
Returns the value of attribute custom_buttons.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def end |
#dom_id ⇒ Object
Returns the value of attribute dom_id.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def dom_id @dom_id end |
#filter_toolbar_data ⇒ Object
Returns the value of attribute filter_toolbar_data.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def end |
#pager_id ⇒ Object
Returns the value of attribute pager_id.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def pager_id @pager_id end |
#prm_add_data ⇒ Object
Returns the value of attribute prm_add_data.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def prm_add_data @prm_add_data end |
#prm_del_data ⇒ Object
Returns the value of attribute prm_del_data.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def prm_del_data @prm_del_data end |
#prm_edit_data ⇒ Object
Returns the value of attribute prm_edit_data.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def prm_edit_data @prm_edit_data end |
#prm_search_data ⇒ Object
Returns the value of attribute prm_search_data.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def prm_search_data @prm_search_data end |
#prm_view_data ⇒ Object
Returns the value of attribute prm_view_data.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def prm_view_data @prm_view_data end |
#restfull ⇒ Object
Returns the value of attribute restfull.
28 29 30 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28 def restfull @restfull end |
Instance Method Details
#custom_button {|custom_button| ... } ⇒ Object
Creates a custom button for the navigator
85 86 87 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 85 def (&block) self. << JqGridNavGridParameter.new(&block) end |
#filter_toolbar(create_clear_button = true) {|filter_toolbar, toggle_button, clear_button| ... } ⇒ Object
Creates a custom button for the navigator
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 95 def (=true, &block) self. = JqGridNavGridParameter.new() = JqGridNavGridParameter.new() = JqGridNavGridParameter.new() block.call(self., , ) . << "function (){ var sgrid = jQuery('##{dom_id}')[0]; sgrid.toggleToolbar(); } " . << "function (){ var sgrid = jQuery('##{dom_id}')[0]; sgrid.clearToolbar(); } " self. << self. << if end |
#is_restfull? ⇒ Boolean
191 192 193 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 191 def is_restfull? self.restfull end |
#nav_grid_parameters ⇒ Object
150 151 152 153 154 155 156 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 150 def nav_grid_parameters " {\n \#{options_to_jqgrid_options}\n }\n EO_JS\nend\n" |
#prm_add(&block) ⇒ Object
60 61 62 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 60 def prm_add(&block) prm_add_data.(&block) end |
#prm_del(&block) ⇒ Object
66 67 68 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 66 def prm_del(&block) prm_del_data.(&block) end |
#prm_edit(&block) ⇒ Object
54 55 56 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 54 def prm_edit(&block) prm_edit_data.(&block) end |
#prm_search(&block) ⇒ Object
72 73 74 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 72 def prm_search(&block) prm_search_data.(&block) end |
#prm_view(&block) ⇒ Object
77 78 79 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 77 def prm_view(&block) prm_view_data.(&block) end |
#restful_param_add ⇒ Object
177 178 179 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 177 def restful_param_add prm_add_data.mtype "POST" end |
#restful_param_delete ⇒ Object
181 182 183 184 185 186 187 188 189 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 181 def restful_param_delete prm_del_data.mtype "DELETE" prm_del_data.onclick_submit raw <<-EO_JS function(rp_ge, postdata) { rp_ge.url = jQuery("##{dom_id}").jqGrid('getGridParam','editurl') + '/' + postdata return {}; } EO_JS end |
#restful_param_edit ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 164 def restful_param_edit prm_edit_data.mtype "PUT" prm_edit_data.onclick_submit raw <<-EO_JS function(rp_ge, postdata) { selrow = jQuery("##{dom_id}").jqGrid('getGridParam','selrow'); if (selrow!=null){ rp_ge.url = jQuery("##{dom_id}").jqGrid('getGridParam','editurl') + '/' + selrow; } return {}; } EO_JS end |
#set_nav_grid_restful_extensions ⇒ Object
158 159 160 161 162 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 158 def set_nav_grid_restful_extensions restful_param_edit restful_param_add restful_param_delete end |
#to_js ⇒ String
Creates the js for a navigator
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 117 def to_js params=[nav_grid_parameters] if is_restful? set_nav_grid_restful_extensions end params.push([prm_edit_data.to_js, prm_add_data.to_js, prm_del_data.to_js, prm_search_data.to_js, prm_view_data.to_js]).flatten! js_parts = [] js_parts << " jQuery(\"#\#{dom_id}\").jqGrid('navGrid','#\#{pager_id}',\#{params.join(\",\\n\")} );\n EO_JS\n\n self.custom_buttons.each do |custom_button|\n js_parts << <<-EO_JS\n jQuery(\"#\#{dom_id}\").jqGrid('navButtonAdd','#\#{pager_id}',\#{custom_button.to_js} );\n EO_JS\n end\n\n if self.filter_toolbar_data\n js_parts << <<-EO_JS\n jQuery(\"#\#{dom_id}\").jqGrid('filterToolbar',\#{self.filter_toolbar_data.to_js});\n EO_JS\n end\n\n js_parts.join(\"\\n\")\nend\n" |