Add getContributionsByCategory() and findUnusedCategories() method to group object
Benjamin Renard

Benjamin Renard commited on 2014-08-02 14:39:13
Showing 1 changed files, with 30 additions and 0 deletions.

... ...
@@ -337,6 +337,36 @@ function Group(uuid,name,data) {
337 337
     };
338 338
   }
339 339
   
340
+  this.getContributionsByCategory=function (category) {
341
+	  var ret={};
342
+	  for (uuid in this.contributions) {
343
+		  if (this.contributions[uuid].category==category.uuid) {
344
+			  ret[uuid]=this.contributions[uuid];
345
+		  }
346
+	  }
347
+	  return ret;
348
+  }
349
+  
350
+  this.findUnusedCategories=function() {
351
+	  var cats={};
352
+	  for (uuid in this.contributions) {
353
+		  cid=this.contributions[uuid].category;
354
+		  if ($.type(cats[cid])=='undefined') {
355
+			  cats[cid]=1;
356
+		  }
357
+		  else {
358
+			  cats[cid]++;
359
+		  }
360
+	  }
361
+	  var ret={};
362
+	  for (cid in this.categories) {
363
+		if ($.type(cats[cid])=='undefined') {
364
+			ret[cid]=this.categories[cid];
365
+		}
366
+	  }
367
+	  return ret;
368
+  }
369
+  
340 370
   /*
341 371
    * Categories
342 372
    */
343 373