I have the following code that is written for the Titanium platform for developing mobile applications. The problem I am facing is that the loadPage () method does not call other methods. What am I missing here?
Titanium.UI.currentWindow.barColor = Titanium.UI.currentWindow.barColor;
Titanium.UI.currentWindow.title = 'My Media';
function Media()
{
this.properties = {
currentPage : 1,
url : 'http://localhost/past?return=json&count=20&page=',
rowColor: '#fff',
rowSelectedColor: '#6BBBFA',
filter: 'filter'
};
this.table = false;
this.wrapper = false;
this.products = false;
this.showSearch = function()
{
var search = Titanium.UI.createSearchBar({
barColor: Titanium.UI.currentWindow.barColor,
showCancel: false
});
search.addEventListener('change', function(e)
{
e.value;
});
search.addEventListener('return', function(e)
{
search.blur();
});
search.addEventListener('cancel', function(e)
{
search.blur();
});
return search;
};
this.createRow = function(product)
{
var row = Ti.UI.createTableViewRow();
var image = Ti.UI.createImageView({
image: product.image,
top: 5,
left: 5,
width:100,
height:70,
canScale: true
});
var video = Ti.UI.createLabel({
color: '#000',
font: {
fontSize: 14,
fontWeight: 'bold',
fontFamily: 'Arial'
},
left: 110,
top: 2,
height: 20,
width: 170,
clickName: 'video',
text: product.name
});
var date = Ti.UI.createLabel({
color: '#999',
font: {
fontSize: 13,
fontWeight: 'normal',
fontFamily: 'Arial'
},
left: 110,
top: 22,
height: 20,
width: 100,
clickName: 'date',
text: product.date
});
row.height = 80;
row.className = 'mediaItem';
row.selectedBackgroundColor = this.properties.rowSelectedColor;
row.hasDetail = true;
row.filter = video.text;
row.add(image);
row.add(video);
row.add(date);
this.addRowToTable(row);
};
this.addRows = function()
{
var item;
for(item in this.products)
{
if(item)
{
this.createRow(this.products[item]);
}
}
this.showMoreButton();
};
this.buildTable = function()
{
if(!this.table)
{
this.table = Titanium.UI.createTableView({
search: this.showSearch(),
filterAttribute: this.properties.filter,
backgroundColor: '#ffffff'
});
this.wrapperView = Titanium.UI.createView({
backgroundColor: 'transparent'
});
this.wrapperView.add(this.table);
Titanium.UI.currentWindow.add(this.wrapperView);
}
};
this.addRowToTable = function(row)
{
if(this.table)
{
this.table.appendRow(row);
}
};
this.showMoreButton = function()
{
var row = Ti.UI.createTableViewRow();
row.backgroundColor = '#6BBBFA';
row.selectedBackgroundColor = '#666';
row.isUpdateRow = true;
var rowText = Ti.UI.createLabel({
color: '#fff',
font: {
fontSize:16,
fontWeight:'bold'
},
text: 'Show More Videos',
width: 'auto',
height: 'auto'
});
row.className = 'updated_row';
row.add(rowText);
row.addEventListener('click', function(e){
this.loadPage();
});
this.addRowToTable(row);
};
this.incrementPage = function()
{
this.properties.currentPage = this.properties.currentPage + 1;
};
this.loadPage = function()
{
xhr = Titanium.Network.createHTTPClient();
xhr.open('GET', this.properties.url + this.properties.currentPage);
xhr.onload = function()
{
var response = JSON.parse(xhr.responseText);
this.products = response.products;
this.buildTable();
this.addRows();
this.incrementPage();
};
xhr.onerror = function(e)
{
var a = Titanium.UI.createAlertDialog({
title:'Error',
message: 'There was an error with the request. Please try again later'
});
a.show();
};
xhr.send();
};
};
var media = new Media();
media.loadPage();