mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-25 15:29:17 +01:00
tabbox widget
This commit is contained in:
parent
239f75c8b9
commit
703b6a3cf8
@ -508,10 +508,11 @@ var et2_widget = /** @class */ (function (_super) {
|
|||||||
* is called with the node.
|
* is called with the node.
|
||||||
*
|
*
|
||||||
* @param _node XML node to read
|
* @param _node XML node to read
|
||||||
|
* @param _name XML node name
|
||||||
*
|
*
|
||||||
* @return et2_widget
|
* @return et2_widget
|
||||||
*/
|
*/
|
||||||
et2_widget.prototype.createElementFromNode = function (_node) {
|
et2_widget.prototype.createElementFromNode = function (_node, _name) {
|
||||||
var attributes = {};
|
var attributes = {};
|
||||||
// Parse the "readonly" and "type" flag for this element here, as they
|
// Parse the "readonly" and "type" flag for this element here, as they
|
||||||
// determine which constructor is used
|
// determine which constructor is used
|
||||||
|
@ -646,10 +646,11 @@ export class et2_widget extends ClassWithAttributes
|
|||||||
* is called with the node.
|
* is called with the node.
|
||||||
*
|
*
|
||||||
* @param _node XML node to read
|
* @param _node XML node to read
|
||||||
|
* @param _name XML node name
|
||||||
*
|
*
|
||||||
* @return et2_widget
|
* @return et2_widget
|
||||||
*/
|
*/
|
||||||
createElementFromNode(_node)
|
createElementFromNode(_node, _name?)
|
||||||
{
|
{
|
||||||
var attributes = {};
|
var attributes = {};
|
||||||
|
|
||||||
|
4
api/js/etemplate/et2_types.d.ts
vendored
4
api/js/etemplate/et2_types.d.ts
vendored
@ -155,4 +155,8 @@ declare var et2_IExposable : any;
|
|||||||
declare function et2_createWidget(type : string, params : {}, parent? : any) : any;
|
declare function et2_createWidget(type : string, params : {}, parent? : any) : any;
|
||||||
declare function nm_action(_action : {}, _senders : [], _target : any, _ids? : any) : void;
|
declare function nm_action(_action : {}, _senders : [], _target : any, _ids? : any) : void;
|
||||||
declare function et2_compileLegacyJS(_code : string, _widget : et2_widget, _context? : HTMLElement) : Function;
|
declare function et2_compileLegacyJS(_code : string, _widget : et2_widget, _context? : HTMLElement) : Function;
|
||||||
|
// et2_core_xml.js
|
||||||
declare function et2_loadXMLFromURL(_url : string, _callback : Function, _context? : object, _fail_callback? : Function) : void;
|
declare function et2_loadXMLFromURL(_url : string, _callback : Function, _context? : object, _fail_callback? : Function) : void;
|
||||||
|
declare function et2_directChildrenByTagName(_node, _tagName);
|
||||||
|
declare function et2_filteredNodeIterator(_node, _callback, _context);
|
||||||
|
declare function et2_readAttrWithDefault(_node, _name, _default?);
|
@ -1,3 +1,4 @@
|
|||||||
|
"use strict";
|
||||||
/**
|
/**
|
||||||
* EGroupware eTemplate2 - JS Description object
|
* EGroupware eTemplate2 - JS Description object
|
||||||
*
|
*
|
||||||
@ -6,410 +7,350 @@
|
|||||||
* @subpackage api
|
* @subpackage api
|
||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
* @author Andreas Stöckel
|
* @author Andreas Stöckel
|
||||||
* @copyright Stylite 2011
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
*/
|
||||||
|
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;
|
||||||
et2_core_baseWidget;
|
et2_core_baseWidget;
|
||||||
expose;
|
expose;
|
||||||
*/
|
*/
|
||||||
|
require("./et2_core_common");
|
||||||
|
var et2_core_inheritance_1 = require("./et2_core_inheritance");
|
||||||
|
var et2_core_widget_1 = require("./et2_core_widget");
|
||||||
|
var et2_core_DOMWidget_1 = require("./et2_core_DOMWidget");
|
||||||
|
var et2_core_baseWidget_1 = require("./et2_core_baseWidget");
|
||||||
|
require("./et2_types");
|
||||||
/**
|
/**
|
||||||
* Class which implements the "description" XET-Tag
|
* Class which implements the "description" XET-Tag
|
||||||
*
|
|
||||||
* @augments et2_baseWidget
|
|
||||||
*/
|
*/
|
||||||
var et2_description = (function(){ "use strict"; return expose(et2_baseWidget.extend([et2_IDetachedDOM],
|
var et2_description = /** @class */ (function (_super) {
|
||||||
{
|
__extends(et2_description, _super);
|
||||||
attributes: {
|
/**
|
||||||
"label": {
|
* Constructor
|
||||||
"name": "Label",
|
*/
|
||||||
"default": "",
|
function et2_description(_parent, _attrs, _child) {
|
||||||
"type": "string",
|
var _this =
|
||||||
"description": "The label is displayed by default in front (for radiobuttons behind) each widget (if not empty). If you want to specify a different position, use a '%s' in the label, which gets replaced by the widget itself. Eg. '%s Name' to have the label Name behind a checkbox. The label can contain variables, as descript for name. If the label starts with a '@' it is replaced by the value of the content-array at this index (with the '@'-removed and after expanding the variables).",
|
// Call the inherited constructor
|
||||||
"translate": true
|
_super.call(this, _parent, _attrs, et2_core_inheritance_1.ClassWithAttributes.extendAttributes(et2_core_DOMWidget_1.et2_DOMWidget._attributes, _child || {})) || this;
|
||||||
},
|
_this.legacyOptions = ["font_style", "href", "activate_links", "for",
|
||||||
"value": {
|
"extra_link_target", "extra_link_popup", "statustext"];
|
||||||
"name": "Value",
|
_this._labelContainer = null;
|
||||||
"type": "string",
|
// Create the span/label tag which contains the label text
|
||||||
"description": "Displayed text",
|
_this.span = jQuery(document.createElement(_this.options["for"] ? "label" : "span"))
|
||||||
"translate": "!no_lang",
|
.addClass("et2_label");
|
||||||
"default": ""
|
et2_insertLinkText(_this._parseText(_this.options.value), _this.span[0], _this.options.href ? _this.options.extra_link_target : '_blank');
|
||||||
},
|
_this.setDOMNode(_this.span[0]);
|
||||||
|
return _this;
|
||||||
/**
|
}
|
||||||
* Options converted from the "options"-attribute.
|
et2_description.prototype.transformAttributes = function (_attrs) {
|
||||||
*/
|
_super.prototype.transformAttributes.call(this, _attrs);
|
||||||
"font_style": {
|
if (this.id) {
|
||||||
"name": "Font Style",
|
var val = this.getArrayMgr("content").getEntry(this.id);
|
||||||
"type": "string",
|
if (val) {
|
||||||
"description": "Style may be a compositum of \"b\" and \"i\" which " +
|
_attrs["value"] = val;
|
||||||
" renders the text bold and/or italic."
|
}
|
||||||
},
|
}
|
||||||
"href": {
|
};
|
||||||
"name": "Link URL",
|
et2_description.prototype.doLoadingFinished = function () {
|
||||||
"type": "string",
|
_super.prototype.doLoadingFinished.call(this);
|
||||||
"description": "Link URL, empty if you don't wan't to display a link."
|
// Get the real id of the 'for' widget
|
||||||
},
|
var for_widget = null;
|
||||||
"activate_links": {
|
if (this.options["for"] && ((for_widget = this.getParent().getWidgetById(this.options.for)) ||
|
||||||
"name": "Replace URLs",
|
(for_widget = this.getRoot().getWidgetById(this.options.for))) && for_widget && for_widget.id) {
|
||||||
"type": "boolean",
|
if (for_widget.dom_id) {
|
||||||
"default": false,
|
this.span.attr("for", for_widget.dom_id);
|
||||||
"description": "If set, URLs in the text are automatically replaced " +
|
}
|
||||||
"by links"
|
else {
|
||||||
},
|
// Target widget is not done yet, need to wait
|
||||||
"for": {
|
var tab_deferred = jQuery.Deferred();
|
||||||
"name": "Label for widget",
|
window.setTimeout(function () {
|
||||||
"type": "string",
|
this.span.attr("for", for_widget.dom_id);
|
||||||
"description": "Marks the text as label for the given widget."
|
tab_deferred.resolve();
|
||||||
},
|
}.bind(this), 0);
|
||||||
"extra_link_target": {
|
return tab_deferred.promise();
|
||||||
"name": "Link target",
|
}
|
||||||
"type": "string",
|
}
|
||||||
"default": "_browser",
|
return true;
|
||||||
"description": "Link target for href attribute"
|
};
|
||||||
},
|
et2_description.prototype.set_label = function (_value) {
|
||||||
"extra_link_popup": {
|
// Abort if ther was no change in the label
|
||||||
"name": "Popup",
|
if (_value == this.label) {
|
||||||
"type": "string",
|
return;
|
||||||
"description": "widthxheight, if popup should be used, eg. 640x480"
|
}
|
||||||
},
|
if (_value) {
|
||||||
"expose_view":{
|
// Create the label container if it didn't exist yet
|
||||||
name: "Expose view",
|
if (this._labelContainer == null) {
|
||||||
type: "boolean",
|
this._labelContainer = jQuery(document.createElement("label"))
|
||||||
default: false,
|
.addClass("et2_label");
|
||||||
description: "Clicking on description with href value would popup an expose view, and will show content referenced by href."
|
this.getSurroundings().insertDOMNode(this._labelContainer[0]);
|
||||||
},
|
}
|
||||||
mime:{
|
// Clear the label container.
|
||||||
name: "Mime type",
|
this._labelContainer.empty();
|
||||||
type: "string",
|
// Create the placeholder element and set it
|
||||||
default: '',
|
var ph = document.createElement("span");
|
||||||
description: "Mime type of the registered link"
|
this.getSurroundings().setWidgetPlaceholder(ph);
|
||||||
},
|
// Split the label at the "%s"
|
||||||
mime_data:{
|
var parts = et2_csvSplit(_value, 2, "%s");
|
||||||
name: "Mime data",
|
// Update the content of the label container
|
||||||
type: "string",
|
for (var i = 0; i < parts.length; i++) {
|
||||||
default: '',
|
if (parts[i]) {
|
||||||
description: "hash for data stored on service-side with egw_link::(get|set)_data()"
|
this._labelContainer.append(document.createTextNode(parts[i]));
|
||||||
},
|
}
|
||||||
hover_action: {
|
if (i == 0) {
|
||||||
"name": "hover action",
|
this._labelContainer.append(ph);
|
||||||
"type": "js",
|
}
|
||||||
"default": et2_no_init,
|
}
|
||||||
"description": "JS code which is executed when clicking on action button. This action is explicitly for attached nodes, like in nm."
|
// add class if label is empty
|
||||||
},
|
this._labelContainer.toggleClass('et2_label_empty', !_value || !parts[0]);
|
||||||
hover_action_title: {
|
}
|
||||||
"name": "hover action title",
|
else {
|
||||||
"type": "string",
|
// Delete the labelContainer from the surroundings object
|
||||||
"default": "Edit",
|
if (this._labelContainer) {
|
||||||
"description": "Text to show as tooltip of defined action"
|
this.getSurroundings().removeDOMNode(this._labelContainer[0]);
|
||||||
}
|
}
|
||||||
|
this._labelContainer = null;
|
||||||
},
|
}
|
||||||
|
// Update the surroundings in order to reflect the change in the label
|
||||||
legacyOptions: ["font_style", "href", "activate_links", "for",
|
this.getSurroundings().update();
|
||||||
"extra_link_target", "extra_link_popup", "statustext"],
|
// Copy the given value
|
||||||
|
this.label = _value;
|
||||||
/**
|
};
|
||||||
* Constructor
|
/**
|
||||||
*
|
* Function to get media content to feed the expose
|
||||||
* @memberOf et2_description
|
* @param {type} _value
|
||||||
*/
|
* @returns {Array|Array.getMedia.mediaContent}
|
||||||
init: function() {
|
*/
|
||||||
this._super.apply(this, arguments);
|
et2_description.prototype.getMedia = function (_value) {
|
||||||
|
var base_url = egw.webserverUrl.match(/^\//, 'ig') ? egw(window).window.location.origin : '';
|
||||||
// Create the span/label tag which contains the label text
|
var mediaContent = [];
|
||||||
this.span = jQuery(document.createElement(this.options["for"] ? "label" : "span"))
|
if (_value) {
|
||||||
.addClass("et2_label");
|
mediaContent = [{
|
||||||
|
title: this.options.label,
|
||||||
|
href: base_url + _value,
|
||||||
|
type: this.options.type + "/*",
|
||||||
et2_insertLinkText(this._parseText(this.options.value), this.span[0],
|
thumbnail: base_url + _value
|
||||||
this.options.href ? this.options.extra_link_target : '_blank');
|
}];
|
||||||
|
if (_value.match(/\/webdav.php/, 'ig'))
|
||||||
this.setDOMNode(this.span[0]);
|
mediaContent[0]["download_href"] = base_url + _value + '?download';
|
||||||
},
|
}
|
||||||
|
return mediaContent;
|
||||||
transformAttributes: function(_attrs) {
|
};
|
||||||
this._super.apply(this, arguments);
|
et2_description.prototype.set_value = function (_value) {
|
||||||
|
if (!_value)
|
||||||
if (this.id)
|
_value = "";
|
||||||
{
|
if (!this.options.no_lang)
|
||||||
var val = this.getArrayMgr("content").getEntry(this.id);
|
_value = this.egw().lang(_value);
|
||||||
|
if (this.options.value && (this.options.value + "").indexOf('%s') != -1) {
|
||||||
if (val)
|
_value = this.options.value.replace(/%s/g, _value);
|
||||||
{
|
}
|
||||||
_attrs["value"] = val;
|
et2_insertLinkText(this._parseText(_value), this.span[0], this.options.href ? this.options.extra_link_target : '_blank');
|
||||||
}
|
// Add hover action button (Edit)
|
||||||
}
|
if (this.options.hover_action) {
|
||||||
},
|
this._build_hover_action();
|
||||||
|
}
|
||||||
doLoadingFinished: function() {
|
if (this.options.extra_link_popup || this.options.mime) {
|
||||||
|
var href = this.options.href;
|
||||||
this._super.apply(this, arguments);
|
var mime_data = this.options.mime_data;
|
||||||
|
var self = this;
|
||||||
// Get the real id of the 'for' widget
|
var $span = this.options.mime_data ? jQuery(this.span) : jQuery('a', this.span);
|
||||||
var for_widget = null;
|
$span.click(function (e) {
|
||||||
if (this.options["for"] && (
|
if (self.options.expose_view && typeof self.options.mime != 'undefined' && self.options.mime.match(self.mime_regexp, 'ig')) {
|
||||||
(for_widget = this.getParent().getWidgetById(this.options.for)) ||
|
// ToDoExpose: self._init_blueimp_gallery(e, href);
|
||||||
(for_widget = this.getRoot().getWidgetById(this.options.for))
|
}
|
||||||
) && for_widget && for_widget.id)
|
else {
|
||||||
{
|
egw(window).open_link(mime_data || href, self.options.extra_link_target, self.options.extra_link_popup, null, null, self.options.mime);
|
||||||
if(for_widget.dom_id)
|
}
|
||||||
{
|
e.preventDefault();
|
||||||
this.span.attr("for", for_widget.dom_id);
|
return false;
|
||||||
}
|
});
|
||||||
else
|
}
|
||||||
{
|
};
|
||||||
// Target widget is not done yet, need to wait
|
et2_description.prototype._parseText = function (_value) {
|
||||||
var tab_deferred = jQuery.Deferred();
|
if (this.options.href) {
|
||||||
window.setTimeout(function() {
|
var href = this.options.href;
|
||||||
this.span.attr("for", for_widget.dom_id);
|
if (href.indexOf('/') == -1 && href.split('.').length >= 3 &&
|
||||||
tab_deferred.resolve();
|
!(href.indexOf('mailto:') != -1 || href.indexOf('://') != -1 || href.indexOf('javascript:') != -1)) {
|
||||||
}.bind(this),0);
|
href = "/index.php?menuaction=" + href;
|
||||||
|
}
|
||||||
return tab_deferred.promise();
|
if (href.charAt(0) == '/') // link relative to eGW
|
||||||
}
|
{
|
||||||
}
|
href = egw.link(href);
|
||||||
return true;
|
}
|
||||||
},
|
return [{
|
||||||
|
"href": href,
|
||||||
set_label: function(_value) {
|
"text": _value
|
||||||
// Abort if ther was no change in the label
|
}];
|
||||||
if (_value == this.label)
|
}
|
||||||
{
|
else if (this.options.activate_links) {
|
||||||
return;
|
return et2_activateLinks(_value);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (_value)
|
return [_value];
|
||||||
{
|
}
|
||||||
// Create the label container if it didn't exist yet
|
};
|
||||||
if (this._labelContainer == null)
|
et2_description.prototype.set_font_style = function (_value) {
|
||||||
{
|
this.font_style = _value;
|
||||||
this._labelContainer = jQuery(document.createElement("label"))
|
this.span.toggleClass("et2_bold", _value.indexOf("b") >= 0);
|
||||||
.addClass("et2_label");
|
this.span.toggleClass("et2_italic", _value.indexOf("i") >= 0);
|
||||||
this.getSurroundings().insertDOMNode(this._labelContainer[0]);
|
};
|
||||||
}
|
/**
|
||||||
|
* Code for implementing et2_IDetachedDOM
|
||||||
// Clear the label container.
|
*
|
||||||
this._labelContainer.empty();
|
* @param {array} _attrs
|
||||||
|
*/
|
||||||
// Create the placeholder element and set it
|
et2_description.prototype.getDetachedAttributes = function (_attrs) {
|
||||||
var ph = document.createElement("span");
|
_attrs.push("value", "class", "href");
|
||||||
this.getSurroundings().setWidgetPlaceholder(ph);
|
};
|
||||||
|
et2_description.prototype.getDetachedNodes = function () {
|
||||||
// Split the label at the "%s"
|
return [this.span[0]];
|
||||||
var parts = et2_csvSplit(_value, 2, "%s");
|
};
|
||||||
|
et2_description.prototype.setDetachedAttributes = function (_nodes, _values, _data) {
|
||||||
// Update the content of the label container
|
// Update the properties
|
||||||
for (var i = 0; i < parts.length; i++)
|
var updateLink = false;
|
||||||
{
|
if (typeof _values["href"] != "undefined") {
|
||||||
if (parts[i])
|
updateLink = true;
|
||||||
{
|
this.options.href = _values["href"];
|
||||||
this._labelContainer.append(document.createTextNode(parts[i]));
|
}
|
||||||
}
|
if (typeof _values["value"] != "undefined" || (updateLink && (_values["value"] || this.options.value))) {
|
||||||
if (i == 0)
|
this.span = jQuery(_nodes[0]);
|
||||||
{
|
this.set_value(_values["value"]);
|
||||||
this._labelContainer.append(ph);
|
}
|
||||||
}
|
if (typeof _values["class"] != "undefined") {
|
||||||
}
|
_nodes[0].setAttribute("class", _values["class"]);
|
||||||
|
}
|
||||||
// add class if label is empty
|
// Add hover action button (Edit), _data is nm's row data
|
||||||
this._labelContainer.toggleClass('et2_label_empty', !_value || !parts[0]);
|
if (this.options.hover_action) {
|
||||||
}
|
this._build_hover_action(_data);
|
||||||
else
|
}
|
||||||
{
|
};
|
||||||
// Delete the labelContainer from the surroundings object
|
/**
|
||||||
if (this._labelContainer)
|
* Builds button for hover action
|
||||||
{
|
* @param {object} _data
|
||||||
this.getSurroundings().removeDOMNode(this._labelContainer[0]);
|
*/
|
||||||
}
|
et2_description.prototype._build_hover_action = function (_data) {
|
||||||
this._labelContainer = null;
|
var content = _data && _data.content ? _data.content : undefined;
|
||||||
}
|
var widget = this;
|
||||||
|
this.span.off().on('mouseenter', jQuery.proxy(function (event) {
|
||||||
// Update the surroundings in order to reflect the change in the label
|
event.stopImmediatePropagation();
|
||||||
this.getSurroundings().update();
|
var self = this;
|
||||||
|
this.span.tooltip({
|
||||||
// Copy the given value
|
items: 'span.et2_label',
|
||||||
this.label = _value;
|
position: { my: "right top", at: "left top", collision: "flipfit" },
|
||||||
},
|
tooltipClass: "et2_email_popup",
|
||||||
/**
|
content: function () {
|
||||||
* Function to get media content to feed the expose
|
return jQuery('<a href="#" class= "et2_url_email_contactPlus" title="' + egw.lang(widget.options.hover_action_title) + '"><img src="'
|
||||||
* @param {type} _value
|
+ egw.image("edit") + '"/></a>')
|
||||||
* @returns {Array|Array.getMedia.mediaContent}
|
.on('click', function () {
|
||||||
*/
|
widget.options.hover_action.call(self, self.widget, content);
|
||||||
getMedia: function (_value)
|
});
|
||||||
{
|
},
|
||||||
var base_url = egw.webserverUrl.match(/^\//,'ig')?egw(window).window.location.origin :'';
|
close: function (event, ui) {
|
||||||
var mediaContent = [];
|
ui.tooltip.hover(function () {
|
||||||
if (_value)
|
jQuery(this).stop(true).fadeTo(400, 1);
|
||||||
{
|
}, function () {
|
||||||
mediaContent = [{
|
jQuery(this).fadeOut("400", function () { jQuery(this).remove(); });
|
||||||
title: this.options.label,
|
});
|
||||||
href: base_url + _value,
|
}
|
||||||
type: this.options.type + "/*",
|
})
|
||||||
thumbnail: base_url + _value
|
.tooltip("open");
|
||||||
}];
|
}, { widget: this, span: this.span }));
|
||||||
if (_value.match(/\/webdav.php/,'ig')) mediaContent[0]["download_href"] = base_url + _value + '?download';
|
};
|
||||||
}
|
et2_description._attributes = {
|
||||||
return mediaContent;
|
"label": {
|
||||||
},
|
"name": "Label",
|
||||||
set_value: function(_value) {
|
"default": "",
|
||||||
if (!_value) _value = "";
|
"type": "string",
|
||||||
if (!this.options.no_lang) _value = this.egw().lang(_value);
|
"description": "The label is displayed by default in front (for radiobuttons behind) each widget (if not empty). If you want to specify a different position, use a '%s' in the label, which gets replaced by the widget itself. Eg. '%s Name' to have the label Name behind a checkbox. The label can contain variables, as descript for name. If the label starts with a '@' it is replaced by the value of the content-array at this index (with the '@'-removed and after expanding the variables).",
|
||||||
if (this.options.value && (this.options.value+"").indexOf('%s') != -1)
|
"translate": true
|
||||||
{
|
},
|
||||||
_value = this.options.value.replace(/%s/g, _value);
|
"value": {
|
||||||
}
|
"name": "Value",
|
||||||
et2_insertLinkText(this._parseText(_value),
|
"type": "string",
|
||||||
this.span[0],
|
"description": "Displayed text",
|
||||||
this.options.href ? this.options.extra_link_target : '_blank'
|
"translate": "!no_lang",
|
||||||
);
|
"default": ""
|
||||||
// Add hover action button (Edit)
|
},
|
||||||
if (this.options.hover_action)
|
/**
|
||||||
{
|
* Options converted from the "options"-attribute.
|
||||||
this._build_hover_action();
|
*/
|
||||||
}
|
"font_style": {
|
||||||
if(this.options.extra_link_popup || this.options.mime)
|
"name": "Font Style",
|
||||||
{
|
"type": "string",
|
||||||
var href = this.options.href;
|
"description": "Style may be a compositum of \"b\" and \"i\" which " +
|
||||||
var mime_data = this.options.mime_data;
|
" renders the text bold and/or italic."
|
||||||
var self= this;
|
},
|
||||||
var $span = this.options.mime_data? jQuery(this.span): jQuery('a',this.span);
|
"href": {
|
||||||
$span.click(function(e) {
|
"name": "Link URL",
|
||||||
if (self.options.expose_view && typeof self.options.mime !='undefined' && self.options.mime.match(self.mime_regexp,'ig'))
|
"type": "string",
|
||||||
{
|
"description": "Link URL, empty if you don't wan't to display a link."
|
||||||
self._init_blueimp_gallery(e, href);
|
},
|
||||||
}
|
"activate_links": {
|
||||||
else
|
"name": "Replace URLs",
|
||||||
{
|
"type": "boolean",
|
||||||
egw(window).open_link(mime_data || href, self.options.extra_link_target, self.options.extra_link_popup, null, null, self.options.mime);
|
"default": false,
|
||||||
}
|
"description": "If set, URLs in the text are automatically replaced " +
|
||||||
e.preventDefault();
|
"by links"
|
||||||
return false;
|
},
|
||||||
});
|
"for": {
|
||||||
}
|
"name": "Label for widget",
|
||||||
},
|
"type": "string",
|
||||||
|
"description": "Marks the text as label for the given widget."
|
||||||
_parseText: function(_value) {
|
},
|
||||||
if (this.options.href)
|
"extra_link_target": {
|
||||||
{
|
"name": "Link target",
|
||||||
var href = this.options.href;
|
"type": "string",
|
||||||
if (href.indexOf('/')==-1 && href.split('.').length >= 3 &&
|
"default": "_browser",
|
||||||
!(href.indexOf('mailto:')!=-1 || href.indexOf('://') != -1 || href.indexOf('javascript:') != -1)
|
"description": "Link target for href attribute"
|
||||||
)
|
},
|
||||||
{
|
"extra_link_popup": {
|
||||||
href = "/index.php?menuaction="+href;
|
"name": "Popup",
|
||||||
}
|
"type": "string",
|
||||||
if (href.charAt(0) == '/') // link relative to eGW
|
"description": "widthxheight, if popup should be used, eg. 640x480"
|
||||||
{
|
},
|
||||||
href = egw.link(href);
|
"expose_view": {
|
||||||
}
|
name: "Expose view",
|
||||||
return [{
|
type: "boolean",
|
||||||
"href": href,
|
default: false,
|
||||||
"text": _value
|
description: "Clicking on description with href value would popup an expose view, and will show content referenced by href."
|
||||||
}];
|
},
|
||||||
}
|
mime: {
|
||||||
else if (this.options.activate_links)
|
name: "Mime type",
|
||||||
{
|
type: "string",
|
||||||
return et2_activateLinks(_value);
|
default: '',
|
||||||
}
|
description: "Mime type of the registered link"
|
||||||
else
|
},
|
||||||
{
|
mime_data: {
|
||||||
return [_value];
|
name: "Mime data",
|
||||||
}
|
type: "string",
|
||||||
},
|
default: '',
|
||||||
|
description: "hash for data stored on service-side with egw_link::(get|set)_data()"
|
||||||
set_font_style: function(_value) {
|
},
|
||||||
this.font_style = _value;
|
hover_action: {
|
||||||
|
"name": "hover action",
|
||||||
this.span.toggleClass("et2_bold", _value.indexOf("b") >= 0);
|
"type": "js",
|
||||||
this.span.toggleClass("et2_italic", _value.indexOf("i") >= 0);
|
"default": et2_no_init,
|
||||||
},
|
"description": "JS code which is executed when clicking on action button. This action is explicitly for attached nodes, like in nm."
|
||||||
|
},
|
||||||
/**
|
hover_action_title: {
|
||||||
* Code for implementing et2_IDetachedDOM
|
"name": "hover action title",
|
||||||
*
|
"type": "string",
|
||||||
* @param {array} _attrs
|
"default": "Edit",
|
||||||
*/
|
"description": "Text to show as tooltip of defined action"
|
||||||
getDetachedAttributes: function(_attrs)
|
}
|
||||||
{
|
};
|
||||||
_attrs.push("value", "class", "href");
|
return et2_description;
|
||||||
},
|
}(et2_core_baseWidget_1.et2_baseWidget));
|
||||||
|
et2_core_widget_1.et2_register_widget(et2_description, ["description", "label"]);
|
||||||
getDetachedNodes: function()
|
|
||||||
{
|
|
||||||
return [this.span[0]];
|
|
||||||
},
|
|
||||||
|
|
||||||
setDetachedAttributes: function(_nodes, _values, _data)
|
|
||||||
{
|
|
||||||
// Update the properties
|
|
||||||
var updateLink = false;
|
|
||||||
if (typeof _values["href"] != "undefined")
|
|
||||||
{
|
|
||||||
updateLink = true;
|
|
||||||
this.options.href = _values["href"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof _values["value"] != "undefined" || (updateLink && (_values["value"] || this.options.value)))
|
|
||||||
{
|
|
||||||
this.span = jQuery(_nodes[0]);
|
|
||||||
this.set_value(_values["value"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof _values["class"] != "undefined")
|
|
||||||
{
|
|
||||||
_nodes[0].setAttribute("class", _values["class"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add hover action button (Edit), _data is nm's row data
|
|
||||||
if (this.options.hover_action)
|
|
||||||
{
|
|
||||||
this._build_hover_action(_data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds button for hover action
|
|
||||||
* @param {object} _data
|
|
||||||
*/
|
|
||||||
_build_hover_action: function(_data)
|
|
||||||
{
|
|
||||||
var content = _data && _data.content ? _data.content: undefined;
|
|
||||||
var widget = this;
|
|
||||||
this.span.off().on('mouseenter', jQuery.proxy(function(event) {
|
|
||||||
event.stopImmediatePropagation();
|
|
||||||
var self = this;
|
|
||||||
this.span.tooltip({
|
|
||||||
items: 'span.et2_label',
|
|
||||||
position: {my:"right top", at:"left top", collision:"flipfit"},
|
|
||||||
tooltipClass: "et2_email_popup",
|
|
||||||
content: function()
|
|
||||||
{
|
|
||||||
return jQuery('<a href="#" class= "et2_url_email_contactPlus" title="'+egw.lang(widget.options.hover_action_title)+'"><img src="'
|
|
||||||
+egw.image("edit") +'"/></a>')
|
|
||||||
.on('click', function() {
|
|
||||||
widget.options.hover_action.call(self, self.widget, content);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
close: function( event, ui )
|
|
||||||
{
|
|
||||||
ui.tooltip.hover(
|
|
||||||
function () {
|
|
||||||
jQuery(this).stop(true).fadeTo(400, 1);
|
|
||||||
},
|
|
||||||
function () {
|
|
||||||
jQuery(this).fadeOut("400", function(){ jQuery(this).remove();});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.tooltip("open");
|
|
||||||
}, {widget: this, span: this.span}));
|
|
||||||
}
|
|
||||||
}));}).call(this);
|
|
||||||
et2_register_widget(et2_description, ["description", "label"]);
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
584
api/js/etemplate/et2_widget_tabs.ts
Normal file
584
api/js/etemplate/et2_widget_tabs.ts
Normal file
@ -0,0 +1,584 @@
|
|||||||
|
/**
|
||||||
|
* EGroupware eTemplate2 - JS Tabs object
|
||||||
|
*
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
|
* @package etemplate
|
||||||
|
* @subpackage api
|
||||||
|
* @link http://www.egroupware.org
|
||||||
|
* @author Andreas Stöckel
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*egw:uses
|
||||||
|
jsapi.egw;
|
||||||
|
/vendor/bower-asset/jquery/dist/jquery.js;
|
||||||
|
et2_core_valueWidget;
|
||||||
|
*/
|
||||||
|
|
||||||
|
import './et2_core_common';
|
||||||
|
import { ClassWithAttributes } from "./et2_core_inheritance";
|
||||||
|
import { et2_widget, et2_createWidget, et2_register_widget, WidgetConfig } from "./et2_core_widget";
|
||||||
|
import { et2_DOMWidget } from './et2_core_DOMWidget'
|
||||||
|
import { et2_valueWidget } from './et2_core_valueWidget'
|
||||||
|
import './et2_types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class which implements the tabbox-tag
|
||||||
|
*/
|
||||||
|
class et2_tabbox extends et2_valueWidget implements et2_IInput,et2_IResizeable,et2_IPrint
|
||||||
|
{
|
||||||
|
static readonly _attributes : any = {
|
||||||
|
'tabs': {
|
||||||
|
'name': 'Tabs',
|
||||||
|
'default': et2_no_init,
|
||||||
|
'description': "Array of [extra] tabs. Each tab needs {label:..., template:...}. Additional optional keys are prepend, hidden and id, for access into content array"
|
||||||
|
},
|
||||||
|
'add_tabs': {
|
||||||
|
'name': 'Add tabs',
|
||||||
|
'default': false,
|
||||||
|
'description': 'Set to true if tabs should be added to tabs from read from template, default false if not'
|
||||||
|
},
|
||||||
|
'tab_height': {
|
||||||
|
name: 'Tabs innerHeight',
|
||||||
|
default: '',
|
||||||
|
description: 'Set the innerHeight for the tab content'
|
||||||
|
},
|
||||||
|
'align_tabs': {
|
||||||
|
name: 'Tabs alignment',
|
||||||
|
type: 'string',
|
||||||
|
default: 'h',
|
||||||
|
description: 'Set tabs and their headers arrangment either horizental (h) or vertical (v). Default value is horizental.'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currently selected tab
|
||||||
|
*/
|
||||||
|
selected_index: number|boolean = 0;
|
||||||
|
tabData: any[] = [];
|
||||||
|
container: JQuery;
|
||||||
|
flagContainer: JQuery;
|
||||||
|
tabContainer: JQuery;
|
||||||
|
tab_height: number;
|
||||||
|
value: number | boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
constructor(_parent, _attrs? : WidgetConfig, _child? : object)
|
||||||
|
{
|
||||||
|
// Call the inherited constructor
|
||||||
|
super(_parent, _attrs, ClassWithAttributes.extendAttributes(et2_DOMWidget._attributes, _child || {}));
|
||||||
|
|
||||||
|
// Create the outer tabbox container
|
||||||
|
this.container = jQuery(document.createElement("div"))
|
||||||
|
.addClass("et2_tabbox");
|
||||||
|
|
||||||
|
// Create the upper container for the tab flags
|
||||||
|
this.flagContainer = jQuery(document.createElement("div"))
|
||||||
|
.addClass("et2_tabheader")
|
||||||
|
.appendTo(this.container);
|
||||||
|
|
||||||
|
// Create the lower tab container
|
||||||
|
this.tabContainer = jQuery(document.createElement("div"))
|
||||||
|
.addClass("et2_tabs")
|
||||||
|
.appendTo(this.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy()
|
||||||
|
{
|
||||||
|
super.destroy();
|
||||||
|
|
||||||
|
this.container = null;
|
||||||
|
this.flagContainer = null;
|
||||||
|
this.tabData = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
_readTabs(tabData, tabs)
|
||||||
|
{
|
||||||
|
var selected = "";
|
||||||
|
this.selected_index = false;
|
||||||
|
var hidden = {};
|
||||||
|
if (this.id)
|
||||||
|
{
|
||||||
|
// Set the value for this element
|
||||||
|
var contentMgr = this.getArrayMgr("content");
|
||||||
|
if (contentMgr != null) {
|
||||||
|
var val = contentMgr.getEntry(this.id);
|
||||||
|
if (val !== null)
|
||||||
|
{
|
||||||
|
selected = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contentMgr = this.getArrayMgr("readonlys");
|
||||||
|
if (contentMgr != null) {
|
||||||
|
var val = contentMgr.getEntry(this.id);
|
||||||
|
if (val !== null && typeof val !== 'undefined')
|
||||||
|
{
|
||||||
|
hidden = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var i = 0;
|
||||||
|
et2_filteredNodeIterator(tabs, function(node, nodeName) {
|
||||||
|
if (nodeName == "tab")
|
||||||
|
{
|
||||||
|
var index_name = et2_readAttrWithDefault(node, "id");
|
||||||
|
var hide = false;
|
||||||
|
var widget_options = {};
|
||||||
|
if(index_name) {
|
||||||
|
if(selected == index_name) this.selected_index = i;
|
||||||
|
if(hidden[index_name]) {
|
||||||
|
hide = true;
|
||||||
|
}
|
||||||
|
// Get the class attribute and add it as widget_options
|
||||||
|
var classAttr = et2_readAttrWithDefault(node,"class");
|
||||||
|
if (classAttr)
|
||||||
|
{
|
||||||
|
widget_options = {'class':classAttr};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tabData.push({
|
||||||
|
"id": index_name,
|
||||||
|
"label": this.egw().lang(et2_readAttrWithDefault(node, "label", "Tab")),
|
||||||
|
"widget": null,
|
||||||
|
"widget_options": widget_options,
|
||||||
|
"contentDiv": null,
|
||||||
|
"flagDiv": null,
|
||||||
|
"hidden": hide,
|
||||||
|
"XMLNode": null,
|
||||||
|
"promise": null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw("Error while parsing: Invalid tag '" + nodeName +
|
||||||
|
"' in tabs tag");
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Make sure we don't try to display a hidden tab
|
||||||
|
for(var i = 0; i < tabData.length && this.selected_index === false; i++)
|
||||||
|
{
|
||||||
|
if(!tabData[i].hidden) this.selected_index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_readTabPanels(tabData, tabpanels)
|
||||||
|
{
|
||||||
|
var i = 0;
|
||||||
|
et2_filteredNodeIterator(tabpanels, function(node, nodeName) {
|
||||||
|
if (i < tabData.length)
|
||||||
|
{
|
||||||
|
// Store node for later evaluation
|
||||||
|
tabData[i].XMLNode = node;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw("Error while reading tabpanels tag, too many widgets!");
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadFromXML(_node)
|
||||||
|
{
|
||||||
|
// Get the tabs and tabpanels tags
|
||||||
|
var tabsElems = et2_directChildrenByTagName(_node, "tabs");
|
||||||
|
var tabpanelsElems = et2_directChildrenByTagName(_node, "tabpanels");
|
||||||
|
var tabData = [];
|
||||||
|
|
||||||
|
// Check for a parent height, we'll apply it to tab panels
|
||||||
|
var height = et2_readAttrWithDefault(_node.parentNode, "height",null);
|
||||||
|
if(height)
|
||||||
|
{
|
||||||
|
this.tabContainer.css("height", height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if no tabs set or they should be added to tabs from xml
|
||||||
|
if (!this.options.tabs || this.options.add_tabs)
|
||||||
|
{
|
||||||
|
if (tabsElems.length == 1 && tabpanelsElems.length == 1)
|
||||||
|
{
|
||||||
|
var tabs = tabsElems[0];
|
||||||
|
var tabpanels = tabpanelsElems[0];
|
||||||
|
|
||||||
|
// Parse the "tabs" tag
|
||||||
|
this._readTabs(tabData, tabs);
|
||||||
|
|
||||||
|
// Read and create the widgets defined in the "tabpanels"
|
||||||
|
this._readTabPanels(tabData, tabpanels);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.egw().debug("error","Error while parsing tabbox, none or multiple tabs or tabpanels tags!",this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.options.tabs)
|
||||||
|
{
|
||||||
|
var readonly = this.getArrayMgr("readonlys").getEntry(this.id) || {};
|
||||||
|
for(var i = 0; i < this.options.tabs.length; i++)
|
||||||
|
{
|
||||||
|
var tab = this.options.tabs[i];
|
||||||
|
var tab_id = tab.id || tab.template;
|
||||||
|
var tab_options = {id: tab_id, template:tab.template, url: tab.url, content: undefined};
|
||||||
|
if(tab.id)
|
||||||
|
{
|
||||||
|
tab_options.content = tab.id;
|
||||||
|
}
|
||||||
|
tabData[tab.prepend ? 'unshift' : 'push'].call(tabData, {
|
||||||
|
"id": tab_id,
|
||||||
|
"label": this.egw().lang(tab.label),
|
||||||
|
"widget": null,
|
||||||
|
"widget_options": tab_options,
|
||||||
|
"contentDiv": null,
|
||||||
|
"flagDiv": null,
|
||||||
|
"hidden": typeof tab.hidden != "undefined" ? tab.hidden : readonly[tab_id] || false,
|
||||||
|
"XMLNode": null,
|
||||||
|
"promise": null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the tab DOM-Nodes
|
||||||
|
this.createTabs(tabData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load is finished, set up tabs to load on their own
|
||||||
|
*/
|
||||||
|
doLoadingFinished()
|
||||||
|
{
|
||||||
|
var tab_deferred = jQuery.Deferred();
|
||||||
|
var promises = [];
|
||||||
|
var tabs = this;
|
||||||
|
|
||||||
|
// Specially process the selected index so it shows up right away
|
||||||
|
this._loadTab(this.selected_index,promises);
|
||||||
|
|
||||||
|
// Apply parent now, which actually puts into the DOM
|
||||||
|
// This has to be before loading the child, so the dom sub-tree is not
|
||||||
|
// disconnected, which causes problems for things like CKEditor
|
||||||
|
super.doLoadingFinished();
|
||||||
|
|
||||||
|
// We can do this and not wind up with 2 because child is a template,
|
||||||
|
// which has special handling
|
||||||
|
this._children[0].loadingFinished(promises);
|
||||||
|
|
||||||
|
// Defer parsing & loading of other tabs until later
|
||||||
|
window.setTimeout(function() {
|
||||||
|
for (var i = 0; i < tabs.tabData.length; i++)
|
||||||
|
{
|
||||||
|
if (i == tabs.selected_index) continue;
|
||||||
|
tabs._loadTab(i,promises);
|
||||||
|
}
|
||||||
|
jQuery.when.apply(jQuery,promises).then(function() {
|
||||||
|
tab_deferred.resolve();
|
||||||
|
});
|
||||||
|
},0);
|
||||||
|
|
||||||
|
return tab_deferred.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load & render a tab's content
|
||||||
|
*
|
||||||
|
* @param {number} index numerical index of tab in this.tabData array
|
||||||
|
* @param {array} promises
|
||||||
|
*/
|
||||||
|
_loadTab(index,promises)
|
||||||
|
{
|
||||||
|
var tabData = this.tabData[index];
|
||||||
|
if(!tabData || tabData.loaded) return;
|
||||||
|
if(tabData.XMLNode != null)
|
||||||
|
{
|
||||||
|
if(tabData.hidden)
|
||||||
|
{
|
||||||
|
// Set hidden tab to readonly, so widgets aren't active
|
||||||
|
// Do not modify the XMLNode, or the change will be cached for all
|
||||||
|
tabData.XMLNode = tabData.XMLNode.cloneNode();
|
||||||
|
tabData.XMLNode.setAttribute('readonly', true);
|
||||||
|
}
|
||||||
|
tabData.widget = this.createElementFromNode(tabData.XMLNode,
|
||||||
|
tabData.XMLNode.nodeName.toLowerCase());
|
||||||
|
|
||||||
|
// Release the XML node
|
||||||
|
tabData.XMLNode = null;
|
||||||
|
}
|
||||||
|
else if (tabData.widget_options)
|
||||||
|
{
|
||||||
|
tabData.widget = et2_createWidget('template',tabData.widget_options,this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set loaded flag to not do this again, even if not fully done
|
||||||
|
tabData.loaded = true;
|
||||||
|
|
||||||
|
// loadingFinished() will be called either when the promise from doLoadingFinished is resolved,
|
||||||
|
// or during the normal execution
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for custom tabs
|
||||||
|
*
|
||||||
|
* @param {object} _attrs
|
||||||
|
*/
|
||||||
|
transformAttributes(_attrs)
|
||||||
|
{
|
||||||
|
super.transformAttributes(_attrs);
|
||||||
|
|
||||||
|
// Add in settings that are objects
|
||||||
|
var data = this.getArrayMgr("modifications").getEntry(this.id);
|
||||||
|
for(var key in data)
|
||||||
|
{
|
||||||
|
if(typeof data[key] === 'object' && ! _attrs[key]) _attrs[key] = data[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createTabs(tabData)
|
||||||
|
{
|
||||||
|
this.tabData = tabData;
|
||||||
|
|
||||||
|
this.tabContainer.empty();
|
||||||
|
this.flagContainer.empty();
|
||||||
|
|
||||||
|
for (var i = 0; i < this.tabData.length; i++)
|
||||||
|
{
|
||||||
|
var entry = this.tabData[i];
|
||||||
|
entry.flagDiv = jQuery(document.createElement("span"))
|
||||||
|
.addClass("et2_tabflag")
|
||||||
|
.appendTo(this.flagContainer);
|
||||||
|
// Class to tab's div container
|
||||||
|
if (entry.widget_options && typeof entry.widget_options.class != 'undefined')
|
||||||
|
{
|
||||||
|
entry.flagDiv.addClass(entry.widget_options.class);
|
||||||
|
}
|
||||||
|
entry.flagDiv.text(entry.label || "Tab");
|
||||||
|
if(entry.hidden || this.tabData.length === 1)
|
||||||
|
{
|
||||||
|
entry.flagDiv.hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entry.flagDiv.click({"tabs": this, "idx": i}, function(e) {
|
||||||
|
e.data.tabs.setActiveTab(e.data.idx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
entry.contentDiv = jQuery(document.createElement("div"))
|
||||||
|
.addClass("et2_tabcntr")
|
||||||
|
.appendTo(this.tabContainer);
|
||||||
|
if (this.options.align_tabs == 'v') {
|
||||||
|
entry.flagDiv.unbind('click');
|
||||||
|
entry.flagDiv.text("");
|
||||||
|
jQuery(document.createElement('div'))
|
||||||
|
.addClass('et2_tabtitle')
|
||||||
|
.text(entry.label || "Tab")
|
||||||
|
.click({"tabs": this, "idx": i}, function(e) {
|
||||||
|
e.data.tabs.flagContainer.children(":eq(" + e.data.idx + ")").toggleClass('active');
|
||||||
|
if (e.data.tabs.selected_index != e.data.idx) e.data.tabs.setActiveTab(e.data.idx);
|
||||||
|
})
|
||||||
|
.appendTo(entry.flagDiv);
|
||||||
|
entry.contentDiv.appendTo(entry.flagDiv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.align_tabs == 'v'){
|
||||||
|
|
||||||
|
this.container.addClass('vertical');
|
||||||
|
this.tabContainer.hide();
|
||||||
|
}
|
||||||
|
// Check for a passed in value
|
||||||
|
if(this.options.value)
|
||||||
|
{
|
||||||
|
this.selected_index = 0;
|
||||||
|
for(var i = 0; i < this.tabData.length; i++)
|
||||||
|
{
|
||||||
|
if(this.tabData[i].id == this.options.value)
|
||||||
|
{
|
||||||
|
this.selected_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setActiveTab(this.selected_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the index of the currently active tab
|
||||||
|
*
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
get_active_tab()
|
||||||
|
{
|
||||||
|
return this.selected_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the currently active tab by index
|
||||||
|
*
|
||||||
|
* @param {number} _idx
|
||||||
|
*/
|
||||||
|
setActiveTab(_idx)
|
||||||
|
{
|
||||||
|
this.selected_index = _idx;
|
||||||
|
|
||||||
|
// Remove the "active" flag from all tabs-flags
|
||||||
|
jQuery(".et2_tabflag", this.flagContainer).removeClass("active");
|
||||||
|
|
||||||
|
// Hide all tab containers
|
||||||
|
this.tabContainer.children().hide();
|
||||||
|
|
||||||
|
// Set the tab flag with the given index active and show the corresponding
|
||||||
|
// container
|
||||||
|
this.flagContainer.children(":eq(" + _idx + ")").addClass("active");
|
||||||
|
this.tabContainer.children(":eq(" + _idx + ")").show();
|
||||||
|
|
||||||
|
// lookup for nm children and trigger a resize, since nm inside inactive
|
||||||
|
// tabs are not getting render due to tab's deffer loading.
|
||||||
|
if (this._children.length > 0 && this.tabData && this.tabData.length > 0) {
|
||||||
|
this.tabData[_idx]['widget'].iterateOver(function(nm){
|
||||||
|
if (nm && nm._type == 'nextmatch') nm.resize();
|
||||||
|
}, this.tabData[_idx]['widget'], et2_nextmatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activate the tab containing the given widget
|
||||||
|
*
|
||||||
|
* @param {et2_widget} widget
|
||||||
|
* @return {bool} widget was found in a tab
|
||||||
|
*/
|
||||||
|
activateTab(widget)
|
||||||
|
{
|
||||||
|
var tab = widget;
|
||||||
|
while(tab._parent && tab._parent._type !='tabbox')
|
||||||
|
{
|
||||||
|
tab = tab._parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
var child_index = this._children.indexOf(tab);
|
||||||
|
for(var i = 0; i < this.tabData.length; i++)
|
||||||
|
{
|
||||||
|
if(this.tabData[i].widget == tab)
|
||||||
|
{
|
||||||
|
this.setActiveTab(i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDOMNode(_sender)
|
||||||
|
{
|
||||||
|
if (_sender === this || typeof _sender === 'undefined')
|
||||||
|
{
|
||||||
|
return this.container[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (var i = 0; i < this.tabData.length; i++)
|
||||||
|
{
|
||||||
|
if (this.tabData[i].widget == _sender)
|
||||||
|
{
|
||||||
|
return this.tabData[i].contentDiv[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set_tab_height(_height)
|
||||||
|
{
|
||||||
|
this.tab_height = _height;
|
||||||
|
this.tabContainer.css("height", _height);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_height(_value)
|
||||||
|
{
|
||||||
|
this.height = _value;
|
||||||
|
|
||||||
|
this.tabContainer.css("height", _value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getValue has to return the value of the input widget
|
||||||
|
*/
|
||||||
|
getValue()
|
||||||
|
{
|
||||||
|
return this.selected_index !== false ? this.tabData[<number>this.selected_index].id : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is dirty returns true if the value of the widget has changed since it
|
||||||
|
* was loaded.
|
||||||
|
*/
|
||||||
|
isDirty()
|
||||||
|
{
|
||||||
|
return this.selected_index != this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Causes the dirty flag to be reseted.
|
||||||
|
*/
|
||||||
|
resetDirty()
|
||||||
|
{
|
||||||
|
this.value = this.selected_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
isValid(messages)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
resize(_height)
|
||||||
|
{
|
||||||
|
if(_height)
|
||||||
|
{
|
||||||
|
this.set_height(this.tabContainer.height() + _height);
|
||||||
|
}
|
||||||
|
//Set the height of tabs with the heighest height
|
||||||
|
else if(_height === 0)
|
||||||
|
{
|
||||||
|
this.set_height(this.tabContainer.height());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up for printing
|
||||||
|
*
|
||||||
|
* @return {undefined|Deferred} Return a jQuery Deferred object if not done setting up
|
||||||
|
* (waiting for data)
|
||||||
|
*/
|
||||||
|
beforePrint()
|
||||||
|
{
|
||||||
|
// Remove the "active" flag from all tabs-flags
|
||||||
|
jQuery(".et2_tabflag", this.flagContainer).removeClass("active");
|
||||||
|
|
||||||
|
// Remove height limit
|
||||||
|
this.tabContainer.css("height", '');
|
||||||
|
|
||||||
|
// Show all enabled tabs
|
||||||
|
for (var i = 0; i < this.tabData.length; i++)
|
||||||
|
{
|
||||||
|
var entry = this.tabData[i];
|
||||||
|
if(entry.hidden) continue;
|
||||||
|
entry.flagDiv.insertBefore(entry.contentDiv);
|
||||||
|
entry.contentDiv.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset after printing
|
||||||
|
*/
|
||||||
|
afterPrint()
|
||||||
|
{
|
||||||
|
for (var i = 0; i < this.tabData.length; i++)
|
||||||
|
{
|
||||||
|
var entry = this.tabData[i];
|
||||||
|
entry.flagDiv.appendTo(this.flagContainer);
|
||||||
|
}
|
||||||
|
this.setActiveTab(this.get_active_tab());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
et2_register_widget(et2_tabbox, ["tabbox"]);
|
Loading…
Reference in New Issue
Block a user