1 /* A very simple client that shows a basic usage of the pz2.js
4 // create a parameters array and pass it to the pz2's constructor
5 // then register the form submit event with the pz2.search function
6 // autoInit is set to true on default
7 var usesessions = false;
8 var pazpar2path = '/service-proxy/';
9 var showResponseType = '';
10 // Facet configuration
11 var querys = {'su': '', 'au': '', 'xt': ''};
12 var query_client_server = {'su': 'subject', 'au': 'author', 'xt': 'xtargets'};
13 var querys_server = {};
15 var state = new State();
16 // Fail to get JSON working stabil.
17 var showResponseType = 'xml';
21 var recToShowPageSize = 20;
22 var recToShow = recToShowPageSize;
26 var curDetRecData = null;
27 var curSort = 'relevance';
28 var curFilter = 'ALL';
29 var submitted = false;
33 var tab = "recordview";
38 var previousOrientation = window.orientation || 0;
41 window.addEventListener("load",function() {
43 setTimeout(function(){
44 // Hide the address bar!
45 window.scrollTo(0, 1);
49 function calcRecPerPage() {
50 state.width = window.innerWidth;
51 state.height = window.innerHeight;
52 return Math.max(Math.round((state.height - 88 - 40) / 60), 5) ;
55 function checkOrientation() {
56 if(state.height != window.innerHeight){
57 var newPageSize = calcRecPerPage();
58 //alert("orient change: Dimension " + state.width + " " + state.height + " Old Rec/page " + state.recPerPage + " New: " + newPageSize);
59 state.setRecPerPage(newPageSize);
60 my_paz.show(state.getStartWith(), state.getRecPerPage(), curSort);
64 state.setRecPerPage(calcRecPerPage());
66 window.addEventListener("resize", checkOrientation, false);
67 window.addEventListener("orientationchange", checkOrientation, false);
69 // (optional) Android doesn't always fire orientationChange on 180 degree turns
70 //setInterval(checkOrientation, 2000);
72 var imageHelper = new ImageHelper();
74 if (document.location.hash == '#pazpar2' || document.location.search.match("useproxy=false")) {
76 pazpar2path = '/pazpar2/search.pz2';
77 showResponseType = 'xml';
80 my_paz = new pz2( { "onshow": my_onshow,
81 // "showtime": 2000, //each timer (show, stat, term, bytarget) can be specified this way
82 "pazpar2path": pazpar2path,
85 "onterm": my_onterm_iphone,
86 "termlist": "xtargets,subject,author",
88 "usesessions" : usesessions,
89 "showResponseType": showResponseType,
90 "onrecord": my_onrecord,
91 "errorhandler" : my_onerror}
95 // pz2.js event handlers:
97 function my_onerror(error) {
98 alert("Unhandled error: " + error.code);
101 case "8": alert("No resources were selected for the search"); break;
102 // target not configured, this is a pazpar2 bug
103 // but for now simply research
114 auth.check(loggedIn, login);
117 alert("Unhandled error: " + error.code);
118 throw error; // display error in JavaScript console
122 //FF has a bug and un-escaped location.hash, don't use it
123 function getRealHash() {
124 var i = window.location.href.indexOf('#');
125 return i > -1 ? window.location.href.substr(i) : "";
128 function loginFormSubmit() {
129 triedUser = document.loginForm.username.value;
130 triedPass = document.loginForm.password.value;
131 auth.login( {"username": triedUser,
132 "password": triedPass},
136 function handleKeyPress(e)
140 key = window.event.keyCode;
144 if(key == 13 || key == 10)
146 button = document.getElementById('button');
156 function authCb(authData) {
157 if (!authData.loginFailed) {
162 if (authData.loggedIn == true) {
163 showhide("recordview");
167 function logOutClick() {
168 auth.logOut(authCb, authCb);
171 function loggedOut() {
172 var login = document.getElementById("login");
173 login.innerHTML = 'Login';
176 function loggingOutFailed() {
177 alert("Logging out failed");
185 auth.logOut(loggedOut, loggingOutFailed, true);
188 function logInOrOut() {
189 var loginElement = document.getElementById("login");
190 if (loginElement.innerHTML == 'Login')
195 function loggedIn() {
196 var login = document.getElementById("login");
197 login.innerHTML = 'Logout';
198 document.getElementById("log").innerHTML = login.innerHTML;
202 function auth_check() {
203 auth.check(loggedIn, login);
208 function auth_check_item(methods) {
209 auth.check(itemMain, function () { window.location = "login.html" + window.location.search + "&page="+window.location.pathname;}, methods );
213 function itemMain() {
215 if (auth.styleCss && document.getElementById("stylesheet")) {
216 document.getElementById("stylesheet").href = auth.styleCss;
219 // parse HTTP GET params (!!!)
220 window.location.parameters = parseQueryString(window.location.search);
221 var params = window.location.parameters;
222 // query params used by optional record_facets.js
223 if (window.RecordFacets != undefined) {
224 this.recordFacets = new RecordFacets();
225 this.recordFacets.setRequestParams(params);
227 prefixRecId = params["prefixrecid"];
228 query_state = params["query_state"];
229 recQuery = params["recordquery"];
230 // load templating components
233 renderComponent("authLogoComp", auth);
234 renderComponent("authInfoComp", auth);
235 renderComponent("infoComp",null);
236 renderComponent("backToSearchComp",query_state);
238 my_paz = new pz2( {"pazpar2path": auth.servicePath,
239 "usesessions" : usesessions,
240 "errorhandler" : my_onerror,
241 "onrecord" : my_onrecord
244 // http params have highest priority
245 showDetails(prefixRecId,recQuery);
250 // Pz2.js event handlers:
252 function my_oninit() {
257 function showMoreRecords() {
259 recToShow += recToShowPageSize;
260 for ( ; i < recToShow && i < state.recPerPage; i++) {
261 var element = document.getElementById(recIDs[i]);
263 element.style.display = '';
265 if (i == state.recPerPage) {
266 var element = document.getElementById('recdiv_END');
268 element.style.display = 'none';
272 function hideRecords() {
273 for ( var i = 0; i < recToShow; i++) {
274 var element = document.getElementById(recIDs[i]);
275 if (element && recIDs != curDetRecId)
276 element.style.display = 'none';
278 var element = document.getElementById('recdiv_END');
280 element.style.display = 'none';
283 function showRecords() {
284 for (var i = 0 ; i < recToShow && i < state.recPerPage; i++) {
285 var element = document.getElementById(recIDs[i]);
287 element.style.display = '';
289 var element = document.getElementById('recdiv_END');
291 if (i == state.recPerPage)
292 element.style.display = 'none';
294 element.style.display = '';
298 function my_onshow(data) {
300 totalRec = data.merged;
302 var pager = document.getElementById("pager");
303 pager.innerHTML = "";
305 pager.innerHTML +='<div class="status">Displaying: '
306 + (data.start + 1) + ' to ' + (data.start + data.num) +
307 ' of ' + data.merged + ' (found: '
308 + data.total + ')</div>';
310 var results = document.getElementById("results");
313 if (data.hits == undefined)
316 for (var i = 0; i < data.hits.length; i++) {
317 var hit = data.hits[i];
318 var recDivID = "recdiv_" + hit.recid;
319 recIDs[i] = recDivID;
322 style = ' style="display:none" ';
323 html.push('<li class="img" id="' + recDivID + '" ' + style + '>' );
324 html.push('<a class="img" href="#' + i + '" id="rec_'+hit.recid + '" onclick="showDetails(this.id);return false;" >');
326 var useThumbnails = hit["md-use_thumbnails"];
327 var thumburls = hit["md-thumburl"];
328 if (thumburls && (useThumbnails == undefined || useThumbnails == "1")) {
329 var thumbnailtag = imageHelper.getImageTagByRecId(hit.recid,"md-thumburl", 60, "S");
330 html.push(thumbnailtag);
332 if (hit["md-isbn"] != undefined) {
333 var coverimagetag = imageHelper.getImageTagByRecId(hit.recid, "md-isbn", 60, "S");
334 if (coverimagetag.length>0) {
335 html.push(coverimagetag);
343 html.push('<a href="#" id="rec_'+hit.recid + '" onclick="showDetails(this.id);return false;">');
344 html.push(hit["md-title"]);
347 if (hit["md-title-remainder"] != undefined) {
348 html.push('<a href="#" id="rec_'+hit.recid + '" onclick="showDetails(this.id);return false;">');
349 html.push(hit["md-title-remainder"]);
353 if (hit["md-author"] != undefined) {
354 html.push('<a href="#" id="rec_'+hit.recid + '" onclick="showDetails(this.id);return false;">');
355 html.push(hit["md-author"]);
359 else if (hit["md-title-responsibility"] != undefined) {
360 html.push('<a href="#" id="rec_'+hit.recid + '" onclick="showDetails(this.id);return false;">');
361 html.push(hit["md-title-responsibility"]);
365 for (var idx = lines ; idx < 2 ; idx++) {
366 html.push('<a href="#" id="rec_'+hit.recid + '" onclick="showDetails(this.id);return false;">');
371 html.push('<a href="go.html" id="rec_'+ hit.recid + '" >');
372 html.push("item page;");
376 if (hit.recid == curDetRecId) {
377 html.push(renderDetails_iphone(curDetRecData));
382 if (data.activeclients == 0)
385 // set up "More..." if needed.
386 style = 'display:none';
387 if (recToShow < recPerPage) {
388 style = 'display:block';
390 html.push('<li class="img" id="recdiv_END" style="' + style + '"><a onclick="showMoreRecords()">More...</a></li>');
392 replaceHtml(results, html.join(''));
395 function my_onstat(data) {
396 var stat = document.getElementById("stat");
400 stat.innerHTML = '<b> .:STATUS INFO</b> -- Active clients: '
402 + '/' + data.clients + ' -- </span>'
403 + '<span>Retrieved records: ' + data.records
404 + '/' + data.hits + ' :.</span>';
407 function showhide(newtab, hash) {
408 var showtermlist = false;
412 if (tab == "recordview") {
413 document.getElementById("recordview").style.display = '';
414 if (hash != undefined)
415 document.location.hash = hash;
418 document.getElementById("recordview").style.display = 'none';
420 if (tab == "xtargets") {
421 document.getElementById("term_xtargets").style.display = '';
425 document.getElementById("term_xtargets").style.display = 'none';
427 if (tab == "subjects") {
428 document.getElementById("term_subjects").style.display = '';
432 document.getElementById("term_subjects").style.display = 'none';
434 if (tab == "authors") {
435 document.getElementById("term_authors").style.display = '';
439 document.getElementById("term_authors").style.display = 'none';
441 if (tab == "detailview") {
442 document.getElementById("detailview").style.display = '';
445 document.getElementById("detailview").style.display = 'none';
446 var element = document.getElementById("rec_" + curDetRecId);
447 if (element != undefined)
448 element.scrollIntoView();
451 if (showtermlist == false)
452 document.getElementById("termlist").style.display = 'none';
454 document.getElementById("termlist").style.display = '';
456 var tabDiv = document.getElementById("loginDiv");
457 if (tab == "login") {
458 tabDiv.style.display = '';
461 tabDiv.style.display = 'none';
465 function my_onterm(data) {
468 termlists.push('<div id="term_xtargets" >');
469 termlists.push('<h4 class="termtitle">Sources</h4>');
470 termlists.push('<ul class="termlist">');
471 termlists.push('<li> <a href="#" target_id="reset_xt" onclick="limitOrResetTarget(\'reset_xt\',\'All\');return false;">All</a></li>');
472 for (var i = 0; i < data.xtargets.length && i < SourceMax; i++ ) {
473 termlists.push('<li class="termlist"><a href="#" target_id='+data.xtargets[i].id
474 + ' onclick="limitOrResetTarget(this.getAttribute(\'target_id\'), \'' + data.xtargets[i].name + '\');return false;">'
475 + data.xtargets[i].name + ' (' + data.xtargets[i].freq + ')</a></li>');
477 termlists.push('</ul>');
478 termlists.push('</div>');
480 termlists.push('<div id="term_subjects" >');
481 termlists.push('<h4>Subjects</h4>');
482 termlists.push('<ul class="termlist">');
483 termlists.push('<li><a href="#" target_id="reset_su" onclick="limitOrResetQuery(\'reset_su\',\'All\');return false;">All</a></li>');
484 for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) {
485 termlists.push('<li><a href="#" onclick="limitOrResetQuery(\'su\', \'' + data.subject[i].name + '\');return false;">'
486 + data.subject[i].name + ' (' + data.subject[i].freq + ')</a></li>');
488 termlists.push('</ul>');
489 termlists.push('</div>');
491 termlists.push('<div id="term_authors" >');
492 termlists.push('<h4 class="termtitle">Authors</h4>');
493 termlists.push('<ul class="termlist">');
494 termlists.push('<li><a href="#" onclick="limitOrResetQuery(\'reset_au\',\'All\');return false;">All</a></li>');
495 for (var i = 0; i < data.author.length && i < AuthorMax; i++ ) {
496 termlists.push('<li><a href="#" onclick="limitOrResetQuery(\'au\', \'' + data.author[i].name +'\');return false;">'
497 + data.author[i].name
499 + data.author[i].freq
502 termlists.push('</ul>');
503 termlists.push('</div>');
504 var termlist = document.getElementById("termlist");
505 replaceHtml(termlist, termlists.join(''));
510 function my_onterm_iphone(data) {
512 var targets = "reset_xt|All\n";
514 for (var i = 0; i < data.xtargets.length; i++ ) {
516 targets = targets + data.xtargets[i].id + "|" + data.xtargets[i].name + "|" + data.xtargets[i].freq + "\n";
518 termlist["xtargets"] = targets;
519 var subjects = "reset_su|All\n";
520 for (var i = 0; i < data.subject.length; i++ ) {
521 subjects = subjects + "su" + "|" + data.subject[i].name + "|" + data.subject[i].freq + "\n";
523 termlist["subjects"] = subjects;
524 var authors = "reset_au|All\n";
525 for (var i = 0; i < data.author.length; i++ ) {
526 authors = authors + "au" + "|" + data.author[i].name + "|" + data.author[i].freq + "\n";
528 termlist["authors"] = authors;
529 callback.send("termlist", "refresh");
532 function getTargets() {
533 return termlist['xtargets'];
536 function getSubjects() {
537 return termlist['subjects'];
540 function getAuthors() {
541 return termlist['authors'];
544 function my_onrecord(data) {
546 // FIXME: record is async!!
547 clearTimeout(my_paz.recordTimer);
548 // in case on_show was faster to redraw element
549 var detailRecordDiv = document.getElementById('detailrecord');
550 if (!detailRecordDiv)
552 curDetRecData = data;
553 var html = renderDetails_iphone(curDetRecData);
554 detailRecordDiv.innerHTML = html;
555 showhide('detailview');
559 function my_onrecord_iphone(data) {
561 callback.send("record", data.recid, data, data.xtargets[i].freq);
565 function my_onbytarget(data) {
566 var targetDiv = document.getElementById("bytarget");
567 var table ='<table><thead><tr><td>Target ID</td><td>Hits</td><td>Diags</td>'
568 +'<td>Records</td><td>State</td></tr></thead><tbody>';
570 for (var i = 0; i < data.length; i++ ) {
571 table += "<tr><td>" + data[i].id +
572 "</td><td>" + data[i].hits +
573 "</td><td>" + data[i].diagnostic +
574 "</td><td>" + data[i].records +
575 "</td><td>" + data[i].state + "</td></tr>";
578 table += '</tbody></table>';
579 targetDiv.innerHTML = table;
582 ////////////////////////////////////////////////////////////////////////////////
583 ////////////////////////////////////////////////////////////////////////////////
585 // wait until the DOM is ready
588 // document.search.onsubmit = onFormSubmitEventHandler;
589 document.search.query.value = '';
590 document.select.sort.onchange = onSelectDdChange;
591 document.select.perpage.onchange = onSelectDdChange;
592 if (document.location.search.match("inApp=true"))
593 applicationMode(true);
595 applicationMode(false);
597 window.location.parameters = parseQueryString(window.location.search);
598 window.location.parametersMulti = parseQueryStringMulti(window.location.search);
600 // hash params have highest priority, than query params
601 var params = (window.location.hash && window.location.hash.length > 1)
602 ? parseQueryString(getRealHash())
603 : window.location.parameters;
604 var paramsMulti = window.location.parametersMulti;
606 var params = parseQueryString(window.location.search);
608 document.search.query.value = params.query;
609 onFormSubmitEventHandler();
613 controlRegister.loadControls();
615 //append settings to the 'state'
616 loadSettings(function (setts) {
617 state.setFallbackSettings(setts);
618 controlRegister.populateControls(setts); // set controls from cookies
619 controlRegister.populateControls(params); // override from query string
620 stateChanged(params);
625 function applicationMode(newmode)
627 var searchdiv = document.getElementById("searchForm");
631 document.getElementById("heading").style.display="none";
632 searchdiv.style.display = 'none';
636 document.getElementById("nav").style.display="";
637 document.getElementById("normal").style.display="inline";
638 document.getElementById("normal").style.visibility="";
639 searchdiv.style.display = '';
640 //document.search.onsubmit = onFormSubmit;
644 // when search button pressed
645 function onFormSubmitEventHandler()
648 document.location.hash = "query=" + document.search.query.value;
649 //window.location.search = "query=" + document.search.query.value;
656 function onSelectDdChange()
658 if (!submitted) return false;
661 my_paz.show(0, state.recPerPage, curSort);
666 function stateChanged(params) {
667 if (params == undefined)
669 if (params["query"]) {
670 // If this page was accessed with a query param, usually means
671 // new page refresh, but not always!
672 state.reset(); // to ensure it's clean and fallbacks are loaded
674 state.loadParams(params);
675 } else if (params["query_state"]) {
676 // If this page was accessed with a serialized State object
677 state.reset(); // to ensure it's clean and fallbacks are loaded
678 state.deserialize(String(params["query_state"]));
680 document.search.query.value = state.simpleQuery;
681 document.select.sort.value = state.curSort;
682 //document.select.perpage.value = state.recPerPage;
683 if (document.category && document.category.category_filter) {
684 document.category.category_filter.value = state.categoryFilter;
686 if (document.search.query.value != "")
696 function getFacets() {
698 for (var key in querys_server) {
699 if (result.length > 0)
701 result += querys_server[key];
706 function triggerSearch ()
708 // Restore to initial page size. Old stuff
709 recToShow = recToShowPageSize;
712 my_paz.search(document.search.query.value, state.recPerPage, curSort, curFilter, undefined,
714 "limit" : getFacets()
717 showhide("recordview");
720 function loadSelect ()
722 curSort = document.select.sort.value;
723 //state.recPerPage = document.select.perpage.value;
726 // limit the query after clicking the facet
727 function limitQuery(field, value)
729 var newQuery = ' and ' + field + '="' + value + '"';
730 querys[field] += newQuery;
731 document.search.query.value += newQuery;
732 onFormSubmitEventHandler();
733 showhide("recordview");
736 // limit the query after clicking the facet
737 function limitQueryServer(field, value)
739 // Check for client field usage
740 var fieldname = query_client_server[field];
744 var newQuery = fieldname + '=' + value.replace(",", "\\,").replace("|", "\\,");
745 // Does it already exists?
746 if (querys_server[fieldname])
747 querys_server[fieldname] += "," + newQuery;
749 querys_server[fieldname] = newQuery;
750 // document.search.query.value += newQuery;
751 onFormSubmitEventHandler();
752 showhide("recordview");
757 // limit the query after clicking the facet
758 function removeQuery (field, value) {
759 document.search.query.value.replace(' and ' + field + '="' + value + '"', '');
760 onFormSubmitEventHandler();
761 showhide("recordview");
764 // limit the query after clicking the facet
765 function limitOrResetQuery (field, value, selected) {
767 limitOrResetQueryServer(field,value, selected);
770 if (field == 'reset_su' || field == 'reset_au') {
771 var reset_field = field.substring(6);
772 document.search.query.value = document.search.query.value.replace(querys[reset_field], '');
773 querys[reset_field] = '';
774 onFormSubmitEventHandler();
775 showhide("recordview");
778 limitQuery(field, value);
779 //alert("limitOrResetQuerry: query after: " + document.search.query.value);
782 // limit the query after clicking the facet
783 function limitOrResetQueryServer (field, value, selected) {
784 if (field.substring(0,6) == 'reset_') {
785 var clientname = field.substring(6);
786 var fieldname = query_client_server[clientname];
788 fieldname = clientname;
789 delete querys_server[fieldname];
790 onFormSubmitEventHandler();
791 showhide("recordview");
794 limitQueryServer(field, value);
795 //alert("limitOrResetQuerry: query after: " + document.search.query.value);
801 // limit by target functions
802 function limitTarget (id, name)
804 curFilter = 'pz:id=' + id;
811 function delimitTarget ()
820 function limitOrResetTarget(id, name) {
821 if (id == 'reset_xt') {
825 limitTarget(id,name);
829 function drawPager (pagerDiv)
831 //client indexes pages from 1 but pz2 from 0
833 var pages = Math.ceil(totalRec / state.recPerPage);
835 var firstClkbl = ( state.curPage - onsides > 0 )
836 ? state.curPage - onsides
839 var lastClkbl = firstClkbl + 2*onsides < pages
840 ? firstClkbl + 2*onsides
843 var prev = '<span id="prev">Prev</span><b> | </b>';
844 if (state.curPage > 1)
845 var prev = '<a href="#" id="prev" onclick="pagerPrev();">'
846 +'Prev</a><b> | </b>';
849 for(var i = firstClkbl; i <= lastClkbl; i++) {
851 if(i == state.curPage)
852 numLabel = '<b>' + i + '</b>';
854 middle += '<a href="#" onclick="showPage(' + i + ')"> '
855 + numLabel + ' </a>';
858 var next = '<b> | </b><span id="next">Next</span>';
859 if (pages - state.curPage > 0)
860 var next = '<b> | </b><a href="#" id="next" onclick="pagerNext()">'
868 if (lastClkbl < pages)
871 pagerDiv.innerHTML += '<div class="pager">'
872 + prev + predots + middle + postdots + next + '</div>';
875 function showPage(pageNum)
877 //state.curPage = pageNum;
878 state.curPage = pageNum;
880 my_paz.showPage( state.curPage - 1 );
883 // simple paging functions
885 function pagerNext() {
886 if ( totalRec - state.recPerPage*state.curPage > 0) {
894 function pagerPrev() {
895 if ( my_paz.showPrev() != false ) {
898 if (state.curPage <= 0)
899 throw "Zeo or negative current page";
904 // swithing view between targets and records
906 function switchView(view) {
908 var targets = document.getElementById('targetview');
909 var records = document.getElementById('recordview');
913 targets.style.display = "block";
914 records.style.display = "none";
917 targets.style.display = "none";
918 records.style.display = "block";
921 alert('Unknown view.');
925 function hideLogo() {
926 document.getElementById("logo").style.display = 'none';
929 function displayLoading() {
930 document.getElementById("loading").style.display = 'inline';
933 function finishLoading() {
934 document.getElementById("loading").style.display = 'none';
938 // detailed record drawing
939 function showDetails (prefixRecId) {
940 var recId = prefixRecId.replace('rec_', '');
941 var oldRecId = curDetRecId;
944 // if the same clicked, just show it again
945 if (recId == oldRecId) {
946 showhide('detailview');
949 // request the record
951 my_paz.record_with_query(recId, state.simpleQuery);
954 function replaceHtml(el, html) {
955 var oldEl = typeof el === "string" ? document.getElementById(el) : el;
956 /*@cc_on // Pure innerHTML is slightly faster in IE
957 oldEl.innerHTML = html;
960 var newEl = oldEl.cloneNode(false);
961 newEl.innerHTML = html;
962 oldEl.parentNode.replaceChild(newEl, oldEl);
963 /* Since we just removed the old element from the DOM, return a reference
964 to the new element, which can be used to restore variable references. */
968 function renderDetails(data, marker)
970 var details = '<div class="details" id="det_'+data.recid+'"><table>';
971 if (marker) details += '<tr><td>'+ marker + '</td></tr>';
972 if (data["md-title"] != undefined) {
973 details += '<tr><td><b>Title</b></td><td><b>:</b> '+data["md-title"];
974 if (data["md-title-remainder"] != undefined) {
975 details += ' : <span>' + data["md-title-remainder"] + ' </span>';
977 if (data["md-author"] != undefined) {
978 details += ' <span><i>'+ data["md-auhtor"] +'</i></span>';
980 details += '</td></tr>';
982 if (data["md-date"] != undefined)
983 details += '<tr><td><b>Date</b></td><td><b>:</b> ' + data["md-date"] + '</td></tr>';
984 if (data["md-author"] != undefined)
985 details += '<tr><td><b>Author</b></td><td><b>:</b> ' + data["md-author"] + '</td></tr>';
986 if (data["md-electronic-url"] != undefined)
987 details += '<tr><td><b>URL</b></td><td><b>:</b> <a href="' + data["md-electronic-url"] + '" target="_blank">' + data["md-electronic-url"] + '</a>' + '</td></tr>';
988 if (data["location"][0]["md-subject"] != undefined)
989 details += '<tr><td><b>Subject</b></td><td><b>:</b> ' + data["location"][0]["md-subject"] + '</td></tr>';
990 if (data["location"][0]["@name"] != undefined)
991 details += '<tr><td><b>Location</b></td><td><b>:</b> ' + data["location"][0]["@name"] + " (" +data["location"][0]["@id"] + ")" + '</td></tr>';
992 details += '</table></div>';
996 var default_tag = 'big';
997 function renderLine(title, value, tag) {
998 if (tag == undefined)
1000 if (value != undefined)
1001 return '<li><h3>' + title + '</h3><' + tag + '>' + value + '</' + tag + '></li>';
1005 function renderLines(title, values, name, tag) {
1006 if (tag == undefined)
1009 if (values != undefined && values.length)
1010 for (var idx = 0 ; idx < values.length ; idx++)
1011 if (values[idx][name] != undefined )
1012 result += values[idx][name] + ' ';
1014 result = '<li><h3>' + title + '</h3><' + tag + '>' + result + '</' + tag + '></li>';
1018 // Values is a array of locations.
1020 function renderLinesURL(title, values, name, url, tag) {
1021 if (tag == undefined)
1024 result = '<li><h3>' + title + '</h3><' + tag + ' style="display: inline-block;">';
1025 if (values != undefined && values.length) {
1026 for (var idx = 0 ; idx < values.length ; idx++) {
1027 var url = choose_url(values[idx], auth.proxyUrl);
1029 result += '<a target="_blank" href="' + url + '">' + values[idx][name] + '</a><br>';
1031 result += values[idx][name] + '<br>';
1034 result += '</' + tag + '></li>';
1038 function renderLineURL(title, URL, display) {
1039 if (URL != undefined)
1040 return '<li><h3>' + title + '</h3><a href="' + URL + '" target="_blank">' + display + '</a></li>';
1044 function renderLineEmail(dtitle, email, display) {
1045 if (email != undefined)
1046 return '<li><h3>' + title + '</h3> <a href="mailto:' + email + '" target="_blank">' + display + '</a></li>';
1051 function find_prioritized(values) {
1052 for (var index = 0; index < values.length; index++) {
1053 if (values[index] != undefined)
1054 return values[index];
1059 function renderDetails_iphone(data, marker)
1061 //return renderDetails(data,marker);
1065 var details = '<div class="details" id="det_'+data.recid+'" >'
1067 details += '<h4>'+ marker + '</h4>';
1068 details += '<ul class="field" >';
1071 if (data["md-title"] != undefined) {
1072 title += data["md-title"];
1073 if (data["md-title-remainder"] != undefined) {
1074 title += '<br><i>' + data["md-title-remainder"] + '</i>';
1077 details += renderLine('Title', title);
1079 var author = find_prioritized(
1082 data["md-title-responsibility"]
1086 var coverimagetag = imageHelper.getImageTagByRecId(data.recid, "md-isbn", undefined, "M");
1088 +=renderLine('Date', data["md-date"])
1089 + renderLine('Author', data["md-author"])
1090 // + renderLineURL('URL', data["md-electronic-url"], data["md-electronic-url"])
1091 + renderLine('Description', data["md-description"])
1092 // + renderLines('Subjects', data["location"], "md-subject")
1095 details += renderLinesURL('Location', data["location"], "@name", "md-url_recipe");
1096 details += '<li><a href="#" onclick="showhide(\'recordview\')" style="font-size: 18px;margin-left: 10px;">Back</a></li>';
1097 if (coverimagetag.length>0) {
1098 details += renderLine(' ', coverimagetag);
1101 details += '</ul></div>';