{"size": 1275, "ext": "js", "max_stars_repo_path": "src/nor/norApp/directives/norForm/controller.js", "max_stars_repo_name": "sendanor/nor-app", "max_stars_repo_stars_event_min_datetime": "2020-08-28T08:22:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-28T08:22:05.000Z", "max_issues_repo_path": "src/nor/norApp/directives/norForm/controller.js", "max_issues_repo_name": "sendanor/nor-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nor/norApp/directives/norForm/controller.js", "max_forks_repo_name": "sendanor/nor-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.5, "max_line_length": 124, "alphanum_fraction": 0.6070588235}
"use strict";

/* Forms */
module.exports = ['$scope', '$http', '$log', '$location', 'norRouter', function($scope, $http, $log, $location, norRouter) {

	$scope.content = $scope.content || ($scope.model && $scope.model.content) || [];
	$scope.data = {};

	//norRouter.addResetAction(function() {
	//	$scope.data = {};
	//});

	/** Submit a form with HTTP POST action to REST API */
	$scope.submit = function() {
		$log.debug("form submit called: ", $scope.data );

		var path = $scope.model.$target || $location.path();
		norRouter.post(path, $scope.data).then(function(data) {
			$log.debug('data = ', data);
			//norRouter.reset();
			//norRouter.changeScopeData($scope.model, data);
			$scope.data = {};
			norRouter.resetModel($scope.model, data);
		}, function errorCallback(response) {
			$log.error("error: ", response);
		});

	};

	// Alerts
	$scope.alerts = [];

	/** Close alert */
	$scope.closeAlert = function(alert) {
		$scope.alerts = $scope.alerts.filter(function(a) {
			return a !== alert;
		});
	};

	/** Create an alert */
	$scope.openAlert = function(alert) {
			alert = alert || {};
			alert.type = alert.type || "danger";
			alert.title = alert.title || "Unknown Alert";
			alert.content = alert.content || "";
			$scope.alerts.push( alert );
	};

}];
