Component refactoring.
@@ -31,8 +31,8 @@ <script src="js/vendor/ace/ext-searchbox.js"> </script>
<script src="js/vendor/ace/ext-settings_menu.js"> </script> <script src="js/vendor/ace/ext-statusbar.js"> </script> <script src="js/utils.js"> </script> - <script src="js/components/widgets.js"> </script> <script src="js/models.js"> </script> + <script src="js/components/widgets.js"> </script> <script src="js/components/navbar.js"> </script> <script src="js/components/uploader.js"> </script> <script src="js/components/editor.js"> </script>
@@ -2,6 +2,7 @@ (function(){
'use strict'; var app = window.LS || (window.LS = {}); var u = app.utils; + var w = app.widgets; app.doclist = {};@@ -23,10 +24,10 @@ obj.title = m("a", {href: path+ctrl.id, config: m.route}, [ctrl.id]);
obj.content = m("div", [ m("p", [ctrl.content]), m("p", ctrl.tags.map(function(tag){ - return u.taglink(tag); + return w.taglink({name: tag, key: u.guid()}); })) ]); - return m(".row.search-result", m(".col-md-12", [u.panel(obj)])); + return m(".row.search-result", m(".col-md-12", [w.panel(obj)])); } };@@ -41,15 +42,16 @@ };
app.doclist.view = function(ctrl){ var results = m(".row", [m(".col-md-12", ctrl.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", [u.paginator(ctrl.querydata)]), + m(".row.text-center", [w.paginator(ctrl.querydata)]), results, - m(".row.text-center", [u.paginator(ctrl.querydata)]) + m(".row.text-center", [w.paginator(ctrl.querydata)]) ]); };
@@ -3,7 +3,6 @@ 'use strict';
var app = window.LS || (window.LS = {}); app.editor = {}; - app.editor.config = function(obj){ return function(element, isInitialized, context){ var e = element;@@ -56,8 +55,15 @@ /**
* @param obj * - content The content of the editor */ - app.editor.view = function(obj) { - return m(".editor.panel.panal-default", {config: app.editor.config(obj)}, obj.content); + app.editor.controller = function(args) { + return { + content: args.content, + id: args.id, + readOnly: args.readOnly, + }; + }; + app.editor.view = function(ctrl) { + return m(".editor.panel.panal-default", {config: app.editor.config(ctrl)}, ctrl.content); }; }());
@@ -89,7 +89,7 @@ }
if (ctrl.c_page === 0){ prev = page(0, "«", true); } - if (c_page === ctrl.max_page){ + if (ctrl.c_page === ctrl.max_page){ next = page(ctrl.max_page, "»", true); } pages.push(page(i));@@ -137,13 +137,13 @@ app.widgets.taglink = function(obj){
var taglink = { controller: function(args) { return { - color: /^\$/.test(args.tag) ? "warning" : "primary", - tag: args.tag + color: /^\$/.test(args.name) ? "warning" : "primary", + name: args.name }; }, view: function(ctrl) { return m("span.tag-label.label.label-"+ctrl.color, - [m("i.fa.fa-tag"), " ", m("a", {href: "/tags/"+ctrl.tag, config:m.route}, ctrl.tag)]); + [m("i.fa.fa-tag"), " ", m("a", {href: "/tags/"+ctrl.name, config:m.route}, ctrl.name)]); } }; return m.component(taglink, obj);@@ -167,13 +167,13 @@ app.widgets.tagbutton = function(obj) {
var tagbutton = { controller: function(args){ return { - tag: args.tag, + name: args.tag, n: args.n }; }, view: function(ctrl) { return m("a", {href: "/tags/"+ctrl.tag, config:m.route}, - [m("i.fa.fa-tag"), " "+ctrl.tag+" ", m("span.badge", ctrl.n)]); + [m("i.fa.fa-tag"), " "+ctrl.name+" ", m("span.badge", ctrl.n)]); } }; return m.component(tagbutton, obj);@@ -183,7 +183,7 @@ // Toolbar
app.widgets.toolbar = function(obj) { var toolbar = { controller: function(args){ - return {link: args.links}; + return {links: args.links}; }, view: function(ctrl){ return m("nav.toolbar.btn-group[role='group'][aria-label='...'].pull-right",
@@ -1,7 +1,8 @@
(function(){ 'use strict'; var app = window.LS || (window.LS = {}); - var u = LS.utils; + var u = app.utils; + var w = app.widgets; // Document module app.document = {vm: {}};@@ -178,7 +179,7 @@ // Module main view
app.document.main = function(){ var vm = app.document.vm; var titleLeft = vm.id(); - var titleRight = m("span.pull-right", vm.tags.map(function(t){return u.taglink(t);})); + var titleRight = m("span.pull-right", vm.tags.map(function(t){return w.taglink({name: t, key: u.guid()});})); // Delete confirmation dialog var deleteDialogCfg = { title: "Delete Document",@@ -231,16 +232,16 @@ var panelContent;
if (vm.image){ panelContent = m("div.text-center", [m("img", {src: "/docs/"+vm.id(), title: vm.id()})]); } else { - panelContent = app.editor.view(vm); + panelContent = m.component(app.editor, vm); } var title = m("span",[titleLeft, titleRight]); return m("div", [ vm.uploader.view(), - u.modal(deleteDialogCfg), - u.modal(editTagsDialogCfg), - m(".row", [u.toolbar({links: vm.tools()})]), - m(".row", [u.panel({title: title, content:panelContent})]) + w.modal(deleteDialogCfg), + w.modal(editTagsDialogCfg), + m(".row", [w.toolbar({links: vm.tools()})]), + m(".row", [w.panel({title: title, content:panelContent})]) ]); };
@@ -1,7 +1,8 @@
(function(){ 'use strict'; var app = window.LS || (window.LS = {}); - var u = LS.utils; + var u = app.utils; + var w = app.widgets; // Guide Module app.guide = {vm: {}};@@ -16,7 +17,7 @@ vm.links = app.system.read_only ? m.prop([]) : m.prop([{action: vm.edit, title: "Edit", icon: "edit"}]);
}; app.guide.main = function(){ return m("article.row", [ - u.toolbar({links: app.guide.vm.links()}), + w.toolbar({links: app.guide.vm.links()}), m.trust(app.guide.vm.content()) ]); };
@@ -1,7 +1,8 @@
(function(){ 'use strict'; var app = window.LS || (window.LS = {}); - var u = LS.utils; + var u = app.utils; + var w = app.widgets; // HTMLDoc Module app.htmldoc = {vm: {}};@@ -18,7 +19,7 @@ vm.links = m.prop([{action: vm.view, title: "View Source", icon: "code"}]);
}; app.htmldoc.main = function(){ return m("article.row", [ - u.toolbar({links: app.htmldoc.vm.links()}), + w.toolbar({links: app.htmldoc.vm.links()}), m.trust(app.htmldoc.vm.content()) ]); };
@@ -1,7 +1,8 @@
(function(){ 'use strict'; var app = window.LS || (window.LS = {}); - var u = LS.utils; + var u = app.utils; + var w = app.widgets; // Info Module app.info = {vm: {}};@@ -28,12 +29,12 @@ ])]);
var logo = m(".col-sm-6", [m("img", {src: "images/litestore.png"})]); var taglist = m("ul.list-unstyled", info.tags.map(function(tag){ var key = Object.keys(tag)[0]; - return m("li", [u.tagbutton(key, tag[key])]); + return m("li", [w.tagbutton({tag: key, n: tag[key], key: u.guid()})]); }) ); var v = m(".row", [ - m(".col-md-6", [u.panel({title: "Datastore Information", content: m(".row", [logo,infolist])})]), - m(".col-md-6", [u.panel({title: "Tags", content: taglist})]) + m(".col-md-6", [w.panel({title: "Datastore Information", content: m(".row", [logo, infolist])})]), + m(".col-md-6", [w.panel({title: "Tags", content: taglist})]) ]); return v; };
@@ -71,9 +71,7 @@ * @property vm a view-model (with init function)
* @property main the main view to load */ u.layout = function(mod) { - - mod.controller = mod.controller || function(){ - this.navbar = new app.navbar.controller(); + mod.controller = mod.controller || function(args){ mod.vm.init(); // Display flash if set on previous route mod.vm.flash = m.prop(u.flash());@@ -87,11 +85,10 @@ mod.vm.flashError = function(obj){
mod.vm.showFlash({type: "warning", content: obj.error}); }; }; - mod.view = function(ctrl){ return m("div", [ m(".container", [ - app.navbar.view(ctrl.navbar), + m.component(app.navbar), m("main", [mod.vm.flash(), mod.main()]), m("footer.footer.container.center", [ m("p")])