/**
 * TaskPasswordCtrl Controller
 * Extracted from bookings module
 */

Bookings.controller('TaskPasswordCtrl', ['$scope', 'taskDevices', '$uibModalInstance', 'password', 'keychainTypes', function ($scope, taskDevices, $uibModalInstance, password, keychainTypes) {

	$scope.data = {
		password: password,
		devices: taskDevices,
		types: keychainTypes
	};

	//Initialize the type if it is empty
	if (!$scope.data.password.type)
		$scope.data.password.type = "windows";

	$scope.save = function () {
		$uibModalInstance.close($scope.data.password);
	};

	$scope.cancel = function () {
		$uibModalInstance.dismiss('cancel');
	};

	$scope.isFormValid = function () {
		if (!$scope.data.password.username)
			return false;

		if (!$scope.data.password.password)
			return false;

		return true;
	}
}]);
