I have the following:
app.showMessage('template', book.title(), [save, cancel]).then(function(result) {
if (result == save) {
alert('saved');
} else if (result == cancel) {
alert('canceled');
}
});
This is working great, but I'd like to replace 'template'
with the path of a view that will get bound to the current viewmodel (a form for add/edit object). Is there any mechanism in place to achieve this?
I've done this:
dialog.MessageBox.setViewUrl('/App/views/templates/editBook.html');
Which works, but all of the chrome and dialog goodness is lost - it replaces the entire dialog template, not just the inner template.
EDIT:
I now have a dedicated view/viewmodel pair and I'm using this:
vm.editBook = function (book) {
dialog.show('viewmodels/editBook', book);
};
With my editBook.js:
define(function () {
var vm = {};
vm.book= ko.observable();
vm.cancel = function () {
alert('should cancel');
};
vm.save = function() {
};
vm.activate = function(book) {
vm.book(book);
};
return vm;
});
my view:
<div data-view="plugins/messageBox" class="messageBox" data-bind="with: book">,
<div class="modal-header">
<h3 data-bind="text: title"></h3>
</div>
<div class="modal-body">
<p class="message" data-bind="text: title"></p>
</div>
<div class="modal-footer">
<button data-bind="click: $parent.cancel">cancel</button>
<div style="clear:both;"></div>
</div>
</div>
But then how do I close the dialog from the view? I tried passing the dialog object to the vm to call dialog.close
but this doesn't seem to work.
Update again: By requiring the dialog
plugin and calling dialog.close(vm), durandal knows how to select and close the right dialog:
vm.cancel = function () {
//alert('should cancel');
dialog.close(vm);
};
So I think I'm all set... but any confirmation would be cool from the pros out there.