@@ -28,7 +28,10 @@ class Kandan.Helpers.Channels
28
28
@ channel_pagination_el: (channelId )->
29
29
$ (" #channels-#{ channelId} .pagination" )
30
30
31
- @ getChannelIdFromTabIndex: (tabIndex )->
31
+ @ getTabIndexByChannelId: (channelId )->
32
+ $ (" #channels-#{ channelId} " ).prev (" div" ).length
33
+
34
+ @ getChannelIdByTabIndex: (tabIndex )->
32
35
$ (" #channels .ui-tabs-panel" )
33
36
.eq (tabIndex)
34
37
.data (' channel_id' )
@@ -50,24 +53,34 @@ class Kandan.Helpers.Channels
50
53
confirmAgain = confirm (" Are you damn sure?" )
51
54
return confirmAgain
52
55
53
- @ flushActivities: (channelID )->
54
- $channelActivities = $ (" #channel-activities-#{ channelID } " )
56
+ @ flushActivities: (channelId )->
57
+ $channelActivities = $ (" #channel-activities-#{ channelId } " )
55
58
if $channelActivities .children ().length > @options .maxActivities
56
59
oldest = $channelActivities .children ().first ().data (" activity_id" )
57
60
$channelActivities .children ().first ().remove ()
58
61
$channelActivities .prev ().data (" oldest" , oldest)
59
62
60
- @ deleteChannel : (channelIndex )->
61
- channelId = @ getChannelIdFromTabIndex (channelIndex )
62
- channel = new Kandan.Models.Channel ({ id : channelId} )
63
- return false if @ confirmDeletion () == false
63
+ @ deleteChannelById : (channelId )->
64
+ if @ channelExists (channelId )
65
+ tabIndex = @ getTabIndexByChannelId ( channelId)
66
+ @ deleteChannelByTabIndex (tabIndex, true )
64
67
68
+ @ confirmAndDeleteChannel: (channel , tabIndex )->
69
+ return false if @ confirmDeletion () == false
65
70
channel .destroy ({success : ()=>
66
- $ (" #channels" ).tabs (" remove" , channelIndex )
71
+ $ (" #channels" ).tabs (" remove" , tabIndex )
67
72
})
68
73
69
- @ channel_not_exists: (channelId )->
70
- $ (" #channels-#{ channelId} " ).length == 0
74
+ @ deleteChannelByTabIndex: (tabIndex , deleted )->
75
+ deleted = deleted || false
76
+ channelId = @ getChannelIdByTabIndex (tabIndex)
77
+ channel = new Kandan.Models.Channel ({id : channelId})
78
+ return @ confirmAndDeleteChannel (channel, tabIndex) if not deleted
79
+ $ (" #channels" ).tabs (" remove" , tabIndex)
80
+
81
+ @ channelExists: (channelId )->
82
+ return true if $ (" #channels-#{ channelId} " ).length > 0
83
+ false
71
84
72
85
73
86
@ create_channel_area: (channel )->
@@ -88,7 +101,7 @@ class Kandan.Helpers.Channels
88
101
89
102
90
103
@ add_activity: (activity_attributes , state )->
91
- if activity_attributes .channel != undefined && @ channel_not_exists (activity_attributes .channel_id )
104
+ if activity_attributes .channel != undefined && ( not @ channelExists (activity_attributes .channel_id ) )
92
105
@ create_channel_area (new Kandan.Models.Channel (activity_attributes .channel ))
93
106
94
107
if activity_attributes .channel_id
0 commit comments