forked from publify/publify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_helper.rb
76 lines (62 loc) · 2.96 KB
/
content_helper.rb
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
module Admin::ContentHelper
def link_to_destroy_draft(record, controller = controller.controller_name)
return unless record.state.to_s.downcase == "draft"
link_to(_("Destroy this draft"),
{ controller: controller, action: 'destroy', id: record.id },
data: { confirm: _("Are you sure?")},
method: :post, class: 'btn danger' )
end
def auto_complete_result(entries, field, phrase = nil)
return unless entries
items = entries.map { |entry| content_tag("li", phrase ? highlight(entry[field], phrase) : h(entry[field])) }
content_tag("ul", items.uniq.join.html_safe, {:class => 'unstyled', :id => 'autocomplete'})
end
def auto_complete_field(field_id, options = {})
function = "var #{field_id}_auto_completer = new Ajax.Autocompleter("
function << "'#{field_id}', "
function << "'" + (options[:update] || "#{field_id}_auto_complete") + "', "
function << "'#{url_for(options[:url])}'"
js_options = {}
js_options[:tokens] = array_or_string_for_javascript(options[:tokens]) if options[:tokens]
js_options[:callback] = "function(element, value) { return #{options[:with]} }" if options[:with]
js_options[:indicator] = "'#{options[:indicator]}'" if options[:indicator]
js_options[:select] = "'#{options[:select]}'" if options[:select]
js_options[:paramName] = "'#{options[:param_name]}'" if options[:param_name]
js_options[:frequency] = "#{options[:frequency]}" if options[:frequency]
js_options[:method] = "'#{options[:method].to_s}'" if options[:method]
{ :after_update_element => :afterUpdateElement,
:on_show => :onShow, :on_hide => :onHide, :min_chars => :minChars }.each do |k,v|
js_options[v] = options[k] if options[k]
end
function << (', ' + options_for_javascript(js_options) + ')')
javascript_tag(function)
end
def get_feedback_status(status)
status ? _("enabled") : _("disabled")
end
def get_post_types
post_types = @post_types || []
if post_types.size.zero?
return hidden_field_tag "article[post_type]", "read"
end
html = "<div class='well'>"
html << content_tag(:h4, _("Article type"))
html << "<select name=article[post_type]>"
post_types.each do |pt|
html << "<option value='read' #{'selected' if @article.post_type == 'read'} >#{_('Default')}</option>"
html << "<option #{'selected' if @article.post_type == pt.permalink} value='#{pt.permalink}'>#{pt.name}</option>"
end
html << "</select>"
html << "</div>"
end
def toggle_element(element, label=_("Change"))
"<a href=\"#\" onclick=\"Element.toggle('#{element}'); return false\">#{label}</a>".html_safe
end
def ok_button(element)
content_tag(:p, content_tag(:span, toggle_element('status', "OK"), :class => 'btn btn-mini'))
end
def publish_now_or_already_published(article)
return _("now") unless article.published and article.state.to_s.downcase == 'published'
display_date_and_time(article.published_at)
end
end