From a5766fb094796f808a10c6e91ce46f388598edf0 Mon Sep 17 00:00:00 2001 From: Adam Franco Date: Thu, 19 Dec 2024 16:40:56 -0500 Subject: [PATCH] #47: Run Prittier on all Javascripts to clean up code formatting. --- assets/app.js | 4 +- assets/bookmarks.js | 55 +- assets/email_controls.js | 96 +-- assets/export.js | 1100 +++++++++++++++++------------ assets/export_revision_diff.js | 50 +- assets/export_revision_history.js | 117 +-- assets/offering_search.js | 18 +- assets/schedules.js | 363 ++++++---- 8 files changed, 1040 insertions(+), 763 deletions(-) diff --git a/assets/app.js b/assets/app.js index 4d5b99bf..b9400336 100644 --- a/assets/app.js +++ b/assets/app.js @@ -4,5 +4,5 @@ * This file will be included onto the page via the importmap() Twig function, * which should already be in your base.html.twig. */ -import './styles/app.css'; -import 'bookmarks' +import "./styles/app.css"; +import "bookmarks"; diff --git a/assets/bookmarks.js b/assets/bookmarks.js index b96e7024..a4d4a3ca 100644 --- a/assets/bookmarks.js +++ b/assets/bookmarks.js @@ -1,33 +1,40 @@ -import './styles/bookmarks.css'; -import $ from 'jquery'; +import "./styles/bookmarks.css"; +import $ from "jquery"; -$(function() { // on DOM ready +$(function () { + // on DOM ready - $('.save_course a').click(function () { - var clickedAnchor = $(this); - var courseId = $(this).siblings('input[name=course_id]').val(); - - $.ajax({ - url: clickedAnchor.attr('href'), - success: function () { - if (clickedAnchor.hasClass('save')) { - bookmarks_show_forget(courseId); - } else { - bookmarks_show_save(courseId); - } - } - - }); - return false; - }); + $(".save_course a").click(function () { + var clickedAnchor = $(this); + var courseId = $(this).siblings("input[name=course_id]").val(); + $.ajax({ + url: clickedAnchor.attr("href"), + success: function () { + if (clickedAnchor.hasClass("save")) { + bookmarks_show_forget(courseId); + } else { + bookmarks_show_save(courseId); + } + }, + }); + return false; + }); }); function bookmarks_show_save(courseId) { - $('.save_course input[name=course_id][value="' + courseId + '"]').siblings('a.save').show(); - $('.save_course input[name=course_id][value="' + courseId + '"]').siblings('a.forget').hide(); + $('.save_course input[name=course_id][value="' + courseId + '"]') + .siblings("a.save") + .show(); + $('.save_course input[name=course_id][value="' + courseId + '"]') + .siblings("a.forget") + .hide(); } function bookmarks_show_forget(courseId) { - $('.save_course input[name=course_id][value="' + courseId + '"]').siblings('a.save').hide(); - $('.save_course input[name=course_id][value="' + courseId + '"]').siblings('a.forget').show(); + $('.save_course input[name=course_id][value="' + courseId + '"]') + .siblings("a.save") + .hide(); + $('.save_course input[name=course_id][value="' + courseId + '"]') + .siblings("a.forget") + .show(); } diff --git a/assets/email_controls.js b/assets/email_controls.js index 101e8552..bd5cc11d 100644 --- a/assets/email_controls.js +++ b/assets/email_controls.js @@ -1,60 +1,65 @@ -import $ from 'jquery'; - -$('document').ready(function() { +import $ from "jquery"; +$("document").ready(function () { /********************************************************* * Email controls *********************************************************/ - $(".email_dialog").each(function() { + $(".email_dialog").each(function () { var button = $(this).siblings(".email_button"); var emailDialog = $(this).dialog({ - autoOpen: false, - width: 700, - modal: true - }); + autoOpen: false, + width: 700, + modal: true, + }); button.data("emailDialog", emailDialog); }); - $(".email_button").click(function(){ - var emailDialog = $(this).data('emailDialog'); + $(".email_button").click(function () { + var emailDialog = $(this).data("emailDialog"); emailDialog.dialog("open"); // Store the original subject. - var field = emailDialog.find('input[name=subject]'); - if (!field.data('orig')) { - field.data('orig', field.val()); + var field = emailDialog.find("input[name=subject]"); + if (!field.data("orig")) { + field.data("orig", field.val()); } // Store the original message. - var field = emailDialog.find('textarea[name=message]'); - if (!field.data('orig')) { - field.data('orig', field.val()); + var field = emailDialog.find("textarea[name=message]"); + if (!field.data("orig")) { + field.data("orig", field.val()); } return false; }); - $(".email_dialog form").submit(function() { + $(".email_dialog form").submit(function () { var to = $(this).find("input[name=to]").val(); - to = to.replace(/^\s*/, '').replace(/\s*$/, ''); + to = to.replace(/^\s*/, "").replace(/\s*$/, ""); if (!to.length) { - if (!confirm("You didn't specify a recipient.\n\nClick 'Cancel' to add one or 'Ok' to send only to yourself.")) { + if ( + !confirm( + "You didn't specify a recipient.\n\nClick 'Cancel' to add one or 'Ok' to send only to yourself." + ) + ) { return false; } } if (to.length && !validateEmail(to)) { - alert("It doesn't look like you specified a valid email address in the 'To:' field."); + alert( + "It doesn't look like you specified a valid email address in the 'To:' field." + ); return false; } // Submit the form asynchronously, clear the to & body, then close. var form = $(this); - var emailDialog = form.parents('.email_dialog'); + var emailDialog = form.parents(".email_dialog"); $.ajax({ type: "POST", - url: form.attr('action'), + url: form.attr("action"), data: form.serialize(), success: function (data, textStatus, req) { if (data.length) { @@ -62,37 +67,36 @@ $('document').ready(function() { } // Clear the form. - form.find('input[name=to]').val(''); + form.find("input[name=to]").val(""); - var field = form.find('input[name=subject]'); - field.val(field.data('orig')); + var field = form.find("input[name=subject]"); + field.val(field.data("orig")); - var field = form.find('textarea[name=message]'); - field.val(field.data('orig')); + var field = form.find("textarea[name=message]"); + field.val(field.data("orig")); }, - error: function(req, textStatus, errorThrown) { - emailDialog.dialog('open'); + error: function (req, textStatus, errorThrown) { + emailDialog.dialog("open"); alert("Couldn't send email.\n\n" + req.responseText); - } + }, }); // Close the dialog. - emailDialog.dialog('close'); + emailDialog.dialog("close"); return false; }); - }); /** -* Validate the email field -* -* @param string emailString -* @return boolean -*/ -function validateEmail (emailString) { + * Validate the email field + * + * @param string emailString + * @return boolean + */ +function validateEmail(emailString) { var addresses = emailString.split(","); for (var i = 0; i < addresses.length; i++) { - var address = addresses[i].replace(/^\s*/, '').replace(/\s*$/, ''); + var address = addresses[i].replace(/^\s*/, "").replace(/\s*$/, ""); if (!validateEmailAddress(address)) { return false; } @@ -101,13 +105,13 @@ function validateEmail (emailString) { } /** -* Validate an email address. -* By "sectrean" at http://stackoverflow.com/questions/46155/validate-email-address-in-javascript/46181#46181 -* -* @param string email -* @return boolean -*/ -function validateEmailAddress (email) { + * Validate an email address. + * By "sectrean" at http://stackoverflow.com/questions/46155/validate-email-address-in-javascript/46181#46181 + * + * @param string email + * @return boolean + */ +function validateEmailAddress(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return email.match(re); } diff --git a/assets/export.js b/assets/export.js index 87f56bfe..9c1721ff 100644 --- a/assets/export.js +++ b/assets/export.js @@ -1,23 +1,36 @@ -import './styles/export.css'; -import $ from 'jquery'; -import 'jquery-ui'; +import "./styles/export.css"; +import $ from "jquery"; +import "jquery-ui"; var loading = false; /* Helper functions for catalog export configuration */ function selectConfig(url) { - var config = $('#config-selector').find('select').val(); - window.location.href = url + '/' + config; + var config = $("#config-selector").find("select").val(); + window.location.href = url + "/" + config; } // ------ GENERATORS ------ // function generateSection(id, type, input) { - return "
  • " + generateSectionHTML(type, input); + return ( + "
  • " + + generateSectionHTML(type, input) + ); } function generateSectionHTML(type, input) { - return "
    Type: " + type + "" + input + ""; + return ( + "
    Type: " + + type + + "" + + input + + "" + ); } // Cache of courselist data for reuse. @@ -27,577 +40,724 @@ let courselists_to_populate = []; let loading_courselist = false; function generateInputTag(type, value, callback) { - switch(type) { - case "h1": - case "h2": - if(value.indexOf(';') !== -1) { - var toc = value.substring(value.indexOf(';') + 1); - value = value.substring(0, value.indexOf(';')); - } else { - var toc = ''; - } - callback(""); - break; - case "page_content": - callback(""); - break; - case "custom_text": - callback(""); - break; - case "course_list": - // We only want to perform a single fetch of data for the course lists to - // not fire of dozens of requests for the same data, so we'll fire off the - // first request and then queue up addtional inputs to render that we'll - // go through when the result comes back. - - // If we've already loaded the data, just use it. - if (courselist_data[$('#catalogId').val()]) { - setCourseListInputForData(courselist_data[$('#catalogId').val()], value, callback); - } else { - // If we don't have data yet, add our element to the queue to be rendered. - courselists_to_populate.push({ - catalog: $('#catalogId').val(), - value: value, - callback: callback - }); - // Kick off a load of the data if we aren't loading yet. - if (!loading_courselist) { - // Set up an overlay to prevent working with or saving the form until - // population is finished. - loading_courselist = true; - $('body').append("

    Loading course list options...

    "); - $('.loading-overlay').css("height", $(window).height()); - $(window).resize(function() { - $('.loading-overlay').css("height", $(window).height()); - }); - - // Run the request and work through our queue when we get the result back. - $.ajax({ - url: $('#config-body').data('courselist-url'), - type: "GET", - error: function(error) { - throw error; - }, - success: function(data) { - courselist_data[$('#catalogId').val()] = data; - var l; - while (l = courselists_to_populate.pop()) { - setCourseListInputForData(courselist_data[l['catalog']], l['value'], l['callback']); - } - loading_courselist = false; - $('.loading-overlay').hide(); + switch (type) { + case "h1": + case "h2": + if (value.indexOf(";") !== -1) { + var toc = value.substring(value.indexOf(";") + 1); + value = value.substring(0, value.indexOf(";")); + } else { + var toc = ""; } - }); - } - } - break; - default: - throw "Invalid input tag type: " + type; - } + callback( + "" + ); + break; + case "page_content": + callback( + "" + ); + break; + case "custom_text": + callback( + "" + ); + break; + case "course_list": + // We only want to perform a single fetch of data for the course lists to + // not fire of dozens of requests for the same data, so we'll fire off the + // first request and then queue up addtional inputs to render that we'll + // go through when the result comes back. + + // If we've already loaded the data, just use it. + if (courselist_data[$("#catalogId").val()]) { + setCourseListInputForData( + courselist_data[$("#catalogId").val()], + value, + callback + ); + } else { + // If we don't have data yet, add our element to the queue to be rendered. + courselists_to_populate.push({ + catalog: $("#catalogId").val(), + value: value, + callback: callback, + }); + // Kick off a load of the data if we aren't loading yet. + if (!loading_courselist) { + // Set up an overlay to prevent working with or saving the form until + // population is finished. + loading_courselist = true; + $("body").append( + "

    Loading course list options...

    " + ); + $(".loading-overlay").css("height", $(window).height()); + $(window).resize(function () { + $(".loading-overlay").css("height", $(window).height()); + }); + + // Run the request and work through our queue when we get the result back. + $.ajax({ + url: $("#config-body").data("courselist-url"), + type: "GET", + error: function (error) { + throw error; + }, + success: function (data) { + courselist_data[$("#catalogId").val()] = data; + var l; + while ((l = courselists_to_populate.pop())) { + setCourseListInputForData( + courselist_data[l["catalog"]], + l["value"], + l["callback"] + ); + } + loading_courselist = false; + $(".loading-overlay").hide(); + }, + }); + } + } + break; + default: + throw "Invalid input tag type: " + type; + } } function setCourseListInputForData(data, value, callback) { - if (value === '') value = 'unselected'; - // Course filters. - if (value.indexOf(',') !== -1) { - var selection = value.substring(0, value.indexOf(',')); - var filters = value.substring(value.indexOf(',') +1); - var filterHTML = "
    Course #'s to exclude: " - } else { - var selection = value; - var filterHTML = "
    Course #'s to exclude: " - } - var sectionInput = data; - sectionInput = sectionInput.replace(""); - sectionInput = sectionInput.replace("
  • " + title + "
    show/hide
  • "; - } else { - return "
  • " + title + "
    show/hide
  • "; - } + if (visible) { + return ( + "
  • " + + title + + "
    show/hide
  • " + ); + } else { + return ( + "
  • " + + title + + "
    show/hide
  • " + ); + } } // ----- INIT ------ // function buildList(jsonData, callback) { - if (!jsonData || JSON.stringify(jsonData) === "{}") { - newGroup(); - callback() - } else { - - /* - * The count variable is used to ensure that this whole block flows synchronously. - * Otherwise, callback will fire early or multiple times. - * This is a hacky way to do this and if you have a better idea, please feel free - * to implement. - */ - var count = 0; - $.each(jsonData, function(key, value) { - $.each(value, function(sectionKey, sectionValue) { - count++; - }); - }); - // Subtract group names from count. - count -= Object.keys(jsonData).length; - $.each(jsonData, function(key, value) { - var groupName = 'no-group'; - if(key.indexOf('group') !== -1 ) { - groupName = '#' + key; - $('#sections-list').append(generateGroup(key, "Unnamed Group", false)); - $.each(value, function(sectionKey, sectionValue) { - if (sectionKey === 'title') { - giveGroupTitle(groupName, sectionValue); - } else { - generateInputTag(sectionValue.type, sectionValue.value, function(result) { - var li = generateSection(sectionKey, sectionValue.type, result); - $(groupName).find(".section-group").append(li); - reorderSectionsBasedOnIds(groupName); - if (!--count) { callback(); } + if (!jsonData || JSON.stringify(jsonData) === "{}") { + newGroup(); + callback(); + } else { + /* + * The count variable is used to ensure that this whole block flows synchronously. + * Otherwise, callback will fire early or multiple times. + * This is a hacky way to do this and if you have a better idea, please feel free + * to implement. + */ + var count = 0; + $.each(jsonData, function (key, value) { + $.each(value, function (sectionKey, sectionValue) { + count++; }); - } }); - } else { - throw "Invalid JSON: " + jsonData; - } - }); - } + // Subtract group names from count. + count -= Object.keys(jsonData).length; + $.each(jsonData, function (key, value) { + var groupName = "no-group"; + if (key.indexOf("group") !== -1) { + groupName = "#" + key; + $("#sections-list").append( + generateGroup(key, "Unnamed Group", false) + ); + $.each(value, function (sectionKey, sectionValue) { + if (sectionKey === "title") { + giveGroupTitle(groupName, sectionValue); + } else { + generateInputTag( + sectionValue.type, + sectionValue.value, + function (result) { + var li = generateSection( + sectionKey, + sectionValue.type, + result + ); + $(groupName).find(".section-group").append(li); + reorderSectionsBasedOnIds(groupName); + if (!--count) { + callback(); + } + } + ); + } + }); + } else { + throw "Invalid JSON: " + jsonData; + } + }); + } } function populate() { - $('#config-selector').change(function() { - window.location = this.value; - }); - if(!$('#configId').val()) { - return; - } - $('#save-export-config-button').on('click', function() { - saveJSON(); - }); - $('#reset-export-config-button').on('click', function() { - reset(); - }); - $('#delete-export-config-button').on('click', function() { - deleteConfig($('#configId').val()); - }); - $('#show-hide-export-config-groups-button').on('click', function() { - showHide(); - }); - - loading = true; - $.ajax({ - url: $('#config-body').data('latest-url'), - type: "GET", - dataType: "JSON", - success: function(data) { - buildList(data, function() { - renameGroups(); - resetEventListeners(); - loading = false; - $('.error-message').removeClass('error'); - $('.error-message').addClass('hidden'); - }); + $("#config-selector").change(function () { + window.location = this.value; + }); + if (!$("#configId").val()) { + return; } - }); + $("#save-export-config-button").on("click", function () { + saveJSON(); + }); + $("#reset-export-config-button").on("click", function () { + reset(); + }); + $("#delete-export-config-button").on("click", function () { + deleteConfig($("#configId").val()); + }); + $("#show-hide-export-config-groups-button").on("click", function () { + showHide(); + }); - // hide error message. - $('.error-message').addClass('hidden'); + loading = true; + $.ajax({ + url: $("#config-body").data("latest-url"), + type: "GET", + dataType: "JSON", + success: function (data) { + buildList(data, function () { + renameGroups(); + resetEventListeners(); + loading = false; + $(".error-message").removeClass("error"); + $(".error-message").addClass("hidden"); + }); + }, + }); + + // hide error message. + $(".error-message").addClass("hidden"); } // ----- HELPERS ------- // function reorderSectionsBasedOnIds(groupId) { - var sections = $(groupId).find('.section').toArray(); - sections.sort(function(a, b) { - var aId = parseInt(a['id'].substring(7)); - var bId = parseInt(b['id'].substring(7)); - return aId - bId; - }); - $(groupId).find('.section-group').empty().append(sections); + var sections = $(groupId).find(".section").toArray(); + sections.sort(function (a, b) { + var aId = parseInt(a["id"].substring(7)); + var bId = parseInt(b["id"].substring(7)); + return aId - bId; + }); + $(groupId).find(".section-group").empty().append(sections); } function reset() { - $('#sections-list').html(''); - populate(); - $('.error-message').removeClass('success error'); - $('.error-message').addClass('hidden'); + $("#sections-list").html(""); + populate(); + $(".error-message").removeClass("success error"); + $(".error-message").addClass("hidden"); } function hasTOC(input) { - return ($($(input).parent().children(".toc")[0]).val() !== ''); + return $($(input).parent().children(".toc")[0]).val() !== ""; } function isTOC(input) { - return ($(input).hasClass('toc')); + return $(input).hasClass("toc"); } function resetEventListeners() { - $( "#sections-list" ).sortable({ - stop: function( event, ui ) {} - }); - $( "#sections-list .group" ).find('.section-group').sortable({ - stop: function( event, ui ) {} - }); - - // Add event listeners for value changes. - // I will never understand why javascript doesn't do this for us. - $('.section-input').change(function() { - $(this).attr('value', $(this).val()); - if ($(this).parent().parent().html().indexOf('Type: h1') !== -1) { - $('#sections-list .new').removeClass('new'); - if ( (!isTOC(this) && !hasTOC(this)) || isTOC(this)) { - giveGroupTitle(this, $(this).val()); + $("#sections-list").sortable({ + stop: function (event, ui) {}, + }); + $("#sections-list .group") + .find(".section-group") + .sortable({ + stop: function (event, ui) {}, + }); + + // Add event listeners for value changes. + // I will never understand why javascript doesn't do this for us. + $(".section-input").change(function () { + $(this).attr("value", $(this).val()); + if ($(this).parent().parent().html().indexOf("Type: h1") !== -1) { + $("#sections-list .new").removeClass("new"); + if ((!isTOC(this) && !hasTOC(this)) || isTOC(this)) { + giveGroupTitle(this, $(this).val()); + renameGroups(); + } + } + }); + $(".filter-input").change(function () { + $(this).attr("value", $(this).val()); + }); + $(".section-dropdown").change(function () { + $(this).attr("value", $(this).val()); + }); + $("#sections-list").on("sortstop", function (event, ui) { + // TODO - is there really any reason to rename groups and sections? As long + // as their ids are unique do they really need to be in order? renameGroups(); - } - } - }); - $('.filter-input').change(function() { - $(this).attr('value', $(this).val()); - }); - $('.section-dropdown').change(function() { - $(this).attr('value', $(this).val()); - }); - $( "#sections-list" ).on( "sortstop", function(event, ui) { - // TODO - is there really any reason to rename groups and sections? As long - // as their ids are unique do they really need to be in order? - renameGroups(); - renameSections(); - }); - $( "#sections-list .group" ).on( "sortstop", function(event, ui) { - // TODO - is there really any reason to rename groups and sections? As long - // as their ids are unique do they really need to be in order? - renameGroups(); - renameSections(); - }); - - // Attach handlers to buttons based on class. - $('.group-toggle-description').unbind('click').on('click', function () { - toggleGroup(this); - }); - $('.add-group-below').unbind('click').on('click', function () { - newGroup(this); - }); - $('.button-section-add').unbind('click').on('click', function () { - newSection(this); - }); - $('.button-delete-section').unbind('click').on('click', function () { - deleteSection(this); - }); - $('.button-delete-group').unbind('click').on('click', function () { - deleteGroup(this); - }); - $('.button-confirm-delete').unbind('click').on('click', function () { - confirmDelete($(this).data('config-id')); - }); - $('.button-cancel-delete').unbind('click').on('click', function () { - cancelDelete(); - }); - $('.select-section-type').unbind('click').on('click', function () { - defineSection(this); - }); + renameSections(); + }); + $("#sections-list .group").on("sortstop", function (event, ui) { + // TODO - is there really any reason to rename groups and sections? As long + // as their ids are unique do they really need to be in order? + renameGroups(); + renameSections(); + }); + // Attach handlers to buttons based on class. + $(".group-toggle-description") + .unbind("click") + .on("click", function () { + toggleGroup(this); + }); + $(".add-group-below") + .unbind("click") + .on("click", function () { + newGroup(this); + }); + $(".button-section-add") + .unbind("click") + .on("click", function () { + newSection(this); + }); + $(".button-delete-section") + .unbind("click") + .on("click", function () { + deleteSection(this); + }); + $(".button-delete-group") + .unbind("click") + .on("click", function () { + deleteGroup(this); + }); + $(".button-confirm-delete") + .unbind("click") + .on("click", function () { + confirmDelete($(this).data("config-id")); + }); + $(".button-cancel-delete") + .unbind("click") + .on("click", function () { + cancelDelete(); + }); + $(".select-section-type") + .unbind("click") + .on("click", function () { + defineSection(this); + }); } function showHide() { - var groups = $('#sections-list .group').toArray(); - var visible = true; - groups.forEach(function(element, index) { - if(index === 0) { - visible = $(element).find('.section-group').hasClass('visible'); - } + var groups = $("#sections-list .group").toArray(); + var visible = true; + groups.forEach(function (element, index) { + if (index === 0) { + visible = $(element).find(".section-group").hasClass("visible"); + } - if (!visible) { - $(element).find('.section-group').addClass('visible'); - $(element).find('.group-controls').removeClass('hidden'); - } else { - $(element).find('.section-group').removeClass('visible'); - $(element).find('.group-controls').addClass('hidden'); - } - }); + if (!visible) { + $(element).find(".section-group").addClass("visible"); + $(element).find(".group-controls").removeClass("hidden"); + } else { + $(element).find(".section-group").removeClass("visible"); + $(element).find(".group-controls").addClass("hidden"); + } + }); } function validateInput(id, type, value, callback) { - // Strip ""s around value. - value = value.substring(1, value.length - 1); - switch(type) { - case 'h1': - case 'h2': - callback(); - // var validCharacters = /^[\/*.?!,;:()&" 0-9a-zA-Z]+$/; - // if (validCharacters.test(value)) { - // callback(); - // } else { - // callback("Headers may only contain letters, numbers, .,?!\&;:(), and double quotes (\"\").", id); - //} - break; - case 'page_content': - var validURL = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/; - if (validURL.test(value)) { - callback(); - } else { - callback("Please enter a valid URL. Example: http://catalog.middlebury.edu/spanish", id); - } - break; - case 'custom_text': - callback(); - break; - case 'course_list': - if(value === "unselected") { - callback('Please select a course from the course list', id); - } else { - callback(); - } - break; - default: - callback("Invalid input type. I have no idea how you accomplished this.", id); - } -} - -// ------ SAVE -------- // - -function saveJSON() { - if(loading) { - $('.error-message').html("

    Still loading data... Please wait.

    "); - $('.error-message').removeClass('hidden success'); - $('.error-message').addClass('error'); - return; - } - var completelyValid = true; - var JSONString = "{"; - - var groups = $('#sections-list .group').toArray(); - groups.forEach(function(element, index) { - var groupId = element['id']; - JSONString += "\"" + groupId + "\":{"; - - var groupTitle = $(element).find('.group-title')[0].innerHTML; - JSONString += "\"title\":\"" + groupTitle + "\","; - - var sections = $(element).find('.section').toArray(); - sections.forEach(function(element, index) { - if (!completelyValid) return; - - var sectionId = element['id']; - var section = $(element); - var sectionType = section.find('.section-type')[0].innerHTML.substring(section.find('.section-type')[0].innerHTML.indexOf(': ') + 2); - var sectionValue = ''; - switch(sectionType) { + // Strip ""s around value. + value = value.substring(1, value.length - 1); + switch (type) { case "h1": case "h2": - sectionValue = $($($(element).find('.section-value')[0]).find('input')[0]).val(); - var toc = $($($(element).find('.section-value')[0]).find('input')[1]).val(); - if (toc) { - sectionValue += ";" + toc; - } - break; + callback(); + // var validCharacters = /^[\/*.?!,;:()&" 0-9a-zA-Z]+$/; + // if (validCharacters.test(value)) { + // callback(); + // } else { + // callback("Headers may only contain letters, numbers, .,?!\&;:(), and double quotes (\"\").", id); + //} + break; + case "page_content": + var validURL = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/; + if (validURL.test(value)) { + callback(); + } else { + callback( + "Please enter a valid URL. Example: http://catalog.middlebury.edu/spanish", + id + ); + } + break; case "custom_text": - sectionValue = $($($(element).find('.section-value')[0]).find('textarea')[0]).val(); - sectionValue = sectionValue.replace(/(?:\r\n|\r|\n)/g, '\\n'); - sectionValue = sectionValue.replace(/\"/g, '"'); - break; + callback(); + break; case "course_list": - sectionValue = $($($(element).find('.section-value')[0]).find('select')[0]).val(); - if ($(element).find('.filter-input').val()) { - var filters = $(element).find('.filter-input').val(); - // Remove trailing " - //sectionValue = sectionValue.substring(0, sectionValue.length - 1); - sectionValue += "," + filters; - } - break; + if (value === "unselected") { + callback("Please select a course from the course list", id); + } else { + callback(); + } + break; default: - sectionValue = $($($(element).find('.section-value')[0]).find('input')[0]).val(); - break; - } - - sectionValue = "\"" + sectionValue + "\""; - - validateInput(sectionId, sectionType, sectionValue, function(error, sectionId) { - if(error) { - $('.error-message').html("

    Error: " + error + "

    "); - $('.error-message').addClass('error'); - $('.error-message').removeClass('hidden success'); - $("#" + sectionId).css('background', '#f95757'); - completelyValid = false; - } else { - $('.error-message').addClass('hidden'); - JSONString += "\"section" + eval(index + 1) + "\":{\"type\":\"" + sectionType +"\",\"value\":" + sectionValue + "},"; - completelyValid = true; - } - }); - }); - - // Remove trailing , - JSONString = JSONString.substring(0, JSONString.length - 1); + callback( + "Invalid input type. I have no idea how you accomplished this.", + id + ); + } +} - JSONString += "},"; - }); +// ------ SAVE -------- // - if (completelyValid) { - $('.section').css('background', '#b5c5dd'); +function saveJSON() { + if (loading) { + $(".error-message").html("

    Still loading data... Please wait.

    "); + $(".error-message").removeClass("hidden success"); + $(".error-message").addClass("error"); + return; + } + var completelyValid = true; + var JSONString = "{"; + + var groups = $("#sections-list .group").toArray(); + groups.forEach(function (element, index) { + var groupId = element["id"]; + JSONString += '"' + groupId + '":{'; + + var groupTitle = $(element).find(".group-title")[0].innerHTML; + JSONString += '"title":"' + groupTitle + '",'; + + var sections = $(element).find(".section").toArray(); + sections.forEach(function (element, index) { + if (!completelyValid) return; + + var sectionId = element["id"]; + var section = $(element); + var sectionType = section + .find(".section-type")[0] + .innerHTML.substring( + section.find(".section-type")[0].innerHTML.indexOf(": ") + 2 + ); + var sectionValue = ""; + switch (sectionType) { + case "h1": + case "h2": + sectionValue = $( + $($(element).find(".section-value")[0]).find("input")[0] + ).val(); + var toc = $( + $($(element).find(".section-value")[0]).find("input")[1] + ).val(); + if (toc) { + sectionValue += ";" + toc; + } + break; + case "custom_text": + sectionValue = $( + $($(element).find(".section-value")[0]).find( + "textarea" + )[0] + ).val(); + sectionValue = sectionValue.replace( + /(?:\r\n|\r|\n)/g, + "\\n" + ); + sectionValue = sectionValue.replace(/\"/g, """); + break; + case "course_list": + sectionValue = $( + $($(element).find(".section-value")[0]).find( + "select" + )[0] + ).val(); + if ($(element).find(".filter-input").val()) { + var filters = $(element).find(".filter-input").val(); + // Remove trailing " + //sectionValue = sectionValue.substring(0, sectionValue.length - 1); + sectionValue += "," + filters; + } + break; + default: + sectionValue = $( + $($(element).find(".section-value")[0]).find("input")[0] + ).val(); + break; + } - // Remove trailing , - JSONString = JSONString.substring(0, JSONString.length - 1); - JSONString += "}"; + sectionValue = '"' + sectionValue + '"'; + + validateInput(sectionId, sectionType, sectionValue, function ( + error, + sectionId + ) { + if (error) { + $(".error-message").html("

    Error: " + error + "

    "); + $(".error-message").addClass("error"); + $(".error-message").removeClass("hidden success"); + $("#" + sectionId).css("background", "#f95757"); + completelyValid = false; + } else { + $(".error-message").addClass("hidden"); + JSONString += + '"section' + + eval(index + 1) + + '":{"type":"' + + sectionType + + '","value":' + + sectionValue + + "},"; + completelyValid = true; + } + }); + }); - // Ensure valid JSON if no sections are present. - if(JSONString === "}") JSONString = "{}"; + // Remove trailing , + JSONString = JSONString.substring(0, JSONString.length - 1); - $.ajax({ - url: "../exports/" + $('#configId').attr('value') + "/insertrevision", - type: "POST", - dataType: 'json', - data: { - note: $('#note').val(), - jsonData: JSONString - }, - error: function(error) { - console.log(error); - }, - success: function(data) { - $('.error-message').html("

    Saved successfully

    "); - $('.error-message').removeClass('hidden error'); - $('.error-message').addClass('success'); - setTimeout(function() { - $('.error-message').addClass('hidden'); - $('.error-message').removeClass('success'); - }, 5000); - } + JSONString += "},"; }); - } + + if (completelyValid) { + $(".section").css("background", "#b5c5dd"); + + // Remove trailing , + JSONString = JSONString.substring(0, JSONString.length - 1); + JSONString += "}"; + + // Ensure valid JSON if no sections are present. + if (JSONString === "}") JSONString = "{}"; + + $.ajax({ + url: + "../exports/" + + $("#configId").attr("value") + + "/insertrevision", + type: "POST", + dataType: "json", + data: { + note: $("#note").val(), + jsonData: JSONString, + }, + error: function (error) { + console.log(error); + }, + success: function (data) { + $(".error-message").html("

    Saved successfully

    "); + $(".error-message").removeClass("hidden error"); + $(".error-message").addClass("success"); + setTimeout(function () { + $(".error-message").addClass("hidden"); + $(".error-message").removeClass("success"); + }, 5000); + }, + }); + } } // ------ CONFIGS ------- // function deleteConfig(configId) { - if($('#warning-box').length) return; - $('#config-body').append("

    Are you sure you want to delete this configuration? This cannot be undone. All related revisions will be gone as well.

    "); - resetEventListeners(); + if ($("#warning-box").length) return; + $("#config-body").append( + "

    Are you sure you want to delete this configuration? This cannot be undone. All related revisions will be gone as well.

    " + ); + resetEventListeners(); } function confirmDelete(confId) { - $.ajax({ - url: "../exports/" + configId + "/deleteconfig", - type: "POST", - data: { - configId: confId - }, - error: function(error) { - console.log(error); - }, - success: function(data) { - location.reload(true); - } - }); + $.ajax({ + url: "../exports/" + configId + "/deleteconfig", + type: "POST", + data: { + configId: confId, + }, + error: function (error) { + console.log(error); + }, + success: function (data) { + location.reload(true); + }, + }); } function cancelDelete() { - $('#warning-box').remove(); + $("#warning-box").remove(); } // ------ GROUPS ------- // function giveGroupTitle(selector, value) { - $(selector).closest('#sections-list .group').find('.group-title')[0].innerHTML = value; + $(selector) + .closest("#sections-list .group") + .find(".group-title")[0].innerHTML = value; } function renameGroups() { - $('#sections-list .group').toArray().forEach(function(element, index) { - $(element).attr('id', 'group' + eval(index + 1)); - }); + $("#sections-list .group") + .toArray() + .forEach(function (element, index) { + $(element).attr("id", "group" + eval(index + 1)); + }); } function toggleGroup(button) { - $(button).closest('#sections-list .group').find('.section-group').toggleClass('visible'); - $(button).closest('#sections-list .group').find('.group-controls').toggleClass('hidden'); + $(button) + .closest("#sections-list .group") + .find(".section-group") + .toggleClass("visible"); + $(button) + .closest("#sections-list .group") + .find(".group-controls") + .toggleClass("hidden"); } function newGroup(thisButton) { - // Only allow user to create one group at a time. - if ($('#sections-list .new').length) return; - - var newgenerateGroup = generateGroup('temp', 'Please fill out an h1 section to give this group a name', true); - - if(!thisButton) { - if($('#begin-message')) { - $('#begin-message').remove(); + // Only allow user to create one group at a time. + if ($("#sections-list .new").length) return; + + var newgenerateGroup = generateGroup( + "temp", + "Please fill out an h1 section to give this group a name", + true + ); + + if (!thisButton) { + if ($("#begin-message")) { + $("#begin-message").remove(); + } + $("#sections-list").append(newgenerateGroup); + } else { + var li = $(thisButton).parent().parent(); + $(newgenerateGroup).insertAfter(li); } - $('#sections-list').append(newgenerateGroup); - } else { - var li = $(thisButton).parent().parent(); - $(newgenerateGroup).insertAfter(li); - } - $('#temp').addClass('new'); + $("#temp").addClass("new"); - // Create h1 section. - newGroupFirstSection(); + // Create h1 section. + newGroupFirstSection(); } function deleteGroup(thisButton) { - $(thisButton).closest('#sections-list .group').remove(); - if ($('#sections-list').find('.group').length === 0) { - newGroup(); - } + $(thisButton).closest("#sections-list .group").remove(); + if ($("#sections-list").find(".group").length === 0) { + newGroup(); + } - renameGroups(); + renameGroups(); } // ------ SECTIONS ----- // function renameSections() { - $('.section').toArray().forEach(function(element, index) { - $(element).attr('id', 'section' + eval(index + 1)); - }); + $(".section") + .toArray() + .forEach(function (element, index) { + $(element).attr("id", "section" + eval(index + 1)); + }); } function newGroupFirstSection() { - generateInputTag('h1', '', function(input) { - var newSectionHTML = "
  • " + generateSectionHTML('h1', input) + "
  • "; - $('#sections-list .new').children("ul").append(newSectionHTML); - resetEventListeners(); - }); + generateInputTag("h1", "", function (input) { + var newSectionHTML = + "
  • " + + generateSectionHTML("h1", input) + + "
  • "; + $("#sections-list .new").children("ul").append(newSectionHTML); + resetEventListeners(); + }); } function newSection(thisButton) { - var newSectionHTML = "
  • "; - if(!thisButton) { - if($('#begin-message')) { - $('#begin-message').remove(); + var newSectionHTML = + "
  • "; + if (!thisButton) { + if ($("#begin-message")) { + $("#begin-message").remove(); + } + $("#sections-list").append(newSectionHTML); + } else { + var li = $(thisButton).parent().parent(); + $(newSectionHTML).insertAfter(li); } - $('#sections-list').append(newSectionHTML); - } else { - var li = $(thisButton).parent().parent(); - $(newSectionHTML).insertAfter(li); - } - resetEventListeners(); - renameSections(); + resetEventListeners(); + renameSections(); } function defineSection(select) { - var sectionType = $(select).val(); - var li = $(select).parent(); + var sectionType = $(select).val(); + var li = $(select).parent(); - generateInputTag(sectionType, '', function(result) { - $(li).html(generateSectionHTML(sectionType, result)); + generateInputTag(sectionType, "", function (result) { + $(li).html(generateSectionHTML(sectionType, result)); - resetEventListeners(); - }); + resetEventListeners(); + }); } function deleteSection(thisButton) { - if ($(thisButton).closest('#sections-list .group').find('.section').length === 1) { - deleteGroup(thisButton); - } else { - $(thisButton).closest('.section').remove(); - } - renameSections(); + if ( + $(thisButton).closest("#sections-list .group").find(".section") + .length === 1 + ) { + deleteGroup(thisButton); + } else { + $(thisButton).closest(".section").remove(); + } + renameSections(); } -$(document).ready(function() { - populate(); - resetEventListeners(); +$(document).ready(function () { + populate(); + resetEventListeners(); }); diff --git a/assets/export_revision_diff.js b/assets/export_revision_diff.js index 1b3078ab..911cf984 100644 --- a/assets/export_revision_diff.js +++ b/assets/export_revision_diff.js @@ -1,38 +1,54 @@ -import 'diff2html/bundles/css/diff2html.min.css'; -import './styles/export.css'; -import $ from 'jquery'; -import 'jquery-ui'; +import "diff2html/bundles/css/diff2html.min.css"; +import "./styles/export.css"; +import $ from "jquery"; +import "jquery-ui"; // import { Diff2Html } from 'diff2html'; -import Diff2HtmlUI from 'diff2html/bundles/js/diff2html-ui.min.js'; -import * as Diff from 'diff'; +import Diff2HtmlUI from "diff2html/bundles/js/diff2html-ui.min.js"; +import * as Diff from "diff"; function buildDiffView(text1, text2, label1, label2) { var changes = Diff.diffLines(text1, text2); if (changes.length > 1) { - const diff = Diff.createPatch('', text1, text2, label1, label2, { options: { context: 5} }); + const diff = Diff.createPatch("", text1, text2, label1, label2, { + options: { context: 5 }, + }); const configuration = { drawFileList: true, - matching: 'lines', - outputFormat: 'side-by-side', + matching: "lines", + outputFormat: "side-by-side", fileListToggle: false, fileListStartVisible: false, fileContentToggle: false, - container: document.createElement('div'), - diff2htmlUi:null, - highlight: true + container: document.createElement("div"), + diff2htmlUi: null, + highlight: true, }; - var diff2htmlUi = new Diff2HtmlUI.Diff2HtmlUI($('#diff').get(0), diff, configuration); + var diff2htmlUi = new Diff2HtmlUI.Diff2HtmlUI( + $("#diff").get(0), + diff, + configuration + ); diff2htmlUi.draw(); } else { - $('#diff').append("

    No difference in JSON data between these revisions

    "); + $("#diff").append( + "

    No difference in JSON data between these revisions

    " + ); } } -$(document).ready(function() { +$(document).ready(function () { buildDiffView( $("#rev1").val(), $("#rev2").val(), - "Revision #" + $("#rev1").data('rev-id') + " (" + $("#rev1").data('rev-date') + ")", - "Revision #" + $("#rev2").data('rev-id') + " (" + $("#rev2").data('rev-date') + ")", + "Revision #" + + $("#rev1").data("rev-id") + + " (" + + $("#rev1").data("rev-date") + + ")", + "Revision #" + + $("#rev2").data("rev-id") + + " (" + + $("#rev2").data("rev-date") + + ")" ); }); diff --git a/assets/export_revision_history.js b/assets/export_revision_history.js index c54f99d9..bc5f8105 100644 --- a/assets/export_revision_history.js +++ b/assets/export_revision_history.js @@ -1,66 +1,87 @@ -import './styles/export.css'; -import $ from 'jquery'; -import 'jquery-ui'; +import "./styles/export.css"; +import $ from "jquery"; +import "jquery-ui"; var selected = []; function sortSelected() { - selected.sort(function(a, b) { - // if a timestamp later than b timestamp - var dateA = new Date($('#' + a).parents('tr').find('.timestamp')[0].innerText); - var dateB = new Date($('#' + b).parents('tr').find('.timestamp')[0].innerText); - if (dateA < dateB) { - return -1; - } else if (dateA === dateB) { - return 0; - } else { - return 1; - } - }); + selected.sort(function (a, b) { + // if a timestamp later than b timestamp + var dateA = new Date( + $("#" + a) + .parents("tr") + .find(".timestamp")[0].innerText + ); + var dateB = new Date( + $("#" + b) + .parents("tr") + .find(".timestamp")[0].innerText + ); + if (dateA < dateB) { + return -1; + } else if (dateA === dateB) { + return 0; + } else { + return 1; + } + }); } function compare(url) { - sortSelected(); - var rev1 = $($('#' + selected[0]).parents('tr').find('.revId')[0]).val(); - var rev2 = $($('#' + selected[1]).parents('tr').find('.revId')[0]).val(); - if(!rev1 || !rev2) return; - var win = window.open(url.replace(/-rev1-/, rev1).replace(/-rev2-/, rev2), '_blank'); - win.focus(); + sortSelected(); + var rev1 = $( + $("#" + selected[0]) + .parents("tr") + .find(".revId")[0] + ).val(); + var rev2 = $( + $("#" + selected[1]) + .parents("tr") + .find(".revId")[0] + ).val(); + if (!rev1 || !rev2) return; + var win = window.open( + url.replace(/-rev1-/, rev1).replace(/-rev2-/, rev2), + "_blank" + ); + win.focus(); } function renderSelected() { - $('input[type=radio]').prop('checked', false); - selected.forEach(function(element) { $('#' + element).prop('checked', true); }); + $("input[type=radio]").prop("checked", false); + selected.forEach(function (element) { + $("#" + element).prop("checked", true); + }); } function revertTo(url, revId) { - $.ajax({ - url: url, - type: "POST", - data: { - revId: revId - }, - success: function(data) { - location.reload(); - }, - error: function(error) { - throw error; - } - }); + $.ajax({ + url: url, + type: "POST", + data: { + revId: revId, + }, + success: function (data) { + location.reload(); + }, + error: function (error) { + throw error; + }, + }); } -$(document).ready(function() { - $('input[type=radio]').change(function() { - selected.push(this.id); - if (selected.length > 2) selected.shift(); - renderSelected(); - }); +$(document).ready(function () { + $("input[type=radio]").change(function () { + selected.push(this.id); + if (selected.length > 2) selected.shift(); + renderSelected(); + }); - $('.compare-revisions-button').on('click', function() { - compare($(this).data('url')); - }); + $(".compare-revisions-button").on("click", function () { + compare($(this).data("url")); + }); - $('.revert-button').on('click', function() { - revertTo($(this).data('url'), $(this).data('rev-id')); - }); + $(".revert-button").on("click", function () { + revertTo($(this).data("url"), $(this).data("rev-id")); + }); }); diff --git a/assets/offering_search.js b/assets/offering_search.js index db661b15..a5e7d0a2 100644 --- a/assets/offering_search.js +++ b/assets/offering_search.js @@ -1,13 +1,13 @@ -import './styles/offering_search.css'; -import $ from 'jquery'; -import expander from 'jquery-expander'; +import "./styles/offering_search.css"; +import $ from "jquery"; +import expander from "jquery-expander"; expander($); -$('document').ready(function() { - $('div.description').expander({ - slicePoint: 140, // default is 100 - expandPrefix: '... ', // text to come before the expand link - expandText: 'read more', // default is 'read more...' - userCollapseText: '[collapse]' // default is '[collapse expanded text]' +$("document").ready(function () { + $("div.description").expander({ + slicePoint: 140, // default is 100 + expandPrefix: "... ", // text to come before the expand link + expandText: "read more", // default is 'read more...' + userCollapseText: "[collapse]", // default is '[collapse expanded text]' }); }); diff --git a/assets/schedules.js b/assets/schedules.js index c1aff967..f090b541 100755 --- a/assets/schedules.js +++ b/assets/schedules.js @@ -1,44 +1,42 @@ -import './jquery-ui/jquery-ui.css' -import '@toast-ui/calendar/dist/toastui-calendar.min.css'; -import './styles/schedules.css'; -import $ from 'jquery'; -import 'jquery-ui'; -import './email_controls.js'; -import Calendar from '@toast-ui/calendar'; - -$('document').ready(function() { - - $('#schedules_term_choice select').change(function () { +import "./jquery-ui/jquery-ui.css"; +import "@toast-ui/calendar/dist/toastui-calendar.min.css"; +import "./styles/schedules.css"; +import $ from "jquery"; +import "jquery-ui"; +import "./email_controls.js"; +import Calendar from "@toast-ui/calendar"; + +$("document").ready(function () { + $("#schedules_term_choice select").change(function () { window.location = $(this).val(); }); $("a.remove_course").click(function () { - if (confirm('Do you want to remove the bookmark for this course?')) { - var li = $(this).parents('li.bookmarked_course'); + if (confirm("Do you want to remove the bookmark for this course?")) { + var li = $(this).parents("li.bookmarked_course"); $.ajax({ - url: $(this).attr('href'), + url: $(this).attr("href"), success: function () { li.remove(); - } + }, }); } return false; }); - /********************************************************* * Set up the add-sections dialog controls *********************************************************/ $(".add_section_dialog").each(function () { var form = $(this).siblings("form.add_to_schedule_form"); var addDialog = $(this).dialog({ - autoOpen: false, - width: 600, - modal: true, - close: function(event, ui) { - $(this).find("select.section_set").empty(); - } - }); + autoOpen: false, + width: 600, + modal: true, + close: function (event, ui) { + $(this).find("select.section_set").empty(); + }, + }); form.data("addDialog", addDialog); }); @@ -54,12 +52,16 @@ $('document').ready(function() { addDialog.dialog("open"); }); - $('form.delete_schedule').submit(function () { - return confirm('Are you sure you want to delete this schedule?'); + $("form.delete_schedule").submit(function () { + return confirm("Are you sure you want to delete this schedule?"); }); - $('a.print_button').click(function() { - var printView = window.open(this.href, this.target, "menubar=1,resizable=1,height=600,width=800,scrollbars=1"); + $("a.print_button").click(function () { + var printView = window.open( + this.href, + this.target, + "menubar=1,resizable=1,height=600,width=800,scrollbars=1" + ); printView.focus(); return false; }); @@ -67,36 +69,36 @@ $('document').ready(function() { /********************************************************* * Remove dialog controls *********************************************************/ - $(".remove_dialog").each(function() { + $(".remove_dialog").each(function () { var button = $(this).siblings(".remove_button"); var removeDialog = $(this).dialog({ - autoOpen: false, - width: 600, - modal: true - }); + autoOpen: false, + width: 600, + modal: true, + }); button.data("removeDialog", removeDialog); }); - $(".remove_button").click(function(){ - var removeDialog = $(this).data('removeDialog'); + $(".remove_button").click(function () { + var removeDialog = $(this).data("removeDialog"); removeDialog.dialog("open"); }); - $(".remove_dialog .cancel").click(function() { - $(this).parent().dialog('close'); + $(".remove_dialog .cancel").click(function () { + $(this).parent().dialog("close"); }); $(".change_section_dialog").each(function () { var button = $(this).siblings(".change_sections_button"); var addDialog = $(this).dialog({ - autoOpen: false, - width: 600, - modal: true, - close: function(event, ui) { - $(this).find("ul.section_sets").empty(); - } - }); + autoOpen: false, + width: 600, + modal: true, + close: function (event, ui) { + $(this).find("ul.section_sets").empty(); + }, + }); button.data("addDialog", addDialog); }); @@ -116,62 +118,70 @@ $('document').ready(function() { /********************************************************* * Calendar controls *********************************************************/ - $(".calendar").each(function() { + $(".calendar").each(function () { var button = $(this).siblings(".calendar_button"); var calendar = $(this).dialog({ - autoOpen: false, - width: 900, - modal: true, - }); + autoOpen: false, + width: 900, + modal: true, + }); button.data("calendar", calendar); }); - $(".calendar_button").click(function(){ - alert('not yet re-implemented. Needs a new calendar library.'); + $(".calendar_button").click(function () { + alert("not yet re-implemented. Needs a new calendar library."); return false; - var jsonUrl = $(this).attr('href'); - var calendar = $(this).data('calendar'); + var jsonUrl = $(this).attr("href"); + var calendar = $(this).data("calendar"); calendar.dialog("open"); - if (!calendar.data('initialized')) { + if (!calendar.data("initialized")) { renderSchedule(calendar, jsonUrl); - calendar.data('initialized', true); + calendar.data("initialized", true); } return false; }); // Render the #calender item on a page if it exists (such as on preview) - $("#calendar").each(function() { - renderSchedule($(this), $(this).children('input[name=jsonUrl]').val(), 45, 11); + $("#calendar").each(function () { + renderSchedule( + $(this), + $(this).children("input[name=jsonUrl]").val(), + 45, + 11 + ); }); - }); function renderSchedule(calendarElement, jsonUrl, timeslotHeight, textSize) { - if (!timeslotHeight) - timeslotHeight = 20; - if (!textSize) - textSize = 13; + if (!timeslotHeight) timeslotHeight = 20; + if (!textSize) textSize = 13; var year = new Date().getFullYear(); var month = new Date().getMonth(); var day = new Date().getDate(); - var startHour = new Number(calendarElement.find('input:hidden[name=start_hour]').val()); - var endHour = new Number(calendarElement.find('input:hidden[name=end_hour]').val()); - - var scheduleHeight = ((endHour - startHour + 1) * timeslotHeight) + 45; - calendarElement.css({height: scheduleHeight + "px"}); + var startHour = new Number( + calendarElement.find("input:hidden[name=start_hour]").val() + ); + var endHour = new Number( + calendarElement.find("input:hidden[name=end_hour]").val() + ); + var scheduleHeight = (endHour - startHour + 1) * timeslotHeight + 45; + calendarElement.css({ height: scheduleHeight + "px" }); var showWeekend = true; - if (calendarElement.find('input:hidden[name=show_sunday]').val() == 'no' && calendarElement.find('input:hidden[name=show_saturday]').val() == 'no') { + if ( + calendarElement.find("input:hidden[name=show_sunday]").val() == "no" && + calendarElement.find("input:hidden[name=show_saturday]").val() == "no" + ) { showWeekend = false; } - const formatTime = function(date) { + const formatTime = function (date) { var hours = date.getHours(); var minutes = date.getMinutes(); var meridian = "am"; @@ -181,86 +191,113 @@ function renderSchedule(calendarElement, jsonUrl, timeslotHeight, textSize) { hours = hours - 12; } } - return hours + ":" + minutes.toString().padStart(2, '0') + " " + meridian; - } + return ( + hours + ":" + minutes.toString().padStart(2, "0") + " " + meridian + ); + }; $.getJSON(jsonUrl, function (data) { console.log(data); - const calendar = new Calendar( - calendarElement.get(0), - { - defaultView: 'week', - usageStatistics: false, - isReadOnly: true, + const calendar = new Calendar(calendarElement.get(0), { + defaultView: "week", + usageStatistics: false, + isReadOnly: true, + week: { + taskView: false, + eventView: ["time"], + hourStart: startHour, + hourEnd: endHour, + dayNames: [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ], + showNowIndicator: false, + workweek: !showWeekend, + }, + theme: { week: { - taskView: false, - eventView: ['time'], - hourStart: startHour, - hourEnd: endHour, - dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], - showNowIndicator: false, - workweek: !showWeekend, - }, - theme: { - week: { - today: { - color: 'black', - backgroundColor: 'transparent', - }, - pastDay: { - color: 'black', - }, + today: { + color: "black", + backgroundColor: "transparent", + }, + pastDay: { + color: "black", }, - common: { - holiday: { - color: 'black', - } - } }, - calendars: [ - { - id: 'sections', - name: 'Sections', - backgroundColor: '#03bd9e', - } - ], - template: { - time(event) { - - return `
    ${formatTime(event.start)} - ${formatTime(event.end)}
    ${event.title}
    ${event.location} - CRN: ${event.raw.crn}
    `; + common: { + holiday: { + color: "black", }, - } - } - ); + }, + }, + calendars: [ + { + id: "sections", + name: "Sections", + backgroundColor: "#03bd9e", + }, + ], + template: { + time(event) { + return `
    ${formatTime( + event.start + )} - ${formatTime( + event.end + )}
    ${ + event.title + }
    ${ + event.location + } - CRN: ${event.raw.crn}
    `; + }, + }, + }); console.log(calendar); calendar.createEvents(data); }); - calendarElement.find('td.wc-day-column-header').each(function() { - $(this).html($(this).html().replace(/<.*$/, '')); + calendarElement.find("td.wc-day-column-header").each(function () { + $(this).html($(this).html().replace(/<.*$/, "")); }); - $('form.delete_schedule').submit(function () { - return confirm('Are you sure you want to delete this schedule?'); + $("form.delete_schedule").submit(function () { + return confirm("Are you sure you want to delete this schedule?"); }); - $('a.print_button').click(function() { - var printView = window.open(this.href, this.target, "menubar=1,resizable=1,height=600,width=800,scrollbars=1"); + $("a.print_button").click(function () { + var printView = window.open( + this.href, + this.target, + "menubar=1,resizable=1,height=600,width=800,scrollbars=1" + ); printView.focus(); return false; }); } -function getSectionSets (dialog, scheduleId) { +function getSectionSets(dialog, scheduleId) { var lookupUrl = dialog.children("input[name=section_lookup_url]").val(); var courseId = dialog.children("input[name=course_id]").val(); dialog.find("input[name=scheduleId]").val(scheduleId); - $.getJSON(lookupUrl, {course: courseId, scheduleId: scheduleId}, function (data, textStatus) { - populateSectionSetSelect(dialog, scheduleId, data); - populateSectionTypes(dialog, scheduleId, dialog.find("select.section_set").val(), data); - }); + $.getJSON( + lookupUrl, + { course: courseId, scheduleId: scheduleId }, + function (data, textStatus) { + populateSectionSetSelect(dialog, scheduleId, data); + populateSectionTypes( + dialog, + scheduleId, + dialog.find("select.section_set").val(), + data + ); + } + ); } function populateSectionSetSelect(dialog, scheduleId, data) { @@ -269,9 +306,9 @@ function populateSectionSetSelect(dialog, scheduleId, data) { var i = 0; for (var linkSetId in data) { i++; - var option = $(''); + var option = $('"); if (data[linkSetId].selected) { - option.attr('selected', 'selected'); + option.attr("selected", "selected"); } selectList.append(option); } @@ -281,23 +318,27 @@ function populateSectionSetSelect(dialog, scheduleId, data) { dialog.find("div.section_set").hide(); } - selectList.data('section_data', data); - selectList.data('dialog', dialog); - selectList.data('scheduleId', scheduleId); - selectList.change(function() { - populateSectionTypes($(this).data('dialog'), $(this).data('scheduleId'), $(this).val(), $(this).data('section_data')); + selectList.data("section_data", data); + selectList.data("dialog", dialog); + selectList.data("scheduleId", scheduleId); + selectList.change(function () { + populateSectionTypes( + $(this).data("dialog"), + $(this).data("scheduleId"), + $(this).val(), + $(this).data("section_data") + ); }); } -function populateSectionTypes (dialog, scheduleId, linkSetId, data) { - +function populateSectionTypes(dialog, scheduleId, linkSetId, data) { var typesList = dialog.find("ul.section_types"); typesList.empty(); var i = 0; - for (var linkTypeId in data[linkSetId]['types']) { - var sectionType = data[linkSetId]['types'][linkTypeId]; + for (var linkTypeId in data[linkSetId]["types"]) { + var sectionType = data[linkSetId]["types"][linkTypeId]; - var typeListItem = $('
  • '); + var typeListItem = $("
  • "); typesList.append(typeListItem); var typeList = $(''); typeListItem.append(typeList); @@ -307,26 +348,54 @@ function populateSectionTypes (dialog, scheduleId, linkSetId, data) { var item = $('
  • '); typeList.append(item); - var radio = $(''); + var radio = $( + '' + ); item.append(radio); if (section.selected) { - radio.attr('checked', 'checked'); + radio.attr("checked", "checked"); } - item.append(' '); + item.append(" "); item.append(section.name); - item.append('
    '+section.type+' - '+section.instructor+'
    '); - item.append(''); + item.append( + '
    ' + + section.type + + ' - ' + + section.instructor + + "
    " + ); + item.append(""); if (section.conflicts) { - var conflictsClass = ' conflicting'; - var conflictNames = '
        ' + section.conflictString; + var conflictsClass = " conflicting"; + var conflictNames = + "
        " + section.conflictString; } else { - var conflictsClass = ''; - var conflictNames = ''; + var conflictsClass = ""; + var conflictNames = ""; } - item.append('
    '+section.schedule+conflictNames+'
    '); - item.append('
    '+section.location+'
    '); + item.append( + '
    ' + + section.schedule + + conflictNames + + "
    " + ); + item.append( + '
    ' + + section.location + + "
    " + ); if (section.availability) { - item.append('
    '+section.availability+'
    '); + item.append( + '
    ' + + section.availability + + "
    " + ); } }