From edbbf7ffbb0cf573527261a7574cdb8fd8426fa3 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati <vikhyatk@gmail.com> Date: Fri, 11 Apr 2014 08:13:02 +0530 Subject: [PATCH 1/3] Switch the awkward poll.post.poll_details.closed to poll.closed. --- plugins/poll/assets/javascripts/poll_ui.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/poll/assets/javascripts/poll_ui.js b/plugins/poll/assets/javascripts/poll_ui.js index 2cc8da4c6..2314edd18 100644 --- a/plugins/poll/assets/javascripts/poll_ui.js +++ b/plugins/poll/assets/javascripts/poll_ui.js @@ -1,12 +1,13 @@ var Poll = Discourse.Model.extend({ post: null, options: [], + closed: false, postObserver: function() { - this.updateOptionsFromJson(this.get('post.poll_details')); + this.updateFromJson(this.get('post.poll_details')); }.observes('post.poll_details'), - updateOptionsFromJson: function(json) { + updateFromJson: function(json) { var selectedOption = json["selected"]; var options = []; @@ -18,6 +19,8 @@ var Poll = Discourse.Model.extend({ })); }); this.set('options', options); + + this.set('closed', json.closed); }, saveVote: function(option) { @@ -29,16 +32,16 @@ var Poll = Discourse.Model.extend({ type: "PUT", data: {post_id: this.get('post.id'), option: option} }).then(function(newJSON) { - this.updateOptionsFromJson(newJSON); + this.updateFromJson(newJSON); }.bind(this)); } }); var PollController = Discourse.Controller.extend({ poll: null, - showResults: Em.computed.oneWay('poll.post.poll_details.closed'), + showResults: Em.computed.oneWay('poll.closed'), - disableRadio: Em.computed.any('poll.post.poll_details.closed', 'loading'), + disableRadio: Em.computed.any('poll.closed', 'loading'), actions: { selectOption: function(option) { @@ -80,7 +83,7 @@ function initializePollView(self) { var pollDetails = post.get('poll_details'); var poll = Poll.create({post: post}); - poll.updateOptionsFromJson(pollDetails); + poll.updateFromJson(pollDetails); var pollController = PollController.create({ poll: poll, From 2928ce6ca15b89a958e9d62db20cc2febda2386b Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati <vikhyatk@gmail.com> Date: Fri, 11 Apr 2014 08:41:37 +0530 Subject: [PATCH 2/3] Remove the colon from the poll prefix, drop regex support. This is needed to make it possible to programmatically toggle between open and closed polls. --- plugins/poll/config/locales/server.en.yml | 4 ++-- plugins/poll/config/locales/server.es.yml | 4 ++-- plugins/poll/config/locales/server.fr.yml | 4 ++-- plugins/poll/config/locales/server.it.yml | 4 ++-- plugins/poll/poll.rb | 2 +- plugins/poll/spec/poll_plugin/poll_spec.rb | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/poll/config/locales/server.en.yml b/plugins/poll/config/locales/server.en.yml index 143aac27f..3a7443506 100644 --- a/plugins/poll/config/locales/server.en.yml +++ b/plugins/poll/config/locales/server.en.yml @@ -13,5 +13,5 @@ en: must_contain_poll_options: "must contain a list of poll options" cannot_have_modified_options: "cannot be modified after the first five minutes. Contact a moderator if you need to change them." cannot_add_or_remove_options: "can only be edited, not added or removed. If you need to add or remove options you should lock this topic and create a new one." - prefix: "Poll:" - closed_prefix: "Closed Poll:" + prefix: "Poll" + closed_prefix: "Closed Poll" diff --git a/plugins/poll/config/locales/server.es.yml b/plugins/poll/config/locales/server.es.yml index f4b8e7710..bc6c0bb2a 100644 --- a/plugins/poll/config/locales/server.es.yml +++ b/plugins/poll/config/locales/server.es.yml @@ -13,5 +13,5 @@ es: must_contain_poll_options: "debe que contener una lista con las respuestas de la encuesta" cannot_have_modified_options: "no se pueden modificar las respuestas de la encuesta pasados 5 minutos" cannot_add_or_remove_options: "solo se puede modificar, no se pueden añadir o quitar. Si necesitas añadir o quitar respuestas debes bloquear este tema y crear una encuesta nueva." - prefix: "Encuesta:" - closed_prefix: "Encuesta Cerrada:" + prefix: "Encuesta" + closed_prefix: "Encuesta Cerrada" diff --git a/plugins/poll/config/locales/server.fr.yml b/plugins/poll/config/locales/server.fr.yml index fc857f72d..0372d6abe 100644 --- a/plugins/poll/config/locales/server.fr.yml +++ b/plugins/poll/config/locales/server.fr.yml @@ -19,5 +19,5 @@ fr: must_contain_poll_options: "doit contenir une liste d'options pour le sondage" cannot_have_modified_options: "ne peuvent pas être modifiés après 5 minutes. Merci de contacter un moderateur, si vous souhaitez les modifier" cannot_add_or_remove_options: "peuvent seulement être modifiés. Si vous souhaitez en supprimer ou en ajouter, veuillez créer un nouveau sujet." - prefix: "Sondage\\s?:" - closed_prefix: "Sondage fermé\\s?:" + prefix: "Sondage " + closed_prefix: "Sondage fermé " diff --git a/plugins/poll/config/locales/server.it.yml b/plugins/poll/config/locales/server.it.yml index 0d92f3bf3..096fae740 100644 --- a/plugins/poll/config/locales/server.it.yml +++ b/plugins/poll/config/locales/server.it.yml @@ -13,5 +13,5 @@ it: must_contain_poll_options: "deve contenere una lista di opzioni per il sondaggio" cannot_have_modified_options: "non possono essere modificate dopo i primi cinque minuti. Contatta un moderatore se hai bisogno di cambiarle." cannot_add_or_remove_options: "non possono essere modificate, aggiunte o rimosse. Se vuoi aggiungere o rimuovere opzioni al sondaggio, devi bloccare questo topice crearne uno nuovo." - prefix: "Sondaggio:" - closed_prefix: "Sondaggio Chiuso:" + prefix: "Sondaggio" + closed_prefix: "Sondaggio Chiuso" diff --git a/plugins/poll/poll.rb b/plugins/poll/poll.rb index 5fec92965..57d8632cf 100644 --- a/plugins/poll/poll.rb +++ b/plugins/poll/poll.rb @@ -21,7 +21,7 @@ module ::PollPlugin return false end - topic.title =~ /^(#{I18n.t('poll.prefix')}|#{I18n.t('poll.closed_prefix')})/i + topic.title =~ /^(#{I18n.t('poll.prefix').strip}|#{I18n.t('poll.closed_prefix').strip})\s?:/i end def has_poll_details? diff --git a/plugins/poll/spec/poll_plugin/poll_spec.rb b/plugins/poll/spec/poll_plugin/poll_spec.rb index 1c32d87fb..caa1c4523 100644 --- a/plugins/poll/spec/poll_plugin/poll_spec.rb +++ b/plugins/poll/spec/poll_plugin/poll_spec.rb @@ -14,12 +14,12 @@ describe PollPlugin::Poll do expect(poll.is_poll?).to be_false end - it "allows the prefix translation to contain regular expressions" do - topic.title = "Poll : This might be a poll" + it "strips whitespace from the prefix translation" do + topic.title = "Polll: This might be a poll" topic.save expect(PollPlugin::Poll.new(post).is_poll?).to be_false - I18n.expects(:t).with('poll.prefix').returns("Poll\\s?:") - I18n.expects(:t).with('poll.closed_prefix').returns("Closed Poll\\s?:") + I18n.expects(:t).with('poll.prefix').returns("Polll ") + I18n.expects(:t).with('poll.closed_prefix').returns("Closed Poll ") expect(PollPlugin::Poll.new(post).is_poll?).to be_true end From edfea2f801ddb8bc82840938d355bd5a175a2bb1 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati <vikhyatk@gmail.com> Date: Fri, 11 Apr 2014 09:05:07 +0530 Subject: [PATCH 3/3] Update poll when title is changed. --- plugins/poll/assets/javascripts/poll_ui.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/poll/assets/javascripts/poll_ui.js b/plugins/poll/assets/javascripts/poll_ui.js index 2314edd18..4e4bc8a56 100644 --- a/plugins/poll/assets/javascripts/poll_ui.js +++ b/plugins/poll/assets/javascripts/poll_ui.js @@ -7,6 +7,10 @@ var Poll = Discourse.Model.extend({ this.updateFromJson(this.get('post.poll_details')); }.observes('post.poll_details'), + fetchNewPostDetails: function() { + this.get('post.topic.postStream').triggerChangedPost(this.get('post.id'), this.get('post.topic.updated_at')); + }.observes('post.topic.title'), + updateFromJson: function(json) { var selectedOption = json["selected"];