From bcd52bb375eaea773e00889c3fe1e5e0f044ed39 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 19 Jun 2013 18:11:30 +0000 Subject: [PATCH] Better fix for some widgets not being properly initialized (that doesn't break others) --- etemplate/inc/class.etemplate_widget.inc.php | 18 +++++++++++++----- .../inc/class.etemplate_widget_button.inc.php | 1 + ...class.etemplate_widget_customfields.inc.php | 15 +++++++++++++-- .../inc/class.etemplate_widget_link.inc.php | 8 ++++---- .../class.etemplate_widget_menupopup.inc.php | 2 +- .../inc/class.etemplate_widget_textbox.inc.php | 2 +- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget.inc.php b/etemplate/inc/class.etemplate_widget.inc.php index e8009012ba..76671a2602 100644 --- a/etemplate/inc/class.etemplate_widget.inc.php +++ b/etemplate/inc/class.etemplate_widget.inc.php @@ -295,12 +295,20 @@ class etemplate_widget if (!isset($class_name)) { list($basetype) = explode('-',$type); - $class_name = self::$widget_registry[$basetype]; - if (!$class_name && !(class_exists($class_name = 'etemplate_widget_'.str_replace('-','_',$basetype)) || - class_exists($class_name = 'etemplate_widget_'.str_replace('-','_',$type)))) + if (!class_exists($class_name = 'etemplate_widget_'.str_replace('-','_',$type)) && + !class_exists($class_name = 'etemplate_widget_'.str_replace('-','_',$basetype))) { - // default to widget class, we can not ignore it, as the widget may contain other widgets - $class_name = 'etemplate_widget'; + // Try for base type, it's probably better than the root + if(self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) + { + $class_name = self::$widget_registry[$basetype]; + } + else + { + // Fall back to widget class, we can not ignore it, as the widget may contain other widgets + $class_name = 'etemplate_widget'; + //trigger_error("Could not find a class for $type, using $class_name", E_USER_NOTICE); + } } } diff --git a/etemplate/inc/class.etemplate_widget_button.inc.php b/etemplate/inc/class.etemplate_widget_button.inc.php index 741916f88e..2cab139885 100644 --- a/etemplate/inc/class.etemplate_widget_button.inc.php +++ b/etemplate/inc/class.etemplate_widget_button.inc.php @@ -59,3 +59,4 @@ class etemplate_widget_button extends etemplate_widget } } } +etemplate_widget::registerWidget('etemplate_widget_button', array('button','buttononly')); diff --git a/etemplate/inc/class.etemplate_widget_customfields.inc.php b/etemplate/inc/class.etemplate_widget_customfields.inc.php index dfb1f600cf..d6c967eb4d 100644 --- a/etemplate/inc/class.etemplate_widget_customfields.inc.php +++ b/etemplate/inc/class.etemplate_widget_customfields.inc.php @@ -209,6 +209,7 @@ class etemplate_widget_customfields extends etemplate_widget_transformer // Re-format date custom fields from Y-m-d $field_settings =& self::get_array(self::$request->modifications, "{$this->id}[customfields]",true); $field_settings = array(); + $link_types = egw_link::app_list(); foreach($fields as $fname => $field) { if($field['type'] == 'date' && ($d_val = self::$request->content[self::$prefix.$fname]) && !is_numeric($d_val)) @@ -217,11 +218,21 @@ class etemplate_widget_customfields extends etemplate_widget_transformer } // Run beforeSendToClient for each field - $widget = self::factory($field['type'], '<'.$field['type'].' type="'.$field['type'].'" id="'.self::$prefix.$fname.'"/>', self::$prefix.$fname); + $type = $field['type']; + // Link-tos needs to change from appname to link-to + if($link_types[$field['type']]) + { + $type = 'link-to'; + } + $widget = self::factory($type, '<'.$type.' type="'.$type.'" id="'.self::$prefix.$fname.'"/>', self::$prefix.$fname); if(method_exists($widget, 'beforeSendToClient')) { $widget->id = self::$prefix.$fname; - $widget->attrs['type'] = $field['type']; + $widget->attrs['type'] = $type; + if($type == 'link-to') + { + $widget->attrs['only_app'] = $field['type']; + } $widget->beforeSendToClient($this->id == self::GLOBAL_ID ? '':$this->id, $fname); } } diff --git a/etemplate/inc/class.etemplate_widget_link.inc.php b/etemplate/inc/class.etemplate_widget_link.inc.php index fa45c8ea26..f508f4f14d 100644 --- a/etemplate/inc/class.etemplate_widget_link.inc.php +++ b/etemplate/inc/class.etemplate_widget_link.inc.php @@ -57,10 +57,10 @@ class etemplate_widget_link extends etemplate_widget $form_name = self::form_name($cname, $this->id); $value =& self::get_array(self::$request->content, $form_name, true); - if($value && !is_array($value)) + if($value && !is_array($value) && !$this->attrs['only_app']) { // Try to explode - if(!is_array(explode(':',$value))) { + if(count(explode(':',$value)) < 2) { throw new egw_exception_wrong_parameter("Wrong value sent to link widget, needs to be an array. ".array2string($value)); } list($app, $id) = explode(':', $value,2); @@ -71,13 +71,13 @@ class etemplate_widget_link extends etemplate_widget return; } - $app = $value['to_app']; - $id = $value['to_id']; // ToDo: implement on client-side if (!$attrs['help']) self::setElementAttribute($form_name, 'help', 'view this linked entry in its application'); if($attrs['type'] == 'link-list') { + $app = $value['to_app']; + $id = $value['to_id']; $links = egw_link::get_links($app,$id,'','link_lastmod DESC',true, $value['show_deleted']); foreach($links as $link) { $value[] = $link; diff --git a/etemplate/inc/class.etemplate_widget_menupopup.inc.php b/etemplate/inc/class.etemplate_widget_menupopup.inc.php index 7cc2ff5a1f..0376b083c6 100644 --- a/etemplate/inc/class.etemplate_widget_menupopup.inc.php +++ b/etemplate/inc/class.etemplate_widget_menupopup.inc.php @@ -654,4 +654,4 @@ class etemplate_widget_menupopup extends etemplate_widget } } -etemplate_widget::registerWidget('etemplate_widget_menupopup', array('selectbox','listbox','select')); +etemplate_widget::registerWidget('etemplate_widget_menupopup', array('selectbox','listbox','select','menulist','menupopup')); diff --git a/etemplate/inc/class.etemplate_widget_textbox.inc.php b/etemplate/inc/class.etemplate_widget_textbox.inc.php index 2ecffa8696..21932977fa 100644 --- a/etemplate/inc/class.etemplate_widget_textbox.inc.php +++ b/etemplate/inc/class.etemplate_widget_textbox.inc.php @@ -154,4 +154,4 @@ class etemplate_widget_textbox extends etemplate_widget } } } -etemplate_widget::registerWidget('etemplate_widget_textbox', array('textbox','int','integer','float','passwd','hidden','colorpicker')); +etemplate_widget::registerWidget('etemplate_widget_textbox', array('textbox','text','int','integer','float','passwd','hidden','colorpicker'));