mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-04 04:19:41 +01: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:
parent
c999373490
commit
7800cfc5d4
@ -103,7 +103,7 @@ class etemplate_new
|
||||
echo '
|
||||
<div id="container"></div>
|
||||
<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(
|
||||
'content' => $content,
|
||||
'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
|
||||
*
|
||||
|
@ -14,13 +14,14 @@
|
||||
|
||||
/*egw:uses
|
||||
jquery.jquery;
|
||||
et2_inputWidget;
|
||||
et2_baseWidget;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class which implements the "button" XET-Tag
|
||||
*/
|
||||
var et2_button = et2_baseWidget.extend({
|
||||
var et2_button = et2_baseWidget.extend(et2_IInput, {
|
||||
|
||||
attributes: {
|
||||
"label": {
|
||||
@ -40,6 +41,7 @@ var et2_button = et2_baseWidget.extend({
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
this.label = "";
|
||||
this.clicked = false;
|
||||
|
||||
this.btn = $j(document.createElement("button"))
|
||||
.addClass("et2_button")
|
||||
@ -56,11 +58,10 @@ var et2_button = et2_baseWidget.extend({
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fetch the form data
|
||||
var formData = this.getRoot().getValues();
|
||||
|
||||
// Submit it!
|
||||
console.log(formData);
|
||||
// Submit the form
|
||||
this.clicked = true;
|
||||
this.getInstanceManager().submit();
|
||||
this.clicked = false;
|
||||
},
|
||||
|
||||
set_label: function(_value) {
|
||||
@ -70,6 +71,21 @@ var et2_button = et2_baseWidget.extend({
|
||||
|
||||
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._mgrs = {};
|
||||
this._inst = null;
|
||||
|
||||
// Copy the parent parameter and add this widget to its parent children
|
||||
// list.
|
||||
@ -506,7 +507,7 @@ var et2_widget = Class.extend({
|
||||
this.iterateOver(function(_widget) {
|
||||
|
||||
// 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
|
||||
var _target = result;
|
||||
@ -537,8 +538,12 @@ var et2_widget = Class.extend({
|
||||
"', id exists twice!");
|
||||
}
|
||||
|
||||
// Store the value of the widget and reset its dirty flag,
|
||||
_target[_widget.id] = _widget.getValue();
|
||||
// Store the value of the widget and reset its dirty flag
|
||||
var value = _widget.getValue();
|
||||
if (value !== null)
|
||||
{
|
||||
_target[_widget.id] = value;
|
||||
}
|
||||
_widget.resetDirty();
|
||||
|
||||
}, this, et2_IInput);
|
||||
@ -641,6 +646,29 @@ var et2_widget = Class.extend({
|
||||
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
|
||||
* @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
|
||||
this.DOMContainer = _container;
|
||||
this.submitURL = _submitURL;
|
||||
this.menuaction = _menuaction;
|
||||
|
||||
// Preset the object variable
|
||||
this.widgetContainer = null;
|
||||
@ -103,6 +108,7 @@ etemplate2.prototype.load = function(_url, _data)
|
||||
|
||||
// Create the basic widget container and attach it to the DOM
|
||||
this.widgetContainer = new et2_container(null);
|
||||
this.widgetContainer.setInstanceManager(this);
|
||||
this.widgetContainer.setParentDOMNode(this.DOMContainer);
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user