Hi devs,
I have an entity 'Service' which represents a technician doing a service on a camera. During a service it's possible for the tech to replace components such as a lens on the camera. I've set it up so that they can do this from a custom action on the Service as described here: https://docs.espocrm.com/development/custom-buttons/ eg:

(to be clear, they would be replacing a component on the Camera SN123 - you can't see those components on this screen)
When the custom button is clicked, it opens the lens list in a modal:

When a lens is clicked in the model, the code does an ajax call and replaces the existing lens on the camera with the selected one.
This all works fine, but I want to make the user add a reason for replacing the lens. I can successfully open a second modal from the first one, but the first modal closes behind it:

I want to keep it open so that I can give the user the opportunity to cancel instead of entering a reason and be returned to the lens list to make another selection if they want.
I've tried a lot of different ideas such as trying to remove the listener that is closing the first modal (I don't think it's the right approach) and extending the the record-select.js view to customise the lens list from there but I can't make those work. Here is my code:
I can see that once the lens list modal is open, if I add a search filter to the list and open the select, a second modal is opening up and leaving the first intact (eg, clicking the select in the below image), exactly how I want to do it, but I can't figure out how it is doing that:

Can anyone please give me some tips on how to proceed?
Cheers,
Clare
I have an entity 'Service' which represents a technician doing a service on a camera. During a service it's possible for the tech to replace components such as a lens on the camera. I've set it up so that they can do this from a custom action on the Service as described here: https://docs.espocrm.com/development/custom-buttons/ eg:
(to be clear, they would be replacing a component on the Camera SN123 - you can't see those components on this screen)
When the custom button is clicked, it opens the lens list in a modal:
When a lens is clicked in the model, the code does an ajax call and replaces the existing lens on the camera with the selected one.
This all works fine, but I want to make the user add a reason for replacing the lens. I can successfully open a second modal from the first one, but the first modal closes behind it:
I want to keep it open so that I can give the user the opportunity to cancel instead of entering a reason and be returned to the lens list to make another selection if they want.
I've tried a lot of different ideas such as trying to remove the listener that is closing the first modal (I don't think it's the right approach) and extending the the record-select.js view to customise the lens list from there but I can't make those work. Here is my code:
Code:
define('custom:my-action-handler', ['action-handler', 'views/modal', 'model'], function (Dep, Modal, Model) {
return Dep.extend({
actionTest: function (data, e) {
console.log('model = ', this.view.model);
camName = this.view.model.get('cameraName');
Espo.Ui.notify(' ... ');
var viewName = this.getMetadata().get('clientDefs.Lens.modalViews.select') || 'views/modals/select-records';
this.view.createView('dialog', viewName, {
// this.view.createView('dialog', 'custom:extend-select', {
scope: 'Lens', //scope: 'Team',
headerText: `Replace lens on ${camName}`,
createButton: true, //false,
multiple: false,
selectable: false,
skipBuildRows: false,
}, (view) => {
view.render();
Espo.Ui.notify(false);
console.log('my view ', view);
this.view.listenToOnce(view, 'select', models => {
console.log('listen view - select ', view);
this.secondModal();
});
});
},
secondModal: function () {
this.view.createView('dialog', 'views/modal', {
isBeingRendered: true,
templateContent: '<p>Please enter a reason for changing the lens:</p><input id="change-lens-reason"></input>',
headerText: 'Hello world',
backdrop: true,
message: 'Some *message*\n\nHello world!',
buttonList: [
{
name: 'addReason',
label: this.view.translate('Please add reason'),
onClick: () => {
// call addLinkLens
this.close();
},
style: 'primary',
},
{
name: 'close',
label: this.view.translate('Close'),
}
],
}, view => {
view.render();
});
},
addLinkLens: function (id, name) {
console.log('addLinkLens - model id = ', id, ' name = ', name);
console.log('searchData 2 ', this.view.searchData);
// ajax call here to replace lens and create a history record with old lens
},
initTest: function () {
this.controlActionVisibility();
this.view.listenTo(
this.view.model,
'change:status',
this.controlActionVisibility.bind(this)
);
},
controlActionVisibility: function () {
console.log('in controlActionVisibility ', this.view.model);
},
});
});
Can anyone please give me some tips on how to proceed?
Cheers,
Clare

Comment