@@ -10,6 +10,8 @@ window.Discourse.ComposerView = window.Discourse.View.extend
1010 ' content.showPreview' ,
1111 ' content.hidePreview' ]
1212
13+ educationClosed : null
14+
1315 composeState : (->
1416 state = @ get (' content.composeState' )
1517 unless state
@@ -49,28 +51,58 @@ window.Discourse.ComposerView = window.Discourse.View.extend
4951 if $wmdPreview .length > 0
5052 $wmdPreview .scrollTop ($wmdPreview[0 ].scrollHeight )
5153
52-
5354 ).observes (' content.reply' , ' content.hidePreview' )
5455
55- willDestroyElement : ->
56- $ (' body' ).off ' keydown.composer'
56+ closeEducation : ->
57+ @ set (' educationClosed' , true )
58+ false
59+
60+ fetchNewUserEducation : (->
61+
62+ if (Discourse .get (' currentUser.post_count' ) >= Discourse .SiteSettings .educate_until_posts )
63+ @ set (' educationClosed' , true )
64+ return
65+
66+ return unless @ get (' controller.hasReply' )
67+
68+ @ set (' educationClosed' , false )
69+
70+ # If visible update the text
71+ educationKey = if @ get (' content.creatingTopic' ) then ' new-topic' else ' new-reply'
72+ $ .get (" /education/#{ educationKey} " ).then (result) => @ set (' educationContents' , result)
73+
74+ ).observes (' controller.hasReply' , ' content.creatingTopic' , ' Discourse.currentUser.post_count' )
75+
76+ newUserEducationVisible : (->
77+ return ' collapsed' unless @ get (' educationContents' )
78+ return ' collapsed' unless @ get (' content.composeState' ) is Discourse .Composer .OPEN
79+ return ' collapsed' unless @ present (' content.reply' )
80+ return ' collapsed' if @ get (' educationClosed' )
81+
82+ return ' visible'
83+ ).property (' content.composeState' , ' content.reply' , ' educationClosed' , ' educationContents' )
84+
85+ moveNewUserEducation : (sizePx ) ->
86+ $ (' #new-user-education' ).css (' bottom' , sizePx)
5787
5888 resize : (->
5989 # this still needs to wait on animations, need a clean way to do that
6090 Em .run .next null , =>
6191 replyControl = $ (' #reply-control' )
6292 h = replyControl .height () || 0
63- $ (' .topic-area' ).css (' padding-bottom' , " #{ h} px" )
93+ sizePx = " #{ h} px"
94+ $ (' .topic-area' ).css (' padding-bottom' , sizePx)
95+ $ (' #new-user-education' ).css (' bottom' , sizePx)
6496 ).observes (' content.composeState' )
6597
66- didInsertElement : ->
67-
68- # Delegate ESC to the composer
69- $ (' body' ).on ' keydown.composer' , (e ) =>
70- @ get (' controller' ).hitEsc () if e .which == 27
98+ keyUp : (e ) ->
99+ controller = @ get (' controller' )
100+ controller .checkReplyLength ()
101+ controller .hitEsc () if e .which == 27
71102
103+ didInsertElement : ->
72104 replyControl = $ (' #reply-control' )
73- replyControl .DivResizer (resize : @resize )
105+ replyControl .DivResizer (resize : @resize , onDrag : @moveNewUserEducation )
74106 Discourse .TransitionHelper .after (replyControl, @resize )
75107
76108 click : ->
0 commit comments