Some error handling and ensure we are an admin to delete requests.

Also started on the approval of everything
This commit is contained in:
tidusjar 2016-03-08 14:26:26 +00:00
commit 0942bfcbcc
18 changed files with 436 additions and 58 deletions

View file

@ -18,3 +18,4 @@
background-color: #4e5d6c !important;
color: white !important;
}

View file

@ -13,6 +13,67 @@ var tvimer = 0;
movieLoad();
tvLoad();
$('#approveAll').click(function() {
$.ajax({
type: 'post',
url: '/approval/approveall',
dataType: "json",
success: function (response) {
if (checkJsonResponse(response)) {
generateNotify("Success!", "success");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
// Report Issue
$(document).on("click", ".dropdownIssue", function (e) {
var issue = $(this).attr("issue-select");
var id = e.target.id;
// Other issue so the modal is opening
if (issue == 4) {
return;
}
$.ajax({
type: "post",
url: "/requests/reportissue",
data: $form.serialize(), // TODO pass in issue enum and Id
dataType: "json",
success: function (response) {
if (checkJsonResponse(response)) {
generateNotify("Success!", "success");
$("#" + buttonId + "Template").slideUp();
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
// Modal click
$('.theSaveButton').click(function() {
});
// Update the modal
$('#myModal').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var id = button.data('identifier'); // Extract info from data-* attributes
var modal = $(this);
modal.find('.theSaveButton').val(id);
});
$(document).on("click", ".delete", function (e) {
e.preventDefault();
var buttonId = e.target.id;
@ -24,13 +85,11 @@ $(document).on("click", ".delete", function (e) {
data: $form.serialize(),
dataType: "json",
success: function (response) {
console.log(response);
if (response.result === true) {
if (checkJsonResponse(response)) {
generateNotify("Success!", "success");
$("#" + buttonId + "Template").slideUp();
} else {
generateNotify(response.message, "warning");
}
},
error: function (e) {
@ -81,7 +140,8 @@ function buildRequestContext(result, type) {
approved: result.approved,
requestedBy: result.requestedBy,
requestedDate: result.requestedDate,
available: result.available
available: result.available,
admin: result.admin
};
return context;

View file

@ -10,14 +10,14 @@ var searchTemplate = Handlebars.compile(searchSource);
var movieTimer = 0;
var tvimer = 0;
$("#movieSearchContent").keypress(function (e) {
$("#movieSearchContent").keypress(function () {
if (movieTimer) {
clearTimeout(movieTimer);
}
movieTimer = setTimeout(movieSearch, 400);
});
$("#tvSearchContent").keypress(function (e) {
$("#tvSearchContent").keypress(function () {
if (tvimer) {
clearTimeout(tvimer);
}
@ -26,12 +26,17 @@ $("#tvSearchContent").keypress(function (e) {
// Click TV dropdown option
$(document).on("click", ".dropdownTv", function (e) {
e.preventDefault();
var buttonId = e.target.id;
$("#" + buttonId).prop("disabled", true);
e.preventDefault();
var $form = $('#form' + buttonId);
var data = $form.serialize();
var seasons = $(this).attr("season-select");
if (seasons === "1") {
// Send over the latest
data = data + "&latest=true";
}
@ -39,14 +44,16 @@ $(document).on("click", ".dropdownTv", function (e) {
var url = $form.prop('action');
sendRequestAjax(data, type, url, buttonId);
$("#" + buttonId).prop("disabled", false);
});
// Click Request for movie
$(document).on("click", ".requestMovie", function (e) {
$(".requestMovie").prop("disabled", true);
var buttonId = e.target.id;
$("#" + buttonId).prop("disabled", true);
e.preventDefault();
var buttonId = e.target.id;
var $form = $('#form' + buttonId);
var type = $form.prop('method');
@ -54,6 +61,7 @@ $(document).on("click", ".requestMovie", function (e) {
var data = $form.serialize();
sendRequestAjax(data, type, url, buttonId);
$("#" + buttonId).prop("disabled", false);
});
function sendRequestAjax(data, type, url, buttonId) {
@ -113,3 +121,34 @@ function tvSearch() {
});
};
function buildMovieContext(result) {
var date = new Date(result.releaseDate);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.id,
title: result.title,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type: "movie"
};
return context;
}
function buildTvShowContext(result) {
var date = new Date(result.firstAired);
var year = date.getFullYear();
var context = {
posterPath: result.banner,
id: result.id,
title: result.seriesName,
overview: result.overview,
year: year,
type: "tv"
};
return context;
}

View file

@ -9,33 +9,11 @@
});
}
function buildMovieContext(result) {
var date = new Date(result.releaseDate);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.id,
title: result.title,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type: "movie"
};
return context;
}
function buildTvShowContext(result) {
var date = new Date(result.firstAired);
var year = date.getFullYear();
var context = {
posterPath: result.banner,
id: result.id,
title: result.seriesName,
overview: result.overview,
year: year,
type: "tv"
};
return context;
function checkJsonResponse(response) {
if (response.result === true) {
return true;
} else {
generateNotify(response.message, "warning");
return false;
}
}