emberjs-addons/ember-bootstrap — pull request #28 by ferdy-lw (2012-08-15 03:03:00+00:00)
Title: Allow modal pane to override closing

Let the modal pane callback decide to close the pane or not. This allows the bodyViewClass to be overridden with a more complex template that contains fields which can be validated by the callback.

```javascript
App.MyView = Bootstrap.ModalPane.extend({

controllerBinding: 'App.myController',

bodyViewClass: Em.View.extend({
templateName: 'myTemplate'
})
});

App.myController = Em.Controller.create({

myId: null,
myName: null,

showMyView: function(event) {

this.set('myId', null);
this.set('myName', null);

App.MyView.popup({
heading: "My view",
primary: "Add",
secondary: "Cancel",
showBackdrop: true,
callback: function(opts, event) {

if (opts.primary) {

// Validate
var isValid = true;
var myId = App.get('myController.myId');
if (! myId) {
isValid = false;
} else {
var regExp = /^[a-zA-Z0-9\._\-]{3,36}$/;
if (! regExp.test(myId)) {
isValid = false;
}
}

// Validate the name
var name = App.get('myController.myName');
if (! name) {
isValid = false;
}

if (!isValid) {
return false;
}

return true;

} else if (opts.secondary) {
// secondary button was pressed
} else {
// close was pressed
}
}
});
}
});
```

```html

```