Permalink
Browse files

Tidyup EntryListController

  • Loading branch information...
1 parent 420bfe9 commit f4df34d35c12ebc185c78d8aed2e302977a83819 Michael Hughes committed Mar 24, 2013
Showing with 34 additions and 16 deletions.
  1. +19 −16 src/client/EntryListController.coffee
  2. +15 −0 test/client/unit/EntryListController_test.coffee
@@ -15,35 +15,38 @@ 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]
if entry.state==states.STARRED
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
@@ -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"}
+ ]
+
+

0 comments on commit f4df34d

Please sign in to comment.