PDA

View Full Version : Ext.List Object Inside of Ext.Panel Won't Render Unless Orientation Changes



OpnSrce
6 Feb 2011, 7:54 PM
Ext.namespace('Envato.AudioJungle.Previewer');
var lastItemClicked = null; // Stores the last 'play' or 'pause' item clicked on
Envato.AudioJungle.Previewer.audioPreview = new Ext.Audio({}); // Blank audio player used to preview the items
Envato.AudioJungle.Previewer.popularItemList = new Ext.List({ // The list of popular items
store: 'popularItemStore',
emptyText: 'No popular items found',
loadingText: 'Loading Items',
itemTpl: new Ext.XTemplate( // How we format the items when they come back
'<div class = "audio_jungle_item">',
'<img src = "{thumbnail}" class = \"thumbnail\">',
'<span class = "item_title">{[fm.ellipsis(values.item, 20, false)]}</span>',
'<span class = "item_author"> by {user} ({sales} sales)</span>',
'<div class = "x-button play_pause_button">Play</div>',
'</div>'
),
listeners: {
itemtap: function(self, index, item, e) {
var selectedItem = self.getRecord(item);
var tapTarget = e.getTarget(); // Stores what we clicked on
if(tapTarget.innerHTML == 'Play') { // We clicked on a 'Play button'
if(lastItemClicked && lastItemClicked.innerHTML == 'Pause') { // Another item is currently playing
lastItemClicked.innerHTML = 'Play'; // Switch the button to 'Play'
}
lastItemClicked = tapTarget; // Store the currently clicked item as the last clicked item
lastItemClicked.innerHTML = 'Pause'; // Set the button we clicked on to 'Pause'
if(Envato.AudioJungle.Previewer.audioPreview.url) { // Check to see that the audio previewer is not empty
Envato.AudioJungle.Previewer.audioPreview.pause(); // Pause it
}
// Reset the audio previewer to play the item clicked
Envato.AudioJungle.Previewer.audioPreview = new Ext.Audio({
id: 'audioPreview',
hidden: true,
url: selectedItem.get('preview_url'),
renderTo: Ext.getBody()
});
// Play the audio
Envato.AudioJungle.Previewer.audioPreview.play();
} else if (tapTarget.innerHTML == 'Pause') { // We clicked a pause button
Envato.AudioJungle.Previewer.audioPreview.pause(); // Pause playback
tapTarget.innerHTML = 'Play'; // Set the button to say 'Play'
} else {
Ext.Msg.confirm("Audio Jungle", "View this item at AudioJungle.com?", function(btn) {
if(btn == 'yes') {
location.href = selectedItem.get('url');
}
});
}
}
}
});
Envato.AudioJungle.Previewer.optionToolbar = {
dock: 'top',
xtype: 'toolbar',
title: 'AudioJungle - Popular Items'
};
Envato.AudioJungle.Previewer.displayPanel = new Ext.Panel({
layout: 'fit',
fullscreen: true,
dockedItems: Envato.AudioJungle.Previewer.optionToolbar,
items: Envato.AudioJungle.Previewer.popularItemList
});


Ext.namespace('Envato', 'Envato.AudioJungle', 'Envato.AudioJungle.Previewer', 'Envato.Stores');
Ext.setup({
onReady: function() {
Envato.AudioJungle.Previewer.displayPanel.render(Ext.getBody()).doComponentLayout();
}
})



var popularItemFields = [{
name: 'preview_url',
type: 'string'
},{
name: 'sales',
type: 'integer'
},{
name: 'user',
type: 'string'
},{
name: 'cost',
type: 'float'
},{
name: 'url',
type: 'string'
},{
name: 'uploaded_on',
type: 'date',
dateFormat: 'r'
},{
name: 'rating',
type: 'integer'
},{
name: 'tags',
type: 'string'
},{
name: 'thumbnail',
type: 'string'
},{
name: 'id',
type: 'integer'
},{
name: 'item',
type: 'string'
},{
name: 'preview_type',
type: 'string'
},{
name: 'length',
type: 'string'
}];
Ext.regModel('PopularItem', {
fields: popularItemFields
});
Envato.Stores.popularItemsStore = new Ext.data.JsonStore({
sorters: 'item',
model: 'PopularItem',
storeId: 'popularItemStore',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'php/scripts/envato.php',
extraParams: {
site: 'audiojungle'
},
reader: {
type: 'json',
root: 'root',
idProperty: 'id'
}
},
getGroupString: function(record) {
return record.get('item')[0];
}
});



The toolbar at the top of the screen renders fine, but the list of items doesn't load until I change the orientation of my device (ipad and iphone). What am I doing wrong?