nodebb-plugin-poll 3.2.1 → 3.2.2
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/package.json +1 -1
- package/plugin.json +0 -1
- package/public/js/poll/creator.js +2 -3
- package/public/js/poll/main.js +9 -1
- package/public/js/poll/view.js +15 -14
- package/templates/poll/view/details.tpl +1 -1
- package/public/js/poll/sockets.js +0 -61
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -70,15 +70,14 @@
|
|
|
70
70
|
return alerts.error('[[error:category-not-selected]]');
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
socket.emit('plugins.poll.canCreate', { cid: post.cid, pid: post.pid }, function (err, canCreate) {
|
|
74
74
|
if (err) {
|
|
75
75
|
return alerts.error(err.message);
|
|
76
76
|
}
|
|
77
77
|
if (!canCreate) {
|
|
78
78
|
return alerts.error('[[error:no-privileges]]');
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
Poll.sockets.getConfig(null, function (err, config) {
|
|
80
|
+
socket.emit('plugins.poll.getConfig', null, function (err, config) {
|
|
82
81
|
if (err) {
|
|
83
82
|
return alerts.error(err);
|
|
84
83
|
}
|
package/public/js/poll/main.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
/* global Poll */
|
|
4
|
+
|
|
3
5
|
window.Poll = {};
|
|
4
6
|
|
|
5
7
|
(function () {
|
|
@@ -9,7 +11,9 @@ window.Poll = {};
|
|
|
9
11
|
});
|
|
10
12
|
};
|
|
11
13
|
|
|
14
|
+
// eslint-disable-next-line import/no-unresolved
|
|
12
15
|
require('poll/serializer')(window.utils);
|
|
16
|
+
|
|
13
17
|
$(window).on('action:topic.loading', function () {
|
|
14
18
|
if (ajaxify.data.posts.length > 0 && ajaxify.data.posts[0].hasOwnProperty('pollId')) {
|
|
15
19
|
getPoll(ajaxify.data.posts[0].pollId);
|
|
@@ -30,11 +34,15 @@ window.Poll = {};
|
|
|
30
34
|
}
|
|
31
35
|
});
|
|
32
36
|
|
|
37
|
+
socket.on('event:poll.voteChange', function (data) {
|
|
38
|
+
Poll.view.update(data);
|
|
39
|
+
});
|
|
40
|
+
|
|
33
41
|
function getPoll(pollId) {
|
|
34
42
|
pollId = parseInt(pollId, 10);
|
|
35
43
|
|
|
36
44
|
if (!isNaN(pollId)) {
|
|
37
|
-
|
|
45
|
+
socket.emit('plugins.poll.get', { pollId }, function (err, pollData) {
|
|
38
46
|
if (err) {
|
|
39
47
|
return Poll.alertError(err.message);
|
|
40
48
|
}
|
package/public/js/poll/view.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
options: votes,
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
socket.emit('plugins.poll.vote', voteData, function (err) {
|
|
26
26
|
if (!config.loggedIn) {
|
|
27
27
|
$(window).trigger('action:poll.vote.notloggedin');
|
|
28
28
|
}
|
|
@@ -55,8 +55,7 @@
|
|
|
55
55
|
pollId: view.pollData.info.pollId,
|
|
56
56
|
options: votes,
|
|
57
57
|
};
|
|
58
|
-
|
|
59
|
-
Poll.sockets.updateVote(voteData, function (err) {
|
|
58
|
+
socket.emit('plugins.poll.updateVote', voteData, function (err) {
|
|
60
59
|
if (err) {
|
|
61
60
|
return Poll.alertError(err.message);
|
|
62
61
|
}
|
|
@@ -76,7 +75,7 @@
|
|
|
76
75
|
handle: function (view) {
|
|
77
76
|
var voteData = { pollId: view.pollData.info.pollId };
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
socket.emit('plugins.poll.removeVote', voteData, function (err) {
|
|
80
79
|
if (err) {
|
|
81
80
|
return Poll.alertError(err.message);
|
|
82
81
|
}
|
|
@@ -119,7 +118,7 @@
|
|
|
119
118
|
handle: function (view, e) {
|
|
120
119
|
var optionId = $(e.currentTarget).parents('[data-poll-option-id]').data('poll-option-id');
|
|
121
120
|
|
|
122
|
-
|
|
121
|
+
socket.emit('plugins.poll.getOptionDetails', {
|
|
123
122
|
pollId: view.pollData.info.pollId,
|
|
124
123
|
optionId: optionId,
|
|
125
124
|
}, function (err, details) {
|
|
@@ -140,7 +139,7 @@
|
|
|
140
139
|
});
|
|
141
140
|
},
|
|
142
141
|
handle: function (view) {
|
|
143
|
-
|
|
142
|
+
socket.emit('plugins.poll.getConfig', null, function (err, config) {
|
|
144
143
|
if (err) {
|
|
145
144
|
console.error(err);
|
|
146
145
|
}
|
|
@@ -250,15 +249,17 @@
|
|
|
250
249
|
};
|
|
251
250
|
|
|
252
251
|
View.prototype.showOptionDetails = function (details) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
252
|
+
require(['bootbox'], function (bootbox) {
|
|
253
|
+
app.parseAndTranslate('poll/view/details', details, function (html) {
|
|
254
|
+
bootbox.dialog({
|
|
255
|
+
message: html,
|
|
256
|
+
backdrop: true,
|
|
257
|
+
buttons: {
|
|
258
|
+
close: {
|
|
259
|
+
label: 'Close',
|
|
260
|
+
},
|
|
260
261
|
},
|
|
261
|
-
}
|
|
262
|
+
});
|
|
262
263
|
});
|
|
263
264
|
});
|
|
264
265
|
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
(function (Poll) {
|
|
4
|
-
var messages = [
|
|
5
|
-
{
|
|
6
|
-
method: 'getPoll',
|
|
7
|
-
message: 'plugins.poll.get',
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
method: 'vote',
|
|
11
|
-
message: 'plugins.poll.vote',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
method: 'updateVote',
|
|
15
|
-
message: 'plugins.poll.updateVote',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
method: 'removeVote',
|
|
19
|
-
message: 'plugins.poll.removeVote',
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
method: 'getOptionDetails',
|
|
23
|
-
message: 'plugins.poll.getOptionDetails',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
method: 'getConfig',
|
|
27
|
-
message: 'plugins.poll.getConfig',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
method: 'canCreate',
|
|
31
|
-
message: 'plugins.poll.canCreate',
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
var handlers = [
|
|
36
|
-
{
|
|
37
|
-
event: 'event:poll.voteChange',
|
|
38
|
-
handle: function (data) {
|
|
39
|
-
Poll.view.update(data);
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
function init() {
|
|
45
|
-
handlers.forEach(function (handler) {
|
|
46
|
-
if (socket.listeners(handler.event).length === 0) {
|
|
47
|
-
socket.on(handler.event, handler.handle);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
messages.forEach(function (message) {
|
|
52
|
-
Poll.sockets[message.method] = function (data, callback) {
|
|
53
|
-
socket.emit(message.message, data, callback);
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
Poll.sockets = {};
|
|
59
|
-
|
|
60
|
-
init();
|
|
61
|
-
}(window.Poll));
|