Skip to content

Commit

Permalink
StudentSupportForm: Move form lock calculations to reducer #1450
Browse files Browse the repository at this point in the history
  • Loading branch information
ltwheeler committed Nov 28, 2017
1 parent 4eb3548 commit 187a457
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,10 @@ instructionalSupportApp.controller('StudentSupportCallFormCtrl', ['$scope', '$ro
};

$scope.termCode = $scope.termShortCodeToTermCode($scope.termShortCode);

// Form locks when a due date has been set, and has passed
$scope.isFormLocked = function () {
if (!$scope.view.state.supportCallResponse) {
return false;
}
// Validate dueDate
var dueDate = $scope.view.state.supportCallResponse.dueDate;
var submitAfterDueDate = $scope.view.state.supportCallResponse.allowSubmissionAfterDueDate;

if (dueDate) {
if (submitAfterDueDate == false) {
var date = new Date();
var currentTime = date.getTime();

if (currentTime > dueDate) {
return true;
}
}
}

return false;
};

$scope.studentSupportCallFormIsValid = function () {
// Validate dueDate
if ( $scope.isFormLocked() ) {
if ($scope.view.state.ui.isFormLocked) {
$scope.validationError = "The due date for this support call has passed.";
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</div>
</div>
<div>
<i ng-if="isFormLocked() == false" class="glyphicon glyphicon-remove student-course-remove"
<i ng-if="view.state.ui.isFormLocked == false" class="glyphicon glyphicon-remove student-course-remove"
uib-tooltip="Delete preference" tooltip-placement="bottom"
confirm-button="deletePreference(preference)"
message="Are you sure you want to delete this preference?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,21 @@ instructionalSupportApp.service('studentReducers', function ($rootScope, $log, s
switch (action.type) {
case INIT_STATE:
ui = {
isPreferenceCommentModalOpen: false
isPreferenceCommentModalOpen: false,
isFormLocked: false
};

// Determine if form should be locked (due date is enforced and has passed)
if (action.payload.supportCallResponse) {
var dueDate = action.payload.supportCallResponse.dueDate;
var dueDateEnforced = action.payload.supportCallResponse.allowSubmissionAfterDueDate == false;
if (dueDate && dueDateEnforced) {
var currentTime = new Date().getTime();
if (currentTime > dueDate) {
ui.isFormLocked = true;
}
}
}
return ui;
case OPEN_PREFERENCE_COMMENT_MODAL:
ui.isPreferenceCommentModalOpen = true;
return ui;
Expand Down

0 comments on commit 187a457

Please sign in to comment.