Module: Mokio::Concerns::Models::Common
- Extended by:
- ActiveSupport::Concern
- Included in:
- ModulePosition
- Defined in:
- lib/mokio/concerns/models/common.rb
Overview
Common module add’s methods commonly used in our models
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DATE_ATTRIBUTES =
Constant with [display_from display_to updated_at created_at] attributes. We dynamicly create additional date_atribute_view methods from this one
%w(display_from display_to updated_at created_at)
Instance Method Summary collapse
-
#active_view ⇒ Object
Output for active parameter, used in CommonController#index.
-
#always_editable_fields ⇒ Object
Table of always editable fields.
-
#cloneable? ⇒ Boolean
Is object cloneable?.
- #display_editable_field?(field_name) ⇒ Boolean
-
#displayed? ⇒ Boolean
Is object selected as displayed?.
-
#lang_id_view ⇒ Object
Output for lang_id parameter, used in CommonController#index.
- #some_editable ⇒ Object
Instance Method Details
#active_view ⇒ Object
Output for active parameter, used in CommonController#index
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mokio/concerns/models/common.rb', line 53 def active_view "<div class=\"activebutton\"> <input type=\"checkbox\" #{"checked=\"checked\"" if self.active} class=\"activebtn switch-small\" data-on=\"success\" data-off=\"danger\" data-on-label=\"<i class='icomoon-icon-checkmark white'></i>\" data-off-label=\"<i class='icomoon-icon-cancel-3 white'></i>\" > </div>" .html_safe end |
#always_editable_fields ⇒ Object
Table of always editable fields
91 92 93 |
# File 'lib/mokio/concerns/models/common.rb', line 91 def always_editable_fields %w(active seq visible always_displayed) end |
#cloneable? ⇒ Boolean
Is object cloneable?
110 111 112 |
# File 'lib/mokio/concerns/models/common.rb', line 110 def cloneable? true end |
#display_editable_field?(field_name) ⇒ Boolean
103 104 105 |
# File 'lib/mokio/concerns/models/common.rb', line 103 def display_editable_field?(field_name) editable || always_editable_fields.include?(field_name) end |
#displayed? ⇒ Boolean
Is object selected as displayed?
84 85 86 |
# File 'lib/mokio/concerns/models/common.rb', line 84 def displayed? (((!display_from.nil? && display_from <= Date.today ) || display_from.nil?) && ((!display_to.nil? && display_to >= Date.today ) || display_to.nil?)) end |
#lang_id_view ⇒ Object
Output for lang_id parameter, used in CommonController#index
76 77 78 79 |
# File 'lib/mokio/concerns/models/common.rb', line 76 def lang_id_view return Mokio::Lang.find(self.lang_id).name unless self.lang_id.nil? return I18n.t('backend.all') if self.lang_id.nil? end |
#some_editable ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/mokio/concerns/models/common.rb', line 95 def some_editable if !self.editable && !self.changed.nil? (self.changed.to_set - self.always_editable_fields.to_set).each do |field| errors.add(field.to_sym, "#{I18n.t('activerecord.errors.editable.not_permitted')}") end end end |