To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / plugins / redmine_tags / lib / redmine_tags / hooks / model_issue_hook.rb @ 1361:7c0909052511
History | View | Annotate | Download (2.36 KB)
| 1 |
# This file is a part of redmine_tags
|
|---|---|
| 2 |
# redMine plugin, that adds tagging support.
|
| 3 |
#
|
| 4 |
# Copyright (c) 2010 Eric Davis
|
| 5 |
# Copyright (c) 2010 Aleksey V Zapparov AKA ixti
|
| 6 |
#
|
| 7 |
# redmine_tags is free software: you can redistribute it and/or modify
|
| 8 |
# it under the terms of the GNU General Public License as published by
|
| 9 |
# the Free Software Foundation, either version 3 of the License, or
|
| 10 |
# (at your option) any later version.
|
| 11 |
#
|
| 12 |
# redmine_tags is distributed in the hope that it will be useful,
|
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
# GNU General Public License for more details.
|
| 16 |
#
|
| 17 |
# You should have received a copy of the GNU General Public License
|
| 18 |
# along with redmine_tags. If not, see <http://www.gnu.org/licenses/>.
|
| 19 |
|
| 20 |
module RedmineTags |
| 21 |
module Hooks |
| 22 |
class ModelIssueHook < Redmine::Hook::ViewListener |
| 23 |
def controller_issues_edit_before_save(context={}) |
| 24 |
save_tags_to_issue(context, true)
|
| 25 |
end
|
| 26 |
|
| 27 |
def controller_issues_bulk_edit_before_save(context={}) |
| 28 |
save_tags_to_issue(context, true)
|
| 29 |
end
|
| 30 |
|
| 31 |
# Issue has an after_save method that calls reload (update_nested_set_attributes)
|
| 32 |
# This makes it impossible for a new record to get a tag_list, it's
|
| 33 |
# cleared on reload. So instead, hook in after the Issue#save to update
|
| 34 |
# this issue's tag_list and call #save ourselves.
|
| 35 |
def controller_issues_new_after_save(context={}) |
| 36 |
save_tags_to_issue(context, false)
|
| 37 |
context[:issue].save
|
| 38 |
end
|
| 39 |
|
| 40 |
def save_tags_to_issue(context, create_journal) |
| 41 |
params = context[:params]
|
| 42 |
|
| 43 |
if params && params[:issue] && !params[:issue][:tag_list].nil? |
| 44 |
old_tags = context[:issue].tag_list.to_s
|
| 45 |
context[:issue].tag_list = params[:issue][:tag_list] |
| 46 |
new_tags = context[:issue].tag_list.to_s
|
| 47 |
|
| 48 |
if create_journal and not (old_tags == new_tags || context[:issue].current_journal.blank?) |
| 49 |
context[:issue].current_journal.details << JournalDetail.new(:property => 'attr', |
| 50 |
:prop_key => 'tag_list', |
| 51 |
:old_value => old_tags,
|
| 52 |
:value => new_tags)
|
| 53 |
end
|
| 54 |
end
|
| 55 |
end
|
| 56 |
end
|
| 57 |
end
|
| 58 |
end
|