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.

user_preference.rb 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class UserPreference < ActiveRecord::Base
  18. belongs_to :user
  19. serialize :others
  20. attr_protected :others, :user_id
  21. before_save :set_others_hash
  22. def initialize(attributes=nil, *args)
  23. super
  24. self.others ||= {}
  25. end
  26. def set_others_hash
  27. self.others ||= {}
  28. end
  29. def [](attr_name)
  30. if attribute_present? attr_name
  31. super
  32. else
  33. others ? others[attr_name] : nil
  34. end
  35. end
  36. def []=(attr_name, value)
  37. if attribute_present? attr_name
  38. super
  39. else
  40. h = (read_attribute(:others) || {}).dup
  41. h.update(attr_name => value)
  42. write_attribute(:others, h)
  43. value
  44. end
  45. end
  46. def comments_sorting; self[:comments_sorting] end
  47. def comments_sorting=(order); self[:comments_sorting]=order end
  48. def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end
  49. def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end
  50. end