From 3cb8bbb851daba2df857e1345cc809e5e154ddfc Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 5 Jul 2016 22:14:59 +0800 Subject: [PATCH] UX: Automatically generate poll name for poll builder. --- .../discourse/components/d-editor.js.es6 | 1 + .../javascripts/controllers/poll-ui-builder.js.es6 | 13 ++++++++----- .../discourse/templates/modals/poll-ui-builder.hbs | 5 ----- plugins/poll/config/locales/client.en.yml | 3 --- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index 08fc9a552..d26bdb47b 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -487,6 +487,7 @@ export default Ember.Component.extend({ applySurround: (head, tail, exampleKey) => this._applySurround(selected, head, tail, exampleKey), applyList: (head, exampleKey) => this._applyList(selected, head, exampleKey), addText: text => this._addText(selected, text), + getText: () => this.get('value'), }; if (button.sendAction) { 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 f7ccb2395..2a1bd3b86 100644 --- a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 +++ b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 @@ -91,12 +91,17 @@ export default Ember.Controller.extend({ return this._comboboxOptions(1, (parseInt(pollMax) || 1) + 1); }, - @computed("isNumber", "showMinMax", "pollName", "pollType", "publicPoll", "pollOptions", "pollMin", "pollMax", "pollStep") - pollOutput(isNumber, showMinMax, pollName, pollType, publicPoll, pollOptions, pollMin, pollMax, pollStep) { + @computed("isNumber", "showMinMax", "pollType", "publicPoll", "pollOptions", "pollMin", "pollMax", "pollStep") + pollOutput(isNumber, showMinMax, pollType, publicPoll, pollOptions, pollMin, pollMax, pollStep) { let pollHeader = '[poll'; let output = ''; - if (pollName) pollHeader += ` name=${pollName.trim().replace(/\s/g, '-')}`; + const match = this.get("toolbarEvent").getText().match(/\[poll(\s+name=[^\s\]]+)*.*\]/igm); + + if (match) { + pollHeader += ` name=poll${match.length + 1}`; + }; + if (pollType) pollHeader += ` type=${pollType}`; if (pollMin && showMinMax) pollHeader += ` min=${pollMin}`; if (pollMax) pollHeader += ` max=${pollMax}`; @@ -137,8 +142,6 @@ export default Ember.Controller.extend({ _setupPoll() { this.setProperties({ - pollName: '', - pollNamePlaceholder: I18n.t("poll.ui_builder.poll_name.placeholder"), pollType: null, publicPoll: false, pollOptions: '', diff --git a/plugins/poll/assets/javascripts/discourse/templates/modals/poll-ui-builder.hbs b/plugins/poll/assets/javascripts/discourse/templates/modals/poll-ui-builder.hbs index 5177357ab..ed01df734 100644 --- a/plugins/poll/assets/javascripts/discourse/templates/modals/poll-ui-builder.hbs +++ b/plugins/poll/assets/javascripts/discourse/templates/modals/poll-ui-builder.hbs @@ -1,10 +1,5 @@