diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 02c9678..71d9542 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -139,12 +139,17 @@ }); //Question Options - // --------------------------------------------------- - $(".remove-option").click(function(e){ + // ------------------------------------------------------------------------------------ + $(".options_table").on("click", ".remove-option", function(e){ e.preventDefault(); - $(this).parent().parent().remove(); + + // 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 another option to the question's options + $(".add-option").click(function(e){ e.preventDefault(); @@ -153,17 +158,20 @@ clone = last.clone(); nbr = parseInt(last.find(".number_field").val()); + // Update the input field names and ids clone.find("input").each(function(index){ - if($(this).hasClass("number_field")){ - $(this).val("" + (nbr + 1)).prop("value", nbr + 1); - - }else if($(this).hasClass("small_text_field")){ - $(this).val(""); - } - $(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); }); diff --git a/app/assets/stylesheets/admin.css.less b/app/assets/stylesheets/admin.css.less index 002f953..958bb3e 100644 --- a/app/assets/stylesheets/admin.css.less +++ b/app/assets/stylesheets/admin.css.less @@ -894,6 +894,11 @@ .question_options_popover{ padding-left: 12px; } + .remove-option { + color: @orange_colour; + text-decoration: underline; + cursor: pointer; + } } .border_bottom{ diff --git a/app/controllers/dmptemplates_controller.rb b/app/controllers/dmptemplates_controller.rb index f6edfeb..97980e3 100644 --- a/app/controllers/dmptemplates_controller.rb +++ b/app/controllers/dmptemplates_controller.rb @@ -296,16 +296,11 @@ def admin_cloneversion if user_signed_in? && current_user.is_org_admin? then @old_version = Version.find(params[:version_id]) - -puts "WE ARE HERE BEFORE THE CLONE!!!!!!!!!" - @version = @old_version.amoeba_dup @phase = @version.phase respond_to do |format| -puts "WE ARE HERE BEFORE THE SAVE!!!!!!!!!" - if @version.save format.html { redirect_to admin_phase_dmptemplate_path(@phase, :version_id => @version.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } format.json { head :no_content } @@ -421,6 +416,10 @@ @phase = @version.phase respond_to do |format| + + +puts "PARAMS: #{params[:question]}" + if @question.update_attributes(params[:question]) format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } format.json { head :no_content }