OSDN Git Service

add lg_id in resource picture
[pettanr/pettanr.git] / app / controllers / application_controller.rb
index 73cb83d..00f2d46 100644 (file)
@@ -137,7 +137,7 @@ class ApplicationController < ActionController::Base
           :filer => @filer
         }
       }
-      format.json { render json: @items.to_json(@my_model_class.list_json_opt) }
+      format.json { render json: @items.to_json }
       format.atom 
       format.rss
     end
@@ -148,6 +148,17 @@ class ApplicationController < ActionController::Base
     @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name
   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
+  end
+  
   def set_show
     set_model
     @item = @my_model_class.show(params[:id], @operators)
@@ -167,6 +178,10 @@ class ApplicationController < ActionController::Base
     format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
   end
   
+  def show_json_format_for_root format
+    format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
+  end
+  
   def set_new
     set_model
     @item = @my_model_class.new
@@ -188,7 +203,7 @@ class ApplicationController < ActionController::Base
           :form => @form
         }
       }
-      format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
+      format.json { render json: @item.to_json }
     end
   end
   
@@ -202,10 +217,10 @@ class ApplicationController < ActionController::Base
     render_form
   end
   
-  def created_html_format format
+  def created_html_format format, redirect_url = nil
     format.html {
       flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
-      redirect_to @item
+      redirect_to (redirect_url ? redirect_url : @item)
     }
   end
   
@@ -228,10 +243,10 @@ class ApplicationController < ActionController::Base
     }
   end
   
-  def render_create
+  def render_create redirect_url = nil
     if @item.save
       respond_to do |format|
-        created_html_format format
+        created_html_format format, redirect_url
         created_json_format format
       end
     else
@@ -242,10 +257,38 @@ class ApplicationController < ActionController::Base
     end
   end
   
-  def updated_html_format format
+  def leaf_created_html_format format, redirect_url
+    format.html {
+      flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
+      redirect_to redirect_url
+    }
+  end
+  
+  def leaf_not_created_html_format format, redirect_url
+    format.html {
+      flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
+      redirect_to redirect_url
+    }
+  end
+  
+  def leaf_render_create redirect_url
+    if @item.store @operators
+      respond_to do |format|
+        leaf_created_html_format format, redirect_url
+        created_json_format format
+      end
+    else
+      respond_to do |format|
+        leaf_not_created_html_format format, redirect_url
+        not_created_json_format format
+      end
+    end
+  end
+  
+  def updated_html_format format, redirect_url = nil
     format.html {
       flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
-      redirect_to @item
+      redirect_to (redirect_url ? redirect_url : @item)
     }
   end
   
@@ -268,10 +311,10 @@ class ApplicationController < ActionController::Base
     }
   end
   
-  def render_update
+  def render_update redirect_url = nil
     if @item.save
       respond_to do |format|
-        updated_html_format format
+        updated_html_format format, redirect_url
         updated_json_format format
       end
     else
@@ -282,6 +325,34 @@ class ApplicationController < ActionController::Base
     end
   end
   
+  def leaf_updated_html_format format, redirect_url
+    format.html {
+      flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
+      redirect_to redirect_url
+    }
+  end
+  
+  def leaf_not_update_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
+    }
+  end
+  
+  def leaf_render_update ot, redirect_url
+    if @item.store @operators, ot
+      respond_to do |format|
+        leaf_updated_html_format format, redirect_url
+        updated_json_format format
+      end
+    else
+      respond_to do |format|
+        leaf_not_updated_html_format format, redirect_url
+        not_updated_json_format format
+      end
+    end
+  end
+  
   def list_count
     set_list
     j = {:count => @list.count(@operators, {:id => params[:id]})}
@@ -315,11 +386,6 @@ class ApplicationController < ActionController::Base
     list_result.items
   end
   
-  def assist_filer item_name, items
-    filer_manager = Pettanr::Application::manifest.filer_managers[item_name]
-    filer_manager.open(item_name, items, @operators, nil)
-  end
-  
   def set_image(file)
     if file.respond_to?(:read)
       file.read