Skip to content

Commit

Permalink
Provide a bookmarklet for creating new resources
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 5, 2014
1 parent b886197 commit 8783f36
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 18 deletions.
15 changes: 12 additions & 3 deletions app/controllers/spotlight/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@ class ResourcesController < ApplicationController
before_filter :authenticate_user!, except: [:show]

load_resource :exhibit, class: Spotlight::Exhibit
before_filter :build_resource, only: :create
before_filter :build_resource, only: [:new, :create]

load_and_authorize_resource through: :exhibit
helper_method :from_popup?

def index
render json: @resources
end

def new

render layout: 'spotlight/popup'
end

def create
@resource.attributes = resource_params

if @resource.save
redirect_to admin_exhibit_catalog_index_path(@resource.exhibit)
if from_popup?
render layout: false, text: "<html><script>window.close();</script></html>"
else
redirect_to admin_exhibit_catalog_index_path(@resource.exhibit)
end
else
render action: 'new'
end
Expand All @@ -33,5 +38,9 @@ def resource_params
def build_resource
@resource ||= @exhibit.resources.build(resource_params).becomes_provider
end

def from_popup?
params.fetch(:popup, false)
end
end
end
16 changes: 11 additions & 5 deletions app/models/spotlight/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,23 @@ def self.class_for_resource r
end

def becomes_provider
z = self.becomes Spotlight::Resource.class_for_resource(self)
z.type = z.class.to_s
z
end
klass = Spotlight::Resource.class_for_resource(self)

protected
if klass
z = self.becomes klass
z.type = z.class.to_s
z
else
self
end
end

def needs_provider?
type.blank?
end

protected

def blacklight_solr
@solr ||= RSolr.connect(blacklight_solr_config)
end
Expand Down
52 changes: 52 additions & 0 deletions app/views/layouts/spotlight/popup.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<!-- Mobile viewport optimization h5bp.com/ad -->
<meta name="HandheldFriendly" content="True">
<meta name="viewport" content="width=device-width,initial-scale=1.0">

<!-- Mobile IE allows us to activate ClearType technology for smoothing fonts for easy reading -->
<!--[if IEMobile]>
<meta http-equiv="cleartype" content="on">
<![endif]-->

<title><%= h(@page_title || application_name) %></title>
<link href="<%= current_exhibit ? spotlight.exhibit_opensearch_catalog_path(current_exhibit, :format => 'xml', :only_path => false) : main_app.opensearch_catalog_path(:format => 'xml', :only_path => false) %>" title="<%= application_name %>" type="application/opensearchdescription+xml" rel="search"/>
<%= favicon_link_tag asset_path('favicon.ico') %>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= content_for(:head) %>

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

</head>
<body class="<%= render_body_class %>">

<div id="ajax-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal menu" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>

<!-- /container -->
<div id="main-container" class="container">
<div class="row">
<div class="col-md-12">
<div id="main-flashes">
<%= render :partial=>'/flash_msg' %>
</div>
</div>
</div>

<%= yield %>
</div>

</body>
</html>
7 changes: 4 additions & 3 deletions app/views/spotlight/catalog/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<div id="content" class="col-md-9">
<%= curation_page_title %>

<%= render 'spotlight/resources/form' %>
<div class="clearfix">
<%= render 'spotlight/resources/bookmarklet' %>
</div>

<%= render 'spotlight/resources/csv/form' %>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/spotlight/resources/_bookmarklet.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="col-md-12">
<p><%= t(:'.instructions') %></p>

<%= link_to t(:'.bookmarklet', application_name: application_name), "javascript:var q=document.location; void(open('#{new_exhibit_resource_url(current_exhibit) }?popup=true&resource[url]='+encodeURIComponent(q),'#{ application_name }','toolbar=no,width=700,height=350'));", class: 'btn btn-default', onclick: "return false;" %>
</div>
19 changes: 15 additions & 4 deletions app/views/spotlight/resources/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<%= bootstrap_form_for [@resource.exhibit, @resource], style: :horizontal, right: 'col-sm-5 col-md-5', :html => {:multipart => true, class: 'clearfix' } do |f| %>
<%= form_for [@resource.exhibit, @resource.becomes(Spotlight::Resource)] do |f| %>
<%= hidden_field_tag :popup, value: from_popup? %>
<div class="form-group">
<%= f.text_field :url %>
<div class="form-group <%= @resource.url and @resource.needs_provider? ? 'has-warning' : 'has-success' %> has-feedback">
<%= f.label :url, class: 'control-label' %>
<%= f.hidden_field :url, class: 'form-control' %>
<%= f.text_field :url, class: 'form-control', disabled: true %>
<span class="glyphicon <%= @resource.url and @resource.needs_provider? ? 'glyphicon-warning-sign' : 'glyphicon-ok' %> form-control-feedback"></span>
<% if @resource.url and @resource.needs_provider? %>
<p class="help-block"><%= t(:'.needs_provider') %></p>
<% elsif @resource.url %>
<p class="help-block"><%= t(:'.has_provider') %></p>
<% end %>
</div>
</div>
<div class="form-actions col-md-7 col-sm-7">
<div class="primary-actions">
<%= cancel_link @resource, :back, class: 'btn btn-default' %>
<%= cancel_link @resource, 'javascript:window.close()', class: 'btn btn-default' %>
<%= f.submit nil, class: 'btn btn-primary' %>
</div>
</div>
<% end %>
<% end %>
4 changes: 3 additions & 1 deletion app/views/spotlight/resources/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div id="content" class="col-md-9">
<%= curation_page_title %>
<%= render 'form' %>
<%= render 'form' %>
</div>
12 changes: 10 additions & 2 deletions config/locales/spotlight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ en:
options: "Options"
field:
label: "Display Label"
items_count:
items_count:
one: "%{count} item"
other: "%{count} items"
values_count:
Expand Down Expand Up @@ -234,10 +234,18 @@ en:
feature_pages:
nav_link: Curated Features
resources:
new:
header: "Add Resource"
form:
needs_provider: "Could not find an appropriate importer"
has_provider: "Ready to import"
csv:
header: 'CSV Import'
form:
template: "Download Template"
bookmarklet:
instructions: "Drag this button to the bookmarks toolbar in your web browser"
bookmarklet: "%{application_name} widget"
roles:
index:
title: Site Administration - Users
Expand All @@ -249,7 +257,7 @@ en:
nav_link: "Browse"
index:
header: "Browse"
title: "Curation - Browse"
title: "Curation - Browse"
categories_header: "Browse Categories"
instructions: "Use the Save search button on a search results page to create a new browse category. Select the categories you want to be displayed on the browse landing page. Drag and drop categories to change the order in which they appear on that page."
no_saved_searches: "You can save search results while in curation mode to create browse categories, which will be displayed here."
Expand Down

0 comments on commit 8783f36

Please sign in to comment.