Module: Appoxy::UI::ApplicationHelper

Defined in:
lib/ui/application_helper.rb

Overview

To use, include in your ApplicationHelper. include Appoxy::UI::ApplicationHelper

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
# File 'lib/ui/application_helper.rb', line 13

def self.included(base)
#                puts self.class.name + " included in " + base.class.name
end

Instance Method Details



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ui/application_helper.rb', line 50

def appoxy_footer
  ret = ''

  if current_user # && current_user.time_zone.blank?
    ret += '
    <script type="text/javascript">
  $(document).ready(function() {
      var myDate = new Date();
      var tz_offset = -(myDate.getTimezoneOffset() / 60);
//            document.write(tz_offset);
      $.post("/users/' + current_user.id + '/timezone", { offset: tz_offset })
  });
    </script>'
  end

  if defined?(RELEASE_INFO)
    ret += '<div style="clear:both; margin-top:15px;"
    class="instance_info_div">' + INSTANCE_INFO["instance_id"] + ':
    Revision ' + RELEASE_INFO["scm"]["revision"][0..5] + ' built on ' +
        RELEASE_INFO["deploy_date"] + '</div>'
  end

  if ::Rails.env == "development"
    ret += '<div class="debug">' + ERB::Util.html_escape(SimpleRecord.stats.inspect) + '</div>'
  end
  ret.html_safe
end

#appoxy_geo_finder(options = {}) ⇒ Object

Helper for getting user’s geo location and storing it on User object. options:

:show_map=>"#div_to_show_on" - This will display a tiny map of location


138
139
140
141
142
143
144
145
# File 'lib/ui/application_helper.rb', line 138

def appoxy_geo_finder(options={})
#        ret = File.read('_geo_location_finder.html.erb')
  options.merge!({:current_user=>current_user})
  options = Appoxy::UI::BindingHack.new(options)
  template = ERB.new(File.read(File.join(File.dirname(__FILE__), '_geo_location_finder.html.erb')))
  ret = template.result(options.get_binding)
  ret.html_safe
end

#appoxy_headerObject

Place in application.html.erb in head to get default Appoxy style elements and javascripts.



42
43
44
45
46
47
48
# File 'lib/ui/application_helper.rb', line 42

def appoxy_header
  # stylesheets and what not could either be included in this gem or links to s3

  # include google javascript for jquery and jquery-ui and perhaps jquery tools
  ret = appoxy_javascripts
  ret.html_safe
end

#appoxy_javascriptsObject



32
33
34
35
36
37
38
39
# File 'lib/ui/application_helper.rb', line 32

def appoxy_javascripts
  '<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAhes0f80sBcwL-h5xCNkkgxQBmiBpQeSpIciQPfZ5Ss-a60KXIRQOVvqzsNpqzhmG9tjky_5rOuaeow"></script>
  <script type="text/javascript">
      google.load("jquery", "1");
      google.load("jqueryui", "1");
  </script>
'.html_safe
end

#base_urlObject



21
22
23
24
25
26
27
28
# File 'lib/ui/application_helper.rb', line 21

def base_url
  r = "#{request.protocol}#{request.host}"
  if request.port != 80
    r << ":#{request.port}"
  end
  @base_url = r
  r
end

#current_urlObject



17
18
19
# File 'lib/ui/application_helper.rb', line 17

def current_url
  request.url
end

#date_format(date, options = {}) ⇒ Object

options:

:format=>:long, default = :long
:user=> a User object, if not specified will use @current_user


81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ui/application_helper.rb', line 81

def date_format(date, options={})
  format = options[:format] || :long
#        puts 'date_format on ' + date.class.name + " --- " + date.inspect
  user ||= @current_user
  return '' if date.nil?
  date = Time.parse(date) if date.is_a?(String)
  if date.is_a?(Date) && !date.is_a?(DateTime) && !date.is_a?(Time)
    return date.to_formatted_s(format)
  end
  return date.to_local_s(user, :format=>format)
end

#error_messages_for(ob, options = {}) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ui/application_helper.rb', line 120

def error_messages_for(ob, options={})
  return '' if ob.nil?
  if ob.errors.size > 0
    s = "<div class=\"error_message_for_container\">"
    s2 = ""
    ob.errors.full_messages.each do |msg|
      s2 << (:div, msg, :class => "error_message_for")
    end
    s << s2
    s << "</div>"
    s.html_safe
  end
end

#flash_messages(options = {}) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ui/application_helper.rb', line 93

def flash_messages(options={})
  if flash.size > 0
    s = "<div class=\"flash_messages_container\">"
    s2 = ""
    flash.each_pair do |type, msg|
      clazz = "flash #{type}"
      if options[:theme] == :jquery
        if type == "error"
          clazz << " ui-state-error"
        elsif type == "highlight"
          clazz << " ui-state-highlight"
        end
      end
      if msg.is_a?(Array)
        msg.each do |m|
          s2 << (:div, m, :class =>clazz)
        end
      else
        s2 << (:div, msg, :class =>clazz)
      end
    end
    s << s2
    s << "</div>"
    s.html_safe
  end
end

#latest_news(feed_url, options = {}) ⇒ Object

feed_url: url to atom or rss feed options:

:div_id => default is "news_feed"


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/ui/application_helper.rb', line 150

def latest_news(feed_url, options={})
  div_id = options[:div_id] || "news_feed"
  s = <<-EOF
<div id="#{div_id}"></div>

<script type="text/javascript">

google.load("feeds", "1");

function #{div_id}_init() {
    var feed = new google.feeds.Feed("#{feed_url}");
    feed.setNumEntries(3)
    feed.load(function(result) {
        if (!result.error) {
            var container = $("##{div_id}");
            for (var i = 0; i < result.feed.entries.length; i++) {
                var entry = result.feed.entries[i];
              container.append('<div><div class="blog_title"><a href="' + entry.link + '">' + entry.title + '</a></div>'
              + '<div class="blog_body">' + entry.contentSnippet + '</div>'
              + '<div class="blog_date">' + entry.publishedDate + '</div>'
              + '</div>');
            }
        }
    });
}
google.setOnLoadCallback(#{div_id}_init);
</script>
  EOF
  s.html_safe
end

#visualizationsObject



181
182
183
# File 'lib/ui/application_helper.rb', line 181

def visualizations
  Visualizations.new
end