Better errors from podcast 'Add' dialog

This commit is contained in:
Duncan Sommerville 2015-11-10 19:26:25 -05:00
parent de380369ed
commit c5a5839eff
10 changed files with 44 additions and 14 deletions

View file

@ -28,6 +28,7 @@ class LocaleController extends Zend_Controller_Action
$translations = array ( $translations = array (
//common/common.js //common/common.js
"Audio Player" => _("Audio Player"), "Audio Player" => _("Audio Player"),
"Something went wrong!" => _("Something went wrong!"),
//dashboard/dashboard.js //dashboard/dashboard.js
"Recording:" => _("Recording:"), "Recording:" => _("Recording:"),
"Master Stream" => _("Master Stream"), "Master Stream" => _("Master Stream"),

View file

@ -217,7 +217,6 @@ class PlaylistController extends Zend_Controller_Action
$id = $this->_getParam('id', null); $id = $this->_getParam('id', null);
$type = $this->_getParam('type'); $type = $this->_getParam('type');
$objInfo = Application_Model_Library::getObjInfo($type); $objInfo = Application_Model_Library::getObjInfo($type);
Logging::info("editing {$type} {$id}");
// if (!is_null($id)) { // if (!is_null($id)) {
Application_Model_Library::changePlaylist($id, $type); Application_Model_Library::changePlaylist($id, $type);

View file

@ -188,8 +188,6 @@ class Application_Model_Block implements Application_Model_LibraryEditable
*/ */
public function getContents($filterFiles=false) public function getContents($filterFiles=false)
{ {
Logging::info("Getting contents for block {$this->id}");
$sql = <<<SQL $sql = <<<SQL
SELECT pc.id AS id, SELECT pc.id AS id,
pc.position, pc.position,

View file

@ -80,7 +80,6 @@ class Rest_PodcastController extends Zend_Rest_Controller
} }
try { try {
//$requestData = json_decode($this->getRequest()->getRawBody(), true);
$requestData = $this->getRequest()->getPost(); $requestData = $this->getRequest()->getPost();
$podcast = Application_Service_PodcastService::createFromFeedUrl($requestData["url"]); $podcast = Application_Service_PodcastService::createFromFeedUrl($requestData["url"]);
@ -94,17 +93,16 @@ class Rest_PodcastController extends Zend_Rest_Controller
catch (PodcastLimitReachedException $e) { catch (PodcastLimitReachedException $e) {
$this->getResponse() $this->getResponse()
->setHttpResponseCode(400) ->setHttpResponseCode(400)
->appendBody("ERROR: Podcast limit reached."); ->appendBody("Podcast limit reached.");
} }
catch (InvalidPodcastException $e) { catch (InvalidPodcastException $e) {
$this->getResponse() $this->getResponse()
->setHttpResponseCode(400) ->setHttpResponseCode(400)
->appendBody("ERROR: Invalid Podcast."); ->appendBody("Invalid podcast!");
} }
catch (Exception $e) { catch (Exception $e) {
$this->unknownErrorResponse();
Logging::error($e->getMessage()); Logging::error($e->getMessage());
throw $e; $this->unknownErrorResponse();
} }
} }
@ -215,7 +213,7 @@ class Rest_PodcastController extends Zend_Rest_Controller
private function unknownErrorResponse() private function unknownErrorResponse()
{ {
$resp = $this->getResponse(); $resp = $this->getResponse();
$resp->setHttpResponseCode(400); $resp->setHttpResponseCode(500);
$resp->appendBody("An unknown error occurred."); $resp->appendBody("An unknown error occurred.");
} }

View file

@ -72,7 +72,7 @@ class Application_Service_PodcastService
//TODO: why is this so slow? //TODO: why is this so slow?
$rss = self::getPodcastFeed($feedUrl); $rss = self::getPodcastFeed($feedUrl);
if (!$rss) { if (!$rss || !empty($rss->error())) {
throw new InvalidPodcastException(); throw new InvalidPodcastException();
} }

View file

@ -1,5 +1,5 @@
<div id="podcast_url_dialog"> <div id="podcast_url_dialog">
<form name="podcast_url_form" style="margin-top: 10px;"> <form id="podcast_url_form" name="podcast_url_form" style="margin-top: 10px;">
<?php echo $this->csrf ?> <?php echo $this->csrf ?>
<table style="padding: 0;"> <table style="padding: 0;">
<tr> <tr>
@ -9,13 +9,14 @@
</label> </label>
</td> </td>
<td style="text-align: right"> <td style="text-align: right">
<input type="text" name="podcast_url_field" name="url" size="40" style="margin-left: 10px; margin-bottom: 10px;" placeholder="http://example.com/podcast.xml"/> <input id="podcast_url_field" type="url" name="url" size="40" style="margin-left: 10px; margin-bottom: 10px;" placeholder="http://example.com/podcast.xml"/>
</td> </td>
</tr> </tr>
</table> </table>
<button class="btn btn-new right-floated" type="button" onclick="AIRTIME.podcast.addPodcast()"> <button class="btn btn-new right-floated" type="submit">
<?php echo _("Subscribe"); ?> <?php echo _("Subscribe"); ?>
</button> </button>
<span class="errors" style="display:none"></span>
</form> </form>
<!-- <p style="clear: both; text-align: center; opacity: 0.7; margin-top: 20px;">Paste the URL of a podcast RSS feed above.</p> --> <!-- <p style="clear: both; text-align: center; opacity: 0.7; margin-top: 20px;">Paste the URL of a podcast RSS feed above.</p> -->
</div> </div>

View file

@ -4168,3 +4168,9 @@ li .ui-state-hover {
#podcast_url_dialog table tr td { #podcast_url_dialog table tr td {
padding: 0px; padding: 0px;
} }
#podcast_url_dialog .errors {
display: inline-block;
float: right;
width: 50%;
}

View file

@ -304,6 +304,20 @@ function getUsabilityHint() {
}); });
} }
// TODO: build this out so we can use it as a fallback in fail cases
function buildErrorDialog(message) {
var el = $("<div id='error_dialog'></div>");
el.text(message);
$(document.body).append(el);
$("#error_dialog").dialog({
title: $.i18n._("Something went wrong!"),
resizable: false,
modal: true,
width: "auto",
height: "auto"
});
}
/** /**
* Add title attributes (whose values are their inner text) to all elements in the calling parent matching selector * Add title attributes (whose values are their inner text) to all elements in the calling parent matching selector
* *

View file

@ -524,6 +524,12 @@ var AIRTIME = (function (AIRTIME) {
AIRTIME.library.podcastTableWidget.clearSelection(); AIRTIME.library.podcastTableWidget.clearSelection();
AIRTIME.library.setCurrentTable(AIRTIME.library.DataTableTypeEnum.PODCAST_EPISODES); AIRTIME.library.setCurrentTable(AIRTIME.library.DataTableTypeEnum.PODCAST_EPISODES);
$("#podcast_url_dialog").dialog("close"); $("#podcast_url_dialog").dialog("close");
}).fail(function (e) {
var errors = $("#podcast_url_dialog").find(".errors");
errors.show(200).text(e.responseText);
setTimeout(function () {
errors.hide(200);
}, 3000);
}); });
}; };
@ -679,3 +685,10 @@ var AIRTIME = (function (AIRTIME) {
return AIRTIME; return AIRTIME;
}(AIRTIME || {})); }(AIRTIME || {}));
$(document).ready(function() {
$(document).on("submit", "#podcast_url_form", function (e) {
e.preventDefault();
AIRTIME.podcast.addPodcast();
});
});

View file

@ -303,7 +303,7 @@ var AIRTIME = (function(AIRTIME) {
var foundAtIdx = $.inArray(aData, self._selectedRows); var foundAtIdx = $.inArray(aData, self._selectedRows);
console.log('checkbox mouse', iVisualRowIdx, foundAtIdx); //console.log('checkbox mouse', iVisualRowIdx, foundAtIdx);
//If the clicked row is already selected, deselect it. //If the clicked row is already selected, deselect it.
if (foundAtIdx >= 0 && self._selectedRows.length >= 1) { if (foundAtIdx >= 0 && self._selectedRows.length >= 1) {