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 = $('').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 = $("