[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) { MCT.prototype.dialog = function (view, title) {
return new Dialog(view).show(); return new Dialog(view, title).show();
}; };
MCT.prototype.start = function () { MCT.prototype.start = function () {

View File

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

View File

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