some item/list drag&drop (works in firefox, buggy in safari, fails in chrome)

This commit is contained in:
rolux 2011-08-28 06:24:01 +00:00
parent 22e4ddc628
commit 20fc6a5bf5
4 changed files with 139 additions and 16 deletions

View file

@ -189,6 +189,7 @@ pandora.ui.folderBrowserList = function(id) {
return that; return that;
}; };
/*
pandora.ui.folderList = function(id) { pandora.ui.folderList = function(id) {
var i = Ox.getPositionById(pandora.site.sectionFolders[pandora.user.ui.section], id), var i = Ox.getPositionById(pandora.site.sectionFolders[pandora.user.ui.section], id),
that; that;
@ -424,11 +425,9 @@ pandora.ui.folderList = function(id) {
pandora.resizeFolders(); pandora.resizeFolders();
}, },
move: function(event, data) { move: function(event, data) {
/*
data.ids.forEach(function(id, pos) { data.ids.forEach(function(id, pos) {
pandora.user.ui.lists[id].position = pos; pandora.user.ui.lists[id].position = pos;
}); });
*/
pandora.api.sortLists({ pandora.api.sortLists({
section: id, section: id,
ids: data.ids ids: data.ids
@ -627,10 +626,8 @@ pandora.ui.folders = function() {
}); });
} else if (data.id == 'browse') { } else if (data.id == 'browse') {
alert('??') alert('??')
/* //pandora.$ui.sectionList[1].replaceWith(pandora.$ui.publicLists = pandora.ui.publicLists());
pandora.$ui.sectionList[1].replaceWith(pandora.$ui.publicLists = pandora.ui.publicLists()); //pandora.site.showAllPublicLists = true;
pandora.site.showAllPublicLists = true;
*/
} }
}, },
toggle: function(event, data) { toggle: function(event, data) {
@ -661,4 +658,5 @@ pandora.ui.folders = function() {
} }
return that; return that;
}; };
*/

View file

@ -149,7 +149,7 @@ pandora.ui.folderList = function(id) {
} else if (id == 'featured') { } else if (id == 'featured') {
query = {conditions: [{key: 'status', value: 'featured', operator: '='}], operator: '&'}; query = {conditions: [{key: 'status', value: 'featured', operator: '='}], operator: '&'};
} }
return pandora.api.findLists($.extend(data, { return pandora.api.findLists(Ox.extend(data, {
query: query query: query
}), callback); }), callback);
}, },
@ -187,16 +187,14 @@ pandora.ui.folderList = function(id) {
}, },
'delete': function(event, data) { 'delete': function(event, data) {
var $list = pandora.$ui.folderList[id]; var $list = pandora.$ui.folderList[id];
pandora.user.ui.listQuery.conditions = []; pandora.URL.set('?find=');
pandora.URL.set(pandora.Query.toString());
$list.options({selected: []}); $list.options({selected: []});
if (id == 'personal') { if (id == 'personal') {
pandora.api.removeList({ pandora.api.removeList({
id: data.ids[0] id: data.ids[0]
}, function(result) { }, function(result) {
// fixme: is this the best way to delete a ui preference? pandora.UI.set(['lists', data.ids[0]].join('|'), null);
delete pandora.user.ui.lists[data.ids[0]]; Ox.print('SHOULD BE DELETED:', pandora.user.ui.lists)
pandora.UI.set({lists: pandora.user.ui.lists});
Ox.Request.clearCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
$list.reloadList(); $list.reloadList();
}); });

View file

@ -456,16 +456,143 @@ pandora.ui.list = function() { // fixme: remove view argument
}); });
} }
var $tooltip = Ox.Tooltip({
animate: false
}).css({
textAlign: 'center'
});
['list', 'icons'].indexOf(view) > -1 && that.bind({ ['list', 'icons'].indexOf(view) > -1 && that.bind({
dragstart: function(e) { dragstart: function(e) {
var editable = pandora.getListData().editable,
ids = that.options('selected'),
item = ids.length == 1 ? that.value(ids[0], 'title') : ids.length;
Ox.forEach(pandora.$ui.folderList, function($list, i) { Ox.forEach(pandora.$ui.folderList, function($list, i) {
$list.addClass('OxDrop'); $list.find('.OxItem').each(function() {
var $item = $(this),
data = $list.value($item.data('id'));
if (
data.user == pandora.user.username
&& data.type == 'static'
&& !$item.is('.OxSelected')
) {
pandora.api.find({
query: {
conditions: [
{key: 'list', value: data.id, operator: '='},
{
conditions: ids.map(function(id) {
return {key: 'id', value: id, operator: '='};
}),
operator: '|'
}
],
operator: '&'
}
}, function(result) {
var items = ids.length - result.data.items;
items && $item.addClass('OxDrop').bind({
dragenter: function(e) {
$(this).addClass('OxDragover');
},
dragover: function(e) {
$tooltip.options({
title: getTitle(e, ids.length == 1 ? item : items, data.id.split('/').pop())
+ (editable && e.shiftKey && result.data.items
? '<br/>and remove ' + result.data.items + ' '
+ pandora.site.itemName[result.data.items == 1 ? 'singular' : 'plural'].toLowerCase()
+ '<br/>from the list "' + pandora.user.ui.list.split('/').pop() + '"'
: '')
}).show(e);
//e.originalEvent.dataTransfer.dropEffect = 'none';
e.originalEvent.preventDefault();
return false;
},
dragleave: function(e) {
$(this).removeClass('OxDragover');
},
drop: function(e) {
Ox.print('DROP', data);
var $this = $(this), folder, listData;
if (editable && e.shiftKey) {
pandora.api.removeListItems({
list: pandora.user.ui.list,
items: ids
}, pandora.reloadList);
listData = pandora.getListData();
folder = listData.status == 'private' ? 'personal' : data.status;
pandora.$ui.folderList[folder].value(
listData.id, 'items',
pandora.$ui.folderList[folder].value(listData.id, 'items') - ids.length
);
}
pandora.api.addListItems({
list: data.id,
items: ids
});
folder = data.status == 'private' ? 'personal' : data.status;
pandora.$ui.folderList[folder].value(
data.id, 'items',
pandora.$ui.folderList[folder].value(data.id, 'items') + items
);
Ox.Request.clearCache(); // fixme: remove
setTimeout(function() {
$this.removeClass('OxDragover');
}, 250);
e.originalEvent.stopPropagation();
return false;
}
});
});
}
});
}); });
e.originalEvent.dataTransfer.setDragImage(
$('<img>').attr({src: Ox.UI.PATH + 'png/transparent.png'})[0], 0, 0
);
Ox.UI.$document.bind({
dragover: function(e) {
$tooltip.options({
title: getTitle(e, item)
}).show(e);
e.originalEvent.preventDefault();
return false;
}
});
function getTitle(e, item, list) {
return (editable && e.shiftKey ? 'Move' : 'Copy') + ' '
+ (Ox.isString(item) ? '"' + item + '"' : item + ' ' + pandora.site.itemName[item == 1 ? 'singular' : 'plural'].toLowerCase())
+ (list ? '<br/>to the list "' + list + '"' : '');
}
//e.originalEvent.dataTransfer.setData('text/plain', JSON.stringify(that.options('selected')));
}, },
dragend: function(e) { dragend: function(e) {
Ox.print('DRAGEND')
$tooltip.hide();
Ox.UI.$document.unbind('dragover');
$('.OxDrop').removeClass('OxDrop')
.unbind('dragenter')
.unbind('dragover')
.unbind('dragleave')
.unbind('drop');
/*
Ox.forEach(pandora.$ui.folderList, function($list, i) { Ox.forEach(pandora.$ui.folderList, function($list, i) {
$list.removeClass('OxDrop'); $list.find('.OxItem').each(function() {
var $item = $(this), id = $item.data('id');
if (
$list.value(id, 'user') == pandora.user.username
&& $list.value(id, 'type') == 'static'
&& !$item.is('.OxSelected')
) {
$item.removeClass('OxDrop')
.unbind('dragenter')
.unbind('dragover')
.unbind('dragleave')
.unbind('drop');
}
});
}); });
*/
} }
}).bindEvent({ }).bindEvent({
closepreview: function(data) { closepreview: function(data) {

View file

@ -22,9 +22,9 @@ pandora.ui.siteDialog = function(section) {
.attr({src: '/static/png/' + ( .attr({src: '/static/png/' + (
id == 'software' ? 'pandora' : 'logo' id == 'software' ? 'pandora' : 'logo'
) + '256.png'}) ) + '256.png'})
.css({width: '128px'}) .css({width: '256px'})
), ),
size: 144 size: 272
}, },
{ {
element: Ox.Element() element: Ox.Element()