nodebb-plugin-poll 3.0.2 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/poll.js CHANGED
@@ -132,6 +132,9 @@ const Scheduler = require('./scheduler');
132
132
  if (err) {
133
133
  return callback(err);
134
134
  }
135
+ // sort options according to option id. option id are supposed to preseve the order as in Poll.add(),
136
+ // when the user create the poll
137
+ options.sort((a, b) => a - b);
135
138
  async.map(options, (option, next) => {
136
139
  Poll.getOption(pollId, option, withVotes, next);
137
140
  }, callback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-poll",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "NodeBB Poll Plugin",
5
5
  "main": "library.js",
6
6
  "scripts": {
@@ -61,18 +61,21 @@
61
61
  }
62
62
 
63
63
  function composerBtnHandle(composer, textarea) {
64
- require(['composer/controls'], function (controls) {
64
+ require(['composer/controls', 'alerts'], function (controls, alerts) {
65
65
  var post = composer.posts[composer.active];
66
66
  if (!post || !post.isMain || (isNaN(parseInt(post.cid, 10)) && isNaN(parseInt(post.pid, 10)))) {
67
- return app.alertError('[[poll:error.not_main]]');
67
+ return alerts.error('[[poll:error.not_main]]');
68
68
  }
69
69
  if (parseInt(post.cid, 10) === 0) {
70
- return app.alertError('[[error:category-not-selected]]');
70
+ return alerts.error('[[error:category-not-selected]]');
71
71
  }
72
72
 
73
73
  Poll.sockets.canCreate({ cid: post.cid, pid: post.pid }, function (err, canCreate) {
74
- if (err || !canCreate) {
75
- return app.alertError(err.message);
74
+ if (err) {
75
+ return alerts.error(err.message);
76
+ }
77
+ if (!canCreate) {
78
+ return alerts.error('[[error:no-privileges]]');
76
79
  }
77
80
 
78
81
  Poll.sockets.getConfig(null, function (err, config) {
@@ -118,7 +121,7 @@
118
121
 
119
122
  Creator.show = function (poll, config, callback) {
120
123
  if (poll.hasOwnProperty('info')) {
121
- return app.alertError('Editing not implemented.');
124
+ return Poll.alertError('Editing not implemented');
122
125
  }
123
126
 
124
127
  require(['flatpickr', 'flatpickr.i10n', 'bootbox', 'dayjs', 'translator'], function (flatpickr, flatpickrI10N, bootbox, dayjs, Translator) {
@@ -3,6 +3,12 @@
3
3
  window.Poll = {};
4
4
 
5
5
  (function () {
6
+ window.Poll.alertError = function (message) {
7
+ require(['alerts'], function (alerts) {
8
+ alerts.error(message);
9
+ });
10
+ };
11
+
6
12
  require('poll/serializer')(window.utils);
7
13
  $(window).on('action:topic.loading', function () {
8
14
  if (ajaxify.data.posts.length > 0 && ajaxify.data.posts[0].hasOwnProperty('pollId')) {
@@ -22,7 +28,7 @@ window.Poll = {};
22
28
  if (!isNaN(pollId)) {
23
29
  Poll.sockets.getPoll({ pollId: pollId }, function (err, pollData) {
24
30
  if (err) {
25
- return app.alertError(err.message);
31
+ return Poll.alertError(err.message);
26
32
  }
27
33
  Poll.view.load(pollData);
28
34
  });
@@ -28,7 +28,7 @@
28
28
  }
29
29
 
30
30
  if (err) {
31
- return app.alertError(err.message);
31
+ return Poll.alertError(err.message);
32
32
  }
33
33
 
34
34
  view.showResultsPanel();
@@ -58,7 +58,7 @@
58
58
 
59
59
  Poll.sockets.updateVote(voteData, function (err) {
60
60
  if (err) {
61
- return app.alertError(err.message);
61
+ return Poll.alertError(err.message);
62
62
  }
63
63
  view.showResultsPanel();
64
64
  });
@@ -78,7 +78,7 @@
78
78
 
79
79
  Poll.sockets.removeVote(voteData, function (err) {
80
80
  if (err) {
81
- return app.alertError(err.message);
81
+ return Poll.alertError(err.message);
82
82
  }
83
83
  view.showResultsPanel();
84
84
  });
@@ -124,7 +124,7 @@
124
124
  optionId: optionId,
125
125
  }, function (err, details) {
126
126
  if (err) {
127
- return app.alertError(err.message);
127
+ return Poll.alertError(err.message);
128
128
  }
129
129
 
130
130
  view.showOptionDetails(details);