Skip to content

Instantly share code, notes, and snippets.

@funkytaco
Forked from AlexFrazer/controller.js
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funkytaco/f1a454c84c9f8ec0aad7 to your computer and use it in GitHub Desktop.
Save funkytaco/f1a454c84c9f8ec0aad7 to your computer and use it in GitHub Desktop.
'use strict';
angular.module('app')
.controller('CreateWorkflowCtrl', function($scope, $location, Workflow, Category) {
$scope.workflow = new Workflow();
$scope.page = 0;
$scope.create = function() {
$scope.workflow.$save(function(data) {
$location.path("/workflow/" + data.id);
}, function(err) {
$scope.$broadcast('error', error);
});
};
$scope.updateCategories = function() {
Category.query({ page: $scope.page }, function(data) {
$scope.categories = data;
}, function(err) {
$scope.$broadcast('error', err);
});
}
$scope.$watch('page', $scope.updateCategories);
$scope.$on('error', function(error) {
// TO DO: add validation warnings.
});
});
<form class="form-horizontal container" role="form" ng-submit="create()">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control"
ng-model="workflow.name" ng-required ng-maxlength="1024"
/>
</div>
<h4>Categories</h4>
<hr/>
<div ng-switch="categories.num_results">
<div ng-switch-when="0" class="text-center">
<p class="text-muted">
There are currently no categories available.
You must make a category before you can make a workflow.
</p>
<a class="btn btn-default btn-large" href="/#/create/category">
Make one now
</a>
</div>
<div ng-switch-default>
<div class="row">
<div class="col-md-4">
<div class="form-group" ng-repeat="category in categories.objects">
<!-- HERE BE THE PROBLEM -->
</div>
</div>
</div>
</div>
</div>
<div class="text-center paging">
<pagination
ng-model="page"
num-pages="categories.total_pages"
total-items="categories.num_results"
>
</pagination>
</div>
<button type="submit" class="btn btn-large btn-success pull-right">
Create
</button>
@funkytaco
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment