Module | DocumentHelper
In: | app/helpers/document_helper.rb

-*- coding: utf-8 -*- 関連文書機能のヘルパーを与える。

### Methods

check_box_to_delete document_inner_url document_product_form_content document_url hidden_relatable link_to_cancel link_to_close_popup product_selector submit_to_create submit_to_delete submit_to_select summary td_check_box_for_mutual

### Public Instance methods

check_box_to_delete(document)

削除するための check box を返す。

[Source]

         # File app/helpers/document_helper.rb, line 109
    109:   def check_box_to_delete(document)
    110:     name = document.new_record? ? "deleted[#{document.target_type}_#{document.target_id}]" : "deleted[#{document.id}]"
    111:     check_box_tag(name, 1, false)
    112:   end

document_inner_url(x)

関連文書のリンクのための URL を返す。

[Source]

         # File app/helpers/document_helper.rb, line 99
     99:   def document_inner_url(x)
    100:     if x.is_a?(Document)
    101:       options = x.url_options_for(@relatable)
    102:     else
    103:       options = x.url_options_as_document_node
    104:     end
    105:     url_for(options.merge(:controller => "product", :action => "show_only"))
    106:   end

document_product_form_content()

関連付ける機能を選択するための一覧を返す。

[Source]

        # File app/helpers/document_helper.rb, line 20
    20:   def document_product_form_content
    21:     content = []
    22:     content << hidden_relatable(:type, :top)
    23:     content << hidden_relatable(:id, :top)
    24:     content << hidden_relatable(:product_id, :top)
    25:     content << product_selector
    26:     unless params[:target_product_id].blank?
    27:       if product = Product.find_by_id(params[:target_product_id].to_i)
    28:         if product.visible? && product.document?
    29:           content << submit_to_select
    30:           content << submit_to_create if product.modifiable?
    31:         end
    32:       end
    33:     end
    34:     return content.join("")
    35:   end

document_url(x)

関連文書のリンクのための URL を返す。

[Source]

        # File app/helpers/document_helper.rb, line 89
    89:   def document_url(x)
    90:     if x.is_a?(Document)
    91:       options = x.fragment_options_for(@relatable)
    92:     else
    93:       options = x.fragment_options_as_document_node
    94:     end
    95:     url_for(:action => "view", :fragment => URI.encode(fragment_for(options)))
    96:   end

hidden_relatable(name, x)

関連付け対象を埋め込むタグを返す。

[Source]

       # File app/helpers/document_helper.rb, line 5
    5:   def hidden_relatable(name, x)
    6:     hidden_field_tag name, params[name], {:id => "relatable_#{name}_#{x}"}
    7:   end

link_to_cancel()

取り消しのリンクを返す。

[Source]

        # File app/helpers/document_helper.rb, line 15
    15:   def link_to_cancel
    16:     link_with_effect s_("button|Cancel"), "cancel"
    17:   end

link_to_close_popup()

ポップアップを閉じるリンクを返す。

[Source]

        # File app/helpers/document_helper.rb, line 10
    10:   def link_to_close_popup
    11:     link_with_effect s_("button|Close"), "summary"
    12:   end

product_selector()

関連付ける機能を選択するための select box を返す。

[Source]

        # File app/helpers/document_helper.rb, line 38
    38:   def product_selector
    39:     id = "document_product_id"
    40:     options = Product.find(:all).select {|p| p.visible? && p.document?}.map {|p| [p.name, p.id]}
    41:     options.unshift([h(s_("Document|select product for new document")), nil])
    42:     result = select_tag(:target_product_id,
    43:                         options_for_select(options, params[:target_product_id].to_i),
    44:                         :id => id,
    45:                         :onchange => "['document_product_select', 'document_product_create'].each(function(x) {(e=$(x))&&e.disable();});$('view_dp').hide();")
    46:     result += observe_field(id,
    47:                             :with => "Form.serialize('document_product')",
    48:                             :update => "document_product",
    49:                             :complete => visual_effect(:highlight, id, :queue => {
    50:                                                          :scope => "document",
    51:                                                          :limit => 2,
    52:                                                          :position => "end"
    53:                                                        }),
    54:                             :url => {:action => "product"})
    55:     return result
    56:   end

submit_to_create()

新規文書作成画面を表示するための submit ボタンを返す。

[Source]

        # File app/helpers/document_helper.rb, line 69
    69:   def submit_to_create
    70:     submit_to_remote("create",
    71:                      h(s_("button|New")),
    72:                      :update => "view_dp",
    73:                      :complete => "$('view_dp').show();",
    74:                      :url => {:controller => "product", :action => "create_document", :product_id => params[:target_product_id], :relatable_product_id => params[:product_id]},
    75:                      :html => {:class => "button", :id => "document_product_create"})
    76:   end

submit_to_delete()

削除を実行するための submit ボタンを返す。

[Source]

        # File app/helpers/document_helper.rb, line 79
    79:   def submit_to_delete
    80:     submit_to_remote("delete",
    81:                      h(s_("Document|delete")),
    82:                      :update => "document_table_base",
    83:                      :complete => visual_effect(:highlight, "document_table", :queue => {:scope => "document", :limit => 2, :position => "end"}),
    84:                      :url => {:action => "delete", :product_id => @relatable_product.id},
    85:                      :html => {:class => "button"})
    86:   end

submit_to_select()

関連文書選択画面を表示するための submit ボタンを返す。

[Source]

        # File app/helpers/document_helper.rb, line 59
    59:   def submit_to_select
    60:     submit_to_remote("select",
    61:                      h(s_("button|Select")),
    62:                      :update => "view_dp",
    63:                      :complete => "$('view_dp').show();",
    64:                      :url => {:controller => "product", :action => "select_document", :product_id => params[:target_product_id], :relatable_product_id => params[:product_id]},
    65:                      :html => {:class => "button", :id => "document_product_select"})
    66:   end

summary()

関連文書のサマリを返す。

[Source]

         # File app/helpers/document_helper.rb, line 128
    128:   def summary
    129:     result = []
    130:     if (count = @documents.size) > 0
    131:       result << ns_("Document|%{count} document related", "%{count} documents related", count) % {:count => count}
    132:     else
    133:       result << s_("Document|no document related")
    134:     end
    135:     if session[:added_documents]
    136:       if @relatable
    137:         documents = session[:added_documents].select {|a| a.relatable == @relatable}
    138:       else
    139:         documents = session[:added_documents].select {|a| a.relatable_type == params[:type] && !a.relatable_id}
    140:       end
    141:       if (count = documents.size) > 0
    142:         result << ns_("Document|%{count} document will be added", "%{count} documents will be added", count) % {:count => count}
    143:       end
    144:     end
    145:     if @relatable
    146:       if session[:deleted_documents] && (count = session[:deleted_documents].select {|a| a.relatable == @relatable || a.target == @relatable}.size) > 0
    147:         result << ns_("Document|%{count} document will be deleted", "%{count} documents will be deleted", count) % {:count => count}
    148:       end
    149:     end
    150:     s_("Document|Documents: ") + result.join(" / ")
    151:   end

td_check_box_for_mutual(document)

相互参照のための check box を返す。

[Source]

         # File app/helpers/document_helper.rb, line 115
    115:   def td_check_box_for_mutual(document)
    116:     id = document.new_record? ? "document_mutual_#{document.target_type}_#{document.target_id}" : "document_mutual_#{document.id}"
    117:     name = document.new_record? ? "mutual[#{document.target_type}_#{document.target_id}]" : "mutual[#{document.id}]"
    118:     result = check_box_tag(name, 1, document.mutual?, :id => id)
    119:     result += observe_field(id,
    120:                             :with => "Form.serialize('document_table_form')",
    121:                             :update => "document_table",
    122:                             :complete => visual_effect(:highlight, "td_#{id}", :queue => {:scope => "document", :limit => 2, :position => "end"}),
    123:                             :url => {:action => "toggle_mutual", :product_id => @relatable_product.id})
    124:     return content_tag(:td, result, :id => "td_#{id}")
    125:   end

[Validate]