From 443947a319692e0462024c99f06e4d18ab5f0344 Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 17 Oct 2009 23:32:18 +0200 Subject: changed some node related methods and implementation of unlock --- app/controllers/nodes_controller.rb | 24 ++++++++++-------------- app/helpers/link_helper.rb | 11 +++++++++++ app/views/nodes/index.html.erb | 6 ++---- app/views/nodes/show.html.erb | 4 ++-- public/stylesheets/admin.css | 2 +- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 20aea5a..4f72744 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -43,7 +43,8 @@ class NodesController < ApplicationController end def show - @page = Node.find(params[:id]).pages.last + node = Node.find(params[:id]) + @page = node.draft || node.head end def edit @@ -51,7 +52,11 @@ class NodesController < ApplicationController @draft = @node.find_or_create_draft( current_user ) rescue LockedByAnotherUser => e flash[:error] = e.message - redirect_to :back + if request.referer + redirect_to :back + else + redirect_to node_path(@node) + end end end @@ -81,22 +86,13 @@ class NodesController < ApplicationController end def unlock - # TODO that actually has to be implemented in the model, once we have - # permissions - if @node.lock_owner - @node.unlock! + if @node.unlock! flash[:notice] = "Node unlocked" else - flash[:notice] = "Cannot unlock" + flash[:notice] = "Already unlocked" end - redirect_to :back - end - - def move_to - parent = Node.find params[:parent_id] - @node.move_to_child_of parent - redirect_to(@node) + redirect_to node_path(@node) end private diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index 65137ee..b77a1df 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb @@ -40,4 +40,15 @@ module LinkHelper return :class => "selected" end end + + def unlock_link + message = "Are you sure you want to unlock?\n" + + "Locked by #{@node.lock_owner.login}\n" + + "Last modified #{@page.updated_at.to_s(:db)}" + + link_to( + 'Unlock', unlock_node_path(@node), :method => :put, :confirm => message + ) + end + end \ No newline at end of file diff --git a/app/views/nodes/index.html.erb b/app/views/nodes/index.html.erb index d78a997..46c58f6 100644 --- a/app/views/nodes/index.html.erb +++ b/app/views/nodes/index.html.erb @@ -20,10 +20,8 @@

<%= link_to_path(node.unique_name, node.unique_name) %>

- <%= link_to 'show', node_path(node) %> - <%= link_to 'Revisions', node_revisions_path(node) %> - <%# link_to 'Destroy', node, :method => :delete, :confirm => "Are you sure you want to delete this node?" %> - <%= link_to 'Unlock', unlock_node_path(node), :method => :put, :confirm => "Are you sure you want to unlock?" %> + <%= link_to 'show', node_path(node) %> + <%= link_to 'Revisions', node_revisions_path(node) %> <%= node.lock_owner.login if node.lock_owner %> diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index 99fb264..87f65f5 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb @@ -2,7 +2,7 @@ <%= link_to 'Edit', edit_node_path(@node), :class => "unselected" %> <%= link_to 'Preview', preview_page_path(@page) %> <%= link_to 'Revisions', node_revisions_path(@node) %> - <%= link_to 'Unlock', unlock_node_path(@node), :method => :put, :confirm => "Are you sure you want to unlock?" %> + <%= unlock_link if @node.locked? %> <% end %> @@ -19,7 +19,7 @@ <% if @page.node.locked? %> Locked by - <%= @page.node.lock_owner.login %> + <%= @page.node.lock_owner.login %> <% end %> diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css index 1822ed1..6fa5b59 100644 --- a/public/stylesheets/admin.css +++ b/public/stylesheets/admin.css @@ -48,7 +48,7 @@ th { width: 12px; } -span#flash_error { +span#flash_error, span.warning { color: #ffffff; letter-spacing: 1px; background-color: #ff9600; -- cgit v1.3