mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-26 21:01:30 +02:00
Fixed problem with id not being copied when cloning an template rewrote a part of the attribute merging system - now not only references of the attribute descriptors are copied between the instances.
This commit is contained in:
parent
67b05dc93c
commit
4f2eeaafe1
@ -29,7 +29,7 @@ if (typeof Array.prototype.indexOf == "undefined")
|
|||||||
* ET2_DEBUGLEVEL specifies which messages are printed to the console. Decrease
|
* ET2_DEBUGLEVEL specifies which messages are printed to the console. Decrease
|
||||||
* the value of ET2_DEBUGLEVEL to get less messages.
|
* the value of ET2_DEBUGLEVEL to get less messages.
|
||||||
*/
|
*/
|
||||||
var ET2_DEBUGLEVEL = 0;
|
var ET2_DEBUGLEVEL = 4;
|
||||||
|
|
||||||
function et2_debug(_level, _msg)
|
function et2_debug(_level, _msg)
|
||||||
{
|
{
|
||||||
@ -158,6 +158,12 @@ function et2_checkType(_val, _type)
|
|||||||
throw("Invalid type identifier supplied.");
|
throw("Invalid type identifier supplied.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If et2_no_init is set as default value, the initAttributes function will not
|
||||||
|
* try to initialize the attribute with the default value.
|
||||||
|
*/
|
||||||
|
var et2_no_init = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the given attribute with the given id. The validation checks for
|
* Validates the given attribute with the given id. The validation checks for
|
||||||
* the existance of a human name, a description, a type and a default value.
|
* the existance of a human name, a description, a type and a default value.
|
||||||
|
@ -150,31 +150,47 @@
|
|||||||
|
|
||||||
function addAttributeFunctions(prototype, _super)
|
function addAttributeFunctions(prototype, _super)
|
||||||
{
|
{
|
||||||
var attributes = prototype.attributes;
|
function _copyMerge(_new, _old)
|
||||||
|
{
|
||||||
|
var result = {};
|
||||||
|
|
||||||
|
// Copy the new object
|
||||||
|
if (typeof _new != "undefined")
|
||||||
|
{
|
||||||
|
for (var key in _new)
|
||||||
|
{
|
||||||
|
result[key] = _new[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge the old object
|
||||||
|
for (var key in _old)
|
||||||
|
{
|
||||||
|
if (typeof result[key] == "undefined")
|
||||||
|
{
|
||||||
|
result[key] = _old[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
var attributes = {};
|
||||||
|
|
||||||
|
// Copy the old attributes
|
||||||
|
for (var key in prototype.attributes)
|
||||||
|
{
|
||||||
|
attributes[key] = _copyMerge({}, prototype.attributes[key]);
|
||||||
|
}
|
||||||
|
|
||||||
// Add the old attributes to the new ones. If the attributes already
|
// Add the old attributes to the new ones. If the attributes already
|
||||||
// exist, they are merged.
|
// exist, they are merged.
|
||||||
for (var key in _super.attributes)
|
for (var key in _super.attributes)
|
||||||
{
|
{
|
||||||
var attrib = _super.attributes[key];
|
var _old = _super.attributes[key];
|
||||||
|
var _new = {};
|
||||||
|
|
||||||
if (typeof attributes[key] == "undefined")
|
attributes[key] = _copyMerge(attributes[key], _old);
|
||||||
{
|
|
||||||
// In the case that the old attribute has no equivalent in the
|
|
||||||
// new class, simply create a reference to the old one.
|
|
||||||
attributes[key] = attrib;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Otherwise merge the two attribute descriptors.
|
|
||||||
for (var key2 in attrib)
|
|
||||||
{
|
|
||||||
if (typeof attributes[key][key2] == "undefined")
|
|
||||||
{
|
|
||||||
attributes[key][key2] = attrib[key2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the attributes
|
// Validate the attributes
|
||||||
@ -183,6 +199,8 @@
|
|||||||
et2_validateAttrib(key, attributes[key]);
|
et2_validateAttrib(key, attributes[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prototype.attributes = attributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The initAttributes function sets the attributes to their default
|
* The initAttributes function sets the attributes to their default
|
||||||
* values. The attributes are not overwritten, which means, that the
|
* values. The attributes are not overwritten, which means, that the
|
||||||
@ -192,7 +210,7 @@
|
|||||||
prototype.initAttributes = function() {
|
prototype.initAttributes = function() {
|
||||||
for (var key in this.attributes)
|
for (var key in this.attributes)
|
||||||
{
|
{
|
||||||
if (!this.attributes[key].ignore)
|
if (!this.attributes[key].ignore && this.attributes[key]["default"] !== et2_no_init)
|
||||||
{
|
{
|
||||||
this.setAttribute(key, this.attributes[key]["default"],
|
this.setAttribute(key, this.attributes[key]["default"],
|
||||||
false);
|
false);
|
||||||
|
@ -50,7 +50,7 @@ var et2_inputWidget = et2_baseWidget.extend(et2_IInput, {
|
|||||||
"name": "Value",
|
"name": "Value",
|
||||||
"description": "The value of the widget",
|
"description": "The value of the widget",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": ""
|
"default": et2_no_init
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -115,10 +115,18 @@ var et2_template = et2_DOMWidget.extend({
|
|||||||
// isProxied property to true
|
// isProxied property to true
|
||||||
tmpl.makeProxied();
|
tmpl.makeProxied();
|
||||||
|
|
||||||
|
// Do not copy the id when cloning as this leads to infinit
|
||||||
|
// recursion
|
||||||
|
tmpl.attributes["id"].ignore = true;
|
||||||
|
|
||||||
// Create a clone of the template and add it as child of this
|
// Create a clone of the template and add it as child of this
|
||||||
// template (done by passing "this" to the clone function)
|
// template (done by passing "this" to the clone function)
|
||||||
this.proxiedTemplate = tmpl.clone(this);
|
this.proxiedTemplate = tmpl.clone(this);
|
||||||
|
|
||||||
|
// Reset the "ignore" flag and manually copy the id
|
||||||
|
tmpl.attributes["id"].ignore = false;
|
||||||
|
this.proxiedTemplate.id = tmpl.id;
|
||||||
|
|
||||||
// Disallow adding any new node to this template
|
// Disallow adding any new node to this template
|
||||||
this.supportedWidgetClasses = [];
|
this.supportedWidgetClasses = [];
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ var et2_textbox = et2_inputWidget.extend({
|
|||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
|
|
||||||
this.input = null;
|
this.input = null;
|
||||||
|
this.id = "";
|
||||||
|
|
||||||
this.createInputWidget();
|
this.createInputWidget();
|
||||||
},
|
},
|
||||||
|
@ -58,7 +58,7 @@ var et2_widget = Class.extend({
|
|||||||
"id": {
|
"id": {
|
||||||
"name": "ID",
|
"name": "ID",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Unique identifier of the widget"
|
"description": "Unique identifier of the widget",
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,6 +92,8 @@ var et2_widget = Class.extend({
|
|||||||
_type = "widget";
|
_type = "widget";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.id = "";
|
||||||
|
|
||||||
// Copy the parent parameter and add this widget to its parent children
|
// Copy the parent parameter and add this widget to its parent children
|
||||||
// list.
|
// list.
|
||||||
this._parent = _parent;
|
this._parent = _parent;
|
||||||
@ -161,7 +163,6 @@ var et2_widget = Class.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
assign: function(_obj) {
|
assign: function(_obj) {
|
||||||
|
|
||||||
// Create a clone of all child elements of the given object
|
// Create a clone of all child elements of the given object
|
||||||
for (var i = 0; i < _obj._children.length; i++)
|
for (var i = 0; i < _obj._children.length; i++)
|
||||||
{
|
{
|
||||||
@ -171,7 +172,7 @@ var et2_widget = Class.extend({
|
|||||||
// Copy all properties
|
// Copy all properties
|
||||||
for (var key in _obj.attributes)
|
for (var key in _obj.attributes)
|
||||||
{
|
{
|
||||||
if (!_obj.attributes[key].ignore && key != "id")
|
if (!_obj.attributes[key].ignore)
|
||||||
{
|
{
|
||||||
this.setAttribute(key, _obj.getAttribute(key));
|
this.setAttribute(key, _obj.getAttribute(key));
|
||||||
}
|
}
|
||||||
@ -414,7 +415,7 @@ var et2_widget = Class.extend({
|
|||||||
// corresponding setter function exists. If yes, it is called.
|
// corresponding setter function exists. If yes, it is called.
|
||||||
for (var key in this.attributes)
|
for (var key in this.attributes)
|
||||||
{
|
{
|
||||||
if (!this.attributes[key].ignore && key != "id")
|
if (!this.attributes[key].ignore)
|
||||||
{
|
{
|
||||||
this.setAttribute(key, this.getAttribute(key));
|
this.setAttribute(key, this.getAttribute(key));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user