Class: Lipsiadmin::Ext::Store

Inherits:
Component show all
Defined in:
lib/view/helpers/ext/store.rb

Overview

Generate a new Ext.data.GroupingStore

Examples:

var store = new Ext.data.GroupingStore({
  reader: new Ext.data.JsonReader({
    id:'id',
    totalProperty:'count', root:'results',
    fields:[{
    name: "accounts.name"
  },{
    name: "accounts.categories.name"
  },{
    type: "date",
    renderer: Ext.util.Format.dateRenderer(),
    name: "accounts.date",
    dateFormat: "c"
  },{
    type: "date",
    renderer: Ext.util.Format.dateTimeRenderer(),
    name: "accounts.datetime",
    dateFormat: "c"
  } ]}),
  proxy: new Ext.data.HttpProxy({ url:'/backend/accounts.json' }),
  remoteSort: true
});

grid.store do |store|
  store.url "/backend/accounts.json"
  store.add "accounts.name"
  store.add "accounts.categories.name"
  store.add "accounts.date", :type => :date
  store.add "accounts.datetime", :type => :datetime
end

Instance Method Summary collapse

Methods inherited from Component

#add, #after, #before, #config, #config=, #get_var, #id, #method_missing, #on, #prefix=, #raise_error, #title, #un, #var, #with_output_buffer

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Store

:nodoc:

Yields:

  • (_self)

Yield Parameters:



40
41
42
43
44
45
46
# File 'lib/view/helpers/ext/store.rb', line 40

def initialize(options={}, &block)#:nodoc:
  @fields   = []
  super("Ext.data.GroupingStore", options)
  remoteSort true                     if config[:remoteSort].blank?
  baseParams("_method" => "GET")      if config[:baseParams].blank?
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Lipsiadmin::Ext::Component

Instance Method Details

#add_field(name = nil, options = {}) ⇒ Object

Add fields to a Ext.data.JsonReader

Examples:

{
  type: "date",
  renderer: Ext.util.Format.dateTimeRenderer(),
  name: "accounts.datetime",
  dateFormat: "c"
}

add "accounts.datetime", :type => :datetime

Raises:



71
72
73
74
75
76
77
78
79
80
# File 'lib/view/helpers/ext/store.rb', line 71

def add_field(name=nil, options={})#:nodoc:
  options[:name] = name if name
  case options[:type]
    when :date          then options.merge!({ :type => "date", :dateFormat => "Y-m-d" })
    when :time_to_date  then options.merge!({ :type => "date", :dateFormat => "c" })
    when :datetime      then options.merge!({ :type => "date", :dateFormat => "c" })
  end
  raise ComponentError, "You must provide a Name for all fields" if options[:name].blank?
  @fields << Configuration.new(options)
end

#fields(fields) ⇒ Object

This add automatically fields from an array



54
55
56
# File 'lib/view/helpers/ext/store.rb', line 54

def fields(fields)
  fields.each { |options| add_field(nil, options) }
end

#to_sObject

Return the javascript for create a new Ext.data.GroupingStore

Raises:



83
84
85
86
87
88
89
90
# File 'lib/view/helpers/ext/store.rb', line 83

def to_s
  raise ComponentError, "You must provide the correct var the store."       if get_var.blank?
  raise ComponentError, "You must provide the url for get the store data."  if @url.blank? && config[:proxy].blank?
  raise ComponentError, "You must provide some fields for get build store." if @fields.blank?
  config[:proxy]  = default_proxy  if config[:proxy].blank?
  config[:reader] = default_reader if config[:reader].blank?
  super
end

#url(value) ⇒ Object

The url for getting the json data



49
50
51
# File 'lib/view/helpers/ext/store.rb', line 49

def url(value)
  @url = value
end