OSDN Git Service

add: license publisher
[pettanr/pettanr.git] / app / controllers / application_controller.rb
index c6c83a9..9072fb3 100644 (file)
@@ -114,7 +114,7 @@ class ApplicationController < ActionController::Base
     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_controller.name, @my_action.action_name, @operators, params
+    @list = Locmare::ListGroup.list @my_action.controller.name, @my_action.action_name, @operators, params
   end
   
   def filer_list
@@ -127,39 +127,40 @@ class ApplicationController < ActionController::Base
           :filer => @filer
         }
       }
-      format.json {
-        res = {
-          :page_status => @list.page_status.to_hash,
-          # rails3.2 has problem
-          # y method defined as private
-          # attribute y conflict at PanelPicture, balloon ..etc
-          # use i.attributes[name]
-          :list => @items.map{|i| i.attributes}
-          # :list => @items.to_json
-        }
-        render json:  res.to_json
-      }
+      list_json_format @list, format
       format.atom 
       format.rss
     end
   end
   
+  def list_json_format list, format
+    format.json {
+      res = {
+        :page_status => list.page_status.to_hash,
+        # rails3.2 has problem
+        # y method defined as private
+        # attribute y conflict at PanelPicture, balloon ..etc
+        # use i.attributes[name]
+        :list => list.items.map{|i| i.attributes}
+        # :list => @items.to_json
+      }
+      render json:  res.to_json
+    }
+  end
+  
   def set_play
     set_list
-    @binder_controller = Manifest.manifest.controllers[params[:controller].to_s]
-    @binder_action = @my_controller.actions[params[:action].to_s]
+    @binder_action = @my_action.original
+    @binder_controller = @binder_action.controller
     @binder_model = Manifest.manifest.models[@binder_action.item_name]
     @binder_model_class = @binder_model.classify
     @item = @binder_model_class.show(params[:id], @operators)
   end
   
   def play_list
-    @options = params
-    @options[:my_play] = @item.own?(@operators)
-    list_result = @list.open(@operators)
-    @items = list_result.items 
-    @count = list_result.count
-    @pager = list_result.paginate
+    @items = @list.items #.map {|sp| sp.root }
+    @count = @list.total
+    @pager = @list.page_status.pager
   end
   
   def set_show
@@ -201,7 +202,7 @@ class ApplicationController < ActionController::Base
   def render_form
     respond_to do |format|
       format.html { 
-        @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
+        @form = Locmare::Bucket.factory @item.item_name, 'default', @item, true, true, @operators
         render @form.template_name, :locals => {
           :form => @form
         }
@@ -297,7 +298,7 @@ class ApplicationController < ActionController::Base
   
   def updated_json_format format
     format.json {
-      head :ok
+      render json: '{}', status: :ok
     }
   end
   
@@ -365,7 +366,7 @@ class ApplicationController < ActionController::Base
   
   def destroyed_json_format format
     format.json {
-      head :ok
+      render json: '{}', status: :ok
     }
   end
   
@@ -382,7 +383,7 @@ class ApplicationController < ActionController::Base
     }
   end
   
-  def render_destroy redirect_url = nil
+  def render_destroy redirect_url
     if @item.destroy
       respond_to do |format|
         destroyed_html_format format, redirect_url
@@ -396,11 +397,17 @@ class ApplicationController < ActionController::Base
     end
   end
   
-  def list_count
-    set_list
-    j = {:count => @list.count()}
-    respond_to do |format|
-      format.json { render json: j.to_json }
+  def render_destroy_by destroy_method_name, redirect_url = nil
+    if @item.__send__(destroy_method_name)
+      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
   
@@ -423,10 +430,9 @@ class ApplicationController < ActionController::Base
     }
   end
   
-  def assist_items controller_name, list_name
-    list = Locmare::ListGroup.list controller_name, list_name, @operators, {:id => @item.id, :page => 1, :page_size => 5}
-    list_result = list.open(@operators)
-    list_result.items
+  def assist_items controller_name, action_name
+    list = Locmare::ListGroup.list controller_name, action_name, @operators, {:id => @item.id, :page => 1, :page_size => 5}
+    list.items
   end
   
   def set_image(file)