gridftp: handle paths beginning with `~`
[qcg-portal.git] / filex / static / filex / filex.js
index 7eabdd2..6785d74 100644 (file)
@@ -107,7 +107,7 @@ $(function(){
         },
 
         full: function() {
-            return this.pluck('path').join('/') || '/';
+            return this.pluck('name').join('/').replace(/^\/+/, '/');
         }
     });
 
@@ -192,12 +192,12 @@ $(function(){
 
         render: function() {
             if (this.model.get('active')) {
-                this.$el.text(this.model.get('text'));
+                this.$el.text(this.model.get('name'));
             }
             else {
                 this.$el.html($('<a/>', {
                     href: '#',
-                    text: this.model.get('text')
+                    text: this.model.get('name')
                 }));
             }
             this.$el.toggleClass('active', this.model.get('active'));
@@ -261,13 +261,13 @@ $(function(){
                 lockOptgroupOrder: true,
                 create: function(input, callback) {
                     var $form = $('#favorite-form'),
-                        parts = input.split('/', 1),
+                        parts = input.split('/'),
                         callback_called = false;
 
-                    $form.find('#id_host').val(parts[0]);
+                    $form.find('#id_host').val(parts.shift());
 
-                    if (parts.length > 1)
-                        $form.find('#id_path').val(parts[1]);
+                    if (parts.length)
+                        $form.find('#id_path').val(parts.join('/'));
 
                     $form.on('submit', function(e) {
                         var $this = $(this),
@@ -326,13 +326,15 @@ $(function(){
         },
 
         load: function(location) {
-            var path = location.replace(/(^\/+|\/+$)/g, '').split('/'),
-                host = path.shift(),
-                pathBits = [new Filex.PathBit({'text': '/', 'path': ''})].concat(_.map(path, function(name) {
-                    return new Filex.PathBit({'text': name, 'path': name});
-                }));
-
-            this.host = host;
+            var hostRootPath = location.split(/\/(\/|~)(.*)/),
+                pathBits = [new Filex.PathBit({'name': hostRootPath[1]})].concat(
+                    _.chain(hostRootPath[2].split('/'))
+                        .filter(_.identity)
+                        .map(function(name) { return new Filex.PathBit({'name': name}) })
+                        .value()
+                );
+
+            this.host = hostRootPath[0];
             this.path.reset(pathBits);
 
             this.$host.text(this.host);
@@ -393,7 +395,7 @@ $(function(){
         },
 
         selectedDir: function(dir) {
-            this.path.add({'text': dir.get('name'), 'path': dir.get('name')});
+            this.path.add({'name': dir.get('name')});
         },
 
         selectedPath: function(bit) {
@@ -459,20 +461,13 @@ $(function(){
 
             $btn.button('loading');
 
-            $.post(url, data, 'json').done(function () {
+            $.post(url, data, 'json').done(function (response) {
                 $btn.button('reset');
 
-                if (is_active) {
-                    locations.removeOption(data.host + data.path);
-                }
-                else {
-                    locations.addOption({
-                        group: 'usr',
-                        host: data.host,
-                        path: data.path,
-                        value: data.host + data.path
-                    });
-                }
+                if (is_active)
+                    locations.removeOption(data.host + '/' + data.path);
+                else
+                    locations.addOption(response);
             }).fail(function() {
                 $btn.button('reset');
                 $btn.button('toggle');
@@ -495,7 +490,7 @@ $(function(){
         },
 
         updateFavorites: function() {
-            var loc = this.host + this.path.full(),
+            var loc = this.host + '/' + this.path.full(),
                 favorites = this.hostSelectize.options;
 
             if (favorites.hasOwnProperty(loc)) {