@@ -17,42 +17,12 @@ Discourse.ComposerController = Discourse.Controller.extend({
17
17
this . set ( 'similarTopics' , Em . A ( ) ) ;
18
18
} ,
19
19
20
- updateDraftStatus : function ( ) {
21
- this . get ( 'model' ) . updateDraftStatus ( ) ;
22
- } ,
23
-
24
- appendText : function ( text ) {
25
- var c = this . get ( 'model' ) ;
26
- if ( c ) { c . appendText ( text ) ; }
27
- } ,
28
-
29
- categories : function ( ) {
30
- return Discourse . Category . list ( ) ;
31
- } . property ( ) ,
32
-
33
20
actions : {
34
-
35
21
// Toggle the reply view
36
22
toggle : function ( ) {
37
- this . closeAutocomplete ( ) ;
38
- switch ( this . get ( 'model.composeState' ) ) {
39
- case Discourse . Composer . OPEN :
40
- if ( this . blank ( 'model.reply' ) && this . blank ( 'model.title' ) ) {
41
- this . close ( ) ;
42
- } else {
43
- this . shrink ( ) ;
44
- }
45
- break ;
46
- case Discourse . Composer . DRAFT :
47
- this . set ( 'model.composeState' , Discourse . Composer . OPEN ) ;
48
- break ;
49
- case Discourse . Composer . SAVING :
50
- this . close ( ) ;
51
- }
52
- return false ;
23
+ this . toggle ( ) ;
53
24
} ,
54
25
55
-
56
26
togglePreview : function ( ) {
57
27
this . get ( 'model' ) . togglePreview ( ) ;
58
28
} ,
@@ -66,86 +36,122 @@ Discourse.ComposerController = Discourse.Controller.extend({
66
36
this . cancelComposer ( ) ;
67
37
} ,
68
38
69
- save : function ( force ) {
70
- var composer = this . get ( 'model' ) ,
71
- composerController = this ;
39
+ save : function ( ) {
40
+ this . save ( ) ;
41
+ }
42
+ } ,
72
43
73
- if ( composer . get ( 'cantSubmitPost' ) ) {
74
- this . set ( 'view.showTitleTip' , Date . now ( ) ) ;
75
- this . set ( 'view.showCategoryTip' , Date . now ( ) ) ;
76
- this . set ( 'view.showReplyTip' , Date . now ( ) ) ;
77
- return ;
78
- }
44
+ updateDraftStatus : function ( ) {
45
+ this . get ( 'model' ) . updateDraftStatus ( ) ;
46
+ } ,
79
47
80
- composer . set ( 'disableDrafts' , true ) ;
81
-
82
- // for now handle a very narrow use case
83
- // if we are replying to a topic AND not on the topic pop the window up
84
- if ( ! force && composer . get ( 'replyingToTopic' ) ) {
85
- var topic = this . get ( 'topic' ) ;
86
- if ( ! topic || topic . get ( 'id' ) !== composer . get ( 'topic.id' ) )
87
- {
88
- var message = I18n . t ( "composer.posting_not_on_topic" , { title : this . get ( 'model.topic.title' ) } ) ;
89
-
90
- var buttons = [ {
91
- "label" : I18n . t ( "composer.cancel" ) ,
92
- "class" : "cancel" ,
93
- "link" : true
94
- } ] ;
95
-
96
- if ( topic ) {
97
- buttons . push ( {
98
- "label" : I18n . t ( "composer.reply_here" ) + "<br/><div class='topic-title overflow-ellipsis'>" + topic . get ( 'title' ) + "</div>" ,
99
- "class" : "btn btn-reply-here" ,
100
- "callback" : function ( ) {
101
- composer . set ( 'topic' , topic ) ;
102
- composer . set ( 'post' , null ) ;
103
- composerController . save ( true ) ;
104
- }
105
- } ) ;
106
- }
48
+ appendText : function ( text ) {
49
+ var c = this . get ( 'model' ) ;
50
+ if ( c ) { c . appendText ( text ) ; }
51
+ } ,
52
+
53
+ categories : function ( ) {
54
+ return Discourse . Category . list ( ) ;
55
+ } . property ( ) ,
56
+
57
+
58
+ toggle : function ( ) {
59
+ this . closeAutocomplete ( ) ;
60
+ switch ( this . get ( 'model.composeState' ) ) {
61
+ case Discourse . Composer . OPEN :
62
+ if ( this . blank ( 'model.reply' ) && this . blank ( 'model.title' ) ) {
63
+ this . close ( ) ;
64
+ } else {
65
+ this . shrink ( ) ;
66
+ }
67
+ break ;
68
+ case Discourse . Composer . DRAFT :
69
+ this . set ( 'model.composeState' , Discourse . Composer . OPEN ) ;
70
+ break ;
71
+ case Discourse . Composer . SAVING :
72
+ this . close ( ) ;
73
+ }
74
+ return false ;
75
+ } ,
107
76
77
+ save : function ( force ) {
78
+ var composer = this . get ( 'model' ) ,
79
+ composerController = this ;
80
+
81
+ if ( composer . get ( 'cantSubmitPost' ) ) {
82
+ this . set ( 'view.showTitleTip' , Date . now ( ) ) ;
83
+ this . set ( 'view.showCategoryTip' , Date . now ( ) ) ;
84
+ this . set ( 'view.showReplyTip' , Date . now ( ) ) ;
85
+ return ;
86
+ }
87
+
88
+ composer . set ( 'disableDrafts' , true ) ;
89
+
90
+ // for now handle a very narrow use case
91
+ // if we are replying to a topic AND not on the topic pop the window up
92
+ if ( ! force && composer . get ( 'replyingToTopic' ) ) {
93
+ var topic = this . get ( 'topic' ) ;
94
+ if ( ! topic || topic . get ( 'id' ) !== composer . get ( 'topic.id' ) )
95
+ {
96
+ var message = I18n . t ( "composer.posting_not_on_topic" , { title : this . get ( 'model.topic.title' ) } ) ;
97
+
98
+ var buttons = [ {
99
+ "label" : I18n . t ( "composer.cancel" ) ,
100
+ "class" : "cancel" ,
101
+ "link" : true
102
+ } ] ;
103
+
104
+ if ( topic ) {
108
105
buttons . push ( {
109
- "label" : I18n . t ( "composer.reply_original " ) + "<br/><div class='topic-title overflow-ellipsis'>" + this . get ( 'model.topic. title' ) + "</div>" ,
110
- "class" : "btn-primary btn-reply-on-original " ,
106
+ "label" : I18n . t ( "composer.reply_here " ) + "<br/><div class='topic-title overflow-ellipsis'>" + topic . get ( 'title' ) + "</div>" ,
107
+ "class" : "btn btn-reply-here " ,
111
108
"callback" : function ( ) {
112
- composerController . _actions . save . apply ( composerController , [ true ] ) ;
109
+ composer . set ( 'topic' , topic ) ;
110
+ composer . set ( 'post' , null ) ;
111
+ composerController . save ( true ) ;
113
112
}
114
113
} ) ;
115
-
116
- bootbox . dialog ( message , buttons , { "classes" : "reply-where-modal" } ) ;
117
- return ;
118
114
}
115
+
116
+ buttons . push ( {
117
+ "label" : I18n . t ( "composer.reply_original" ) + "<br/><div class='topic-title overflow-ellipsis'>" + this . get ( 'model.topic.title' ) + "</div>" ,
118
+ "class" : "btn-primary btn-reply-on-original" ,
119
+ "callback" : function ( ) {
120
+ composerController . save ( true ) ;
121
+ }
122
+ } ) ;
123
+
124
+ bootbox . dialog ( message , buttons , { "classes" : "reply-where-modal" } ) ;
125
+ return ;
119
126
}
127
+ }
120
128
121
- return composer . save ( {
122
- imageSizes : this . get ( 'view' ) . imageSizes ( )
123
- } ) . then ( function ( opts ) {
129
+ return composer . save ( {
130
+ imageSizes : this . get ( 'view' ) . imageSizes ( )
131
+ } ) . then ( function ( opts ) {
124
132
125
- // If we replied as a new topic successfully, remove the draft.
126
- if ( composerController . get ( 'replyAsNewTopicDraft' ) ) {
127
- composerController . destroyDraft ( ) ;
128
- }
133
+ // If we replied as a new topic successfully, remove the draft.
134
+ if ( composerController . get ( 'replyAsNewTopicDraft' ) ) {
135
+ composerController . destroyDraft ( ) ;
136
+ }
129
137
130
- opts = opts || { } ;
131
- composerController . close ( ) ;
138
+ opts = opts || { } ;
139
+ composerController . close ( ) ;
132
140
133
- var currentUser = Discourse . User . current ( ) ;
134
- if ( composer . get ( 'creatingTopic' ) ) {
135
- currentUser . set ( 'topic_count' , currentUser . get ( 'topic_count' ) + 1 ) ;
136
- } else {
137
- currentUser . set ( 'reply_count' , currentUser . get ( 'reply_count' ) + 1 ) ;
138
- }
139
- Discourse . URL . routeTo ( opts . post . get ( 'url' ) ) ;
141
+ var currentUser = Discourse . User . current ( ) ;
142
+ if ( composer . get ( 'creatingTopic' ) ) {
143
+ currentUser . set ( 'topic_count' , currentUser . get ( 'topic_count' ) + 1 ) ;
144
+ } else {
145
+ currentUser . set ( 'reply_count' , currentUser . get ( 'reply_count' ) + 1 ) ;
146
+ }
147
+ Discourse . URL . routeTo ( opts . post . get ( 'url' ) ) ;
140
148
141
- } , function ( error ) {
142
- composer . set ( 'disableDrafts' , false ) ;
143
- bootbox . alert ( error ) ;
144
- } ) ;
145
- }
149
+ } , function ( error ) {
150
+ composer . set ( 'disableDrafts' , false ) ;
151
+ bootbox . alert ( error ) ;
152
+ } ) ;
146
153
} ,
147
154
148
-
149
155
/**
150
156
Checks to see if a reply has been typed. This is signaled by a keyUp
151
157
event in a view.
0 commit comments