Revision 1246:d375687d09b5 plugins

View differences:

plugins/redmine_tags/lib/redmine_tags/hooks/model_project_hook.rb
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 ModelProjectHook < Redmine::Hook::ViewListener
23
      def controller_project_before_save(context={})
24
        save_tags_to_project(context, true)
25
      end
26

  
27
      # Issue has an after_save method that calls reload (update_nested_set_attributes)
28
      # This makes it impossible for a new record to get a tag_list, it's
29
      # cleared on reload. So instead, hook in after the Issue#save to update
30
      # this issue's tag_list and call #save ourselves.
31
      def controller_projects_before_save(context={})
32
        save_tags_to_project(context, false)
33
        context[:project].save
34
      end
35

  
36
      def save_tags_to_project(context, create_journal)
37
        params = context[:params]
38

  
39
   #     if params && params[:issue] && !params[:issue][:tag_list].nil?
40
   #       old_tags = context[:issue].tag_list.to_s
41
   #       context[:issue].tag_list = params[:issue][:tag_list]
42
   #       new_tags = context[:issue].tag_list.to_s
43
   #
44
   #       if create_journal and not (old_tags == new_tags || context[:issue].current_journal.blank?)
45
   #         context[:issue].current_journal.details << JournalDetail.new(:property => 'attr',
46
   #                                                                      :prop_key => 'tag_list',
47
   #                                                                      :old_value => old_tags,
48
   #                                                                      :value => new_tags)
49
   #       end
50
   #     end
51
      end
52
    end
53
  end
54
end

Also available in: Unified diff