Last active
August 29, 2015 14:02
-
-
Save liorkesos/8b0da339167bbace42b4 to your computer and use it in GitHub Desktop.
Arricles packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('mean').controller('ArticlesController', ['$scope', '$stateParams', '$location', 'Global', 'Articles', | |
function($scope, $stateParams, $location, Global, Articles) { | |
$scope.global = Global; | |
$scope.hasAuthorization = function(article) { | |
if (!article || !article.user) return false; | |
return $scope.global.isAdmin || article.user._id === $scope.global.user._id; | |
}; | |
$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); | |
}); | |
this.title = ''; | |
this.content = ''; | |
} else { | |
$scope.submitted = true; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section data-ng-controller="ArticlesController"> | |
<form name="articleForm" class="form-horizontal col-md-6" role="form" data-ng-submit="create(articleForm.$valid)" novalidate> | |
<div class="form-group" ng-class="{ 'has-error' : submitted && articleForm.title.$invalid }"> | |
<label mean-token="'create-title'" class="col-md-3 control-label">Title</label> | |
<div class="col-md-9"> | |
<input name="title" type="text" class="form-control" data-ng-model="title" id="title" placeholder="Title" required> | |
<div ng-show="submitted && articleForm.title.$invalid" class="help-block"> | |
<p ng-show="articleForm.title.$error.required">Title is required</p> | |
</div> | |
</div> | |
</div> | |
<div class="form-group" ng-class="{ 'has-error' : submitted && articleForm.content.$invalid }"> | |
<label mean-token="'create-content'" for="content" class="col-md-3 control-label">Content</label> | |
<div class="col-md-9"> | |
<textarea name="content" data-ng-model="content" id="content" cols="30" rows="10" placeholder="Content" class="form-control" required></textarea> | |
<div ng-show="submitted && articleForm.content.$invalid" class="help-block"> | |
<p ng-show="articleForm.content.$error.required">Content is required</p> | |
</div> | |
</div> | |
</div> | |
<div class="form-group"> | |
<div class="col-md-offset-3 col-md-9"> | |
<button type="submit" class="btn btn-info">Submit</button> | |
</div> | |
</div> | |
</form> | |
</section> | |
~ | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment