diff --git a/app/views/phases/_edit_phase.html.erb b/app/views/phases/_edit_phase.html.erb
index fe0edf8..8c989de 100644
--- a/app/views/phases/_edit_phase.html.erb
+++ b/app/views/phases/_edit_phase.html.erb
@@ -12,7 +12,7 @@
+
+ <%#= render partial: 'guidances/guidance_display', locals: {question: question} %>
+
+
\ No newline at end of file
diff --git a/app/views/sections/_edit_section.html.erb b/app/views/sections/_edit_section.html.erb
index 05b6bd1..a3506ea 100644
--- a/app/views/sections/_edit_section.html.erb
+++ b/app/views/sections/_edit_section.html.erb
@@ -10,19 +10,16 @@
<%= f.label(:title, _('Title'), { class: "control-label" }) %>
<%= f.text_field(:title, { class: "form-control", 'aria-required': false, placeholder: _('Enter a title for the section'), 'data-toggle': 'tooltip', title: _('Enter a title for the section')} ) %>
-
<%= f.label(:number, _('Order of display'), class: "control-label") %>
<%= f.number_field(:number, in: 1..15, class: "form-control", 'aria-required': false, 'data-toggle': 'tooltip', title: _('This allows you to order sections.')) %>
-
-
<%= f.button(_('Save'), class: 'btn btn-default', type: "submit") %>
<%= link_to _('Delete'), admin_destroy_section_path(section_id: section.id),
@@ -38,12 +35,14 @@
<% questions = section.questions.order('number') %>
<% if questions.present? %>
<% questions.each do |question| %>
- <% if question.modifiable %>
- <%#= render partial: 'questions/edit_question', locals: {question: question} %>
- <% else %>
- <%#= render partial: 'questions/show_question', locals: {question: question} %>
- <% end %>
- <% if questions.last.id != question.id %>
+
+
">
+ <%= render partial: 'questions/show_question', locals: {question: question} %>
+
+
" style="display: none;">
+ <%= render partial: 'questions/edit_question', locals: {question: question} %>
+
+ <% if questions.last.id == question.id %>
<% end %>
<% end %>
diff --git a/app/views/sections/_show_section.html.erb b/app/views/sections/_show_section.html.erb
index 55930c7..5e15582 100644
--- a/app/views/sections/_show_section.html.erb
+++ b/app/views/sections/_show_section.html.erb
@@ -11,10 +11,14 @@
<% questions = section.questions.order('number') %>
<% if questions.present? %>
<% questions.each do |question| %>
+
+
">
+ <%= render partial: 'questions/show_question', locals: {question: question} %>
+
<% if question.modifiable %>
- <%#= render partial: 'questions/edit_question', locals: {question: question} %>
- <% else %>
- <%#= render partial: 'questions/show_question', locals: {question: question} %>
+
" style="display: none;">
+ <%= render partial: 'questions/edit_question', locals: {question: question} %>
+
<% end %>
<% if questions.last.id != question.id %>
@@ -22,4 +26,4 @@
<% end %>
<% end %>
-
+
\ No newline at end of file
diff --git a/app/views/templates/_edit_template.html.erb b/app/views/templates/_edit_template.html.erb
index 0300ddd..7b18016 100644
--- a/app/views/templates/_edit_template.html.erb
+++ b/app/views/templates/_edit_template.html.erb
@@ -4,11 +4,11 @@
<%= f.label(:title, _('Title'), class: "control-label") %>
<%= f.text_field(:title, class: "form-control", "aria-required": false, 'data-toggle': 'tooltip', title: _('Please enter a title for your template.')) %>
-
+
diff --git a/lib/assets/javascripts/admin.js b/lib/assets/javascripts/admin.js
deleted file mode 100644
index e1e8ea6..0000000
--- a/lib/assets/javascripts/admin.js
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
-**Project: DMPRoadmap
-**Description: This file include all javascript regarding admin interface
-**Copyright: Digital Curation Centre and California Digital Library
-*/
-
-
-$( 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({
- 'scrollTop': $('.in .current_question').offset().top
- }, 1000);
- }
- else {
- $(document.body).animate({
- 'scrollTop': $('.in').offset().top
- }, 1000);
- }
- }
-
- // This handler serves to display/hide default_answer field as well as to display/hide question_options fields
- // depending on the question_format selected
- $('.question_format').change(function(){
- var selected = $(this).val();
- var question_div = $(this).closest('.question-div');
- if(selected === '1' || selected === '2') {
- question_div.find('.ques_format_option').hide();
- question_div.find('.default_answer').show();
- if(selected === '1') { //textarea
- question_div.find('.default_answer_textfield').hide();
- question_div.find('.default_answer_textarea').prev().show()
- }
- else { //textfield
- question_div.find('.default_answer_textarea').prev().hide();
- question_div.find('.default_answer_textfield').show();
- }
- }
- else if(selected === '3' || selected === '4' || selected === '5' || selected === '6') { // option_based
- question_div.find('.default_answer').hide();
- question_div.find('.ques_format_option').show();
- }
- });
-
- //action for show or hide template editing display
- $('#edit_template_button').click(function(e){
- e.preventDefault();
-
- $('#edit_template_div').show();
- $('#show_template_div').hide();
- });
-
-
- //action for show or hide phase display
- $('#edit_phase_button').click(function(e){
- e.preventDefault();
- $('#edit_phase_div').show();
- $('#show_phase_div').hide();
- });
-
- //action to hide the alert to edit a version
- $("#edit-version-confirmed").click(function (e){
- $("#version_edit_alert").modal("hide");
- });
-
- //action to clone/add a version
- $("#clone-version-confirmed").click(function (){
- $("#new_project").submit();
- });
-
- //action for show question editing display
- $('.edit_question_button').click(function(e){
- var q_id = $(this).prev(".question_id").val();
- $('#edit_question_div_'+ q_id).show();
- $('#show_question_div_'+ q_id).hide();
- e.preventDefault();
- });
-
-
- $(".cancel_edit_question").click(function(e){
- var q_id = $(this).prev(".question_id").val();
- $('#edit_question_div_'+ q_id).hide();
- $('#show_question_div_'+ q_id).show();
- e.preventDefault();
- });
-
- //action for adding a new question
- $('.add_question_button').click(function(e){
- var s_id = $(this).prev(".section_id").val();
- $('#add_question_block_div_'+ s_id).show();
- $('#add_question_button_div_'+ s_id).hide();
- e.preventDefault();
-
- });
-
- //if question text area is empty send alert
- $('.new_question_save_button').click(function(e){
- var s_id = $(this).prev(".section_id").val();
- if ($('#new_question_text_'+ s_id).tinymce().getContent() === ''){
- alert(__('Question text is empty, please enter your question.'));
- return false;
- }
- });
-
- //action for cancelling a new question
- $('.cancel_add_new_question').click(function(e){
- var s_id_new = $(this).prev(".section_id_new").val();
- $('#add_question_block_div_'+ s_id_new).hide();
- $('#add_question_button_div_'+ s_id_new).show();
- e.preventDefault();
- });
-
- //action for adding a new section
- $('#add_section_button').click(function(e){
- $('#add_section_block_div').show();
- $('#add_section_button_div').hide();
- e.preventDefault();
- });
-
-
- //action for cancelling a new section
- $('#cancel_add_section').click(function(e){
- $('#add_section_block_div').hide();
- $('#add_section_button_div').show();
- e.preventDefault();
- });
-
- //ANNOTATIONS
- //action for adding a new annotation
- $('.add_annotations_button').click(function(e){
- var q_id = $(this).prev(".question_id").val();
- $('#add_annotations_block_'+ q_id).show();
- $('#add_annotations_button_'+ q_id).hide();
- e.preventDefault();
- });
-
- //cancelling edit of an annotation
- $(".cancel_edit_annotations").click(function(e){
- var q_id = $(this).prev(".question_id").val();
- $('#edit_annotations_div_'+ q_id).hide();
- $('#show_annotations_div_'+ q_id).show();
- e.preventDefault();
- });
-
- //cancelling addition of an annotation
- $(".cancel_add_annotations").click(function(e){
- var q_id = $(this).prev(".question_id").val();
- $('#add_annotations_block_'+ q_id).hide();
- $('#add_annotations_button_'+ q_id).show();
- e.preventDefault();
- });
-
- //edit an annotation
- $('.edit_form_for_annotations').click(function(e){
- var q_id = $(this).prev(".question_id").val();
- $('#edit_annotations_div_'+ q_id).show();
- $('#show_annotations_div_'+ q_id).hide();
- e.preventDefault();
- });
-
- //GUIDANCE
- //action for adding a new guidance next to the question
- $('.add_guidance_button').click(function(e){
- var q_id = $(this).prev(".question_id").val();
- $('#add_guidance_block_'+ q_id).show();
- $('#add_guidance_button_'+ q_id).hide();
- e.preventDefault();
- });
-
- //cancelling edit of guidance next to the question
- $(".cancel_guidance_answer").click(function(e){
- var q_id = $(this).prev(".question_id").val();
- $('#edit_guidance_div_'+ q_id).hide();
- $('#show_guidance_div_'+ q_id).show();
- e.preventDefault();
- });
-
- //edit guidance next to the question
- $('.edit_form_for_guidance').click(function(e){
- var q_id = $(this).prev(".question_id").val();
- $('#edit_guidance_div_'+ q_id).show();
- $('#show_guidance_div_'+ q_id).hide();
- e.preventDefault();
- });
-
- });
-
-
-//remove option when question format is base on a choice
-function remove_object(link){
- $(link).prev("input[type=hidden]").val("1");
- $(link).closest(".options_content").hide();
-
-}
-function add_object(link, association, content) {
- var new_id = new Date().getTime();
- var regexp = new RegExp("new_" + association, "g");
-
- if (association == 'options') {
- $(link).parent().children('.options_table').children('.options_tbody').children('.new_option_before').before(content.replace(regexp, new_id));
- }
-}
-
-// Returns text statistics for the specified editor by id
-function getStats(id) {
- var body = tinymce.get(id).getBody(), text = tinymce.trim(body.innerText || body.textContent);
-
- return {
- chars: text.length
- };
-}
\ No newline at end of file
diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js
index 94e863e..bb948af 100644
--- a/lib/assets/javascripts/application.js
+++ b/lib/assets/javascripts/application.js
@@ -24,10 +24,14 @@
import './views/plans/index';
import './views/plans/new';
import './views/plans/share';
-import './views/questions/index';
-import './views/questions/new';
+import './views/sections/edit';
import './views/sections/index';
import './views/sections/new';
+import './views/questions/edit';
+import './views/questions/index';
+import './views/questions/new';
+import './views/questions/show';
+import './views/question_options/index';
import './views/shared/create_account_form';
import './views/shared/sign_in_form';
import './views/templates/edit';
diff --git a/lib/assets/javascripts/utils/isValidInputType.js b/lib/assets/javascripts/utils/isValidInputType.js
index 5fcfc94..d31550c 100644
--- a/lib/assets/javascripts/utils/isValidInputType.js
+++ b/lib/assets/javascripts/utils/isValidInputType.js
@@ -20,7 +20,8 @@
@param value Number to validate
*/
export const isValidNumber = (value) => {
- if (isString(value)) { // Only if is string value we try to convert to Number
+ if (isString(value)
+ && value.trim().length > 0) { // Only if is non-empty string value we try to convert to Number
// since Number([]), Number(new Date()), Number(null) are converted to zero
return !isNaN(Number(value));
}
diff --git a/lib/assets/javascripts/views/phases/edit.js b/lib/assets/javascripts/views/phases/edit.js
index 6ab9f1e..d3bbefd 100644
--- a/lib/assets/javascripts/views/phases/edit.js
+++ b/lib/assets/javascripts/views/phases/edit.js
@@ -1,9 +1,11 @@
import 'bootstrap-sass/assets/javascripts/bootstrap/collapse';
import expandCollapseAll from '../../utils/expandCollapseAll';
+import { Tinymce } from '../../utils/tinymce';
$(() => {
// Attach handlers for the expand/collapse all accordions
expandCollapseAll();
+ Tinymce.init({ selector: '.phase' });
$('.phase_show_link').on('click', (e) => {
e.preventDefault();
$(e.target).closest('.phase_edit').hide();
diff --git a/lib/assets/javascripts/views/question_options/index.js b/lib/assets/javascripts/views/question_options/index.js
new file mode 100644
index 0000000..fbbfc9f
--- /dev/null
+++ b/lib/assets/javascripts/views/question_options/index.js
@@ -0,0 +1,30 @@
+$(() => {
+ $('.delete_question_option').on('click', (e) => {
+ e.preventDefault();
+ const source = e.target;
+ $(source).closest('[data-attribute="question_option"]').hide();
+ });
+ $('.new_question_option').on('click', (e) => {
+ e.preventDefault();
+ const source = e.target;
+ const last = $(source).closest('[data-attribute="question_options"]').find('[data-attribute="question_option"]').last();
+ const cloned = last.clone(true);
+ const array = $(cloned).find('[id$="_number"]').prop('id').match(/[^\d]*(\d)+[^$]*/);
+ if (array) {
+ const index = Number(array[1]);
+ // Reset values for the new cloned inputs
+ cloned.find(`[id$="${index}_number"]`).val(index + 2);
+ cloned.find(`[id$=${index}_text]`).val('');
+ cloned.find(`[id$=${index}_is_default]`).prop('checked', false);
+ cloned.find(`[id$="${index}__destroy"]`).val(false);
+ cloned.find('input').each((i, el) => {
+ // Rename id and name for the cloned inputs
+ $(el).prop('id', $(el).prop('id').replace(/_\d+_/g, `_${index + 1}_`));
+ $(el).prop('name', $(el).prop('name').replace(/\[\d+\]/g, `[${index + 1}]`));
+ });
+ last.after(cloned);
+ cloned.show();
+ }
+ });
+});
+
diff --git a/lib/assets/javascripts/views/questions/edit.js b/lib/assets/javascripts/views/questions/edit.js
new file mode 100644
index 0000000..2a12c4b
--- /dev/null
+++ b/lib/assets/javascripts/views/questions/edit.js
@@ -0,0 +1,15 @@
+import { Tinymce } from '../../utils/tinymce';
+import ariatiseForm from '../../utils/ariatiseForm';
+import onChangeQuestionFormat from './sharedEventHandlers';
+
+$(() => {
+ Tinymce.init({ selector: '.question' });
+ ariatiseForm({ selector: '.question_form' });
+ $('.edit_question_cancel').on('click', (e) => {
+ e.preventDefault();
+ const questionEdit = $(e.target).closest('.question_edit');
+ questionEdit.hide();
+ questionEdit.parent().find('.question_show').show();
+ });
+ $('[name="question[question_format_id]"]').on('change', onChangeQuestionFormat);
+});
diff --git a/lib/assets/javascripts/views/questions/new.js b/lib/assets/javascripts/views/questions/new.js
index 1bf910c..b26541e 100644
--- a/lib/assets/javascripts/views/questions/new.js
+++ b/lib/assets/javascripts/views/questions/new.js
@@ -1,7 +1,14 @@
+import { Tinymce } from '../../utils/tinymce';
+import ariatiseForm from '../../utils/ariatiseForm';
+import onChangeQuestionFormat from './sharedEventHandlers';
+
$(() => {
+ Tinymce.init({ selector: '.question' });
+ ariatiseForm({ selector: '.question_form' });
$('.new_question_cancel').on('click', (e) => {
const questionNew = $(e.target).closest('.question_new');
questionNew.hide();
questionNew.closest('.row').find('.question_new_link').show();
});
+ $('[name="question[question_format_id]"]').on('change', onChangeQuestionFormat);
});
diff --git a/lib/assets/javascripts/views/questions/sharedEventHandlers.js b/lib/assets/javascripts/views/questions/sharedEventHandlers.js
new file mode 100644
index 0000000..e29cfea
--- /dev/null
+++ b/lib/assets/javascripts/views/questions/sharedEventHandlers.js
@@ -0,0 +1,32 @@
+const onChangeQuestionFormat = (e) => {
+ const source = e.target;
+ const selected = source.value;
+ const defaultValue = $(source).closest('form').find('[data-attribute="default_value"]');
+ const questionOptions = $(source).closest('form').find('[data-attribute="question_options"]');
+ switch (selected) {
+ case '1':
+ questionOptions.hide();
+ defaultValue.show();
+ defaultValue.find('[data-attribute="textfield"]').hide();
+ defaultValue.find('[data-attribute="textarea"]').show();
+ break;
+ case '2':
+ questionOptions.hide();
+ defaultValue.show();
+ defaultValue.find('[data-attribute="textarea"]').hide();
+ defaultValue.find('[data-attribute="textfield"]').show();
+ break;
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ defaultValue.hide();
+ questionOptions.show();
+ break;
+ default :
+ break;
+ }
+};
+
+export { onChangeQuestionFormat as default };
+
diff --git a/lib/assets/javascripts/views/questions/show.js b/lib/assets/javascripts/views/questions/show.js
new file mode 100644
index 0000000..668c007
--- /dev/null
+++ b/lib/assets/javascripts/views/questions/show.js
@@ -0,0 +1,8 @@
+$(() => {
+ $('.question_edit_link').on('click', (e) => {
+ const source = e.target;
+ const target = $(source).attr('href');
+ $(source).closest('.question_show').hide();
+ $(target).show();
+ });
+});
diff --git a/lib/assets/javascripts/views/sections/edit.js b/lib/assets/javascripts/views/sections/edit.js
new file mode 100644
index 0000000..44a1faa
--- /dev/null
+++ b/lib/assets/javascripts/views/sections/edit.js
@@ -0,0 +1,5 @@
+import { Tinymce } from '../../utils/tinymce';
+
+$(() => {
+ Tinymce.init({ selector: '.section' });
+});
diff --git a/lib/assets/javascripts/views/templates/edit.js b/lib/assets/javascripts/views/templates/edit.js
index f98eb3d..eb4de0d 100644
--- a/lib/assets/javascripts/views/templates/edit.js
+++ b/lib/assets/javascripts/views/templates/edit.js
@@ -1,4 +1,7 @@
+import { Tinymce } from '../../utils/tinymce';
+
$(() => {
+ Tinymce.init({ selector: '.template' });
$('.template_show_link').on('click', (e) => {
e.preventDefault();
$(e.target).closest('.template_edit').hide();