PDA

View Full Version : Local ArrayStore Updating via set ERROR



@TSM
9 Jan 2013, 5:03 AM
I am having an issue updating the store (uploadImagesStore).
Within the function processNextUpload I have a gridRow.set but this seems to fail and give me the following from Air.
It seems to show the update on screen but then does not progress down the list.


TypeError: Result of expression 'row' [undefined] is not an object. at app:/lib/extjs/ext-all-debug.js : 47271
at app:/lib/extjs/ext-all-debug.js : 47541
at app:/lib/extjs/ext-all-debug.js : 319
at app:/lib/extjs/ext-all-debug.js : 63
at app:/lib/extjs/ext-all-debug.js : 24204
at app:/lib/extjs/ext-all-debug.js : 22944
at app:/lib/extjs/ext-all-debug.js : 22937
at app:/lib/uploader.js : 302
at app:/lib/uploader.js : 231
at app:/lib/uploader.js : 373
at app:/lib/uploader.js : 33
at app:/lib/uploader.js : 126
at app:/lib/extjs/ext-all-debug.js : 31038
h at app:/lib/extjs/ext-all-debug.js : 4624
undefined at undefined : undefined



XAir.uploader = {
active:false,
progressbar:null,
data:[],
dataCounter:-1,
totalUploaded:0,
concurrency:1,
folderName:'',
uploadImagesStore:new Ext.data.JsonStore({
fields : [{name:'id',type:'int'},{name:'filename',type:'string'},{name:'status',type:'string'}],
root : 'images'
}),
init : function(){
XAir.uploader.setUploadData();

if(XAir.uploader.data.length==0){
Ext.MessageBox.alert('Alert', 'Choose Images to Upload');
return;
}else if(XAir.uploader.confirm()==false){

return false;
}
},
start:function(){
XAir.uploader.active = true;
XAir.uploader.createProgressbar();

XAir.uploader.dataCounter = -1;
XAir.uploader.totalUploaded = 0;

XAir.uploader.concurrency = XAir.config.configXmlObj.settings.uploadConcurrency;
for(var i=1;i<=XAir.uploader.concurrency;i++){
uploadHandler(i);
}
},
confirm:function(){

var newAssetsCount = 0;
var updateAssetsCount = 0;
for(var i=0;i<XAir.uploader.data.length;i++){
if(XAir.uploader.data[i].action=='Update'){
updateAssetsCount = updateAssetsCount+1;
}else if(XAir.uploader.data[i].action=='New'){
newAssetsCount = newAssetsCount+1;
}
}

var uploadConfirmWindow = new Ext.Window({
closable: false,
modal: true,
frame: true,
height: 150,
width: 300,
defaultType: 'textfield',
bodyStyle: 'padding: 5px',
labelWidth: 150,
layout: "form",
id:'uploadConfirmForm',
items: [{
xtype: 'compositefield',
fieldLabel: 'New Assets',
items: [{
xtype:'displayfield',
id:'unew_assets_count',
name:'new_assets_count',
value:newAssetsCount
}]
},{
xtype: 'compositefield',
fieldLabel: 'Update Assets',
items: [{
xtype:'displayfield',
id:'update_assets_count',
name:'update_assets_count',
value:updateAssetsCount
}]
},{
xtype: 'compositefield',
fieldLabel: 'Total',
items: [{
xtype:'displayfield',
value:(newAssetsCount+updateAssetsCount)
}]
},{
xtype:'textfield',
fieldLabel:'Folder name',
id:'upload_folder_name',
name:'upload_folder_name'
},
/*,{
xtype:'combo',
width:350,
name:'fds_id',
fieldLabel: 'Incoming Set',
allowBlank : true,
store : new Ext.data.Store({
remoteSort: true,
proxy: new Ext.data.HttpProxy({
url: XAir.application.IPS_HOST + XAir.application.INCOMINGSETS_URL
}),
reader: new Ext.data.JsonReader({
root: 'usersFolders',
totalProperty: 'totalCount',
id: 'fds_id'
}, [
{name: 'fds_id'},
{name: 'fds_subfolder_name'}
])
}),
mode: 'remote',
minChars: 2,
emptyText : 'Select A Incoming Set',
selectOnFocus: true,
forceSelection : true,
displayField:'fds_subfolder_name',
valueField:'fds_id',
hiddenName:'fds_id',
editable: true,
triggerAction: 'all'
}*/],
buttons: [{
text: 'Continue',
handler: function(){
XAir.uploader.folderName = Ext.getCmp('upload_folder_name').getValue();
uploadConfirmWindow.close();
XAir.uploader.start();
}
}, {
text: 'Cancel',
handler: function(){
uploadConfirmWindow.close();
return false;
}
}]
});

uploadConfirmWindow.show();
},
closeProgressbar:function(){
XAir.uploader.progressbar.progressbarWindow.close();
XAir.uploader.progressbar = null;
},
createProgressbar:function()
{
<!-------------Progressbar---------------->
var totalProgress = new Ext.ProgressBar({
text:'Initializing...'
});

var uploadImagesGrid = new Ext.grid.GridPanel({
layout: 'fit',
height: 'auto',
id:'uploadImagesGrid',
store:this.uploadImagesStore,
loadMask: true,
cm: new Ext.grid.ColumnModel({
columns: [
{ header: 'ID', dataIndex: 'id', width:50 },
{ header: 'Filename', dataIndex: 'filename', width:200 },
{ header: 'Status', dataIndex: 'status', width:100 }
]
})
});

var progressbarWindow = new Ext.Window({
closable: false,
modal: true,
title: "Upload Progress",
height: 310,
width: 450,
closeAction: "hide",
items:[
{
title:'Total Progress'
},
totalProgress,
{
html: "<div id='uploadItemProgress' style:'padding:5px;'><p>Initializing...</p></div>",
xtype: "panel",
autoScroll:true,
height:200,
hidden: true
},uploadImagesGrid
],
buttons: [
{
text:'close',
handler:function(){
XAir.uploader.closeProgressbar();
}
}
]
});
<!----------------------------->
XAir.uploader.progressbar = {
progressbarWindow:progressbarWindow,
totalProgress:totalProgress
};
progressbarWindow.show();
},
updateProgressbar:function(){
XAir.uploader.progressbar.totalProgress.updateProgress(XAir.uploader.totalUploaded/XAir.uploader.data.length,'Uploaded '+XAir.uploader.totalUploaded+' of '+ XAir.uploader.data.length);
},
setUploadData:function(){
XAir.uploader.data = getImagesGridSelectedRecords();
//var newData = [],recType = XAir.uploader.uploadImagesStore.recordType;
var new2Data = {"images":[]};
for(var i=0;i<XAir.uploader.data.length;i++){
/*newData.push(new recType({
id : XAir.uploader.data[i].id,
filename : XAir.uploader.data[i].filename,
status : 'Pending'
}));*/
new2Data.images.push({id:XAir.uploader.data[i].id,filename:XAir.uploader.data[i].filename,status:'pending'});
}
XAir.uploader.uploadImagesStore.loadData(new2Data);
}


}




<!-- Upload Handler -->
var uploadHandler = function(i){
var bytesLoaded =0;
var totalBytesLoaded=0;
var bytesTotal=0;
var filename=null;
var file=null;
var currentData = null;

var init = function(){
processNextUpload();
}

var startUpload = function(fileNativepath,paramsString){

filename = fileNativepath.substring(fileNativepath.lastIndexOf(air.File.separator)+1);

//Start uploading progress
Ext.fly('uploadItemProgress').dom.innerHTML += '<p>Started Uploading '+filename+'</p>';
var urlRequest = new air.URLRequest( XAir.application.IPS_HOST + XAir.application.UPLOAD_URL + '?' + paramsString );

var boundary = '--------------======-------------------AaB03x';
urlRequest.useCache = false;
urlRequest.contentType = 'multipart/form-data, boundary='+boundary;
urlRequest.method='POST';


var byteArray = new air.ByteArray();

file = new air.File(fileNativepath);

var fileStream = new air.FileStream();
fileStream.open(file, air.FileMode.READ);
var fileContents = new air.ByteArray();
fileStream.readBytes(fileContents, 0, file.size);
fileStream.close();

byteArray.writeUTFBytes( "--"+boundary+"\r\n" );
byteArray.writeUTFBytes( "Content-Disposition: form-data; name=\"Filedata\"; filename=\""+file.name+"\"\r\n" );
byteArray.writeUTFBytes( "Content-Transfer-Encoding: binary\r\n" );
byteArray.writeUTFBytes( "Content-Length: "+file.size+"\r\n" );
byteArray.writeUTFBytes( "Content-Type: application/octet-stream\r\n" );
byteArray.writeUTFBytes( "\r\n" );

byteArray.writeBytes(fileContents, 0, fileContents.length);

byteArray.writeUTFBytes( "\r\n--"+boundary+"--\r\n" );
urlRequest.data = byteArray;

var urlLoader = new air.URLLoader();
urlLoader.addEventListener(air.ProgressEvent.PROGRESS , uploadProgress);
urlLoader.addEventListener(air.IOErrorEvent.IO_ERROR , uploadError);
urlLoader.addEventListener(air.Event.COMPLETE, uploadComplete);
urlLoader.load(urlRequest);


/*file.addEventListener(air.ProgressEvent.PROGRESS, uploadProgress);
file.addEventListener(air.Event.COMPLETE, uploadComplete);
file.addEventListener(air.SecurityErrorEvent.SECURITY_ERROR, uploadError);
file.addEventListener(air.HTTPStatusEvent.HTTP_STATUS, uploadError);
file.addEventListener(air.IOErrorEvent.IO_ERROR, uploadError);
file.upload(urlRequest, "uploadfile");*/


}


var processNextUpload = function(){
//start Next download
XAir.uploader.dataCounter++;
if(typeof XAir.uploader.data[XAir.uploader.dataCounter] == 'object')
{
currentData = XAir.uploader.data[XAir.uploader.dataCounter];
fileNativepath = currentData.directory + air.File.separator + currentData.filename;
paramsString = 'formAction='+currentData.action;
paramsString += '&userId='+XAir.user.usr_id;
paramsString += '&sessionId='+XAir.user.session_id;
paramsString += '&folder_name='+XAir.uploader.folderName;
air.trace(currentData.id+"-"+XAir.uploader.dataCounter);
//XAir.uploader.uploadImagesStore.removeAt(XAir.uploader.uploadImagesStore.getCount()-1);


var gridRow = XAir.uploader.uploadImagesStore.getAt(XAir.uploader.dataCounter);
gridRow.set('status','Uploading');
//Ext.getCmp('uploadImagesGrid').getView().refresh();
gridRow.commit();
//Ext.getCmp('uploadImagesGrid').getStore().commitChanges();
//air.trace(Ext.getCmp('uploadImagesGrid').store.getById(currentData.id));
startUpload(fileNativepath,paramsString);
}else{
//openNativeProcess();
}
}

var uploadProgress = function(event)
{
bytesLoaded = event.bytesLoaded;
if(bytesTotal != event.bytesTotal)
bytesTotal = event.bytesTotal;

air.trace("Progress", event.bytesLoaded, event.bytesTotal);
}

var uploadComplete = function(event)
{
bytesLoaded = 0;
bytesTotal = 0;
totalBytesLoaded = 0;

air.trace("Data: "+event.target.data);

//Check for response
var xmlObjTree = new XML.ObjTree();
var response = xmlObjTree.parseXML( event.target.data );

if(response.result.status=='true'){
//Update total downloaded items
XAir.uploader.totalUploaded++;

//Update Progressbar
Ext.fly('uploadItemProgress').dom.innerHTML += '<p>Uploaded '+filename+' ('+response.result.message+')</p>';
XAir.uploader.updateProgressbar();

//Mark Ext grid row as Success
var gridRow = Ext.getCmp('imagesGrid').getStore().getAt(currentData.id-1);
gridRow.set('status','<img src="lib/extjs/resources/images/tick.png">');
Ext.getCmp('imagesGrid').getStore().commitChanges();
}else{
//Update Progressbar
Ext.fly('uploadItemProgress').dom.innerHTML += '<p>Error Uploading '+filename+' ('+response.result.message+')</p>';
XAir.uploader.updateProgressbar();

//Mark Ext grid row as Failed
var gridRow = Ext.getCmp('imagesGrid').getStore().getAt(currentData.id-1);
gridRow.set('status','<img src="lib/extjs/resources/images/cross.png">');
Ext.getCmp('imagesGrid').getStore().commitChanges();
}
processNextUpload();
}

var uploadError = function (event)
{
//var errorStr = event.toString();
//air.trace("Error uploading: " + filename + "\n Message: " + errorStr);

//Mark Ext grid row as Failed
var gridRow = Ext.getCmp('imagesGrid').getStore().getAt(currentData.id-1);
gridRow.set('status','<img src="lib/extjs/resources/images/cross.png" >');
Ext.getCmp('imagesGrid').getStore().commitChanges();

Ext.fly('uploadItemProgress').dom.innerHTML += '<p>Error Uploading '+filename+' (connection error)</p>';
processNextUpload();
}

init();
}

mitchellsimoens
11 Jan 2013, 1:07 PM
What component and method is the error being thrown on?