mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-05 23:05:59 +02:00
Implemented et2_IInput interface for et2_button in order to transfer the id of the clicked button back to the server, implemented etemplate2.submit function, implemented egw_json et2_load response type to load a new template with new data.
This commit is contained in:
@ -103,7 +103,7 @@ class etemplate_new
|
|||||||
echo '
|
echo '
|
||||||
<div id="container"></div>
|
<div id="container"></div>
|
||||||
<script>
|
<script>
|
||||||
var et2 = new etemplate2(document.getElementById("container"), "");
|
var et2 = new etemplate2(document.getElementById("container"), "etemplate_new::ajax_process_content");
|
||||||
et2.load("'.$GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path.'",'.json_encode(array(
|
et2.load("'.$GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path.'",'.json_encode(array(
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'sel_options' => $sel_options,
|
'sel_options' => $sel_options,
|
||||||
@ -117,6 +117,25 @@ class etemplate_new
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process via Ajax submitted content
|
||||||
|
*/
|
||||||
|
static public function ajax_process_content(array $content)
|
||||||
|
{
|
||||||
|
error_log(__METHOD__."(".print_r($content, true).")");
|
||||||
|
|
||||||
|
$response = egw_json_response::get();
|
||||||
|
$response->generic("et2_load", array(
|
||||||
|
"url" => $GLOBALS['egw_info']['server']['webserver_url']."/etemplate/js/test/et2_test_expressions.xet",
|
||||||
|
"data" => array(
|
||||||
|
"content" => array(
|
||||||
|
"display_text" => "",
|
||||||
|
"textbox" => "Hello world!"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path of template relative to EGW_SERVER_ROOT
|
* Path of template relative to EGW_SERVER_ROOT
|
||||||
*
|
*
|
||||||
|
@ -14,13 +14,14 @@
|
|||||||
|
|
||||||
/*egw:uses
|
/*egw:uses
|
||||||
jquery.jquery;
|
jquery.jquery;
|
||||||
|
et2_inputWidget;
|
||||||
et2_baseWidget;
|
et2_baseWidget;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class which implements the "button" XET-Tag
|
* Class which implements the "button" XET-Tag
|
||||||
*/
|
*/
|
||||||
var et2_button = et2_baseWidget.extend({
|
var et2_button = et2_baseWidget.extend(et2_IInput, {
|
||||||
|
|
||||||
attributes: {
|
attributes: {
|
||||||
"label": {
|
"label": {
|
||||||
@ -40,6 +41,7 @@ var et2_button = et2_baseWidget.extend({
|
|||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
|
|
||||||
this.label = "";
|
this.label = "";
|
||||||
|
this.clicked = false;
|
||||||
|
|
||||||
this.btn = $j(document.createElement("button"))
|
this.btn = $j(document.createElement("button"))
|
||||||
.addClass("et2_button")
|
.addClass("et2_button")
|
||||||
@ -56,11 +58,10 @@ var et2_button = et2_baseWidget.extend({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the form data
|
// Submit the form
|
||||||
var formData = this.getRoot().getValues();
|
this.clicked = true;
|
||||||
|
this.getInstanceManager().submit();
|
||||||
// Submit it!
|
this.clicked = false;
|
||||||
console.log(formData);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
set_label: function(_value) {
|
set_label: function(_value) {
|
||||||
@ -70,6 +71,21 @@ var et2_button = et2_baseWidget.extend({
|
|||||||
|
|
||||||
this.btn.text(_value);
|
this.btn.text(_value);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
isDirty: function() {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
resetDirty: function() {
|
||||||
|
},
|
||||||
|
|
||||||
|
getValue: function() {
|
||||||
|
if (this.clicked)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -101,6 +101,7 @@ var et2_widget = Class.extend({
|
|||||||
|
|
||||||
this.id = "";
|
this.id = "";
|
||||||
this._mgrs = {};
|
this._mgrs = {};
|
||||||
|
this._inst = null;
|
||||||
|
|
||||||
// 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.
|
||||||
@ -506,7 +507,7 @@ var et2_widget = Class.extend({
|
|||||||
this.iterateOver(function(_widget) {
|
this.iterateOver(function(_widget) {
|
||||||
|
|
||||||
// Get the path to the node we have to store the value at
|
// Get the path to the node we have to store the value at
|
||||||
var path = _widget.getContentMgr().getPath();
|
var path = _widget.getArrayMgr("content").getPath();
|
||||||
|
|
||||||
// Set the _target variable to that node
|
// Set the _target variable to that node
|
||||||
var _target = result;
|
var _target = result;
|
||||||
@ -537,8 +538,12 @@ var et2_widget = Class.extend({
|
|||||||
"', id exists twice!");
|
"', id exists twice!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the value of the widget and reset its dirty flag,
|
// Store the value of the widget and reset its dirty flag
|
||||||
_target[_widget.id] = _widget.getValue();
|
var value = _widget.getValue();
|
||||||
|
if (value !== null)
|
||||||
|
{
|
||||||
|
_target[_widget.id] = value;
|
||||||
|
}
|
||||||
_widget.resetDirty();
|
_widget.resetDirty();
|
||||||
|
|
||||||
}, this, et2_IInput);
|
}, this, et2_IInput);
|
||||||
@ -641,6 +646,29 @@ var et2_widget = Class.extend({
|
|||||||
delete(this._mgrs[key]);
|
delete(this._mgrs[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the instance manager object (of type etemplate2, see etemplate2.js)
|
||||||
|
*/
|
||||||
|
setInstanceManager: function(_inst) {
|
||||||
|
this._inst = _inst;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the instance manager
|
||||||
|
*/
|
||||||
|
getInstanceManager: function() {
|
||||||
|
if (this._inst != null)
|
||||||
|
{
|
||||||
|
return this._inst;
|
||||||
|
}
|
||||||
|
else if (this._parent)
|
||||||
|
{
|
||||||
|
return this._parent.getInstanceManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -31,11 +31,16 @@
|
|||||||
* should be inserted
|
* should be inserted
|
||||||
* @param _submitURL is the URL to which the form data should be submitted.
|
* @param _submitURL is the URL to which the form data should be submitted.
|
||||||
*/
|
*/
|
||||||
function etemplate2(_container, _submitURL)
|
function etemplate2(_container, _menuaction)
|
||||||
{
|
{
|
||||||
|
if (typeof _menuaction == "undefined")
|
||||||
|
{
|
||||||
|
_menuaction = "etemplate_new::ajax_process_content";
|
||||||
|
}
|
||||||
|
|
||||||
// Copy the given parameters
|
// Copy the given parameters
|
||||||
this.DOMContainer = _container;
|
this.DOMContainer = _container;
|
||||||
this.submitURL = _submitURL;
|
this.menuaction = _menuaction;
|
||||||
|
|
||||||
// Preset the object variable
|
// Preset the object variable
|
||||||
this.widgetContainer = null;
|
this.widgetContainer = null;
|
||||||
@ -103,6 +108,7 @@ etemplate2.prototype.load = function(_url, _data)
|
|||||||
|
|
||||||
// Create the basic widget container and attach it to the DOM
|
// Create the basic widget container and attach it to the DOM
|
||||||
this.widgetContainer = new et2_container(null);
|
this.widgetContainer = new et2_container(null);
|
||||||
|
this.widgetContainer.setInstanceManager(this);
|
||||||
this.widgetContainer.setParentDOMNode(this.DOMContainer);
|
this.widgetContainer.setParentDOMNode(this.DOMContainer);
|
||||||
|
|
||||||
// Split the given data into array manager objects and pass those to the
|
// Split the given data into array manager objects and pass those to the
|
||||||
@ -110,4 +116,53 @@ etemplate2.prototype.load = function(_url, _data)
|
|||||||
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
|
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
etemplate2.prototype.submit = function()
|
||||||
|
{
|
||||||
|
// Get the form values
|
||||||
|
var values = this.widgetContainer.getValues();
|
||||||
|
|
||||||
|
// Create the request object
|
||||||
|
if (typeof egw_json_request != "undefined")
|
||||||
|
{
|
||||||
|
var request = new egw_json_request(this.menuaction, [values], this);
|
||||||
|
request.sendRequest(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
console.log(values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function which handles the EGW JSON et2_load response
|
||||||
|
*/
|
||||||
|
function etemplate2_handle_response(_type, _response)
|
||||||
|
{
|
||||||
|
if (_type == "et2_load")
|
||||||
|
{
|
||||||
|
// Check the parameters
|
||||||
|
var data = _response.data;
|
||||||
|
if (typeof data.url == "string" && data.data instanceof Object)
|
||||||
|
{
|
||||||
|
this.load(data.url, data.data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw("Error while parsing et2_load response");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the egw_json result object
|
||||||
|
if (typeof egw_json_register_plugin != "undefined")
|
||||||
|
{
|
||||||
|
// Calls etemplate2_handle_response in the context of the object which
|
||||||
|
// requested the response from the server
|
||||||
|
egw_json_register_plugin(etemplate2_handle_response, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
et2_debug("info", "EGW JSON Plugin could not be registered, running ET2 standalone.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user