diff --git a/api/src/Page/Shipment.php b/api/src/Page/Shipment.php index 24fbeea13..c67d51e46 100644 --- a/api/src/Page/Shipment.php +++ b/api/src/Page/Shipment.php @@ -89,7 +89,7 @@ class Shipment extends Page //'FIRSTEXPERIMENTID' => '\w+\d+-\d+', // Fields for responsive remote questions: - 'DYNAMIC' => '1?|Yes|No', + 'DYNAMIC' => '\w+', 'REMOTEORMAILIN' => '.*', 'SESSIONLENGTH' => '\w+', 'ENERGY' => '.*', @@ -101,6 +101,7 @@ class Shipment extends Page 'MULTIAXISGONIOMETRY' => '1?|Yes|No', 'ENCLOSEDHARDDRIVE' => '1?|Yes|No', 'ENCLOSEDTOOLS' => '1?|Yes|No', + 'LONGWAVELENGTH' => '1?|Yes|No', 'COMMENTS' => '.*', @@ -164,7 +165,8 @@ class Shipment extends Page 'EXTRASUPPORTREQUIREMENT', 'MULTIAXISGONIOMETRY', 'ENCLOSEDHARDDRIVE', - 'ENCLOSEDTOOLS' + 'ENCLOSEDTOOLS', + 'LONGWAVELENGTH', ); public static $dispatch = array( @@ -2856,7 +2858,7 @@ function _add_shipment() $dynamic = null; if ($this->has_arg('DYNAMIC')) { - $dynamic = $this->arg("DYNAMIC") ? "Yes" : "No"; + $dynamic = $this->arg("DYNAMIC"); } $extra_array = array( @@ -2866,6 +2868,7 @@ function _add_shipment() ); if ($dynamic) { + $long_wavelength = $this->has_arg('LONGWAVELENGTH') ? $this->arg('LONGWAVELENGTH') : ''; $remote_or_mailin = $this->has_arg('REMOTEORMAILIN') ? $this->arg('REMOTEORMAILIN') : ''; $session_length = $this->has_arg('SESSIONLENGTH') ? $this->arg('SESSIONLENGTH') : ''; $energy_requirements = $this->has_arg('ENERGY') ? $this->arg('ENERGY') : ''; @@ -2888,6 +2891,7 @@ function _add_shipment() $multi_axis_goniometry = $this->arg('MULTIAXISGONIOMETRY') ? "Yes" : "No"; } $dynamic_options = array( + "LONGWAVELENGTH" => $long_wavelength, "REMOTEORMAILIN" => $remote_or_mailin, "SESSIONLENGTH" => $session_length, "ENERGY" => $energy_requirements, diff --git a/client/src/js/models/shipment.js b/client/src/js/models/shipment.js index eccef8c27..b55ddc00e 100644 --- a/client/src/js/models/shipment.js +++ b/client/src/js/models/shipment.js @@ -18,6 +18,10 @@ define(['backbone'], function (Backbone) { pattern: 'fcode', }, + DYNAMIC: { + required: true, + }, + FIRSTEXPERIMENTID: { required: false, pattern: 'number', @@ -27,6 +31,10 @@ define(['backbone'], function (Backbone) { required: false, }, + COMMENTS: { + required: false, + }, + SESSIONLENGTH: { required: false, pattern: 'number', diff --git a/client/src/js/modules/shipment/views/shipment.js b/client/src/js/modules/shipment/views/shipment.js index bbde464f3..2e634d38d 100644 --- a/client/src/js/modules/shipment/views/shipment.js +++ b/client/src/js/modules/shipment/views/shipment.js @@ -58,6 +58,7 @@ define(['marionette', ui: { add_dewar: '#add_dewar', + longwavelength: '.longwavelength', }, @@ -178,13 +179,19 @@ define(['marionette', if (!dynamicSelectedValues.includes(dynamic)) { this.$el.find(".remoteormailin").hide() this.$el.find(".remoteform").hide() + this.ui.longwavelength.hide() } else { industrial_codes = ['in', 'sw'] industrial_visit = industrial_codes.includes(app.prop.slice(0,2)) if (industrial_visit) { this.$el.find(".remoteormailin").show() } - this.$el.find(".remoteform").show() + this.ui.longwavelength.show() + if (this.model.get('LONGWAVELENGTH') === 'Yes') { + this.$el.find(".remoteform").hide() + } else { + this.$el.find(".remoteform").show() + } } }, @@ -214,7 +221,13 @@ define(['marionette', edit.create("ENCLOSEDHARDDRIVE", 'select', { data: {'Yes': 'Yes', 'No': 'No'}}) edit.create("ENCLOSEDTOOLS", 'select', { data: {'Yes': 'Yes', 'No': 'No'}}) - edit.create("DYNAMIC", 'select', { data: {'Yes': 'Yes', 'No': 'No'}}) + edit.create("DYNAMIC", 'select', { data: { + 'No': 'I have a session already scheduled', + 'UDC': 'I am sending pucks for Unattended Data Collection', + 'Imaging': 'I am sending plates for imaging', + 'Yes': 'I would like a session to be scheduled', + 'Other': 'Something else', + }}) industrial_codes = ['in', 'sw'] industrial_visit = industrial_codes.includes(app.prop.slice(0,2)) if (!industrial_visit) { @@ -223,6 +236,7 @@ define(['marionette', edit.create("REMOTEORMAILIN", 'select', { data: {'Remote': 'Remote', 'Mail-in': 'Mail-in', 'Other': 'Other'}}) } + edit.create("LONGWAVELENGTH", 'select', { data: {'Yes': 'Yes', 'No': 'No'}}) edit.create("SESSIONLENGTH", 'text') edit.create("ENERGY", 'text') edit.create("MICROFOCUSBEAM", 'select', { data: {'Yes': 'Yes', 'No': 'No'}}) @@ -233,7 +247,7 @@ define(['marionette', edit.create("MULTIAXISGONIOMETRY", 'select', { data: {'Yes': 'Yes', 'No': 'No'}}) this.updateDynamic() - this.listenTo(this.model, "change:DYNAMIC", this.updateDynamic) + this.listenTo(this.model, "change", this.updateDynamic) var self = this this.contacts = new LabContacts(null, { state: { pageSize: 9999 } }) diff --git a/client/src/js/modules/shipment/views/shipmentadd.js b/client/src/js/modules/shipment/views/shipmentadd.js index 602e33487..da90f4e66 100644 --- a/client/src/js/modules/shipment/views/shipmentadd.js +++ b/client/src/js/modules/shipment/views/shipmentadd.js @@ -56,26 +56,31 @@ define(['marionette', 'views/form', }, events: { - 'change input[name=DEWARS]': 'updateFCodes', + 'change @ui.dewars': 'updateFCodes', 'change @ui.lcret': 'getlcdetails', 'change select[name^=FCODES]': 'checkFCodes', 'change @ui.name': 'checkFCodes', 'click a.add_lc': 'addLC', - 'click @ui.noexp': 'updateFirstExp', - 'click @ui.dynamic': 'updateDynamicSchedule', - 'change select[name^=SAFETYLEVEL]': 'changeSafetyLevel', + 'change @ui.safetylevel': 'changeSafetyLevel', + 'change @ui.dynamic': 'updateFirstExp', + 'change @ui.longwavelengthsel': 'updateLongWavelength', }, ui: { + dewars: 'input[name=DEWARS]', lcret: 'select[name=RETURNLABCONTACTID]', lcout: 'select[name=SENDINGLABCONTACTID]', first: 'select[name=FIRSTEXPERIMENTID]', name: 'input[name=SHIPPINGNAME]', - noexp: 'input[name=noexp]', - dynamic: 'input[name=DYNAMIC]', // A checkbox to indicate dynamic/remote mail-in scheduling - comments: 'textarea[name=COMMENTS]', // We need this so we can prefill comments to aid users - safetylevel: 'select[name^=SAFETYLEVEL]', - udcresponsive: '.udcresponsive', + dynamic: 'input[name=DYNAMIC]', + udc: '#udc', + responsive: '#responsive', + imaging: '#imaging', + existing: '#existingsession', + other: '#other', + safetylevel: 'select[name=SAFETYLEVEL]', + longwavelengthsel: 'select[name=LONGWAVELENGTH]', + longwavelengthli: '.longwavelength', }, addLC: function(e) { @@ -102,45 +107,78 @@ define(['marionette', 'views/form', changeSafetyLevel: function() { if (this.ui.safetylevel.val() === 'Green') { - this.ui.udcresponsive.show() + this.ui.udc.prop('disabled', false) + this.ui.responsive.prop('disabled', false) + this.ui.imaging.prop('disabled', false) + this.ui.other.prop('disabled', false) } else { - this.ui.noexp.prop('checked', false) - this.updateFirstExp() - this.ui.dynamic.prop('checked', false) + this.ui.udc.prop('disabled', true) + this.ui.udc.prop('checked', false) + this.ui.responsive.prop('disabled', true) + this.ui.responsive.prop('checked', false) + this.ui.imaging.prop('disabled', true) + this.ui.imaging.prop('checked', false) + this.ui.other.prop('disabled', true) + this.ui.other.prop('checked', false) this.updateDynamicSchedule() - this.ui.udcresponsive.hide() } }, updateFirstExp: function() { - if (this.ui.noexp.is(':checked')) { - this.ui.first.html('') - this.ui.dynamic.prop('checked', false) - } else { + if (this.visits.length === 0) { + this.ui.existing.prop('disabled', true) + } + if (this.ui.existing.is(':checked')) { + this.ui.first.show() this.ui.first.html(''+this.visits.opts()) + } else { + this.ui.first.html('').change() + this.ui.first.hide() } + if (this.ui.other.is(':checked')) { + this.model.validation.COMMENTS.required = true + } else { + this.model.validation.COMMENTS.required = false + } + this.updateDynamicSchedule() }, updateDynamicSchedule: function() { - // Added as a fix to allow dynamic sessions - // An extra option for proposals with no sessions yet that are not automated - industrial_codes = ['in', 'sw'] - industrial_visit = industrial_codes.includes(app.prop.slice(0,2)) - if (this.ui.dynamic.is(':checked')) { - this.ui.first.html('') - this.ui.noexp.prop('checked', false) - this.$el.find(".remoteform").show() - if (industrial_visit) { - this.model.validation.REMOTEORMAILIN.required = true - this.$el.find(".remoteormailin").show() - } + if (this.ui.responsive.is(':checked')) { + this.ui.longwavelengthli.show() + this.updateLongWavelength() } else { - this.model.validation.REMOTEORMAILIN.required = false - this.ui.first.html(''+this.visits.opts()) - this.$el.find(".remoteform").hide() - if (industrial_visit) { - this.$el.find(".remoteormailin").hide() - } + this.ui.longwavelengthli.hide() + this.hideRemoteForm() + } + }, + + updateLongWavelength: function() { + if (this.ui.longwavelengthsel.val() === 'No') { + this.showRemoteForm() + } else { + this.hideRemoteForm() + } + }, + + isIndustrialProposal: function() { + industrial_codes = ['in', 'sw'] + return industrial_codes.includes(app.prop.slice(0,2)) + }, + + showRemoteForm: function() { + this.$el.find(".remoteform").show() + if (this.isIndustrialProposal()) { + this.model.validation.REMOTEORMAILIN.required = true + this.$el.find(".remoteormailin").show() + } + }, + + hideRemoteForm: function() { + this.model.validation.REMOTEORMAILIN.required = false + this.$el.find(".remoteform").hide() + if (this.isIndustrialProposal()) { + this.$el.find(".remoteormailin").hide() } }, @@ -206,7 +244,7 @@ define(['marionette', 'views/form', Update number of facility code inputs based on number of dewars */ updateFCodes: function() { - var d = this.$el.find('input[name=DEWARS]').val() + var d = this.ui.dewars.val() d > 0 ? this.$el.find('li.d').show() : this.$el.find('li.d').hide() var fcs = _.map(_.range(1,parseInt(d)+1), function(i) { return { id: i } }) this.fcodes.set(fcs) diff --git a/client/src/js/templates/shipment/shipment.html b/client/src/js/templates/shipment/shipment.html index a58058375..f219d1344 100644 --- a/client/src/js/templates/shipment/shipment.html +++ b/client/src/js/templates/shipment/shipment.html @@ -127,7 +127,26 @@