fix bugs related to 'New Edit from Selection'

This commit is contained in:
rolux 2014-02-07 08:07:45 +00:00
parent 0e71ada256
commit 50d122f54b
2 changed files with 49 additions and 57 deletions

View file

@ -373,7 +373,7 @@ pandora.ui.mainMenu = function() {
if (ui.section == 'texts') { if (ui.section == 'texts') {
pandora.addText({type: 'text'}); pandora.addText({type: 'text'});
} else { } else {
pandora.addList(data.id.indexOf('smart') > -1, data.id.indexOf('from') > -1); pandora.addFolderItem(ui.section, data.id.indexOf('smart') > -1, data.id.indexOf('from') > -1);
} }
} else if (Ox.contains(['neweditfromselection', 'newsmarteditfromresults'], data.id)) { } else if (Ox.contains(['neweditfromselection', 'newsmarteditfromresults'], data.id)) {
pandora.addEdit(data.id.indexOf('smart') > -1, data.id.indexOf('from') > -1); pandora.addEdit(data.id.indexOf('smart') > -1, data.id.indexOf('from') > -1);

View file

@ -36,9 +36,15 @@ pandora.addFolderItem = function(section) {
}; };
if (isFrom) { if (isFrom) {
if (!isSmart) { if (!isSmart) {
data.items = isItems ? ui.listSelection if (isItems) {
: ui.section == 'items' ? pandora.$ui.clipList.options('selected') data.items = ui.listSelection;
: pandora.$ui.editPanel.getSelectedClips(); } else {
data.clips = pandora.getClipData(
ui.section == 'items'
? pandora.$ui.clipList.options('selected') // FIXME: still wrong, could be annotation or in-to-out
: pandora.$ui.editPanel.getSelectedClips()
);
}
} else { } else {
data.query = ui.find; data.query = ui.find;
} }
@ -78,10 +84,10 @@ pandora.addFolderItem = function(section) {
sort: [{key: 'id', operator: ''}], sort: [{key: 'id', operator: ''}],
range: [0, result.data.items] range: [0, result.data.items]
}, function(result) { }, function(result) {
var items = result.data.items.map(function(item) { data.items = result.data.items.map(function(item) {
return item.id; return item.id;
}); });
addList(items); addList();
}); });
} else { } else {
addList(); addList();
@ -89,7 +95,7 @@ pandora.addFolderItem = function(section) {
}); });
} else { } else {
pandora.api.getEdit({id: list}, function(result) { pandora.api.getEdit({id: list}, function(result) {
var items = result.data.clips.map(function(clip) { data.clips = result.data.clips.map(function(clip) {
return Ox.extend({ return Ox.extend({
item: clip.item item: clip.item
}, clip.annotation ? { }, clip.annotation ? {
@ -99,7 +105,7 @@ pandora.addFolderItem = function(section) {
out: clip.out out: clip.out
}); });
}); });
addList(items); addList();
}); });
} }
} else { } else {
@ -107,28 +113,9 @@ pandora.addFolderItem = function(section) {
} }
}); });
} }
function addList(items) { function addList() {
pandora.api[isItems ? 'addList' : 'addEdit'](data, function(result) { pandora.api[isItems ? 'addList' : 'addEdit'](data, function(result) {
var newList = result.data.id; getPosterFrames(result.data.id);
if (items) {
if (isItems) {
pandora.api.addListItems({
list: newList,
items: items
}, function() {
getPosterFrames(newList);
});
} else {
pandora.api.addClips({
clips: items,
edit: newList
}, function(result) {
getPosterFrames(newList);
});
}
} else {
getPosterFrames(newList);
}
}); });
} }
function getPosterFrames(newList) { function getPosterFrames(newList) {
@ -141,7 +128,7 @@ pandora.addFolderItem = function(section) {
conditions: [{key: 'list', value: newList, operator: '=='}], conditions: [{key: 'list', value: newList, operator: '=='}],
operator: '&' operator: '&'
} : { } : {
conditions: Ox.unique(result.data.clips.map(function(clips) { conditions: Ox.unique(result.data.clips.map(function(clip) {
return {key: 'id', value: clip.item, operator: '=='}; return {key: 'id', value: clip.item, operator: '=='};
})), })),
operator: '|' operator: '|'
@ -189,6 +176,9 @@ pandora.addFolderItem = function(section) {
}); });
} }
function reloadFolder(newList) { function reloadFolder(newList) {
// FIXME: collapsing sets ui showFolder,
// but should work the other way around
// (same applies to addText, below)
pandora.$ui.folder[0].options({collapsed: false}); pandora.$ui.folder[0].options({collapsed: false});
Ox.Request.clearCache(isItems ? 'findLists' : 'findEdits'); Ox.Request.clearCache(isItems ? 'findLists' : 'findEdits');
$folderList.bindEventOnce({ $folderList.bindEventOnce({
@ -447,7 +437,7 @@ pandora.createLinks = function($element) {
}); });
} else { } else {
pandora.api.addClips({ pandora.api.addClips({
clips: getClipData(items), clips: pandora.getClipData(items),
edit: target, edit: target,
index: pandora.user.ui.edits[pandora.user.ui.edit].selection.length index: pandora.user.ui.edits[pandora.user.ui.edit].selection.length
? Ox.getObjectById( ? Ox.getObjectById(
@ -457,7 +447,7 @@ pandora.createLinks = function($element) {
: void 0 : void 0
}, function(result) { }, function(result) {
// adding clips creates new ids, so mutate items in history // adding clips creates new ids, so mutate items in history
items.splice.apply(items, [0, items.length].concat(getClipItems(result.data.clips))); items.splice.apply(items, [0, items.length].concat(pandora.getClipItems(result.data.clips)));
callback(result, items); callback(result, items);
}); });
} }
@ -498,7 +488,7 @@ pandora.createLinks = function($element) {
} }
function editItem(item, callback) { function editItem(item, callback) {
var clip = getClipData([item])[0], var clip = pandora.getClipData([item])[0],
id = getClipIds([item])[0]; id = getClipIds([item])[0];
pandora.api.editClip({ pandora.api.editClip({
id: id, id: id,
@ -507,36 +497,12 @@ pandora.createLinks = function($element) {
}, callback); }, callback);
} }
function getClipData(items) {
return items.map(function(clip) {
var split = clip.split('/'),
item = split[0],
points = split[1].split('-');
return Ox.extend({
item: item
}, points.length == 1 ? {
annotation: item + '/' + points[0]
} : {
'in': parseFloat(points[0]),
out: parseFloat(points[1])
});
});
}
function getClipIds(items) { function getClipIds(items) {
return items.map(function(clip) { return items.map(function(clip) {
return clip.split('/').pop(); return clip.split('/').pop();
}); });
} }
function getClipItems(clips) {
return clips.map(function(clip) {
return (
clip.annotation || clip.item + '/' + clip['in'] + '-' + clip.out
) + '/' + (clip.id || '');
});
}
function getType(items) { function getType(items) {
return Ox.contains(items[0], '/') || Ox.contains(items[0][0], '/') ? 'clip' : 'item'; return Ox.contains(items[0], '/') || Ox.contains(items[0][0], '/') ? 'clip' : 'item';
} }
@ -882,6 +848,32 @@ pandora.getAllItemsTitle = function(section) {
: Ox._('{0} ' + Ox.toTitleCase(section), [pandora.site.site.name]); : Ox._('{0} ' + Ox.toTitleCase(section), [pandora.site.site.name]);
}; };
pandora.getClipData = function(items) {
return items.map(function(clip) {
var split = clip.split('/'),
item = split[0],
points = split[1].split('-');
return Ox.extend({
item: item
}, points.length == 1 ? {
annotation: item + '/' + points[0]
} : {
'in': parseFloat(points[0]),
out: parseFloat(points[1])
});
});
};
pandora.getClipItems = function(data) {
return data.map(function(clip) {
return (
clip.annotation || clip.item + '/' + clip['in'] + '-' + clip.out
) + '/' + (clip.id || '');
});
};
// FIXME: naming hazard, above and below
pandora.getClipsItems = function(width) { pandora.getClipsItems = function(width) {
width = width || window.innerWidth width = width || window.innerWidth
- pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1 - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 1