PDA

View Full Version : Method Error



maecy
24 Nov 2013, 8:24 AM
I really don't know if I got the title right but I don't know what's really the problem. Okay, I am trying to restrict inserting 0 for the staytime. I have this code:



staytimeValidation: function(){
var scope = this;
var time = scope.getTime().getValue();

if (time > 0){
var scope = dlti.controller.DLTIController.getInstance();
scope.createPlaylist();
scope.LoadPlaylistDetails();
scope.getPlaylistDetailsGrid().show();
}
else{
Ext.Msg.alert('Error', '0 is not a valid time. Please enter a higher number');
}
},

Is it okay if I put the other methods inside a method? I always get this error:

Uncaught TypeError: Cannot read property 'data' of undefined

The bold part of the code below is the source of the error when I traced it.



createPlaylist:function(record){
var scope = this;
var vo = record;
var sel = scope.getShowImages().getSelectionModel().getSelection();
var user = scope.getProfinfo().getForm().getValues();
var filename = sel[0].data.filename;
var imageid = sel[0].data.image_id;
var transition = scope.getTransitions().getValue();
var time = scope.getTime().getValue();
var date = new Date();
var playlistid = scope.getRndInt().getValue();
var sel2 = scope.getTerminalGrid().getSelectionModel().getSelection();
var terminals = sel2[0].data;



Ext.Service.invoke(
'PlaylistManager',
'saveplaylistdetails',
[user.id,filename,imageid,transition,time,date,playlistid],
function(p){
console.log('eto ang p',p)
if(p.success){
Ext.Msg.alert('dlti', p.result[0].message);
scope.getPlaylistDetailsGrid().show();
scope.getTransitions().reset();
scope.getTime().reset();


scope.getAllowedtime().setValue(terminals.num_of_spots*30);
var staytime = scope.getAllowedtime().getValue();
scope.getTime().setMaxValue(staytime);

Ext.Service.invoke(
'PlaylistManager',
'getstaytime',
[user.id,imageid,playlistid],
function(p1){
scope.getAccumulatedtime().setValue(p1.result);
var totalacc = scope.getAccumulatedtime().getValue();
var totalavl = staytime - totalacc;
scope.getTime().setMaxValue(totalavl);
scope.getTotalAvailabletime().setValue(totalavl);

}
);


}else{
Ext.Msg.alert('Error', 'Please check your inputs.');
scope.getPlaylistDetailsGrid.show();



}
});

},

Farish
24 Nov 2013, 1:45 PM
you should use a condition to check if any records are selected or not. may be this is the reason why you are getting an error. when no records are selected, getSelection() will return null or empty array. make sure that the result of getSelection() has length > 0.

maecy
24 Nov 2013, 6:07 PM
I already have that. And even though there are records selected, it gives me the same error.

Farish
24 Nov 2013, 11:53 PM
set a breakpoint and debug using Firebug plugin for Firefox. you can also put console.log(sel2); and see what it prints.