Commit 96f406995da57c8c42f3d0ba121a695b7878f8f2

Authored by Nikita Kulshreshtha
1 parent 82c7c8e8

commit

400-SOURCECODE/AIAHTML5.Web/search-wp.js
1 -  
2 -  
3 -loadTermData = function (currentBodyViewId, languageName, languageID) {  
4 -  
5 - console.log('search-wp, loadTermData, time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));  
6 - var termNoJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json';  
7 -  
8 - var TermNumberData;  
9 - var AJAX_req = new XMLHttpRequest();  
10 - AJAX_req.open("GET", termNoJsonPath, true);  
11 - AJAX_req.setRequestHeader("Content-type", "application/json");  
12 -  
13 - AJAX_req.onreadystatechange = function () {  
14 - if (AJAX_req.readyState == 4 && AJAX_req.status == 200) {  
15 - TermNumberData = JSON.parse(AJAX_req.responseText);  
16 - console.log("data returned: " + TermNumberData);  
17 -  
18 - loadTermTextData(TermNumberData, languageName, languageID);  
19 -  
20 - }  
21 - }  
22 - AJAX_req.send();  
23 -  
24 -  
25 -}  
26 -  
27 -  
28 -loadTermTextData = function (TermNumberData, languageName, languageID) {  
29 -  
30 - var languageFileName;  
31 - if(languageName == "English (Undergraduate)")  
32 - {  
33 - languageFileName = "English_Undergraduate";  
34 - }  
35 - else if (languageName == "Japanese (Kanji)") {  
36 - languageFileName = "Japanese_Kanji";  
37 - }  
38 - else if (languageName == "Japanese (Yomi)")  
39 - {  
40 - languageFileName = "Japanese_yomi";  
41 - }  
42 - else  
43 - {  
44 - languageFileName = languageName;  
45 - }  
46 -  
47 - var termTextJsonPath = '~/../content/data/json/da/vocab/' + languageFileName + '/cm_dat_vocabterm_' + languageID + '.json';  
48 -  
49 - var VocabTermData = '';  
50 - var AJAX_req = new XMLHttpRequest();  
51 - AJAX_req.open("GET", termTextJsonPath, true);  
52 - AJAX_req.setRequestHeader("Content-type", "application/json");  
53 - AJAX_req.onreadystatechange = function () {  
54 - if (AJAX_req.readyState == 4 && AJAX_req.status == 200) {  
55 - console.log('AJAX_req.readyState= ' + AJAX_req.readyState + ' and AJAX_req.status =' + AJAX_req.status);  
56 -  
57 - VocabTermData = JSON.parse(AJAX_req.responseText);  
58 - var vocabTermTxt = [];  
59 - TermNumberData.TermData.Term.forEach(function (value1, key1) {  
60 - VocabTermData.VocabTerms.Term.forEach(function (value2, key2) {  
61 - if (value1._ActualTermNumber === value2._ActualTermNumber) {  
62 - vocabTermTxt.push(  
63 - {  
64 - "_ActualTermNumber": value2._ActualTermNumber,  
65 - "_TermText": value2._TermText,  
66 - "_cdId": value2._cdId  
67 - }  
68 - );  
69 - }  
70 - })  
71 - })  
72 - self.postMessage({  
73 - 'vocabTermTxt': vocabTermTxt,  
74 - 'TermNumberData': TermNumberData,  
75 - 'VocabTermData': VocabTermData,  
76 - 'language': languageName  
77 -  
78 - });  
79 - }  
80 - }  
81 - AJAX_req.send();  
82 -}  
83 -  
84 -  
85 -self.onmessage = function (e) {  
86 - console.log("search");  
87 - //console.log('search-wp onmessage time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));  
88 - loadTermData(e.data.currentBodyViewId, e.data.languageName, e.data.languageID);  
89 -  
90 -  
91 -}  
92 - 1 +
  2 +
  3 +loadTermData = function (currentBodyViewId, languageName, languageID) {
  4 +
  5 + console.log('search-wp, loadTermData, time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
  6 + var termNoJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json';
  7 +
  8 + var TermNumberData;
  9 + var AJAX_req = new XMLHttpRequest();
  10 + AJAX_req.open("GET", termNoJsonPath, true);
  11 + AJAX_req.setRequestHeader("Content-type", "application/json");
  12 +
  13 + AJAX_req.onreadystatechange = function () {
  14 + if (AJAX_req.readyState == 4 && AJAX_req.status == 200) {
  15 + TermNumberData = JSON.parse(AJAX_req.responseText);
  16 + console.log("data returned: " + TermNumberData);
  17 +
  18 + loadTermTextData(TermNumberData, languageName, languageID);
  19 +
  20 + }
  21 + }
  22 + AJAX_req.send();
  23 +
  24 +
  25 +}
  26 +
  27 +
  28 +loadTermTextData = function (TermNumberData, languageName, languageID) {
  29 +
  30 + var languageFileName;
  31 + if(languageName == "English (Undergraduate)")
  32 + {
  33 + languageFileName = "English_Undergraduate";
  34 + }
  35 + else if (languageName == "Japanese (Kanji)") {
  36 + languageFileName = "Japanese_Kanji";
  37 + }
  38 + else if (languageName == "Japanese (Yomi)")
  39 + {
  40 + languageFileName = "Japanese_yomi";
  41 + }
  42 + else
  43 + {
  44 + languageFileName = languageName;
  45 + }
  46 +
  47 + var termTextJsonPath = '~/../content/data/json/da/vocab/' + languageFileName + '/cm_dat_vocabterm_' + languageID + '.json';
  48 +
  49 + var VocabTermData = '';
  50 + var AJAX_req = new XMLHttpRequest();
  51 + AJAX_req.open("GET", termTextJsonPath, true);
  52 + AJAX_req.setRequestHeader("Content-type", "application/json");
  53 + AJAX_req.onreadystatechange = function () {
  54 + if (AJAX_req.readyState == 4 && AJAX_req.status == 200) {
  55 + console.log('AJAX_req.readyState= ' + AJAX_req.readyState + ' and AJAX_req.status =' + AJAX_req.status);
  56 +
  57 + VocabTermData = JSON.parse(AJAX_req.responseText);
  58 + var vocabTermTxt = [];
  59 + TermNumberData.TermData.Term.forEach(function (value1, key1) {
  60 + VocabTermData.VocabTerms.Term.forEach(function (value2, key2) {
  61 + if (value1._ActualTermNumber === value2._ActualTermNumber) {
  62 + vocabTermTxt.push(
  63 + {
  64 + "_ActualTermNumber": value2._ActualTermNumber,
  65 + "_TermText": value2._TermText,
  66 + "_cdId": value2._cdId
  67 + }
  68 + );
  69 + }
  70 + })
  71 + })
  72 + self.postMessage({
  73 + 'vocabTermTxt': vocabTermTxt,
  74 + 'TermNumberData': TermNumberData,
  75 + 'VocabTermData': VocabTermData,
  76 + 'language': languageName
  77 +
  78 + });
  79 + }
  80 + }
  81 + AJAX_req.send();
  82 +}
  83 +
  84 +
  85 +self.onmessage = function (e) {
  86 + console.log("search");
  87 + //console.log('search-wp onmessage time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
  88 + loadTermData(e.data.currentBodyViewId, e.data.languageName, e.data.languageID);
  89 +
  90 +
  91 +}
  92 +