diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb
index a9c5b2f..8bb0f82 100644
--- a/app/views/devise/registrations/edit.html.erb
+++ b/app/views/devise/registrations/edit.html.erb
@@ -115,18 +115,3 @@
<% end %>
-
-
-
-
@@ -77,7 +78,7 @@
diff --git a/app/views/plans/share.html.erb b/app/views/plans/share.html.erb
index 42f6988..3c3f301 100644
--- a/app/views/plans/share.html.erb
+++ b/app/views/plans/share.html.erb
@@ -1,5 +1,5 @@
<%- model_class = Plan -%>
-
+<% javascript('plans/share.js') %>
<%= render :partial => "plan_title", locals: {plan: @plan} %>
@@ -35,7 +35,7 @@
<% else %>
<%= form_for role, url: {controller: :roles, action: :update, id: role.id }, html: {method: :put} do |f| %>
<% end %>
<% end %>
diff --git a/app/views/question_options/_option_fields.html.erb b/app/views/question_options/_option_fields.html.erb
index aa361f3..1d00634 100644
--- a/app/views/question_options/_option_fields.html.erb
+++ b/app/views/question_options/_option_fields.html.erb
@@ -3,5 +3,8 @@
<%= f.number_field :number, in: 1..20, class: "number_field option"%> |
<%= f.text_field :text, as: :string, class: "small_text_field" %> |
<%= f.check_box :is_default %> |
-
<%= f.hidden_field :_destroy %><%= _('Remove') %> |
+
+ <%= f.hidden_field :_destroy %>
+ <%= _('Remove') %>
+ |
diff --git a/app/views/shared/_register_form.html.erb b/app/views/shared/_register_form.html.erb
index ab2f719..1546594 100644
--- a/app/views/shared/_register_form.html.erb
+++ b/app/views/shared/_register_form.html.erb
@@ -1,4 +1,4 @@
-<% javascript "shared/register_form.js" %>
+<% javascript('shared/register_form.js') %>
<%= form_for(resource, :as => "user", :url => registration_path("user"), :htmlb => {:autocomplete =>"off"}, :html => {class: "roadmap-form"}) do |f| %>
diff --git a/config/application.rb b/config/application.rb
index 7d2908a..236abc9 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -79,10 +79,13 @@
config.assets.precompile += %w(roadmap-form.scss)
config.assets.precompile += %w(plans/new_plan.js)
+ config.assets.precompile += %w(plans/edit.js)
+ config.assets.precompile += %w(plans/share.js)
config.assets.precompile += %w(contacts/new_contact.js)
config.assets.precompile += %w(shared/register_form.js)
config.assets.precompile += %w(answers/status.js)
config.assets.precompile += %w(notes/index.js)
+ config.assets.precompile += %w(bootstrap_listeners.js)
config.autoload_paths += %W(#{config.root}/lib)
config.action_controller.include_all_helpers = true
diff --git a/lib/assets/javascripts/admin.js b/lib/assets/javascripts/admin.js
index 7b47b6b..3e2ac45 100644
--- a/lib/assets/javascripts/admin.js
+++ b/lib/assets/javascripts/admin.js
@@ -7,7 +7,45 @@
$( document ).ready(function() {
+ /*----------------
+ Listener for removing a question_option for option_based questions
+ Note the usage of event-delegation approach through the presence of the selector (e.g. .remove-option) which means the handler
+ is ONLY called when the event occurs at .remove-option and has the advantage of processing events from descendant elements (e.g. tr class="options_content")
+ that are added to the document at a later time
+ ------------------*/
+ $('.options_table').on('click','.remove-option', function(e){
+ e.preventDefault();
+ $(this).prev().val(true);
+ $(this).closest('.options_content').hide();
+ });
+ /*----------------
+ Listener for adding a question_option for option_based questions
+ ------------------*/
+ $(".add-option").click(function(e){
+ e.preventDefault();
+ var tbl = $(this).parent().find("table.options_table > tbody.options_tbody"),
+ last = tbl.find("tr:last"),
+ clone = last.clone();
+ nbr = parseInt(last.find(".number_field").val());
+
+ // Update the input field names and ids
+ clone.find("input").each(function(index){
+ $(this).prop("id", $(this).prop("id").replace(/_\d+_/g, "_" + nbr + "_"));
+ $(this).prop("name", $(this).prop("name").replace(/\[\d+\]/g, "[" + nbr + "]"));
+ });
+
+ // Remove the hidden class and make sure the new row is not marked for removal
+ clone.removeClass('hidden');
+ clone.find("[id$=" + nbr + "__destroy]").val(false);
+
+ // Default the other values
+ clone.find("[id$=" + nbr + "_number]").val("" + (nbr + 1));
+ clone.find("[id$=" + nbr + "_text]").val("");
+ clone.find("[id$=" + nbr + "_is_default]").prop("checked", false);
+
+ last.after(clone);
+ });
if($('.in').length > 0) {
if ($('.in .current_question').length > 0) {
$(document.body).animate({
diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js
index 3f45565..432d0b0 100644
--- a/lib/assets/javascripts/application.js
+++ b/lib/assets/javascripts/application.js
@@ -22,173 +22,4 @@
//= require_tree ./locale
//= require gettext/all
//= require jquery-accessible-autocomplet-list-aria.js
-
-
-$( document ).ready(function() {
-
- $(function(){
- $('.dropdown-toggle').dropdown()
- });
-
- $('.accordion-body').on('show', function() {
- var plus = $(this).parent().children(".accordion-heading").children(".accordion-toggle").children(".icon-plus").removeClass("icon-plus").addClass("icon-minus");
- }).on('hide', function(){
- var minus = $(this).parent().children(".accordion-heading").children(".accordion-toggle").children(".icon-minus").removeClass("icon-minus").addClass("icon-plus");
- });
-
- //accordion home page
- $('.accordion-home').on('show', function() {
- var plus = $(this).parent().find(".plus-laranja").removeClass("plus-laranja").addClass("minus-laranja");
- }).on('hide', function(){
- var minus = $(this).parent().find(".minus-laranja").removeClass("minus-laranja").addClass("plus-laranja");
- });
-
- //accordion project details page when project has more than 1 plan
- $('.accordion-project').on('show', function() {
- var plus = $(this).parent().children(".accordion-heading").find(".plus-laranja").removeClass("plus-laranja").addClass("minus-laranja");
- }).on('hide', function(){
- var minus = $(this).parent().children(".accordion-heading").find(".minus-laranja").removeClass("minus-laranja").addClass("plus-laranja");
- });
-
- $('.export-format-selection').click(function(e){
- e.preventDefault();
- if($(this).val() == 'pdf'){
- $('#pdf-format-options').show();
- }else{
- $('#pdf-format-options').hide();
- }
- });
-
- //$('#3-or-4-splash').modal();
-
- $('.typeahead').select2({
- width: "element",
- allowClear: true
- });
-
- $(".help").popover();
-
- $('.has-tooltip').tooltip({
- placement: "right",
- trigger: "focus"
- });
-
- $(".show-edit-toggle").click(function (e) {
- e.preventDefault();
-
- $(".edit-plan-details").toggle();
- $(".show-plan-details").toggle();
- });
-
- $(".toggle-existing-user-access").change(function(){
- $(this).closest("form").submit();
- });
-
- $('#user_organisation_id').on("change", function(e) {
- e.preventDefault();
- var selected_org = $(this).select2("val");
- var other_orgs = $("#other-organisation-name").attr("data-orgs").split(",");
- var index = $.inArray(selected_org, other_orgs);
- if (index > -1) {
- $("#other-organisation-name").show();
- $("#user_other_organisation").focus();
- }
- else {
- $("#other-organisation-name").hide();
- }
- });
-
- $("#other-org-link > a").click(function(e){
- e.preventDefault();
- var other_org = $("#other-organisation-name").attr("data-orgs").split(",");
- $("#user_organisation_id").select2("val", other_org);
- $("#other-org-link").hide();
- $("#user_organisation_id").change();
- });
-
- //alert dialog for unlink Shibbileth account
- $("#unlink-institutional-credentials-dialog").on("show", function(){
- $('.select2-choice').hide();
- });
-
- $("#unlink-shibboleth-cancelled").click(function (){
- $("#unlink-institutional-credentials-dialog").modal("hide");
- $('.select2-choice').show();
- });
-
- $("#unlink-shibboleth-confirmed").click(function (){
- $("#unlink_flag").val('true');
- $("#edit_user").submit();
-
- });
-
- //Question Options
- // ---------------------------------------------------------------------------
- $(".options_table").on("click", ".remove-option", function(e){
- e.preventDefault();
-
- // Mark the option for removal
- $($(this).siblings()[0]).val(true);
-
- // Hide the entire table row and the associated hidden field for the item
- $(this).parent().parent().addClass('hidden');
- });
-
- $(".add-option").click(function(e){
- e.preventDefault();
-
- var tbl = $(this).parent().find("table.options_table > tbody.options_tbody"),
- last = tbl.find("tr:last"),
- clone = last.clone();
- nbr = parseInt(last.find(".number_field").val());
-
- // Update the input field names and ids
- clone.find("input").each(function(index){
- $(this).prop("id", $(this).prop("id").replace(/_\d+_/g, "_" + nbr + "_"));
- $(this).prop("name", $(this).prop("name").replace(/\[\d+\]/g, "[" + nbr + "]"));
- });
-
- // Remove the hidden class and make sure the new row is not marked for removal
- clone.removeClass('hidden');
- clone.find("[id$=" + nbr + "__destroy]").val(false);
-
- // Default the other values
- clone.find("[id$=" + nbr + "_number]").val("" + (nbr + 1));
- clone.find("[id$=" + nbr + "_text]").val("");
- clone.find("[id$=" + nbr + "_is_default]").prop("checked", false);
-
- last.after(clone);
- });
-
- /*$('#continue-to-new').click(function(e){
- var destination = $(this).attr("href");
- var n = destination.lastIndexOf('=');
- destination = decodeURIComponent(destination.substring(n + 1));
- $.post('splash_logs', {destination: destination} );
- $("#3-or-4-splash").modal('hide');
- return false;
- });*/
-
-});
-
-// ---------------------------------------------------------------------------
-function selectItemsFromJsonArray(array, selector, array_of_values, callback){
- var out = [];
-
- if(!Array.isArray(array_of_values)){
- array_of_values = [array_of_values];
- }
-
- for(var i = 0; i < array.length; i++){
- if(array_of_values.indexOf('' + array[i][selector]) >= 0){
- out.push(array[i]);
- }
- }
-
- var selectItemsFromJsonArrayInterval = setInterval(function(){
- if(i >= array.length){
- clearInterval(selectItemsFromJsonArrayInterval);
- callback(out);
- }
- }, 50);
-}
+//= require bootstrap_listeners.js
diff --git a/lib/assets/javascripts/bootstrap_listeners.js b/lib/assets/javascripts/bootstrap_listeners.js
new file mode 100644
index 0000000..409805d
--- /dev/null
+++ b/lib/assets/javascripts/bootstrap_listeners.js
@@ -0,0 +1,23 @@
+$(document).ready(function(){
+ $('.accordion-body').on('show.bs.collapse', function(){
+ $(this).parent().find('.icon-plus').removeClass('icon-plus').addClass('icon-minus');
+ }).on('hide.bs.collapse', function(){
+ $(this).parent().find('.icon-minus').removeClass('icon-minus').addClass('icon-plus');
+ });
+ $('.accordion-home').on('show', function() {
+ $(this).parent().find('.plus-laranja').removeClass('plus-laranja').addClass('minus-laranja');
+ }).on('hide', function(){
+ $(this).parent().find('.minus-laranja').removeClass('minus-laranja').addClass('plus-laranja');
+ });
+ $('.accordion-project').on('show', function() {
+ $(this).parent().find('.plus-laranja').removeClass('plus-laranja').addClass('minus-laranja');
+ }).on('hide', function(){
+ $(this).parent().find('.minus-laranja').removeClass('minus-laranja').addClass('plus-laranja');
+ });
+ // Initialises all tooltips present on a page
+ $('.has-tooltip').tooltip({
+ placement: "right",
+ trigger: "focus"
+ });
+ $(".help").popover();
+});
\ No newline at end of file
diff --git a/lib/assets/javascripts/export_configure.js b/lib/assets/javascripts/export_configure.js
index d05864b..2229eee 100644
--- a/lib/assets/javascripts/export_configure.js
+++ b/lib/assets/javascripts/export_configure.js
@@ -105,4 +105,15 @@
});
});
});
+ /*----------------
+ Listener for select that displays the formatting options (e.g. csv, html, pdf, txt, etc.)
+ ------------------*/
+ $('.export-format-selection').click(function(e){
+ e.preventDefault();
+ if($(this).val() === 'pdf'){
+ $('#pdf-format-options').show();
+ }else{
+ $('#pdf-format-options').hide();
+ }
+ });
});
diff --git a/lib/assets/javascripts/plans/edit.js b/lib/assets/javascripts/plans/edit.js
new file mode 100644
index 0000000..941f1a5
--- /dev/null
+++ b/lib/assets/javascripts/plans/edit.js
@@ -0,0 +1,10 @@
+$(document).ready(function(){
+ /*----------------
+ Listener for click on buttons containing show-edit-toggle class
+ ------------------*/
+ $(".show-edit-toggle").click(function (e) {
+ e.preventDefault();
+ $(".edit-plan-details").toggle();
+ $(".show-plan-details").toggle();
+ });
+});
\ No newline at end of file
diff --git a/lib/assets/javascripts/plans/share.js b/lib/assets/javascripts/plans/share.js
new file mode 100644
index 0000000..3ea4591
--- /dev/null
+++ b/lib/assets/javascripts/plans/share.js
@@ -0,0 +1,9 @@
+$(document).ready(function(){
+ /*----------------
+ Listener for changes in access-level for a plan shared with a user
+ TODO partial update instead of forcing a page reload
+ ------------------*/
+ $(".toggle-access-level").change(function(){
+ $(this).closest('form').submit();
+ });
+});
\ No newline at end of file
diff --git a/lib/assets/javascripts/shared/register_form.js b/lib/assets/javascripts/shared/register_form.js
index 82b077d..0a2be6c 100644
--- a/lib/assets/javascripts/shared/register_form.js
+++ b/lib/assets/javascripts/shared/register_form.js
@@ -4,7 +4,21 @@
var valid_password = false;
var valid_password_confirmation = false;
var valid_accept_terms = false;
-
+ /*----------------
+ Inits select2 for any typeahead class (e.g. at views/shared/_register_form.html.erb)
+ ------------------*/
+ $('.typeahead').select2({
+ width: "element",
+ allowClear: true
+ });
+ // TODO removing once the new create account functionality is in place
+ $("#other-org-link > a").click(function(e){
+ e.preventDefault();
+ var other_org = $("#other-organisation-name").attr("data-orgs").split(",");
+ $("#user_organisation_id").select2("val", other_org);
+ $("#other-org-link").hide();
+ $("#user_organisation_id").change();
+ });
$("#user_email.text_field.reg-input").change(function(){
if (email_regex.test($(this).val())) {
$(this).next().hide();