From 9efd77724dca97d940470b72214283d02d5e5c35 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 2 Jan 2015 00:26:04 +0100 Subject: [PATCH] add option to select default view for list in dialog and use if user has no list settings, fixes #2636 --- pandora/itemlist/models.py | 2 +- static/js/folderList.js | 20 +++++-- static/js/listDialog.js | 109 +++++++++++++++++++++++-------------- 3 files changed, 83 insertions(+), 48 deletions(-) diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index fdae0cef..b49b0a7e 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -196,7 +196,7 @@ class List(models.Model): def json(self, keys=None, user=None): if not keys: - keys=['id', 'name', 'user', 'type', 'query', 'status', 'subscribed', 'posterFrames', 'description'] + keys=['id', 'name', 'user', 'type', 'query', 'status', 'subscribed', 'posterFrames', 'description', 'view'] response = {} for key in keys: if key == 'items': diff --git a/static/js/folderList.js b/static/js/folderList.js index 054909a2..db3d18cb 100644 --- a/static/js/folderList.js +++ b/static/js/folderList.js @@ -106,7 +106,7 @@ pandora.ui.folderList = function(id, section) { operator: '+', tooltip: function(data) { return data.type == 'static' - ? (data.user == pandora.user.username ? Ox._('Edit Default View') : Ox._('Default View: ...')) + ? (data.user == pandora.user.username ? Ox._('Edit {0}', [Ox._(folderItem)]) : '') : data.type == 'smart' ? (data.user == pandora.user.username ? Ox._('Edit Query') : Ox._('Show Query')) : data.type.toUpperCase(); @@ -264,7 +264,8 @@ pandora.ui.folderList = function(id, section) { columns: columns, droppable: id != 'volumes', items: items, - keys: ['modified'].concat(section != 'texts' ? ['query', 'name'] : ['rightslevel']), + keys: ['modified'].concat(section != 'texts' + ? ['query', 'name', 'view'] : ['rightslevel']), max: 1, min: 0, pageLength: 1000, @@ -314,6 +315,8 @@ pandora.ui.folderList = function(id, section) { } else if (data.key == 'type') { if (that.value(data.id, 'type') == 'smart') { pandora.$ui.listDialog = pandora.ui.listDialog('query').open(); + } else { + pandora.$ui.listDialog = pandora.ui.listDialog('general').open(); } } else if (data.key == 'status') { var status = that.value(data.id, data.key) == 'private' ? 'public' : 'private'; @@ -334,7 +337,7 @@ pandora.ui.folderList = function(id, section) { pandora.api['unsubscribeFrom' + folderItem]({ id: data.ids[0] }, function(result) { - Ox.Request.clearCache(); // fixme: remove + Ox.Request.clearCache('findList'); that.reloadList(); }); } else if (id == 'featured' && canEditFeatured) { @@ -343,9 +346,9 @@ pandora.ui.folderList = function(id, section) { id: data.ids[0], status: 'public' }, function(result) { + Ox.Request.clearCache('findList'); // fixme: duplicated if (result.data.user == pandora.user.username || result.data.subscribed) { - Ox.Request.clearCache(); // fixme: remove pandora.$ui.folderList[ result.data.user == pandora.user.username ? 'personal' : 'favorite' ].reloadList(); @@ -402,10 +405,15 @@ pandora.ui.folderList = function(id, section) { pandora.UI.set({ find: { conditions: list ? [ - {key: 'list', value: data.ids[0], operator: '=='} + {key: 'list', value: list, operator: '=='} ] : [], operator: '&' - } + }, + listView: list + ? pandora.user.ui.lists[list] + ? pandora.user.ui.lists[list].view + : that.value(list).view + : void 0 }); } else { pandora.UI.set(section.slice(0, -1), list); diff --git a/static/js/listDialog.js b/static/js/listDialog.js index 3083f0f2..69816f12 100644 --- a/static/js/listDialog.js +++ b/static/js/listDialog.js @@ -199,58 +199,69 @@ pandora.ui.listGeneralPanel = function(listData) { submit: editName }) .appendTo(that), - $itemsInput = ui.section != 'texts' + $select = (ui.section == 'items' + ? Ox.Select({ + items: pandora.site.listViews.map(function(view) { + return {id: view.id, title: view.title}; + }), + label: Ox._('View'), + labelWidth: 80, + value: listData.view, + width: 320 + }) + .bindEvent({ + change: editView + }) + : ui.section != 'texts' + ? Ox.Input({ + disabled: true, + label: Ox._('Items'), + labelWidth: 80, + value: listData.items, + width: 320 + }) + : Ox.Select({ + items: pandora.site.textRightsLevels.map(function(rightsLevel, i) { + console.log(listData); + return { + id: i, + title: rightsLevel.name, + }; + }), + label: Ox._('Rights Level'), + labelWidth: 80, + value: listData.rightslevel, + width: 320 + }) + .bindEvent({ + change: editRightsLevel + }) + ) + .css({position: 'absolute', left: '160px', top: '40px'}) + .appendTo(that), + $statusSelect = (listData.status == 'featured' ? Ox.Input({ disabled: true, - label: Ox._('Items'), + label: Ox._('Status'), labelWidth: 80, - value: listData.items, + value: 'Featured', width: 320 }) - .css({position: 'absolute', left: '160px', top: '40px'}) - .appendTo(that) : Ox.Select({ - items: pandora.site.textRightsLevels.map(function(rightsLevel, i) { - console.log(listData); - return { - id: i, - title: rightsLevel.name, - }; - }), - label: Ox._('Rights Level'), + items: [ + {id: 'private', title: Ox._('Private')}, + {id: 'public', title: Ox._('Public')} + ], + label: Ox._('Status'), labelWidth: 80, - value: listData.rightslevel, + value: listData.status, width: 320 }) - .css({position: 'absolute', left: '160px', top: '40px'}) .bindEvent({ - change: editRightsLevel + change: editStatus }) - .appendTo(that), - $statusSelect = listData.status == 'featured' - ? Ox.Input({ - disabled: true, - label: Ox._('Status'), - labelWidth: 80, - value: 'Featured', - width: 320 - }) + ) .css({position: 'absolute', left: '160px', top: '64px'}) - .appendTo(that) - : Ox.Select({ - items: [ - {id: 'private', title: Ox._('Private')}, - {id: 'public', title: Ox._('Public')} - ], - label: Ox._('Status'), - labelWidth: 80, - value: listData.status, - width: 320 - }) - .css({position: 'absolute', left: '160px', top: '64px'}) - .bindEvent({ - change: editStatus - }) .appendTo(that), $subscribersInput = Ox.Input({ disabled: true, @@ -333,7 +344,23 @@ pandora.ui.listGeneralPanel = function(listData) { }, function(result) { Ox.Request.clearCache('getText'); //fixme: reload text and folder list - $itemsInput.value(result.data.rightslevel); + $select.value(result.data.rightslevel); + }); + } + function editView(data) { + var view = data.value; + pandora.api.editList({ + id: listData.id, + view: view + }, function(result) { + $select.value(result.data.view); + Ox.Request.clearCache('findList'); + pandora.$ui.folderList[ + result.data.status == 'featured' + ? 'featured' + : result.data.user == pandora.user.username + ? 'personal' : 'favorite' + ].reloadList(); }); } function getDescriptionHeight() {