diff --git a/plugins/poll/assets/javascripts/poll_ui.js b/plugins/poll/assets/javascripts/poll_ui.js index 2cc8da4c6ba..4e4bc8a560f 100644 --- a/plugins/poll/assets/javascripts/poll_ui.js +++ b/plugins/poll/assets/javascripts/poll_ui.js @@ -1,12 +1,17 @@ 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) { + 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"]; var options = []; @@ -18,6 +23,8 @@ var Poll = Discourse.Model.extend({ })); }); this.set('options', options); + + this.set('closed', json.closed); }, saveVote: function(option) { @@ -29,16 +36,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 +87,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, diff --git a/plugins/poll/config/locales/server.en.yml b/plugins/poll/config/locales/server.en.yml index 143aac27f3d..3a74435068c 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 f4b8e771019..bc6c0bb2a71 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 fc857f72d1a..0372d6abe0f 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 0d92f3bf3ed..096fae740ef 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 5fec9296588..57d8632cf3a 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 1c32d87fb5a..caa1c45236a 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