Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tidyup EntryListController

  • Loading branch information...
commit f4df34d35c12ebc185c78d8aed2e302977a83819 1 parent 420bfe9
Michael Hughes authored
View
35 src/client/EntryListController.coffee
@@ -15,21 +15,21 @@ controller.EntryListCtrl = ($scope,$http)->
$scope.entries = data
.error (data,status)->
- ignoreOutput = (data,status)->
-
- $scope.encode = (url)->
- encodeURIComponent url
-
- $scope.plusMinus = (open)->
- if open then "minus" else "plus"
+ #internal functions
+ $scope.changeState = (entry,state)->
+ ignoreOutput = (data,status)->
+
+ if $http
+ $http.get("/changeState?state=" + state + "&id=" + $scope.encode(entry.id))
+ .success(ignoreOutput)
+ .error(ignoreOutput)
+ #events
$scope.remove = (index)->
entry = $scope.entries[index]
$scope.entries.splice index,1
- if $http
- $http.get("/changeState?state=" + states.ARCHIVED + "&id=" + $scope.encode(entry.id))
- .success(ignoreOutput)
- .error(ignoreOutput)
+ $scope.changeState entry,states.ARCHIVED
+
$scope.star = (index)->
entry = $scope.entries[index]
@@ -37,13 +37,16 @@ controller.EntryListCtrl = ($scope,$http)->
entry.state=states.NEW
else
entry.state=states.STARRED
- if $http
- $http.get("/changeState?state="+ entry.state + "&id=" + $scope.encode(entry.id))
- .success(ignoreOutput)
- .error(ignoreOutput)
+ $scope.changeState entry,entry.state
+
+ # Template helpers
+ $scope.encode = (url)->
+ encodeURIComponent url
+
+ $scope.plusMinus = (open)->
+ if open then "minus" else "plus"
$scope.status = (state)->
if state==states.STARRED then "" else "-empty"
-
scope:$scope
View
15 test/client/unit/EntryListController_test.coffee
@@ -15,4 +15,19 @@ describe 'A EntryListCtrl controller', ->
{title:"c",id:"cc"}
]
+ it 'should be able to star entries in a list', ()->
+ c = new controller.EntryListCtrl({})
+ c.scope.entries = [
+ {title:"a",id:"aa",state:"new"},
+ {title:"b",id:"bb",state:"new"},
+ {title:"c",id:"cc",state:"new"}
+ ]
+ c.scope.star(1)
+ expect(c.scope.entries).to.eql [
+ {title:"a",id:"aa",state:"new"},
+ {title:"b",id:"bb",state:"starred"},
+ {title:"c",id:"cc",state:"new"}
+ ]
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.