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
:
