Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
{
"id": "nodebb-plugin-slack-extended",
"name": "Slack Integration",
"description": "Posts new posts via Slack webhooks",
"description": "Posts new post via Slack webhooks",
"url": "https://github.com/pichalite/nodebb-plugin-slack-extended.git",
"library": "./library.js",
"hooks": [
{ "hook": "static:app.load", "method": "init" },
{ "hook": "filter:admin.header.build", "method": "adminMenu" },
{ "hook": "action:post.save", "method": "postSave"}
{
"hook": "static:app.load",
"method": "init"
},
{
"hook": "filter:admin.header.build",
"method": "adminMenu"
},
{
"hook": "action:post.save",
"method": "postSave"
}
],
"templates": "./public/templates"
"templates": "./public/templates",
"modules": {
"../admin/plugins/slack.js": "public/admin.js"
}
}
52 changes: 52 additions & 0 deletions public/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* globals app, $, socket, define */

'use strict';

define('admin/plugins/slack', ['settings'], function (settings) {
var Slack = {};

$(document).ready(function() {
var categories = null;

function addOptionsToAllSelects() {
$('.form-control.slack-category').each(function(index, element) {
addOptionsToSelect($(element));
});
}

function addOptionsToSelect(select) {
for(var i=0; i<categories.length; ++i) {
select.append('<option value=' + categories[i].cid + '>' + categories[i].name + '</option>');
}
}

socket.emit('categories.get', function(err, data) {
categories = data;
addOptionsToAllSelects();
});
});

Slack.init = function () {
settings.load('slack', $('.slack-settings'));

$('#save').on('click', function () {
Promise.all([
new Promise((resolve, reject) => {
settings.save('slack', $('.slack-settings'), err => (!err ? resolve() : reject(err)));
}),
]).then(() => {
app.alert({
type: 'success',
alert_id: 'slack-saved',
title: 'Settings Saved',
message: 'Please reload your NodeBB to apply these settings',
clickfn: function() {
socket.emit('admin.reload');
}
});
}).catch(app.alertError);
});
};

return Slack;
});
43 changes: 0 additions & 43 deletions public/templates/admin/plugins/slack.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,3 @@
</div>
</div>
</div>

<script>

$(document).ready(function() {
var categories = null;

function addOptionsToAllSelects() {
$('.form-control.slack-category').each(function(index, element) {
addOptionsToSelect($(element));
});
}

function addOptionsToSelect(select) {
for(var i=0; i<categories.length; ++i) {
select.append('<option value=' + categories[i].cid + '>' + categories[i].name + '</option>');
}
}

socket.emit('categories.get', function(err, data) {
categories = data;
addOptionsToAllSelects();
});

});

require(['settings'], function(Settings) {
Settings.load('slack', $('.slack-settings'));

$('#save').on('click', function() {
Settings.save('slack', $('.slack-settings'), function() {
app.alert({
type: 'success',
alert_id: 'slack-saved',
title: 'Settings Saved',
message: 'Please reload your NodeBB to apply these settings',
clickfn: function() {
socket.emit('admin.reload');
}
});
});
});
});
</script>