Merge pull request #2256 from vikhyat/poll-plugin

Poll plugin updates
This commit is contained in:
Sam 2014-04-11 14:07:15 +10:00
commit f628ca3d8d
7 changed files with 26 additions and 19 deletions

View File

@ -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,

View File

@ -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"

View File

@ -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"

View File

@ -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é "

View File

@ -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"

View File

@ -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?

View File

@ -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