From e76cffd8b076a8c2a96cc6adc78bcb6c78206254 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 20 Mar 2012 17:55:35 +0100 Subject: [PATCH] CC-3463 : timeline usability moving multiple files within the timeline. --- airtime_mvc/application/models/Scheduler.php | 126 ++++++++++-------- .../library/events/library_playlistbuilder.js | 4 +- .../library/events/library_showbuilder.js | 4 +- .../public/js/airtime/library/library.js | 14 +- .../public/js/airtime/showbuilder/builder.js | 63 ++++++++- 5 files changed, 147 insertions(+), 64 deletions(-) diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 1c77774c9..54622e8a7 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -285,62 +285,84 @@ class Application_Model_Scheduler { public function moveItem($selectedItems, $afterItems, $adjustSched = true) { $this->con->beginTransaction(); - + try { - - $origSelTs = intval($selectedItems[0]["timestamp"]); - $origAfterTs = intval($afterItems[0]["timestamp"]); - - Logging::log("Moving item {$selectedItems[0]["id"]}"); - Logging::log("After {$afterItems[0]["id"]}"); - - $selected = CcScheduleQuery::create()->findPk($selectedItems[0]["id"], $this->con); - if (is_null($selected)) { - throw new OutDatedScheduleException("The schedule you're viewing is out of date!"); + + //checks on whether the item to move after is ok. + Logging::log("Moving after item: {$afterItems[0]["id"]}"); + $origAfterTs = intval($afterItems[0]["timestamp"]); + + if (intval($afterItems[0]["id"]) === 0) { + $afterInstance = CcShowInstancesQuery::create()->findPK($afterItems[0]["instance"], $this->con); + } + else { + $after = CcScheduleQuery::create()->findPk($afterItems[0]["id"], $this->con); + if (is_null($after)) { + throw new OutDatedScheduleException("The schedule you're viewing is out of date!"); + } + $afterInstance = $after->getCcShowInstances($this->con); + } + + $currTs = intval($afterInstance->getDbLastScheduled("U")) ? : 0; + if ($origAfterTs !== $currTs) { + $show = $afterInstance->getCcShow($this->con); + throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!"); } - $selectedInstance = $selected->getCcShowInstances($this->con); - - if (intval($afterItems[0]["id"]) === 0) { - - $afterInstance = CcShowInstancesQuery::create()->findPK($afterItems[0]["instance"], $this->con); - } - else { - $after = CcScheduleQuery::create()->findPk($afterItems[0]["id"], $this->con); - if (is_null($after)) { - throw new OutDatedScheduleException("The schedule you're viewing is out of date!"); + + //map show instances to cc_schedule primary keys. + $modifiedMap = array(); + $movedData = array(); + + //prepare each of the selected items. + for ($i = 0; $i < count($selectedItems); $i++) { + + Logging::log("Moving item {$selectedItems[$i]["id"]}"); + + $origSelTs = intval($selectedItems[$i]["timestamp"]); + $selected = CcScheduleQuery::create()->findPk($selectedItems[$i]["id"], $this->con); + if (is_null($selected)) { + throw new OutDatedScheduleException("The schedule you're viewing is out of date!"); + } + $selectedInstance = $selected->getCcShowInstances($this->con); + + if (is_null($selectedInstance) || is_null($afterInstance)) { + throw new OutDatedScheduleException("The schedule you're viewing is out of date!"); + } + + $currTs = intval($selectedInstance->getDbLastScheduled("U")) ? : 0; + if ($origSelTs !== $currTs) { + $show = $selectedInstance->getCcShow($this->con); + throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!"); } - $afterInstance = $after->getCcShowInstances($this->con); + + $data = $this->fileInfo; + $data["id"] = $selected->getDbFileId(); + $data["cliplength"] = $selected->getDbClipLength(); + $data["cuein"] = $selected->getDbCueIn(); + $data["cueout"] = $selected->getDbCueOut(); + $data["fadein"] = $selected->getDbFadeIn(); + $data["fadeout"] = $selected->getDbFadeOut(); + $data["sched_id"] = $selected->getDbId(); + + $movedData[] = $data; + + //figure out which items must be removed from calculated show times. + $showInstanceId = $selectedInstance->getDbId(); + $schedId = $selected->getDbId(); + if (isset($modifiedMap[$showInstanceId])) { + array_push($modifiedMap[$showInstanceId], $schedId); + } + else { + $modifiedMap[$showInstanceId] = array($schedId); + } + } + + //calculate times excluding the to be moved items. + foreach ($modifiedMap as $instance => $schedIds) { + $this->removeGaps($instance, $schedIds); } - - if (is_null($selectedInstance) || is_null($afterInstance)) { - throw new OutDatedScheduleException("The schedule you're viewing is out of date!"); - } - - $currTs = intval($selectedInstance->getDbLastScheduled("U")) ? : 0; - if ($origSelTs !== $currTs) { - $show = $selectedInstance->getCcShow($this->con); - throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!"); - } - - $currTs = intval($afterInstance->getDbLastScheduled("U")) ? : 0; - if ($origAfterTs !== $currTs) { - $show = $afterInstance->getCcShow($this->con); - throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!"); - } - - $this->removeGaps($selectedInstance->getDbId(), $selected->getDbId()); - - $data = $this->fileInfo; - $data["id"] = $selected->getDbFileId(); - $data["cliplength"] = $selected->getDbClipLength(); - $data["cuein"] = $selected->getDbCueIn(); - $data["cueout"] = $selected->getDbCueOut(); - $data["fadein"] = $selected->getDbFadeIn(); - $data["fadeout"] = $selected->getDbFadeOut(); - $data["sched_id"] = $selected->getDbId(); - - $this->insertAfter($afterItems, array($data), $adjustSched); - + + $this->insertAfter($afterItems, $movedData, $adjustSched); $this->con->commit(); Application_Model_RabbitMq::PushSchedule(); diff --git a/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js b/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js index 0d0acfffc..6ca255a06 100644 --- a/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js +++ b/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js @@ -50,10 +50,10 @@ var AIRTIME = (function(AIRTIME){ } if (selected.length === 1) { - message = "Moving "+selected.length+" Item."; + message = "Adding "+selected.length+" Item."; } else { - message = "Moving "+selected.length+" Items."; + message = "Adding "+selected.length+" Items."; } container = $('
') diff --git a/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js b/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js index c18d36b9e..b822e1bae 100644 --- a/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js +++ b/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js @@ -51,10 +51,10 @@ var AIRTIME = (function(AIRTIME){ } if (selected.length === 1) { - message = "Moving "+selected.length+" Item."; + message = "Adding "+selected.length+" Item."; } else { - message = "Moving "+selected.length+" Items."; + message = "Adding "+selected.length+" Items."; } container = $('
').attr('id', 'draggingContainer') diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 99fd2a6a2..064d0e4fd 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -222,14 +222,20 @@ var AIRTIME = (function(AIRTIME) { event.preventDefault(); } } - }, - hide: 'mouseout' - + }, + hide: 'mouseout' }); }, "fnDrawCallback": AIRTIME.library.events.fnDrawCallback, "fnHeaderCallback": function(nHead) { - $(nHead).find("input[type=checkbox]").attr("checked", false); + var oTT, + checked = $(nHead).find("input[type=checkbox]").filter(":checked"); + + if (checked.length > 0) { + oTT = TableTools.fnGetInstance('library_display'); + checked.attr("checked", false); + oTT.fnSelectNone(); + } }, "aaSorting": [[3, 'asc']], diff --git a/airtime_mvc/public/js/airtime/showbuilder/builder.js b/airtime_mvc/public/js/airtime/showbuilder/builder.js index 22c108026..b215b50d4 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/builder.js @@ -472,7 +472,9 @@ var AIRTIME = (function(AIRTIME){ fnReceive, fnUpdate, i, - html; + html, + helperData, + draggingContainer; fnAdd = function() { var aMediaIds = [], @@ -489,8 +491,11 @@ var AIRTIME = (function(AIRTIME){ fnMove = function() { var aSelect = [], aAfter = []; + + for(i = 0; i < helperData.length; i++) { + aSelect.push({"id": helperData[i].id, "instance": helperData[i].instance, "timestamp": helperData[i].timestamp}); + } - aSelect.push({"id": aItemData[0].id, "instance": aItemData[0].instance, "timestamp": aItemData[0].timestamp}); aAfter.push({"id": oPrevData.id, "instance": oPrevData.instance, "timestamp": oPrevData.timestamp}); AIRTIME.showbuilder.fnMove(aSelect, aAfter); @@ -533,7 +538,7 @@ var AIRTIME = (function(AIRTIME){ //item was dragged in if (origTrs !== undefined) { - $("#show_builder_table tr.ui-draggable") + tableDiv.find("tr.ui-draggable") .empty() .after(html); @@ -543,6 +548,11 @@ var AIRTIME = (function(AIRTIME){ } //item was reordered. else { + + ui.item + .empty() + .after(draggingContainer.html()); + aItemData.push(ui.item.data("aData")); fnMove(); } @@ -551,9 +561,54 @@ var AIRTIME = (function(AIRTIME){ return { placeholder: "placeholder show-builder-placeholder ui-state-highlight", forcePlaceholderSize: true, + helper: function(event, item) { + var oTT = TableTools.fnGetInstance('show_builder_table'), + selected = oTT.fnGetSelectedData(), + elements = tableDiv.find('tr:not(:first) input:checked').parents('tr'), + thead = $("#show_builder_table thead"), + colspan = thead.find("th").length, + trfirst = thead.find("tr:first"), + width = trfirst.width(), + height = trfirst.height(), + message; + + //elements.hide(); + + //if nothing is checked select the dragged item. + if (selected.length === 0) { + selected = [item.data("aData")]; + } + + if (selected.length === 1) { + message = "Moving "+selected.length+" Item."; + } + else { + message = "Moving "+selected.length+" Items."; + } + + draggingContainer = $('') + .addClass('sb-helper') + .append('') + .find("td") + .attr("colspan", colspan) + .width(width) + .height(height) + .addClass("ui-state-highlight") + .append(message) + .end(); + + helperData = selected; + + return draggingContainer; + }, items: 'tr:not(:first, :last, .sb-header, .sb-footer, .sb-not-allowed)', receive: fnReceive, - update: fnUpdate + update: fnUpdate, + start: function(event, ui) { + var elements = tableDiv.find('tr:not(:first) input:checked').parents('tr'); + + elements.hide(); + } }; }());