/**
 * BookingsSupportCtrl Controller
 * Extracted from bookings module
 */

Bookings.controller('BookingsSupportCtrl', ['$scope', '$route', '$routeParams', '$location', 'supportForm', '$ClientsManager', 'BookingsLocationManager', 'TaskTemplatesService', function ($scope, $route, $routeParams, $location, supportForm, $ClientsManager, BookingsLocationManager, TaskTemplatesService) {

	// ------------------------------------------------------------------------
	//
	//	SCOPE VARIABLES BELOW -->
	//
	// ------------------------------------------------------------------------

	$scope.data = supportForm.data;

	// working with the shared service managers
	$scope.clientManager = $ClientsManager;
	$scope.locationManager = BookingsLocationManager;

	$scope.form = supportForm;
	$scope.routeParams = $routeParams;

	// added by nadeem 13.2.17 - if the user use the add task to project button 
	// then this will pass the project id forward to the back-end
	// the crated task will then be correctly associated with the correct project
	if (typeof ($scope.$parent.projectId != 'undefined')) {
		$scope.data.project_id = $scope.$parent.projectId;
	}

	/**
	 * Bind the task templates typeahead remote options to the scope.
	 *
	 * @object
	 */
	$scope.templatesRemoteOptions = TaskTemplatesService;

	// ------------------------------------------------------------------------
	//
	//	WATCHERS AND EVENT LISTENERS BELOW -->
	//
	// ------------------------------------------------------------------------
	$scope.$watch('data.site_user_id', function () {
		$scope.data.direct_dial = BookingsLocationManager.getUserDDI($scope.data.site_user_id);
	});

	$scope.$watch('data.site_id', function () {
		$scope.data.direct_dial = BookingsLocationManager.getUserDDI($scope.data.site_user_id);
	});

	$scope.$watch('data.urgent', function (value) {
		if (value == '1' && !$scope.data.severity_id) {
			$scope.data.severity_id = 3;
		}
	});

	// ------------------------------------------------------------------------
	//
	//	FUNCTIONS BELOW THIS LINE -->
	//
	// ------------------------------------------------------------------------


}]);
