Class: Symphonia::ApplicationHelper::SymphoniaModalDialog

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/symphonia/application_helper.rb

Overview

def render_modal_dialog(show = true, options = {}, &block)

tags = SymphoniaModalDialog.new(self, options)
yield tags if block_given?
html = tags.to_html
if show
  "$('##{tags.modal_id}').remove();$('body').append('#{j html}'); showModal('##{tags.modal_id}');".html_safe
else
  html
end

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, options = {}) ⇒ SymphoniaModalDialog

Returns a new instance of SymphoniaModalDialog.



306
307
308
309
310
311
312
# File 'app/helpers/symphonia/application_helper.rb', line 306

def initialize(controller, options = {})
  @c = controller
  @title = options.delete(:title)
  @modal_id = options.delete(:id) || 'modal-dialog'
  @form_options = options.delete(:form_options) || {}
  @options = options
end

Instance Attribute Details

#body(&block) ⇒ Object



337
338
339
340
341
342
343
# File 'app/helpers/symphonia/application_helper.rb', line 337

def body(&block)
  if block_given?
    @body = @c.capture(&block)
  else
    @body = (@body.is_a?(Proc) ? @body.call.to_s : @body.to_s)
  end
end


345
346
347
348
349
350
351
# File 'app/helpers/symphonia/application_helper.rb', line 345

def footer(&block)
  if block_given?
    @footer = @c.capture(&block)
  else
    @footer = (@footer.is_a?(Proc) ? @footer.call.to_s : @footer.to_s)
  end
end

Returns the value of attribute modal_id.



302
303
304
# File 'app/helpers/symphonia/application_helper.rb', line 302

def modal_id
  @modal_id
end

#sizeObject

Returns the value of attribute size.



304
305
306
# File 'app/helpers/symphonia/application_helper.rb', line 304

def size
  @size
end

#titleObject

Returns the value of attribute title.



302
303
304
# File 'app/helpers/symphonia/application_helper.rb', line 302

def title
  @title
end

Instance Method Details

#header(&block) ⇒ Object



329
330
331
332
333
334
335
# File 'app/helpers/symphonia/application_helper.rb', line 329

def header(&block)
  if block_given?
    @header = @c.capture(&block)
  else
    @header = (@header.is_a?(Proc) ? @header.call.to_s : @header.to_s)
  end
end

#submit(name = nil, options = {}) ⇒ Object



353
354
355
356
# File 'app/helpers/symphonia/application_helper.rb', line 353

def submit(name = nil, options = {})
  name ||= @c.t(:button_save)
  @footer = footer.to_s + @c.link_to(name, 'javascript:void(0)', { onclick: "$('##{@modal_id}').find('form').submit()", class: 'btn btn-primary' }.merge(options)).html_safe
end

#to_htmlObject



316
317
318
319
320
321
322
323
324
325
326
327
# File 'app/helpers/symphonia/application_helper.rb', line 316

def to_html
  html = "<div id='#{@modal_id}' style='' class='modal fade' role='dialog'><div class='modal-dialog #{'modal-lg' if size.present?}'><div class='modal-content'>"
  html << @c.(:div, class: 'modal-header') do
    @c.(:button, '', class: 'close fa fa-times', data: { dismiss: 'modal' }, 'aria-hidden' => true) + @c.(:h4, @title, class: 'modal-title') + @header.to_s
  end
  content = @c.(:div, @c.(:div, body.html_safe, class: 'modal-content-inner-container container-fluid'), class: 'modal-body')
  content << @c.(:div, footer.html_safe, class: 'modal-footer')

  html << content.html_safe
  html << '</div></div></div>'
  html.html_safe
end