Fix show more button and make it disabled when loading

This commit is contained in:
Piotr Sarnacki 2012-10-02 22:39:11 +02:00
parent 2e16337e68
commit 202f158d55
7 changed files with 75 additions and 15 deletions

View File

@ -1,3 +1,4 @@
require 'travis/expandable_record_array'
require 'travis/model'
@Travis.Repository = Travis.Model.extend
@ -13,14 +14,28 @@ require 'travis/model'
builds: (->
id = @get('id')
Travis.Build.byRepositoryId id, event_type: 'push'
Travis.Build.filter (data) -> parseInt(data.get('repository_id')) == id && !data.get('pull_request')
builds = Travis.Build.byRepositoryId id, event_type: 'push'
array = Travis.ExpandableRecordArray.create
type: Travis.Build
content: Ember.A([])
store: @get('store')
array.load(builds)
array
).property()
pullRequests: (->
id = @get('id')
Travis.Build.byRepositoryId id, event_type: 'pull_request'
Travis.Build.filter (data) -> parseInt(data.get('repository_id')) == id && data.get('pull_request')
builds = Travis.Build.byRepositoryId id, event_type: 'pull_request'
array = Travis.ExpandableRecordArray.create
type: Travis.Build
content: Ember.A([])
store: @get('store')
array.load(builds)
array
).property()
branches: (->

View File

@ -40,9 +40,7 @@
</tbody>
</table>
<p>
<button {{action showMore on="click" target="this" isVisibleBinding="hasMore"}}>
{{t builds.show_more}}
</button>
{{view view.ShowMoreButton}}
</p>
{{else}}
<div class="loading"><span>Loading</span></div>

View File

@ -1,12 +1,28 @@
@Travis.reopen
BuildsView: Travis.View.extend
templateName: 'builds/list'
buildsBinding: 'controller'
buildsBinding: 'controller.builds'
showMore: ->
id = @get('controller.repository.id')
number = @get('controller.builds.lastObject.number')
Travis.Build.olderThanNumber(id, number)
number = @get('builds.lastObject.number')
@get('builds').load Travis.Build.olderThanNumber(id, number)
ShowMoreButton: Em.View.extend
tagName: 'button'
classNameBindings: ['isLoading']
attributeBindings: ['disabled']
isLoadingBinding: 'controller.builds.isLoading'
template: Em.Handlebars.compile('{{view.label}}')
disabledBinding: 'isLoading'
label: (->
if @get('isLoading') then 'Loading' else 'Show more'
).property('isLoading')
click: ->
@get('parentView').showMore()
BuildsItemView: Travis.View.extend
tagName: 'tr'

View File

@ -0,0 +1,29 @@
Travis.ExpandableRecordArray = DS.RecordArray.extend
isLoaded: false
isLoading: false
load: (array) ->
@set 'isLoading', true
self = this
observer = ->
if @get 'isLoaded'
content = self.get 'content'
array.removeObserver 'isLoaded', observer
array.forEach (record) ->
self.pushObject record
self.set 'isLoading', false
self.set 'isLoaded', true
array.addObserver 'isLoaded', observer
pushObject: (record) ->
ids = @get 'content'
id = record.get 'id'
clientId = record.get 'clientId'
return if ids.contains clientId
ids.pushObject clientId

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
9937c24d
73435ff6