Hiding edit/delete/new buttons in read-only mode.
h3rald h3rald@h3rald.com
Sun, 22 Mar 2015 18:10:17 +0100
5 files changed,
32 insertions(+),
24 deletions(-)
M
app/js/app.js
→
app/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.js
→
app/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.js
→
app/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.js
→
app/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); -}()) +}())