From cd21cadfe79a537c5398bf30919a49a1ce423ef9 Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Mon, 11 Jan 2010 17:53:44 +0800 Subject: [PATCH] Add panel namespace --- .../admin/announcements_controller.rb | 69 ------------------- .../panel/announcements_controller.rb | 49 +++++++++++++ app/views/layouts/admin.html.erb | 2 +- .../announcements/_form.html.erb | 0 .../announcements/edit.html.erb | 4 +- .../announcements/index.html.erb | 6 +- .../announcements/new.html.erb | 4 +- config/routes.rb | 6 +- 8 files changed, 61 insertions(+), 79 deletions(-) delete mode 100644 app/controllers/admin/announcements_controller.rb create mode 100644 app/controllers/panel/announcements_controller.rb rename app/views/{admin => panel}/announcements/_form.html.erb (100%) rename app/views/{admin => panel}/announcements/edit.html.erb (67%) rename app/views/{admin => panel}/announcements/index.html.erb (61%) rename app/views/{admin => panel}/announcements/new.html.erb (61%) diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb deleted file mode 100644 index b29f47a2..00000000 --- a/app/controllers/admin/announcements_controller.rb +++ /dev/null @@ -1,69 +0,0 @@ -class Admin::AnnouncementsController < ApplicationController - - before_filter :require_entry_name, :only => [:index, :new] - - layout "admin" - - def index - @announcements = Announcement.find(:all, :conditions => { :entry_name => params[:entry_name] }) - - respond_to do |format| - format.html - format.xml { render :xml => @announcements } - end - end - - def new - @announcement = Announcement.new - @announcement.entry_name = params[:entry_name] - - respond_to do |format| - format.htm - format.xml { render :xml => @announcement } - end - end - - def edit - @announcement = Announcement.find(params[:id]) - end - - def create - @announcement = Announcement.new(params[:announcement]) - - respond_to do |format| - if @announcement.save - flash[:notice] = 'Announcement was successfully created.' - format.html { redirect_to admin_announcements_path } - format.xml { render :xml => @announcement, :status => :created, :location => @announcement } - else - format.html { render :action => "new" } - format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } - end - end - end - - def update - @announcement = Announcement.find(params[:id]) - - respond_to do |format| - if @announcement.update_attributes(params[:announcement]) - flash[:notice] = 'Announcement was successfully updated.' - format.html { redirect_to admin_announcements_path } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } - end - end - end - - def destroy - @announcement = Announcement.find(params[:id]) - @announcement.destroy - - respond_to do |format| - format.html { redirect_to admin_announcements_path } - format.xml { head :ok } - end - end -end diff --git a/app/controllers/panel/announcements_controller.rb b/app/controllers/panel/announcements_controller.rb new file mode 100644 index 00000000..243a1329 --- /dev/null +++ b/app/controllers/panel/announcements_controller.rb @@ -0,0 +1,49 @@ +class Panel::AnnouncementsController < ApplicationController + + before_filter :require_entry_name, :only => [:index, :new] + + layout "admin" + + def index + @announcements = Announcement.find(:all, :conditions => { :entry_name => params[:entry_name] }) + end + + def new + @announcement = Announcement.new + @announcement.entry_name = params[:entry_name] + end + + def edit + @announcement = Announcement.find(params[:id]) + end + + def create + @announcement = Announcement.new(params[:announcement]) + + if @announcement.save + flash[:notice] = 'Announcement was successfully created.' + redirect_to panel_announcements_path( :entry_name => @announcement.entry_name ) + else + render :action => "new" + end + end + + def update + @announcement = Announcement.find(params[:id]) + + if @announcement.update_attributes(params[:announcement]) + flash[:notice] = 'Announcement was successfully updated.' + redirect_to panel_announcements_path( :entry_name => @announcement.entry_name ) + else + render :action => "edit" + end + end + + def destroy + @announcement = Announcement.find(params[:id]) + @announcement.destroy + + redirect_to panel_announcements_path( :entry_name => @announcement.entry_name ) + end + +end diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index b134dcda..9ce896be 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -23,7 +23,7 @@
  • <%= link_to t(:page, :scope => :admin), admin_pages_path %>
  • <%= link_to t(:snippet, :scope => :admin), admin_snippets_path %>
  • <%= link_to t(:layout, :scope => :admin), admin_layouts_path %>
  • -
  • <%= link_to t(:announcement, :scope => :admin), admin_announcements_path( :entry_name => 'news' ) %>
  • +
  • <%= link_to t(:announcement, :scope => :admin), panel_announcements_path( :entry_name => 'news' ) %>
  • diff --git a/app/views/admin/announcements/_form.html.erb b/app/views/panel/announcements/_form.html.erb similarity index 100% rename from app/views/admin/announcements/_form.html.erb rename to app/views/panel/announcements/_form.html.erb diff --git a/app/views/admin/announcements/edit.html.erb b/app/views/panel/announcements/edit.html.erb similarity index 67% rename from app/views/admin/announcements/edit.html.erb rename to app/views/panel/announcements/edit.html.erb index 06dc1c2e..00ce99be 100644 --- a/app/views/admin/announcements/edit.html.erb +++ b/app/views/panel/announcements/edit.html.erb @@ -1,6 +1,6 @@

    Editing announcement

    -<% form_for @announcement, :url => admin_announcement_path(@announcement) do |f| %> +<% form_for @announcement, :url => panel_announcement_path(@announcement) do |f| %> <%= f.error_messages %> <%= render :partial => "form", :locals => { :f => f } %> @@ -11,4 +11,4 @@ <% end %> <%= link_to 'Show', @announcement %> | -<%= link_to 'Back', admin_announcements_path %> \ No newline at end of file +<%= link_to 'Back', panel_announcements_path %> \ No newline at end of file diff --git a/app/views/admin/announcements/index.html.erb b/app/views/panel/announcements/index.html.erb similarity index 61% rename from app/views/admin/announcements/index.html.erb rename to app/views/panel/announcements/index.html.erb index 6342b10b..2d1d1c20 100644 --- a/app/views/admin/announcements/index.html.erb +++ b/app/views/panel/announcements/index.html.erb @@ -10,12 +10,12 @@ <%=h announcement.title %> <%= link_to 'Show', announcement_path(announcement) %> | - <%= link_to 'Edit', edit_admin_announcement_path(announcement) %> | - <%= link_to 'Destroy', admin_announcement_path(announcement), :confirm => 'Are you sure?', :method => :delete %> + <%= link_to 'Edit', edit_panel_announcement_path(announcement) %> | + <%= link_to 'Destroy', panel_announcement_path(announcement), :confirm => 'Are you sure?', :method => :delete %> <% end %>
    -<%= link_to 'New announcement', new_admin_announcement_path( :entry_name => params[:entry_name] ) %> \ No newline at end of file +<%= link_to 'New announcement', new_panel_announcement_path( :entry_name => params[:entry_name] ) %> \ No newline at end of file diff --git a/app/views/admin/announcements/new.html.erb b/app/views/panel/announcements/new.html.erb similarity index 61% rename from app/views/admin/announcements/new.html.erb rename to app/views/panel/announcements/new.html.erb index aec0eede..207aef11 100644 --- a/app/views/admin/announcements/new.html.erb +++ b/app/views/panel/announcements/new.html.erb @@ -1,6 +1,6 @@

    New announcement

    -<% form_for @announcement, :url => admin_announcements_path do |f| %> +<% form_for @announcement, :url => panel_announcements_path do |f| %> <%= f.error_messages %> <%= render :partial => "form", :locals => { :f => f } %> @@ -10,4 +10,4 @@

    <% end %> -<%= link_to 'Back', admin_announcements_path %> \ No newline at end of file +<%= link_to 'Back', panel_announcements_path %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0db55810..ff58cce3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,8 +6,10 @@ ActionController::Routing::Routes.draw do |map| admin.resources :pages admin.resources :layouts admin.resources :snippets - - admin.resources :announcements + end + + map.namespace :panel do |panel| + panel.resources :announcements end # The priority is based upon order of creation: first created -> highest priority.