PDA

View Full Version : Are you sure you want to untoggle that SegmentedButton?



intellix
12 May 2012, 9:29 AM
Ok so the project I'm working on required a confirmation dialog to ask the user if they were sure they wanted to untoggle a SegmentedButton. This is the first time for me using ExtJS, ST2 so you may not appreciate what I've created... but here it is:

Inside Ext.application you need to specify that you want to use an over-ride which exists as app/view/override/SegmentedButton.js


Ext.application({
requires: [
'App.view.override.SegmentedButton'
],

// rest of it


Override (to allow beforetoggle event):


Ext.define('App.view.override.SegmentedButton', {
override: 'Ext.SegmentedButton',


initialize: function () {
var me = this;


me.on({
delegate: '> button',
scope: me,
tap: 'onButtonPress'
});


me.callParent();
},


onButtonPress: function (button) {


var me = this,
pressedButtons = me.getPressedButtons() || [],
buttons = [],
alreadyPressed;


wasPressed = (buttons.indexOf(button) !== -1) || (pressedButtons.indexOf(button) !== -1);


me.fireEvent('beforetoggle', me, button, wasPressed);


}

});


beforetoggle event within my controller which is called on 'beforetoggle':


onSegmentedbuttonBeforeToggle: function(segmentedbutton, button, wasPressed, options) {
// Remove ability to depress it so it doesnt change until confirmed
segmentedbutton.setAllowDepress(false);


// Check if button is already down
if (wasPressed) {


// Is user sure he wants to remove that selection?
Ext.Msg.confirm("Confirmation", "Are you sure you want to remove that selection?", function (reply) {


if (reply === 'yes') {
segmentedbutton.setAllowDepress(true);
segmentedbutton.onButtonRelease(button);
}


});


}
},

mitchellsimoens
14 May 2012, 6:25 AM
I would think this would be better suited for a plugin or an extension of segmentedbutton. If you use an override, you override all segmentedbuttons which you may not want.