diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index c53052f..e1e0f97 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -454,12 +454,6 @@ $(link).closest(".options_content").hide(); } -$(".remove-option").click(function(e){ - e.preventDefault(); - remove_object($(this).parent()); -}); - - function add_object(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g"); @@ -469,7 +463,6 @@ } } - // 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); diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 1a02b4a..02c9678 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -16,7 +16,7 @@ //= require v1.js //= require select2.min.js //= require jquery.placeholder.js -//= require turbolinks +//= require tinymce-jquery //= require i18n //= require i18n/translations @@ -138,22 +138,36 @@ }); + //Question Options + // --------------------------------------------------- + $(".remove-option").click(function(e){ + e.preventDefault(); + $(this).parent().parent().remove(); + }); // Add another option to the question's options $(".add-option").click(function(e){ e.preventDefault(); - - var tbl = $(this).parent().find("table.options_table > tbody"), + + var tbl = $(this).parent().find("table.options_table > tbody.options_tbody"), last = tbl.find("tr:last"), - clone = last.clone(); - - clone.find(".number_field").val(parseInt(last.find(".number_field").val()) + 1); - clone.find(".small_text_field").val(""); - clone.find("input[type='checkbox']").prop("checked", false); + clone = last.clone(); + nbr = parseInt(last.find(".number_field").val()); + + 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 + "]")); + }); last.after(clone); }); - /*$('#continue-to-new').click(function(e){ var destination = $(this).attr("href"); var n = destination.lastIndexOf('='); diff --git a/app/controllers/dmptemplates_controller.rb b/app/controllers/dmptemplates_controller.rb index 7e72cd1..f6edfeb 100644 --- a/app/controllers/dmptemplates_controller.rb +++ b/app/controllers/dmptemplates_controller.rb @@ -295,11 +295,17 @@ #clone a version of a template def admin_cloneversion if user_signed_in? && current_user.is_org_admin? then - @old_version = Version.find(params[:version_id]) + @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 } @@ -392,7 +398,6 @@ @question.guidance = params["new-question-guidance"] @question.default_value = params["new-question-default-value"] - respond_to do |format| if @question.save format.html { redirect_to admin_phase_dmptemplate_path(:id => @question.section.version.phase_id, :version_id => @question.section.version_id, :section_id => @question.section_id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } @@ -500,4 +505,67 @@ end end +# GUIDANCES + + #create a guidance + def admin_createguidance + if user_signed_in? && current_user.is_org_admin? then + @question = Question.find(params[:question][:id]) + @guidance = Guidance.new(params[:guidance]) + @guidance.question_id = @question.id + #@question.guidance = params["new-question-guidance"] + #@question.default_value = params["new-question-default-value"] + + + respond_to do |format| + if @guidance.save + format.html { redirect_to admin_phase_dmptemplate_path(:id => @question.section.version.phase_id, :version_id => @question.section.version_id, :section_id => @question.section_id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } + format.json { head :no_content } + else + format.html { render action: "admin_phase" } + format.json { render json: @guidance.errors, status: :unprocessable_entity } + end + end + end + end + + #update a guidance of a template + def admin_updateguidance + if user_signed_in? && current_user.is_org_admin? then + @question = Question.find(params[:id]) + @question.guidance = params["question-guidance-#{params[:id]}"] + @question.default_value = params["question-default-value-#{params[:id]}"] + @section = @question.section + @version = @section.version + @phase = @version.phase + + respond_to do |format| + 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 } + else + format.html { render action: "admin_phase" } + format.json { render json: @question.errors, status: :unprocessable_entity } + end + end + end + end + + #delete a version, sections and guidance + def admin_destroyguidance + if user_signed_in? && current_user.is_org_admin? then + @question = Question.find(params[:question_id]) + @section = @question.section + @version = @section.version + @phase = @version.phase + @question.destroy + + respond_to do |format| + format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } + format.json { head :no_content } + end + end + end + + end diff --git a/app/models/answer.rb b/app/models/answer.rb index 279f038..7c2e4dd 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -4,8 +4,9 @@ belongs_to :question belongs_to :user belongs_to :plan - accepts_nested_attributes_for :question - accepts_nested_attributes_for :plan + +# accepts_nested_attributes_for :question +# accepts_nested_attributes_for :plan has_and_belongs_to_many :options, join_table: "answers_options" diff --git a/app/models/dmptemplate.rb b/app/models/dmptemplate.rb index 0e2aac4..e11ca4e 100644 --- a/app/models/dmptemplate.rb +++ b/app/models/dmptemplate.rb @@ -1,6 +1,7 @@ class Dmptemplate < ActiveRecord::Base - attr_accessible :organisation_id, :description, :published, :title, :user_id, :locale, :is_default, :guidance_group_ids, :as => [:default, :admin] + attr_accessible :id, :organisation_id, :description, :published, :title, :user_id, :locale, + :is_default, :guidance_group_ids, :as => [:default, :admin] #associations between tables has_many :phases diff --git a/app/models/option.rb b/app/models/option.rb index 442dbdf..09aedaa 100644 --- a/app/models/option.rb +++ b/app/models/option.rb @@ -3,11 +3,11 @@ #associations between tables belongs_to :question - has_many :option_warnings, :dependent => :destroy - has_and_belongs_to_many :answers, join_table: "answers_options" + has_many :option_warnings, :dependent => :destroy + + has_and_belongs_to_many :answers, join_table: "answers_options" attr_accessible :text, :question_id, :is_default, :number, :as => [:default, :admin] - def to_s "#{text}" diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 0aa0c88..7dcac35 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -15,7 +15,7 @@ belongs_to :parent, :class_name => 'Organisation' has_many :children, :class_name => 'Organisation', :foreign_key => 'parent_id' - accepts_nested_attributes_for :organisation_type +# accepts_nested_attributes_for :organisation_type accepts_nested_attributes_for :dmptemplates attr_accessible :abbreviation, :banner_text, :description, :domain, :logo_file_name, :name, :stylesheet_file_id, :target_url, :organisation_type_id, :wayfless_entity, :parent_id, :sort_name diff --git a/app/models/phase.rb b/app/models/phase.rb index 4f18a8e..6cb09ba 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -12,11 +12,11 @@ has_many :versions, :dependent => :destroy has_many :sections, :through => :versions, :dependent => :destroy - has_many :questions, :through => :sections, :dependent => :destroy + has_many :questions, :through => :sections, :dependent => :destroy #Link the child's data accepts_nested_attributes_for :versions, :allow_destroy => true - accepts_nested_attributes_for :dmptemplate +# accepts_nested_attributes_for :dmptemplate attr_accessible :description, :number, :title, :dmptemplate_id, :as => [:default, :admin] diff --git a/app/models/plan.rb b/app/models/plan.rb index e2989a3..25983ef 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -13,9 +13,10 @@ belongs_to :version has_many :answers has_many :plan_sections - accepts_nested_attributes_for :project + +# accepts_nested_attributes_for :project accepts_nested_attributes_for :answers - accepts_nested_attributes_for :version +# accepts_nested_attributes_for :version has_settings :export, class_name: 'Settings::Dmptemplate' do |s| s.key :export, defaults: Settings::Dmptemplate::DEFAULT_SETTINGS diff --git a/app/models/question.rb b/app/models/question.rb index 2a8d087..3b6cd6b 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -14,15 +14,16 @@ belongs_to :question_format accepts_nested_attributes_for :answers, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true - accepts_nested_attributes_for :section - accepts_nested_attributes_for :question_format +# accepts_nested_attributes_for :section +# accepts_nested_attributes_for :question_format accepts_nested_attributes_for :options, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true accepts_nested_attributes_for :suggested_answers, :allow_destroy => true accepts_nested_attributes_for :themes - - attr_accessible :theme_ids, :as => [:default, :admin] - attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, :parent_id, :suggested_answer, :text, :section_id,:question_format_id,:options_attributes,:suggested_answers_attributes, :option_comment_display, :as => [:default, :admin] + attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, :parent_id, + :suggested_answer, :text, :section_id,:question_format_id,:options_attributes, + :suggested_answers_attributes, :option_comment_display, :theme_ids, + :as => [:default, :admin] def to_s "#{text}" diff --git a/app/models/section.rb b/app/models/section.rb index d5b59c4..223e350 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -8,7 +8,7 @@ #Link the data accepts_nested_attributes_for :questions, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true - accepts_nested_attributes_for :version +# accepts_nested_attributes_for :version attr_accessible :organisation_id, :description, :number, :title, :version_id , :published, :questions_attributes, :as => [:default, :admin] diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb index 55f5448..01d233e 100644 --- a/app/models/suggested_answer.rb +++ b/app/models/suggested_answer.rb @@ -3,7 +3,7 @@ belongs_to :organisation belongs_to :question - accepts_nested_attributes_for :question +# accepts_nested_attributes_for :question attr_accessible :organisation_id, :question_id, :text, :is_example, :as => [:default, :admin] diff --git a/app/models/theme.rb b/app/models/theme.rb index 19a9daf..70b5b11 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -5,8 +5,8 @@ has_and_belongs_to_many :guidances, join_table: "themes_in_guidance" - accepts_nested_attributes_for :guidances - accepts_nested_attributes_for :questions +# accepts_nested_attributes_for :guidances +# accepts_nested_attributes_for :questions attr_accessible :guidance_ids , :as => [:default, :admin] attr_accessible :question_ids, :as => [:default, :admin] diff --git a/app/models/version.rb b/app/models/version.rb index 029418d..13e17c8 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -8,10 +8,11 @@ has_many :plans #Link the data - accepts_nested_attributes_for :phase - #accepts_nested_attributes_for :sections, :allow_destroy => true +# accepts_nested_attributes_for :phase + accepts_nested_attributes_for :sections, :allow_destroy => true - attr_accessible :description, :number, :published, :title, :phase_id, :as => [:default, :admin] + attr_accessible :id, :description, :number, :published, :title, :phase_id, + :sections_attributes, :as => [:default, :admin] def to_s "#{title}" diff --git a/app/views/dmptemplates/_edit_question.html.erb b/app/views/dmptemplates/_edit_question.html.erb index e96aa67..70f5cc3 100644 --- a/app/views/dmptemplates/_edit_question.html.erb +++ b/app/views/dmptemplates/_edit_question.html.erb @@ -67,15 +67,11 @@ <%end%> <%end%> -