source: main/trunk/greenstone3/web/interfaces/oran/js/classifier_scripts.js@ 25442

Last change on this file since 25442 was 25442, checked in by sjm84, 12 years ago

Some changes to allow for RESTful classifiers

  • Property svn:executable set to *
File size: 3.6 KB
Line 
1var inProgress = new Array();
2var openClassifiers = new Array();
3var busy = false;
4
5function isExpanded(sectionID)
6{
7 var divElem = document.getElementById("div" + sectionID);
8 if(!divElem.style.display || divElem.style.display == "block")
9 {
10 return true;
11 }
12 return false;
13}
14
15function toggleSection(sectionID)
16{
17 var section = document.getElementById("div" + sectionID);
18 var sectionToggle = document.getElementById("toggle" + sectionID);
19
20 if(sectionToggle == undefined)
21 {
22 return;
23 }
24
25 if(section)
26 {
27 if(isExpanded(sectionID))
28 {
29 section.style.display = "none";
30 sectionToggle.setAttribute("src", gs.imageURLs.expand);
31
32 if(openClassifiers[sectionID] != undefined)
33 {
34 delete openClassifiers[sectionID];
35 }
36 }
37 else
38 {
39 section.style.display = "block";
40 sectionToggle.setAttribute("src", gs.imageURLs.collapse);
41 openClassifiers[sectionID] = true;
42 }
43 updateOpenClassifiers();
44 }
45 else
46 {
47 httpRequest(sectionID);
48 }
49}
50
51function updateOpenClassifiers()
52{
53 var oc = "";
54 var first = true;
55 for(var key in openClassifiers)
56 {
57 if(first)
58 {
59 first = false;
60 }
61 else
62 {
63 oc += ",";
64 }
65
66 oc += key;
67 }
68
69 if(oc != undefined)
70 {
71 window.location.hash = oc;
72 }
73}
74
75function openStoredClassifiers()
76{
77 if(window.location.hash != undefined && window.location.hash.length > 1)
78 {
79 var toOpen = window.location.hash.substring(1,window.location.hash.length).split(",");
80 var loopFunction = function(sectionArray, index)
81 {
82 if(!busy && index < sectionArray.length)
83 {
84 busy = true;
85 toggleSection(sectionArray[index]);
86 setTimeout(function()
87 {
88 loopFunction(sectionArray, index + 1);
89 }, 25);
90
91 return true;
92 }
93
94 setTimeout(function()
95 {
96 loopFunction(sectionArray, index);
97 }, 25);
98 return false;
99 }
100
101 if(toOpen.length > 0)
102 {
103 loopFunction(toOpen, 0);
104 }
105 }
106}
107
108function httpRequest(sectionID)
109{
110 if(!inProgress[sectionID])
111 {
112 inProgress[sectionID] = true;
113 var httpRequest = new gs.functions.ajaxRequest();
114
115 var sectionToggle = document.getElementById("toggle" + sectionID);
116 sectionToggle.setAttribute("src", gs.imageURLs.loading);
117
118 var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
119
120 if(gs.cgiParams.berryBasket == "on")
121 {
122 url = url + "&berrybasket=on";
123 }
124
125 if(url.indexOf("#") != -1)
126 {
127 url = url.substring(0, url.indexOf("#"));
128 }
129 httpRequest.open('GET', url, true);
130 httpRequest.onreadystatechange = function()
131 {
132 if (httpRequest.readyState == 4)
133 {
134 if (httpRequest.status == 200)
135 {
136 var newDiv = document.createElement("div");
137 var sibling = document.getElementById("title" + sectionID);
138 var parent = sibling.parentNode;
139 if(sibling.nextSibling)
140 {
141 parent.insertBefore(newDiv, sibling.nextSibling);
142 }
143 else
144 {
145 parent.appendChild(newDiv);
146 }
147
148 newDiv.innerHTML = httpRequest.responseText;
149 sectionToggle.setAttribute("src", gs.imageURLs.collapse);
150 openClassifiers[sectionID] = true;
151
152 if(gs.cgiParams.berryBasket == "on")
153 {
154 checkout();
155 }
156 else if(gs.cgiParams.documentbasket == "on")
157 {
158 dmcheckout();
159 }
160 updateOpenClassifiers();
161 }
162 else
163 {
164 sectionToggle.setAttribute("src", gs.imageURLs.expand);
165 }
166 inProgress[sectionID] = false;
167 busy = false;
168 }
169 }
170 httpRequest.send();
171 }
172}
Note: See TracBrowser for help on using the repository browser.