* 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
This commit is contained in:
Hadi Nategh 2015-04-01 12:29:20 +00:00
parent 8af7a8a6b8
commit 02e525b95f
3 changed files with 31 additions and 20 deletions

View File

@ -63,7 +63,7 @@
<menulist> <menulist>
<menupopup id="${row}[cf_type2]" no_lang="1" multiple="true" empty_label="All"/> <menupopup id="${row}[cf_type2]" no_lang="1" multiple="true" empty_label="All"/>
</menulist> </menulist>
<description id="${row}[cf_name]" /> <description id="${row}[cf_name]" no_lang="1" />
<vbox> <vbox>
<description id="${row}[cf_label]" no_lang="1"/> <description id="${row}[cf_label]" no_lang="1"/>
<description id="${row}[cf_label]"/> <description id="${row}[cf_label]"/>

View File

@ -135,17 +135,21 @@ class etemplate_widget_customfields extends etemplate_widget_transformer
// app changed // app changed
$customfields =& egw_customfields::get($app); $customfields =& egw_customfields::get($app);
} }
// Filter fields // Filter fields
if($this->attrs['field-names']) 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; if ($f[0] == "!")
$this->attrs['field-names'] = substr($this->attrs['field_names'],1); {
$f= substr($f,1);
$negate_fields[]= $f;
}
$field_filters []= $f;
} }
$field_filter = explode(',', $this->attrs['field_names']);
} }
$fields = $customfields; $fields = $customfields;
$use_private = self::expand_name($this->attrs['use-private'],0,0,'','',self::$cont); $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 // Remove filtered fields
if($field_filter && (!$negate_field_filter && !in_array($key, $field_filter) || if($field_filters && in_array($key, $negate_fields) && in_array($key, $field_filters))
$negate_field_filter && in_array($key, $field_filter)))
{ {
unset($fields[$key]); 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 // check if name refers to a single custom field --> show only that
$matches = null; $matches = null;
if (($pos=strpos($form_name,self::$prefix)) !== false && // allow the prefixed name to be an array index too 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]); $fields = array($name => $fields[$name]);
$value = array($this->prefix.$name => $value); $value = array(self::$prefix.$name => $value);
$form_name = substr($form_name,0,-strlen("[$this->prefix$name]")); $form_name = self::$prefix.$name;
} }
if(!is_array($fields)) $fields = array(); 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']) && if (!empty($this->attrs['sub-type']) && !empty($field['type2']) &&
strpos(','.$field['type2'].',',','.$field['type2'].',') === false) continue; // not for our content type// 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; $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 !!!'),''); 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); $valid =& self::get_array($validated, $field_name, true);
if (is_array($valid)) $valid = implode(',', $valid); if (is_array($valid)) $valid = implode(',', $valid);

View File

@ -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: '#', prefix: '#',
@ -189,7 +189,8 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput
{ {
var row = jQuery(document.createElement("tr")) var row = jQuery(document.createElement("tr"))
.appendTo(this.tbody); .appendTo(this.tbody)
.addClass(this.id+'_'+id);
var cf = jQuery(document.createElement("td")) var cf = jQuery(document.createElement("td"))
.appendTo(row); .appendTo(row);
if(!field.type) field.type = 'text";' 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 // Set the value for this element
var contentMgr = this.getArrayMgr("content"); var contentMgr = this.getArrayMgr("content");
if (contentMgr != null) { if (contentMgr != null) {
var val = contentMgr.getEntry(this.id); var val = contentMgr.getEntry(this.id);
_attrs["value"] = {}; _attrs["value"] = {};
if (val !== null) if (val !== null)
{ {
// Only set the values that match desired custom fields if(this.id.indexOf(this.prefix) === 0 && data.fields[this.id.replace(this.prefix,'')] === true)
for(var key in val)
{ {
if(key.indexOf(this.prefix) == 0) { _attrs['value'][this.id] = val;
_attrs["value"][key] = val[key]; }
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; //_attrs["value"] = val;