From 58bc3367df508bf504e2f03dbd416656deb571ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=B6ckel?= Date: Fri, 9 Sep 2011 11:29:07 +0000 Subject: [PATCH] Implemented server-side callback function --- .../class.etemplate_widget_nextmatch.inc.php | 45 +++++++++++++++++++ etemplate/js/et2_core_interfaces.js | 6 +-- .../js/et2_dataview_model_dataProvider.js | 32 ++++++++----- etemplate/js/et2_extension_nextmatch.js | 22 ++++----- 4 files changed, 77 insertions(+), 28 deletions(-) create mode 100644 etemplate/inc/class.etemplate_widget_nextmatch.inc.php diff --git a/etemplate/inc/class.etemplate_widget_nextmatch.inc.php b/etemplate/inc/class.etemplate_widget_nextmatch.inc.php new file mode 100644 index 0000000000..3b3a83f539 --- /dev/null +++ b/etemplate/inc/class.etemplate_widget_nextmatch.inc.php @@ -0,0 +1,45 @@ + + * @copyright 2002-11 by RalfBecker@outdoor-training.de + * @version $Id: class.etemplate_widget_button.inc.php 36221 2011-08-20 10:27:38Z ralfbecker $ + */ + +/** + * eTemplate image widget + * Displays image from URL, vfs, or finds by name + */ +class etemplate_widget_nextmatch extends etemplate_widget +{ + + public function __construct($xml='') { + if($xml) parent::__construct($xml); + } + + static public function ajax_get_rows($fetchList) + { + error_log(__METHOD__."(".array2string($fetchList).")"); + + // Force the array to be associative + $result = array("null" => null); + + foreach ($fetchList as $entry) + { + for ($i = 0; $i < $entry["count"]; $i++) + { + $result[$entry["startIdx"] + $i] = json_decode('{"info_id":"5","info_type":"email","info_from":"tracker","info_addr":"tracker","info_subject":"InfoLog grid view: problem with Opera; \'permission denied\' while saving","info_des":"","info_owner":"5","info_responsible":[],"info_access":"public","info_cat":"0","info_datemodified":1307112528,"info_startdate":1306503000,"info_enddate":"0", "info_id_parent":"0","info_planned_time":"0","info_replanned_time":"0","info_used_time":"0","info_status":"done", "info_confirm":"not","info_modifier":"5","info_link_id":0,"info_priority":"1","pl_id":"0","info_price":null, "info_percent":"100%","info_datecompleted":1307112528,"info_location":"","info_custom_from":1, "info_uid":"infolog-5-18d12c7bf195f6b9d602e1fa5cde28f1","info_cc":"","caldav_name":"5.ics","info_etag":"0", "info_created":1307112528,"info_creator":"5","links":[],"info_anz_subs":0,"sub_class":"normal_done","info_link":{"title":"tracker"},"class":"rowNoClose rowNoCloseAll ","info_type_label":"E-Mail","info_status_label":"done","info_number":"5"}'); + } + } + + $response = egw_json_response::get(); + $response->data($result); + } + +} + diff --git a/etemplate/js/et2_core_interfaces.js b/etemplate/js/et2_core_interfaces.js index 3a522dcd23..68f492d81d 100644 --- a/etemplate/js/et2_core_interfaces.js +++ b/etemplate/js/et2_core_interfaces.js @@ -93,14 +93,14 @@ var et2_ISubmitListener = new Interface({ var et2_IDetachedDOM = new Interface({ /** - * Returns a list of attributes which can be set when working in the + * Creates a list of attributes which can be set when working in the * "detached" mode. The result is stored in the _attrs array which is provided * by the calling code. */ getDetachedAttributes: function(_attrs) {}, /** - * Returns an array of DOM nodes. The (relativly) same DOM-Nodes have to be + * Returns an array of DOM nodes. The (relatively) same DOM-Nodes have to be * passed to the "setDetachedAttributes" function in the same order. */ getDetachedNodes: function() {}, @@ -109,7 +109,7 @@ var et2_IDetachedDOM = new Interface({ * Sets the given associative attribute->value array and applies the * attributes to the given DOM-Node. * - * @param _nodes is an array of nodes which has to be in the same order as + * @param _nodes is an array of nodes which have to be in the same order as * the nodes returned by "getDetachedNodes" * @param _values is an associative array which contains a subset of attributes * returned by the "getDetachedAttributes" function and sets them to the diff --git a/etemplate/js/et2_dataview_model_dataProvider.js b/etemplate/js/et2_dataview_model_dataProvider.js index 0b2383294f..198e628499 100644 --- a/etemplate/js/et2_dataview_model_dataProvider.js +++ b/etemplate/js/et2_dataview_model_dataProvider.js @@ -131,10 +131,15 @@ var et2_dataview_dataProvider = Class.extend(et2_IDataProvider, { key = parseInt(key); var b = Math.max(0, key - r); - var t = Math.min(key + r, this._total - 1); - for (var i = b; i <= t; i ++) + var t = Math.min(key + this._stepSize, this._total - 1); + var c = 0; + for (var i = b; i <= t && c < this._stepSize; i ++) { - marked[i] = true; + if (typeof this._data[i] == "undefined") + { + marked[i] = true; + c++; + } } } @@ -185,17 +190,20 @@ var et2_dataview_dataProvider = Class.extend(et2_IDataProvider, { for (var key in _data) { - // Make sure the key is a int - key = parseInt(key); + if (!isNaN(key)) + { + // Make sure the key is a int + key = parseInt(key); - // Copy the data for the given index - this._data[key] = { - "data": _data[key], - "timestamp": time - }; + // Copy the data for the given index + this._data[key] = { + "data": _data[key], + "timestamp": time + }; - // Update the row associated to the index - this._callUpdateData(key); + // Update the row associated to the index + this._callUpdateData(key); + } } }, diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index 8e8824afe8..1be6996fa9 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -14,6 +14,7 @@ /*egw:uses jquery.jquery; + /phpgwapi/egw_json.js; et2_widget; et2_core_interfaces; et2_core_DOMWidget; @@ -106,20 +107,15 @@ var et2_nextmatch = et2_DOMWidget.extend(et2_IResizeable, { * Get Rows callback */ getRows: function(_fetchList, _callback, _context) { - console.log("Nextmatch will fetch ", _fetchList); - // Create the entries: - var entries = {}; - for (var i = 0; i < _fetchList.length; i++) - { - var start = _fetchList[i].startIdx; - for (var j = 0; j < _fetchList[i].count; j++) - { - entries[start + j] = -{"info_id":"5","info_type":"email","info_from":"tracker","info_addr":"tracker","info_subject":"InfoLog grid view: problem with Opera; 'permission denied' while saving","info_des":"","info_owner":"5","info_responsible":[],"info_access":"public","info_cat":"0","info_datemodified":1307112528,"info_startdate":1306503000,"info_enddate":"0", "info_id_parent":"0","info_planned_time":"0","info_replanned_time":"0","info_used_time":"0","info_status":"done", "info_confirm":"not","info_modifier":"5","info_link_id":0,"info_priority":"1","pl_id":"0","info_price":null, "info_percent":"100%","info_datecompleted":1307112528,"info_location":"","info_custom_from":1, "info_uid":"infolog-5-18d12c7bf195f6b9d602e1fa5cde28f1","info_cc":"","caldav_name":"5.ics","info_etag":"0", "info_created":1307112528,"info_creator":"5","links":[],"info_anz_subs":0,"sub_class":"normal_done","info_link":{"title":"tracker"},"class":"rowNoClose rowNoCloseAll ","info_type_label":"E-Mail","info_status_label":"done","info_number":"5"} - } - } + // Create an ajax-request + var request = new egw_json_request( + "etemplate_widget_nextmatch::ajax_get_rows::etemplate", [_fetchList], + this); - _callback.call(_context, entries); + // Send the request + request.sendRequest(true, function(_data) { + _callback.call(_context, _data); + }, null); }, /**