Class | DisplayToList
In: | app/models/display_to_list.rb
Parent: | Display

一覧画面のモデル

### Methods

available? default_list? generate_config_output options_to_extract options_to_order_by options_to_select private_copy query_options selected_items type_name

### Constants

BUTTON_TYPE | = | [ [N_("Display|New"), "new"], ]

### Public Instance methods

available?()

権限にしたがって利用可能かどうかを判定する。

[Source]

        # File app/models/display_to_list.rb, line 49
    49:   def available?
    50:     product.visible?
    51:   end

default_list?()

既定の一覧かどうかを判定する。

[Source]

         # File app/models/display_to_list.rb, line 148
    148:   def default_list?
    149:     default_list = DefaultList.find_by_user_id_and_product_id(User.current_id, product.id)
    150:     return default_list && id == default_list.display_id
    151:   end

generate_config_output()

適切な ConfigOutput のインスタンスを生成する。

[Source]

         # File app/models/display_to_list.rb, line 131
    131:   def generate_config_output
    132:     return config_output if config_output
    133:     user_id = User.current_id
    134:     raise "current user is expected" unless user_id
    135:     config_output = ConfigOutput.create!(:display_to_list_id => id,
    136:                                          :name => name,
    137:                                          :user_id => user_id)
    138:     items.each_with_index do |item,i|
    139:       ConfigOutputItem.create!(:config_output_id => config_output.id,
    140:                                :item_id => item.id,
    141:                                :name => item.name,
    142:                                :position => i + 1)
    143:     end
    144:     return config_output
    145:   end

options_to_extract()

画面に抽出される条件を返す。 SearchCondition も参照する。

[Source]

        # File app/models/display_to_list.rb, line 55
    55:   def options_to_extract
    56:     options = (e = extract) ? {:conditions => e} : {}
    57:     if search_condition
    58:       if e = search_condition.extract
    59:         if options[:conditions]
    60:           options[:conditions] << " AND #{e}"
    61:         else
    62:           options[:conditions] = e
    63:         end
    64:       end
    65:     end
    66:     return options
    67:   end

options_to_order_by()

画面でレコードを順序づける ORDER BY 句のハッシュを返す。

[Source]

        # File app/models/display_to_list.rb, line 70
    70:   def options_to_order_by
    71:     if search_condition
    72:       if options = search_condition.options_to_order_by
    73:         return options
    74:       end
    75:     end
    76:     orders = items.reject {|item| item.direction.blank? || item.direction =~ /none/i || item.position.blank?}
    77:     return {} if orders.empty?
    78:     orders = orders.sort {|i,j| (i.position && j.position) ? (i.position - j.position) : 0}
    79:     return {:order => orders.map(&:order).join(",")}
    80:   end

options_to_select()

画面に表示される項目の条件を返す。

[Source]

        # File app/models/display_to_list.rb, line 83
    83:   def options_to_select
    84:     column_names = ["id"]
    85:     items.each do |i|
    86:       if i.readable?
    87:         case i
    88:         when ItemProper, ItemPlural
    89:           column_names << i.column_name
    90:         when ItemPolymorphic
    91:           column_names << "#{i.column_name}_id"
    92:           column_names << "#{i.column_name}_type"
    93:         end
    94:       end
    95:     end
    96:     return {:select => column_names.join(",")}
    97:   end

private_copy()

個人利用のためのコピーを返す。

[Source]

         # File app/models/display_to_list.rb, line 116
    116:   def private_copy
    117:     user =  User.current
    118:     raise "current user is expected" unless user
    119:     display = DisplayToListPrivate.new
    120:     display.attributes = attributes
    121:     display.person_id = user.person_id
    122:     message_source = PoMessageSingular.find(name_po)
    123:     message_copy = message_source.private_copy
    124:     display.name_po = message_copy.id
    125:     display.save!
    126:     items.each {|item| item.private_copy(display.id)}
    127:     return display
    128:   end

query_options()

[Source]

         # File app/models/display_to_list.rb, line 99
     99:   def query_options
    100:     options = {}
    101:     if product.is_a?(ProductMultiple)
    102:       options[:group] = product.pivot
    103:     end
    104:     options.update(options_to_extract)
    105:     options.update(options_to_order_by)
    106:     options.update(options_to_select)
    107:     return options
    108:   end

selected_items()

選択された項目を返す。

[Source]

         # File app/models/display_to_list.rb, line 111
    111:   def selected_items
    112:     items.select(&:selected?).sort_by(&:layout)
    113:   end

type_name()

種類の名前を返す。

[Source]

        # File app/models/display_to_list.rb, line 44
    44:   def type_name
    45:     s_("Display|List")
    46:   end

[Validate]