diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/assets_controller.rb | 22 | ||||
| -rw-r--r-- | app/views/assets/edit.html.erb | 17 | ||||
| -rw-r--r-- | app/views/assets/new.html.erb | 17 | ||||
| -rw-r--r-- | app/views/nodes/show.html.erb | 18 |
4 files changed, 68 insertions, 6 deletions
diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index becfe13..fbede0a 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb | |||
| @@ -28,6 +28,7 @@ class AssetsController < ApplicationController | |||
| 28 | # GET /assets/new.xml | 28 | # GET /assets/new.xml |
| 29 | def new | 29 | def new |
| 30 | @asset = Asset.new | 30 | @asset = Asset.new |
| 31 | @attach_node = Node.not_in_trash.find_by(:id => params[:node_id]) if params[:node_id].present? | ||
| 31 | 32 | ||
| 32 | respond_to do |format| | 33 | respond_to do |format| |
| 33 | format.html # new.html.erb | 34 | format.html # new.html.erb |
| @@ -44,10 +45,12 @@ class AssetsController < ApplicationController | |||
| 44 | # POST /assets.xml | 45 | # POST /assets.xml |
| 45 | def create | 46 | def create |
| 46 | @asset = Asset.new(asset_params) | 47 | @asset = Asset.new(asset_params) |
| 48 | attach_node = Node.not_in_trash.find_by(:id => params[:node_id]) if params[:node_id].present? | ||
| 47 | 49 | ||
| 48 | respond_to do |format| | 50 | respond_to do |format| |
| 49 | if @asset.save | 51 | if @asset.save |
| 50 | flash[:notice] = 'Asset was successfully created.' | 52 | flash[:notice] = 'Asset was successfully created.' |
| 53 | attach_to(attach_node) if attach_node | ||
| 51 | format.html { redirect_to(@asset) } | 54 | format.html { redirect_to(@asset) } |
| 52 | format.xml { render :xml => @asset, :status => :created, :location => @asset } | 55 | format.xml { render :xml => @asset, :status => :created, :location => @asset } |
| 53 | else | 56 | else |
| @@ -91,4 +94,23 @@ class AssetsController < ApplicationController | |||
| 91 | def asset_params | 94 | def asset_params |
| 92 | params.require(:asset).permit(:name, :upload, :creator, :source_url, :license_key) | 95 | params.require(:asset).permit(:name, :upload, :creator, :source_url, :license_key) |
| 93 | end | 96 | end |
| 97 | |||
| 98 | def attach_to node | ||
| 99 | result = node.attach_asset!(@asset, :user => current_user, | ||
| 100 | :headline => params[:headline].present?) | ||
| 101 | flash[:notice] = | ||
| 102 | if result[:attached].zero? | ||
| 103 | "Asset saved — it was already attached to “#{node.title}”." | ||
| 104 | else | ||
| 105 | "Asset was successfully created and attached to “#{node.title}”." | ||
| 106 | end | ||
| 107 | case result[:headline] | ||
| 108 | when :set then flash[:notice] += " It is now the page's headline." | ||
| 109 | when :kept_existing then flash[:headline_kept_path] = node_path(node) | ||
| 110 | when :not_eligible then flash[:error] = "This asset type cannot be a headline." | ||
| 111 | end | ||
| 112 | rescue LockedByAnotherUser | ||
| 113 | flash[:locked_by] = node.lock_owner&.login | ||
| 114 | flash[:locked_node_path] = node_path(node) | ||
| 115 | end | ||
| 94 | end | 116 | end |
diff --git a/app/views/assets/edit.html.erb b/app/views/assets/edit.html.erb index 3ef8fea..0c1dd8f 100644 --- a/app/views/assets/edit.html.erb +++ b/app/views/assets/edit.html.erb | |||
| @@ -31,6 +31,23 @@ | |||
| 31 | ) %> | 31 | ) %> |
| 32 | </div> | 32 | </div> |
| 33 | 33 | ||
| 34 | <div class="node_description">attach to page</div> | ||
| 35 | <div class="node_content"> | ||
| 36 | <div class="restore_picker"> | ||
| 37 | <%= text_field_tag :asset_node_search_term, @attach_node&.title, | ||
| 38 | :placeholder => "Search for a page…", :autocomplete => "off" %> | ||
| 39 | <div id="asset_node_search_results" class="search_results" style="display: none"></div> | ||
| 40 | </div> | ||
| 41 | <%= hidden_field_tag :node_id, @attach_node&.id %> | ||
| 42 | <span class="field_hint">Optional — attaches this asset to that page, all pending versions included.</span> | ||
| 43 | </div> | ||
| 44 | |||
| 45 | <div class="node_description"></div> | ||
| 46 | <div class="node_content"> | ||
| 47 | <label><%= check_box_tag :headline, "1" %> attach as the page's headline</label> | ||
| 48 | <span class="field_hint">Applies only if the page has no headline yet.</span> | ||
| 49 | </div> | ||
| 50 | |||
| 34 | <div class="node_description">Actions</div> | 51 | <div class="node_description">Actions</div> |
| 35 | <div class="node_content node_info_group"> | 52 | <div class="node_content node_info_group"> |
| 36 | <div class="node_info_group_items"> | 53 | <div class="node_info_group_items"> |
diff --git a/app/views/assets/new.html.erb b/app/views/assets/new.html.erb index 2cf8865..7bded94 100644 --- a/app/views/assets/new.html.erb +++ b/app/views/assets/new.html.erb | |||
| @@ -26,6 +26,23 @@ | |||
| 26 | ) %> | 26 | ) %> |
| 27 | </div> | 27 | </div> |
| 28 | 28 | ||
| 29 | <div class="node_description">attach to page</div> | ||
| 30 | <div class="node_content"> | ||
| 31 | <div class="restore_picker"> | ||
| 32 | <%= text_field_tag :asset_node_search_term, @attach_node&.title, | ||
| 33 | :placeholder => "Search for a page…", :autocomplete => "off" %> | ||
| 34 | <div id="asset_node_search_results" class="search_results" style="display: none"></div> | ||
| 35 | </div> | ||
| 36 | <%= hidden_field_tag :node_id, @attach_node&.id %> | ||
| 37 | <span class="field_hint">Optional — attaches this asset to that page, all pending versions included.</span> | ||
| 38 | </div> | ||
| 39 | |||
| 40 | <div class="node_description"></div> | ||
| 41 | <div class="node_content"> | ||
| 42 | <label><%= check_box_tag :headline, "1" %> attach as the page's headline</label> | ||
| 43 | <span class="field_hint">Applies only if the page has no headline yet.</span> | ||
| 44 | </div> | ||
| 45 | |||
| 29 | <div class="node_description">Actions</div> | 46 | <div class="node_description">Actions</div> |
| 30 | <div class="node_content node_info_group"> | 47 | <div class="node_content node_info_group"> |
| 31 | <div class="node_info_group_items"> | 48 | <div class="node_info_group_items"> |
diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index adf79dd..b981e4b 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb | |||
| @@ -253,10 +253,10 @@ | |||
| 253 | <% end %> | 253 | <% end %> |
| 254 | </div> | 254 | </div> |
| 255 | 255 | ||
| 256 | <% if @page.assets.any? %> | 256 | <div class="node_description">Attachments</div> |
| 257 | <% headline_asset_id = @page.headline_asset&.id %> | 257 | <div class="node_content node_info_group"> |
| 258 | <div class="node_description">Images</div> | 258 | <% if @page.assets.any? %> |
| 259 | <div class="node_content node_info_group"> | 259 | <% headline_asset_id = @page.headline_asset&.id %> |
| 260 | <ul class="thumbnail_list"> | 260 | <ul class="thumbnail_list"> |
| 261 | <% @page.assets.each do |asset| %> | 261 | <% @page.assets.each do |asset| %> |
| 262 | <li class="<%= "is_headline" if asset.id == headline_asset_id %>"> | 262 | <li class="<%= "is_headline" if asset.id == headline_asset_id %>"> |
| @@ -269,8 +269,14 @@ | |||
| 269 | </li> | 269 | </li> |
| 270 | <% end %> | 270 | <% end %> |
| 271 | </ul> | 271 | </ul> |
| 272 | </div> | 272 | <% end %> |
| 273 | <% end %> | 273 | <p class="add_attachments"> |
| 274 | <%= link_to new_asset_path(:node_id => @node.id), class: 'action_button' do %> | ||
| 275 | <%= icon("paperclip", library: "tabler", "aria-hidden": true) %> Upload new attachment | ||
| 276 | <% end %> | ||
| 277 | <span class="field_hint">To add or remove existing attachments, edit this node instead.</span> | ||
| 278 | </p> | ||
| 279 | </div> | ||
| 274 | 280 | ||
| 275 | <div class="node_description">Events</div> | 281 | <div class="node_description">Events</div> |
| 276 | <div class="node_content node_info_group"> | 282 | <div class="node_content node_info_group"> |
