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-15 16:29:58 +02:00
|
|
|
et2_inputWidget;
|
2011-08-10 16:36:31 +02:00
|
|
|
et2_baseWidget;
|
2011-08-07 15:43:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "button" XET-Tag
|
|
|
|
*/
|
2011-08-15 16:29:58 +02:00
|
|
|
var et2_button = et2_baseWidget.extend(et2_IInput, {
|
2011-08-10 16:36:31 +02:00
|
|
|
|
|
|
|
attributes: {
|
|
|
|
"label": {
|
|
|
|
"name": "caption",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Label of the button"
|
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
|
|
|
|
|
|
|
init: function(_parent) {
|
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-10 16:36:31 +02:00
|
|
|
|
2011-08-07 15:43:46 +02:00
|
|
|
this.btn = $j(document.createElement("button"))
|
2011-08-15 11:24:32 +02:00
|
|
|
.addClass("et2_button")
|
|
|
|
.click(this, function(e) {e.data.buttonClick()});
|
2011-08-07 15:43:46 +02:00
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
this.setDOMNode(this.btn[0]);
|
2011-08-07 15:43:46 +02:00
|
|
|
},
|
|
|
|
|
2011-08-15 11:24:32 +02:00
|
|
|
buttonClick: function() {
|
|
|
|
// Execute the JS code connected to the event handler
|
|
|
|
if (this.onclick != null)
|
|
|
|
{
|
|
|
|
if (!this.onclick())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-15 16:29:58 +02:00
|
|
|
// Submit the form
|
|
|
|
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) {
|
|
|
|
if (_value != this.value)
|
|
|
|
{
|
|
|
|
this.label = _value;
|
|
|
|
|
|
|
|
this.btn.text(_value);
|
|
|
|
}
|
2011-08-15 16:29:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
isDirty: function() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
resetDirty: function() {
|
|
|
|
},
|
|
|
|
|
|
|
|
getValue: function() {
|
|
|
|
if (this.clicked)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return null;
|
2011-08-07 15:43:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
et2_register_widget(et2_button, ["button"]);
|
|
|
|
|