This is the base class of ext components
You can generate your custom ExtJs objects like:
# Generates:
# var groupingView = Ext.grid.GroupingView({
# forceFit: true
# });
Component.new("Ext.grid.GroupingView", { :forceFit => true });
Generates and add new Component for generate on the fly ExtJs Objects
Examples:
# Generates:
# var panel = new Ext.Panel({
# id: 'testPanel',
# region: 'center',
# ...
# })
# mycmp.add(panel)
#
mycmp.add "Ext.Panel" do |panel|
panel.id "testPanel",
panel.region :center
...
end
[ show source ]
# File lib/view/helpers/ext/component.rb, line 164
164: def add(klass, options={}, &block)
165: add_object(Component.new(klass, options.merge(:prefix => get_var), &block))
166: end
Returns an array of javascripts to add afters component is rendered.
[ show source ]
# File lib/view/helpers/ext/component.rb, line 103
103: def after
104: @after
105: end
[ show source ]
# File lib/view/helpers/ext/component.rb, line 97
97: def before
98: @before
99: end
Return the configuration hash
[ show source ]
# File lib/view/helpers/ext/component.rb, line 75
75: def config
76: @config
77: end
Write the the configuration of object from an hash
[ show source ]
# File lib/view/helpers/ext/component.rb, line 69
69: def config=(options={})
70: @config = Configuration.new(options)
71: end
[ show source ]
# File lib/view/helpers/ext/component.rb, line 48
48: def get_var
49: # I will nillify obj if they are blank
50: @var = nil if @var.blank?
51: @config.delete(:var) if @config[:var].blank?
52:
53: # Return a correct var
54: current_var = (@var || @config[:var] || build_var)
55: @prefix.to_s + current_var.to_s
56: end
The id of the component
[ show source ]
# File lib/view/helpers/ext/component.rb, line 33
33: def id(new_id)
34: @config[:id] = new_id
35: end
Generates a new handler for the given component
Examples:
# Generates:
# grid.on("dblclick", function() {
# edit();
# new();
# Ext.Msg.alert("Hello", "world");
# });
grid.on :dblclick do |p|
p.call "edit"
p.call "new"
p.ext_alert "Hello", "world"
end
[ show source ]
# File lib/view/helpers/ext/component.rb, line 123
123: def on(event, function=nil, scope=nil, &block)
124: # Remove old handlers
125: un(event)
126: @un[event.to_sym] = false # we need to reset it
127: scope = ", #{scope.to_l}" unless scope.blank?
128: if function
129: after << "#{get_var}.on(#{event.to_json}, #{function}#{scope});"
130: else
131: generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(self, &block)
132: after << "#{get_var}.on(#{event.to_json}, function() { \n #{generator.to_s.gsub("\n", "\n ")}\n}#{scope});"
133: end
134: end
Set the prefix for the var of the component. This is usefull when for example we are using two grids for solve conflict problems.
[ show source ]
# File lib/view/helpers/ext/component.rb, line 91
91: def prefix=(value)
92: @prefix = value
93: end
Define the title of the component.
Every component can have a title, because in Lipsiadmin we use it as a "pagetitle", but if you need it as a config you can provide global = false
[ show source ]
# File lib/view/helpers/ext/component.rb, line 63
63: def title(title, global=true)
64: global ? (before << "Backend.app.setTitle(#{title.to_json});") : config[:title] = title
65: end
Returns the javascript for current component
# Generates: var rowSelectionModel = Ext.grid.RowSelectionModel();
Component.new("Ext.grid.RowSelectionModel").to_s
[ show source ]
# File lib/view/helpers/ext/component.rb, line 178
178: def to_s(options={})
179: script = returning [] do |script|
180: script << @before.uniq.compact.join("\n\n")
181: script << "var #{get_var} = new #{@klass}(#{config.to_s});"
182: script << @after.uniq.compact.join("\n\n")
183: end
184: script.delete_if { |s| s.blank? }.join("\n\n")
185: end
Remove a listener
Example: grid.un(:dblclick)
[ show source ]
# File lib/view/helpers/ext/component.rb, line 140
140: def un(event)
141: @un[event.to_sym] = true
142: found = @after.delete_if { |s| s.start_with?("#{get_var}.on(#{event.to_json}") if s.is_a?(String) }
143: after << "#{get_var}.un(#{event.to_json})" unless found
144: end
Set var used by the component
Generates: var myVar = new Ext.Grid({...});
store.var "myVar"
[ show source ]
# File lib/view/helpers/ext/component.rb, line 42
42: def var(var)
43: @var = var
44: end