/**
 * SiteModalCtrl Controller
 * Extracted from clients module
 */

ClientsModule.controller('SiteModalCtrl', ['$scope', '$uibModalInstance', 'data', 'DoNotSave', 'Site', 'ErrorsHandler', 'client_id', function ($scope, $uibModalInstance, data, DoNotSave, Site, ErrorsHandler, client_id) {

	$scope.data = data || {};
	$scope.data.client_id = client_id;

	$scope.submit = function () {

		if (!DoNotSave) {
			if ($scope.data.id) {
				Site.update($scope.data, function (response) {
					$uibModalInstance.close(response);
				}, ErrorsHandler);
			}
			else {
				Site.save($scope.data, function (response) {
					$uibModalInstance.close(response);
				}, ErrorsHandler);
			}
		}
		else {
			$uibModalInstance.close($scope.data);
		}
	};

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