Class: RailsJqGrid::JqGridNavGrid

Inherits:
Object
  • Object
show all
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

Attributes included from JqGridMethodMissing

#jq_grid_js_options

Instance Method Summary collapse

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.custom_buttons = []
  self.filter_toolbar_data = nil

  self.init_jq_grid_js_options 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_buttonsObject

Returns the value of attribute custom_buttons.



28
29
30
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 28

def custom_buttons
  @custom_buttons
end

#dom_idObject

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_dataObject

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 filter_toolbar_data
  @filter_toolbar_data
end

#pager_idObject

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_dataObject

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_dataObject

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_dataObject

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_dataObject

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_dataObject

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

#restfullObject

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

Yields:

See Also:



85
86
87
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 85

def custom_button(&block)
  self.custom_buttons << JqGridNavGridParameter.new(&block)
end

#filter_toolbar(create_clear_button = true) {|filter_toolbar, toggle_button, clear_button| ... } ⇒ Object

Creates a custom button for the navigator

Yields:

  • (filter_toolbar, toggle_button, clear_button)

    creates the toggle- and clear-button

See Also:



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 filter_toolbar(create_clear_button=true, &block)
  self.filter_toolbar_data = JqGridNavGridParameter.new()
  toggle_button = JqGridNavGridParameter.new()
  clear_button = JqGridNavGridParameter.new()

  block.call(self.filter_toolbar_data, toggle_button, clear_button)

  toggle_button.on_click_button << "function (){ var sgrid = jQuery('##{dom_id}')[0];
                                                 sgrid.toggleToolbar(); } "

  clear_button.on_click_button << "function (){ var sgrid = jQuery('##{dom_id}')[0];
                                                 sgrid.clearToolbar(); } "


  self.custom_buttons << toggle_button
  self.custom_buttons << clear_button if create_clear_button

end

#is_restfull?Boolean

Returns:

  • (Boolean)


191
192
193
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 191

def is_restfull?
  self.restfull
end


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

Parameters:

  • options (Block)

    for add action

See Also:



60
61
62
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 60

def prm_add(&block)
  prm_add_data.set_jqgrid_options(&block)
end

#prm_del(&block) ⇒ Object

Parameters:

  • options (Block)

    for delete action

See Also:



66
67
68
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 66

def prm_del(&block)
  prm_del_data.set_jqgrid_options(&block)
end

#prm_edit(&block) ⇒ Object

Parameters:

  • options (Block)

    for edit action

See Also:



54
55
56
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 54

def prm_edit(&block)
  prm_edit_data.set_jqgrid_options(&block)
end

#prm_search(&block) ⇒ Object

Parameters:

  • options (Block)

    for search action

See Also:



72
73
74
# File 'app/models/rails_jq_grid/jq_grid_nav_grid.rb', line 72

def prm_search(&block)
  prm_search_data.set_jqgrid_options(&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.set_jqgrid_options(&block)
end

#restful_param_addObject



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_deleteObject



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_editObject



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_extensionsObject



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_jsString

Creates the js for a navigator

Returns:

  • (String)

    Contains the javascript for the navigator

See Also:



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"