From b21d98211e53a4e7ef35d2649ba680b1995321a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobi=20Sch=C3=A4fer?= Date: Sun, 13 May 2012 17:02:09 +0000 Subject: [PATCH] Implemented first basic version of layout option for switching display of skin edit controls, ie. a button that appears next to every editable skin and directly leads to the skin editor when clicked. --- code/Layout/$Layout.skin | 5 ++++ code/Layout/Layout.js | 31 ++++++++++++++++++++++++ code/Root/$Root.skin | 16 +++++++++++++ code/Root/Root.js | 2 +- code/Site/Site.js | 11 +++++---- code/Skin/Skin.js | 11 ++++----- code/User/User.js | 5 ++-- static/www/antville.js | 41 ++++++++++++++++++++++++++++++++ static/www/jquery.cookie.js | 47 +++++++++++++++++++++++++++++++++++++ 9 files changed, 154 insertions(+), 15 deletions(-) create mode 100644 static/www/jquery.cookie.js diff --git a/code/Layout/$Layout.skin b/code/Layout/$Layout.skin index 33e12f03..c0e3bef6 100644 --- a/code/Layout/$Layout.skin +++ b/code/Layout/$Layout.skin @@ -25,9 +25,14 @@ $(function() { ... <% layout.link images <% gettext Images %> %> <% layout.link skins <% gettext Skins %> prefix=" | " %> +<% //layout.link sandbox <% gettext Sandbox %> prefix=" | " %>

+ + + + <% layout.values %> diff --git a/code/Layout/Layout.js b/code/Layout/Layout.js index 76d9a11f..7bf4f108 100644 --- a/code/Layout/Layout.js +++ b/code/Layout/Layout.js @@ -93,6 +93,22 @@ Layout.remove = function(options) { return; } +Layout.sandbox = function(value) { + var cookie = User.COOKIE + 'LayoutSandbox'; + var id = res.handlers.site._id; + if (typeof value === 'undefined') { + return req.cookies[cookie] === id; + } + if (value === true) { + res.setCookie(cookie, id); + //session.data.layout = new Layout; + } else if (value === false) { + res.unsetCookie(cookie); + //delete session.data.layout; + } + return value; +} + /** * @function * @returns {String[]} @@ -140,6 +156,7 @@ Layout.prototype.getPermission = function(action) { case "import": case "reset": case "skins": + case "sandbox": return res.handlers.site.getPermission("main") && Membership.require(Membership.OWNER) || User.require(User.PRIVILEGED); @@ -216,6 +233,9 @@ Layout.prototype.update = function(data) { } res.write("\n"); skin.setSource(res.pop()); + + Layout.sandbox(!!data.sandbox); + this.description = data.description; this.mode = data.mode; this.touch(); @@ -297,6 +317,17 @@ Layout.prototype.import_action = function() { return; } +Layout.prototype.sandbox_action = function() { + Layout.sandbox(!Layout.sandbox()); + res.redirect(req.data.http_referer); + return; +} + +Layout.prototype.sandbox_macro = function() { + res.write(Layout.sandbox()); + return; +} + /** * * @param {String} name diff --git a/code/Root/$Root.skin b/code/Root/$Root.skin index 4e2d5387..4264a4d0 100644 --- a/code/Root/$Root.skin +++ b/code/Root/$Root.skin @@ -274,6 +274,22 @@ div.skin div.title { border: 1px solid #cc0000; } +.layout-sandbox { + height: 22px; +} + +.layout-sandbox div { + position: fixed; + top: 0; + left: 0; + right: 0; + height: 22px; + padding: 0 20px; + background: url('<% root.static sandbox.png %>'); + background-position: 0 23px; + text-align: left; +} + <% #FIXME %>
diff --git a/code/Root/Root.js b/code/Root/Root.js index 10eb2e65..62f68f2e 100644 --- a/code/Root/Root.js +++ b/code/Root/Root.js @@ -191,6 +191,7 @@ Root.prototype.sites_action = function() { } Root.prototype.updates_xml_action = function() { + res.contentType = "text/xml"; var now = new Date; var feed = new rome.SyndFeedImpl(); feed.setFeedType("rss_2.0"); @@ -219,7 +220,6 @@ Root.prototype.updates_xml_action = function() { var output = new rome.SyndFeedOutput(); //output.output(feed, res.servletResponse.writer); return; var xml = output.outputString(feed); - res.contentType = "text/xml"; res.write(xml); //injectXslDeclaration(xml)); return; } diff --git a/code/Site/Site.js b/code/Site/Site.js index d303b386..9acfc0f1 100644 --- a/code/Site/Site.js +++ b/code/Site/Site.js @@ -407,8 +407,9 @@ Site.prototype.main_js_action = function() { res.dependsOn(String(Root.VERSION)); res.digest(); this.renderSkin("$Site#include", - {href:"http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"}); - this.renderSkin("$Site#include", {href: root.getStaticUrl("antville.js?v=1.3")}); + {href:"http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"}); + this.renderSkin("$Site#include", {href: root.getStaticUrl("jquery.cookie.js")}); + this.renderSkin("$Site#include", {href: root.getStaticUrl("antville.js?v=" + Root.VERSION)}); this.renderSkin("$Site#include", {href: this.href("user.js")}); return; } @@ -437,25 +438,25 @@ Site.prototype.backup_js_action = function() { } Site.prototype.rss_xml_action = function() { + res.contentType = "text/xml"; res.dependsOn(this.modified); res.digest(); - res.contentType = "text/xml"; res.write(this.getXml(this.stories.union)); return; } Site.prototype.stories_xml_action = function() { + res.contentType = "text/xml"; res.dependsOn(this.modified); res.digest(); - res.contentType = "text/xml"; res.write(this.getXml(this.stories.recent)); return; } Site.prototype.comments_xml_action = function() { + res.contentType = "text/xml"; res.dependsOn(this.modified); res.digest(); - res.contentType = "text/xml"; res.write(this.getXml(this.stories.comments)); return; } diff --git a/code/Skin/Skin.js b/code/Skin/Skin.js index f64373bc..5e95ea35 100644 --- a/code/Skin/Skin.js +++ b/code/Skin/Skin.js @@ -187,10 +187,7 @@ Skin.prototype.update = function(data) { var macro = "response.body"; if (!createSkin(data.source).containsMacro(macro)) { var macro = ["<%", macro, "%>"].join(String.EMPTY); - throw Error(gettext("The {0} macro is missing. It is essential for accessing the site and must be present in this skin.", - macro)); - //data.source = ["<% // ", gettext("The following macro was automatically added to prevent the site from becoming inacessible."), - // " %>\n<% ", macro, " %>\n\n", data.source].join(String.EMPTY); + throw Error(gettext("The {0} macro is missing. It is essential for accessing the site and must be present in this skin.", macro)); } } this.setSource(data.source); @@ -221,7 +218,7 @@ Skin.prototype.reset_action = function() { Skin.prototype.compare_action = function() { var originalSkin = this.source || String.EMPTY; - var diff = originalSkin.diff(this.getSource()); + var diff = this.getSource().diff(originalSkin); if (!diff) { res.message = gettext("No differences were found."); } else { @@ -230,7 +227,7 @@ Skin.prototype.compare_action = function() { for each (let line in diff) { if (line.deleted) { param.right = encode(line.value); - param.leftStatus = "removed"; + param.leftStatus = "added"; param.rightStatus = ''; for (let i=0; i 0) { + $('.skin-control').remove(); + return; + } + /*$('body').prepend($('
').attr('class', 'layout-sandbox') + .append($('
') + .append($('
Show Controls: is true then checked %>>