From 371c6a27d3498ef7bbc65781488573d36bc16012 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 20 Jun 2005 21:27:10 +0000 Subject: [PATCH] pile-o-work. Most of this is RecordDetailPage work and accompanying tweaks to make said page better. git-svn-id: svn://svn.open-ils.org/ILS/trunk@881 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../javascript/opac/AbstractRecordResultPage.js | 6 +- Open-ILS/src/javascript/opac/GlobalInit.js | 45 ++- Open-ILS/src/javascript/opac/LocationTree.js | 58 ++-- Open-ILS/src/javascript/opac/MRResultPage.js | 7 +- Open-ILS/src/javascript/opac/RecordDetailPage.js | 336 ++++++++++++++------- Open-ILS/src/javascript/opac/RecordResultPage.js | 9 + Open-ILS/src/javascript/util/RemoteRequest.js | 3 + Open-ILS/src/javascript/util/UserSession.js | 16 +- Open-ILS/src/javascript/util/ils_utils.js | 7 +- Open-ILS/src/javascript/util/webutils.js | 27 ++ 10 files changed, 373 insertions(+), 141 deletions(-) diff --git a/Open-ILS/src/javascript/opac/AbstractRecordResultPage.js b/Open-ILS/src/javascript/opac/AbstractRecordResultPage.js index 877010085d..9115361976 100644 --- a/Open-ILS/src/javascript/opac/AbstractRecordResultPage.js +++ b/Open-ILS/src/javascript/opac/AbstractRecordResultPage.js @@ -566,10 +566,12 @@ AbstractRecordResultPage.prototype.buildNextLinks = function() { AbstractRecordResultPage.prototype.buildResourcePic = function(c, resource) { + return buildResourcePic(c, resource); +} - var pic = createAppElement("img"); - var big_pic_div = createAppElement("div"); +function buildResourcePic(c, resource) { + var pic = createAppElement("img"); pic.setAttribute("src", "/images/" + resource + ".jpg"); pic.className = "record_resource_pic"; diff --git a/Open-ILS/src/javascript/opac/GlobalInit.js b/Open-ILS/src/javascript/opac/GlobalInit.js index fb44732ecb..a38e6c5869 100644 --- a/Open-ILS/src/javascript/opac/GlobalInit.js +++ b/Open-ILS/src/javascript/opac/GlobalInit.js @@ -8,6 +8,7 @@ var globalOrgTreeWidgetBox = null; var globalSelectedLocation = null; var globalSearchDepth = null; var globalMenuManager = null; +var globalCopyStatus = null; var locationStack = new Array(); var lastSearchString = null; @@ -17,8 +18,6 @@ var lastSearchType = null; var loaded = false; - - function addLocation(type, title) { try { if(globalAppFrame) { @@ -40,6 +39,17 @@ function globalInit() { if( isXUL() && globalAppFrame ) globalAppFrame.document.body.style.background = "#FFF"; + if(paramObj.__location != null) { + globalSelectedLocation = findOrgUnit(paramObj.__location); + debug("Setting selected location to " + globalSelectedLocation.name() ); + } + + + if(paramObj.__depth != null) { + globalSearchDepth = findOrgType(paramObj.__depth); + debug("Setting selected depth to " + globalSearchDepth.name() ); + } + var page_name = globalPageTarget; if(!page_name) @@ -142,9 +152,38 @@ function GlobalInitLoad() { } else { globalUser = null; globalLocation = globalOrgTree; - globalSearchDepth = findOrgDepth(globalOrgTree.ou_type()); + if(globalSearchDepth == null) + globalSearchDepth = findOrgDepth(globalOrgTree.ou_type()); + } + + grabCopyStatus(); + +} + +function grabCopyStatus() { + if(globalCopyStatus) return; + + debug("Grabbing copy statuses"); + var req = new RemoteRequest( + "open-ils.search", + "open-ils.search.config.copy_status.retrieve.all" ); + + if(paramObj.__sub_frame) { + /* we have to grab the copy statuses synchronously */ + req.send(true); + globalCopyStatus = r.getResultObject(); + + } else { + + req.setCompleteCallback(function(r) { + debug("Got globalCopyStatus"); + globalCopyStatus = r.getResultObject(); }); + + req.send(); } + } + diff --git a/Open-ILS/src/javascript/opac/LocationTree.js b/Open-ILS/src/javascript/opac/LocationTree.js index 835c3a0680..42081a1ab3 100644 --- a/Open-ILS/src/javascript/opac/LocationTree.js +++ b/Open-ILS/src/javascript/opac/LocationTree.js @@ -1,23 +1,40 @@ /* */ -function LocationTree( tree ) { +function LocationTree( tree, box_id, container_id ) { this.orgTree = tree; + + this.treeContainerBoxId = container_id; + this.treeBoxId = box_id; + this.setObjects(); +} + + +LocationTree.prototype.setObjects = function() { + if(this.treeContainerBoxId) + this.treeContainerBox = getById(this.treeContainerBoxId); + else + this.treeContainerBox = getById("ot_nav_widget"); + + if(this.treeBoxId) + this.treeBox = getById(treeBoxId); + else + this.treeBox = getById("ot_nav_widget_box"); + } LocationTree.prototype.buildOrgTreeWidget = function() { - this.widget = buildOrgTreeWidget(); + debug("Somebody called buildOrgTreeWidget on me..."); + this.setObjects(); + this.widget = buildOrgTreeWidget(globalOrgTree, true); } -function buildOrgTreeWidget(org_node) { +function buildOrgTreeWidget(org_node, root) { var item; - globalPage.treeWidgetElements = new Array(); - - if(org_node == null) { - org_node = globalOrgTree; + if(root) { item = new WebFXTree(org_node.name()); item.setBehavior('classic'); } else { @@ -29,8 +46,6 @@ function buildOrgTreeWidget(org_node) { "javascript:globalPage.updateSelectedLocation('" + org_node.id() + "');" + "globalPage.locationTree.hide();"; - globalPage.treeWidgetElements[item.id] = org_node; - for( var index in org_node.children()) { var childorg = org_node.children()[index]; if( childorg != null ) { @@ -45,7 +60,8 @@ function buildOrgTreeWidget(org_node) { LocationTree.prototype.hide = function() { - this.treeContainerBox = getById("ot_nav_widget"); + this.setObjects(); + this.widget = buildOrgTreeWidget(globalOrgTree, true); if(this.treeContainerBox && this.treeContainerBox.className.indexOf("nav_bar_visible") != -1 ) { swapClass( this.treeContainerBox, "nav_bar_hidden", "nav_bar_visible" ); @@ -56,16 +72,18 @@ LocationTree.prototype.hide = function() { LocationTree.prototype.toggle = function(button_div, offsetx, offsety) { - this.treeContainerBox = getById("ot_nav_widget"); - this.treeBox = getById("ot_nav_widget_box"); + this.setObjects(); debug("Tree container " + this.treeContainerBox ); debug("Tree box " + this.treeBox ); + swapClass( this.treeContainerBox, "nav_bar_hidden", "nav_bar_visible" ); + var obj = this; if(this.treeBox && this.treeBox.firstChild.nodeType == 3) { - setTimeout("renderTree()", 5 ); + setTimeout(function() { renderTree(obj); }, 5 ); } + if( button_div && offsetx == null && offsety == null ) { var x = findPosX(button_div); var y = findPosY(button_div); @@ -86,16 +104,10 @@ LocationTree.prototype.toggle = function(button_div, offsetx, offsety) { } -function renderTree() { - - globalPage.locationTree.treeContainerBox = getById("ot_nav_widget"); - globalPage.locationTree.treeBox = getById("ot_nav_widget_box"); - - if(!globalPage.locationTree.widget) - globalPage.locationTree.buildOrgTreeWidget(); - globalPage.locationTree.treeBox.innerHTML = - globalPage.locationTree.widget.toString(); - +function renderTree(tree) { + tree.setObjects(); + if(!tree.widget) tree.buildOrgTreeWidget(); + tree.treeBox.innerHTML = tree.widget.toString(); } diff --git a/Open-ILS/src/javascript/opac/MRResultPage.js b/Open-ILS/src/javascript/opac/MRResultPage.js index 1df3426f87..28577ce56e 100644 --- a/Open-ILS/src/javascript/opac/MRResultPage.js +++ b/Open-ILS/src/javascript/opac/MRResultPage.js @@ -212,11 +212,16 @@ MRResultPage.prototype.doSearch = function() { this.searchDepth = globalSearchDepth; /* see if this is a new search */ - if( string != this.string || + if( isXUL() || /* don't cache client searches */ + string != this.string || stype != this.stype || this.searchLocation != location || this.searchDepth != depth ) { + debug("Resetting MRSearch for search " + string); this.resetSearch(); + + } else { + debug("Not Resetting MRSearch for search " + string); } this.searchDepth = depth; diff --git a/Open-ILS/src/javascript/opac/RecordDetailPage.js b/Open-ILS/src/javascript/opac/RecordDetailPage.js index 5ef099644c..0bdbf5613e 100644 --- a/Open-ILS/src/javascript/opac/RecordDetailPage.js +++ b/Open-ILS/src/javascript/opac/RecordDetailPage.js @@ -9,6 +9,36 @@ function RecordDetailPage() { this.searchBar = new SearchBarChunk(); } +RecordDetailPage.prototype.setPageTrail = function() { + var box = getById("page_trail"); + if(!box) return; + + var d = this.buildTrailLink("start",true); + if(d) { + box.appendChild(d); + } else { + d = this.buildTrailLink("advanced_search",true); + if(d) + box.appendChild(d); + } + + var b = this.buildTrailLink("mr_result", true); + + if(b) { + box.appendChild(this.buildDivider()); + box.appendChild(b); + } + + box.appendChild(this.buildDivider()); + try { + box.appendChild(this.buildTrailLink("record_result", true)); + } catch(E) {} /* doesn't work when deep linking */ + + box.appendChild(this.buildDivider()); + box.appendChild( + this.buildTrailLink("record_detail",false)); +} + RecordDetailPage.instance = function() { if( globalRecordDetailPage != null ) @@ -22,7 +52,21 @@ RecordDetailPage.prototype.init = function() { } RecordDetailPage.prototype.draw = function() { - this.mainBox = getById("record_detail_main_box"); + this.mainBox = getById("record_detail_copy_info"); + + this.mainBox.appendChild(elem("br")); + this.parentLink = elem("a", + { href : "javascript:void(0)", + id : "parent_link", + style : "text-decoration:underline" } ); + + this.mainBox.appendChild(this.parentLink); + this.locationTree = elem("div"); + this.mainBox.appendChild(this.locationTree); + + this.treeDiv = elem("div"); + this.mainBox.appendChild(this.treeDiv); + this.fetchRecord(paramObj.__record); /* sets this.record */ this.viewMarc = getById("record_detail_view_marc"); @@ -31,9 +75,13 @@ RecordDetailPage.prototype.draw = function() { RecordDetailPage.prototype.setViewMarc = function(record) { var marcb = elem( "a", - { href:"javascript:void(0)" }, {}, "View Marc" ); + { + href:"javascript:void(0)", + style: "text-decoration:underline" + }, + {}, "View MARC" ); - debug("Setting up view marc callback with record " + record.doc_id()); + debug(".ou_type()Setting up view marc callback with record " + record.doc_id()); var func = buildViewMARCWindow(record); marcb.onclick = func; this.viewMarc.appendChild(marcb); @@ -77,16 +125,17 @@ RecordDetailPage.prototype.drawRecord = function(record) { var subject_cell = getById("record_detail_subject_cell"); var tcn_cell = getById("record_detail_tcn_cell"); var resource_cell = getById("record_detail_resource_cell"); + var pic_cell = getById("record_detail_pic_cell"); - add_css_class(title_cell, "detail_item_cell"); - add_css_class(author_cell, "detail_item_cell"); - add_css_class(isbn_cell, "detail_item_cell"); - add_css_class(edition_cell, "detail_item_cell"); - add_css_class(pubdate_cell, "detail_item_cell"); + add_css_class(title_cell, "detail_item_cell"); + add_css_class(author_cell, "detail_item_cell"); + add_css_class(isbn_cell, "detail_item_cell"); + add_css_class(edition_cell, "detail_item_cell"); + add_css_class(pubdate_cell, "detail_item_cell"); add_css_class(publisher_cell, "detail_item_cell"); - add_css_class(subject_cell, "detail_item_cell"); - add_css_class(tcn_cell, "detail_item_cell"); - add_css_class(resource_cell, "detail_item_cell"); + add_css_class(subject_cell, "detail_item_cell"); + add_css_class(tcn_cell, "detail_item_cell"); + add_css_class(resource_cell, "detail_item_cell"); title_cell.appendChild( createAppTextNode(normalize(record.title()))); @@ -106,95 +155,166 @@ RecordDetailPage.prototype.drawRecord = function(record) { createAppTextNode(record.subject())); tcn_cell.appendChild( createAppTextNode(record.tcn())); + + + + + var resource = record.types_of_resource()[0]; + var r_pic = elem("img", + { src: "/images/" + resource + ".jpg" } ); + resource_cell.appendChild(r_pic); + resource_cell.appendChild(createAppTextNode(" ")); + resource_cell.appendChild( createAppTextNode(record.types_of_resource())); - this.drawCopyTree(record); + + + var isbn = record.isbn(); + if(isbn) isbn = isbn.replace(/\s+/,""); + else isbn = ""; + + var img_src = "http://images.amazon.com/images/P/" +isbn + ".01.MZZZZZZZ.jpg"; + var pic = createAppElement("img"); + pic.setAttribute("src", img_src); + pic_cell.appendChild(pic); + + var orgUnit = globalSelectedLocation; + if(!orgUnit) orgUnit = globalLocation; + + this.drawCopyTrees(orgUnit, record); } -RecordDetailPage.prototype.grabCopyTree = function(record, orgUnit, callback) { - debug("Grabbing copy tree for " + orgUnit.name() ); +/* if sync, it is a synchronous call */ +RecordDetailPage.prototype.grabCopyTree = function(record, orgUnit, callback, sync) { + + var orgIds = new Array(); + if(orgUnit.constructor == Array) { + for(var x = 0; x < orgUnit.length; x++) { + orgIds.push(orgUnit[x].id()); + } + } else { + orgIds.push(orgUnit.id()); + } + + debug("Grabbing copy tree for " + orgIds); var req = new RemoteRequest( "open-ils.cat", "open-ils.cat.asset.copy_tree.retrieve", - null, record.doc_id(), orgUnit.id() ); + null, record.doc_id(), orgIds ); + + var obj = this; + + if(sync) { /* synchronous call */ + req.send(true); + callback(req.getResultObject()); - var obj = this; + } else { req.setCompleteCallback( function(r) { callback(r.getResultObject()); }); - req.send(); + } } -RecordDetailPage.prototype.drawCopyTree = function(record) { +/* entry point for displaying the copy details pane */ +RecordDetailPage.prototype.drawCopyTrees = function(orgUnit, record) { - var user = UserSession.instance(); + debug("OrgUnit depth is: " + findOrgType(orgUnit.ou_type()).depth()); - /* - if(user && user.connected) - orgUnit = findOrgUnit(user.userObject.home_ou()); - else { - */ - var orgUnit = globalSelectedLocation; - if(!orgUnit) - orgUnit = globalLoction; - - var obj = this; - debug("We're connected, collecting local copies"); - this.grabCopyTree(record, orgUnit, - function(tree) { - obj.displayCopyTree(tree, "Local Volumes/Copies for " - + orgUnit.name(), "local_copy_tree" ); - obj.addExtraLinks(record); - } - ); + this.displayLocationTree(record); + + /* display a 'hold on' message */ + this.treeDiv.appendChild(elem("br")); + this.treeDiv.appendChild(elem("br")); + + /* everyone gets to see the location tree */ + var depth = parseInt(findOrgType(orgUnit.ou_type()).depth()); + if(depth != 0) { + this.treeDiv.appendChild(elem("div", null, null, "Loading copy information...")); + if(parseInt(findOrgType(orgUnit.ou_type()).can_have_vols())) + this.displayParentLink(orgUnit, record); + this.displayTrees(orgUnit, record); + } } -RecordDetailPage.prototype.addExtraLinks = function(record) { +/* displays a link to choose another location and embeds a + copy of the location tree for choosing said location */ +RecordDetailPage.prototype.displayLocationTree = function(record) { + + var locTree = new LocationTree(globalOrgTree); + locTree.buildOrgTreeWidget(); + + +} - var user = UserSession.instance(); +/* displays a link to view info for the parent org + if showMe == true, we don't search for the parent, + but use the given orgUnit as the link point */ +RecordDetailPage.prototype.displayParentLink = function(orgUnit, record, showMe) { - var href = createAppElement("a"); - href.setAttribute("href", "javascript:void(0)"); - var trail = orgNodeTrail(findOrgUnit(user.userObject.home_ou())); - var region = trail[1]; /* org trail starts at top, region is second */ - href.appendChild(createAppTextNode("-> See Volumes/Copies for " + region.name())); + var region = orgUnit; + if(!showMe) + region = findOrgUnit(orgUnit.parent_ou()); + + var href = this.parentLink; + removeChildren(href); + + href.appendChild(createAppTextNode( + "View Volumes/Copies for " + region.name())); var obj = this; - href.onclick = function() { - var thingy = getById("system_copy_tree"); - if(thingy) { - obj.mainBox.removeChild(thingy); - } else { - obj.grabCopyTree(record, region, - function(tree) { - if(tree) debug("In grabb copy callback for system with tree"); - obj.displayCopyTree(tree, - "Volumes/Copies for " + region.name(), "system_copy_tree"); - } - ); - } + href.onclick = function() { + + removeChildren(obj.treeDiv); + obj.treeDiv.appendChild(elem("br")); + obj.treeDiv.appendChild(elem("br")); + obj.treeDiv.appendChild(elem("div", null, null, "Loading copy information...")); + + /* allows the above message to be displayed */ + setTimeout(function() { obj.displayTrees(region, record, true) }, 100); + + if(showMe) + obj.displayParentLink(orgUnit, record); + else + obj.displayParentLink(orgUnit, record, true); } var reg_div = createAppElement("div"); reg_div.appendChild(href); - this.mainBox.appendChild(createAppElement("br")); - this.mainBox.appendChild(createAppElement("br")); - this.mainBox.appendChild(reg_div); + this.mainBox.insertBefore(reg_div, this.treeDiv); +} +/* displays copy info for orgUnit and all of it's children. + if orgUnit is a region (depth == 1), then we just show + all of our children. if it's a branch, sub-branch, etc. + the current branch as well as all of it's children are displayed */ +RecordDetailPage.prototype.displayTrees = function(orgUnit, record, sync) { + var obj = this; + var orgs = orgUnit.children(); + if(!orgs) orgs = []; + + if(parseInt(findOrgType(orgUnit.ou_type()).can_have_vols())) + orgs.unshift(orgUnit); + + this.grabCopyTree(record, orgs, + function(tree) { + obj.displayCopyTree(tree, "Volumes/Copies for " + orgUnit.name() ); + }, sync ); } -/* id is the id of the chunk we're adding to the page, prevents duplicates */ -RecordDetailPage.prototype.displayCopyTree = function(tree, title, id) { + +/* displays a single copy tree */ +RecordDetailPage.prototype.displayCopyTree = function(tree, title) { - var treeDiv = createAppElement("div"); - treeDiv.appendChild(createAppElement("br")); - treeDiv.appendChild(createAppElement("br")); + debug("Displaying copy tree for " + title); + var treeDiv = this.treeDiv; + removeChildren(treeDiv); add_css_class( treeDiv, "copy_tree_div" ); + var table = createAppElement("table"); add_css_class(table, "copy_tree_table"); var header_row = table.insertRow(table.rows.length); @@ -210,17 +330,28 @@ RecordDetailPage.prototype.displayCopyTree = function(tree, title, id) { var cell1 = row2.insertCell(row2.cells.length); var cell2 = row2.insertCell(row2.cells.length); var cell3 = row2.insertCell(row2.cells.length); + var cell4 = row2.insertCell(row2.cells.length); cell1.appendChild(createAppTextNode("Callnumber")); - cell2.appendChild(createAppTextNode("Volume Owned By")); - cell3.appendChild(createAppTextNode("Barcode")); + cell2.appendChild(createAppTextNode("Location")); + cell3.appendChild(createAppTextNode("Barcode(s)")); + cell4.appendChild(createAppTextNode("Availability")); add_css_class(cell1, "detail_header_cell"); add_css_class(cell2, "detail_header_cell"); add_css_class(cell3, "detail_header_cell"); + add_css_class(cell4, "detail_header_cell"); + if(tree.length == 0) { + var row = table.insertRow(table.rows.length); + row.insertCell(0).appendChild( + createAppTextNode("No copies available for this location")); + } + + var x = 0; for( var i in tree ) { var row = table.insertRow(table.rows.length); + if(x%2) add_css_class(row, "copy_tree_row_highlight"); var volume = tree[i]; var cell1 = row.insertCell(row.cells.length); @@ -230,58 +361,53 @@ RecordDetailPage.prototype.displayCopyTree = function(tree, title, id) { add_css_class(cell2, "detail_item_cell"); cell2.appendChild(createAppTextNode( findOrgUnit(volume.owning_lib()).name())); + + var cell3 = row.insertCell(row.cells.length); + add_css_class(cell3, "detail_item_cell"); + cell3.appendChild(createAppTextNode(" ")); + + var cell4 = row.insertCell(row.cells.length); + add_css_class(cell4, "detail_item_cell"); + cell4.appendChild(createAppTextNode(" ")); var copies = volume.copies(); var c = 0; while(c < copies.length) { var copy = copies[c]; + if(c == 0) { /* put the first barcode in the same row as the callnumber */ - var row = table.insertRow(table.rows.length); - row.insertCell(0); - row.insertCell(1); - var ce = row.insertCell(2); - add_css_class(ce, "detail_item_cell"); - ce.appendChild(createAppTextNode(copy.barcode())); - c++; - } - } + cell3.removeChild(cell3.childNodes[0]); + cell3.appendChild(createAppTextNode(copy.barcode())); + cell4.removeChild(cell4.childNodes[0]); - treeDiv.appendChild(table); - treeDiv.id = id; - this.mainBox.appendChild(treeDiv); -} + cell4.appendChild(createAppTextNode( + find_list(globalCopyStatus, + function(i) { return (i.id() == copy.status()); } ).name() )); + } else { -RecordDetailPage.prototype.setPageTrail = function() { - var box = getById("page_trail"); - if(!box) return; + var row = table.insertRow(table.rows.length); + if(x%2) add_css_class(row, "copy_tree_row_highlight"); + row.insertCell(0).appendChild(createAppTextNode(" ")); + row.insertCell(1).appendChild(createAppTextNode(" ")); - var d = this.buildTrailLink("start",true); - if(d) { - box.appendChild(d); - } else { - d = this.buildTrailLink("advanced_search",true); - if(d) - box.appendChild(d); - } + var ce = row.insertCell(2); + var status_cell = row.insertCell(3); + add_css_class(ce, "detail_item_cell"); + add_css_class(status_cell, "detail_item_cell"); + ce.appendChild(createAppTextNode(copy.barcode())); - var b = this.buildTrailLink("mr_result", true); + status_cell.appendChild(createAppTextNode( + find_list(globalCopyStatus, + function(i) { return (i.id() == copy.status()); } ).name() )); + } - if(b) { - box.appendChild(this.buildDivider()); - box.appendChild(b); + c++; + } + x++; } - box.appendChild(this.buildDivider()); - try { - box.appendChild(this.buildTrailLink("record_result", true)); - } catch(E) {} /* doesn't work when deep linking */ - - box.appendChild(this.buildDivider()); - box.appendChild( - this.buildTrailLink("record_detail",false)); + treeDiv.appendChild(table); } - - diff --git a/Open-ILS/src/javascript/opac/RecordResultPage.js b/Open-ILS/src/javascript/opac/RecordResultPage.js index f77b488abf..b5b6a99dd4 100644 --- a/Open-ILS/src/javascript/opac/RecordResultPage.js +++ b/Open-ILS/src/javascript/opac/RecordResultPage.js @@ -321,6 +321,15 @@ RecordResultPage.prototype.mrSearch = function(mrid) { function(req) { try{ obj.gatherIDs(req.getResultObject()); + + if(parseInt(obj.hitCount) == 1) { + debug("Redirecting to record detail page with record " + obj.recordIDs[0] ); + url_redirect( [ + "target", "record_detail", + "record", obj.recordIDs[0] ] ); + return; + } + obj.collectRecords(); } catch(E) { throw ("Search Error " + E ); } } diff --git a/Open-ILS/src/javascript/util/RemoteRequest.js b/Open-ILS/src/javascript/util/RemoteRequest.js index 8d97055c0c..eba4d749eb 100644 --- a/Open-ILS/src/javascript/util/RemoteRequest.js +++ b/Open-ILS/src/javascript/util/RemoteRequest.js @@ -99,6 +99,7 @@ function RemoteRequest( service, method ) { var i = 2; this.params = ""; + while(i < arguments.length) { var object = js2JSON(arguments[i++]); this.params += "&__param=" + encodeURIComponent(object); @@ -251,8 +252,10 @@ RemoteRequest.prototype.send = function(blocking) { 'application/x-www-form-urlencoded'); } + debug("Remote Request sending..." + data); this.xmlhttp.send( data ); this.sendCount += 1; + debug("Remote Request done sending"); return this; } diff --git a/Open-ILS/src/javascript/util/UserSession.js b/Open-ILS/src/javascript/util/UserSession.js index 96d943cc20..911c71cca7 100644 --- a/Open-ILS/src/javascript/util/UserSession.js +++ b/Open-ILS/src/javascript/util/UserSession.js @@ -55,11 +55,15 @@ UserSession.prototype.verifySession = function(ses) { var request = new RemoteRequest("open-ils.auth", "open-ils.auth.session.retrieve", this.session_id ); + debug("1"); request.send(true); + debug("2"); var user = request.getResultObject(); + debug("3"); if( typeof user == 'object' && user._isfieldmapper) { + debug("User retrieved, setting up user info"); this.username = user.usrname(); this.userObject = user; this.connected = true; @@ -151,13 +155,13 @@ UserSession.prototype.grabOrgUnit = function(org) { request.send(true); this.userObject = request.getResultObject(); - if(org) - this.orgUnit = org; - else - this.orgUnit = findOrgUnit(this.userObject.home_ou()); + if(org) this.orgUnit = org; + else this.orgUnit = findOrgUnit(this.userObject.home_ou()); - globalSelectedDepth = findOrgDepth(this.orgUnit.ou_type()); - globalPage.updateSelectedLocation(this.orgUnit); + if(!paramObj.__depth) + globalSelectedDepth = findOrgDepth(this.orgUnit.ou_type()); + if(!paramObj.__location) + globalPage.updateSelectedLocation(this.orgUnit); globalPage.updateCurrentLocation(this.orgUnit); return; diff --git a/Open-ILS/src/javascript/util/ils_utils.js b/Open-ILS/src/javascript/util/ils_utils.js index c5549dcf8f..cddc2b7346 100644 --- a/Open-ILS/src/javascript/util/ils_utils.js +++ b/Open-ILS/src/javascript/util/ils_utils.js @@ -8,6 +8,7 @@ function findOrgDepth(type_id) { var t = findOrgType(type_id); if(t != null) return t.depth(); + return null; } @@ -67,7 +68,6 @@ function getOrgById(id, node) { function orgNodeTrail(node) { var nodeArray = new Array(); while( node ) { - debug("pushing " + node.name() ); nodeArray.push(node); node = findOrgUnit(node.parent_ou()); } @@ -75,5 +75,10 @@ function orgNodeTrail(node) { return nodeArray; } +function findSiblingOrgs(node) { + return findOrgUnit(node.parent_ou()).children(); +} + + diff --git a/Open-ILS/src/javascript/util/webutils.js b/Open-ILS/src/javascript/util/webutils.js index a208cd5871..ff71cb03ef 100644 --- a/Open-ILS/src/javascript/util/webutils.js +++ b/Open-ILS/src/javascript/util/webutils.js @@ -67,6 +67,8 @@ function createAppTextNode(text) { each substring */ function normalize(val) { + if(!val) return ""; + var newVal = ''; val = val.split(' '); var reg = /\w/; @@ -327,6 +329,8 @@ function add_css_class(w,c) { } else { e = getById(w); } + if(!e) return; + var css_class_string = e.className; var css_class_array; @@ -353,6 +357,7 @@ function remove_css_class(w,c) { } else { e = getById(w); } + if(!e) return; var css_class_string = ''; var css_class_array = e.className; @@ -617,4 +622,26 @@ function elem(name, attrs, style, text) { return e; } +function filter_list(list,f) { + var new_list = []; + for (var i in list) { + var t = f( list[i] ); + if (t) new_list.push( list[i] ); + } + return new_list; +} +function find_list(list,f) { + for (var i in list) { + var t = f( list[i] ); + if (t) return list[i]; + } + return null; +} + +function removeChildren(node) { + if(typeof node == 'object' && node != null) { + while(node.childNodes[0]) + node.removeChild(node.childNodes[0]); + } +} -- 2.11.0