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),
|
2018-01-11 23:48:26 -05:00
|
|
|
model = $editList.data("model"),
|
|
|
|
path = $editList.data("path");
|
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() {
|
2018-01-11 23:48:26 -05:00
|
|
|
window.location.href = "/dashboard/" + path + "-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
|
2018-01-11 23:48:26 -05:00
|
|
|
window.location.href = "/dashboard/" + path + "-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("");
|
|
|
|
|
2018-01-13 01:16:19 -05:00
|
|
|
// initialize the filter list functionality
|
2016-12-22 00:20:44 -05:00
|
|
|
const filterList = new List("edit-list-wrapper", {
|
2018-01-12 23:58:43 -05:00
|
|
|
valueNames: [ "title-column" ]
|
2016-12-22 00:20:44 -05:00
|
|
|
});
|
2018-01-13 01:16:19 -05:00
|
|
|
|
|
|
|
// add/remove a filtered class to identify when the list is filtered
|
|
|
|
$filter.on("input", function() {
|
|
|
|
if ($filter.val() === "") {
|
|
|
|
$editList.removeClass("filtered");
|
|
|
|
} else {
|
|
|
|
$editList.addClass("filtered");
|
|
|
|
}
|
|
|
|
});
|
2016-12-22 00:20:44 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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"),
|
2018-01-15 23:43:20 -05:00
|
|
|
$datePickers = $(".date-picker"),
|
2016-08-01 21:26:54 -04:00
|
|
|
$mkdEditors = $(".mkd-editor"),
|
2018-01-11 01:13:58 -05:00
|
|
|
$imgUploads = $(".image-upload"),
|
2016-08-01 21:26:54 -04:00
|
|
|
$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"),
|
2018-01-11 23:54:00 -05:00
|
|
|
path = $editItem.data("path"),
|
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,
|
2018-01-12 23:19:24 -05:00
|
|
|
minutes,
|
|
|
|
changes = false;
|
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);
|
|
|
|
});
|
|
|
|
|
2018-01-15 23:43:20 -05:00
|
|
|
// add values from the contents of date-picker class elements
|
|
|
|
$datePickers.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);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-01-11 01:13:58 -05:00
|
|
|
const uploadImage = function(row_id, currentImage) {
|
|
|
|
let file, imgUpload;
|
2016-08-01 21:26:54 -04:00
|
|
|
|
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();
|
2018-01-11 23:54:00 -05:00
|
|
|
window.location.href = "/dashboard/" + path;
|
2016-01-26 23:20:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// add the image from the image upload box for image-upload class elements
|
2018-01-11 01:13:58 -05:00
|
|
|
if ($imgUploads.length >= currentImage + 1) {
|
|
|
|
imgUpload = $imgUploads[currentImage];
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-01-11 01:13:58 -05:00
|
|
|
if ($(imgUpload).val() !== "") {
|
|
|
|
file = new FormData();
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2018-01-11 01:13:58 -05:00
|
|
|
// add the file, id and model to the formData variable
|
|
|
|
file.append("file", imgUpload.files[0]);
|
|
|
|
file.append("name", $(imgUpload).attr("name"));
|
|
|
|
file.append("id", row_id);
|
|
|
|
file.append("model", model);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: "/dashboard/image-upload",
|
|
|
|
data: file,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
beforeSend: function(xhr) { xhr.setRequestHeader("X-CSRF-TOKEN", $token.val()); }
|
|
|
|
}).always(function(response) {
|
|
|
|
console.log(`response: ${response.responseText}`);
|
|
|
|
|
|
|
|
if (response === "success") {
|
|
|
|
uploadImage(row_id, currentImage + 1);
|
|
|
|
} else {
|
|
|
|
hideLoadingModal();
|
|
|
|
showAlert("ERROR: Failed to upload image");
|
|
|
|
submitting = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
uploadImage(row_id, currentImage + 1);
|
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 23:43:20 -05:00
|
|
|
// enable the datepicker for each element with the date-picker class
|
|
|
|
$datePickers.each(function() {
|
|
|
|
$(this).pickadate({
|
|
|
|
format: "yyyy-mm-dd",
|
|
|
|
formatSubmit: "yyyy-mm-dd",
|
2018-01-16 00:38:08 -05:00
|
|
|
clear: false,
|
|
|
|
selectYears: true,
|
|
|
|
selectMonths: true
|
2016-01-26 23:20:08 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
|
2018-01-12 23:19:24 -05:00
|
|
|
// initialize change events for back button
|
|
|
|
$editItem.find("input, textarea, select").on("input change", function() {
|
|
|
|
changes = true;
|
|
|
|
$submit.removeClass("disabled");
|
|
|
|
});
|
|
|
|
|
2016-01-26 23:20:08 -05:00
|
|
|
// 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) {
|
2018-01-12 23:19:24 -05:00
|
|
|
if (changes) {
|
|
|
|
askConfirmation("Cancel changes and return to the list?", function() {
|
|
|
|
window.location.href = "/dashboard/" + path;
|
|
|
|
});
|
|
|
|
} else {
|
2018-01-11 23:54:00 -05:00
|
|
|
window.location.href = "/dashboard/" + path;
|
2018-01-12 23:19:24 -05:00
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// initialize submit button
|
2016-08-01 21:26:54 -04:00
|
|
|
$submit.on("click", function() {
|
2018-01-12 23:19:24 -05:00
|
|
|
if (!submitting && changes) {
|
2016-01-26 23:20:08 -05:00
|
|
|
submitting = true;
|
|
|
|
|
|
|
|
// show the loading modal
|
|
|
|
showLoadingModal();
|
|
|
|
|
|
|
|
// populate the formData object
|
|
|
|
getFormData();
|
2018-01-11 01:13:58 -05:00
|
|
|
console.log(JSON.stringify(formData));
|
2016-01-26 23:20:08 -05:00
|
|
|
|
|
|
|
// 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)) {
|
2018-01-11 01:13:58 -05:00
|
|
|
uploadImage(response.replace(/^id:/, ""), 0);
|
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();
|
|
|
|
}
|
|
|
|
});
|