2016-01-26 23:20:08 -05:00
|
|
|
// declare a reverse function for jquery
|
|
|
|
jQuery.fn.reverse = [].reverse;
|
|
|
|
|
|
|
|
// show the confirmation modal and run the supplied command if confirm is pressed
|
|
|
|
function askConfirmation(message, command) {
|
2016-08-01 21:26:54 -04:00
|
|
|
const $confirmationModal = $("#confirmation-modal"),
|
|
|
|
$heading = $confirmationModal.find(".panel-heading"),
|
|
|
|
$cancelButton = $confirmationModal.find(".btn.cancel-button"),
|
|
|
|
$confirmButton = $confirmationModal.find(".btn.confirm-button"),
|
2016-01-26 23:20:08 -05:00
|
|
|
fadeTime = 250;
|
|
|
|
|
|
|
|
// close the confirmation modal and unbind its events
|
2016-08-01 21:26:54 -04:00
|
|
|
const closeConfirmationModal = function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
// unbind events
|
2016-08-01 21:26:54 -04:00
|
|
|
$(document).off("keyup", escapeModal);
|
|
|
|
$cancelButton.off("click", closeConfirmationModal);
|
|
|
|
$confirmButton.off("click", confirmModal);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// clear the heading
|
|
|
|
$heading.empty();
|
|
|
|
|
|
|
|
// hide the modal
|
|
|
|
$confirmationModal.css({ opacity: 0 });
|
2016-08-01 21:26:54 -04:00
|
|
|
setTimeout(function() { $confirmationModal.css({ visibility: "hidden" }); }, fadeTime);
|
2016-01-26 23:20:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// close the modal if the escape button is pressed
|
2016-08-01 21:26:54 -04:00
|
|
|
const escapeModal = function(e) {
|
|
|
|
if (e.keyCode === 27) { closeConfirmationModal(); }
|
2016-01-26 23:20:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// functionality to run when clicking the confirm button
|
2016-08-01 21:26:54 -04:00
|
|
|
const confirmModal = function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
command();
|
|
|
|
closeConfirmationModal();
|
|
|
|
};
|
|
|
|
|
|
|
|
// hide the modal when the cancel button is pressed
|
2016-08-01 21:26:54 -04:00
|
|
|
$cancelButton.on("click", closeConfirmationModal);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// hide the modal when the escape key is pressed
|
2016-08-01 21:26:54 -04:00
|
|
|
$(document).on("keyup", escapeModal);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// run the command and hide the modal when the confirm button is pressed
|
2016-08-01 21:26:54 -04:00
|
|
|
$confirmButton.on("click", confirmModal);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// set the heading with the supplied message
|
|
|
|
$heading.text(message);
|
|
|
|
|
|
|
|
// show the confirmation modal
|
|
|
|
$confirmationModal.css({
|
2016-08-01 21:26:54 -04:00
|
|
|
visibility: "visible",
|
2016-01-26 23:20:08 -05:00
|
|
|
opacity: 1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// show the alert modal and display the provided message until accept is pressed
|
|
|
|
function showAlert(message, command) {
|
2016-08-01 21:26:54 -04:00
|
|
|
const $alertModal = $("#alert-modal"),
|
|
|
|
$message = $alertModal.find(".message"),
|
|
|
|
$acceptButton = $alertModal.find(".btn.accept-button"),
|
2016-01-26 23:20:08 -05:00
|
|
|
fadeTime = 250;
|
|
|
|
|
|
|
|
// close the alert modal and unbind its events
|
2016-08-01 21:26:54 -04:00
|
|
|
const closeAlertModal = function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
// unbind events
|
2016-08-01 21:26:54 -04:00
|
|
|
$(document).off("keyup", escapeModal);
|
|
|
|
$acceptButton.off("click", closeAlertModal);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// clear the message
|
|
|
|
$message.empty();
|
|
|
|
|
|
|
|
// hide the modal
|
|
|
|
$alertModal.css({ opacity: 0 });
|
2016-08-01 21:26:54 -04:00
|
|
|
setTimeout(function() { $alertModal.css({ visibility: "hidden" }); }, fadeTime);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// if a command was passed run it now
|
2016-08-01 21:26:54 -04:00
|
|
|
if (command !== undefined) { command(); }
|
2016-01-26 23:20:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// close the modal if the escape button is pressed
|
2016-08-01 21:26:54 -04:00
|
|
|
const escapeModal = function(e) {
|
|
|
|
if (e.keyCode === 27) { closeAlertModal(); }
|
2016-01-26 23:20:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// hide the modal when the escape key is pressed
|
2016-08-01 21:26:54 -04:00
|
|
|
$(document).on("keyup", escapeModal);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// hide the modal when the accept button is pressed
|
2016-08-01 21:26:54 -04:00
|
|
|
$acceptButton.on("click", closeAlertModal);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// set the message with the supplied message
|
|
|
|
$message.text(message);
|
|
|
|
|
|
|
|
// show the alert modal
|
|
|
|
$alertModal.css({
|
2016-08-01 21:26:54 -04:00
|
|
|
visibility: "visible",
|
2016-01-26 23:20:08 -05:00
|
|
|
opacity: 1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize edit list functionality
|
|
|
|
function editListInit() {
|
2016-08-01 21:26:54 -04:00
|
|
|
const editList = document.getElementById("edit-list"),
|
2016-01-26 23:20:08 -05:00
|
|
|
$editList = $(editList),
|
2016-08-01 21:26:54 -04:00
|
|
|
model = $editList.data("model");
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// initialize new button functionality
|
2016-08-01 21:26:54 -04:00
|
|
|
const newButtonInit = function() {
|
|
|
|
const $newButton = $(".btn.new-button");
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2016-08-01 21:26:54 -04:00
|
|
|
$newButton.on("click", function() {
|
|
|
|
window.location.href = "/dashboard/" + model + "-edit/new";
|
2016-01-26 23:20:08 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// initialize edit button functionality
|
2016-08-01 21:26:54 -04:00
|
|
|
const editButtonInit = function() {
|
|
|
|
const $editButtons = $(".btn.edit-button");
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2016-08-01 21:26:54 -04:00
|
|
|
$editButtons.on("click", function() {
|
|
|
|
const $this = $(this),
|
|
|
|
$listItem = $this.closest(".list-group-item"),
|
|
|
|
itemId = $listItem.data("id");
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// go to the edit page
|
2016-08-01 21:26:54 -04:00
|
|
|
window.location.href = "/dashboard/" + model + "-edit/" + itemId;
|
2016-01-26 23:20:08 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// initialize delete button functionality
|
2016-08-01 21:26:54 -04:00
|
|
|
const deleteButtonInit = function() {
|
|
|
|
const $deleteButtons = $(".btn.delete-button");
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2016-08-01 21:26:54 -04:00
|
|
|
$deleteButtons.on("click", function() {
|
|
|
|
const $this = $(this),
|
|
|
|
$listItem = $this.closest(".list-group-item"),
|
|
|
|
itemId = $listItem.data("id");
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2016-08-01 21:26:54 -04:00
|
|
|
askConfirmation("Are you sure you want to delete this?", function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
$.ajax({
|
2016-08-01 21:26:54 -04:00
|
|
|
type: "DELETE",
|
|
|
|
url: "/dashboard/delete",
|
2016-01-26 23:20:08 -05:00
|
|
|
data: {
|
2016-08-01 21:26:54 -04:00
|
|
|
model: model,
|
|
|
|
id: itemId,
|
|
|
|
_token: $("#token").val()
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
}).always(function(response) {
|
2016-08-01 21:26:54 -04:00
|
|
|
if (response === "success") {
|
2016-01-26 23:20:08 -05:00
|
|
|
$listItem.slideUp(150, function() { $listItem.remove(); });
|
|
|
|
} else {
|
2016-08-01 21:26:54 -04:00
|
|
|
showAlert("ERROR: Failed to delete record");
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-04 23:23:26 -05:00
|
|
|
// initialize action button functionality
|
|
|
|
const actionButtonInit = function() {
|
|
|
|
const $actionButtons = $(".btn.action-button");
|
|
|
|
|
|
|
|
$actionButtons.on("click", function() {
|
|
|
|
const $this = $(this),
|
|
|
|
$listItem = $this.closest(".list-group-item"),
|
|
|
|
itemId = $listItem.data("id"),
|
|
|
|
confirmationMessage = $this.data("confirmation"),
|
|
|
|
successMessage = $this.data("success"),
|
|
|
|
errorMessage = $this.data("error"),
|
|
|
|
postUrl = $this.data("url");
|
|
|
|
|
|
|
|
askConfirmation(confirmationMessage, function() {
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: postUrl,
|
|
|
|
data: {
|
|
|
|
id: itemId,
|
|
|
|
_token: $("#token").val()
|
|
|
|
}
|
|
|
|
}).always(function(response) {
|
|
|
|
if (response === "success") {
|
|
|
|
showAlert(successMessage);
|
|
|
|
} else {
|
|
|
|
showAlert("ERROR: " + errorMessage);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-01-26 23:20:08 -05:00
|
|
|
// initialize sort functionality if data-sort is set
|
2016-08-01 21:26:54 -04:00
|
|
|
const sortRowInit = function() {
|
|
|
|
let sortOrder = {}, sortCol, sortable;
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2016-08-01 21:26:54 -04:00
|
|
|
if ($editList.attr("data-sort")) {
|
|
|
|
sortCol = $editList.data("sort");
|
|
|
|
|
|
|
|
sortable = Sortable.create(editList, {
|
|
|
|
handle: ".sort-icon",
|
2016-01-26 23:20:08 -05:00
|
|
|
onUpdate: function() {
|
|
|
|
// update the sortOrder object based on the updated order
|
2016-08-01 21:26:54 -04:00
|
|
|
$editList.find(".list-group-item").reverse().each(function(index) {
|
|
|
|
sortOrder[$(this).data("id")] = index;
|
2016-01-26 23:20:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
$.ajax({
|
2016-08-01 21:26:54 -04:00
|
|
|
type: "POST",
|
|
|
|
url: "/dashboard/reorder",
|
2016-01-26 23:20:08 -05:00
|
|
|
data: {
|
2016-08-01 21:26:54 -04:00
|
|
|
model: model,
|
|
|
|
order: sortOrder,
|
2016-01-26 23:20:08 -05:00
|
|
|
column: sortCol,
|
2016-08-01 21:26:54 -04:00
|
|
|
_token: $("#token").val()
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
}).always(function(response) {
|
2016-08-01 21:26:54 -04:00
|
|
|
if (response !== "success") {
|
|
|
|
showAlert("ERROR: Sorting failed", function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
document.location.reload(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-22 00:20:44 -05:00
|
|
|
// initialize filter functionality if the filter-input element exists
|
|
|
|
const filterInputInit = function() {
|
|
|
|
const $filter = $("#filter-input");
|
|
|
|
|
|
|
|
if ($filter.length) {
|
|
|
|
// empty the filter
|
|
|
|
$filter.val("");
|
|
|
|
|
|
|
|
const filterList = new List("edit-list-wrapper", {
|
|
|
|
valueNames: [ "title" ]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-26 23:20:08 -05:00
|
|
|
newButtonInit();
|
|
|
|
editButtonInit();
|
|
|
|
deleteButtonInit();
|
2017-01-04 23:23:26 -05:00
|
|
|
actionButtonInit();
|
2016-01-26 23:20:08 -05:00
|
|
|
sortRowInit();
|
2016-12-22 00:20:44 -05:00
|
|
|
filterInputInit();
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function editItemInit() {
|
2016-08-01 21:26:54 -04:00
|
|
|
const $editItem = $("#edit-item"),
|
|
|
|
$submit = $("#submit"),
|
|
|
|
$backButton = $("#back"),
|
|
|
|
$textInputs = $(".text-input"),
|
|
|
|
$dateTimePickers = $(".date-time-picker"),
|
|
|
|
$mkdEditors = $(".mkd-editor"),
|
|
|
|
$imgUpload = $("#image-upload"),
|
|
|
|
$token = $("#_token"),
|
|
|
|
$spinner = $("#loading-modal"),
|
2016-01-26 23:20:08 -05:00
|
|
|
fadeTime = 250,
|
2016-08-01 21:26:54 -04:00
|
|
|
model = $editItem.data("model"),
|
2017-01-03 22:55:12 -05:00
|
|
|
id = $editItem.data("id"),
|
|
|
|
operation = id === "new" ? "create" : "update";
|
2016-08-01 21:26:54 -04:00
|
|
|
|
|
|
|
let allowTimes = [],
|
2016-01-26 23:20:08 -05:00
|
|
|
simplemde = [],
|
|
|
|
formData = {},
|
2016-08-01 21:26:54 -04:00
|
|
|
submitting = false,
|
|
|
|
hours,
|
|
|
|
minutes;
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// show the loading modal
|
2016-08-01 21:26:54 -04:00
|
|
|
const showLoadingModal = function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
$spinner.css({
|
2016-08-01 21:26:54 -04:00
|
|
|
visibility: "visible",
|
2016-01-26 23:20:08 -05:00
|
|
|
opacity: 1
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// hide the loading modal
|
2016-08-01 21:26:54 -04:00
|
|
|
const hideLoadingModal = function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
$spinner.css({ opacity: 0 });
|
2016-08-01 21:26:54 -04:00
|
|
|
setTimeout(function() { $spinner.css({ visibility: "hidden" }); }, fadeTime);
|
2016-01-26 23:20:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// fill the formData object with data from all the form fields
|
2016-08-01 21:26:54 -04:00
|
|
|
const getFormData = function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
// function to add a column and value to the formData object
|
2016-08-01 21:26:54 -04:00
|
|
|
const addFormData = function(column, value) {
|
2016-01-26 23:20:08 -05:00
|
|
|
// add the value to a key with the column name
|
|
|
|
formData[column] = value;
|
|
|
|
|
|
|
|
// add the column to the array of columns
|
|
|
|
formData.columns.push(column);
|
|
|
|
};
|
|
|
|
|
|
|
|
// reset the formData object
|
|
|
|
formData = {};
|
|
|
|
|
|
|
|
// add the database model row id and _token
|
|
|
|
formData.model = model;
|
|
|
|
formData.id = id;
|
|
|
|
formData._token = $token.val();
|
|
|
|
|
|
|
|
// create an empty array to contain the list of columns
|
|
|
|
formData.columns = [];
|
|
|
|
|
|
|
|
// add values from the contents of text-input class elements
|
|
|
|
$textInputs.each(function() {
|
2016-08-01 21:26:54 -04:00
|
|
|
const $this = $(this),
|
|
|
|
column = $this.attr("id"),
|
2016-01-26 23:20:08 -05:00
|
|
|
value = $this.val();
|
|
|
|
|
|
|
|
addFormData(column, value);
|
|
|
|
});
|
|
|
|
|
|
|
|
// add values from the contents of date-time-picker class elements
|
|
|
|
$dateTimePickers.each(function() {
|
2016-08-01 21:26:54 -04:00
|
|
|
const $this = $(this),
|
|
|
|
column = $this.attr("id"),
|
|
|
|
value = $this.val() + ":00";
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
addFormData(column, value);
|
|
|
|
});
|
|
|
|
|
|
|
|
// add values from the contents of the markdown editor for mkd-editor class elements
|
|
|
|
$mkdEditors.each(function() {
|
2016-08-01 21:26:54 -04:00
|
|
|
const $this = $(this),
|
|
|
|
column = $this.attr("id"),
|
2016-01-26 23:20:08 -05:00
|
|
|
value = simplemde[column].value();
|
|
|
|
|
|
|
|
addFormData(column, value);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-01 21:26:54 -04:00
|
|
|
const uploadImage = function(row_id) {
|
|
|
|
let file;
|
|
|
|
|
2016-01-26 23:20:08 -05:00
|
|
|
// functionality to run on success
|
2016-08-01 21:26:54 -04:00
|
|
|
const returnSuccess = function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
hideLoadingModal();
|
2017-04-29 01:12:01 -04:00
|
|
|
window.location.href = "/dashboard/" + model;
|
2016-01-26 23:20:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// add the image from the image upload box for image-upload class elements
|
2016-08-01 21:26:54 -04:00
|
|
|
if ($imgUpload.length && $imgUpload.val() !== "") {
|
|
|
|
file = new FormData();
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// add the file, id and model to the formData variable
|
2016-08-01 21:26:54 -04:00
|
|
|
file.append("file", $imgUpload[0].files[0]);
|
|
|
|
file.append("id", row_id);
|
|
|
|
file.append("model", model);
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
$.ajax({
|
2016-08-01 21:26:54 -04:00
|
|
|
type: "POST",
|
|
|
|
url: "/dashboard/image-upload",
|
|
|
|
data: file,
|
2016-01-26 23:20:08 -05:00
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
2016-08-01 21:26:54 -04:00
|
|
|
beforeSend: function(xhr) { xhr.setRequestHeader("X-CSRF-TOKEN", $token.val()); }
|
2016-01-26 23:20:08 -05:00
|
|
|
}).always(function(response) {
|
2016-08-01 21:26:54 -04:00
|
|
|
if (response === "success") {
|
2016-01-26 23:20:08 -05:00
|
|
|
returnSuccess();
|
|
|
|
} else {
|
|
|
|
hideLoadingModal();
|
2016-08-01 21:26:54 -04:00
|
|
|
showAlert("ERROR: Failed to upload image");
|
2016-01-26 23:20:08 -05:00
|
|
|
submitting = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
returnSuccess();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// allow start time selection to start on the hour and every 15 minutes after
|
2016-08-01 21:26:54 -04:00
|
|
|
for (hours = 0; hours <= 23; hours++) {
|
|
|
|
for (minutes = 0; minutes <= 3; minutes++) {
|
|
|
|
allowTimes.push(hours + ":" + (minutes === 0 ? "00" : minutes * 15));
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable the datetimepicker for each element with the date-time-picker class
|
|
|
|
$dateTimePickers.each(function() {
|
|
|
|
$(this).datetimepicker({
|
2016-08-01 21:26:54 -04:00
|
|
|
format: "Y-m-d H:i",
|
2016-01-26 23:20:08 -05:00
|
|
|
allowTimes: allowTimes,
|
|
|
|
step: 15
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// enable the markdown editor for each element with the mkd-editor class
|
|
|
|
$mkdEditors.each(function() {
|
2016-08-01 21:26:54 -04:00
|
|
|
const $this = $(this),
|
|
|
|
column = $this.attr("id");
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
simplemde[column] = new SimpleMDE({
|
|
|
|
element: this,
|
|
|
|
toolbar: [
|
2016-08-01 21:26:54 -04:00
|
|
|
"bold",
|
|
|
|
"italic",
|
|
|
|
"|",
|
|
|
|
"heading-1",
|
|
|
|
"heading-2",
|
|
|
|
"heading-3",
|
|
|
|
"|",
|
|
|
|
"quote",
|
|
|
|
"unordered-list",
|
|
|
|
"ordered-list",
|
|
|
|
"link"
|
2016-01-26 23:20:08 -05:00
|
|
|
],
|
2016-08-01 21:26:54 -04:00
|
|
|
blockStyles: { italic: "_" },
|
2016-01-26 23:20:08 -05:00
|
|
|
autoDownloadFontAwesome: false,
|
2016-04-08 18:03:18 -04:00
|
|
|
tabSize: 4,
|
|
|
|
spellChecker: false
|
2016-01-26 23:20:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2016-08-01 21:26:54 -04:00
|
|
|
simplemde[column].value($this.attr("value"));
|
2016-01-26 23:20:08 -05:00
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
|
|
|
|
// initialize back button
|
2016-08-01 21:26:54 -04:00
|
|
|
$backButton.on("click", function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
if (!submitting) {
|
2016-08-01 21:26:54 -04:00
|
|
|
askConfirmation("Cancel and return to the " + model + " list?", function() {
|
|
|
|
window.location.href = "/dashboard/" + model;
|
2016-01-26 23:20:08 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// initialize submit button
|
2016-08-01 21:26:54 -04:00
|
|
|
$submit.on("click", function() {
|
2016-01-26 23:20:08 -05:00
|
|
|
if (!submitting) {
|
|
|
|
submitting = true;
|
|
|
|
|
|
|
|
// show the loading modal
|
|
|
|
showLoadingModal();
|
|
|
|
|
|
|
|
// populate the formData object
|
|
|
|
getFormData();
|
|
|
|
|
|
|
|
// submit the update
|
|
|
|
$.ajax({
|
2016-08-01 21:26:54 -04:00
|
|
|
type: "POST",
|
|
|
|
url: "/dashboard/edit",
|
2016-01-26 23:20:08 -05:00
|
|
|
data: formData
|
|
|
|
}).always(function(response) {
|
|
|
|
if (/^id:[0-9][0-9]*$/.test(response)) {
|
2016-08-01 21:26:54 -04:00
|
|
|
uploadImage(response.replace(/^id:/, ""));
|
2016-01-26 23:20:08 -05:00
|
|
|
} else {
|
|
|
|
hideLoadingModal();
|
2017-01-03 22:55:12 -05:00
|
|
|
showAlert("ERROR: Failed to " + operation + " record");
|
2016-01-26 23:20:08 -05:00
|
|
|
submitting = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// run once the document is ready
|
|
|
|
$(document).ready(function() {
|
2016-08-01 21:26:54 -04:00
|
|
|
if ($("#edit-list").length) {
|
2016-01-26 23:20:08 -05:00
|
|
|
editListInit();
|
2016-08-01 21:26:54 -04:00
|
|
|
} else if ($("#edit-item").length) {
|
2016-01-26 23:20:08 -05:00
|
|
|
editItemInit();
|
|
|
|
}
|
|
|
|
});
|