mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-26 12:51:52 +02:00
Added new attribute type 'js', which cares about converting given JS code to a function
This commit is contained in:
parent
26ce82186c
commit
29c16431ad
@ -27,6 +27,12 @@ var et2_button = et2_baseWidget.extend({
|
|||||||
"name": "caption",
|
"name": "caption",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Label of the button"
|
"description": "Label of the button"
|
||||||
|
},
|
||||||
|
|
||||||
|
"onclick": {
|
||||||
|
"name": "onclick",
|
||||||
|
"type": "js",
|
||||||
|
"description": "JS code which gets executed when the button is clicked"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -36,11 +42,27 @@ var et2_button = et2_baseWidget.extend({
|
|||||||
this.label = "";
|
this.label = "";
|
||||||
|
|
||||||
this.btn = $j(document.createElement("button"))
|
this.btn = $j(document.createElement("button"))
|
||||||
.addClass("et2_button");
|
.addClass("et2_button")
|
||||||
|
.click(this, function(e) {e.data.buttonClick()});
|
||||||
|
|
||||||
this.setDOMNode(this.btn[0]);
|
this.setDOMNode(this.btn[0]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
buttonClick: function() {
|
||||||
|
// Execute the JS code connected to the event handler
|
||||||
|
if (this.onclick != null)
|
||||||
|
{
|
||||||
|
if (!this.onclick())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the form data
|
||||||
|
var formData = this.getRoot().getValues();
|
||||||
|
|
||||||
|
// Submit it!
|
||||||
|
console.log(formData);
|
||||||
|
},
|
||||||
|
|
||||||
set_label: function(_value) {
|
set_label: function(_value) {
|
||||||
if (_value != this.value)
|
if (_value != this.value)
|
||||||
{
|
{
|
||||||
|
@ -64,7 +64,7 @@ function et2_debug(_level, _msg)
|
|||||||
/**
|
/**
|
||||||
* Array with all types supported by the et2_checkType function.
|
* Array with all types supported by the et2_checkType function.
|
||||||
*/
|
*/
|
||||||
var et2_validTypes = ["boolean", "string", "float", "integer", "any"];
|
var et2_validTypes = ["boolean", "string", "float", "integer", "any", "js"];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object whith default values for the above types. Do not specify array or
|
* Object whith default values for the above types. Do not specify array or
|
||||||
@ -74,6 +74,7 @@ var et2_validTypes = ["boolean", "string", "float", "integer", "any"];
|
|||||||
var et2_typeDefaults = {
|
var et2_typeDefaults = {
|
||||||
"boolean": false,
|
"boolean": false,
|
||||||
"string": "",
|
"string": "",
|
||||||
|
"js": null,
|
||||||
"float": 0.0,
|
"float": 0.0,
|
||||||
"integer": 0,
|
"integer": 0,
|
||||||
"any": null
|
"any": null
|
||||||
@ -114,6 +115,29 @@ function et2_checkType(_val, _type)
|
|||||||
_err();
|
_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_type == "js")
|
||||||
|
{
|
||||||
|
// Handle the default case
|
||||||
|
if (_val === null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new function containing the code
|
||||||
|
if (typeof _val == "string")
|
||||||
|
{
|
||||||
|
if (_val !== "")
|
||||||
|
{
|
||||||
|
// TODO: Parse JS code properly
|
||||||
|
return new Function(_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_err();
|
||||||
|
}
|
||||||
|
|
||||||
// Check whether the given value is of the type "string"
|
// Check whether the given value is of the type "string"
|
||||||
if (_type == "string")
|
if (_type == "string")
|
||||||
{
|
{
|
||||||
|
@ -69,5 +69,5 @@ var et2_textbox = et2_inputWidget.extend({
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
et2_register_widget(et2_textbox, ["textbox"]);
|
et2_register_widget(et2_textbox, ["textbox", "int", "float"]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user