1 | //used to stored the current items in document basket, including collection name, document id and dodument title
|
---|
2 | //in the format of collection:id:[title], it is updated when the page is loaded (reloaded) or the user adds
|
---|
3 | // new items in the berry basket (see documentBasketDDPlayer.js). It is used to show the contents of the berry basket.
|
---|
4 |
|
---|
5 | var show = false;
|
---|
6 | var docList = new Array();
|
---|
7 |
|
---|
8 | var oldHeight=120;
|
---|
9 | var oldWidth=140;
|
---|
10 | var oldBg;
|
---|
11 |
|
---|
12 | var dd = new ygDDOnTop('documentbasket');
|
---|
13 | dd.setHandleElId('documenthandle');
|
---|
14 |
|
---|
15 | var dmcheckout = function(){
|
---|
16 |
|
---|
17 | if ( document.getElementById('documentbasket') == null ) return;
|
---|
18 |
|
---|
19 | var request_type = "GET";
|
---|
20 | var url = "?a=pr&rt=r&ro=1&s=GetDocuments&o=XML&hhf=[{\"name\":\"Cache-Control\", \"value\":\"no-cache\"}]&c=";
|
---|
21 |
|
---|
22 | var responseSuccess = function(o){
|
---|
23 | //alert(o.responseText);
|
---|
24 | var response = o.responseXML;
|
---|
25 | var size = response.getElementsByTagName('size').item(0).getAttribute('value');
|
---|
26 |
|
---|
27 | var items = response.getElementsByTagName('item');
|
---|
28 |
|
---|
29 | docList = new Array();
|
---|
30 | for (var i=0;i < items.length ; i++ )
|
---|
31 | {
|
---|
32 | // remove document images from the document basket if it already contains this item
|
---|
33 | var itemID = "documentBasketBook" + items[i].getAttribute('collection') + ":" + items[i].getAttribute('name');
|
---|
34 | var item = YAHOO.util.Dom.get(itemID);
|
---|
35 | if (item != null){
|
---|
36 | var parent = item.parentNode;
|
---|
37 | parent.removeChild(item);
|
---|
38 | }
|
---|
39 | docList[docList.length] = items[i];
|
---|
40 | }
|
---|
41 |
|
---|
42 | //add document image into the document basket
|
---|
43 | updateDocumentImages();
|
---|
44 |
|
---|
45 | // set document images visible
|
---|
46 | // they are set to be invisible to prevent flickering when first loaded (see documentbasket.css)
|
---|
47 |
|
---|
48 | var docs = document.getElementsByTagName('img');
|
---|
49 | new YAHOO.util.DDTarget('documentbasket','documentbox');
|
---|
50 |
|
---|
51 | for (var j=0; j < docs.length; j++){
|
---|
52 | var doc = docs[j];
|
---|
53 | var parent = doc.parentNode;
|
---|
54 |
|
---|
55 | if (doc.id.indexOf("documentBasketBook") != -1){
|
---|
56 | doc.style.visibility = "visible";
|
---|
57 | new documentBasketDDPlayer(doc.id,'documentbox',docList);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | //updateDocumentCount();
|
---|
61 | correctDocumentExpandCollapseButtons();
|
---|
62 | }
|
---|
63 |
|
---|
64 | var responseFailure = function(o){
|
---|
65 | alert("CHECKOUT FAILED");
|
---|
66 | }
|
---|
67 |
|
---|
68 | var callback = {
|
---|
69 | success: responseSuccess,
|
---|
70 | failure: responseFailure
|
---|
71 | }
|
---|
72 |
|
---|
73 | //var date = new Date();
|
---|
74 | //url += "&rand=" + date.getTime();
|
---|
75 | YAHOO.util.Connect.asyncRequest(request_type , url , callback);
|
---|
76 | }
|
---|
77 |
|
---|
78 | function updateDocumentImages(){
|
---|
79 |
|
---|
80 | var docs = YAHOO.util.Dom.get('documentpages');
|
---|
81 | if ( docs == null ) return;
|
---|
82 |
|
---|
83 | while(docs.hasChildNodes())
|
---|
84 | {
|
---|
85 | docs.removeChild(docs.firstChild);
|
---|
86 | }
|
---|
87 |
|
---|
88 | for (var i = 0; i < docList.length && i < 12; i++ ){
|
---|
89 | var img = document.createElement('img');
|
---|
90 | img.src = gs.imageURLs.pageIcon;
|
---|
91 | docs.appendChild(img);
|
---|
92 | }
|
---|
93 |
|
---|
94 | //show the help message if there are no docs
|
---|
95 | if ( docList.length == 0 ) {
|
---|
96 | var docHelpMsg = document.createElement('span');
|
---|
97 | docs.appendChild(docHelpMsg);
|
---|
98 | docHelpMsg.appendChild(document.createTextNode('Drop your document/pages here'));
|
---|
99 | docHelpMsg.setAttribute('id','docHelpMsg');
|
---|
100 | }
|
---|
101 |
|
---|
102 | //show the expand buttons
|
---|
103 | correctDocumentExpandCollapseButtons();
|
---|
104 |
|
---|
105 | }
|
---|
106 |
|
---|
107 | function correctDocumentExpandCollapseButtons() {
|
---|
108 | var dbecl = YAHOO.util.Dom.get('documentBasketExpandCollapseLinks');
|
---|
109 | if ( dbecl == null ) return;
|
---|
110 | if ( docList.length > 0 ) {
|
---|
111 | YAHOO.util.Dom.get('documentBasketExpandCollapseLinks').style.display='';
|
---|
112 | } else {
|
---|
113 | YAHOO.util.Dom.get('documentBasketExpandCollapseLinks').style.display='none';
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | function updateDocumentCount() {
|
---|
118 | var docs = YAHOO.util.Dom.get('documentpages');
|
---|
119 | var documentCount = YAHOO.util.Dom.get('documentCount');
|
---|
120 | if ( docs == null || documentCount == null ) return;
|
---|
121 | if ( docList.length == 0 ) {
|
---|
122 | documentCount.innerHTML = "empty";
|
---|
123 | } else {
|
---|
124 | documentCount.innerHTML = docList.length;
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | function documentBoxUpdate(e) {
|
---|
129 | //alert( arguments.callee );
|
---|
130 | var target = e.target;
|
---|
131 | if ((target.id.toLowerCase() == 'documentbasket' || target.id.toLowerCase() == 'documentpages') && !show){
|
---|
132 | showDocumentBox();
|
---|
133 | show = true;
|
---|
134 | }else{
|
---|
135 | if (target.id.toLowerCase() == 'hideview' && show){
|
---|
136 | hideDocumentBox();
|
---|
137 | show = false;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | if (target.className == 'pick'){
|
---|
142 | addDocument(target);
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | function showDocumentBox() {
|
---|
147 | //alert( arguments.callee );
|
---|
148 | var documentBasket= YAHOO.util.Dom.get('documentbasket');
|
---|
149 | var documentHandle = YAHOO.util.Dom.get('documenthandle');
|
---|
150 | var documentPages = YAHOO.util.Dom.get('documentpages');
|
---|
151 | var width = 500;
|
---|
152 | var height = 40;
|
---|
153 | var i=0;
|
---|
154 |
|
---|
155 | //remove berryImages in the berry basket
|
---|
156 | while (documentPages.hasChildNodes()) {
|
---|
157 | documentPages.removeChild(documentPages.firstChild);
|
---|
158 | }
|
---|
159 | while (documentHandle.hasChildNodes()) {
|
---|
160 | documentHandle.removeChild(documentHandle.firstChild);
|
---|
161 | }
|
---|
162 |
|
---|
163 | var div = document.createElement('div');
|
---|
164 | documentPages.appendChild(div);
|
---|
165 | var list = document.createElement('ol');
|
---|
166 | div.appendChild(list);
|
---|
167 |
|
---|
168 | list.id = 'doclist';
|
---|
169 |
|
---|
170 | //put the document pages in
|
---|
171 | for (i; i < docList.length; i++){
|
---|
172 | var documentItem = docList[i];
|
---|
173 | var documentElement = document.createElement('li');
|
---|
174 | list.appendChild(documentElement);
|
---|
175 | var title = documentItem.getAttribute('title');
|
---|
176 | var root_title = documentItem.getAttribute('root_title');
|
---|
177 | //var id = berryItem.getAttribute('collection')+":"+berryItem.getAttribute('name');
|
---|
178 |
|
---|
179 | if (root_title != ""){
|
---|
180 | root_title +=":";
|
---|
181 | }
|
---|
182 |
|
---|
183 | title = root_title+title;
|
---|
184 | if (title.length > 50){
|
---|
185 | title = title.substring(0,20)+" ... "+title.substr(title.length-35,35);
|
---|
186 | }
|
---|
187 |
|
---|
188 | documentElement.setAttribute("class","documentitem");
|
---|
189 | documentElement.setAttribute("title",title);
|
---|
190 | documentElement.innerHTML = title;
|
---|
191 | height +=40;
|
---|
192 | }
|
---|
193 |
|
---|
194 | oldHeight = documentBasket.style.height;
|
---|
195 | oldWidth = documentBasket.style.width;
|
---|
196 | oldBg = documentBasket.style.background;
|
---|
197 |
|
---|
198 | documentBasket.style.background ='url("interfaces/default/images/kete2.png") 0 0 repeat';
|
---|
199 | documentBasket.style.cursor = "default";
|
---|
200 | documentBasket.className = "show";
|
---|
201 |
|
---|
202 | //put the full view link in
|
---|
203 | var fullView = document.createElement('a');
|
---|
204 | documentPages.appendChild(fullView);
|
---|
205 |
|
---|
206 | //Find the collection in the cgi parameters
|
---|
207 | var url = window.location.href;
|
---|
208 | var colstart = url.indexOf("&c=");
|
---|
209 | var collectionName = "";
|
---|
210 | if (colstart != -1)
|
---|
211 | {
|
---|
212 | var colend = url.indexOf("&", (colstart + 1));
|
---|
213 | if (colend == -1)
|
---|
214 | {
|
---|
215 | colend = url.length - 1;
|
---|
216 | }
|
---|
217 | collectionName = url.substring(colstart + 3, colend);
|
---|
218 | }
|
---|
219 |
|
---|
220 | fullView.appendChild(document.createTextNode('Full View »'));
|
---|
221 | fullView.setAttribute("href","?a=g&sa=documentbasket&c=&s=DisplayDocumentList&rt=r&p.c=" + collectionName);
|
---|
222 | fullView.setAttribute("id","documentpagesFullViewLink");
|
---|
223 |
|
---|
224 | //toggle expand/collapse links
|
---|
225 | var expandLink = YAHOO.util.Dom.get('documentBasketExpandLink');
|
---|
226 | var collapseLink = YAHOO.util.Dom.get('documentBasketCollapseLink');
|
---|
227 | if ( expandLink != null && collapseLink != null ) {
|
---|
228 | expandLink.style.display = 'none';
|
---|
229 | collapseLink.style.display = '';
|
---|
230 | }
|
---|
231 |
|
---|
232 | }
|
---|
233 |
|
---|
234 | function hideDocumentBox() {
|
---|
235 | //alert( arguments.callee );
|
---|
236 | var i = 0;
|
---|
237 | var documentBasket = YAHOO.util.Dom.get('documentbasket');
|
---|
238 | var documentHandle = YAHOO.util.Dom.get('documenthandle');
|
---|
239 | var documentPages = YAHOO.util.Dom.get('documentpages');
|
---|
240 | documentBasket.style.height = oldHeight;
|
---|
241 | documentBasket.style.width = oldWidth;
|
---|
242 | documentBasket.style.background = oldBg;
|
---|
243 | documentBasket.style.cursor = "pointer";
|
---|
244 | documentBasket.className = "hide";
|
---|
245 |
|
---|
246 | while (documentPages.hasChildNodes()) {
|
---|
247 | documentPages.removeChild(documentPages.firstChild);
|
---|
248 | }
|
---|
249 |
|
---|
250 | while (documentHandle.hasChildNodes()) {
|
---|
251 | documentHandle.removeChild(documentHandle.firstChild);
|
---|
252 | }
|
---|
253 |
|
---|
254 | updateDocumentImages();
|
---|
255 | //updateDocumentCount();
|
---|
256 |
|
---|
257 | //toggle expand/collapse links
|
---|
258 | var expandLink = YAHOO.util.Dom.get('documentBasketExpandLink');
|
---|
259 | var collapseLink = YAHOO.util.Dom.get('documentBasketCollapseLink');
|
---|
260 | if ( expandLink != null && collapseLink != null ) {
|
---|
261 | expandLink.style.display = '';
|
---|
262 | collapseLink.style.display = 'none';
|
---|
263 | }
|
---|
264 |
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | function addDocument(el){
|
---|
269 | var addurl = "?a=pr&rt=r&ro=1&s=AddDocument&c=&s1.id=2&o=XML&hhf=[{\"name\":\"Cache-Control\", \"value\":\"no-cache\"}]&s1.item=" + el.id;
|
---|
270 |
|
---|
271 | var addSuccess = function(o){
|
---|
272 | var result = o.responseXML;
|
---|
273 | var items = result.getElementsByTagName('item');
|
---|
274 |
|
---|
275 | if (items.length < 0){
|
---|
276 |
|
---|
277 | var item = items[0];
|
---|
278 | var documentbasket = YAHOO.util.Dom.get('documentbasket');
|
---|
279 | var documentPages = YAHOO.util.Dom.get('documentpages');
|
---|
280 | docList[docList.length]= item;
|
---|
281 | var parent =el.parentNode;
|
---|
282 | if (parent == null) return;
|
---|
283 | parent.removeChild(el);
|
---|
284 | var itemID = item.getAttribute('collection')+":"+item.getAttribute('name');
|
---|
285 | //added
|
---|
286 | if (parent !=null && parent.id == "documentberries"){
|
---|
287 |
|
---|
288 | var root = YAHOO.util.Dom.get(itemID+":root");
|
---|
289 | var section = YAHOO.util.Dom.get(itemID+":section");
|
---|
290 |
|
---|
291 | if(root!=null && root.id.indexOf(itemID) !=-1){
|
---|
292 | parent.removeChild(root);
|
---|
293 | }
|
---|
294 |
|
---|
295 | if(section!=null && section.id.indexOf(itemID) !=-1){
|
---|
296 | parent.removeChild(section);
|
---|
297 | }
|
---|
298 |
|
---|
299 | }
|
---|
300 |
|
---|
301 | if (!YAHOO.util.Dom.get('hideview') && docList.length < 13){
|
---|
302 |
|
---|
303 | while (documentpages.hasChildNodes()) {
|
---|
304 | documentpages.removeChild(documentpages.firstChild);
|
---|
305 | }
|
---|
306 |
|
---|
307 | for (var i =0; i < docList.length; i++ ){
|
---|
308 | var img = document.createElement('img');
|
---|
309 | img.src = gs.imageURLs.pageIcon;
|
---|
310 | documentpages.appendChild(img);
|
---|
311 | }
|
---|
312 |
|
---|
313 | } else {
|
---|
314 |
|
---|
315 | if (YAHOO.util.Dom.get('hideview')){
|
---|
316 | var documentBasket = YAHOO.util.Dom.get('documentbasket');
|
---|
317 | var documentPages = YAHOO.util.Dom.get('documentpages');
|
---|
318 | var doclist = YAHOO.util.Dom.get('doclist');
|
---|
319 | var tid = el.id;
|
---|
320 | var documentItem;
|
---|
321 | var documentElement = document.createElement('li');
|
---|
322 |
|
---|
323 | for (var i in docList){
|
---|
324 | documentItem = docList[i];
|
---|
325 | var id = documentItem.getAttribute('collection')+":"+documentItem.getAttribute('name');
|
---|
326 |
|
---|
327 | if (id == tid){
|
---|
328 | var title = documentItem.getAttribute('title');
|
---|
329 | var root_title = documentItem.getAttribute('root_title');
|
---|
330 | if (root_title != ""){
|
---|
331 | root_title +=":";
|
---|
332 | }
|
---|
333 |
|
---|
334 | title = root_title+title;
|
---|
335 | if (title.length > 50){
|
---|
336 | title = title.substring(0,20)+" ... "+title.substr(title.length-35,35);
|
---|
337 | }
|
---|
338 |
|
---|
339 | documentElement.appendChild(document.createTextNode(title));
|
---|
340 | documentElement.setAttribute("class","documentitem");
|
---|
341 | doclist.appendChild(documentElement);
|
---|
342 | var heightStr = documentBasket.style.height+"";
|
---|
343 | var height =parseInt(heightStr.substring(0,heightStr.length-2)) +18;
|
---|
344 | documentBasket.style.height = height;
|
---|
345 | documentPages.style.height = height;
|
---|
346 | break;
|
---|
347 | }
|
---|
348 |
|
---|
349 | }
|
---|
350 |
|
---|
351 | }
|
---|
352 |
|
---|
353 | }
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 | var addFailure = function(o){
|
---|
358 | }
|
---|
359 |
|
---|
360 | var addcallback = {
|
---|
361 | success:addSuccess,
|
---|
362 | failure:addFailure
|
---|
363 | }
|
---|
364 |
|
---|
365 | YAHOO.util.Connect.asyncRequest(request_type , addurl , addcallback);
|
---|
366 | }
|
---|
367 |
|
---|
368 | YAHOO.util.Event.addListener(window, 'load', dmcheckout);
|
---|
369 | //YAHOO.util.Event.addListener(window, 'click', documentBoxUpdate);
|
---|
370 |
|
---|