Skip to content

Remove every reference to http://localhost in coopstarter.js

There are at least two references to our local devs environment in the coopstarter.js file

See the language selection method:

/**
 * Manage the select language
 */
function manageSelectLanguage() {
  const languageSelects = document.getElementsByClassName("languageChoice")
  for (let item of languageSelects) {
    item.addEventListener("change", function() {
      //We listen the selected option for the language
      uriLanguage = item.querySelector("option:checked").value

      //We retrieve element of the url
      var pathAfterThePrefix = window.location.pathname.split('/')[2];
      var base_url = location.host

      //If the selected language is french
      if (uriLanguage === '{"@id": "http://localhost:8000/languages/1/"}') {
        //Redirection with the appropriate prefixe.
        var redirect = "http://"+base_url+'/fr/'+pathAfterThePrefix

        document.location.href = redirect
      } else {
        var redirect = "http://"+base_url+'/en/'+pathAfterThePrefix
        document.location.href = redirect
        
      }
      
    })
  }
}

And this one:

function InitManagementForType() {
  var forms = document.querySelectorAll(".resource_by_step");

  forms.forEach(form => {
    form.addEventListener(
      "populate",
      e => {
        window.setTimeout(() => {
          let type_hidden_field = form.querySelectorAll('select[name="type"]');
          type_hidden_field.forEach(function(select_hidden) {
            options_hidden = select_hidden.getElementsByTagName("option");
            for (let option_hidden of options_hidden) {
              option_hidden.removeAttribute("selected");
              if (option_hidden.value == '{"@id": "http://localhost:8000/types/1/"}') {
                //Actually selecting the option if it is the good one
                option_hidden.setAttribute("selected", "selected");
                select_hidden.setAttribute("value", option_hidden.value);
              }
            }
           //Trigerring a reload of the associated form
      let parent_form = select_hidden.closest("sib-form");
      parent_form.component.inputChange();
      refreshPagination();
          });
        });
      },
      3000
    );
  });
}

It should be replaced by substr checks on the proper resources IDs so it can work on other environments than dev.