'use strict';

// Blogs controller
angular.module('blogs').controller('BlogsController', ['$scope', '$stateParams', '$location', 'Authentication', 'Blogs',
	function($scope, $stateParams, $location, Authentication, Blogs) {
		$scope.authentication = Authentication;

		// Create new Blog
		$scope.create = function() {
			console.log(this)

			// Create new Blog object
			var blog = new Blogs ({
				name: this.name,
				category: this.category,
				content: this.content
			});

			// Redirect after save
			blog.$save(function(response) {
				$location.path('blogs/' + response._id);

				// Clear form fields
				$scope.name = '';
			}, function(errorResponse) {
				$scope.error = errorResponse.data.message;
			});
		};

		// Remove existing Blog
		$scope.remove = function(blog) {
			if ( blog ) { 
				blog.$remove();

				for (var i in $scope.blogs) {
					if ($scope.blogs [i] === blog) {
						$scope.blogs.splice(i, 1);
					}
				}
			} else {
				$scope.blog.$remove(function() {
					$location.path('blogs');
				});
			}
		};

		// Update existing Blog
		$scope.update = function() {
			var blog = $scope.blog;

			blog.$update(function() {
				$location.path('blogs/' + blog._id);
			}, function(errorResponse) {
				$scope.error = errorResponse.data.message;
			});
		};

		// Find a list of Blogs
		$scope.find = function() {
			$scope.blogs = Blogs.query();
		};

		// Find existing Blog
		$scope.findOne = function() {
			$scope.blog = Blogs.get({ 
				blogId: $stateParams.blogId
			});
		};
	}
]);
@@ -260,16 +260,190 @@
 ation;%0A%0A
+%09%09$scope.categories = %5B%0A%09       %22Auto Deportivo%22,%0A%09       %22Auto Familiar%22,%0A%09       %22Camioneta Deportiva%22,%0A%09       %22Camioneta Familiar%22,%0A%09       %22Vehiculo Todo Terreno%22%0A%09%09%5D;%0A%0A
 %09%09// Cre
@@ -612,16 +612,24 @@
 category
+Selected
 ,%0A%09%09%09%09co

Add categories