Fix closing broadcast messages

This commit is contained in:
Piotr Sarnacki 2015-09-04 09:03:50 +02:00
parent ea88a6271a
commit 1570935099
10 changed files with 27 additions and 32 deletions

View File

@ -1,10 +1,13 @@
`import Ember from 'ember'`
`import LimitedArray from 'travis/utils/limited-array'`
`import Broadcast from 'travis/models/broadcast'`
Controller = Ember.Controller.extend
needs: ['currentUser']
currentUserBinding: 'controllers.currentUser.model'
FlashDisplayComponent = Ember.Component.extend
auth: Ember.inject.service()
store: Ember.inject.service()
currentUserBinding: 'auth.currentUser'
classNames: ['flash']
tagName: 'ul'
init: ->
@_super.apply this, arguments
@ -28,7 +31,7 @@ Controller = Ember.Controller.extend
broadcasts = Ember.ArrayProxy.create(content: [])
if @get('currentUser.id')
@store.find('broadcast').then (result) ->
@get('store').find('broadcast').then (result) ->
broadcasts.pushObjects(result.toArray())
broadcasts
@ -42,14 +45,14 @@ Controller = Ember.Controller.extend
Ember.run.later(this, (-> @get('flashes.content').removeObject(msg)), 15000)
close: (msg) ->
if msg instanceof Broadcast
if msg.constructor.modelName == "broadcast"
msg.setSeen()
@notifyPropertyChange('unseenBroadcasts')
else
@get('flashes').removeObject(msg)
actions:
close: (msg) ->
closeMessage: (msg) ->
@close(msg)
`export default Controller`
`export default FlashDisplayComponent`

View File

@ -1,6 +1,6 @@
`import BasicView from 'travis/views/basic'`
`import Ember from 'ember'`
View = BasicView.extend
FlashItemComponent = Ember.Component.extend
tagName: 'li'
classNameBindings: ['type']
@ -10,6 +10,6 @@ View = BasicView.extend
actions:
close: ->
@get('controller').close(@get('flash'))
this.attrs.close(@get('flash'))
`export default View`
`export default FlashItemComponent`

View File

@ -0,0 +1,3 @@
{{#each flash in messages}}
{{flash-item flash=flash close=(action 'closeMessage')}}
{{/each}}

View File

@ -0,0 +1,2 @@
<p>{{{flash.message}}}</p>
<a class="close" {{action "close"}}></a>

View File

@ -1,6 +1 @@
{{#each flash in messages}}
{{#view "flash-item" flashBinding="flash"}}
<p>{{{flash.message}}}</p>
<a class="close" {{action "close" target=view}}></a>
{{/view}}
{{/each}}

View File

@ -4,7 +4,7 @@
{{render "top"}}
</header>
{{render "flash"}}
{{flash-display}}
<div class="wrapper-main">
<div id="main" role="main">

View File

@ -2,7 +2,7 @@
{{render "top"}}
</div>
{{render "flash"}}
{{flash-display}}
{{yield}}

View File

@ -6,7 +6,7 @@
</header>
<div class="centered">
{{render "flash"}}
{{flash-display}}
<div id="main" class="main" role="main">
{{yield}}
@ -17,4 +17,4 @@
<footer>
{{render "footer"}}
</footer>
</footer>

View File

@ -6,7 +6,7 @@
</header>
<div class="centered">
{{render "flash"}}
{{flash-display}}
<div id="main" class="main" role="main">
{{yield}}
</div>
@ -15,4 +15,4 @@
<footer>
{{render "footer"}}
</footer>
</footer>

View File

@ -1,8 +0,0 @@
`import BasicView from 'travis/views/basic'`
View = BasicView.extend
classNames: ['flash']
tagName: 'ul'
templateName: 'layouts/flash'
`export default View`