Skip to content
Open
26 changes: 26 additions & 0 deletions app/assets/javascripts/sibling_popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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, 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.pathname = type + "s/new"
+ "?parent=" + parent
+ "&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;
}
5 changes: 5 additions & 0 deletions app/assets/stylesheets/sibling_popup.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +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; }
3 changes: 3 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions app/controllers/sibling_popup_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class SiblingPopupController < ApplicationController
layout 'popup'

def show
# we have params['query_param_name'] available here
end

end
2 changes: 2 additions & 0 deletions app/helpers/sibling_popup_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SiblingPopupHelper
end
12 changes: 12 additions & 0 deletions app/views/layouts/popup.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title><%= @title || 'PMP' %></title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body class='popup'>
<%= yield :layout %>
</body>
</html>
3 changes: 3 additions & 0 deletions app/views/pages/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

<div id="content" class="span9">
<%= render_breadcrumbs %>
<i class='fa fa-cog fa-2x'
onclick="show_sibling_popup('<%= @page.parent %>', '<%= @page.prev_sib %>', '<%= @page.next_sib %>', '<%= @page.id %>');"
style='cursor: pointer; float: right;'></i>
<p id="notice"><%= notice %></p>

<h1>Page <%= @page.id %></h1>
Expand Down
38 changes: 38 additions & 0 deletions app/views/sibling_popup/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script type='application/javascript'>
function new_before() {
redirect_parent(get_select_value('objectType'),
'<%=params[%q/parent/]%>',
'<%=params[%q/prev_sib/]%>',
'<%=params[%q/old_sib/]%>');
}

function new_after() {
redirect_parent(get_select_value('objectType'),
'<%=params[%q/parent/]%>',
'<%=params[%q/old_sib/]%>',
'<%=params[%q/next_sib/]%>');
}
</script>

<% @title = 'Create a new sibling'%>
<h1><%= @title%></h1>

<form onsubmit='window.close();'>
Add a
<select id='objectType'
onchange='document.getElementById("before").disabled=false;
document.getElementById("after").disabled=false;'>
<option disabled='disabled' selected='selected'>Select</option>
<% ObjectProfile.each do |name, profile| %>
<option value='<%= name %>'><%= name %></option>
<% end %>
</select>
sibling.

<div>
<input id='before' type='submit' value='Add before this' disabled='true' onclick="new_before();"/>
<input id='after' type='submit' value='Add after this' disabled='true' onclick="new_after();"/>
<input type='submit' value='Cancel'/>
</div>

</form>
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/object_profiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
collection:
page:
paged:
section:
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PagedMedia::Application.routes.draw do
get 'sibling_popup/show'

resources :pages
resources :collections
resources :sections
Expand Down
30 changes: 30 additions & 0 deletions lib/object_profile.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions spec/controllers/sibling_popup_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions spec/helpers/sibling_popup_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions spec/views/sibling_popup/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe "sibling_popup/show.html.erb" do
pending "add some examples to (or delete) #{__FILE__}"
end