From 01c563ca85f6e439b356fe2d20f7edce87f10cf4 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 20 Jun 2016 12:40:24 +0800 Subject: [PATCH] FIX: Use internal value for poll builder. --- .../controllers/poll-ui-builder.js.es6 | 27 +++++++++++-------- .../controllers/poll-ui-builder-test.js.es6 | 8 +++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 index 3bb34f21d..61e703e74 100644 --- a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 +++ b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 @@ -2,27 +2,32 @@ import { default as computed, observes } from 'ember-addons/ember-computed-decor export default Ember.Controller.extend({ needs: ['modal'], + numberPollType: 'number', + multiplePollType: 'multiple', init() { this._super(); this._setupPoll(); }, - @computed - pollTypes() { - return [I18n.t("poll.ui_builder.poll_type.number"), I18n.t("poll.ui_builder.poll_type.multiple")].map(type => { - return { name: type, value: type }; - }); + @computed("numberPollType", "multiplePollType") + pollTypes(numberPollType, multiplePollType) { + let types = []; + + types.push({ name: I18n.t("poll.ui_builder.poll_type.number"), value: numberPollType }); + types.push({ name: I18n.t("poll.ui_builder.poll_type.multiple"), value: multiplePollType }); + + return types; }, - @computed("pollType", "pollOptionsCount") - isMultiple(pollType, count) { - return (pollType === I18n.t("poll.ui_builder.poll_type.multiple")) && count > 0; + @computed("pollType", "pollOptionsCount", "multiplePollType") + isMultiple(pollType, count, multiplePollType) { + return (pollType === multiplePollType) && count > 0; }, - @computed("pollType") - isNumber(pollType) { - return pollType === I18n.t("poll.ui_builder.poll_type.number"); + @computed("pollType", "numberPollType") + isNumber(pollType, numberPollType) { + return pollType === numberPollType; }, @computed("isNumber", "isMultiple") diff --git a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 index ccbeb20e9..02c4ad8d0 100644 --- a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 +++ b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 @@ -6,7 +6,7 @@ test("isMultiple", function() { const controller = this.subject(); controller.setProperties({ - pollType: I18n.t("poll.ui_builder.poll_type.multiple"), + pollType: controller.get("multiplePollType"), pollOptionsCount: 1 }); @@ -29,7 +29,7 @@ test("isNumber", function() { equal(controller.get("isNumber"), false, "it should be false"); - controller.set("pollType", I18n.t("poll.ui_builder.poll_type.number")); + controller.set("pollType", controller.get("numberPollType")); equal(controller.get("isNumber"), true, "it should be true"); }); @@ -159,7 +159,7 @@ test("number pollOutput", function() { controller.setProperties({ isNumber: true, - pollType: I18n.t("poll.ui_builder.poll_type.number"), + pollType: controller.get("numberPollType"), pollMin: 1 }); @@ -208,7 +208,7 @@ test("multiple pollOutput", function() { controller.setProperties({ isMultiple: true, - pollType: I18n.t("poll.ui_builder.poll_type.multiple"), + pollType: controller.get("multiplePollType"), pollMin: 1, pollOptions: "1\n2" });