Module: Lipsiadmin::View::Helpers::ExtHelper

Defined in:
lib/view/helpers/ext_helper.rb

Overview

Module containing the methods useful for ext/prototype

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



15
16
17
18
19
# File 'lib/view/helpers/ext_helper.rb', line 15

def self.included(base)#:nodoc:
  base.class_eval do
    alias_method_chain :to_s, :refactoring
  end
end

Instance Method Details

#ext_alert(title, message) ⇒ Object

Show a Ext.alert popup

# Generates: Ext.Msg.alert('Hey!', 'Hello World')
ext_alert('Hey!', 'Hello World')


87
88
89
# File 'lib/view/helpers/ext_helper.rb', line 87

def ext_alert(title, message)
  call "Ext.Msg.alert", title, message
end

#fn(function = nil, &block) ⇒ Object

Create a javascript function

# Generates: function() { window.show(); };
page.fn("window.show();")
or
page.fn { |p| p.call "window.show" }


116
117
118
119
120
121
122
# File 'lib/view/helpers/ext_helper.rb', line 116

def fn(function=nil, &block)
  if function
    record "function() { #{literal(function)} }"
  else
    record block_to_function(function || block)
  end
end

#grid(options = {}, &block) ⇒ Object

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


145
146
147
# File 'lib/view/helpers/ext_helper.rb', line 145

def grid(options={}, &block)
  self << Lipsiadmin::Ext::Grid.new(options, &block)
end

#hide_dialogsObject

Hide all open dialogs



28
29
30
# File 'lib/view/helpers/ext_helper.rb', line 28

def hide_dialogs
  record "Ext.Msg.getDialog().hide()"
end

#load(location) ⇒ Object

Load html/js and eval it’s code

# Generates: Backend.app.loadJs('/my/javascript.js');
load(:controller => :my, :action => :javascript, :format => :js)


50
51
52
53
# File 'lib/view/helpers/ext_helper.rb', line 50

def load(location)
  url = location.is_a?(String) ? location : @context.url_for(location)
  call "Backend.app.load", url
end

#mask(title = nil) ⇒ Object

Mask the Backend App

# Generates: Backend.app.mask('Hello World')
mask("Hello World")


105
106
107
# File 'lib/view/helpers/ext_helper.rb', line 105

def mask(title=nil)
  call "Backend.app.mask", title
end

#show_errors_for(*objects) ⇒ Object

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)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/view/helpers/ext_helper.rb', line 67

def show_errors_for(*objects)
  count   = objects.inject(0) {|sum, object| sum + object.errors.count }
  unless count.zero?
    error_messages = objects.map {|object| object.errors.full_messages.map {|msg| "<li>#{msg}</li>" } }
    record "Ext.Msg.show({
              title:    Backend.locale.messages.alert.title,
              msg:      '<ul>#{escape_javascript(error_messages.join)}</ul>',
              buttons:  Ext.Msg.OK,
              minWidth: 400
            });"
  else
    record "Ext.Msg.alert(Backend.locale.messages.compliments.title, Backend.locale.messages.compliments.message);"
  end
end

#to_s_with_refactoringObject

:nodoc:



21
22
23
24
25
# File 'lib/view/helpers/ext_helper.rb', line 21

def to_s_with_refactoring #:nodoc:
  returning javascript = @lines * $/ do
    source = javascript.dup
  end
end

#unmaskObject

Unmask the Backend App

# Generates: Backend.app.unmask()
unmask


96
97
98
# File 'lib/view/helpers/ext_helper.rb', line 96

def unmask
  call "Backend.app.unmask"
end

#update(*options_for_render) ⇒ Object

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


41
42
43
# File 'lib/view/helpers/ext_helper.rb', line 41

def update(*options_for_render)
  call "Backend.app.update", render(*options_for_render), true
end