summaryrefslogtreecommitdiff
path: root/web-ui/app/js/tags/ui/tag_base.js
blob: 58f285f7d3cdc1cfcaac24a6897c168e7e79f76f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
define(['views/i18n', 'page/events'], function(i18n, events) {

  function tagBase() {
    var ALWAYS_HIDE_BADGE_FOR = ['sent', 'trash', 'all'];
    var TOTAL_BADGE = ['drafts'];

    this.displayBadge = function(tag) {
      if(_.include(ALWAYS_HIDE_BADGE_FOR, tag.name)) { return false; }
      if(this.badgeType(tag) === 'total') {
        return tag.counts.total > 0;
      } else {
        return (tag.counts.total - tag.counts.read) > 0;
      }
    };

    this.badgeType = function(tag) {
      return _.include(TOTAL_BADGE, tag.name) ? 'total' : 'unread';
    };

  }

  return tagBase;

});