From 83dbe50894b04ec5d0a0cfc2a24b180905bae7b5 Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 8 Aug 2013 15:51:57 +0000 Subject: [PATCH] fix (some) copy & paste bugs in edits --- static/js/editPanel.js | 14 +------------- static/js/utils.js | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/static/js/editPanel.js b/static/js/editPanel.js index 66629ac2f..5d528d892 100644 --- a/static/js/editPanel.js +++ b/static/js/editPanel.js @@ -200,19 +200,7 @@ pandora.ui.editPanel = function() { paste: function() { var clips; if (pandora.clipboard.type() == 'clip') { - clips = pandora.clipboard.paste().map(function(clip) { - var split = clip.split('/'), - item = split[0], - points = split[1].split('-'); - return Ox.extend({ - item: item - }, points.length == 1 ? { - annotation: clip - } : { - 'in': parseFloat(points[0]), - out: parseFloat(points[1]) - }); - }); + clips = pandora.clipboard.paste(); pandora.doHistory('paste', clips, ui.edit, function(result) { Ox.Request.clearCache('getEdit'); updateClips(edit.clips.concat(result.data.clips)); diff --git a/static/js/utils.js b/static/js/utils.js index eccc6a63d..4fc651c20 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -360,7 +360,7 @@ pandora.createLinks = function($element) { }; function addItems(items, target, callback) { - var type = getType(items); + var clips, type = getType(items); if (type == 'item') { pandora.api.find({ query: { @@ -382,7 +382,7 @@ pandora.createLinks = function($element) { } }); } else { - pandora.api.addClips({items: items, edit: target}, callback); + pandora.api.addClips({clips: parseClips(items), edit: target, index: 0}, callback); } } @@ -419,14 +419,31 @@ pandora.createLinks = function($element) { function getType(items) { return items[0] && Ox.contains(items[0], '/') ? 'clip' : 'item'; - }; + } + + function parseClips(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: clip + } : { + 'in': parseFloat(points[0]), + out: parseFloat(points[1]) + }); + }); + } function removeItems(items, target, callback) { var type = getType(items); - pandora.api[type == 'item' ? 'removeListItems' : 'removeClips']( - Ox.extend({items: items}, type == 'item' ? 'list' : 'edit', target), - callback - ); + if (type == 'item') { + pandora.api.removeListItems({items: items, list: target}, callback); + } else { + pandora.api.removeClips({clips: parseClips(items), edit: target}, callback); + } } }());