From 0d47709ed1e9273776c6ee599c9fbf9ad2ca2961 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 15 Sep 2011 18:00:17 +0000 Subject: [PATCH] Implement transformer changing type on client side by changing type while loading --- ...ss.etemplate_widget_projectmanager.inc.php | 80 +++++++++++++++++++ etemplate/js/et2_core_widget.js | 11 +++ 2 files changed, 91 insertions(+) create mode 100644 etemplate/inc/class.etemplate_widget_projectmanager.inc.php diff --git a/etemplate/inc/class.etemplate_widget_projectmanager.inc.php b/etemplate/inc/class.etemplate_widget_projectmanager.inc.php new file mode 100644 index 0000000000..698e5d961b --- /dev/null +++ b/etemplate/inc/class.etemplate_widget_projectmanager.inc.php @@ -0,0 +1,80 @@ + array( + 'projectmanager-select' => 'menupopup', + 'projectmanager-pricelist' => 'menupopup', + 'projectmanager-select-erole' => 'menupopup', + ) + ); + + /** + * (Array of) comma-separated list of legacy options to automatically replace when parsing with set_attrs + * + * @var string|array + */ + protected $legacy_options = ''; + + /** + * Fill type options in self::$request->sel_options to be used on the client + * + * @param string $cname + */ + public function beforeSendToClient($cname) + { + if ($this->type) + { + $form_name = self::form_name($cname, $this->id); + // += to keep further options set by app code + if (!is_array(self::$request->sel_options[$form_name])) self::$request->sel_options[$form_name] = array(); + $pm_widget = new projectmanager_widget(); + $cell = $this->attrs + array('type'=>$this->type); + $pm_widget->pre_process($form_name, self::get_array(self::$request->content, $form_name), + $cell, + $this->attrs['readonly'], + $extension, + $template + ); + self::$request->sel_options[$form_name] += $cell['sel_options']; + + // if no_lang was modified, forward modification to the client + if ($cell['no_lang'] != $this->attr['no_lang']) + { + self::setElementAttribute($form_name, 'no_lang', $no_lang); + } + } + + parent::beforeSendToClient($cname); + } + + /** + * Validate input + * + * @todo + * @param string $cname current namespace + * @param array $content + * @param array &$validated=array() validated content + * @return boolean true if no validation error, false otherwise + */ + public function validate($cname, array $content, &$validated=array()) + { + } +} diff --git a/etemplate/js/et2_core_widget.js b/etemplate/js/et2_core_widget.js index a86ef7976a..ca234899e6 100644 --- a/etemplate/js/et2_core_widget.js +++ b/etemplate/js/et2_core_widget.js @@ -552,6 +552,17 @@ var et2_widget = Class.extend({ _node.getAttribute("id"), _node.getAttribute("readonly"), this.readonly); + // Check to see if modifications change type + var modifications = this.getArrayMgr("modifications"); + if(modifications && _node.getAttribute("id")) { + var entry = modifications.getEntry(_node.getAttribute("id")); + if(entry && entry.type) + { + _nodeName = attributes["type"] = entry.type + } + entry = null; + } + // Get the constructor - if the widget is readonly, use the special "_ro" // constructor if it is available var constructor = typeof et2_registry[_nodeName] == "undefined" ?