Add panel namespace

This commit is contained in:
Wen-Tien Chang 2010-01-11 17:53:44 +08:00
parent 314f6d5219
commit cd21cadfe7
8 changed files with 61 additions and 79 deletions

View File

@ -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

View File

@ -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

View File

@ -23,7 +23,7 @@
<li><%= link_to t(:page, :scope => :admin), admin_pages_path %></li> <li><%= link_to t(:page, :scope => :admin), admin_pages_path %></li>
<li><%= link_to t(:snippet, :scope => :admin), admin_snippets_path %></li> <li><%= link_to t(:snippet, :scope => :admin), admin_snippets_path %></li>
<li><%= link_to t(:layout, :scope => :admin), admin_layouts_path %></li> <li><%= link_to t(:layout, :scope => :admin), admin_layouts_path %></li>
<li><%= link_to t(:announcement, :scope => :admin), admin_announcements_path( :entry_name => 'news' ) %></li> <li><%= link_to t(:announcement, :scope => :admin), panel_announcements_path( :entry_name => 'news' ) %></li>
</ul> </ul>
</div> </div>

View File

@ -1,6 +1,6 @@
<h1>Editing announcement</h1> <h1>Editing announcement</h1>
<% form_for @announcement, :url => admin_announcement_path(@announcement) do |f| %> <% form_for @announcement, :url => panel_announcement_path(@announcement) do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
@ -11,4 +11,4 @@
<% end %> <% end %>
<%= link_to 'Show', @announcement %> | <%= link_to 'Show', @announcement %> |
<%= link_to 'Back', admin_announcements_path %> <%= link_to 'Back', panel_announcements_path %>

View File

@ -10,12 +10,12 @@
<tr> <tr>
<td><%=h announcement.title %></td> <td><%=h announcement.title %></td>
<td><%= link_to 'Show', announcement_path(announcement) %> | <td><%= link_to 'Show', announcement_path(announcement) %> |
<%= link_to 'Edit', edit_admin_announcement_path(announcement) %> | <%= link_to 'Edit', edit_panel_announcement_path(announcement) %> |
<%= link_to 'Destroy', admin_announcement_path(announcement), :confirm => 'Are you sure?', :method => :delete %></td> <%= link_to 'Destroy', panel_announcement_path(announcement), :confirm => 'Are you sure?', :method => :delete %></td>
</tr> </tr>
<% end %> <% end %>
</table> </table>
<br /> <br />
<%= link_to 'New announcement', new_admin_announcement_path( :entry_name => params[:entry_name] ) %> <%= link_to 'New announcement', new_panel_announcement_path( :entry_name => params[:entry_name] ) %>

View File

@ -1,6 +1,6 @@
<h1>New announcement</h1> <h1>New announcement</h1>
<% form_for @announcement, :url => admin_announcements_path do |f| %> <% form_for @announcement, :url => panel_announcements_path do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
@ -10,4 +10,4 @@
</p> </p>
<% end %> <% end %>
<%= link_to 'Back', admin_announcements_path %> <%= link_to 'Back', panel_announcements_path %>

View File

@ -6,8 +6,10 @@ ActionController::Routing::Routes.draw do |map|
admin.resources :pages admin.resources :pages
admin.resources :layouts admin.resources :layouts
admin.resources :snippets admin.resources :snippets
end
admin.resources :announcements
map.namespace :panel do |panel|
panel.resources :announcements
end end
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.