From bd624bdd14ef63186064b2e39fc422f328b24b26 Mon Sep 17 00:00:00 2001 From: Patrick Maia Date: Thu, 7 Aug 2014 18:01:01 -0300 Subject: disables save draft, add tag, reply-section features --- web-ui/app/js/features/features.js | 18 ++++++++++++++++++ web-ui/app/js/lib/features.js | 5 ----- web-ui/app/js/mail_view/data/mail_sender.js | 9 ++++++--- web-ui/app/js/mail_view/ui/mail_view.js | 21 ++++++++++++--------- web-ui/app/js/mail_view/ui/reply_section.js | 5 +++-- web-ui/app/js/main.js | 3 ++- web-ui/app/js/mixins/with_feature_toggle.js | 9 +++------ web-ui/karma.conf.js | 1 + web-ui/test/features.js | 7 +++++++ web-ui/test/test-main.js | 3 ++- 10 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 web-ui/app/js/features/features.js delete mode 100644 web-ui/app/js/lib/features.js create mode 100644 web-ui/test/features.js diff --git a/web-ui/app/js/features/features.js b/web-ui/app/js/features/features.js new file mode 100644 index 00000000..74efdd07 --- /dev/null +++ b/web-ui/app/js/features/features.js @@ -0,0 +1,18 @@ +define([], function() { + var disabledFeatures; + + function getFeatures() { + disabledFeatures = disabledFeatures || fetchDisabledFeatures(); + return disabledFeatures; + } + + function fetchDisabledFeatures() { + return ['saveDraft', 'createNewTag', 'replySection']; + } + + return { + isEnabled: function(featureName) { + return ! _.contains(getFeatures(), featureName); + } + }; +}); diff --git a/web-ui/app/js/lib/features.js b/web-ui/app/js/lib/features.js deleted file mode 100644 index deacc8fe..00000000 --- a/web-ui/app/js/lib/features.js +++ /dev/null @@ -1,5 +0,0 @@ -define([], function() { - return { - - }; -}); diff --git a/web-ui/app/js/mail_view/data/mail_sender.js b/web-ui/app/js/mail_view/data/mail_sender.js index 7440f5a7..0dba1a02 100644 --- a/web-ui/app/js/mail_view/data/mail_sender.js +++ b/web-ui/app/js/mail_view/data/mail_sender.js @@ -2,9 +2,10 @@ define( [ 'flight/lib/component', 'mail_view/data/mail_builder', - 'page/events' + 'page/events', + 'features' ], - function (defineComponent, mailBuilder, events) { + function (defineComponent, mailBuilder, events, features) { 'use strict'; return defineComponent(mailSender); @@ -67,7 +68,9 @@ define( this.after('initialize', function () { this.on(events.mail.send, this.sendMail); - this.on(events.mail.saveDraft, this.saveDraft); + if(features.isEnabled('saveDraft')) { + this.on(events.mail.saveDraft, this.saveDraft); + } this.on(document, events.mail.save, this.saveMailWithCallback); }); } diff --git a/web-ui/app/js/mail_view/ui/mail_view.js b/web-ui/app/js/mail_view/ui/mail_view.js index 1e27c879..9114fa2e 100644 --- a/web-ui/app/js/mail_view/ui/mail_view.js +++ b/web-ui/app/js/mail_view/ui/mail_view.js @@ -12,10 +12,11 @@ define( 'helpers/view_helper', 'mixins/with_hide_and_show', 'page/events', - 'views/i18n' + 'views/i18n', + 'features' ], - function (defineComponent, templates, mailActions, viewHelpers, withHideAndShow, events, i18n) { + function (defineComponent, templates, mailActions, viewHelpers, withHideAndShow, events, i18n, features) { return defineComponent(mailView, mailActions, withHideAndShow); @@ -148,13 +149,15 @@ define( }; this.createNewTag = function() { - var tagsCopy = this.attr.mail.tags.slice(); - tagsCopy.push(this.select('newTagInput').val()); - this.attr.tagCompleter.clear(); - this.attr.tagCompleter.clearPrefetchCache(); - this.attr.tagCompleter.clearRemoteCache(); - this.trigger(document, events.mail.tags.update, { ident: this.attr.mail.ident, tags: _.uniq(tagsCopy)}); - this.trigger(document, events.dispatchers.tags.refreshTagList); + if(features.isEnabled('createNewTag')) { + var tagsCopy = this.attr.mail.tags.slice(); + tagsCopy.push(this.select('newTagInput').val()); + this.attr.tagCompleter.clear(); + this.attr.tagCompleter.clearPrefetchCache(); + this.attr.tagCompleter.clearRemoteCache(); + this.trigger(document, events.mail.tags.update, { ident: this.attr.mail.ident, tags: _.uniq(tagsCopy)}); + this.trigger(document, events.dispatchers.tags.refreshTagList); + } }; this.handleKeyDown = function(event) { diff --git a/web-ui/app/js/mail_view/ui/reply_section.js b/web-ui/app/js/mail_view/ui/reply_section.js index 866a255a..80781842 100644 --- a/web-ui/app/js/mail_view/ui/reply_section.js +++ b/web-ui/app/js/mail_view/ui/reply_section.js @@ -5,13 +5,14 @@ define( 'mail_view/ui/reply_box', 'mail_view/ui/forward_box', 'mixins/with_hide_and_show', + 'mixins/with_feature_toggle', 'page/events' ], - function (defineComponent, templates, ReplyBox, ForwardBox, withHideAndShow, events) { + function (defineComponent, templates, ReplyBox, ForwardBox, withHideAndShow, withFeatureToggle, events) { 'use strict'; - return defineComponent(replySection, withHideAndShow); + return defineComponent(replySection, withHideAndShow, withFeatureToggle('replySection')); function replySection() { this.defaultAttrs({ diff --git a/web-ui/app/js/main.js b/web-ui/app/js/main.js index 22a11c3a..665416fc 100644 --- a/web-ui/app/js/main.js +++ b/web-ui/app/js/main.js @@ -20,7 +20,8 @@ requirejs.config({ 'search': 'js/search', 'foundation': 'js/foundation', 'i18next': 'bower_components/i18next/i18next.amd', - 'quoted-printable': 'bower_components/quoted-printable' + 'quoted-printable': 'bower_components/quoted-printable', + 'features': 'js/features/features' } }); diff --git a/web-ui/app/js/mixins/with_feature_toggle.js b/web-ui/app/js/mixins/with_feature_toggle.js index 3a484388..2b071e68 100644 --- a/web-ui/app/js/mixins/with_feature_toggle.js +++ b/web-ui/app/js/mixins/with_feature_toggle.js @@ -1,15 +1,12 @@ -define(['lib/features'], +define(['features'], function(features) { function withFeatureToggle(componentName) { return function() { - var defaultToggle = {enabled: true}; - this.around('initialize', function(basicInitialize) { - var featureToggle = features[componentName] || defaultToggle; - if(featureToggle.enabled) { - basicInitialize(arguments[1], arguments[2]); + if(features.isEnabled(componentName)) { + return basicInitialize(arguments[1], arguments[2]); } }); }; diff --git a/web-ui/karma.conf.js b/web-ui/karma.conf.js index 6a4463fe..015de6bb 100644 --- a/web-ui/karma.conf.js +++ b/web-ui/karma.conf.js @@ -41,6 +41,7 @@ module.exports = function (config) { {pattern: 'app/locales/**/*.json', included: false}, {pattern: 'app/js/**/*.js', included: false}, {pattern: 'test/test_data.js', included: false}, + {pattern: 'test/features.js', included: false}, {pattern: 'test/spec/**/*.spec.js', included: false}, 'test/test-main.js' diff --git a/web-ui/test/features.js b/web-ui/test/features.js new file mode 100644 index 00000000..be5a62d5 --- /dev/null +++ b/web-ui/test/features.js @@ -0,0 +1,7 @@ +define([], function() { + return { + isEnabled: function(featureName) { + return true; + } + }; +}); diff --git a/web-ui/test/test-main.js b/web-ui/test/test-main.js index e07d292c..8bdd45e3 100644 --- a/web-ui/test/test-main.js +++ b/web-ui/test/test-main.js @@ -28,7 +28,8 @@ requirejs.config({ 'monkey_patching': 'app/js/monkey_patching', 'i18next': 'app/bower_components/i18next/i18next.amd', 'quoted-printable': 'app/bower_components/quoted-printable', - 'test': 'test' + 'test': 'test', + 'features': 'test/features' }, -- cgit v1.2.3