PDA

View Full Version : MVC change component's item's state before init?



wmcnamara
13 Feb 2013, 9:09 AM
I'm currently working on an app, where the need has arisen to be able to hide certain components (being items of the primary component of a view) when certain hash variables are set in the uri.

Currently I would like to handle this before the controllers/views are initialized. (eg handle them in the Application launch method)

Is this to far fetched, or would it be best, to just handle this on a beforeRender event in controller referencing the specific view in question?

I've used the " this.getView('myview'); " method to get the constructor for the view thinking that would be where to start, but being everything is defined in the initComponent (note I'm using Architect), . I'm unsure as to have to modify the item's properties before its been initialized.

scottmartin
13 Feb 2013, 11:31 AM
See if this will help:



Ext.define('MYAPP.view.users.Edit', {
extend : 'Ext.form.Panel',

..

initComponent : function () {

var me = this;

Ext.applyIf(me, {
items : me.buildItems()
});

me.callParent(arguments);
},

buildItems : function () {
var me = this;

return [
{
xtype : 'fieldset',
height : 50,
collapsible : false,
title : 'User Info',
defaults : {
anchor : '100%'
},
items : [
{
name : 'user_name',
xtype : 'textfield',
itemId : 'field_user_name',
fieldLabel : 'User Name',
hidden : (myhash === 'hideme') ? true : false
}
]
}
];
}

});


Scott.

wmcnamara
13 Feb 2013, 11:55 AM
I like the Idea, but there's no way to integrate that into Architect, except for creating an override.
And I'm not entirely sure how overrides work and as far as I can tell, override's make the Design view useless, unless I'm mistaken?

scottmartin
13 Feb 2013, 12:59 PM
You should be able to create the override in in SA.