From 24afe66c75e3fc5a67ba816a4795c50928e714b8 Mon Sep 17 00:00:00 2001
From: j <0x006A@0x2620.org>
Date: Tue, 16 Jul 2013 14:04:21 +0000
Subject: [PATCH] merge pandora.enableDragAndDrop and
-pandora.enableDragAndDropClip
---
static/js/clipList.js | 2 +-
static/js/utils.js | 389 ++++++++++--------------------------------
2 files changed, 95 insertions(+), 296 deletions(-)
diff --git a/static/js/clipList.js b/static/js/clipList.js
index 9d432483..38a4208e 100644
--- a/static/js/clipList.js
+++ b/static/js/clipList.js
@@ -269,7 +269,7 @@ pandora.ui.clipList = function(videoRatio) {
}
});
- pandora.enableDragAndDropClip(that, true);
+ pandora.enableDragAndDrop(that, true, 'edits');
return that;
}
diff --git a/static/js/utils.js b/static/js/utils.js
index e57e4770..f550671f 100644
--- a/static/js/utils.js
+++ b/static/js/utils.js
@@ -285,7 +285,8 @@ pandora.createLinks = function($element) {
});
};
-pandora.enableDragAndDrop = function($list, canMove) {
+pandora.enableDragAndDrop = function($list, canMove, section) {
+ section = section || pandora.user.ui.section;
var $tooltip = Ox.Tooltip({
animate: false
@@ -295,257 +296,15 @@ pandora.enableDragAndDrop = function($list, canMove) {
$list.bindEvent({
draganddropstart: function(data) {
+ pandora.user.ui.section != section && pandora.$ui.mainPanel.replaceElement(0,
+ pandora.$ui.leftPanel = pandora.ui.leftPanel(section));
drag.action = 'copy';
drag.ids = $list.options('selected'),
drag.item = drag.ids.length == 1
- ? $list.value(drag.ids[0], 'title')
+ ? $list.value(drag.ids[0], 'title') || 1
: drag.ids.length;
drag.source = pandora.getListData(),
drag.targets = {};
- Ox.forEach(pandora.$ui.folderList, function($list) {
- $list.addClass('OxDroppable').find('.OxItem').each(function() {
- var $item = $(this),
- id = $item.data('id'),
- data = $list.value(id);
- drag.targets[id] = Ox.extend({
- editable: data.user == pandora.user.username
- && data.type == 'static',
- selected: $item.is('.OxSelected')
- }, data);
- if (!drag.targets[id].selected && drag.targets[id].editable) {
- $item.addClass('OxDroppable');
- }
- });
- });
- $tooltip.options({title: getTitle()}).show(data.event);
- canMove && Ox.UI.$window.on({
- keydown: keydown,
- keyup: keyup
- });
- },
- draganddrop: function(data) {
- var event = data.event;
- $tooltip.options({
- title: getTitle(event)
- }).show(event);
- if (scrollInterval && !isAtListsTop(event) && !isAtListsBottom(event)) {
- clearInterval(scrollInterval);
- scrollInterval = 0;
- }
- },
- draganddroppause: function(data) {
- var event = data.event, scroll,
- $parent, $grandparent, $panel, title;
- if (!pandora.user.ui.showSidebar) {
- if (event.clientX < 16 && event.clientY >= 44
- && event.clientY < window.innerHeight - 16
- ) {
- pandora.$ui.mainPanel.toggle(0);
- }
- } else {
- $parent = $(event.target).parent();
- $grandparent = $parent.parent();
- $panel = $parent.is('.OxCollapsePanel') ? $parent
- : $grandparent.is('.OxCollapsePanel') ? $grandparent : null;
- if ($panel) {
- title = $panel.children('.OxBar').children('.OxTitle')
- .html().split(' ')[0].toLowerCase();
- if (!pandora.user.ui.showFolder.items[title]) {
- Ox.UI.elements[$panel.data('oxid')].options({collapsed: false});
- }
- }
- if (!scrollInterval) {
- scroll = isAtListsTop(event) ? -16
- : isAtListsBottom(event) ? 16 : 0
- if (scroll) {
- scrollInterval = setInterval(function() {
- pandora.$ui.folders.scrollTop(
- pandora.$ui.folders.scrollTop() + scroll
- );
- }, 100);
- }
- }
- }
- },
- draganddropenter: function(data) {
- var $parent = $(data.event.target).parent(),
- $item = $parent.is('.OxItem') ? $parent : $parent.parent(),
- $list = $item.parent().parent().parent().parent();
- if ($list.is('.OxDroppable')) {
- $item.addClass('OxDrop');
- drag.target = drag.targets[$item.data('id')];
- } else {
- drag.target = null;
- }
- },
- draganddropleave: function(data) {
- var $parent = $(data.event.target).parent(),
- $item = $parent.is('.OxItem') ? $parent : $parent.parent();
- if ($item.is('.OxDroppable')) {
- $item.removeClass('OxDrop');
- drag.target = null;
- }
- },
- draganddropend: function(data) {
- Ox.Log('', data, drag, '------------');
- canMove && Ox.UI.$window.off({
- keydown: keydown,
- keyup: keyup
- });
- if (drag.target && drag.target.editable && !drag.target.selected) {
- if (drag.action == 'copy' || (
- drag.action == 'move' && drag.source.editable
- )) {
- if (drag.action == 'move') {
- pandora.api.removeListItems({
- list: pandora.user.ui._list,
- items: data.ids
- }, pandora.reloadList);
- }
- pandora.api.addListItems({
- list: drag.target.id,
- items: data.ids
- }, function() {
- Ox.Request.clearCache(); // fixme: remove
- pandora.api.find({
- query: {
- conditions: [{key: 'list', value: drag.target.id, operator: '='}],
- operator: ''
- }
- }, function(result) {
- var folder = drag.target.status != 'featured' ? 'personal' : 'featured';
- pandora.$ui.folderList[folder].value(
- drag.target.id, 'items',
- result.data.items
- );
- cleanup(250);
- });
- });
- }
- } else {
- cleanup(0);
- }
- function cleanup(ms) {
- drag = {};
- clearInterval(scrollInterval);
- scrollInterval = 0;
- setTimeout(function() {
- $('.OxDroppable').removeClass('OxDroppable');
- $('.OxDrop').removeClass('OxDrop');
- $tooltip.hide();
- }, ms);
- }
- }
- });
-
- function getTitle() {
- var image, text;
- if (drag.action == 'move' && drag.source.user != pandora.user.username) {
- image = 'symbolClose';
- text = Ox._('You can only remove {0}
from your own lists.',
- [pandora.site.itemName.plural.toLowerCase()]);
- } else if (drag.action == 'move' && drag.source.type == 'smart') {
- image = 'symbolClose';
- text = Ox._('You can\'t remove {0}
from smart lists.',
- [pandora.site.itemName.plural.toLowerCase()]);
- } else if (drag.target && drag.target.user != pandora.user.username) {
- image = 'symbolClose';
- text = Ox._('You can only {0} {1}
to your own lists',
- [drag.action, pandora.site.itemName.plural.toLowerCase()]);
- } else if (drag.target && drag.target.type == 'smart') {
- image = 'symbolClose';
- text = Ox._('You can\'t {0} {1}
to smart lists',
- [drag.action, pandora.site.itemName.plural.toLowerCase()]);
- } else {
- image = drag.action == 'copy' ? 'symbolAdd' : 'symbolRemove';
- text = Ox._(Ox.toTitleCase(drag.action)) + ' ' + (
- Ox.isString(drag.item)
- ? '"' + drag.item + '"'
- : drag.item + ' ' + pandora.site.itemName[
- drag.item == 1 ? 'singular' : 'plural'
- ].toLowerCase()
- ) + '
' + (
- drag.target && !drag.target.selected
- ? Ox._('to the list "{0}"', [Ox.encodeHTMLEntities(drag.target.name)])
- : Ox._('to ' + (pandora.user.ui._list ? 'another' : 'a') + ' list')
- );
- }
- return $('