X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fcontrollers%2Fapplication_controller.rb;h=42e8780635175793491d25b3e87f45335c8143ad;hb=a4838064801c37fddc101f493c654cf0b2c78db4;hp=bb8f2fe9215e051172bc879121afef5f61e91a94;hpb=ac99a9d7dc6bcff459b17b1aa8d09765fc701fbb;p=pettanr%2Fpettanr.git diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bb8f2fe9..42e87806 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -106,12 +106,14 @@ class ApplicationController < ActionController::Base def set_model @my_controller = Manifest.manifest.controllers[params[:controller].to_s] @my_action = @my_controller.actions[params[:action].to_s] - @my_model = Manifest.manifest.models[@my_action.item_name] + @my_model = Manifest.manifest.models[@my_controller.item_name] @my_model_class = @my_model.classify end def set_list set_model + @my_list_model = Manifest.manifest.models[@my_action.item_name] + @my_list_model_class = @my_list_model.classify @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name end @@ -128,15 +130,20 @@ class ApplicationController < ActionController::Base :filer => @filer } } - format.json { render json: @items.to_json } + format.json { render json: @items.map{|i| i.attributes}.to_json } + # rails3.2 has problem + # y method defined as private + # attribute y conflict at PanelPicture, balloon ..etc + # use i.attributes[name] + # format.json { render json: @items.to_json } format.atom format.rss end end def set_play - set_model - @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name + set_list + @item = @my_model_class.show(params[:id], @operators) end def play_list @@ -158,7 +165,7 @@ class ApplicationController < ActionController::Base def show_prof_format format format.prof { self.formats = [:html] - @profiler = Locmare::Profiler.new @my_model.model_name, @item, @operators + @profiler = Locmare::Profiler.new @my_model.item_name, @item, @operators render @profiler.template_name, :locals => { :profiler => @profiler } @@ -170,7 +177,7 @@ class ApplicationController < ActionController::Base end def show_json_format_for_root format - format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) } + format.json { render json: @item.attributes.to_json(@my_model_class.show_json_opt_for_root) } end def set_new @@ -289,7 +296,7 @@ class ApplicationController < ActionController::Base } end - def not_update_html_format format + def not_updated_html_format format format.html { flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human) render_form @@ -323,7 +330,7 @@ class ApplicationController < ActionController::Base } end - def leaf_not_update_html_format format, redirect_url + def leaf_not_updated_html_format format, redirect_url format.html { flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human) redirect_to redirect_url @@ -344,6 +351,46 @@ class ApplicationController < ActionController::Base end end + def destroyed_html_format format, redirect_url + format.html { + flash[:notice] = I18n.t('flash.notice.destroyed', :model => @my_model_class.model_name.human) + redirect_to redirect_url + } + end + + def destroyed_json_format format + format.json { + head :ok + } + end + + def not_destroyed_html_format format + format.html { + flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => @my_model_class.model_name.human) + redirect_to @item + } + end + + def not_destroyed_json_format format + format.json { + render json: @item.errors, status: :unprocessable_entity + } + end + + def render_destroy redirect_url = nil + if @item.destroy + respond_to do |format| + destroyed_html_format format, redirect_url + destroyed_json_format format + end + else + respond_to do |format| + not_destroyed_html_format format + not_destroyed_json_format format + end + end + end + def list_count set_list j = {:count => @list.count(@operators, {:id => params[:id]})}