From 6be21617cd704ac8210dd4862299011e58cc5ecb Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 7 Nov 2011 12:12:13 +0000 Subject: [PATCH] allow for selecting lists via list menu --- static/js/pandora/folderList.js | 5 ---- static/js/pandora/folders.js | 13 +++++++++- static/js/pandora/menu.js | 44 +++++++++++++++++++++------------ static/js/pandora/utils.js | 23 ++++++++--------- 4 files changed, 52 insertions(+), 33 deletions(-) diff --git a/static/js/pandora/folderList.js b/static/js/pandora/folderList.js index ea941b3f..738212e5 100644 --- a/static/js/pandora/folderList.js +++ b/static/js/pandora/folderList.js @@ -364,11 +364,6 @@ pandora.ui.folderList = function(id) { }, select: function(data) { var list = data.ids.length ? data.ids[0] : ''; - if (list) { - Ox.forEach(pandora.$ui.folderList, function($list, id_) { - id != id_ && $list.options('selected', []); - }); - } pandora.UI.set({ find: { conditions: list ? [ diff --git a/static/js/pandora/folders.js b/static/js/pandora/folders.js index 98758aaf..2f673076 100644 --- a/static/js/pandora/folders.js +++ b/static/js/pandora/folders.js @@ -317,12 +317,23 @@ pandora.ui.folders = function() { } that.bindEvent({ pandora_find: function() { - var previousUI = pandora.UI.getPrevious(); + var folder = pandora.getListData().folder, + list = pandora.user.ui._list, + previousList = pandora.UI.getPrevious()._list; + if (list != previousList) { + Ox.forEach(pandora.$ui.folderList, function($list, id) { + id != folder && $list.options('selected', []); + }); + folder && pandora.$ui.folderList[folder].options({selected: [list]}); + } + /* if (!pandora.user.ui._list && previousUI._list) { + pandora.$ui.folderList[pandora.getListData(previous)] Ox.forEach(pandora.$ui.folderList, function($list) { $list.options({selected: []}); }); } + */ } }) return that; diff --git a/static/js/pandora/menu.js b/static/js/pandora/menu.js index 3e3e11de..fe46a302 100644 --- a/static/js/pandora/menu.js +++ b/static/js/pandora/menu.js @@ -155,7 +155,13 @@ pandora.ui.mainMenu = function() { .bindEvent({ change: function(data) { var value = data.checked[0] ? data.checked[0].id : null; - if (data.id == 'find') { + if (data.id == 'allitems') { + if (data.checked) { + pandora.UI.set('find', {conditions: [], operator: '&'}); + } else { + that.checkItem('allitems'); + } + } else if (data.id == 'find') { pandora.$ui.findSelect.options({value: value}); } else if (data.id == 'itemview') { pandora.UI.set({itemView: value}); @@ -208,11 +214,11 @@ pandora.ui.mainMenu = function() { set.listSort = pandora.site.user.ui.listSort; } pandora.UI.set(set); - } else if (['personallists', 'favoritelists', 'featuredlists'].indexOf(data.id) > -1) { + } else if (data.id.substr(0, 8) == 'viewlist') { pandora.UI.set({ find: { - conditions: value ? [ - {key: 'list', value: value.substr(8), operator: '=='} + conditions: data.checked ? [ + {key: 'list', value: data.id.substr(8), operator: '=='} ] : [], operator: '&' } @@ -345,9 +351,15 @@ pandora.ui.mainMenu = function() { && pandora.UI.set({showTimeline: !ui.showTimeline}); }, pandora_find: function() { - var action = ui._list - && pandora.getListData(ui._list).user == pandora.user.username - ? 'enableItem' : 'disableItem'; + var list = ui._list, + listData = pandora.getListData(), + previousList = pandora.UI.getPrevious()._list, + action = list && listData.user == pandora.user.username + ? 'enableItem' : 'disableItem'; + if (list != previousList) { + that.uncheckItem(previousList == '' ? 'allitems' : 'viewlist' + previousList); + that.checkItem(list == '' ? 'allitems' : 'viewlist' + list); + } that[action]('editlist'); that[action]('duplicatelist'); that[action]('deletelist'); @@ -415,18 +427,17 @@ pandora.ui.mainMenu = function() { return { id: folder + 'lists', title: Ox.toTitleCase(folder) + ' Lists', - items: [{ - group: folder + 'lists', - min: 0, - max: 1, - items: lists ? lists[folder].map(function(list) { + items: Ox.isUndefined(lists) + ? [{id: 'loading', title: 'Loading...', disabled: true}] + : lists[folder].length == 0 + ? [{id: 'nolists', title: 'No ' + Ox.toTitleCase(folder) + ' Lists', disabled: true}] + : lists[folder].map(function(list) { return { id: 'viewlist' + list.id, title: (folder == 'favorite' ? list.user + ': ' : '') + list.name, checked: list.id == pandora.user.ui._list }; - }) : [{id: 'loading', title: 'Loading...', disabled: true}] - }] + }) }; }), [ @@ -497,7 +508,7 @@ pandora.ui.mainMenu = function() { ] }; } - // fixme: the sidebar makes the same requests. + // fixme: the sidebar makes (almost) the same requests. // is it ok to make them twice, or should the sidebar trigger the menu replace? var counter = 0, @@ -520,7 +531,8 @@ pandora.ui.mainMenu = function() { Ox.forEach(queries, function(query, folder) { pandora.api.findLists({ query: query, - keys: ['id', 'name', 'user'] + keys: ['id', 'name', 'user'], + sort: [{key: 'position', operator: '+'}] }, function(result) { lists[folder] = result.data.items; if (++counter == 3) { diff --git a/static/js/pandora/utils.js b/static/js/pandora/utils.js index d6c4f9e0..c2b6836f 100644 --- a/static/js/pandora/utils.js +++ b/static/js/pandora/utils.js @@ -572,20 +572,21 @@ pandora.getItemByIdOrTitle = function(str, callback) { }); } -pandora.getListData = function() { - var data = {}, folder; - if (pandora.user.ui._list) { - Ox.forEach(pandora.$ui.folderList, function(list, key) { - if (list.options('selected').length) { - folder = key; +pandora.getListData = function(list) { + var data = {}; + list = Ox.isUndefined(list) ? pandora.user.ui._list : list; + if (list) { + Ox.forEach(pandora.$ui.folderList, function($list, id) { + var values = $list.value(list); + if (!Ox.isEmpty(values)) { + data = Ox.extend({ + editable: data.user == pandora.user.username + && data.type == 'static', + folder: id + }, values); return false; } }); - if (folder) { - data = pandora.$ui.folderList[folder].value(pandora.user.ui._list); - data.editable = data.user == pandora.user.username && data.type == 'static'; - data.folder = folder; - } } return data; };