From 10a0ff263d746d8dc799afecf802c9d91dcf6304 Mon Sep 17 00:00:00 2001 From: "Mark M. Florida" <markflorida@wustl.edu> Date: Wed, 31 Aug 2016 21:25:02 -0500 Subject: [PATCH] XNAT-4286: Menu was not updating after creating new investigator (fixed); changed namespace to match file name and XAPI URI ('investigators' instead of 'investigatorData'). --- .../webapp/scripts/xnat/app/investigators.js | 59 ++++++++++--------- .../screens/xnat_projectData/edit/details.vm | 28 ++++----- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/main/webapp/scripts/xnat/app/investigators.js b/src/main/webapp/scripts/xnat/app/investigators.js index 0ad9de2c..1a3f74a7 100644 --- a/src/main/webapp/scripts/xnat/app/investigators.js +++ b/src/main/webapp/scripts/xnat/app/investigators.js @@ -16,7 +16,7 @@ var XNAT = getObject(XNAT); } }(function(){ - var undef, investigatorData, + var undef, investigators, BASE_URL = '/xapi/investigators', ui = XNAT.ui, xhr = XNAT.xhr, @@ -30,7 +30,7 @@ var XNAT = getObject(XNAT); return xurl.rootUrl(BASE_URL + part); } - investigatorData = getObject(XNAT.app.investigatorData || XNAT.xapi.investigators || {}); + investigators = getObject(XNAT.app.investigators || XNAT.xapi.investigators || {}); var investigatorDataObj = { "id": null, @@ -131,24 +131,30 @@ var XNAT = getObject(XNAT); // renders the <option> elements Investigators.fn.createMenuItems = function(selected){ var self = this; - selected = [].concat(selected); + selected = [].concat(selected).map(function(item){ + return item+''; + }); this.getAll(); this.xhr.done(function(data){ + self.selected = []; - self.menu$ - .empty() - .append(data.map(function(item){ - var id = item.xnatInvestigatordataId+''; - var menuOption = spawn('option', { - value: id, - html: item.lastname + ', ' + item.firstname - }); - if (selected.indexOf(id) > -1) { - self.selected.push(id); - menuOption.selected = true; - } - return menuOption; - })); + + var options = data.map(function(item){ + var id = item.xnatInvestigatordataId+''; + var menuOption = spawn('option', { + value: id, + html: item.lastname + ', ' + item.firstname + }); + if (selected.indexOf(id) > -1) { + self.selected.push(id); + menuOption.selected = true; + } + return menuOption; + }); + + // empty the options, then add the updated options + self.menu$.empty().append(options); + }); return this; }; @@ -170,7 +176,6 @@ var XNAT = getObject(XNAT); // make sure the request is done before rendering this.xhr.done(function(){ $$(container).append(self.menu); - self.menu$.change(); menuInit(self.menu, null, width||200); }); return this; @@ -180,7 +185,7 @@ var XNAT = getObject(XNAT); var self = this; this.createMenuItems(selected); this.xhr.done(function(){ - self.menu$.change(); + //self.menu$.val(selected).change(); menuUpdate(self.menu); }); return this; @@ -285,30 +290,30 @@ var XNAT = getObject(XNAT); // init function for XNAT.misc.blank - investigatorData.init = function(opts){ + investigators.init = function(opts){ return new Investigators(opts); }; - investigatorData.getAll = function(opts){ + investigators.getAll = function(opts){ return this.init().getAll(opts).xhr; }; - investigatorData.get = function(id){ + investigators.get = function(id){ return this.init().get(id).xhr; }; // JUST the REST call to create new investigator - investigatorData.createNew = function(opts){ + investigators.createNew = function(opts){ // }; // JUST the REST call to update the investigator - investigatorData.update = function(){ + investigators.update = function(){ // }; - investigatorData.delete = function(id, opts){ + investigators.delete = function(id, opts){ if (!id) return false; return xhr.delete(extend, { url: setupUrl(id) @@ -318,8 +323,8 @@ var XNAT = getObject(XNAT); ////////////////////////////////////////////////// // this script has loaded - investigatorData.loaded = true; + investigators.loaded = true; - return XNAT.app.investigatorData = XNAT.xapi.investigators = investigatorData; + return XNAT.app.investigators = XNAT.xapi.investigators = investigators; })); diff --git a/src/main/webapp/xnat-templates/screens/xnat_projectData/edit/details.vm b/src/main/webapp/xnat-templates/screens/xnat_projectData/edit/details.vm index 6859e7fd..82db2207 100644 --- a/src/main/webapp/xnat-templates/screens/xnat_projectData/edit/details.vm +++ b/src/main/webapp/xnat-templates/screens/xnat_projectData/edit/details.vm @@ -68,7 +68,7 @@ #end <TR> - <TH align="left" style="vertical-align: top;"> + <TH align="left"> <span class="nobr">$displayManager.getSingularDisplayNameForProject() Description</span> </TH> <TD> @@ -135,7 +135,7 @@ #end <TR> - <TH align="left" valign="top">Investigator(s)</TH> + <TH align="left">Investigator(s)</TH> <TD> <div id="investigatorBox">Loading...</div> </TD> @@ -160,18 +160,18 @@ (function(){ - var investigatorData = getObject(XNAT.app.investigatorData); + var investigators = getObject(XNAT.app.investigators); var projectID = XNAT.data.context.projectID; - investigatorData.project = projectID; - investigatorData.primary = null; - investigatorData.others = []; - investigatorData.count = 0; + investigators.project = projectID; + investigators.primary = null; + investigators.others = []; + investigators.count = 0; //window.invest_manager = new InvestigatorManager(); #if($om.getProperty("pi_xnat_investigatordata_id")) - investigatorData.primary = '$!om.getProperty("pi_xnat_investigatordata_id")'; + investigators.primary = '$!om.getProperty("pi_xnat_investigatordata_id")'; #end // window.other_investigators = new Array(); @@ -179,17 +179,17 @@ #set ($investigators = $om.getInvestigators_investigator()) #foreach($inv in $investigators) #if (!$inv.getXnatInvestigatordataId.equals($primaryInv)) - investigatorData.others.push('$inv.getXnatInvestigatordataId()'); + investigators.others.push('$inv.getXnatInvestigatordataId()'); //window.other_investigators.push("$inv.getXnatInvestigatordataId()"); #end #end - console.log(investigatorData.primary); + console.log(investigators.primary); var iBox = $('#investigatorBox'); var piBox = spawn('span#primary-investigator-menu'); - var piMenu = investigatorData.init(); + var piMenu = investigators.init(); // creates <select> piMenu.createMenu({ @@ -197,7 +197,7 @@ }); // creates <option> elements with PI selected - piMenu.createMenuItems(investigatorData.primary); + piMenu.createMenuItems(investigators.primary); // puts the menu in the box piMenu.render(piBox, 300); @@ -218,7 +218,7 @@ // TODO: 'OTHER' INVESTIGATORS // // function othersMenu(){ -// var iMenu = XNAT.app.investigatorData.init(inv); +// var iMenu = XNAT.app.investigators.init(inv); // // iMenu.setMenu(spawn('select|multiple', {name: iMenuName()} )); // iMenu.getAll({ @@ -239,7 +239,7 @@ // } - //var iDialog = XNAT.app.investigatorData.dialog(); + //var iDialog = XNAT.app.investigators.dialog(); -- GitLab