From b04b7ff01043e7a73ec2315d67a2eb577ff459dd Mon Sep 17 00:00:00 2001 From: James Date: Thu, 10 Nov 2011 15:35:27 -0500 Subject: [PATCH] CC-2848: Misc bugs from demo service - Handling concurrency issue playlist section and show(canlendar) section --- .../controllers/PlaylistController.php | 90 ++++++++++---- .../controllers/ScheduleController.php | 115 +++++++++++++++--- airtime_mvc/application/models/Show.php | 12 +- airtime_mvc/application/models/Subjects.php | 1 - airtime_mvc/public/js/airtime/library/spl.js | 71 +++++++++-- .../public/js/airtime/schedule/add-show.js | 14 ++- .../schedule/full-calendar-functions.js | 21 +++- .../public/js/airtime/schedule/schedule.js | 42 +++++-- .../public/js/contextmenu/AirtimeChanges | 13 ++ airtime_mvc/public/js/contextmenu/jjmenu.js | 10 ++ 10 files changed, 317 insertions(+), 72 deletions(-) create mode 100644 airtime_mvc/public/js/contextmenu/AirtimeChanges diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index f6ca476ba..9eed5f2df 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -36,9 +36,11 @@ class PlaylistController extends Zend_Controller_Action $pl = Application_Model_Playlist::Recall($pl_sess->id); if($pl === FALSE) { unset($pl_sess->id); - return; + return false; } return $pl; + }else{ + return false; } } @@ -84,7 +86,10 @@ class PlaylistController extends Zend_Controller_Action $this->view->headLink()->appendStylesheet($baseUrl.'/css/playlist_builder.css'); $this->_helper->viewRenderer->setResponseSegment('spl'); - $this->view->pl = $this->getPlaylist(); + $pl = $this->getPlaylist(); + if($pl !== false){ + $this->view->pl = $pl; + } } public function newAction() @@ -113,6 +118,10 @@ class PlaylistController extends Zend_Controller_Action $this->changePlaylist($pl_id); $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } $title = $pl->getPLMetaData("dc:title"); $desc = $pl->getPLMetaData("dc:description"); @@ -125,6 +134,10 @@ class PlaylistController extends Zend_Controller_Action $description = $this->_getParam('description', null); $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } if($title) $pl->setName($title); @@ -152,6 +165,10 @@ class PlaylistController extends Zend_Controller_Action } $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } $this->view->pl = $pl; $this->view->pl_id = $pl->getId(); @@ -167,6 +184,10 @@ class PlaylistController extends Zend_Controller_Action if (!is_null($id)) { $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } $res = $pl->addAudioClip($id, $pos); if (PEAR::isError($res)) { @@ -191,6 +212,10 @@ class PlaylistController extends Zend_Controller_Action $newPos = $this->_getParam('newPos'); $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } $pl->moveAudioClip($oldPos, $newPos); @@ -215,6 +240,10 @@ class PlaylistController extends Zend_Controller_Action $positions = array_reverse($positions); $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } foreach ($positions as $pos) { $pl->delAudioClip($pos); @@ -236,6 +265,10 @@ class PlaylistController extends Zend_Controller_Action $request = $this->getRequest(); $pos = $this->_getParam('pos'); $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } if($request->isPost()) { $cueIn = $this->_getParam('cueIn', null); @@ -261,6 +294,10 @@ class PlaylistController extends Zend_Controller_Action $request = $this->getRequest(); $pos = $this->_getParam('pos'); $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } if($request->isPost()) { $fadeIn = $this->_getParam('fadeIn', null); @@ -296,7 +333,10 @@ class PlaylistController extends Zend_Controller_Action if($pl_sess->id === $id){ unset($pl_sess->id); } - } + }else{ + $this->view->playlist_error = true; + return false; + } $this->view->id = $id; $this->view->html = $this->view->render('playlist/index.phtml'); @@ -305,6 +345,10 @@ class PlaylistController extends Zend_Controller_Action public function deleteActiveAction() { $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } Application_Model_Playlist::Delete($pl->getId()); $pl_sess = $this->pl_sess; @@ -316,6 +360,10 @@ class PlaylistController extends Zend_Controller_Action public function closeAction() { $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } $this->closePlaylist($pl); $this->view->html = $this->view->render('playlist/index.phtml'); @@ -325,6 +373,10 @@ class PlaylistController extends Zend_Controller_Action { $request = $this->getRequest(); $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } if($request->isPost()) { $fadeIn = $this->_getParam('fadeIn', null); @@ -351,6 +403,10 @@ class PlaylistController extends Zend_Controller_Action $name = $this->_getParam('name', 'Unknown Playlist'); $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } $pl->setName($name); $this->view->playlistName = $name; @@ -360,6 +416,10 @@ class PlaylistController extends Zend_Controller_Action { $description = $this->_getParam('description', false); $pl = $this->getPlaylist(); + if($pl === false){ + $this->view->playlist_error = true; + return false; + } if($description != false) { $pl->setDescription($description); @@ -374,27 +434,3 @@ class PlaylistController extends Zend_Controller_Action } - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index cc4acd49e..329264855 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -91,7 +91,12 @@ class ScheduleController extends Zend_Controller_Action $user = new Application_Model_User($userInfo->id); if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { - $showInstance = new Application_Model_ShowInstance($showInstanceId); + try{ + $showInstance = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } $error = $showInstance->moveShow($deltaDay, $deltaMin); } @@ -110,7 +115,12 @@ class ScheduleController extends Zend_Controller_Action $user = new Application_Model_User($userInfo->id); if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { - $show = new Application_Model_ShowInstance($showInstanceId); + try{ + $show = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } $error = $show->resizeShow($deltaDay, $deltaMin); } @@ -126,7 +136,13 @@ class ScheduleController extends Zend_Controller_Action $user = new Application_Model_User($userInfo->id); if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { - $show = new Application_Model_ShowInstance($showInstanceId); + try{ + $show = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } + $show->deleteShow(); } } @@ -135,7 +151,12 @@ class ScheduleController extends Zend_Controller_Action { global $CC_CONFIG; $show_instance = $this->_getParam('id'); - $show_inst = new Application_Model_ShowInstance($show_instance); + try{ + $show_inst = new Application_Model_ShowInstance($show_instance); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } $file = $show_inst->getRecordedFile(); $id = $file->getId(); @@ -151,13 +172,21 @@ class ScheduleController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $show = new Application_Model_ShowInstance($id); + try{ + $show = new Application_Model_ShowInstance($id); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } + $params = '/format/json/id/#id#'; $showStartDateHelper = Application_Model_DateHelper::ConvertToLocalDateTime($show->getShowStart()); $showEndDateHelper = Application_Model_DateHelper::ConvertToLocalDateTime($show->getShowEnd()); - + + $menu = array(); + if ($epochNow < $showStartDateHelper->getTimestamp()) { if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId()) && !$show->isRecorded() && !$show->isRebroadcast()) { @@ -228,7 +257,12 @@ class ScheduleController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $show = new Application_Model_ShowInstance($showInstanceId); + try{ + $show = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId())) { $show->scheduleShow(array($plId)); @@ -247,7 +281,12 @@ class ScheduleController extends Zend_Controller_Action $showInstanceId = $this->_getParam('id'); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $show = new Application_Model_ShowInstance($showInstanceId); + try{ + $show = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId())) $show->clearShow(); @@ -261,8 +300,13 @@ class ScheduleController extends Zend_Controller_Action public function findPlaylistsAction() { $post = $this->getRequest()->getPost(); - - $show = new Application_Model_ShowInstance($this->sched_sess->showInstanceId); + try{ + $show = new Application_Model_ShowInstance($this->sched_sess->showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } + $playlists = $show->searchPlaylistsForShow($post); foreach( $playlists['aaData'] as &$data){ // calling two functions to format time to 1 decimal place @@ -282,7 +326,12 @@ class ScheduleController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - $show = new Application_Model_ShowInstance($showInstanceId); + try{ + $show = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId())) { $show->removeGroupFromShow($group_id); @@ -300,7 +349,12 @@ class ScheduleController extends Zend_Controller_Action $showInstanceId = $this->_getParam('id'); $this->sched_sess->showInstanceId = $showInstanceId; - $show = new Application_Model_ShowInstance($showInstanceId); + try{ + $show = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } $start_timestamp = $show->getShowStart(); $end_timestamp = $show->getShowEnd(); @@ -336,11 +390,21 @@ class ScheduleController extends Zend_Controller_Action public function showContentDialogAction() { $showInstanceId = $this->_getParam('id'); - $show = new Application_Model_ShowInstance($showInstanceId); + try{ + $show = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } $originalShowId = $show->isRebroadcast(); if (!is_null($originalShowId)){ - $originalShow = new Application_Model_ShowInstance($originalShowId); + try{ + $originalShow = new Application_Model_ShowInstance($originalShowId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } $originalShowName = $originalShow->getName(); $originalShowStart = $originalShow->getShowStart(); @@ -365,6 +429,12 @@ class ScheduleController extends Zend_Controller_Action $isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true; $showInstanceId = $this->_getParam('id'); + try{ + $showInstance = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } $formWhat = new Application_Form_AddShowWhat(); $formWho = new Application_Form_AddShowWho(); @@ -385,7 +455,6 @@ class ScheduleController extends Zend_Controller_Action $this->view->style = $formStyle; $this->view->addNewShow = false; - $showInstance = new Application_Model_ShowInstance($showInstanceId); $show = new Application_Model_Show($showInstance->getShowId()); $formWhat->populate(array('add_show_id' => $show->getId(), @@ -494,7 +563,7 @@ class ScheduleController extends Zend_Controller_Action foreach($js as $j){ $data[$j["name"]] = $j["value"]; } - + Logging::log("id:".$data['add_show_id']); $show = new Application_Model_Show($data['add_show_id']); $startDateModified = true; @@ -681,7 +750,12 @@ class ScheduleController extends Zend_Controller_Action if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { $showInstanceId = $this->_getParam('id'); - $showInstance = new Application_Model_ShowInstance($showInstanceId); + try{ + $showInstance = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } $show = new Application_Model_Show($showInstance->getShowId()); $show->cancelShow($showInstance->getShowStart()); @@ -695,7 +769,12 @@ class ScheduleController extends Zend_Controller_Action if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { $showInstanceId = $this->_getParam('id'); - $show = new Application_Model_ShowInstance($showInstanceId); + try{ + $show = new Application_Model_ShowInstance($showInstanceId); + }catch(Exception $e){ + $this->view->show_error = true; + return false; + } $show->clearShow(); $show->deleteShow(); // send 'cancel-current-show' command to pypo diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 7b7046f6e..17bd2a028 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -119,6 +119,17 @@ class Application_Model_Show { WHERE starts >= '{$day_timestamp}' AND show_id = {$this->_showId}"; $CC_DBC->query($sql); + + // check if we can safely delete the show + $showInstancesRow = CcShowInstancesQuery::create() + ->filterByDbShowId($this->_showId) + ->findOne(); + + if(is_null($showInstancesRow)){ + $sql = "DELETE FROM cc_show WHERE id = {$this->_showId}"; + $CC_DBC->query($sql); + } + Application_Model_RabbitMq::PushSchedule(); } @@ -1002,7 +1013,6 @@ class Application_Model_Show { } $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}"; - Logging::log($sql); $rebroadcasts = $CC_DBC->GetAll($sql); self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $utcStartDateTime, $duration); diff --git a/airtime_mvc/application/models/Subjects.php b/airtime_mvc/application/models/Subjects.php index 7b2b15cd6..59eeefff1 100644 --- a/airtime_mvc/application/models/Subjects.php +++ b/airtime_mvc/application/models/Subjects.php @@ -144,7 +144,6 @@ class Application_Model_Subjects { global $CC_CONFIG, $CC_DBC; $sql = "SELECT login_attempts FROM ".$CC_CONFIG['subjTable']." WHERE login='$login'"; $res = $CC_DBC->getOne($sql); - Logging::log($res); if (PEAR::isError($res)) { return $res; } diff --git a/airtime_mvc/public/js/airtime/library/spl.js b/airtime_mvc/public/js/airtime/library/spl.js index d05321740..cbb6d24cc 100644 --- a/airtime_mvc/public/js/airtime/library/spl.js +++ b/airtime_mvc/public/js/airtime/library/spl.js @@ -52,7 +52,9 @@ function changeCueIn(event) { } $.post(url, {format: "json", cueIn: cueIn, pos: pos}, function(json){ - + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } if(json.response.error) { showError(span, json.response.error); return; @@ -79,7 +81,9 @@ function changeCueOut(event) { } $.post(url, {format: "json", cueOut: cueOut, pos: pos}, function(json){ - + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } if(json.response.error) { showError(span, json.response.error); return; @@ -106,6 +110,9 @@ function changeFadeIn(event) { } $.post(url, {format: "json", fadeIn: fadeIn, pos: pos}, function(json){ + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } if(json.response.error) { return; } @@ -130,6 +137,9 @@ function changeFadeOut(event) { } $.post(url, {format: "json", fadeOut: fadeOut, pos: pos}, function(json){ + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } if(json.response.error) { return; } @@ -192,7 +202,9 @@ function openFadeEditor(event) { highlightActive(this); $.get(url, {format: "json", pos: pos}, function(json){ - + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } $("#crossfade_"+(pos)+"-"+(pos+1)) .empty() .append(json.html) @@ -228,7 +240,9 @@ function openCueEditor(event) { highlightActive(li); $.get(url, {format: "json", pos: pos}, function(json){ - + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } $("#cues_"+pos) .empty() .append(json.html) @@ -245,7 +259,10 @@ function redrawDataTablePage() { } function setSPLContent(json) { - + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } + if(json.message) { alert(json.message); return; @@ -329,6 +346,9 @@ function moveSPLItem(event, ui) { } function noOpenPL(json) { + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } $("#side_playlist") .empty() .append(json.html); @@ -364,6 +384,9 @@ function createPlaylistMetaForm(json) { data = $("#side_playlist form").serialize(); $.post(url, data, function(json){ + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } openDiffSPL(json); //redraw the library list redrawDataTablePage(); @@ -398,6 +421,9 @@ function deleteSPL() { url = '/Playlist/delete-active/format/json'; $.post(url, function(json){ + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } noOpenPL(json); //redraw the library list redrawDataTablePage(); @@ -405,7 +431,9 @@ function deleteSPL() { } function openDiffSPL(json) { - + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } $("#side_playlist") .empty() .append(json.html); @@ -428,6 +456,9 @@ function editName() { url = '/Playlist/set-playlist-name'; $.post(url, {format: "json", name: input.val()}, function(json){ + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } input.addClass('element_hidden'); nameElement.text(json.playlistName); redrawDataTablePage(); @@ -460,6 +491,9 @@ function setUpSPL() { var url = '/Playlist/set-playlist-fades'; $.get(url, {format: "json"}, function(json){ + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } $("#spl_fade_in_main").find("span") .empty() .append(json.fadeIn); @@ -491,7 +525,11 @@ function setUpSPL() { url = '/Playlist/set-playlist-description'; $.post(url, {format: "json", description: description}, function(json){ - textarea.val(json.playlistDescription); + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + }else{ + textarea.val(json.playlistDescription); + } }); }); @@ -501,7 +539,11 @@ function setUpSPL() { url = '/Playlist/set-playlist-description'; $.post(url, {format: "json"}, function(json){ - textarea.val(json.playlistDescription); + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + }else{ + textarea.val(json.playlistDescription); + } }); }); @@ -520,6 +562,9 @@ function setUpSPL() { } $.post(url, {format: "json", fadeIn: fadeIn}, function(json){ + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } if(json.response.error) { return; } @@ -543,6 +588,9 @@ function setUpSPL() { } $.post(url, {format: "json", fadeOut: fadeOut}, function(json){ + if(json.playlist_error == true){ + alertPlaylistErrorAndReload(); + } if(json.response.error) { return; } @@ -571,6 +619,13 @@ function setUpSPL() { $("#spl_sortable" ).bind( "drop", addSPLItem); } +// Alert the error and reload the page +// this function is used to resolve concurrency issue +function alertPlaylistErrorAndReload(){ + alert("The Playlist doesn't exist anymore!"); + window.location.reload(); +} + $(document).ready(function() { var currentlyOpenedSplId; setUpSPL(); diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index b20ba44d7..09e6a997e 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -60,6 +60,10 @@ function findHosts(request, callback) { } function beginEditShow(data){ + if(data.show_error == true){ + alertShowErrorAndReload(); + return false; + } $("#add-show-form") .empty() .append(data.newForm); @@ -310,7 +314,7 @@ function setAddShowEvents() { .append(json.newForm); setAddShowEvents(); - scheduleRefetchEvents(); + scheduleRefetchEvents(json); } }); }); @@ -432,6 +436,14 @@ $(document).ready(function() { //setAddShowEvents(); }); +//Alert the error and reload the page +//this function is used to resolve concurrency issue +function alertShowErrorAndReload(){ + alert("The show instance doesn't exist anymore!"); + window.location.reload(); +} + + $(window).resize(function(){ var windowWidth = $(this).width(); // margin on showform are 16 px on each side diff --git a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js index c77f435bc..5a5627eee 100644 --- a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js +++ b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js @@ -4,7 +4,10 @@ * */ -function scheduleRefetchEvents() { +function scheduleRefetchEvents(json) { + if(json.show_error == true){ + alert("The show instance doesn't exist anymore!") + } $("#schedule_calendar").fullCalendar( 'refetchEvents' ); } @@ -282,7 +285,6 @@ function eventRender(event, element, view) { } function eventAfterRender( event, element, view ) { - $(element) .jjmenu("click", [{get:"/Schedule/make-context-menu/format/json/id/#id#"}], @@ -301,6 +303,9 @@ function eventDrop(event, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui $.post(url, {day: dayDelta, min: minuteDelta, showInstanceId: event.id}, function(json){ + if(json.show_error == true){ + alertShowErrorAndReload(); + } if(json.error) { alert(json.error); revertFunc(); @@ -316,12 +321,15 @@ function eventResize( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, vie $.post(url, {day: dayDelta, min: minuteDelta, showInstanceId: event.id}, function(json){ + if(json.show_error == true){ + alertShowErrorAndReload(); + } if(json.error) { alert(json.error); revertFunc(); } - scheduleRefetchEvents(); + scheduleRefetchEvents(json); }); } @@ -430,6 +438,13 @@ function addQtipToSCIcons(ele){ } } +//Alert the error and reload the page +//this function is used to resolve concurrency issue +function alertShowErrorAndReload(){ + alert("The show instance doesn't exist anymore!"); + window.location.reload(); +} + $(document).ready(function(){ setInterval( "checkSCUploadStatus()", 5000 ); }) diff --git a/airtime_mvc/public/js/airtime/schedule/schedule.js b/airtime_mvc/public/js/airtime/schedule/schedule.js index 5c7ee99f0..e3cd1a523 100644 --- a/airtime_mvc/public/js/airtime/schedule/schedule.js +++ b/airtime_mvc/public/js/airtime/schedule/schedule.js @@ -74,6 +74,9 @@ function setScheduleDialogEvents(dialog) { $.post(url, {format: "json", groupId: groupId}, function(json){ + if(json.show_error == true){ + alertShowErrorAndReload(); + } var dialog = $("#schedule_playlist_dialog"); setScheduleDialogHtml(json); @@ -103,7 +106,9 @@ function dtDrawCallback() { } function makeScheduleDialog(dialog, json) { - + if(json.show_error == true){ + alertShowErrorAndReload(); + } dialog.find('#schedule_playlists').dataTable( { "bProcessing": true, "bServerSide": true, @@ -151,6 +156,9 @@ function makeScheduleDialog(dialog, json) { $.post(url, {plId: pl_id, search: search}, function(json){ + if(json.show_error == true){ + alertShowErrorAndReload(); + } var dialog = $("#schedule_playlist_dialog"); setScheduleDialogHtml(json); @@ -171,7 +179,7 @@ function confirmCancelShow(show_instance_id){ var url = "/Schedule/cancel-current-show/id/"+show_instance_id; $.ajax({ url: url, - success: function(data){scheduleRefetchEvents();} + success: function(data){scheduleRefetchEvents(data);} }); } } @@ -181,6 +189,12 @@ function uploadToSoundCloud(show_instance_id){ var url = "/Schedule/upload-to-sound-cloud"; var span = $(window.triggerElement).find(".recording"); + $.post(url, + {id: show_instance_id, format: "json"}, + function(json){ + scheduleRefetchEvents(json); + }); + if(span.length == 0){ span = $(window.triggerElement).find(".soundcloud"); span.removeClass("soundcloud") @@ -189,13 +203,6 @@ function uploadToSoundCloud(show_instance_id){ span.removeClass("recording") .addClass("progress"); } - - $.post(url, - {id: show_instance_id, format: "json"}, - function(){ - scheduleRefetchEvents(); - }); - } //used by jjmenu @@ -208,6 +215,9 @@ function getId() { //end functions used by jjmenu function buildContentDialog(json){ + if(json.show_error == true){ + alertShowErrorAndReload(); + } var dialog = $(json.dialog); var viewportwidth; @@ -263,7 +273,9 @@ function buildContentDialog(json){ function buildScheduleDialog(json){ var dialog; - + if(json.show_error == true){ + alertShowErrorAndReload(); + } if(json.error) { alert(json.error); return; @@ -289,9 +301,6 @@ function buildScheduleDialog(json){ checkShowLength(); } -function buildEditDialog(json){ - -} /** * Use user preference for time scale; defaults to month if preference was never set @@ -381,6 +390,13 @@ function createFullCalendar(data){ }); } +//Alert the error and reload the page +//this function is used to resolve concurrency issue +function alertShowErrorAndReload(){ + alert("The show instance doesn't exist anymore!"); + window.location.reload(); +} + $(window).load(function() { $.ajax({ url: "/Api/calendar-init/format/json", dataType:"json", success:createFullCalendar , error:function(jqXHR, textStatus, errorThrown){}}); diff --git a/airtime_mvc/public/js/contextmenu/AirtimeChanges b/airtime_mvc/public/js/contextmenu/AirtimeChanges new file mode 100644 index 000000000..72e7371c4 --- /dev/null +++ b/airtime_mvc/public/js/contextmenu/AirtimeChanges @@ -0,0 +1,13 @@ +* jjmenu library file has to be modified in order to handle some error cases. +* see line 87 in jjemenu.js. Following code was added: + +/* jjmenu doesn't provide ability to add callback function +in case of error. So the error handling has to be included in +the library itself */ +if(data.show_error == true){ + alert("The show doesn't exist anymore!"); + window.location.reload(); +}else if(data.playlist_error == true){ + alert("The playlist doesn't exist anymore!"); + window.location.reload(); +} \ No newline at end of file diff --git a/airtime_mvc/public/js/contextmenu/jjmenu.js b/airtime_mvc/public/js/contextmenu/jjmenu.js index bff93d932..915377217 100644 --- a/airtime_mvc/public/js/contextmenu/jjmenu.js +++ b/airtime_mvc/public/js/contextmenu/jjmenu.js @@ -84,6 +84,16 @@ dynamicItems = true; $.getJSON(uReplace(param[i].get), function(data) { + /* jjmenu doesn't provide ability to add callback function + in case of error. So the error handling has to be included in + the library itself */ + if(data.show_error == true){ + alert("The show instance doesn't exist anymore!"); + window.location.reload(); + }else if(data.playlist_error == true){ + alert("The playlist doesn't exist anymore!"); + window.location.reload(); + } for (var ii in data) { putItem(data[ii]); }