diff --git a/app/assets/javascripts/my_modules.js b/app/assets/javascripts/my_modules.js index 5da8865b8..bfb2d26c6 100644 --- a/app/assets/javascripts/my_modules.js +++ b/app/assets/javascripts/my_modules.js @@ -220,10 +220,8 @@ function bindEditTagsAjax() { // Sets callback for completing/uncompleting task function applyTaskCompletedCallBack() { // First, remove old event handlers, as we use turbolinks - $("[data-action='complete-task'], [data-action='uncomplete-task']").off(); - $("[data-action='complete-task'], [data-action='uncomplete-task']") - .on('click', function() { + .off().on('click', function() { var button = $(this); $.ajax({ url: button.data('link-url'), diff --git a/app/assets/javascripts/protocols/steps.js.erb b/app/assets/javascripts/protocols/steps.js.erb index 8e108b001..b51e903b6 100644 --- a/app/assets/javascripts/protocols/steps.js.erb +++ b/app/assets/javascripts/protocols/steps.js.erb @@ -27,9 +27,8 @@ function applyCheckboxCallBack() { // Sets callback for completing/uncompleting step function applyStepCompletedCallBack() { // First, remove old event handlers, as we use turbolinks - $("[data-action='complete-step'], [data-action='uncomplete-step']").off(); - - $("[data-action='complete-step'], [data-action='uncomplete-step']").on('click', function(e){ + $("[data-action='complete-step'], [data-action='uncomplete-step']") + .off().on('click', function(e){ var button = $(this); var step = $(this).parents(".step"); var completed = !step.hasClass("completed"); diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index 044d73231..469324681 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -192,12 +192,10 @@ class MyModulesController < ApplicationController if saved format.json { alerts = [] - if @my_module.is_overdue? && !@my_module.completed? - alerts << 'alert-red' - elsif @my_module.is_one_day_prior? && !@my_module.completed? - alerts << 'alert-yellow' - elsif @my_module.completed? - alerts << 'alert-green' + alerts << 'alert-green' if @my_module.completed? + unless @my_module.completed? + alerts << 'alert-red' if @my_module.is_overdue? + alerts << 'alert-yellow' if @my_module.is_one_day_prior? end render json: { status: :ok, @@ -352,11 +350,8 @@ class MyModulesController < ApplicationController completed = @my_module.completed? if @my_module.save # Create activity - str = if completed - 'activities.complete_module' - else - 'activities.uncomplete_module' - end + str = 'activities.uncomplete_module' + str = 'activities.complete_module' if completed message = t(str, user: current_user.full_name, module: @my_module.name) @@ -398,11 +393,8 @@ class MyModulesController < ApplicationController end # Create localized title for complete/uncomplete button - button_title = if completed - t('my_modules.buttons.uncomplete') - else - t('my_modules.buttons.complete') - end + button_title = t('my_modules.buttons.complete') + button_title = t('my_modules.buttons.uncomplete') if completed format.json do render json: { diff --git a/app/helpers/my_modules_helper.rb b/app/helpers/my_modules_helper.rb index aedd39178..75dc21eb5 100644 --- a/app/helpers/my_modules_helper.rb +++ b/app/helpers/my_modules_helper.rb @@ -19,6 +19,17 @@ module MyModulesHelper my_module.results.where(archived: false).order(created_at: :desc) end + def get_task_alert_color(my_module) + alert = '' + if !my_module.completed? + alert = ' alert-yellow' if my_module.is_one_day_prior? + alert = ' alert-red' if my_module.is_overdue? + elsif my_module.completed? + alert = ' alert-green' + end + alert + end + def is_steps_page? action_name == "steps" end diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 02bc70fb1..ddcb74e81 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -389,8 +389,7 @@ class MyModule < ActiveRecord::Base completed = false unless step.completed end if completed - complete - save! + update_attributes(state: 'completed', completed_on: DateTime.now) return true end end diff --git a/app/views/canvas/full_zoom/_my_module.html.erb b/app/views/canvas/full_zoom/_my_module.html.erb index 73fc963af..d223470e1 100644 --- a/app/views/canvas/full_zoom/_my_module.html.erb +++ b/app/views/canvas/full_zoom/_my_module.html.erb @@ -1,7 +1,5 @@