Changeset 36906


Ignore:
Timestamp:
2022-11-15T13:59:16+13:00 (3 weeks ago)
Author:
kjdon
Message:

check whether TKMetadataURL is defined before using it - get success result when doing ajax url to undefined.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/utility_scripts.js

    r36904 r36906  
    178178      "MenRestricted","WomenRestricted","CulturallySensitive","SecretSacred","OpenToCommercialization","NonCommercial","CommunityUseOnly","Outreach","OpenToCollaboration"];
    179179   let tkCodes = ["tk_a","tk_cl","tk_f","tk_mc","tk_cv","tk_cr","tk_v","tk_nv","tk_s","tk_wg","tk_mg","tk_mr","tk_wr","tk_cs","tk_ss","tk_oc","tk_nc","tk_co","tk_o","tk_cb"];
    180    for (let i = 0; i < tkLabels.length; i++) {
     180    for (let i = 0; i < tkLabels.length; i++) {
    181181      if (labelName == tkLabels[i]) {
    182182         let labeldiv = document.querySelectorAll(".tklabels img");
    183183         for (image of labeldiv) {
    184             let labelCode = image.src.substr(image.src.lastIndexOf("/") + 1).replace(".png", ""); // get tk label code from image file name
    185             if (labelCode == tkCodes[i]) {
     184             let labelCode = image.src.substr(image.src.lastIndexOf("/") + 1).replace(".png", ""); // get tk label code from image file name
     185             if (labelCode == tkCodes[i]) {
    186186               image.title = "TK " + name + ": " + definition + " Click for more details."; // set tooltip
    187187               if (image.parentElement.parentElement.parentElement.classList[0] != "tocSectionTitle") { // disable onclick event in favourites section
     
    225225      console.error("ajax call not yet loaded tk label metadata set");
    226226   } else {
    227       for (label of tkMetadataElements) { // for each tklabel element in tk.mds
     227       for (label of tkMetadataElements) { // for each tklabel element in tk.mds
    228228         let tkLabelName = label.attributes.name.value; // Element name=""
    229229         let attributes = label.querySelectorAll("[code=" + lang + "] Attribute"); // gets attributes for selected language
     
    260260};
    261261function loadTKMetadataSet(lang, type) {
    262    tkMetadataSetStatus = "loading";
     262    if (gs.variables["tkMetadataURL_"+type] == undefined) {
     263    console.error("tkMetadataURL_"+type+" variable is not defined, can't load TK Metadata Set");
     264    tkMetadataSetStatus = "no-metadata-set-for-this-"+type;
     265    return;
     266    }
     267    tkMetadataSetStatus = "loading";
    263268   $.ajax({
    264269       url: gs.variables["tkMetadataURL_"+type],
    265270       async: false,
    266       success: function(xml) {
     271       success: function(xml) {
    267272         tkMetadataSetStatus = "loaded";
    268273         let parser = new DOMParser();
    269274         let tkmds = parser.parseFromString(xml, "text/xml");
    270275         tkMetadataElements = tkmds.querySelectorAll("Element");
    271          if (document.readyState === "complete") {
     276           if (document.readyState === "complete") {
    272277            addTKLabelsToImages(lang);
    273          } else {
    274             window.onload = function() {
     278           } else {
     279               window.onload = function() {
    275280               addTKLabelsToImages(lang);
    276281            }
     
    278283      },
    279284      error: function() {
    280          tkMetadataSetStatus = "no-metadata-set-for-this-"+type;
    281          console.log("No TK Label Metadata-set found for this "+type);
     285          tkMetadataSetStatus = "no-metadata-set-for-this-"+type;
     286      console.log("No TK Label Metadata-set found for this "+type);
    282287      }
    283288   });
Note: See TracChangeset for help on using the changeset viewer.