PDA

View Full Version : Problem creating my own class (ext.define)



zoggo
7 Sep 2011, 5:37 AM
I created my own class:



Ext.define("AgisViewerLight.Modul.Template",{
MenuClickEvent : null,
ModulWindow: null,
MenuItem: null,


config: {
ModulID : "Template",
MenuPictureSource : "Pictures/om_logo_rot_viewer.png",
MenuPictureText : "TemplateModul",
Viewer : null,
Map : null
},

constructor: function(config) {
this.initConfig(config);

this.callParent();

this.ModulWindow = Ext.create('widget.window', {
height: 495,
width: 400,
layout: {
type: 'fit'
},
closeAction: 'hide',
collapsible: true,
title: 'My Window',
listeners: {
activate: function () {
this.removeCls("ModulWindow");
this.addCls("ModulWinodwActive");
},
deactivate: function () {
this.removeCls("ModulWinodwActive");
this.addCls("ModulWindow");
}
}
});

this.Viewer.ModulCollection.add(this);

return this;
},

show: function () {
this.ModulWindow.show();
return this;
},


enable: function(){
MenuClickEvent = dojo.connect(this.MenuItem, "onclick", this.show);
return this;
}
});


and I instantiate the Class like this



var pModulTest2 = Ext.create('AgisViewerLight.Modul.Template',{
Viewer: AGISViewerLight,
Map: AGISViewerLight.Map
});
pModulTest2.enable();


The enable-method binds the show-method to a clickevent from a html-image. Juts now all works like expectet. The troubles starts in when calling the show-method. from my click-event. The this-object is now the "click-object" (a image tag) a not my own class object. So I can't acces my ModulWindow object. I have to change the scope in some way.

Could anyone help me?

jay@moduscreate.com
7 Sep 2011, 8:29 AM
Why are you using dojo to configure a click event?

Also MenuClickEvent is a global that you're not doing anything with.

you're not following JavaScript naming convention. It's only going to lead to confusion.

zoggo
11 Sep 2011, 11:33 PM
I'm using Dojo for DOM manipulations und registering Events without crossbrowser problems. I can use also pure Jaca Script code.

But you didn't give me any answer for my question. How can I bind my 'show' method to click event from a button outside my object?

mankz
12 Sep 2011, 12:07 AM
var pModulTest2 = Ext.create('AgisViewerLight.Modul.Template',{
Viewer: AGISViewerLight,
Map: AGISViewerLight.Map
});
pModulTest2.enable();

Ext.get('button_foo').on('click', function() {
pModulTest2.show();
});