Added very basic implementation for reading the content array

This commit is contained in:
Andreas Stöckel 2011-08-10 17:44:22 +00:00
parent 4f2eeaafe1
commit 9ea38d694b
5 changed files with 190 additions and 3 deletions

View File

@ -0,0 +1,44 @@
/**
* eGroupWare eTemplate2 - JS content array manager
*
* @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";
function et2_contentArrayMgr(_data, _parentMgr)
{
if (typeof _parentMgr == "undefined")
{
_parentMgr = null;
}
// Copy the parent manager which is needed to access relative data when
// being in a relative perspective of the manager
this.parentMgr = _parentMgr;
// Hold a reference to the data
this.data = _data;
}
et2_contentArrayMgr.prototype.getValueForID = function(_id)
{
if (typeof this.data[_id] != "undefined")
{
return this.data[_id];
}
return null;
}
et2_contentArrayMgr.prototype.openPerspective = function(_rootId)
{
return new et2_contentArrayMgr(this._data[_rootId], this);
}

View File

@ -69,6 +69,20 @@ var et2_inputWidget = et2_baseWidget.extend(et2_IInput, {
} }
}, },
set_id: function(_value) {
this._super.apply(this, arguments);
var mgr = this.getContentMgr();
if (_value != '' && mgr != null)
{
var val = mgr.getValueForID(this.id);
if (val !== null)
{
this.set_value(val);
}
}
},
get_value: function() { get_value: function() {
return this.getValue(); return this.getValue();
}, },

View File

@ -58,7 +58,7 @@ var et2_widget = Class.extend({
"id": { "id": {
"name": "ID", "name": "ID",
"type": "string", "type": "string",
"description": "Unique identifier of the widget", "description": "Unique identifier of the widget"
}, },
/** /**
@ -93,6 +93,7 @@ var et2_widget = Class.extend({
} }
this.id = ""; this.id = "";
this._mgr = 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.
@ -426,6 +427,23 @@ var et2_widget = Class.extend({
{ {
this._children[i].update(); this._children[i].update();
} }
},
setContentMgr: function(_mgr) {
this._mgr = _mgr;
},
getContentMgr: function() {
if (this._mgr != null)
{
return this._mgr;
}
else if (this._parent)
{
return this._parent.getContentMgr();
}
return null;
} }
}); });

View File

@ -0,0 +1,95 @@
var timesheet_data = {
"content":{
"ts_id":"1",
"ts_project":null,
"ts_title":"Test geschrieben",
"ts_description":null,
"ts_start":1307030400,
"ts_duration":"150",
"ts_quantity":"2.5",
"ts_unitprice":null,
"cat_id":null,
"ts_owner":"5",
"ts_modified":1307039479,
"ts_modifier":"5",
"pl_id":null,
"ts_status":null,
"user_timezone_read":"Europe/Berlin",
"msg":null,
"view":false,
"tabs":null,
"link_to":{
"to_id":"1",
"to_app":"timesheet"
},
"js":"<script>\u000a\u000a</script>\u000a",
"ts_quantity_blur":2.5,
"start_time":"18:00",
"pm_integration":null,
"no_ts_status":true,
"all_pm_ids":[],
"history":{
"id":"1",
"app":"timesheet",
"status-widgets":{
"ts_status":[],
"ts_modifier":"select-account",
"cat_id":"select-cat"
}
},
"ts_title_blur":null
},
"sel_options":{
"status":{
"ts_project":"Project",
"ts_title":"Title",
"cat_id":"Category",
"ts_description":"Description",
"ts_start":"Start",
"ts_duration":"Duration",
"ts_quantity":"Quantity",
"ts_unitprice":"Unitprice",
"ts_owner":"Owner",
"ts_modifier":"Modifier",
"ts_status":"Status",
"pm_id":"Projectid",
"customfields":"Custom fields"
},
"ts_owner":{
"5":"User, admin"
},
"ts_status":[]
},
"readonlys":{
"button[delete]":false,
"button[edit]":true,
"button[save]":false,
"button[save_new]":false,
"button[apply]":false,
"ts_owner":true,
"tabs":{
"customfields":true
}
},
"preserv":{
"ts_id":"1",
"ts_project":null,
"ts_title":"Test geschrieben",
"ts_description":null,
"ts_start":1307030400,
"ts_duration":"150",
"ts_quantity":"2.5",
"ts_unitprice":null,
"cat_id":null,
"ts_owner":"5",
"ts_modified":1307039479,
"ts_modifier":"5",
"pl_id":null,
"ts_status":null,
"user_timezone_read":"Europe/Berlin",
"view":false,
"referer":"timesheet.timesheet_ui.index",
"ts_title_blur":null
}
}

View File

@ -15,8 +15,12 @@
<script src="../et2_button.js"></script> <script src="../et2_button.js"></script>
<script src="../et2_box.js"></script> <script src="../et2_box.js"></script>
<script src="../et2_textbox.js"></script> <script src="../et2_textbox.js"></script>
<script src="../et2_contentArrayMgr.js"></script>
<!--<script src="../et2_tabs.js"></script>--> <!--<script src="../et2_tabs.js"></script>-->
<script src="../lib/tooltip.js"></script> <script src="../lib/tooltip.js"></script>
<script src="et2_test_timesheet_edit.json"></script>
<style type="text/css"> <style type="text/css">
body { body {
font-family: Lucida Grande, sans-serif; font-family: Lucida Grande, sans-serif;
@ -166,7 +170,7 @@
<h1>EGroupware ETemplate2 Test</h1> <h1>EGroupware ETemplate2 Test</h1>
<div class="header">Choose one of the following tests:</div> <div class="header">Choose one of the following tests:</div>
<div id="linklist"> <div id="linklist">
<a href="#" onclick="open_xet('et2_test_timesheet_edit.xet');">Timesheet edit dialog</a> <a href="#" onclick="open_xet('et2_test_timesheet_edit.xet', timesheet_data.content);">Timesheet edit dialog</a>
<a href="#" onclick="open_xet('et2_test_template.xet');">Template proxy test</a> <a href="#" onclick="open_xet('et2_test_template.xet');">Template proxy test</a>
<a href="#" onclick="open_xet('et2_test_grid.xet');">Grid test</a> <a href="#" onclick="open_xet('et2_test_grid.xet');">Grid test</a>
<a href="#" onclick="open_xet('et2_test_tabbox.xet');">Tabs test</a> <a href="#" onclick="open_xet('et2_test_tabbox.xet');">Tabs test</a>
@ -174,13 +178,21 @@
<a href="#" onclick="open_xet('et2_test_description.xet');">Description test</a> <a href="#" onclick="open_xet('et2_test_description.xet');">Description test</a>
</div> </div>
<div class="header">ETemplate2 container:</div> <div class="header">ETemplate2 container:</div>
<div id="time"></div>
<div id="container"></div> <div id="container"></div>
<script> <script>
var container = null; var container = null;
function open_xet(file) { function open_xet(file, content) {
if (typeof content == "undefined")
{
content = {};
}
et2_loadXMLFromURL(file, et2_loadXMLFromURL(file,
function(_xmldoc) { function(_xmldoc) {
var t1 = (new Date).getTime();
if (container != null) if (container != null)
{ {
container.destroy(); container.destroy();
@ -189,7 +201,11 @@
container = new et2_container(null); container = new et2_container(null);
container.setParentDOMNode(document.getElementById("container")); container.setParentDOMNode(document.getElementById("container"));
container.setContentMgr(new et2_contentArrayMgr(content));
container.loadFromXML(_xmldoc); container.loadFromXML(_xmldoc);
var t2 = (new Date).getTime();
$j("#time").text("Building the template took " + (t2 - t1) + "ms");
}); });
} }
</script> </script>