From ea84d85f316a7631c4792c46686268f1ebba2709 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 3 Aug 2005 13:44:13 +0000 Subject: [PATCH] new javascript git-svn-id: svn://svn.open-ils.org/ILS/trunk@1596 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../javascript/lib/js/opac/RemoteRequest.js | 218 ++++++++++++++++++ .../src/javascript/lib/js/opac/Request.js | 10 + .../javascript/lib/js/opac/added_content.js | 3 + Open-ILS/src/javascript/lib/js/opac/config.js | 120 ++++++++++ Open-ILS/src/javascript/lib/js/opac/init.js | 81 +++++++ .../src/javascript/lib/js/opac/methods.js | 16 ++ .../src/javascript/lib/js/opac/mresult.js | 92 ++++++++ .../src/javascript/lib/js/opac/opac_utils.js | 148 ++++++++++++ .../src/javascript/lib/js/opac/org_utils.js | 99 ++++++++ .../javascript/lib/js/opac/result_common.js | 135 +++++++++++ .../src/javascript/lib/js/opac/rresult.js | 17 ++ .../src/javascript/lib/js/opac/search_bar.js | 108 +++++++++ 12 files changed, 1047 insertions(+) create mode 100644 Open-ILS/src/javascript/lib/js/opac/RemoteRequest.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/Request.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/added_content.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/config.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/init.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/methods.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/mresult.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/opac_utils.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/org_utils.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/result_common.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/rresult.js create mode 100644 Open-ILS/src/javascript/lib/js/opac/search_bar.js diff --git a/Open-ILS/src/javascript/lib/js/opac/RemoteRequest.js b/Open-ILS/src/javascript/lib/js/opac/RemoteRequest.js new file mode 100644 index 0000000000..017a013a65 --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/RemoteRequest.js @@ -0,0 +1,218 @@ +var XML_HTTP_GATEWAY = "gateway"; +var XML_HTTP_SERVER = "gapines.org"; +var XML_HTTP_MAX_TRIES = 3; + +/* ----------------------------------------------------------------------- */ +/* Request object */ +function RemoteRequest( service, method ) { + + this.service = service; + this.method = method; + this.xmlhttp = false; + this.name = null; + this.sendCount = 0; + + this.type = "POST"; /* default */ + this.id = service + method + Math.random(); + this.cancelled = false; + + var i = 2; + this.params = ""; + + while(i < arguments.length) { + var object = js2JSON(arguments[i++]); + this.params += "¶m=" + encodeURIComponent(object); + } + + if(!this.params) { this.params = ""; } + this.param_string = "service=" + service + "&method=" + method + this.params; + + if( ! this.type || ! this.service || ! this.method ) { + alert( "ERROR IN REQUEST PARAMS"); + return null; + } + + if( this.buildXMLRequest() == null ) + alert("NEWER BROWSER"); +} + +/* constructs our XMLHTTPRequest object */ +RemoteRequest.prototype.buildXMLRequest = function() { + + try { + this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (E) { + this.xmlhttp = false; + } + } + + if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') { + this.xmlhttp = new XMLHttpRequest(); + } + + if(!this.xmlhttp) { + alert("NEEDS NEWER JAVASCRIPT for XMLHTTPRequest()"); + return null; + } + + if( this.callback ) + this.setCompleteCallback( this.callback ); + + return true; +} + + +/* define the callback we use when this request has received + all of its data */ +RemoteRequest.prototype.setCompleteCallback = function(callback) { + + if(this.cancelled) return; + + var object = this; + var obj = this.xmlhttp; + this.callback = callback; + + this.xmlhttp.onreadystatechange = function() { + if( obj.readyState == 4 ) { + + try { + if(object.cancelled) return; + callback(object); + + } catch(E) { + + /* if we receive a communication error, retry the request up + to XML_HTTP_MAX_TRIES attempts */ + if( instanceOf(E, EXCommunication) ) { + + if(object.sendCount >= XML_HTTP_MAX_TRIES ) { + if(isXUL()) { + throw object; + } else { + alert("Arrrgghh, Matey! Error communicating:\n" + + E + "\n" + object.param_string); + } + } else { + object.buildXMLRequest(); + object.send(); + return; + } + } else { + /* any other exception is alerted for now */ + //RemoteRequest.prunePending(object.id); + //alert("Exception: " + E); + throw E; + } + } + + /* on success, remove the request from the pending cache */ + //RemoteRequest.prunePending(object.id); + } + } +} + + +/* http by default. This makes it https. *ONLY works when + embedded in a XUL app. */ +RemoteRequest.prototype.setSecure = function(bool) { + this.secure = bool; +} + +/** Send the request + * By default, all calls are asynchronous. if 'blocking' is + * set to true, then the call will block until a response + * is received. If blocking, callbacks will not be called. + * In other words, you can assume the data is avaiable + * (getResponseObject()) as soon as the send call returns. + */ +RemoteRequest.prototype.send = function(blocking) { + + if(this.cancelled) return; + + /* determine the xmlhttp server dynamically */ + var url = location.protocol + "//" + location.host + "/" + XML_HTTP_GATEWAY; + + if(isXUL()) { + if(this.secure) + url = "https://" + XML_HTTP_SERVER + "/" + XML_HTTP_GATEWAY; + else + url = "http://" + XML_HTTP_SERVER + "/" + XML_HTTP_GATEWAY; + } + + var data = null; + + if( this.type == 'GET' ) { + url += "?" + this.param_string; + } + + if(blocking) { + this.xmlhttp.open(this.type, url, false); + } else { + this.xmlhttp.open(this.type, url, true); + } + + + if( this.type == 'POST' ) { + data = this.param_string; + this.xmlhttp.setRequestHeader('Content-Type', + 'application/x-www-form-urlencoded'); + } + + this.xmlhttp.send( data ); + this.sendCount += 1; + return this; +} + +/* returns the actual response text from the request */ +RemoteRequest.prototype.getText = function() { + return this.xmlhttp.responseText; +} + +RemoteRequest.prototype.isReady = function() { + return this.xmlhttp.readyState == 4; +} + + +/* returns the JSON->js result object */ +RemoteRequest.prototype.getResultObject = function() { + if(this.cancelled) return null; + + var text = this.xmlhttp.responseText; + var obj = JSON2js(text); + + if(obj == null) { + return null; + } + + if(obj.is_err) { + throw new EXCommunication(obj.err_msg); + } + + if( obj[0] != null && obj[1] == null ) + obj = obj[0]; + + /* these are user level exceptions from the server code */ + if(instanceOf(obj, ex)) { + /* the opac will go ahead and spit out the error msg */ + if(!isXUL()) alert(obj.err_msg()); + throw obj; + } + + if(instanceOf(obj, perm_ex)) { + /* the opac will go ahead and spit out the error msg */ + if(!isXUL()) alert(obj.err_msg()); + throw obj; + } + + return obj; +} + +/* adds a new parameter to the request */ +RemoteRequest.prototype.addParam = function(param) { + var string = encodeURIComponent(js2JSON(param)); + this.param_string += "¶m=" + string; +} + diff --git a/Open-ILS/src/javascript/lib/js/opac/Request.js b/Open-ILS/src/javascript/lib/js/opac/Request.js new file mode 100644 index 0000000000..b0c5ac505a --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/Request.js @@ -0,0 +1,10 @@ +function Request(type) { + var s = type.split(":"); + this.request = new RemoteRequest(s[0], s[1]); + for( var x = 1; x!= arguments.length; x++ ) + this.request.addParam(arguments[x]); +} + +Request.prototype.callback = function(cal) { this.request.setCallback(cal); } +Request.prototype.send = function(block){this.request.send(block);} +Request.prototype.result = function(){return this.request.getResultObject();} diff --git a/Open-ILS/src/javascript/lib/js/opac/added_content.js b/Open-ILS/src/javascript/lib/js/opac/added_content.js new file mode 100644 index 0000000000..38c0cdb453 --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/added_content.js @@ -0,0 +1,3 @@ +function buildISBNSrc(isbn) { + return "http://www.thecontentserver.com/bin/cntsvr.dll?GetImage&SysID=Content&CustID=Cafe&Return=1&Type=S&Key=" + isbn ; +} diff --git a/Open-ILS/src/javascript/lib/js/opac/config.js b/Open-ILS/src/javascript/lib/js/opac/config.js new file mode 100644 index 0000000000..e903e9cf5d --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/config.js @@ -0,0 +1,120 @@ +/* Export some constants ----------------------------------------------------- */ + +/* URL params */ +var PARAM_TERM = "term"; /* search term */ +var PARAM_STYPE = "stype"; /* search type */ +var PARAM_LOCATION = "location" /* current location */; +var PARAM_DEPTH = "depth"; /* search depth */ +var PARAM_FORM = "format"; /* search format */ +var PARAM_OFFSET = "offset"; /* search offset */ +var PARAM_COUNT = "count"; /* hits per page */ +var PARAM_HITCOUNT = "hitcount"; /* hits per page */ +var PARAM_RANKS = "hitcount"; /* hits per page */ +var PARAM_MRID = "mrid"; /* metarecord id */ +var PARAM_RID = "rid"; /* metarecord id */ + +/* cookies */ +var PARAM_SEARCHBAR_EXTRAS = "searchbar_extras" + +/* these are the actual param values - set on page load */ + +/* pages */ +var MRESULT = "mresult"; +var RRESULT = "rresult"; +var MYOPAC = "myopac"; +var ADVANCED = "advanced"; +var HOME = "home"; +var PREFS = "prefs"; + + +/* ---------------------------------------------------------------------------- */ +/* Set up ID's and CSS classes */ +/* ---------------------------------------------------------------------------- */ + +var config = {}; +config.text = {}; +config.ids = {}; +config.names = {}; + +config.ids.loading = "loading_div"; +config.ids.canvas = "canvas"; +config.ids.canvas_main = "canvas_main"; + +config.css = {}; +config.css.hide_me = "hide_me"; + +config.page = {}; +config.page[HOME] = "/webxml/index.xml"; +config.page[ADVANCED] = "/webxml/advanced.xml"; +config.page[MRESULT] = "/webxml/mresult.xml"; +config.page[RRESULT] = "/webxml/rresult.xml"; +config.page[PREFS] = "/webxml/webprefs.xml" +config.page[MYOPAC] = "/webxml/myopac/index.xml" + + +/* mresult */ +config.ids.mresult = {}; + +/* result */ +config.ids.result = {}; +config.css.result = {}; +config.names.result = {}; +config.ids.result.offset_start = "offset_start"; +config.ids.result.offset_end = "offset_end"; +config.ids.result.result_count = "result_count"; +config.ids.result.next_link = 'next_link'; +config.ids.result.prev_link = 'prev_link'; +config.ids.result.home_link = 'home_link'; +config.ids.result.end_link = 'end_link'; +config.ids.result.main_table = 'result_table'; +config.ids.result.row_template = 'result_table_template'; +config.ids.result.num_pages = 'num_pages'; +config.ids.result.current_page = 'current_page'; +config.css.result.nav_active = "nav_link_active"; +config.ids.result.top_div = "result_table_div"; +config.ids.result.nav_links = "search_nav_links"; +config.names.result.item_jacket = "item_jacket"; +config.names.result.item_title = "item_title"; +config.names.result.item_author = "item_author"; +config.names.result.counts_row = "counts_row"; +config.names.result.count_cell = "copy_count_cell"; + +config.ids.login = {}; +config.css.login = {}; +config.ids.login.box = "login_box"; +config.ids.login.username = "login_username"; +config.ids.login.password = "login_password"; +config.ids.login.button = "login_button"; + + + +/* searchbar ids and css */ +config.ids.searchbar = {}; +config.css.searchbar = {}; +config.ids.searchbar.text = 'search_box'; +config.ids.searchbar.submit = 'search_submit'; +config.ids.searchbar.type_selector = 'search_type_selector'; +config.ids.searchbar.depth_selector = 'depth_selector'; +config.ids.searchbar.form_selector = 'form_selector'; +config.ids.searchbar.extra_row = 'searchbar_extra'; +config.ids.searchbar.main_row = 'searchbar_main_row'; +config.ids.searchbar.table = 'searchbar_table'; +config.ids.searchbar.tag = 'search_tag_link'; +config.ids.searchbar.tag_on = 'searchbar_tag_on'; +config.ids.searchbar.tag_off = 'searchbar_tag_off'; + + +/* sidebar */ +config.ids.sidebar = {}; +config.css.sidebar = {}; +config.css.sidebar.item = {}; +config.ids.sidebar.home = 'home_link_div'; +config.ids.sidebar.advanced = 'advanced_link_div'; +config.ids.sidebar.myopac = 'myopac_link_div'; +config.ids.sidebar.prefs = 'prefs_link_div'; +config.css.sidebar.item.active = 'side_bar_item_active'; +config.ids.sidebar.mresult = 'mresult_link_div'; +config.ids.sidebar.rresult = 'result_link_div'; +config.ids.sidebar.login = 'login_link'; + + diff --git a/Open-ILS/src/javascript/lib/js/opac/init.js b/Open-ILS/src/javascript/lib/js/opac/init.js new file mode 100644 index 0000000000..b0a23f5912 --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/init.js @@ -0,0 +1,81 @@ + +function init() { + initParams(); + var page = findCurrentPage(); + initSideBar(config.ids.sidebar[page]); + searchBarInit(); + + var login_div = getId(config.ids.sidebar.login); + if(login_div) login_div.onclick = initLogin; + + switch(page) { + case MRESULT: mresultDoSearch(); break; + case RRESULT: rresultDoSearch(); break; + } + +} + +function initLogin() { + config.ids.login.button.onclick = function(){doLogin();} + addCSSClass(getId(config.ids.canvas_main), config.css.hide_me); + removeCSSClass(getId(config.ids.login.box), config.css.hide_me); +} + + +/* set up the colors in the sidebar */ +function initSideBar() { + for( var p in config.ids.sidebar ) { + var page = config.ids.sidebar[p]; + removeCSSClass(getId(page), config.css.sidebar.item.active); + } + var page = findCurrentPage(); + addCSSClass(getId(config.ids.sidebar[page]), config.css.sidebar.item.active); + removeCSSClass(getId(config.ids.sidebar[page]), config.css.hide_me); +} + + +/* sets all of the params values */ +var TERM, STYPE, LOCATION, DEPTH, FORM, OFFSET, COUNT, + HITCOUNT, RANKS, SEARCHBAR_EXTRAS; + +function initParams() { + var cgi = new CGI(); + + TERM = cgi.param(PARAM_TERM); + STYPE = cgi.param(PARAM_STYPE); + FORM = cgi.param(PARAM_FORM); + + LOCATION = parseInt(cgi.param(PARAM_LOCATION)); + DEPTH = parseInt(cgi.param(PARAM_DEPTH)); + OFFSET = parseInt(cgi.param(PARAM_OFFSET)); + COUNT = parseInt(cgi.param(PARAM_COUNT)); + HITCOUNT = parseInt(cgi.param(PARAM_HITCOUNT)); + MRID = parseInt(cgi.param(PARAM_MRID)); + RID = parseInt(cgi.param(PARAM_RID)); + + /* set up some sane defaults */ + if(isNaN(LOCATION)) LOCATION = 1; + if(isNaN(DEPTH)) DEPTH = 0; + if(isNaN(OFFSET)) OFFSET = 0; + if(isNaN(COUNT)) COUNT = 10; + if(isNaN(HITCOUNT)) HITCOUNT = 0; + if(isNaN(SEARCHBAR_EXTRAS)) SEARCHBAR_EXTRAS = 0; + if(isNaN(MRID)) MRID = 0; + if(isNaN(RID)) RID = 0; +} + +/* URL param accessors */ +function getTerm(){return TERM;} +function getStype(){return STYPE;} +function getLocation(){return LOCATION;} +function getDepth(){return DEPTH;} +function getForm(){return FORM;} +function getOffset(){return OFFSET;} +function getDisplayCount(){return COUNT;} +function getHitCount(){return HITCOUNT;} +function getSearchBarExtras(){return SEARCHBAR_EXTRAS;} +function getMrid(){return MRID;}; +function getRid(){return RID;}; + + + diff --git a/Open-ILS/src/javascript/lib/js/opac/methods.js b/Open-ILS/src/javascript/lib/js/opac/methods.js new file mode 100644 index 0000000000..39e384875c --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/methods.js @@ -0,0 +1,16 @@ +/* Methods are defined as service:method */ + +FETCH_MRCOUNT = "open-ils.search:open-ils.search.biblio.class.count" +if(isXUL()) FETCH_MRCOUNT += ".staff"; + +FETCH_MRIDS = "open-ils.search:open-ils.search.biblio.class" +if(isXUL()) FETCH_MRIDS += ".staff"; + +FETCH_MRMODS = "open-ils.search:open-ils.search.biblio.metarecord.mods_slim.retrieve"; + +FETCH_MR_COPY_COUNTS = "open-ils.search:open-ils.search.biblio.metarecord.copy_count" +if(isXUL()) FETCH_MR_COPY_COUNTS += ".staff"; + + + + diff --git a/Open-ILS/src/javascript/lib/js/opac/mresult.js b/Open-ILS/src/javascript/lib/js/opac/mresult.js new file mode 100644 index 0000000000..b650eb58ad --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/mresult.js @@ -0,0 +1,92 @@ +var records = new Array(); +var ranks = new Array(); +var table; +var rowtemplate; + +function mresultDoSearch() { + + table = getId(config.ids.result.main_table); + rowtemplate = table.removeChild(getId(config.ids.result.row_template)); + removeChildren(table); + + if(getOffset() == 0 || getHitCount() == null ) { + mresultGetCount(); + mresultCollectIds(); + } else { + resultSetInfo(); + mresultCollectIds(); + mresultCollectRecords(); + } +} + +function mresultGetCount() { + var req = new Request(FETCH_MRCOUNT, + getStype(), getTerm(), getLocation(), getDepth(), getForm() ); + req.callback( function(r) { + HITCOUNT = parseInt(r.getResultObject()); + resultSetInfo(); }); + req.send(); +} + + +/* performs the actual search */ +function mresultCollectIds() { + var req = new Request(FETCH_MRIDS, getStype(), getTerm(), + getLocation(), getDepth(), getDisplayCount(), getOffset(), getForm() ); + req.callback( function(r) { + mresultSetRecords(r.getResultObject().ids); + mresultCollectRecords(); }); + req.send(); +} + +function mresultSetRecords(idstruct) { + var o = getOffset(); + for( var x = o; x!= idstruct.length + o; x++ ) { + records[x] = idstruct[x - o][0]; + ranks[x] = idstruct[x - o][1]; + } +} + + +function mresultCollectRecords() { + for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) { + if(isNull(records[x])) break; + + var req = new Request(FETCH_MRMODS, records[x]); + req.callback(function(r){ + var rec = r.getResultObject(); + resultDisplayRecord(rec, rowtemplate, true); + mresultCollectCopyCounts(rec); + }); + req.send(); + + /* + if( x == (getDisplayCount() + getOffset()) - 1 ) { + getId(config.ids.result.top_div).appendChild( + getId(config.ids.result.nav_links).cloneNode(true)); + } + */ + } +} + +function mresultCollectCopyCounts(rec) { + if(rec == null) return; + if(rec.doc_id() == null) return; + + var req = new Request(FETCH_MR_COPY_COUNTS, getLocation(), rec.doc_id() ); + req.callback(function(r){ mresultDisplayCopyCounts(rec, r.getResultObject()); }); + req.send(); +} + +function mresultDisplayCopyCounts(rec, copy_counts) { + if(copy_counts == null || rec == null) return; + var i = 0; + while(copy_counts[i] != null) { + var cell = getId("copy_count_cell_" + i +"_" + rec.doc_id()); + cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count)); + i++; + } +} + + + diff --git a/Open-ILS/src/javascript/lib/js/opac/opac_utils.js b/Open-ILS/src/javascript/lib/js/opac/opac_utils.js new file mode 100644 index 0000000000..a26a196ec9 --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/opac_utils.js @@ -0,0 +1,148 @@ +var IAMXUL = false; +function isXUL() { return IAMXUL; } + + +/* - Request ------------------------------------------------------------- */ +function Request(type) { + var s = type.split(":"); + this.request = new RemoteRequest(s[0], s[1]); + for( var x = 1; x!= arguments.length; x++ ) + this.request.addParam(arguments[x]); +} + +Request.prototype.callback = function(cal) { this.request.setCompleteCallback(cal); } +Request.prototype.send = function(block){this.request.send(block);} +/* ----------------------------------------------------------------------- */ + + +/* finds the name of the current page */ +function findCurrentPage() { + for( var p in config.page ) { + var path = location.pathname; + + if(!path.match(/.*\.xml$/)) + path += "index.xml"; /* in case they go to / */ + + if( config.page[p] == path) + return p; + } + return null; +} + + +/* builds an opac URL. If no page is defined, the current page is used + if slim, then only everything after the ? is returned (no host portion) + */ +function buildOPACLink(args, slim) { + + if(!args) args = {}; + + if(!slim) { + var string = location.protocol + "//" + location.host; + if(args.page) string += config.page[args.page]; + else string += config.page[findCurrentPage()]; + } + + string += "?"; + + for( var x in args ) { + if(x == "page" || args[x] == null) continue; + string += "&" + x + "=" + encodeURIComponent(args[x]); + } + + string += _appendParam(TERM, PARAM_TERM, args, getTerm, string); + string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string); + string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string); + string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string); + string += _appendParam(FORM, PARAM_FORM, args, getForm, string); + string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string); + string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string); + string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string); + string += _appendParam(MRID, PARAM_MRID, args, getMrid, string); + string += _appendParam(RID, PARAM_RID, args, getRid, string); + return string.replace(/\&$/,'').replace(/\?\&/,"?"); +} + +function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) { + var ret = ""; + if( fieldVar != null && overrideArgs[fieldName] == null ) + ret = "&" + fieldName + "=" + encodeURIComponent(getFunc()); + return ret; +} + + + + + +/* ----------------------------------------------------------------------- */ +/* some useful exceptions */ +function EX(message) { this.init(message); } + +EX.prototype.init = function(message) { + this.message = message; +} + +EX.prototype.toString = function() { + return "\n *** Exception Occured \n" + this.message; +} + +EXCommunication.prototype = new EX(); +EXCommunication.prototype.constructor = EXCommunication; +EXCommunication.baseClass = EX.prototype.constructor; + +function EXCommunication(message) { + this.init("EXCommunication: " + message); +} +/* ----------------------------------------------------------------------- */ + +function cleanISBN(isbn) { + if(isbn) { + isbn = isbn.toString().replace(/^\s+/,""); + var idx = isbn.indexOf(" "); + if(idx > -1) { isbn = isbn.substring(0, idx); } + } else isbn = ""; + return isbn; +} + + +function doLogin() { +} + + +/* ----------------------------------------------------------------------- */ +/* builds a link that goes to the title listings for a metarecord */ +function buildTitleLink(rec, link) { + + var t = rec.title(); + t = normalize(truncate(t, 65)); + link.appendChild(text(t)); + + var args = {}; + args.page = RRESULT; + args[PARAM_OFFSET] = 0; + args[PARAM_MRID] = rec.doc_id(); + link.setAttribute("href", buildOPACLink(args)); +} + +/* builds an author search link */ +function buildAuthorLink(rec, link) { + + var a = rec.author(); + a = normalize(truncate(a, 65)); + link.appendChild(text(a)); + + var args = {}; + args.page = MRESULT; + args[PARAM_OFFSET] = 0; + args[PARAM_STYPE] = "author"; + args[PARAM_TERM] = rec.author(); + link.setAttribute("href", buildOPACLink(args)); + +} +/* ----------------------------------------------------------------------- */ + + + + + + diff --git a/Open-ILS/src/javascript/lib/js/opac/org_utils.js b/Open-ILS/src/javascript/lib/js/opac/org_utils.js new file mode 100644 index 0000000000..14fd4cfe38 --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/org_utils.js @@ -0,0 +1,99 @@ +/* takes an org unit or id and return the numeric depth */ +function findOrgDepth(org_id_or_node) { + + if(org_id_or_node == null || globalOrgTypes == null) + return null; + + var org = findOrgUnit(org_id_or_node); + + var t = findOrgType(org.ou_type()); + if(t != null) return t.depth(); + + return null; +} + +/* takes the org type id from orgunit.ou_type() field and returns + the org type object */ +function findOrgType(type_id) { + + if(type_id == null || globalOrgTypes == null) + return null; + + if(typeof type_id == 'object') + return type_id; + + for(var type in globalOrgTypes) { + var t =globalOrgTypes[type]; + if( t.id() == type_id || t.id() == parseInt(type_id) ) + return t; + } + return null; +} + + +/* locates a specific org unit by id, acts as a cache of orgs*/ +var orgArraySearcher = null; + +/* flatten the org tree for faster searching */ +function _flattenOrgs(node) { + + if(node == null) { + node = globalOrgTree; + orgArraySearcher = new Object(); + } + + orgArraySearcher[node.id()] = node; + for(var idx in node.children()) { + _flattenOrgs(node.children()[idx]); + } +} + +/* returns an org unit by id. if an object is passed in as the id, + then the object is assumed to be an org unit and is returned */ +function findOrgUnit(org_id, branch) { + + if(org_id == null) return null; + if(typeof org_id == 'object') return org_id; + + /* if we don't have the global org tree, grab the org unit from the server */ + var tree_exists = false; + try{if(globalOrgTree != null) tree_exists = true;}catch(E){} + + if(!tree_exists) { + var org = orgArraySearcher[org_id]; + if(org) return org; + var r = new RemoteRequest( + "open-ils.actor", + "open-ils.actor.org_unit.retrieve", null, org_id); + r.send(true); + orgArraySearcher[org_id] = r.getResultObject(); + return orgArraySearcher[org_id]; + } + + if(orgArraySearcher == null) + _flattenOrgs(); + + return orgArraySearcher[org_id]; +} + + +/* builds a trail from the top of the org tree to the node provide. + basically fleshes out 'my orgs' + Returns an array of [org0, org1, ..., myorg] + */ +function orgNodeTrail(node) { + var nodeArray = new Array(); + while( node ) { + nodeArray.push(node); + node = findOrgUnit(node.parent_ou()); + } + nodeArray = nodeArray.reverse(); + return nodeArray; +} + + +/* returns an array of sibling org units / +function findSiblingOrgs(node) { + return findOrgUnit(node.parent_ou()).children(); +} + diff --git a/Open-ILS/src/javascript/lib/js/opac/result_common.js b/Open-ILS/src/javascript/lib/js/opac/result_common.js new file mode 100644 index 0000000000..12d25127f0 --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/result_common.js @@ -0,0 +1,135 @@ + +function resultSetInfo() { + var c; + if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount(); + else c = getDisplayCount() + getOffset(); + + var pages = parseInt(getHitCount() / getDisplayCount()) + 1; + getId(config.ids.result.current_page).appendChild(text( (getOffset()/getDisplayCount()) + 1)); + getId(config.ids.result.num_pages).appendChild(text(pages + ")")); + + var o = getOffset(); + + if( !((o + getDisplayCount()) >= getHitCount()) ) { + + var args = {}; + args[PARAM_OFFSET] = o + getDisplayCount(); + getId(config.ids.result.next_link).setAttribute("href", buildOPACLink(args)); + addCSSClass(getId(config.ids.result.next_link), config.css.result.nav_active); + + args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount()); + getId(config.ids.result.end_link).setAttribute("href", buildOPACLink(args)); + addCSSClass(getId(config.ids.result.end_link), config.css.result.nav_active); + } + + if( o > 0 ) { + + var args = {}; + args[PARAM_OFFSET] = o - getDisplayCount(); + getId(config.ids.result.prev_link).setAttribute( "href", buildOPACLink(args)); + addCSSClass(getId(config.ids.result.prev_link), config.css.result.nav_active); + + args[PARAM_OFFSET] = 0; + getId(config.ids.result.home_link).setAttribute( "href", buildOPACLink(args)); + addCSSClass(getId(config.ids.result.home_link), config.css.result.nav_active); + } + + getId(config.ids.result.offset_start).appendChild(text(o + 1)); + getId(config.ids.result.offset_end).appendChild(text(c)); + getId(config.ids.result.result_count).appendChild(text(getHitCount())); + + +} + + +function resultDisplayRecord(rec, rowtemplate, is_mr) { + + if(rec == null) rec = {}; + + /* hide the 'now loading...' message */ + addCSSClass(getId(config.ids.loading), config.css.hide_me); + + var r = rowtemplate.cloneNode(true); + + var pic = findNodeByName(r, config.names.result.item_jacket); + pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn()))); + + + var title_link = findNodeByName(r, config.names.result.item_title); + var author_link = findNodeByName(r, config.names.result.item_author); + + if( is_mr ) buildTitleLink(rec, title_link); + buildAuthorLink(rec, author_link); + + var countsrow = findNodeByName(r, config.names.result.counts_row); + + /* adjust the width according to how many org counts are added */ + findNodeByName(r, "result_table_title_cell").width = + resultAddCopyCounts(countsrow, rec) + "%"; + + table.appendChild(r); + +} + + +/* -------------------------------------------------------------------- */ +/* dynamically add the copy count rows based on the org type + 'countsrow' is the row into which we will add TD's to hold + the copy counts + This code generates copy count cells with an id of + + 'copy_count_cell__' for later insertion + of copy counts + + return the percent width left over after the each count is added. + if 3 counts are added, returns 100 - (cell.width * 3) + */ + +function resultAddCopyCounts(countsrow, rec) { + + var ccell = findNodeByName(countsrow, config.names.result.count_cell); + + + var nodes = orgNodeTrail(findOrgUnit(getLocation())); + var node = nodes[0]; + var type = findOrgType(node.ou_type()); + ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id(); + ccell.title = type.opac_label(); + addCSSClass(ccell, "copy_count_cell_even"); + + + var lastcell = ccell; + + if(nodes[1]) { + + var x = 1; + var d = findOrgDepth(nodes[1]); + var d2 = findOrgDepth(nodes[nodes.length -1]); + + for( var i = d; i <= d2 ; i++ ) { + + ccell = ccell.cloneNode(true); + + if((i % 2)) + removeCSSClass(ccell, "copy_count_cell_even"); + else + addCSSClass(ccell, "copy_count_cell_even"); + + var node = nodes[x++]; + var type = findOrgType(node.ou_type()); + + ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id(); + ccell.title = type.opac_label(); + countsrow.insertBefore(ccell, lastcell); + lastcell = ccell; + + } + } + + return 100 - (nodes.length * 8); + +} + + + + diff --git a/Open-ILS/src/javascript/lib/js/opac/rresult.js b/Open-ILS/src/javascript/lib/js/opac/rresult.js new file mode 100644 index 0000000000..8b073e93e2 --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/rresult.js @@ -0,0 +1,17 @@ +var records = new Array(); +var table; +var rowtemplate; +var mrid; + +function rresultDoSearch() { + + table = getId(config.ids.result.main_table); + rowtemplate = table.removeChild(getId(config.ids.result.row_template)); + removeChildren(table); + mrid = getMrid(); + + /* + rresultGetCount(); + rresultCollectIds(); + */ +} diff --git a/Open-ILS/src/javascript/lib/js/opac/search_bar.js b/Open-ILS/src/javascript/lib/js/opac/search_bar.js new file mode 100644 index 0000000000..05f7cd13fe --- /dev/null +++ b/Open-ILS/src/javascript/lib/js/opac/search_bar.js @@ -0,0 +1,108 @@ + +var searchBarExpanded = false; +var searchBarTable; +var searchBarTagLink; +var searchBarExtraRow; +var searchBarMainRow; + +var typeSelector; +var depthSelector; +var formSelector; + +function searchBarInit() { + + getId(config.ids.searchbar.text).focus(); + getId(config.ids.searchbar.text).onkeydown = + function(evt) {if(userPressedEnter(evt)) searchBarSubmit();}; + getId(config.ids.searchbar.submit).onclick = searchBarSubmit; + + searchBarTable = getId(config.ids.searchbar.table); + searchBarTagLink = getId(config.ids.searchbar.tag); + searchBarExtraRow = getId(config.ids.searchbar.extra_row); + searchBarMainRow = getId(config.ids.searchbar.main_row); + + typeSelector = getId(config.ids.searchbar.type_selector); + depthSelector = getId(config.ids.searchbar.depth_selector); + formSelector = getId(config.ids.searchbar.form_selector); + + searchBarTagLink.onclick = function(){searchBarToggle();} + + /* set up the selector objects, etc */ + var t = getTerm(); + if(t == null) t = ""; + getId(config.ids.searchbar.text).value = t; + setSelector(typeSelector, getStype()); + setSelector(depthSelector, getDepth()); + setSelector(formSelector, getForm()); + + //typeSelector.onchange = function(){searchBarSelectorChanged("type");}; + //depthSelector.onchange = function(){searchBarSelectorChanged("depth");}; + //formSelector.onchange = function(){searchBarSelectorChanged("form");}; + + if(getSearchBarExtras()) searchBarToggle(); +} + +/* +function searchBarSelectorChanged(type) { + + var args = {}; + switch( type ) { + + case "type": + args[PARAM_STYPE] = typeSelector.options[typeSelector.selectedIndex].value + break; + + case "depth": + args[PARAM_DEPTH] = parseInt(depthSelector.options[depthSelector.selectedIndex].value); + break; + + case "form": + args[PARAM_FORM] = formSelector.options[formSelector.selectedIndex].value; + break; + } + + args[PARAM_OFFSET] = 0; + + if(findCurrentPage() == MRESULT || findCurrentPage() == RRESULT ) + goTo(buildOPACLink(args)); +} +*/ + +function searchBarSubmit() { + var text = getId(config.ids.searchbar.text).value; + if(!text || text == "") return; + var type_s = getId(config.ids.searchbar.type_selector); + + var args = {}; + args.page = MRESULT; + args[PARAM_OFFSET] = 0; + args[PARAM_TERM] = text; + args[PARAM_STYPE] = type_s.options[type_s.selectedIndex].value; + + args[PARAM_DEPTH] = parseInt(depthSelector.options[depthSelector.selectedIndex].value); + args[PARAM_FORM] = formSelector.options[formSelector.selectedIndex].value; + goTo(buildOPACLink(args)); +} + + +function searchBarToggle() { + + if(searchBarExpanded) { + + addCSSClass(searchBarExtraRow,config.css.hide_me); + searchBarExpanded = false; + getId(config.ids.searchbar.tag_off).className = "show_me_inline"; + getId(config.ids.searchbar.tag_on).className = "hide_me"; + //SEARCHBAR_EXTRAS = 0; set cookie... + + } else { + + removeCSSClass(searchBarExtraRow,config.css.hide_me); + searchBarExpanded = true; + getId(config.ids.searchbar.tag_off).className = "hide_me"; + getId(config.ids.searchbar.tag_on).className = "show_me_inline"; + //SEARCHBAR_EXTRAS = 1; set cookie... + } +} + + -- 2.43.2