Ok here is the full code (obviously I have removed any specific urls, but this is the full code as is)
Basically I am just wondering how do proper paging in the sidebar, given that my json feed returns more then 20 items
CODE
/**
* @author pkelly
*/
var SampleSidebarView = new KONtx.Class({
ClassName: 'SampleSidebarView',
Extends: KONtx.system.SidebarView,
config: {
rows: 3,
columns: 3
},
initialize: function() {
this.parent();
},
fetchData: function() {
var u = new URL();
var count = 20;
var pageNum = 1;
u.location = 'http://www.trylifecache.com/pva/data/users/ec51b165c3e0498288137937f6c4bd66/feed/all?page='+ pageNum +'&count='+ count +'&fmt=simplejson';
u.fetchAsync(this.handleFetchResponse.bindTo(this));
},
handleFetchResponse: function(u) {
if(u.response != 200) {
// request failed
return;
}
// do whatever you need to do to format the data and store in "result"
else {
var self = this;
var imageArr = [];
var my_data_struct = JSON.parse(u.result);
var totalCount = my_data_struct.feed.totalResults;
//if (totalCount > count){
//}
var images = my_data_struct.feed.entry;
for (var i in images){
var attr = [];
var item = images[i];
attr.push(item.links[2].mediaGroup[0].thumbnail[0].url);
attr.push(item.title);
attr.push(item.published);
attr.push(item.links[2].mediaGroup[0].content[0].height);
attr.push(item.links[2].mediaGroup[0].content[0].width);
imageArr.push(attr);
}
}
//this.cache.imgData = images(imageArr).slice(0,50).map(function(src,i){return{src:src,label:'Image #'+(i+1)}});
this.cache.imgData = imageArr.slice(0).map(function(src,i){return{src:src[0],title:src[1],create:src[2],height:src[3],width:src[4],label:src[1]}});
log(this.cache.imgData);
this.controls.grid.changeDataset(this.cache.imgData);
},
createView: function (){
var __baseID = (this.id||this.ClassName||this._ktxID+'.ImageGrid');
this.controls = {};
this.controls.headerText = new KONtx.element.Text({
label: "My Recent Photos",
wrap: true,
truncation: 'end',
styles: {
fontSize: '20px',
color: '#FFFFFF',
textAlign: 'left',
width: this.width,
height: 36,
hOffset: 5
}
}).appendTo(this);
//
// if this seems goofy, it's because we need to create the page
// indicator and metadata container first so we can measure their
// height and fit the grid in last.
//
this.controls.pageindicator = new KONtx.control.PageIndicator({
id: __baseID+'.PageIndicator',
styles: {
vAlign: 'bottom',
vOffset: this.height
}
}).appendTo(this);
this.controls.metadata = new KONtx.control.MetadataDisplay({
id: __baseID+'.Metadata',
styles: {
height: 23,
vAlign: 'bottom',
vOffset: this.height - this.controls.pageindicator.height
}
}).appendTo(this);
this.controls.grid = new KONtx.control.Grid({
id: __baseID+'.Grid',
rows: this.config.rows,
columns: this.config.columns,
styles: {
width: this.width,
height: this.height -
this.controls.headerText.height -
this.controls.pageindicator.height -
this.controls.metadata.height,
vOffset: this.controls.headerText.height
},
cellCreator: this.imageCellCreator,
cellUpdater: this.imageCellUpdater
}).appendTo(this);
//
// and now that everyone's created, let's introduce them to each other.
//
this.controls.grid.attachAccessories( this.controls.pageindicator, this.controls.metadata );
},
updateView: function (){
this.fetchData();
//this.controls.grid.changeDataset(this.cache.imgData);
},
//
// cell create/update methods get fired in context of grid
//
imageCellCreator: function () {
return new KONtx.control.PhotoGridCell({
styles: this.getCellDimensions(),
events: {
// this onSelect fires in context of cell
onSelect: function (event){
var dataItemNumber = this.getCellDataIndex() + 1;
var dataItemData = this.getCellDataItem();
log ("height: " + dataItemData.height);
log ("width: " + dataItemData.width);
var imageRef = dataItemData.src;
imageRef = imageRef.replace(/thumbnail/, "photos");
imageRef = imageRef.replace(/\?th=77\&tw=77\&s=true/g, "");
KONtx.application.loadView('view-Image',
{
imageURL: imageRef,
imageTitle: dataItemData.title,
createDate: dataItemData.create,
height: dataItemData.height,
width: dataItemData.width
},false);
}
}
});
},
imageCellUpdater: function (cell, dataitem) {
cell.setSources(dataitem);
}
});