From f597de57b5cfa15b770aa43c5030c5005acc6e82 Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 19 Sep 2011 12:29:55 +0000 Subject: [PATCH] update filter, add list dialog --- pandora/0xdb.json | 2 +- static/js/pandora.api.js | 6 ++-- static/js/pandora/Query.js | 2 +- static/js/pandora/ui/filter.js | 38 +++++++++++++---------- static/js/pandora/ui/filterDialog.js | 14 +++++---- static/js/pandora/ui/folderBrowserList.js | 6 +++- static/js/pandora/ui/foldersList.js | 32 +++++++++++++------ static/js/pandora/ui/info.js | 6 ++-- static/js/pandora/ui/leftPanel.js | 5 +-- static/js/pandora/ui/videoPreview.js | 11 +++---- static/json/pandora.json | 1 + 11 files changed, 75 insertions(+), 48 deletions(-) diff --git a/pandora/0xdb.json b/pandora/0xdb.json index 53d0ed994..bb712806e 100644 --- a/pandora/0xdb.json +++ b/pandora/0xdb.json @@ -31,7 +31,7 @@ { "id": "all", "title": "All", - "type": "string", + "type": "text", "find": true }, { diff --git a/static/js/pandora.api.js b/static/js/pandora.api.js index 70ed9cda4..42f640ffd 100755 --- a/static/js/pandora.api.js +++ b/static/js/pandora.api.js @@ -94,7 +94,7 @@ function constructList() { app.api.api(function(results) { var items = []; Ox.forEach(results.data.actions, function(v, k) { - items.push({'name': v}) + items.push({'name': k}) }); items.sort(_sort); var result = {'data': {'items': items.length}}; @@ -104,7 +104,7 @@ function constructList() { app.api.api(function(results) { var items = []; Ox.forEach(results.data.actions, function(v, k) { - items.push({'name': v}) + items.push({'name': k}) }); items.sort(_sort); var result = {'data': {'items': items}}; @@ -142,7 +142,7 @@ function constructList() { .addClass("margin") .click(function() { $code.toggle()}) .appendTo(info) - var f = app.actions[k].code[0]; + var f = app.actions[id].code[0]; $('').html(' View Source ('+f+')').appendTo(info) $('
').append($code).appendTo(info) 
                 hljs.highlightBlock($code[0], '    ');
diff --git a/static/js/pandora/Query.js b/static/js/pandora/Query.js
index 390ec9e93..953705595 100644
--- a/static/js/pandora/Query.js
+++ b/static/js/pandora/Query.js
@@ -96,7 +96,7 @@ pandora.Query = (function() {
                 find: {index: -1, key: '', value: ''},
                 groups: [], // {index, query, selected}
                 list: '',
-                query: {conditions: [], operator: ''}
+                query: {conditions: [], operator: '&'}
             },
             subconditions = [];
         if (str.length) {
diff --git a/static/js/pandora/ui/filter.js b/static/js/pandora/ui/filter.js
index 1b2158b33..03e62ee70 100644
--- a/static/js/pandora/ui/filter.js
+++ b/static/js/pandora/ui/filter.js
@@ -1,21 +1,27 @@
 // vim: et:ts=4:sw=4:sts=4:ft=javascript
-pandora.ui.filter = function() {
+pandora.ui.filter = function(list) {
     var that = Ox.Filter({
-        findKeys: Ox.map(pandora.site.itemKeys, function(key) {
-            return key.id == 'all' ? null : {
-                autocomplete: key.autocomplete,
-                autocompleteSortKey: key.autocompleteSortKey,
-                format: key.format,
-                id: key.id,
-                title: key.title,
-                type: key.type == 'layer' ? Ox.getObjectById(
-                    pandora.site.layers, key.id
-                ).type : key.type
-            };
-        }),
-        sortKeys: pandora.site.sortKeys,
-        viewKeys: pandora.site.listViews
-    });
+            findKeys: Ox.merge(Ox.map(pandora.site.itemKeys, function(key) {
+                return {
+                    autocomplete: key.autocomplete,
+                    autocompleteSortKey: key.autocompleteSortKey,
+                    format: key.format,
+                    id: key.id,
+                    title: key.title,
+                    type: key.type == 'layer' ? Ox.getObjectById(
+                        pandora.site.layers, key.id
+                    ).type : key.type
+                };
+            }), {
+                id: 'list',
+                title: 'List',
+                type: 'list'
+            }),
+            query: list ? list.query : pandora.user.ui.query,
+            sortKeys: pandora.site.sortKeys,
+            viewKeys: pandora.site.listViews
+        })
+        .css({padding: '16px'});
     return that;
 };
 
diff --git a/static/js/pandora/ui/filterDialog.js b/static/js/pandora/ui/filterDialog.js
index 90f1fc020..7386c9017 100644
--- a/static/js/pandora/ui/filterDialog.js
+++ b/static/js/pandora/ui/filterDialog.js
@@ -1,5 +1,5 @@
 // vim: et:ts=4:sw=4:sts=4:ft=javascript
-pandora.ui.filterDialog = function() {
+pandora.ui.filterDialog = function(list) {
     var that = Ox.Dialog({
         buttons: [
             Ox.Button({
@@ -11,6 +11,7 @@ pandora.ui.filterDialog = function() {
                         alert(JSON.stringify(pandora.$ui.filter.options('query')));
                     }
                 }),
+            /*
             Ox.Button({
                     id: 'cancel',
                     title: 'Cancel'
@@ -20,9 +21,10 @@ pandora.ui.filterDialog = function() {
                         pandora.$ui.filterDialog.close();
                     }
                 }),
+            */
             Ox.Button({
-                    id: 'save',
-                    title: 'Save'
+                    id: 'done',
+                    title: 'Done'
                 })
                 .bindEvent({
                     click: function() {
@@ -30,13 +32,13 @@ pandora.ui.filterDialog = function() {
                     }
                 })
         ],
-        content: pandora.$ui.filter = pandora.ui.filter().css({padding: '16px'}),
+        content: pandora.$ui.filter = pandora.ui.filter(list),
         maxWidth: 648 + Ox.UI.SCROLLBAR_SIZE,
         minHeight: 264,
         minWidth: 648 + Ox.UI.SCROLLBAR_SIZE,
         height: 264,
-        keys: {enter: 'save', escape: 'cancel'},
-        title: 'Advanced Find',
+        // keys: {enter: 'save', escape: 'cancel'},
+        title: list ? 'Smart List - ' + list.name : 'Advanced Find',
         width: 648 + Ox.UI.SCROLLBAR_SIZE
     });
     return that;
diff --git a/static/js/pandora/ui/folderBrowserList.js b/static/js/pandora/ui/folderBrowserList.js
index 47caa4b0a..fe33f4158 100644
--- a/static/js/pandora/ui/folderBrowserList.js
+++ b/static/js/pandora/ui/folderBrowserList.js
@@ -138,7 +138,11 @@ pandora.ui.folderBrowserList = function(id) {
         .bindEvent({
             click: function(data) {
                 if (data.key == 'type') {
-                    alert('...');
+                    /*
+                    if (that.value(data.id, 'type') == 'smart') {
+                        pandora.$ui.filterDialog = pandora.ui.filterDialog(that.value(data.id, 'query')).open();
+                    }
+                    */
                 } else if (data.key == 'subscribed') {
                     var subscribed = that.value(data.id, 'subscribed');
                     pandora.api[subscribed ? 'unsubscribeFromList' : 'subscribeToList']({
diff --git a/static/js/pandora/ui/foldersList.js b/static/js/pandora/ui/foldersList.js
index a1e013b04..d9f520c03 100644
--- a/static/js/pandora/ui/foldersList.js
+++ b/static/js/pandora/ui/foldersList.js
@@ -8,6 +8,9 @@ pandora.ui.folderList = function(id) {
         if (id != 'volumes') {
             columns = [
                 {
+                    clickable: function(data) {
+                        return data.user == pandora.user.username;
+                    },
                     format: function() {
                         return $('').attr({
                                 src: Ox.UI.getImageURL('symbolIcon')
@@ -19,6 +22,9 @@ pandora.ui.folderList = function(id) {
                     },
                     id: 'user',
                     operator: '+',
+                    tooltip: function(data) {
+                        return data.user == pandora.user.username ? 'Edit Icon' : '';
+                    },
                     visible: true,
                     width: 16
                 },
@@ -229,6 +235,7 @@ pandora.ui.folderList = function(id) {
         that = Ox.TextList({
             columns: columns,
             items: items,
+            keys: ['query'],
             max: 1,
             min: 0,
             pageLength: 1000,
@@ -282,15 +289,20 @@ pandora.ui.folderList = function(id) {
                 }
             },
             click: function(data) {
-                var $list = pandora.$ui.folderList[id];
-                if (data.key == 'type') {
-                    pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
+                //var $list = pandora.$ui.folderList[id];
+                if (data.key == 'user') {
+                    pandora.$ui.filterDialog = pandora.ui.listDialog(that.value(data.id), 'icon').open();
+                    
+                } else if (data.key == 'type') {
+                    if (that.value(data.id, 'type') == 'smart') {
+                        pandora.$ui.filterDialog = pandora.ui.listDialog(that.value(data.id), 'query').open();
+                    }
                 } else if (data.key == 'status') {
                     pandora.api.editList({
                         id: data.id,
-                        status: $list.value(data.id, data.key) == 'private' ? 'public' : 'private'
+                        status: that.value(data.id, data.key) == 'private' ? 'public' : 'private'
                     }, function(result) {
-                        $list.value(result.data.id, 'status', result.data.status);
+                        that.value(result.data.id, 'status', result.data.status);
                     });
                 } else if (data.key == 'path') {
                     
@@ -300,23 +312,23 @@ pandora.ui.folderList = function(id) {
             },
             'delete': function(data) {
                 // fixme: add a confirmation dialog
-                var $list = pandora.$ui.folderList[id];
+                //var $list = pandora.$ui.folderList[id];
                 pandora.URL.set('?find=');
-                $list.options({selected: []});
+                that.options({selected: []});
                 if (id == 'personal') {
                     pandora.api.removeList({
                         id: data.ids[0]
                     }, function(result) {
                         pandora.UI.set(['lists', data.ids[0]].join('|'), null);
                         Ox.Request.clearCache(); // fixme: remove
-                        $list.reloadList();
+                        that.reloadList();
                     });
                 } else if (id == 'favorite') {
                     pandora.api.unsubscribeFromList({
                         id: data.ids[0]
                     }, function(result) {
                         Ox.Request.clearCache(); // fixme: remove
-                        $list.reloadList();
+                        that.reloadList();
                     });
                 } else if (id == 'featured' && pandora.user.level == 'admin') {
                     pandora.api.editList({
@@ -330,7 +342,7 @@ pandora.ui.folderList = function(id) {
                                 result.data.user == pandora.user.username ? 'personal' : 'favorite'
                             ].reloadList();
                         }
-                        $list.reloadList();
+                        that.reloadList();
                     });
                 }
             },
diff --git a/static/js/pandora/ui/info.js b/static/js/pandora/ui/info.js
index 59b591a92..4b71a50d7 100644
--- a/static/js/pandora/ui/info.js
+++ b/static/js/pandora/ui/info.js
@@ -27,9 +27,11 @@ pandora.ui.info = function() {
             if (result.data) {
                 pandora.$ui.videoPreview && pandora.$ui.videoPreview.removeElement();
                 pandora.$ui.videoPreview = pandora.ui.videoPreview({
-                    id: id,
                     duration: result.data.duration,
-                    frameRatio: result.data.videoRatio
+                    frameRatio: result.data.videoRatio,
+                    height: pandora.getInfoHeight(),
+                    id: id,
+                    width: pandora.user.ui.sidebarSize
                 }).appendTo(pandora.$ui.info);
             }
         });
diff --git a/static/js/pandora/ui/leftPanel.js b/static/js/pandora/ui/leftPanel.js
index 5f3e76923..ebaf48e98 100644
--- a/static/js/pandora/ui/leftPanel.js
+++ b/static/js/pandora/ui/leftPanel.js
@@ -23,6 +23,7 @@ pandora.ui.leftPanel = function() {
         .bindEvent({
             resize: function(data) {
                 pandora.user.ui.sidebarSize = data.size;
+                var infoHeight = pandora.getInfoHeight();
                 if (data.size < pandora.site.sectionButtonsWidth && pandora.$ui.sectionButtons) {
                     pandora.$ui.sectionButtons.removeElement();
                     delete pandora.$ui.sectionButtons;
@@ -32,8 +33,8 @@ pandora.ui.leftPanel = function() {
                     delete pandora.$ui.sectionSelect;
                     pandora.$ui.sectionbar.append(pandora.$ui.sectionButtons = pandora.ui.sectionButtons());
                 }
-                !pandora.user.ui.showInfo && pandora.$ui.leftPanel.css({bottom: -infoSize});
-                pandora.$ui.leftPanel.size(2, pandora.getInfoHeight());
+                !pandora.user.ui.showInfo && pandora.$ui.leftPanel.css({bottom: -infoHeight});
+                pandora.$ui.leftPanel.size(2, infoHeight);
                 pandora.$ui.info.resizeInfo();
                 pandora.resizeFolders();
             },
diff --git a/static/js/pandora/ui/videoPreview.js b/static/js/pandora/ui/videoPreview.js
index a56c4c36b..5b1ee0278 100644
--- a/static/js/pandora/ui/videoPreview.js
+++ b/static/js/pandora/ui/videoPreview.js
@@ -4,20 +4,19 @@ pandora.ui.videoPreview = function(data) {
     var that = Ox.VideoPreview({
             duration: data.duration,
             getFrame: function(position) {
-                var width = pandora.user.ui.sidebarSize,
-                    height = Math.min(width, 256),
-                    resolution = Ox.filter(pandora.site.video.resolutions, function(resolution, i) {
-                        return resolution >= height || i == pandora.site.video.resolutions.length - 1;
+                var resolution = Ox.filter(pandora.site.video.resolutions, function(resolution, i) {
+                        return resolution >= data.height || i == pandora.site.video.resolutions.length - 1;
                     })[0];
                 return '/' + data.id + '/' + resolution + 'p' + (
                     Ox.isUndefined(position) ? '' : position
                 ) + '.jpg';
             },
+            frameCSS: data.frameCSS,
             frameRatio: data.frameRatio,
-            height: pandora.getInfoHeight(),
+            height: data.height,
             scaleToFill: true,
             timeline: '/' + data.id + '/timeline16p.png',
-            width: pandora.user.ui.sidebarSize
+            width: data.width
         })
         .bindEvent({
             click: function(event) {
diff --git a/static/json/pandora.json b/static/json/pandora.json
index 756e9f7d7..3216b7784 100644
--- a/static/json/pandora.json
+++ b/static/json/pandora.json
@@ -43,5 +43,6 @@
   "js/pandora/ui/mediaView.js",
   "js/pandora/ui/home.js",
   "js/pandora/ui/preferencesDialog.js",
+  "js/pandora/ui/listDialog.js",
   "js/pandora/ui/siteDialog.js"
 ]