Skip to content

Commit

Permalink
Merge pull request #372 from delageniere/issue350
Browse files Browse the repository at this point in the history
Issue350
  • Loading branch information
antolinos authored Mar 23, 2018
2 parents 4413733 + 53d3e4d commit 0e49f2e
Show file tree
Hide file tree
Showing 17 changed files with 398 additions and 132 deletions.
70 changes: 29 additions & 41 deletions js/core/view/shipping/caseform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function CaseForm(args) {
this.showTitle = args.showTitle;
}
}

this.onSaved = new Event(this);
}

Expand All @@ -40,9 +39,9 @@ CaseForm.prototype.getDewar = function() {
this.dewar.code = Ext.getCmp(this.id + "dewar_code").getValue();
this.dewar.comments = Ext.getCmp(this.id + "dewar_comments").getValue();
this.dewar.transportValue = Ext.getCmp(this.id + "dewar_transportValue").getValue();
// this.dewar.storageLocation = Ext.getCmp("dewar_storageLocation").getValue();
this.dewar.storageLocation = this.storageLocationComboBox.getValue();
//this.dewar.firstExperimentId = this.sessionsCombo.getValue();

return this.dewar;
};

Expand All @@ -60,29 +59,17 @@ CaseForm.prototype.setDewar = function(dewar) {
Ext.getCmp(this.id + "dewar_code").setValue(this.dewar.code);
Ext.getCmp(this.id + "dewar_comments").setValue(this.dewar.comments);
Ext.getCmp(this.id + "dewar_transportValue").setValue(this.dewar.transportValue);
// Ext.getCmp("dewar_storageLocation").setValue(this.dewar.storageLocation);
this.storageLocationComboBox.setValue(this.dewar.storageLocation);
/*if (this.dewar.sessionVO != null) {
this.sessionsCombo.setValue(this.dewar.sessionVO.sessionId);
}*/

};

/*
CaseForm.prototype.getSessionCombo = function() {
this.sessionsCombo = BIOSAXS_COMBOMANAGER.getComboSessions(EXI.proposalManager.getFutureSessions(), {
labelWidth : 200,
margin : '5 0 00 0',
width : 500
});
return this.sessionsCombo;
};*/

CaseForm.prototype.getStorageLocationCombo = function() {
this.storageLocationComboBox = BIOSAXS_COMBOMANAGER.getComboStorageTemperature();
return this.storageLocationComboBox;
};

CaseForm.prototype.getPanel = function(dewar) {
CaseForm.prototype.getPanel = function(dewar, hideReimb) {

this.panel = Ext.create('Ext.form.Panel', {
width : this.width - 10,
// cls : 'border-grid',
Expand All @@ -106,30 +93,31 @@ CaseForm.prototype.getPanel = function(dewar) {
id : this.id + 'dewar_code',
labelWidth : 200,
width : 500
}
},
]
},
this.getStorageLocationCombo(),
{
xtype : 'numberfield',
width : 500,
labelWidth : 200,
margin : '10 0 0 0',
fieldLabel : 'Transport Value',
id : this.id + 'dewar_transportValue'
},
{
xtype : 'textareafield',
name : 'comments',
fieldLabel : 'Comments',
labelWidth : 200,
width : 500,
margin : '10 0 0 0',
height : 100,
id : this.id + 'dewar_comments'
} ]
} ]
});
},
this.getStorageLocationCombo(),
{
xtype : 'numberfield',
width : 500,
labelWidth : 200,
margin : '10 0 0 0',
fieldLabel : 'Transport Value',
id : this.id + 'dewar_transportValue'
},
{
xtype : 'textareafield',
name : 'comments',
fieldLabel : 'Comments',
labelWidth : 200,
width : 500,
margin : '10 0 0 0',
height : 100,
id : this.id + 'dewar_comments'
},
]}]
});

this.refresh(dewar);
return this.panel;
};
};
67 changes: 57 additions & 10 deletions js/core/view/shipping/parcelgrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function ParcelGrid(args) {
this.btnEditVisible = true;
this.btnRemoveVisible = true;

this.reimbursementId = this.id + "_reimbursement_panel";

if (args != null) {
if (args.height != null) {
this.height = args.height;
Expand Down Expand Up @@ -43,29 +45,71 @@ function ParcelGrid(args) {
this.onRemove = new Event(this);
}

ParcelGrid.prototype.getReimbursementContentHTML = function(currentReimbursedDewars, maxReimbursedDewars ) {
return "("+ currentReimbursedDewars +" reimbursed out of " + maxReimbursedDewars +" allowed)";
};
ParcelGrid.prototype.getReimbursementHTML = function(currentReimbursedDewars, maxReimbursedDewars ) {
if (maxReimbursedDewars){
if (maxReimbursedDewars > 0){
return "<span id='" + this.reimbursementId +"' style='color:orange'>" + this.getReimbursementContentHTML(currentReimbursedDewars, maxReimbursedDewars)+ "</span>"
}
}
return "";
};

ParcelGrid.prototype.refreshReimbursementContentHTML = function(currentReimbursedDewars, maxReimbursedDewars ) {
$("#" + this.reimbursementId).html(this.getReimbursementContentHTML(currentReimbursedDewars, maxReimbursedDewars));
};

ParcelGrid.prototype.displayContentLabel = function(dewars,nSamples,nMeasured, currentReimbursedDewars, maxReimbursedDewars ) {

$("#" + this.id + "-label").html("Content (" + dewars.length + " Parcels " + this.getReimbursementHTML(currentReimbursedDewars, maxReimbursedDewars) + " - " + nSamples + " Samples - " + nMeasured + " Measured )");
};

ParcelGrid.prototype.getAuthorizedReimbursedDewars = function(sessions) {
if (sessions){
if (sessions.length > 0){
return sessions[0].nbReimbDewars;
}
};
return 0;
};

ParcelGrid.prototype.getCurrentReimbursedDewars = function(dewars) {
return _.filter(dewars, function(o){ return o.isReimbursed == true}).length;
};

ParcelGrid.prototype.load = function(shipment,hasExportedData,samples,withoutCollection) {
var _this = this;
this.shipment = shipment;
this.dewars = shipment.dewarVOs;
this.hasExportedData = hasExportedData;
nSamples = 0;
nMeasured = 0;
this.maxReimbursedDewars = 0;
this.currentReimbursedDewars = 0;
if (samples) {
nSamples = samples.length;
nMeasured = nSamples - withoutCollection.length;
this.samples = _.groupBy(samples,"Dewar_dewarId");
this.withoutCollection = _.groupBy(withoutCollection,"Dewar_dewarId");
};

if (shipment){
this.maxReimbursedDewars = this.getAuthorizedReimbursedDewars(this.shipment.sessions);
this.currentReimbursedDewars = this.getCurrentReimbursedDewars(this.dewars);
}

this.dewars.sort(function(a, b) {
return a.dewarId - b.dewarId;
});

$("#" + this.id + "-label").html("Content (" + this.dewars.length + " Parcels - " + nSamples + " Samples - " + nMeasured + " Measured)");
this.displayContentLabel(this.dewars, nSamples, nMeasured, this.currentReimbursedDewars, this.maxReimbursedDewars);
$("#" + this.id + "-add-button").removeClass("disabled");
$("#" + this.id + "-add-button").unbind('click').click(function(sender){
_this.edit();
});

if (nSamples > 0) {
$("#" + this.id + "-export").removeClass("disabled");
$("#" + this.id + "-export").unbind('click').click(function(sender){
Expand All @@ -74,14 +118,15 @@ ParcelGrid.prototype.load = function(shipment,hasExportedData,samples,withoutCol
exportForm.show();
});
}

this.fillTab("content", this.dewars);

this.attachCallBackAfterRender();
};

ParcelGrid.prototype.fillTab = function (tabName, dewars) {
var _this = this;
var _this = this;

$("#" + tabName + "-" + this.id).html("");
this.parcelPanels[tabName] = Ext.create('Ext.panel.Panel', {
// cls : 'border-grid',
Expand All @@ -98,20 +143,22 @@ ParcelGrid.prototype.fillTab = function (tabName, dewars) {
dewar["shippingId"] = _this.shipment.shippingId;

var onSuccess = function(sender, shipment) {
_this.panel.setLoading(false);
_this.panel.doLayout();
_this.panel.setLoading(false);
_this.refreshReimbursementContentHTML( _this.getCurrentReimbursedDewars(shipment.dewarVOs), _this.getAuthorizedReimbursedDewars(shipment.sessions));
_this.currentReimbursedDewars = _this.getCurrentReimbursedDewars(shipment.dewarVOs);
_this.panel.doLayout();
};
EXI.getDataAdapter({onSuccess : onSuccess}).proposal.dewar.saveDewar(_this.shipment.shippingId, dewar);
}

for ( var i in dewars) {
var parcelPanel = new ParcelPanel({
height : 90,
width : this.panel.getWidth()*0.9,
height : 110,
width : this.panel.getWidth()*0.9,
shippingId : this.shipment.shippingId,
shippingStatus : this.shipment.shippingStatus,
index : Number(i)+1,
currentTab : tabName
currentTab : tabName,
});
this.parcelPanels[tabName].insert(parcelPanel.getPanel());
parcelPanel.load(this.dewars[i],this.shipment,this.samples[this.dewars[i].dewarId],this.withoutCollection[this.dewars[i].dewarId]);
Expand All @@ -130,7 +177,7 @@ ParcelGrid.prototype.edit = function(dewar) {
width : 600,
modal : true,
layout : 'fit',
items : [ caseForm.getPanel(dewar) ],
items : [ caseForm.getPanel(dewar, true) ],
listeners : {
afterrender : function(component, eOpts) {
if (_this.puck != null) {
Expand Down
116 changes: 116 additions & 0 deletions js/core/view/shipping/reimbursementform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* @showTitle
*
* #onSaved
* #onAddPlates
* #onRemovePlates
**/
function ReimbForm(args) {
this.id = BUI.id();
this.width = 600;
this.showTitle = true;
if (args != null) {
if (args.showTitle != null) {
this.showTitle = args.showTitle;
}
}
this.onSaved = new Event(this);
}

ReimbForm.prototype.fillStores = function() {
var _this = this;
this.panel.setLoading("Loading Labcontacts from database");

var proposal = BUI.getProposal();
proposal.onDataRetrieved.attach(function(sender, data) {
_this.labContactForSendingStore.loadData(data, false);
_this.labContactForReturnStore.loadData(data, false);
_this.panel.setLoading(false);
});
proposal.getLabContactsByProposalId();

};

ReimbForm.prototype.refresh = function(dewar) {
this.setDewar(dewar);
};

ReimbForm.prototype.getDewar = function() {
this.dewar.isReimbursed = Ext.getCmp(this.id + "dewar_isReimbursed").getValue();
return this.dewar;
};

ReimbForm.prototype.setDewar = function(dewar) {
this.dewar = dewar;

if (this.dewar == null){
this.dewar={};
this.dewar["isReimbursed"] = "";
}

Ext.getCmp(this.id + "dewar_isReimbursed").setValue(this.dewar.isReimbursed);
};

ReimbForm.prototype.getCurrentReimbursedDewars = function(dewars) {
return _.filter(dewars, function(o){ return o.isReimbursed == true}).length;
};

ReimbForm.prototype.hideReimbursedButton = function(shipment, dewar){
this.maxReimb = 0;
debugger;
if (shipment) {
if (shipment.sessions.length > 0){
this.maxReimb = shipment.sessions[0].nbReimbDewars;
}
}
if (dewar.isReimbursed)
return false;
if (this.getCurrentReimbursedDewars(shipment.dewarVOs) < this.maxReimb){
return false;
}
return true;
}

ReimbForm.prototype.getBoxLabelText = function(shipment, dewar){

boxLabel = 'By setting this parcel to reimbursed, the labels printed for the sending<br>will contain the fedex account that you should use to send your dewars. <br>Please note that you MUST NOT use this account to ship more<br>than the allowed number of dewars. <br>In case of abuse, your proposal will no more benefit<br>from parcel reimbursement.';
if (this.hideReimbursedButton(shipment, dewar) == true){
boxLabel = "<span style='color:orange'>You are not authorized to select another parcel to be reimbursed</span>";
}
return boxLabel;
}

ReimbForm.prototype.getPanel = function(dewar, shipment) {
this.panel = Ext.create('Ext.form.Panel', {
width : this.width - 10,
title : this.getBoxLabelText(shipment, dewar),
// cls : 'border-grid',
// margin : 10,
padding : 10,
height : 320,
items : [ {
xtype : 'container',
margin : "2 2 2 2",
collapsible : false,
defaultType : 'textfield',
layout : 'anchor',
items : [
{
xtype: 'checkbox',
fieldLabel : ' ',
boxLabel : 'Click if you agree with these conditions and you want to have this parcel automatically reimbursed.',
hideLabel:true,
labelWidth : 500,
name : 'isReimbursed',
id : this.id + 'dewar_isReimbursed',
trueText: 'true',
falseText: 'false' ,
hidden : this.hideReimbursedButton(shipment, dewar) //false //'{4 < 3}'
},

]}]
});

this.refresh(dewar);
return this.panel;
};
3 changes: 2 additions & 1 deletion js/core/view/shipping/shipmentform.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ ShipmentForm.prototype.load = function(shipment,hasExportedData) {
if (shipment){
if (shipment.sessions.length > 0){
beamlineName = shipment.sessions[0].beamlineName;
nbReimbDewars = shipment.sessions[0].nbReimbDewars;
startDate = moment(shipment.sessions[0].startDate).format("DD/MM/YYYY");
}
}

dust.render("shipping.form.template", {id : this.id, to : toData, from : fromData, beamlineName : beamlineName, startDate : startDate, shipment : shipment}, function(err, out){
dust.render("shipping.form.template", {id : this.id, to : toData, from : fromData, beamlineName : beamlineName, startDate : startDate, shipment : shipment, nbReimbDewars : nbReimbDewars}, function(err, out){
html = out;
});

Expand Down
Loading

0 comments on commit 0e49f2e

Please sign in to comment.