I want to create custom modal. Basically, I have a table which has rows in it. When the user clicks on a row, I want a pop-up window to appear. I am following the description of how to create a custom modal in this link: http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals/
Based on the description, I figured I need two classes to create a custom modal. One is the view and another one is modal.
I actually the two classes with the exact same code in the link.
My question is, how do I display the custom modal when a row is clicked?
Let's say this is my table in my view called index.html
<table class="table table-bordered table-hover">
<thead>
<tr>
<th></th>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
And suppose I have a view called messageBox.html
Here's the code for it:
<div class="messageBox">
<div class="modal-header">
<h3 data-bind="html: title"></h3>
</div>
<div class="modal-body">
<p class="message" data-bind="html: message"></p>
</div>
<div class="modal-footer" data-bind="foreach: options">
<button class="btn" data-bind="click: function () { $parent.selectOption($data); }, html: $data, css: { 'btn-primary': $index() == 0, autofocus: $index() == 0 }"></button>
</div>
</div>
And a modal called messageBox.js
. Here's the code for it:
define(function() {
var MessageBox = function(message, title, options) {
this.message = message;
this.title = title || MessageBox.defaultTitle;
this.options = options || MessageBox.defaultOptions;
};
MessageBox.prototype.selectOption = function (dialogResult) {
this.modal.close(dialogResult);
};
MessageBox.defaultTitle = '';
MessageBox.defaultOptions = ['Ok'];
return MessageBox;
});
How do I tie the table click event with this custom modal that I created?