]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
put reminder in for refactoring
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / rdetail.js
1 /* */
2
3 attachEvt("common", "run", rdetailDraw);
4 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
5 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
6
7 var record = null;
8 var cp_statuses = null;
9 var recordsCache = [];
10
11 var copyRowParent = null;
12 var copyRow = null;
13 var statusRow = null;
14 var numStatuses = null;
15 var defaultCN;
16 var callnumberCache = {};
17 var rdetailLocalOnly = true;
18 var globalCNCache       = {};
19 var localTOC;
20 var cachedRecords;
21
22
23
24 var nextContainerIndex;
25
26 function rdetailReload() {
27         var args = {};
28         args[PARAM_LOCATION] = getNewSearchLocation();
29         args[PARAM_DEPTH] = depthSelGetDepth();
30         goTo(buildOPACLink(args));
31 }
32
33 var nextRecord;
34 var prevRecord;
35
36 var rdetailPrev = null;
37 var rdetailNext = null;
38 var rdetailStart = null;
39 var rdetailEnd = null;
40
41 /* looks to see if we have a next and/or previous record in the
42 record cache, if so, set up the nav links */
43 function rdetailSetPaging() {
44
45         cachedRecords = JSON2js(cookieManager.read(COOKIE_SRIDS));
46         if(!(cachedRecords && cachedRecords.ids)) return;
47
48         for( var i = 0; i < cachedRecords.ids.length; i++ ) {
49                 var rec = cachedRecords.ids[i];
50                 if( rec == getRid() ) {
51                         if( i > 0 ) prevRecord = cachedRecords.ids[i-1];
52                         if( i < cachedRecords.ids.length - 1 )
53                                 nextRecord = cachedRecords.ids[i+1];
54                         break;
55                 }
56         }
57
58         $('np_offset').appendChild(text(i+1));
59         $('np_count').appendChild(text(cachedRecords.ids.length));
60
61         if(prevRecord) {
62                 unHideMe($('np_table'));
63                 unHideMe($('np_prev'));
64                 unHideMe($('np_start'));
65                 rdetailPrev = function() { _rdetailNav(prevRecord); };
66                 rdetailStart = function() { _rdetailNav(cachedRecords.ids[0]); };
67         }
68
69         if(nextRecord) {
70                 unHideMe($('np_table'));
71                 unHideMe($('np_next'));
72                 unHideMe($('np_end'));
73                 rdetailNext = function() { _rdetailNav(nextRecord); };
74                 rdetailEnd = function() { _rdetailNav(cachedRecords.ids[cachedRecords.ids.length-1]); };
75         }
76
77         runEvt('rdetail', 'nextPrevDrawn', i, cachedRecords.ids.length);
78 }
79
80
81 function _rdetailNav(id) {
82         var args = {};
83         args[PARAM_RID] = id;
84         goTo(buildOPACLink(args));
85 }
86
87 function rdetailDraw() {
88
89         detachAllEvt('common','depthChanged');
90         detachAllEvt('common','locationUpdated');
91         attachEvt('common','depthChanged', rdetailReload);
92         attachEvt('common','locationUpdated', rdetailReload);
93         attachEvt('common','holdUpdated', rdetailReload);
94         attachEvt('common','holdUpdateCanceled', rdetailReload);
95
96         copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
97         copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
98         statusRow = G.ui.rdetail.cp_status.parentNode;
99         statusRow.id = '__rdsrow';
100
101         G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
102         G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
103
104         if(getLocation() == globalOrgTree.id())
105                 hideMe(G.ui.rdetail.cp_info_all);
106
107         var req = new Request(FETCH_RMODS, getRid());
108         req.callback(_rdetailDraw);
109         req.send();
110
111         rdetailSetPaging();
112 }
113
114 function buildunAPISpan (span, type, id) {
115         var cgi = new CGI();
116         var d = new Date();
117
118         addCSSClass(span,'unapi-id');
119
120         span.setAttribute(
121                 'title',
122                 'tag:' + cgi.server_name + ',' +
123                         d.getFullYear() +
124                         ':' + type + '/' + id
125         );
126 }
127
128 var rdeatilMarcFetched = false;
129 function rdetailViewMarc(r,id) {
130         hideMe($('rdetail_extras_loading'));
131         $('rdetail_view_marc_box').innerHTML = r.getResultObject();
132
133         var d = new Date();
134
135         var span = div.appendChild( elem('abbr') );
136
137         buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
138
139         /* add the unapi span inside a hidden div */
140         $('rdetail_view_marc_box').insertBefore(span, $('rdetail_view_marc_box').firstChild);
141 }
142
143
144 function rdetailShowLocalCopies() {
145
146         var found = false;
147         var rows = copyRowParent.getElementsByTagName("tr");
148         for( var r in rows ) {
149                 var row = rows[r];
150                 if( row.parentNode != copyRowParent ) continue; /* don't hide copy details sub-rows */
151                 if(row.id == "__rdsrow") continue;
152                 if(row.getAttribute && row.getAttribute("local")) {
153                         unHideMe(row);
154                         found = true;
155                 } else {
156                         hideMe(row);
157                 }
158         }
159
160         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
161         hideMe(G.ui.rdetail.cp_info_local);
162         unHideMe(G.ui.rdetail.cp_info_all);
163         rdetailLocalOnly = true;
164 }
165
166 function rdetailShowAllCopies() {
167         var rows = copyRowParent.getElementsByTagName("tr");
168         for( var r in rows ) 
169                 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
170                         unHideMe(rows[r]);
171
172         hideMe(G.ui.rdetail.cp_info_all);
173         unHideMe(G.ui.rdetail.cp_info_local);
174         hideMe(G.ui.rdetail.cp_info_none);
175         rdetailLocalOnly = false;
176 }
177
178
179 function _rdetailDraw(r) {
180         record = r.getResultObject();
181
182         runEvt('rdetail', 'recordRetrieved', record.doc_id());
183
184         G.ui.rdetail.title.appendChild(text(record.title()));
185         buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
186         G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
187         G.ui.rdetail.edition.appendChild(text(record.edition()));
188         G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
189         G.ui.rdetail.publisher.appendChild(text(record.publisher()));
190         $('rdetail_physical_desc').appendChild(text(record.physical_description()));
191         G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
192         setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
193         G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
194
195         $('rdetail_place_hold').setAttribute(
196                 'href','javascript:holdsDrawEditor({record:"'+record.doc_id()+'",type:"T"});');
197
198         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
199         runEvt("rdetail", "recordDrawn");
200         recordsCache.push(record);
201
202         rdetailSetExtrasSelector();
203
204         var breq = new Request(FETCH_BRE, [getRid()]);
205         breq.callback( rdetailCheckDeleted );
206         breq.send();
207
208         var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
209         req.callback(rdetailHandleAddedContent);
210         req.send();
211
212         resultBuildCaches( [ record ] );
213         resultDrawSubjects();
214         resultDrawSeries();
215 }
216
217 function rdetailCheckDeleted(r) {
218         var br = r.getResultObject()[0];
219         if( br.deleted() == 1 ) {
220                 hideMe($('rdetail_place_hold'));
221                 $('rdetail_more_actions_selector').disabled = true;
222                 unHideMe($('rdetail_deleted_exp'));
223         }
224 }
225
226 function rdetailSetExtrasSelector() {
227         if(!grabUser()) return;
228         unHideMe($('rdetail_more_actions'));
229
230         var req = new Request( 
231                 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
232         req.callback(rdetailAddBookbags);
233         req.send();
234 }
235
236 function rdetailAddBookbags(r) {
237
238         var containers = r.getResultObject();
239         var selector = $('rdetail_more_actions_selector');
240         var found = false;
241         var index = 3;
242         doSelectorActions(selector);
243
244         for( var i = 0; i != containers.length; i++ ) {
245                 found = true;
246                 var container = containers[i];
247                 insertSelectorVal( selector, index++, container.name(), 
248                         "container_" + container.id(), rdetailAddToBookbag,  1 );
249         }
250
251         nextContainerIndex = index;
252 }
253
254 var _actions = {};
255 function rdetailNewBookbag() {
256         var name = prompt($('rdetail_bb_new').innerHTML,"");
257         if(!name) return;
258
259         var id;
260         if( id = containerCreate( name ) ) {
261                 alert($('rdetail_bb_success').innerHTML);
262                 var selector = $('rdetail_more_actions_selector');
263                 insertSelectorVal( selector, nextContainerIndex++, name, 
264                         "container_" + id, rdetailAddToBookbag, 1 );
265                 setSelector( selector, 'start' );
266         }
267 }
268
269
270 function rdetailAddToBookbag() {
271         var selector = $('rdetail_more_actions_selector');
272         var id = selector.options[selector.selectedIndex].value;
273         setSelector( selector, 'start' );
274
275         if( containerCreateItem( id.substring(10), record.doc_id() )) {
276                 alert($('rdetail_bb_item_success').innerHTML);
277         }
278 }
279
280
281
282 var rdetailTocFetched           = false;
283 var rdetailReviewFetched        = false;
284 var rdetailMarcFetched          = false;
285
286 function rdetailShowExtra(type, args) {
287
288         hideMe($('rdetail_copy_info_div'));
289         hideMe($('rdetail_reviews_div'));
290         hideMe($('rdetail_toc_div'));
291         hideMe($('rdetail_marc_div'));
292         hideMe($('cn_browse'));
293         hideMe($('rdetail_cn_browse_div'));
294         hideMe($('rdetail_notes_div'));
295
296         removeCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
297         removeCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
298         removeCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
299         removeCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
300         removeCSSClass($('rdetail_annotation_link'), 'rdetail_extras_selected');
301         removeCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
302
303         var req;
304         switch(type) {
305
306                 case "copyinfo": 
307                         unHideMe($('rdetail_copy_info_div')); 
308                         addCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
309                         break;
310
311                 case "reviews": 
312                         addCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
313                         unHideMe($('rdetail_reviews_div')); 
314                         if(rdetailReviewFetched) break;
315                         unHideMe($('rdetail_extras_loading'));
316                         rdetailReviewFetched = true;
317                         req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
318                         req.callback(rdetailShowReviews);
319                         req.send();
320                         break;
321
322                 case "toc": 
323                         addCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
324                         unHideMe($('rdetail_toc_div'));
325                         if(rdetailTocFetched) break;
326                         unHideMe($('rdetail_extras_loading'));
327                         rdetailTocFetched = true;
328                         if(localTOC) {
329                                 hideMe($('rdetail_extras_loading'));
330                                 $('rdetail_toc_div').innerHTML = record.toc().replace(/--/g, "<br/>");
331                         } else {
332                                 req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
333                                 req.callback(rdetailShowTOC);
334                                 req.send();
335                         }
336                         break;
337
338                 case "marc": 
339                         addCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
340                         unHideMe($('rdetail_marc_div')); 
341                         if(rdetailMarcFetched) return;
342                         unHideMe($('rdetail_extras_loading'));
343                         rdetailMarcFetched = true;
344                         req = new Request( FETCH_MARC_HTML, record.doc_id() );
345                         req.callback(rdetailViewMarc); 
346                         req.send();
347                         break;
348
349                 case 'cn':
350                         addCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
351                         unHideMe($('rdetail_cn_browse_div'));
352                         rdetailShowCNBrowse(defaultCN, getLocation(), null, true);
353                         break;
354
355         }
356 }
357
358 function rdetailVolumeDetails(args) {
359         var row = $(args.rowid);
360         var tbody = row.parentNode;
361         cpdBuild( tbody, row, record, args.cn, args.org, args.depth );
362         return;
363 }
364
365
366 function rdetailBuildCNList() {
367
368         var select = $('cn_browse_selector');
369         var index = 0;
370         var arr = [];
371         for( var cn in callnumberCache ) arr.push( cn );
372         arr.sort();
373
374         if( arr.length == 0 ) {
375                 hideMe($('rdetail_cn_browse_select_div'));
376                 return;
377         }
378
379         for( var i in arr ) {
380                 var cn = arr[i];
381                 var opt = new Option(cn);
382                 select.options[index++] = opt;
383         }
384         select.onchange = rdetailGatherCN;
385 }
386
387 function rdetailGatherCN() {
388         var cn = getSelectorVal($('cn_browse_selector'));
389         rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
390         setSelector( $('cn_browse_selector'), cn );
391 }
392
393
394 function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
395         if(!cn) return;
396         rdetailBuildCNList();
397         setSelector( $('cn_browse_selector'), cn );
398         hideMe($('rdetail_copy_info_div'));
399         hideMe($('rdetail_reviews_div'));
400         hideMe($('rdetail_toc_div'));
401         hideMe($('rdetail_marc_div'));
402         unHideMe($('rdetail_cn_browse_div'));
403         unHideMe($('cn_browse'));
404         if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
405         cnBrowseGo(cn, loc, depth);
406 }
407
408 function rdetailHandleAddedContent(r) {
409         var resp = r.getResultObject();
410         if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
411         if( resp.TOC == 'true' ) {
412                 unHideMe($('rdetail_toc_link'));
413         } else {
414                 if( record.toc() ) {
415                         localTOC = true;
416                         unHideMe($('rdetail_toc_link'));
417                 }
418         }
419 }
420
421
422 function rdetailShowReviews(r) {
423         hideMe($('rdetail_extras_loading'));
424         var res = r.getResultObject();
425         var par = $('rdetail_reviews_div');
426         var template = par.removeChild($('rdetail_review_template'));
427         if( res && res.length > 0 ) {
428                 unHideMe($('rdetail_reviews_link'));
429                 for( var i = 0; i != res.length; i++ ) {
430                         var rev = res[i];       
431                         if( rev.text && rev.info ) {
432                                 var node = template.cloneNode(true);
433                                 $n(node, 'review_header').appendChild(text(rev.info));
434                                 $n(node, 'review_text').appendChild(text(rev.text));
435                                 par.appendChild(node);
436                         }
437                 }
438         }
439 }
440
441 function rdetailShowTOC(r) {
442         hideMe($('rdetail_extras_loading'));
443         var resp = r.getResultObject();
444         if(resp) {
445                 unHideMe($('rdetail_toc_link'));
446                 $('rdetail_toc_div').innerHTML = resp;
447         }
448 }
449
450
451 function rdetailBuildInfoRows() {
452         //var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id(), getLocation(), getDepth())
453         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id());
454         req.callback(_rdetailBuildInfoRows);
455         req.send();
456 }
457
458 /* pre-allocate the copy info table with all org units in correct order */
459 function _rdetailRows(node) {
460
461         if(node) {
462
463                 var row = copyRow.cloneNode(true);
464                 row.id = "cp_info_" + node.id();
465
466                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
467                 var cntd  = findNodeByName( row, config.names.rdetail.cn_cell );
468                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
469                 var actions = $n(row, 'rdetail_actions_cell');
470         
471                 var p = libtd.getElementsByTagName('a')[0];
472                 libtd.insertBefore(text(node.name()), p);
473                 //libtd.appendChild(text(node.name()));
474                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
475         
476                 if(!findOrgType(node.ou_type()).can_have_vols()) {
477
478                         row.removeChild(cntd);
479                         row.removeChild(cpctd);
480                         row.removeChild(actions);
481                         row.setAttribute('novols', '1');
482
483                         libtd.setAttribute("colspan", numStatuses + 3 );
484                         libtd.colSpan = numStatuses + 3;
485                         addCSSClass(row, 'copy_info_region_row');
486                 } 
487         
488                 copyRowParent.appendChild(row);
489
490         } else { node = globalOrgTree; }
491
492         for( var c in node.children() ) 
493                 _rdetailRows(node.children()[c]);
494 }
495
496 function rdetailCNPrint(orgid, cn) {
497         /*
498         var arr = cpdBuildPrintWindow( record, orgid);
499         var win = arr[0];
500         var div = arr[1];
501         */
502         var div = cpdBuildPrintWindow( record, orgid);
503         var template = div.removeChild($n(div, 'cnrow'));
504         var rowNode = $("cp_info_" + orgid);
505         cpdStylePopupWindow(div);
506         openWindow(div.innerHTML);
507         /*
508         win.document.body.innerHTML = div.innerHTML;
509         */
510 }
511
512 /* walk through the copy info and build rows where necessary */
513 var localCNFound = false;
514 var ctr = 0;
515 function _rdetailBuildInfoRows(r) {
516
517         _rdetailRows();
518
519         var summary = r.getResultObject();
520         if(!summary) return;
521
522         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
523                 G.ui.rdetail.cp_info_loading);
524
525         var found = false;
526         for( var i = 0; i < summary.length; i++ ) {
527
528                 var arr = summary[i];
529                 globalCNCache[arr[1]] = 1;
530                 var thisOrg = findOrgUnit(arr[0]);
531                 var rowNode = $("cp_info_" + thisOrg.id());
532                 if(!rowNode) continue;
533
534                 /* set up the print link (not done) */
535                 var pn = rowNode.previousSibling;
536                 if( pn && pn.getAttribute('novols') ) {
537                         var a = $n(pn, 'lib_print_link');
538                         a.setAttribute('href',
539                                 'javascript:rdetailCNPrint('+thisOrg.id()+',"'+arr[1]+'");');
540                         /*unHideMe(a);*/
541                         /* make this more smarter */
542                 }
543
544                 if(rowNode.getAttribute("used")) {
545
546                         if( rowNode.nextSibling )
547                                 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
548                         else
549                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
550                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
551                         n.appendChild(text(thisOrg.name()));
552                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
553                         rowNode.id = "cp_info_" + thisOrg.id() + '_' + (++ctr); /* ensure a unique id */
554
555                 } else {
556                         rowNode.setAttribute("used", "1");
557                 }
558
559                 var cpc_temp = rowNode.removeChild(
560                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
561
562                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
563
564                 var isLocal = false;
565                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { 
566                         found = true; 
567                         isLocal = true; 
568                         if(!localCNFound) {
569                                 localCNFound = true;
570                                 defaultCN = arr[1];
571                         }
572                 }
573
574                 if(isLocal) unHideMe(rowNode);
575
576                 rdetailSetPath( thisOrg, isLocal );
577                 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg );
578
579                 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
580         }
581
582         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
583 }
584
585
586 function rdetailBuildBrowseInfo(row, cn, local, orgNode) {
587
588         /* used for building the shelf browser */
589         if(local) {
590                 var cache = callnumberCache[cn];
591                 if( cache ) cache.count++;
592                 else callnumberCache[cn] = { count : 1 };
593         }
594
595         var depth = getDepth();
596         if( !local ) depth = findOrgDepth(globalOrgTree);
597
598         $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
599
600         _debug('setting action clicks for cn ' + cn);
601
602         var dHref = 'javascript:rdetailVolumeDetails('+
603                 '{rowid : "'+row.id+'", cn :"'+cn+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
604
605         var bHref = 'javascript:rdetailShowCNBrowse("' + cn + '", '+orgNode.id()+', "'+depth+'");'; 
606
607         $n(row, 'details').setAttribute('href', dHref);
608         $n(row, 'browse').setAttribute('href', bHref);
609
610         if(isXUL()) {
611                 unHideMe($n(row, 'hold_div'));
612                 $n(row, 'hold').onclick = function() {
613                         var req = new Request(FETCH_VOLUME_BY_INFO, cn, record.doc_id(), orgNode.id());
614                         req.callback(
615                                 function(r) {
616                                         var vol = r.getResultObject();
617                                         holdsDrawEditor({type: 'V', volumeObject : vol});
618                                 }
619                         );
620                         req.send();
621                 };
622         }
623 }
624
625
626 /* sets the path to org as 'active' and displays the 
627         path if it's local */
628 function rdetailSetPath(org, local) {
629         if( findOrgDepth(org) == 0 ) return;
630         var row = $("cp_info_" + org.id());
631         row.setAttribute("hasinfo", "1");
632         if(local) {
633                 unHideMe(row);
634                 row.setAttribute("local", "1");
635         }
636         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
637 }
638
639
640
641 /**
642  * Append all the statuses for a give summary to the 
643  * copy summary table */
644 function rdetailApplyStatuses( row, template, statuses ) {
645         for( var j in _statusPositions ) {
646                 var stat = _statusPositions[j];
647                 var val = statuses[stat.id()];
648                 var nn = template.cloneNode(true);
649                 if(val) nn.appendChild(text(val));
650                 else nn.appendChild(text(0));
651                 row.appendChild(nn);    
652         }
653 }
654
655
656 /* --------------------------------------------------------------------- */
657 var _statusPositions = {};
658
659 /**
660  * Add one td (creating a new column) to the copy summary
661  * table for each holdable copy status
662  */
663 function rdetailBuildStatusColumns() {
664
665         rdetailGrabCopyStatuses();
666         var parent = statusRow;
667         var template = parent.removeChild(G.ui.rdetail.cp_status);
668
669         var i = 0;
670         for( i = 0; i < cp_statuses.length; i++ ) {
671
672                 var c = cp_statuses[i];
673
674                 if(c && c.holdable()) {
675
676                         var name = c.name();
677                         _statusPositions[i] = c;
678                         var node = template.cloneNode(true);
679                         var data = findNodeByName( node, config.names.rdetail.cp_status);
680
681                         data.appendChild(text(name));
682                         parent.appendChild(node);
683                 }       
684         }       
685
686         numStatuses = 0;
687         for(x in _statusPositions) numStatuses++; 
688 }
689
690 function rdetailGrabCopyStatuses() {
691         if(cp_statuses) return cp_statuses;
692    var req = new Request(FETCH_COPY_STATUSES);
693    req.send(true);
694         cp_statuses = req.result();
695         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
696 }
697
698 function _rdetailSortStatuses(a, b) {
699         return parseInt(a.id()) - parseInt(b.id());
700 }
701
702