feat ($ionicActionSheet): pass button object to buttonClicked

Closes #1369.

Right now `buttonClicked` accepts only the index of the pressed button that means you have to work with indices to decide which one it is. In case you move buttons around to get better UX, you'd have to be very careful with those indices. It's easier to add `id` property to buttons and simply check for it. Index-agnostic solution is more maintainable and leads to less changes to the code when the buttons order is being changed.
This commit is contained in:
Pavel Strashkin
2014-05-12 22:34:34 -07:00
committed by Andrew Joslin
parent 0c960b5450
commit e0c7979aa5

View File

@@ -69,8 +69,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
* - `{string=}` `destructiveText` The text for a 'danger' on the action sheet.
* - `{function=}` `cancel` Called if the cancel button is pressed or the backdrop is tapped.
* - `{function=}` `buttonClicked` Called when one of the non-destructive buttons is clicked,
* with the index of the button that was clicked. Return true to close the action sheet,
* or false to keep it opened.
* with the index of the button that was clicked and the button object. Return true to close
* the action sheet, or false to keep it opened.
* - `{function=}` `destructiveButtonClicked` Called when the destructive button is clicked.
* Return true to close the action sheet, or false to keep it opened.
*/
@@ -80,7 +80,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
extend(scope, {
cancel: angular.noop,
buttonClicked: angular.noop,
destructiveButtonClicked: angular.noop
destructiveButtonClicked: angular.noop,
buttons: []
}, opts);
// Compile the template
@@ -121,7 +122,7 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
scope.buttonClicked = function(index) {
// Check if the button click event returned true, which means
// we can close the action sheet
if((opts.buttonClicked && opts.buttonClicked(index)) === true) {
if((opts.buttonClicked && opts.buttonClicked(index, opts.buttons[index])) === true) {
hideSheet(false);
}
};