From 7be7d322ce734470719fff808ce81377983034e1 Mon Sep 17 00:00:00 2001 From: pichalite Date: Fri, 27 May 2016 10:14:14 -0700 Subject: [PATCH] ability to toggle display of subcategories on categories page (#284) * ability to toggle display of subcategories on categories page * settingsv2 --- lib/admin.js | 24 +++++++++++++++++ library.js | 36 +++++++++++++++++++++++++- plugin.json | 8 +++++- templates/admin/plugins/persona.tpl | 17 ++++++++++++ templates/partials/categories/item.tpl | 2 ++ 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 lib/admin.js create mode 100644 templates/admin/plugins/persona.tpl diff --git a/lib/admin.js b/lib/admin.js new file mode 100644 index 0000000..53fd658 --- /dev/null +++ b/lib/admin.js @@ -0,0 +1,24 @@ +'use strict'; +/* globals $, app */ + +define('admin/plugins/persona', ['settings'], function(Settings) { + + var ACP = {}; + + ACP.init = function() { + Settings.load('persona', $('.persona-settings')); + + $('#save').on('click', function() { + Settings.save('persona', $('.persona-settings'), function() { + app.alert({ + type: 'success', + alert_id: 'persona-saved', + title: 'Settings Saved', + message: 'Persona settings saved' + }); + }); + }); + }; + + return ACP; +}); \ No newline at end of file diff --git a/library.js b/library.js index ccc03a9..2d6bd19 100644 --- a/library.js +++ b/library.js @@ -1,9 +1,30 @@ 'use strict'; var S = require.main.require('string'); +var meta = module.parent.require('./meta'); var library = {}; +library.init = function(params, callback) { + var app = params.router; + var middleware = params.middleware; + + app.get('/admin/plugins/persona', middleware.admin.buildHeader, renderAdmin); + app.get('/api/admin/plugins/persona', renderAdmin); + + callback(); +}; + +library.addAdminNavigation = function(header, callback) { + header.plugins.push({ + route: '/plugins/persona', + icon: 'fa-paint-brush', + name: 'Persona Theme' + }); + + callback(null, header); +}; + library.getTeasers = function(data, callback) { data.teasers.forEach(function(teaser) { if (teaser && teaser.content) { @@ -65,4 +86,17 @@ library.defineWidgetAreas = function(areas, callback) { callback(null, areas); }; -module.exports = library; +library.getThemeConfig = function(config, callback) { + + meta.settings.get('persona', function(err, settings) { + config.hideSubCategories = settings.hideSubCategories === 'on'; + }); + + callback(false, config); +}; + +function renderAdmin(req, res, next) { + res.render('admin/plugins/persona', {}); +} + +module.exports = library; \ No newline at end of file diff --git a/plugin.json b/plugin.json index 4fa47f9..d26f5cc 100644 --- a/plugin.json +++ b/plugin.json @@ -3,7 +3,10 @@ "library": "library.js", "hooks": [ { "hook": "filter:teasers.get", "method": "getTeasers" }, - { "hook": "filter:widgets.getAreas", "method": "defineWidgetAreas" } + { "hook": "filter:widgets.getAreas", "method": "defineWidgetAreas" }, + { "hook": "filter:config.get", "method": "getThemeConfig" }, + { "hook": "static:app.load", "method": "init" }, + { "hook": "filter:admin.header.build", "method": "addAdminNavigation" } ], "scripts": [ "lib/persona.js", @@ -11,5 +14,8 @@ "lib/modules/autohidingnavbar.min.js", "lib/modules/slideout.min.js", "lib/client/chats.js" + ], + "acpScripts": [ + "lib/admin.js" ] } \ No newline at end of file diff --git a/templates/admin/plugins/persona.tpl b/templates/admin/plugins/persona.tpl new file mode 100644 index 0000000..d39dd72 --- /dev/null +++ b/templates/admin/plugins/persona.tpl @@ -0,0 +1,17 @@ +
+
Theme Settings
+
+
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/templates/partials/categories/item.tpl b/templates/partials/categories/item.tpl index d6761d3..ca8b467 100644 --- a/templates/partials/categories/item.tpl +++ b/templates/partials/categories/item.tpl @@ -13,7 +13,9 @@ {../descriptionParsed} + {function.generateChildrenCategories} +