Class | ProductController
In: | app/controllers/product_controller.rb
Parent: | ApplicationController

-*- coding: utf-8 -*- プロダクトの制御を行う:

- 一覧画面
- 詳細画面
- 新規作成画面
- 編集画面
- 削除画面

### Methods

add_detail create_document destroy edit index list new order_details select_document show show_only

### Constants

DEFAULT_PER_PAGE | = | 10
ALLOWED_PER_PAGE | = | [ 10, 20, 50, 100, 0, ]

### Public Instance methods

add_detail()

詳細を追加する

[Source]

         # File app/controllers/product_controller.rb, line 221
    221:   def add_detail
    222:   end

create_document()

関連文書向けに新規作成する

[Source]

         # File app/controllers/product_controller.rb, line 195
    195:   def create_document
    196:     @copying = false
    197:     view_in :document
    198:     create("create_document") do
    199:       p = {
    200:         :type => params[:type],
    201:         :product_id => params[:relatable_product_id],
    202:         :target_id => @it.id,
    203:         :target_type => @it.class.to_s,
    204:         :target_product_id => @product.id,
    205:       }
    206:       p[:id] = params[:id] unless params[:id].blank?
    207:       render :update do |page|
    208:         page << "new Ajax.Updater('document_table_base', '#{url_for(:controller => "document", :action => "select")}', {onComplete: function(){$('view_dp').innerHTML = '';}, parameters: #{p.to_json}})"
    209:       end
    210:     end
    211:   end

destroy()

削除を行う。

[Source]

         # File app/controllers/product_controller.rb, line 79
     79:   def destroy
     80:     view_in :detail
     81:     prepare_display_to :show
     82:     raise PermissionDenied, "product is not modifiable" unless @product.modifiable?
     83:     raise DisabledException, "disabled with respect to button" unless @display.button_delete?
     84:     unless request.post? && params[:id] && (params[:confirm_destroy] || request.xhr?)
     85:       begin
     86:         @it = @model_class.find(params[:id])
     87:       rescue ActiveRecord::RecordNotFound
     88:         flash[:notice] = s_("flash|notice|It has been already destroyed.")
     89:         x_close_or_redirect_to :action => "list"
     90:         return
     91:       end
     92:       # @title : same as show
     93:       @display = Object.new
     94:       def @display.method_missing(sym, *args)
     95:         return false
     96:       end
     97:       def @display.button_back?
     98:         return true
     99:       end
    100:       render :action => :confirm_destroy
    101:       return
    102:     end
    103:     begin
    104:       it = @model_class.find(params[:id])
    105:       if @product.is_a?(ProductDetailed)
    106:         @details = it.details
    107:         @details.each {|d| instance_variable_set("@details_#{d.id}", d)}
    108:       end
    109:       if with_logic(it, :destroy)
    110:         flash[:notice] = s_("flash|notice|It was successfully destroyed.")
    111:       else
    112:         flash[:warning] = s_("flash|warning|It was failed to destroy.")
    113:       end
    114:     rescue ActiveRecord::RecordNotFound
    115:       flash[:notice] = s_("flash|notice|It has been already destroyed.")
    116:       x_close_or_redirect_to :action => "list"
    117:       return
    118:     end
    119:     x_close_or_redirect_to :action => "list"
    120:   end

edit()

編集画面を表示し、編集を行う。

[Source]

         # File app/controllers/product_controller.rb, line 133
    133:   def edit
    134:     view_in :detail
    135:     prepare_display_to :edit
    136:     begin
    137:       @it = @model_class.find(params[:id])
    138:     rescue ActiveRecord::RecordNotFound
    139:       flash[:notice] = s_("flash|notice|It has been already destroyed.")
    140:       x_close_or_redirect_to :action => "list"
    141:       return
    142:     end
    143:
    144:     return if use_picker
    145:
    146:     if @product.is_a?(ProductDetailed)
    147:       @details = @it.details
    148:       @details.each {|d| instance_variable_set("@details_#{d.id}", d)}
    149:       begin
    150:         @old_details = ActiveSupport::JSON.decode(params[:old_details] || "[]")
    151:       rescue ActiveSupport::JSON::ParseError
    152:         @old_details = []
    153:       end
    154:       set_new_details
    155:       set_order_details
    156:     end
    157:
    158:     if params[:it]
    159:       set_attributes
    160:       if request.post? && params[:update]
    161:         # update
    162:         begin
    163:           if with_logic(@it, :update)
    164:             flash[:notice] = s_("flash|notice|It was successfully updated.")
    165:             x_close_or_redirect_to :action => "list"
    166:             return
    167:           end
    168:         rescue ActiveRecord::StaleObjectError
    169:           @stale_object_error = true
    170:         end
    171:       end
    172:     end
    173:
    174:     render :action => "form"
    175:   end

index()

`list` へリダイレクトする。

[Source]

        # File app/controllers/product_controller.rb, line 10
    10:   def index
    11:     redirect_to :action => :list
    12:   end

list()

一覧画面を表示する。

[Source]

        # File app/controllers/product_controller.rb, line 15
    15:   def list
    16:     view_in :m
    17:     prepare_display_to_list
    18:     options = @display.query_options
    19:     setup_list_id
    20:     setup_per_page(@model_class, options) do |default_per_page|
    21:       sync_fragment("m", :per, default_per_page)
    22:     end
    23:     sync_fragment("m", :page, 1)
    24:     @pages, @things = paginate(@model_class, options)
    25:     @header_per_line = User.list_header_per_line
    26:   end

new()

新規作成画面を表示し、新規作成を行う。

[Source]

         # File app/controllers/product_controller.rb, line 123
    123:   def   newnewnew
    124:     @copying = !!params[:id]
    125:     view_in :detail
    126:     create("form") do
    127:       flash[:notice] = s_("flash|notice|It was successfully created.")
    128:       x_close_or_redirect_to :action => "list"
    129:     end
    130:   end

order_details()

詳細を並び替える。

[Source]

         # File app/controllers/product_controller.rb, line 214
    214:   def order_details
    215:     render :update do |page|
    216:       page[:order_details].value = params[:details_table_body].to_json
    217:     end
    218:   end

select_document()

関連文書を選択するための一覧を表示する。

[Source]

         # File app/controllers/product_controller.rb, line 178
    178:   def select_document
    179:     view_in :document
    180:     prepare_display_to_list
    181:     options = @display.query_options
    182:     setup_per_page(@model_class, options) do |default_per_page|
    183:       params[:per] ||= default_per_page
    184:     end
    185:     @pages, @things = paginate(@model_class, options)
    186:     @header_per_line = User.list_header_per_line
    187:     begin
    188:       @relatable = params[:type].constantize.find(params[:id])
    189:     rescue
    190:       @relatable = nil
    191:     end
    192:   end

show()

詳細画面を表示する。

[Source]

        # File app/controllers/product_controller.rb, line 29
    29:   def show
    30:     view_in :detail
    31:     prepare_display_to :show
    32:     begin
    33:       @it = @model_class.find(params[:id], :readonly => true)
    34:     rescue ActiveRecord::RecordNotFound
    35:       flash[:notice] = s_("flash|notice|It does not exists.")
    36:       x_close_or_redirect_to :action => "list"
    37:       return
    38:     end
    39:     if @product.is_a?(ProductDetailed)
    40:       @details = @it.details
    41:     end
    42:
    43:     @id_suffix = "#{@it.id}of#{@product.id}"
    44:
    45:     return if use_picker
    46:
    47:     if @display.mail?
    48:       @disable_mailsend = true
    49:       if params[:mail] && !params[:mail][:recipients].blank?
    50:         @disable_mailsend = false
    51:       end
    52:       if !@disable_mailsend && params[:mailsend]
    53:         mail_to_queue(@it, true)
    54:       end
    55:     end
    56:   end

show_only()

詳細画面(関連文書用)を表示する。

[Source]

        # File app/controllers/product_controller.rb, line 59
    59:   def show_only
    60:     @parent_view = "view_detail"
    61:     # @current_view,@sub_view は後で設定
    62:     prepare_display_to :show
    63:     begin
    64:       @it = @model_class.find(params[:id], :readonly => true)
    65:     rescue ActiveRecord::RecordNotFound
    66:       flash[:notice] = s_("flash|notice|It does not exists.")
    67:       x_close_or_redirect_to :action => "list"
    68:       return
    69:     end
    70:     if @product.is_a?(ProductDetailed)
    71:       @details = @it.details
    72:     end
    73:     @id_suffix = "#{@it.id}of#{@product.id}"
    74:     @current_view = "view_detail#{@it.id}of#{@product.id}"
    75:     @sub_view = "view_subofdetail#{@it.id}of#{@product.id}"
    76:   end

[Validate]