search-wp.js 4.1 KB


loadTermData = function (currentBodyViewId, languageName, languageID,windowid) {
    
   // console.log('search-wp, loadTermData, time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
    var termNoJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json';
    
    var TermNumberData;
    var AJAX_req = new XMLHttpRequest();
    AJAX_req.open("GET", termNoJsonPath, true);
    AJAX_req.setRequestHeader("Content-type", "application/json");

    AJAX_req.onreadystatechange = function () {
        if (AJAX_req.readyState == 4 && AJAX_req.status == 200) {
            TermNumberData = JSON.parse(AJAX_req.responseText);
           // console.log("data returned: " + TermNumberData);

            loadTermTextData(TermNumberData, languageName, languageID, currentBodyViewId,windowid);
           
        }
    }
    AJAX_req.send();


}


loadTermTextData = function (TermNumberData, languageName, languageID, currentBodyViewId,windowid) {
  
    var languageFileName;
    if(languageName == "English (Undergraduate)")
    {
        languageFileName = "English_Undergraduate";
    }
    else if (languageName == "Japanese (Kanji)") {
        languageFileName = "Japanese_Kanji";
    }
    else if (languageName == "Japanese (Yomi)")
    {
        languageFileName = "Japanese_yomi";
    }
    else
    {
        languageFileName = languageName;
    }
  
    var termTextJsonPath = '~/../content/data/json/da/vocab/' + languageFileName + '/cm_dat_vocabterm_' + languageID + '.json';
      
        var VocabTermData = '';
        var AJAX_req = new XMLHttpRequest();
        AJAX_req.open("GET", termTextJsonPath, true);
        AJAX_req.setRequestHeader("Content-type", "application/json");
        AJAX_req.onreadystatechange = function () {
            if (AJAX_req.readyState == 4 && AJAX_req.status == 200) {
                //console.log('AJAX_req.readyState= ' + AJAX_req.readyState + ' and AJAX_req.status =' + AJAX_req.status);
              
                VocabTermData = JSON.parse(AJAX_req.responseText);
                var vocabTermTxt = [];
                var vocabData=VocabTermData.VocabTerms.Term;
                TermNumberData.TermData.Term.forEach(function (value1, key1) {            
                    for (var i = 0; i < vocabData.length; i ++) {
                        if (value1._ActualTermNumber === vocabData[i]._ActualTermNumber) {
                            vocabTermTxt.push(
                                {
                                    "_ActualTermNumber": vocabData[i]._ActualTermNumber,
                                    "_TermText": vocabData[i]._TermText
                                   // "_cdId": vocabData[i]._cdId
                                });
                                break;
                        }
                    }
                    // VocabTermData.VocabTerms.Term.forEach(function (value2, key2) {
                    //     if (value1._ActualTermNumber === value2._ActualTermNumber) {
                    //         debugger
                    //         vocabTermTxt.push(
                    //             {
                    //                 "_ActualTermNumber": value2._ActualTermNumber,
                    //                 "_TermText": value2._TermText,
                    //                 "_cdId": value2._cdId
                    //             }
                    //             );
                    //             break;
                    //     }
                    // })
                })
                    self.postMessage({
                        'vocabTermTxt': vocabTermTxt,
                        'TermNumberData': TermNumberData,
                         'VocabTermData': VocabTermData,
                         'language': languageName,
                         "bodyViewID": currentBodyViewId,
                         "winId": windowid,

                    });
            }
        }
    AJAX_req.send();
}


self.onmessage = function (e) {
   // console.log("search");
    loadTermData(e.data.currentBodyViewId, e.data.languageName, e.data.languageID,e.data.windowid);
  

}