Class: Netzke::Tree::Base

Constant Summary

NODE_ATTRS =
{
  boolean: %w[leaf checked expanded expandable qtip qtitle],
  string: %w[icon icon_cls href href_target qtip qtitle]
}

Constants included from Basepack::Attributes

Basepack::Attributes::ATTRIBUTE_METHOD_NAME

Constants included from Basepack::Columns

Basepack::Columns::COLUMN_METHOD_NAME

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Basepack::DataAccessor

#model, #model_adapter

Methods included from Basepack::Attributes

#apply_attribute_dsl, #association_attr?, #association_value_defaults, #attribute_overrides, #attributes, #augment_attribute_config

Methods included from Basepack::Columns

#append_association_values_column, #attributes_for_search, #build_column_config, #default_form_items, #final_columns, #final_columns_hash, #form_items, #insert_primary_column, #js_columns, #non_meta_columns

Methods included from Grid::Permissions

#allowed_to?, #allowed_to_read?, #permissions

Methods included from Grid::Components

#configure_form, #configure_form_window

Methods included from Grid::Actions

#has_add_action?, #has_add_in_form_action?, #has_apply_action?, #has_delete_action?, #has_edit_action?, #has_edit_in_form_action?, #has_search_action?

Methods included from Grid::Services

#count_records, #create, #destroy, #on_data_changed, #update

Methods included from Grid::Endpoints

#attempt_operation

Methods included from Grid::Configuration

#bbar, #context_menu, #default_bbar, #default_context_menu, #default_tools, #tools, #validate_config

Class Method Details

.i18n_idObject

Borrow translations from the grid for now



125
126
127
# File 'lib/netzke/tree/base.rb', line 125

def i18n_id
  "netzke.grid.base"
end

.server_side_config_optionsObject



120
121
122
# File 'lib/netzke/tree/base.rb', line 120

def server_side_config_options
  super + [:model]
end

Instance Method Details

#columnsObject



130
131
132
# File 'lib/netzke/tree/base.rb', line 130

def columns
  add_node_interface_methods(super)
end

#configure_client(c) ⇒ Object

Overrides `Grid::Configuration#configure_client`



165
166
167
168
169
# File 'lib/netzke/tree/base.rb', line 165

def configure_client(c)
  super

  c.root ||= model_adapter.record_to_hash(model_adapter.root, final_columns).netzke_literalize_keys
end

#get_records(params) ⇒ Object

Overrides Grid::Services#get_records



135
136
137
138
139
140
141
# File 'lib/netzke/tree/base.rb', line 135

def get_records(params)
  if params[:id] == 'root'
    model_adapter.find_root_records(config[:scope])
  else
    model_adapter.find_record_children(model_adapter.find_record(params[:id]), config[:scope])
  end
end

#is_node_expanded?(record) ⇒ Boolean



160
161
162
# File 'lib/netzke/tree/base.rb', line 160

def is_node_expanded?(record)
  record.respond_to?(:expanded) && record.expanded?
end

#node_to_hash(record, columns) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/netzke/tree/base.rb', line 152

def node_to_hash(record, columns)
  model_adapter.record_to_hash(record, columns).tap do |hash|
    if is_node_expanded?(record)
      hash["children"] = model_adapter.find_record_children(record, config[:scope]).map {|child| node_to_hash(child, columns).netzke_literalize_keys}
    end
  end
end

#read(params = {}) ⇒ Object

Overrides Grid::Services#read so we send records as key-value JSON (instead of array)



144
145
146
147
148
149
150
# File 'lib/netzke/tree/base.rb', line 144

def read(params = {})
  {}.tap do |res|
    records = get_records(params)
    res["children"] = records.map{|r| node_to_hash(r, final_columns).netzke_literalize_keys}
    res["total"] = count_records(params)  if config[:enable_pagination]
  end
end