Fix wrong number of actions in toolbar, since we could multi-layered actions as single button

This commit is contained in:
Hadi Nategh 2014-02-13 14:33:48 +00:00
parent 36170bf4e3
commit 7386333c10

View File

@ -100,7 +100,8 @@ var et2_toolbar = et2_DOMWidget.extend(
this.actionlist.empty(); this.actionlist.empty();
this.actionbox.append('<h class="ui-toolbar-menulistHeader">'+egw.lang('more')+' ...'+'</h>'); this.actionbox.append('<h class="ui-toolbar-menulistHeader">'+egw.lang('more')+' ...'+'</h>');
this.actionbox.append('<div id="' + this.id + '-menulist' +'" class="ui-toolbar-menulist" ></div>'); this.actionbox.append('<div id="' + this.id + '-menulist' +'" class="ui-toolbar-menulist" ></div>');
var that = this;
var pref = egw.preference(this.id,this.egw().getAppName()); var pref = egw.preference(this.id,this.egw().getAppName());
if (pref && !jQuery.isArray(pref)) this.preference = pref; if (pref && !jQuery.isArray(pref)) this.preference = pref;
@ -114,7 +115,43 @@ var et2_toolbar = et2_DOMWidget.extend(
} }
} }
this.countActions = Object.keys(actions).length - Object.keys(this.preference).length; //Count number of actions including their children
var countActions = function (actions)
{
var totalCount = 0;
var childCounter = function (action, count)
{
var children = action.children || 0,
returnCounter = count || 0;
if (children)
{
returnCounter -= 1;
for (var nChild in children)
returnCounter += 1;
returnCounter = childCounter (children[nChild], returnCounter);
}
else
{
returnCounter = count;
}
return returnCounter;
}
for (var nAction in actions)
{
if (that.flat_list)
{
totalCount += childCounter(actions[nAction],1);
}
else
{
totalCount ++;
}
}
return totalCount;
}
this.countActions = countActions(actions) - Object.keys(this.preference).length;
var last_group = false; var last_group = false;
var last_group_id = false; var last_group_id = false;
for(var name in actions) for(var name in actions)
@ -227,7 +264,7 @@ var et2_toolbar = et2_DOMWidget.extend(
var toolbar =jQuery('#'+this.id+'-'+'actionlist').find('button'), var toolbar =jQuery('#'+this.id+'-'+'actionlist').find('button'),
toolbox = jQuery('#'+this.id+'-'+'actionbox'), toolbox = jQuery('#'+this.id+'-'+'actionbox'),
menulist = jQuery('#'+this.id+'-'+'menulist'); menulist = jQuery('#'+this.id+'-'+'menulist');
var that = this;
toolbar.draggable({ toolbar.draggable({
cancel:true, cancel:true,
zIndex: 1000, zIndex: 1000,