Module: ErpApp::Widgets::Railties::ActionView::Helpers::WidgetHelper

Defined in:
lib/erp_app/widgets/railties/action_view/helpers/widget_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_widget_url(action, id = nil, params = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/erp_app/widgets/railties/action_view/helpers/widget_helper.rb', line 28

def build_widget_url(action, id=nil, params={})
  url = if id
          "/erp_app/widgets/#{@name}/#{action}/#{@uuid}/#{id}"
        else
          "/erp_app/widgets/#{@name}/#{action}/#{@uuid}"
        end

  if params
    url = "#{url}?"
    params.each do |k, v|
      url += "#{k.to_s}=#{v.to_s}&"
    end
    url = url[0...url.length - 1]
  end

  url
end

#get_widget_actionObject



54
55
56
# File 'lib/erp_app/widgets/railties/action_view/helpers/widget_helper.rb', line 54

def get_widget_action
  params[:widget_action] || 'index'
end

#include_widgetsObject



50
51
52
# File 'lib/erp_app/widgets/railties/action_view/helpers/widget_helper.rb', line 50

def include_widgets
  raw ErpApp::Widgets::JavascriptLoader.glob_javascript
end

#render_widget(name, opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/erp_app/widgets/railties/action_view/helpers/widget_helper.rb', line 8

def render_widget(name, opts={})
  action = opts[:action] || :index
  params = opts[:params].nil? ? {} : opts[:params]

  uuid = Digest::SHA1.hexdigest(Time.now.to_s + rand(10000).to_s)

  #render widget
  widget_obj = "::Widgets::#{name.to_s.camelize}::Base".constantize.new(self.controller, name.to_s, action.to_s, uuid, params, nil)
  result = widget_obj.process(action.to_s)

  html = "<div id=\"#{uuid}\" class='compass_ae-widget'>"
  html << result
  html << "</div>"
  html << "<script type='text/javascript'>"
  html << "Compass.ErpApp.Widgets.LoadedWidgets.push({id:'#{uuid}',name:'#{name.to_s}',action:'#{action.to_s}',params:#{params.to_json}});"
  html << "</script>"

  raw html
end

#set_widget_params(widget_params = {}) ⇒ Object



58
59
60
61
# File 'lib/erp_app/widgets/railties/action_view/helpers/widget_helper.rb', line 58

def set_widget_params(widget_params={})
  widget_params.merge!(params.symbolize_keys)
  widget_params
end

#widget_result_idObject



46
47
48
# File 'lib/erp_app/widgets/railties/action_view/helpers/widget_helper.rb', line 46

def widget_result_id
  "#{@uuid}_result"
end