Explorar o código

HUE-727 [fb] filechooser.js should not always open on / by default

Changed filechooser.js
Added initial path to the places where filechooser is used
Added cookie to save the last opened path

Conflicts solved by Romain:

	apps/beeswax/src/beeswax/templates/execute.mako
	apps/filebrowser/src/filebrowser/templates/chown.mako
	apps/filebrowser/src/filebrowser/templates/listdir_components.mako
	apps/filebrowser/src/filebrowser/templates/move.mako
	desktop/core/static/js/Source/jHue/jquery.filechooser.js
Enrico Berti %!s(int64=13) %!d(string=hai) anos
pai
achega
36a1b25

+ 1 - 0
desktop/core/src/desktop/templates/common_header.mako

@@ -47,6 +47,7 @@ from desktop.lib.i18n import smart_unicode
   <script src="/static/js/Source/jHue/jquery.selector.js"></script>
   <script src="/static/js/Source/jHue/jquery.alert.js"></script>
   <script src="/static/js/Source/jHue/jquery.rowselector.js"></script>
+  <script src="/static/ext/js/jquery/plugins/jquery.cookie.js"></script>
   <script src="/static/ext/js/jquery/plugins/jquery.simpleplaceholder.js"></script>
   <script src="/static/ext/js/jquery/plugins/jquery.dataTables.1.8.2.min.js"></script>
   <script src="/static/js/Source/jHue/jquery.datatables.sorting.js"></script>

+ 47 - 0
desktop/core/static/ext/js/jquery/plugins/jquery.cookie.js

@@ -0,0 +1,47 @@
+/*!
+ * jQuery Cookie Plugin
+ * https://github.com/carhartl/jquery-cookie
+ *
+ * Copyright 2011, Klaus Hartl
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.opensource.org/licenses/GPL-2.0
+ */
+(function($) {
+    $.cookie = function(key, value, options) {
+
+        // key and at least value given, set cookie...
+        if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
+            options = $.extend({}, options);
+
+            if (value === null || value === undefined) {
+                options.expires = -1;
+            }
+
+            if (typeof options.expires === 'number') {
+                var days = options.expires, t = options.expires = new Date();
+                t.setDate(t.getDate() + days);
+            }
+
+            value = String(value);
+
+            return (document.cookie = [
+                encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
+                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
+                options.path    ? '; path=' + options.path : '',
+                options.domain  ? '; domain=' + options.domain : '',
+                options.secure  ? '; secure' : ''
+            ].join(''));
+        }
+
+        // key and possibly options given, get cookie...
+        options = value || {};
+        var decode = options.raw ? function(s) { return s; } : decodeURIComponent;
+
+        var pairs = document.cookie.split('; ');
+        for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
+            if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
+        }
+        return null;
+    };
+})(jQuery);

+ 5 - 1
desktop/core/static/js/Source/jHue/jquery.filechooser.js

@@ -47,6 +47,7 @@
                     _parent.navigateTo(data.view.dirname);
                     return;
                 }
+                $.cookie("hueFileBrowserLastPath", path, { expires: 90 });
                 _parent.previousPath = path;
                 var _breadcrumbs = $("<ul>").addClass("hueBreadcrumb").css("padding", "0");
                 var _home = $("<li>");
@@ -185,6 +186,9 @@
         if ($.trim(this.options.initialPath) != "") {
             this.navigateTo(this.options.initialPath);
         }
+        else if ($.cookie("hueFileBrowserLastPath") != null) {
+            this.navigateTo($.cookie("hueFileBrowserLastPath"));
+        }
         else {
             this.navigateTo("/?default_to_home");
         }
@@ -201,4 +205,4 @@
         });
     }
 
-})(jQuery, window, document);
+})(jQuery, window, document);