From 1751832dd06867bf86690be50d240a37cb82bedc Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 19 Feb 2013 07:25:14 +0000 Subject: [PATCH] fix info box for texts, redirect to main text page if text does not exist, dont fail if folder gets removed before init is called --- pandora/text/views.py | 1 + static/js/pandora/allItems.js | 13 +++++---- static/js/pandora/folderList.js | 16 ++++++----- static/js/pandora/info.js | 48 ++++++++++++++++++++------------- static/js/pandora/text.js | 4 ++- 5 files changed, 51 insertions(+), 31 deletions(-) diff --git a/pandora/text/views.py b/pandora/text/views.py index a5c9be00a..27f6bb50a 100644 --- a/pandora/text/views.py +++ b/pandora/text/views.py @@ -11,6 +11,7 @@ from ox.django.decorators import login_required_json from ox.django.http import HttpFileResponse from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response from django.db.models import Count, Q, Sum, Max +from django.conf import settings from item import utils import models diff --git a/static/js/pandora/allItems.js b/static/js/pandora/allItems.js index 7165c37b6..1f9469c9d 100644 --- a/static/js/pandora/allItems.js +++ b/static/js/pandora/allItems.js @@ -39,24 +39,27 @@ pandora.ui.allItems = function() { }) .html(pandora.user.ui.section == 'items' ? 'All ' + pandora.site.itemName.plural : pandora.site.site.name + ' ' + Ox.toTitleCase(pandora.user.ui.section)) - .appendTo(that); + .appendTo(that), + $items, + $clickButton, + $uploadButton; if (pandora.user.ui.section == 'items') { - var $items = $('
') + $items = $('
') .css({ float: 'left', width: '42px', margin: '1px 4px 1px 3px', textAlign: 'right' }) - .appendTo(that), + .appendTo(that); $clickButton = Ox.Button({ style: 'symbol', title: 'click', type: 'image' }) .css({opacity: 0.25}) - .appendTo(that), + .appendTo(that); $uploadButton = Ox.Button({ style: 'symbol', title: 'upload', @@ -71,7 +74,7 @@ pandora.ui.allItems = function() { } that.update = function(items) { - $items.html(Ox.formatNumber(items)); + $items && $items.html(Ox.formatNumber(items)); }; that.resizeElement = function(width) { diff --git a/static/js/pandora/folderList.js b/static/js/pandora/folderList.js index 73ee510da..83b408f6f 100644 --- a/static/js/pandora/folderList.js +++ b/static/js/pandora/folderList.js @@ -355,13 +355,15 @@ pandora.ui.folderList = function(id) { }, */ init: function(data) { - pandora.site.sectionFolders[ui.section][i].items = data.items; - pandora.$ui.folder[i].$content.css({ - height: data.items * 16 + 'px' - }); - pandora.$ui.folderList[id].css({ - height: data.items * 16 + 'px' - }); + if(pandora.site.sectionFolders[ui.section][i]) { + pandora.site.sectionFolders[ui.section][i].items = data.items; + pandora.$ui.folder[i].$content.css({ + height: data.items * 16 + 'px' + }); + pandora.$ui.folderList[id].css({ + height: data.items * 16 + 'px' + }); + } pandora.resizeFolders(); }, move: function(data) { diff --git a/static/js/pandora/info.js b/static/js/pandora/info.js index aa2ecac11..5e5a7de04 100644 --- a/static/js/pandora/info.js +++ b/static/js/pandora/info.js @@ -3,6 +3,8 @@ pandora.ui.info = function() { var ui = pandora.user.ui, + folderItems = ui.section == 'items' ? 'Lists' : Ox.toTitleCase(ui.section), + folderItem = folderItems.slice(0, -1), view = getView(), that = Ox.Element() @@ -25,7 +27,8 @@ pandora.ui.info = function() { ) { updateInfo(); } - } + }, + pandora_text: updateInfo }); //pandora.$ui.leftPanel && resize(); @@ -40,7 +43,7 @@ pandora.ui.info = function() { } function getId() { - return ui.item || ( + return ui[folderItem.toLowerCase()] || ( ui.listSelection.length ? ui.listSelection[ui.listSelection.length - 1] : null @@ -48,9 +51,13 @@ pandora.ui.info = function() { } function getView() { - return !getId() ? 'list' - : !ui.item && pandora.isClipView() ? 'poster' - : 'video'; + return ui.section == 'items' + ? !getId() + ? 'list' + : !ui.item && pandora.isClipView() + ? 'poster' + : 'video' + : folderItem.toLowerCase(); } function resizeInfo() { @@ -64,7 +71,7 @@ pandora.ui.info = function() { var id = getId(), previousView = view; view = getView(); - if (view == 'list') { + if (view == 'list' || view == 'text') { emptyInfo(); that.append(pandora.$ui.listInfo = pandora.ui.listInfo()); previousView == 'video' && resizeInfo(); @@ -147,7 +154,7 @@ pandora.ui.info = function() { that.resizeInfo = function() { var view = getView(); - if (view == 'list') { + if (view == 'list' || view == 'text') { pandora.$ui.listInfo.resizeInfo(); } else if (view == 'poster') { pandora.$ui.posterInfo.resizeInfo(); @@ -160,7 +167,7 @@ pandora.ui.info = function() { }; that.updateListInfo = function() { - getView() == 'list' && that.empty().append( + ['list', 'text'].indexOf(getView()) > -1 && that.empty().append( pandora.$ui.listInfo = pandora.ui.listInfo() ); }; @@ -170,14 +177,16 @@ pandora.ui.info = function() { }; pandora.ui.listInfo = function() { - - var list = pandora.user.ui._list, - canEditFeaturedLists = pandora.site.capabilities.canEditFeaturedLists[pandora.user.level], + var ui = pandora.user.ui, + folderItems = ui.section == 'items' ? 'Lists' : Ox.toTitleCase(ui.section), + folderItem = folderItems.slice(0, -1), + list = pandora.user.ui.section == 'items' ? pandora.user.ui._list : ui[folderItem.toLowerCase()], + canEditFeaturedLists = pandora.site.capabilities['canEditFeatured' + folderItems][pandora.user.level], that = $('
').css({padding: '16px', textAlign: 'center'}), $icon = Ox.Element('') .attr({ src: list - ? '/list/' + list + '/icon256.jpg?' + Ox.uid() + ? '/' + folderItem.toLowerCase() + '/' + list + '/icon256.jpg?' + Ox.uid() : '/static/png/icon.png' }) .css(getIconCSS()) @@ -190,7 +199,7 @@ pandora.ui.listInfo = function() { //pandora.api.editList({id: list, description: 'foobbar'}, callback) //pandora.api.editPage({name: 'allItems', body: 'foobar'}, callback) if (list) { - pandora.api.findLists({ + pandora.api['find' + folderItems]({ query: {conditions: [{key: 'id', value: list, operator: '=='}]}, keys: ['description', 'status', 'name', 'user'] }, function(result) { @@ -232,7 +241,7 @@ pandora.ui.listInfo = function() { submit: function(data) { data.value = Ox.decodeHTMLEntities(data.value); if (data.value != item.name) { - pandora.api.editList({ + pandora.api['edit' + folderItem]({ id: list, name: data.value }, function(result) { @@ -278,12 +287,12 @@ pandora.ui.listInfo = function() { }, submit: function(data) { if (data.value != item.description) { - pandora.api.editList({ + pandora.api['edit' + folderItem]({ id: list, description: data.value }, function(result) { item.description = result.data.description; - Ox.Request.clearCache('findLists'); + Ox.Request.clearCache('find' + folderItems); }); } } @@ -293,7 +302,7 @@ pandora.ui.listInfo = function() { that.append( $('
') .css({paddingTop: '16px'}) - .html('List not found') + .html(folderItem + ' not found') ); } }); @@ -301,7 +310,10 @@ pandora.ui.listInfo = function() { that.append( $('
') .css({fontWeight: 'bold'}) - .html('All ' + pandora.site.itemName.plural) + .html(ui.section == 'items' + ? 'All ' + pandora.site.itemName.plural + : pandora.site.site.name + ' ' + folderItems + ) ); } diff --git a/static/js/pandora/text.js b/static/js/pandora/text.js index 05df5c842..b98666e6e 100644 --- a/static/js/pandora/text.js +++ b/static/js/pandora/text.js @@ -21,7 +21,9 @@ pandora.ui.text = function() { function getText(id) { pandora.api.getText({id: id}, function(result) { - if (result.data.type == 'pdf') { + if (!result.data) { + pandora.UI.set({text: ''}); + } else if (result.data.type == 'pdf') { $text && $text.remove(); $text = Ox.Editable({ clickLink: pandora.clickLink,