Class: Netzke::Form::Base

Inherits:
Base
  • Object
show all
Includes:
Basepack::Attributes, Basepack::DataAccessor, Basepack::Fields, Endpoints, Services
Defined in:
lib/netzke/form/base.rb

Overview

Ext.form.Panel-based component with the following features

  • automatic default attribute configuration (overridable via config)

  • model validations

  • dynamic loading of form data

  • lockable mode

Client-side methods are documented here: api.netzke.org/client/classes/Netzke.Form.Base.html.

Configuration

model

Name of the ActiveRecord model that provides data to this Grid (e.g. “User”) or the model's class (e.g. User). Model is optional if you provide custom implementation of the endpoints.

record_id

Id of the record to be displayd in the form. Also see :record

record

Record to be displayd in the form. Takes precedence over :record_id

items

The layout of the fields as an array. See “Layout configuration”.

mode

Render mode, accepted options:

  • lockable - makes the form panel load initially in “display mode”, then lets “unlock” it, change the values, and “lock” it again, while updating the values on the server

Configuring attributes

Overriding individual attributes

Use the attribute DSL method to override configuration for a specific attribute. See Basepack::Attributes.

Layout configuration

The layout of the form is configured by supplying the item config option, same way it would be configured in Ext (thus allowing for complex form layouts). Form will expand fields by looking at their names (unless bind is set to false for a specific field).

Endpoints

Form implements the following endpoints:

  • load - loads a record with a given id from the server, e.g.:

    someForm.server.load({id: 100});
    
  • submit - gets called when the form gets submitted (e.g. by pressing the Apply button, or by calling netzkeOnApply)

  • get_combobox_options - gets called when a 'remote' combobox field gets expanded

Constant Summary

Constants included from Basepack::Attributes

Basepack::Attributes::ATTRIBUTE_METHOD_NAME

Instance Method Summary collapse

Methods included from Basepack::DataAccessor

#model, #model_adapter

Methods included from Basepack::Fields

#fields, #fields_from_items, #items

Methods included from Basepack::Attributes

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

Methods included from Services

#submit, #values

Instance Method Details

#bbarObject



113
114
115
# File 'lib/netzke/form/base.rb', line 113

def bbar
  config.has_key?(:bbar) ? config[:bbar] : default_bbar
end

#configure_client(c) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/netzke/form/base.rb', line 67

def configure_client(c)
  super

  configure_locked(c)

  if model_adapter
    c.pri = model_adapter.primary_key
  end

  if !c.multiedit
    c.record = js_record_data if record
  else
    c.record_id = c.record = nil if c.multiedit # never set record_id in multi-edit mode
  end
end

#configure_locked(c) ⇒ Object



95
96
97
# File 'lib/netzke/form/base.rb', line 95

def configure_locked(c)
  c[:locked] = c[:locked].nil? ? (c[:mode] == :lockable) : c[:locked]
end

#default_bbarObject



117
118
119
120
121
122
123
# File 'lib/netzke/form/base.rb', line 117

def default_bbar
  [].tap do |bbar|
    unless config.read_only
      bbar << "->" << :apply
    end
  end
end

#js_record_dataObject

A hash of record data including the meta field



105
106
107
# File 'lib/netzke/form/base.rb', line 105

def js_record_data
  model_adapter.record_to_hash(record, fields.values).merge(:meta => meta_field).netzke_literalize_keys
end

#multiedit?Boolean

Returns:

  • (Boolean)


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

def multiedit?
  !!config.multiedit
end

#recordObject



109
110
111
# File 'lib/netzke/form/base.rb', line 109

def record
  @record ||= config[:record] || config[:record_id] && model_adapter.find_record(config[:record_id])
end