egroupware_official/api/js/etemplate/et2_dataview_view_rowProvider.js

109 lines
3.5 KiB
JavaScript
Raw Normal View History

/**
* EGroupware eTemplate2 - Class which contains a factory method for rows
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage dataview
* @link https://www.egroupware.org
* @author Andreas Stöckel
* @copyright EGroupware GmbH 2011-2021
*/
/*egw:uses
2020-01-31 21:07:27 +01:00
/vendor/bower-asset/jquery/dist/jquery.js;
et2_core_inheritance;
et2_core_interfaces;
et2_core_arrayMgr;
et2_core_widget;
*/
/**
* The row provider contains prototypes (full clonable dom-trees)
* for all registered row types.
*/
export class et2_dataview_rowProvider {
2020-01-31 21:07:27 +01:00
/**
*
* @param _outerId
* @param _columnIds
*/
constructor(_outerId, _columnIds) {
2020-01-31 21:07:27 +01:00
// Copy the given parameters
this._outerId = _outerId;
this._columnIds = _columnIds;
this._prototypes = {};
this._template = null;
this._mgrs = null;
this._rootWidget = null;
// Create the default row "prototypes"
this._createFullRowPrototype();
this._createDefaultPrototype();
this._createEmptyPrototype();
this._createLoadingPrototype();
}
destroy() {
this._template = null;
this._mgrs = null;
this._rootWidget = null;
this._prototypes = {};
this._columnIds = [];
}
getColumnCount() {
2020-01-31 21:07:27 +01:00
return this._columnIds.length;
}
2020-01-31 21:07:27 +01:00
/**
* Returns a clone of the prototype with the given name. If the generator
* callback function is given, this function is called if the prototype
* does not yet registered.
*
* @param {string} _name
* @param {function} _generator
* @param {object} _context
*/
getPrototype(_name, _generator, _context) {
2020-01-31 21:07:27 +01:00
if (typeof this._prototypes[_name] == "undefined") {
if (typeof _generator != "undefined") {
this._prototypes[_name] = _generator.call(_context, this._outerId, this._columnIds);
}
else {
return null;
}
}
return this._prototypes[_name].clone();
}
2020-01-31 21:07:27 +01:00
/* ---- PRIVATE FUNCTIONS ---- */
_createFullRowPrototype() {
2020-01-31 21:07:27 +01:00
var tr = jQuery(document.createElement("tr"));
var td = jQuery(document.createElement("td"))
.addClass(this._outerId + "_td_fullRow")
.attr("colspan", this._columnIds.length)
.appendTo(tr);
var div = jQuery(document.createElement("div"))
.addClass(this._outerId + "_div_fullRow")
.appendTo(td);
this._prototypes["fullRow"] = tr;
}
_createDefaultPrototype() {
var tr = jQuery(document.createElement("tr"));
// Append a td for each column
for (var column of this._columnIds) {
if (!column)
continue;
var td = jQuery(document.createElement("td"))
.addClass(this._outerId + "_td_" + column)
.appendTo(tr);
var div = jQuery(document.createElement("div"))
.addClass(this._outerId + "_div_" + column)
.addClass("innerContainer")
.appendTo(td);
}
this._prototypes["default"] = tr;
}
_createEmptyPrototype() {
2020-01-31 21:07:27 +01:00
this._prototypes["empty"] = jQuery(document.createElement("tr"));
}
_createLoadingPrototype() {
2020-01-31 21:07:27 +01:00
var fullRow = this.getPrototype("fullRow");
jQuery("div", fullRow).addClass("loading");
this._prototypes["loading"] = fullRow;
}
}
2020-01-31 21:07:27 +01:00
//# sourceMappingURL=et2_dataview_view_rowProvider.js.map