PDA

View Full Version : Repostion Ext.MessageBox.alert() without changing the current code



himanshu24
18 Jul 2013, 4:27 AM
I want to get all Ext.MessageBox.alert() across application and set it to new position.
We have many jsp pages in our application , in which we have used Ext.MessageBox.alert(), now the requirement is to reposition all message boxes , without touching their code in jsp..i can include a js file though

Option 1 :
i found i am able to repostion a message alert by : http://stackoverflow.com/questions/13987031/extjs-ext-messagebox-show-will-not-vertical-align-with-y
but then i have to change all jsp pages and add:



msgBox= Ext.MessageBox.alert(jsonData.responseMessage);
msgBox.getPositionEl().setTop(50);


Option 2 : extend the message box : still change all jsp

Option 3: use css : dont know how?

Can anyone please guide me if there is anyother solution or Css solution will be fine::-/

My code is below


Ext.Ajax.request({
url : 'submitAddZone.htm',
params : {
zoneName : Ext.getCmp('zoneNameId').getValue(),
emailParam : Ext.getCmp('emailId').getValue(),
requestTypeParam : Ext.getCmp('requestTypeId').getValue(),
level : selectedLevel + 1,
parentZoneName : selectedParentZone,
currency : currencyValue,
startDate : Ext.getCmp('startDateId').getValue(),
startTime : Ext.getCmp('startTimeId').getValue()
},
method : 'POST',

success : function(response,request) {
toggleAddZoneElements();

var jsonData = Ext.decode(response.responseText);
if(jsonData.isSuccess){
msgBox= Ext.MessageBox.alert(jsonData.responseMessage);
msgBox.getPositionEl().setTop(50);

addZoneWin.close();
toggleAddZoneButtons();
tree.getStore().load({url: 'loadCustomerStructure.htm'});
}else{
Ext.getCmp('sendRequest').setIcon();
Ext.getCmp('errorMessage1').setText(Encoder.htmlDecode(jsonData.errorMessage));
Ext.getCmp('errorMessage1').show();
}
},
failure : function(
response) {
toggleAddZoneElements();
msgBox= Ext.MessageBox.alert(notCreatedLabel);
addZoneWin.close();
msgBox.getPositionEl().setTop(50);
}

});

skirtle
18 Jul 2013, 7:29 PM
Can't you just override the alert method to call setTop at the end?

Something like this:


Ext.define('MyMsg', {
override: 'Ext.window.MessageBox',

alert: function() {
this.callParent(arguments);

this.getEl().setTop(50);
}
});

Note this is using override, not extend, so it changes the existing MessageBox class rather than creating a subclass.