summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2009-12-11 18:58:12 +0000
committerChristopher Lenz <cmlenz@apache.org>2009-12-11 18:58:12 +0000
commitf6447a3f18a3a1ee51cd488af7e65b51f10c0131 (patch)
treeccfed74c72275196b4cc32745e24fe3b4bd0230a /share
parent908f1a6068f6a055b15790289643d0e0a53f53a2 (diff)
Futon: Improve storage of session state by storing short-term settings in the window.name.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@889766 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share')
-rw-r--r--share/Makefile.am1
-rw-r--r--share/www/config.html1
-rw-r--r--share/www/couch_tests.html1
-rw-r--r--share/www/custom_test.html1
-rw-r--r--share/www/database.html22
-rw-r--r--share/www/document.html1
-rw-r--r--share/www/index.html5
-rw-r--r--share/www/replicator.html1
-rw-r--r--share/www/script/futon.browse.js39
-rw-r--r--share/www/script/futon.js121
-rw-r--r--share/www/script/jquery.cookies.js50
-rw-r--r--share/www/status.html7
12 files changed, 151 insertions, 99 deletions
diff --git a/share/Makefile.am b/share/Makefile.am
index 0d5e585e..e32f09c3 100644
--- a/share/Makefile.am
+++ b/share/Makefile.am
@@ -84,7 +84,6 @@ nobase_dist_localdata_DATA = \
www/script/futon.browse.js \
www/script/futon.format.js \
www/script/futon.js \
- www/script/jquery.cookies.js \
www/script/jquery.couch.js \
www/script/jquery.dialog.js \
www/script/jquery.editinline.js \
diff --git a/share/www/config.html b/share/www/config.html
index 53e52c4a..f324c923 100644
--- a/share/www/config.html
+++ b/share/www/config.html
@@ -20,7 +20,6 @@ specific language governing permissions and limitations under the License.
<link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">
<script src="script/json2.js"></script>
<script src="script/jquery.js?1.3.2"></script>
- <script src="script/jquery.cookies.js?0.11.0"></script>
<script src="script/jquery.couch.js?0.11.0"></script>
<script src="script/jquery.editinline.js?0.11.0"></script>
<script src="script/futon.js?0.11.0"></script>
diff --git a/share/www/couch_tests.html b/share/www/couch_tests.html
index 9064a88d..d34e3f8c 100644
--- a/share/www/couch_tests.html
+++ b/share/www/couch_tests.html
@@ -20,7 +20,6 @@ specific language governing permissions and limitations under the License.
<link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">
<script src="script/json2.js"></script>
<script src="script/jquery.js?1.3.2"></script>
- <script src="script/jquery.cookies.js?0.11.0"></script>
<script src="script/jquery.couch.js?0.11.0"></script>
<script src="script/couch.js?0.11.0"></script>
<script src="script/futon.js?0.11.0"></script>
diff --git a/share/www/custom_test.html b/share/www/custom_test.html
index 41d1a4a1..21d33ea5 100644
--- a/share/www/custom_test.html
+++ b/share/www/custom_test.html
@@ -20,7 +20,6 @@ specific language governing permissions and limitations under the License.
<link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">
<script src="script/json2.js"></script>
<script src="script/jquery.js?1.3.2"></script>
- <script src="script/jquery.cookies.js?0.11.0"></script>
<script src="script/jquery.couch.js?0.11.0"></script>
<script src="script/jquery.resizer.js?0.11.0"></script>
<script src="script/couch.js?0.11.0"></script>
diff --git a/share/www/database.html b/share/www/database.html
index c44d83fc..a4dedfcf 100644
--- a/share/www/database.html
+++ b/share/www/database.html
@@ -20,7 +20,6 @@ specific language governing permissions and limitations under the License.
<link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">
<script src="script/json2.js"></script>
<script src="script/jquery.js?1.3.2"></script>
- <script src="script/jquery.cookies.js?0.11.0"></script>
<script src="script/jquery.couch.js?0.11.0"></script>
<script src="script/jquery.dialog.js?0.11.0"></script>
<script src="script/jquery.resizer.js?0.11.0"></script>
@@ -70,13 +69,10 @@ specific language governing permissions and limitations under the License.
horizontal: true
});
- // Restore preferences/state from cookies
- var desc = $.cookies.get(page.db.name + ".desc");
- if (desc) $("#documents thead th.key").addClass("desc");
- var reduce = $.cookies.get(page.db.name + ".doreduce");
- $("#reduce :checkbox")[0].checked = reduce;
- var rowsPerPage = $.cookies.get(page.db.name + ".perpage");
- if (rowsPerPage) $("#perpage").val(rowsPerPage);
+ // Restore preferences/state
+ $("#documents thead th.key").toggleClass("desc", $.futon.storage.get("desc"));
+ $("#reduce :checkbox")[0].checked = $.futon.storage.get("reduce");
+ $("#perpage").val($.futon.storage.get("per_page"));
page.populateViewsMenu();
page.populateViewEditor();
@@ -87,7 +83,7 @@ specific language governing permissions and limitations under the License.
$("#switch select").change(function() {
var viewName = $(this).val();
- if (!viewName) $.cookies.remove(page.db.name + ".view");
+ if (!viewName) $.futon.storage.del("view");
location.href = "?" + encodeURIComponent(page.db.name) +
(viewName ? "/" + viewName : "");
});
@@ -97,15 +93,11 @@ specific language governing permissions and limitations under the License.
});
$("#reduce :checkbox").click(function() {
page.updateDocumentListing();
- if (this.checked) {
- $.cookies.set(page.db.name + ".doreduce", "1");
- } else {
- $.cookies.remove(page.db.name + ".doreduce");
- }
+ $.futon.storage.set("reduce", this.checked);
});
$("#perpage").change(function() {
page.updateDocumentListing();
- $.cookies.set(page.db.name + ".perpage", this.value);
+ $.futon.storage.set("per_page", this.value);
});
$("#toolbar button.add").click(page.newDocument);
$("#toolbar button.compact").click(page.compactDatabase);
diff --git a/share/www/document.html b/share/www/document.html
index 57d458d4..2202f170 100644
--- a/share/www/document.html
+++ b/share/www/document.html
@@ -20,7 +20,6 @@ specific language governing permissions and limitations under the License.
<link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">
<script src="script/json2.js"></script>
<script src="script/jquery.js?1.3.2"></script>
- <script src="script/jquery.cookies.js?0.11.0"></script>
<script src="script/jquery.couch.js?0.11.0"></script>
<script src="script/jquery.dialog.js?0.11.0"></script>
<script src="script/jquery.editinline.js?0.11.0"></script>
diff --git a/share/www/index.html b/share/www/index.html
index 3255767f..8115bc4d 100644
--- a/share/www/index.html
+++ b/share/www/index.html
@@ -20,7 +20,6 @@ specific language governing permissions and limitations under the License.
<link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">
<script src="script/json2.js"></script>
<script src="script/jquery.js?1.3.2"></script>
- <script src="script/jquery.cookies.js?0.11.0"></script>
<script src="script/jquery.couch.js?0.11.0"></script>
<script src="script/jquery.dialog.js?0.11.0"></script>
<script src="script/futon.js?0.11.0"></script>
@@ -34,11 +33,11 @@ specific language governing permissions and limitations under the License.
this.updateSelection(location.pathname + "index.html");
});
}
- var dbsPerPage = $.cookies.get("perpage");
+ var dbsPerPage = $.futon.storage.get("per_page");
if (dbsPerPage) $("#perpage").val(dbsPerPage);
$("#perpage").change(function() {
page.updateDatabaseListing();
- $.cookies.set("perpage", this.value);
+ $.futon.storage.set("per_page", this.value);
});
page.updateDatabaseListing();
diff --git a/share/www/replicator.html b/share/www/replicator.html
index d5873d3c..3516128d 100644
--- a/share/www/replicator.html
+++ b/share/www/replicator.html
@@ -20,7 +20,6 @@ specific language governing permissions and limitations under the License.
<link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">
<script src="script/json2.js"></script>
<script src="script/jquery.js?1.3.2"></script>
- <script src="script/jquery.cookies.js?0.11.0"></script>
<script src="script/jquery.couch.js?0.11.0"></script>
<script src="script/futon.js?0.11.0"></script>
<script>
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js
index 76084d64..37f4ef08 100644
--- a/share/www/script/futon.browse.js
+++ b/share/www/script/futon.browse.js
@@ -18,6 +18,8 @@
CouchIndexPage: function() {
page = this;
+ $.futon.storage.declare("per_page", {defaultValue: 10});
+
this.addDatabase = function() {
$.showDialog("dialog/_create_database.html", {
submit: function(data, callback) {
@@ -95,11 +97,22 @@
CouchDatabasePage: function() {
var urlParts = location.search.substr(1).split("/");
var dbName = decodeURIComponent(urlParts.shift());
+
+ $.futon.storage.declareWithPrefix(dbName + ".", {
+ desc: {},
+ language: {defaultValue: "javascript"},
+ map_fun: {},
+ reduce_fun: {},
+ reduce: {},
+ per_page: {defaultValue: 10},
+ view: {defaultValue: ""}
+ });
+
var viewName = (urlParts.length > 0) ? urlParts.join("/") : null;
if (viewName) {
- $.cookies.set(dbName + ".view", viewName);
+ $.futon.storage.set("view", viewName);
} else {
- viewName = $.cookies.get(dbName + ".view", "");
+ viewName = $.futon.storage.get("view");
if (viewName) {
this.redirecting = true;
location.href = "database.html?" + encodeURIComponent(dbName) +
@@ -204,10 +217,10 @@
});
$("#grouptruenotice").show();
} else if (viewName == "_temp_view") {
- page.viewLanguage = $.cookies.get(db.name + ".language", page.viewLanguage);
+ page.viewLanguage = $.futon.storage.get("language");
page.updateViewEditor(
- $.cookies.get(db.name + ".map", templates[page.viewLanguage]),
- $.cookies.get(db.name + ".reduce", "")
+ $.futon.storage.get("map", templates[page.viewLanguage]),
+ $.futon.storage.get("reduce")
);
$("#grouptruenotice").show();
} else {
@@ -312,13 +325,13 @@
db.openDoc("_design/" + designDocId, {
error: function(status, error, reason) {
if (status == 404) {
- $.cookies.remove(dbName + ".view");
+ $.futon.storage.del("view");
location.href = "database.html?" + encodeURIComponent(db.name);
}
},
success: function(resp) {
if(!resp.views || !resp.views[localViewName]) {
- $.cookies.remove(dbName + ".view");
+ $.futon.storage.del("view");
location.href = "database.html?" + encodeURIComponent(db.name);
}
var viewCode = resp.views[localViewName];
@@ -512,10 +525,10 @@
if ($("#documents thead th.key").is(".desc")) {
if (typeof options.descending == 'undefined') options.descending = true;
var descend = true;
- $.cookies.set(dbName + ".desc", "1");
+ $.futon.storage.set("desc", "1");
} else {
var descend = false;
- $.cookies.remove(dbName + ".desc");
+ $.futon.storage.del("desc");
}
$("#paging a").unbind();
$("#documents").find("tbody.content").empty().end().show();
@@ -641,19 +654,19 @@
if (viewName == "_temp_view") {
$("#viewcode").show().removeClass("collapsed");
var mapFun = $("#viewcode_map").val();
- $.cookies.set(db.name + ".map", mapFun);
+ $.futon.storage.set("map_fun", mapFun);
var reduceFun = $.trim($("#viewcode_reduce").val()) || null;
if (reduceFun) {
- $.cookies.set(db.name + ".reduce", reduceFun);
+ $.futon.storage.set("reduce_fun", reduceFun);
if ($("#reduce :checked").length) {
options.group = true;
} else {
options.reduce = false;
}
} else {
- $.cookies.remove(db.name + ".reduce");
+ $.futon.storage.del("reduce");
}
- $.cookies.set(db.name + ".language", page.viewLanguage);
+ $.futon.storage.set("language", page.viewLanguage);
db.query(mapFun, reduceFun, page.viewLanguage, options);
} else if (viewName == "_design_docs") {
options.startkey = options.descending ? "_design0" : "_design";
diff --git a/share/www/script/futon.js b/share/www/script/futon.js
index 31f04a90..f5a81444 100644
--- a/share/www/script/futon.js
+++ b/share/www/script/futon.js
@@ -35,22 +35,22 @@
}
this.addDatabase = function(name) {
- var recentDbs = $.cookies.get("recent", "").split(",");
+ var recentDbs = $.futon.storage.get("recent", "").split(",");
if ($.inArray(name, recentDbs) == -1) {
recentDbs.unshift(name);
if (recentDbs.length > 10) recentDbs.length = 10;
- $.cookies.set("recent", recentDbs.join(","));
+ $.futon.storage.set("recent", recentDbs.join(","));
this.updateDatabases();
}
}
this.removeDatabase = function(name) {
// remove database from recent databases list
- var recentDbs = $.cookies.get("recent", "").split(",");
+ var recentDbs = $.futon.storage.get("recent").split(",");
var recentIdx = $.inArray(name, recentDbs);
if (recentIdx >= 0) {
recentDbs.splice(recentIdx, 1);
- $.cookies.set("recent", recentDbs.join(","));
+ $.futon.storage.set("recent", recentDbs.join(","));
this.updateDatabases();
}
}
@@ -61,7 +61,7 @@
selection = [this.pathname, this.search];
});
$("#dbs").empty();
- var recentDbs = $.cookies.get("recent", "").split(",");
+ var recentDbs = $.futon.storage.get("recent").split(",");
recentDbs.sort();
$.each(recentDbs, function(idx, name) {
if (name) {
@@ -123,13 +123,113 @@
$("#sidebar-toggle")
.attr("title", hidden ? "Show Sidebar" : "Hide Sidebar");
- $.cookies.set("sidebar", hidden ? "hidden" : "show");
+ $.futon.storage.set("sidebar", hidden ? "hidden" : "show");
};
}
+ function Storage() {
+ var storage = this;
+ this.decls = {};
+
+ this.declare = function(name, options) {
+ this.decls[name] = $.extend({}, {
+ scope: "window",
+ defaultValue: null,
+ prefix: ""
+ }, options || {});
+ }
+
+ this.declareWithPrefix = function(prefix, decls) {
+ for (var name in decls) {
+ var options = decls[name];
+ options.prefix = prefix;
+ storage.declare(name, options);
+ }
+ }
+
+ this.del = function(name) {
+ lookup(name, function(decl) {
+ handlers[decl.scope].del(decl.prefix + name);
+ });
+ }
+
+ this.get = function(name, defaultValue) {
+ return lookup(name, function(decl) {
+ var value = handlers[decl.scope].get(decl.prefix + name);
+ if (value !== undefined) {
+ return value;
+ }
+ if (defaultValue !== undefined) {
+ return defaultValue;
+ }
+ return decl.defaultValue;
+ });
+ }
+
+ this.set = function(name, value) {
+ lookup(name, function(decl) {
+ handlers[decl.scope].set(decl.prefix + name, value);
+ });
+ }
+
+ function lookup(name, callback) {
+ var decl = storage.decls[name];
+ if (decl === undefined) {
+ return decl;
+ }
+ return callback(decl);
+ }
+
+ var handlers = {
+
+ "cookie": {
+ get: function(name) {
+ var nameEq = name + "=";
+ var parts = document.cookie.split(';');
+ for (var i = 0; i < parts.length; i++) {
+ var part = parts[i].replace(/^\s+/, "");
+ if (part.indexOf(nameEq) == 0) {
+ return unescape(part.substring(nameEq.length, part.length));
+ }
+ }
+ },
+ set: function(name, value) {
+ var date = new Date();
+ date.setTime(date.getTime() + 14*24*60*60*1000); // two weeks
+ document.cookie = name + "=" + escape(value) + "; expires=" +
+ date.toGMTString();
+ },
+ del: function(name) {
+ var date = new Date();
+ date.setTime(date.getTime() - 24*60*60*1000); // yesterday
+ document.cookie = name + "=; expires=" + date.toGMTString();
+ }
+ },
+
+ "window": {
+ get: function(name) {
+ return JSON.parse(window.name || "{}")[name];
+ },
+ set: function(name, value) {
+ var obj = JSON.parse(window.name || "{}");
+ obj[name] = value || null;
+ window.name = JSON.stringify(obj);
+ },
+ del: function(name) {
+ var obj = JSON.parse(window.name || "{}");
+ delete obj[name];
+ window.name = JSON.stringify(obj);
+ }
+ }
+
+ };
+
+ }
+
$.futon = $.futon || {};
$.extend($.futon, {
- navigation: new Navigation()
+ navigation: new Navigation(),
+ storage: new Storage()
});
$.fn.addPlaceholder = function(text) {
@@ -183,9 +283,12 @@
.ajaxStart(function() { $(this.body).addClass("loading"); })
.ajaxStop(function() { $(this.body).removeClass("loading"); });
+ $.futon.storage.declare("sidebar", {scope: "cookie", defaultValue: "show"});
+ $.futon.storage.declare("recent", {scope: "cookie", defaultValue: ""});
+
$(function() {
document.title = "Apache CouchDB - Futon: " + document.title;
- if ($.cookies.get("sidebar") == "hidden") {
+ if ($.futon.storage.get("sidebar") == "hidden") {
// doing this as early as possible prevents flickering
$(document.body).addClass("fullwidth");
}
@@ -195,7 +298,7 @@
$.futon.navigation.toggle(e.shiftKey ? 2500 : 500);
return false;
});
- if ($.cookies.get("sidebar") == "hidden") {
+ if ($.futon.storage.get("sidebar") == "hidden") {
$.futon.navigation.toggle(0);
}
diff --git a/share/www/script/jquery.cookies.js b/share/www/script/jquery.cookies.js
deleted file mode 100644
index 642f1792..00000000
--- a/share/www/script/jquery.cookies.js
+++ /dev/null
@@ -1,50 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-(function($) {
- $.cookies = $.cookies || {}
- $.extend($.cookies, {
-
- /* Return the value of a cookie. */
- get: function(name, defaultValue) {
- var nameEq = name + "=";
- var parts = document.cookie.split(';');
- for (var i = 0; i < parts.length; i++) {
- var part = parts[i].replace(/^\s+/, "");
- if (part.indexOf(nameEq) == 0) {
- return unescape(part.substring(nameEq.length, part.length));
- }
- }
- return defaultValue !== undefined ? defaultValue : null;
- },
-
- /* Create or update a cookie. */
- set: function(name, value, path, days) {
- var params = [];
- if (path) {
- params.push("; path=" + path);
- }
- if (days) {
- var date = new Date();
- date.setTime(date.getTime() + (days * 24*60*60*1000));
- params.push("; expires=" + date.toGMTString());
- }
- document.cookie = name + "=" + escape(value) + params.join();
- },
-
- /* Remove a cookie. */
- remove: function(name, path) {
- $.cookies.set(name, "", path, -1);
- }
-
- });
-})(jQuery);
diff --git a/share/www/status.html b/share/www/status.html
index 72cd2afe..3e23f85d 100644
--- a/share/www/status.html
+++ b/share/www/status.html
@@ -20,7 +20,6 @@ specific language governing permissions and limitations under the License.
<link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">
<script src="script/json2.js"></script>
<script src="script/jquery.js?1.3.1"></script>
- <script src="script/jquery.cookies.js?0.11.0"></script>
<script src="script/jquery.couch.js?0.11.0"></script>
<script src="script/futon.js?0.11.0"></script>
</head>
@@ -52,6 +51,8 @@ specific language governing permissions and limitations under the License.
<script>
var refreshTimeout = null;
+ $.futon.storage.declare("poll_interval", {defaultValue: 5});
+
function refresh() {
$.couch.activeTasks({
success: function(tasks) {
@@ -83,12 +84,12 @@ specific language governing permissions and limitations under the License.
}
$("#interval .secs").text(value);
refresh();
- $.cookies.set("pollinterval", value);
+ $.futon.storage.set("poll_interval", value);
}
$(function() {
var slider = $("#interval input");
- slider.val(parseInt($.cookies.get("pollinterval", "5")) || 5);
+ slider.val(parseInt($.futon.storage.get("poll_interval")));
if (slider[0].type == "range") {
slider.bind("input", function() {
updateInterval(this.value);