Getting a list of all categories on ACP plugin settings
-
How do I display in ACP plugin settings all categories so the user can select them manually, in order to then automatically post a topic in all of them (for example, using the hook
filter:post.create
)?For example, like
nodebb-plugin-question-and-answer
does: -
Have you tried looking at what Q&A does? The source is here
-
I already have the list with all categories, but now I want the function I have in the
/static/lib/main.js
file to run only on the categories I selected on the plugin settings page (those settings are stored in the/library.js
file).Can I do this or do I have to move that function to the
/library.js
file too?
static/lib/main.js
:"use strict"; $(window).on('action:ajaxify.end', function(ev) { var CategoriesIds = [28,29]; // I want to change this to fetch the categories selected from the plugin's settings page // instead of using the array above, to prevent the user having to modify the plugin files // to change the ID of the categories if( $.inArray( parseInt(ajaxify.data.cid, 10) , CategoriesIds) != -1){ runFunction(); } });
/library.js
:plugin.init = function (params, callback) { var app = params.router; var middleware = params.middleware; app.get('/admin/plugins/myPlugin', middleware.admin.buildHeader, renderAdmin); app.get('/api/admin/plugins/myPlugin', renderAdmin); handleSocketIO(); meta.settings.get('myPlugin', function (err, settings) { if (err) { return callback(err); } plugin._settings = settings; callback(); }); }; plugin.appendConfig = function (config, callback) { config['myPlugin'] = plugin._settings; setImmediate(callback, null, config); }; function renderAdmin(req, res, next) { async.waterfall([ async.apply(db.getSortedSetRange, 'categories:cid', 0, -1), function (cids, next) { categories.getCategoriesFields(cids, ['cid', 'name'], next); }, ], function (err, data) { if (err) { return next(err); } res.render('admin/plugins/myPlugin', { categories: data, }); }); } module.exports = plugin;
Plugin config page on ACP
: -
It depends on what you hope to accomplish. Some things can only be done on the server, some things can only be done on the client, some things can be done on both but are easier on one or the other.
Without knowing what
runFunction()
does I can't really advise. -
I can tell u what runFunction() is, I just simplified it for a better understanding.
Because what I just to replace is this conditionif( $.inArray( parseInt(ajaxify.data.cid, 10) , CategoriesIds) != -1)
instead of going search if the current category is on the arrayCategoriesIds
above (hardcoded), I need to check if the current category is on the selection made by the user on the plugin config page.And I'm not realizing how I make that connection between the plugin settings and the function.
I don't know if I'm making sense to you, but here is the repository with all the code: https://github.com/jtsimoes/nodebb-plugin-nsfw