Module | ApplicationHelper
In: | app/helpers/application_helper.rb

Methods added to this helper will be available to all templates in the application.

Copyright (c) 2006 Logica

### Methods

div_id editable_content link_to_change_report_notification_toggle link_to_comment link_to_done_toggle link_to_notification_toggle link_to_page link_to_reviewer link_to_site link_to_user link_to_version link_to_version2 links_to_pages menulink_to tabular_form_for tinymce

### Classes and Modules

Class ApplicationHelper::TabularFormBuilder

### Public Instance methods

div_id(record, call_id)

returns unique div id from a record in a page

[Source]

         # File app/helpers/application_helper.rb, line 253
    253:   def div_id(record, call_id)
    254:     return  record.class.to_s + record.id.to_s + "_" + call_id
    255:   end

editable_content(options)

Helper to simplify In-Place Editing

[Source]

        # File app/helpers/application_helper.rb, line 19
    19:   def editable_content(options)
    20:     options[:content] = { :element => 'span' }.merge(options[:content])
    21:     options[:url] = {}.merge(options[:url])
    22:     options[:ajax] = { :okText => 'Save', :cancelText => 'Cancel'}.merge(options[:ajax] || {})
    23:     script = Array.new
    24:     script << 'new Ajax.InPlaceEditor('
    25:     script << "  '#{options[:content][:options][:id]}',"
    26:     script << "  '#{url_for(options[:url])}',"
    27:     script << "  {"
    28:     script << options[:ajax].map{ |key, value| "#{key.to_s}: #{value}" }.join(", ")
    29:     script << "  }"
    30:     script << ")"
    31:     content_tag(
    32:                 options[:content][:element],
    33:                 options[:content][:text],
    34:                 options[:content][:options]
    35:     ) + javascript_tag( script.join)
    36:   end

link_to_change_report_notification_toggle(type = 'D', user = session['user'])

[Source]

         # File app/helpers/application_helper.rb, line 111
    111:   def link_to_change_report_notification_toggle(type = 'D', user = session['user'])
    112:     returning html = [] do
    113:       if !user.nil? && (mine?(user) || cadmin?)
    114:           checked = ""
    115:           checked = "checked" if (type == 'D' && user.notify_daily == 1) || (type == 'M' && user.notify_monthly == 1) || (type == 'W' && user.notify_weekly == 1) || (type == 'I' && user.notify_immediate == 1)
    116:           txt = "<input type=checkbox #{checked} DISABLED> Daily" if type == 'D'
    117:           txt = "<input type=checkbox #{checked} DISABLED> Monthly" if type == 'M'
    118:           txt = "<input type=checkbox #{checked} DISABLED> Weekly" if type == 'W'
    119:           txt = "<input type=checkbox #{checked} DISABLED> Immediate" if type == 'I'
    120:           div_id = "change_report_" + user.id.to_s + "_"  + type
    121:           #checked = "checked" if type == 'M' && user.notify_monthly == "1"
    122:           #checked = "checked" if type == 'D' && user.notify_weekly == "1"
    123:         if mine?(user) || cadmin?
    124:           html << "<span id=\"" + div_id + "\">"
    125:           html << link_to_remote(txt.gsub('DISABLED', ''), :update => div_id, :url => {:controller => "users", :action => "toggle_change_report_notification", :type => type, :user_id => user.id}, :method => 'post')
    126:           html << "</span>"
    127:         else
    128:           html << txt
    129:         end
    130:       else
    131:         html << "ERROR: No user specified"
    132:       end
    133:     end.join("\n")
    134:   end

link_to_comment(comment)

link_to helper method for a Comment

[Source]

         # File app/helpers/application_helper.rb, line 248
    248:   def link_to_comment(comment)
    249:     link_to(truncate(strip_tags(comment.text)), :controller => 'pages', :action => 'discussion', :site_folder => comment.site.folder, :id => comment.page.id)
    250:   end

link_to_done_toggle(record)

[Source]

         # File app/helpers/application_helper.rb, line 136
    136:   def link_to_done_toggle(record)
    137:     class_name = 'DaText'
    138:     class_name = record.class.name if ['Version','Upload', 'UserVersion', 'BaselineProcessVersion'].include?(record.class.name)
    139:     returning html = [] do
    140:       html << "<span id=\"" + div_id(record, "done_toggle") + "\">"
    141:       if record.done == 'Y'
    142:         title = 'Click to mark this record \'todo\''
    143:         html4checkbox = "<input type=checkbox checked>"
    144:       else
    145:         title = 'Check to mark this record \'done\''
    146:         html4checkbox = "<input type=checkbox>"
    147:       end
    148:       if  !session["user"] || !admin?
    149:         html << html4checkbox.gsub('type=checkbox', 'type=checkbox disabled=disabled')
    150:       else
    151:         html << link_to_remote(html4checkbox, :update => div_id(record, 'done_toggle'), :url => { :controller => 'review', :action => "toggle_done", :id => record.id, :class_name => class_name}, :title => title)
    152:       end
    153:       html << "</span>"
    154:     end.join("\n")
    155:   end

link_to_notification_toggle(page, notification_type, user = session['user'])

Helper link_to_notification_toggle

[Source]

         # File app/helpers/application_helper.rb, line 95
     95:   def link_to_notification_toggle(page, notification_type, user = session['user'])
     96:     returning html = [] do
     97:       notification = Notification.find(:first, :conditions => ["user_id=? and page_id=? and notification_type=?", user.id, page.id, notification_type])
     98:       if session['user'] && (mine?(user) || cadmin?)
     99:         div_id = "notification_" + page.id.to_s + "_" + notification_type
    100:         html << "<span id=\"" + div_id + "\">"
    101:         txt = "<input type=checkbox>notify me of new comments and changes"
    102:         txt = "<input type=checkbox checked>notify me of new comments and changes" if notification
    103:         html << link_to_remote(txt, :update => div_id, :url => {:controller => "users", :action => "notification", :page_id => page.id, :site_id => page.site.id,:user_id => user.id, :notification_type=> notification_type}, :method => 'post')
    104:         html << "</span>"
    105:       else
    106:         html << "<input type=checkbox #{'checked' if notification} DISABLED>notify me of new comments and changes"
    107:       end
    108:     end.join("\n")
    109:   end

link_to_page(page)

Link To for a Page

[Source]

        # File app/helpers/application_helper.rb, line 90
    90:   def link_to_page(page)
    91:       link_to(page.presentation_name + ' ' + image_tag("link.gif",:border => 0,:title => "Activate page \"#{page.presentation_name}\" in site \"#{page.site.title}\""), page.url)
    92:   end

link_to_reviewer(record)

Helper link_to_reviewer to set the reviewer. See ReviewController.

[Source]

         # File app/helpers/application_helper.rb, line 158
    158:     def link_to_reviewer(record)
    159:       returning url = [] do
    160:         url << "<span id=\"" + div_id(record, "reviewer") + "\">"
    161:         if  !session["user"]
    162:           if  record.reviewer_id != nil
    163:             url << link_to_user(record.reviewer)
    164:           end
    165:         else
    166:           if  record.reviewer_id == nil
    167:             if  admin?
    168:               url << link_to_remote("_______", :update => div_id(record, "reviewer"), :url => { :controller => 'review', :action => 'assign', :id => record.id, :class_name => record.class} )
    169:             else
    170:               url << ""
    171:             end
    172:           else
    173:               url << link_to_remote(record.reviewer.name, :update => div_id(record, "reviewer"), :url => { :controller => 'review', :action => 'assign', :id => record.id, :class_name => record.class} )
    174:           end
    175:           url << "</span> "
    176:         end
    177:       end.join("\n")
    178:     end

link_to_site(site)

Helper for a Site

[Source]

         # File app/helpers/application_helper.rb, line 229
    229:   def link_to_site(site)
    230:     img = "link.gif"
    231:     img = "link_gs.gif" if !site.wiki?
    232:     ttl = site.title
    233:     ttl = site.title + ' (OBSOLETE)' unless site.obsolete_on.nil?
    234:     link = link_to(ttl,:controller => 'sites',:action => 'description',:id => site.id) #if !admin?
    235:     link += ' ' + link_to(image_tag(img,:border => 0,:title => "Activate site \"#{site.title}\""), site.url, :title => "Activate site \"#{site.title}\"", :popup => true)
    236:     if  site.type == 'BaselineProcess'
    237:       link += ' ' + link_to(image_tag("csv.gif", :border => 0, :title => "Download content information as CSV"), {:controller => "sites", :action => "csv", :id => site.id}, :method => :post )
    238:     end
    239:     return link
    240:   end

link_to_user(user)

link_to helper method for a User

[Source]

         # File app/helpers/application_helper.rb, line 243
    243:   def link_to_user(user)
    244:     link_to(user.name,:controller => 'users',:action => 'show',:id => user.id) + image_tag("user" + user.admin + '.png', :border => 0, :title => "")
    245:   end

link_to_version(version,urlprefix)

link_to helper method for a Version. Renders a link with a given prefix (often "version") with possibly a lot of clickable images displaying status

[Source]

         # File app/helpers/application_helper.rb, line 181
    181:   def link_to_version(version,urlprefix)
    182:     returning link = [] do
    183:       # TODO below incorrect
    184:       urlprefix = 'CHECKOUT' if version.version.nil?
    185:       link << link_to(urlprefix + " " + version.version.to_s,:controller => 'versions',:action => 'show',:id => version.id)
    186:       if  !version.version_id
    187:       else
    188:         source_version = version.source_version
    189:         if  version.wiki_id != source_version.wiki_id
    190:           from_site = source_version.wiki
    191:           to_site = version.wiki
    192:           link << link_to(image_tag('site.gif', :border => 0,  :title => 'Based on version ' + source_version.version.to_s + " from site " + from_site.title) ,:controller => 'versions',:action => 'show',:id => source_version.id)
    193:         else
    194:           if version.page_id != source_version.page_id
    195:             base_page = source_version.page
    196:             link << link_to(image_tag('new.png', :border => 0, :title => 'New page based on  ' + source_version.page.presentation_name + " version " + source_version.version.to_s) ,:controller => 'versions',:action => 'show',:id => source_version.id)
    197:           else
    198:             if  version.version != source_version.version + 1
    199:               link <<  " (based on "
    200:               link << link_to(" version " + source_version.version.to_s,:controller => 'versions',:action => 'show',:id => source_version.id)
    201:               link <<  ")"
    202:             end
    203:           end
    204:         end
    205:       end
    206:       if version.current
    207:         link << image_tag('harvest.gif', :title => 'This version is the current version')
    208:       end
    209:       checkout = version.checkout
    210:       if  checkout
    211:         user = checkout.user
    212:         link << link_to(image_tag('checkout.gif', :border => 0, :title =>'Version is checked-out by ' + user.name ),:controller => 'versions',:action => 'show',:id => version.id)
    213:         link << " "
    214:         if user == session['user'] || cadmin?
    215:           link << link_to(image_tag('edit.gif', :border => 0, :title =>'Version is checked-out by you. Click to continue editing.' ),:controller => 'pages',:action => 'edit',:checkout_id => checkout.id)
    216:         end
    217:       end
    218:       link << link_to(image_tag('compare.gif', :border => 0, :title =>'Compare with previous version' ),:controller => 'versions', :action => 'diff',:id => version)
    219:       link << link_to(image_tag('txt.gif', :border => 0,  :title =>'View as plain text' ), {:controller => 'versions',:action => 'text',:id => version})
    220:     end.join("\n")
    221:   end

link_to_version2(version)

Helper for a Version

[Source]

         # File app/helpers/application_helper.rb, line 224
    224:   def link_to_version2(version)
    225:     link_to_page(version.page) + ' ' + link_to_version(version,'version')
    226:   end

links_to_pages(pages)

helper method for a displaying navigation links to first, next, previous, last pages to use when displaying records in pages. See preserving parameters [64.233.183.104/search?q=cache:VZkWDCGLNBIJ:wiki.rubyonrails.com/rails/show/HowtoPagination+pagination+how+to+ruby+on+rails&hl=nl&gl=nl&ct=clnk&cd=4]

[Source]

         # File app/helpers/application_helper.rb, line 259
    259:   def links_to_pages(pages)
    260:     if pages.length > 1
    261:       returning link = [] do
    262:         link << '<p>'
    263:       link << link_to(image_tag('first_page.png', :border => 0, :align=>"middle", :title => "First Page"), {:params => params.merge(:page => 1)} ) if pages.current.previous
    264:       link << image_tag('first_page_disabled.png', :border => 0, :align=>"middle", :title => "First Page")  if !pages.current.previous
    265:       link << link_to(image_tag('previous_page.png', :border => 0, :align=>"middle", :title => "Previous Page"), {:params => params.merge(:page => pages.current.previous)}) if pages.current.previous
    266:       link << image_tag('previous_page_disabled.png', :border => 0, :align=>"middle", :title => "Previous Page")  if !pages.current.previous
    267:       link << "<small>[" + pages.current.number.to_s + "/" + pages.length.to_s + "]</small>"
    268:       link << link_to(image_tag('next_page.png', :border => 0, :align=>"middle", :title => "Next Page"),  {:params => params.merge(:page => pages.current.next)}) if pages.current.next
    269:       link << image_tag('next_page_disabled.png', :border => 0, :align=>"middle", :title => "Next Page")  if !pages.current.next
    270:       link << link_to(image_tag('last_page.png', :border => 0, :align=>"middle", :title => "Last Page"), {:params => params.merge( :page => pages.last)}) if pages.current.next
    271:       link << image_tag('last_page_disabled.png', :border => 0, :align=>"middle", :title => "Last Page")  if !pages.current.next
    272:       link << '</p>'
    273:       end.join("\n")
    274:     end
    275:   end

menulink_to(*args)

TODO a better name for this method

[Source]

        # File app/helpers/application_helper.rb, line 39
    39:   def menulink_to(*args)
    40:     logger.debug("Creating menulink #{args.inspect}, #{params[:action]}")
    41:     current = @current || params[:action].capitalize
    42:     s=' class="current"' if args[0].downcase == current.downcase
    43:     if current == 'Edit'
    44:       txt = "Are you sure? By navigating away from the editor any unsaved changes will be lost."
    45:       if args.size == 3
    46:         args.last[:confirm] = txt
    47:       else
    48:         args << {:confirm => txt}
    49:       end
    50:     end
    51:     args[0] = "<span>#{args[0]}</span>"
    52:     "<li#{s}>" + link_to(*args) + '</li>'
    53:   end

tabular_form_for(name, object = nil, options = nil, &proc)

[Source]

        # File app/helpers/application_helper.rb, line 69
    69:   def tabular_form_for(name, object = nil, options = nil, &proc)
    70:     if @table_heading
    71:       concat("<div>#{@table_heading}</div>", proc.binding)
    72:     else
    73:       concat("<div>#{name.to_s.humanize}</div>", proc.binding)
    74:     end
    75:     concat("<div class=\"sectionContent\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"sectionTable\"><tr valign=\"top\"><td class=\"sectionTableCell\"><table>",
    76:     proc.binding)
    77:     form_for(name,
    78:              object,
    79:      (options||{}).merge(:builder => TabularFormBuilder),
    80:     &proc)
    81:     concat("</table></td></tr></table></div>", proc.binding)
    82:   end

tinymce(theme = 'simple')

Helper tinymce in your view to render textarea‘s as TinyMCE textarea‘s

[Source]

        # File app/helpers/application_helper.rb, line 85
    85:   def tinymce(theme = 'simple')
    86:     @tinymce = theme
    87:   end

[Validate]