some fixes for valueWidget

This commit is contained in:
Ralf Becker 2020-01-21 12:48:48 +01:00 committed by Hadi Nategh
parent 8b3f9947e6
commit d9e2e26fcd
5 changed files with 347 additions and 410 deletions

View File

@ -1,3 +1,4 @@
"use strict";
/** /**
* EGroupware eTemplate2 - JS Widget base class * EGroupware eTemplate2 - JS Widget base class
* *
@ -7,13 +8,30 @@
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @author Andreas Stöckel * @author Andreas Stöckel
*/ */
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
/*egw:uses /*egw:uses
/vendor/bower-asset/jquery/dist/jquery.js; /vendor/bower-asset/jquery/dist/jquery.js;
lib/tooltip; lib/tooltip;
et2_core_DOMWidget; et2_core_DOMWidget;
*/ */
//import { ClassWithAttributes } from './et2_core_inheritance';
require("./et2_core_interfaces");
require("./et2_core_common");
var et2_core_DOMWidget_1 = require("./et2_core_DOMWidget");
var et2_core_inheritance_1 = require("./et2_core_inheritance");
/** /**
* Class which manages the DOM node itself. The simpleWidget class is derrived * Class which manages the DOM node itself. The simpleWidget class is derrived
* from et2_DOMWidget and implements the getDOMNode function. A setDOMNode * from et2_DOMWidget and implements the getDOMNode function. A setDOMNode
@ -21,407 +39,319 @@
* *
* @augments et2_DOMWidget * @augments et2_DOMWidget
*/ */
var et2_baseWidget = (function(){ "use strict"; return et2_DOMWidget.extend(et2_IAligned, var et2_baseWidget = /** @class */ (function (_super) {
{ __extends(et2_baseWidget, _super);
attributes: { /**
"statustext": { * Constructor
"name": "Tooltip", */
"type": "string", function et2_baseWidget(_parent, _attrs, _child) {
"description": "Tooltip which is shown for this element", var _this =
"translate": true // Call the inherited constructor
}, _super.call(this, _parent, _attrs, et2_core_inheritance_1.ClassWithAttributes.extendAttributes(et2_core_DOMWidget_1.et2_DOMWidget._attributes, _child || {})) || this;
"statustext_html": { _this.align = 'left';
"name": "Tooltip is html", _this.node = null;
"type": "boolean", _this.statustext = '';
"description": "Flag to allow html content in tooltip", _this._messageDiv = null;
"default": false _this._tooltipElem = null;
}, return _this;
"align": { }
"name": "Align", et2_baseWidget.prototype.destroy = function () {
"type": "string", _super.prototype.destroy.call(this);
"default": "left", this.node = null;
"description": "Position of this element in the parent hbox" this._messageDiv = null;
}, };
"onclick": { /**
"name": "onclick", * The setMessage function can be used to attach a small message box to the
"type": "js", * widget. This is e.g. used to display validation errors or success messages
"default": et2_no_init, *
"description": "JS code which is executed when the element is clicked." * @param _text is the text which should be displayed as a message
} * @param _type is an css class which is attached to the message box.
}, * Currently available are "hint", "success" and "validation_error", defaults
* to "hint"
/** * @param _floating if true, the object will be in one row with the element,
* Constructor * defaults to true
* * @param _prepend if set, the message is displayed behind the widget node
* @memberOf et2BaseWidget * instead of before. Defaults to false.
*/ */
init: function() { et2_baseWidget.prototype.showMessage = function (_text, _type, _floating, _prepend) {
this.align = "left"; // Preset the parameters
if (typeof _type == "undefined") {
this._super.apply(this, arguments); _type = "hint";
}
this.node = null; if (typeof _floating == "undefined") {
this.statustext = ""; _floating = true;
this._messageDiv = null; }
this._tooltipElem = null; if (typeof _prepend == "undefined") {
}, _prepend = false;
}
destroy: function() { var surr = this.getSurroundings();
this._super.apply(this, arguments); // Remove the message div from the surroundings before creating a new
// one
this.node = null; this.hideMessage(false, true);
this._messageDiv = null; // Create the message div and add it to the "surroundings" manager
}, this._messageDiv = jQuery(document.createElement("div"))
.addClass("message")
/** .addClass(_type)
* The setMessage function can be used to attach a small message box to the .addClass(_floating ? "floating" : "")
* widget. This is e.g. used to display validation errors or success messages .text(_text.valueOf() + "");
* // Decide whether to prepend or append the div
* @param _text is the text which should be displayed as a message if (_prepend) {
* @param _type is an css class which is attached to the message box. surr.prependDOMNode(this._messageDiv[0]);
* Currently available are "hint", "success" and "validation_error", defaults }
* to "hint" else {
* @param _floating if true, the object will be in one row with the element, surr.appendDOMNode(this._messageDiv[0]);
* defaults to true }
* @param _prepend if set, the message is displayed behind the widget node surr.update();
* instead of before. Defaults to false. };
*/ /**
showMessage: function(_text, _type, _floating, _prepend) { * The hideMessage function can be used to hide a previously shown message.
*
// Preset the parameters * @param _fade if true, the message div will fade out, otherwise the message
if (typeof _type == "undefined") * div is removed immediately. Defaults to true.
{ * @param _noUpdate is used internally to prevent an update of the surroundings
_type = "hint"; * manager.
} */
et2_baseWidget.prototype.hideMessage = function (_fade, _noUpdate) {
if (typeof _floating == "undefined") if (typeof _fade == "undefined") {
{ _fade = true;
_floating = true; }
} if (typeof _noUpdate == "undefined") {
_noUpdate = false;
if (typeof _prepend == "undefined") }
{ // Remove the message from the surroundings manager and remove the
_prepend = false; // reference to it
} if (this._messageDiv != null) {
var surr = this.getSurroundings();
var surr = this.getSurroundings(); var self = this;
var messageDiv = this._messageDiv;
// Remove the message div from the surroundings before creating a new self._messageDiv = null;
// one var _done = function () {
this.hideMessage(false, true); surr.removeDOMNode(messageDiv[0]);
// Update the surroundings manager
// Create the message div and add it to the "surroundings" manager if (!_noUpdate) {
this._messageDiv = jQuery(document.createElement("div")) surr.update();
.addClass("message") }
.addClass(_type) };
.addClass(_floating ? "floating" : "") // Either fade out or directly call the function which removes the div
.text(_text.valueOf() + ""); if (_fade) {
messageDiv.fadeOut("fast", _done);
// Decide whether to prepend or append the div }
if (_prepend) else {
{ _done();
surr.prependDOMNode(this._messageDiv[0]); }
} }
else };
{ et2_baseWidget.prototype.detachFromDOM = function () {
surr.appendDOMNode(this._messageDiv[0]); // Detach this node from the tooltip node
} if (this._tooltipElem) {
this.egw().tooltipUnbind(this._tooltipElem);
surr.update(); this._tooltipElem = null;
}, }
// Remove the binding to the click handler
/** if (this.node) {
* The hideMessage function can be used to hide a previously shown message. jQuery(this.node).unbind("click.et2_baseWidget");
* }
* @param _fade if true, the message div will fade out, otherwise the message return _super.prototype.detachFromDOM.call(this);
* div is removed immediately. Defaults to true. };
* @param _noUpdate is used internally to prevent an update of the surroundings et2_baseWidget.prototype.attachToDOM = function () {
* manager. var ret = _super.prototype.attachToDOM.call(this);
*/ // Add the binding for the click handler
hideMessage: function(_fade, _noUpdate) { if (this.node) {
if (typeof _fade == "undefined") jQuery(this.node).bind("click.et2_baseWidget", this, function (e) {
{ return e.data.click.call(e.data, e, this);
_fade = true; });
} if (typeof this.onclick == 'function')
jQuery(this.node).addClass('et2_clickable');
if (typeof _noUpdate == "undefined") }
{ // Update the statustext
_noUpdate = false; this.set_statustext(this.statustext);
} return ret;
};
// Remove the message from the surroundings manager and remove the et2_baseWidget.prototype.setDOMNode = function (_node) {
// reference to it if (_node != this.node) {
if (this._messageDiv != null) // Deatch the old node from the DOM
{ this.detachFromDOM();
var surr = this.getSurroundings(); // Set the new DOM-Node
var self = this; this.node = _node;
var messageDiv = this._messageDiv; // Attatch the DOM-Node to the tree
self._messageDiv = null; return this.attachToDOM();
}
var _done = function() { return false;
surr.removeDOMNode(messageDiv[0]); };
et2_baseWidget.prototype.getDOMNode = function (_sender) {
// Update the surroundings manager return this.node;
if (!_noUpdate) };
{ et2_baseWidget.prototype.getTooltipElement = function () {
surr.update(); return this.getDOMNode(this);
} };
}; /**
* Click handler calling custom handler set via onclick attribute to this.onclick
// Either fade out or directly call the function which removes the div *
if (_fade) * @param _ev
{ * @returns
messageDiv.fadeOut("fast", _done); */
} et2_baseWidget.prototype.click = function (_ev) {
else if (typeof this.onclick == 'function') {
{ // Make sure function gets a reference to the widget, splice it in as 2. argument if not
_done(); var args = Array.prototype.slice.call(arguments);
} if (args.indexOf(this) == -1)
} args.splice(1, 0, this);
}, return this.onclick.apply(this, args);
}
detachFromDOM: function() { return true;
// Detach this node from the tooltip node };
if (this._tooltipElem) et2_baseWidget.prototype.set_statustext = function (_value) {
{ // Tooltip should not be shown in mobile view
this.egw().tooltipUnbind(this._tooltipElem); if (egwIsMobile())
this._tooltipElem = null; return;
} // Don't execute the code below, if no tooltip will be attached/detached
if (_value == "" && !this._tooltipElem) {
// Remove the binding to the click handler return;
if (this.node) }
{ // allow statustext to contain multiple translated sub-strings eg: {Firstname}.{Lastname}
jQuery(this.node).unbind("click.et2_baseWidget"); if (_value.indexOf('{') !== -1) {
} var egw = this.egw();
_value = _value.replace(/{([^}]+)}/g, function (str, p1) {
this._super.apply(this, arguments); return egw.lang(p1);
}, });
}
attachToDOM: function() { this.statustext = _value;
this._super.apply(this, arguments); //Get the domnode the tooltip should be attached to
var elem = jQuery(this.getTooltipElement());
// Add the binding for the click handler if (elem) {
if (this.node) //If a tooltip is already attached to the element, remove it first
{ if (this._tooltipElem) {
jQuery(this.node).bind("click.et2_baseWidget", this, function(e) { this.egw().tooltipUnbind(this._tooltipElem);
return e.data.click.call(e.data, e, this); this._tooltipElem = null;
}); }
if (typeof this.onclick == 'function') jQuery(this.node).addClass('et2_clickable'); if (_value && _value != '') {
} this.egw().tooltipBind(elem, _value, this.options.statustext_html);
this._tooltipElem = elem;
// Update the statustext }
this.set_statustext(this.statustext); }
}, };
et2_baseWidget.prototype.set_align = function (_value) {
setDOMNode: function(_node) { this.align = _value;
if (_node != this.node) };
{ et2_baseWidget.prototype.get_align = function () {
// Deatch the old node from the DOM return this.align;
this.detachFromDOM(); };
et2_baseWidget._attributes = {
// Set the new DOM-Node "statustext": {
this.node = _node; "name": "Tooltip",
"type": "string",
// Attatch the DOM-Node to the tree "description": "Tooltip which is shown for this element",
return this.attachToDOM(); "translate": true
} },
"statustext_html": {
return false; "name": "Tooltip is html",
}, "type": "boolean",
"description": "Flag to allow html content in tooltip",
getDOMNode: function() { "default": false
return this.node; },
}, "align": {
"name": "Align",
getTooltipElement: function() { "type": "string",
return this.getDOMNode(this); "default": "left",
}, "description": "Position of this element in the parent hbox"
},
/** "onclick": {
* Click handler calling custom handler set via onclick attribute to this.onclick "name": "onclick",
* "type": "js",
* @param _ev "default": et2_no_init,
* @returns "description": "JS code which is executed when the element is clicked."
*/ }
click: function(_ev) { };
if(typeof this.onclick == 'function') return et2_baseWidget;
{ }(et2_core_DOMWidget_1.et2_DOMWidget));
// Make sure function gets a reference to the widget, splice it in as 2. argument if not exports.et2_baseWidget = et2_baseWidget;
var args = Array.prototype.slice.call(arguments);
if(args.indexOf(this) == -1) args.splice(1, 0, this);
return this.onclick.apply(this, args);
}
return true;
},
set_statustext: function(_value) {
// Tooltip should not be shown in mobile view
if (egwIsMobile()) return;
// Don't execute the code below, if no tooltip will be attached/detached
if (_value == "" && !this._tooltipElem)
{
return;
}
// allow statustext to contain multiple translated sub-strings eg: {Firstname}.{Lastname}
if (_value.indexOf('{') !== -1)
{
var egw = this.egw();
_value = _value.replace(/{([^}]+)}/g, function(str,p1)
{
return egw.lang(p1);
});
}
this.statustext = _value;
//Get the domnode the tooltip should be attached to
var elem = jQuery(this.getTooltipElement());
if (elem)
{
//If a tooltip is already attached to the element, remove it first
if (this._tooltipElem)
{
this.egw().tooltipUnbind(this._tooltipElem);
this._tooltipElem = null;
}
if (_value && _value != '')
{
this.egw().tooltipBind(elem, _value, this.options.statustext_html);
this._tooltipElem = elem;
}
}
},
set_align: function(_value) {
this.align = _value;
},
get_align: function(_value) {
return this.align;
}
});}).call(this);
/** /**
* Simple container object * Simple container object
*
* @augments et2_baseWidget
*/ */
var et2_container = (function(){ "use strict"; return et2_baseWidget.extend( var et2_container = /** @class */ (function (_super) {
{ __extends(et2_container, _super);
/** /**
* Constructor * Constructor
* */
* @memberOf et2_container function et2_container(_parent, _attrs, _child) {
*/ // Call the inherited constructor
init: function() { return _super.call(this, _parent, _attrs, et2_core_inheritance_1.ClassWithAttributes.extendAttributes(et2_core_DOMWidget_1.et2_DOMWidget._attributes, _child || {})) || this;
this._super.apply(this, arguments); }
/**
this.setDOMNode(document.createElement("div")); * The destroy function destroys all children of the widget, removes itself
}, * from the parents children list.
* Overriden to not try to remove self from parent, as that's not possible.
/** */
* The destroy function destroys all children of the widget, removes itself et2_container.prototype.destroy = function () {
* from the parents children list. // Call the destructor of all children
* Overriden to not try to remove self from parent, as that's not possible. for (var i = this._children.length - 1; i >= 0; i--) {
*/ this._children[i].destroy();
destroy: function() { }
// Call the destructor of all children // Free the array managers if they belong to this widget
for (var i = this._children.length - 1; i >= 0; i--) for (var key in this._mgrs) {
{ if (this._mgrs[key] && this._mgrs[key].owner == this) {
this._children[i].free(); this._mgrs[key].destroy();
} }
}
// Free the array managers if they belong to this widget };
for (var key in this._mgrs) return et2_container;
{ }(et2_baseWidget));
if (this._mgrs[key] && this._mgrs[key].owner == this)
{
this._mgrs[key].free();
}
}
}
});}).call(this);
/** /**
* Container object for not-yet supported widgets * Container object for not-yet supported widgets
* *
* @augments et2_baseWidget * @augments et2_baseWidget
*/ */
var et2_placeholder = (function(){ "use strict"; return et2_baseWidget.extend([et2_IDetachedDOM], var et2_placeholder = /** @class */ (function (_super) {
{ __extends(et2_placeholder, _super);
/** /**
* Constructor * Constructor
* */
* @memberOf et2_placeholder function et2_placeholder(_parent, _attrs, _child) {
*/ var _this =
init: function() { // Call the inherited constructor
this._super.apply(this, arguments); _super.call(this, _parent, _attrs, et2_core_inheritance_1.ClassWithAttributes.extendAttributes(et2_core_DOMWidget_1.et2_DOMWidget._attributes, _child || {})) || this;
_this.visible = false;
// The attrNodes object will hold the DOM nodes which represent the _this.attrNodes = {};
// values of this object // Create the placeholder div
this.attrNodes = {}; _this.placeDiv = jQuery(document.createElement("span"))
.addClass("et2_placeholder");
this.visible = false; var headerNode = jQuery(document.createElement("span"))
.text(_this.getType() || "")
// Create the placeholder div .addClass("et2_caption")
this.placeDiv = jQuery(document.createElement("span")) .appendTo(_this.placeDiv);
.addClass("et2_placeholder"); var attrsCntr = jQuery(document.createElement("span"))
.appendTo(_this.placeDiv)
var headerNode = jQuery(document.createElement("span")) .hide();
.text(this._type || "") headerNode.click(_this, function (e) {
.addClass("et2_caption") e.data.visible = !e.data.visible;
.appendTo(this.placeDiv); if (e.data.visible) {
attrsCntr.show();
var attrsCntr = jQuery(document.createElement("span")) }
.appendTo(this.placeDiv) else {
.hide(); attrsCntr.hide();
}
headerNode.click(this, function(e) { });
e.data.visible = !e.data.visible; for (var key in _this.options) {
if (e.data.visible) if (typeof _this.options[key] != "undefined") {
{ if (typeof _this.attrNodes[key] == "undefined") {
attrsCntr.show(); _this.attrNodes[key] = jQuery(document.createElement("span"))
} .addClass("et2_attr");
else attrsCntr.append(_this.attrNodes[key]);
{ }
attrsCntr.hide(); _this.attrNodes[key].text(key + "=" + _this.options[key]);
} }
}); }
_this.setDOMNode(_this.placeDiv[0]);
for (var key in this.options) return _this;
{ }
if (typeof this.options[key] != "undefined") et2_placeholder.prototype.getDetachedAttributes = function (_attrs) {
{ _attrs.push("value");
if (typeof this.attrNodes[key] == "undefined") };
{ et2_placeholder.prototype.getDetachedNodes = function () {
this.attrNodes[key] = jQuery(document.createElement("span")) return [this.placeDiv[0]];
.addClass("et2_attr"); };
attrsCntr.append(this.attrNodes[key]); et2_placeholder.prototype.setDetachedAttributes = function (_nodes, _values) {
} this.placeDiv = jQuery(_nodes[0]);
};
this.attrNodes[key].text(key + "=" + this.options[key]); return et2_placeholder;
} }(et2_baseWidget));
}
this.setDOMNode(this.placeDiv[0]);
},
getDetachedAttributes: function(_attrs) {
_attrs.push("value");
},
getDetachedNodes: function() {
return [this.placeDiv[0]];
},
setDetachedAttributes: function(_nodes, _values) {
this.placeDiv = jQuery(_nodes[0]);
}
});}).call(this);

View File

@ -28,7 +28,7 @@ import { et2_widget, et2_createWidget, et2_register_widget, WidgetConfig } from
* *
* @augments et2_DOMWidget * @augments et2_DOMWidget
*/ */
class et2_baseWidget extends et2_DOMWidget implements et2_IAligned export class et2_baseWidget extends et2_DOMWidget implements et2_IAligned
{ {
static readonly _attributes: any = { static readonly _attributes: any = {
"statustext": { "statustext": {

View File

@ -28,7 +28,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
/vendor/bower-asset/jquery/dist/jquery.js; /vendor/bower-asset/jquery/dist/jquery.js;
et2_core_baseWidget; et2_core_baseWidget;
*/ */
require("./et2_core_baseWidget"); var et2_core_baseWidget_1 = require("./et2_core_baseWidget");
require("./et2_core_common"); require("./et2_core_common");
/** /**
* et2_valueWidget is the base class for et2_inputWidget - valueWidget introduces * et2_valueWidget is the base class for et2_inputWidget - valueWidget introduces
@ -40,7 +40,10 @@ require("./et2_core_common");
var et2_valueWidget = /** @class */ (function (_super) { var et2_valueWidget = /** @class */ (function (_super) {
__extends(et2_valueWidget, _super); __extends(et2_valueWidget, _super);
function et2_valueWidget() { function et2_valueWidget() {
return _super !== null && _super.apply(this, arguments) || this; var _this = _super !== null && _super.apply(this, arguments) || this;
_this.label = '';
_this._labelContainer = null;
return _this;
} }
/** /**
* *
@ -124,4 +127,5 @@ var et2_valueWidget = /** @class */ (function (_super) {
} }
}; };
return et2_valueWidget; return et2_valueWidget;
}(et2_baseWidget)); }(et2_core_baseWidget_1.et2_baseWidget));
exports.et2_valueWidget = et2_valueWidget;

View File

@ -15,7 +15,7 @@
et2_core_baseWidget; et2_core_baseWidget;
*/ */
import './et2_core_baseWidget' import { et2_baseWidget } from './et2_core_baseWidget'
import './et2_core_common'; import './et2_core_common';
/** /**
@ -25,7 +25,7 @@ import './et2_core_common';
* *
* @augments et2_baseWidget * @augments et2_baseWidget
*/ */
class et2_valueWidget extends et2_baseWidget export class et2_valueWidget extends et2_baseWidget
{ {
static readonly _attributes : any = { static readonly _attributes : any = {
"label": { "label": {
@ -43,6 +43,9 @@ class et2_valueWidget extends et2_baseWidget
} }
}; };
label: string = '';
private _labelContainer: JQuery = null;
/** /**
* *
* *
@ -73,7 +76,7 @@ class et2_valueWidget extends et2_baseWidget
} }
} }
set_label(_value) set_label(_value : string)
{ {
// Abort if there was no change in the label // Abort if there was no change in the label
if (_value == this.label) if (_value == this.label)

View File

@ -5,13 +5,14 @@ declare module eT2
declare var etemplate2 : any; declare var etemplate2 : any;
declare class et2_widget{} declare class et2_widget{}
declare class et2_DOMWidget extends et2_widget{} declare class et2_DOMWidget extends et2_widget{}
declare class et2_baseWidget extends et2_DOMWidget{}
declare class et2_valueWidget extends et2_baseWidget{}
declare class et2_inputWidget{ declare class et2_inputWidget{
getInputNode() : HTMLElement getInputNode() : HTMLElement
} }
declare var et2_surroundingsMgr : any; declare var et2_surroundingsMgr : any;
declare var et2_arrayMgr : any; declare var et2_arrayMgr : any;
declare var et2_readonlysArrayMgr : any; declare var et2_readonlysArrayMgr : any;
declare var et2_baseWidget : any;
declare var et2_container : any; declare var et2_container : any;
declare var et2_placeholder : any; declare var et2_placeholder : any;
declare var et2_validTypes : string[]; declare var et2_validTypes : string[];
@ -25,7 +26,6 @@ declare var et2_IAligned : any;
declare var et2_ISubmitListener : any; declare var et2_ISubmitListener : any;
declare var et2_IDetachedDOM : any; declare var et2_IDetachedDOM : any;
declare var et2_IPrint : any; declare var et2_IPrint : any;
declare var et2_valueWidget : any;
declare var et2_registry : {}; declare var et2_registry : {};
declare var et2_dataview : any; declare var et2_dataview : any;
declare var et2_dataview_controller : any; declare var et2_dataview_controller : any;