search-wp.js 2.65 KB


loadTermData = function (currentBodyViewId)
{
    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);
            }
        }
        AJAX_req.send();

      
}


loadTermTextData = function (TermNumberData) {
  
    //1.
    var termTextJsonPath = '~/../content/data/json/da/vocab/english/cm_dat_vocabterm_1.json';

    // readTextFile(termTextJsonPath, function (text) {

    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) {
            VocabTermData = JSON.parse(AJAX_req.responseText);
            console.log("data returned FOR VocabTermData: " + VocabTermData);

            var vocabTermTxt = [];

            TermNumberData.TermData.Term.forEach(function (value1, key1) {

                VocabTermData.VocabTerms.Term.forEach(function (value2, key2) {

                    if (value1._ActualTermNumber === value2._ActualTermNumber) {
                        vocabTermTxt.push(
                            {
                                "_ActualTermNumber": value2._ActualTermNumber,
                                "_TermText": value2._TermText,
                                "_cdId": value2._cdId
                            }
                            );
                    }
                })

            })

            self.postMessage({
                'vocabTermTxt': vocabTermTxt,
                'TermNumberData': TermNumberData,
                'VocabTermData': VocabTermData

            });

        }
    }
    AJAX_req.send();
        
     
}


self.onmessage = function (e) {
    //console.log('search-wp onmessage time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
    loadTermData(e.data.currentBodyViewId);

}