From 6ee7f3f219207dd75bf0d798eac33174fb83582e Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 30 Sep 2014 22:08:57 +0000 Subject: [PATCH] Basics of infolog-value and tracker-value widgets --- .../inc/class.etemplate_widget_entry.inc.php | 3 +++ etemplate/js/et2_widget_entry.js | 4 +-- infolog/inc/class.infolog_widget.inc.php | 26 ++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget_entry.inc.php b/etemplate/inc/class.etemplate_widget_entry.inc.php index 31eb341470..e9e04ecd06 100644 --- a/etemplate/inc/class.etemplate_widget_entry.inc.php +++ b/etemplate/inc/class.etemplate_widget_entry.inc.php @@ -68,6 +68,9 @@ abstract class etemplate_widget_entry extends etemplate_widget_transformer $form_name = self::form_name($cname, $this->id); $data_id = $this->value ? self::form_name($cname, $this->value) : self::form_name($cname, self::ID_PREFIX . $this->id); + // No need to proceed + if(!$this->id) return; + // Find out which record to load $value = self::get_array(self::$request->content, $form_name, false, true); diff --git a/etemplate/js/et2_widget_entry.js b/etemplate/js/et2_widget_entry.js index 873dd4ca10..52052451c0 100644 --- a/etemplate/js/et2_widget_entry.js +++ b/etemplate/js/et2_widget_entry.js @@ -93,11 +93,11 @@ var et2_entry = et2_valueWidget.extend( } var attrs = { id: this.options.field, - type: entry.type, + type: entry.type || 'label', readonly: this.options.readonly }; var widget = et2_createWidget(attrs.type, attrs, this); } }); -et2_register_widget(et2_entry, ["entry", 'contact-value', 'contact-account', 'contact-template']); \ No newline at end of file +et2_register_widget(et2_entry, ["entry", 'contact-value', 'contact-account', 'contact-template', 'infolog-value','tracker-value']); \ No newline at end of file diff --git a/infolog/inc/class.infolog_widget.inc.php b/infolog/inc/class.infolog_widget.inc.php index cd5193665a..4fcb0b147a 100644 --- a/infolog/inc/class.infolog_widget.inc.php +++ b/infolog/inc/class.infolog_widget.inc.php @@ -21,7 +21,7 @@ * 3) colon (:) separted list of alternative fields: the first non-empty one is used if the selected value is empty * There's a special field "sum" in 1), which sums up all fields given in alternatives. */ -class infolog_widget +class infolog_widget extends etemplate_widget_entry { /** * exported methods of this class @@ -56,14 +56,29 @@ class infolog_widget /** * Constructor of the extension * - * @param string $ui '' for html */ - function __construct($ui) + function __construct($xml) { - $this->ui = $ui; + parent::__construct($xml); $this->infolog = new infolog_bo(); } + public function get_entry($value, array $attrs) + { + // Already done + if (is_array($value) && !(array_key_exists('app',$value) && array_key_exists('id', $value))) return $value; + + // Link entry, already in array format + if(is_array($value) && array_key_exists('app', $value) && array_key_exists('id', $value)) $value = $value['id']; + + // Link entry, in string format + if (substr($value,0,8) == 'infolog:') $value = substr($value,8); + if($value) + { + return $this->infolog->read($value); + } + return array(); + } /** * pre-processing of the extension * @@ -258,3 +273,6 @@ class infolog_widget return $fields; } } + +// register widgets for etemplate2 +etemplate_widget::registerWidget('infolog_widget',array('infolog-value', 'infolog-fields')); \ No newline at end of file