# Methods added to this helper will be available to all templates in the # application. module ApplicationHelper include PermissionName # Displays context help. You can pass the content of the help message as the # first parameter or using template code inside a block passed to this # method. *Note*: the block is ignored if content is not # nil # # The method returns the text generated, so you can also use it inside a # <%= ... %> # # Follow some examples ... # # Passing the text as argument: # # <% help 'This your help message' %> # # Using a block: # # <% help do %> # This is the help message to be displayed. It can contain any HTML you # want: bold, italic. It can also contain calls # to any Rails helper, like <%= link_to 'home', :controller => 'home' %>. # <% end %> # # You can also pass an optional argument to force the use of textile in your # help message: # # <% help nil, :textile do %> # You can also use *textile*! # <% end %> # # or, using the return of the method: # # <%= help 'this is your help message' %> # # Formally, the type argument can be :html (i.e. no # conversion of the input) or :textile (converts the message, in # textile, into HTML). It defaults to :html. # # TODO: implement correcly the 'Help' button click def help(content = nil, type = :html, &block) @help_message_id ||= 1 help_id = "help_message_#{@help_message_id}" if content.nil? return '' if block.nil? content = capture(&block) end if type == :textile content = RedCloth.new(content).to_html end # TODO: implement this button, and add style='display: none' to the help # message DIV button = link_to_function(content_tag('span', _('Help')), "Element.show('#{help_id}')", :class => 'help_button' ) close_button = content_tag("div", link_to_function(_("Close"), "Element.hide('#{help_id}')", :class => 'close_help_button')) text = content_tag('div', button + content_tag('div', content_tag('div', content) + close_button, :class => 'help_message', :id => help_id, :style => 'display: none;'), :class => 'help_box') unless block.nil? concat(text, block.binding) end text end # alias for help(content, :textile). You can pass a block in the # same way you would do if you called help directly. def help_textile(content = nil, &block) help(content, :textile, &block) end # TODO: do something more useful here # TODO: test this helper # TODO: add an icon? # TODO: the command rake test:rcov didn't works because of this method. See what it's the problem def environment_identification content_tag('div', @environment.name, :id => 'environment_identification') end def link_to_cms(text, profile = nil, options = {}) profile ||= current_user.login link_to text, myprofile_path(:controller => 'cms', :profile => profile), options end def link_to_profile(text, profile = nil, options = {}) profile ||= current_user.login link_to text, profile_path(:profile => profile) , options end def link_to_homepage(text, profile = nil, options = {}) profile ||= current_user.login link_to text, homepage_path(:profile => profile) , options end def link_to_myprofile(text, url = {}, profile = nil, options = {}) profile ||= current_user.login link_to text, { :profile => profile, :controller => 'profile_editor' }.merge(url), options end def link_to_document(doc, text = nil) text ||= doc.title path = doc.path.split(/\//) link_to text, homepage_path(:profile => doc.profile.identifier , :page => path) end # TODO: add the actual links # TODO: test this helper def user_links links = [ ( link_to_myprofile( _('My profile') )), ( link_to_myprofile _('My Enterprises'), {:controller => 'membership_editor'} ), ( link_to(_('Admin'), { :controller => 'admin_panel' }) if current_user.person.is_admin?), ].join("\n") content_tag('span', links, :id => 'user_links') end def shortcut_header_links if logged_in? [ ( link_to_myprofile( content_tag('span', _('My profile')), {}, nil, { :id => 'icon_go_home'} ) ), # MUDAR, O ID acima deve ser no Link 'admin_panel' }, :id => 'icon_admin' if current_user.person.is_admin?), ( link_to content_tag('span', _('Logout')), { :controller => 'account', :action => 'logout'}, :id => 'icon_logout', :method => 'post'), ] else [ ( link_to content_tag('span', _('Login')), { :controller => 'account', :action => 'login' }, :id => 'icon_login' ), ] end.join(" ") end def link_if_permitted(link, permission = nil, target = nil) if permission.nil? || current_user.person.has_permission?(permission, target) link else nil end end def admin_links environment = current_user.person.environment links = [ [(link_to _('Features'), :controller => 'features'), 'edit_environment_features', environment], [(link_to _('Edit visual'), :controller => 'edit_template'), 'edit_environment_design', environment], [(link_to _('Manage categories'), :controller => 'categories'), 'manage_environment_categories', environment], [(link_to _('Manage permissions'), :controller => 'role'), 'manage_environment_roles', environment], [(link_to _('Manage validators'), :controller => 'region_validators'), 'manage_environment_validators', environment], ] end def membership_links links = [ [(link_to _('New enterprise'), :controller => 'membership_editor', :action => 'new_enterprise'),'create_enterprise_for_profile', profile], ] end def person_links links = [ [(link_to_myprofile _('Edit visual design'), {:controller => 'profile_editor', :action => 'design_editor'}, profile.identifier), 'edit_profile_design', profile], [(link_to_myprofile _('Edit profile'), {:controller => 'profile_editor'}, profile.identifier), 'edit_profile', profile], [(link_to_myprofile _('Manage content'), {:controller => 'cms'}, profile.identifier), 'post_content', profile], ] end def enterprise_links links = [ [(link_to_myprofile _('Edit visual design'), {:controller => 'profile_editor', :action => 'design_editor'}, profile.identifier), 'edit_profile_design', profile], [(link_to_myprofile _('Edit informations'), {:controller => 'profile_editor'}, profile.identifier), 'edit_profile', profile], [(link_to_myprofile _('Manage content'), {:controller => 'cms'}, profile.identifier), 'post_content', profile], # [(link_to_myprofile _('Exclude'), {:controller => 'enterprise_editor', :action => 'destroy'}, profile.identifier), 'edit_profile', profile], ] end def myprofile_links links = [ [(link_to _('Change password'), {:controller => 'account', :action => 'change_password'}), 'edit_profile', profile] ] end def design_links links = [ [(link_to _('Change template'), :controller => 'profile_editor', :action => 'design_editor_change_template')], [(link_to _('Change block theme'), :controller => 'profile_editor', :action => 'design_editor_change_theme')], [(link_to _('Change icon theme'), :controller => 'profile_editor', :action => 'design_editor_change_icon_theme')], ] end def search_box [form_tag({:controller => 'search', :action => 'index'}, :method => 'get'), design_display_button_submit('find', '', :title => _('Search')), text_field_tag( 'query', _('your search here'), :id => "input_search", :onfocus => 'javascript: if (this.value == %s) { this.value = ""; }' % _('your search here').inspect, :onblur => "javascript: if (this.value == '') { this.value = %s}" % _('your search here').inspect), '', ].join("\n") end def footer # FIXME: add some information from the environment [ content_tag('div', 'Copyright © 2007, Noosfero - Change Me!'), content_tag('div', _('%s, version %s' % [ link_to('developers', 'http://www.colivre.coop.br/Noosfero'), Noosfero::VERSION])), ].join("\n") end # returns the current profile beign viewed. # # Make sure that you use this helper method only in contexts where there # should be a current profile (i.e. while viewing some profile's pages, or the # profile info, etc), because if there is no profile an exception is thrown. def profile @profile || raise("There is no current profile") end # displays an # # Current implementation generates a