From 8a06430026bd6864ef240694826208623a886e7a Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 30 Jun 2018 23:32:54 +0200 Subject: [PATCH] [mod] refactoring, extract functions --- src/js/yunohost/filters.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/js/yunohost/filters.js b/src/js/yunohost/filters.js index 1fab600a..298168e2 100644 --- a/src/js/yunohost/filters.js +++ b/src/js/yunohost/filters.js @@ -8,27 +8,26 @@ * Filters * */ - app.before(/domains\/add/, function (req){ + + function prefetchDomains(req) { // Preload domains list. req.params.domains = []; req.api('/domains', function(data) { req.params.domains = data.domains; }); - }); - app.before(/apps\/install\//, function (req){ - // Preload domains list. - req.params.domains = []; - req.api('/domains', function(data) { - req.params.domains = data.domains; - }); - }); - app.before(/apps\/install\//, function (req){ + } + + function prefetchUsers(req){ // Preload users lists. req.params.users = []; req.api('/users', function(data) { req.params.users = data.users; }); - }); + } + + app.before(/domains\/add/, prefetchDomains); + app.before(/apps\/install\//, prefetchDomains); + app.before(/apps\/install\//, prefetchUsers); app.before({except: {path: ['#/logout', '#/login', '#/postinstall', '#/postinstall/domain', '#/postinstall/password']}}, function (req) { @@ -45,4 +44,4 @@ app.after(function () {}); -})(); \ No newline at end of file +})();