I have a dataview which loads a directory listing from a php file. It's a relatively simple setup, but for some reason during the Store loading, the files themselves are loaded/cached.
store: new Ext.data.Store({
fields: ['url', 'thumbUrl', 'title', 'filetype'],
sortInfo: {field: 'title', direction: "ASC"},
proxy: new Ext.data.HttpProxy({url: 'getUploads.php?dir=' + dir}),
reader: new Ext.data.JsonReader({root: 'uploads'}, ['url', 'thumbUrl', 'title']),
autoLoad: true,
listeners: {
'beforeload': function(ds, records, opts) {
var t=0;
},
'load': function(ds, records, opts) {
for(var i=0; i
var title = records[i].get('title');
var f = title.substr( title.lastIndexOf('.')+1 );
records[i].set('filetype', f);
var fileTypes = {
'html': 'html',
...........
'xslx': 'spreadsheet'
};
if(fileTypes[f] !== 'image') { IPM FAQs and Troubleshooting Tips:: directory listing or initiates the sending or receiving of a file, its connection to the configuration server, real time poller, data view server, or http://www.cisco.com/univercd/cc/td/doc/product/rtrmgmt/ipmcw2k/cipm26/uguide/ipmfaq.pdfHOME |
records[i].set('thumbUrl', './images/thumbs/' + (fileTypes[f] 'unknown') + '.png');
}
records[i].set('title', shorten(title, 20));
}
}
}
})
The response is relatively simple:
{'uploads': [
{'url':'./uploads/Guthrie1.aif', 'thumbUrl':'./uploads/Guthrie1.aif', 'title':'Guthrie1.aif'},
{'url':'./uploads/Portal Song.mp3', 'thumbUrl':'./uploads/Portal Song.mp3', 'title':'Portal Song.mp3'},
{'url':'./uploads/olive.jpg', 'thumbUrl':'./uploads/olive.jpg', 'title':'olive.jpg'},
{'url':'./uploads/purple.jpg', 'thumbUrl':'./uploads/purple.jpg', 'title':'purple.jpg'}
]}
All I'm loading is the url strings and titles, yet for some reason when the data store is loaded, the files are cached (appear in the NET tab of FireBug).
So the Portal Song.mp3 (all 5mb) is cached.
Any reason why?
I've never found a good way to put logic into a template. Would you mind giving an example of some basic logic, or better yet, a function call?
Ok It wasn't the store that caused it.
I'm displaying a DataView with file icons. On the store's 'load' event, I'm determining which icon to use for which file, but when it first comes in it was set to use the file itself for the thumbnail (like for images).
Had to do the work in PHP instead of JS, as I can't determine a way to affect the records after they are in JS, but before they are added to the store.
It's solved though.
Yup! Either do that or you could put in some custom logic in your Template.
Yeah, that's what I assumed. There isn't a way to get a listener between when the request is returned and when the records are added, is there?
I have it working, I'd just rather write it in JS than PHP.
Here's my question, in sequential form
1) Create data store for DataView with autoLoad
2) 'beforeload' fires (nothing actually done, but the request is fired off)
3) PHP gets the directory listing and returns this
{'uploads': [
{'url':'./uploads/Guthrie1.aif', 'thumbUrl':'./uploads/Guthrie1.aif', 'title':'Guthrie1.aif'},
{'url':'./uploads/Portal Song.mp3', 'thumbUrl':'./uploads/Portal Song.mp3', 'title':'Portal Song.mp3'},
{'url':'./uploads/olive.jpg', 'thumbUrl':'./uploads/olive.jpg', 'title':'olive.jpg'},
{'url':'./uploads/purple.jpg', 'thumbUrl':'./uploads/purple.jpg', 'title':'purple.jpg'}
]}
4) Store loads records from request
5) 'load' event is fired. JS changes thumbUrl to appropriate thumbnail image based on filetype
Somewhere between 4 and 5 it's already rendered the DataView, so it attempts to read the thumbUrl as the img src.
Oh! I got it. I can simply return blank for the thumbUrl since I already get the info I need in the url and title.
Nevermind. No questions anymore. Thanks.
Hrm, I'm unsure of what the question is. I would suggest using an icon for the mp3 for the thumbUrl.
This problem is caused by using the thumbUrl. Http will pull down any file regardless of type that is included in a src attribute of an img tag.
I Am a Sinner – What About You?
Global Sourcing and Supplier Online by Dylan
|