main.js

About this file

The function in this JS file allows the user to handle certain actions on the admin page. The current user can view agencies, which then changes the URL. Upon clicking the activate or deactivate buttons, an agency can activate or deactivate an agency.
The user can also check off another user to change the status, such as becoming a superuser in the agency or removing the user.

Code Issues

  • The click event listener function for activating and deactivating an agency looks very similar. Recommend creating a separate click event function that takes in a data object. For example, after refactoring, the call to activate an agency can look like $("#activate").click(actOrDeact({is_active:true})).
  • On line 118, use of unexpected alert is detected. JavaScripts' alert, confirm, and prompt functions are widely considered to be obtrusive as UI elements and should be replaced by a more appropriate custom UI implementation. Furthermore, alert is often used while debugging code, which should be removed before deployment to production. The following patterns are considered problems:

      
      //Bad:
      alert("here!");
      confirm("Are you sure?");
      prompt("What's your name?", "John Doe");
    
      //Good:
      customAlert("Something happened!");
      customConfirm("Are you sure?");
      customPrompt("Who are you?");
      
      
      

Code Check Report




   68:22  error  Unexpected alert  no-alert
   97:22  error  Unexpected alert  no-alert
  118:26  error  Unexpected alert  no-alert

✖ 3 problems (3 errors, 0 warnings)
                        

Documentation drawn from source code

$(function () {
  $("#agencies").change(function () {
  $("#activate").click(function () {
    success: function () {
  $("#deactivate").click(function () {
    success: function () {
  $("input[name^='user-super']").click(function () {
  $("#add-button").click(function () {
    success: function () {
  $("input[name^='user-status']").click(function () {
    success: function (data) {
  $("#remove").click(function () {
   idsToRemove.each(function () {
     success: function () {

Source code