Class: EasyModalWindow::Dialog
- Inherits:
-
Object
- Object
- EasyModalWindow::Dialog
- Defined in:
- lib/easy_modal_window.rb
Constant Summary collapse
- ALLOWED_OPTIONS =
[:window_selector, :title_selector, :render_template, :render_partial, :formats, :locals, :resizable, :height, :width, :buttons, :before_close, :success_message, :object, :container_class, :element_class, :errors_group_class].freeze
Instance Attribute Summary collapse
-
#modal_options ⇒ Object
readonly
Returns the value of attribute modal_options.
Instance Method Summary collapse
-
#before_close ⇒ Object
TODO: simplify this method.
- #buttons ⇒ Object
-
#initialize(args) ⇒ Dialog
constructor
A new instance of Dialog.
Constructor Details
#initialize(args) ⇒ Dialog
Returns a new instance of Dialog.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/easy_modal_window.rb', line 13 def initialize(args) = {} [:window_selector] = '#ajax-modal' [:title_selector] = 'h3.title' [:render_template] = nil [:render_partial] = nil [:locals] = {} [:formats] = [:html] [:resizable] = true [:height] = 'auto' [:width] = 'auto' # hash with button descriptions: {first_button: {name: 'Name', # condition: -> {...}, # action: 'location.reload();', # class: 'my-css-class'}, # second_button: ...} [:buttons] = {} # dialog callbacks # {condition: ->{...}, action: '...'} [:before_close] = {} # options for result templates [:success_message] = 'All right' [:object] = nil [:container_class] = '' [:element_class] = '' [:errors_group_class] = '' .merge!(args.slice(*EasyModalWindow::Dialog::ALLOWED_OPTIONS)) end |
Instance Attribute Details
#modal_options ⇒ Object (readonly)
Returns the value of attribute modal_options.
7 8 9 |
# File 'lib/easy_modal_window.rb', line 7 def end |
Instance Method Details
#before_close ⇒ Object
TODO: simplify this method
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/easy_modal_window.rb', line 53 def before_close result = {} if [:before_close].has_key?(:action) && [:before_close][:action].present? result[:action] = [:before_close][:action] else result[:condition] = false result[:action] = '' return result end result[:condition] = [:before_close][:condition].nil? || value_of([:before_close][:condition]) result end |
#buttons ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/easy_modal_window.rb', line 68 def [:buttons].inject([]) do |h, (k, v)| h.push( { internal_name: k, name: v[:name] || 'unknown', condition: value_of(v[:condition]).nil? || value_of(v[:condition]), action: v[:action] || '', class: v[:class] || '' } ) end end |