'use strict';
app.controller('resetPasswordDialogController', ['$scope', '$http', '$modalInstance', '$translate', 'blockUI', 'lib', 'userId', function ($scope, $http, $modalInstance, $translate, blockUI, lib, userId) {

	$scope.password = '';
	$scope.passwordConfirm = '';

	var init = function () {
	};

	$scope.submit = function () {
		
		if ($scope.password === '') {
			$translate(['message', 'ucFillPassword']).then(function (msgs) {
				lib.showAlert(msgs.message, msgs.ucFillPassword);
			});
			return;
		}
		if ($scope.passwordConfirm === '') {
			$translate(['message', 'ucFillPasswordConfirm']).then(function (msgs) {
				lib.showAlert(msgs.message, msgs.ucFillPasswordConfirm);
			});
			return;
		}
		if ($scope.password !== $scope.passwordConfirm) {
			$translate(['message', 'ucPasswordsDoNotMatch']).then(function (msgs) {
				lib.showAlert(msgs.message, msgs.ucPasswordsDoNotMatch);
			});
			return;
		}

		blockUI.start();
		$http.put('/Api/Users/' + userId + '/Password', {
			password: $scope.password
		}).then(function (response) {
			blockUI.stop();
			$modalInstance.close();
		}, lib.handleRestError);
	};

	$scope.cancel = function () {
		$modalInstance.close();
	};

	init();
}]);
