nodebb-plugin-poll
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -40,3 +40,3 @@ var NodeBB = require('./nodebb'), | ||
db.setObject('poll:' + pollid + ':settings', pollSettings); | ||
db.listAppend('polls', pollid); | ||
db.listAppend('polls', pollid, function(){}); | ||
@@ -43,0 +43,0 @@ //Register poll with a topic and post |
@@ -38,4 +38,6 @@ var XRegExp = require('xregexp').XRegExp, | ||
Utils.app.render('poll/notify', { pollid: data.posts[0]['poll:id'] }, function(err, html) { | ||
data.posts[0].content += html; | ||
return callback(null, data); | ||
NodeBB.translator.translate(html, function(html) { | ||
data.posts[0].content += html; | ||
return callback(null, data); | ||
}); | ||
}); | ||
@@ -42,0 +44,0 @@ } else { |
var NodeBB = {}; | ||
(function(parent) { | ||
NodeBB = { | ||
NodeBB = module.exports = { | ||
db: parent.require('./database'), | ||
@@ -10,9 +10,7 @@ settings: parent.require('./settings'), | ||
topics: parent.require('./topics'), | ||
postTools: parent.require('./postTools'), | ||
pluginSockets: parent.require('./socket.io/plugins'), | ||
adminSockets: parent.require('./socket.io/admin').plugins, | ||
socketIndex: parent.require('./socket.io/index') | ||
socketIndex: parent.require('./socket.io/index'), | ||
translator: parent.require('../public/src/modules/translator') | ||
}; | ||
}(module.parent.parent)); | ||
module.exports = NodeBB; |
@@ -8,2 +8,4 @@ var S = require('string'), | ||
db = NodeBB.db, | ||
fs = module.parent.parent.require('fs'), | ||
path = module.parent.parent.require('path'), | ||
@@ -15,2 +17,3 @@ Config = require('./config'), | ||
pollSettingsRegex = XRegExp('(?<key>.+?)="(?<value>.+?)"', 'g'), | ||
translations, | ||
@@ -167,2 +170,29 @@ pollSettingsMap = { | ||
jobs: {} | ||
}, | ||
loadTranslations: function(){ | ||
Utils.translations = { }; | ||
var languagesPath = path.resolve(__dirname, '../public/language'); | ||
var langs = fs.readdirSync(languagesPath); | ||
for (var l in langs) { | ||
var lang = langs[l], | ||
langPath = languagesPath + '/' + lang; | ||
if (fs.lstatSync(langPath).isDirectory()) { | ||
var files = fs.readdirSync(langPath); | ||
for (var f in files) { | ||
var file = files[f], | ||
filePath = langPath + '/' + file; | ||
if (!fs.lstatSync(filePath).isDirectory() && file.slice(-5) === '.json') { | ||
try { | ||
Utils.translations[langs[l]] = JSON.parse(fs.readFileSync(filePath), 'utf8'); | ||
NodeBB.translator.addTranslation(lang, file.slice(0, -5), Utils.translations[langs[l]]); | ||
}catch (e){ | ||
console.log("Poll: Error reading " + filePath + ": " + e); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@@ -169,0 +199,0 @@ }; |
@@ -23,3 +23,3 @@ var NodeBB = require('./lib/nodebb'), | ||
} | ||
Utils.loadTranslations(); | ||
data.router.get('/admin/poll', data.middleware.admin.buildHeader, renderAdmin); | ||
@@ -26,0 +26,0 @@ data.router.get('/api/admin/poll', renderAdmin); |
{ | ||
"name": "nodebb-plugin-poll", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "NodeBB Poll Plugin", | ||
@@ -30,4 +30,4 @@ "main": "library.js", | ||
"nbbpm": { | ||
"compatibility": "^0.6.0" | ||
"compatibility": "^0.7.0 || ^0.8.0 || ^0.9.0" | ||
} | ||
} |
@@ -32,3 +32,4 @@ { | ||
], | ||
"templates": "./templates" | ||
"templates": "./templates", | ||
"languages": "public/language" | ||
} |
@@ -41,2 +41,3 @@ (function(Poll) { | ||
message: html, | ||
className: 'poll-creator', | ||
buttons: { | ||
@@ -43,0 +44,0 @@ cancel: { |
(function() { | ||
window.Poll = { | ||
load: function(data) { | ||
Poll.sockets.emit.load(data.pollid, function(err, poll) { | ||
load: function(pollid) { | ||
Poll.sockets.emit.load(pollid, function(err, poll) { | ||
if (!err) { | ||
@@ -6,0 +6,0 @@ Poll.view.init(poll, function(pollView) { |
@@ -53,7 +53,18 @@ (function(Poll) { | ||
window.templates.parse('poll/view', poll, callback); | ||
window.templates.parse('poll/view', poll, function(html){ | ||
var plugPath = '/plugins/nodebb-plugin-poll/public', | ||
relPath = config.relative_path; | ||
config.relative_path = plugPath; | ||
require(['translator'], function(translator) { | ||
translator.translate(html, config.userLang, function(translatedHtml) { | ||
callback(translatedHtml); | ||
}); | ||
}); | ||
config.relative_path = relPath; | ||
}); | ||
}, | ||
insertPoll: function(poll, callback) { | ||
View.parsePoll(poll, function(html) { | ||
$('#post-container .post-row[data-index="0"] .post-content').prepend(html); | ||
$('[component="post"][data-index="0"] [component="post/content"]').prepend(html); | ||
callback(); | ||
@@ -81,5 +92,7 @@ }); | ||
var option = poll.options[i], | ||
optionView = pollView.find('#pollResult' + option.id); | ||
optionView = pollView.find('.poll-view-result[data-poll-result="'+option.id+'"]'); | ||
optionView.find('.poll-view-result-percentage').text(option.percentage + '%'); | ||
optionView.find('.poll-view-result-progressbar').css('width', option.percentage + '%'); | ||
optionView.find('.poll-view-result-votecount').text(option.votecount + ' votes'); | ||
} | ||
@@ -111,3 +124,12 @@ }, | ||
window.templates.parse('poll/view/messages', message, function(html) { | ||
pollView.find('.poll-view-messages').html(html).removeClass('hidden'); | ||
var plugPath = '/plugins/nodebb-plugin-poll/public', | ||
relPath = config.relative_path; | ||
config.relative_path = plugPath; | ||
require(['translator'], function(translator) { | ||
translator.translate(html, config.userLang, function(translatedHtml) { | ||
pollView.find('.poll-view-messages').html(translatedHtml).removeClass('hidden'); | ||
}); | ||
}); | ||
config.relative_path = relPath; | ||
}); | ||
@@ -120,3 +142,7 @@ }, | ||
window.templates.parse('poll/view/details', details, function(html) { | ||
bootbox.alert(html); | ||
require(['translator'], function(translator) { | ||
translator.translate(html, config.userLang, function(translatedHtml) { | ||
bootbox.alert(translatedHtml); | ||
}); | ||
}); | ||
}); | ||
@@ -123,0 +149,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
103214
33
1357
1
5