OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / controllers / application_controller.rb
index 00f2d46..e79e4f2 100644 (file)
@@ -23,39 +23,32 @@ class ApplicationController < ActionController::Base
       :location => {:controller => params[:controller], :action => params[:action]}
     }
     @server_result[:location][:id] = params[:id] if params[:id]
-    if Admin.count.to_i == 0 or License.count.to_i == 0
-      if params[:controller] == 'system' and params[:action] == 'start'
-      else
-        redirect_to :controller => '/system', :action => 'start'
-      end
+    user = if user_signed_in?
+      current_user
     else
-      user = if user_signed_in?
-        current_user
-      else
-        nil
-      end
-      author = if user
-        user.author
-      else
-        nil
-      end
-      artist = if user
-        user.artist
-      else
-        nil
-      end
-      admin = if admin_signed_in?
-        current_admin
-      else
-        nil
-      end
-      demand_user = if demand_user_signed_in?
-        current_demand_user
-      else
-        nil
-      end
-      @operators = Operator.new [user, author, artist, admin, demand_user]
+      nil
+    end
+    author = if user
+      user.author
+    else
+      nil
+    end
+    artist = if user
+      user.artist
+    else
+      nil
+    end
+    admin = if admin_signed_in?
+      current_admin
+    else
+      nil
     end
+    demand_user = if demand_user_signed_in?
+      current_demand_user
+    else
+      nil
+    end
+    @operators = Operator.new [user, author, artist, admin, demand_user]
   end
   
   def authenticate_reader
@@ -80,7 +73,6 @@ class ApplicationController < ActionController::Base
     else
       respond_to do |format|
         format.html { redirect_to main_app.new_author_path, :status => :found }
-        format.js { render "authors/new" }
         format.json { 
           raise ActiveRecord::Forbidden
         }
@@ -95,7 +87,6 @@ class ApplicationController < ActionController::Base
     else
       respond_to do |format|
         format.html { redirect_to main_app.new_artist_path, :status => :found }
-        format.js { render "artists/new" }
         format.json { 
           raise ActiveRecord::Forbidden
         }
@@ -121,42 +112,55 @@ class ApplicationController < ActionController::Base
   
   def set_list
     set_model
-    @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name
+    @my_list_model = Manifest.manifest.models[@my_action.item_name]
+    @my_list_model_class = @my_list_model.classify
+    @list = Locmare::ListGroup.list @my_action.controller.name, @my_action.action_name, @operators, params
   end
   
   def filer_list
     set_list
-    list_result = @list.open(@operators, 
-      {:id => params[:id], :page => params[:page], :page_size => params[:page_size]}
-    )
-    @items = list_result.items 
+    @items = @list.items 
     respond_to do |format|
       format.html {
-        @filer = Locmare::Filer.new @list.item_name, list_result.items, list_result, :default, @operators
+        @filer = Locmare::Filer.new @list.item_name, @items, @list.page_status, @operators
         render @filer.template_name, :locals => {
           :filer => @filer
         }
       }
-      format.json { render json: @items.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_model
-    @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name
+    set_list
+    @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 = {:id => params[:id], :my_play => @item.own?(@operators), 
-      :offset => params[:offset], :count => params[:count], 
-      :page => params[:page], :page_size => params[:page_size]
-    }
-    list_result = @list.open(@operators, @options)
-    @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
@@ -167,7 +171,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_class.item_name, @item, @operators
       render @profiler.template_name, :locals => {
         :profiler => @profiler
       }
@@ -198,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
         }
@@ -294,11 +298,11 @@ class ApplicationController < ActionController::Base
   
   def updated_json_format format
     format.json {
-      head :ok
+      render json: '{}', status: :ok
     }
   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
@@ -332,7 +336,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
@@ -353,11 +357,43 @@ class ApplicationController < ActionController::Base
     end
   end
   
-  def list_count
-    set_list
-    j = {:count => @list.count(@operators, {:id => params[:id]})}
-    respond_to do |format|
-      format.json { render json: j.to_json }
+  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 {
+      render json: '{}', status: :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
   
@@ -380,10 +416,9 @@ class ApplicationController < ActionController::Base
     }
   end
   
-  def assist_items item_name, list_name
-    list = Locmare::ListGroup.list item_name, list_name
-    list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5})
-    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)