* Addressbook: fixed sorting of category tree

fixes not displayed cat-tree and validation error introduced with r47575
This commit is contained in:
Ralf Becker 2014-07-09 11:18:47 +00:00
parent 6d9421e034
commit 2a6168a1c2
2 changed files with 21 additions and 6 deletions

View File

@ -125,6 +125,20 @@ class etemplate_widget_tree extends etemplate_widget
return false;
}
/**
* Check if given $id is cat_id attribute of one of given array members
*
* @param int $id
* @param array $cats
* @return boolean
*/
public static function in_cats($id, array $cats)
{
return (boolean)array_filter($cats, function($cat) use($id){
return $cat['id'] == $id;
});
}
/**
* Validate input
*
@ -149,7 +163,7 @@ class etemplate_widget_tree extends etemplate_widget
$allowed += self::selOptions($form_name);
foreach((array) $value as $val)
{
if ($this->type == 'tree-cat' && !($this->attrs['multiple'] && !$val) && !isset($allowed[$val]) ||
if ($this->type == 'tree-cat' && !($this->attrs['multiple'] && !$val) && !self::in_cats($val, $allowed) ||
$this->type == 'tree' && !self::in_tree($val, $allowed))
{
self::set_validation_error($form_name,lang("'%1' is NOT allowed%2)!", $val,
@ -169,7 +183,7 @@ class etemplate_widget_tree extends etemplate_widget
self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),'');
}
$valid =& self::get_array($validated, $form_name, true);
$valid = $value;
if (true) $valid = $value;
//error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value).', allowed='.array2string($allowed));
}
}

View File

@ -151,7 +151,7 @@ var et2_tree = et2_inputWidget.extend(
// Try again according to ID
if(!content_options) content_options = this.getArrayMgr("sel_options").getEntry(this.id);
if(_attrs["select_options"] && content_options)
if(_attrs["select_options"] && !jQuery.isEmptyObject(_attrs["select_options"]) && content_options)
{
_attrs["select_options"] = jQuery.extend({},_attrs["select_options"],content_options);
} else if (content_options) {
@ -250,10 +250,11 @@ var et2_tree = et2_inputWidget.extend(
}
// Structure data for category tree
if(this._type == 'tree-cat' && !jQuery.isArray(options)) {
if(this._type == 'tree-cat')
{
var data = {id:0,item:[]};
var stack = [];
for(var key in options)
var stack = {};
for(var key=0; key < options.length; key++)
{
// See if item has an icon
if(options[key].data && typeof options[key].data.icon !== 'undefined' && options[key].data.icon)