Class | ProductGeneratorController |
In: |
app/controllers/product_generator_controller.rb
|
Parent: | ApplicationController |
画面生成を制御する。
画面を削除する。
# File app/controllers/product_generator_controller.rb, line 160 160: def display_destroy 161: view_in :display 162: setup_display 163: 164: unless @params[:confirm_destroy] 165: render :action => "display_edit" 166: return 167: end 168: 169: @display = Display.find(params[:id]) 170: if @display && @display.destroy 171: flash[:notice] = s_("flash|notice|Display was successfully destroyed.") 172: else 173: flash[:warning] = s_("flash|warning|Display was failed to destroy.") 174: end 175: x_redirect_to @current_view, :close, :action => "manage", :id => @product.id 176: end
画面を編集する。
# File app/controllers/product_generator_controller.rb, line 144 144: def display_edit 145: view_in :display 146: setup_display 147: unless request.post? && params[:display] 148: render 149: return 150: end 151: 152: @display.attributes = params[:display] 153: if @display.save 154: flash[:notice] = s_("flash|notice|Product was successfully updated.") 155: x_redirect_to "display", :close, :action => "manage", :id => @product.id 156: end 157: end
機能の編集を行う。
# File app/controllers/product_generator_controller.rb, line 72 72: def edit 73: view_in :product 74: @sub_view = nil 75: @product = Product.find(params[:id]) 76: unless request.post? && params[:product] 77: render :action => "product_name_form" 78: return 79: end 80: 81: @product.attributes = params[:product] 82: @product.save! 83: flash[:notice] = s_("flash|notice|Product was successfully updated.") 84: x_redirect_to "product", :close, :action => "list" 85: rescue ActiveRecord::ActiveRecordError 86: @product ||= Product.new 87: render :action => "product_name_form" 88: end
項目を編集する。
# File app/controllers/product_generator_controller.rb, line 179 179: def item_edit 180: view_in :item 181: @item = Item.find(params[:id]) 182: setup_item 183: 184: if params[:item] 185: @item.attributes = params[:item] 186: if @item.save 187: flash[:notice] = s_("flash|notice|Item was successfully updated.") 188: x_redirect_to @current_view, :close, :action => "display_edit", :id => @display.id 189: return 190: end 191: end 192: 193: if @item.is_a?(ItemProper) 194: render :action => "item_proper" 195: else 196: render :action => "item_pseudo" 197: end 198: end
擬似項目を新規作成する。
# File app/controllers/product_generator_controller.rb, line 201 201: def item_new_pseudo 202: view_in :item 203: @item = ItemPseudo.new :display_id => params[:id] 204: setup_item 205: 206: if params[:item] 207: if @item.name_po_message = PoMessageSingular.create(:msgctxt => "", :msgid => params[:item]["name_en"]) 208: @item.attributes = params[:item] 209: if @item.save 210: flash[:notice] = s_("flash|notice|Item was successfully created.") 211: x_redirect_to @current_view, :close, :action => "display_edit", :id => @display.id 212: return 213: end 214: end 215: end 216: 217: render :action => "item_pseudo" 218: end
機能の一覧を表示する。
# File app/controllers/product_generator_controller.rb, line 25 25: def list 26: view_in :main 27: sync_fragment "main", :page, 1 28: @product_pages, @products = paginate :products, :order => "id" 29: end
機能に紐づいた画面を編集する。
# File app/controllers/product_generator_controller.rb, line 91 91: def manage 92: view_in :product 93: @product = Product.find(params[:id]) 94: @displays = @product.displays.find(:all, 95: :conditions => {:type => ['DisplayToList','DisplayToShow','DisplayToEdit','DisplayToNew']}, 96: :order => "id") 97: @displays_count = @displays.size 98: unless request.post? && params[:product] 99: render :action => "product_content_form" 100: return 101: end 102: 103: failed = false 104: @product.attributes = params[:product] 105: @displays.each do |display| 106: display.attributes = params[:display][display.id.to_s] 107: failed = true unless display.save 108: end 109: if !failed && @product.save 110: flash[:notice] = s_("flash|notice|Product was successfully updated.") 111: x_redirect_to "product", :close, :action => "show" 112: else 113: @product ||= Product.new 114: render :action => "product_content_form" 115: end 116: rescue ActiveRecord::ActiveRecordError 117: @product ||= Product.new 118: render :action => "product_content_form" 119: end
機能を新規作成する。
# File app/controllers/product_generator_controller.rb, line 38 38: def new 39: view_in :side 40: unless request.post? && params[:product] 41: @product = Product.new 42: render :action => "product_name_form" 43: return 44: end 45: 46: product_class = params[:product]["type"].constantize 47: unless product_class < Product 48: # should not happen via usual UI 49: raise "invalid product type" 50: end 51: product_class.transaction do 52: @product = product_class.create!({ 53: :code => params[:product]["code"], 54: :name_po => 0, 55: :model_name => params[:product]["model_name"], 56: }) 57: rest_attributes = params[:product].dup 58: [:code, :model_name].each {|k| rest_attributes.delete(k)} 59: @product.attributes = rest_attributes 60: @product.save! 61: end 62: flash[:notice] = s_("flash|notice|Product was successfully created.") 63: x_redirect_to "side", :close, :action => "list" 64: rescue ActiveRecord::RecordInvalid 65: unless @product 66: @product = product_class.for_error_message(params[:product]) 67: end 68: render :action => "product_name_form" 69: end
一覧画面を新規作成する。
# File app/controllers/product_generator_controller.rb, line 122 122: def new_list 123: view_in :product 124: @product = Product.find(params[:id]) 125: unless request.post? && @product 126: render 127: return 128: end 129: 130: # ':name_po => 0' indicates a transitive status. 131: DisplayToList.create! :product_id => @product.id, :code => "NEW_LIST_#{rand.to_s[(2..-1)]}", :name_po => 0 132: flash_message = s_("flash|notice|A list was successfully added.") 133: 134: if request.xhr? 135: flash.now[:notice] = flash_message 136: manage 137: else 138: flash[:notice] = flash_message 139: redirect_to :action => "manage", :id => params[:id] 140: end 141: end