edit sort

This commit is contained in:
j 2014-02-06 10:28:35 +00:00
parent b21fe0f8f7
commit 491a9f6a3f

View file

@ -42,7 +42,7 @@ pandora.ui.editPanel = function() {
clip.position = edit.duration; clip.position = edit.duration;
edit.duration += clip.duration; edit.duration += clip.duration;
}); });
callback(); sortClips(callback);
}); });
} }
@ -86,10 +86,9 @@ pandora.ui.editPanel = function() {
annotationsSize: ui.annotationsSize, annotationsSize: ui.annotationsSize,
annotationsSort: ui.annotationsSort, annotationsSort: ui.annotationsSort,
clickLink: pandora.clickLink, clickLink: pandora.clickLink,
clipRatio: pandora.site.video.previewRatio,
clips: Ox.clone(edit.clips), clips: Ox.clone(edit.clips),
clipSize: listSize, clipSize: listSize,
clipSort: ui.edits[ui.edit].sort,
clipSortOptions: [/*...*/],
clipTooltip: 'clips <span class="OxBright">' + Ox.SYMBOLS.SHIFT + 'C</span>', clipTooltip: 'clips <span class="OxBright">' + Ox.SYMBOLS.SHIFT + 'C</span>',
clipView: ui.edits[ui.edit].view, clipView: ui.edits[ui.edit].view,
duration: edit.duration, duration: edit.duration,
@ -121,11 +120,10 @@ pandora.ui.editPanel = function() {
showUsers: pandora.site.annotations.showUsers, showUsers: pandora.site.annotations.showUsers,
smallTimelineURL: getSmallTimelineURL(), smallTimelineURL: getSmallTimelineURL(),
sort: ui.edits[ui.edit].sort, sort: ui.edits[ui.edit].sort,
sortOptions: ( sortOptions: [
edit.type == 'static' {id: 'index', title: Ox._('Sort Manually'), operator: '+'}
? [{id: 'index', title: Ox._('Sort Manually'), operator: '+'}] ]
: [] .concat(
).concat(
pandora.site.clipKeys.map(function(key) { pandora.site.clipKeys.map(function(key) {
return Ox.extend(Ox.clone(key), { return Ox.extend(Ox.clone(key), {
title: Ox._(('Sort by Clip {0}'), [Ox._(key.title)]) title: Ox._(('Sort by Clip {0}'), [Ox._(key.title)])
@ -269,38 +267,14 @@ pandora.ui.editPanel = function() {
pandora.UI.set({videoScale: data.scale}); pandora.UI.set({videoScale: data.scale});
}, },
select: function(data) { select: function(data) {
pandora.UI.set(editsKey('selection'), data.ids); pandora.UI.set({editSelection: data.ids});
}, },
size: function(data) { size: function(data) {
pandora.UI.set({clipSize: data.size}); pandora.UI.set({clipSize: data.size});
}, },
sort: function(data) { sort: function(data) {
pandora.UI.set(editsKey('sort'), data); pandora.UI.set({editSort: data});
var key = data[0].key; sortClips(updateClips);
if (key == 'position') {
key = 'in';
}
if ([
'id', 'index', 'in', 'out', 'duration',
'title', 'director', 'year', 'videoRatio'
].indexOf(key) > -1) {
edit.clips = Ox.sortBy(edit.clips, key);
if (data[0].operator == '-') {
edit.clips.reverse();
}
updateClips(edit.clips);
} else {
pandora.api.sortClips({
edit: edit.id,
sort: data
}, function(result) {
edit.clips.forEach(function(clip) {
clip['sort'] = result.data.clips.indexOf(clip.id);
});
edit.clips = Ox.sortBy(edit.clips, 'sort');
updateClips(edit.clips);
});
}
}, },
split: function(data) { split: function(data) {
var clips = [serializeClips(data.ids), serializeClips(data.split)]; var clips = [serializeClips(data.ids), serializeClips(data.split)];
@ -323,7 +297,7 @@ pandora.ui.editPanel = function() {
pandora.UI.set({showTimeline: data.showTimeline}); pandora.UI.set({showTimeline: data.showTimeline});
}, },
view: function(data) { view: function(data) {
pandora.UI.set(editsKey('view'), data.view); pandora.UI.set({editView: data.view});
data.view == 'grid' && enableDragAndDrop(); data.view == 'grid' && enableDragAndDrop();
}, },
volume: function(data) { volume: function(data) {
@ -457,6 +431,35 @@ pandora.ui.editPanel = function() {
}); });
} }
function sortClips(callback) {
var sort = pandora.user.ui.editSort;
var key = sort[0].key;
if (key == 'position') {
key = 'in';
}
if ([
'id', 'index', 'in', 'out', 'duration',
'title', 'director', 'year', 'videoRatio'
].indexOf(key) > -1) {
edit.clips = Ox.sortBy(edit.clips, key);
if (sort[0].operator == '-') {
edit.clips.reverse();
}
callback(edit.clips);
} else {
pandora.api.sortClips({
edit: edit.id,
sort: sort
}, function(result) {
edit.clips.forEach(function(clip) {
clip['sort'] = result.data.clips.indexOf(clip.id);
});
edit.clips = Ox.sortBy(edit.clips, 'sort');
callback(edit.clips);
});
}
}
function updateClips(clips) { function updateClips(clips) {
clips = clips || edit.clips; clips = clips || edit.clips;
edit.clips = clips; edit.clips = clips;