Improve GroupsList each() method and use it in count() and export() methods

This commit is contained in:
Benjamin Renard 2014-01-12 20:08:27 +01:00
parent 13f3db00d5
commit cc37ad1ffc

View file

@ -28,13 +28,9 @@ function GroupList() {
}
this.export=function() {
ret={};
for (el in this) {
if (this.isGroup(this[el])) {
ret[el]=this[el].export();
}
}
return ret;
return this.each(function(idx,group) {
return group.export();
});
}
this.import=function(groups) {
@ -60,18 +56,20 @@ function GroupList() {
this.each=function(fct) {
var idx=0;
var ret={};
for (el in this) {
if(this.isGroup(this[el])) {
fct(idx++,this[el]);
ret[el]=fct(idx++,this[el]);
}
}
return ret;
}
this.count=function() {
len=0;
for (el in this) {
if (this.isGroup(this[el])) len=len+1;
}
this.each(function(idx,group) {
len=len+1;
});
return len;
}