Module containing the methods useful for ext/prototype
Methods
Public Instance methods
Show a Ext.alert popup
# Generates: Ext.Msg.alert('Hey!', 'Hello World')
ext_alert('Hey!', 'Hello World')
[ show source ]
# File lib/view/helpers/ext_helper.rb, line 87
87: def ext_alert(title, message)
88: call "Ext.Msg.alert", title, message
89: end
Create a javascript function
# Generates: function() { window.show(); };
page.fn("window.show();")
or
page.fn { |p| p.call "window.show" }
[ show source ]
# File lib/view/helpers/ext_helper.rb, line 116
116: def fn(function=nil, &block)
117: if function
118: record "function() { #{literal(function)} }"
119: else
120: record block_to_function(function || block)
121: end
122: end
Generate a full customizable Ext.GridPanel
Examples:
page.grid do |grid|
grid.id "grid-posts"
grid.title "List all Post"
grid.base_path "/backend/posts"
grid.forgery_protection_token request_forgery_protection_token
grid.authenticity_token form_authenticity_token
grid.tbar :default
grid.store do |store|
store.url "/backend/posts.json"
store.fields @column_store.store_fields
end
grid.columns do |columns|
columns.fields @column_store.column_fields
end
grid.bbar :store => grid.get_store, :pageSize => params[:limit]
end
[ show source ]
# File lib/view/helpers/ext_helper.rb, line 145
145: def grid(options={}, &block)
146: self << Lipsiadmin::Ext::Grid.new(options, &block)
147: end
Hide all open dialogs
[ show source ]
# File lib/view/helpers/ext_helper.rb, line 28
28: def hide_dialogs
29: record "Ext.Msg.getDialog().hide()"
30: end
Load html/js and eval it‘s code
# Generates: Backend.app.loadJs('/my/javascript.js');
load(:controller => :my, :action => :javascript, :format => :js)
[ show source ]
# File lib/view/helpers/ext_helper.rb, line 50
50: def load(location)
51: url = location.is_a?(String) ? location : @context.url_for(location)
52: call "Backend.app.load", url
53: end
Mask the Backend App
# Generates: Backend.app.mask('Hello World')
mask("Hello World")
[ show source ]
# File lib/view/helpers/ext_helper.rb, line 105
105: def mask(title=nil)
106: call "Backend.app.mask", title
107: end
Show errors (if they are) for the given objects and show a Ext.Message with explanation of the errors or if errors are empty, a congratulation message.
# Generates:
# Ext.Msg.show({
# title:Backend.locale.messages.alert.title,
# msg: '<ul>Name can't be blank!</ul>',
# buttons: Ext.Msg.OK,
# minWidth: 400
# })
show_errors_for(@account)
[ show source ]
# File lib/view/helpers/ext_helper.rb, line 67
67: def show_errors_for(*objects)
68: count = objects.inject(0) {|sum, object| sum + object.errors.count }
69: unless count.zero?
70: error_messages = objects.map {|object| object.errors.full_messages.map {|msg| "<li>#{msg}</li>" } }
71: record "Ext.Msg.show({
72: title: Backend.locale.messages.alert.title,
73: msg: '<ul>#{escape_javascript(error_messages.join)}</ul>',
74: buttons: Ext.Msg.OK,
75: minWidth: 400
76: });"
77: else
78: record "Ext.Msg.alert(Backend.locale.messages.compliments.title, Backend.locale.messages.compliments.message);"
79: end
80: end
Unmask the Backend App
# Generates: Backend.app.unmask() unmask
[ show source ]
# File lib/view/helpers/ext_helper.rb, line 96
96: def unmask
97: call "Backend.app.unmask"
98: end
Replaces the inner HTML of the Main Panel of Backend.
options_for_render may be either a string of HTML to insert, or a hash of options to be passed to ActionView::Base#render. For example:
# Replaces the inner HTML of the Main Panel of +Backend+.
# Generates: Backend.app.update("-- Contents of 'person' partial --");
page.update :partial => 'person', :object => @person
[ show source ]
# File lib/view/helpers/ext_helper.rb, line 41
41: def update(*options_for_render)
42: call "Backend.app.update", render(*options_for_render), true
43: end