Customising your CourseSales.com administration portal with JavaScript

Friday, Jun 22, 2018

The JavaScript code CourseSales.com staff use by default for the administration portal is below. You can just copy and paste this into your own, making modifications where necessary. In fact you might be able to download your copy by visiting https://{shortname}.coursesales.com/co/{shortname}/csadmin.js

If this is the case then perhaps a file has been created for your already and it might have some customizations that you rely on! Don’t just overwrite it - be sure to take a backup.

// This is the modifications that enable the CourseSales.com admin area to be customised
// Use jquery or javascript to modify how the elements within the admin portal operate
// This can be changed in Setup>Settings, by adjusting the files referenced (uploaded by CS.com)
// Email any changes to support@coursesales.com


$(document).ready(function() {

  initOnCompleteLoad();

  /* ***************** */
  /* Standard Listen Functions */
  * ***************** */

  //Links to wizard js file to be included
  var link = document.createElement( "script" );
  link.src = "https://cs.coursesales.com/co/cs/cstour.js";
  link.type = "text/javascript";
  document.getElementsByTagName( "head" )[0].appendChild( link );

  //Links to wizard CSS file to be included

  var link = document.createElement( "link" );
  link.href ="https://cs.coursesales.com/co/cs/bootstrap-tour-standalone.min.css";
  link.type = "text/css";
  link.rel = "stylesheet";
  link.media = "screen,print";
  document.getElementsByTagName( "head" )[0].appendChild( link );

  // Preselects the timezone for Venues on the venues add page
  $('form[action="/venue/addpost"] select[id="VenueTimezone"]').val('Australia/Brisbane');

  // The following preselects the timezone for Logins
  $("form[action='/login/addpost'] select[id='LoginTimezone']").val('Australia/Brisbane');

  // this shows and hides Terms or other content, add content with a <span class=toggle-wrap>content here</span> to make this work (css req too)
  $(".toggle-trigger").click(function() {
    $(this).parent().nextAll('.toggle-wrap').first().toggle('slow');
  });

  //Adds a Tawk.to (chat) icon to the blue bar
  $('a[href^="support"]').before('<a id="CStawk" href="#"><img src="/co/tiad/chat_small.png"></a>');

  //Open chat when icon is clicked in the blue bar
  $('#CStawk').on('click', function(){
    JumpLinkTawk();
  });

  //The following displays the correct options to the customer user to ensure that they select options that will alert the Support team. 
   if ($('#username').text().indexOf("Support") == -1 && window.location.href.indexOf("support") > -1) {
      $("#SupportStatus option[value='107']").remove(); //Assistance Offered
      $("#SupportStatus option[value='104']").remove(); //Information Required
      $("#SupportStatus option[value='111']").remove(); //Authorisation Requested
      $("#SupportStatus option[value='120']").remove(); //Quoted
      $("#SupportStatus option[value='160']").remove(); //Invoiced
      $("#SupportStatus option[value='300']").remove(); //Scheduled
      $("#SupportStatus option[value='700']").remove(); //Ready For Review
     }

     //The following does the same but is for when the customer creates a ticket from the top blue bar. 

     $('span.spticon').click(function () {
     setTimeout(function(){
     $("#SupportStatus option[value='107']").remove(); //Assistance Offered
     $("#SupportStatus option[value='104']").remove(); //Information Required
     $("#SupportStatus option[value='111']").remove(); //Authorisation Requested
     $("#SupportStatus option[value='120']").remove(); //Quoted
     $("#SupportStatus option[value='160']").remove(); //Invoiced
     $("#SupportStatus option[value='300']").remove(); //Scheduled
     $("#SupportStatus option[value='700']").remove(); //Ready For Review
     }, 1000);
   });

   //The following limits the options to CourseSales Support user (with support in the Display name) to ensure that they can only user options that will alert the customer. 

   if ($('#username').text().indexOf("Support") != -1 && window.location.href.indexOf("support") > -1) {
    $("#SupportStatus option[value='105']").remove(); //Assistance Requested
    $("#SupportStatus option[value='110']").remove(); //Quote Requested
    $("#SupportStatus option[value='130']").remove(); //Quote Rejected
    $("#SupportStatus option[value='140']").remove(); //Quote Accepted
    $("#SupportStatus option[value='200']").remove(); //Paid Deposit
    $("#SupportStatus option[value='600']").remove(); //Changes Requested
    $("#SupportStatus option[value='750']").remove(); //Work Accepted
    $("#SupportStatus option[value='800']").remove(); //Paid Balance
   }

   /* ***************** */
   /* RTO Listen Functions */
   * ***************** */
   // Checks the value 'Generate Course Topics from the Course Format' when adding course dates so that course topics are created by default.
   $('#CourseDateCrsTpcCreate').attr('checked', true);

    // Preselects the status when updating Document Topics - can be removed past 1 Oct 2018 (Q2 release)
   if (location.pathname.indexOf('/document/bulkchangedoctpc') > -1) {
    $('select[id="CourseDateCycleId"]').val('-1');
   }

   //clears the postcode/locality lookup to avoid confusion (without this only the first locality in list is displayed)
   $(".ACaddress input[type=\"text\"]").val("");

   // This hides the draw on a document by simulating the click on the toggle checkbox (configured to include 'ToggleSurvey' as the class)
   $(".ToggleSurvey").trigger('click');

   // Copy details on click of 'Copy address details' button
   $('#ACbutton').on('click', function(){
   autoAdd();
   });

   //When the USI links are clicked these functions open the pretty windows to create or find a USI.

      $('#JumpLinkUSICreate').on('click', function(){
       JumpLinkUSICreate();
      });
      $('#JumpLinkUSIForgot').on('click', function(){
       JumpLinkUSIForgot();
      });
   //Open the Document Topics draw by default
   $("#docTpcLst").jqGrid('setGridState', 'visible');


   //The following modifies the Document Registration Lists

   $('.crsDocLst').prepend(
    $('<div class="header"><div class="heading1 crsDocLstRowName">Name details</div><div class="heading2 crsDocLstRowUsi">USI</div><div class="heading3 crsDocLstRowExtId">Ref No</div><div class="heading4 crsDocLstRowBirth">DoB</div><div class="heading5">Comp</div><div class="heading6 crsDocLstRowSig">Signature</div></div>')
);

   $('<div class="crsDocLstRowComp">Yes / No</div>').insertAfter(".crsDocLstRowBirth:not('.heading4')");

 });

 /* ***************** */
 /* Standard Functions */
 * ***************** */
 //Function to open the chat (Tawk.to) widget
 function JumpLinkTawk() {
 window.open('https://tawk.to/chat/5afb790b227d3d7edc255abb/default/?$_tawk_popout=true','_blank','height=400,menubar=no,status=no,scrollbars=yes,titlebar=yes,toolbar=no,width=300,top=200, left=1200"','');
 }


 /* ***************** */
 /* RTO Functions */
 * ***************** */

 //Functions to create the windows for the USI links.
 function JumpLinkUSICreate() {
 window.open('https://portal.usi.gov.au/student/Usi/Create/OnBehalfOf','_blank','height=400,menubar=no,status=no,scrollbars=yes,titlebar=yes,toolbar=no,width=400','');
 }

 function JumpLinkUSIForgot() {
 window.open('https://portal.usi.gov.au/student/Usi/Forgotten','_blank','height=400,menubar=no,status=no,scrollbars=yes,titlebar=yes,toolbar=no,width=400','');
 }

 //The following is for copying the postcode, locality and state to the respective fields from the autolookup
 var selStateId= '';

 function initOnCompleteLoad() {
 /*To disable editing make text fields readonly and select field disabled plus a hidden field*/
 /*important that the hidden field is created before the original field is disabled. */
 sid= $('div.ACstate select').attr('id');
 sval = $('div.ACstate select').val();
 sname= $('div.ACstate select').attr('name');
 selStateId = sid;
 $("div.ACstate select").attr('name', 'selState');
 $("div.ACstate select").attr('id', 'selState');
 $("div.ACstate").append('<input type=hidden name=' + sname + ' id=' + sid + ' value="'+sval+'" >');
 //Comment these next three lines if you wish to be able to edit the values eg for OSPC entries (otherwise they are disabled)
 $("div.ACstate select").prop('disabled', true);
 $('input[type="text"].ACpostcode').prop('readonly', true);
 $('input[type="text"].AClocality').prop('readonly', true);
 $(".ACaddress").parent().after('<div class="fld fldWd25 fldfl"><div class="wdg"><label></label><br><input type="button" id="ACbutton" value="Copy address details..."></div></div>');
 }

 function autoAdd() {
 /* Get the autocomplete value and split based on ' - ' getting the Postcode first, tidy up spaces before or after */
 Section1 = $(".ACaddress input[type=\"text\"]").val(); 
 Section1 = Section1.trim();
 Postcode = Section1.split(" - ")[0];
 Postcode = Postcode.trim();

 /* now get the suburb, tidy up spaces before or after */
 Section1 = Section1.split(" - ")[1];
 Section1 = Section1.trim();
 Suburb = Section1.split(/ [^ ]*$/)[0];
 Section1 = Section1.replace(Suburb, "");
 Section1 = Section1.trim();

 /*now change the 3-letter code to the AVETMISS numerical values then pick off the number*/

 Section1 = Section1.replace("QLD", "3");
 Section1 = Section1.replace("NSW", "1");
 Section1 = Section1.replace("NT", "7");
 Section1 = Section1.replace("VIC", "2");
 Section1 = Section1.replace("ACT", "8");
 Section1 = Section1.replace("SA", "4");
 Section1 = Section1.replace("WA", "5");
 Section1 = Section1.replace("TAS", "6");

 myreg = /[^ ]*$/;
 State = myreg.exec(Section1);

 /* Define the field values */

 $('#' + selStateId).val(State);
 $('input[type="text"].AClocality').val(Suburb);
 $('input[type="text"].ACpostcode').val(Postcode);
 $("div.ACstate select").val(Section1);
 return this;
 }