Refactored search and Doclist component.
h3rald h3rald@h3rald.com
Sat, 16 May 2015 13:15:35 +0200
4 files changed,
38 insertions(+),
37 deletions(-)
M
admin/js/components/doclist.js
→
admin/js/components/doclist.js
@@ -9,21 +9,22 @@
// Subcomponent app.doclist.panel = { - controller: function(args){ - return { - id: args.id, - tags: args.tags, - content: args.content - }; - }, - - view: function(ctrl){ + /** + * @typedef {Object} DoclistPanelConfig + * @prop {string} id + * @prop {string[]} tags + * @prop {string} content + * + * @param {Function} ctrl + * @param {DoclistPanelConfig} args + */ + view: function(ctrl, args){ var obj = {}; - var path = (ctrl.id.match(/\.html?$/)) ? "/html/" : "/document/view/"; - obj.title = m("a", {href: path+ctrl.id, config: m.route}, [ctrl.id]); + var path = (args.id.match(/\.html?$/)) ? "/html/" : "/document/view/"; + obj.title = m("a", {href: path+args.id, config: m.route}, [args.id]); obj.content = m("div", [ - m("p", [ctrl.content]), - m("p", ctrl.tags.map(function(tag){ + m("p", [args.content]), + m("p", args.tags.map(function(tag){ return w.taglink({name: tag, key: u.guid()}); })) ]);@@ -31,28 +32,27 @@ return m(".row.search-result", m(".col-md-12", [w.panel(obj)]));
} }; - app.doclist.controller = function(args){ - return { - items: args.items, - title: args.title, - subtitle: args.subtitle, - querydata: args.querydata - }; - }; - - app.doclist.view = function(ctrl){ - var results = m(".row", [m(".col-md-12", ctrl.items.map(function(item){ + /** + * @param {Function} ctrl + * @param {Object} args + * @param {string} args.title + * @param {string} args.subtitle + * @param {array.} args.items + * @param {PaginatorConfig} args.querydata + */ + app.doclist.view = function(ctrl, args){ + var results = m(".row", [m(".col-md-12", args.items.map(function(item){ item.key = u.guid(); return m.component(app.doclist.panel, item); }))]); return m("section", [ - m(".row", [ctrl.title]), - m(".row", [ctrl.subtitle]), - m(".row.text-center", [w.paginator(ctrl.querydata)]), + m(".row", [args.title]), + m(".row", [args.subtitle]), + m(".row.text-center", [w.paginator(args.querydata)]), results, - m(".row.text-center", [w.paginator(ctrl.querydata)]) + m(".row.text-center", [w.paginator(args.querydata)]) ]); }; -}());+}());
M
admin/js/components/widgets.js
→
admin/js/components/widgets.js
@@ -37,12 +37,14 @@ return m.component(panel, obj);
}; /** + * @typedef {Object} PaginatorConfig + * @prop {string} baseurl + * @prop {int} total + * @prop {int} limit + * @prop {int} offset + * * Creates a Paginator component. - * @param {Object} obj - * @param {string} obj.baseurl - * @param {int} obj.total - * @param {int} obj.limit - * @param {int} obj.offset + * @param {PaginatorConfig} obj */ app.widgets.paginator = function(obj) { var paginator = {
M
admin/js/modules/search.js
→
admin/js/modules/search.js
@@ -36,4 +36,4 @@ };
u.layout(app.search); -}());+}());