PDA

View Full Version : Uncaught TypeError: undefined is not a function



sinaalizadeh
28 Aug 2014, 1:24 PM
In my extjs controller I call a method from application to check if the user is admin or not, but I get 'Uncaught TypeError: undefined is not a function' error. I used Sencha cmd to create project structure and also I changed the ext/ext-dev.js to ext/ext-all-dev.js as some suggested, but it didn't help.

My part of controller is

{
xtype: 'button',
itemId: 'taskAdminBtn',
iconCls: 'admin',
hidden: !MyApp.getApplication().isAdmin(),
text: 'Admin'
},


and here is my function definition


var me = this;
me.isAdmin = function() {
return userObj.adminRole === 'Y';
};

skirtle
28 Aug 2014, 4:23 PM
Without context it's difficult to tell.

Is it the call to getApplication or isAdmin that's failing?

Is this definitely the application when you're defining isAdmin?

Is the code where you define isAdmin definitely running before you try to use isAdmin?

sinaalizadeh
28 Aug 2014, 11:13 PM
the problem is that isAdmin function is not loaded because it is defined in another function which will be called after login process. and login page is not created. I don't know what's the problem.
here is my application.js file



Ext.define('App.Application', {
name: 'App',
extend: 'Ext.app.Application',
requires: ['App.view.Viewport', 'App.view.LogonWindow'],
models: ['User'],
controllers: ['MainController', 'UserController'],
stores: ['User'],

init : function(application){
App.URL_PREFIX = 'sth/';
Ext.Ajax.on('beforerequest', function(conn, options, eOpts){
options.url = App.URL_PREFIX + options.url;
});
},

launch: function() {

var me = this;
App.console = function(output) {
if (typeof console !== 'undefined') {
console.info(output);
}
};
me.logonWindow = Ext.create('App.view.LogonWindow');
me.logonWindow.show();
},
doAfterLogon: function(userObj) {
App.console(userObj);
var me = this;
me.getUser = function() {
return userObj;
};
me.isAdmin = function() {
return userObj.adminRole === 'Y';
};
Ext.create('App.view.Viewport');
me.logonWindow.hide();
}
});

sinaalizadeh
29 Aug 2014, 1:18 AM
the problem was "autoCreateViewport : true" , I have already defined it so I had to remove this in my application.js file