diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb index eb780d73b..29d145dbb 100644 --- a/app/controllers/admin/items_controller.rb +++ b/app/controllers/admin/items_controller.rb @@ -6,12 +6,14 @@ class Admin::ItemsController < ApplicationController before_filter :find_parent_item before_filter :find_snippets, :only => :index before_filter :is_admin? + before_filter :set_current_item def index if params[:item_id] - @page = Item.find(params[:item_id]) + @item = Item.find(params[:item_id]) else - @page = Item.first(:conditions => {:parent_id => nil}) + @item = Item.first(:conditions => {:parent_id => nil}) + @page = @item end end diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb index 88ece1bb9..b1ba5db62 100644 --- a/app/controllers/admin/links_controller.rb +++ b/app/controllers/admin/links_controller.rb @@ -1,18 +1,19 @@ class Admin::LinksController < ApplicationController - layout "admin" + layout "content" + before_filter :authenticate_user! before_filter :find_parent_item before_filter :is_admin? def show - #TODO + @link ||= Link.find(params[:id]) end def new @link = Link.new @link.is_published = true - @link.parent_id = @parent_item.id rescue nil + @link.parent_id = Page.find(params[:parent_id]).id rescue nil end def edit @@ -24,10 +25,17 @@ class Admin::LinksController < ApplicationController @link = Link.new(params[:link]) if @link.save - flash[:notice] = t('admin.create_success_link') - redirect_to admin_items_url( :parent_id => @link.parent_id ) + flash.now[:notice] = t('admin.create_success_link') + respond_to do |format| + format.html { + redirect_to admin_link_url(@link) + } + format.js {} + end else - render :action => "new" + flash.now[:error] = t('admin.create_error_link') + @i18n_variable = @link.i18n_variable + render :action => "new" end end @@ -35,9 +43,16 @@ class Admin::LinksController < ApplicationController @link = Link.find(params[:id]) if @link.update_attributes(params[:link]) - flash[:notice] = t('admin.update_success_link') - redirect_to admin_items_url( :parent_id => @link.parent_id ) + flash.now[:notice] = t('admin.update_success_link') + respond_to do |format| + format.html { + redirect_to admin_link_url(@link) + } + format.js {} + end else + flash.now[:error] = t('admin.update_error_link') + @i18n_variable = @link.i18n_variable render :action => "edit" end end @@ -46,8 +61,16 @@ class Admin::LinksController < ApplicationController @link = Link.find(params[:id]) @link.destroy @link.destroy_i18n_variable - - redirect_to admin_items_url( :parent_id => @link.parent_id ) + end + + def delete + destroy + respond_to do |format| + format.html { + redirect_to admin_items_url + } + format.js {} + end end end diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 1373ea4a7..9be2d1280 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -1,12 +1,21 @@ class Admin::PagesController < ApplicationController layout "content" + before_filter :authenticate_user! before_filter :find_parent_item before_filter :is_admin? + before_filter :set_current_item def show - #TODO + @page = Page.find(params[:id]) + respond_to do |format| + format.html { + @item = @page + render 'admin/items/index' + } + format.js {} + end end def new diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ee8568b58..d24c75058 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base include Parser helper :all - before_filter :set_locale, :set_site + before_filter :set_locale, :set_site # Find the parent for the given item def find_parent_item @@ -51,5 +51,9 @@ class ApplicationController < ActionController::Base @site_in_use_locales = @site.in_use_locales @site_valid_locales = @site.valid_locales end + + def set_current_item + session[:current_page] = params[:id] || @page.id || @link.id || @item.id rescue nil + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f6c77ceb1..e17b54fee 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,25 +49,35 @@ module ApplicationHelper end end - def render_node_and_children(node, current_name = 'home') + def render_node_and_children(node) ret = '' if node + case node._type + when 'Page' + dest = admin_page_path(:id => node.id) + when 'Link' + dest = admin_link_path(:id => node.id) + end ret << "
+ <%= f.submit t(:update) %> <%= link_back %> +
+<% end %> diff --git a/app/views/admin/links/_new.html.erb b/app/views/admin/links/_new.html.erb new file mode 100644 index 000000000..23cbd5a2f --- /dev/null +++ b/app/views/admin/links/_new.html.erb @@ -0,0 +1,13 @@ ++ <%= f.submit t(:create) %> <%= link_back %> +
+ +<% end %> diff --git a/app/views/admin/links/_show.html.erb b/app/views/admin/links/_show.html.erb new file mode 100644 index 000000000..4b7aa2766 --- /dev/null +++ b/app/views/admin/links/_show.html.erb @@ -0,0 +1,24 @@ +<%= flash_messages %> ++ <%= t('admin.name') %> + <%= @link.name %> +
+ +<% @site_valid_locales.each do |locale| %> ++ <%= "#{t('admin.title')} #{locale}" %> + <%= @link.i18n_variable[locale] if @link.i18n_variable %> +
+<% end %> + ++ <%= t('admin.is_published') %> + <%= @link.is_published.to_s %> +
+ ++ <%= t('admin.url') %> + <%= @link.url %> +
+ +<%= link_to t(:edit), edit_admin_link_path(@link) %> \ No newline at end of file diff --git a/app/views/admin/links/create.js.erb b/app/views/admin/links/create.js.erb new file mode 100644 index 000000000..9190c0052 --- /dev/null +++ b/app/views/admin/links/create.js.erb @@ -0,0 +1,2 @@ +$('#sidebar').html("<%= escape_javascript(render(:partial => 'admin/items/site_map_left_bar')) %>"); +$('#main').html("<%= escape_javascript(render(:partial => 'admin/links/show')) %>"); \ No newline at end of file diff --git a/app/views/admin/links/delete.js.erb b/app/views/admin/links/delete.js.erb new file mode 100644 index 000000000..d8771a3cc --- /dev/null +++ b/app/views/admin/links/delete.js.erb @@ -0,0 +1 @@ +$('#sidebar').html("<%= escape_javascript(render(:partial => 'admin/items/site_map_left_bar')) %>"); \ No newline at end of file diff --git a/app/views/admin/links/edit.html.erb b/app/views/admin/links/edit.html.erb index 25a65c934..7729178c2 100644 --- a/app/views/admin/links/edit.html.erb +++ b/app/views/admin/links/edit.html.erb @@ -1,10 +1,5 @@ -- <%= f.submit t(:update) %> <%= link_back %> -
-<% end %> +<%= render 'edit' %> diff --git a/app/views/admin/links/edit.js.erb b/app/views/admin/links/edit.js.erb new file mode 100644 index 000000000..b1292081a --- /dev/null +++ b/app/views/admin/links/edit.js.erb @@ -0,0 +1 @@ +$('#main').html("<%= escape_javascript(render(:partial => 'admin/links/edit')) %>"); \ No newline at end of file diff --git a/app/views/admin/links/new.html.erb b/app/views/admin/links/new.html.erb index 0151abc0e..7d7142b51 100644 --- a/app/views/admin/links/new.html.erb +++ b/app/views/admin/links/new.html.erb @@ -1,11 +1,5 @@ -- <%= f.submit t(:create) %> <%= link_back %> -
- -<% end %> +<%= render 'new' %> diff --git a/app/views/admin/links/new.js.erb b/app/views/admin/links/new.js.erb new file mode 100644 index 000000000..fb85026e2 --- /dev/null +++ b/app/views/admin/links/new.js.erb @@ -0,0 +1 @@ +$('#main').html("<%= escape_javascript(render(:partial => 'admin/links/new')) %>"); \ No newline at end of file diff --git a/app/views/admin/links/show.html.erb b/app/views/admin/links/show.html.erb new file mode 100644 index 000000000..bf733a474 --- /dev/null +++ b/app/views/admin/links/show.html.erb @@ -0,0 +1,5 @@ +<% content_for :sidebar do %> + +<% end -%> + +<%= render 'show' %> diff --git a/app/views/admin/links/show.js.erb b/app/views/admin/links/show.js.erb new file mode 100644 index 000000000..f9411af54 --- /dev/null +++ b/app/views/admin/links/show.js.erb @@ -0,0 +1 @@ +$('#main').html("<%= escape_javascript(render(:partial => 'show')) %>"); \ No newline at end of file diff --git a/app/views/admin/links/update.js.erb b/app/views/admin/links/update.js.erb new file mode 100644 index 000000000..0225c28bb --- /dev/null +++ b/app/views/admin/links/update.js.erb @@ -0,0 +1 @@ +$('#main').html("<%= escape_javascript(render(:partial => 'admin/links/show')) %>"); \ No newline at end of file diff --git a/app/views/admin/pages/_show.html.erb b/app/views/admin/pages/_show.html.erb new file mode 100644 index 000000000..22a5f373c --- /dev/null +++ b/app/views/admin/pages/_show.html.erb @@ -0,0 +1 @@ +<%= parse_page(@page).html_safe %> \ No newline at end of file diff --git a/app/views/admin/pages/show.html.erb b/app/views/admin/pages/show.html.erb new file mode 100644 index 000000000..3e1160c7a --- /dev/null +++ b/app/views/admin/pages/show.html.erb @@ -0,0 +1 @@ +<%= render 'show' %> \ No newline at end of file diff --git a/app/views/admin/pages/show.js.erb b/app/views/admin/pages/show.js.erb new file mode 100644 index 000000000..f9411af54 --- /dev/null +++ b/app/views/admin/pages/show.js.erb @@ -0,0 +1 @@ +$('#main').html("<%= escape_javascript(render(:partial => 'show')) %>"); \ No newline at end of file diff --git a/app/views/layouts/_page.html.erb b/app/views/layouts/_page.html.erb deleted file mode 100644 index 221e472b1..000000000 --- a/app/views/layouts/_page.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= parse_page(@page).html_safe if @page._type.eql?('Page') %> \ No newline at end of file diff --git a/app/views/layouts/_site_map_left_bar.html.erb b/app/views/layouts/_site_map_left_bar.html.erb deleted file mode 100644 index c9291de1f..000000000 --- a/app/views/layouts/_site_map_left_bar.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render_node_and_children(@page) %> \ No newline at end of file diff --git a/app/views/layouts/content.html.erb b/app/views/layouts/content.html.erb index b4acc1e59..7269b7d64 100644 --- a/app/views/layouts/content.html.erb +++ b/app/views/layouts/content.html.erb @@ -2,12 +2,13 @@ -