nodebb-plugin-poll
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -40,2 +40,12 @@ "use strict"; | ||
Plugin.registerFormatting = function(payload, callback) { | ||
payload.options.push({ | ||
name: 'poll', | ||
className: 'fa ' + Config.plugin.icon, | ||
title: '[[poll:creator_title]]' | ||
}); | ||
callback(null, payload); | ||
}; | ||
Plugin.addUserPrivilege = function(privileges, callback) { | ||
@@ -42,0 +52,0 @@ privileges.push('poll:create'); |
{ | ||
"name": "nodebb-plugin-poll", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "NodeBB Poll Plugin", | ||
@@ -5,0 +5,0 @@ "main": "library.js", |
@@ -10,2 +10,3 @@ { | ||
{ "hook": "filter:admin.header.build", "method": "addAdminNavigation" }, | ||
{ "hook": "filter:composer.formatting", "method": "registerFormatting" }, | ||
@@ -12,0 +13,0 @@ { "hook": "filter:privileges.list", "method": "addUserPrivilege" }, |
@@ -7,16 +7,26 @@ "use strict"; | ||
var Creator = {}; | ||
var config; | ||
var composer; | ||
function init() { | ||
$(window).on('action:composer.enhanced', function() { | ||
require(['composer'], function(c) { | ||
composer = c; | ||
c.addButton('fa fa-bar-chart-o', Creator.show); | ||
}); | ||
initComposer(); | ||
}); | ||
} | ||
Creator.show = function(textarea) { | ||
Poll.sockets.canCreate({cid: composer.posts[composer.active].cid}, function(err, canCreate) { | ||
function initComposer() { | ||
require(['composer', 'composer/formatting', 'composer/controls'], function(composer, formatting, controls) { | ||
if (formatting && controls) { | ||
formatting.addButtonDispatch('poll', function(textarea) { | ||
composerBtnHandle(composer, textarea); | ||
}); | ||
} | ||
}); | ||
} | ||
function composerBtnHandle(composer, textarea) { | ||
var post = composer.posts[composer.active]; | ||
if (!post || !post.isMain || !post.cid || isNaN(parseInt(post.cid, 10))) { | ||
return app.alertError('Can only add poll in main post.'); | ||
} | ||
Poll.sockets.canCreate({cid: post.cid}, function(err, canCreate) { | ||
if (err || !canCreate) { | ||
@@ -26,5 +36,3 @@ return app.alertError(err.message); | ||
Poll.sockets.getConfig(null, function(err, c) { | ||
config = c; | ||
Poll.sockets.getConfig(null, function(err, config) { | ||
var poll = {}; | ||
@@ -43,8 +51,25 @@ | ||
showModal(poll, config, textarea); | ||
Creator.show(poll, config, function(data) { | ||
// Anything invalid will be discarded by the serializer | ||
var markup = Poll.serializer.deserialize(data, config); | ||
// Remove any existing poll markup | ||
textarea.value = Poll.serializer.removeMarkup(textarea.value); | ||
// Insert the poll markup at the bottom | ||
if (textarea.value.charAt(textarea.value.length - 1) !== '\n') { | ||
markup = '\n' + markup; | ||
} | ||
textarea.value += markup; | ||
}); | ||
}); | ||
}); | ||
}; | ||
} | ||
function showModal(poll, config, textarea) { | ||
Creator.show = function(poll, config, callback) { | ||
if (poll.hasOwnProperty('info')) { | ||
return app.alertError('Editing not implemented.'); | ||
} | ||
app.parseAndTranslate('poll/creator', { poll: poll, config: config }, function(html) { | ||
@@ -68,3 +93,25 @@ // Initialise modal | ||
callback: function(e) { | ||
return save(e, textarea); | ||
clearErrors(); | ||
var form = $(e.currentTarget).parents('.bootbox').find('#pollCreator'); | ||
var obj = form.serializeObject(); | ||
// Let's be nice and at least show an error if there are no options | ||
obj.options.filter(function(obj) { | ||
return obj.length; | ||
}); | ||
if (obj.options.length == 0) { | ||
return error('[[poll:error.no_options]]'); | ||
} | ||
if (obj.settings.end && !moment(obj.settings.end).isValid()) { | ||
return error('[[poll:error.valid_date]]'); | ||
} else if (obj.settings.end) { | ||
obj.settings.end = moment(obj.settings.end).valueOf(); | ||
} | ||
callback(obj); | ||
return true; | ||
} | ||
@@ -123,41 +170,4 @@ } | ||
}); | ||
} | ||
}; | ||
function save(e, textarea) { | ||
clearErrors(); | ||
var form = $(e.currentTarget).parents('.bootbox').find('#pollCreator'); | ||
var obj = form.serializeObject(); | ||
// Let's be nice and at least show an error if there are no options | ||
obj.options.filter(function(obj) { | ||
return obj.length; | ||
}); | ||
if (obj.options.length == 0) { | ||
return error('[[poll:error.no_options]]'); | ||
} | ||
if (obj.settings.end && !moment(obj.settings.end).isValid()) { | ||
return error('[[poll:error.valid_date]]'); | ||
} else if (obj.settings.end) { | ||
obj.settings.end = moment(obj.settings.end).valueOf(); | ||
} | ||
// Anything invalid will be discarded by the serializer | ||
var markup = Poll.serializer.deserialize(obj, config); | ||
// Remove any existing poll markup | ||
textarea.value = Poll.serializer.removeMarkup(textarea.value); | ||
// Insert the poll markup at the bottom | ||
if (textarea.value.charAt(textarea.value.length - 1) !== '\n') { | ||
markup = '\n' + markup; | ||
} | ||
textarea.value += markup; | ||
return true; | ||
} | ||
function error(message) { | ||
@@ -164,0 +174,0 @@ var errorBox = $('#pollErrorBox'); |
@@ -26,3 +26,4 @@ "use strict"; | ||
votingPanelButton: panel.find('.poll-button-voting'), | ||
resultsPanelButton: panel.find('.poll-button-results') | ||
resultsPanelButton: panel.find('.poll-button-results'), | ||
editButton: panel.find('.poll-button-edit') | ||
}; | ||
@@ -219,2 +220,19 @@ | ||
} | ||
}, | ||
{ | ||
// Editing | ||
register: function(view) { | ||
var self = this; | ||
view.dom.editButton.off('click').on('click', function() { | ||
self.handle(view); | ||
}); | ||
}, | ||
handle: function(view) { | ||
console.log(view.pollData); | ||
Poll.sockets.getConfig(null, function(err, config) { | ||
Poll.creator.show(view.pollData, config, function(data) { | ||
console.log(data); | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -221,0 +239,0 @@ ]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
187425
1985