From 02e525b95fbb18d3339ab5155bc189faaccfff6b Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 1 Apr 2015 12:29:20 +0000 Subject: [PATCH] * All apps/customfields: Fix customfields options with multiple negated fields and single custom field Specify css class on customfield's row with named as field's id, in order to be able to customize its style --- admin/templates/default/customfields.xet | 2 +- ...lass.etemplate_widget_customfields.inc.php | 27 ++++++++++--------- etemplate/js/et2_extension_customfields.js | 22 ++++++++++----- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/admin/templates/default/customfields.xet b/admin/templates/default/customfields.xet index a5393238f3..c22848e45d 100644 --- a/admin/templates/default/customfields.xet +++ b/admin/templates/default/customfields.xet @@ -63,7 +63,7 @@ - + diff --git a/etemplate/inc/class.etemplate_widget_customfields.inc.php b/etemplate/inc/class.etemplate_widget_customfields.inc.php index 2425c7c58b..6c23d03414 100644 --- a/etemplate/inc/class.etemplate_widget_customfields.inc.php +++ b/etemplate/inc/class.etemplate_widget_customfields.inc.php @@ -135,17 +135,21 @@ class etemplate_widget_customfields extends etemplate_widget_transformer // app changed $customfields =& egw_customfields::get($app); } - // Filter fields if($this->attrs['field-names']) { - if($this->attrs['field-names'][0] == '!') + $fields_name = explode(',', $this->attrs['field-names']); + foreach($fields_name as &$f) { - $negate_field_filter = true; - $this->attrs['field-names'] = substr($this->attrs['field_names'],1); + if ($f[0] == "!") + { + $f= substr($f,1); + $negate_fields[]= $f; + } + $field_filters []= $f; } - $field_filter = explode(',', $this->attrs['field_names']); } + $fields = $customfields; $use_private = self::expand_name($this->attrs['use-private'],0,0,'','',self::$cont); @@ -160,8 +164,7 @@ class etemplate_widget_customfields extends etemplate_widget_transformer } // Remove filtered fields - if($field_filter && (!$negate_field_filter && !in_array($key, $field_filter) || - $negate_field_filter && in_array($key, $field_filter))) + if($field_filters && in_array($key, $negate_fields) && in_array($key, $field_filters)) { unset($fields[$key]); } @@ -169,11 +172,11 @@ class etemplate_widget_customfields extends etemplate_widget_transformer // check if name refers to a single custom field --> show only that $matches = null; if (($pos=strpos($form_name,self::$prefix)) !== false && // allow the prefixed name to be an array index too - preg_match("/$this->prefix([^\]]+)/",$form_name,$matches) && isset($fields[$name=$matches[1]])) + preg_match($preg = '/'.self::$prefix.'([^\]]+)/',$form_name,$matches) && isset($fields[$name=$matches[1]])) { $fields = array($name => $fields[$name]); - $value = array($this->prefix.$name => $value); - $form_name = substr($form_name,0,-strlen("[$this->prefix$name]")); + $value = array(self::$prefix.$name => $value); + $form_name = self::$prefix.$name; } if(!is_array($fields)) $fields = array(); @@ -199,7 +202,7 @@ class etemplate_widget_customfields extends etemplate_widget_transformer { if (!empty($this->attrs['sub-type']) && !empty($field['type2']) && strpos(','.$field['type2'].',',','.$field['type2'].',') === false) continue; // not for our content type// - if (isset($value[$this->prefix.$lname]) && $value[$this->prefix.$lname] !== '') //break; + if (isset($value[self::$prefix.$lname]) && $value[self::$prefix.$lname] !== '') //break; { $fields_with_vals[]=$lname; } @@ -368,7 +371,7 @@ class etemplate_widget_customfields extends etemplate_widget_transformer { self::set_validation_error($field,lang('Field must not be empty !!!'),''); } - $field_name = self::form_name($form_name != self::GLOBAL_ID ? $form_name : $cname, $field); + $field_name = $this->id[0] == self::$prefix && $customfields[substr($this->id,1)] ? $this->id : self::form_name($form_name != self::GLOBAL_ID ? $form_name : $cname, $field); $valid =& self::get_array($validated, $field_name, true); if (is_array($valid)) $valid = implode(',', $valid); diff --git a/etemplate/js/et2_extension_customfields.js b/etemplate/js/et2_extension_customfields.js index f01a7a8c16..27317c5eda 100644 --- a/etemplate/js/et2_extension_customfields.js +++ b/etemplate/js/et2_extension_customfields.js @@ -53,7 +53,7 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput } }, - legacyOptions: ["type_filter","private"], // Field restriction & private done server-side + legacyOptions: ["type_filter","private", "fields"], // Field restriction & private done server-side prefix: '#', @@ -189,7 +189,8 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput { var row = jQuery(document.createElement("tr")) - .appendTo(this.tbody); + .appendTo(this.tbody) + .addClass(this.id+'_'+id); var cf = jQuery(document.createElement("td")) .appendTo(row); if(!field.type) field.type = 'text";' @@ -286,15 +287,22 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput // Set the value for this element var contentMgr = this.getArrayMgr("content"); if (contentMgr != null) { - var val = contentMgr.getEntry(this.id); + var val = contentMgr.getEntry(this.id); _attrs["value"] = {}; if (val !== null) { - // Only set the values that match desired custom fields - for(var key in val) + if(this.id.indexOf(this.prefix) === 0 && data.fields[this.id.replace(this.prefix,'')] === true) { - if(key.indexOf(this.prefix) == 0) { - _attrs["value"][key] = val[key]; + _attrs['value'][this.id] = val; + } + else + { + // Only set the values that match desired custom fields + for(var key in val) + { + if(key.indexOf(this.prefix) == 0) { + _attrs["value"][key] = val[key]; + } } } //_attrs["value"] = val;