@@ -15,55 +15,45 @@ angular.module('ionic-nodeclub')
1515 $ionicActionSheet
1616) ->
1717
18+ collectTopic = ->
19+ authService
20+ .isAuthenticated ()
21+ .then ->
22+ if $scope .isCollected
23+ userService .deCollectTopic $scope .topic
24+ .then ->
25+ $scope .isCollected = false
26+ toast ' 已取消收藏'
27+ else
28+ userService .collectTopic $scope .topic
29+ .then ->
30+ $scope .isCollected = true
31+ toast ' 收藏成功'
32+
33+ loadTopic = (refresh ) ->
34+ $scope .loading = true
35+ topicService .getDetail $stateParams .topicId , refresh
36+ .then (topic) ->
37+ $scope .topic = topic
38+ .catch (error) ->
39+ $scope .error = error
40+ .finally ->
41+ $scope .loading = false
42+ $scope .$broadcast (' scroll.refreshComplete' )
43+
1844 angular .extend $scope,
1945 loading : false
2046 isCollected : false
2147 error : null
2248 topic : null
2349
24- loadTopic : (reload = false ) ->
25- $scope .loading = true
26- topicService .getDetail $stateParams .topicId , reload
27- .then (topic) ->
28- $scope .topic = topic
29- .catch (error) ->
30- $scope .error = error
31- .finally ->
32- $scope .loading = false
33-
34- collectTopic : (topic ) ->
35- authService
36- .isAuthenticated ()
37- .then ->
38- if $scope .isCollected
39- userService .deCollectTopic topic
40- .then ->
41- $scope .isCollected = false
42- toast ' 已取消收藏'
43- else
44- userService .collectTopic topic
45- .then ->
46- $scope .isCollected = true
47- toast ' 收藏成功'
48-
49- replyTopic : ->
50- authService
51- .isAuthenticated ()
52- .then ->
53- $state .go ' app.replies' , topicId : $stateParams .topicId
54-
55- myCollect : ->
56- authService
57- .isAuthenticated ()
58- .then (me) ->
59- $state .go ' app.user' , loginname : me .loginname
50+ doRefresh : ->
51+ loadTopic (refresh = true )
6052
6153 showTopicAction : ->
6254 $ionicActionSheet .show
6355 buttons : [
64- text : ' 重新加载'
65- ,
66- text : ' 回复话题'
56+ text : ' 话题回复'
6757 ,
6858 text : if ! $scope .isCollected then ' 收藏话题' else ' 取消收藏'
6959 ,
@@ -74,20 +64,17 @@ angular.module('ionic-nodeclub')
7464 buttonClicked : (index ) ->
7565 switch index
7666 when 0
77- $scope . loadTopic ( true )
67+ $state . go ' app.replies ' , topicId : $stateParams . topicId
7868 when 1
79- $scope . replyTopic ()
69+ collectTopic ()
8070 when 2
81- $scope .collectTopic ()
82- when 3
8371 $state .go ' app.user' , loginname : $scope .topic .author .loginname
8472 else
8573 window .open " #{ API .server } /topic/#{ $stateParams .topicId } " , ' _system'
8674 return true
8775
8876
89-
90- $scope .loadTopic ()
77+ loadTopic (refresh = false )
9178 userService .checkCollect $stateParams .topicId
9279 .then (isCollected) ->
9380 $scope .isCollected = isCollected
0 commit comments