diff --git a/mcc/resources/web/mcc/window/MarkShippedWindow.js b/mcc/resources/web/mcc/window/MarkShippedWindow.js
index dd369edb7..9d38932c4 100644
--- a/mcc/resources/web/mcc/window/MarkShippedWindow.js
+++ b/mcc/resources/web/mcc/window/MarkShippedWindow.js
@@ -10,11 +10,6 @@ Ext4.define('MCC.window.MarkShippedWindow', {
return;
}
- if (checked.length !== 1) {
- Ext4.Msg.alert('Error', 'Currently only one ID is supported as a time');
- return;
- }
-
Ext4.create('MCC.window.MarkShippedWindow', {
dataRegionName: dataRegionName,
rowIds: checked
@@ -37,23 +32,6 @@ Ext4.define('MCC.window.MarkShippedWindow', {
html: 'This will:
1) Mark the selected animals as shipped from this center
2) Enter a new demographics record in the selected study
3) Preserve the MCC ID for each animal.',
border: false,
style: 'padding-bottom: 10px;'
- },{
- xtype: 'checkbox',
- fieldLabel: 'Animal Will Use Previous Id',
- itemId: 'usePreviousId',
- listeners: {
- scope: this,
- change: function (field, val) {
- var target = field.up('panel').down('#newId');
- target.allowBlank = !!val;
- target.setVisible(!val);
- }
- },
- },{
- xtype: 'textfield',
- fieldLabel: 'New ID (blank if unchanged)',
- itemId: 'newId',
- allowBlank: false
},{
xtype: 'datefield',
fieldLabel: 'Effective Date',
@@ -105,7 +83,7 @@ Ext4.define('MCC.window.MarkShippedWindow', {
}
}
}
- }],
+ }, this.getAnimalIdFields()],
buttons: [{
text: 'Submit',
handler: this.onSubmit,
@@ -121,11 +99,72 @@ Ext4.define('MCC.window.MarkShippedWindow', {
this.callParent(arguments);
},
+ getAnimalIdFields: function(){
+ var fields = [{
+ xtype: 'displayfield',
+ value: 'Animal ID',
+ width: 150
+ },{
+ xtype: 'displayfield',
+ value: 'Keep Existing ID?',
+ width: 150
+ },{
+ xtype: 'displayfield',
+ value: 'New ID (blank if unchanged)',
+ }];
+
+ Ext4.Array.forEach(this.rowIds, function(rowId){
+ const animalId = this.lsidToAnimalId(rowId);
+ fields = fields.concat([{
+ xtype: 'displayfield',
+ value: animalId,
+ },{
+ xtype: 'checkbox',
+ itemId: 'usePreviousId-' + animalId,
+ checked: false,
+ listeners: {
+ scope: this,
+ change: function (field, val) {
+ var target = field.up('panel').down('#newId-' + animalId);
+ target.allowBlank = !!val;
+ target.setDisabled(val);
+ }
+ }
+ },{
+ xtype: 'textfield',
+ itemId: 'newId-' + animalId,
+ disabled: false,
+ allowBlank: true
+ }]);
+ }, this);
+
+ return {
+ layout: {
+ type: 'table',
+ columns: 3
+ },
+ border: false,
+ defaults: {
+ style: 'padding:5px;',
+ border: false
+ },
+ items: fields
+ };
+ },
+
+ lsidToAnimalId: function(lsid){
+ lsid = lsid.split(':')[4];
+ lsid = lsid.split('.');
+ lsid.shift();
+
+ return lsid.join('.');
+ },
+
onSubmit: function(btn){
Ext4.Msg.wait('Loading...');
var win = btn.up('window');
- var lsid = win.rowIds[0];
+ var lsids = win.rowIds;
var effectiveDate = win.down('#effectiveDate').getValue();
var centerName = win.down('#centerName').getValue();
var targetFolder = win.down('#targetFolder').getValue();
@@ -134,9 +173,19 @@ Ext4.define('MCC.window.MarkShippedWindow', {
return;
}
- if (!win.down('#usePreviousId').getValue() && !win.down('#newId').getValue()) {
- Ext4.Msg.hide();
- Ext4.Msg.alert('Error', 'Must enter the new ID');
+ var hasError = false;
+ Ext4.Array.forEach(this.rowIds, function(rowId) {
+ var animalId = this.lsidToAnimalId(rowId);
+ var useExisting = win.down('#usePreviousId-' + animalId).getValue();
+ if (!useExisting && !win.down('#newId-' + animalId).getValue()) {
+ Ext4.Msg.hide();
+ Ext4.Msg.alert('Error', 'Must enter the new ID for: ' + animalId);
+ hasError = true;
+ return false;
+ }
+ }, this);
+
+ if (hasError) {
return;
}
@@ -145,122 +194,125 @@ Ext4.define('MCC.window.MarkShippedWindow', {
LABKEY.Query.selectRows({
schemaName: 'study',
queryName: 'Demographics',
- filterArray: [LABKEY.Filter.create('lsid', lsid)],
+ filterArray: [LABKEY.Filter.create('lsid', lsids.join(';'), LABKEY.Filter.Types.IN)],
columns: 'Id,gender,colony,species,birth,death,center,Id/MostRecentDeparture/MostRecentDeparture,Id/mccAlias/externalAlias,calculated_status,dam,sire,damMccAlias/externalAlias,sireMccAlias/externalAlias',
scope: this,
failure: LDK.Utils.getErrorCallback(),
success: function(results) {
if (!results || !results.rows || !results.rows.length) {
Ext4.Msg.hide();
- Ext4.Msg.alert('Error', 'No row round for LSID: ' + lsid + '. This is not expected');
- return;
+ Ext4.Msg.alert('Error', 'No rows found for, this is not expected');
+ return false;
}
- var row = results.rows[0];
- var newId = win.down('#newId').getValue() || row.Id;
var commands = [];
+ Ext4.Array.forEach(results.rows, function(row){
+ var effectiveId = win.down('#usePreviousId-' + row.Id).getValue() ? row.Id : win.down('#newId-' + row.Id).getValue();
+ // This should be checked above, although perhaps case sensitivity could get involved:
+ LDK.Assert.assertNotEmpty('Missing effective ID after query', effectiveId);
- var shouldAddDeparture = !row['Id/MostRecentDeparture/MostRecentDeparture'] || row['Id/MostRecentDeparture/MostRecentDeparture'] !== Ext4.Date.format(row.effectiveDate, 'Y-m-d') || row.Id !== newId;
- if (shouldAddDeparture) {
- commands.push({
- command: 'insert',
- schemaName: 'study',
- queryName: 'Departure',
- rows: [{
- Id: row.Id,
- date: effectiveDate,
- destination: centerName,
- description: row.colony ? 'Original center: ' + row.colony : null,
- qcstate: null,
- objectId: null,
- QCStateLabel: 'Completed'
- }]
- });
- }
+ var shouldAddDeparture = !row['Id/MostRecentDeparture/MostRecentDeparture'] || row['Id/MostRecentDeparture/MostRecentDeparture'] !== Ext4.Date.format(row.effectiveDate, 'Y-m-d') || row.Id !== effectiveId;
+ if (shouldAddDeparture) {
+ commands.push({
+ command: 'insert',
+ schemaName: 'study',
+ queryName: 'Departure',
+ rows: [{
+ Id: row.Id,
+ date: effectiveDate,
+ destination: centerName,
+ description: row.colony ? 'Original center: ' + row.colony : null,
+ qcstate: null,
+ objectId: null,
+ QCStateLabel: 'Completed'
+ }]
+ });
+ }
- // If going to a new LK folder, we're creating a whole new record:
- if (targetFolderId.toUpperCase() !== LABKEY.Security.currentContainer.id.toUpperCase() || newId !== row.Id) {
- commands.push({
- command: 'insert',
- containerPath: targetFolder,
- schemaName: 'study',
- queryName: 'Demographics',
- rows: [{
- Id: newId,
- date: effectiveDate,
- alternateIds: row.Id !== newId ? row.Id : null,
- gender: row.gender,
- species: row.species,
- birth: row.birth,
- death: row.death,
- dam: row.dam,
- sire: row.sire,
- damMccAlias: row['damMccAlias/externalAlias'],
- sireMccAlias: row['sireMccAlias/externalAlias'],
- colony: centerName,
- source: row.colony,
- calculated_status: 'Alive',
- mccAlias: row['Id/mccAlias/externalAlias'],
- QCState: null,
- QCStateLabel: 'Completed',
- objectId: null
- }]
- });
+ // If going to a new LK folder, we're creating a whole new record:
+ if (targetFolderId.toUpperCase() !== LABKEY.Security.currentContainer.id.toUpperCase() || effectiveId !== row.Id) {
+ commands.push({
+ command: 'insert',
+ containerPath: targetFolder,
+ schemaName: 'study',
+ queryName: 'Demographics',
+ rows: [{
+ Id: effectiveId,
+ date: effectiveDate,
+ alternateIds: row.Id !== effectiveId ? row.Id : null,
+ gender: row.gender,
+ species: row.species,
+ birth: row.birth,
+ death: row.death,
+ dam: row.dam,
+ sire: row.sire,
+ damMccAlias: row['damMccAlias/externalAlias'],
+ sireMccAlias: row['sireMccAlias/externalAlias'],
+ colony: centerName,
+ source: row.colony,
+ calculated_status: 'Alive',
+ mccAlias: row['Id/mccAlias/externalAlias'],
+ QCState: null,
+ QCStateLabel: 'Completed',
+ objectId: null
+ }]
+ });
- commands.push({
- command: 'update',
- containerPath: null, //Use current folder
- schemaName: 'study',
- queryName: 'Demographics',
- rows: [{
- Id: row.Id, // NOTE: always change the original record
- excludeFromCensus: true
- }]
- });
- }
- else {
- // Otherwise update the existing:
- commands.push({
- command: 'update',
- containerPath: targetFolder,
- schemaName: 'study',
- queryName: 'Demographics',
- rows: [{
- Id: row.Id,
- date: effectiveDate,
- alternateIds: null,
- gender: row.gender,
- species: row.species,
- birth: row.birth,
- death: row.death,
- dam: row.dam,
- sire: row.sire,
- colony: centerName,
- source: row.colony,
- calculated_status: 'Alive',
- QCState: null,
- QCStateLabel: 'Completed',
- objectId: null
- }]
- });
+ commands.push({
+ command: 'update',
+ containerPath: null, //Use current folder
+ schemaName: 'study',
+ queryName: 'Demographics',
+ rows: [{
+ Id: row.Id, // NOTE: always change the original record
+ excludeFromCensus: true
+ }]
+ });
+ }
+ else {
+ // Otherwise update the existing:
+ commands.push({
+ command: 'update',
+ containerPath: targetFolder,
+ schemaName: 'study',
+ queryName: 'Demographics',
+ rows: [{
+ Id: row.Id,
+ date: effectiveDate,
+ alternateIds: null,
+ gender: row.gender,
+ species: row.species,
+ birth: row.birth,
+ death: row.death,
+ dam: row.dam,
+ sire: row.sire,
+ colony: centerName,
+ source: row.colony,
+ calculated_status: 'Alive',
+ QCState: null,
+ QCStateLabel: 'Completed',
+ objectId: null
+ }]
+ });
- // And also add an arrival record. NOTE: set the date after the departure to get status to update properly
- var arrivalDate = new Date(effectiveDate).setMinutes(effectiveDate.getMinutes() + 1);
- commands.push({
- command: 'insert',
- containerPath: targetFolder,
- schemaName: 'study',
- queryName: 'Arrival',
- rows: [{
- Id: newId,
- date: arrivalDate,
- source: centerName,
- QCState: null,
- QCStateLabel: 'Completed',
- objectId: null
- }]
- });
- }
+ // And also add an arrival record. NOTE: set the date after the departure to get status to update properly
+ var arrivalDate = new Date(effectiveDate).setMinutes(effectiveDate.getMinutes() + 1);
+ commands.push({
+ command: 'insert',
+ containerPath: targetFolder,
+ schemaName: 'study',
+ queryName: 'Arrival',
+ rows: [{
+ Id: effectiveId,
+ date: arrivalDate,
+ source: centerName,
+ QCState: null,
+ QCStateLabel: 'Completed',
+ objectId: null
+ }]
+ });
+ }
+ }, this);
LABKEY.Query.saveRows({
commands: commands,
diff --git a/mcc/test/src/org/labkey/test/tests/mcc/MccTest.java b/mcc/test/src/org/labkey/test/tests/mcc/MccTest.java
index 89d94101c..c4a2f2739 100644
--- a/mcc/test/src/org/labkey/test/tests/mcc/MccTest.java
+++ b/mcc/test/src/org/labkey/test/tests/mcc/MccTest.java
@@ -40,6 +40,7 @@
import org.labkey.test.util.DataRegionTable;
import org.labkey.test.util.Ext4Helper;
import org.labkey.test.util.PermissionsHelper;
+import org.labkey.test.util.ext4cmp.Ext4CmpRef;
import org.labkey.test.util.ext4cmp.Ext4ComboRef;
import org.labkey.test.util.ext4cmp.Ext4FieldRef;
@@ -128,7 +129,7 @@ private void testAnimalImportAndTransfer() throws Exception
new Window.WindowFinder(getDriver()).withTitle("Error").waitFor();
waitAndClick(Ext4Helper.Locators.ext4Button("OK"));
- Ext4FieldRef.getForLabel(this, "Animal Will Use Previous Id").setChecked(true);
+ _ext4Helper.queryOne("#usePreviousId-Animal2", Ext4FieldRef.class).setChecked(true);
waitAndClick(Ext4Helper.Locators.ext4Button("Submit"));
new Window.WindowFinder(getDriver()).withTitle("Success").waitFor();
@@ -181,7 +182,7 @@ private void testAnimalImportAndTransfer() throws Exception
sleep(100);
Ext4ComboRef.getForLabel(this, "Target Folder").setComboByDisplayValue("Other");
- Ext4FieldRef.getForLabel(this, "Animal Will Use Previous Id").setChecked(true);
+ _ext4Helper.queryOne("#usePreviousId-Animal2", Ext4FieldRef.class).setChecked(true);
waitAndClick(Ext4Helper.Locators.ext4Button("Submit"));
new Window.WindowFinder(getDriver()).withTitle("Success").waitFor();
@@ -238,7 +239,7 @@ private void testAnimalImportAndTransfer() throws Exception
sleep(100);
Ext4ComboRef.getForLabel(this, "Target Folder").setComboByDisplayValue("Other");
- Ext4FieldRef.getForLabel(this, "New ID (blank if unchanged)").setValue("TheNewId");
+ _ext4Helper.queryOne("#newId-12345", Ext4FieldRef.class).setValue("TheNewId");
waitAndClick(Ext4Helper.Locators.ext4Button("Submit"));
new Window.WindowFinder(getDriver()).withTitle("Success").waitFor();