Class: Marty::DataGridView

Inherits:
McflyGridPanel show all
Includes:
Extras::Layout
Defined in:
app/components/marty/data_grid_view.rb,
app/services/marty/data_grid_view/save_grid.rb

Direct Known Subclasses

DataGridUserView

Defined Under Namespace

Classes: SaveGrid

Constant Summary

Constants included from Extras::Layout

Extras::Layout::BOOL_MAP, Extras::Layout::MAP_BOOL

Constants included from Permissions

Permissions::NETZKE_ENDPOINTS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extras::Layout

#bool_getter, #bool_setter, #dispfield, #enum_array, #enum_column, #enum_setter, #fieldset, #get_sorter, #hbox, #hspacer, #jsonb_field, #nullable_bool_column, #range_column, #range_field, #range_getter, #range_setter, #textarea_field, #tooltip, #vbox, #vspacer

Methods inherited from McflyGridPanel

#augment_attribute_config, #get_records

Methods inherited from Grid

#child_components, #class_can?, #configure_form_window, #get_json_sorter, #has_search_action?, #initialize, #linked_components

Methods included from Permissions

#can_call_endpoint?, #can_perform_action?, #can_perform_actions, #current_user_roles, extended, #has_any_perm?, #has_marty_permissions, #has_perm?

Constructor Details

This class inherits a constructor from Marty::Grid

Class Method Details

.client_show_grid_jsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/components/marty/data_grid_view.rb', line 29

def self.client_show_grid_js
  javascript = l(<<-JS)
  function(count, data, title_str) {
     var columns = [];
     var fields  = [];

     for (var i=0; i<count; i++) {
        fields.push("a" + i);
        columns.push({dataIndex: "a" + i, text: i, flex: 1});
     }

     Ext.create('Ext.Window', {
       height:        "80%",
       width:         "80%",
       x:             0,
       y:             0,
       autoWidth:     true,
       modal:         true,
       autoScroll:    true,
       title:         title_str,
       items: {
         xtype:       'grid',
         border:      false,
         hideHeaders: false,
         columns:     columns,
         store:       Ext.create('Ext.data.ArrayStore', {
           fields: fields,
           data: data,
           })
       },
    }).show();
  }
  JS
  javascript
end

.edit_grid_js(options = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/components/marty/data_grid_view.rb', line 65

def self.edit_grid_js(options = {})
  dg        = options[:data_grid] || 'data_grid'
  title_str = options[:title_str] || 'Data Grid'

  javascript = l(<<-JS)
  function() {
     var sel = this.getSelectionModel().getSelection()[0];
     var record_id = sel && sel.getId();
     this.server.editGrid({record_id: record_id,
                          data_grid: "#{dg}",
                          title_str: "#{title_str}"});
  }
  JS
  javascript
end

.get_edit_permission(_permissions) ⇒ Object



190
191
192
# File 'app/components/marty/data_grid_view.rb', line 190

def self.get_edit_permission(_permissions)
  'edit_all'
end

.show_grid_js(options = {}) ⇒ Object

show_grid_js and client_show_grid_js have specific handles so they can be used by various other components FIXME: add the ability to pull specific functions from other component javascripts or add a base to pull from



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/marty/data_grid_view.rb', line 13

def self.show_grid_js(options = {})
  dg        = options[:data_grid] || 'data_grid'
  title_str = options[:title_str] || 'Data Grid'

  javascript = l(<<-JS)
  function() {
     var sel = this.getSelectionModel().getSelection()[0];
     var record_id = sel && sel.getId();
     this.server.showGrid({record_id: record_id,
                          data_grid: "#{dg}",
                          title_str: "#{title_str}"});
  }
  JS
  javascript
end

Instance Method Details

#configure(c) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/components/marty/data_grid_view.rb', line 88

def configure(c)
  super

  c.title   = I18n.t('data_grid')
  c.model   = 'Marty::DataGrid'
  c.attributes =
    [
      :name,
      :vcols,
      :hcols,
      :lenient,
      :strict_null_mode,
      :data_type,
      :constraint,
      :perm_view,
      :perm_edit_data,
      :perm_edit_all,
      :created_dt,
    ]

  c.store_config.merge!(sorters:  [{ property: :name, direction: 'ASC' }])
  c.editing      = :in_form
  c.paging       = :pagination
  c.multi_select = false
end

#default_bbarObject



230
231
232
# File 'app/components/marty/data_grid_view.rb', line 230

def default_bbar
  [:show_grid, :edit_grid] + super
end

#default_context_menuObject



234
235
236
# File 'app/components/marty/data_grid_view.rb', line 234

def default_context_menu
  []
end

#default_form_itemsObject



238
239
240
241
242
243
244
# File 'app/components/marty/data_grid_view.rb', line 238

def default_form_items
  [
    :name,
    :perm_view, :perm_edit_data, :perm_edit_all,
    textarea_field(:export, height: 300, hide_label: true),
  ]
end

#set_perms(dg, data) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/components/marty/data_grid_view.rb', line 114

def set_perms(dg, data)
  permstrs = %w[perm_view perm_edit_data perm_edit_all]
  view, edit_data, edit_all = data.values_at(*permstrs).map do |plist|
    Marty::RoleType.from_nice_names(plist)
  end
  dg.permissions = {
    view: view.presence || [],
    edit_data: edit_data.presence || [],
    edit_all: edit_all.presence || [],
  }
  dg.save!
end