Module: Skyline::DialogHelper

Defined in:
app/helpers/skyline/dialog_helper.rb

Instance Method Summary collapse

Instance Method Details

#dialog(title, *args, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/skyline/dialog_helper.rb', line 3

def dialog(title,*args,&block)   
  options_for_render = args.extract_options!
  options_for_render.reverse_merge! :width => "auto", :height => "auto"
  
  if args.any?
    content = args.last 
    options = options_for_render
  else
    options = options_for_render.slice!(:partial, :locals)   
    content = render(options_for_render)
  end
  
  options.each do |k,v|
    options[k] = case v
      when String,Symbol then "'" + escape_javascript(v.to_s) + "'"
      when Hash then options_for_javascript(v)
      else v
    end
  end    
  
  p =  "(function(){"
  p << "var sd = new Skyline.Dialog(#{options_for_javascript(options)});"
  p << "sd.setTitle('#{escape_javascript(title)}');"
  p << "sd.setContent('#{escape_javascript(content)}');"
  p << "sd.setup(); sd.show();"
  p << "})()"
  p.html_safe
end