This repository was archived by the owner on Jan 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathapplication_helper.rb
More file actions
287 lines (237 loc) · 7.92 KB
/
application_helper.rb
File metadata and controls
287 lines (237 loc) · 7.92 KB
1
2
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def content_for(*args)
super unless args.first.to_sym == :column and mobile?
end
def logo_image
logo = @organization ? @organization.logo(:top) : "header_logo_black.png"
image_tag(logo, :alt => "Teambox")
end
def archived_project_strip(project)
if project.try(:archived)
render 'shared/strip', :project => project
end
end
def submit_or_cancel(object, name, submit_id, loading_id)
render 'shared/submit_or_cancel',
:object => object,
:name => name,
:submit_id => submit_id,
:loading_id => loading_id
end
# types: success, error, notice
def show_flash
flash.each do |type, message|
unless message.blank?
haml_tag :p, h(message.html_safe), :class => "flash flash-#{type}"
end
end
end
def navigation(project,projects,recent_projects)
render 'shared/navigation',
:project => project,
:projects => projects,
:recent_projects => recent_projects
end
def search_bar
render 'shared/search_bar'
end
def header
render 'shared/header'
end
def footer
render 'shared/footer'
end
def location_name?(names)
Array(names).any?{ |name| name == location_name }
end
def location_name
"#{action_name}_#{controller.controller_name}"
end
def loading_image(id)
image_tag('loading.gif', :id => id, :class => 'loading', :style => 'display: none')
end
def loading(action, id = nil)
img_id = id ? "#{action}_loading_#{id}" : "#{action}_loading"
image_tag('loading.gif', :id => img_id, :class => 'loading', :style => 'display: none', :alt => '')
end
def posted_date(datetime)
datetime = datetime.in_time_zone(current_user.time_zone) if current_user
content_tag :time, localize(datetime, :format => :long), :class => 'timeago',
:datetime => datetime.xmlschema, :pubdate => true, :'data-msec' => datetime_ms(datetime)
end
def datetime_ms(datetime)
datetime = datetime.in_time_zone(current_user.time_zone) if current_user
datetime.to_i * 1000
end
def drag_image
image_tag('drag.png', :class => 'drag')
end
def loading_action_image(e=nil, hidden=false)
image_tag('loading.gif',
:id => "loading_action#{ "_#{e}" if e}",
:class => 'loading_action',
:style => (hidden ? 'display:none' : nil))
end
def is_controller?(_controller, _action = nil)
controller.controller_name == _controller.to_s and (_action == nil or controller.action_name == _action.to_s)
end
def support_link
if url = Teambox.config.support_url
link_to t('.support'), url
end
end
def mobile_link
link_to t('.mobile'), change_format_path(:m)
end
def help_link
if url = Teambox.config.help_url
link_to t('.help'), "#{url}/#{controller.controller_name}"
end
end
def to_sentence(array)
array.to_sentence(:two_words_connector => " #{t('common.and')} ",
:last_word_connector => " #{t('common.and')} ")
end
def upgrade_browser
render 'shared/upgrade_browser'
end
def chrome_frame
render 'shared/chrome_frame'
end
def latest_announcement
render 'shared/latest_announcement'
end
def errors_for(model, field)
error = case errors = model.errors.on(field)
when Array then errors.first
when String then errors
end
"<div class='errors_for'>#{error}</div>".html_safe
end
def formatting_documentation_link
link_to '', text_styles_path, :rel => :facebox, :class => :style_icon, :title => t('projects.show.text_styling')
end
def formatting_invitations_link
link_to t('invitations.search.help'), invite_format_path, :rel => :facebox
end
def host_with_protocol
request.protocol + request.host + request.port_string
end
def human_hours(hours)
hours = (hours.to_f * 100).round.to_f / 100
if hours > 0
minutes = ((hours % 1) * 60).round
if minutes == 60
hours += 1
minutes = 0
end
if minutes.zero?
t('comments.comment.hours', :hours => hours.to_i)
else
t('comments.comment.hours_with_minutes', :hours => hours.to_i, :minutes => minutes)
end
end
end
def set_reload_url(path)
@reload_url = path
end
def reload_url
@reload_url || url_for(request.path_parameters)
end
def rss?
request.format == :rss
end
def time_tracking_enabled?
Teambox.config.allow_time_tracking || false
end
def auto_discovery_link_by_context(user, project)
if user
path = project ? project_path(project, :format => :rss) : projects_path(:format => :rss)
auto_discovery_link_tag(:rss, user_rss_token(path))
end
end
def configure_this_organization
if Teambox.config.community && @community_role == :admin && @community_organization.description.blank? && params[:organization].nil?
message = if location_name != "appearance_organizations"
link_to("Click here", appearance_organization_path(@community_organization)) + " to configure your organization"
else
"Introduce some HTML code for your main site to configure your site"
end
%(<div style="background-color: rgb(255,255,220); border-bottom: 1px solid rgb(200,200,150); width: 100%; display: block; font-size: 12px; padding: 10px 0; text-align: center">
#{message}
</div>).html_safe
end
end
def locale_select_values
I18n.available_locales.map { |code|
[t(code, :scope => :locales, :locale => code), code.to_s]
}.sort_by(&:first)
end
def current_locale_name
t(I18n.locale, :scope => :locales, :locale => I18n.locale)
end
# collecting stats about Teambox installations
def tracking_code
if Teambox.config.tracking_enabled and Rails.env.production?
fake_img = "https://teambox.com/logo.png/#{request.host}"
%(<div style="background-image: url(#{fake_img})"></div>).html_safe
end
end
def preview_button
content_tag(:button, :'data-alternate' => t('comments.preview.close'), :class => :preview) do
t('comments.preview.preview')
end
end
def upload_form_html_options(page, upload)
id = upload.new_record? ? 'new_upload' : 'upload_file_form'
form_classes = %w(upload_form app_form)
form_classes << 'form_error' unless upload.errors.empty?
form_classes << 'new_upload' if upload.new_record?
hidden = page || (action_name == 'index' && upload.errors.empty?)
form_style = hidden ? 'display: none' : nil
{:html => { :multipart => true, :id => id, :style => form_style, :class => form_classes}}
end
##
## eg. js_id(:edit_header,@project,@tasklist) => project_21_task_list_12_edit_header
## eg. js_id(:new_header,@project,Task.new) => project_21_task_list_new_header
## eg. js_id(@project,Task.new) => project_21_task_list
def js_id(*args)
if args.is_a?(Array)
element = args[0].is_a?(String) || args[0].is_a?(Symbol) ? args[0] : nil
models = args.slice(1,args.size-1)
raise ArgumentError unless models.all?{|a|a.is_a?(ActiveRecord::Base)}
elsif args.is_a?(ActiveRecord::Base)
models = [args]
else
raise ArgumentError
end
generate_js_path(element,models)
end
def generate_js_path(element,models)
path = []
models.each do |model|
path << model.class.to_s.underscore
path << model.id unless model.new_record?
end
path << element unless element.nil?
path.join('_')
end
def show_form_errors(target,form_id)
page.select("##{form_id} .error").each do |e|
e.remove
end
target.errors.each do |field,message|
errors = <<BLOCK
var e = $('#{form_id}').down('.#{field}');
if (e) {
if(e.down('.error'))
e.down('.error').insert({bottom: "<br /><span>'#{message}'</span>"})
else
e.insert({ bottom: "<p class='error'><span>#{message}</span></p>"})
}
BLOCK
page << errors
end
end
end