diff --git a/app/controllers/api/v0/plans_controller.rb b/app/controllers/api/v0/plans_controller.rb index c96d174..ac2f1b4 100644 --- a/app/controllers/api/v0/plans_controller.rb +++ b/app/controllers/api/v0/plans_controller.rb @@ -37,15 +37,15 @@ template = org.templates.find_by title: params[:template][:name] # else error: organization has more than one template and template name unspecified else - render json: I18n.t("api.org_multiple_templates"), status: 400 and return + render json: _('{"Error":"Organisation has more than one template and template name unspecified or invalid"}'), status: 400 and return end # else error: organization specified is not a funder else - render json: I18n.t("api.org_not_funder"), status: 400 and return + render json: _('{"Error":"Organisation specified is not a funder"}'), status: 400 and return end # else error: organization does not exist else - render json: I18n.t("api.org_dosent_exist"), status: 400 and return + render json: _('{"Error":"Organisation does not exist"}'), status: 400 and return end all_groups = [] @@ -90,7 +90,7 @@ end else - render json: I18n.t("api.no_auth_for_endpoint"), status: 400 and return + render json: _('{"Error":"You do not have authorisation to view this endpoint"}'), status: 400 and return end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9b06df8..cd010f9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,7 +14,7 @@ rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized def user_not_authorized - redirect_to root_url, alert: I18n.t('unauthorized') + redirect_to root_url, alert: _('You need to sign in or sign up before continuing.') end before_filter :get_languages diff --git a/app/controllers/guidance_groups_controller.rb b/app/controllers/guidance_groups_controller.rb index 3729dd7..585f32c 100644 --- a/app/controllers/guidance_groups_controller.rb +++ b/app/controllers/guidance_groups_controller.rb @@ -27,7 +27,7 @@ end if @guidance_group.save - redirect_to admin_index_guidance_path, notice: I18n.t('org_admin.guidance_group.created_message') + redirect_to admin_index_guidance_path, notice: _('Guidance group was successfully created.') else render action: "new" end @@ -48,7 +48,7 @@ @guidance_group.org_id = current_user.org_id if @guidance_group.update_attributes(params[:guidance_group]) - redirect_to admin_index_guidance_path(params[:guidance_group]), notice: I18n.t('org_admin.guidance_group.updated_message') + redirect_to admin_index_guidance_path(params[:guidance_group]), notice: _('Guidance group was successfully updated.') else render action: "edit" end @@ -63,7 +63,7 @@ @guidance_group.published = true if @guidance_group.update_attributes(params[:guidance_group]) - redirect_to admin_index_guidance_path(params[:guidance_group]), notice: I18n.t('org_admin.guidance_group.updated_message') + redirect_to admin_index_guidance_path(params[:guidance_group]), notice: _('Guidance group was successfully updated.') else render action: "edit" end @@ -77,7 +77,7 @@ authorize @guidance_group @guidance_group.destroy - redirect_to admin_index_guidance_path, notice: I18n.t('org_admin.guidance_group.destroyed_message') + redirect_to admin_index_guidance_path, notice: _('Guidance group was successfully deleted.') end end \ No newline at end of file diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb index 75c0808..674e0f6 100644 --- a/app/controllers/guidances_controller.rb +++ b/app/controllers/guidances_controller.rb @@ -59,10 +59,10 @@ # updates phases, versions, sections and questions based on template selected dmptemplate = Template.find(params[:dmptemplate_id]) # map to title and id for use in our options_for_select - @phases = dmptemplate.phases.map{|a| [a.title, a.id]}.insert(0, I18n.t('helpers.select_phase')) - @versions = dmptemplate.versions.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_version')) - @sections = dmptemplate.sections.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_section')) - @questions = dmptemplate.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) + @phases = dmptemplate.phases.map{|a| [a.title, a.id]}.insert(0, _('Select a phase')) + @versions = dmptemplate.versions.map{|s| [s.title, s.id]}.insert(0, _('Select a version')) + @sections = dmptemplate.sections.map{|s| [s.title, s.id]}.insert(0, _('Select a section')) + @questions = dmptemplate.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question')) end def update_versions @@ -70,9 +70,9 @@ # updates versions, sections and questions based on phase selected phase = Phase.find(params[:phase_id]) # map to name and id for use in our options_for_select - @versions = phase.versions.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_version')) - @sections = phase.sections.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_section')) - @questions = phase.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) + @versions = phase.versions.map{|s| [s.title, s.id]}.insert(0, _('Select a version')) + @sections = phase.sections.map{|s| [s.title, s.id]}.insert(0, _('Select a section')) + @questions = phase.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question')) end def update_sections @@ -80,15 +80,15 @@ # updates sections and questions based on version selected version = Version.find(params[:version_id]) # map to name and id for use in our options_for_select - @sections = version.sections.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_section')) - @questions = version.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) + @sections = version.sections.map{|s| [s.title, s.id]}.insert(0, _('Select a section')) + @questions = version.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question')) end def update_questions authorize Guidance # updates songs based on artist selected section = Section.find(params[:section_id]) - @questions = section.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) + @questions = section.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question')) end ## @@ -116,7 +116,7 @@ end if @guidance.save - redirect_to admin_show_guidance_path(@guidance), notice: I18n.t('org_admin.guidance.created_message') + redirect_to admin_show_guidance_path(@guidance), notice: _('Guidance was successfully created.') else render action: "new" end @@ -131,7 +131,7 @@ @guidance.question_id = params["question_id"] if @guidance.update_attributes(params[:guidance]) - redirect_to admin_show_guidance_path(params[:guidance]), notice: I18n.t('org_admin.guidance.updated_message') + redirect_to admin_show_guidance_path(params[:guidance]), notice: _('Guidance was successfully updated.') else render action: "edit" end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 8a400f6..40f5e32 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -32,7 +32,7 @@ if @note.save session[:question_id_notes] = answer.question_id - redirect_to edit_plan_phase_path(@plan, @phase), status: :found, notice: I18n.t("helpers.comments.note_created") + redirect_to edit_plan_phase_path(@plan, @phase), status: :found, notice: _('Comment was successfully created.') end end @@ -48,7 +48,7 @@ if @note.update_attributes(params[:note]) session[:question_id_notes] = @note.question_id - redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: I18n.t("helpers.comments.note_updated") + redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: _('Comment was successfully updated.') end end @@ -65,7 +65,7 @@ if @note.update_attributes(params[:note]) session[:question_id_notes] = @note.question_id - redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: I18n.t("helpers.comments.note_removed") + redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: _('Comment has been removed.') end end end diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb index 905fd06..301f1c6 100644 --- a/app/controllers/orgs_controller.rb +++ b/app/controllers/orgs_controller.rb @@ -30,13 +30,13 @@ begin if @org.update_attributes(assign_params) - redirect_to admin_show_org_path(params[:id]), notice: I18n.t("admin.org_updated_message") + redirect_to admin_show_org_path(params[:id]), notice: _('Organisation was successfully updated.') else flash[:notice] = @org.errors.collect{|e| e.message}.join('
').html_safe render action: "admin_edit" end rescue Dragonfly::Job::Fetch::NotFound => dflye - flash[:notice] = I18n.t("admin.org_bad_logo") + flash[:notice] = _('There seems to be a problem with your logo. Please upload it again.') render action: "admin_edit" end end diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index 6133a45..942dbb4 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -93,7 +93,7 @@ @phase.description = params["phase-desc"] @phase.modifiable = true if @phase.save - redirect_to admin_show_phase_path(id: @phase.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + redirect_to admin_show_phase_path(id: @phase.id, edit: 'true'), notice: _('Information was successfully created.') else render action: "admin_show" end @@ -106,7 +106,7 @@ authorize @phase @phase.description = params["phase-desc"] if @phase.update_attributes(params[:phase]) - redirect_to admin_show_phase_path(@phase), notice: I18n.t('org_admin.templates.updated_message') + redirect_to admin_show_phase_path(@phase), notice: _('Information was successfully updated.') else render action: "admin_show" end @@ -118,7 +118,7 @@ authorize @phase @template = @phase.template @phase.destroy - redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.destroyed_message') + redirect_to admin_template_template_path(@template), notice: _('Information was successfully deleted.') end diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 43be23d..158ccf1 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -77,7 +77,7 @@ @plan.principal_investigator = current_user.name - @plan.title = I18n.t('helpers.project.my_project_name')+' ('+@plan.template.title+')' + @plan.title = _('My plan')+' ('+@plan.template.title+')' # We should use interpolated string since the order of the words from this message could vary among languages @plan.assign_creator(current_user.id) @@ -89,9 +89,9 @@ respond_to do |format| if @plan.save #format.html { redirect_to({:action => "show", :id => @plan.slug, :show_form => "yes"}, {:notice => I18n.t('helpers.project.success')}) } - format.html { redirect_to({:action => "show", :id => @plan.id, :editing => true }, {:notice => I18n.t('helpers.project.success')}) } + format.html { redirect_to({:action => "show", :id => @plan.id, :editing => true }, {:notice => _('Plan was successfully created.')}) } else - @error = "Something went wrong" + @error = "Something went wrong" format.html { render action: "new" } end end @@ -121,7 +121,7 @@ end elsif user_signed_in? then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end else respond_to do |format| @@ -158,7 +158,7 @@ end elsif !@plan.readable_by?(current_user.id) then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end end end @@ -171,7 +171,7 @@ if user_signed_in? && @plan.editable_by?(current_user.id) then respond_to do |format| if @plan.update_attributes(params[:plan]) - format.html { redirect_to @plan, :editing => false, notice: I18n.t('helpers.project.success_update') } + format.html { redirect_to @plan, :editing => false, notice: _('Plan was successfully updated.') } format.json { head :no_content } else format.html { render action: "edit" } @@ -213,7 +213,7 @@ end elsif !@plan.editable_by?(current_user.id) then respond_to do |format| - format.html { redirect_to plans_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to plans_url, notice: _('This account does not have access to that plan.') } end end end @@ -394,7 +394,7 @@ end elsif !@plan.editable_by(current_user.id) then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5b98dd2..5bb893f 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -9,7 +9,9 @@ ## TODO: Is this A magic String? the "Show_shib_link?" as we define it and users dont see cookies if user_signed_in? then if (current_user.shibboleth_id.nil? || current_user.shibboleth_id.length == 0) && !cookies[:show_shib_link].nil? && cookies[:show_shib_link] == "show_shib_link" then - flash.notice = "Would you like to #{view_context.link_to I18n.t('helpers.shibboleth_to_link_text'), user_omniauth_shibboleth_path}".html_safe + flash.notice = ActionController::Base.helpers.link_to( + _('Link your %{application_name} account to your institutional credentials (UK users only)' % { :application_name => Rails.configuration.branding[:application][:name]}, + user_omniauth_shibboleth_path)).html_safe() end @projects = current_user.projects.filter(params[:filter]) @@ -40,7 +42,7 @@ end elsif user_signed_in? then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end else respond_to do |format| @@ -77,7 +79,7 @@ end elsif !@project.editable_by(current_user.id) then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end end end @@ -91,7 +93,7 @@ end elsif !@project.editable_by(current_user.id) then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end end end @@ -132,11 +134,11 @@ end @project.principal_investigator = current_user.name(false) - @project.title = I18n.t('helpers.project.my_project_name')+' ('+@project.dmptemplate.title+')' + @project.title = _('My plan')+' ('+@project.dmptemplate.title+')' # We should use interpolated string since the order of the words from this message could vary among languages @project.assign_creator(current_user.id) respond_to do |format| if @project.save - format.html { redirect_to({:action => "show", :id => @project.slug, :show_form => "yes"}, {:notice => I18n.t('helpers.project.success')}) } + format.html { redirect_to({:action => "show", :id => @project.slug, :show_form => "yes"}, {:notice => _('Plan was successfully created.')}) } else format.html { render action: "new" } end @@ -154,7 +156,7 @@ if user_signed_in? && @project.editable_by(current_user.id) then if @project.update_attributes(params[:project]) respond_to do |format| - format.html { redirect_to({:action => "show", :id => @project.slug, notice: I18n.t('helpers.project.success_update') }) } + format.html { redirect_to({:action => "show", :id => @project.slug, notice: _('Plan was successfully updated.') }) } end else respond_to do |format| diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index d150bff..803479f 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -9,7 +9,7 @@ @question.guidance = params["new-question-guidance"] @question.default_value = params["new-question-default-value"] if @question.save! - redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully created.') else render action: "phases/admin_show" end @@ -24,7 +24,7 @@ @section = @question.section @phase = @section.phase if @question.update_attributes(params[:question]) - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully updated.') else render action: "phases/admin_show" end @@ -37,7 +37,7 @@ @section = @question.section @phase = @section.phase @question.destroy - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: _('Information was successfully deleted.') end end \ No newline at end of file diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index d4e4072..8b2b71c 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -7,12 +7,12 @@ authorize @role @role.access_level = params[:role][:access_level].to_i if params[:role][:email].present? - message = I18n.t('helpers.project.user_added') + message = _('User added to project') if @role.save if @role.user.nil? then if User.find_by_email(params[:role][:email]).nil? then User.invite!(email: params[:role][:email]) - message = I18n.t('helpers.project.invitation_success') + message = _('Invitation issued successfully.') @role.user = User.find_by_email(params[:role][:email]) @role.save else @@ -29,7 +29,7 @@ render action: "new" end else - flash[:notice] = I18n.t('helpers.project.enter_email') + flash[:notice] = _('Please enter an email address') redirect_to controller: 'plans', action: 'share', id: @role.plan.slug end end @@ -39,7 +39,7 @@ authorize @role @role.access_level = params[:role][:access_level].to_i if @role.update_attributes(params[:role]) - flash[:notice] = I18n.t('helpers.project.sharing_updated') + flash[:notice] = _('Sharing details successfully updated.') UserMailer.permissions_change_notification(@role).deliver redirect_to controller: 'plans', action: 'share', id: @role.plan.slug else @@ -54,7 +54,7 @@ plan = @role.plan @role.destroy - flash[:notice] = I18n.t('helpers.project.access_removed') + flash[:notice] = _('Access removed') UserMailer.project_access_removed_notification(user, plan).deliver redirect_to controller: 'plans', action: 'share', id: @role.plan.slug end diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb index 42a65a4..9670c84 100644 --- a/app/controllers/sections_controller.rb +++ b/app/controllers/sections_controller.rb @@ -11,7 +11,7 @@ @phase = section.phase if @section.save redirect_to admin_show_phase_template_path(id: @section.phase_id, - :section_id => @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + :section_id => @section.id, edit: 'true'), notice: _('Information was successfully created.') else render action: "phases/admin_show" end @@ -25,7 +25,7 @@ @section.description = params["section-desc-#{params[:id]}"] @phase = @section.phase if @section.update_attributes(params[:section]) - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id , edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id , edit: 'true'), notice: _('Information was successfully updated.') else render action: "phases/admin_show" end @@ -38,9 +38,7 @@ authorize @section @phase = @section.phase @section.destroy - redirect_to admin_show_phase_path(id: @phase.id, edit: 'true' ), notice: I18n.t('org_admin.templates.destroyed_message') + redirect_to admin_show_phase_path(id: @phase.id, edit: 'true' ), notice: _('Information was successfully deleted.') end - - - + end \ No newline at end of file diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 99a0aad..6435da8 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -68,11 +68,11 @@ else # the project has no plans for some reason - redirect_to public_plans_path, notice: I18n.t('helpers.settings.projects.errors.no_plan') + redirect_to public_plans_path, notice: _('The plan is incomplete.') end else # Otherwise redirect to the home page with an unauthorized message - redirect_to public_plans_path, notice: I18n.t('helpers.settings.plans.errors.no_access_account') + redirect_to public_plans_path, notice: _('This account does not have access to that plan.') end end end \ No newline at end of file diff --git a/app/controllers/suggested_answers_controller.rb b/app/controllers/suggested_answers_controller.rb index a42e289..bb53c6a 100644 --- a/app/controllers/suggested_answers_controller.rb +++ b/app/controllers/suggested_answers_controller.rb @@ -7,7 +7,7 @@ @suggested_answer = SuggestedAnswer.new(params[:suggested_answer]) authorize @suggested_answer if @suggested_answer.save - redirect_to admin_show_phase_path(id: @suggested_answer.question.section.phase_id, section_id: @suggested_answer.question.section_id, question_id: @suggested_answer.question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + redirect_to admin_show_phase_path(id: @suggested_answer.question.section.phase_id, section_id: @suggested_answer.question.section_id, question_id: @suggested_answer.question.id, edit: 'true'), notice: _('Information was successfully created.') else render action: "phases/admin_show" end @@ -22,7 +22,7 @@ @section = @question.section @phase = @section.phase if @suggested_answer.update_attributes(params[:suggested_answer]) - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully updated.') else render action: "phases/admin_show" end @@ -36,7 +36,7 @@ @section = @question.section @phase = @section.phase @suggested_answer.destroy - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: _('Information was successfully deleted.') end end \ No newline at end of file diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index afaf084..a0521c9 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -157,7 +157,7 @@ authorize @template if @template.published? # published templates cannot be edited - redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.read_only') and return + redirect_to admin_template_template_path(@template), notice: _('Published templates cannot be edited.') and return end @template.description = params["template-desc"] if @template.update_attributes(params[:template]) @@ -168,7 +168,7 @@ new_version.published = false new_version.save! end - redirect_to admin_index_template_path(), notice: I18n.t('org_admin.templates.updated_message') + redirect_to admin_index_template_path(), notice: _('Information was successfully updated.') else render action: "edit" end @@ -196,7 +196,7 @@ end authorize @template if @template.save! - redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.created_message') + redirect_to admin_template_template_path(@template), notice: _('Information was successfully created.') else render action: "admin_new" end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 17ab73f..98b9c59 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -48,7 +48,7 @@ end end @user.save! - redirect_to({controller: 'users', action: 'admin_index'}, {notice: I18n.t('helpers.success')}) + redirect_to({controller: 'users', action: 'admin_index'}, {notice: _('Information was successfully updated.')}) # helpers.success key does not exist, replaced with a generic string end end diff --git a/app/models/plan.rb b/app/models/plan.rb index e28b8d3..4c5f974 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -289,7 +289,7 @@ answers.id as answerid, answers.plan_id as plan_id, answers.text as answertext, - answers.created_at as created, + answers.updated_at as updated, users.email as username') .where("questions.id in (?) and answers.plan_id = ?",question_ids, self.id) .to_a @@ -305,7 +305,7 @@ plan: rec.plan_id, id: rec.answerid, text: rec.answertext, - created: rec.created, + updated: rec.updated, user: rec.username } end @@ -326,7 +326,7 @@ aid = answer.nil? ? nil : answer[:id] atext = answer.nil? ? nil : answer[:text] - created = answer.nil? ? nil : answer[:created] + updated = answer.nil? ? nil : answer[:updated] uname = answer.nil? ? nil : answer[:user] space_used += height_of_text(stitle, 1, 1) @@ -356,7 +356,7 @@ status["questions"][qid] = { "format" => format, "answer_id" => aid, - "answer_created_at" => created.to_i, + "answer_updated_at" => updated.to_i, "answer_text" => atext, "answered_by" => uname } diff --git a/app/models/question.rb b/app/models/question.rb index c36aaef..f6c3b8a 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -45,7 +45,7 @@ end - def isOptionBased? + def option_based? format = self.question_format return format.option_based end diff --git a/app/views/answers/update.js.erb b/app/views/answers/update.js.erb index c26a623..1ffdc73 100644 --- a/app/views/answers/update.js.erb +++ b/app/views/answers/update.js.erb @@ -1,5 +1,3 @@ -console.log("Answer update called"); - // after saving the answer (and possibly getting a conflict) // set the message div about the answer. // On success this will be "" on error it will be the diff --git a/app/views/phases/_answer.html.erb b/app/views/phases/_answer.html.erb index d3563f9..7e74f5b 100644 --- a/app/views/phases/_answer.html.erb +++ b/app/views/phases/_answer.html.erb @@ -20,7 +20,7 @@ <%= af.inputs do %> - <% if question.isOptionBased? %> + <% if question.option_based? %> <% options = question.options.order("number") %> @@ -37,7 +37,7 @@ :collection => options, :label => false, :input_html => { :multiple => true , :disabled => :true } %> - <% elsif qformat.radiobuttons %> + <% elsif qformat.radiobuttons?%>
    <% options.each do |op| %>
  1. diff --git a/app/views/phases/_answer_form.html.erb b/app/views/phases/_answer_form.html.erb index dee0e31..31e4ee3 100644 --- a/app/views/phases/_answer_form.html.erb +++ b/app/views/phases/_answer_form.html.erb @@ -57,7 +57,7 @@
    - <% if question_obj.isOptionBased? %> + <% if question_obj.option_based? %> <% options = question.options.order("number") %> diff --git a/db/migrate/20170301105806_add_type_column_to_question_format.rb b/db/migrate/20170301105806_add_type_column_to_question_format.rb deleted file mode 100644 index 4931eb1..0000000 --- a/db/migrate/20170301105806_add_type_column_to_question_format.rb +++ /dev/null @@ -1,33 +0,0 @@ -class AddTypeColumnToQuestionFormat < ActiveRecord::Migration - def self.up - add_column :question_formats, :formattype, :integer, :default => 0 - QuestionFormat.all.each do |qf| - if qf.title == "Text area" - qf.textarea = true - end - if qf.title == "Text field" - qf.textfield = true - end - if qf.title == "Radio buttons" - qf.radiobuttons = true - end - if qf.title == "Check box" - qf.checkbox = true - end - if qf.title == "Dropdown" - qf.dropdown = true - end - if qf.title == "Multi select box" - qf.multiselectbox = true - end - if qf.title == "Date" - qf.date = true - end - qf.save - end - end - - def self.down - remove_column :question_formats, :formattype - end -end diff --git a/db/migrate/20170302111544_question_format_to_enum.rb b/db/migrate/20170302111544_question_format_to_enum.rb index 45624e2..760085e 100644 --- a/db/migrate/20170302111544_question_format_to_enum.rb +++ b/db/migrate/20170302111544_question_format_to_enum.rb @@ -1,5 +1,6 @@ class QuestionFormatToEnum < ActiveRecord::Migration def self.up + add_column :question_formats, :formattype, :integer, :default => 0 QuestionFormat.all.each do |qf| if qf.title == "Text area" qf.textarea! diff --git a/lib/assets/javascripts/plans.js b/lib/assets/javascripts/plans.js index aa1323a..89ac3d6 100644 --- a/lib/assets/javascripts/plans.js +++ b/lib/assets/javascripts/plans.js @@ -91,35 +91,21 @@ // Handle section actions on accordion expansion/collapse $('.section-collapse').on('show', function() { var section = $(this); - section.find(".loaded").show(); - section.find(".loading").show(); - // Only lock if there are forms on the page (not read-only) - //if ($('.question-form').length > 0) { - // section.check_section_lock(); - section.find(".question-form").show(); - // check for updated answers - // I (Ray) think we no longer want this but this needs - // replaced by the optimistic locking but I'm leaving it - // till the locking is re-imp0lemented -// $.getJSON("status.json", function(data) { -// $.fn.update_plan_progress(data); -// $(".section-status").each(function(){ -// $(this).update_section_progress(data); -// }); -// //For each question in section, check answer timestamp against currently displayed -// var section_id = section.attr("id").split('-')[1]; -// var num_questions = data.sections[section_id]["questions"].length; -// for (var i = 0; i < num_questions; i++) { -// question_id = data.sections[section_id]["questions"][i]; -// //If timestamp newer than displayed, update answers -// if ($.fn.update_timestamp(question_id, data)) { -// $.fn.update_answer(question_id); -// } -// } -// section.find(".loading").hide(); -// section.find(".loaded").show(); -// }); + $.getJSON("status.json", function(data) { + $.fn.update_plan_progress(data); + $(".section-status").each(function(){ + $(this).update_section_progress(data); + }); + + //For each question in section, check answer timestamp against currently displayed + var section_id = section.attr("id").split('-')[1]; + var num_questions = data.sections[section_id]["questions"].length; + for (var i = 0; i < num_questions; i++) { + question_id = data.sections[section_id]["questions"][i]; + $.fn.update_timestamp(question_id, data) + } + }); }).on('hide', function(){ var section = $(this); // Only attempt unlock if there are forms on the page (not read-only) @@ -355,70 +341,6 @@ return false; }; -$.fn.update_answer = function(question_id) { - $.ajax({ - type: 'GET', - url: "answer.json?q_id="+question_id, - dataType: 'json', - async: false, //Needs to be synchronous, otherwise end up mixing up answers - success: function(data) { - if (data != null) { - //Get divs containing the form and readonly versions - var form_div = $("#question-form-"+question_id); - var readonly_div = $("#question-readonly-"+question_id); - //Look for textfields - if ($("input#answer-text-"+question_id).length == 1) { - $("input#answer-text-"+question_id).val(data.text); - readonly_div.find('.answer-text-readonly').html("

    "+data.text+"

    "); - } - else { - //Update answer text - both in textarea and readonly - $('#answer-text-'+question_id).val(data.text); - tinymce.get('answer-text-'+question_id).setContent(data.text); - readonly_div.find('.answer-text-readonly').html(data.text); - } - //Update answer options - both in form and readonly - num_options = data.options.length; - form_div.find('option').each(function(){ - var selected = false; - for (var j =0; j < num_options; j++) { - if ($(this).val() == data.options[j].id) { - selected = true; - } - } - if (selected) { - $(this).attr('selected', 'selected'); - } - else { - $(this).removeAttr('selected'); - } - }); - form_div.find(':checkbox,:radio').each(function(){ - var selected = false; - for (var j =0; j < num_options; j++) { - if ($(this).val() == data.options[j].id) { - selected = true; - } - } - if (selected) { - $(this).attr('checked', 'checked'); - } - else { - $(this).removeAttr('checked'); - } - }); - - var list_string = ""; - for (var j =0; j < num_options; j++) { - list_string += "
  2. "+data.options[j].text+"
  3. "; - } - readonly_div.find('.options').html(list_string); - form_div.closest(".accordion-group").find(".section-status:first").toggle_dirty(question_id, false); - } - } - }); - -}; $.fn.update_section_progress = function(data) { s_id = $(this).attr("id").split('-')[0]; @@ -456,8 +378,7 @@ q_status = $('#'+question_id+'-status'); var t = q_status.children("abbr:first"); var current_timestamp = new Date(t.attr('data-time')); - var timestamp = data.questions[question_id]["answer_created_at"]; - var timestamp = data.questions[question_id]["answer_created_at"]; + var timestamp = data.questions[question_id]["answer_updated_at"]; if (timestamp != null) { timestamp = new Date(Number(timestamp) * 1000); if (timestamp.getTime() != current_timestamp.getTime()) {