From b4693de1ef84c0281aceb0b3f814e5241af333ec Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Tue, 1 Sep 2015 17:04:48 -0400 Subject: [PATCH 1/9] [HPT-570] Pop up a new window --- .../javascripts/sibling_popup.js.coffee | 3 ++ app/assets/stylesheets/sibling_popup.css.scss | 3 ++ app/controllers/sibling_popup_controller.rb | 4 +++ app/helpers/sibling_popup_helper.rb | 2 ++ app/views/pages/show.html.erb | 1 + app/views/sibling_popup/show.html.erb | 19 ++++++++++++ config/application.rb | 1 + config/object_profiles.yml | 4 +++ config/routes.rb | 2 ++ lib/object_profile.rb | 30 +++++++++++++++++++ .../sibling_popup_controller_spec.rb | 12 ++++++++ spec/helpers/sibling_popup_helper_spec.rb | 15 ++++++++++ .../views/sibling_popup/show.html.erb_spec.rb | 5 ++++ 13 files changed, 101 insertions(+) create mode 100644 app/assets/javascripts/sibling_popup.js.coffee create mode 100644 app/assets/stylesheets/sibling_popup.css.scss create mode 100644 app/controllers/sibling_popup_controller.rb create mode 100644 app/helpers/sibling_popup_helper.rb create mode 100644 app/views/sibling_popup/show.html.erb create mode 100644 config/object_profiles.yml create mode 100644 lib/object_profile.rb create mode 100644 spec/controllers/sibling_popup_controller_spec.rb create mode 100644 spec/helpers/sibling_popup_helper_spec.rb create mode 100644 spec/views/sibling_popup/show.html.erb_spec.rb diff --git a/app/assets/javascripts/sibling_popup.js.coffee b/app/assets/javascripts/sibling_popup.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/sibling_popup.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/sibling_popup.css.scss b/app/assets/stylesheets/sibling_popup.css.scss new file mode 100644 index 0000000..3f175ad --- /dev/null +++ b/app/assets/stylesheets/sibling_popup.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sibling_popup controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/sibling_popup_controller.rb b/app/controllers/sibling_popup_controller.rb new file mode 100644 index 0000000..c59bb95 --- /dev/null +++ b/app/controllers/sibling_popup_controller.rb @@ -0,0 +1,4 @@ +class SiblingPopupController < ApplicationController + def show + end +end diff --git a/app/helpers/sibling_popup_helper.rb b/app/helpers/sibling_popup_helper.rb new file mode 100644 index 0000000..3b12540 --- /dev/null +++ b/app/helpers/sibling_popup_helper.rb @@ -0,0 +1,2 @@ +module SiblingPopupHelper +end diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb index 0b37bdf..acf7e8e 100644 --- a/app/views/pages/show.html.erb +++ b/app/views/pages/show.html.erb @@ -7,6 +7,7 @@

<%= notice %>

Page <%= @page.id %>

+ diff --git a/app/views/sibling_popup/show.html.erb b/app/views/sibling_popup/show.html.erb new file mode 100644 index 0000000..71b5bb4 --- /dev/null +++ b/app/views/sibling_popup/show.html.erb @@ -0,0 +1,19 @@ +

SiblingPopup#show

+

Find me in app/views/sibling_popup/show.html.erb

+ +
+ Add a + + sibling. + + Add before this + Add after this + Cancel +
diff --git a/config/application.rb b/config/application.rb index 8a290fd..48ef12f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -13,6 +13,7 @@ class Application < Rails::Application g.test_framework :rspec, :spec => true end + config.autoload_paths << Rails.root.join("lib") # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers diff --git a/config/object_profiles.yml b/config/object_profiles.yml new file mode 100644 index 0000000..ca49eb3 --- /dev/null +++ b/config/object_profiles.yml @@ -0,0 +1,4 @@ +collection: +page: +paged: +section: \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index fa34089..85eb938 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ PagedMedia::Application.routes.draw do + get 'sibling_popup/show' + resources :pages resources :collections resources :sections diff --git a/lib/object_profile.rb b/lib/object_profile.rb new file mode 100644 index 0000000..fa1014b --- /dev/null +++ b/lib/object_profile.rb @@ -0,0 +1,30 @@ +# Represent a profile for a type of Node. +# At the moment all it does (correctly) is to list the profiles, which are +# named (and eventually described) in config/object_profiles.yaml +#-- +# Copyright (c) 2015 Indiana University +# All rights reserved. + +require 'yaml' + +class ObjectProfile + @@PROFILES = YAML.load_file('config/object_profiles.yml') + + private_class_method :new + + def name + NAME + end + + # Enumerate profile names and bodies for a block, as if this were a Hash. + def self.each + @@PROFILES.each do |name, profile| + yield name, profile + end + end + + # Return the body of the named profile. + def self.find(name) + @@PROFILES[name] + end +end \ No newline at end of file diff --git a/spec/controllers/sibling_popup_controller_spec.rb b/spec/controllers/sibling_popup_controller_spec.rb new file mode 100644 index 0000000..5ccee09 --- /dev/null +++ b/spec/controllers/sibling_popup_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe SiblingPopupController do + + describe "GET 'show'" do + it "returns http success" do + get 'show' + response.should be_success + end + end + +end diff --git a/spec/helpers/sibling_popup_helper_spec.rb b/spec/helpers/sibling_popup_helper_spec.rb new file mode 100644 index 0000000..f1afbe6 --- /dev/null +++ b/spec/helpers/sibling_popup_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the SiblingPopupHelper. For example: +# +# describe SiblingPopupHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +describe SiblingPopupHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/sibling_popup/show.html.erb_spec.rb b/spec/views/sibling_popup/show.html.erb_spec.rb new file mode 100644 index 0000000..f5d2833 --- /dev/null +++ b/spec/views/sibling_popup/show.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "sibling_popup/show.html.erb" do + pending "add some examples to (or delete) #{__FILE__}" +end From 382bb37c915723f3f8702c585e6a6b1e58554e29 Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Thu, 3 Sep 2015 09:45:18 -0400 Subject: [PATCH 2/9] [HPT-570] Clean layout for simple popups --- app/controllers/sibling_popup_controller.rb | 3 +++ app/views/layouts/popup.html.erb | 12 ++++++++++++ app/views/sibling_popup/show.html.erb | 16 ++++++++-------- 3 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 app/views/layouts/popup.html.erb diff --git a/app/controllers/sibling_popup_controller.rb b/app/controllers/sibling_popup_controller.rb index c59bb95..7c55843 100644 --- a/app/controllers/sibling_popup_controller.rb +++ b/app/controllers/sibling_popup_controller.rb @@ -1,4 +1,7 @@ class SiblingPopupController < ApplicationController + layout 'popup' + def show end + end diff --git a/app/views/layouts/popup.html.erb b/app/views/layouts/popup.html.erb new file mode 100644 index 0000000..0fc212a --- /dev/null +++ b/app/views/layouts/popup.html.erb @@ -0,0 +1,12 @@ + + + + <%= @title || 'PMP' %> + <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> + <%= javascript_include_tag "application", "data-turbolinks-track" => true %> + <%= csrf_meta_tags %> + + + <%= yield :layout %> + + diff --git a/app/views/sibling_popup/show.html.erb b/app/views/sibling_popup/show.html.erb index 71b5bb4..efcf4ef 100644 --- a/app/views/sibling_popup/show.html.erb +++ b/app/views/sibling_popup/show.html.erb @@ -1,5 +1,5 @@ -

SiblingPopup#show

-

Find me in app/views/sibling_popup/show.html.erb

+<% @title = 'Create a new sibling'%> +

<%= @title%>

Add a @@ -10,10 +10,10 @@ <% end %> sibling. - - Add before this - Add after this - Cancel + +
+ + + +
From f0b0991aee295129b3aa564d93388532978d56ae Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Fri, 4 Sep 2015 17:04:04 -0400 Subject: [PATCH 3/9] [HPT-570] Make the popup show a form depending on the type of sibling to be created. --- app/assets/javascripts/sibling_popup.js | 8 ++++++++ app/assets/javascripts/sibling_popup.js.coffee | 3 --- app/assets/stylesheets/sibling_popup.css.scss | 2 ++ app/views/layouts/popup.html.erb | 2 +- app/views/pages/show.html.erb | 2 +- app/views/sibling_popup/show.html.erb | 18 ++++++++++++++++-- 6 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 app/assets/javascripts/sibling_popup.js delete mode 100644 app/assets/javascripts/sibling_popup.js.coffee diff --git a/app/assets/javascripts/sibling_popup.js b/app/assets/javascripts/sibling_popup.js new file mode 100644 index 0000000..0068d56 --- /dev/null +++ b/app/assets/javascripts/sibling_popup.js @@ -0,0 +1,8 @@ +function show_form(type) { + divs = document.getElementsByClassName('popup_alternate_div'); + for (i = 0; i < divs.length; i++) { + divs[i].style.display = 'none'; + } + + document.getElementById('form_for_' + type).style.display = 'inherit'; +}; \ No newline at end of file diff --git a/app/assets/javascripts/sibling_popup.js.coffee b/app/assets/javascripts/sibling_popup.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/sibling_popup.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/sibling_popup.css.scss b/app/assets/stylesheets/sibling_popup.css.scss index 3f175ad..5c10678 100644 --- a/app/assets/stylesheets/sibling_popup.css.scss +++ b/app/assets/stylesheets/sibling_popup.css.scss @@ -1,3 +1,5 @@ // Place all the styles related to the sibling_popup controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +body.popup { padding-top: 0; } diff --git a/app/views/layouts/popup.html.erb b/app/views/layouts/popup.html.erb index 0fc212a..f5a26c4 100644 --- a/app/views/layouts/popup.html.erb +++ b/app/views/layouts/popup.html.erb @@ -6,7 +6,7 @@ <%= javascript_include_tag "application", "data-turbolinks-track" => true %> <%= csrf_meta_tags %> - + <%= yield :layout %> diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb index acf7e8e..3c9be6a 100644 --- a/app/views/pages/show.html.erb +++ b/app/views/pages/show.html.erb @@ -7,7 +7,7 @@

<%= notice %>

Page <%= @page.id %>

- + diff --git a/app/views/sibling_popup/show.html.erb b/app/views/sibling_popup/show.html.erb index efcf4ef..12f8c50 100644 --- a/app/views/sibling_popup/show.html.erb +++ b/app/views/sibling_popup/show.html.erb @@ -3,17 +3,31 @@
Add a - <% ObjectProfile.each do |name, profile| %> <% end %> sibling. - +
+
+ +<% objects = {} %> +<% ObjectProfile.each do |p_name, profile| %> + <% next if p_name.eql?('section') %> + +<% end %> From 7b394ae36bb92470419ce8607634c741e249dc4e Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Fri, 11 Sep 2015 14:26:06 -0400 Subject: [PATCH 4/9] [HPT-570 Extract to-be-common logic into the popup script document, move the control up, make it an icon not a button. --- app/assets/javascripts/sibling_popup.js | 7 ++++++- app/views/pages/show.html.erb | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/sibling_popup.js b/app/assets/javascripts/sibling_popup.js index 0068d56..b49d838 100644 --- a/app/assets/javascripts/sibling_popup.js +++ b/app/assets/javascripts/sibling_popup.js @@ -5,4 +5,9 @@ function show_form(type) { } document.getElementById('form_for_' + type).style.display = 'inherit'; -}; \ No newline at end of file +}; + +function show_sibling_popup() { + window.open("/sibling_popup/show", "_blank", + "location=no,menubar=no,status=no,toolbar=no,height=300,width=400"); +} diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb index 3c9be6a..877d278 100644 --- a/app/views/pages/show.html.erb +++ b/app/views/pages/show.html.erb @@ -4,10 +4,12 @@
<%= render_breadcrumbs %> +

<%= notice %>

Page <%= @page.id %>

- From e01b3d2c9455e1b8d0d396851f7b2b0e0251b480 Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Tue, 15 Sep 2015 16:58:49 -0400 Subject: [PATCH 5/9] [HPT-570] Try just redirecting to the existing object New pages --- app/assets/javascripts/sibling_popup.js | 16 ++++++++++++++-- app/views/pages/show.html.erb | 2 +- app/views/sibling_popup/show.html.erb | 23 ++++++----------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/sibling_popup.js b/app/assets/javascripts/sibling_popup.js index b49d838..81431cf 100644 --- a/app/assets/javascripts/sibling_popup.js +++ b/app/assets/javascripts/sibling_popup.js @@ -1,3 +1,5 @@ +// Run this in the dialog popup to make a specific object type's form visible. +// FIXME defunct function show_form(type) { divs = document.getElementsByClassName('popup_alternate_div'); for (i = 0; i < divs.length; i++) { @@ -7,7 +9,17 @@ function show_form(type) { document.getElementById('form_for_' + type).style.display = 'inherit'; }; -function show_sibling_popup() { - window.open("/sibling_popup/show", "_blank", +// Run this in the parent window to create the dialog popup. +function show_sibling_popup(parent, prev_sib, next_sib) { + window.open("/sibling_popup/show?parent=" + parent + "&prev_sib=" + prev_sib + "next_sib=" + next_sib, + "_blank", "location=no,menubar=no,status=no,toolbar=no,height=300,width=400"); } + +// Run this in the dialog popup to redirect the parent window to a new-object page. +function redirect_parent(type, parent, prev_sib, next_sib) { + opener.location=(type + "s/new" + + "?parent=" + parent + + "&prev_sib=" + prev_sib + + "&next_sib=" + next_sib); +} diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb index 877d278..07d6481 100644 --- a/app/views/pages/show.html.erb +++ b/app/views/pages/show.html.erb @@ -5,7 +5,7 @@
<%= render_breadcrumbs %>

<%= notice %>

diff --git a/app/views/sibling_popup/show.html.erb b/app/views/sibling_popup/show.html.erb index 12f8c50..65e4163 100644 --- a/app/views/sibling_popup/show.html.erb +++ b/app/views/sibling_popup/show.html.erb @@ -3,7 +3,7 @@
Add a - <% ObjectProfile.each do |name, profile| %> @@ -12,22 +12,11 @@ sibling.
- - - + // What's "this"? "selected"? + +
- -<% objects = {} %> -<% ObjectProfile.each do |p_name, profile| %> - <% next if p_name.eql?('section') %> - -<% end %> From c353618324afa0c13e445350465e6f5276e81150 Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Tue, 15 Sep 2015 21:21:00 -0400 Subject: [PATCH 6/9] Work out how to identify selection with Javascript --- app/assets/javascripts/sibling_popup.js | 9 +++++++++ app/views/sibling_popup/show.html.erb | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/sibling_popup.js b/app/assets/javascripts/sibling_popup.js index 81431cf..f9701d2 100644 --- a/app/assets/javascripts/sibling_popup.js +++ b/app/assets/javascripts/sibling_popup.js @@ -23,3 +23,12 @@ function redirect_parent(type, parent, prev_sib, next_sib) { + "&prev_sib=" + prev_sib + "&next_sib=" + next_sib); } + +// Extract value of a Select element. +function get_select_value(id) { + selector = Document.getElementById(id); + // TODO check null selector + index = selector.selectedIndex; + // TODO check no selection + return selector.options[index].value; +} diff --git a/app/views/sibling_popup/show.html.erb b/app/views/sibling_popup/show.html.erb index 65e4163..5b83cd4 100644 --- a/app/views/sibling_popup/show.html.erb +++ b/app/views/sibling_popup/show.html.erb @@ -13,9 +13,11 @@
// What's "this"? "selected"? + onclick='redirect_parent(get_select_value("objectType"), this.parent, this.prev_sib, this); // What is "this"? + window.close();'/> + onclick='redirect_parent(get_select_value("objectType"), this.parent, this, this.next_sib); + window.close();'/>
From e5f757bc311dbe1bc1aedcf925cbc5e2ab566c34 Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Wed, 16 Sep 2015 17:03:51 -0400 Subject: [PATCH 7/9] [HPT-570] Actually redirect the main page and fill in fields. --- app/assets/javascripts/sibling_popup.js | 22 +++++++------------- app/controllers/pages_controller.rb | 3 +++ app/controllers/sibling_popup_controller.rb | 1 + app/views/pages/show.html.erb | 2 +- app/views/sibling_popup/show.html.erb | 23 ++++++++++++++------- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/sibling_popup.js b/app/assets/javascripts/sibling_popup.js index f9701d2..1736dad 100644 --- a/app/assets/javascripts/sibling_popup.js +++ b/app/assets/javascripts/sibling_popup.js @@ -1,32 +1,24 @@ -// Run this in the dialog popup to make a specific object type's form visible. -// FIXME defunct -function show_form(type) { - divs = document.getElementsByClassName('popup_alternate_div'); - for (i = 0; i < divs.length; i++) { - divs[i].style.display = 'none'; - } - - document.getElementById('form_for_' + type).style.display = 'inherit'; -}; +// Copyright (c) 2015 Indiana University +// All rights reserved. // Run this in the parent window to create the dialog popup. -function show_sibling_popup(parent, prev_sib, next_sib) { - window.open("/sibling_popup/show?parent=" + parent + "&prev_sib=" + prev_sib + "next_sib=" + next_sib, +function show_sibling_popup(parent, prev_sib, next_sib, old_sib) { + window.open("/sibling_popup/show?parent=" + parent + "&prev_sib=" + prev_sib + "&next_sib=" + next_sib + "&old_sib=" + old_sib, "_blank", "location=no,menubar=no,status=no,toolbar=no,height=300,width=400"); } // Run this in the dialog popup to redirect the parent window to a new-object page. function redirect_parent(type, parent, prev_sib, next_sib) { - opener.location=(type + "s/new" + opener.location.pathname = type + "s/new" + "?parent=" + parent + "&prev_sib=" + prev_sib - + "&next_sib=" + next_sib); + + "&next_sib=" + next_sib; } // Extract value of a Select element. function get_select_value(id) { - selector = Document.getElementById(id); + selector = document.getElementById(id); // TODO check null selector index = selector.selectedIndex; // TODO check no selection diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 2a9c76e..45b345e 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -25,6 +25,9 @@ def new @page = Page.new session[:came_from] = :page @page = Page.new(params[:page]) + @page.parent = params[:parent] if params[:parent] + @page.prev_sib = params[:prev_sib] if params[:prev_sib] + @page.next_sib = params[:next_sib] if params[:next_sib] add_breadcrumb "Create Page" end diff --git a/app/controllers/sibling_popup_controller.rb b/app/controllers/sibling_popup_controller.rb index 7c55843..9c9f4cf 100644 --- a/app/controllers/sibling_popup_controller.rb +++ b/app/controllers/sibling_popup_controller.rb @@ -2,6 +2,7 @@ class SiblingPopupController < ApplicationController layout 'popup' def show + # we have params['query_param_name'] available here end end diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb index 07d6481..dcc46ad 100644 --- a/app/views/pages/show.html.erb +++ b/app/views/pages/show.html.erb @@ -5,7 +5,7 @@
<%= render_breadcrumbs %>

<%= notice %>

diff --git a/app/views/sibling_popup/show.html.erb b/app/views/sibling_popup/show.html.erb index 5b83cd4..ebc7e30 100644 --- a/app/views/sibling_popup/show.html.erb +++ b/app/views/sibling_popup/show.html.erb @@ -3,7 +3,9 @@
Add a - <% ObjectProfile.each do |name, profile| %> @@ -12,13 +14,18 @@ sibling.
- - - + <% p params %> + + +
From 1547a670d17f930a7ef87305c5b9dc41e7abafc9 Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Thu, 17 Sep 2015 09:36:46 -0400 Subject: [PATCH 8/9] [HPT-570] Fix bug to make the popup close; remove debug print. --- app/views/sibling_popup/show.html.erb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/views/sibling_popup/show.html.erb b/app/views/sibling_popup/show.html.erb index ebc7e30..38dc3fc 100644 --- a/app/views/sibling_popup/show.html.erb +++ b/app/views/sibling_popup/show.html.erb @@ -1,11 +1,10 @@ <% @title = 'Create a new sibling'%>

<%= @title%>

-
+ Add a Date: Thu, 17 Sep 2015 10:40:59 -0400 Subject: [PATCH 9/9] [HPT-570] Extract big, complex, multi-line event scripts to local functions and tidy up. --- app/views/sibling_popup/show.html.erb | 31 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/app/views/sibling_popup/show.html.erb b/app/views/sibling_popup/show.html.erb index 38dc3fc..9247ab8 100644 --- a/app/views/sibling_popup/show.html.erb +++ b/app/views/sibling_popup/show.html.erb @@ -1,10 +1,27 @@ + + <% @title = 'Create a new sibling'%>

<%= @title%>

Add a - + +