couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r889766 - in /couchdb/trunk/share: ./ www/ www/script/
Date Fri, 11 Dec 2009 18:58:13 GMT
Author: cmlenz
Date: Fri Dec 11 18:58:12 2009
New Revision: 889766

URL: http://svn.apache.org/viewvc?rev=889766&view=rev
Log:
Futon: Improve storage of session state by storing short-term settings in the window.name.

Removed:
    couchdb/trunk/share/www/script/jquery.cookies.js
Modified:
    couchdb/trunk/share/Makefile.am
    couchdb/trunk/share/www/config.html
    couchdb/trunk/share/www/couch_tests.html
    couchdb/trunk/share/www/custom_test.html
    couchdb/trunk/share/www/database.html
    couchdb/trunk/share/www/document.html
    couchdb/trunk/share/www/index.html
    couchdb/trunk/share/www/replicator.html
    couchdb/trunk/share/www/script/futon.browse.js
    couchdb/trunk/share/www/script/futon.js
    couchdb/trunk/share/www/status.html

Modified: couchdb/trunk/share/Makefile.am
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/Makefile.am?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/Makefile.am (original)
+++ couchdb/trunk/share/Makefile.am Fri Dec 11 18:58:12 2009
@@ -84,7 +84,6 @@
     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 \

Modified: couchdb/trunk/share/www/config.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/config.html?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/config.html (original)
+++ couchdb/trunk/share/www/config.html Fri Dec 11 18:58:12 2009
@@ -20,7 +20,6 @@
     <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>

Modified: couchdb/trunk/share/www/couch_tests.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/couch_tests.html?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/couch_tests.html [utf-8] (original)
+++ couchdb/trunk/share/www/couch_tests.html [utf-8] Fri Dec 11 18:58:12 2009
@@ -20,7 +20,6 @@
     <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>

Modified: couchdb/trunk/share/www/custom_test.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/custom_test.html?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/custom_test.html (original)
+++ couchdb/trunk/share/www/custom_test.html Fri Dec 11 18:58:12 2009
@@ -20,7 +20,6 @@
     <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>

Modified: couchdb/trunk/share/www/database.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/database.html?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/database.html [utf-8] (original)
+++ couchdb/trunk/share/www/database.html [utf-8] Fri Dec 11 18:58:12 2009
@@ -20,7 +20,6 @@
     <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 @@
           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 @@
 
         $("#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 @@
         });
         $("#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);

Modified: couchdb/trunk/share/www/document.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/document.html?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/document.html [utf-8] (original)
+++ couchdb/trunk/share/www/document.html [utf-8] Fri Dec 11 18:58:12 2009
@@ -20,7 +20,6 @@
     <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>

Modified: couchdb/trunk/share/www/index.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/index.html?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/index.html [utf-8] (original)
+++ couchdb/trunk/share/www/index.html [utf-8] Fri Dec 11 18:58:12 2009
@@ -20,7 +20,6 @@
     <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 @@
             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();

Modified: couchdb/trunk/share/www/replicator.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/replicator.html?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/replicator.html [utf-8] (original)
+++ couchdb/trunk/share/www/replicator.html [utf-8] Fri Dec 11 18:58:12 2009
@@ -20,7 +20,6 @@
     <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>

Modified: couchdb/trunk/share/www/script/futon.browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.browse.js?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.browse.js [utf-8] Fri Dec 11 18:58:12 2009
@@ -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";

Modified: couchdb/trunk/share/www/script/futon.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.js?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.js (original)
+++ couchdb/trunk/share/www/script/futon.js Fri Dec 11 18:58:12 2009
@@ -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);
       }
 

Modified: couchdb/trunk/share/www/status.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/status.html?rev=889766&r1=889765&r2=889766&view=diff
==============================================================================
--- couchdb/trunk/share/www/status.html (original)
+++ couchdb/trunk/share/www/status.html Fri Dec 11 18:58:12 2009
@@ -20,7 +20,6 @@
     <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 @@
   <script>
     var refreshTimeout = null;
 
+    $.futon.storage.declare("poll_interval", {defaultValue: 5});
+
     function refresh() {
       $.couch.activeTasks({
         success: function(tasks) {
@@ -83,12 +84,12 @@
       }
       $("#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);



Mime
View raw message