all repos — litestore @ 9678e675d320fb2ba6d09d35728d42c443be6faf

A minimalist nosql document store.

Hiding edit/delete/new buttons in read-only mode.
h3rald h3rald@h3rald.com
Sun, 22 Mar 2015 18:10:17 +0100
commit

9678e675d320fb2ba6d09d35728d42c443be6faf

parent

c8cd1088eb40ed442c48cb6fd3305334284d851a

M app/js/app.jsapp/js/app.js

@@ -3,15 +3,21 @@ 'use strict';

var app = window.LS || (window.LS = {}); app.flash = m.prop(); - - m.route.mode = "hash"; + app.system = m.prop(); + app.init = function(info){ + app.system(info); + console.log(app.system()); + m.route.mode = "hash"; - m.route(document.body, "/info", { - '/info': app.info, - "/tags/:id": app.tags, - "/document/:action/:id...": app.document, - "/guide/:id": app.guide, - "/new": app.create, - "/search": app.search - }); + m.route(document.body, "/info", { + '/info': app.info, + "/tags/:id": app.tags, + "/document/:action/:id...": app.document, + "/guide/:id": app.guide, + "/new": app.create, + "/search": app.search + }); + }; + Info.get().then(app.init); + }());
M app/js/modules/document.jsapp/js/modules/document.js

@@ -93,6 +93,9 @@ vm.viewDocument();

} }; vm.tools = function(){ + if (app.system().read_only) { + return []; + } switch (vm.action){ case "view": return [
M app/js/modules/guide.jsapp/js/modules/guide.js

@@ -12,7 +12,7 @@ vm.content = Page.get(vm.id()).then(function(content){return content}, vm.flashError);

vm.edit = function(){ m.route("/document/edit/app/md/"+vm.id()+".md"); }; - vm.links = m.prop([{action: vm.edit, title: "Edit", icon: "edit"}]); + 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", [
M app/js/modules/info.jsapp/js/modules/info.js

@@ -5,13 +5,9 @@ var u = LS.utils;

// Info Module app.info = {vm: {}}; - app.info.vm.init = function() { - var vm = this; - vm.content = Info.get().then(function(info){return info;}, vm.flashError); - }; + app.info.vm.init = function() {}; app.info.main = function(){ - var vm = app.info.vm; - var info = vm.content(); + var info = app.system(); var infolist = m("dl", [ m("dt", "Version"), m("dd", info.version),

@@ -39,4 +35,4 @@ return v;

}; u.layout(app.info); -}()) +}())
M app/js/navbar.jsapp/js/navbar.js

@@ -31,14 +31,17 @@ }

}, view: function(ctrl){ var vm = app.navlinks.vm; - return m("ul.nav.navbar-nav", [ + var links = [ m("li", {class: vm.activelink("info")}, [m("a", {href: "/info", config: m.route}, [m("i.fa.fa-info-circle"), " Info"])]), u.dropdown({title: "Guide", icon:"fa-book", links: vm.guidelinks, active: vm.activelink("guide")}), - u.dropdown({title: "Tags", icon:"fa-tag", links: vm.taglinks(vm.info()), active: vm.activelink("tags")}), - m("li", {class: vm.activelink("new")}, [m("a", {href: "/document/create/", config: m.route}, - [m("i.fa.fa-plus-circle"), " New"])]) - ]); + u.dropdown({title: "Tags", icon:"fa-tag", links: vm.taglinks(vm.info()), active: vm.activelink("tags")})]; + if (!app.system().read_only) { + links.push(m("li", + {class: vm.activelink("new")}, [m("a", {href: "/document/create/", config: m.route}, + [m("i.fa.fa-plus-circle"), " New"])])); + } + return m("ul.nav.navbar-nav", links); } };

@@ -122,4 +125,4 @@ ])

]); } }; -}()); +}());