summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Pretto Nunes <anunes@thoughtworks.com>2015-02-13 17:49:46 -0200
committerAlexandre Pretto Nunes <anunes@thoughtworks.com>2015-02-19 16:41:24 -0200
commit63f74d2d9bcc85cff2fea92e80f49774bef5e6bf (patch)
tree1848295a91932db90afdbbc10bfd6b562059bf5f
parent8e2143bce8c05d1e7ad6e9fbb4052b80ef49da9d (diff)
#239 Remove deprecated code of tag shortcuts
-rw-r--r--web-ui/app/js/tags/ui/tag.js47
-rw-r--r--web-ui/app/js/tags/ui/tag_shortcut.js85
-rw-r--r--web-ui/test/spec/tags/ui/tag_shortcut.spec.js57
3 files changed, 44 insertions, 145 deletions
diff --git a/web-ui/app/js/tags/ui/tag.js b/web-ui/app/js/tags/ui/tag.js
index a41310e8..ba6dfe61 100644
--- a/web-ui/app/js/tags/ui/tag.js
+++ b/web-ui/app/js/tags/ui/tag.js
@@ -19,15 +19,14 @@ define(
[
'flight/lib/component',
'views/templates',
- 'tags/ui/tag_base',
'page/events',
'views/i18n'
],
- function (defineComponent, templates, tagBase, events, i18n) {
+ function (defineComponent, templates, events, i18n) {
'use strict';
- var Tag = defineComponent(tag, tagBase);
+ var Tag = defineComponent(tag);
Tag.appendedTo = function (parent, data) {
var res = new this();
@@ -39,6 +38,44 @@ define(
function tag() {
+ 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';
+ };
+
+ this.doUnselect = function () {
+ this.$node.removeClass('selected');
+ };
+
+ this.doSelect = function () {
+ this.$node.addClass('selected');
+ };
+
+ this.selectTag = function (ev, data) {
+ this.attr.currentTag = data.tag;
+ if (data.tag === this.attr.tag.name) {
+ this.doSelect();
+ }
+ else {
+ this.doUnselect();
+ }
+ };
+
+ this.selectTagAll = function () {
+ this.selectTag(null, {tag: 'all'});
+ };
+
this.viewFor = function (tag, template, currentTag) {
return template({
tagName: tag.default ? i18n('tags.' + tag.name) : tag.name,
@@ -100,6 +137,10 @@ define(
this.on(document, events.mail.read, this.decreaseReadCountIfMatchingTag);
this.on(document, events.search.perform, this.addSearchingClass);
this.on(document, events.search.empty, this.removeSearchingClass);
+
+ this.on(document, events.ui.tag.select, this.selectTag);
+ this.on(document, events.search.perform, this.selectTagAll);
+ this.on(document, events.search.empty, this.selectTagAll);
});
this.renderAndAttach = function (parent, data) {
diff --git a/web-ui/app/js/tags/ui/tag_shortcut.js b/web-ui/app/js/tags/ui/tag_shortcut.js
deleted file mode 100644
index b5b76825..00000000
--- a/web-ui/app/js/tags/ui/tag_shortcut.js
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2014 ThoughtWorks, Inc.
- *
- * Pixelated is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Pixelated is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
- */
-'use strict';
-define(
- [
- 'flight/lib/component',
- 'views/templates',
- 'page/events',
- 'tags/ui/tag_base',
- 'flight/lib/utils'
- ],
-
- function (describeComponent, templates, events, tagBase, utils) {
-
- var TagShortcut = describeComponent(tagShortcut, tagBase);
-
- TagShortcut.appendedTo = function (parent, data) {
- var res = new this();
- res.renderAndAttach(parent, data);
- return res;
- };
-
- return TagShortcut;
-
- function tagShortcut() {
-
- this.renderTemplate = function (tag, currentTag) {
- var model = {
- tagName: tag.name,
- displayBadge: this.displayBadge(tag),
- badgeType: this.badgeType(tag),
- count: this.badgeType(tag) === 'total' ? tag.counts.total : (tag.counts.total - tag.counts.read),
- icon: iconFor[tag.name],
- selected: tag.name === currentTag ? 'selected' : ''
- };
- return templates.tags.shortcut(model);
- };
-
- this.renderAndAttach = function (parent, options) {
- parent.append(this.renderTemplate(options.tag, options.currentTag));
- this.initialize(parent.children().last(), options);
- };
-
- this.reRender = function () {
- this.$node.html(this.renderTemplate(this.attr.tag, this.attr.currentTag));
- };
-
- var iconFor = {
- 'inbox': 'inbox',
- 'sent': 'send',
- 'drafts': 'pencil',
- 'trash': 'trash-o',
- 'all': 'archive'
- };
-
- this.doTeardown = function () {
- if (!jQuery.contains(document, this.$node[0])) {
- this.teardown();
- }
- };
-
- this.after('initialize', function () {
- this.on('click', function () {
- this.attr.trigger.triggerSelect();
- });
- this.on(document, events.tags.shortcuts.teardown, this.doTeardown);
- });
-
- }
- }
-);
diff --git a/web-ui/test/spec/tags/ui/tag_shortcut.spec.js b/web-ui/test/spec/tags/ui/tag_shortcut.spec.js
deleted file mode 100644
index fe235541..00000000
--- a/web-ui/test/spec/tags/ui/tag_shortcut.spec.js
+++ /dev/null
@@ -1,57 +0,0 @@
-/* global jasmine */
-/* global Pixelated */
-
-describeComponent('tags/ui/tag_shortcut', function () {
- 'use strict';
-
- var parent, shortcut, component, TagShortcut;
-
- beforeEach(function () {
- TagShortcut = require('tags/ui/tag_shortcut');
-
- component = jasmine.createSpyObj('tagComponent', ['triggerSelect']);
- parent = $('<ul>');
- $('body').append(parent);
- shortcut = TagShortcut.appendedTo(parent, { tag: { name: 'inbox', counts: { total: 15 }}, trigger: component });
- });
-
- afterEach(function () {
- $('body')[0].removeChild(parent[0]);
- });
-
- it('renders the shortcut inside the parent', function () {
- expect(parent.html()).toMatch('<i class="fa fa-inbox"></i>');
- expect(parent.html()).toMatch('<div class="shortcut-label">inbox</div>');
- });
-
- it('selects and unselect on tag.select', function () {
- $(document).trigger(Pixelated.events.ui.tag.select, { tag: 'inbox'});
-
- expect(shortcut.$node).toHaveClass('selected');
-
- $(document).trigger(Pixelated.events.ui.tag.select, { tag: 'sent'});
-
- expect(shortcut.$node).not.toHaveClass('selected');
- });
-
- it('delegates the click to linked tag', function (){
- shortcut.$node.click();
-
- expect(component.triggerSelect).toHaveBeenCalled();
- });
-
- it('teardown shortcuts on event but only if they are not in the DOM', function () {
- parent.empty();
- var shortcutAddedAfterEmptyingParent = TagShortcut.appendedTo(parent, { tag: { name: 'inbox', counts: { total: 15 }}, trigger: component });
- // by now shorcut is not in the DOM anymore but shortcutAddedAfterEmptyingParent is
-
- spyOn(shortcut, 'teardown').and.callThrough();
- spyOn(shortcutAddedAfterEmptyingParent, 'teardown').and.callThrough();
-
- $(document).trigger(Pixelated.events.tags.shortcuts.teardown);
-
- expect(shortcut.teardown).toHaveBeenCalled();
- expect(shortcutAddedAfterEmptyingParent.teardown).not.toHaveBeenCalled();
- });
-});
-