Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Client-side Validation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
enkodellc committed Jun 6, 2014
1 parent 19e937c commit 8524d5f
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions public/modules/articles/controllers/articles.client.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ angular.module('articles').controller('ArticlesController', ['$scope', '$statePa
function($scope, $stateParams, $location, Authentication, Articles) {
$scope.authentication = Authentication;

$scope.create = function() {
var article = new Articles({
title: this.title,
content: this.content
});
article.$save(function(response) {
$location.path('articles/' + response._id);
}, function(errorResponse) {
$scope.error = errorResponse.data.message;
});

this.title = '';
this.content = '';
$scope.create = function(isValid) {
if (isValid) {
var article = new Articles({
title: this.title,
content: this.content
});
article.$save(function(response) {
$location.path('articles/' + response._id);
}, function(errorResponse) {
$scope.error = errorResponse.data.message;
});

this.title = '';
this.content = '';
}else{
$scope.submitted = true;
}
};

$scope.remove = function(article) {
Expand All @@ -35,14 +39,18 @@ angular.module('articles').controller('ArticlesController', ['$scope', '$statePa
}
};

$scope.update = function() {
var article = $scope.article;

article.$update(function() {
$location.path('articles/' + article._id);
}, function(errorResponse) {
$scope.error = errorResponse.data.message;
});
$scope.update = function(isValid) {
if (isValid) {
var article = $scope.article;

article.$update(function() {
$location.path('articles/' + article._id);
}, function(errorResponse) {
$scope.error = errorResponse.data.message;
});
}else{
$scope.submitted = true;
}
};

$scope.find = function() {
Expand All @@ -55,4 +63,4 @@ angular.module('articles').controller('ArticlesController', ['$scope', '$statePa
});
};
}
]);
]);

0 comments on commit 8524d5f

Please sign in to comment.