[API] Title dialog

This commit is contained in:
Victor Woeltjen 2016-06-17 14:05:00 -07:00
parent 13920d8802
commit dbe6a4efc1
3 changed files with 20 additions and 13 deletions

View File

@ -85,8 +85,8 @@ define([
});
};
MCT.prototype.dialog = function (view) {
return new Dialog(view).show();
MCT.prototype.dialog = function (view, title) {
return new Dialog(view, title).show();
};
MCT.prototype.start = function () {

View File

@ -1,25 +1,30 @@
define(['text!./dialog.html', 'zepto'], function (overlayTemplate, $) {
function Dialog(view) {
define(['text!./dialog.html', 'zepto'], function (dialogTemplate, $) {
function Dialog(view, title) {
this.view = view;
this.title = title;
}
Dialog.prototype.show = function () {
var $body = $('body');
var $overlay = $(overlayTemplate);
var $contents = $overlay.find('.contents .editor');
var $close = $overlay.find('.close');
var $dialog = $(dialogTemplate);
var $contents = $dialog.find('.contents .editor');
var $close = $dialog.find('.close');
var $ok = $overlay.find('.ok');
var $cancel = $overlay.find('.cancel');
var $ok = $dialog.find('.ok');
var $cancel = $dialog.find('.cancel');
var view = this.view;
function dismiss() {
$overlay.remove();
$dialog.remove();
view.destroy();
}
$body.append($overlay);
if (this.title) {
$dialog.find('.title').text(this.title);
}
$body.append($dialog);
this.view.show($contents[0]);
return new Promise(function (resolve, reject) {

View File

@ -115,14 +115,16 @@ define([
$(container).append($els);
$add.on('click', function () {
mct.dialog({
var view = {
show: function (container) {
$(container).append($('<span>Dialog!</span>'));
},
destroy: function () {
}
}).then(
};
mct.dialog(view, "Add a Task").then(
window.alert.bind(window, 'resolve'),
window.alert.bind(window, 'reject')
);