AnsweredAssumed Answered

Quick tip: request confirmation for subpanel inline edit based on parent value

Question asked by Francesca Shiekh on Nov 4, 2016

Thought I'd share this and maybe get some improvement tips.

 

We have a wContracts custom module with a supbanel for Products.

All actions on Products are restricted to the subpanel on wContracts (they can't access record view or list view for Products).

 

If a user does an inline-edit on a Product on a wContract that is already Approved we want to warn them before they are given the chance to proceed. Similarly on Delete.

 

This is the controller for the Edit.

custom/modules/wContractProducts/clients/base/views/subpanel-list/subpanel-list.js

({
  extendsFrom: 'SubpanelListView',
  initialize: function(options){
    this._super('initialize', [options]);
    this.context.on('list:editrow:fire', this.checkStatus, this);
  },
  checkStatus: function(){
    var self = this,
        parentContract = this.context.parent.get('model'); //get the parent model
    //check the parent status
    if(parentContract.get('contract_approval_status_c') == 'Approved'){
      app.alert.show('confirm_edit', {
        level: 'confirmation',
        messages: 'You are changing an Approved Contract, click to continue Edit.',
        autoClose: false,
        onConfirm: function(){
          //reset the approvals on the Contract and continue
          parentContract.set('manager_approval_c', 'NA',  {silent: true});
          parentContract.set('finance_approval_c', 'NA', {silent: true});
          parentContract.set('legal_approval_c', 'NA', {silent: true});
          parentContract.set('contract_approval_status_c', '', {silent: true});
          parentContract.save();
        },
        onCancel: function(){
          //exit edit more and confirm the cancel
          self.$('.inline-cancel').click(); //exit edit mode
          app.alert.show('canceled', {
            level: 'success',
            messages: 'Canceled',
            autoClose: true
          });
        }
      });
    }
  },

 

I would like the user to see the parentContract changes immediately refreshed but don't want to reload the whole view. Suggestions on how to achieve this would be very welcome.

 

hope this helps someone else achive their goals.
FrancescaS

Outcomes