diff --git a/airtime_mvc/application/configs/ACL.php b/airtime_mvc/application/configs/ACL.php index 511763bf6..ae6d83625 100644 --- a/airtime_mvc/application/configs/ACL.php +++ b/airtime_mvc/application/configs/ACL.php @@ -16,7 +16,6 @@ $ccAcl->add(new Zend_Acl_Resource('library')) ->add(new Zend_Acl_Resource('error')) ->add(new Zend_Acl_Resource('login')) ->add(new Zend_Acl_Resource('whmcs-login')) - ->add(new Zend_Acl_Resource('new-playlist')) ->add(new Zend_Acl_Resource('playlist')) ->add(new Zend_Acl_Resource('plupload')) ->add(new Zend_Acl_Resource('schedule')) @@ -25,13 +24,11 @@ $ccAcl->add(new Zend_Acl_Resource('library')) ->add(new Zend_Acl_Resource('dashboard')) ->add(new Zend_Acl_Resource('preference')) ->add(new Zend_Acl_Resource('showbuilder')) - ->add(new Zend_Acl_Resource('show-builder')) ->add(new Zend_Acl_Resource('playouthistory')) ->add(new Zend_Acl_Resource('playouthistorytemplate')) ->add(new Zend_Acl_Resource('listenerstat')) ->add(new Zend_Acl_Resource('usersettings')) ->add(new Zend_Acl_Resource('audiopreview')) - ->add(new Zend_Acl_Resource('new-webstream')) ->add(new Zend_Acl_Resource('webstream')) ->add(new Zend_Acl_Resource('locale')) ->add(new Zend_Acl_Resource('upgrade')) @@ -53,12 +50,10 @@ $ccAcl->allow('G', 'index') ->allow('G', 'error') ->allow('G', 'user', 'edit-user') ->allow('G', 'showbuilder') - ->allow('G', 'show-builder') ->allow('G', 'api') ->allow('G', 'schedule') ->allow('G', 'dashboard') ->allow('G', 'audiopreview') - ->allow('G', 'new-webstream') ->allow('G', 'webstream') ->allow('G', 'locale') ->allow('G', 'upgrade') @@ -74,7 +69,6 @@ $ccAcl->allow('G', 'index') ->allow('H', 'usersettings') ->allow('H', 'plupload') ->allow('H', 'library') - ->allow('H', 'new-playlist') ->allow('H', 'playlist') ->allow('H', 'playouthistory') ->allow('A', 'playouthistorytemplate') diff --git a/airtime_mvc/application/controllers/NewPlaylistController.php b/airtime_mvc/application/controllers/NewPlaylistController.php deleted file mode 100644 index 7d768ffaf..000000000 --- a/airtime_mvc/application/controllers/NewPlaylistController.php +++ /dev/null @@ -1,648 +0,0 @@ -_helper->getHelper('AjaxContext'); - $ajaxContext->addActionContext('add-items', 'json') - ->addActionContext('move-items', 'json') - ->addActionContext('delete-items', 'json') - ->addActionContext('set-fade', 'json') - ->addActionContext('set-crossfade', 'json') - ->addActionContext('set-cue', 'json') - ->addActionContext('new', 'json') - ->addActionContext('edit', 'json') - ->addActionContext('delete', 'json') - ->addActionContext('close-playlist', 'json') - ->addActionContext('play', 'json') - ->addActionContext('set-playlist-fades', 'json') - ->addActionContext('get-playlist-fades', 'json') - ->addActionContext('set-playlist-name', 'json') - ->addActionContext('set-playlist-description', 'json') - ->addActionContext('playlist-preview', 'json') - ->addActionContext('get-playlist', 'json') - ->addActionContext('save', 'json') - ->addActionContext('smart-block-generate', 'json') - ->addActionContext('smart-block-shuffle', 'json') - ->addActionContext('get-block-info', 'json') - ->addActionContext('shuffle', 'json') - ->addActionContext('empty-content', 'json') - ->initContext(); - - //This controller writes to the session all over the place, so we're going to reopen it for writing here. - session_start(); //Reopen the session for writing - } - - private function getPlaylist($p_type) - { - $obj = null; - $objInfo = Application_Model_Library::getObjInfo($p_type); - - $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); - - if (isset($obj_sess->id)) { - $obj = new $objInfo['className']($obj_sess->id); - - $modified = $this->_getParam('modified', null); - if ($obj->getLastModified("U") !== $modified) { - $this->createFullResponse($obj); - throw new PlaylistOutDatedException(sprintf(_("You are viewing an older version of %s"), $obj->getName())); - } - } - - return $obj; - } - - private function createUpdateResponse($obj) - { - $formatter = new LengthFormatter($obj->getLength()); - $this->view->length = $formatter->format(); - - $this->view->obj = $obj; - $this->view->contents = $obj->getContents(); - $this->view->html = $this->view->render('playlist/update.phtml'); - $this->view->name = $obj->getName(); - $this->view->description = $obj->getDescription(); - $this->view->modified = $obj->getLastModified("U"); - - unset($this->view->obj); - } - - private function createFullResponse($obj = null, $isJson = false, - $formIsValid = false) - { - $isBlock = false; - $viewPath = 'playlist/_playlist.phtml'; - if ($obj instanceof Application_Model_Block) { - $isBlock = true; - $viewPath = 'playlist/_smart-block.phtml'; - } - if (isset($obj)) { - $formatter = new LengthFormatter($obj->getLength()); - $this->view->length = $formatter->format(); - - if ($isBlock) { - $form = new Application_Form_SmartBlockCriteriaNew(); - $form->removeDecorator('DtDdWrapper'); - $form->startForm($obj->getId(), $formIsValid); - - $this->view->form = $form; - $this->view->obj = $obj; - $this->view->type = "sb"; - $this->view->id = $obj->getId(); - - if ($isJson) { - return $this->view->render($viewPath); - } else { - $this->view->html = $this->view->render($viewPath); - } - } else { - $this->view->obj = $obj; - $this->view->type = "pl"; - $this->view->id = $obj->getId(); - if ($isJson) { - return $this->view->html = $this->view->render($viewPath); - } else { - $this->view->html = $this->view->render($viewPath); - } - unset($this->view->obj); - } - } else { - if ($isJson) { - return $this->view->render($viewPath); - } else { - $this->view->html = $this->view->render($viewPath); - } - } - } - - private function playlistOutdated($e) - { - $this->view->error = $e->getMessage(); - } - - private function blockDynamic($obj) - { - $this->view->error = _("You cannot add tracks to dynamic blocks."); - $this->createFullResponse($obj); - } - - private function playlistNotFound($p_type, $p_isJson = false) - { - $p_type = ucfirst($p_type); - $this->view->error = sprintf(_("%s not found"), $p_type); - - Logging::info("{$p_type} not found"); - Application_Model_Library::changePlaylist(null, $p_type); - - if (!$p_isJson) { - $this->createFullResponse(null); - } else { - $this->_helper->json->sendJson(array("error"=>$this->view->error, "result"=>1, "html"=>$this->createFullResponse(null, $p_isJson))); - } - } - - private function playlistNoPermission($p_type) - { - $this->view->error = sprintf(_("You don't have permission to delete selected %s(s)."), $p_type); - $this->changePlaylist(null, $p_type); - $this->createFullResponse(null); - } - - private function playlistUnknownError($e) - { - $this->view->error = _("Something went wrong."); - Logging::info($e->getMessage()); - } - - private function wrongTypeToBlock($obj) - { - $this->view->error = _("You can only add tracks to smart block."); - $this->createFullResponse($obj); - } - - private function wrongTypeToPlaylist($obj) - { - $this->view->error = _("You can only add tracks, smart blocks, and webstreams to playlists."); - $this->createFullResponse($obj); - } - - public function newAction() - { - //$pl_sess = $this->pl_sess; - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $type = $this->_getParam('type'); - - $objInfo = Application_Model_Library::getObjInfo($type); - - $name = _('Untitled Playlist'); - if ($type == 'block') { - $name = _('Untitled Smart Block'); - } - - $obj = new $objInfo['className'](); - $obj->setName($name); - $obj->setMetadata('dc:creator', $userInfo->id); - - Application_Model_Library::changePlaylist($obj->getId(), $type); - $this->createFullResponse($obj); - } - - public function editAction() - { - $id = $this->_getParam('id', null); - $type = $this->_getParam('type'); - $objInfo = Application_Model_Library::getObjInfo($type); - Logging::info("editing {$type} {$id}"); - -// if (!is_null($id)) { - Application_Model_Library::changePlaylist($id, $type); -// } - - try { - $obj = new $objInfo['className']($id); - $this->createFullResponse($obj); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound(); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function deleteAction() - { - $ids = $this->_getParam('ids'); - $ids = (!is_array($ids)) ? array($ids) : $ids; - $type = $this->_getParam('type'); - - $obj = null; - - $objInfo = Application_Model_Library::getObjInfo($type); - - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - - $obj_sess = new Zend_Session_Namespace( - UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); - - try { - Logging::info("Currently active {$type} {$obj_sess->id}"); - if (in_array($obj_sess->id, $ids)) { - Logging::info("Deleting currently active {$type}"); - Application_Model_Library::changePlaylist(null, $type); - } else { - Logging::info("Not deleting currently active {$type}"); - $obj = new $objInfo['className']($obj_sess->id); - } - - if (strcmp($objInfo['className'], 'Application_Model_Playlist')==0) { - Application_Model_Playlist::deletePlaylists($ids, $userInfo->id); - } else { - Application_Model_Block::deleteBlocks($ids, $userInfo->id); - } - $this->createFullResponse($obj); - } catch (PlaylistNoPermissionException $e) { - $this->playlistNoPermission($type); - } catch (BlockNoPermissionException $e) { - $this->playlistNoPermission($type); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function closePlaylistAction() { - $type = $this->_getParam('type'); - $obj = null; - Application_Model_Library::changePlaylist($obj, $type); - $this->createFullResponse($obj); - } - - public function addItemsAction() - { - $ids = $this->_getParam('aItems', array()); - $ids = (!is_array($ids)) ? array($ids) : $ids; - $afterItem = $this->_getParam('afterItem', null); - $addType = $this->_getParam('type', 'after'); - // this is the obj type of destination - $obj_type = $this->_getParam('obj_type'); - - try { - $obj = $this->getPlaylist($obj_type); - if ($obj_type == 'playlist') { - foreach ($ids as $id) { - if (is_array($id) && isset($id[1])) { - if ($id[1] == 'playlist') { - throw new WrongTypeToPlaylistException; - } - } - } - $obj->addAudioClips($ids, $afterItem, $addType); - } elseif ($obj->isStatic()) { - // if the dest is a block object - //check if any items are playlists - foreach ($ids as $id) { - if (is_array($id) && isset($id[1])) { - if ($id[1] != 'audioclip') { - throw new WrongTypeToBlockException; - } - } - } - $obj->addAudioClips($ids, $afterItem, $addType); - } else { - throw new BlockDynamicException; - } - $this->createUpdateResponse($obj); - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($obj_type); - } catch (WrongTypeToBlockException $e) { - $this->wrongTypeToBlock($obj); - } catch (WrongTypeToPlaylistException $e) { - $this->wrongTypeToPlaylist($obj); - } catch (BlockDynamicException $e) { - $this->blockDynamic($obj); - } catch (BlockNotFoundException $e) { - $this->playlistNotFound($obj_type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function moveItemsAction() - { - $ids = $this->_getParam('ids'); - $ids = (!is_array($ids)) ? array($ids) : $ids; - $afterItem = $this->_getParam('afterItem', null); - $type = $this->_getParam('obj_type'); - - try { - $obj = $this->getPlaylist($type); - $obj->moveAudioClips($ids, $afterItem); - $this->createUpdateResponse($obj); - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function deleteItemsAction() - { - $ids = $this->_getParam('ids'); - $ids = (!is_array($ids)) ? array($ids) : $ids; - $modified = $this->_getParam('modified'); - $type = $this->_getParam('obj_type'); - - try { - $obj = $this->getPlaylist($type); - $obj->delAudioClips($ids); - $this->createUpdateResponse($obj); - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function emptyContentAction() - { - $type = $this->_getParam('obj_type'); - try { - $obj = $this->getPlaylist($type); - if ($type == 'playlist') { - $obj->deleteAllFilesFromPlaylist(); - } else { - $obj->deleteAllFilesFromBlock(); - } - $this->createUpdateResponse($obj); - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function setCueAction() - { - $id = $this->_getParam('id'); - $cueIn = $this->_getParam('cueIn', null); - $cueOut = $this->_getParam('cueOut', null); - $type = $this->_getParam('type'); - - try { - $obj = $this->getPlaylist($type); - $response = $obj->changeClipLength($id, $cueIn, $cueOut); - - if (!isset($response["error"])) { - $this->view->response = $response; - $this->createUpdateResponse($obj); - } else { - $this->view->cue_error = $response["error"]; - $this->view->code = $response["type"]; - } - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function setFadeAction() - { - $id = $this->_getParam('id'); - $fadeIn = $this->_getParam('fadeIn', null); - $fadeOut = $this->_getParam('fadeOut', null); - $type = $this->_getParam('type'); - - try { - $obj = $this->getPlaylist($type); - $response = $obj->changeFadeInfo($id, $fadeIn, $fadeOut); - - if (!isset($response["error"])) { - $this->createUpdateResponse($obj); - $this->view->response = $response; - } else { - $this->view->fade_error = $response["error"]; - } - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function setCrossfadeAction() - { - $id1 = $this->_getParam('id1', null); - $id2 = $this->_getParam('id2', null); - $type = $this->_getParam('type'); - $fadeIn = $this->_getParam('fadeIn', 0); - $fadeOut = $this->_getParam('fadeOut', 0); - $offset = $this->_getParam('offset', 0); - - try { - $obj = $this->getPlaylist($type); - $response = $obj->createCrossfade($id1, $fadeOut, $id2, $fadeIn, $offset); - - if (!isset($response["error"])) { - $this->createUpdateResponse($obj); - } else { - $this->view->error = $response["error"]; - } - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function getPlaylistFadesAction() - { - $type = $this->_getParam('type'); - try { - $obj = $this->getPlaylist($type); - $fades = $obj->getFadeInfo(0); - $this->view->fadeIn = $fades[0]; - - $fades = $obj->getFadeInfo($obj->getSize()-1); - $this->view->fadeOut = $fades[1]; - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - /** - * The playlist fades are stored in the elements themselves. - * The fade in is set to the first elements fade in and - * the fade out is set to the last elements fade out. - **/ - public function setPlaylistFadesAction() - { - $fadeIn = $this->_getParam('fadeIn', null); - $fadeOut = $this->_getParam('fadeOut', null); - $type = $this->_getParam('type'); - - try { - $obj = $this->getPlaylist($type); - $obj->setfades($fadeIn, $fadeOut); - $this->view->modified = $obj->getLastModified("U"); - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function setPlaylistNameDescAction() - { - $name = $this->_getParam('name', _('Unknown Playlist')); - $description = $this->_getParam('description', ""); - $type = $this->_getParam('type'); - - try { - $obj = $this->getPlaylist($type); - $obj->setName(trim($name)); - $obj->setDescription($description); - $this->view->description = $description; - $this->view->playlistName = $name; - $this->view->modified = $obj->getLastModified("U"); - } catch (PlaylistOutDatedException $e) { - $this->playlistOutdated($e); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound($type, true); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function saveAction() - { - $request = $this->getRequest(); - $params = $request->getPost(); - $result = array(); - - if ($params['type'] == 'block') { - try { - $bl = new Application_Model_Block($params['obj_id']); - } catch (BlockNotFoundException $e) { - $this->playlistNotFound('block', true); - } - $form = new Application_Form_SmartBlockCriteriaNew(); - $form->startForm($params['obj_id']); - if ($form->isValid($params)) { - $this->setPlaylistNameDescAction(); - $bl->saveSmartBlockCriteria($params['data']); - $result['html'] = $this->createFullResponse($bl, true, true); - $result['result'] = 0; - } else { - $this->view->form = $form; - $this->view->unsavedName = $params['name']; - $this->view->unsavedDesc = $params['description']; - $viewPath = 'playlist/_smart-block.phtml'; - $this->view->obj = $bl; - $this->view->id = $bl->getId(); - $result['html'] = $this->view->render($viewPath); - $result['result'] = 1; - } - $result['type'] = "sb"; - $result['id'] = $bl->getId(); - $result["modified"] = $bl->getLastModified("U"); - } else if ($params['type'] == 'playlist') { - $this->setPlaylistNameDescAction(); - $result["modified"] = $this->view->modified; - } - - $this->_helper->json->sendJson($result); - } - - public function smartBlockGenerateAction() - { - $request = $this->getRequest(); - $params = $request->getPost(); - - //make sure block exists - try { - $bl = new Application_Model_Block($params['obj_id']); - - $form = new Application_Form_SmartBlockCriteriaNew(); - $form->startForm($params['obj_id']); - if ($form->isValid($params)) { - $result = $bl->generateSmartBlock($params['data']); - $this->_helper->json->sendJson(array("result"=>0, "html"=>$this->createFullResponse($bl, true, true))); - } else { - $this->view->obj = $bl; - $this->view->id = $bl->getId(); - $this->view->form = $form; - $viewPath = 'playlist/_smart-block.phtml'; - $result['html'] = $this->view->render($viewPath); - $result['result'] = 1; - $this->_helper->json->sendJson($result); - } - } catch (BlockNotFoundException $e) { - $this->playlistNotFound('block', true); - } catch (Exception $e) { - Logging::info($e); - $this->playlistUnknownError($e); - } - } - - public function smartBlockShuffleAction() - { - $request = $this->getRequest(); - $params = $request->getPost(); - try { - $bl = new Application_Model_Block($params['obj_id']); - $result = $bl->shuffleSmartBlock(); - - if ($result['result'] == 0) { - $this->_helper->json->sendJson(array("result"=>0, "html"=>$this->createFullResponse($bl, true))); - } else { - $this->_helper->json->sendJson($result); - } - } catch (BlockNotFoundException $e) { - $this->playlistNotFound('block', true); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function shuffleAction() - { - $request = $this->getRequest(); - $params = $request->getPost(); - try { - $pl = new Application_Model_Playlist($params['obj_id']); - $result = $pl->shuffle(); - - if ($result['result'] == 0) { - $this->_helper->json->sendJson(array("result"=>0, "html"=>$this->createFullResponse($pl, true))); - } else { - $this->_helper->json->sendJson($result); - } - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound('block', true); - } catch (Exception $e) { - $this->playlistUnknownError($e); - } - } - - public function getBlockInfoAction() - { - $request = $this->getRequest(); - $params = $request->getPost(); - $bl = new Application_Model_Block($params['id']); - if ($bl->isStatic()) { - $out = $bl->getContents(); - $out['isStatic'] = true; - } else { - $out = $bl->getCriteria(); - $out['isStatic'] = false; - } - $this->_helper->json->sendJson($out); - } -} -class WrongTypeToBlockException extends Exception {} -class WrongTypeToPlaylistException extends Exception {} -class BlockDynamicException extends Exception {} diff --git a/airtime_mvc/application/controllers/NewWebstreamController.php b/airtime_mvc/application/controllers/NewWebstreamController.php deleted file mode 100644 index 22db7bf7f..000000000 --- a/airtime_mvc/application/controllers/NewWebstreamController.php +++ /dev/null @@ -1,150 +0,0 @@ -_helper->getHelper('AjaxContext'); - $ajaxContext->addActionContext('new', 'json') - ->addActionContext('save', 'json') - ->addActionContext('edit', 'json') - ->addActionContext('delete', 'json') - ->initContext(); - } - - public function newAction() - { - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - if (!$this->isAuthorized(-1)) { - // TODO: this header call does not actually print any error message - header("Status: 401 Not Authorized"); - return; - } - - $webstream = new CcWebstream(); - - //we're not saving this primary key in the DB so it's OK to be -1 - $webstream->setDbId(-1); - $webstream->setDbName(_("Untitled Webstream")); - $webstream->setDbDescription(""); - $webstream->setDbUrl("http://"); - $webstream->setDbLength("00:30:00"); - $webstream->setDbName(_("Untitled Webstream")); - $webstream->setDbCreatorId($userInfo->id); - $webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC'))); - $webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC'))); - - //clear the session in case an old playlist was open: CC-4196 - Application_Model_Library::changePlaylist(null, null); - - $this->view->obj = new Application_Model_Webstream($webstream); - $this->view->action = "new"; - $this->view->html = $this->view->render('webstream/_webstream.phtml'); - } - - public function editAction() - { - $request = $this->getRequest(); - - $id = $request->getParam("id"); - if (is_null($id)) { - throw new Exception("Missing parameter 'id'"); - } - - $webstream = CcWebstreamQuery::create()->findPK($id); - if ($webstream) { - Application_Model_Library::changePlaylist($id, "stream"); - } - $this->view->obj = new Application_Model_Webstream($webstream); - $this->view->action = "edit"; - $this->view->html = $this->view->render('webstream/_webstream.phtml'); - } - - public function deleteAction() - { - $request = $this->getRequest(); - $id = $request->getParam("ids"); - - if (!$this->isAuthorized($id)) { - header("Status: 401 Not Authorized"); - - return; - } - - $type = "stream"; - Application_Model_Library::changePlaylist(null, $type); - - $webstream = CcWebstreamQuery::create()->findPK($id)->delete(); - - $this->view->obj = null; - $this->view->action = "delete"; - $this->view->html = $this->view->render('webstream/_webstream.phtml'); - - } - - /*TODO : make a user object be passed a parameter into this function so - that it does not have to be fetched multiple times.*/ - public function isAuthorized($webstream_id) - { - $user = Application_Model_User::getCurrentUser(); - if ($user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { - return true; - } - - if ($user->isHost()) { - // not creating a webstream - if ($webstream_id != -1) { - $webstream = CcWebstreamQuery::create()->findPK($webstream_id); - /*we are updating a playlist. Ensure that if the user is a - host/dj, that he has the correct permission.*/ - $user = Application_Model_User::getCurrentUser(); - //only allow when webstream belongs to the DJ - return $webstream->getDbCreatorId() == $user->getId(); - } - /*we are creating a new stream. Don't need to check whether the - DJ/Host owns the stream*/ - return true; - } else { - Logging::info( $user ); - } - return false; - } - - public function saveAction() - { - $request = $this->getRequest(); - - $id = $request->getParam("id"); - - $parameters = array(); - foreach (array('id','length','name','description','url') as $p) { - $parameters[$p] = trim($request->getParam($p)); - } - - if (!$this->isAuthorized($id)) { - header("Status: 401 Not Authorized"); - return; - } - - - list($analysis, $mime, $mediaUrl, $di) = Application_Model_Webstream::analyzeFormData($parameters); - try { - if (Application_Model_Webstream::isValid($analysis)) { - $streamId = Application_Model_Webstream::save($parameters, $mime, $mediaUrl, $di); - - Application_Model_Library::changePlaylist($streamId, "stream"); - - $this->view->statusMessage = "
"._("Webstream saved.")."
"; - $this->view->streamId = $streamId; - $this->view->length = $di->format("%Hh %Im"); - } else { - throw new Exception("isValid returned false"); - } - } catch (Exception $e) { - Logging::debug($e->getMessage()); - $this->view->statusMessage = "
"._("Invalid form values.")."
"; - $this->view->streamId = -1; - $this->view->analysis = $analysis; - } - } -} diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 2bbe691e1..8bfaac1ab 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -41,6 +41,7 @@ class PlaylistController extends Zend_Controller_Action $objInfo = Application_Model_Library::getObjInfo($p_type); $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); + if (isset($obj_sess->id)) { $obj = new $objInfo['className']($obj_sess->id); @@ -89,6 +90,7 @@ class PlaylistController extends Zend_Controller_Action $this->view->form = $form; $this->view->obj = $obj; + $this->view->type = "sb"; $this->view->id = $obj->getId(); if ($isJson) { @@ -98,6 +100,7 @@ class PlaylistController extends Zend_Controller_Action } } else { $this->view->obj = $obj; + $this->view->type = "pl"; $this->view->id = $obj->getId(); if ($isJson) { return $this->view->html = $this->view->render($viewPath); @@ -194,9 +197,9 @@ class PlaylistController extends Zend_Controller_Action $objInfo = Application_Model_Library::getObjInfo($type); Logging::info("editing {$type} {$id}"); - if (!is_null($id)) { - Application_Model_Library::changePlaylist($id, $type); - } +// if (!is_null($id)) { + Application_Model_Library::changePlaylist($id, $type); +// } try { $obj = new $objInfo['className']($id); @@ -519,7 +522,7 @@ class PlaylistController extends Zend_Controller_Action $request = $this->getRequest(); $params = $request->getPost(); $result = array(); - + if ($params['type'] == 'block') { try { $bl = new Application_Model_Block($params['obj_id']); @@ -534,20 +537,23 @@ class PlaylistController extends Zend_Controller_Action $result['html'] = $this->createFullResponse($bl, true, true); $result['result'] = 0; } else { - $this->view->obj = $bl; - $this->view->id = $bl->getId(); $this->view->form = $form; $this->view->unsavedName = $params['name']; $this->view->unsavedDesc = $params['description']; $viewPath = 'playlist/smart-block.phtml'; + $this->view->obj = $bl; + $this->view->id = $bl->getId(); $result['html'] = $this->view->render($viewPath); $result['result'] = 1; } + $result['type'] = "sb"; + $result['id'] = $bl->getId(); + $result["modified"] = $bl->getLastModified("U"); } else if ($params['type'] == 'playlist') { $this->setPlaylistNameDescAction(); + $result["modified"] = $this->view->modified; } - $result["modified"] = $this->view->modified; $this->_helper->json->sendJson($result); } diff --git a/airtime_mvc/application/controllers/ShowBuilderController.php b/airtime_mvc/application/controllers/ShowBuilderController.php deleted file mode 100644 index b46172a52..000000000 --- a/airtime_mvc/application/controllers/ShowBuilderController.php +++ /dev/null @@ -1,86 +0,0 @@ -getType(); - - //$this->_helper->layout->setLayout("showbuilder"); - - $this->view->headScript()->appendScript("localStorage.setItem( 'user-type', '$userType' );"); - $this->view->headScript()->appendScript(Application_Common_GoogleAnalytics::generateGoogleTagManagerDataLayerJavaScript()); - - $this->view->headLink()->appendStylesheet($baseUrl . 'css/redmond/jquery-ui-1.8.8.custom.css?' . $CC_CONFIG['airtime_version']); - - $this->view->headScript()->appendFile($baseUrl.'js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.ColVis.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.colReorder.min.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.columnFilter.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); - - $this->view->headScript()->appendFile($baseUrl.'js/blockui/jquery.blockUI.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/utilities/utilities.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - - $this->view->headLink()->appendStylesheet($baseUrl.'css/media_library.css?'.$CC_CONFIG['airtime_version']); - $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.contextMenu.css?'.$CC_CONFIG['airtime_version']); - $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/ColVis.css?'.$CC_CONFIG['airtime_version']); - $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/dataTables.colReorder.min.css?'.$CC_CONFIG['airtime_version']); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/_library.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/events/_library_showbuilder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - - // PLUPLOAD - $this->view->headScript()->appendFile($baseUrl.'js/libs/dropzone.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - - $this->view->headScript()->appendFile($baseUrl.'js/timepicker/jquery.ui.timepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/showbuilder/_builder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/showbuilder/_main_builder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - - // MEDIA BUILDER - $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/_spl.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/playlist/_smart_blockbuilder.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); - $this->view->headLink()->appendStylesheet($baseUrl.'css/playlist_builder.css?'.$CC_CONFIG['airtime_version']); - - $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']); - $this->view->headLink()->appendStylesheet($baseUrl.'css/showbuilder.css?'.$CC_CONFIG['airtime_version']); - $this->view->headLink()->appendStylesheet($baseUrl.'css/_showbuilder.css?'.$CC_CONFIG['airtime_version']); - - $csrf_namespace = new Zend_Session_Namespace('csrf_namespace'); - $csrf_element = new Zend_Form_Element_Hidden('csrf'); - $csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label'); - $this->view->csrf = $csrf_element; - - $request = $this->getRequest(); - //populate date range form for show builder. - $now = time(); - $from = $request->getParam("from", $now); - $to = $request->getParam("to", $now + (3*60*60)); - - $utcTimezone = new DateTimeZone("UTC"); - $displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone()); - - $start = DateTime::createFromFormat("U", $from, $utcTimezone); - $start->setTimezone($displayTimeZone); - $end = DateTime::createFromFormat("U", $to, $utcTimezone); - $end->setTimezone($displayTimeZone); - - $form = new Application_Form_ShowBuilderNew(); - $form->populate(array( - 'sb_date_start' => $start->format("Y-m-d"), - 'sb_time_start' => $start->format("H:i"), - 'sb_date_end' => $end->format("Y-m-d"), - 'sb_time_end' => $end->format("H:i") - )); - - $this->view->sb_form = $form; - } - -} diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index c96ca658e..00f91c5fd 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -20,32 +20,25 @@ class ShowbuilderController extends Zend_Controller_Action public function indexAction() { - $CC_CONFIG = Config::getConfig(); - - $request = $this->getRequest(); - $response = $this->getResponse(); - - //Enable AJAX requests from www.airtime.pro because the autologin during the seamless sign-up follows - //a redirect here. - CORSHelper::enableATProCrossOriginRequests($request, $response); - $baseUrl = Application_Common_OsPath::getBaseDir(); + $userType = Application_Model_User::GetCurrentUser()->getType(); + + //$this->_helper->layout->setLayout("showbuilder"); - $user = Application_Model_User::GetCurrentUser(); - $userType = $user->getType(); $this->view->headScript()->appendScript("localStorage.setItem( 'user-type', '$userType' );"); $this->view->headScript()->appendScript(Application_Common_GoogleAnalytics::generateGoogleTagManagerDataLayerJavaScript()); + $this->view->headLink()->appendStylesheet($baseUrl . 'css/redmond/jquery-ui-1.8.8.custom.css?' . $CC_CONFIG['airtime_version']); + $this->view->headScript()->appendFile($baseUrl.'js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.ColVis.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - //$this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.ColReorder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.colReorder.min.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.columnFilter.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/js-timezone-detect/jstz-1.0.4.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/blockui/jquery.blockUI.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); @@ -54,50 +47,32 @@ class ShowbuilderController extends Zend_Controller_Action $this->view->headLink()->appendStylesheet($baseUrl.'css/media_library.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.contextMenu.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/ColVis.css?'.$CC_CONFIG['airtime_version']); - $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/ColReorder.css?'.$CC_CONFIG['airtime_version']); + $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/dataTables.colReorder.min.css?'.$CC_CONFIG['airtime_version']); + $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/library.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/events/library_showbuilder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - //Show the timezone and language setup popup, if needed. - $this->checkAndShowSetupPopup($request); + // PLUPLOAD + $this->view->headScript()->appendFile($baseUrl.'js/libs/dropzone.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - //determine whether to remove/hide/display the library. - $showLib = false; - if (!$user->isGuest()) { - $disableLib = false; + $this->view->headScript()->appendFile($baseUrl.'js/timepicker/jquery.ui.timepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'js/airtime/showbuilder/builder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'js/airtime/showbuilder/main_builder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $data = Application_Model_Preference::getNowPlayingScreenSettings(); - if (!is_null($data)) { - if ($data["library"] == "true") { - $showLib = true; - } - } - } else { - $disableLib = true; - } - $this->view->disableLib = $disableLib; - $this->view->showLib = $showLib; + // MEDIA BUILDER + $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/spl.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'js/airtime/playlist/smart_blockbuilder.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); + $this->view->headLink()->appendStylesheet($baseUrl.'css/playlist_builder.css?'.$CC_CONFIG['airtime_version']); - //only include library things on the page if the user can see it. - if (!$disableLib) { - $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/library.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/events/library_showbuilder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']); + $this->view->headLink()->appendStylesheet($baseUrl.'css/showbuilder.css?'.$CC_CONFIG['airtime_version']); + $this->view->headLink()->appendStylesheet($baseUrl.'css/_showbuilder.css?'.$CC_CONFIG['airtime_version']); // TODO - $data = Application_Model_Preference::getCurrentLibraryTableSetting(); - if (!is_null($data)) { - $libraryTable = json_encode($data); - $this->view->headScript()->appendScript("localStorage.setItem( 'datatables-library', JSON.stringify($libraryTable) );"); - } else { - $this->view->headScript()->appendScript("localStorage.setItem( 'datatables-library', '' );"); - } - } - - $data = Application_Model_Preference::getTimelineDatatableSetting(); - if (!is_null($data)) { - $timelineTable = json_encode($data); - $this->view->headScript()->appendScript("localStorage.setItem( 'datatables-timeline', JSON.stringify($timelineTable) );"); - } else { - $this->view->headScript()->appendScript("localStorage.setItem( 'datatables-timeline', '' );"); - } + $csrf_namespace = new Zend_Session_Namespace('csrf_namespace'); + $csrf_element = new Zend_Form_Element_Hidden('csrf'); + $csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label'); + $this->view->csrf = $csrf_element; + $request = $this->getRequest(); //populate date range form for show builder. $now = time(); $from = $request->getParam("from", $now); @@ -113,20 +88,13 @@ class ShowbuilderController extends Zend_Controller_Action $form = new Application_Form_ShowBuilder(); $form->populate(array( - 'sb_date_start' => $start->format("Y-m-d"), - 'sb_time_start' => $start->format("H:i"), - 'sb_date_end' => $end->format("Y-m-d"), - 'sb_time_end' => $end->format("H:i") - )); + 'sb_date_start' => $start->format("Y-m-d"), + 'sb_time_start' => $start->format("H:i"), + 'sb_date_end' => $end->format("Y-m-d"), + 'sb_time_end' => $end->format("H:i") + )); $this->view->sb_form = $form; - - $this->view->headScript()->appendFile($baseUrl.'js/timepicker/jquery.ui.timepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/showbuilder/builder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/showbuilder/main_builder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - - $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']); - $this->view->headLink()->appendStylesheet($baseUrl.'css/showbuilder.css?'.$CC_CONFIG['airtime_version']); } /** Check if we need to show the timezone/language setup popup and display it. (eg. on first run) */ @@ -192,7 +160,7 @@ class ShowbuilderController extends Zend_Controller_Action } $displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone()); - + $start = $instance->getDbStarts(null); $start->setTimezone($displayTimeZone); $end = $instance->getDbEnds(null); @@ -208,7 +176,7 @@ class ShowbuilderController extends Zend_Controller_Action $this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml'); } - + public function checkBuilderFeedAction() { $request = $this->getRequest(); @@ -231,7 +199,7 @@ class ShowbuilderController extends Zend_Controller_Action public function builderFeedAction() { $current_time = time(); - + $request = $this->getRequest(); $show_filter = intval($request->getParam("showFilter", 0)); $show_instance_filter = intval($request->getParam("showInstanceFilter", 0)); @@ -253,10 +221,10 @@ class ShowbuilderController extends Zend_Controller_Action public function scheduleAddAction() { $request = $this->getRequest(); - + $mediaItems = $request->getParam("mediaIds", array()); $scheduledItems = $request->getParam("schedIds", array()); - + $log_vars = array(); $log_vars["url"] = $_SERVER['HTTP_HOST']; $log_vars["action"] = "showbuilder/schedule-add"; @@ -264,7 +232,7 @@ class ShowbuilderController extends Zend_Controller_Action $log_vars["params"]["media_items"] = $mediaItems; $log_vars["params"]["scheduled_items"] = $scheduledItems; Logging::info($log_vars); - + try { $scheduler = new Application_Model_Scheduler(); $scheduler->scheduleAfter($scheduledItems, $mediaItems); @@ -281,7 +249,7 @@ class ShowbuilderController extends Zend_Controller_Action { $request = $this->getRequest(); $items = $request->getParam("items", array()); - + $log_vars = array(); $log_vars["url"] = $_SERVER['HTTP_HOST']; $log_vars["action"] = "showbuilder/schedule-remove"; @@ -331,8 +299,7 @@ class ShowbuilderController extends Zend_Controller_Action public function scheduleReorderAction() { - throw new Exception("this controller is/was a no-op please fix your - code"); + throw new Exception("this controller is/was a no-op please fix your code"); } } diff --git a/airtime_mvc/application/controllers/WebstreamController.php b/airtime_mvc/application/controllers/WebstreamController.php index 1d94923c3..d78a9d305 100644 --- a/airtime_mvc/application/controllers/WebstreamController.php +++ b/airtime_mvc/application/controllers/WebstreamController.php @@ -14,7 +14,6 @@ class WebstreamController extends Zend_Controller_Action public function newAction() { - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); if (!$this->isAuthorized(-1)) { // TODO: this header call does not actually print any error message diff --git a/airtime_mvc/application/forms/ShowBuilder.php b/airtime_mvc/application/forms/ShowBuilder.php index 291caccc2..f7d61795f 100644 --- a/airtime_mvc/application/forms/ShowBuilder.php +++ b/airtime_mvc/application/forms/ShowBuilder.php @@ -69,7 +69,7 @@ class Application_Form_ShowBuilder extends Zend_Form_SubForm // add a select to choose a show. $showSelect = new Zend_Form_Element_Select("sb_show_filter"); - $showSelect->setLabel(_("Show:")); + $showSelect->setLabel(_("Filter by Show")); $showSelect->setMultiOptions($this->getShowNames()); $showSelect->setValue(null); $showSelect->setDecorators(array('ViewHelper')); @@ -85,7 +85,7 @@ class Application_Form_ShowBuilder extends Zend_Form_SubForm private function getShowNames() { - $showNames = array("0" => "-------------------------"); + $showNames = array("0" => _("Filter by Show")); $shows = CcShowQuery::create() ->setFormatter(ModelCriteria::FORMAT_ON_DEMAND) diff --git a/airtime_mvc/application/forms/ShowBuilderNew.php b/airtime_mvc/application/forms/ShowBuilderNew.php deleted file mode 100644 index 2d28facb0..000000000 --- a/airtime_mvc/application/forms/ShowBuilderNew.php +++ /dev/null @@ -1,103 +0,0 @@ -setDecorators(array( - array('ViewScript', array('viewScript' => 'form/show-builder.phtml')) - )); - - // Add start date element - $startDate = new Zend_Form_Element_Text('sb_date_start'); - $startDate->class = 'input_text'; - $startDate->setRequired(true) - ->setLabel(_('Date Start:')) - ->setValue(date("Y-m-d")) - ->setFilters(array('StringTrim')) - ->setValidators(array( - 'NotEmpty', - array('date', false, array('YYYY-MM-DD')))) - ->setDecorators(array('ViewHelper')); - $startDate->setAttrib('alt', 'date'); - $this->addElement($startDate); - - // Add start time element - $startTime = new Zend_Form_Element_Text('sb_time_start'); - $startTime->class = 'input_text'; - $startTime->setRequired(true) - ->setValue('00:00') - ->setFilters(array('StringTrim')) - ->setValidators(array( - 'NotEmpty', - array('date', false, array('HH:mm')), - array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered'))))) - ->setDecorators(array('ViewHelper')); - $startTime->setAttrib('alt', 'time'); - $this->addElement($startTime); - - // Add end date element - $endDate = new Zend_Form_Element_Text('sb_date_end'); - $endDate->class = 'input_text'; - $endDate->setRequired(true) - ->setLabel(_('Date End:')) - ->setValue(date("Y-m-d")) - ->setFilters(array('StringTrim')) - ->setValidators(array( - 'NotEmpty', - array('date', false, array('YYYY-MM-DD')))) - ->setDecorators(array('ViewHelper')); - $endDate->setAttrib('alt', 'date'); - $this->addElement($endDate); - - // Add end time element - $endTime = new Zend_Form_Element_Text('sb_time_end'); - $endTime->class = 'input_text'; - $endTime->setRequired(true) - ->setValue('01:00') - ->setFilters(array('StringTrim')) - ->setValidators(array( - 'NotEmpty', - array('date', false, array('HH:mm')), - array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered'))))) - ->setDecorators(array('ViewHelper')); - $endTime->setAttrib('alt', 'time'); - $this->addElement($endTime); - - // add a select to choose a show. - $showSelect = new Zend_Form_Element_Select("sb_show_filter"); - $showSelect->setLabel(_("Filter by Show")); - $showSelect->setMultiOptions($this->getShowNames()); - $showSelect->setValue(null); - $showSelect->setDecorators(array('ViewHelper')); - $this->addElement($showSelect); - - if ($user->getType() === 'H') { - $myShows = new Zend_Form_Element_Checkbox('sb_my_shows'); - $myShows->setLabel(_('All My Shows:')) - ->setDecorators(array('ViewHelper')); - $this->addElement($myShows); - } - } - - private function getShowNames() - { - $showNames = array("0" => _("Filter by Show")); - - $shows = CcShowQuery::create() - ->setFormatter(ModelCriteria::FORMAT_ON_DEMAND) - ->orderByDbName() - ->find(); - - foreach ($shows as $show) { - - $showNames[$show->getDbId()] = $show->getDbName(); - } - - return $showNames; - } - -} diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 5423ab657..a0f6d861c 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -341,7 +341,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } $generate = new Zend_Form_Element_Button('generate_button'); - $generate->setAttrib('class', 'btn btn-small'); + $generate->setAttrib('class', 'sp-button btn'); $generate->setAttrib('title', _('Generate playlist content and save criteria')); $generate->setIgnore(true); $generate->setLabel(_('Generate')); @@ -349,7 +349,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $this->addElement($generate); $shuffle = new Zend_Form_Element_Button('shuffle_button'); - $shuffle->setAttrib('class', 'btn btn-small'); + $shuffle->setAttrib('class', 'sp-button btn'); $shuffle->setAttrib('title', _('Shuffle playlist content')); $shuffle->setIgnore(true); $shuffle->setLabel(_('Shuffle')); diff --git a/airtime_mvc/application/forms/SmartBlockCriteriaNew.php b/airtime_mvc/application/forms/SmartBlockCriteriaNew.php deleted file mode 100644 index ff2d87c38..000000000 --- a/airtime_mvc/application/forms/SmartBlockCriteriaNew.php +++ /dev/null @@ -1,615 +0,0 @@ - "", - "album_title" => "s", - "bit_rate" => "n", - "bpm" => "n", - "composer" => "s", - "conductor" => "s", - "copyright" => "s", - "cuein" => "n", - "cueout" => "n", - "artist_name" => "s", - "encoded_by" => "s", - "utime" => "n", - "mtime" => "n", - "lptime" => "n", - "genre" => "s", - "isrc_number" => "s", - "label" => "s", - "language" => "s", - "length" => "n", - "mime" => "s", - "mood" => "s", - "owner_id" => "s", - "replay_gain" => "n", - "sample_rate" => "n", - "track_title" => "s", - "track_number" => "n", - "info_url" => "s", - "year" => "n" - ); - - private function getCriteriaOptions($option = null) - { - if (!isset($this->criteriaOptions)) { - $this->criteriaOptions = array( - 0 => _("Select criteria"), - "album_title" => _("Album"), - "bit_rate" => _("Bit Rate (Kbps)"), - "bpm" => _("BPM"), - "composer" => _("Composer"), - "conductor" => _("Conductor"), - "copyright" => _("Copyright"), - "cuein" => _("Cue In"), - "cueout" => _("Cue Out"), - "artist_name" => _("Creator"), - "encoded_by" => _("Encoded By"), - "genre" => _("Genre"), - "isrc_number" => _("ISRC"), - "label" => _("Label"), - "language" => _("Language"), - "mtime" => _("Last Modified"), - "lptime" => _("Last Played"), - "length" => _("Length"), - "mime" => _("Mime"), - "mood" => _("Mood"), - "owner_id" => _("Owner"), - "replay_gain" => _("Replay Gain"), - "sample_rate" => _("Sample Rate (kHz)"), - "track_title" => _("Title"), - "track_number" => _("Track Number"), - "utime" => _("Uploaded"), - "info_url" => _("Website"), - "year" => _("Year") - ); - } - - if (is_null($option)) return $this->criteriaOptions; - else return $this->criteriaOptions[$option]; - } - - private function getStringCriteriaOptions() - { - if (!isset($this->stringCriteriaOptions)) { - $this->stringCriteriaOptions = array( - "0" => _("Select modifier"), - "contains" => _("contains"), - "does not contain" => _("does not contain"), - "is" => _("is"), - "is not" => _("is not"), - "starts with" => _("starts with"), - "ends with" => _("ends with") - ); - } - return $this->stringCriteriaOptions; - } - - private function getNumericCriteriaOptions() - { - if (!isset($this->numericCriteriaOptions)) { - $this->numericCriteriaOptions = array( - "0" => _("Select modifier"), - "is" => _("is"), - "is not" => _("is not"), - "is greater than" => _("is greater than"), - "is less than" => _("is less than"), - "is in the range" => _("is in the range") - ); - } - return $this->numericCriteriaOptions; - } - - private function getLimitOptions() - { - if (!isset($this->limitOptions)) { - $this->limitOptions = array( - "hours" => _("hours"), - "minutes" => _("minutes"), - "items" => _("items") - ); - } - return $this->limitOptions; - } - private function getSortOptions() - { - if (!isset($this->sortOptions)) { - $this->sortOptions = array( - "random" => _("random"), - "newest" => _("newest"), - "oldest" => _("oldest") - ); - } - return $this->sortOptions; - } - - - public function init() - { - } - - /* - * converts UTC timestamp citeria into user timezone strings. - */ - private function convertTimestamps(&$criteria) - { - $columns = array("utime", "mtime", "lptime"); - - foreach ($columns as $column) { - - if (isset($criteria[$column])) { - - foreach ($criteria[$column] as &$constraint) { - - $constraint['value'] = - Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['value']); - - if (isset($constraint['extra'])) { - $constraint['extra'] = - Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['extra']); - } - } - } - } - } - - public function startForm($p_blockId, $p_isValid = false) - { - // load type - $out = CcBlockQuery::create()->findPk($p_blockId); - if ($out->getDbType() == "static") { - $blockType = 0; - } else { - $blockType = 1; - } - - $spType = new Zend_Form_Element_Radio('sp_type'); - $spType->setLabel(_('Set smart block type:')) - ->setDecorators(array('viewHelper')) - ->setMultiOptions(array( - 'static' => _('Static'), - 'dynamic' => _('Dynamic') - )) - ->setValue($blockType); - $this->addElement($spType); - - $bl = new Application_Model_Block($p_blockId); - $storedCrit = $bl->getCriteria(); - - //need to convert criteria to be displayed in the user's timezone if there's some timestamp type. - self::convertTimestamps($storedCrit["crit"]); - - /* $modRoadMap stores the number of same criteria - * Ex: 3 Album titles, and 2 Track titles - * We need to know this so we display the form elements properly - */ - $modRowMap = array(); - - $openSmartBlockOption = false; - if (!empty($storedCrit)) { - $openSmartBlockOption = true; - } - - $criteriaKeys = array(); - if (isset($storedCrit["crit"])) { - $criteriaKeys = array_keys($storedCrit["crit"]); - } - $numElements = count($this->getCriteriaOptions()); - for ($i = 0; $i < $numElements; $i++) { - $criteriaType = ""; - - if (isset($criteriaKeys[$i])) { - $critCount = count($storedCrit["crit"][$criteriaKeys[$i]]); - } else { - $critCount = 1; - } - - $modRowMap[$i] = $critCount; - - /* Loop through all criteria with the same field - * Ex: all criteria for 'Album' - */ - for ($j = 0; $j < $critCount; $j++) { - /****************** CRITERIA ***********/ - if ($j > 0) { - $invisible = ' sp-invisible'; - } else { - $invisible = ''; - } - - $criteria = new Zend_Form_Element_Select("sp_criteria_field_".$i."_".$j); - $criteria->setAttrib('class', 'input_select sp_input_select'.$invisible) - ->setValue('Select criteria') - ->setDecorators(array('viewHelper')) - ->setMultiOptions($this->getCriteriaOptions()); - if ($i != 0 && !isset($criteriaKeys[$i])) { - $criteria->setAttrib('disabled', 'disabled'); - } - - if (isset($criteriaKeys[$i])) { - $criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]]; - $criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]); - } - $this->addElement($criteria); - - /****************** MODIFIER ***********/ - $criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$i."_".$j); - $criteriaModifers->setValue('Select modifier') - ->setAttrib('class', 'input_select sp_input_select') - ->setDecorators(array('viewHelper')); - if ($i != 0 && !isset($criteriaKeys[$i])) { - $criteriaModifers->setAttrib('disabled', 'disabled'); - } - if (isset($criteriaKeys[$i])) { - if ($criteriaType == "s") { - $criteriaModifers->setMultiOptions($this->getStringCriteriaOptions()); - } else { - $criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions()); - } - $criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]); - } else { - $criteriaModifers->setMultiOptions(array('0' => _('Select modifier'))); - } - $this->addElement($criteriaModifers); - - /****************** VALUE ***********/ - $criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$i."_".$j); - $criteriaValue->setAttrib('class', 'input_text sp_input_text') - ->setDecorators(array('viewHelper')); - if ($i != 0 && !isset($criteriaKeys[$i])) { - $criteriaValue->setAttrib('disabled', 'disabled'); - } - if (isset($criteriaKeys[$i])) { - $criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]); - } - $this->addElement($criteriaValue); - - /****************** EXTRA ***********/ - $criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$i."_".$j); - $criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text') - ->setDecorators(array('viewHelper')); - if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"])) { - $criteriaExtra->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]); - $criteriaValue->setAttrib('class', 'input_text sp_extra_input_text'); - } else { - $criteriaExtra->setAttrib('disabled', 'disabled'); - } - $this->addElement($criteriaExtra); - - }//for - - }//for - - $repeatTracks = new Zend_Form_Element_Checkbox('sp_repeat_tracks'); - $repeatTracks->setDecorators(array('viewHelper')) - ->setLabel(_('Allow Repeat Tracks:')); - if (isset($storedCrit["repeat_tracks"])) { - $repeatTracks->setChecked($storedCrit["repeat_tracks"]["value"] == 1?true:false); - } - $this->addElement($repeatTracks); - - $sort = new Zend_Form_Element_Select('sp_sort_options'); - $sort->setAttrib('class', 'sp_input_select') - ->setDecorators(array('viewHelper')) - ->setMultiOptions($this->getSortOptions()); - if (isset($storedCrit["sort"])) { - $sort->setValue($storedCrit["sort"]["value"]); - } - $this->addElement($sort); - - $limit = new Zend_Form_Element_Select('sp_limit_options'); - $limit->setAttrib('class', 'sp_input_select') - ->setDecorators(array('viewHelper')) - ->setMultiOptions($this->getLimitOptions()); - if (isset($storedCrit["limit"])) { - $limit->setValue($storedCrit["limit"]["modifier"]); - } - $this->addElement($limit); - - $limitValue = new Zend_Form_Element_Text('sp_limit_value'); - $limitValue->setAttrib('class', 'sp_input_text_limit') - ->setLabel(_('Limit to')) - ->setDecorators(array('viewHelper')); - $this->addElement($limitValue); - if (isset($storedCrit["limit"])) { - $limitValue->setValue($storedCrit["limit"]["value"]); - } else { - // setting default to 1 hour - $limitValue->setValue(1); - } - - //getting block content candidate count that meets criteria - $bl = new Application_Model_Block($p_blockId); - if ($p_isValid) { - $files = $bl->getListofFilesMeetCriteria(); - $showPoolCount = true; - } else { - $files = null; - $showPoolCount = false; - } - - $generate = new Zend_Form_Element_Button('generate_button'); - $generate->setAttrib('class', 'sp-button btn'); - $generate->setAttrib('title', _('Generate playlist content and save criteria')); - $generate->setIgnore(true); - $generate->setLabel(_('Generate')); - $generate->setDecorators(array('viewHelper')); - $this->addElement($generate); - - $shuffle = new Zend_Form_Element_Button('shuffle_button'); - $shuffle->setAttrib('class', 'sp-button btn'); - $shuffle->setAttrib('title', _('Shuffle playlist content')); - $shuffle->setIgnore(true); - $shuffle->setLabel(_('Shuffle')); - $shuffle->setDecorators(array('viewHelper')); - $this->addElement($shuffle); - - $this->setDecorators(array( - array('ViewScript', array('viewScript' => 'form/_smart-block-criteria.phtml', "openOption"=> $openSmartBlockOption, - 'criteriasLength' => count($this->getCriteriaOptions()), 'poolCount' => $files['count'], 'modRowMap' => $modRowMap, - 'showPoolCount' => $showPoolCount)) - )); - } - - public function preValidation($params) - { - $data = Application_Model_Block::organizeSmartPlaylistCriteria($params['data']); - // add elelments that needs to be added - // set multioption for modifier according to criteria_field - $modRowMap = array(); - foreach ($data['criteria'] as $critKey=>$d) { - $count = 1; - foreach ($d as $modKey=>$modInfo) { - if ($modKey == 0) { - $eleCrit = $this->getElement("sp_criteria_field_".$critKey."_".$modKey); - $eleCrit->setValue($this->getCriteriaOptions($modInfo['sp_criteria_field'])); - $eleCrit->setAttrib("disabled", null); - - $eleMod = $this->getElement("sp_criteria_modifier_".$critKey."_".$modKey); - $criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']]; - if ($criteriaType == "s") { - $eleMod->setMultiOptions($this->getStringCriteriaOptions()); - } elseif ($criteriaType == "n") { - $eleMod->setMultiOptions($this->getNumericCriteriaOptions()); - } else { - $eleMod->setMultiOptions(array('0' => _('Select modifier'))); - } - $eleMod->setValue($modInfo['sp_criteria_modifier']); - $eleMod->setAttrib("disabled", null); - - $eleValue = $this->getElement("sp_criteria_value_".$critKey."_".$modKey); - $eleValue->setValue($modInfo['sp_criteria_value']); - $eleValue->setAttrib("disabled", null); - - if (isset($modInfo['sp_criteria_extra'])) { - $eleExtra = $this->getElement("sp_criteria_extra_".$critKey."_".$modKey); - $eleExtra->setValue($modInfo['sp_criteria_extra']); - $eleValue->setAttrib('class', 'input_text sp_extra_input_text'); - $eleExtra->setAttrib("disabled", null); - } - - } else { - $criteria = new Zend_Form_Element_Select("sp_criteria_field_".$critKey."_".$modKey); - $criteria->setAttrib('class', 'input_select sp_input_select sp-invisible') - ->setValue('Select criteria') - ->setDecorators(array('viewHelper')) - ->setMultiOptions($this->getCriteriaOptions()); - - $criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']]; - $criteria->setValue($this->getCriteriaOptions($modInfo['sp_criteria_field'])); - $this->addElement($criteria); - - /****************** MODIFIER ***********/ - $criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$critKey."_".$modKey); - $criteriaModifers->setValue('Select modifier') - ->setAttrib('class', 'input_select sp_input_select') - ->setDecorators(array('viewHelper')); - - if ($criteriaType == "s") { - $criteriaModifers->setMultiOptions($this->getStringCriteriaOptions()); - } elseif ($criteriaType == "n") { - $criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions()); - } else { - $criteriaModifers->setMultiOptions(array('0' => _('Select modifier'))); - } - $criteriaModifers->setValue($modInfo['sp_criteria_modifier']); - $this->addElement($criteriaModifers); - - /****************** VALUE ***********/ - $criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$critKey."_".$modKey); - $criteriaValue->setAttrib('class', 'input_text sp_input_text') - ->setDecorators(array('viewHelper')); - $criteriaValue->setValue($modInfo['sp_criteria_value']); - $this->addElement($criteriaValue); - - /****************** EXTRA ***********/ - $criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$critKey."_".$modKey); - $criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text') - ->setDecorators(array('viewHelper')); - if (isset($modInfo['sp_criteria_extra'])) { - $criteriaExtra->setValue($modInfo['sp_criteria_extra']); - $criteriaValue->setAttrib('class', 'input_text sp_extra_input_text'); - } else { - $criteriaExtra->setAttrib('disabled', 'disabled'); - } - $this->addElement($criteriaExtra); - $count++; - } - } - $modRowMap[$critKey] = $count; - } - - $decorator = $this->getDecorator("ViewScript"); - $existingModRow = $decorator->getOption("modRowMap"); - foreach ($modRowMap as $key=>$v) { - $existingModRow[$key] = $v; - } - $decorator->setOption("modRowMap", $existingModRow); - - // reconstruct the params['criteria'] so we can populate the form - $formData = array(); - foreach ($params['data'] as $ele) { - $formData[$ele['name']] = $ele['value']; - } - - $this->populate($formData); - - return $data; - } - - public function isValid($params) - { - $isValid = true; - $data = $this->preValidation($params); - $criteria2PeerMap = array( - 0 => "Select criteria", - "album_title" => "DbAlbumTitle", - "artist_name" => "DbArtistName", - "bit_rate" => "DbBitRate", - "bpm" => "DbBpm", - "composer" => "DbComposer", - "conductor" => "DbConductor", - "copyright" => "DbCopyright", - "cuein" => "DbCuein", - "cueout" => "DbCueout", - "encoded_by" => "DbEncodedBy", - "utime" => "DbUtime", - "mtime" => "DbMtime", - "lptime" => "DbLPtime", - "genre" => "DbGenre", - "info_url" => "DbInfoUrl", - "isrc_number" => "DbIsrcNumber", - "label" => "DbLabel", - "language" => "DbLanguage", - "length" => "DbLength", - "mime" => "DbMime", - "mood" => "DbMood", - "owner_id" => "DbOwnerId", - "replay_gain" => "DbReplayGain", - "sample_rate" => "DbSampleRate", - "track_title" => "DbTrackTitle", - "track_number" => "DbTrackNumber", - "year" => "DbYear" - ); - - // things we need to check - // 1. limit value shouldn't be empty and has upperbound of 24 hrs - // 2. sp_criteria or sp_criteria_modifier shouldn't be 0 - // 3. validate formate according to DB column type - $multiplier = 1; - $result = 0; - - // validation start - if ($data['etc']['sp_limit_options'] == 'hours') { - $multiplier = 60; - } - if ($data['etc']['sp_limit_options'] == 'hours' || $data['etc']['sp_limit_options'] == 'mins') { - $element = $this->getElement("sp_limit_value"); - if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) { - $element->addError(_("Limit cannot be empty or smaller than 0")); - $isValid = false; - } else { - $mins = floatval($data['etc']['sp_limit_value']) * $multiplier; - if ($mins > 1440) { - $element->addError(_("Limit cannot be more than 24 hrs")); - $isValid = false; - } - } - } else { - $element = $this->getElement("sp_limit_value"); - if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) { - $element->addError(_("Limit cannot be empty or smaller than 0")); - $isValid = false; - } elseif (!ctype_digit($data['etc']['sp_limit_value'])) { - $element->addError(_("The value should be an integer")); - $isValid = false; - } elseif (intval($data['etc']['sp_limit_value']) > 500) { - $element->addError(_("500 is the max item limit value you can set")); - $isValid = false; - } - } - - if (isset($data['criteria'])) { - foreach ($data['criteria'] as $rowKey=>$row) { - foreach ($row as $key=>$d) { - $element = $this->getElement("sp_criteria_field_".$rowKey."_".$key); - // check for not selected select box - if ($d['sp_criteria_field'] == "0" || $d['sp_criteria_modifier'] == "0") { - $element->addError(_("You must select Criteria and Modifier")); - $isValid = false; - } else { - $column = CcFilesPeer::getTableMap()->getColumnByPhpName($criteria2PeerMap[$d['sp_criteria_field']]); - // validation on type of column - if (in_array($d['sp_criteria_field'], array('length', 'cuein', 'cueout'))) { - if (!preg_match("/^(\d{2}):(\d{2}):(\d{2})/", $d['sp_criteria_value'])) { - $element->addError(_("'Length' should be in '00:00:00' format")); - $isValid = false; - } - } elseif ($column->getType() == PropelColumnTypes::TIMESTAMP) { - if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) { - $element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)")); - $isValid = false; - } else { - $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']); - if (!$result["success"]) { - // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 ) - $element->addError($result["errMsg"]); - $isValid = false; - } - } - - if (isset($d['sp_criteria_extra'])) { - if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) { - $element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)")); - $isValid = false; - } else { - $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_extra']); - if (!$result["success"]) { - // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 ) - $element->addError($result["errMsg"]); - $isValid = false; - } - } - } - } elseif ($column->getType() == PropelColumnTypes::INTEGER && - $d['sp_criteria_field'] != 'owner_id') { - if (!is_numeric($d['sp_criteria_value'])) { - $element->addError(_("The value has to be numeric")); - $isValid = false; - } - // length check - if ($d['sp_criteria_value'] >= pow(2,31)) { - $element->addError(_("The value should be less then 2147483648")); - $isValid = false; - } - } elseif ($column->getType() == PropelColumnTypes::VARCHAR) { - if (strlen($d['sp_criteria_value']) > $column->getSize()) { - $element->addError(sprintf(_("The value should be less than %s characters"), $column->getSize())); - $isValid = false; - } - } - } - - if ($d['sp_criteria_value'] == "") { - $element->addError(_("Value cannot be empty")); - $isValid = false; - } - }//end foreach - }//for loop - }//if - - return $isValid; - } -} diff --git a/airtime_mvc/application/layouts/scripts/layout.phtml b/airtime_mvc/application/layouts/scripts/layout.phtml index 5552d386a..b7b14696c 100644 --- a/airtime_mvc/application/layouts/scripts/layout.phtml +++ b/airtime_mvc/application/layouts/scripts/layout.phtml @@ -98,15 +98,15 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+ diff --git a/airtime_mvc/application/views/scripts/form/_smart-block-criteria.phtml b/airtime_mvc/application/views/scripts/form/_smart-block-criteria.phtml deleted file mode 100644 index ca85d3e2e..000000000 --- a/airtime_mvc/application/views/scripts/form/_smart-block-criteria.phtml +++ /dev/null @@ -1,148 +0,0 @@ -
-
- -
- - element->getElement('sp_type')->getValue(); - foreach ($this->element->getElement('sp_type')->getMultiOptions() as $radio) : ?> - - - - - -
- -
- criteriasLength; $i++) { - // modRowMap holds the number of modifier rows for each criteria element - // i.e. if we have 'Album contains 1' and 'Album contains 2' the modRowMap - // for Album is 2 - ?> - modRowMap[$i]; $j++) { - // determine if logic label should be 'and' or 'or' - if ($this->modRowMap[$i] > 1 && $j != $this->modRowMap[$i]-1) $logicLabel = _('or'); - else $logicLabel = _('and'); - - $disabled = $this->element->getElement("sp_criteria_field_".$i."_".$j)->getAttrib('disabled') == 'disabled'?true:false; - // determine if the next row is disabled and only display the logic label if it isn't - if ($j == $this->modRowMap[$i]-1 && $i < 25) { - $n = $i+1; - $nextIndex = $n."_0"; - } elseif ($j+1 <= $this->modRowMap[$i]-1) { - $n = $j+1; - $nextIndex = $i."_".$n; - - } - $nextDisabled = $this->element->getElement("sp_criteria_field_".$nextIndex)->getAttrib('disabled') == 'disabled'?true:false; - ?> -
0) && $disabled) { - echo 'style=display:none'; - } ?>> - element->getElement("sp_criteria_field_".$i."_".$j) ?> - - - - element->getElement("sp_criteria_modifier_".$i."_".$j) ?> - element->getElement("sp_criteria_value_".$i."_".$j) ?> - element->getElement("sp_criteria_extra_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>>element->getElement('sp_criteria_extra_'.$i."_".$j) ?> - - - - - > - - - element->getElement("sp_criteria_field_".$i."_".$j)->hasErrors()) : ?> - element->getElement("sp_criteria_field_".$i."_".$j)->getMessages() as $error): ?> - - - - - -
- - - -
- -
- element->getElement('sp_repeat_tracks')->getLabel() ?> - element->getElement('sp_repeat_tracks')?> - element->getElement("sp_repeat_tracks")->hasErrors()) : ?> - element->getElement("sp_repeat_tracks")->getMessages() as $error): ?> - - - - - - -
-
- Sort tracks by - element->getElement('sp_sort_options') ?> - element->getElement("sp_sort_options")->hasErrors()) : ?> - element->getElement("sp_sort_options")->getMessages() as $error): ?> - - - - - -
-
- element->getElement('sp_limit_value')->getLabel() ?> - element->getElement('sp_limit_value')?> - element->getElement('sp_limit_options') ?> - element->getElement("sp_limit_value")->hasErrors()) : ?> - element->getElement("sp_limit_value")->getMessages() as $error): ?> - - - - - -
- - showPoolCount) { ?> -
- - poolCount > 1) { - echo $this->poolCount; - ?> - - - - poolCount == 1) { - echo $this->poolCount; - ?> - - - - - 0 - - - -
- -
- -
- -
-
- element->getElement('generate_button');?> -
-
- element->getElement('shuffle_button');?> -
-
diff --git a/airtime_mvc/application/views/scripts/form/show-builder.phtml b/airtime_mvc/application/views/scripts/form/show-builder.phtml deleted file mode 100644 index bba94655c..000000000 --- a/airtime_mvc/application/views/scripts/form/show-builder.phtml +++ /dev/null @@ -1,16 +0,0 @@ -
- element->getElement('sb_date_start'); ?> - element->getElement('sb_time_start'); ?> - element->getElement('sb_date_end'); ?> - element->getElement('sb_time_end'); ?> - - - - - element->getElement('sb_show_filter') ?> - - element->getElement('sb_my_shows')):?> - - element->getElement('sb_my_shows'); ?> - -
diff --git a/airtime_mvc/application/views/scripts/form/showbuilder.phtml b/airtime_mvc/application/views/scripts/form/showbuilder.phtml index 5dbf4734d..bba94655c 100644 --- a/airtime_mvc/application/views/scripts/form/showbuilder.phtml +++ b/airtime_mvc/application/views/scripts/form/showbuilder.phtml @@ -1,25 +1,16 @@ -element->getElement('sb_date_start'); ?> -element->getElement('sb_time_start'); ?> -element->getElement('sb_date_end'); ?> -element->getElement('sb_time_end'); ?> +
+ element->getElement('sb_date_start'); ?> + element->getElement('sb_time_start'); ?> + element->getElement('sb_date_end'); ?> + element->getElement('sb_time_end'); ?> + + + - - -
-
- - - - + element->getElement('sb_show_filter') ?> -
- - element->getElement('sb_show_filter') ?> - - element->getElement('sb_my_shows')):?> - - element->getElement('sb_my_shows'); ?> - -
-
+ element->getElement('sb_my_shows')):?> + + element->getElement('sb_my_shows'); ?> +
diff --git a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml index 9da7ca765..ca85d3e2e 100644 --- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml @@ -1,21 +1,9 @@ -
-
- - +
-
-
- element->getElement('generate_button') ?> -
-
- element->getElement('shuffle_button') ?> -
-
element->getElement('sp_type')->getValue(); @@ -26,6 +14,7 @@ +
@@ -79,12 +68,10 @@ -
-
+
element->getElement('sp_repeat_tracks')->getLabel() ?> - element->getElement('sp_repeat_tracks')?> element->getElement("sp_repeat_tracks")->hasErrors()) : ?> element->getElement("sp_repeat_tracks")->getMessages() as $error): ?> @@ -93,7 +80,7 @@ -
+
Sort tracks by @@ -105,8 +92,7 @@ -
-
+
element->getElement('sp_limit_value')->getLabel() ?> element->getElement('sp_limit_value')?> @@ -118,7 +104,6 @@ -
showPoolCount) { ?> @@ -135,7 +120,7 @@ } else if ($this->poolCount == 1) { echo $this->poolCount; ?> - +
- - + +
+
+ element->getElement('generate_button');?> +
+
+ element->getElement('shuffle_button');?> +
+
diff --git a/airtime_mvc/application/views/scripts/playlist/_playlist.phtml b/airtime_mvc/application/views/scripts/playlist/_playlist.phtml deleted file mode 100644 index 9eab3d802..000000000 --- a/airtime_mvc/application/views/scripts/playlist/_playlist.phtml +++ /dev/null @@ -1,71 +0,0 @@ -obj)) { - $contents = $this->obj->getContents(); - $count = count($contents); -} -?> - -obj)) : ?> -
- - - -
-

- escape($this->obj->getName()); ?> -

-

length; ?>

-
- - -
-
-
- -
-
- -
-
- -
-
- -
-
- "> - - -
-
- - form; ?> - - -
- -
-
- -
-
- -
-
- - -
- \ No newline at end of file diff --git a/airtime_mvc/application/views/scripts/playlist/_smart-block.phtml b/airtime_mvc/application/views/scripts/playlist/_smart-block.phtml deleted file mode 100644 index 017c2e656..000000000 --- a/airtime_mvc/application/views/scripts/playlist/_smart-block.phtml +++ /dev/null @@ -1,72 +0,0 @@ -obj)) { - $contents = $this->obj->getContents(); - $count = count($contents); -} -?> - -obj)) : ?> -
- - - -
-

- - unsavedName)) echo $this->unsavedName; - else echo $this->escape($this->obj->getName()); - ?> - -

-

length; ?>

-
- - -
-
-
- -
-
- - form; ?> -
-
- -
-
- "> - - -
-
- - -
- -
-
- -
-
- -
-
- - -
- diff --git a/airtime_mvc/application/views/scripts/playlist/playlist.phtml b/airtime_mvc/application/views/scripts/playlist/playlist.phtml index 8d8d0be4f..9eab3d802 100644 --- a/airtime_mvc/application/views/scripts/playlist/playlist.phtml +++ b/airtime_mvc/application/views/scripts/playlist/playlist.phtml @@ -4,83 +4,68 @@ if (isset($this->obj)) { $count = count($contents); } ?> - -
-
- - -
-obj)) : ?> -
- -
-
- -
-
- -
-
- -
-
- "> - - -
- -
obj)) : ?> - - - -
-

- escape($this->obj->getName()); ?> -

-

length; ?>

-
- +
+ + + +
+

+ escape($this->obj->getName()); ?> +

+

length; ?>

+
+ -
-
-
- - form; ?> - - -
-
- + +
+
+ +
+
+ +
- + \ No newline at end of file diff --git a/airtime_mvc/application/views/scripts/playlist/smart-block.phtml b/airtime_mvc/application/views/scripts/playlist/smart-block.phtml index 9ad40d990..017c2e656 100644 --- a/airtime_mvc/application/views/scripts/playlist/smart-block.phtml +++ b/airtime_mvc/application/views/scripts/playlist/smart-block.phtml @@ -4,86 +4,67 @@ if (isset($this->obj)) { $count = count($contents); } ?> - -
-
- - -
-obj)) : ?> -
- -
-
- -
-
- -
-
- "> - - -
- -
obj)) : ?> - - - - - +
+ + + + + -
-
- +
-
- - form; ?> - - -
-
-
    - contents = $contents; - echo $this->render('playlist/update.phtml') ?> -
+
    + contents = $contents; + echo $this->render('playlist/update.phtml') ?> +
+
+
+ +
+
+ +
diff --git a/airtime_mvc/application/views/scripts/show-builder/index.phtml b/airtime_mvc/application/views/scripts/show-builder/index.phtml deleted file mode 100644 index 4ad028ef2..000000000 --- a/airtime_mvc/application/views/scripts/show-builder/index.phtml +++ /dev/null @@ -1,41 +0,0 @@ -quotaLimitReached) { ?> -csrf ?> - - - - - -csrf ?> - -
-
-

Library

-
-
-
- - -
-
-
-
-
-
- -
-
- -
-
-
-
- sb_form; ?> -
-
-
- -dialog ?> diff --git a/airtime_mvc/application/views/scripts/showbuilder/index.phtml b/airtime_mvc/application/views/scripts/showbuilder/index.phtml index 0473ec1bf..4ad028ef2 100644 --- a/airtime_mvc/application/views/scripts/showbuilder/index.phtml +++ b/airtime_mvc/application/views/scripts/showbuilder/index.phtml @@ -1,23 +1,41 @@ -disableLib): ?> -
showLib): ?> - style="display:none" - -> - render('library/library.phtml') ?> -
- +quotaLimitReached) { ?> +csrf ?> + + + + -
-
- disableLib && !$this->showLib):?> - - - - - sb_form; ?> +csrf ?> + +
+
+

Library

+
+
+
+ + +
+
+
+
-
-lang_tz_popup_form; ?> +
+
+ +
+
+
+
+ sb_form; ?> +
+
+
+ +dialog ?> diff --git a/airtime_mvc/application/views/scripts/webstream/_webstream.phtml b/airtime_mvc/application/views/scripts/webstream/_webstream.phtml deleted file mode 100644 index 0d4288668..000000000 --- a/airtime_mvc/application/views/scripts/webstream/_webstream.phtml +++ /dev/null @@ -1,47 +0,0 @@ -obj)) : ?> - - obj->getLastModified('U'); ?>"/> - - - -
- -

- escape($this->obj->getName()); ?> -

-

obj->getDefaultLength(); ?>

-
- -
-
-
- -
-
- -
- - -
-
- -
- -
-
- -
-
- -
-
- -
-
- -
-
- - -
- diff --git a/airtime_mvc/application/views/scripts/webstream/webstream.phtml b/airtime_mvc/application/views/scripts/webstream/webstream.phtml index 484a8a638..0d4288668 100644 --- a/airtime_mvc/application/views/scripts/webstream/webstream.phtml +++ b/airtime_mvc/application/views/scripts/webstream/webstream.phtml @@ -1,26 +1,3 @@ - -
-
- - -
- -obj)) : ?> -
- -
-
- -
- -
- obj)) : ?> obj->getLastModified('U'); ?>"/> @@ -35,17 +12,13 @@

obj->getDefaultLength(); ?>

-
- -
-
-
- -
- -
-
- +
+
+
+ +
+
+
@@ -60,6 +33,15 @@
+
+
+ +
+
+ +
+
+
diff --git a/airtime_mvc/public/js/airtime/library/_library.js b/airtime_mvc/public/js/airtime/library/_library.js deleted file mode 100644 index a4f8d6b63..000000000 --- a/airtime_mvc/public/js/airtime/library/_library.js +++ /dev/null @@ -1,1392 +0,0 @@ -var AIRTIME = (function(AIRTIME) { - var mod, - libraryInit, - oTable, - $libContent, - $libTable, - LIB_SELECTED_CLASS = "lib-selected", - chosenItems = {}, - visibleChosenItems = {}, - $previouslySelected, - flagForDeselection = false; - - - // we need to know whether the criteria value is string or - // numeric in order to provide a single textbox or range textboxes - // in the advanced search - // s => string - // n => numberic - var libraryColumnTypes = { - 0 : "", - "album_title" : "s", - "artist_name" : "s", - "bit_rate" : "n", - "bpm" : "n", - "comments" : "s", - "composer" : "s", - "conductor" : "s", - "copyright" : "s", - "cuein" : "n", - "cueout" : "n", - "utime" : "n", - "mtime" : "n", - "lptime" : "n", - "disc_number" : "n", - "encoded_by" : "s", - "genre" : "s", - "isrc_number" : "s", - "label" : "s", - "language" : "s", - "length" : "n", - "lyricist" : "s", - "mime" : "s", - "mood" : "s", - "name" : "s", - "orchestra" : "s", - "rating" : "n", - "sample_rate" : "n", - "track_title" : "s", - "track_num" : "n", - "year" : "n", - "owner_id" : "s", - "info_url" : "s", - "replay_gain" : "n" - }; - - if (AIRTIME.library === undefined) { - AIRTIME.library = {}; - } - mod = AIRTIME.library; - - mod.getChosenItemsLength = function(){ - var cItem, - selected, - $trs; - - // Get visible items and check if any chosenItems are visible - $trs = $libTable.find("tr"); - $trs.each(function(i){ - for (cItem in chosenItems) { - if (cItem === $(this).attr("id")) { - visibleChosenItems[cItem] = $(this).data('aData'); - } - } - }); - - selected = Object.keys(visibleChosenItems).length; - visibleChosenItems = {}; - return selected; - }; - - mod.getChosenAudioFilesLength = function(){ - // var files = Object.keys(chosenItems), - var files, - $trs, - cItem, - i, length, - count = 0, - reAudio=/^(au|st|pl|bl)/ ; - - // Get visible items and check if any chosenItems are visible - $trs = $libTable.find("tr"); - $trs.each(function(i){ - for (cItem in chosenItems) { - if (cItem === $(this).attr("id")) { - visibleChosenItems[cItem] = $(this).data('aData'); - } - } - }); - - files = Object.keys(visibleChosenItems); - - for (i = 0, length = files.length; i < length; i++) { - - if (files[i].search(reAudio) !== -1) { - count++; - } - } - visibleChosenItems = {}; - return count; - }; - - mod.changeAddButtonText = function($button, btnText) { - $button.text(btnText); - }; - - mod.createToolbarButtons = function () { - $menu = $("
"); - $menu - .append("
" + - "" + - "
") - .append("
" + - "" + - "
") - - .append("
" + - "" + - "
") - .append("
" + - "" + - "
") - .append("
" + - "" + - "" + - "
" - ); - }; - - mod.moveSearchBarToHeader = function() { - $("#library_display_filter").appendTo("#library_content > .panel-header"); - $("#advanced_search").click(function(e) { - e.stopPropagation(); - }); - }; - - mod.createToolbarDropDown = function() { - $('#sb-select-page').click(function(){mod.selectCurrentPage();}); - $('#sb-dselect-page').click(function(){mod.deselectCurrentPage();}); - $('#sb-dselect-all').click(function(){mod.selectNone();}); - }; - - mod.checkDeleteButton = function() { - var selected = mod.getChosenItemsLength(), - check = false; - - if (selected !== 0) { - check = true; - } - - if (check === true) { - AIRTIME.button.enableButton("btn-group #sb-trash", false); - } - else { - AIRTIME.button.disableButton("btn-group #sb-trash", false); - } - }; - - mod.checkEditButton = function() { - var selected = mod.getChosenItemsLength(), - check = false; - - if (selected >= 1) { - check = true; - } - - if (check === true) { - AIRTIME.button.enableButton("btn-group #sb-edit", false); - } - else { - AIRTIME.button.disableButton("btn-group #sb-edit", false); - } - }; - - mod.checkNewButton = function() { - var selected = $(".media_type_selector.selected").attr("selection_id"), - check = false; - - if (selected != 1) { - check = true; - } - - if (check === true) { - AIRTIME.button.enableButton("btn-group #sb-new", false); - } - else { - AIRTIME.button.disableButton("btn-group #sb-new", false); - } - }; - - mod.checkToolBarIcons = function() { - AIRTIME.library.checkAddButton(); - AIRTIME.library.checkDeleteButton(); - AIRTIME.library.checkEditButton(); - AIRTIME.library.checkNewButton(); - }; - - mod.getSelectedData = function() { - var id, - data = [], - cItem, - $trs; - - $.fn.reverse = [].reverse; - - // Get visible items and check if any chosenItems are visible - $trs = $libTable.find("tr").reverse(); - $trs.each(function(i){ - for (cItem in chosenItems) { - if (cItem === $(this).attr("id")) { - visibleChosenItems[cItem] = $(this).data('aData'); - } - } - }); - - for (id in visibleChosenItems) { - if (visibleChosenItems.hasOwnProperty(id)) { - data.push(visibleChosenItems[id]); - } - } - visibleChosenItems = {}; - return data; - }; - - mod.redrawChosen = function() { - var ids = Object.keys(chosenItems), - i, length, - $el; - - for (i = 0, length = ids.length; i < length; i++) { - $el = $libTable.find("#"+ids[i]); - - if ($el.length !== 0) { - mod.highlightItem($el); - mod.checkItem($el); - } - } - }; - - mod.isChosenItem = function($el) { - var id = $el.attr("id"), - item = chosenItems[id]; - - return item !== undefined; - }; - - mod.addToChosen = function($el) { - var id = $el.attr("id"); - - chosenItems[id] = $el.data('aData'); - }; - - mod.removeFromChosen = function($el) { - var id = $el.attr("id"); - - // used to not keep dragged items selected. - if (!$el.hasClass(LIB_SELECTED_CLASS)) { - delete chosenItems[id]; - } - }; - - mod.checkItem = function($el) { - $el.find(".library_checkbox > input").prop('checked', true); - $("#super-checkbox").prop("checked", true); - }; - - mod.uncheckItem = function($el) { - $el.find(".library_checkbox > input").prop('checked', false); - if ($("." + LIB_SELECTED_CLASS.length == 0)) { - $("#super-checkbox").prop("checked", false); - } - }; - - mod.highlightItem = function($el) { - $el.addClass(LIB_SELECTED_CLASS); - }; - - mod.unHighlightItem = function($el) { - $el.removeClass(LIB_SELECTED_CLASS); - }; - - mod.selectItem = function($el) { - mod.highlightItem($el); - mod.addToChosen($el); - - mod.checkToolBarIcons(); - }; - - mod.deselectItem = function($el) { - mod.unHighlightItem($el); - mod.removeFromChosen($el); - mod.checkToolBarIcons(); - }; - - /* - * selects all items which the user can currently see. (behaviour taken from - * gmail) - * - * by default the items are selected in reverse order so we need to reverse - * it back - */ - mod.selectCurrentPage = function() { - $.fn.reverse = [].reverse; - var $trs = $libTable.find("tbody").find("tr").reverse(); - - $trs.each(function(i, el){ - mod.selectItem($(el)); - mod.checkItem($(el)); - }); - - mod.checkToolBarIcons(); - - }; - - /* - * deselects all items that the user can currently see. (behaviour taken - * from gmail) - */ - mod.deselectCurrentPage = function() { - var $trs = $libTable.find("tr"); - - $trs.each(function(i, el){ - mod.deselectItem($(el)); - mod.uncheckItem($(el)); - }); - - mod.checkToolBarIcons(); - }; - - mod.selectNone = function() { - var $trs = $libTable.find("tr"); - $trs.each(function(i, el){ - mod.deselectItem($(el)); - mod.uncheckItem($(el)); - }); - $previouslySelected = undefined; - - chosenItems = {}; - - mod.checkToolBarIcons(); - }; - - mod.fnRedraw = function() { - oTable.fnStandingRedraw(); - }; - - mod.fnDeleteItems = function(aMedia) { - //Prevent the user from spamming the delete button while the AJAX request is in progress - AIRTIME.button.disableButton("btn-group #sb-trash", false); - var openTabObjectIds = $(".obj_id"), - mediaIds = []; - for (var i in aMedia) { - mediaIds.push(parseInt(aMedia[i].id)); - } - - openTabObjectIds.each(function(i, el) { - var v = parseInt($(el).val()); - if ($.inArray(v, mediaIds) > -1) { - AIRTIME.playlist.closeTab($(el).closest(".pl-content").attr("tab-id")); - } - }); - - $.post(baseUrl+"library/delete", - {"format": "json", "media": aMedia}, - function(json){ - if (json.message !== undefined) { - alert(json.message); - } - - chosenItems = {}; - oTable.fnStandingRedraw(); - - //Re-enable the delete button - AIRTIME.button.enableButton("btn-group #sb-trash", false); - }); - }; - - mod.fnDeleteSelectedItems = function() { - if (confirm($.i18n._('Are you sure you want to delete the selected item(s)?'))) { - var aData = AIRTIME.library.getSelectedData(), - item, - temp, - aMedia = [], - currentObjId = $(".side_playlist.active-tab").find(".obj_id").val(), - currentObjType = $(".side_playlist.active-tab").find(".obj_type").val(), - closeObj = false; - - // process selected files/playlists. - for (item in aData) { - temp = aData[item]; - if (temp !== null && temp.hasOwnProperty('id') ) { - aMedia.push({"id": temp.id, "type": temp.ftype}); - if ( (temp.id == currentObjId && temp.ftype === currentObjType) || - temp.id == currentObjId && temp.ftype === "stream" && currentObjType === "webstream") { - closeObj = true; - } - } - } - - AIRTIME.library.fnDeleteItems(aMedia); - - // close the object (playlist/block/webstream) - // on the right side if it was just deleted - // from the library - if (closeObj) { - $.post(baseUrl+"playlist/close-playlist", - {"format": "json", "type": currentObjType}, - function(json) { - $("#editor_pane_wrapper").empty().append(json.html); - }); - } - } - }; - - - libraryInit = function() { - - $libContent = $("#library_content"); - - /* - * Icon hover states in the toolbar. - */ - $libContent.on("mouseenter", ".fg-toolbar ul li", function(ev) { - $el = $(this); - - if (!$el.hasClass("ui-state-disabled")) { - $el.addClass("ui-state-hover"); - } - }); - $libContent.on("mouseleave", ".fg-toolbar ul li", function(ev) { - $el = $(this); - - if (!$el.hasClass("ui-state-disabled")) { - $el.removeClass("ui-state-hover"); - } - }); - - var colReorderMap = new Array(); - - $libTable = $libContent.find("table"); - - function getTableHeight() { - return $libContent.height() - 175; - } - - function setColumnFilter(oTable){ - // TODO : remove this dirty hack once js is refactored - if (!oTable.fnSettings()) { return ; } - var aoCols = oTable.fnSettings().aoColumns; - var colsForAdvancedSearch = new Array(); - var advanceSearchDiv = $("div#advanced_search"); - advanceSearchDiv.empty(); - $.each(aoCols, function(i,ele){ - if (ele.bSearchable) { - var currentColId = ele._ColReorder_iOrigCol; - - var inputClass = 'filter_column filter_number_text'; - var labelStyle = "style='margin-right:35px;'"; - if (libraryColumnTypes[ele.mDataProp] != "s") { - inputClass = 'filterColumn filter_number_range'; - labelStyle = ""; - } - - if (ele.bVisible) { - advanceSearchDiv.append( - "
" + - "" + - "
" + - "
"); - } else { - advanceSearchDiv.append( - ""); - } - - if (libraryColumnTypes[ele.mDataProp] == "s") { - var obj = { sSelector: "#"+ele.mDataProp } - } else { - var obj = { sSelector: "#"+ele.mDataProp, type: "number-range" } - } - colsForAdvancedSearch.push(obj); - } else { - colsForAdvancedSearch.push(null); - } - }); - - oTable.columnFilter({ - aoColumns: colsForAdvancedSearch, - bUseColVis: true, - sPlaceHolder: "head:before" - } - ); - } - - function setFilterElement(iColumn, bVisible){ - var actualId = colReorderMap[iColumn]; - var selector = "div#advanced_search_col_"+actualId; - var $el = $(selector); - - if (bVisible) { - $el.show(); - } else { - $el.hide(); - } - } - - function getLibraryDatatableStrings() { - //Set up the datatables string translation table with different strings depending on - //whether you're viewing files, playlists, smart blocks, etc. - var type = parseInt($(".media_type_selector.selected").attr("selection_id")); - type = (type === undefined) ? 1 : type; - - //FIXME: The code that calls this function doesn't work as intended because you can't - // change the oLanguage property of a datatable dynamically. :( - - switch (type) { - /* - case 0: - return getDatatablesStrings({ - "sEmptyTable": $.i18n._("No files found"), - }); - break; - case 1: - return getDatatablesStrings({ - "sEmptyTable": $.i18n._("No playlists found"), - }); - break; - case 2: - return getDatatablesStrings({ - "sEmptyTable": $.i18n._("No smart blocks found"), - }); - break;*/ - default: - return getDatatablesStrings({ - "sEmptyTable": $.i18n._(""), - "sZeroRecords": $.i18n._("No matching results found.") - }); - break; - }; - - } - - - oTable = $libTable.dataTable( { - - // put hidden columns at the top to insure they can never be visible - // on the table through column reordering. - - //IMPORTANT: WHEN ADDING A NEW COLUMN PLEASE CONSULT WITH THE WIKI - // https://wiki.sourcefabric.org/display/CC/Adding+a+new+library+datatable+column - "aoColumns": [ - /* ftype */ { "sTitle" : "" , "mDataProp" : "ftype" , "bSearchable" : false , "bVisible" : false }, - /* Checkbox */ { "sTitle" : "" , "mDataProp" : "checkbox" , "bSortable" : false , "bSearchable" : false , "sWidth" : "16px" , "sClass" : "library_checkbox" }, - /* Type */ { "sTitle" : "" , "mDataProp" : "image" , "bSortable" : false , "bSearchable" : false , "sWidth" : "16px" , "sClass" : "library_type" , "iDataSort" : 0 }, - /* Is Scheduled */ { "sTitle" : $.i18n._("Scheduled") , "mDataProp" : "is_scheduled" , "bVisible" : false , "bSearchable" : false , "sWidth" : "90px" , "sClass" : "library_is_scheduled" }, - ///* Is Playlist */ { "sTitle" : $.i18n._("Playlist / Block") , "mDataProp" : "is_playlist" , "bSearchable" : false , "sWidth" : "110px" , "sClass" : "library_is_playlist"} , - /* Title */ { "sTitle" : $.i18n._("Title") , "mDataProp" : "track_title" , "sClass" : "library_title" , "sWidth" : "170px" }, - /* Creator */ { "sTitle" : $.i18n._("Creator") , "mDataProp" : "artist_name" , "sClass" : "library_creator" , "sWidth" : "160px" }, - /* Album */ { "sTitle" : $.i18n._("Album") , "mDataProp" : "album_title" , "sClass" : "library_album" , "sWidth" : "150px" }, - /* Bit Rate */ { "sTitle" : $.i18n._("Bit Rate") , "mDataProp" : "bit_rate" , "bVisible" : false , "sClass" : "library_bitrate" , "sWidth" : "80px" }, - /* BPM */ { "sTitle" : $.i18n._("BPM") , "mDataProp" : "bpm" , "bVisible" : false , "sClass" : "library_bpm" , "sWidth" : "50px" }, - /* Composer */ { "sTitle" : $.i18n._("Composer") , "mDataProp" : "composer" , "bVisible" : false , "sClass" : "library_composer" , "sWidth" : "150px" }, - /* Conductor */ { "sTitle" : $.i18n._("Conductor") , "mDataProp" : "conductor" , "bVisible" : false , "sClass" : "library_conductor" , "sWidth" : "125px" }, - /* Copyright */ { "sTitle" : $.i18n._("Copyright") , "mDataProp" : "copyright" , "bVisible" : false , "sClass" : "library_copyright" , "sWidth" : "125px" }, - /* Cue In */ { "sTitle" : $.i18n._("Cue In") , "mDataProp" : "cuein" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" }, - /* Cue Out */ { "sTitle" : $.i18n._("Cue Out") , "mDataProp" : "cueout" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" }, - /* Encoded */ { "sTitle" : $.i18n._("Encoded By") , "mDataProp" : "encoded_by" , "bVisible" : false , "sClass" : "library_encoded" , "sWidth" : "150px" }, - /* Genre */ { "sTitle" : $.i18n._("Genre") , "mDataProp" : "genre" , "bVisible" : false , "sClass" : "library_genre" , "sWidth" : "100px" }, - /* ISRC Number */ { "sTitle" : $.i18n._("ISRC") , "mDataProp" : "isrc_number" , "bVisible" : false , "sClass" : "library_isrc" , "sWidth" : "150px" }, - /* Label */ { "sTitle" : $.i18n._("Label") , "mDataProp" : "label" , "bVisible" : false , "sClass" : "library_label" , "sWidth" : "125px" }, - /* Language */ { "sTitle" : $.i18n._("Language") , "mDataProp" : "language" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" }, - /* Last Modified */ { "sTitle" : $.i18n._("Last Modified") , "mDataProp" : "mtime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "155px" }, - /* Last Played */ { "sTitle" : $.i18n._("Last Played") , "mDataProp" : "lptime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "155px" }, - /* Length */ { "sTitle" : $.i18n._("Length") , "mDataProp" : "length" , "sClass" : "library_length" , "sWidth" : "80px" }, - /* Mime */ { "sTitle" : $.i18n._("Mime") , "mDataProp" : "mime" , "bVisible" : false , "sClass" : "library_mime" , "sWidth" : "80px" }, - /* Mood */ { "sTitle" : $.i18n._("Mood") , "mDataProp" : "mood" , "bVisible" : false , "sClass" : "library_mood" , "sWidth" : "70px" }, - /* Owner */ { "sTitle" : $.i18n._("Owner") , "mDataProp" : "owner_id" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" }, - /* Replay Gain */ { "sTitle" : $.i18n._("Replay Gain") , "mDataProp" : "replay_gain" , "bVisible" : false , "sClass" : "library_replay_gain" , "sWidth" : "125px" }, - /* Sample Rate */ { "sTitle" : $.i18n._("Sample Rate") , "mDataProp" : "sample_rate" , "bVisible" : false , "sClass" : "library_sr" , "sWidth" : "125px" }, - /* Track Number */ { "sTitle" : $.i18n._("Track Number") , "mDataProp" : "track_number" , "bVisible" : false , "sClass" : "library_track" , "sWidth" : "125px" }, - /* Upload Time */ { "sTitle" : $.i18n._("Uploaded") , "mDataProp" : "utime" , "bVisible" : false , "sClass" : "library_upload_time" , "sWidth" : "155px" }, - /* Website */ { "sTitle" : $.i18n._("Website") , "mDataProp" : "info_url" , "bVisible" : false , "sClass" : "library_url" , "sWidth" : "150px" }, - /* Year */ { "sTitle" : $.i18n._("Year") , "mDataProp" : "year" , "bVisible" : false , "sClass" : "library_year" , "sWidth" : "60px" }, - /* Context Menu */ { "sTitle" : "" , "mData" : null , "bSortable" : false , "sClass" : "library_actions" , "bSearchable" : false , "sWidth" : "16px" } - ], - - "bProcessing": true, - "bServerSide": true, - - "aLengthMenu": [5, 10, 15, 20, 25, 50, 100], - - "bStateSave": true, - "fnStateSaveParams": function (oSettings, oData) { - // remove oData components we don't want to save. - delete oData.oSearch; - delete oData.aoSearchCols; - }, - "fnStateSave": function (oSettings, oData) { - localStorage.setItem('datatables-library', JSON.stringify(oData)); - /* - $.ajax({ - url: baseUrl+"usersettings/set-library-datatable", - type: "POST", - data: {settings : oData, format: "json"}, - dataType: "json" - }); - */ - - colReorderMap = oData.ColReorder; - }, - "fnStateLoad": function fnLibStateLoad(oSettings) { - var settings = localStorage.getItem('datatables-library'); - - try { - return JSON.parse(settings); - } catch (e) { - return null; - } - }, - "fnStateLoadParams": function (oSettings, oData) { - var i, - length, - a = oData.abVisCols; - - if (a) { - // putting serialized data back into the correct js type to make - // sure everything works properly. - for (i = 0, length = a.length; i < length; i++) { - if (typeof(a[i]) === "string") { - a[i] = (a[i] === "true"); - } - } - } - - a = oData.ColReorder; - if (a) { - for (i = 0, length = a.length; i < length; i++) { - if (typeof(a[i]) === "string") { - a[i] = parseInt(a[i], 10); - } - } - } - - oData.iEnd = parseInt(oData.iEnd, 10); - oData.iLength = parseInt(oData.iLength, 10); - oData.iStart = parseInt(oData.iStart, 10); - oData.iCreate = parseInt(oData.iCreate, 10); - }, - - "sAjaxSource": baseUrl+"Library/contents-feed", - "sAjaxDataProp": "files", - - "fnServerData": function ( sSource, aoData, fnCallback ) { - /* - * The real validation check is done in - * dataTables.columnFilter.js We also need to check it here - * because datatable is redrawn everytime an action is performed - * in the Library page. In order for datatable to redraw the - * advanced search fields MUST all be valid. - */ - var advSearchFields = $("div#advanced_search").children(':visible'); - var advSearchValid = validateAdvancedSearch(advSearchFields); - var type; - aoData.push( { name: "format", value: "json"} ); - aoData.push( { name: "advSearch", value: advSearchValid} ); - - // push whether to search files/playlists or all. - type = $(".media_type_selector.selected").attr("selection_id"); - type = (type === undefined) ? 1 : type; - aoData.push( { name: "type", value: type} ); - - getUsabilityHint(); - - $.ajax( { - "dataType": 'json', - "type": "POST", - "url": sSource, - "data": aoData, - "success": fnCallback - } ); - }, - "fnRowCallback": AIRTIME.library.fnRowCallback, - "fnCreatedRow": function( nRow, aData, iDataIndex ) { - // add checkbox - $(nRow).find('td.library_checkbox').html(""); - - $(nRow).find('td.library_actions') - .text("...") - .on('click', function(e) { - $(this).contextMenu({x: $(e.target).offset().left, y: $(e.target).offset().top}) - }).html("
...
"); - - // add audio preview image/button - if (aData.ftype === "audioclip") { - $(nRow).find('td.library_type').html(''); - } else if (aData.ftype === "playlist") { - $(nRow).find('td.library_type').html(''); - } else if (aData.ftype === "block") { - $(nRow).find('td.library_type').html(''); - } else if (aData.ftype === "stream") { - $(nRow).find('td.library_type').html(''); - } - - if (aData.is_scheduled) { - $(nRow).find("td.library_is_scheduled").html(''); - } else if (!aData.is_scheduled) { - $(nRow).find("td.library_is_scheduled").html(''); - } - if (aData.is_playlist) { - $(nRow).find("td.library_is_playlist").html(''); - } else if (!aData.is_playlist) { - $(nRow).find("td.library_is_playlist").html(''); - } - - // add the play function to the library_type td - $(nRow).find('td.library_type').click(function(){ - if (aData.ftype === 'playlist' && aData.length !== '0.0'){ - open_playlist_preview(aData.audioFile, 0); - } else if (aData.ftype === 'audioclip') { - if (isAudioSupported(aData.mime)) { - open_audio_preview(aData.ftype, aData.id); - } - } else if (aData.ftype == 'stream') { - if (isAudioSupported(aData.mime)) { - open_audio_preview(aData.ftype, aData.id); - } - } else if (aData.ftype == 'block' && aData.bl_type == 'static') { - open_block_preview(aData.audioFile, 0); - } - return false; - }); - }, - // remove any selected nodes before the draw. - "fnPreDrawCallback": function( oSettings ) { - - // make sure any dragging helpers are removed or else they'll be - // stranded on the screen. - $("#draggingContainer").remove(); - }, - "fnDrawCallback": AIRTIME.library.fnDrawCallback, - - "aaSorting": [[5, 'asc']], - "sPaginationType": "full_numbers", - "bJQueryUI": true, - "bAutoWidth": false, - "oLanguage": getLibraryDatatableStrings(), - - // R = ColReorder, C = ColVis - "sDom": 'Rf<"dt-process-rel"r><"H"<"library_toolbar"C>><"dataTables_scrolling"t><"F"ilp>>', - - "oColVis": { - "sAlign": "right", - "aiExclude": [0, 1, 2, 31], - "sSize": "css", - "fnStateChange": setFilterElement, - "buttonText": $.i18n._("Columns") - }, - - "oColReorder": { - "iFixedColumnsRight": 1, - "iFixedColumns": 3 - }, - - "bScrollCollapse": false - - }); - - setColumnFilter(oTable); - oTable.fnSetFilteringDelay(350); - - var simpleSearchText; - - $libContent.on("click", "legend", function(){ - $simpleSearch = $libContent.find("#library_display_filter label"); - var $fs = $(this).parents("fieldset"), - searchHeight, - tableHeight = getTableHeight(), - height; - - if ($fs.hasClass("closed")) { - $fs.removeClass("closed"); - searchHeight = $fs.height(); - - //keep value of simple search for when user switches back to it - simpleSearchText = $simpleSearch.find('input').val(); - - // clear the simple search text field and reset datatable - $(".dataTables_filter input").val("").keyup(); - - $simpleSearch.addClass("sp-invisible"); - } - else { - // clear the advanced search fields - var divs = $("div#advanced_search").children(':visible'); - $.each(divs, function(i, div){ - fields = $(div).children().find('input'); - $.each(fields, function(i, field){ - if ($(field).val() !== "") { - $(field).val(""); - // we need to reset the results when removing - // an advanced search field - $(field).keyup(); - } - }); - }); - - //reset datatable with previous simple search results (if any) - $(".dataTables_filter input").val(simpleSearchText).keyup(); - - $simpleSearch.removeClass("sp-invisible"); - $fs.addClass("closed"); - } - }); - - AIRTIME.library.setupLibraryToolbar(oTable); - - $libTable.find("tbody").on("dblclick", "tr", function(ev) { - var data = $(this).data("aData"); - AIRTIME.library.dblClickAdd(data, data.ftype); - }); - - $libTable.find("tbody").on("mousedown", "tr > td.library_checkbox", function(ev) { - var $tr = $(this).parent(), - // Get the ID of the selected row - $rowId = $tr.attr("id"); - - if (!$tr.hasClass(LIB_SELECTED_CLASS)) { - if (ev.shiftKey && $previouslySelected !== undefined) { - if ($previouslySelected.attr("id") == $rowId) { - return; - } - - // If the selected row comes before the previously selected row, - // we want to select previous rows, otherwise we select next - if ($previouslySelected.prevAll("#" + $rowId).length !== 0) { - $previouslySelected.prevUntil($tr).each(function (i, el) { - mod.selectItem($(el)); - mod.checkItem($(el)); - }); - } else { - $previouslySelected.nextUntil($tr).each(function (i, el) { - mod.selectItem($(el)); - mod.checkItem($(el)); - }); - } - } - mod.selectItem($tr); - mod.checkItem($tr); - } else { - flagForDeselection = true; - } - - // Remember this row so we can properly multiselect - $previouslySelected = $tr; - }); - - $libTable.find("tbody").on("mousedown", "tr > td:not(.library_checkbox)", function(ev) { - var $tr = $(this).parent(), - // Get the ID of the selected row - $rowId = $tr.attr("id"); - - if (ev.shiftKey && $previouslySelected !== undefined) { - if ($previouslySelected.attr("id") == $rowId) { - return; - } - - // If the selected row comes before the previously selected row, - // we want to select previous rows, otherwise we select next - if ($previouslySelected.prevAll("#" + $rowId).length !== 0) { - $previouslySelected.prevUntil($tr).each(function (i, el) { - mod.selectItem($(el)); - mod.checkItem($(el)); - }); - } else { - $previouslySelected.nextUntil($tr).each(function (i, el) { - mod.selectItem($(el)); - mod.checkItem($(el)); - }); - } - } else if (!ev.ctrlKey) { - AIRTIME.library.selectNone(); - } - - mod.selectItem($tr); - mod.checkItem($tr); - - // Remember this row so we can properly multiselect - $previouslySelected = $tr; - }); - - $libTable.find("tbody").on("click", "tr", function() { - var tr = $(this); - - if (flagForDeselection) { - flagForDeselection = false; - mod.deselectItem(tr); - mod.uncheckItem(tr); - } else { - mod.checkItem(tr); - } - }); - - $libTable.find("thead").on("click", "th > input[type='checkbox']", function() { - if ($(this).is(":checked")) { - AIRTIME.library.selectCurrentPage(); - $(this).prop("checked", true); - } else { - AIRTIME.library.selectNone(); - $(this).prop("checked", false); - } - }); - - $('#sb-actions').on("click", function(e) { - $("#library_display tr:has(td)").contextMenu({x: $(e.target).offset().left, y: $(e.target).offset().top}); - }); - - // begin context menu initialization. - AIRTIME.library.ctxMenu = $.contextMenu({ - selector: '#library_display tr:has(td)', - //trigger: "left", - trigger: "custom", - - build: function($el, e) { - var data, screen, items, callback, $tr; - - $tr = $el; - data = $tr.data("aData"); - screen = $tr.data("screen"); - - function processMenuItems(oItems) { - - // define an add to playlist callback. - if (oItems.pl_add !== undefined) { - var aItems = []; - - callback = function() { - aItems.push(new Array(data.id, data.ftype)); - AIRTIME.playlist.fnAddItems(aItems, undefined, 'after'); - }; - - oItems.pl_add.callback = callback; - } - - // define an edit callback. - if (oItems.edit !== undefined) { - if (data.ftype === "audioclip") { - callback = function() { - $.get(oItems.edit.url, {format: "json"}, function(json){ - AIRTIME.playlist.fileMdEdit(json); - }); - }; - } else if (data.ftype === "playlist" || data.ftype === "block") { - callback = function() { - AIRTIME.playlist.fnEdit(data.id, data.ftype, baseUrl+'new-playlist/edit'); - AIRTIME.playlist.validatePlaylistElements(); - }; - } else if (data.ftype === "stream") { - callback = function() { - AIRTIME.playlist.fnEdit(data.id, data.ftype, baseUrl + 'new-webstream/edit'); - } - } else { - throw new Exception($.i18n._("Unknown type: ") + data.ftype); - } - oItems.edit.callback = callback; - } - - // define a play callback. - if (oItems.play !== undefined) { - - if (oItems.play.mime !== undefined) { - if (!isAudioSupported(oItems.play.mime)) { - oItems.play.disabled = true; - } - } - - callback = function() { - if (data.ftype === 'playlist' && data.length !== '0.0'){ - playlistIndex = $(this).parent().attr('id').substring(3); // remove - // the - // pl_ - open_playlist_preview(playlistIndex, 0); - } else if (data.ftype === 'audioclip' || data.ftype === 'stream') { - open_audio_preview(data.ftype, data.id); - } else if (data.ftype === 'block') { - blockIndex = $(this).parent().attr('id').substring(3); // remove - // the - // pl_ - open_block_preview(blockIndex, 0); - } - }; - oItems.play.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" || data.ftype === "block") && screen === "playlist") { - callback = function() { - aMedia = []; - aMedia.push({"id": data.id, "type": data.ftype}); - if (confirm($.i18n._('Are you sure you want to delete the selected item?'))) { - AIRTIME.library.fnDeleteItems(aMedia); - } - }; - } - else { - callback = function() { - var media = []; - - if (confirm($.i18n._('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; - - if (json.message) { - alert(json.message); - } - - oTable = $("#library_display").dataTable(); - oTable.fnDeleteRow( $tr[0] ); - }); - } - }; - } - - oItems.del.callback = callback; - } - - // define a download callback. - if (oItems.download !== undefined) { - - callback = function() { - document.location.href = oItems.download.url; - }; - oItems.download.callback = callback; - } - // add callbacks for Soundcloud menu items. - if (oItems.soundcloud !== undefined) { - var soundcloud = oItems.soundcloud.items; - - // define an upload to soundcloud callback. - if (soundcloud.upload !== undefined) { - - callback = function() { - alert($.i18n._("Your track is being uploaded and will " + - "appear on SoundCloud in a couple of minutes")); - $.post(soundcloud.upload.url, function(){}); - }; - soundcloud.upload.callback = callback; - } - - // define an upload to soundcloud callback. - if (soundcloud.remove !== undefined) { - - callback = function() { - alert($.i18n._("Your track is being deleted from SoundCloud")); - $.post(soundcloud.remove.url, function(){}); - }; - soundcloud.remove.callback = callback; - } - - // define a view on soundcloud callback - if (soundcloud.view !== undefined) { - - callback = function() { - window.open(soundcloud.view.url); - }; - soundcloud.view.callback = callback; - } - } - // add callbacks for duplicate menu items. - if (oItems.duplicate !== undefined) { - var url = oItems.duplicate.url; - callback = function() { - $.post(url, {format: "json", id: data.id }, function(json){ - oTable.fnStandingRedraw(); - }); - }; - oItems.duplicate.callback = callback; - } - // remove 'Add to smart block' option if the current - // block is dynamic - if ($('input:radio[name=sp_type]:checked').val() === "1") { - delete oItems.pl_add; - } - items = oItems; - } - - request = $.ajax({ - url: baseUrl+"library/context-menu", - type: "GET", - data: {id : data.id, type: data.ftype, format: "json", "screen": screen}, - dataType: "json", - async: false, - success: function(json){ - processMenuItems(json.items); - } - }); - - return { - items: items - }; - } - }); - }; - - mod.libraryInit = libraryInit; - - return AIRTIME; - -}(AIRTIME || {})); - -function buildEditMetadataDialog (json){ - var dialog = $(json.dialog); - - dialog.dialog({ - autoOpen: false, - title: $.i18n._("Edit Metadata"), - width: 460, - height: 660, - modal: true, - close: closeDialogLibrary - }); - - dialog.dialog('open'); -} - -function closeDialogLibrary(event, ui) { - $(this).remove(); -} - -/* - * This function is called from dataTables.columnFilter.js - */ -function validateAdvancedSearch(divs) { - var valid, - allValid = true, - fieldName, - fields, - searchTerm = Array(), - searchTermType, - regExpr, - timeRegEx = "\\d{2}[:]([0-5]){1}([0-9]){1}[:]([0-5]){1}([0-9]){1}([.]\\d{1,6})?", - dateRegEx = "\\d{4}[-]\\d{2}[-]\\d{2}?", - integerRegEx = "^\\d+$", - numericRegEx = "^\\d+[.]?\\d*$"; - - searchTerm[0] = ""; - searchTerm[1] = ""; - $.each(divs, function(i, div){ - fieldName = $(div).children('div').attr('id'); - fields = $(div).children().find('input'); - searchTermType = validationTypes[fieldName]; - valid = true; - - $.each(fields, function(i, field){ - searchTerm[i] = $(field).val(); - - if (searchTerm[i] !== "") { - - if (searchTermType === "l") { - regExpr = new RegExp("^" +timeRegEx+ "$"); - } else if (searchTermType === "t") { - var pieces = searchTerm[i].split(" "); - if (pieces.length === 2) { - regExpr = new RegExp("^" +dateRegEx+ " " +timeRegEx+ "$"); - } else if (pieces.length === 1) { - regExpr = new RegExp("^" +dateRegEx+ "$"); - } - } else if (searchTermType === "i") { - regExpr = new RegExp(integerRegEx); - } else if (searchTermType === "n") { - regExpr = new RegExp(numericRegEx); - if (searchTerm[i].charAt(0) === "-") { - searchTerm[i] = searchTerm[i].substr(1); - } - } - - // string fields do not need validation - if (searchTermType !== "s") { - valid = regExpr.test(searchTerm[i]); - if (!valid) allValid = false; - } - - addRemoveValidationIcons(valid, $(field), searchTermType); - - /* - * Empty fields should not have valid/invalid indicator Range values - * are considered valid even if only the 'From' value is provided. - * Therefore, if the 'To' value is empty but the 'From' value is not - * empty we need to keep the validation icon on screen. - */ - } else if (searchTerm[0] === "" && searchTerm[1] !== "" || - searchTerm[0] === "" && searchTerm[1] === ""){ - if ($(field).closest('div').prev().hasClass('checked-icon') || - $(field).closest('div').prev().hasClass('not-available-icon')) { - $(field).closest('div').prev().remove(); - } - } - - if (!valid) { - return false; - } - }); - }); - - return allValid; -} - -function addRemoveValidationIcons(valid, field, searchTermType) { - var title = ''; - if (searchTermType === 'i') { - title = $.i18n._('Input must be a positive number'); - } else if (searchTermType === 'n') { - title = $.i18n._('Input must be a number'); - } else if (searchTermType === 't') { - title = $.i18n._('Input must be in the format: yyyy-mm-dd'); - } else if (searchTermType === 'l') { - title = $.i18n._('Input must be in the format: hh:mm:ss.t'); - } - - var validIndicator = " ", - invalidIndicator = " "; - - if (valid) { - if (!field.closest('div').prev().hasClass('checked-icon')) { - // remove invalid icon before adding valid icon - if (field.closest('div').prev().hasClass('not-available-icon')) { - field.closest('div').prev().remove(); - } - field.closest('div').before(validIndicator); - } - } else { - if (!field.closest('div').prev().hasClass('not-available-icon')) { - // remove valid icon before adding invalid icon - if (field.closest('div').prev().hasClass('checked-icon')) { - field.closest('div').prev().remove(); - } - field.closest('div').before(invalidIndicator); - } - } -} - -function resizeAdvancedSearch() { - var s = $("#advanced_search"); - s.css("max-height", $(window).height() / 4); - s.css("overflow", "auto"); -} - -/* - * Validation types: s => string i => integer n => numeric (positive/negative, - * whole/decimals) t => timestamp l => length - */ -var validationTypes = { - "album_title" : "s", - "artist_name" : "s", - "bit_rate" : "i", - "bpm" : "i", - "comments" : "s", - "composer" : "s", - "conductor" : "s", - "copyright" : "s", - "cuein" : "l", - "cueout" : "l", - "encoded_by" : "s", - "utime" : "t", - "mtime" : "t", - "lptime" : "t", - "disc_number" : "i", - "genre" : "s", - "isrc_number" : "s", - "label" : "s", - "language" : "s", - "length" : "l", - "lyricist" : "s", - "mood" : "s", - "mime" : "s", - "name" : "s", - "orchestra" : "s", - "owner_id" : "s", - "rating" : "i", - "replay_gain" : "n", - "sample_rate" : "n", - "track_title" : "s", - "track_number" : "i", - "info_url" : "s", - "year" : "i" -}; - -$(document).ready(function() { - $('.active-tab .md-save').live("click", function() { - var file_id = $('#file_id').val(), - data = $(".active-tab #edit-md-dialog form").serializeArray(); - $.post(baseUrl+'library/edit-file-md', {format: "json", id: file_id, data: data}, function() { - //$("#edit-md-dialog").dialog().remove(); - - // don't redraw the library table if we are on calendar page - // we would be on calendar if viewing recorded file metadata - if ($("#schedule_calendar").length === 0) { - oTable.fnStandingRedraw(); - } - }); - - AIRTIME.playlist.closeTab(); - }); - - $('#edit-md-dialog').live("keyup", function(event) { - if (event.keyCode === 13) { - $('#editmdsave').click(); - } - }); - - if (location.hash === "") { - $("a[href$='#files']").parent().addClass("selected"); - } - $("a[href$='"+location.hash+"']").parent().addClass("selected"); - - // Slightly hacky way of triggering the click event when it's outside of the anchor text - $(".media_type_selector").on("click", function() { - // Need get(0) here so we don't create a stack overflow by recurring the click on the parent - $(this).find("a").get(0).click(); - }); - - $(window).on('hashchange', function() { - // If we click Dashboard from one of the media views, do nothing - if (!location.hash) { - return; - } - AIRTIME.library.selectNone(); - $(".media_type_selector").each(function () { - $(this).removeClass("selected"); - }); - $("a[href$='"+location.hash+"']").parent().addClass("selected"); - oTable.fnDraw(); - }); - - /* Overridden by hashchange function - - $(".media_type_selector").on("click", function() { - if (!$(this).hasClass("selected")) { - AIRTIME.library.selectNone(); - $(".media_type_selector").each(function () { - $(this).removeClass("selected"); - }); - $(this).addClass("selected"); - oTable.fnDraw(); - } - }); - */ - - $("#advanced-options").on("click", function() { - resizeAdvancedSearch(); - }); - - $(window).resize(function() { - resizeAdvancedSearch(); - }); -}); - diff --git a/airtime_mvc/public/js/airtime/library/_spl.js b/airtime_mvc/public/js/airtime/library/_spl.js deleted file mode 100644 index 2d3f6f729..000000000 --- a/airtime_mvc/public/js/airtime/library/_spl.js +++ /dev/null @@ -1,1576 +0,0 @@ -//-------------------------------------------------------------------------------------------------------------------------------- -// Playlist Functions -//-------------------------------------------------------------------------------------------------------------------------------- - -var AIRTIME = (function(AIRTIME){ - - if (AIRTIME.playlist === undefined) { - AIRTIME.playlist = {}; - } - - var mod = AIRTIME.playlist, - viewport, - $lib, - $pl, - $togglePl = $(""), - widgetHeight, - resizeTimeout, - width, - $tabCount = 0, - $openTabs = {}; - - function isTimeValid(time) { - //var regExpr = new RegExp("^\\d{2}[:]\\d{2}[:]\\d{2}([.]\\d{1,6})?$"); - var regExpr = new RegExp("^\\d{2}[:]([0-5]){1}([0-9]){1}[:]([0-5]){1}([0-9]){1}([.]\\d{1})?$"); - - return regExpr.test(time); - } - - function isFadeValid(fade) { - var regExpr = new RegExp("^\\d{1}(\\d{1})?([.]\\d{1})?$"); - - return regExpr.test(fade); - } - - function playlistError(json) { - alert(json.error); - //closeTab(); - //openPlaylist(json); - } - - function stopAudioPreview() { - // stop any preview playing - $('#jquery_jplayer_1').jPlayer('stop'); - } - - function highlightActive(el) { - - $(el).addClass("ui-state-active"); - } - - function unHighlightActive(el) { - - $(el).removeClass("ui-state-active"); - } - - function showError(el, error) { - $(el).parent().next() - .empty() - .append(error) - .show(); - } - - function hideError(el) { - $(el).parent().next() - .empty() - .hide(); - } - - function changeCueIn(event) { - event.stopPropagation(); - var span = $(this), - id = span.parent().attr("id").split("_").pop(), - url = baseUrl+"new-playlist/set-cue", - cueIn = $.trim(span.text()), - li = span.parents("li"), - unqid = li.attr("unqid"), - lastMod = getModified(), - type = $pl.find('.obj_type').val(); - - if (!isTimeValid(cueIn)){ - showError(span, $.i18n._("please put in a time '00:00:00 (.0)'")); - return; - } - $.post(url, - {format: "json", cueIn: cueIn, id: id, modified: lastMod, type: type}, - function(json){ - - if (json.error !== undefined){ - playlistError(json); - return; - } - if (json.cue_error !== undefined) { - showError(span, json.cue_error); - return; - } - - setPlaylistContent(json); - - li = $('.side_playlist.active-tab li[unqid='+unqid+']'); - li.find(".cue-edit").toggle(); - highlightActive(li); - highlightActive(li.find('.spl_cue')); - }); - } - - function changeCueOut(event) { - event.stopPropagation(); - var span = $(this), - id = span.parent().attr("id").split("_").pop(), - url = baseUrl+"new-playlist/set-cue", - cueOut = $.trim(span.text()), - li = span.parents("li"), - unqid = li.attr("unqid"), - lastMod = getModified(), - type = $pl.find('.obj_type').val(); - - if (!isTimeValid(cueOut)){ - showError(span, $.i18n._("please put in a time '00:00:00 (.0)'")); - return; - } - - $.post(url, - {format: "json", cueOut: cueOut, id: id, modified: lastMod, type: type}, - function(json){ - - if (json.error !== undefined){ - playlistError(json); - return; - } - if (json.cue_error !== undefined) { - showError(span, json.cue_error); - return; - } - - setPlaylistContent(json); - - li = $('.side_playlist.active-tab li[unqid='+unqid+']'); - li.find(".cue-edit").toggle(); - highlightActive(li); - highlightActive(li.find('.spl_cue')); - }); - } - - /* used from waveform pop-up */ - function changeCues($el, id, cueIn, cueOut) { - - var url = baseUrl+"new-playlist/set-cue", - lastMod = getModified(), - type = $pl.find('.obj_type').val(), - li, - span; - - if (!isTimeValid(cueIn)){ - $el.find('.cue-in-error').val($.i18n._("please put in a time '00:00:00 (.0)'")).show(); - return; - } - else { - $el.find('.cue-in-error').hide(); - } - - if (!isTimeValid(cueOut)){ - $el.find('.cue-out-error').val($.i18n._("please put in a time '00:00:00 (.0)'")).show(); - return; - } - else { - $el.find('.cue-out-error').hide(); - } - - $.post(url, - {format: "json", cueIn: cueIn, cueOut: cueOut, id: id, modified: lastMod, type: type}, - function(json){ - - $el.dialog('destroy'); - $el.remove(); - - if (json.error !== undefined){ - playlistError(json); - return; - } - if (json.cue_error !== undefined) { - - li = $('.side_playlist.active-tab li[unqid='+id+']'); - - if (json.code === 0) { - - span = $('#spl_cue_in_'+id).find('span'); - showError(span, json.cue_error); - span = $('#spl_cue_out_'+id).find('span'); - showError(span, json.cue_error); - } - else if (json.code === 1) { - - span = $('#spl_cue_in_'+id).find('span'); - showError(span, json.cue_error); - } - else if (json.code === 2) { - - span = $('#spl_cue_out_'+id).find('span'); - showError(span, json.cue_error); - } - - return; - } - - setPlaylistContent(json); - - li = $('.side_playlist.active-tab li[unqid='+id+']'); - li.find(".cue-edit").toggle(); - highlightActive(li); - highlightActive(li.find('.spl_cue')); - }); - } - - /* used from waveform pop-up */ - function changeCrossfade($el, id1, id2, fadeIn, fadeOut, offset, id) { - - var url = baseUrl+"new-playlist/set-crossfade", - lastMod = getModified(), - type = $pl.find('.obj_type').val(); - - $.post(url, - {format: "json", fadeIn: fadeIn, fadeOut: fadeOut, id1: id1, id2: id2, offset: offset, modified: lastMod, type: type}, - function(json){ - - $el.dialog('destroy'); - $el.remove(); - - if (json.error !== undefined){ - playlistError(json); - return; - } - - setPlaylistContent(json); - - $li = $pl.find('li[unqid='+id+']'); - $li.find('.crossfade').toggle(); - highlightActive($li.find('.spl_fade_control')); - }); - } - - function changeFadeIn(event) { - event.preventDefault(); - - var span = $(this), - id = span.parent().attr("id").split("_").pop(), - url = baseUrl+"new-playlist/set-fade", - fadeIn = $.trim(span.text()), - li = span.parents("li"), - unqid = li.attr("unqid"), - lastMod = getModified(), - type = $pl.find('.obj_type').val(); - - if (!isFadeValid(fadeIn)){ - showError(span, $.i18n._("please put in a time in seconds '00 (.0)'")); - return; - } - - $.post(url, - {format: "json", fadeIn: fadeIn, id: id, modified: lastMod, type: type}, - function(json){ - - if (json.error !== undefined){ - playlistError(json); - return; - } - if (json.fade_error !== undefined) { - showError(span, json.fade_error); - return; - } - - setPlaylistContent(json); - - li = $pl.find('li[unqid='+unqid+']'); - li.find('.crossfade').toggle(); - highlightActive(li.find('.spl_fade_control')); - }); - } - - function changeFadeOut(event) { - event.stopPropagation(); - - var span = $(this), - id = span.parent().attr("id").split("_").pop(), - url = baseUrl+"new-playlist/set-fade", - fadeOut = $.trim(span.text()), - li = span.parents("li"), - unqid = li.attr("unqid"), - lastMod = getModified(), - type = $pl.find('.obj_type').val(); - - if (!isFadeValid(fadeOut)){ - showError(span, $.i18n._("please put in a time in seconds '00 (.0)'")); - return; - } - - $.post(url, - {format: "json", fadeOut: fadeOut, id: id, modified: lastMod, type: type}, - function(json){ - - if (json.error !== undefined){ - playlistError(json); - return; - } - if (json.fade_error !== undefined) { - showError(span, json.fade_error); - return; - } - - setPlaylistContent(json); - - li = $pl.find('li[unqid='+unqid+']'); - li.find('.crossfade').toggle(); - highlightActive(li.find('.spl_fade_control')); - }); - } - - function submitOnEnter(event) { - //enter was pressed - if(event.keyCode === 13) { - event.preventDefault(); - $(this).blur(); - } - } - - function openFadeEditor(event) { - var li; - - event.stopPropagation(); - - li = $(this).parents("li"); - li.find(".crossfade").toggle(); - - if ($(this).hasClass("ui-state-active")) { - unHighlightActive(this); - } - else { - highlightActive(this); - } - } - - function openCueEditor(event) { - var li, icon; - - event.stopPropagation(); - - icon = $(this); - li = $(this).parents("li"); - li.find(".cue-edit").toggle(); - - if (li.hasClass("ui-state-active")) { - unHighlightActive(li); - unHighlightActive(icon); - } - else { - highlightActive(li); - highlightActive(icon); - } - } - - function editName() { - var nameElement = $(this); - //remove any newlines if user somehow snuck them in (easy to do if dragging/dropping text) - nameElement.text(nameElement.text().replace("\n", "")); - - var name = $pl.find(".playlist_name_display").text(); - $(".nav.nav-tabs .active a > span.tab-name").text(name); - } - - function redrawLib() { - var dt = $lib.find("#library_display").dataTable(); - - dt.fnStandingRedraw(); - AIRTIME.library.redrawChosen(); - } - - function setPlaylistContent(json) { - var $html = $(json.html); - - $('#spl_name > a') - .empty() - .append(json.name); - $pl.find('.obj_length') - .empty() - .append(json.length); - $('#fieldset-metadate_change textarea') - .empty() - .val(json.description); - - $pl.find('.spl_sortable').off('focusout keydown'); - $pl.find('.spl_sortable') - .empty() - .append($html); - setCueEvents(); - setFadeEvents(); - setModified(json.modified); - AIRTIME.playlist.validatePlaylistElements(); - redrawLib(); - } - - function setFadeIcon(){ - var contents = $pl.find(".spl_sortable"); - var show = contents.is(":visible"); - var empty = $pl.find(".spl_empty"); - - if (!show || empty.length > 0) { - $pl.find("#spl_crossfade").hide(); - } else { - //get list of playlist contents - var list = contents.children(); - - //if first and last items are blocks, hide the fade icon - var first = list.first(); - var last = list.last(); - if (first.find(':first-child').children().attr('blockid') !== undefined && - last.find(':first-child').children().attr('blockid') !== undefined) { - $pl.find("#spl_crossfade").hide(); - } else { - $pl.find("#spl_crossfade").show(); - } - } - } - - function getId() { - return parseInt($pl.find(".obj_id").val(), 10); - } - - function getModified() { - return parseInt($pl.find(".obj_lastMod").val(), 10); - } - - function setModified(modified) { - $pl.find(".obj_lastMod").val(modified); - } - - /* - * Should all be moved to builder.js eventually - */ - function buildNewTab(json) { - AIRTIME.library.selectNone(); - - var tabId = $openTabs[json.type + json.id]; - if (tabId !== undefined) { - AIRTIME.showbuilder.switchTab($("#pl-tab-content-" + tabId), $("#pl-tab-" + tabId)); - return undefined; - } - $tabCount++; - - var wrapper = "
", - t = $("#show_builder").append(wrapper).find("#pl-tab-content-" + $tabCount), - pane = $(".editor_pane_wrapper:last"), - name = json.type == "md" ? // file - pane.append(json.html).find("#track_title").val() + $.i18n._(" - Metadata Editor") - : pane.append(json.html).find(".playlist_name_display").text(), - tab = - "", - tabs = $(".nav.nav-tabs"); - - if (json.id) { - $openTabs[json.type + json.id] = $tabCount; - } - - $(".nav.nav-tabs li").removeClass("active"); - tabs.append(tab); - tabs.find("#pl-tab-" + $tabCount + " span.tab-name").text(name); - - var newTab = $("#pl-tab-" + $tabCount); - AIRTIME.showbuilder.switchTab(t, newTab); - - return {wrapper: pane, tab: newTab, pane: t}; - } - - function openFileMdEditor(json) { - var newTab = buildNewTab(json); - if (newTab === undefined) { - return; - } - newTab.tab.on("click", function() { - if (!$(this).hasClass('active')) { - AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab); - } - }); - newTab.wrapper.find(".md-cancel").on("click", function() { - closeTab(); - }); - initialEvents(); - } - - function openPlaylist(json) { - var newTab = buildNewTab(json); - if (newTab === undefined) { - return; - } - newTab.tab.on("click", function() { - if (!$(this).hasClass('active')) { - AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab); - $.post(baseUrl+'new-playlist/edit', - {format: "json", id: newTab.pane.find(".obj_id").val(), type: newTab.pane.find(".obj_type").val()}); - } - }); - AIRTIME.playlist.init(); - - // functions in smart_blockbuilder.js - setupUI(); - appendAddButton(); - appendModAddButton(); - removeButtonCheck(); - } - - function openPlaylistPanel() { - viewport = AIRTIME.utilities.findViewportDimensions(); - var screenWidth = Math.floor(viewport.width - 40); - widgetHeight = viewport.height - 185; - - $pl.show().width(Math.floor(screenWidth * 0.44)); - $pl.height(widgetHeight); - $("#pl_edit").hide(); - } - - function closeTab(id) { - var curr = $(".active-tab"), - pane = id ? $(".pl-content[tab-id='" + id + "']") : curr, - tab = id ? $(".nav.nav-tabs [tab-id='" + id + "']") : $(".nav.nav-tabs .active"), - toPane = pane.next().length > 0 ? pane.next() : pane.prev(), - toTab = tab.next().length > 0 ? tab.next() : tab.prev(), - objId = pane.find(".obj_id").val(), - pl = id ? pane : $pl; - delete $openTabs[tab.attr("tab-type") + objId]; // Remove the closed tab from our open tabs array - - // Remove the relevant DOM elements (the tab and the tab content) - tab.remove(); - pl.remove(); - - if (pane.get(0) == curr.get(0)) { // Closing the current tab, otherwise we don't need to switch tabs - AIRTIME.showbuilder.switchTab(toPane, toTab); - } - } - - mod.closeTab = function(id) { - closeTab(id); - }; - - //Purpose of this function is to iterate over all playlist elements - //and verify whether they can be previewed by the browser or not. If not - //then the playlist element is greyed out - mod.validatePlaylistElements = function(){ - $.each($("div .big_play"), function(index, value){ - if ($(value).attr('blockId') === undefined) { - var mime = $(value).attr("data-mime-type"); - //If mime is undefined it is likely because the file was - //deleted from the library. This case is handled in mod.onReady() - if (mime !== undefined) { - if (isAudioSupported(mime)) { - $(value).bind("click", openAudioPreview); - } else { - $(value).attr("class", "big_play_disabled dark_class"); - $(value).qtip({ - content: $.i18n._("Your browser does not support playing this file type: ")+ mime, - show: 'mouseover', - hide: { - delay: 500, - fixed: true - }, - style: { - border: { - width: 0, - radius: 4 - }, - classes: "ui-tooltip-dark ui-tooltip-rounded" - }, - position: { - my: "left bottom", - at: "right center" - } - }) - } - } - } else { - if ($(value).attr('blocktype') === 'dynamic') { - $(value).attr("class", "big_play_disabled dark_class"); - $(value).qtip({ - content: $.i18n._('Dynamic block is not previewable'), - show: 'mouseover', - hide: { - delay: 500, - fixed: true - }, - style: { - border: { - width: 0, - radius: 4 - }, - classes: "ui-tooltip-dark ui-tooltip-rounded" - }, - position: { - my: "left bottom", - at: "right center" - } - }) - } else { - $(value).bind("click", openAudioPreview); - } - } - }); - }; - - //sets events dynamically for playlist entries (each row in the playlist) - function setPlaylistEntryEvents() { - $pl.delegate(".spl_sortable .ui-icon-closethick", - {"click": function(ev){ - var id; - id = parseInt($(this).attr("id").split("_").pop(), 10); - AIRTIME.playlist.fnDeleteItems([id]); - }}); - - $pl.delegate(".spl_fade_control", - {"click": openFadeEditor}); - - $pl.delegate(".spl_cue", - {"click": openCueEditor}); - - $pl.delegate(".spl_block_expand", - {"click": function(ev){ - var id = parseInt($(this).attr("id").split("_").pop(), 10); - var blockId = parseInt($(this).attr("blockId"), 10); - if ($(this).hasClass('close')) { - var sUrl = baseUrl+"new-playlist/get-block-info"; - mod.disableUI(); - $.post(sUrl, {format:"json", id:blockId}, function(data){ - $html = ""; - var isStatic = data.isStatic; - delete data.type; - if (isStatic) { - $.each(data, function(index, ele){ - if (ele.track_title !== undefined) { - if (ele.creator === null) { - ele.creator = ""; - } - if (ele.track_title === null) { - ele.track_title = ""; - } - $html += "
  • " + - ""+ele.track_title+" - " + - ""+ele.creator+"" + - ""+ele.length+"" + - "
  • "; - } - }) - } else { - for (var key in data.crit){ - $.each(data.crit[key], function(index, ele){ - var extra = (ele['extra']==null)?"":"- "+ele['extra']; - $html += "
  • " + - ""+ele['display_name']+"" + - ""+ele['display_modifier']+"" + - ""+ele['value']+"" + - ""+extra+"" + - "
  • "; - }); - } - $html += "

  • "+$.i18n._("Limit to: ")+data.limit.value+" "+data.limit.display_modifier+"
  • "; - } - $pl.find("#block_"+id+"_info").html($html).show(); - mod.enableUI(); - }); - $(this).removeClass('close'); - } else { - $pl.find("#block_"+id+"_info").html("").hide(); - $(this).addClass('close'); - } - }}); - } - - //sets events dynamically for the cue editor. - function setCueEvents() { - var temp = $('.active-tab .spl_sortable'); - temp.on("focusout", ".spl_cue_in span", changeCueIn); - temp.on("keydown", ".spl_cue_in span", submitOnEnter); - - temp.on("focusout", ".spl_cue_out span", changeCueOut); - temp.on("keydown", ".spl_cue_out span", submitOnEnter); - - //remove show waveform buttons since web audio api is not supported. - if (!(window.AudioContext || window.webkitAudioContext)) { - temp.find('.pl-waveform-cues-btn') - .parent() - .html($.i18n._("Waveform features are available in a browser supporting the Web Audio API")); - } - } - - //sets events dynamically for the fade editor. - function setFadeEvents() { - var temp = $('.active-tab .spl_sortable'); - temp.on("focusout", ".spl_fade_in span", changeFadeIn); - temp.on("keydown", ".spl_fade_in span", submitOnEnter); - - temp.on("focusout", ".spl_fade_out span", changeFadeOut); - temp.on("keydown", ".spl_fade_out span", submitOnEnter); - - //remove show waveform buttons since web audio api is not supported. - if (!(window.AudioContext || window.webkitAudioContext)) { - temp.find('.pl-waveform-fades-btn') - .parent() - .html($.i18n._("Waveform features are available in a browser supporting the Web Audio API")); - } - } - - function initialEvents() { - var cachedDescription; - - //main playlist fades events - $pl.on("click", "#spl_crossfade", function() { - var lastMod = getModified(), - type = $pl.find('.obj_type').val(); - - if ($(this).hasClass("ui-state-active")) { - $(this).removeClass("ui-state-active"); - $pl.find("#crossfade_main").hide(); - } - else { - $(this).addClass("ui-state-active"); - - var url = baseUrl+'new-playlist/get-playlist-fades'; - $.post(url, - {format: "json", modified: lastMod, type: type}, - function(json){ - if (json.error !== undefined){ - playlistError(json); - } - else { - var fadeIn = $pl.find("span.spl_main_fade_in"); - var fadeOut = $pl.find("span.spl_main_fade_out"); - if (json.fadeIn == null) { - fadeIn.parent().prev().hide(); - fadeIn.hide(); - } else { - fadeIn.parent().prev().show(); - fadeIn.show(); - fadeIn.empty().append(json.fadeIn); - } - if (json.fadeOut == null) { - fadeOut.parent().prev().hide(); - fadeOut.hide(); - } else { - fadeOut.parent().prev().show(); - fadeOut.show(); - fadeOut.empty().append(json.fadeOut); - } - if (json.fadeIn != null || json.fadeOut != null) { - $pl.find("#crossfade_main").show(); - } - } - }); - } - }); - - $pl.on("blur", "span.spl_main_fade_in", function(event){ - event.stopPropagation(); - - var url = baseUrl+"new-playlist/set-playlist-fades", - span = $(this), - fadeIn = $.trim(span.text()), - lastMod = getModified(), - type = $pl.find('.obj_type').val(); - - if (!isFadeValid(fadeIn)){ - showError(span, $.i18n._("please put in a time in seconds '00 (.0)'")); - return; - } - - $.post(url, - {format: "json", fadeIn: fadeIn, modified: lastMod, type: type}, - function(json){ - hideError(span); - if (json.modified !== undefined) { - setModified(json.modified); - } - }); - }); - - $pl.on("blur", "span.spl_main_fade_out", function(event){ - event.stopPropagation(); - - var url = baseUrl+"new-playlist/set-playlist-fades", - span = $(this), - fadeOut = $.trim(span.text()), - lastMod = getModified(), - type = $pl.find('.obj_type').val(); - - if (!isFadeValid(fadeOut)){ - showError(span, $.i18n._("please put in a time in seconds '00 (.0)'")); - return; - } - - $.post(url, - {format: "json", fadeOut: fadeOut, modified: lastMod, type: type}, - function(json){ - hideError(span); - if (json.modified !== undefined) { - setModified(json.modified); - } - }); - }); - - $pl.on("keydown", "span.spl_main_fade_in, span.spl_main_fade_out", submitOnEnter); - - $pl.on("click", "#crossfade_main > .ui-icon-closethick", function(){ - $pl.find("#spl_crossfade").removeClass("ui-state-active"); - $pl.find("#crossfade_main").hide(); - }); - //end main playlist fades. - - //edit playlist name event - $pl.on("keydown", ".playlist_name_display", submitOnEnter); - $pl.on("blur", ".playlist_name_display", editName); - - //edit playlist description events - $pl.on("click", "legend", function(){ - var $fs = $(this).parents("fieldset"); - - if ($fs.hasClass("closed")) { - cachedDescription = $fs.find("textarea").val(); - $fs.removeClass("closed"); - } - else { - $fs.addClass("closed"); - } - }); - - - $pl.on("click", 'button[id="playlist_shuffle_button"]', function(){ - obj_id = $pl.find('.obj_id').val(); - url = baseUrl+"new-playlist/shuffle"; - enableLoadingIcon(); - $.post(url, {format: "json", obj_id: obj_id}, function(json){ - - if (json.error !== undefined) { - alert(json.error); - } - if (json.html !== undefined) { - closeTab(); - openPlaylist(json); - } - if (json.result == "0") { - $pl.find('.success').text($.i18n._('Playlist shuffled')); - $pl.find('.success').show(); - } - disableLoadingIcon(); - setTimeout(removeSuccessMsg, 5000); - }); - }); - - $pl.find("#webstream_save").on("click", function(){ - //get all fields and POST to server - //description - //stream url - //default_length - //playlist name - var id = $pl.find(".obj_id").attr("value"); - var description = $pl.find("#description").val(); - var streamurl = $pl.find("#streamurl-element input").val(); - var length = $pl.find("#streamlength-element input").val(); - var name = $pl.find(".playlist_name_display").text(); - - //hide any previous errors (if any) - $(".side_playlist.active-tab .errors").empty().hide(); - - var url = baseUrl+'new-webstream/save'; - $.post(url, - {format: "json", id:id, description: description, url:streamurl, length: length, name: name}, - function(json){ - if (json.analysis){ - for (var s in json.analysis){ - var field = json.analysis[s]; - - if (!field[0]) { - var elemId = "#"+s+"-error"; - var $div = $(".side_playlist.active-tab " + elemId).text(field[1]).show(); - } - } - } else { - var $status = $(".side_playlist.active-tab .status"); - $status.html(json.statusMessage); - $status.show(); - setTimeout(function(){$status.fadeOut("slow", function(){$status.empty()})}, 5000); - - var $ws_id = $(".active-tab .obj_id"); - $ws_id.attr("value", json.streamId); - - var $ws_id = $("#ws_delete"); - $ws_id.show(); - - - var length = $(".side_playlist.active-tab .ws_length"); - length.text(json.length); - - //redraw the library to show the new webstream - redrawLib(); - } - - }); - - - }); - - $pl.find("#webstream_cancel, #cancel_button").on("click", function() { - var tabId = $pl.attr("tab-id"); - $("li[tab-id=" + tabId + "] .lib_pl_close").click(); - }); - - $lib.on("click", "#pl_edit", function() { - openPlaylistPanel(); - $.ajax({ - url : baseUrl+"usersettings/set-library-screen-settings", - type : "POST", - data : { - settings : { - playlist : true - }, - format : "json" - }, - dataType : "json" - }); - }); - - // Unbind so each tab is only handled by its own close button - $(".lib_pl_close").unbind().click(function(e) { - e.preventDefault(); - e.stopPropagation(); - - $(this).unbind("click"); // Prevent repeated clicks in quick succession from closing multiple tabs - - var tabId = $(this).closest("li").attr("tab-id"); - //AIRTIME.showbuilder.switchTab($("#pl-tab-content-" + tabId), $("#pl-tab-" + tabId)); - //$pl.hide(); - - // We need to update the text on the add button - AIRTIME.library.checkAddButton(); - // We also need to run the draw callback to update how dragged items are drawn - AIRTIME.library.fnDrawCallback(); - - var name = $pl.find('.playlist_name_display').text().trim(); - - if ((name == "Untitled Playlist" - || name == "Untitled Smart Block") - && $pl.find(".spl_sortable .spl_empty").length == 1) { - mod.fnDelete(undefined, tabId); - } else { - closeTab(tabId); - } - - $.ajax( { - url : baseUrl+"usersettings/set-library-screen-settings", - type : "POST", - data : { - settings : { - playlist : false - }, - format : "json" - }, - dataType : "json" - }); - }); - - $pl.on("click", "#save_button", function(event) { - /* Smart blocks: get name, description, and criteria - * Playlists: get name, description - */ - var criteria = $pl.find('form').serializeArray(), - block_name = $pl.find('.playlist_name_display').text(), - block_desc = $pl.find('textarea[name="description"]').val(), - save_action = baseUrl+'new-playlist/save', - obj_id = $pl.find(".obj_id").val(), - obj_type = $pl.find('.obj_type').val(), - lastMod = getModified(), - dt = $('table[id="library_display"]').dataTable(); - enableLoadingIcon(); - $.post(save_action, - {format: "json", data: criteria, name: block_name, description: block_desc, obj_id: obj_id, type: obj_type, modified: lastMod}, - function(json){ - if (json.error !== undefined) { - alert(json.error); - } - if (json.html !== undefined) { - closeTab(); - openPlaylist(json); - } - setModified(json.modified); - if (obj_type == "block") { - callback(json, "save"); - } else { - $('.success').text($.i18n._('Playlist saved')); - $('.success').show(); - setTimeout(removeSuccessMsg, 5000); - dt.fnStandingRedraw(); - } - setFadeIcon(); - disableLoadingIcon(); - } - ); - }); - - $pl.find("#pl-bl-clear-content").unbind().on("click", function(event) { - var sUrl = baseUrl+"new-playlist/empty-content", - oData = {}; - playlistRequest(sUrl, oData); - }); - } - - function setUpPlaylist() { - var sortableConf; - - sortableConf = (function(){ - var aReceiveItems, - html, - fnReceive, - fnUpdate; - - fnReceive = function(event, ui) { - var aItems = [], - aSelected, - i, - length; - - AIRTIME.library.addToChosen(ui.item); - - //filter out anything that isn't an audiofile. - aSelected = AIRTIME.library.getSelectedData(); - - for (i = 0, length = aSelected.length; i < length; i++) { - aItems.push(new Array(aSelected[i].id, aSelected[i].ftype)); - } - - aReceiveItems = aItems; - html = ui.helper.html(); - - AIRTIME.library.removeFromChosen(ui.item); - }; - - fnUpdate = function(event, ui) { - var prev, - aItems = [], - iAfter, - sAddType; - - prev = ui.item.prev(); - if (prev.hasClass("spl_empty") || prev.length === 0) { - iAfter = undefined; - sAddType = 'before'; - } - else { - iAfter = parseInt(prev.attr("id").split("_").pop(), 10); - sAddType = 'after'; - } - - //item was dragged in from library datatable - if (aReceiveItems !== undefined) { - - $pl.find("tr.ui-draggable") - .after(html) - .empty(); - - aItems = aReceiveItems; - aReceiveItems = undefined; - - AIRTIME.playlist.fnAddItems(aItems, iAfter, sAddType); - } - //item was reordered. - else { - aItems.push(parseInt(ui.item.attr("id").split("_").pop(), 10)); - AIRTIME.playlist.fnMoveItems(aItems, iAfter); - } - }; - - return { - items: 'li', - //hack taken from - //http://stackoverflow.com/questions/2150002/jquery-ui-sortable-how-can-i-change-the-appearance-of-the-placeholder-object - placeholder: { - element: function(currentItem) { - return $('
  • ')[0]; - }, - update: function(container, p) { - return; - } - }, - forcePlaceholderSize: true, - //handle: 'div.list-item-container', - start: function(event, ui) { - ui.placeholder.height(56); - }, - axis: "y", - containment: "document", - receive: fnReceive, - update: fnUpdate - }; - }()); - - $pl.find(".spl_sortable").sortable(sortableConf); - AIRTIME.playlist.validatePlaylistElements(); - } - - mod.fnNew = function() { - var url = baseUrl+'new-playlist/new'; - - stopAudioPreview(); - - $.post(url, - {format: "json", type: 'playlist'}, - function(json){ - openPlaylist(json); - redrawLib(); - }); - }; - - mod.fnWsNew = function() { - var url = baseUrl+'new-webstream/new'; - - stopAudioPreview(); - - $.post(url, - {format: "json"}, - function(json){ - openPlaylist(json); - redrawLib(); - }); - }; - - - mod.fnNewBlock = function() { - var url = baseUrl+'new-playlist/new'; - - stopAudioPreview(); - - $.post(url, - {format: "json", type: 'block'}, - function(json){ - openPlaylist(json); - redrawLib(); - }); - }; - - mod.fileMdEdit = function(json) { - openFileMdEditor(json); - }; - - mod.fnEdit = function(id, type, url) { - //openPlaylistPanel(); - stopAudioPreview(); - - $.post(url, - {format: "json", id: id, type: type}, - function(json){ - openPlaylist(json); - redrawLib(); - }); - }; - - - mod.fnDelete = function(plid, tabId) { - var url, id, lastMod, type, pl = (tabId === undefined) ? $pl : $('#pl-tab-content-' + tabId); - - stopAudioPreview(); - id = (plid === undefined) ? getId() : plid; - lastMod = getModified(); - type = pl.find('.obj_type').val(); - url = baseUrl+'new-playlist/delete'; - - $.post(url, - {format: "json", ids: id, modified: lastMod, type: type}, - function(json) { - closeTab(tabId); - redrawLib(); - }); - }; - - mod.fnWsDelete = function(wsid) { - var url, id, lastMod; - - stopAudioPreview(); - id = (wsid === undefined) ? getId() : wsid; - lastMod = getModified(); - type = $pl.find('.obj_type').val(); - url = baseUrl+'new-webstream/delete'; - - $.post(url, - {format: "json", ids: id, modified: lastMod, type: type}, - function(json){ - openPlaylist(json); - redrawLib(); - }); - }; - - mod.disableUI = function() { - - $lib.block({ - message: "", - theme: true, - applyPlatformOpacityRules: false - }); - - $pl.block({ - message: "", - theme: true, - applyPlatformOpacityRules: false - }); - }; - - mod.fnOpenPlaylist = function(json) { - openPlaylist(json); - }; - - mod.enableUI = function() { - $lib.unblock(); - $pl.unblock(); - - setupUI(); - }; - - function playlistResponse(json){ - if (json.error !== undefined) { - playlistError(json); - } - else { - setPlaylistContent(json); - setFadeIcon(); - } - - mod.enableUI(); - } - - function playlistRequest(sUrl, oData) { - var lastMod, - obj_type = $pl.find('.obj_type').val(); - - mod.disableUI(); - - lastMod = getModified(); - - oData["modified"] = lastMod; - oData["obj_type"] = obj_type; - oData["format"] = "json"; - - $.post( - sUrl, - oData, - playlistResponse - ); - } - - mod.fnAddItems = function(aItems, iAfter, sAddType) { - AIRTIME.library.selectNone(); - var sUrl = baseUrl+"new-playlist/add-items"; - oData = {"aItems": aItems, "afterItem": iAfter, "type": sAddType}; - playlistRequest(sUrl, oData); - }; - - mod.fnMoveItems = function(aIds, iAfter) { - var sUrl = baseUrl+"new-playlist/move-items", - oData = {"ids": aIds, "afterItem": iAfter}; - - playlistRequest(sUrl, oData); - }; - - mod.fnDeleteItems = function(aItems) { - var sUrl = baseUrl+"new-playlist/delete-items", - oData = {"ids": aItems}; - - playlistRequest(sUrl, oData); - }; - - mod.showFadesWaveform = function(e) { - var $el = $(e.target), - $parent = $el.parents("dl"), - $li = $el.parents("li"), - $fadeOut = $parent.find(".spl_fade_out"), - $fadeIn = $parent.find(".spl_fade_in"), - $html = $($("#tmpl-pl-fades").html()), - tracks = [], - dim = AIRTIME.utilities.findViewportDimensions(), - playlistEditor, - id1, id2, - id = $li.attr("unqid"); - - - function removeDialog() { - playlistEditor.stop(); - - $html.dialog("destroy"); - $html.remove(); - } - - if ($fadeOut.length > 0) { - - tracks.push({ - src: $fadeOut.data("fadeout"), - cuein: $fadeOut.data("cuein"), - cueout: $fadeOut.data("cueout"), - fades: [{ - shape: $fadeOut.data("type"), - type: "FadeOut", - end: $fadeOut.data("cueout") - $fadeOut.data("cuein"), - start: $fadeOut.data("cueout") - $fadeOut.data("cuein") - $fadeOut.data("length") - }], - states: { - 'fadein': false, - 'shift': false - } - }); - - id1 = $fadeOut.data("item"); - } - - if ($fadeIn.length > 0) { - - tracks.push({ - src: $fadeIn.data("fadein"), - start: $fadeIn.data("offset"), - cuein: $fadeIn.data("cuein"), - cueout: $fadeIn.data("cueout"), - fades: [{ - shape: $fadeIn.data("type"), - type: "FadeIn", - end: $fadeIn.data("length"), - start: 0 - }], - states: { - 'fadeout': false, - 'shift': false - } - }); - - id2 = $fadeIn.data("item"); - } - - //set the first track to not be moveable (might only be one track depending on what follows) - //tracks[0].states["shift"] = false; - - $html.dialog({ - modal: true, - title: $.i18n._("Fade Editor"), - show: 'clip', - hide: 'clip', - width: dim.width - 100, - height: 350, - buttons: [ - {text: $.i18n._("Cancel"), class: "btn btn-small", click: removeDialog}, - {text: $.i18n._("Save"), class: "btn btn-small btn-inverse", click: function() { - var json = playlistEditor.getJson(), - offset, - fadeIn, fadeOut, - fade; - - playlistEditor.stop(); - - if (json.length === 0) - { - id1 = undefined; - id2 = undefined; - } - else if (json.length === 1) { - - fade = json[0]["fades"][0]; - - if (fade["type"] === "FadeOut") { - fadeOut = fade["end"] - fade["start"]; - id2 = undefined; //incase of track decode error. - } - else { - fadeIn = fade["end"] - fade["start"]; - id1 = undefined; //incase of track decode error. - } - } - else { - - offset = json[0]["end"] - json[1]["start"]; - - fade = json[0]["fades"][0]; - fadeOut = fade["end"] - fade["start"]; - - fade = json[1]["fades"][0]; - fadeIn = fade["end"] - fade["start"]; - } - - fadeIn = (fadeIn === undefined) ? undefined : fadeIn.toFixed(1); - fadeOut = (fadeOut === undefined) ? undefined : fadeOut.toFixed(1); - - changeCrossfade($html, id1, id2, fadeIn, fadeOut, offset, id); - }} - ], - open: function (event, ui) { - - var config = new Config({ - resolution: 15000, - state: "cursor", - mono: true, - timescale: true, - waveHeight: 80, - container: $html[0], - UITheme: "jQueryUI", - timeFormat: 'hh:mm:ss.u' - }); - - playlistEditor = new PlaylistEditor(); - playlistEditor.setConfig(config); - playlistEditor.init(tracks); - }, - close: removeDialog, - resizeStop: function(event, ui) { - playlistEditor.resize(); - } - }); - }; - - mod.showCuesWaveform = function(e) { - var $el = $(e.target), - $li = $el.parents("li"), - id = $li.attr("unqid"), - $parent = $el.parent(), - uri = $parent.data("uri"), - $html = $($("#tmpl-pl-cues").html()), - cueIn = $li.find('.spl_cue_in').data("cueIn"), - cueOut = $li.find('.spl_cue_out').data("cueOut"), - cueInSec = $li.find('.spl_cue_in').data("cueSec"), - cueOutSec = $li.find('.spl_cue_out').data("cueSec"), - tracks = [{ - src: uri, - selected: { - start: cueInSec, - end: cueOutSec - } - }], - dim = AIRTIME.utilities.findViewportDimensions(), - playlistEditor; - - function removeDialog() { - playlistEditor.stop(); - - $html.dialog("destroy"); - $html.remove(); - } - - $html.find('.editor-cue-in').html(cueIn); - $html.find('.editor-cue-out').html(cueOut); - - $html.on("click", ".set-cue-in", function(e) { - var cueIn = $html.find('.audio_start').val(); - - $html.find('.editor-cue-in').html(cueIn); - }); - - $html.on("click", ".set-cue-out", function(e) { - var cueOut = $html.find('.audio_end').val(); - - $html.find('.editor-cue-out').html(cueOut); - }); - - $html.dialog({ - modal: true, - title: $.i18n._("Cue Editor"), - show: 'clip', - hide: 'clip', - width: dim.width - 100, - height: 325, - buttons: [ - {text: $.i18n._("Cancel"), class: "btn btn-small", click: removeDialog}, - {text: $.i18n._("Save"), class: "btn btn-small btn-inverse", click: function() { - var cueIn = $html.find('.editor-cue-in').html(), - cueOut = $html.find('.editor-cue-out').html(); - - playlistEditor.stop(); - - changeCues($html, id, cueIn, cueOut); - }} - ], - open: function (event, ui) { - - var config = new Config({ - resolution: 15000, - mono: true, - timescale: true, - waveHeight: 80, - container: $html[0], - UITheme: "jQueryUI", - timeFormat: 'hh:mm:ss.u' - }); - - playlistEditor = new PlaylistEditor(); - playlistEditor.setConfig(config); - playlistEditor.init(tracks); - }, - close: removeDialog, - resizeStop: function(event, ui) { - playlistEditor.resize(); - } - }); - }; - - mod.setAsActive = function() { - $pl = $(".active-tab"); - }; - - mod.init = function() { - AIRTIME.playlist.setAsActive(); - - //$pl.delegate("#spl_delete", {"click": function(ev){ - // AIRTIME.playlist.fnDelete(); - //}}); - // - //$pl.delegate("#ws_delete", {"click": function(ev){ - // AIRTIME.playlist.fnWsDelete(); - //}}); - - $pl.delegate(".pl-waveform-cues-btn", {"click": function(ev){ - AIRTIME.playlist.showCuesWaveform(ev); - }}); - - $pl.delegate(".pl-waveform-fades-btn", {"click": function(ev){ - AIRTIME.playlist.showFadesWaveform(ev); - }}); - - setPlaylistEntryEvents(); - setCueEvents(); - setFadeEvents(); - setFadeIcon(); - - initialEvents(); - setUpPlaylist(); - - $pl.find(".ui-icon-alert").qtip({ - content: { - text: sprintf($.i18n._("%s is unsure about the status of this file. This can happen when the file is on a remote drive that is unaccessible or the file is in a directory that isn't 'watched' anymore."), PRODUCT_NAME) - }, - position: { - adjust: { - resize: true, - method: "flip flip" - }, - at: "right center", - my: "left top", - viewport: $(window) - }, - style: { - classes: "ui-tooltip-dark" - }, - show: 'mouseover', - hide: 'mouseout' - }); - }; - - mod.onReady = function() { - $lib = $("#library_content"); - - $('#new-playlist').live('click', function(){AIRTIME.playlist.fnNew();}); - $('#new-smart-block').live('click', function(){AIRTIME.playlist.fnNewBlock();}); - $('#new-webstream').live('click', function(){AIRTIME.playlist.fnWsNew();}); - - AIRTIME.playlist.init(); - }; - - mod.onResize = function() { - var h = $(".panel-header .nav").height(); - $(".pl-content").css("margin-top", h + 5); // 8px extra for padding - $("#show_builder_table_wrapper").css("top", h + 5); - }; - - return AIRTIME; - -}(AIRTIME || {})); - - -$(document).ready(AIRTIME.playlist.onReady); -$(window).resize(AIRTIME.playlist.onResize); diff --git a/airtime_mvc/public/js/airtime/library/events/_library_showbuilder.js b/airtime_mvc/public/js/airtime/library/events/_library_showbuilder.js deleted file mode 100644 index 4b5a7a718..000000000 --- a/airtime_mvc/public/js/airtime/library/events/_library_showbuilder.js +++ /dev/null @@ -1,350 +0,0 @@ -var AIRTIME = (function(AIRTIME) { - var mod; - - if (AIRTIME.library === undefined) { - AIRTIME.library = {}; - } - - mod = AIRTIME.library; - - mod.checkAddButton = function() { - var selected = mod.getChosenItemsLength(), $cursor = $('tr.sb-selected'), check = false, - shows = $('tr.sb-header'), current = $('tr.sb-current-show'), - // TODO: this is an ugly way of doing this... we should find a more robust way of checking which view we're in. - btnText = (window.location.href.toLowerCase().indexOf("schedule") > -1) ? $.i18n._('Add to show') : $.i18n._('Add to next show'); - - // make sure library items are selected and a cursor is selected. - if (selected !== 0) { - check = true; - } - - if (shows.length === 0) { - check = false; - } - - if (check) { - AIRTIME.button.enableButton("btn-group #library-plus", false); - } else { - AIRTIME.button.disableButton("btn-group #library-plus", false); - } - - if ($("#show_builder_table").is(":visible")) { - if ($cursor.length !== 0) { - btnText = $.i18n._('Add after selected items'); - } else if (current.length !== 0) { - btnText = $.i18n._('Add to current show'); - } - } else { - var objType = $('.active-tab .obj_type').val(); - if (objType === 'block') { - btnText = $.i18n._('Add to current smart block'); - } else { - btnText = $.i18n._('Add to current playlist'); - } - } - AIRTIME.library.changeAddButtonText($('.btn-group #library-plus #lib-plus-text'), btnText); - }; - - mod.fnRowCallback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { - var $nRow = $(nRow); - - if (aData.ftype === "audioclip") { - $nRow.addClass("lib-audio"); - $image = $nRow.find('td.library_type'); - if (!isAudioSupported(aData.mime)) { - $image.html(''); - aData.image = ''; - } - } else if (aData.ftype === "stream") { - $nRow.addClass("lib-stream"); - } else { - $nRow.addClass("lib-pl"); - } - - $nRow.attr("id", aData["tr_id"]).data("aData", aData).data("screen", - "timeline"); - }; - - mod.fnDrawCallback = function fnLibDrawCallback() { - - mod.redrawChosen(); - mod.checkToolBarIcons(); - - var cb = $('th.library_checkbox'); - if (cb.find("input").length == 0) { - cb.append(""); - } - - if ($("#show_builder_table").is(":visible")) { - $('#library_display tr.lib-audio, tr.lib-pl, tr.lib-stream') - .draggable( - { - helper: function () { - - var $el = $(this), selected = mod - .getChosenItemsLength(), container, thead = $("#show_builder_table thead"), colspan = thead - .find("th").length, width = $el.width(), message; - - // dragging an element that has an unselected - // checkbox. - if (mod.isChosenItem($el) === false) { - selected++; - } - - if (selected === 1) { - message = $.i18n._("Adding 1 Item"); - } else { - message = sprintf($.i18n._("Adding %s Items"), selected); - } - - container = $('
    ').attr('id', - 'draggingContainer').append('') - .find("tr").append('').find("td") - .attr("colspan", colspan).width(width) - .addClass("ui-state-highlight").append( - message).end().end(); - - return container; - }, - cursor: 'pointer', - //cursorAt: { - // top: 30, - // right: 10 - //}, - distance: 25, // min-distance for dragging - connectToSortable: '#show_builder_table' - }); - } else { - $('#library_display tr.lib-audio, tr.lib-stream, tr.lib-pl, tr.lib-block') - .draggable( - { - helper: function () { - - var $el = $(this), selected = mod - .getChosenAudioFilesLength(), container, message, - width = $(this).width(), height = 55; - - // dragging an element that has an unselected - // checkbox. - if (mod.isChosenItem($el) === false) { - selected++; - } - - if (selected === 1) { - message = $.i18n._("Adding 1 Item"); - } else { - message = sprintf($.i18n._("Adding %s Items"), selected); - } - - container = $('
    ').append( - "
  • ").find("li").addClass( - "ui-state-default").append("
    ") - .find("div").addClass( - "list-item-container").append( - message).end().width(width) - .height(height).end(); - - return container; - }, - cursor: 'pointer', - //cursorAt: { - // top: 30, - // right: 10 - //}, - distance: 25, // min-distance for dragging - connectToSortable: '.active-tab .spl_sortable' - }); - } - }; - - mod.dblClickAdd = function(data, type) { - var i, length, temp, aMediaIds = [], aSchedIds = [], aData = []; - - if ($("#show_builder_table").is(":visible")) { - // process selected files/playlists. - aMediaIds.push({ - "id": data.id, - "type": type - }); - - $("#show_builder_table tr.sb-selected").each(function (i, el) { - aData.push($(el).data("aData")); - }); - - // process selected schedule rows to add media after. - for (i = 0, length = aData.length; i < length; i++) { - temp = aData[i]; - aSchedIds.push({ - "id": temp.id, - "instance": temp.instance, - "timestamp": temp.timestamp - }); - } - - if (aSchedIds.length == 0) { - if (!addToCurrentOrNext(aSchedIds)) { - return; - } - } - - AIRTIME.showbuilder.fnAdd(aMediaIds, aSchedIds); - } else { - // process selected files/playlists. - aMediaIds.push(new Array(data.id, data.ftype)); - - // check if a playlist/block is open before adding items - if ($('.active-tab .obj_type').val() == 'playlist' - || $('.active-tab .obj_type').val() == 'block') { - AIRTIME.playlist.fnAddItems(aMediaIds, undefined, 'after'); - } - } - }; - - function addToCurrentOrNext(arr) { - var el; - // Add to the end of the current or next show by getting the footer - el = $(".sb-footer.sb-future:first"); - var data = el.prev().data("aData"); - - if (data === undefined) { - alert($.i18n._("Cannot schedule outside a show.\nTry creating a show first.")); - return false; - } - - arr.push({ - "id" : data.id, - "instance" : data.instance, - "timestamp" : data.timestamp - }); - - if (!isInView(el)) { - $('.dataTables_scrolling.sb-padded').animate({ - scrollTop: el.offset().top - }, 0); - } - - return true; - } - - mod.setupLibraryToolbar = function() { - var $toolbar = $(".lib-content .fg-toolbar:first"); - - mod.createToolbarButtons(); - mod.moveSearchBarToHeader(); - - $toolbar.append($menu); - // add to timeline button - $toolbar - .find('#library-plus') - .click( - function() { - - if (AIRTIME.button.isDisabled('btn-group #library-plus') === true) { - return; - } - - var selected = AIRTIME.library.getSelectedData(), data, i, length, temp, aMediaIds = [], aSchedIds = [], aData = []; - - if ($("#show_builder_table").is(":visible")) { - for (i = 0, length = selected.length; i < length; i++) { - data = selected[i]; - aMediaIds.push( { - "id" : data.id, - "type" : data.ftype - }); - } - - // process selected files/playlists. - $("#show_builder_table tr.sb-selected").each(function(i, el) { - aData.push($(el).data("aData")); - }); - - // process selected schedule rows to add media - // after. - for (i = 0, length = aData.length; i < length; i++) { - temp = aData[i]; - aSchedIds.push( { - "id" : temp.id, - "instance" : temp.instance, - "timestamp" : temp.timestamp - }); - } - - if (aSchedIds.length == 0) { - if (!addToCurrentOrNext(aSchedIds)) { - return; - } - } - - AIRTIME.showbuilder.fnAdd(aMediaIds, aSchedIds); - } else { - for (i = 0, length = selected.length; i < length; i++) { - data = selected[i]; - aMediaIds.push([data.id, data.ftype]); - } - - // check if a playlist/block is open before adding items - if ($('.active-tab .obj_type').val() == 'playlist' - || $('.active-tab .obj_type').val() == 'block') { - AIRTIME.playlist.fnAddItems(aMediaIds, undefined, 'after'); - } - } - }); - - // delete from library. - $toolbar.find('.icon-trash').parent().click(function() { - - if (AIRTIME.button.isDisabled('icon-trash') === true) { - return; - } - - AIRTIME.library.fnDeleteSelectedItems(); - }); - - $toolbar.find('#sb-new').click(function() { - if (AIRTIME.button.isDisabled('btn-group #sb-new') === true) { - return; - } - - var selection = $(".media_type_selector.selected").attr("selection_id"); - - if (selection == 2) { - AIRTIME.playlist.fnNew(); - } else if (selection == 3) { - AIRTIME.playlist.fnNewBlock(); - } else if (selection == 4) { - AIRTIME.playlist.fnWsNew(); - } - }); - - - $toolbar.find('#sb-edit').click(function() { - if (AIRTIME.button.isDisabled('btn-group #sb-edit') === true) { - return; - } - - var selected = $(".lib-selected"); - - selected.each(function(i, el) { - var data = $(el).data("aData"); - - if (data.ftype === "audioclip") { - $.get(baseUrl + "library/edit-file-md/id/" + data.id, {format: "json"}, function(json){ - AIRTIME.playlist.fileMdEdit(json); - //buildEditMetadataDialog(json); - }); - } else if (data.ftype === "playlist" || data.ftype === "block") { - AIRTIME.playlist.fnEdit(data.id, data.ftype, baseUrl+'new-playlist/edit'); - AIRTIME.playlist.validatePlaylistElements(); - } else if (data.ftype === "stream") { - AIRTIME.playlist.fnEdit(data.id, data.ftype, baseUrl + 'new-webstream/edit'); - } - }); - }); - - mod.createToolbarDropDown(); - }; - - return AIRTIME; - -}(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 8dcfd651b..9c17fa001 100644 --- a/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js +++ b/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js @@ -11,7 +11,7 @@ var AIRTIME = (function(AIRTIME) { var selected = mod.getChosenItemsLength(), $cursor = $('tr.sb-selected'), check = false, shows = $('tr.sb-header'), current = $('tr.sb-current-show'), // TODO: this is an ugly way of doing this... we should find a more robust way of checking which view we're in. - cursorText = (window.location.href.toLowerCase().indexOf("schedule") > -1) ? $.i18n._('Add to show') : $.i18n._('Add to next show'); + btnText = (window.location.href.toLowerCase().indexOf("schedule") > -1) ? $.i18n._('Add to show') : $.i18n._('Add to next show'); // make sure library items are selected and a cursor is selected. if (selected !== 0) { @@ -22,18 +22,27 @@ var AIRTIME = (function(AIRTIME) { check = false; } - if (check === true) { + if (check) { AIRTIME.button.enableButton("btn-group #library-plus", false); } else { AIRTIME.button.disableButton("btn-group #library-plus", false); } - if ($cursor.length !== 0) { - cursorText = $.i18n._('Add before selected items'); - } else if (current.length !== 0) { - cursorText = $.i18n._('Add to current show'); + if ($("#show_builder_table").is(":visible")) { + if ($cursor.length !== 0) { + btnText = $.i18n._('Add after selected items'); + } else if (current.length !== 0) { + btnText = $.i18n._('Add to current show'); + } + } else { + var objType = $('.active-tab .obj_type').val(); + if (objType === 'block') { + btnText = $.i18n._('Add to current smart block'); + } else { + btnText = $.i18n._('Add to current playlist'); + } } - AIRTIME.library.changeAddButtonText($('.btn-group #library-plus #lib-plus-text'), ' '+ cursorText); + AIRTIME.library.changeAddButtonText($('.btn-group #library-plus #lib-plus-text'), btnText); }; mod.fnRowCallback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { @@ -53,7 +62,7 @@ var AIRTIME = (function(AIRTIME) { } $nRow.attr("id", aData["tr_id"]).data("aData", aData).data("screen", - "timeline"); + "timeline"); }; mod.fnDrawCallback = function fnLibDrawCallback() { @@ -61,15 +70,20 @@ var AIRTIME = (function(AIRTIME) { mod.redrawChosen(); mod.checkToolBarIcons(); - $('#library_display tr.lib-audio, tr.lib-pl, tr.lib-stream') - .draggable( + var cb = $('th.library_checkbox'); + if (cb.find("input").length == 0) { + cb.append(""); + } + + if ($("#show_builder_table").is(":visible")) { + $('#library_display tr.lib-audio, tr.lib-pl, tr.lib-stream') + .draggable( { - helper : function() { + helper: function () { var $el = $(this), selected = mod - .getChosenItemsLength(), container, thead = $("#show_builder_table thead"), colspan = thead - .find("th").length, width = thead.find( - "tr:first").width(), message; + .getChosenItemsLength(), container, thead = $("#show_builder_table thead"), colspan = thead + .find("th").length, width = $el.width(), message; // dragging an element that has an unselected // checkbox. @@ -84,73 +98,123 @@ var AIRTIME = (function(AIRTIME) { } container = $('
    ').attr('id', - 'draggingContainer').append('') - .find("tr").append('').find("td") - .attr("colspan", colspan).width(width) - .addClass("ui-state-highlight").append( - message).end().end(); + 'draggingContainer').append('') + .find("tr").append('').find("td") + .attr("colspan", colspan).width(width) + .addClass("ui-state-highlight").append( + message).end().end(); return container; }, - cursor : 'pointer', - cursorAt: { - top: 30, - left: 100 - }, - connectToSortable : '#show_builder_table' + cursor: 'pointer', + //cursorAt: { + // top: 30, + // right: 10 + //}, + distance: 25, // min-distance for dragging + connectToSortable: '#show_builder_table' }); + } else { + $('#library_display tr.lib-audio, tr.lib-stream, tr.lib-pl, tr.lib-block') + .draggable( + { + helper: function () { + + var $el = $(this), selected = mod + .getChosenAudioFilesLength(), container, message, + width = $(this).width(), height = 55; + + // dragging an element that has an unselected + // checkbox. + if (mod.isChosenItem($el) === false) { + selected++; + } + + if (selected === 1) { + message = $.i18n._("Adding 1 Item"); + } else { + message = sprintf($.i18n._("Adding %s Items"), selected); + } + + container = $('
    ').append( + "
  • ").find("li").addClass( + "ui-state-default").append("
    ") + .find("div").addClass( + "list-item-container").append( + message).end().width(width) + .height(height).end(); + + return container; + }, + cursor: 'pointer', + //cursorAt: { + // top: 30, + // right: 10 + //}, + distance: 25, // min-distance for dragging + connectToSortable: '.active-tab .spl_sortable' + }); + } }; mod.dblClickAdd = function(data, type) { var i, length, temp, aMediaIds = [], aSchedIds = [], aData = []; - // process selected files/playlists. - aMediaIds.push( { - "id" : data.id, - "type" : type - }); - - $("#show_builder_table tr.sb-selected").each(function(i, el) { - aData.push($(el).prev().data("aData")); - }); - - // process selected schedule rows to add media after. - for (i = 0, length = aData.length; i < length; i++) { - temp = aData[i]; - aSchedIds.push( { - "id" : temp.id, - "instance" : temp.instance, - "timestamp" : temp.timestamp + if ($("#show_builder_table").is(":visible")) { + // process selected files/playlists. + aMediaIds.push({ + "id": data.id, + "type": type }); - } - if (aSchedIds.length == 0) { - if (!addToCurrentOrNext(aSchedIds)) { - return; + $("#show_builder_table tr.sb-selected").each(function (i, el) { + aData.push($(el).data("aData")); + }); + + // process selected schedule rows to add media after. + for (i = 0, length = aData.length; i < length; i++) { + temp = aData[i]; + aSchedIds.push({ + "id": temp.id, + "instance": temp.instance, + "timestamp": temp.timestamp + }); + } + + if (aSchedIds.length == 0) { + if (!addToCurrentOrNext(aSchedIds)) { + return; + } + } + + AIRTIME.showbuilder.fnAdd(aMediaIds, aSchedIds); + } else { + // process selected files/playlists. + aMediaIds.push(new Array(data.id, data.ftype)); + + // check if a playlist/block is open before adding items + if ($('.active-tab .obj_type').val() == 'playlist' + || $('.active-tab .obj_type').val() == 'block') { + AIRTIME.playlist.fnAddItems(aMediaIds, undefined, 'after'); } } - - AIRTIME.showbuilder.fnAdd(aMediaIds, aSchedIds); }; function addToCurrentOrNext(arr) { var el; - // Get the show instance id of the first non-data row (id = 0) - // The second last row in the table with that instance id is the - // last schedule item for the first show. (This is important for - // the Now Playing screen if multiple shows are in view). - el = $("[si_id="+$("#0").attr("si_id")+"]"); - var temp = el.eq(-2).data("aData"); + // Add to the end of the current or next show by getting the footer + el = $(".sb-footer.sb-future:first"); + var data = el.prev().data("aData"); - if (temp === undefined) { - alert($.i18n._("Cannot schedule outside a show.")); + if (data === undefined) { + alert($.i18n._("Cannot schedule outside a show.\nTry creating a show first.")); return false; } arr.push({ - "id" : temp.id, - "instance" : temp.instance, - "timestamp" : temp.timestamp + "id" : data.id, + "instance" : data.instance, + "timestamp" : data.timestamp }); if (!isInView(el)) { @@ -159,57 +223,72 @@ var AIRTIME = (function(AIRTIME) { }, 0); } - return arr; + return true; } mod.setupLibraryToolbar = function() { var $toolbar = $(".lib-content .fg-toolbar:first"); mod.createToolbarButtons(); + mod.moveSearchBarToHeader(); $toolbar.append($menu); // add to timeline button $toolbar - .find('.icon-plus').parent() + .find('#library-plus') .click( function() { if (AIRTIME.button.isDisabled('btn-group #library-plus') === true) { return; } - - var selected = AIRTIME.library.getSelectedData(), data, i, length, temp, aMediaIds = [], aSchedIds = [], aData = []; - - // process selected files/playlists. - for (i = 0, length = selected.length; i < length; i++) { - data = selected[i]; - aMediaIds.push( { - "id" : data.id, - "type" : data.ftype - }); - } - - $("#show_builder_table tr.sb-selected") - .each(function(i, el) { - aData.push($(el).prev().data("aData")); - }); - - // process selected schedule rows to add media - // after. - for (i = 0, length = aData.length; i < length; i++) { - temp = aData[i]; - aSchedIds.push( { - "id" : temp.id, - "instance" : temp.instance, - "timestamp" : temp.timestamp - }); - } - if (aSchedIds.length == 0) { - addToCurrentOrNext(aSchedIds); + var selected = AIRTIME.library.getSelectedData(), data, i, length, temp, aMediaIds = [], aSchedIds = [], aData = []; + + if ($("#show_builder_table").is(":visible")) { + for (i = 0, length = selected.length; i < length; i++) { + data = selected[i]; + aMediaIds.push( { + "id" : data.id, + "type" : data.ftype + }); + } + + // process selected files/playlists. + $("#show_builder_table tr.sb-selected").each(function(i, el) { + aData.push($(el).data("aData")); + }); + + // process selected schedule rows to add media + // after. + for (i = 0, length = aData.length; i < length; i++) { + temp = aData[i]; + aSchedIds.push( { + "id" : temp.id, + "instance" : temp.instance, + "timestamp" : temp.timestamp + }); + } + + if (aSchedIds.length == 0) { + if (!addToCurrentOrNext(aSchedIds)) { + return; + } + } + + AIRTIME.showbuilder.fnAdd(aMediaIds, aSchedIds); + } else { + for (i = 0, length = selected.length; i < length; i++) { + data = selected[i]; + aMediaIds.push([data.id, data.ftype]); + } + + // check if a playlist/block is open before adding items + if ($('.active-tab .obj_type').val() == 'playlist' + || $('.active-tab .obj_type').val() == 'block') { + AIRTIME.playlist.fnAddItems(aMediaIds, undefined, 'after'); + } } - - AIRTIME.showbuilder.fnAdd(aMediaIds, aSchedIds); }); // delete from library. @@ -222,6 +301,47 @@ var AIRTIME = (function(AIRTIME) { AIRTIME.library.fnDeleteSelectedItems(); }); + $toolbar.find('#sb-new').click(function() { + if (AIRTIME.button.isDisabled('btn-group #sb-new') === true) { + return; + } + + var selection = $(".media_type_selector.selected").attr("selection_id"); + + if (selection == 2) { + AIRTIME.playlist.fnNew(); + } else if (selection == 3) { + AIRTIME.playlist.fnNewBlock(); + } else if (selection == 4) { + AIRTIME.playlist.fnWsNew(); + } + }); + + + $toolbar.find('#sb-edit').click(function() { + if (AIRTIME.button.isDisabled('btn-group #sb-edit') === true) { + return; + } + + var selected = $(".lib-selected"); + + selected.each(function(i, el) { + var data = $(el).data("aData"); + + if (data.ftype === "audioclip") { + $.get(baseUrl + "library/edit-file-md/id/" + data.id, {format: "json"}, function(json){ + AIRTIME.playlist.fileMdEdit(json); + //buildEditMetadataDialog(json); + }); + } else if (data.ftype === "playlist" || data.ftype === "block") { + AIRTIME.playlist.fnEdit(data.id, data.ftype, baseUrl+'playlist/edit'); + AIRTIME.playlist.validatePlaylistElements(); + } else if (data.ftype === "stream") { + AIRTIME.playlist.fnEdit(data.id, data.ftype, baseUrl + 'webstream/edit'); + } + }); + }); + mod.createToolbarDropDown(); }; diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index cfa4fe1ec..e80f763de 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -7,7 +7,8 @@ var AIRTIME = (function(AIRTIME) { LIB_SELECTED_CLASS = "lib-selected", chosenItems = {}, visibleChosenItems = {}, - $previouslySelected; + $previouslySelected, + flagForDeselection = false; // we need to know whether the criteria value is string or @@ -51,33 +52,32 @@ var AIRTIME = (function(AIRTIME) { "info_url" : "s", "replay_gain" : "n" }; - + if (AIRTIME.library === undefined) { AIRTIME.library = {}; } mod = AIRTIME.library; - + mod.getChosenItemsLength = function(){ var cItem, selected, $trs; - // Get visible items and check if any chosenItems are visible - $trs = $libTable.find("tbody input:checkbox").parents("tr"); + $trs = $libTable.find("tr"); $trs.each(function(i){ for (cItem in chosenItems) { if (cItem === $(this).attr("id")) { visibleChosenItems[cItem] = $(this).data('aData'); } - } + } }); - + selected = Object.keys(visibleChosenItems).length; visibleChosenItems = {}; return selected; }; - + mod.getChosenAudioFilesLength = function(){ // var files = Object.keys(chosenItems), var files, @@ -86,21 +86,21 @@ var AIRTIME = (function(AIRTIME) { i, length, count = 0, reAudio=/^(au|st|pl|bl)/ ; - + // Get visible items and check if any chosenItems are visible - $trs = $libTable.find("tbody input:checkbox").parents("tr"); + $trs = $libTable.find("tr"); $trs.each(function(i){ for (cItem in chosenItems) { if (cItem === $(this).attr("id")) { visibleChosenItems[cItem] = $(this).data('aData'); } - } + } }); - + files = Object.keys(visibleChosenItems); - + for (i = 0, length = files.length; i < length; i++) { - + if (files[i].search(reAudio) !== -1) { count++; } @@ -108,43 +108,64 @@ var AIRTIME = (function(AIRTIME) { visibleChosenItems = {}; return count; }; - + mod.changeAddButtonText = function($button, btnText) { $button.text(btnText); }; - - mod.createToolbarButtons = function() { + + mod.createToolbarButtons = function () { $menu = $("
    "); $menu + .append("
    " + + "" + + "
    ") + .append("
    " + + "" + + "
    ") + .append("
    " + - "" + - "" + - "
    ") + "" + + "
    ") + .append("
    " + + "" + + "
    ") .append("
    " + - "" + - "
    ") - .append("
    " + - "" + - "
    "); + "" + + "" + + "
    "); }; - + + mod.moveSearchBarToHeader = function() { + $("#library_display_filter").appendTo("#library_content > .panel-header"); + $("#advanced_search").click(function(e) { + e.stopPropagation(); + }); + }; + mod.createToolbarDropDown = function() { $('#sb-select-page').click(function(){mod.selectCurrentPage();}); $('#sb-dselect-page').click(function(){mod.deselectCurrentPage();}); $('#sb-dselect-all').click(function(){mod.selectNone();}); }; - + mod.checkDeleteButton = function() { var selected = mod.getChosenItemsLength(), check = false; @@ -152,7 +173,7 @@ var AIRTIME = (function(AIRTIME) { if (selected !== 0) { check = true; } - + if (check === true) { AIRTIME.button.enableButton("btn-group #sb-trash", false); } @@ -160,31 +181,64 @@ var AIRTIME = (function(AIRTIME) { AIRTIME.button.disableButton("btn-group #sb-trash", false); } }; - + + mod.checkEditButton = function() { + var selected = mod.getChosenItemsLength(), + check = false; + + if (selected >= 1) { + check = true; + } + + if (check === true) { + AIRTIME.button.enableButton("btn-group #sb-edit", false); + } + else { + AIRTIME.button.disableButton("btn-group #sb-edit", false); + } + }; + + mod.checkNewButton = function() { + var selected = $(".media_type_selector.selected").attr("selection_id"), + check = false; + + if (selected != 1) { + check = true; + } + + if (check === true) { + AIRTIME.button.enableButton("btn-group #sb-new", false); + } + else { + AIRTIME.button.disableButton("btn-group #sb-new", false); + } + }; + mod.checkToolBarIcons = function() { - AIRTIME.library.checkAddButton(); AIRTIME.library.checkDeleteButton(); + AIRTIME.library.checkEditButton(); + AIRTIME.library.checkNewButton(); }; - + mod.getSelectedData = function() { var id, data = [], cItem, $trs; - + $.fn.reverse = [].reverse; - + // Get visible items and check if any chosenItems are visible - $trs = $libTable.find("tbody input:checkbox").parents("tr").reverse(); + $trs = $libTable.find("tr").reverse(); $trs.each(function(i){ for (cItem in chosenItems) { if (cItem === $(this).attr("id")) { visibleChosenItems[cItem] = $(this).data('aData'); } - } + } }); - + for (id in visibleChosenItems) { if (visibleChosenItems.hasOwnProperty(id)) { data.push(visibleChosenItems[id]); @@ -193,73 +247,79 @@ var AIRTIME = (function(AIRTIME) { visibleChosenItems = {}; return data; }; - + mod.redrawChosen = function() { var ids = Object.keys(chosenItems), i, length, $el; - + for (i = 0, length = ids.length; i < length; i++) { $el = $libTable.find("#"+ids[i]); - + if ($el.length !== 0) { mod.highlightItem($el); + mod.checkItem($el); } } }; - + mod.isChosenItem = function($el) { var id = $el.attr("id"), item = chosenItems[id]; - return item !== undefined ? true : false; + return item !== undefined; }; - + mod.addToChosen = function($el) { var id = $el.attr("id"); - + chosenItems[id] = $el.data('aData'); }; - + mod.removeFromChosen = function($el) { var id = $el.attr("id"); - + // used to not keep dragged items selected. if (!$el.hasClass(LIB_SELECTED_CLASS)) { delete chosenItems[id]; - } + } }; - + + mod.checkItem = function($el) { + $el.find(".library_checkbox > input").prop('checked', true); + $("#super-checkbox").prop("checked", true); + }; + + mod.uncheckItem = function($el) { + $el.find(".library_checkbox > input").prop('checked', false); + if ($("." + LIB_SELECTED_CLASS.length == 0)) { + $("#super-checkbox").prop("checked", false); + } + }; + mod.highlightItem = function($el) { - var $input = $el.find("input"); - - $input.attr("checked", true); $el.addClass(LIB_SELECTED_CLASS); }; - + mod.unHighlightItem = function($el) { - var $input = $el.find("input"); - - $input.attr("checked", false); $el.removeClass(LIB_SELECTED_CLASS); }; - + mod.selectItem = function($el) { - mod.highlightItem($el); mod.addToChosen($el); - + // Remember this row so we can properly multiselect + $previouslySelected = $el; + mod.checkToolBarIcons(); }; - + mod.deselectItem = function($el) { - mod.unHighlightItem($el); mod.removeFromChosen($el); - mod.checkToolBarIcons(); }; - + /* * selects all items which the user can currently see. (behaviour taken from * gmail) @@ -269,63 +329,67 @@ var AIRTIME = (function(AIRTIME) { */ mod.selectCurrentPage = function() { $.fn.reverse = [].reverse; - var $inputs = $libTable.find("tbody input:checkbox"), - $trs = $inputs.parents("tr").reverse(); - - $inputs.attr("checked", true); - $trs.addClass(LIB_SELECTED_CLASS); + var $trs = $libTable.find("tbody").find("tr").reverse(); $trs.each(function(i, el){ - $el = $(this); - mod.addToChosen($el); + mod.selectItem($(el)); + mod.checkItem($(el)); }); mod.checkToolBarIcons(); - + }; - + /* * deselects all items that the user can currently see. (behaviour taken * from gmail) */ mod.deselectCurrentPage = function() { - var $inputs = $libTable.find("tbody input:checkbox"), - $trs = $inputs.parents("tr"), - id; - - $inputs.attr("checked", false); - $trs.removeClass(LIB_SELECTED_CLASS); - + var $trs = $libTable.find("tr"); + $trs.each(function(i, el){ - $el = $(this); - id = $el.attr("id"); - delete chosenItems[id]; + mod.deselectItem($(el)); + mod.uncheckItem($(el)); }); - - mod.checkToolBarIcons(); - }; - - mod.selectNone = function() { - var $inputs = $libTable.find("tbody input:checkbox"), - $trs = $inputs.parents("tr"); - - $inputs.attr("checked", false); - $trs.removeClass(LIB_SELECTED_CLASS); - - chosenItems = {}; - + mod.checkToolBarIcons(); }; - - mod.fnDeleteItems = function(aMedia) { + mod.selectNone = function() { + var $trs = $libTable.find("tr"); + $trs.each(function(i, el){ + mod.deselectItem($(el)); + mod.uncheckItem($(el)); + }); + $previouslySelected = undefined; + + chosenItems = {}; + + mod.checkToolBarIcons(); + }; + + mod.fnRedraw = function() { + oTable.fnStandingRedraw(); + }; + + mod.fnDeleteItems = function(aMedia) { //Prevent the user from spamming the delete button while the AJAX request is in progress AIRTIME.button.disableButton("btn-group #sb-trash", false); - //Hack to immediately show the "Processing" div in DataTables to give the user some sort of feedback. - $(".dataTables_processing").css('visibility','visible'); + var openTabObjectIds = $(".obj_id"), + mediaIds = []; + for (var i in aMedia) { + mediaIds.push(parseInt(aMedia[i].id)); + } - $.post(baseUrl+"library/delete", - {"format": "json", "media": aMedia}, + openTabObjectIds.each(function(i, el) { + var v = parseInt($(el).val()); + if ($.inArray(v, mediaIds) > -1) { + AIRTIME.playlist.closeTab($(el).closest(".pl-content").attr("tab-id")); + } + }); + + $.post(baseUrl+"library/delete", + {"format": "json", "media": aMedia}, function(json){ if (json.message !== undefined) { alert(json.message); @@ -338,15 +402,15 @@ var AIRTIME = (function(AIRTIME) { AIRTIME.button.enableButton("btn-group #sb-trash", false); }); }; - + mod.fnDeleteSelectedItems = function() { if (confirm($.i18n._('Are you sure you want to delete the selected item(s)?'))) { var aData = AIRTIME.library.getSelectedData(), item, temp, aMedia = [], - currentObjId = $(".side_playlist").find(".obj_id").val(), - currentObjType = $(".side_playlist").find(".obj_type").val(), + currentObjId = $(".side_playlist.active-tab").find(".obj_id").val(), + currentObjType = $(".side_playlist.active-tab").find(".obj_type").val(), closeObj = false; // process selected files/playlists. @@ -355,7 +419,7 @@ var AIRTIME = (function(AIRTIME) { if (temp !== null && temp.hasOwnProperty('id') ) { aMedia.push({"id": temp.id, "type": temp.ftype}); if ( (temp.id == currentObjId && temp.ftype === currentObjType) || - temp.id == currentObjId && temp.ftype === "stream" && currentObjType === "webstream") { + temp.id == currentObjId && temp.ftype === "stream" && currentObjType === "webstream") { closeObj = true; } } @@ -370,42 +434,42 @@ var AIRTIME = (function(AIRTIME) { $.post(baseUrl+"playlist/close-playlist", {"format": "json", "type": currentObjType}, function(json) { - $(".side_playlist").empty().append(json.html); + $("#editor_pane_wrapper").empty().append(json.html); }); } } }; - + libraryInit = function() { - + $libContent = $("#library_content"); - + /* * Icon hover states in the toolbar. */ $libContent.on("mouseenter", ".fg-toolbar ul li", function(ev) { $el = $(this); - + if (!$el.hasClass("ui-state-disabled")) { $el.addClass("ui-state-hover"); - } + } }); $libContent.on("mouseleave", ".fg-toolbar ul li", function(ev) { $el = $(this); - + if (!$el.hasClass("ui-state-disabled")) { $el.removeClass("ui-state-hover"); - } + } }); - + var colReorderMap = new Array(); - + $libTable = $libContent.find("table"); - + function getTableHeight() { - return $libContent.height() - 175; + return $libContent.height() - 175; } - + function setColumnFilter(oTable){ // TODO : remove this dirty hack once js is refactored if (!oTable.fnSettings()) { return ; } @@ -416,28 +480,28 @@ var AIRTIME = (function(AIRTIME) { $.each(aoCols, function(i,ele){ if (ele.bSearchable) { var currentColId = ele._ColReorder_iOrigCol; - - var inputClass = 'filter_column filter_number_text'; + + var inputClass = 'filter_column filter_number_text'; var labelStyle = "style='margin-right:35px;'"; if (libraryColumnTypes[ele.mDataProp] != "s") { inputClass = 'filterColumn filter_number_range'; labelStyle = ""; } - + if (ele.bVisible) { advanceSearchDiv.append( "
    " + - "" + - "
    " + + "" + + "
    " + "
    "); } else { advanceSearchDiv.append( ""); } - + if (libraryColumnTypes[ele.mDataProp] == "s") { var obj = { sSelector: "#"+ele.mDataProp } } else { @@ -448,82 +512,111 @@ var AIRTIME = (function(AIRTIME) { colsForAdvancedSearch.push(null); } }); - + oTable.columnFilter({ - aoColumns: colsForAdvancedSearch, - bUseColVis: true, - sPlaceHolder: "head:before" + aoColumns: colsForAdvancedSearch, + bUseColVis: true, + sPlaceHolder: "head:before" } ); } - + function setFilterElement(iColumn, bVisible){ var actualId = colReorderMap[iColumn]; var selector = "div#advanced_search_col_"+actualId; var $el = $(selector); - + if (bVisible) { $el.show(); } else { $el.hide(); } - - //resize to prevent double scroll bars. - var $fs = $el.parents("fieldset"), - tableHeight = getTableHeight(), - searchHeight = $fs.height(); - - $libContent.find(".dataTables_scrolling").css("max-height", tableHeight - searchHeight); } - + + function getLibraryDatatableStrings() { + //Set up the datatables string translation table with different strings depending on + //whether you're viewing files, playlists, smart blocks, etc. + var type = parseInt($(".media_type_selector.selected").attr("selection_id")); + type = (type === undefined) ? 1 : type; + + //FIXME: The code that calls this function doesn't work as intended because you can't + // change the oLanguage property of a datatable dynamically. :( + + switch (type) { + /* + case 0: + return getDatatablesStrings({ + "sEmptyTable": $.i18n._("No files found"), + }); + break; + case 1: + return getDatatablesStrings({ + "sEmptyTable": $.i18n._("No playlists found"), + }); + break; + case 2: + return getDatatablesStrings({ + "sEmptyTable": $.i18n._("No smart blocks found"), + }); + break;*/ + default: + return getDatatablesStrings({ + "sEmptyTable": $.i18n._(""), + "sZeroRecords": $.i18n._("No matching results found.") + }); + break; + }; + + } + oTable = $libTable.dataTable( { - + // put hidden columns at the top to insure they can never be visible // on the table through column reordering. - + //IMPORTANT: WHEN ADDING A NEW COLUMN PLEASE CONSULT WITH THE WIKI // https://wiki.sourcefabric.org/display/CC/Adding+a+new+library+datatable+column "aoColumns": [ - /* ftype */ { "sTitle" : "" , "mDataProp" : "ftype" , "bSearchable" : false , "bVisible" : false } , - /* Checkbox */ { "sTitle" : "" , "mDataProp" : "checkbox" , "bSortable" : false , "bSearchable" : false , "sWidth" : "25px" , "sClass" : "library_checkbox" } , - /* Type */ { "sTitle" : "" , "mDataProp" : "image" , "bSearchable" : false , "sWidth" : "25px" , "sClass" : "library_type" , "iDataSort" : 0 } , - /* Is Scheduled */ { "sTitle" : $.i18n._("Scheduled") , "mDataProp" : "is_scheduled" , "bSearchable" : false , "sWidth" : "90px" , "sClass" : "library_is_scheduled"} , - /* Is Playlist */ { "sTitle" : $.i18n._("Playlist / Block") , "mDataProp" : "is_playlist" , "bSearchable" : false , "sWidth" : "110px" , "sClass" : "library_is_playlist"} , - /* Title */ { "sTitle" : $.i18n._("Title") , "mDataProp" : "track_title" , "sClass" : "library_title" , "sWidth" : "170px" } , - /* Creator */ { "sTitle" : $.i18n._("Creator") , "mDataProp" : "artist_name" , "sClass" : "library_creator" , "sWidth" : "160px" } , - /* Album */ { "sTitle" : $.i18n._("Album") , "mDataProp" : "album_title" , "sClass" : "library_album" , "sWidth" : "150px" } , - /* Bit Rate */ { "sTitle" : $.i18n._("Bit Rate") , "mDataProp" : "bit_rate" , "bVisible" : false , "sClass" : "library_bitrate" , "sWidth" : "80px" }, - /* BPM */ { "sTitle" : $.i18n._("BPM") , "mDataProp" : "bpm" , "bVisible" : false , "sClass" : "library_bpm" , "sWidth" : "50px" }, - /* Composer */ { "sTitle" : $.i18n._("Composer") , "mDataProp" : "composer" , "bVisible" : false , "sClass" : "library_composer" , "sWidth" : "150px" }, - /* Conductor */ { "sTitle" : $.i18n._("Conductor") , "mDataProp" : "conductor" , "bVisible" : false , "sClass" : "library_conductor" , "sWidth" : "125px" }, - /* Copyright */ { "sTitle" : $.i18n._("Copyright") , "mDataProp" : "copyright" , "bVisible" : false , "sClass" : "library_copyright" , "sWidth" : "125px" }, - /* Cue In */ { "sTitle" : $.i18n._("Cue In") , "mDataProp" : "cuein" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" }, - /* Cue Out */ { "sTitle" : $.i18n._("Cue Out") , "mDataProp" : "cueout" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" }, - /* Encoded */ { "sTitle" : $.i18n._("Encoded By") , "mDataProp" : "encoded_by" , "bVisible" : false , "sClass" : "library_encoded" , "sWidth" : "150px" }, - /* Genre */ { "sTitle" : $.i18n._("Genre") , "mDataProp" : "genre" , "bVisible" : false , "sClass" : "library_genre" , "sWidth" : "100px" }, - /* ISRC Number */ { "sTitle" : $.i18n._("ISRC") , "mDataProp" : "isrc_number" , "bVisible" : false , "sClass" : "library_isrc" , "sWidth" : "150px" }, - /* Label */ { "sTitle" : $.i18n._("Label") , "mDataProp" : "label" , "bVisible" : false , "sClass" : "library_label" , "sWidth" : "125px" }, - /* Language */ { "sTitle" : $.i18n._("Language") , "mDataProp" : "language" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" }, - /* Last Modified */ { "sTitle" : $.i18n._("Last Modified") , "mDataProp" : "mtime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "125px" }, - /* Last Played */ { "sTitle" : $.i18n._("Last Played") , "mDataProp" : "lptime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "125px" }, - /* Length */ { "sTitle" : $.i18n._("Length") , "mDataProp" : "length" , "sClass" : "library_length" , "sWidth" : "80px" } , - /* Mime */ { "sTitle" : $.i18n._("Mime") , "mDataProp" : "mime" , "bVisible" : false , "sClass" : "library_mime" , "sWidth" : "80px" }, - /* Mood */ { "sTitle" : $.i18n._("Mood") , "mDataProp" : "mood" , "bVisible" : false , "sClass" : "library_mood" , "sWidth" : "70px" }, - /* Owner */ { "sTitle" : $.i18n._("Owner") , "mDataProp" : "owner_id" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" }, - /* Replay Gain */ { "sTitle" : $.i18n._("Replay Gain") , "mDataProp" : "replay_gain" , "bVisible" : false , "sClass" : "library_replay_gain" , "sWidth" : "80px" }, - /* Sample Rate */ { "sTitle" : $.i18n._("Sample Rate") , "mDataProp" : "sample_rate" , "bVisible" : false , "sClass" : "library_sr" , "sWidth" : "80px" }, - /* Track Number */ { "sTitle" : $.i18n._("Track Number") , "mDataProp" : "track_number" , "bVisible" : false , "sClass" : "library_track" , "sWidth" : "65px" }, - /* Upload Time */ { "sTitle" : $.i18n._("Uploaded") , "mDataProp" : "utime" , "sClass" : "library_upload_time" , "sWidth" : "125px" } , - /* Website */ { "sTitle" : $.i18n._("Website") , "mDataProp" : "info_url" , "bVisible" : false , "sClass" : "library_url" , "sWidth" : "150px" }, - /* Year */ { "sTitle" : $.i18n._("Year") , "mDataProp" : "year" , "bVisible" : false , "sClass" : "library_year" , "sWidth" : "60px" } - ], - - + /* ftype */ { "sTitle" : "" , "mDataProp" : "ftype" , "bSearchable" : false , "bVisible" : false }, + /* Checkbox */ { "sTitle" : "" , "mDataProp" : "checkbox" , "bSortable" : false , "bSearchable" : false , "sWidth" : "16px" , "sClass" : "library_checkbox" }, + /* Type */ { "sTitle" : "" , "mDataProp" : "image" , "bSortable" : false , "bSearchable" : false , "sWidth" : "16px" , "sClass" : "library_type" , "iDataSort" : 0 }, + /* Is Scheduled */ { "sTitle" : $.i18n._("Scheduled") , "mDataProp" : "is_scheduled" , "bVisible" : false , "bSearchable" : false , "sWidth" : "90px" , "sClass" : "library_is_scheduled" }, + ///* Is Playlist */ { "sTitle" : $.i18n._("Playlist / Block") , "mDataProp" : "is_playlist" , "bSearchable" : false , "sWidth" : "110px" , "sClass" : "library_is_playlist"} , + /* Title */ { "sTitle" : $.i18n._("Title") , "mDataProp" : "track_title" , "sClass" : "library_title" , "sWidth" : "170px" }, + /* Creator */ { "sTitle" : $.i18n._("Creator") , "mDataProp" : "artist_name" , "sClass" : "library_creator" , "sWidth" : "160px" }, + /* Album */ { "sTitle" : $.i18n._("Album") , "mDataProp" : "album_title" , "sClass" : "library_album" , "sWidth" : "150px" }, + /* Bit Rate */ { "sTitle" : $.i18n._("Bit Rate") , "mDataProp" : "bit_rate" , "bVisible" : false , "sClass" : "library_bitrate" , "sWidth" : "80px" }, + /* BPM */ { "sTitle" : $.i18n._("BPM") , "mDataProp" : "bpm" , "bVisible" : false , "sClass" : "library_bpm" , "sWidth" : "50px" }, + /* Composer */ { "sTitle" : $.i18n._("Composer") , "mDataProp" : "composer" , "bVisible" : false , "sClass" : "library_composer" , "sWidth" : "150px" }, + /* Conductor */ { "sTitle" : $.i18n._("Conductor") , "mDataProp" : "conductor" , "bVisible" : false , "sClass" : "library_conductor" , "sWidth" : "125px" }, + /* Copyright */ { "sTitle" : $.i18n._("Copyright") , "mDataProp" : "copyright" , "bVisible" : false , "sClass" : "library_copyright" , "sWidth" : "125px" }, + /* Cue In */ { "sTitle" : $.i18n._("Cue In") , "mDataProp" : "cuein" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" }, + /* Cue Out */ { "sTitle" : $.i18n._("Cue Out") , "mDataProp" : "cueout" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" }, + /* Encoded */ { "sTitle" : $.i18n._("Encoded By") , "mDataProp" : "encoded_by" , "bVisible" : false , "sClass" : "library_encoded" , "sWidth" : "150px" }, + /* Genre */ { "sTitle" : $.i18n._("Genre") , "mDataProp" : "genre" , "bVisible" : false , "sClass" : "library_genre" , "sWidth" : "100px" }, + /* ISRC Number */ { "sTitle" : $.i18n._("ISRC") , "mDataProp" : "isrc_number" , "bVisible" : false , "sClass" : "library_isrc" , "sWidth" : "150px" }, + /* Label */ { "sTitle" : $.i18n._("Label") , "mDataProp" : "label" , "bVisible" : false , "sClass" : "library_label" , "sWidth" : "125px" }, + /* Language */ { "sTitle" : $.i18n._("Language") , "mDataProp" : "language" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" }, + /* Last Modified */ { "sTitle" : $.i18n._("Last Modified") , "mDataProp" : "mtime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "155px" }, + /* Last Played */ { "sTitle" : $.i18n._("Last Played") , "mDataProp" : "lptime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "155px" }, + /* Length */ { "sTitle" : $.i18n._("Length") , "mDataProp" : "length" , "sClass" : "library_length" , "sWidth" : "80px" }, + /* Mime */ { "sTitle" : $.i18n._("Mime") , "mDataProp" : "mime" , "bVisible" : false , "sClass" : "library_mime" , "sWidth" : "80px" }, + /* Mood */ { "sTitle" : $.i18n._("Mood") , "mDataProp" : "mood" , "bVisible" : false , "sClass" : "library_mood" , "sWidth" : "70px" }, + /* Owner */ { "sTitle" : $.i18n._("Owner") , "mDataProp" : "owner_id" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" }, + /* Replay Gain */ { "sTitle" : $.i18n._("Replay Gain") , "mDataProp" : "replay_gain" , "bVisible" : false , "sClass" : "library_replay_gain" , "sWidth" : "125px" }, + /* Sample Rate */ { "sTitle" : $.i18n._("Sample Rate") , "mDataProp" : "sample_rate" , "bVisible" : false , "sClass" : "library_sr" , "sWidth" : "125px" }, + /* Track Number */ { "sTitle" : $.i18n._("Track Number") , "mDataProp" : "track_number" , "bVisible" : false , "sClass" : "library_track" , "sWidth" : "125px" }, + /* Upload Time */ { "sTitle" : $.i18n._("Uploaded") , "mDataProp" : "utime" , "bVisible" : false , "sClass" : "library_upload_time" , "sWidth" : "155px" }, + /* Website */ { "sTitle" : $.i18n._("Website") , "mDataProp" : "info_url" , "bVisible" : false , "sClass" : "library_url" , "sWidth" : "150px" }, + /* Year */ { "sTitle" : $.i18n._("Year") , "mDataProp" : "year" , "bVisible" : false , "sClass" : "library_year" , "sWidth" : "60px" }, + /* Context Menu */ { "sTitle" : "" , "mData" : null , "bSortable" : false , "sClass" : "library_actions" , "bSearchable" : false , "sWidth" : "16px" } + ], + "bProcessing": true, "bServerSide": true, - - "aLengthMenu": [[5, 10, 15, 20, 25, 50, 100], [5, 10, 15, 20, 25, 50, 100]], - + + "aLengthMenu": [5, 10, 15, 20, 25, 50, 100], + "bStateSave": true, "fnStateSaveParams": function (oSettings, oData) { // remove oData components we don't want to save. @@ -533,19 +626,19 @@ var AIRTIME = (function(AIRTIME) { "fnStateSave": function (oSettings, oData) { localStorage.setItem('datatables-library', JSON.stringify(oData)); /* - $.ajax({ - url: baseUrl+"usersettings/set-library-datatable", - type: "POST", - data: {settings : oData, format: "json"}, - dataType: "json" - }); - */ + $.ajax({ + url: baseUrl+"usersettings/set-library-datatable", + type: "POST", + data: {settings : oData, format: "json"}, + dataType: "json" + }); + */ colReorderMap = oData.ColReorder; }, "fnStateLoad": function fnLibStateLoad(oSettings) { var settings = localStorage.getItem('datatables-library'); - + try { return JSON.parse(settings); } catch (e) { @@ -556,17 +649,17 @@ var AIRTIME = (function(AIRTIME) { var i, length, a = oData.abVisCols; - + if (a) { // putting serialized data back into the correct js type to make // sure everything works properly. for (i = 0, length = a.length; i < length; i++) { if (typeof(a[i]) === "string") { - a[i] = (a[i] === "true") ? true : false; - } + a[i] = (a[i] === "true"); + } } } - + a = oData.ColReorder; if (a) { for (i = 0, length = a.length; i < length; i++) { @@ -575,16 +668,16 @@ var AIRTIME = (function(AIRTIME) { } } } - + oData.iEnd = parseInt(oData.iEnd, 10); oData.iLength = parseInt(oData.iLength, 10); oData.iStart = parseInt(oData.iStart, 10); oData.iCreate = parseInt(oData.iCreate, 10); }, - + "sAjaxSource": baseUrl+"Library/contents-feed", "sAjaxDataProp": "files", - + "fnServerData": function ( sSource, aoData, fnCallback ) { /* * The real validation check is done in @@ -598,10 +691,10 @@ var AIRTIME = (function(AIRTIME) { var type; aoData.push( { name: "format", value: "json"} ); aoData.push( { name: "advSearch", value: advSearchValid} ); - + // push whether to search files/playlists or all. - type = $("#library_display_type").find("select").val(); - type = (type === undefined) ? 0 : type; + type = $(".media_type_selector.selected").attr("selection_id"); + type = (type === undefined) ? 1 : type; aoData.push( { name: "type", value: type} ); getUsabilityHint(); @@ -619,6 +712,12 @@ var AIRTIME = (function(AIRTIME) { // add checkbox $(nRow).find('td.library_checkbox').html(""); + $(nRow).find('td.library_actions') + .text("...") + .on('click', function(e) { + $(this).contextMenu({x: $(e.target).offset().left, y: $(e.target).offset().top}) + }).html("
    ...
    "); + // add audio preview image/button if (aData.ftype === "audioclip") { $(nRow).find('td.library_type').html(''); @@ -658,137 +757,40 @@ var AIRTIME = (function(AIRTIME) { } return false; }); - - alreadyclicked=false; - // call the context menu so we can prevent the event from - // propagating. - $(nRow).find('td:not(.library_checkbox, .library_type)').click(function(e){ - var el=$(this); - if (alreadyclicked) - { - alreadyclicked=false; // reset - clearTimeout(alreadyclickedTimeout); // prevent this - // from - // happening - // do what needs to happen on double click. - - $tr = $(el).parent(); - data = $tr.data("aData"); - AIRTIME.library.dblClickAdd(data, data.ftype); - } - else - { - alreadyclicked=true; - alreadyclickedTimeout=setTimeout(function(){ - alreadyclicked=false; // reset when it happens - // do what needs to happen on single click. - // use el instead of $(this) because $(this) is - // no longer the element - el.contextMenu({x: e.pageX, y: e.pageY}); - },300); // <-- dblclick tolerance here - } - return false; - }); - - /*$(nRow).find(".media-item-in-use").qtip({ - content: { - text: aData.status_msg - }, - hide: { - delay: 500, - fixed: true - }, - style: { - border: { - width: 0, - radius: 4 - }, - classes: "ui-tooltip-dark ui-tooltip-rounded" - }, - position: { - my: "left bottom", - at: "right center" - }, - });*/ - - // add a tool tip to appear when the user clicks on the type - // icon. - $(nRow).find("td:not(.library_checkbox, .library_type)").qtip({ - content: { - text: function(event, api) { - $.get(baseUrl+"library/get-file-metadata", - ({format: "html", id : aData.id, type: aData.ftype}), - function (html) { - api.set('content.text', html); - }, "html") - .fail(function (xhr, status, error) { - api.set('content.text', status + ': ' + error) - }); - return 'Loading...'; - }, - title: { - text: aData.track_title - } - }, - position: { - target: 'event', - adjust: { - resize: true, - method: "flip flip" - }, - my: 'left center', - at: 'right center', - viewport: $(window), // Keep the tooltip on-screen at - // all times - effect: false // Disable positioning animation - }, - style: { - classes: "ui-tooltip-dark file-md-long" - }, - show: 'mousedown', - events: { - show: function(event, api) { - // Only show the tooltip if it was a right-click - if(event.originalEvent.button !== 2) { - event.preventDefault(); - } - } - }, - hide: {event:'mouseout', delay: 50, fixed:true} - }); }, - // remove any selected nodes before the draw. + // remove any selected nodes before the draw. "fnPreDrawCallback": function( oSettings ) { - + // make sure any dragging helpers are removed or else they'll be // stranded on the screen. $("#draggingContainer").remove(); }, "fnDrawCallback": AIRTIME.library.fnDrawCallback, - + "aaSorting": [[5, 'asc']], "sPaginationType": "full_numbers", "bJQueryUI": true, "bAutoWidth": false, - "oLanguage": getDatatablesStrings({ - "sZeroRecords": $.i18n._("No matching records found."), - }), - + "oLanguage": getLibraryDatatableStrings(), + // R = ColReorder, C = ColVis - "sDom": 'Rl<"#library_display_type">f<"dt-process-rel"r><"H"<"library_toolbar"C>><"dataTables_scrolling"t><"F"ip>', - + "sDom": 'Rf<"dt-process-rel"r><"H"<"library_toolbar"C>><"dataTables_scrolling"t><"F"ilp>>', + "oColVis": { "sAlign": "right", - "aiExclude": [0, 1, 2], + "aiExclude": [0, 1, 2, 31], "sSize": "css", "fnStateChange": setFilterElement, - "buttonText": $.i18n._("Show / hide columns") + "buttonText": $.i18n._("Columns") }, - + "oColReorder": { + "iFixedColumnsRight": 1, "iFixedColumns": 3 - } - + }, + + "bScrollCollapse": false + }); setColumnFilter(oTable); @@ -799,9 +801,9 @@ var AIRTIME = (function(AIRTIME) { $libContent.on("click", "legend", function(){ $simpleSearch = $libContent.find("#library_display_filter label"); var $fs = $(this).parents("fieldset"), - searchHeight, - tableHeight = getTableHeight(), - height; + searchHeight, + tableHeight = getTableHeight(), + height; if ($fs.hasClass("closed")) { $fs.removeClass("closed"); @@ -814,10 +816,6 @@ var AIRTIME = (function(AIRTIME) { $(".dataTables_filter input").val("").keyup(); $simpleSearch.addClass("sp-invisible"); - - //resize the library table to avoid a double scroll bar. CC-4504 - height = tableHeight - searchHeight; - $libContent.find(".dataTables_scrolling").css("max-height", height); } else { // clear the advanced search fields @@ -833,115 +831,165 @@ var AIRTIME = (function(AIRTIME) { } }); }); - + //reset datatable with previous simple search results (if any) $(".dataTables_filter input").val(simpleSearchText).keyup(); $simpleSearch.removeClass("sp-invisible"); $fs.addClass("closed"); - - //resize the library table to avoid a double scroll bar. CC-4504 - $libContent.find(".dataTables_scrolling").css("max-height", tableHeight); } }); - - var tableHeight = getTableHeight(); - $libContent.find(".dataTables_scrolling").css("max-height", tableHeight); - - AIRTIME.library.setupLibraryToolbar(oTable); - - $("#library_display_type") - .addClass("dataTables_type") - .append(''); - } - else { - $node.empty(); - } - } - - //add the show colour to the leftmost td - if (aData.footer !== true) { - - if ($nRow.hasClass('sb-header')) { - a = 1; - } - else if ($nRow.hasClass('odd')) { - a = 0.3; - } - else if ($nRow.hasClass('even')) { - a = 0.4; - } - - //convert from hex to rgb. - r = parseInt((aData.backgroundColor).substring(0,2), 16); - g = parseInt((aData.backgroundColor).substring(2,4), 16); - b = parseInt((aData.backgroundColor).substring(4,6), 16); - - $nRow.find('td:first').css('background', 'rgba('+r+', '+g+', '+b+', '+a+')'); - } - - //save some info for reordering purposes. - $nRow.data({"aData": aData}); - - if (aData.scheduled === 1) { - $nRow.addClass(NOW_PLAYING_CLASS); - } - else if (aData.scheduled === 0 || aData.scheduled === undefined) { - $nRow.addClass("sb-past"); - } - else { - $nRow.addClass("sb-future"); - } - - if (aData.allowed !== true || aData.linked_allowed === false) { - $nRow.addClass("sb-not-allowed"); - } - else { - $nRow.addClass("sb-allowed"); - $nRow.attr("id", aData.id); - $nRow.attr("si_id", aData.instance); - } - - //status used to colour tracks. - if (aData.status === 2) { - $nRow.addClass("sb-boundry"); - } - else if (aData.status === 0) { - $nRow.addClass("sb-over"); - } - - if (aData.currentShow === true) { - $nRow.addClass("sb-current-show"); - } - }, - //remove any selected nodes before the draw. - "fnPreDrawCallback": function( oSettings ) { - - //make sure any dragging helpers are removed or else they'll be stranded on the screen. - $("#draggingContainer").remove(); - }, - "fnDrawCallback": function fnBuilderDrawCallback(oSettings, json) { - - if (!isInitialized) { - //when coming to 'Now Playing' page we want the page - //to jump to the current track - if ($(this).find("."+NOW_PLAYING_CLASS).length > 0) { - mod.jumpToCurrentTrack(); - } - } - - isInitialized = true; - var aData, - elements, - i, length, temp; - - clearTimeout(mod.timeout); - - //order of importance of elements for setting the next timeout. - elements = [ - $sbTable.find("tr."+NOW_PLAYING_CLASS), - $sbTable.find("tbody").find("tr.sb-future.sb-footer, tr.sb-future.sb-header").filter(":first") - ]; - - //check which element we should set a timeout relative to. - for (i = 0, length = elements.length; i < length; i++) { - temp = elements[i]; - - if (temp.length > 0) { - aData = temp.data("aData"); - // max time interval - // setTimeout allows only up to (2^31)-1 millisecs timeout value - maxRefreshInterval = Math.pow(2, 31) - 1; - refreshInterval = aData.refresh * 1000; - if(refreshInterval > maxRefreshInterval){ - refreshInterval = maxRefreshInterval; - } - mod.timeout = setTimeout(function() {mod.refresh(aData.id)}, refreshInterval); //need refresh in milliseconds - break; - } - } - - - mod.checkToolBarIcons(); - - var sid; - if (selectedRows !== undefined) { - selectedRows.each(function (i, el) { - sid = $(el).attr("id"); - var tr = $("#" + sid); - tr.addClass(SB_SELECTED_CLASS); - tr.find("input[type='checkbox']").prop("checked", true); - }); - } - }, - - // R = ColReorder, C = ColVis - "sDom": 'R<"dt-process-rel"r><"sb-padded"<"H"C>><"dataTables_scrolling sb-padded"t><"F">', - - "oColVis": { - "aiExclude": [ 0, 1 ], - "buttonText": $.i18n._("Columns") - }, - - "oColReorder": { - "iFixedColumns": 2 - }, - - "sAjaxDataProp": "schedule", - "oLanguage": getDatatablesStrings({ - "sZeroRecords": $.i18n._("There are no shows scheduled during the specified time period."), - "sEmptyTable": $.i18n._("There are no shows scheduled during the specified time period."), - }), - "sAjaxSource": baseUrl+"showbuilder/builder-feed", - - "bScrollCollapseY": false - }); - - $sbTable.find("tbody").on("mousedown", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty))", function(ev) { - var $tr = $(this), - // Get the ID of the selected row - $rowId = $tr.attr("id"); - - if (!$tr.hasClass(SB_SELECTED_CLASS)) { - if (ev.shiftKey && $previouslySelected !== undefined) { - if ($previouslySelected.attr("id") == $rowId) { - return; - } - - // If the selected row comes before the previously selected row, - // we want to select previous rows, otherwise we select next - if ($previouslySelected.prevAll("#" + $rowId).length !== 0) { - $previouslySelected.prevUntil($tr).each(function (i, el) { - $(el).addClass(SB_SELECTED_CLASS); - $(el).find(".sb-checkbox > input").prop('checked', true); - }); - } else { - $previouslySelected.nextUntil($tr).each(function (i, el) { - $(el).addClass(SB_SELECTED_CLASS); - $(el).find(".sb-checkbox > input").prop('checked', true); - }); - } - } - $tr.addClass(SB_SELECTED_CLASS); - $tr.find(".sb-checkbox > input").prop('checked', true); - } else { - flagForDeselection = true; - } - - selectedRows = $("." + SB_SELECTED_CLASS); - // Remember this row so we can properly multiselect - $previouslySelected = $tr; - }); - - $sbTable.find("tbody").on("click", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty))", function(ev) { - if (flagForDeselection) { - flagForDeselection = false; - $(this).removeClass(SB_SELECTED_CLASS); - $(this).find(".sb-checkbox > input").prop('checked', false); - } else { - $(this).find(".sb-checkbox > input").prop('checked', true); - } - selectedRows = $("." + SB_SELECTED_CLASS); - mod.checkToolBarIcons(); - }); - - //begin context menu initialization. - $.contextMenu({ - selector: '#show_builder tr.lib-audio:not(.sb-past)', - trigger: "right", - - build: function($el, e) { - var items, - $tr = $el, - data = $tr.data("aData"), - cursorClass = "cursor-selected-row", - callback; - - function processMenuItems(oItems) { - - //define a preview callback. - if (oItems.preview !== undefined) { - - callback = function() { - open_show_preview(data.instance, data.pos); - }; - - oItems.preview.callback = callback; - } - - //define a select cursor callback. - if (oItems.selCurs !== undefined) { - - callback = function() { - var $tr = $(this).parents('tr').next(); - - mod.selectCursor($tr); - }; - - oItems.selCurs.callback = callback; - } - - //define a remove cursor callback. - if (oItems.delCurs !== undefined) { - - callback = function() { - var $tr = $(this).parents('tr').next(); - - mod.removeCursor($tr); - }; - - oItems.delCurs.callback = callback; - } - - //define a delete callback. - if (oItems.del !== undefined) { - - callback = function() { - AIRTIME.showbuilder.fnRemove([{ - id: data.id, - timestamp: data.timestamp, - instance: data.instance - }]); - }; - - oItems.del.callback = callback; - } - - //only show the cursor selecting options if the library is visible on the page. - if ($tr.next().find('.marker').length === 0) { - delete oItems.selCurs; - delete oItems.delCurs; - } - //check to include either select or remove cursor. - else { - if ($tr.next().hasClass(cursorClass)) { - delete oItems.selCurs; - } - else { - delete oItems.delCurs; - } - } - - items = oItems; - } - - request = $.ajax({ - url: baseUrl+"showbuilder/context-menu", - type: "GET", - data: {id : data.id, format: "json"}, - dataType: "json", - async: false, - success: function(json){ - processMenuItems(json.items); - } - }); - - return { - items: items - }; - - } - }); - - var sortableConf = (function(){ - var origTrs, - aItemData = [], - oPrevData, - fnAdd, - fnMove, - fnReceive, - fnUpdate, - i, - html, - helperData, - draggingContainer; - - fnAdd = function() { - var aMediaIds = [], - aSchedIds = []; - - for(i = 0; i < aItemData.length; i++) { - aMediaIds.push({"id": aItemData[i].id, "type": aItemData[i].ftype}); - } - aSchedIds.push({"id": oPrevData.id, "instance": oPrevData.instance, "timestamp": oPrevData.timestamp}); - - mod.fnAdd(aMediaIds, aSchedIds); - }; - - 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}); - } - - aAfter.push({"id": oPrevData.id, "instance": oPrevData.instance, "timestamp": oPrevData.timestamp}); - - mod.fnMove(aSelect, aAfter); - }; - - fnReceive = function(event, ui) { - var aItems = []; - - AIRTIME.library.addToChosen(ui.item); - - aItems = AIRTIME.library.getSelectedData(); - origTrs = aItems; - html = ui.helper.html(); - - AIRTIME.library.removeFromChosen(ui.item); - }; - - fnUpdate = function(event, ui) { - var prev = ui.item.prev(); - - //can't add items outside of shows. - if (prev.find("td:first").hasClass("dataTables_empty") - || prev.length === 0) { - alert($.i18n._("Cannot schedule outside a show.")); - ui.item.remove(); - return; - } - - //if item is added after a footer, add the item after the last item in the show. - if (prev.hasClass("sb-footer")) { - prev = prev.prev(); - } - - aItemData = []; - oPrevData = prev.data("aData"); - - //item was dragged in - if (origTrs !== undefined) { - - $sbTable.find("tr.ui-draggable") - .empty() - .after(html); - - aItemData = origTrs; - origTrs = undefined; - fnAdd(); - } - //item was reordered. - else { - - //ui.item - // .empty() - // .after(draggingContainer.html()); - - aItemData.push(ui.item.data("aData")); - fnMove(); - } - }; - - return { - placeholder: "sb-placeholder ui-state-highlight", - //forcePlaceholderSize: true, - distance: 25, - helper: - function(event, item) { - var selected = mod.getSelectedData(NOW_PLAYING_CLASS), - thead = $("#show_builder_table thead"), - colspan = thead.find("th").length, - trfirst = thead.find("tr:first"), - width = trfirst.width(), - height = trfirst.height(), - message; - - //if nothing is checked select the dragged item. - if (selected.length === 0) { - selected = [item.data("aData")]; - } - - if (selected.length === 1) { - message = sprintf($.i18n._("Moving %s"), selected[0].title); - //draggingContainer = item; //Default DataTables drag and drop - draggingContainer = $('') - .addClass('sb-helper') - .append('') - .find("td") - .attr("colspan", colspan) - .width(width) - .height(height) - .addClass("ui-state-highlight") - .append(message) - .end(); - } - else { - message = sprintf($.i18n._("Moving %s Items"), selected.length); - 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-not-allowed, .sb-past, .sb-now-playing, .sb-empty)', - cancel: '.sb-footer', - receive: fnReceive, - update: fnUpdate, - axis: "y", - containment: "document", - start: function(event, ui) { - var elements = $sbTable.find('tr.'+SB_SELECTED_CLASS).not("."+NOW_PLAYING_CLASS); - elements.hide(); - }, - stop: function() { - var elements = $sbTable.find('tr.'+SB_SELECTED_CLASS).not("."+NOW_PLAYING_CLASS); - elements.show(); - } - }; - }()); - - $sbTable.sortable(sortableConf); - - //start setup of the builder toolbar. - $toolbar = $(".sb-content .fg-toolbar:first"); - var footer = $(".sb-content .fg-toolbar:last"), - timerange = $(".sb-timerange"); - $toolbar.append(timerange); - - $menu = $("
    "); - $menu.append("
    " + - "" + - "" + - "
    ") - .append("
    " + - "
    ") - .append("
    " + - "
    "); - - //if 'Add/Remove content' was chosen from the context menu - //in the Calendar do not append these buttons - if ($(".ui-dialog-content").length === 0) { - $menu.append("
    " + - "
    ") - .append("
    " + - "
    "); - } - - if (localStorage.getItem('user-type') != 'G') { - $toolbar.append($menu); - } - - $menu = undefined; - - $('#timeline-sa').click(function(){mod.selectAll();}); - $('#timeline-sn').click(function(){mod.selectNone();}); - - //cancel current show - $toolbar.find('.icon-ban-circle').parent() - .click(function() { - var $tr, - data, - msg = $.i18n._('Cancel Current Show?'); - - if (AIRTIME.button.isDisabled('icon-ban-circle', true) === true) { - return; - } - - $tr = $sbTable.find('tr.sb-future:first'); - - if ($tr.hasClass('sb-current-show')) { - data = $tr.data("aData"); - - if (data.record === true) { - msg = $.i18n._('Stop recording current show?'); - } - - if (confirm(msg)) { - var url = baseUrl+"Schedule/cancel-current-show"; - $.ajax({ - url: url, - data: {format: "json", id: data.instance}, - success: function(data){ - $("#library_content").find("#library_display").dataTable().fnStandingRedraw(); - var oTable = $sbTable.dataTable(); - oTable.fnDraw(); - } - }); - } - } - }); - - //jump to current - $toolbar.find('.icon-step-forward').parent() - .click(function() { - - if (AIRTIME.button.isDisabled('icon-step-forward', true) === true) { - return; - } - /* - var $scroll = $sbContent.find(".dataTables_scrolling"), - scrolled = $scroll.scrollTop(), - scrollingTop = $scroll.offset().top, - current = $sbTable.find("."+NOW_PLAYING_CLASS), - currentTop = current.offset().top; - - $scroll.scrollTop(currentTop - scrollingTop + scrolled); - */ - mod.jumpToCurrentTrack(); - }); - - //delete overbooked tracks. - $toolbar.find('.icon-cut', true).parent() - .click(function() { - - if (AIRTIME.button.isDisabled('icon-cut', true) === true) { - return; - } - - var temp, - aItems = [], - trs = $sbTable.find(".sb-over.sb-future.sb-allowed"); - - trs.each(function(){ - temp = $(this).data("aData"); - aItems.push({"id": temp.id, "instance": temp.instance, "timestamp": temp.timestamp}); - }); - - mod.fnRemove(aItems); - }); - - //delete selected tracks - $toolbar.find('.icon-trash').parent() - .click(function() { - - var button = $("#show_builder").find(".icon-trash").parent(); - - if (button.hasClass(DISABLED_CLASS)) { - return; - } - - mod.fnRemoveSelectedItems(); - }); - - //add events to cursors. - $sbTable.find("tbody").on("click", "div.marker", function(event) { - var $tr = $(this).parents("tr"), - $trs; - - if ($tr.hasClass(CURSOR_SELECTED_CLASS)) { - mod.removeCursor($tr); - } - else { - mod.selectCursor($tr); - } - - if (event.ctrlKey === false) { - $trs = $sbTable.find('.'+CURSOR_SELECTED_CLASS).not($tr); - mod.removeCursor($trs); - } - - return false; - }); - - /* - * Select button dropdown state in the toolbar. - * The button has to be disabled to prevent the dropdown - * from opening - */ - $sbContent.on("mouseenter", ".btn-group #timeline-select", function(ev) { - $el = $(this); - - if ($el.hasClass("ui-state-disabled")) { - $el.attr("disabled", "disabled"); - } - else { - $el.removeAttr("disabled"); - } - }); - }; - - return AIRTIME; - -}(AIRTIME || {})); diff --git a/airtime_mvc/public/js/airtime/showbuilder/_main_builder.js b/airtime_mvc/public/js/airtime/showbuilder/_main_builder.js deleted file mode 100644 index 768b24d55..000000000 --- a/airtime_mvc/public/js/airtime/showbuilder/_main_builder.js +++ /dev/null @@ -1,360 +0,0 @@ -AIRTIME = (function(AIRTIME) { - - var viewport, - $lib, - $libWrapper, - $builder, - $fs, - widgetHeight, - screenWidth, - resizeTimeout, - oBaseDatePickerSettings, - oBaseTimePickerSettings, - oRange, - dateStartId = "#sb_date_start", - timeStartId = "#sb_time_start", - dateEndId = "#sb_date_end", - timeEndId = "#sb_time_end", - mod; - - if (AIRTIME.builderMain === undefined) { - AIRTIME.builderMain = {}; - } - mod = AIRTIME.builderMain; - - oBaseDatePickerSettings = { - dateFormat: 'yy-mm-dd', - //i18n_months, i18n_days_short are in common.js - monthNames: i18n_months, - dayNamesMin: i18n_days_short, - onClick: function(sDate, oDatePicker) { - $(this).datepicker( "setDate", sDate ); - }, - onClose: validateTimeRange - }; - - oBaseTimePickerSettings = { - showPeriodLabels: false, - showCloseButton: true, - closeButtonText: $.i18n._("Done"), - showLeadingZero: false, - defaultTime: '0:00', - hourText: $.i18n._("Hour"), - minuteText: $.i18n._("Minute"), - onClose: validateTimeRange - }; - - function setWidgetSize() { - viewport = AIRTIME.utilities.findViewportDimensions(); - widgetHeight = viewport.height - 180; - screenWidth = Math.floor(viewport.width - 50); - - var libTableHeight = widgetHeight - 175, - builderTableHeight = widgetHeight - 95, - oTable; - - if ($fs.is(':visible')) { - builderTableHeight = builderTableHeight - 40; - } - - //set the heights of the main widgets. - $builder//.height(widgetHeight) - .find(".dataTables_scrolling") - //.css("max-height", builderTableHeight) - .end(); - //.width(screenWidth); - - $lib//.height(widgetHeight) - .find(".dataTables_scrolling") - //.css("max-height", libTableHeight) - .end(); - - if ($lib.filter(':visible').length > 0) { - - //$lib.width(Math.floor(screenWidth * 0.47)); - - $builder//.width(Math.floor(screenWidth * 0.47)) - .find("#sb_edit") - .remove() - .end() - .find("#sb_date_start") - .css("margin-left", 0) - .end(); - - oTable = $('#show_builder_table').dataTable(); - //oTable.fnDraw(); - } - } - - function validateTimeRange() { - var oRange, - inputs = $('.sb-timerange > input'), - start, end; - - oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId); - - start = oRange.start; - end = oRange.end; - - if (end >= start) { - inputs.removeClass('error'); - } - else { - if (!inputs.hasClass('error')) { - inputs.addClass('error'); - } - } - - return { - start: start, - end: end, - isValid: end >= start - }; - } - - function showSearchSubmit() { - var fn, - op, - oTable = $('#show_builder_table').dataTable(), - check; - - check = validateTimeRange(); - - if (check.isValid) { - - //reset timestamp value since input values could have changed. - AIRTIME.showbuilder.resetTimestamp(); - - fn = oTable.fnSettings().fnServerData; - fn.start = check.start; - fn.end = check.end; - - op = $("div.sb-advanced-options"); - if (op.is(":visible")) { - - if (fn.ops === undefined) { - fn.ops = {}; - } - fn.ops.showFilter = op.find("#sb_show_filter").val(); - fn.ops.myShows = op.find("#sb_my_shows").is(":checked") ? 1 : 0; - } - - oTable.fnDraw(); - } - } - - mod.onReady = function() { - // Normally we would just use audio/*, but it includes file types that we can't handle (like .m4a) - // We initialize the acceptedMimeTypes variable in Bootstrap so we don't have to duplicate the list - Dropzone.options.content = { - url:'/rest/media', - clickable: false, - acceptedFiles: acceptedMimeTypes.join(), - init: function () { - this.on("sending", function (file, xhr, data) { - data.append("csrf_token", $("#csrf").val()); - }); - }, - dictDefaultMessage: '', - createImageThumbnails: false, - previewTemplate : '
    ' - }; - - // define module vars. - $lib = $("#library_content"); - $builder = $("#show_builder"); - $fs = $builder.find('fieldset'); - - $("#schedule-tab").on("click", function() { - if (!$(this).hasClass('active')) { - AIRTIME.showbuilder.switchTab($("#show_builder .outer-datatable-wrapper"), $(this)); - } - }); - - /* - * Icon hover states for search. - */ - $builder.on("mouseenter", ".sb-timerange .ui-button", function(ev) { - $(this).addClass("ui-state-hover"); - }); - $builder.on("mouseleave", ".sb-timerange .ui-button", function(ev) { - $(this).removeClass("ui-state-hover"); - }); - - $builder.find(dateStartId) - .datepicker(oBaseDatePickerSettings) - .blur(validateTimeRange); - - $builder.find(timeStartId) - .timepicker(oBaseTimePickerSettings) - .blur(validateTimeRange); - - $builder.find(dateEndId) - .datepicker(oBaseDatePickerSettings) - .blur(validateTimeRange); - - $builder.find(timeEndId) - .timepicker(oBaseTimePickerSettings) - .blur(validateTimeRange); - - - oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, - dateEndId, timeEndId); - AIRTIME.showbuilder.fnServerData.start = oRange.start; - AIRTIME.showbuilder.fnServerData.end = oRange.end; - - //the user might not have the library on the page (guest user) - if (AIRTIME.library !== undefined) { - AIRTIME.library.libraryInit(); - } - - AIRTIME.showbuilder.builderDataTable(); - setWidgetSize(); - - $libWrapper = $lib.find("#library_display_wrapper"); - //$builder.find('.dataTables_scrolling').css("max-height", - // widgetHeight - 95); - - $builder.on("click", "#sb_submit", showSearchSubmit); - - $builder.on("click", "#sb_edit", function(ev) { - var schedTable = $("#show_builder_table").dataTable(); - - // reset timestamp to redraw the cursors. - AIRTIME.showbuilder.resetTimestamp(); - - $lib.show().width(Math.floor(screenWidth * 0.48)); - - $builder.width(Math.floor(screenWidth * 0.48)).find("#sb_edit") - .remove().end().find("#sb_date_start") - .css("margin-left", 0).end(); - - schedTable.fnDraw(); - - $.ajax( { - url : baseUrl+"usersettings/set-now-playing-screen-settings", - type : "POST", - data : { - settings : { - library : true - }, - format : "json" - }, - dataType : "json", - success : function() { - } - }); - }); - - $lib.on("click", "#sb_lib_close", function() { - var schedTable = $("#show_builder_table").dataTable(); - - $lib.hide(); - $builder.width(screenWidth).find(".sb-timerange").find("#sb_date_start").css("margin-left", 30) - .end().end(); - - schedTable.fnDraw(); - - $.ajax( { - url : baseUrl+"usersettings/set-now-playing-screen-settings", - type : "POST", - data : { - settings : { - library : false - }, - format : "json" - }, - dataType : "json", - success : function() { - } - }); - }); - - $builder.find('legend').click( - function(ev, item) { - - if ($fs.hasClass("closed")) { - - $fs.removeClass("closed"); - //$builder.find('.dataTables_scrolling').css( - // "max-height", widgetHeight - 150); - } else { - $fs.addClass("closed"); - - // set defaults for the options. - $fs.find('select').val(0); - $fs.find('input[type="checkbox"]').attr("checked", - false); - //$builder.find('.dataTables_scrolling').css( - // "max-height", widgetHeight - 110); - } - }); - - // set click event for all my shows checkbox. - $builder.on("click", "#sb_my_shows", function(ev) { - - if ($(this).is(':checked')) { - $(ev.delegateTarget).find('#sb_show_filter').val(0); - } - - showSearchSubmit(); - }); - - //set select event for choosing a show. - $builder.on("change", '#sb_show_filter', function(ev) { - - if ($(this).val() !== 0) { - $(ev.delegateTarget).find('#sb_my_shows') - .attr("checked", false); - } - - showSearchSubmit(); - - }); - - function checkScheduleUpdates() { - var data = {}, oTable = $('#show_builder_table').dataTable(), fn = oTable - .fnSettings().fnServerData, start = fn.start, end = fn.end; - - data["format"] = "json"; - data["start"] = start; - data["end"] = end; - data["timestamp"] = AIRTIME.showbuilder.getTimestamp(); - data["instances"] = AIRTIME.showbuilder.getShowInstances(); - - if (fn.hasOwnProperty("ops")) { - data["myShows"] = fn.ops.myShows; - data["showFilter"] = fn.ops.showFilter; - data["showInstanceFilter"] = fn.ops.showInstanceFilter; - } - - $.ajax( { - "dataType" : "json", - "type" : "GET", - "url" : baseUrl+"showbuilder/check-builder-feed", - "data" : data, - "success" : function(json) { - if (json.update === true) { - oTable.fnDraw(); - } - setTimeout(checkScheduleUpdates, 5000); - } - }); - - //check if the timeline view needs updating. - setTimeout(checkScheduleUpdates, 5000); - } - }; - - mod.onResize = function() { - - clearTimeout(resizeTimeout); - resizeTimeout = setTimeout(setWidgetSize, 100); - }; - - return AIRTIME; - -} (AIRTIME || {})); - -$(document).ready(AIRTIME.builderMain.onReady); -$(window).resize(AIRTIME.builderMain.onResize); diff --git a/airtime_mvc/public/js/airtime/showbuilder/builder.js b/airtime_mvc/public/js/airtime/showbuilder/builder.js index 8c1ff1dfe..e23a6c5f8 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/builder.js @@ -7,36 +7,38 @@ var AIRTIME = (function(AIRTIME){ $sbContent, $sbTable, $toolbar, - $ul, $lib, cursors = [], cursorIds = [], showInstanceIds = [], headerFooter = [], - DISABLED_CLASS = 'ui-state-disabled'; - + DISABLED_CLASS = 'ui-state-disabled', + selectedRows, + $previouslySelected, + flagForDeselection; + if (AIRTIME.showbuilder === undefined) { AIRTIME.showbuilder = {}; } mod = AIRTIME.showbuilder; - + function checkError(json) { if (json.error !== undefined) { alert(json.error); } } - + mod.timeout = undefined; mod.timestamp = -1; mod.showInstances = []; - + mod.resetTimestamp = function() { - + mod.timestamp = -1; }; - + mod.setTimestamp = function(timestamp) { - + mod.timestamp = timestamp; }; @@ -70,10 +72,10 @@ var AIRTIME = (function(AIRTIME){ .find(".fc-event-inner") .append(''); } - } - + }; + mod.getTimestamp = function() { - + if (mod.timestamp !== undefined) { return mod.timestamp; } @@ -81,50 +83,65 @@ var AIRTIME = (function(AIRTIME){ return -1; } }; - + mod.setShowInstances = function(showInstances) { mod.showInstances = showInstances; }; - + mod.getShowInstances = function() { return mod.showInstances; }; - + mod.refresh = function(schedId) { mod.resetTimestamp(); // once a track plays out we need to check if we can update // the is_scheduled flag in cc_files if (schedId > 0) { - $.post(baseUrl+"schedule/update-future-is-scheduled", - {"format": "json", "schedId": schedId}, function(data) { - if (data.redrawLibTable !== undefined && data.redrawLibTable) { - $("#library_content").find("#library_display").dataTable().fnStandingRedraw(); - } - }); + $.post(baseUrl+"schedule/update-future-is-scheduled", + {"format": "json", "schedId": schedId}, function(data) { + if (data.redrawLibTable !== undefined && data.redrawLibTable) { + $("#library_content").find("#library_display").dataTable().fnStandingRedraw(); + } + }); oSchedTable.fnDraw(); } }; - + + mod.switchTab = function(tab, el) { + $(".active-tab").hide().removeClass("active-tab"); + tab.addClass("active-tab").show(); + + $(".nav.nav-tabs .active").removeClass("active"); + el.addClass("active"); + + if (tab.hasClass("pl-content")) { + AIRTIME.playlist.setAsActive(); + } + AIRTIME.playlist.onResize(); + AIRTIME.library.fnRedraw(); + }; + + mod.checkSelectButton = function() { - var $selectable = $sbTable.find("tbody").find("input:checkbox"); - + var $selectable = $sbTable.find("tr"); + if ($selectable.length !== 0) { AIRTIME.button.enableButton("btn-group #timeline-select", false); - } - else { + } else { AIRTIME.button.disableButton("btn-group #timeline-select", false); } - + //need to check if the 'Select' button is disabled - if ($(".btn-group #timeline-select").is(":disabled")) { - $(".btn-group #timeline-select").removeAttr("disabled"); + var select = $(".btn-group #timeline-select"); + if (select.is(":disabled")) { + select.removeAttr("disabled"); } }; - + mod.checkTrimButton = function() { var $over = $sbTable.find(".sb-over.sb-allowed"); - + if ($over.length !== 0) { AIRTIME.button.enableButton("icon-cut", true); } @@ -132,9 +149,9 @@ var AIRTIME = (function(AIRTIME){ AIRTIME.button.disableButton("icon-cut", true); } }; - + mod.checkDeleteButton = function() { - var $selected = $sbTable.find("tbody").find("input:checkbox").filter(":checked"); + var $selected = $sbTable.find("tr."+SB_SELECTED_CLASS); var button = $("#show_builder").find(".icon-trash").parent(); if ($selected.length !== 0) { @@ -145,10 +162,10 @@ var AIRTIME = (function(AIRTIME){ button.attr('disabled', 'disabled'); } }; - + mod.checkJumpToCurrentButton = function() { var $current = $sbTable.find("."+NOW_PLAYING_CLASS); - + if ($current.length !== 0) { AIRTIME.button.enableButton("icon-step-forward", true); } @@ -156,61 +173,61 @@ var AIRTIME = (function(AIRTIME){ AIRTIME.button.disableButton("icon-step-forward", true); } }; - + mod.checkCancelButton = function() { - + var $current = $sbTable.find(".sb-current-show"), - //this user type should be refactored into a separate users module later - //when there's more time and more JS will need to know user data. + //this user type should be refactored into a separate users module later + //when there's more time and more JS will need to know user data. userType = localStorage.getItem('user-type'), canCancel = false; - + if ($current.length !== 0 && $current.hasClass("sb-allowed")) { - canCancel = true; + canCancel = true; } else if ($current.length !== 0 && (userType === 'A' || userType === 'P')) { canCancel = true; } - + if (canCancel === true) { - AIRTIME.button.enableButton("icon-ban-circle", true); + AIRTIME.button.enableButton("icon-ban-circle", true); } else { - AIRTIME.button.disableButton("icon-ban-circle", true); + AIRTIME.button.disableButton("icon-ban-circle", true); } }; - + mod.checkToolBarIcons = function() { - - //library may not be on the page. - if (AIRTIME.library !== undefined) { - AIRTIME.library.checkAddButton(); - } - + + //library may not be on the page. + if (AIRTIME.library !== undefined) { + AIRTIME.library.checkAddButton(); + } + mod.checkSelectButton(); mod.checkTrimButton(); mod.checkDeleteButton(); mod.checkJumpToCurrentButton(); mod.checkCancelButton(); }; - + mod.selectCursor = function($el) { $el.addClass(CURSOR_SELECTED_CLASS); mod.checkToolBarIcons(); }; - + mod.removeCursor = function($el) { - + $el.removeClass(CURSOR_SELECTED_CLASS); mod.checkToolBarIcons(); }; - + /* * sNot is an optional string to filter selected elements by. (ex removing the currently playing item) */ mod.getSelectedData = function(sNot) { - var $selected = $sbTable.find("tbody").find("input:checkbox").filter(":checked").parents("tr"), + var $selected = $sbTable.find("tr."+SB_SELECTED_CLASS), aData = [], i, length, $item; @@ -218,134 +235,125 @@ var AIRTIME = (function(AIRTIME){ if (sNot !== undefined) { $selected = $selected.not("."+sNot); } - + for (i = 0, length = $selected.length; i < length; i++) { $item = $($selected.get(i)); aData.push($item.data('aData')); } - + return aData.reverse(); }; - + mod.selectAll = function () { - $inputs = $sbTable.find("input:checkbox"); - - $inputs.attr("checked", true); - - $trs = $inputs.parents("tr"); - $trs.addClass(SB_SELECTED_CLASS); - + var $trs = $sbTable.find("tr.lib-audio").not(".sb-past, .sb-empty"); + $trs.addClass(SB_SELECTED_CLASS).find(".sb-checkbox > input").prop('checked', true); + mod.checkToolBarIcons(); }; - + mod.selectNone = function () { - $inputs = $sbTable.find("input:checkbox"); - - $inputs.attr("checked", false); - - $trs = $inputs.parents("tr"); - $trs.removeClass(SB_SELECTED_CLASS); - + var $trs = $sbTable.find("tr.lib-audio"); + $trs.removeClass(SB_SELECTED_CLASS).find(".sb-checkbox > input").prop('checked', false); + $previouslySelected = undefined; + selectedRows = undefined; + mod.checkToolBarIcons(); }; - + mod.disableUI = function() { - - $lib.block({ + + $lib.block({ message: "", theme: true, applyPlatformOpacityRules: false }); - - $sbContent.block({ + + $sbContent.block({ message: "", theme: true, applyPlatformOpacityRules: false }); }; - + mod.enableUI = function() { - $lib.unblock(); $sbContent.unblock(); - - //Block UI changes the postion to relative to display the messages. - $lib.css("position", "static"); - $sbContent.css("position", "static"); }; - + mod.fnItemCallback = function(json) { checkError(json); mod.getSelectedCursors(); + selectedRows = $("." + SB_SELECTED_CLASS); oSchedTable.fnDraw(); - mod.enableUI(); + //Unneccessary reload of the library pane after moving tracks in the showbuilder pane. //$("#library_content").find("#library_display").dataTable().fnStandingRedraw(); getUsabilityHint(); }; - + mod.getSelectedCursors = function() { cursorIds = []; - + /* We need to keep record of which show the cursor belongs to * in the case where more than one show is displayed in the show builder * because header and footer rows have the same id - */ + */ showInstanceIds = []; - + /* Keeps track if the row is a footer. We need to do this because * header and footer rows have the save cursorIds and showInstanceId * so both will be selected in the draw callback - */ + */ headerFooter = []; - + cursors = $(".cursor-selected-row"); for (i = 0; i < cursors.length; i++) { cursorIds.push(($(cursors.get(i)).attr("id"))); showInstanceIds.push(($(cursors.get(i)).attr("si_id"))); if ($(cursors.get(i)).hasClass("sb-footer")) { - headerFooter.push("f"); + headerFooter.push("f"); } else { - headerFooter.push("n"); + headerFooter.push("n"); } } }; - + mod.fnAdd = function(aMediaIds, aSchedIds) { + AIRTIME.library.selectNone(); mod.disableUI(); - $.post(baseUrl+"showbuilder/schedule-add", + $.post(baseUrl+"showbuilder/schedule-add", {"format": "json", "mediaIds": aMediaIds, "schedIds": aSchedIds}, mod.fnItemCallback ); }; - + mod.fnMove = function(aSelect, aAfter) { - + mod.disableUI(); - - $.post(baseUrl+"showbuilder/schedule-move", - {"format": "json", "selectedItem": aSelect, "afterItem": aAfter}, + + $.post(baseUrl+"showbuilder/schedule-move", + {"format": "json", "selectedItem": aSelect, "afterItem": aAfter}, mod.fnItemCallback ); }; - + mod.fnRemove = function(aItems) { - + mod.disableUI(); if (confirm($.i18n._("Delete selected item(s)?"))) { - $.post( baseUrl+"showbuilder/schedule-remove", - {"items": aItems, "format": "json"}, - mod.fnItemCallback - ); - }else{ - mod.enableUI(); + $.post( baseUrl+"showbuilder/schedule-remove", + {"items": aItems, "format": "json"}, + mod.fnItemCallback + ); + } else { + mod.enableUI(); } }; - + mod.fnRemoveSelectedItems = function() { var aData = mod.getSelectedData(), i, @@ -355,18 +363,18 @@ var AIRTIME = (function(AIRTIME){ for (i=0, length = aData.length; i < length; i++) { temp = aData[i]; - aItems.push({"id": temp.id, "instance": temp.instance, "timestamp": temp.timestamp}); + aItems.push({"id": temp.id, "instance": temp.instance, "timestamp": temp.timestamp}); } - + mod.fnRemove(aItems); }; - + mod.fnServerData = function fnBuilderServerData( sSource, aoData, fnCallback ) { - + aoData.push( { name: "timestamp", value: mod.getTimestamp()} ); aoData.push( { name: "instances", value: mod.getShowInstances()} ); aoData.push( { name: "format", value: "json"} ); - + if (mod.fnServerData.hasOwnProperty("start")) { aoData.push( { name: "start", value: mod.fnServerData.start} ); } @@ -378,14 +386,14 @@ var AIRTIME = (function(AIRTIME){ aoData.push( { name: "showFilter", value: mod.fnServerData.ops.showFilter} ); aoData.push( { name: "showInstanceFilter", value: mod.fnServerData.ops.showInstanceFilter} ); } - + $.ajax({ "dataType": "json", "type": "POST", "url": sSource, "data": aoData, "success": function(json) { - mod.updateCalendarStatusIcon(json) + mod.updateCalendarStatusIcon(json); mod.setTimestamp(json.timestamp); mod.setShowInstances(json.instances); mod.getSelectedCursors(); @@ -393,25 +401,23 @@ var AIRTIME = (function(AIRTIME){ } }); }; - + mod.jumpToCurrentTrack = function() { var $scroll = $sbContent.find(".dataTables_scrolling"); var scrolled = $scroll.scrollTop(); var scrollingTop = $scroll.offset().top; - var oTable = $('#show_builder_table').dataTable(); var current = $sbTable.find("."+NOW_PLAYING_CLASS); var currentTop = current.offset().top; $scroll.scrollTop(currentTop - scrollingTop + scrolled); - } + }; mod.builderDataTable = function() { $sbContent = $('#show_builder'); - $lib = $("#library_content"), + $lib = $("#library_content"); $sbTable = $sbContent.find('table'); var isInitialized = false; - var emptyNode = document.createElement('div'); var lockedPreviewIcon = document.createElement('span'); lockedPreviewIcon.setAttribute('class', 'ui-icon ui-icon-locked'); var previewIcon = document.createElement('img'); @@ -420,19 +426,19 @@ var AIRTIME = (function(AIRTIME){ oSchedTable = $sbTable.dataTable( { "aoColumns": [ - /* checkbox */ {"mDataProp": "allowed", "sTitle": "", "sWidth": "15px", "sClass": "sb-checkbox"}, - /* Type */ {"mDataProp": "image", "sTitle": "", "sClass": "library_image sb-image", "sWidth": "16px"}, - /* starts */ {"mDataProp": "starts", "sTitle": $.i18n._("Start"), "sClass": "sb-starts", "sWidth": "60px"}, - /* ends */ {"mDataProp": "ends", "sTitle": $.i18n._("End"), "sClass": "sb-ends", "sWidth": "60px"}, - /* runtime */ {"mDataProp": "runtime", "sTitle": $.i18n._("Duration"), "sClass": "library_length sb-length", "sWidth": "65px"}, - /* title */ {"mDataProp": "title", "sTitle": $.i18n._("Title"), "sClass": "sb-title"}, - /* creator */ {"mDataProp": "creator", "sTitle": $.i18n._("Creator"), "sClass": "sb-creator"}, - /* album */ {"mDataProp": "album", "sTitle": $.i18n._("Album"), "sClass": "sb-album"}, - /* cue in */ {"mDataProp": "cuein", "sTitle": $.i18n._("Cue In"), "bVisible": false, "sClass": "sb-cue-in"}, - /* cue out */ {"mDataProp": "cueout", "sTitle": $.i18n._("Cue Out"), "bVisible": false, "sClass": "sb-cue-out"}, - /* fade in */ {"mDataProp": "fadein", "sTitle": $.i18n._("Fade In"), "bVisible": false, "sClass": "sb-fade-in"}, - /* fade out */ {"mDataProp": "fadeout", "sTitle": $.i18n._("Fade Out"), "bVisible": false, "sClass": "sb-fade-out"}, - /* Mime */ {"mDataProp" : "mime", "sTitle" : $.i18n._("Mime"), "bVisible": false, "sClass": "sb-mime"} + /* checkbox */ {"mDataProp": "allowed", "sTitle": "", "sWidth": "16px", "sClass": "sb-checkbox"}, + /* Type */ {"mDataProp": "image", "sTitle": "", "sClass": "library_image sb-image", "sWidth": "16px"}, + /* starts */ {"mDataProp": "starts", "sTitle": $.i18n._("Start"), "sClass": "sb-starts", "sWidth": "60px"}, + /* ends */ {"mDataProp": "ends", "sTitle": $.i18n._("End"), "sClass": "sb-ends", "sWidth": "60px"}, + /* runtime */ {"mDataProp": "runtime", "sTitle": $.i18n._("Duration"), "sClass": "library_length sb-length", "sWidth": "65px"}, + /* title */ {"mDataProp": "title", "sTitle": $.i18n._("Title"), "sClass": "sb-title"}, + /* creator */ {"mDataProp": "creator", "sTitle": $.i18n._("Creator"), "sClass": "sb-creator"}, + /* album */ {"mDataProp": "album", "sTitle": $.i18n._("Album"), "sClass": "sb-album"}, + /* cue in */ {"mDataProp": "cuein", "sTitle": $.i18n._("Cue In"), "bVisible": false, "sClass": "sb-cue-in"}, + /* cue out */ {"mDataProp": "cueout", "sTitle": $.i18n._("Cue Out"), "bVisible": false, "sClass": "sb-cue-out"}, + /* fade in */ {"mDataProp": "fadein", "sTitle": $.i18n._("Fade In"), "bVisible": false, "sClass": "sb-fade-in"}, + /* fade out */ {"mDataProp": "fadeout", "sTitle": $.i18n._("Fade Out"), "bVisible": false, "sClass": "sb-fade-out"}, + /* Mime */ {"mDataProp" : "mime", "sTitle" : $.i18n._("Mime"), "bVisible": false, "sClass": "sb-mime"} ], "bJQueryUI": true, @@ -451,16 +457,7 @@ var AIRTIME = (function(AIRTIME){ delete oData.aoSearchCols; }, "fnStateSave": function fnStateSave(oSettings, oData) { - localStorage.setItem('datatables-timeline', JSON.stringify(oData)); - - /* - $.ajax({ - url: baseUrl+"usersettings/set-timeline-datatable", - type: "POST", - data: {settings : oData, format: "json"}, - dataType: "json" - });*/ }, "fnStateLoad": function fnBuilderStateLoad(oSettings) { var settings = localStorage.getItem('datatables-timeline'); @@ -478,20 +475,10 @@ var AIRTIME = (function(AIRTIME){ //sure everything works properly. for (i = 0, length = a.length; i < length; i++) { if (typeof(a[i]) === "string") { - a[i] = (a[i] === "true") ? true : false; + a[i] = (a[i] === "true"); } } - /* - a = oData.ColReorder; - if (a) { - for (i = 0, length = a.length; i < length; i++) { - if (typeof(a[i]) === "string") { - a[i] = parseInt(a[i], 10); - } - } - }*/ - oData.iCreate = parseInt(oData.iCreate, 10); }, @@ -502,7 +489,7 @@ var AIRTIME = (function(AIRTIME){ fnPrepareSeparatorRow, $node, cl="", - //background-color to imitate calendar color. + //background-color to imitate calendar color. r,g,b,a, $nRow = $(nRow), $image, @@ -513,7 +500,6 @@ var AIRTIME = (function(AIRTIME){ //Albert: //$(nRow.children[iNodeIndex]).replaceWith(emptyNode); - $node = $(nRow.children[iNodeIndex]); $node.html(sRowContent); @@ -599,7 +585,7 @@ var AIRTIME = (function(AIRTIME){ $node.empty(); } - sSeparatorHTML = ''+$.i18n._("Show Empty")+''; + sSeparatorHTML = ''+$.i18n._("Drag tracks here from the library")+''; cl = cl + " sb-empty odd"; fnPrepareSeparatorRow(sSeparatorHTML, cl, 1); @@ -617,7 +603,7 @@ var AIRTIME = (function(AIRTIME){ } else { - //add the play function if the file exists on disk. + //add the play function if the file exists on disk. $image = $nRow.find('td.sb-image'); $image.empty(); //check if the file exists. @@ -627,12 +613,6 @@ var AIRTIME = (function(AIRTIME){ //$image.html(''); $image.append(lockedPreviewIcon); } else { - /* - $image.html('') - .click(function() { - open_show_preview(aData.instance, aData.pos); - return false; - });*/ $image.append(previewIcon.cloneNode(false)); $image.click(function() { open_show_preview(aData.instance, aData.pos); @@ -691,7 +671,7 @@ var AIRTIME = (function(AIRTIME){ if (aData.scheduled === 1) { $nRow.addClass(NOW_PLAYING_CLASS); } - else if (aData.scheduled === 0) { + else if (aData.scheduled === 0 || aData.scheduled === undefined) { $nRow.addClass("sb-past"); } else { @@ -718,14 +698,6 @@ var AIRTIME = (function(AIRTIME){ if (aData.currentShow === true) { $nRow.addClass("sb-current-show"); } - - //call the context menu so we can prevent the event from propagating. - $nRow.find('td:gt(1)').click(function(e){ - - $(this).contextMenu({x: e.pageX, y: e.pageY}); - - return false; - }); }, //remove any selected nodes before the draw. "fnPreDrawCallback": function( oSettings ) { @@ -744,95 +716,12 @@ var AIRTIME = (function(AIRTIME){ } isInitialized = true; - var wrapperDiv, - markerDiv, - $td, - aData, + var aData, elements, - i, length, temp, - $cursorRows, - $table = $(this), - $parent = $table.parent(), - $tr, - //use this array to cache DOM heights then we can detach the table to manipulate it to increase speed. - heights = []; + i, length, temp; clearTimeout(mod.timeout); - /* - //only create the cursor arrows if the library is on the page. - if ($lib.length > 0 && $lib.filter(":visible").length > 0) { - - $cursorRows = $sbTable.find("tbody tr.sb-future.sb-allowed:not(.sb-header, .sb-empty)"); - - //need to get heights of tds while elements are still in the DOM. - for (i = 0, length = $cursorRows.length; i < length; i++) { - $td = $($cursorRows.get(i)).find("td:first"); - heights.push($td.height()); - } - - //detach the table to increase speed. - $table.detach(); - - for (i = 0, length = $cursorRows.length; i < length; i++) { - - $td = $($cursorRows.get(i)).find("td:first"); - if ($td.hasClass("dataTables_empty")) { - $parent.append($table); - return false; - } - - wrapperDiv = $("
    ", { - "class": "innerWrapper", - "css": { - "height": heights[i] - } - }); - markerDiv = $("
    ", { - "class": "marker" - }); - - $td.append(markerDiv).wrapInner(wrapperDiv); - - } - - //re-highlight selected cursors before draw took place - for (i = 0; i < cursorIds.length; i++) { - if (headerFooter[i] == "f") { - $tr = $table.find("tbody tr.sb-footer[id="+cursorIds[i]+"][si_id="+showInstanceIds[i]+"]"); - } else { - $tr = $table.find("tr[id="+cursorIds[i]+"][si_id="+showInstanceIds[i]+"]"); - } - - //If the currently playing track's cursor is selected, - //and that track is deleted, the cursor position becomes - //unavailble. We have to check the position is available - // before re-highlighting it. - // - if ($tr.find(".sb-checkbox").children().hasClass("innerWrapper")) { - mod.selectCursor($tr); - - // If the selected cursor is the footer row we need to - //explicitly select it because that row does not have - // innerWrapper class - // - } else if ($tr.hasClass("sb-footer")) { - mod.selectCursor($tr); - } - } - - //if there is only 1 cursor on the page highlight it by default. - if ($cursorRows.length === 1) { - $td = $cursorRows.find("td:first"); - if (!$td.hasClass("dataTables_empty")) { - $cursorRows.addClass("cursor-selected-row"); - } - } - - $parent.append($table); - - } - */ //order of importance of elements for setting the next timeout. elements = [ $sbTable.find("tr."+NOW_PLAYING_CLASS), @@ -846,27 +735,37 @@ var AIRTIME = (function(AIRTIME){ if (temp.length > 0) { aData = temp.data("aData"); // max time interval - // setTimeout allows only up to (2^31)-1 millisecs timeout value - maxRefreshInterval = Math.pow(2, 31) - 1; - refreshInterval = aData.refresh * 1000; - if(refreshInterval > maxRefreshInterval){ - refreshInterval = maxRefreshInterval; - } - mod.timeout = setTimeout(function() {mod.refresh(aData.id)}, refreshInterval); //need refresh in milliseconds + // setTimeout allows only up to (2^31)-1 millisecs timeout value + maxRefreshInterval = Math.pow(2, 31) - 1; + refreshInterval = aData.refresh * 1000; + if(refreshInterval > maxRefreshInterval){ + refreshInterval = maxRefreshInterval; + } + mod.timeout = setTimeout(function() {mod.refresh(aData.id)}, refreshInterval); //need refresh in milliseconds break; } } mod.checkToolBarIcons(); + + var sid; + if (selectedRows !== undefined) { + selectedRows.each(function (i, el) { + sid = $(el).attr("id"); + var tr = $("#" + sid); + tr.addClass(SB_SELECTED_CLASS); + tr.find("input[type='checkbox']").prop("checked", true); + }); + } }, // R = ColReorder, C = ColVis - "sDom": 'R<"dt-process-rel"r><"sb-padded"<"H"C>><"dataTables_scrolling sb-padded"t>', + "sDom": 'R<"dt-process-rel"r><"sb-padded"<"H"C>><"dataTables_scrolling sb-padded"t><"F">', "oColVis": { "aiExclude": [ 0, 1 ], - "buttonText": $.i18n._("Show / hide columns"), + "buttonText": $.i18n._("Columns") }, "oColReorder": { @@ -874,425 +773,114 @@ var AIRTIME = (function(AIRTIME){ }, "sAjaxDataProp": "schedule", - "oLanguage": datatables_dict, - "sAjaxSource": baseUrl+"showbuilder/builder-feed" + "oLanguage": getDatatablesStrings({ + "sZeroRecords": $.i18n._("There are no shows scheduled during the specified time period."), + "sEmptyTable": $.i18n._("There are no shows scheduled during the specified time period."), + }), + "sAjaxSource": baseUrl+"showbuilder/builder-feed", + + "bScrollCollapseY": false }); - - $sbTable.find("tbody").on("click", "input:checkbox", function(ev) { - - var $cb = $(this), - $tr = $cb.parents("tr"), - $prev; - - if ($cb.is(":checked")) { - - if (ev.shiftKey) { - $prev = $sbTable.find("tbody").find("tr."+SB_SELECTED_CLASS).eq(-1); - - $prev.nextUntil($tr) - .addClass(SB_SELECTED_CLASS) - .find("input:checkbox") - .attr("checked", true) - .end(); - } - - $tr.addClass(SB_SELECTED_CLASS); - } - else { - $tr.removeClass(SB_SELECTED_CLASS); - } - - mod.checkToolBarIcons(); - }); - - var sortableConf = (function(){ - var origTrs, - aItemData = [], - oPrevData, - fnAdd, - fnMove, - fnReceive, - fnUpdate, - i, - html, - helperData, - draggingContainer; - - fnAdd = function() { - var aMediaIds = [], - aSchedIds = []; - - for(i = 0; i < aItemData.length; i++) { - aMediaIds.push({"id": aItemData[i].id, "type": aItemData[i].ftype}); - } - aSchedIds.push({"id": oPrevData.id, "instance": oPrevData.instance, "timestamp": oPrevData.timestamp}); - - mod.fnAdd(aMediaIds, aSchedIds); - }; - - 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}); - } - - aAfter.push({"id": oPrevData.id, "instance": oPrevData.instance, "timestamp": oPrevData.timestamp}); - - mod.fnMove(aSelect, aAfter); - }; - - fnReceive = function(event, ui) { - var aItems = []; - - AIRTIME.library.addToChosen(ui.item); - - aItems = AIRTIME.library.getSelectedData(); - origTrs = aItems; - html = ui.helper.html(); - - AIRTIME.library.removeFromChosen(ui.item); - }; - - fnUpdate = function(event, ui) { - var prev = ui.item.prev(); - - //can't add items outside of shows. - if (prev.find("td:first").hasClass("dataTables_empty") - || prev.length === 0) { - alert($.i18n._("Cannot schedule outside a show.")); - ui.item.remove(); - return; - } - - //if item is added after a footer, add the item after the last item in the show. - if (prev.hasClass("sb-footer")) { - prev = prev.prev(); - } - - aItemData = []; - oPrevData = prev.data("aData"); - - //item was dragged in - if (origTrs !== undefined) { - - $sbTable.find("tr.ui-draggable") - .empty() - .after(html); - - aItemData = origTrs; - origTrs = undefined; - fnAdd(); - } - //item was reordered. - else { - - //ui.item - // .empty() - // .after(draggingContainer.html()); - - aItemData.push(ui.item.data("aData")); - fnMove(); - } - }; - - return { - placeholder: "sb-placeholder ui-state-highlight", - //forcePlaceholderSize: true, - distance: 10, - helper: - function(event, item) { - var selected = mod.getSelectedData(NOW_PLAYING_CLASS), - thead = $("#show_builder_table thead"), - colspan = thead.find("th").length, - trfirst = thead.find("tr:first"), - width = trfirst.width(), - height = trfirst.height(), - message; - - //if nothing is checked select the dragged item. - if (selected.length === 0) { - selected = [item.data("aData")]; - } - - if (selected.length === 1) { - message = sprintf($.i18n._("Moving %s"), selected[0].title); - //draggingContainer = item; //Default DataTables drag and drop - draggingContainer = $('') - .addClass('sb-helper') - .append('') - .find("td") - .attr("colspan", colspan) - .width(width) - .height(height) - .addClass("ui-state-highlight") - .append(message) - .end(); - } - else { - message = sprintf($.i18n._("Moving %s Items"), selected.length); - draggingContainer = $('') - .addClass('sb-helper') - .append('') - .find("td") - .attr("colspan", colspan) - .width(width) - .height(height) - .addClass("ui-state-highlight") - .append(message) - .end(); + $sbTable.find("tbody").on("mousedown", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty))", function(ev) { + var $tr = $(this), + // Get the ID of the selected row + $rowId = $tr.attr("id"); + + if (!$tr.hasClass(SB_SELECTED_CLASS)) { + if (ev.shiftKey && $previouslySelected !== undefined) { + if ($previouslySelected.attr("id") == $rowId) { + return; } - helperData = selected; - - return draggingContainer; - }, - items: 'tr:not(:first, :last, .sb-header, .sb-not-allowed, .sb-past, .sb-now-playing, .sb-empty)', - cancel: '.sb-footer', - receive: fnReceive, - update: fnUpdate, - start: function(event, ui) { - /* - var elements = $sbTable.find('tr input:checked').parents('tr') - .not(ui.item) - .not("."+NOW_PLAYING_CLASS); - - //remove all other items from the screen, - //don't remove ui.item or else we can not get position information when the user drops later. - elements.remove(); - */ - - var elements = $sbTable.find('tr input:checked').parents('tr').not("."+NOW_PLAYING_CLASS); - - elements.hide(); - }, - stop: function() { - var elements = $sbTable.find('tr.'+SB_SELECTED_CLASS).not("."+NOW_PLAYING_CLASS); - elements.show(); - } - }; - }()); - - $sbTable.sortable(sortableConf); - - //start setup of the builder toolbar. - $toolbar = $(".sb-content .fg-toolbar"); - - $menu = $("
    "); - $menu.append("
    " + - "" + - "" + - "
    ") - .append("
    " + - "
    ") - .append("
    " + - "
    "); - - //if 'Add/Remove content' was chosen from the context menu - //in the Calendar do not append these buttons - if ($(".ui-dialog-content").length === 0) { - $menu.append("
    " + - "
    ") - .append("
    " + - "
    "); - } - - if (localStorage.getItem('user-type') != 'G') { - $toolbar.append($menu); - } - - $menu = undefined; - - $('#timeline-sa').click(function(){mod.selectAll();}); - $('#timeline-sn').click(function(){mod.selectNone();}); - - //cancel current show - $toolbar.find('.icon-ban-circle').parent() - .click(function() { - var $tr, - data, - msg = $.i18n._('Cancel Current Show?'); - - if (AIRTIME.button.isDisabled('icon-ban-circle', true) === true) { - return; - } - - $tr = $sbTable.find('tr.sb-future:first'); - - if ($tr.hasClass('sb-current-show')) { - data = $tr.data("aData"); - - if (data.record === true) { - msg = $.i18n._('Stop recording current show?'); - } - - if (confirm(msg)) { - var url = baseUrl+"Schedule/cancel-current-show"; - $.ajax({ - url: url, - data: {format: "json", id: data.instance}, - success: function(data){ - $("#library_content").find("#library_display").dataTable().fnStandingRedraw(); - var oTable = $sbTable.dataTable(); - oTable.fnDraw(); - } + // If the selected row comes before the previously selected row, + // we want to select previous rows, otherwise we select next + if ($previouslySelected.prevAll("#" + $rowId).length !== 0) { + $previouslySelected.prevUntil($tr).each(function (i, el) { + $(el).addClass(SB_SELECTED_CLASS); + $(el).find(".sb-checkbox > input").prop('checked', true); + }); + } else { + $previouslySelected.nextUntil($tr).each(function (i, el) { + $(el).addClass(SB_SELECTED_CLASS); + $(el).find(".sb-checkbox > input").prop('checked', true); }); } - } - }); - - //jump to current - $toolbar.find('.icon-step-forward').parent() - .click(function() { - - if (AIRTIME.button.isDisabled('icon-step-forward', true) === true) { - return; } - /* - var $scroll = $sbContent.find(".dataTables_scrolling"), - scrolled = $scroll.scrollTop(), - scrollingTop = $scroll.offset().top, - current = $sbTable.find("."+NOW_PLAYING_CLASS), - currentTop = current.offset().top; - - $scroll.scrollTop(currentTop - scrollingTop + scrolled); - */ - mod.jumpToCurrentTrack(); - }); - - //delete overbooked tracks. - $toolbar.find('.icon-cut', true).parent() - .click(function() { - - if (AIRTIME.button.isDisabled('icon-cut', true) === true) { - return; - } - - var temp, - aItems = [], - trs = $sbTable.find(".sb-over.sb-future.sb-allowed"); - - trs.each(function(){ - temp = $(this).data("aData"); - aItems.push({"id": temp.id, "instance": temp.instance, "timestamp": temp.timestamp}); - }); - - mod.fnRemove(aItems); - }); - - //delete selected tracks - $toolbar.find('.icon-trash').parent() - .click(function() { + $tr.addClass(SB_SELECTED_CLASS); + $tr.find(".sb-checkbox > input").prop('checked', true); + } else { + flagForDeselection = true; + } - var button = $("#show_builder").find(".icon-trash").parent(); + selectedRows = $("." + SB_SELECTED_CLASS); + // Remember this row so we can properly multiselect + $previouslySelected = $tr; + }); - if (button.hasClass(DISABLED_CLASS)) { - return; - } - - mod.fnRemoveSelectedItems(); - }); - - //add events to cursors. - $sbTable.find("tbody").on("click", "div.marker", function(event) { - var $tr = $(this).parents("tr"), - $trs; - - if ($tr.hasClass(CURSOR_SELECTED_CLASS)) { - mod.removeCursor($tr); + $sbTable.find("tbody").on("click", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty))", function(ev) { + if (flagForDeselection) { + flagForDeselection = false; + $(this).removeClass(SB_SELECTED_CLASS); + $(this).find(".sb-checkbox > input").prop('checked', false); + } else { + $(this).find(".sb-checkbox > input").prop('checked', true); } - else { - mod.selectCursor($tr); - } - - if (event.ctrlKey === false) { - $trs = $sbTable.find('.'+CURSOR_SELECTED_CLASS).not($tr); - mod.removeCursor($trs); - } - - return false; + selectedRows = $("." + SB_SELECTED_CLASS); + mod.checkToolBarIcons(); }); - - /* - * Select button dropdown state in the toolbar. - * The button has to be disabled to prevent the dropdown - * from opening - */ - $sbContent.on("mouseenter", ".btn-group #timeline-select", function(ev) { - $el = $(this); - - if ($el.hasClass("ui-state-disabled")) { - $el.attr("disabled", "disabled"); - } - else { - $el.removeAttr("disabled"); - } - }); - - + //begin context menu initialization. $.contextMenu({ - selector: '.sb-content table tbody tr:not(.sb-empty, .sb-footer, .sb-header, .sb-record) td:not(.sb-checkbox, .sb-image)', - trigger: "left", - ignoreRightClick: true, - + selector: '#show_builder tr.lib-audio:not(.sb-past)', + trigger: "right", + build: function($el, e) { - var items, - $tr = $el.parent(), - data = $tr.data("aData"), + var items, + $tr = $el, + data = $tr.data("aData"), cursorClass = "cursor-selected-row", callback; function processMenuItems(oItems) { - + //define a preview callback. if (oItems.preview !== undefined) { - + callback = function() { open_show_preview(data.instance, data.pos); }; - + oItems.preview.callback = callback; } - + //define a select cursor callback. if (oItems.selCurs !== undefined) { - + callback = function() { var $tr = $(this).parents('tr').next(); - + mod.selectCursor($tr); }; - + oItems.selCurs.callback = callback; } - - //define a remove cursor callback. + + //define a remove cursor callback. if (oItems.delCurs !== undefined) { - + callback = function() { var $tr = $(this).parents('tr').next(); - + mod.removeCursor($tr); }; - + oItems.delCurs.callback = callback; } - + //define a delete callback. if (oItems.del !== undefined) { - + callback = function() { AIRTIME.showbuilder.fnRemove([{ id: data.id, @@ -1300,10 +888,10 @@ var AIRTIME = (function(AIRTIME){ instance: data.instance }]); }; - + oItems.del.callback = callback; } - + //only show the cursor selecting options if the library is visible on the page. if ($tr.next().find('.marker').length === 0) { delete oItems.selCurs; @@ -1317,30 +905,366 @@ var AIRTIME = (function(AIRTIME){ else { delete oItems.delCurs; } - } - + } + items = oItems; } - + request = $.ajax({ - url: baseUrl+"showbuilder/context-menu", - type: "GET", - data: {id : data.id, format: "json"}, - dataType: "json", - async: false, - success: function(json){ - processMenuItems(json.items); - } + url: baseUrl+"showbuilder/context-menu", + type: "GET", + data: {id : data.id, format: "json"}, + dataType: "json", + async: false, + success: function(json){ + processMenuItems(json.items); + } }); return { items: items }; - + + } + }); + + var sortableConf = (function(){ + var origTrs, + aItemData = [], + oPrevData, + fnAdd, + fnMove, + fnReceive, + fnUpdate, + i, + html, + helperData, + draggingContainer; + + fnAdd = function() { + var aMediaIds = [], + aSchedIds = []; + + for(i = 0; i < aItemData.length; i++) { + aMediaIds.push({"id": aItemData[i].id, "type": aItemData[i].ftype}); + } + aSchedIds.push({"id": oPrevData.id, "instance": oPrevData.instance, "timestamp": oPrevData.timestamp}); + + mod.fnAdd(aMediaIds, aSchedIds); + }; + + 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}); + } + + aAfter.push({"id": oPrevData.id, "instance": oPrevData.instance, "timestamp": oPrevData.timestamp}); + + mod.fnMove(aSelect, aAfter); + }; + + fnReceive = function(event, ui) { + var aItems = []; + + AIRTIME.library.addToChosen(ui.item); + + aItems = AIRTIME.library.getSelectedData(); + origTrs = aItems; + html = ui.helper.html(); + + AIRTIME.library.removeFromChosen(ui.item); + }; + + fnUpdate = function(event, ui) { + var prev = ui.item.prev(); + + //can't add items outside of shows. + if (prev.find("td:first").hasClass("dataTables_empty") + || prev.length === 0) { + alert($.i18n._("Cannot schedule outside a show.")); + ui.item.remove(); + return; + } + + //if item is added after a footer, add the item after the last item in the show. + if (prev.hasClass("sb-footer")) { + prev = prev.prev(); + } + + aItemData = []; + oPrevData = prev.data("aData"); + + //item was dragged in + if (origTrs !== undefined) { + + $sbTable.find("tr.ui-draggable") + .empty() + .after(html); + + aItemData = origTrs; + origTrs = undefined; + fnAdd(); + } + //item was reordered. + else { + + //ui.item + // .empty() + // .after(draggingContainer.html()); + + aItemData.push(ui.item.data("aData")); + fnMove(); + } + }; + + return { + placeholder: "sb-placeholder ui-state-highlight", + //forcePlaceholderSize: true, + distance: 25, + helper: + function(event, item) { + var selected = mod.getSelectedData(NOW_PLAYING_CLASS), + thead = $("#show_builder_table thead"), + colspan = thead.find("th").length, + trfirst = thead.find("tr:first"), + width = trfirst.width(), + height = trfirst.height(), + message; + + //if nothing is checked select the dragged item. + if (selected.length === 0) { + selected = [item.data("aData")]; + } + + if (selected.length === 1) { + message = sprintf($.i18n._("Moving %s"), selected[0].title); + //draggingContainer = item; //Default DataTables drag and drop + draggingContainer = $('') + .addClass('sb-helper') + .append('') + .find("td") + .attr("colspan", colspan) + .width(width) + .height(height) + .addClass("ui-state-highlight") + .append(message) + .end(); + } + else { + message = sprintf($.i18n._("Moving %s Items"), selected.length); + 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-not-allowed, .sb-past, .sb-now-playing, .sb-empty)', + cancel: '.sb-footer', + receive: fnReceive, + update: fnUpdate, + axis: "y", + containment: "document", + start: function(event, ui) { + var elements = $sbTable.find('tr.'+SB_SELECTED_CLASS).not("."+NOW_PLAYING_CLASS); + elements.hide(); + }, + stop: function() { + var elements = $sbTable.find('tr.'+SB_SELECTED_CLASS).not("."+NOW_PLAYING_CLASS); + elements.show(); + } + }; + }()); + + $sbTable.sortable(sortableConf); + + //start setup of the builder toolbar. + $toolbar = $(".sb-content .fg-toolbar:first"); + var footer = $(".sb-content .fg-toolbar:last"), + timerange = $(".sb-timerange"); + $toolbar.append(timerange); + + $menu = $("
    "); + $menu.append("
    " + + "" + + "" + + "
    ") + .append("
    " + + "
    ") + .append("
    " + + "
    "); + + //if 'Add/Remove content' was chosen from the context menu + //in the Calendar do not append these buttons + if ($(".ui-dialog-content").length === 0) { + $menu.append("
    " + + "
    ") + .append("
    " + + "
    "); + } + + if (localStorage.getItem('user-type') != 'G') { + $toolbar.append($menu); + } + + $menu = undefined; + + $('#timeline-sa').click(function(){mod.selectAll();}); + $('#timeline-sn').click(function(){mod.selectNone();}); + + //cancel current show + $toolbar.find('.icon-ban-circle').parent() + .click(function() { + var $tr, + data, + msg = $.i18n._('Cancel Current Show?'); + + if (AIRTIME.button.isDisabled('icon-ban-circle', true) === true) { + return; + } + + $tr = $sbTable.find('tr.sb-future:first'); + + if ($tr.hasClass('sb-current-show')) { + data = $tr.data("aData"); + + if (data.record === true) { + msg = $.i18n._('Stop recording current show?'); + } + + if (confirm(msg)) { + var url = baseUrl+"Schedule/cancel-current-show"; + $.ajax({ + url: url, + data: {format: "json", id: data.instance}, + success: function(data){ + $("#library_content").find("#library_display").dataTable().fnStandingRedraw(); + var oTable = $sbTable.dataTable(); + oTable.fnDraw(); + } + }); + } + } + }); + + //jump to current + $toolbar.find('.icon-step-forward').parent() + .click(function() { + + if (AIRTIME.button.isDisabled('icon-step-forward', true) === true) { + return; + } + /* + var $scroll = $sbContent.find(".dataTables_scrolling"), + scrolled = $scroll.scrollTop(), + scrollingTop = $scroll.offset().top, + current = $sbTable.find("."+NOW_PLAYING_CLASS), + currentTop = current.offset().top; + + $scroll.scrollTop(currentTop - scrollingTop + scrolled); + */ + mod.jumpToCurrentTrack(); + }); + + //delete overbooked tracks. + $toolbar.find('.icon-cut', true).parent() + .click(function() { + + if (AIRTIME.button.isDisabled('icon-cut', true) === true) { + return; + } + + var temp, + aItems = [], + trs = $sbTable.find(".sb-over.sb-future.sb-allowed"); + + trs.each(function(){ + temp = $(this).data("aData"); + aItems.push({"id": temp.id, "instance": temp.instance, "timestamp": temp.timestamp}); + }); + + mod.fnRemove(aItems); + }); + + //delete selected tracks + $toolbar.find('.icon-trash').parent() + .click(function() { + + var button = $("#show_builder").find(".icon-trash").parent(); + + if (button.hasClass(DISABLED_CLASS)) { + return; + } + + mod.fnRemoveSelectedItems(); + }); + + //add events to cursors. + $sbTable.find("tbody").on("click", "div.marker", function(event) { + var $tr = $(this).parents("tr"), + $trs; + + if ($tr.hasClass(CURSOR_SELECTED_CLASS)) { + mod.removeCursor($tr); + } + else { + mod.selectCursor($tr); + } + + if (event.ctrlKey === false) { + $trs = $sbTable.find('.'+CURSOR_SELECTED_CLASS).not($tr); + mod.removeCursor($trs); + } + + return false; + }); + + /* + * Select button dropdown state in the toolbar. + * The button has to be disabled to prevent the dropdown + * from opening + */ + $sbContent.on("mouseenter", ".btn-group #timeline-select", function(ev) { + $el = $(this); + + if ($el.hasClass("ui-state-disabled")) { + $el.attr("disabled", "disabled"); + } + else { + $el.removeAttr("disabled"); } }); }; - + return AIRTIME; - + }(AIRTIME || {})); diff --git a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js index ee23aa6f1..768b24d55 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js @@ -15,12 +15,6 @@ AIRTIME = (function(AIRTIME) { timeStartId = "#sb_time_start", dateEndId = "#sb_date_end", timeEndId = "#sb_time_end", - $toggleLib = $(""+$.i18n._("Add / Remove Content")+""), - $libClose = $('', { - "class": "close-round", - "href": "#", - "id": "sb_lib_close" - }), mod; if (AIRTIME.builderMain === undefined) { @@ -64,22 +58,22 @@ AIRTIME = (function(AIRTIME) { } //set the heights of the main widgets. - $builder.height(widgetHeight) + $builder//.height(widgetHeight) .find(".dataTables_scrolling") - .css("max-height", builderTableHeight) - .end() - .width(screenWidth); + //.css("max-height", builderTableHeight) + .end(); + //.width(screenWidth); - $lib.height(widgetHeight) + $lib//.height(widgetHeight) .find(".dataTables_scrolling") - .css("max-height", libTableHeight) + //.css("max-height", libTableHeight) .end(); if ($lib.filter(':visible').length > 0) { - $lib.width(Math.floor(screenWidth * 0.47)); + //$lib.width(Math.floor(screenWidth * 0.47)); - $builder.width(Math.floor(screenWidth * 0.47)) + $builder//.width(Math.floor(screenWidth * 0.47)) .find("#sb_edit") .remove() .end() @@ -150,11 +144,33 @@ AIRTIME = (function(AIRTIME) { } mod.onReady = function() { + // Normally we would just use audio/*, but it includes file types that we can't handle (like .m4a) + // We initialize the acceptedMimeTypes variable in Bootstrap so we don't have to duplicate the list + Dropzone.options.content = { + url:'/rest/media', + clickable: false, + acceptedFiles: acceptedMimeTypes.join(), + init: function () { + this.on("sending", function (file, xhr, data) { + data.append("csrf_token", $("#csrf").val()); + }); + }, + dictDefaultMessage: '', + createImageThumbnails: false, + previewTemplate : '
    ' + }; + // define module vars. $lib = $("#library_content"); $builder = $("#show_builder"); $fs = $builder.find('fieldset'); + $("#schedule-tab").on("click", function() { + if (!$(this).hasClass('active')) { + AIRTIME.showbuilder.switchTab($("#show_builder .outer-datatable-wrapper"), $(this)); + } + }); + /* * Icon hover states for search. */ @@ -196,10 +212,8 @@ AIRTIME = (function(AIRTIME) { setWidgetSize(); $libWrapper = $lib.find("#library_display_wrapper"); - $libWrapper.prepend($libClose); - - $builder.find('.dataTables_scrolling').css("max-height", - widgetHeight - 95); + //$builder.find('.dataTables_scrolling').css("max-height", + // widgetHeight - 95); $builder.on("click", "#sb_submit", showSearchSubmit); @@ -236,11 +250,9 @@ AIRTIME = (function(AIRTIME) { var schedTable = $("#show_builder_table").dataTable(); $lib.hide(); - $builder.width(screenWidth).find(".sb-timerange").prepend( - $toggleLib).find("#sb_date_start").css("margin-left", 30) + $builder.width(screenWidth).find(".sb-timerange").find("#sb_date_start").css("margin-left", 30) .end().end(); - $toggleLib.removeClass("ui-state-hover"); schedTable.fnDraw(); $.ajax( { @@ -264,8 +276,8 @@ AIRTIME = (function(AIRTIME) { if ($fs.hasClass("closed")) { $fs.removeClass("closed"); - $builder.find('.dataTables_scrolling').css( - "max-height", widgetHeight - 150); + //$builder.find('.dataTables_scrolling').css( + // "max-height", widgetHeight - 150); } else { $fs.addClass("closed"); @@ -273,8 +285,8 @@ AIRTIME = (function(AIRTIME) { $fs.find('select').val(0); $fs.find('input[type="checkbox"]').attr("checked", false); - $builder.find('.dataTables_scrolling').css( - "max-height", widgetHeight - 110); + //$builder.find('.dataTables_scrolling').css( + // "max-height", widgetHeight - 110); } });