diff --git a/airtime_mvc/application/configs/navigation.php b/airtime_mvc/application/configs/navigation.php index 0eec09124..8ab913804 100644 --- a/airtime_mvc/application/configs/navigation.php +++ b/airtime_mvc/application/configs/navigation.php @@ -30,7 +30,7 @@ $pages = array( 'resource' => 'library' ), array( - 'label' => 'Show Builder', + 'label' => 'Airtimeline', 'module' => 'default', 'controller' => 'Showbuilder', 'action' => 'index', diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index eff66ab05..a1ed30f7a 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -49,7 +49,6 @@ class LibraryController extends Zend_Controller_Action $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.TableTools.js','text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/library.js','text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/advancedsearch.js','text/javascript'); $this->view->headLink()->appendStylesheet($baseUrl.'/css/media_library.css'); $this->view->headLink()->appendStylesheet($baseUrl.'/css/jquery.contextMenu.css'); @@ -74,6 +73,8 @@ class LibraryController extends Zend_Controller_Action $id = $this->_getParam('id'); $type = $this->_getParam('type'); + //playlist||timeline + $screen = $this->_getParam('screen'); $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -87,7 +88,7 @@ class LibraryController extends Zend_Controller_Action $menu["edit"] = array("name"=> "Edit Metadata", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}"); if ($user->isAdmin()) { - $menu["delete"] = array("name"=> "Delete", "icon" => "delete"); + $menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete"); } $url = $file->getRelativeFileUrl($baseUrl).'/download/true'; @@ -120,11 +121,11 @@ class LibraryController extends Zend_Controller_Action } else if ($type === "playlist") { - if (!isset($this->pl_sess->id) || $this->pl_sess->id !== $id) { + if ($this->pl_sess->id !== $id && $screen == "playlist") { $menu["edit"] = array("name"=> "Edit", "icon" => "edit"); } - $menu["delete"] = array("name"=> "Delete", "icon" => "delete"); + $menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete"); } $this->view->items = $menu; @@ -132,40 +133,52 @@ class LibraryController extends Zend_Controller_Action public function deleteAction() { - $ids = $this->_getParam('ids'); - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $user = new Application_Model_User($userInfo->id); + //array containing id and type of media to delete. + $mediaItems = $this->_getParam('media', null); - if ($user->isAdmin()) { + $user = Application_Model_User::GetCurrentUser(); - if (!is_null($ids)) { - foreach ($ids as $key => $id) { - $file = Application_Model_StoredFile::Recall($id); + $files = array(); + $playlists = array(); - if (PEAR::isError($file)) { - $this->view->message = $file->getMessage(); - return; - } - else if(is_null($file)) { - $this->view->message = "file doesn't exist"; - return; - } + $message = null; - $res = $file->delete(); + foreach ($mediaItems as $media) { - if (PEAR::isError($res)) { - $this->view->message = $res->getMessage(); - return; - } - else { - $res = settype($res, "integer"); - $data = array("filepath" => $file->getFilePath(), "delete" => $res); - Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data); - } - } - - $this->view->ids = $ids; + if ($media["type"] === "audioclip") { + $files[] = intval($media["id"]); } + else if ($media["type"] === "playlist") { + $playlists[] = intval($media["id"]); + } + } + + if (count($playlists)) { + Application_Model_Playlist::DeletePlaylists($playlists); + } + + if (!$user->isAdmin()) { + return; + } + + foreach ($files as $id) { + Logging::log("deleting file {$id}"); + + $file = Application_Model_StoredFile::Recall($id); + + if (isset($file)) { + try { + $res = $file->delete(); + } + //could throw a scheduled in future exception. + catch (Exception $e) { + $message = "Could not delete some scheduled files."; + } + } + } + + if (isset($message)) { + $this->view->message = $message; } } @@ -252,13 +265,15 @@ class LibraryController extends Zend_Controller_Action public function getUploadToSoundcloudStatusAction(){ $id = $this->_getParam('id'); $type = $this->_getParam('type'); - if($type == "show"){ + + if ($type == "show") { $show_instance = new Application_Model_ShowInstance($id); $this->view->sc_id = $show_instance->getSoundCloudFileId(); $file = $show_instance->getRecordedFile(); $this->view->error_code = $file->getSoundCloudErrorCode(); $this->view->error_msg = $file->getSoundCloudErrorMsg(); - }else{ + } + else if ($type == "file") { $file = Application_Model_StoredFile::Recall($id); $this->view->sc_id = $file->getSoundCloudId(); $this->view->error_code = $file->getSoundCloudErrorCode(); diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index d0ebc7c64..68ae26f61 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -103,17 +103,18 @@ class PlaylistController extends Zend_Controller_Action public function editAction() { - $pl_id = $this->_getParam('id', null); + $id = $this->_getParam('id', null); + Logging::log("editing playlist {$id}"); - if (!is_null($pl_id)) { - $this->changePlaylist($pl_id); + if (!is_null($id)) { + $this->changePlaylist($id); } try { $pl = $this->getPlaylist(); } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist {$pl_id} not found"); + Logging::log("Playlist {$id} not found"); $this->changePlaylist(null); } catch (Exception $e) { diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 1066378a2..27ad956b5 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -227,30 +227,6 @@ class Application_Model_StoredFile { return $md; } - /** - * Delete and insert media file - * - * @param string $p_localFilePath - * local path - * @return TRUE|PEAR_Error - */ - public function replaceFile($p_localFilePath, $p_copyMedia=TRUE) - { - // Dont do anything if the source and destination files are - // the same. - if ($this->name == $p_localFilePath) { - return TRUE; - } - - if ($this->exists) { - $r = $this->deleteFile(); - if (PEAR::isError($r)) { - return $r; - } - } - return $this->addFile($p_localFilePath, $p_copyMedia); - } - /** * Set state of virtual file * @@ -301,97 +277,27 @@ class Application_Model_StoredFile { * * @param boolean $p_deleteFile * - * @return void|PEAR_Error */ public function delete() { - if ($this->exists()) { - if ($this->getFormat() == 'audioclip') { - $res = $this->deleteFile(); - if (PEAR::isError($res)) { - return $res; - } - } + // Check if the file is scheduled to be played in the future + if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) { + throw new DeleteScheduledFileException(); } - // don't delete from the playslist. We might want to put a flag - //Application_Model_Playlist::DeleteFileFromAllPlaylists($this->getId()); + $filepath = $this->getFilePath(); + + if (file_exists($filepath)) { + + $data = array("filepath" => $filepath, "delete" => 1); + Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data); + } + + Application_Model_Playlist::DeleteFileFromAllPlaylists($this->getId()); // set file_exists falg to false $this->_file->setDbFileExists(false); $this->_file->save(); - //$this->_file->delete(); - - if (isset($res)) { - return $res; - } - else { - return false; - } - } - - /** - * Delete media file from filesystem. - * You cant delete a file if it is being accessed. - * You cant delete a file if it is scheduled to be played in the future. - * The file will be removed from all playlists it is a part of. - * - * @return boolean|PEAR_Error - */ - public function deleteFile() - { - global $CC_CONFIG; - - if ($this->isAccessed()) { - return PEAR::raiseError('Cannot delete a file that is currently accessed.'); - } - - // Check if the file is scheduled to be played in the future - if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) { - return PEAR::raiseError('Cannot delete a file that is scheduled in the future.'); - } - - return true; - } - - /** - * Returns true if media file exists - * @return boolean - */ - public function exists() - { - if ($this->_file->isDeleted()) { - return false; - } - if ($this->getFormat() == 'audioclip') { - return $this->existsFile(); - } - } - - /** - * Returns true if raw media file exists - * @return boolean - */ - public function existsFile() { - - $filepath = $this->getFilePath(); - - if (!isset($filepath) || !file_exists($filepath) || !is_readable($filepath)) { - return false; - } - else { - return true; - } - } - - /** - * Returns true if virtual file is currently in use.
- * - * @return boolean - */ - public function isAccessed() - { - return ($this->_file->getDbCurrentlyaccessing() > 0); } /** @@ -824,7 +730,7 @@ class Application_Model_StoredFile { $sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"]; } - Logging::log($sql); + //Logging::log($sql); $results = $CC_DBC->getAll($sql); @@ -1093,3 +999,4 @@ class Application_Model_StoredFile { } } +class DeleteScheduledFileException extends Exception {} diff --git a/airtime_mvc/public/js/airtime/library/advancedsearch.js b/airtime_mvc/public/js/airtime/library/advancedsearch.js deleted file mode 100644 index c8152f75c..000000000 --- a/airtime_mvc/public/js/airtime/library/advancedsearch.js +++ /dev/null @@ -1,66 +0,0 @@ -function addRemove(el) { - var id, span; - - id = $(el).attr("id").split("_").pop(); - - span = $('Remove').click(function(){ - $(this).parent().parent().remove(); - }); - - $(el).find("dl input").after(span); -} - -function ajaxAddRow() { - var group_id; - - group_id = $(this).parent().parent().attr("id").split("_").pop(); - - var url = '/Search/newfield/format/json'; - - $.post(url, {group: group_id}, function(json) { - - var newRow = $(json.html).find("#fieldset-row_"+json.row); - addRemove(newRow); - - $("#fieldset-group_"+group_id+" dl:first").append(newRow); - }); -} - -function removeGroup() { - $(this).parent().parent().remove(); -} - -function ajaxAddGroup() { - - var url = '/Search/newgroup/format/json'; - - $.post(url, function(json) { - - var group = $(json.html); - addRemove(group); - group.find('[id$="search_add_row"]').click(ajaxAddRow); - group.find('[id$="search_remove_group"]').click(removeGroup); - $(".zend_form").append(group); - }); -} - -function advancedSearchSubmit() { - var data = $("#advancedSearch form").serializeArray(); - - $.post("/Search/index", {format: "json", data: data}, function(json){ - var x; - }); -} - -$(document).ready(function() { - - $("#search_add_group").click(ajaxAddGroup); - $("#search_submit").click(advancedSearchSubmit); - - $('[id$="search_add_row"]').click(ajaxAddRow); - $('[id$="search_remove_group"]').click(removeGroup); - - $('[id^="fieldset-row_"]').each(function(i, el){ - addRemove(el); - }); -}); 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 a1e36f401..3da7be438 100644 --- a/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js +++ b/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js @@ -1,61 +1,67 @@ -function fnLibraryTableRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { +var AIRTIME = (function(AIRTIME){ + var mod; + + if (AIRTIME.library === undefined) { + AIRTIME.library = {} + } + + AIRTIME.library.events = {}; + mod = AIRTIME.library.events; + + mod.fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { + var $nRow = $(nRow); + + $nRow.attr("id", aData["tr_id"]) + .data("aData", aData) + .data("screen", "playlist"); + } + + mod.fnDrawCallback = function() { + + $('#library_display tr[id ^= "au"]').draggable({ + helper: 'clone', + /* customize the helper on dragging to look like a pl item + * + helper: function(ev) { + var data, li; + + data = $(ev.currentTarget).data("aData"); + + li = $("
  • "); + li.append(data.track_title); + + return li; + }, + */ + cursor: 'pointer', + connectToSortable: '#spl_sortable' + }); + } + + /* + * @param oTable the datatables instance for the library. + */ + mod.setupLibraryToolbar = function( oLibTable ) { + var aButtons, + fnResetCol; + + fnResetCol = function () { + ColReorder.fnReset( oLibTable ); + return false; + }; + + //[0] = button text + //[1] = id + //[2] = enabled + //[3] = click event + aButtons = [["Reset Order", "library_order_reset", true, fnResetCol], + ["Delete", "library_group_delete", true], + ["Add", "library_group_add", true]]; + + addToolBarButtonsLibrary(aButtons); + } + - $(nRow).attr("id", aData["tr_id"]); - $(nRow).data("aData", aData); - - //var oTT = TableTools.fnGetInstance('library_display'); - //oTT.fnSelect(el); - - /* - $(nRow).find('td') - .jjmenu("rightClick", - [{get:"/Library/context-menu/format/json/id/#id#/type/#type#"}], - {id: aData["id"], type: aData["ftype"]}, - {xposition: "mouse", yposition: "mouse"}); - */ -} - -function fnLibraryTableDrawCallback() { + return AIRTIME; - $('#library_display tr[id ^= "au"]').draggable({ - helper: 'clone', - /* - helper: function(ev) { - var data, li; - - data = $(ev.currentTarget).data("aData"); - - li = $("
  • "); - li.append(data.track_title); - - return li; - }, - */ - cursor: 'pointer', - connectToSortable: '#spl_sortable' - }); -} - -/* - * @param oTable the datatables instance for the library. - */ -function setupLibraryToolbar(oLibTable) { - var aButtons, - oLibTT = TableTools.fnGetInstance('library_display'), - fnResetCol; - - fnResetCol = function () { - ColReorder.fnReset( oLibTable ); - return false; - }; - - //[0] = button text - //[1] = id - //[2] = enabled - //[3] = click event - aButtons = [["Reset Order", "library_order_reset", true, fnResetCol], - ["Delete", "library_group_delete", true], - ["Add", "library_group_add", true]]; - - addToolBarButtonsLibrary(aButtons); -} +}(AIRTIME || {})); 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 4ab9afdc5..d37d6aca1 100644 --- a/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js +++ b/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js @@ -1,80 +1,92 @@ -function fnLibraryTableRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { - var jRow = $(nRow); +var AIRTIME = (function(AIRTIME){ + var mod; - jRow.attr("id", aData["tr_id"]); - jRow.addClass("lib-sb"); - - //save some info for reordering purposes. - jRow.data({"aData": aData}); -} - -function fnLibraryTableDrawCallback() { + if (AIRTIME.library === undefined) { + AIRTIME.library = {} + } - $('#library_display tr:not(:first)').draggable({ - helper: 'clone', - cursor: 'pointer', - connectToSortable: '#show_builder_table' - }); -} - -function setupLibraryToolbar(oLibTable) { - var aButtons, - fnTest, - fnResetCol, - fnAddSelectedItems, - oSchedTable = $("#show_builder_table").dataTable(), - oLibTT = TableTools.fnGetInstance('library_display'), - oSchedTT = TableTools.fnGetInstance('show_builder_table'); + AIRTIME.library.events = {}; + mod = AIRTIME.library.events; - fnTest = function() { - alert("hi"); - }; - - fnResetCol = function () { - ColReorder.fnReset( oLibTable ); - return false; - }; - - fnAddSelectedItems = function() { - var aData = oLibTT.fnGetSelectedData(), - item, - temp, - aMediaIds = [], - aSchedIds = []; + mod.fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { + var $nRow = $(nRow); - //process selected files/playlists. - for (item in aData) { - temp = aData[item]; - if (temp !== null && temp.hasOwnProperty('id')) { - aMediaIds.push({"id": temp.id, "type": temp.ftype}); - } - } + $nRow.attr("id", aData["tr_id"]) + .data("aData", aData) + .data("screen", "timeline"); + } - aData = oSchedTT.fnGetSelectedData(); + mod.fnDrawCallback = function() { - //process selected schedule rows to add media after. - for (item in aData) { - temp = aData[item]; - if (temp !== null && temp.hasOwnProperty('id')) { - aSchedIds.push({"id": temp.id, "instance": temp.instance}); - } - } - - $.post("/showbuilder/schedule-add", - {"format": "json", "mediaIds": aMediaIds, "schedIds": aSchedIds}, - function(json){ - oLibTT.fnSelectNone(); - oSchedTT.fnSelectNone(); - oSchedTable.fnDraw(); - }); - }; - //[0] = button text - //[1] = id - //[2] = enabled - //[3] = click event - aButtons = [["Reset Order", "library_order_reset", true, fnResetCol], - ["Delete", "library_group_delete", true, fnTest], - ["Add", "library_group_add", true, fnAddSelectedItems]]; + $('#library_display tr:not(:first)').draggable({ + helper: 'clone', + cursor: 'pointer', + connectToSortable: '#show_builder_table' + }); + } - addToolBarButtonsLibrary(aButtons); -} \ No newline at end of file + mod.setupLibraryToolbar = function(oLibTable) { + var aButtons, + fnTest, + fnResetCol, + fnAddSelectedItems, + + fnTest = function() { + alert("hi"); + }; + + fnResetCol = function () { + ColReorder.fnReset( oLibTable ); + return false; + }; + + fnAddSelectedItems = function() { + var aData = oLibTT.fnGetSelectedData(), + item, + temp, + aMediaIds = [], + aSchedIds = [], + oSchedTable = $("#show_builder_table").dataTable(), + oLibTT = TableTools.fnGetInstance('library_display'), + oSchedTT = TableTools.fnGetInstance('show_builder_table');; + + //process selected files/playlists. + for (item in aData) { + temp = aData[item]; + if (temp !== null && temp.hasOwnProperty('id')) { + aMediaIds.push({"id": temp.id, "type": temp.ftype}); + } + } + + aData = oSchedTT.fnGetSelectedData(); + + //process selected schedule rows to add media after. + for (item in aData) { + temp = aData[item]; + if (temp !== null && temp.hasOwnProperty('id')) { + aSchedIds.push({"id": temp.id, "instance": temp.instance}); + } + } + + $.post("/showbuilder/schedule-add", + {"format": "json", "mediaIds": aMediaIds, "schedIds": aSchedIds}, + function(json){ + oLibTT.fnSelectNone(); + oSchedTT.fnSelectNone(); + oSchedTable.fnDraw(); + }); + }; + //[0] = button text + //[1] = id + //[2] = enabled + //[3] = click event + aButtons = [["Reset Order", "library_order_reset", true, fnResetCol], + ["Delete", "library_group_delete", true, fnTest], + ["Add", "library_group_add", true, fnAddSelectedItems]]; + + addToolBarButtonsLibrary(aButtons); + } + + return AIRTIME; + +}(AIRTIME || {})); \ No newline at end of file diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 6a6d9523a..33cc15f5d 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -37,39 +37,6 @@ function disableGroupBtn(btnId) { } } -function deleteItem(type, id) { - var tr_id, tr, dt; - - tr_id = type+"_"+id; - tr = $("#"+tr_id); - - dt = $("#library_display").dataTable(); - dt.fnDeleteRow( tr ); -} - -function deleteAudioClip(json) { - if(json.message) { - alert(json.message); - return; - } - - if (json.ids != undefined) { - for (var i = json.ids.length - 1; i >= 0; i--) { - deleteItem("au", json.ids[i]); - } - } - else if (json.id != undefined) { - deleteItem("au", json.id); - } - location.reload(true); -} - -function confirmDeleteGroup() { - if(confirm('Are you sure you want to delete the selected items?')){ - groupDelete(); - } -} - function checkImportStatus(){ $.getJSON('/Preference/is-import-in-progress', function(data){ var div = $('#import_status'); @@ -81,40 +48,41 @@ function checkImportStatus(){ }); } -function deletePlaylist(json) { - if(json.message) { - alert(json.message); - return; - } - - if (json.ids != undefined) { - for (var i = json.ids.length - 1; i >= 0; i--) { - deleteItem("pl", json.ids[i]); - } - } else if (json.id != undefined) { - deleteItem("pl", json.id); - } - window.location.reload(); -} - function addProgressIcon(id) { - if($("#au_"+id).find("td.library_title").find("span").length > 0){ - $("#au_"+id).find("td.library_title").find("span").removeClass(); - $("span[id="+id+"]").addClass("small-icon progress"); - }else{ - $("#au_"+id).find("td.library_title").append(''); + var tr = $("#au_"+id), + span; + + span = tr.find("td.library_title").find("span"); + + if (span.length > 0){ + span.removeClass() + .addClass("small-icon progress"); + } + else{ + tr.find("td.library_title") + .append(''); } } function checkSCUploadStatus(){ - var url = '/Library/get-upload-to-soundcloud-status/format/json'; + + var url = '/Library/get-upload-to-soundcloud-status'; + $("span[class*=progress]").each(function(){ - var id = $(this).attr("id"); + var span, id; + + span = $(this); + id = span.parentsUntil('tr').attr("id").split("_").pop(); + $.post(url, {format: "json", id: id, type:"file"}, function(json){ - if(json.sc_id > 0){ - $("span[id="+id+"]").removeClass("progress").addClass("soundcloud"); - }else if(json.sc_id == "-3"){ - $("span[id="+id+"]").removeClass("progress").addClass("sc-error"); + if (json.sc_id > 0) { + span.removeClass("progress") + .addClass("soundcloud"); + + } + else if (json.sc_id == "-3") { + span.removeClass("progress") + .addClass("sc-error"); } }); }); @@ -280,10 +248,9 @@ function createDataTable(data) { "success": testCallback } ); }, - "fnRowCallback": fnLibraryTableRowCallback, + "fnRowCallback": AIRTIME.library.events.fnRowCallback, "fnCreatedRow": fnCreatedRow, - "fnCreatedRowCallback": fnCreatedRow, - "fnDrawCallback": fnLibraryTableDrawCallback, + "fnDrawCallback": AIRTIME.library.events.fnDrawCallback, "fnHeaderCallback": function(nHead) { $(nHead).find("input[type=checkbox]").attr("checked", false); }, @@ -353,7 +320,7 @@ function createDataTable(data) { }); oTable.fnSetFilteringDelay(350); - setupLibraryToolbar(oTable); + AIRTIME.library.events.setupLibraryToolbar(oTable); $('[name="pl_cb_all"]').click(function(){ var oTT = TableTools.fnGetInstance('library_display'); @@ -385,9 +352,11 @@ $(document).ready(function() { ignoreRightClick: true, build: function($el, e) { - var x, request, data, items, callback; + var x, request, data, screen, items, callback, $tr; - data = $el.parent().data("aData"); + $tr = $el.parent(); + data = $tr.data("aData"); + screen = $tr.data("screen"); function processMenuItems(oItems) { @@ -400,11 +369,46 @@ $(document).ready(function() { }; } else { - + callback = function() { + AIRTIME.playlist.fnEdit(data.id); + }; } oItems.edit.callback = callback; } + //define a delete callback. + if (oItems.del !== undefined) { + + //delete through the playlist controller, will reset + //playlist screen if this is the currently edited playlist. + if (data.ftype === "playlist" && screen === "playlist") { + callback = function() { + + if (confirm('Are you sure you want to delete the selected item?')) { + AIRTIME.playlist.fnDelete(data.id); + } + }; + } + else { + callback = function() { + var media = []; + + if (confirm('Are you sure you want to delete the selected item?')) { + + media.push({"id": data.id, "type": data.ftype}); + $.post(oItems.del.url, {format: "json", media: media }, function(json){ + var oTable, tr; + + oTable = $("#library_display").dataTable(); + oTable.fnDeleteRow( $tr[0] ); + }); + } + }; + } + + oItems.del.callback = callback; + } + //define a download callback. if (oItems.download !== undefined) { @@ -444,7 +448,7 @@ $(document).ready(function() { request = $.ajax({ url: "/library/context-menu", type: "GET", - data: {id : data.id, type: data.ftype, format: "json"}, + data: {id : data.id, type: data.ftype, format: "json", "screen": screen}, dataType: "json", async: false, success: function(json){ @@ -452,16 +456,7 @@ $(document).ready(function() { } }); - - - // this callback is executed every time the menu is to be shown - // its results are destroyed every time the menu is hidden - // e is the original contextmenu event, containing e.pageX and e.pageY (amongst other data) return { - callback: function(key, options) { - var m = "clicked: " + key; - window.console && console.log(m) || alert(m); - }, items: items, determinePosition : function($menu, x, y) { $menu.css('display', 'block') diff --git a/airtime_mvc/public/js/airtime/library/spl.js b/airtime_mvc/public/js/airtime/library/spl.js index 1b040ad1b..553e42196 100644 --- a/airtime_mvc/public/js/airtime/library/spl.js +++ b/airtime_mvc/public/js/airtime/library/spl.js @@ -538,15 +538,26 @@ var AIRTIME = (function(AIRTIME){ }); } - mod.fnEdit = function() { + mod.fnEdit = function(id) { + var url; + stopAudioPreview(); + + url = '/Playlist/edit'; + + $.post(url, + {format: "json", id: id}, + function(json){ + openPlaylist(json); + //redrawLib(); + }); } - mod.fnDelete = function() { + mod.fnDelete = function(plid) { var url, id, lastMod; stopAudioPreview(); - id = getId(); + id = (plid === undefined) ? getId() : plid; lastMod = getModified(); url = '/Playlist/delete';