Skip to content

Instantly share code, notes, and snippets.

@rbinsztock
Created August 3, 2013 18:31
Show Gist options
  • Save rbinsztock/6147485 to your computer and use it in GitHub Desktop.
Save rbinsztock/6147485 to your computer and use it in GitHub Desktop.
app.controller "ArticlesController", ($scope, $http, $location, $state, $stateParams, Article) ->
# =========================================================================
# Initialize
# =========================================================================
$scope.articles = {}
$scope.article = {}
# =========================================================================
# Show
# =========================================================================
if $state.current.name == 'articles'
Article.query(
{}
# Success
, (response) ->
$scope.articles = response
# Error
, (response) ->
)
if $state.current.name == 'show'
Article.get
id: $stateParams['id']
# Success
, (response) ->
$scope.article = response
# Error
, (response) ->
# =========================================================================
# Create
# =========================================================================
$scope.create = ->
Article.save(
{}
, article:
title: $scope.article.title
description: $scope.article.content
# Success
, (response) ->
$location.path "/articles"
# Error
, (response) ->
)
# =========================================================================
# Update
# =========================================================================
if $state.current.name == 'edit'
Article.get
id: $stateParams['id']
# Success
, (response) ->
$scope.article = response
# Error
, (response) ->
$scope.update = ->
Article.update
id: $stateParams['id']
, article:
title: $scope.article.title
description: $scope.article.content
# Success
, (response) ->
$location.path "/articles"
# Error
, (response) ->
# =========================================================================
# Destroy
# =========================================================================
$scope.destroy = (id) ->
Article.delete
id: id
# Success
, (response) ->
i = 0
while i < $scope.articles.length
if $scope.articles[i]['id'] is id
$scope.articles.splice(i,1)
i++
# Error
, (response) ->
@rbinsztock
Copy link
Author

SyntaxError: unexpected TERMINATOR

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