2020-11-15 11:40:08 +00:00
|
|
|
/*\
|
|
|
|
|
|
|
|
title: $:/core/modules/widgets/action-confirm.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: widget
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
|
|
|
|
|
|
|
var ConfirmWidget = function(parseTreeNode,options) {
|
|
|
|
this.initialise(parseTreeNode,options);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Inherit from the base widget class
|
|
|
|
*/
|
|
|
|
ConfirmWidget.prototype = new Widget();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Render this widget into the DOM
|
|
|
|
*/
|
|
|
|
ConfirmWidget.prototype.render = function(parent,nextSibling) {
|
|
|
|
this.computeAttributes();
|
|
|
|
this.execute();
|
|
|
|
this.parentDomNode = parent;
|
|
|
|
this.renderChildren(parent,nextSibling);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Compute the internal state of the widget
|
|
|
|
*/
|
|
|
|
ConfirmWidget.prototype.execute = function() {
|
2020-11-16 17:02:22 +00:00
|
|
|
this.message = this.getAttribute("$message",$tw.language.getString("ConfirmAction"));
|
|
|
|
this.prompt = (this.getAttribute("$prompt","yes") == "no" ? false : true);
|
2020-11-15 11:40:08 +00:00
|
|
|
this.makeChildWidgets();
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Refresh the widget by ensuring our attributes are up to date
|
|
|
|
*/
|
|
|
|
ConfirmWidget.prototype.refresh = function(changedTiddlers) {
|
|
|
|
var changedAttributes = this.computeAttributes();
|
|
|
|
if(changedAttributes["$message"] || changedAttributes["$prompt"]) {
|
|
|
|
this.refreshSelf();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this.refreshChildren(changedTiddlers);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Invoke the action associated with this widget
|
|
|
|
*/
|
|
|
|
ConfirmWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
|
|
|
var invokeActions = true,
|
2021-06-11 15:56:06 +00:00
|
|
|
handled = true,
|
2021-09-22 12:43:02 +00:00
|
|
|
win = event && event.event && event.event.view ? event.event.view : window;
|
2020-11-16 17:02:22 +00:00
|
|
|
if(this.prompt) {
|
2021-06-11 15:56:06 +00:00
|
|
|
invokeActions = win.confirm(this.message);
|
2020-11-15 11:40:08 +00:00
|
|
|
}
|
|
|
|
if(invokeActions) {
|
|
|
|
handled = this.invokeActions(triggeringWidget,event);
|
|
|
|
}
|
|
|
|
return handled;
|
|
|
|
};
|
|
|
|
|
|
|
|
ConfirmWidget.prototype.allowActionPropagation = function() {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports["action-confirm"] = ConfirmWidget;
|
|
|
|
|
2021-06-11 15:56:06 +00:00
|
|
|
})();
|