Module: ErpApp::Extensions::Railties::ActionView::Helpers::IncludeHelper

Defined in:
lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb

Instance Method Summary collapse

Instance Method Details

#include_code_mirror_library(theme = 'vibrant-ink') ⇒ Object



43
44
45
46
47
48
# File 'lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb', line 43

def include_code_mirror_library(theme='vibrant-ink')
  buffer = javascript_include_tag("codemirror_compassae")
  buffer << stylesheet_link_tag("codemirror_compassae")

  buffer
end

#include_compass_ae_instanceObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb', line 50

def include_compass_ae_instance
  compass_ae_instance = CompassAeInstance.find_by_internal_identifier('base')
  json_hash = {
      :version => compass_ae_instance.version,
      :installedAt => compass_ae_instance.created_at.strftime("%B %d, %Y at %I:%M%p"),
      :lastUpdateAt => compass_ae_instance.updated_at.strftime("%B %d, %Y at %I:%M%p"),
      :installedEngines => compass_ae_instance.installed_engines,
      :guid => compass_ae_instance.guid
  }
  raw "<script type=\"text/javascript\">compassAeInstance = #{json_hash.to_json};</script>"
end

#include_highslide(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb', line 8

def include_highslide(options = {})
  raw case options[:version].to_s.downcase
        when 'full'
          static_javascript_include_tag("highslide/highslide/highslide-full.js")
        when 'gallery'
          static_javascript_include_tag("highslide/highslide/highslide-with-gallery.js")
        when 'html'
          static_javascript_include_tag("highslide/highslide/highslide-with-html.js")
        else
          static_javascript_include_tag("highslide/highslide/highslide.js")
      end
end

#load_shared_application_resources(resource_type) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb', line 75

def load_shared_application_resources(resource_type)
  raw case resource_type.to_sym
        when :javascripts
          sources = ErpApp::Config.shared_js_assets.collect { |path| javascript_include_tag(path) }.join(' ')

          # add the root apps shared assets if they exist
          if File.exists? File.join(Rails.root, 'app/assets/javascripts/erp_app/shared/app.js')
            sources += javascript_include_tag('erp_app/shared/app.js')
          end

          sources

        when :stylesheets
          ErpApp::Config.shared_css_assets.collect { |path| stylesheet_link_tag(path) }.join(' ')
      end
end

#set_authenticity_tokenObject



68
69
70
# File 'lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb', line 68

def set_authenticity_token
  raw "<script type='text/javascript'>Compass.ErpApp.Utility.createNamespace('Compass.ErpApp'); Compass.ErpApp.AuthentictyToken = '#{form_authenticity_token}';</script>" if current_user
end

#set_session_timeout(warn_milli_seconds = ((ErpApp::Config.session_warn_after*60)*1000), redirect_milli_seconds = ((ErpApp::Config.session_redirect_after*60)*1000), redirect_to = '/session/sign_out') ⇒ Object Also known as: setSessionTimeout



62
63
64
65
66
# File 'lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb', line 62

def set_session_timeout(warn_milli_seconds=((ErpApp::Config.session_warn_after*60)*1000),
                        redirect_milli_seconds=((ErpApp::Config.session_redirect_after*60)*1000),
                        redirect_to='/session/sign_out')
  raw "<script type='text/javascript'>Compass.ErpApp.Utility.SessionTimeout.setupSessionTimeout(#{warn_milli_seconds}, #{redirect_milli_seconds}, '#{redirect_to}') </script>" if current_user
end

#setup_js_authentication(user = current_user) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb', line 21

def setup_js_authentication(user=current_user)
  # only setup user if a current_user is logged in
  if current_user
    current_user = {
        username: user.username,
        lastloginAt: user.,
        lastActivityAt: user.last_activity_at,
        failedLoginCount: user.failed_logins_count,
        email: user.email,
        roles: user.all_roles.collect { |role| role.internal_identifier },
        capabilities: user.class_capabilities_to_hash,
        id: user.id,
        partyId: user.party.id,
        dbaOrganizationId: user.party.dba_organization.id,
        description: user.party.to_s
    }
    js_string = javascript_include_tag('erp_app/authentication/compass_user.js')
    js_string << (raw "<script type='text/javascript'>var currentUser = new ErpApp.CompassAccessNegotiator.CompassUser(#{current_user.to_json});</script>")
    js_string
  end
end