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 |
# File 'lib/easy_modal_window.rb', line 13 def initialize(args) @modal_options = {} @modal_options[:window_selector] = '#ajax-modal' @modal_options[:title_selector] = 'h3.title' @modal_options[:render_template] = nil @modal_options[:render_partial] = nil @modal_options[:locals] = {} @modal_options[:formats] = [:html] @modal_options[:resizable] = true @modal_options[:height] = 'auto' @modal_options[:width] = 'auto' # hash with button descriptions: {first_button: {name: 'Name', # condition: -> {...}, # action: 'location.reload();'}, # second_button: ...} @modal_options[:buttons] = {} # dialog callbacks # {condition: ->{...}, action: '...'} @modal_options[:before_close] = {} # options for result templates @modal_options[:success_message] = 'All right' @modal_options[:object] = nil @modal_options[:container_class] = '' @modal_options[:element_class] = '' @modal_options[:errors_group_class] = '' @modal_options.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 @modal_options end |
Instance Method Details
#before_close ⇒ Object
TODO: simplify this method
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/easy_modal_window.rb', line 52 def before_close result = {} if @modal_options[:before_close].has_key?(:action) && @modal_options[:before_close][:action].present? result[:action] = @modal_options[:before_close][:action] else result[:condition] = false result[:action] = '' return result end result[:condition] = @modal_options[:before_close][:condition].nil? || value_of(@modal_options[:before_close][:condition]) result end |
#buttons ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/easy_modal_window.rb', line 67 def @modal_options[:buttons].inject([]) do |h, v| option = {} option[:name] = v.last[:name] || 'unknown' option[:condition] = value_of(v.last[:condition]).nil? || value_of(v.last[:condition]) option[:action] = v.last[:action] || '' h << option h end end |