'use strict';

angular.module('app')
    .controller('rgiAssessmentStatusDialogCtrl', function (
        $scope,
        rgiNotifier,
        rgiAssessmentMethodSrvc
    ) {
        var
            setStatus = function(assessment, status) {
                assessment.status = status;
                $scope.statuses[$scope.assessmentId] = status;
            },
            getAssessment = function() {
                var foundAssessment = {};

                $scope.assessments.forEach(function(assessment) {
                    if(assessment._id === $scope.assessmentId) {
                        foundAssessment = assessment;
                    }
                });

                return foundAssessment;
            };

        $scope.setStatus = function () {
            var assessment = getAssessment(),
                originalStatus = assessment.status;

            setStatus(assessment, $scope.newStatus);

            rgiAssessmentMethodSrvc.updateAssessment(assessment)
                .then(function () {
                    rgiNotifier.notify('Status changed!');
                }, function (reason) {
                    rgiNotifier.error(reason);
                    setStatus(assessment, originalStatus);
                }).finally($scope.closeThisDialog);
        };
    });

@@ -332,32 +332,220 @@
 entId%5D = status;
+%0A%0A                if((status.indexOf('reviewer') === 0) && (assessment.reviewer_ID !== undefined)) %7B%0A                    assessment.edit_control = assessment.reviewer_ID;%0A                %7D
 %0A            %7D,%0A

set `edit_control` field on manual change of assessment status