source: main/trunk/greenstone3/web/interfaces/default/js/classifier_scripts.js@ 33128

Last change on this file since 33128 was 33128, checked in by wy59, 5 years ago

Improvements to Coordinate support AND bugfixes. BUT not all the fixes may be ideal, many marked with TODO. 1. Now we support an Array of coordinates. At present these are only displayed as Markers, but in future shapes should appear as shapes. 2. Bugfixes include: (a) expanding sections wasn't working when we had hierarchical docs with Coordinate data, because map-scripts 'overrode' the toggleSection function but no longer did any of the doc expanding behaviour that document_scripts.js used to do. This was not a problem with the ImagesGPS collection, simply because that did not have hierarchical/sectionalised documents. (b) Perl: A previous commit output duplicate Coordinates into the index. Now this doesn't happen. Fix works but may not be ideal. 3. Perl: (a) Reserved index names CD, CS for Coordinate and CoordShort. Note however that LAT and LNG were never added to reserve list for index names. (b) Now doc.pm::processCoord() takes a section parameter and works out the section-ptr from that.

  • Property svn:executable set to *
File size: 3.7 KB
Line 
1var inProgress = new Array();
2var openClassifiers = new Array();
3var busy = false;
4
5function isExpanded(sectionID)
6{
7 var divElem = gs.jqGet("div" + sectionID);
8 if(!divElem.css("display") || divElem.css("display") != "none")
9 {
10 return true;
11 }
12 return false;
13}
14
15// TODO: Is there a better solution
16function _basicToggleSection(sectionID) {
17 // Leave this function here, even though it's empty.
18 // This function is here because:
19 // - it mirrors the identically named version in document_scripts
20 // - and this allows map_scripts to override it without knowing whether it's
21 // overriding classifier_scripts::toggleSection() or document_scripts::toggleSection().
22
23 // This method is not meant to call toggleSection. If anything it would be the other way around
24 // (as occurs in doc_scripts.js). But this method has to remain empty for classifier_scripts.js
25 // since map_scripts largely repeats classifier_scripts.js::toggleSection() code.
26}
27
28function toggleSection(sectionID)
29{
30 var section = gs.jqGet("div" + sectionID);
31 var sectionToggle = gs.jqGet("toggle" + sectionID);
32
33 if(sectionToggle == undefined)
34 {
35 return;
36 }
37
38 //If the div exists
39 if(section.length)
40 {
41 if(isExpanded(sectionID))
42 {
43 section.css("display", "none");
44 sectionToggle.attr("src", gs.imageURLs.expand);
45
46 if(openClassifiers[sectionID] != undefined)
47 {
48 delete openClassifiers[sectionID];
49 }
50 }
51 else
52 {
53 section.css("display", "block");
54 sectionToggle.attr("src", gs.imageURLs.collapse);
55 openClassifiers[sectionID] = true;
56 }
57 updateOpenClassifiers();
58 }
59 else
60 {
61 httpRequest(sectionID);
62 }
63}
64
65function updateOpenClassifiers()
66{
67 var oc = "";
68 var first = true;
69 for(var key in openClassifiers)
70 {
71 if(first)
72 {
73 first = false;
74 }
75 else
76 {
77 oc += ",";
78 }
79
80 oc += key;
81 }
82
83 if(oc != undefined)
84 {
85 window.location.hash = oc;
86 }
87}
88
89function openStoredClassifiers()
90{
91 if(window.location.hash != undefined && window.location.hash.length > 1)
92 {
93 var toOpen = window.location.hash.substring(1,window.location.hash.length).split(",");
94 var loopFunction = function(sectionArray, index)
95 {
96 if(!busy && index < sectionArray.length)
97 {
98 busy = true;
99 toggleSection(sectionArray[index]);
100 setTimeout(function()
101 {
102 loopFunction(sectionArray, index + 1);
103 }, 25);
104
105 return true;
106 }
107
108 setTimeout(function()
109 {
110 loopFunction(sectionArray, index);
111 }, 25);
112 return false;
113 }
114
115 if(toOpen.length > 0)
116 {
117 loopFunction(toOpen, 0);
118 }
119 }
120}
121
122function httpRequest(sectionID)
123{
124 if(!inProgress[sectionID])
125 {
126 inProgress[sectionID] = true;
127
128 var sectionToggle = gs.jqGet("toggle" + sectionID);
129 sectionToggle.attr("src", gs.imageURLs.loading);
130
131 var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
132
133 if(gs.cgiParams.berrybasket == "on")
134 {
135 url = url + "&berrybasket=on";
136 }
137
138 if(url.indexOf("#") != -1)
139 {
140 url = url.substring(0, url.indexOf("#"));
141 }
142
143 $.ajax(url)
144 .success(function(data)
145 {
146 var newDiv = $("<div>");
147 var sibling = gs.jqGet("title" + sectionID);
148 sibling.after(newDiv);
149
150 newDiv.html(data);
151 sectionToggle.attr("src", gs.imageURLs.collapse);
152 openClassifiers[sectionID] = true;
153
154 if(gs.cgiParams.berrybasket == "on")
155 {
156 checkout();
157 }
158 else if(gs.cgiParams.documentbasket == "on")
159 {
160 dmcheckout();
161 }
162 updateOpenClassifiers();
163 })
164 .error(function()
165 {
166 sectionToggle.attr("src", gs.imageURLs.expand);
167 })
168 .complete(function()
169 {
170 inProgress[sectionID] = false;
171 busy = false;
172 });
173 }
174}
Note: See TracBrowser for help on using the repository browser.