/source/UserListing.js
enyo.kind({
name: "UserListing",
kind: "Listing",
published: {
user: null
},
items: [],
lastItem: null,
components: [
{name: "title", content: "Listing", tag: "h2"},
{name: "list", kind: "List", classes: "listing-content", onSetupItem: "setupItem", fit: true, components: [
{name: "record", kind: "blerg.Record", ontap: "itemTap"},
{name: "separator", tag: "hr"}
]},
{name: "api", kind: "blerg.API",
onItemsLoaded: "itemsLoaded"}
],
create: function() {
this.inherited(arguments);
this.userChanged();
},
setupItem: function(inSender, inEvent) {
var r = this.items[inEvent.index];
this.$.record.setTimestamp(r.timestamp);
this.$.record.setData(r.data);
this.$.record.setRecord(r.record);
if (inEvent.index == this.items.length - 1) {
this.$.separator.hide();
} else {
this.$.separator.show();
}
},
userChanged: function() {
if (this.user != null) {
this.title = "@" + this.user
this.$.title.setContent(this.title);
this.items = [];
this.lastItem = null;
this.loadItems();
}
},
loadItems: function() {
if (this.lastItem == null) {
this.$.api.loadUserRecords(this.user);
} else {
var to = this.lastItem - 1;
if (to >= 0) {
var from = to > 50 ? to - 50 : 0;
this.$.api.loadUserRecords(this.user, from, to);
}
}
},
itemsLoaded: function(inSender, inEvent) {
this.items = this.items.concat(inEvent.entries);
this.lastItem = inEvent.from;
this.$.list.setCount(this.items.length);
this.$.list.refresh();
},
itemTap: function(inSender, inEvent) {
}
});