2011-08-07 15:43:46 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate2 - JS Button 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
|
|
|
|
* @copyright Stylite 2011
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
jquery.jquery;
|
2011-08-25 15:35:53 +02:00
|
|
|
et2_core_interfaces;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_core_baseWidget;
|
2011-08-07 15:43:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "button" XET-Tag
|
|
|
|
*/
|
2011-09-14 20:37:38 +02:00
|
|
|
var et2_button = et2_baseWidget.extend([et2_IInput, et2_IDetachedDOM], {
|
2011-08-10 16:36:31 +02:00
|
|
|
|
|
|
|
attributes: {
|
|
|
|
"label": {
|
|
|
|
"name": "caption",
|
|
|
|
"type": "string",
|
2011-08-23 19:05:05 +02:00
|
|
|
"description": "Label of the button",
|
|
|
|
"translate": true
|
2011-08-15 11:24:32 +02:00
|
|
|
},
|
2011-09-14 20:37:38 +02:00
|
|
|
"image": {
|
|
|
|
"name": "Icon",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Use an icon instead of label (when available)"
|
|
|
|
},
|
2011-08-15 11:24:32 +02:00
|
|
|
"onclick": {
|
|
|
|
"name": "onclick",
|
|
|
|
"type": "js",
|
|
|
|
"description": "JS code which gets executed when the button is clicked"
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
},
|
2011-08-07 15:43:46 +02:00
|
|
|
|
2011-08-23 17:05:13 +02:00
|
|
|
init: function() {
|
2011-08-10 16:36:31 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.label = "";
|
2011-08-15 16:29:58 +02:00
|
|
|
this.clicked = false;
|
2011-08-16 14:31:18 +02:00
|
|
|
this.btn = null;
|
2011-08-10 16:36:31 +02:00
|
|
|
|
2011-08-23 17:05:13 +02:00
|
|
|
if (!this.options.readonly)
|
2011-08-16 14:31:18 +02:00
|
|
|
{
|
|
|
|
this.btn = $j(document.createElement("button"))
|
2011-08-22 16:38:05 +02:00
|
|
|
.addClass("et2_button");
|
2011-08-16 14:31:18 +02:00
|
|
|
this.setDOMNode(this.btn[0]);
|
|
|
|
}
|
2011-08-07 15:43:46 +02:00
|
|
|
},
|
|
|
|
|
2011-09-14 20:37:38 +02:00
|
|
|
set_image: function(_image) {
|
|
|
|
if(!this.isInTree()) return;
|
|
|
|
this.options.image = _image;
|
|
|
|
|
|
|
|
var found_image = false;
|
|
|
|
if(this.options.image != "")
|
|
|
|
{
|
|
|
|
if(!this.image)
|
|
|
|
{
|
|
|
|
this.image = et2_createWidget("image",{label: this.options.label});
|
|
|
|
}
|
|
|
|
found_image = this.image.set_src(this.options.image);
|
|
|
|
jQuery(this.image.getDOMNode()).appendTo(this.btn);
|
|
|
|
}
|
|
|
|
if(found_image)
|
|
|
|
{
|
|
|
|
// No label if there's an image
|
|
|
|
this.options.label = "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getDOMNode: function() {
|
2011-09-14 22:36:39 +02:00
|
|
|
return this.btn ? this.btn[0] : null;
|
2011-09-14 20:37:38 +02:00
|
|
|
},
|
|
|
|
|
2011-09-21 23:07:21 +02:00
|
|
|
onclick: function(e) {
|
2011-08-15 11:24:32 +02:00
|
|
|
// Execute the JS code connected to the event handler
|
2011-08-31 02:03:50 +02:00
|
|
|
if (this.options.onclick)
|
2011-08-15 11:24:32 +02:00
|
|
|
{
|
2011-08-31 02:03:50 +02:00
|
|
|
if (!this.options.onclick())
|
2011-08-15 11:24:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-15 16:29:58 +02:00
|
|
|
// Submit the form
|
2011-08-21 15:24:20 +02:00
|
|
|
if (this._type != "buttononly")
|
|
|
|
{
|
|
|
|
this.clicked = true;
|
|
|
|
this.getInstanceManager().submit();
|
|
|
|
this.clicked = false;
|
|
|
|
}
|
2011-08-15 11:24:32 +02:00
|
|
|
},
|
|
|
|
|
2011-08-07 15:43:46 +02:00
|
|
|
set_label: function(_value) {
|
2011-08-16 14:31:18 +02:00
|
|
|
if (this.btn)
|
2011-08-07 15:43:46 +02:00
|
|
|
{
|
|
|
|
this.label = _value;
|
|
|
|
|
|
|
|
this.btn.text(_value);
|
|
|
|
}
|
2011-08-15 16:29:58 +02:00
|
|
|
},
|
|
|
|
|
2011-08-15 18:03:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the et2_IInput interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Always return false as a button is never dirty
|
|
|
|
*/
|
2011-08-15 16:29:58 +02:00
|
|
|
isDirty: function() {
|
2011-08-15 18:03:53 +02:00
|
|
|
return false;
|
2011-08-15 16:29:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
resetDirty: function() {
|
|
|
|
},
|
|
|
|
|
|
|
|
getValue: function() {
|
|
|
|
if (this.clicked)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-15 18:03:53 +02:00
|
|
|
|
|
|
|
// If "null" is returned, the result is not added to the submitted
|
|
|
|
// array.
|
2011-08-15 16:29:58 +02:00
|
|
|
return null;
|
2011-09-14 20:37:38 +02:00
|
|
|
},
|
2011-08-07 15:43:46 +02:00
|
|
|
|
2011-09-14 20:37:38 +02:00
|
|
|
/**
|
|
|
|
* et2_IDetachedDOM
|
|
|
|
*/
|
|
|
|
getDetachedAttributes: function(_attrs)
|
|
|
|
{
|
2011-09-21 23:07:21 +02:00
|
|
|
_attrs.push("value", "class", "image", "onclick");
|
2011-09-14 20:37:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getDetachedNodes: function()
|
|
|
|
{
|
|
|
|
return [this.getDOMNode(),this.image];
|
|
|
|
},
|
|
|
|
|
|
|
|
setDetachedAttributes: function(_nodes, _values)
|
|
|
|
{
|
2011-09-21 23:07:21 +02:00
|
|
|
this.btn = jQuery(_nodes[0]);
|
|
|
|
|
|
|
|
|
2011-09-14 20:37:38 +02:00
|
|
|
this.image = _nodes[1];
|
|
|
|
|
|
|
|
if (typeof _values["id"] != "undefined")
|
|
|
|
{
|
|
|
|
this.set_id(_values["id"]);
|
|
|
|
}
|
|
|
|
if (typeof _values["value"] != "undefined")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof _values["class"] != "undefined")
|
|
|
|
{
|
|
|
|
this.set_class(_values["class"]);
|
|
|
|
}
|
2011-09-21 23:07:21 +02:00
|
|
|
|
|
|
|
if (typeof _values["onclick"] == "string")
|
|
|
|
{
|
|
|
|
_values["onclick"] = new Function(_values["onclick"]);
|
|
|
|
}
|
|
|
|
if (typeof _values["onclick"] == "function")
|
|
|
|
{
|
|
|
|
this.options.onclick = _values["onclick"];
|
|
|
|
this.btn.bind("click.et2_baseWidget", this, function(e) {
|
|
|
|
return e.data.click.call(e.data,e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-09-14 20:37:38 +02:00
|
|
|
}
|
2011-08-07 15:43:46 +02:00
|
|
|
});
|
|
|
|
|
2011-08-21 15:24:20 +02:00
|
|
|
et2_register_widget(et2_button, ["button", "buttononly"]);
|
2011-08-07 15:43:46 +02:00
|
|
|
|