/**
 * BookingsMessageCtrl Controller
 * Extracted from bookings module
 */

Bookings.controller('BookingsMessageCtrl', ['$scope', '$route', '$routeParams', '$location', '_messageForm', '$ClientsManager', 'BookingsLocationManager', function ($scope, $route, $routeParams, $location, _messageForm, $ClientsManager, BookingsLocationManager) {

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

	$scope.data = _messageForm.data;

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

	$scope.form = _messageForm;
	$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;
	}

	// ------------------------------------------------------------------------
	//
	//	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);
	});


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

	$scope.save = _messageForm.save;

}]);
