OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/helpers/journals_helper.rb

134 lines
4.9 KiB

#-- encoding: UTF-8
#-- copyright
# ChiliProject is a project management system.
#
# Copyright (C) 2010-2011 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
module JournalsHelper
# unloadable
include ApplicationHelper
include ERB::Util
include ActionView::Helpers::TagHelper
def self.included(base)
base.class_eval do
if respond_to? :before_filter
before_filter :find_optional_journal, :only => [:edit]
end
end
end
def render_journal(model, journal, options = {})
return "" if journal.initial?
journal_content = render_journal_details(journal, :label_updated_time_by, model, options)
content_tag "div", journal_content, { :id => "change-#{journal.id}", :class => journal.css_classes }
end
# This renders a journal entry with a header and details
def render_journal_details(journal, header_label = :label_updated_time_by, model=nil, options={})
header = <<-HTML
<div class="profile-wrap">
#{avatar(journal.user, :size => "40")}
</div>
<h4>
<div class="journal-link" style="float:right;">#{link_to "##{journal.anchor}", :anchor => "note-#{journal.anchor}"}</div>
#{authoring journal.created_at, journal.user, :label => header_label}
#{content_tag('a', '', :name => "note-#{journal.anchor}")}
</h4>
HTML
if journal.details.any?
details = content_tag "ul", :class => "details journal-attributes" do
journal.details.collect do |detail|
if d = journal.render_detail(detail, :cache => options[:cache]).html_safe
content_tag("li", d)
end
end.compact.join(' ').html_safe
end
end
notes = journal.notes.blank? ?
'' :
render_notes(model, journal, options)
content_tag("div", "#{header}#{details}#{notes}".html_safe, :id => "change-#{journal.id}", :class => "journal")
end
def render_notes(model, journal, options={})
controller = model.class.name.downcase.pluralize
action = 'edit'
reply_links = authorize_for(controller, action)
if User.current.logged?
editable = User.current.allowed_to?(options[:edit_permission], journal.project) if options[:edit_permission]
if journal.user == User.current && options[:edit_own_permission]
editable ||= User.current.allowed_to?(options[:edit_own_permission], journal.project)
end
end
unless journal.notes.blank?
links = [].tap do |l|
if reply_links
Merge remote-tracking branch 'openproject/master' into feature/rails3 Conflicts: app/assets/images/add.png app/assets/images/arrow-down-2.png app/assets/images/arrow-down-3.png app/assets/images/arrow-down-grey.png app/assets/images/arrow-down-white.png app/assets/images/arrow-up-white.png app/assets/images/arrow_breadcrumb.png app/assets/images/arrow_collapsed.png app/assets/images/arrow_down.png app/assets/images/arrow_expanded.png app/assets/images/arrow_grey_top_navigation.png app/assets/images/arrow_left_darkred.png app/assets/images/arrow_right_darkred.png app/assets/images/arrow_white_top_navigation.png app/assets/images/background_active_button.png app/assets/images/background_header.png app/assets/images/background_suche.png app/assets/images/background_top_navigation.png app/assets/images/block.png app/assets/images/clock.png app/assets/images/close_hl.png app/assets/images/comment.png app/assets/images/database_key.png app/assets/images/disk.png app/assets/images/dot-blue.png app/assets/images/exclamation.png app/assets/images/false.png app/assets/images/fav_off.png app/assets/images/gradient-down.png app/assets/images/icon_help.png app/assets/images/icon_help_grey.png app/assets/images/icon_home.png app/assets/images/icon_home_grey.png app/assets/images/lightning.png app/assets/images/logo.png app/assets/images/logo_chiliproject.png app/assets/images/macFFBgHack.png app/assets/images/message.png app/assets/images/pdf.png app/assets/images/pencil.png app/assets/images/plugin.png app/assets/images/projects.png app/assets/images/refresh.png app/assets/images/reload.png app/assets/images/report.png app/assets/images/selected-gradient.jpg app/assets/images/shadow-down.png app/assets/images/speech-blue.png app/assets/images/speech-white.png app/assets/images/star.png app/assets/images/tag.png app/assets/images/task_parent_end.png app/assets/images/text_list_bullets.png app/assets/images/textfield.png app/assets/images/ticket_go.png app/assets/images/time_add.png app/assets/images/toggle_check.png app/assets/images/tr-hover.png app/assets/images/trenner_top_navigation.png app/assets/images/true.png app/assets/images/unlock.png app/assets/images/vcard.png app/assets/images/wiki_styles/tip.png app/assets/stylesheets/default/application.css.erb app/helpers/journals_helper.rb app/helpers/watchers_helper.rb app/models/issue.rb app/models/wiki_menu_item.rb app/views/messages/show.html.erb config/database.yml.example public/images/close_hl.png public/images/close_hover.png test/unit/issue_nested_set_test.rb
12 years ago
l << link_to(image_tag('quote.png', :alt => l(:button_quote), :title => l(:button_quote)),
{ :controller => controller,
:action => action,
:id => model,
:journal_id => journal },
:method => :get,
:remote => true)
end
if editable
13 years ago
l << link_to_in_place_notes_editor(image_tag('edit.png', :alt => l(:button_edit), :title => l(:button_edit)), "journal-#{journal.id}-notes",
{ :controller => 'journals', :action => 'edit', :id => journal },
:title => l(:button_edit))
end
end
end
content = ''
content << content_tag('div', links.join(' '),{ :class => 'contextual' }, false) unless links.empty?
content << textilizable(journal, :notes)
css_classes = "wiki"
css_classes << " editable" if editable
content_tag('div', content, { :id => "journal-#{journal.id}-notes", :class => css_classes }, false)
end
def link_to_in_place_notes_editor(text, field_id, url, options={})
onclick = "new Ajax.Request('#{url_for(url)}', {asynchronous:true, evalScripts:true, method:'get'}); return false;"
link_to text, '#', options.merge(:onclick => onclick)
end
# This may conveniently be used by controllers to find journals referred to in the current request
def find_optional_journal
@journal = Journal.find_by_id(params[:journal_id])
end
def render_reply(journal)
user = journal.user
text = journal.notes
# Replaces pre blocks with [...]
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
render(:update) do |page|
page << "$('notes').value = \"#{escape_javascript content}\";"
page.show 'update'
page << "Form.Element.focus('notes');"
page << "Element.scrollTo('update');"
page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
end
end
end