Class | DocumentController
In: | app/controllers/document_controller.rb
Parent: | ApplicationController

関連文書機能を実装する。

### Methods

cancel delete edit product select show summary test toggle_mutual view

### Public Instance methods

cancel()

関連文書の編集を取り止める。

[Source]

        # File app/controllers/document_controller.rb, line 43
    43:   def cancel
    44:     prepare_to_edit
    45:     session[:added_documents].clear
    46:     session[:deleted_documents].clear
    47:     @documents = @relatable ? @relatable_product.documents_for(@relatable) : []
    48:     return render(:action => "summary")
    49:   end

delete()

関連文書を削除する。

[Source]

        # File app/controllers/document_controller.rb, line 20
    20:   def delete
    21:     prepare_to_edit
    22:     deleted = params[:deleted] || {}
    23:     proc = lambda do |d|
    24:       if d.new_record?
    25:         deleted.fetch("#{d.target_type}_#{d.target_id}", nil).to_i == 1
    26:       else
    27:         deleted.fetch("#{d.id}", nil).to_i == 1
    28:       end
    29:     end
    30:     session[:added_documents].delete_if(&proc)
    31:     @documents.delete_if(&proc)
    32:     deleted.each_pair do |key, value|
    33:       if key.match(/\A([0-9]+)\z/) && value.to_i == 1
    34:         if d = Document.find_by_id(key)
    35:           session[:deleted_documents] |= [d]
    36:         end
    37:       end
    38:     end
    39:     return render(:action => "select")
    40:   end

edit()

関連文書を編集する。

[Source]

        # File app/controllers/document_controller.rb, line 10
    10:   def edit
    11:     prepare_to_edit
    12:   end

product()

関連付ける機能の選択欄を表示する。

[Source]

        # File app/controllers/document_controller.rb, line 57
    57:   def product
    58:   end

select()

関連付ける文書を選択する。

[Source]

        # File app/controllers/document_controller.rb, line 61
    61:   def select
    62:     prepare_to_edit
    63:     unless @documents.find {|d| d.target_id == params[:target_id].to_i && d.target_type == params[:target_type] && d.target_product_id == params[:target_product_id].to_i}
    64:       d = Document.new(:relatable_id   => defined?(@relatable) ? @relatable.id : nil,
    65:                        :relatable_type => params[:type],
    66:                        :relatable_product_id => @relatable_product.id,
    67:                        :target_id      => params[:target_id].to_i,
    68:                        :target_type    => params[:target_type],
    69:                        :target_product_id => params[:target_product_id].to_i)
    70:       session[:added_documents].push(d)
    71:       @documents.push(d)
    72:     end
    73:   end

show()

関連文書の一覧を表示する。

[Source]

        # File app/controllers/document_controller.rb, line 15
    15:   def show
    16:     prepare
    17:   end

summary()

関連文書に関する現在のサマリを表示する。

[Source]

        # File app/controllers/document_controller.rb, line 52
    52:   def summary
    53:     prepare
    54:   end

test()

(試験用)

[Source]

        # File app/controllers/document_controller.rb, line 92
    92:   def test
    93:     prepare
    94:     @current_view = "view_m"
    95:     @sub_view = "view_de"
    96:   end

toggle_mutual()

関連付けの相互性を有効/無効にする。

[Source]

        # File app/controllers/document_controller.rb, line 76
    76:   def toggle_mutual
    77:     prepare_to_edit
    78:     m = params[:mutual] || {}
    79:     proc = lambda do |d|
    80:       if d.new_record?
    81:         d.mutual = (m.fetch("#{d.target_type}_#{d.target_id}", nil).to_i == 1)
    82:       else
    83:         d.mutual = (m.fetch("#{d.id}", nil).to_i == 1)
    84:       end
    85:     end
    86:     session[:added_documents].each(&proc)
    87:     @documents.each(&proc)
    88:     return render(:action => "select")
    89:   end

view()

関連文書の詳細を表示する。

[Source]

       # File app/controllers/document_controller.rb, line 4
    4:   def view
    5:     fragment = URI.decode(params[:fragment])
    6:     redirect_to "/##{fragment}"
    7:   end

[Validate]