diff options
author | Roald de Vries <rdevries@thoughtworks.com> | 2016-12-08 16:59:09 +0100 |
---|---|---|
committer | Roald de Vries <rdevries@thoughtworks.com> | 2016-12-08 16:59:09 +0100 |
commit | fafac3b4128a0993b0de1c6e8ca3062bf1ccc14e (patch) | |
tree | 3b9a446e4c82bb8ba94c1cd0adec57c0042dae28 /web-ui/app/js/tags/ui | |
parent | 521bce7eff5cf921156efe74c91a0499ade43619 (diff) |
Revert "[#801] Merge branch 'signup'"
This reverts commit d10f607a4d40587510b0dc31b31fe4750bf4a3a3, reversing
changes made to c28abba2f5b1186c671ebef508d40ffaae6d5bc5.
Diffstat (limited to 'web-ui/app/js/tags/ui')
-rw-r--r-- | web-ui/app/js/tags/ui/tag.js | 154 | ||||
-rw-r--r-- | web-ui/app/js/tags/ui/tag_base.js | 68 | ||||
-rw-r--r-- | web-ui/app/js/tags/ui/tag_list.js | 105 |
3 files changed, 327 insertions, 0 deletions
diff --git a/web-ui/app/js/tags/ui/tag.js b/web-ui/app/js/tags/ui/tag.js new file mode 100644 index 00000000..37814cfc --- /dev/null +++ b/web-ui/app/js/tags/ui/tag.js @@ -0,0 +1,154 @@ +/* + * 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/>. + */ + +define( + [ + 'flight/lib/component', + 'views/templates', + 'page/events', + 'views/i18n' + ], + + function (defineComponent, templates, events, i18n) { + 'use strict'; + + var Tag = defineComponent(tag); + + Tag.appendedTo = function (parent, data) { + var res = new this(); + res.renderAndAttach(parent, data); + return res; + }; + + return Tag; + + 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.t('tags.' + tag.name) : tag.name, + ident: this.hashIdent(tag.ident), + count: this.badgeType(tag) === 'total' ? tag.counts.total : (tag.counts.total - tag.counts.read), + displayBadge: this.displayBadge(tag), + badgeType: this.badgeType(tag), + icon: tag.icon, + selected: tag.name === currentTag ? 'selected' : '' + }); + }; + + this.decreaseReadCountIfMatchingTag = function (ev, data) { + var mailbox_and_tags = _.flatten([data.tags, data.mailbox]); + if (_.contains(mailbox_and_tags, this.attr.tag.name)) { + this.attr.tag.counts.read++; + this.$node.html(this.viewFor(this.attr.tag, templates.tags.tagInner, this.attr.currentTag)); + if (!_.isUndefined(this.attr.shortcut)) { + this.attr.shortcut.reRender(); + } + } + }; + + this.triggerSelect = function () { + this.trigger(document, events.ui.tag.select, { tag: this.attr.tag.name }); + + this.removeSearchingClass(); + }; + + this.addSearchingClass = function() { + if (this.attr.tag.name === 'all'){ + this.$node.addClass('searching'); + } + }; + + this.hashIdent = function(ident) { + if (typeof ident === 'undefined') { + return ''; + } + if (typeof ident === 'number') { + return ident; + } + if (ident.match(/^[a-zA-Z0-9]+$/)) { + return ident; + } + + /*jslint bitwise: true */ + return Math.abs(String(ident).split('').reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a;},0)); + }; + + this.removeSearchingClass = function() { + if (this.attr.tag.name === 'all'){ + this.$node.removeClass('searching'); + } + }; + + this.after('initialize', function () { + this.on('click', this.triggerSelect); + 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) { + var rendered = this.viewFor(data.tag, templates.tags.tag, data.currentTag); + parent.append(rendered); + this.initialize('#tag-' + this.hashIdent(data.tag.ident), data); + this.on(parent, events.tags.teardown, this.teardown); + }; + } + } +); diff --git a/web-ui/app/js/tags/ui/tag_base.js b/web-ui/app/js/tags/ui/tag_base.js new file mode 100644 index 00000000..9dc1ccbb --- /dev/null +++ b/web-ui/app/js/tags/ui/tag_base.js @@ -0,0 +1,68 @@ +/* + * 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/>. + */ +define(['views/i18n', 'page/events'], function(i18n, events) { + 'use strict'; + + 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'; + }; + + 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.after('initialize', function () { + 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); + }); + } + + return tagBase; + +}); diff --git a/web-ui/app/js/tags/ui/tag_list.js b/web-ui/app/js/tags/ui/tag_list.js new file mode 100644 index 00000000..a2172c6d --- /dev/null +++ b/web-ui/app/js/tags/ui/tag_list.js @@ -0,0 +1,105 @@ +/* + * 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/>. + */ +define( + [ + 'flight/lib/component', + 'tags/ui/tag', + 'views/templates', + 'page/events', + 'page/router/url_params' + ], + + function(defineComponent, Tag, templates, events, urlParams) { + 'use strict'; + + var ICON_FOR = { + 'inbox': 'inbox', + 'sent': 'send', + 'drafts': 'pencil', + 'trash': 'trash-o', + 'all': 'archive' + }; + + var ORDER = { + 'inbox': '0', + 'sent': '1', + 'drafts': '2', + 'trash': '3', + 'all': '4' + }; + + return defineComponent(tagList); + + function tagOrder(nm) { + return ORDER[nm.name] || '999' + nm.name; + } + + function tagList() { + this.defaultAttrs({ + defaultTagList: '#default-tag-list', + customTagList: '#custom-tag-list' + }); + + function renderTag(tag, defaultList, customList) { + var list = tag.default ? defaultList : customList; + + var tagComponent = Tag.appendedTo(list, {tag: tag, currentTag: this.getCurrentTag()}); + } + + function resetTagList(lists) { + _.each(lists, function (list) { + this.trigger(list, events.tags.teardown); + list.empty(); + }.bind(this)); + + } + + this.renderTagList = function(tags) { + var defaultList = this.select('defaultTagList'); + var customList = this.select('customTagList'); + + resetTagList.call(this, [defaultList, customList]); + + tags.forEach(function (tag) { + renderTag.call(this, tag, defaultList, customList); + }.bind(this)); + }; + + this.displayTags = function(ev, data) { + this.renderTagList(_.sortBy(data.tags, tagOrder)); + }; + + this.getCurrentTag = function () { + return this.attr.currentTag || urlParams.getTag(); + }; + + this.updateCurrentTag = function(ev, data) { + this.attr.currentTag = data.tag; + }; + + this.renderTagListTemplate = function () { + this.$node.html(templates.tags.tagList()); + }; + + this.after('initialize', function() { + this.on(document, events.tags.received, this.displayTags); + this.on(document, events.ui.tag.select, this.updateCurrentTag); + this.renderTagListTemplate(); + }); + } + } +); |