diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index ebea43a..75aa6dc 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -22,10 +22,7 @@ @orgs = (Org.institutions + Org.managing_orgs).flatten.uniq.sort{|x,y| x.name <=> y.name } # Get the current user's org - @default_org_name = '' - if @orgs.include?(current_user.org) - @default_org_name = current_user.org.name - end + @default_org = current_user.org if @orgs.include?(current_user.org) respond_to :html end @@ -33,61 +30,7 @@ # GET /plans/possible_templates [JSON] # ------------------------------------------------------------------------------------ def possible_templates - authorize Plan.new - - templates = [] - org = Org.find_by(name: params[:plan_org_name]) - funder = Org.find_by(name: params[:plan_funder_name]) - - if org.nil? - if funder.nil? - msg = _("Using the generic Data Management Plan") - - else - templates << Template.where(published: true, org: @funder) - msg = _("No funder templates available using the generic DMP") if @templates.empty - msg = _("Using the funder's DMP") if @templates.count == 1 - msg = _("Please select form one of the funder's DMPs") if @templates.count > 1 - end - - else - if funder.nil? - templates << Template.where(published: true, org: @org) - msg = _("No organisation templates available using the generic DMP") if @templates.empty - msg = _("Using the organisation's DMP") if @templates.count == 1 - msg = _("Please select form one of the organisation's DMPs") if @templates.count > 1 - - else - templates << Template.where(published: true, org: @funder) - - # Swap out any organisational cusotmizations of a funder template - templates.each do |tmplt| - customization = Template.where(published: true, org: @org, customization_of: tmplt.dmptemplate_id) - unless customization.nil? - templates.delete(tmplt) - templates << customization - end - end - - msg = _("No funder/organisation templates available using the generic DMP") if @templates.empty - msg = _("Using the funder/organisation's DMP") if @templates.count == 1 - msg = _("Please select form one of the funder/organisation's DMPs") if @templates.count > 1 - end - end - - # If no templates were available use the generic templates - if templates.empty? - templates << Template.find_by(is_default: true) - end - - templates = templates.sort{|x,y| x.title <=> y.title } if templates.count > 1 - templates = templates.collect{|t| {id: t.id, title: t.title, org: t.org.name} } - - respond_to do |format| - format.json do - render json: {msg: msg, templates: templates} - end - end + end @@ -97,15 +40,42 @@ @plan = Plan.new authorize @plan - @plan.template = Template.find(plan_params["template_id"]) + @plan.principal_investigator = current_user.name + @plan.data_contact = current_user.email + @plan.funder_name = plan_params[:funder_name] - if @plan.save - @plan.assign_creator(current_user) - - redirect_to plan_path(@plan), notice: _('Plan was successfully created.') + # If a template hasn't been identified look for the available templates + if plan_params[:template_id].blank? + template_options(plan_params[:org_id], plan_params[:funder_id]) + +puts "TEMPLATES: #{@templates.collect{|t| t.id }.join(', ')}" + + # Return the 'Select a template' section + respond_to do |format| + format.js {} + end + + + # Otherwise create the plan else - flash[:notice] = failed_create_error(@plan, 'Plan') - render 'new' + @plan.template = Template.find(plan_params[:template_id]) +=begin + if @plan.save + @plan.assign_creator(current_user) + + flash[:notice] = _('Plan was successfully created.') + respond_to do |format| + format.js { render js: "window.location='#{plan_url(@plan)}'" } + end + + else + # Something went wrong so report the issue to the user + flash[:notice] = failed_create_error(@plan, 'Plan') + respond_to do |format| + format.js {} + end + end +=end end end @@ -381,7 +351,7 @@ private def plan_params - params.require(:plan).permit(:template_id) + params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title) end # different versions of the same template have the same dmptemplate_id @@ -447,4 +417,49 @@ plan.delete(src_plan_key) end + # Collect all of the templates available for the org+funder combination + # -------------------------------------------------------------------------- + def template_options(org_id, funder_id) + templates = [] + + if !org_id.blank? || !funder_id.blank? + if funder_id.blank? + # Load the org's template(s) + unless org_id.nil? + org = Org.find(org_id) + @templates = Template.where(published: true, org: org, customization_of: nil).to_a + @msg = _("We found multiple DMP templates corresponding to the research organisation.") if @templates.count > 1 + end + + else + funder = Org.find(funder_id) + # Load the funder's template(s) + @templates = Template.where(published: true, org: funder).to_a + + unless org_id.blank? + org = Org.find(org_id) + + # Swap out any organisational cusotmizations of a funder template + @templates.each do |tmplt| + customization = Template.find_by(published: true, org: org, customization_of: tmplt.dmptemplate_id) + unless customization.nil? + @templates.delete(tmplt) + @templates << customization + end + end + end + + msg = _("We found multiple DMP templates corresponding to the funder.") if @templates.count > 1 + end + end + + # If no templates were available use the generic templates + if @templates.empty? + @msg = _("Using the generic Data Management Plan") + @templates << Template.find_by(is_default: true) + end + + @templates = templates.sort{|x,y| x.title <=> y.title } if templates.count > 1 + end + end diff --git a/app/models/plan.rb b/app/models/plan.rb index c6a9f67..b941afa 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -1,4 +1,7 @@ class Plan < ActiveRecord::Base + + before_validation :set_creation_defaults + ## # Associations belongs_to :template @@ -1106,4 +1109,14 @@ (num_lines * font_height) + vertical_margin + leading end + # Initialize the title and dirty flags for new templates + # -------------------------------------------------------- + def set_creation_defaults + # Only run this before_validation because rails fires this before save/create + if self.id.nil? + self.title = "My plan (#{self.template.title})" if self.title.nil? + self.visibility = 1 + end + end + end diff --git a/app/models/template.rb b/app/models/template.rb index 63b4b3e..7a228b1 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -130,6 +130,7 @@ self.published = false self.dirty = false self.visibility = 1 + self.is_default = false self.version = 0 if self.version.nil? # Generate a unique identifier for the dmptemplate_id if necessary diff --git a/app/views/plans/_available_templates.html.erb b/app/views/plans/_available_templates.html.erb new file mode 100644 index 0000000..df96337 --- /dev/null +++ b/app/views/plans/_available_templates.html.erb @@ -0,0 +1,18 @@ +

<%= _('Which DMP template would you like to use?') %>

+ + <%= _('We found multiple DMP templates corresponding to your funder.') %> + + + + + + + \ No newline at end of file diff --git a/app/views/plans/create.js.erb b/app/views/plans/create.js.erb new file mode 100644 index 0000000..aed2a41 --- /dev/null +++ b/app/views/plans/create.js.erb @@ -0,0 +1,16 @@ +$("#available-templates").html("").hide(); + +<% if @templates.nil? %> + $(".main_page_content").prepend('

<%= raw notice %>

'); + $(".form-submit").prop("disabled", true); + +<% elsif @templates.count > 1 %> + // Clear the existing contents of the modal and then display template combobox + $("#available-templates").html("<%= escape_javascript(render partial: 'available_templates') %>").fadeIn(); + $(".form-submit").prop("disabled", true); + +<% else %> + // Only one template so fill in the id + $("#available-templates").html(''); + $(".form-submit").prop("disabled", false); +<% end %> \ No newline at end of file diff --git a/app/views/plans/new.html.erb b/app/views/plans/new.html.erb index 9d222f2..8e3b074 100644 --- a/app/views/plans/new.html.erb +++ b/app/views/plans/new.html.erb @@ -4,59 +4,71 @@

<%= _('Create a new plan') %>

- <%= _("Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs.") %> -

+ <%= _("Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs.") %> +

- <%= form_for @plan, method: :post do |f| %> -
-

<%= _('Where will the research be conducted?') %>

- - - - - <% @orgs.each do |org| %> - - - - - <%= _('My research organization is not on the list or no research organization is associated with this plan')%> - -
- -
-

<%= _('Who will fund the research?') %>

- - - - - <% @funders.each do |funder| %> - - - - - <%= _('No funder associated with this plan')%> - -
- - - - <% end %> + <%= form_for @plan, method: :post, remote: true do |f| %> +
+ + +
+

<%= _('Where will the research be conducted?') %>

+ + + + <%= render partial: "shared/accessible_combobox", locals: {name: 'plan[org_name]', + id: 'plan_org_name', + default_selection: @default_org, + models: @orgs, + attribute: 'name'} %> + + + + <%= _('My research organization is not on the list or no research organization is associated with this plan')%> + +
+ + +
+

<%= _('Who will fund the research?') %>

+ + + + <%= render partial: "shared/accessible_combobox", locals: {name: 'plan[funder_name]', + id: 'plan_funder_name', + default_selection: nil, + models: @funders, + attribute: 'name'} %> + + + + <%= _('No funder associated with this plan')%> + +
+ + +
+
+ + +
+

<%= _('What is the subject of your proposal?') %>

+ + + + <% default_name = (current_user.firstname.blank? ? _('My Plan') : current_user.firstname + _(' Plan')) %> + +
+ +
+ + + <% end %> diff --git a/app/views/shared/_accessible_combobox.html.erb b/app/views/shared/_accessible_combobox.html.erb new file mode 100644 index 0000000..1d05151 --- /dev/null +++ b/app/views/shared/_accessible_combobox.html.erb @@ -0,0 +1,65 @@ +<% if !models.nil? %> + <% json = {} %> + <% models.map{|m| json[m[attribute]] = m.id} %> + + + + <% models.each do |model| %> + + + + + + " name="<%= name.gsub("_#{attribute}]", "_id]") %>" + value="<%= default_selection.id unless default_selection.nil? %>" /> + + +<% else %> + <%= _('No items available.') %> +<% end %> \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index f03a36f..99d62cc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -72,6 +72,7 @@ config.assets.precompile += %w(projects.js) config.assets.precompile += %w(jquery.placeholder.js) config.assets.precompile += %w(jquery.tablesorter.js) + config.assets.precompile += %w(jquery-accessible-autocomplet-list-aria.js) config.assets.precompile += %w(export_configure.js) config.assets.precompile += %w(toolbar.js) config.assets.precompile += %w(new_plan.js) diff --git a/db/schema.rb b/db/schema.rb index 62d2ca1..93d90a6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,406 +14,451 @@ ActiveRecord::Schema.define(version: 20170421170849) do create_table "answers", force: :cascade do |t| - t.text "text" - t.integer "plan_id" - t.integer "user_id" - t.integer "question_id" + t.text "text", limit: 65535 + t.integer "plan_id", limit: 4 + t.integer "user_id", limit: 4 + t.integer "question_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "lock_version", default: 0 + t.integer "lock_version", limit: 4, default: 0 end - add_index "answers", ["plan_id"], name: "fk_rails_84a6005a3e" - add_index "answers", ["question_id"], name: "fk_rails_3d5ed4418f" - add_index "answers", ["user_id"], name: "fk_rails_584be190c2" + add_index "answers", ["plan_id"], name: "fk_rails_84a6005a3e", using: :btree + add_index "answers", ["question_id"], name: "fk_rails_3d5ed4418f", using: :btree + add_index "answers", ["user_id"], name: "fk_rails_584be190c2", using: :btree create_table "answers_question_options", id: false, force: :cascade do |t| - t.integer "answer_id", null: false - t.integer "question_option_id", null: false + t.integer "answer_id", limit: 4, null: false + t.integer "question_option_id", limit: 4, null: false end - add_index "answers_question_options", ["answer_id", "question_option_id"], name: "answer_question_option_index" - add_index "answers_question_options", ["question_option_id", "answer_id"], name: "question_option_answer_index" + add_index "answers_question_options", ["answer_id", "question_option_id"], name: "answer_question_option_index", using: :btree + add_index "answers_question_options", ["question_option_id", "answer_id"], name: "question_option_answer_index", using: :btree create_table "exported_plans", force: :cascade do |t| - t.integer "plan_id" - t.integer "user_id" - t.string "format" + t.integer "plan_id", limit: 4 + t.integer "user_id", limit: 4 + t.string "format", limit: 255 t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "phase_id" + t.integer "phase_id", limit: 4 end create_table "file_types", force: :cascade do |t| - t.string "name" - t.string "icon_name" - t.integer "icon_size" - t.string "icon_location" + t.string "name", limit: 255 + t.string "icon_name", limit: 255 + t.integer "icon_size", limit: 4 + t.string "icon_location", limit: 255 t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "file_uploads", force: :cascade do |t| - t.string "name" - t.string "title" - t.text "description" - t.integer "size" + t.string "name", limit: 255 + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "size", limit: 4 t.boolean "published" - t.string "location" - t.integer "file_type_id" + t.string "location", limit: 255 + t.integer "file_type_id", limit: 4 t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "friendly_id_slugs", force: :cascade do |t| - t.string "slug", null: false - t.integer "sluggable_id", null: false - t.string "sluggable_type" + t.string "slug", limit: 255, null: false + t.integer "sluggable_id", limit: 4, null: false + t.string "sluggable_type", limit: 40 t.datetime "created_at" end - add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true - add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id" - add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type" + add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true, using: :btree + add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id", using: :btree + add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree create_table "guidance_groups", force: :cascade do |t| - t.string "name" - t.integer "org_id" + t.string "name", limit: 255 + t.integer "org_id", limit: 4 t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "optional_subset" t.boolean "published" end - add_index "guidance_groups", ["org_id"], name: "fk_rails_819c1dbbc7" + add_index "guidance_groups", ["org_id"], name: "fk_rails_819c1dbbc7", using: :btree create_table "guidances", force: :cascade do |t| - t.text "text" - t.integer "guidance_group_id" + t.text "text", limit: 65535 + t.integer "guidance_group_id", limit: 4 t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "question_id" + t.integer "question_id", limit: 4 t.boolean "published" end - add_index "guidances", ["guidance_group_id"], name: "fk_rails_20d29da787" + add_index "guidances", ["guidance_group_id"], name: "fk_rails_20d29da787", using: :btree create_table "identifier_schemes", force: :cascade do |t| - t.string "name" - t.string "description" + t.string "name", limit: 255 + t.string "description", limit: 255 t.boolean "active" t.datetime "created_at" t.datetime "updated_at" - t.boolean "use_for_login", default: false end create_table "languages", force: :cascade do |t| - t.string "abbreviation" - t.string "description" - t.string "name" + t.string "abbreviation", limit: 255 + t.string "description", limit: 255 + t.string "name", limit: 255 t.boolean "default_language" end create_table "notes", force: :cascade do |t| - t.integer "user_id" - t.text "text" + t.integer "user_id", limit: 4 + t.text "text", limit: 65535 t.boolean "archived" - t.integer "answer_id" - t.integer "archived_by" + t.integer "answer_id", limit: 4 + t.integer "archived_by", limit: 4 t.datetime "created_at" t.datetime "updated_at" end - add_index "notes", ["answer_id"], name: "fk_rails_907f8d48bf" - add_index "notes", ["user_id"], name: "fk_rails_7f2323ad43" + add_index "notes", ["answer_id"], name: "fk_rails_907f8d48bf", using: :btree + add_index "notes", ["user_id"], name: "fk_rails_7f2323ad43", using: :btree create_table "org_token_permissions", force: :cascade do |t| - t.integer "org_id" - t.integer "token_permission_type_id" + t.integer "org_id", limit: 4 + t.integer "token_permission_type_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end - add_index "org_token_permissions", ["org_id"], name: "fk_rails_e1db1b22c5" - add_index "org_token_permissions", ["token_permission_type_id"], name: "fk_rails_2aa265f538" + add_index "org_token_permissions", ["org_id"], name: "fk_rails_e1db1b22c5", using: :btree + add_index "org_token_permissions", ["token_permission_type_id"], name: "fk_rails_2aa265f538", using: :btree create_table "orgs", force: :cascade do |t| - t.string "name" - t.string "abbreviation" - t.string "target_url" - t.string "wayfless_entity" + t.string "name", limit: 255 + t.string "abbreviation", limit: 255 + t.string "target_url", limit: 255 + t.string "wayfless_entity", limit: 255 t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "parent_id" + t.integer "parent_id", limit: 4 t.boolean "is_other" - t.string "sort_name" - t.text "banner_text" - t.string "logo_file_name" - t.integer "region_id" - t.integer "language_id" - t.string "logo_uid" - t.string "logo_name" - t.string "contact_email" - t.integer "org_type", default: 0, null: false + t.string "sort_name", limit: 255 + t.text "banner_text", limit: 65535 + t.string "logo_file_name", limit: 255 + t.integer "region_id", limit: 4 + t.integer "language_id", limit: 4 + t.string "logo_uid", limit: 255 + t.string "logo_name", limit: 255 + t.string "contact_email", limit: 255 + t.integer "org_type", limit: 4, default: 0, null: false end - add_index "orgs", ["language_id"], name: "fk_rails_5640112cab" - add_index "orgs", ["region_id"], name: "fk_rails_5a6adf6bab" + add_index "orgs", ["language_id"], name: "fk_rails_5640112cab", using: :btree + add_index "orgs", ["region_id"], name: "fk_rails_5a6adf6bab", using: :btree create_table "perms", force: :cascade do |t| - t.string "name" + t.string "name", limit: 255 t.datetime "created_at", null: false t.datetime "updated_at", null: false end - add_index "perms", ["name"], name: "index_perms_on_name" - add_index "perms", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id" + add_index "perms", ["name"], name: "index_perms_on_name", using: :btree + add_index "perms", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree create_table "phases", force: :cascade do |t| - t.string "title" - t.text "description" - t.integer "number" - t.integer "template_id" + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "number", limit: 4 + t.integer "template_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "slug" + t.string "slug", limit: 255 t.boolean "modifiable" end - add_index "phases", ["template_id"], name: "fk_rails_0f8036cb2e" + add_index "phases", ["template_id"], name: "fk_rails_0f8036cb2e", using: :btree create_table "plan_guidance_groups", force: :cascade do |t| - t.integer "plan_id" - t.integer "guidance_group_id" + t.integer "plan_id", limit: 4 + t.integer "guidance_group_id", limit: 4 t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "selected" end - add_index "plan_guidance_groups", ["guidance_group_id"], name: "index_plan_guidance_groups_on_guidance_group_id" - add_index "plan_guidance_groups", ["plan_id"], name: "index_plan_guidance_groups_on_plan_id" + add_index "plan_guidance_groups", ["guidance_group_id"], name: "index_plan_guidance_groups_on_guidance_group_id", using: :btree + add_index "plan_guidance_groups", ["plan_id"], name: "index_plan_guidance_groups_on_plan_id", using: :btree create_table "plans", force: :cascade do |t| - t.integer "project_id" - t.string "title" - t.integer "template_id" + t.integer "project_id", limit: 4 + t.string "title", limit: 255 + t.integer "template_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "slug" - t.string "grant_number" - t.string "identifier" - t.text "description" - t.string "principal_investigator" - t.string "principal_investigator_identifier" - t.string "data_contact" - t.string "funder_name" - t.integer "visibility", default: 0, null: false + t.string "slug", limit: 255 + t.string "grant_number", limit: 255 + t.string "identifier", limit: 255 + t.text "description", limit: 65535 + t.string "principal_investigator", limit: 255 + t.string "principal_investigator_identifier", limit: 255 + t.string "data_contact", limit: 255 + t.string "funder_name", limit: 255 + t.integer "visibility", limit: 4, default: 0, null: false end - add_index "plans", ["template_id"], name: "fk_rails_3424ca281f" + add_index "plans", ["template_id"], name: "fk_rails_3424ca281f", using: :btree + + create_table "plans_guidance_groups", force: :cascade do |t| + t.integer "guidance_group_id", limit: 4 + t.integer "plan_id", limit: 4 + end + + add_index "plans_guidance_groups", ["guidance_group_id"], name: "fk_rails_ec1c5524d7", using: :btree + add_index "plans_guidance_groups", ["plan_id"], name: "fk_rails_13d0671430", using: :btree create_table "question_formats", force: :cascade do |t| - t.string "title" - t.text "description" + t.string "title", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "option_based", default: false - t.integer "formattype", default: 0 + t.integer "formattype", limit: 4, default: 0 end create_table "question_options", force: :cascade do |t| - t.integer "question_id" - t.string "text" - t.integer "number" + t.integer "question_id", limit: 4 + t.string "text", limit: 255 + t.integer "number", limit: 4 t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" end - add_index "question_options", ["question_id"], name: "fk_rails_b9c5f61cf9" + add_index "question_options", ["question_id"], name: "fk_rails_b9c5f61cf9", using: :btree create_table "questions", force: :cascade do |t| - t.text "text" - t.text "default_value" - t.text "guidance" - t.integer "number" - t.integer "section_id" + t.text "text", limit: 65535 + t.text "default_value", limit: 65535 + t.text "guidance", limit: 65535 + t.integer "number", limit: 4 + t.integer "section_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "question_format_id" + t.integer "question_format_id", limit: 4 t.boolean "option_comment_display", default: true t.boolean "modifiable" end - add_index "questions", ["question_format_id"], name: "fk_rails_4fbc38c8c7" - add_index "questions", ["section_id"], name: "fk_rails_c50eadc3e3" + add_index "questions", ["question_format_id"], name: "fk_rails_4fbc38c8c7", using: :btree + add_index "questions", ["section_id"], name: "fk_rails_c50eadc3e3", using: :btree create_table "questions_themes", id: false, force: :cascade do |t| - t.integer "question_id", null: false - t.integer "theme_id", null: false + t.integer "question_id", limit: 4, null: false + t.integer "theme_id", limit: 4, null: false end - add_index "questions_themes", ["question_id", "theme_id"], name: "question_theme_index" - add_index "questions_themes", ["theme_id", "question_id"], name: "theme_question_index" + add_index "questions_themes", ["question_id", "theme_id"], name: "question_theme_index", using: :btree + add_index "questions_themes", ["theme_id", "question_id"], name: "theme_question_index", using: :btree create_table "regions", force: :cascade do |t| - t.string "abbreviation" - t.string "description" - t.string "name" - t.integer "super_region_id" + t.string "abbreviation", limit: 255 + t.string "description", limit: 255 + t.string "name", limit: 255 + t.integer "super_region_id", limit: 4 end create_table "roles", force: :cascade do |t| - t.integer "user_id" - t.integer "plan_id" + t.integer "user_id", limit: 4 + t.integer "plan_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "access", default: 0, null: false + t.integer "access", limit: 4, default: 0, null: false end - add_index "roles", ["plan_id"], name: "fk_rails_a1ce6c2772" - add_index "roles", ["user_id"], name: "fk_rails_ab35d699f0" + add_index "roles", ["plan_id"], name: "fk_rails_a1ce6c2772", using: :btree + add_index "roles", ["user_id"], name: "fk_rails_ab35d699f0", using: :btree create_table "sections", force: :cascade do |t| - t.string "title" - t.text "description" - t.integer "number" + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "number", limit: 4 t.datetime "created_at" t.datetime "updated_at" t.boolean "published" - t.integer "phase_id" + t.integer "phase_id", limit: 4 t.boolean "modifiable" end - add_index "sections", ["phase_id"], name: "fk_rails_1853581585" + add_index "sections", ["phase_id"], name: "fk_rails_1853581585", using: :btree create_table "settings", force: :cascade do |t| - t.string "var", null: false - t.text "value" - t.integer "target_id", null: false - t.string "target_type", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "var", limit: 255, null: false + t.text "value", limit: 65535 + t.integer "target_id", limit: 4, null: false + t.string "target_type", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true + add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree create_table "splash_logs", force: :cascade do |t| - t.string "destination" + t.string "destination", limit: 255 t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "suggested_answers", force: :cascade do |t| - t.integer "question_id" - t.integer "org_id" - t.text "text" + t.integer "question_id", limit: 4 + t.integer "org_id", limit: 4 + t.text "text", limit: 65535 t.boolean "is_example" t.datetime "created_at" t.datetime "updated_at" end - add_index "suggested_answers", ["org_id"], name: "fk_rails_473de65779" - add_index "suggested_answers", ["question_id"], name: "fk_rails_daa60b5b70" + add_index "suggested_answers", ["org_id"], name: "fk_rails_473de65779", using: :btree + add_index "suggested_answers", ["question_id"], name: "fk_rails_daa60b5b70", using: :btree create_table "templates", force: :cascade do |t| - t.string "title" - t.text "description" + t.string "title", limit: 255 + t.text "description", limit: 65535 t.boolean "published" - t.integer "org_id" - t.string "locale" + t.integer "org_id", limit: 4 + t.string "locale", limit: 255 t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" - t.integer "version" - t.integer "visibility" - t.integer "customization_of" - t.integer "dmptemplate_id" + t.integer "version", limit: 4 + t.integer "visibility", limit: 4 + t.integer "customization_of", limit: 4 + t.integer "dmptemplate_id", limit: 4 t.boolean "dirty", default: false end - add_index "templates", ["org_id"], name: "fk_rails_481431e1bd" + add_index "templates", ["org_id"], name: "fk_rails_481431e1bd", using: :btree create_table "themes", force: :cascade do |t| - t.string "title" - t.text "description" + t.string "title", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "locale" + t.string "locale", limit: 255 end create_table "themes_in_guidance", id: false, force: :cascade do |t| - t.integer "theme_id" - t.integer "guidance_id" + t.integer "theme_id", limit: 4 + t.integer "guidance_id", limit: 4 end - add_index "themes_in_guidance", ["guidance_id"], name: "fk_rails_a5ab9402df" - add_index "themes_in_guidance", ["theme_id"], name: "fk_rails_7d708f6f1e" + add_index "themes_in_guidance", ["guidance_id"], name: "fk_rails_a5ab9402df", using: :btree + add_index "themes_in_guidance", ["theme_id"], name: "fk_rails_7d708f6f1e", using: :btree create_table "token_permission_types", force: :cascade do |t| - t.string "token_type" - t.text "text_description" + t.string "token_type", limit: 255 + t.text "text_description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "user_identifiers", force: :cascade do |t| - t.string "identifier" + t.string "identifier", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id" - t.integer "identifier_scheme_id" + t.integer "user_id", limit: 4 + t.integer "identifier_scheme_id", limit: 4 end - add_index "user_identifiers", ["identifier_scheme_id"], name: "fk_rails_fe95df7db0" - add_index "user_identifiers", ["user_id"], name: "fk_rails_65c9a98cdb" + add_index "user_identifiers", ["identifier_scheme_id"], name: "fk_rails_fe95df7db0", using: :btree + add_index "user_identifiers", ["user_id"], name: "fk_rails_65c9a98cdb", using: :btree create_table "users", force: :cascade do |t| - t.string "firstname" - t.string "surname" - t.string "email", default: "", null: false - t.string "orcid_id" - t.string "shibboleth_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "encrypted_password", default: "" - t.string "reset_password_token" + t.string "firstname", limit: 255 + t.string "surname", limit: 255 + t.string "email", limit: 255, default: "", null: false + t.string "orcid_id", limit: 255 + t.string "shibboleth_id", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "encrypted_password", limit: 255, default: "" + t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0 + t.integer "sign_in_count", limit: 4, default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip", limit: 255 + t.string "last_sign_in_ip", limit: 255 + t.string "confirmation_token", limit: 255 t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "invitation_token" + t.string "invitation_token", limit: 255 t.datetime "invitation_created_at" t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" - t.string "other_organisation" + t.string "other_organisation", limit: 255 t.boolean "accept_terms" - t.integer "org_id" - t.string "api_token" - t.integer "invited_by_id" - t.string "invited_by_type" - t.integer "language_id" + t.integer "org_id", limit: 4 + t.string "api_token", limit: 255 + t.integer "invited_by_id", limit: 4 + t.string "invited_by_type", limit: 255 + t.integer "language_id", limit: 4 end - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true - add_index "users", ["email"], name: "index_users_on_email", unique: true - add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true - add_index "users", ["language_id"], name: "fk_rails_45f4f12508" - add_index "users", ["org_id"], name: "fk_rails_e73753bccb" - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree + add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree + add_index "users", ["language_id"], name: "fk_rails_45f4f12508", using: :btree + add_index "users", ["org_id"], name: "fk_rails_e73753bccb", using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree create_table "users_perms", id: false, force: :cascade do |t| - t.integer "user_id" - t.integer "perm_id" + t.integer "user_id", limit: 4 + t.integer "perm_id", limit: 4 end - add_index "users_perms", ["perm_id"], name: "fk_rails_457217c31c" - add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id" + add_index "users_perms", ["perm_id"], name: "fk_rails_457217c31c", using: :btree + add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id", using: :btree + add_foreign_key "answers", "plans" + add_foreign_key "answers", "questions" + add_foreign_key "answers", "users" + add_foreign_key "answers_question_options", "answers" + add_foreign_key "answers_question_options", "question_options" + add_foreign_key "guidance_groups", "orgs" + add_foreign_key "guidances", "guidance_groups" + add_foreign_key "notes", "answers" + add_foreign_key "notes", "users" + add_foreign_key "org_token_permissions", "orgs" + add_foreign_key "org_token_permissions", "token_permission_types" + add_foreign_key "orgs", "languages" + add_foreign_key "orgs", "regions" + add_foreign_key "phases", "templates" + add_foreign_key "plan_guidance_groups", "guidance_groups" + add_foreign_key "plan_guidance_groups", "plans" + add_foreign_key "plans", "templates" + add_foreign_key "plans_guidance_groups", "guidance_groups" + add_foreign_key "plans_guidance_groups", "plans" + add_foreign_key "question_options", "questions" + add_foreign_key "questions", "question_formats" + add_foreign_key "questions", "sections" + add_foreign_key "questions_themes", "questions" + add_foreign_key "questions_themes", "themes" + add_foreign_key "roles", "plans" + add_foreign_key "roles", "users" + add_foreign_key "sections", "phases" + add_foreign_key "suggested_answers", "orgs" + add_foreign_key "suggested_answers", "questions" + add_foreign_key "templates", "orgs" + add_foreign_key "themes_in_guidance", "guidances" + add_foreign_key "themes_in_guidance", "themes" + add_foreign_key "user_identifiers", "identifier_schemes" + add_foreign_key "user_identifiers", "users" + add_foreign_key "users", "languages" + add_foreign_key "users", "orgs" + add_foreign_key "users_perms", "perms" + add_foreign_key "users_perms", "users" end diff --git a/lib/assets/javascripts/dmproadmap.scss b/lib/assets/javascripts/dmproadmap.scss new file mode 100644 index 0000000..4605a72 --- /dev/null +++ b/lib/assets/javascripts/dmproadmap.scss @@ -0,0 +1,128 @@ +@import "font-awesome"; + +$font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; + +$white: #FFF; + +$primary-color: #F49700; +$disabled-button-color: #CCC; +$reverse-text: #FFF; + +/* See `.combobox-clear-button` for an example of this mixin in use */ +@mixin icon($icon) { + @extend .fa; + @extend .fa-#{$icon}:before; +} + +.right { + float: right; +} + +.main_header { + margin-bottom: 20px; +} + +.main { + + form { + + .white-fieldset { + background-color: $white; + padding: 0 25px 25px 25px; + margin-bottom: 25px; + + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + border-radius: 10px; + + label, input[type="checkbox"], .combobox-container { + margin-left: 15px; + } + + input[type="text"] { + width: 350px; + margin-bottom: 15px; + } + + input[type="checkbox"] { + vertical-align: top; + } + } + + input[type=submit] { + background-color: $primary-color; + color: $reverse-text; + padding: 10px 30px; + font-size: 12pt; + + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + border-radius: 10px; + } + input[type=submit]:disabled { + background-color: $disabled-button-color; + } + + } + +} + +/* Accessible JQuery combobox */ +/* ----------------------------------------- */ +.invisible { + border: 0; + clip: rect(0 0 0 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; +} + +.combobox-container { + position: relative; + max-width: 385px; + + font-family: $font-family; +} + +.combobox-suggestions { + position: absolute; + left: 0; + width: 362px; + margin-top: -10px; + background: #fff; + z-index: 99; +} +.combobox-suggestion { + color: #666; + border-bottom: 1px solid #000; + border-left: 1px solid #000; + border-right: 1px solid #000; + padding: 5px 10px 5px 10px; + cursor: pointer; + text-align: left; +} +.combobox-suggestion:first-child { + border-top: 1px solid #000; +} +.combobox-suggestion:hover, +.combobox-suggestion:focus { + color: $white; + background-color: $primary-color; +} + +.combobox-clear-button { + @include icon(times-circle); + display: inline; + position: absolute; + border: none; + background: transparent; + padding-top: 3px; + font-size: 16pt; +} + +/* http://geektnt.com/how-to-remove-x-from-search-input-field-on-chrome-and-ie.html */ +.js-combobox[type=text]::-ms-clear { display: none; width: 0; height: 0; } +.js-combobox[type=text]::-ms-reveal { display: none; width: 0; height: 0; } \ No newline at end of file diff --git a/lib/assets/javascripts/new_plan.js b/lib/assets/javascripts/new_plan.js index 861f0d9..5b3a6af 100644 --- a/lib/assets/javascripts/new_plan.js +++ b/lib/assets/javascripts/new_plan.js @@ -1,98 +1,38 @@ $(document).ready(function(){ - // Replace the default js-combobox clear button [X] with a fontawesome icon - $(".combobox-clear-button").html(''); - - // Form submit button is disabled until all requirements are met - $(".form-submit").prop("disabled", true); - - // Function to hide/show the clear button when text changed in the dropdown - $(".combobox-container input.js-combobox").keyup(function(){ - displayClearButton(this); - }); - - $(".combobox-container input.js-combobox").change(function(){ - toggleSubmit(); - }); - - // Initialize the clear buttons on load - $(".combobox-container input.js-combobox").each(function(){ - displayClearButton(this); - }); - - // Hide the clear button if it gets clicked - $(".combobox-clear-button").click(function(){ - $(this).css("display", 'none'); - }); - - // If the user clicks the no Organisation checkbox disable the dropdown and hide clear button - $("#plan_no_org").click(function(){ - $("#plan_org_name").prop("disabled", this.checked).val(""); - displayClearButton($("#plan_org_name")); - toggleSubmit(); - }); - - // If the user clicks the no Funder checkbox disable the dropdown and hide clear button - $("#plan_no_funder").click(function(){ - $("#plan_funder_name").prop("disabled", this.checked).val(""); - displayClearButton($("#plan_funder_name")); - toggleSubmit(); - }); - - $(".form-submit").click(function(e){ - e.preventDefault(); - - retrieveTemplates(function(hash){ - if(hash['templates']){ - if(hash['templates'].length > 1){ - // Display they template selector - console.log(hash); - }else{ - $("#plan_template_id").val(hash['templates'][0]['id']); - // submit the page - $("form").submit(); - } - } - }); - }); + // Form submit button is disabled until all requirements are met + $(".form-submit").prop("disabled", true); + $("#available-templates").hide(); + + // When the hidden org and funder id fields change toogle the submit button + $("#plan_org_id, #plan_funder_id").change(function(){ + retrieveTemplateOptions(); + }); + + // If the user clicks the no Organisation checkbox disable the dropdown and hide clear button + $("#plan_no_org, #plan_no_funder").click(function(){ + var whichOne = $(this).prop('id').split('_')[2]; + $("#plan_" + whichOne + "_name").prop("disabled", this.checked).val("").keyup(); + }); }); -function displayClearButton(combobox){ - var clear = $(combobox).siblings(".combobox-clear-button"); - // For some reason the standard .show() forces a 'display: block;' so we - // instead directly set the attribute to maintain the position of the button - if($(combobox).val().trim().length <= 0){ - clear.css("display", 'none'); - }else{ - clear.css("display", 'inline'); - } -} - // Only display the submit button if the user has made each decision -function toggleSubmit(){ - // If the (no_org checkbox is checked OR an org was selected) AND - // (no_funder checkbox is checked OR a funder was selected) - var show = ($("#plan_no_org").prop("checked") || - $("#plan_org_name").val().trim().length > 0) && - ($("#plan_no_funder").prop("checked") || - $("#plan_funder_name").val().trim().length > 0) && - $('input[name="plan[template_id]"]:checked'); - - $(".form-submit").prop("disabled", !show); +// ------------------------------------------------------------- +function retrieveTemplateOptions(){ + // If the (no_org checkbox is checked OR an org was selected) AND + // (no_funder checkbox is checked OR a funder was selected) + var retrieve = ($("#plan_no_org").prop("checked") || + $("#plan_org_id").val().trim().length > 0) && + ($("#plan_no_funder").prop("checked") || + $("#plan_funder_id").val().trim().length > 0); + + $("#available-templates").fadeOut(); + $("#plan_template_id").val(""); + $(".form-submit").prop('disabled', true); + + if(retrieve){ + // If the templates section isn't available then submit the form to find the template options + if($("#available_templates").html() == undefined){ + $("form").submit(); + } + } } - -// AJAX call to retrieve the list of available templates -function retrieveTemplates(callback){ - var retrieve = ($("#plan_no_org").prop("checked") || - $("#plan_org_name").val().trim().length > 0) && - ($("#plan_no_funder").prop("checked") || - $("#plan_funder_name").val().trim().length > 0); - - if(retrieve){ - var args = {org_name: $("#plan_org_name").val(), - funder_name: $("#plan_funder_name").prop("value")}; - - $.getJSON("/plans/possible_templates", args).done(function(json){ - callback(json); - }); - } -} \ No newline at end of file diff --git a/lib/assets/stylesheets/dmproadmap.scss b/lib/assets/stylesheets/dmproadmap.scss index 10f3dfd..cf05d3b 100644 --- a/lib/assets/stylesheets/dmproadmap.scss +++ b/lib/assets/stylesheets/dmproadmap.scss @@ -8,20 +8,12 @@ $disabled-button-color: #CCC; $reverse-text: #FFF; - +/* See `.combobox-clear-button` for an example of this mixin in use */ @mixin icon($icon) { @extend .fa; @extend .fa-#{$icon}:before; } -h1 { - -} - -h4 { - -} - .main_header { margin-bottom: 20px; } @@ -43,9 +35,10 @@ margin-left: 15px; } - input[type="text"] { + input[type="text"], .combobox-like { width: 350px; margin-bottom: 15px; + margin-left: 15px; } input[type="checkbox"] {