2015-02-10 19:41:24 +00:00
|
|
|
define(function(require, module, exports) {
|
|
|
|
main.consumes = ["Dialog", "util"];
|
|
|
|
main.provides = ["dialog.question"];
|
|
|
|
return main;
|
|
|
|
|
|
|
|
function main(options, imports, register) {
|
|
|
|
var Dialog = imports.Dialog;
|
|
|
|
var util = imports.util;
|
|
|
|
|
|
|
|
/***** Initialization *****/
|
|
|
|
|
|
|
|
var plugin = new Dialog("Ajax.org", main.consumes, {
|
|
|
|
name: "dialog.question",
|
|
|
|
allowClose: false,
|
|
|
|
modal: true,
|
|
|
|
elements: [
|
|
|
|
{ type: "checkbox", id: "dontask", caption: "Don't ask again", visible: false },
|
|
|
|
{ type: "button", id: "yestoall", caption: "Yes to All", color: "green", visible: false },
|
|
|
|
{ type: "button", id: "notoall", caption: "No to All", color: "red", "default": true, visible: false },
|
|
|
|
{ type: "filler" },
|
|
|
|
{ type: "button", id: "yes", caption: "Yes", color: "green", "default": true, hotkey: "Y" },
|
|
|
|
{ type: "button", id: "no", caption: "No", color: "red", hotkey: "N" },
|
|
|
|
{ type: "button", id: "cancel", caption: "Cancel", visible: false, hotkey: "ESC" }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
/***** Methods *****/
|
|
|
|
|
|
|
|
function show(title, header, msg, onYes, onNo, options) {
|
|
|
|
if (!options)
|
|
|
|
options = {};
|
|
|
|
|
|
|
|
return plugin.queue(function(){
|
|
|
|
var all = options.all;
|
|
|
|
var cancel = options.cancel;
|
|
|
|
var showDontAsk = options.showDontAsk;
|
|
|
|
var metadata = options.metadata;
|
|
|
|
|
|
|
|
plugin.title = title;
|
|
|
|
plugin.heading = util.escapeXml(header);
|
|
|
|
plugin.body = util.escapeXml(msg).replace(/\n/g, "<br />");
|
|
|
|
|
|
|
|
plugin.allowClose = cancel;
|
|
|
|
|
2015-05-05 13:49:45 +00:00
|
|
|
var gotYesNo = false;
|
2015-02-10 19:41:24 +00:00
|
|
|
plugin.once("hide", function(){
|
2015-05-05 13:49:45 +00:00
|
|
|
!gotYesNo && cancel && onNo(false, true, metadata);
|
2015-02-10 19:41:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
plugin.update([
|
|
|
|
{ id: "cancel", visible: cancel, onclick: function(){ plugin.hide(); } },
|
|
|
|
{ id: "dontask", visible: showDontAsk },
|
|
|
|
{ id: "yestoall", visible: all, onclick: function(){
|
2015-05-05 13:49:45 +00:00
|
|
|
gotYesNo = true;
|
2015-02-10 19:41:24 +00:00
|
|
|
plugin.hide();
|
|
|
|
onYes(true, metadata);
|
|
|
|
}},
|
|
|
|
{ id: "notoall", visible: all, onclick: function(){
|
2015-05-05 13:49:45 +00:00
|
|
|
gotYesNo = true;
|
2015-02-10 19:41:24 +00:00
|
|
|
plugin.hide();
|
|
|
|
onNo(true, false, metadata);
|
|
|
|
}},
|
|
|
|
{ id: "yes", onclick: function(){
|
2015-05-05 13:49:45 +00:00
|
|
|
gotYesNo = true;
|
2015-02-10 19:41:24 +00:00
|
|
|
plugin.hide();
|
|
|
|
onYes(false, metadata);
|
|
|
|
}},
|
|
|
|
{ id: "no", onclick: function(){
|
2015-05-05 13:49:45 +00:00
|
|
|
gotYesNo = true;
|
2015-02-10 19:41:24 +00:00
|
|
|
plugin.hide();
|
|
|
|
onNo(false, false, metadata);
|
|
|
|
}}
|
|
|
|
]);
|
|
|
|
}, options.queue === false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Register *****/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
plugin.freezePublicAPI({
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
get all(){ return undefined },
|
|
|
|
set all(value) {
|
|
|
|
plugin.update([
|
|
|
|
{ id: "yestoall", visible: value},
|
|
|
|
{ id: "notoall", visible: value}
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
get cancel(){ return undefined },
|
|
|
|
set cancel(value) {
|
|
|
|
plugin.allowClose = value;
|
|
|
|
plugin.update([
|
|
|
|
{ id: "cancel", visible: value }
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
get showDontAsk(){
|
|
|
|
return plugin.getElement("dontask").visible;
|
|
|
|
},
|
|
|
|
set showDontAsk(value) {
|
|
|
|
plugin.update([
|
|
|
|
{ id: "dontask", visible: value }
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
get dontAsk(){
|
|
|
|
return plugin.getElement("dontask").value;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
show: show
|
|
|
|
});
|
|
|
|
|
|
|
|
register("", {
|
|
|
|
"dialog.question": plugin
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|