diff options
| -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 | ||||
| -rw-r--r-- | public/javascripts/admin_interface.js | 4 | ||||
| -rw-r--r-- | public/javascripts/admin_search.js | 17 | ||||
| -rw-r--r-- | public/stylesheets/admin.css | 7 |
7 files changed, 92 insertions, 10 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"> |
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index 64da5a8..5514f3b 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js | |||
| @@ -65,6 +65,10 @@ $(document).ready(function () { | |||
| 65 | related_assets.initialize(); | 65 | related_assets.initialize(); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | if ($("#asset_node_search_term").length != 0) { | ||
| 69 | asset_node_search.initialize_search(); | ||
| 70 | } | ||
| 71 | |||
| 68 | if ($("#rrule_builder").length != 0) { | 72 | if ($("#rrule_builder").length != 0) { |
| 69 | rrule_builder.initialize(); | 73 | rrule_builder.initialize(); |
| 70 | } | 74 | } |
diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js index ad368cb..792849f 100644 --- a/public/javascripts/admin_search.js +++ b/public/javascripts/admin_search.js | |||
| @@ -286,3 +286,20 @@ event_search = { | |||
| 286 | }); | 286 | }); |
| 287 | } | 287 | } |
| 288 | }; | 288 | }; |
| 289 | |||
| 290 | asset_node_search = { | ||
| 291 | initialize_search : function() { | ||
| 292 | initSearchPicker({ | ||
| 293 | inputSelector: "#asset_node_search_term", | ||
| 294 | resultsSelector: "#asset_node_search_results", | ||
| 295 | onSelect: function(node) { | ||
| 296 | $("#asset_node_search_term").val(node.title); | ||
| 297 | $("#node_id").val(node.node_id); | ||
| 298 | } | ||
| 299 | }); | ||
| 300 | |||
| 301 | $("#asset_node_search_term").bind("input", function() { | ||
| 302 | if ($(this).val() === "") { $("#node_id").val(""); } | ||
| 303 | }); | ||
| 304 | } | ||
| 305 | }; | ||
diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css index b69b178..9f73775 100644 --- a/public/stylesheets/admin.css +++ b/public/stylesheets/admin.css | |||
| @@ -831,12 +831,11 @@ form.button_to button[type="submit"] { | |||
| 831 | 831 | ||
| 832 | /* Layout only -- the at-rest visibility (wavy underline) for these | 832 | /* Layout only -- the at-rest visibility (wavy underline) for these |
| 833 | links comes from the scoped rule in Base elements above. */ | 833 | links comes from the scoped rule in Base elements above. */ |
| 834 | .add_events, | ||
| 835 | .add_attachments, | ||
| 834 | .add_child_links { | 836 | .add_child_links { |
| 835 | margin-top: 0.5rem; | 837 | margin-top: 0.5rem; |
| 836 | } | 838 | margin-bottom: 0; |
| 837 | |||
| 838 | .add_child_links a { | ||
| 839 | white-space: nowrap; | ||
| 840 | } | 839 | } |
| 841 | 840 | ||
| 842 | .sitemap_node { | 841 | .sitemap_node { |
