diff options
Diffstat (limited to 'app/controllers/nodes_controller.rb')
| -rw-r--r-- | app/controllers/nodes_controller.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 6caa827..ce8f053 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -30,6 +30,7 @@ class NodesController < ApplicationController | |||
| 30 | @node = Node.new node_params | 30 | @node = Node.new node_params |
| 31 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" | 31 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" |
| 32 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) | 32 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) |
| 33 | @attach_asset = Asset.find(params[:asset_id]) if params.has_key?(:asset_id) | ||
| 33 | end | 34 | end |
| 34 | 35 | ||
| 35 | def create | 36 | def create |
| @@ -51,10 +52,19 @@ class NodesController < ApplicationController | |||
| 51 | :action => "create", | 52 | :action => "create", |
| 52 | :title => params[:title], :path => @node.unique_name) | 53 | :title => params[:title], :path => @node.unique_name) |
| 53 | 54 | ||
| 55 | if params[:asset_id].present? && (asset = Asset.find(params[:asset_id])) | ||
| 56 | result = @node.attach_asset!(asset, :user => current_user, | ||
| 57 | :headline => params[:asset_headline].present?) | ||
| 58 | flash[:notice] = "Page created with “#{asset.name}” attached." | ||
| 59 | flash[:notice] += " It is the page's headline." if result[:headline] == :set | ||
| 60 | flash[:error] = "This asset type cannot be a headline." if result[:headline] == :not_eligible | ||
| 61 | end | ||
| 62 | |||
| 54 | redirect_to(edit_node_path(@node)) | 63 | redirect_to(edit_node_path(@node)) |
| 55 | else | 64 | else |
| 56 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" | 65 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" |
| 57 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) | 66 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) |
| 67 | @attach_asset = Asset.find(params[:asset_id]) if params.has_key?(:asset_id) | ||
| 58 | render :new | 68 | render :new |
| 59 | end | 69 | end |
| 60 | end | 70 | end |
| @@ -77,7 +87,7 @@ class NodesController < ApplicationController | |||
| 77 | "This page has unsaved changes from a previous session, shown below. " \ | 87 | "This page has unsaved changes from a previous session, shown below. " \ |
| 78 | "Save to keep them, or use \"Discard Autosave\" below to go back to the last saved version." | 88 | "Save to keep them, or use \"Discard Autosave\" below to go back to the last saved version." |
| 79 | elsif freshly_locked | 89 | elsif freshly_locked |
| 80 | flash.now[:notice] = "Node locked and ready to edit" | 90 | flash.now[:notice] ||= "Node locked and ready to edit" |
| 81 | end | 91 | end |
| 82 | rescue LockedByAnotherUser => e | 92 | rescue LockedByAnotherUser => e |
| 83 | flash[:error] = e.message | 93 | flash[:error] = e.message |
| @@ -223,10 +233,6 @@ class NodesController < ApplicationController | |||
| 223 | @nodes = index_matching(Node.drafts_and_autosaves) | 233 | @nodes = index_matching(Node.drafts_and_autosaves) |
| 224 | end | 234 | end |
| 225 | 235 | ||
| 226 | def recent | ||
| 227 | @nodes = index_matching(Node.recently_changed) | ||
| 228 | end | ||
| 229 | |||
| 230 | def mine | 236 | def mine |
| 231 | base = Node.joins(:pages) | 237 | base = Node.joins(:pages) |
| 232 | .where("pages.user_id = ? or pages.editor_id = ?", current_user, current_user) | 238 | .where("pages.user_id = ? or pages.editor_id = ?", current_user, current_user) |
