Announcement

Collapse
No announcement yet.

How to save parentView().model (parentModel)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to save parentView().model (parentModel)

    Hey guys,

    I have a custom rowActions for a relationship which calculate some fields but also set a value on parentView().model i could set the values on parentModel (parentView().mode) but i couldn't save the data on parentView().model: how can i save the parentView().model data from a child relationship custom rowActions below my code:

    Code:
    actionSetHoldingPaid: function (data) {
    var id = data.id;
    if (!id) {
     return;
    }
    var model = this.collection.get(id);
    var parentModel = this.getParentView().model;
    if (!model) {
     return;
    }
    
    model.set({
      holdingStatus: 'Paid',
      totalStatus: 'Partially Paid',
    });
    
    // Set netSuccessFee on parentView model works fine
    parentModel.set('netSuccessFee',
       parentModel.get('netSuccessFee') - model.get('holdingFee')
    );
    
    this.listenToOnce(model, 'sync', function () {
       this.notify(false);
       this.collection.fetch();
    }, this);
    
    this.notify('Saving...');
    // Save parentModel data is not working
    parentModel.save();​
    model.save();
    },​
    Thanks

    telecastg item emillod
    Last edited by rabii; 12-14-2022, 01:36 PM.

  • #2
    Hi rabii,
    i let telecastg or emillod because it's not my skill.

    maybe something so ?

    parentModel.save({status: 'Held'});

    Comment


    • rabii
      rabii commented
      Editing a comment
      thanks item i have tried parentModel.save({status: 'Held'}); but not worked.

  • #3
    I think this do the job. (maybe)
    as you can see, it's provided by telecastg

    Payroll one2many PayrollItem
    when create PayrollItem from bottom panel, some data are retreived from Payroll.
    So i think you just need to do somethink like : payrollObject->save();

    PHP Code:
    define('custom:payrollItem-dynamic-handler', ['dynamic-handler'], function (Dep) {

        return 
    Dep.extend({

            
    init: function () {
                /
                
    this.controlFields();
            },

            
    controlFields: function () {

                
    //console.log(this);
                
    if(this.recordView.isNew) {

                    var 
    payrollId this.model.attributes.payrollId;
                    
    //console.log(payrollId)
                    
    var self this;

                    
    this.recordView.getCollectionFactory().create('Payroll', function (payrollCollection){
                        
    payrollCollection.where = [
                            { 
    type:'equals'field:'id'valuepayrollId }
                        ];
                        
    // retrieve the data from the database
                        
    payrollCollection.fetch().then(function(){

                            var  
    payrollObject payrollCollection.get(payrollId);

                            
    self.model.set('laborDate',payrollObject.attributes.laborDate);
                            
    self.model.set('executionDate',payrollObject.attributes.executionDate);
                            
    self.model.set('practrice',payrollObject.attributes.practrice);
                            
    self.model.set('isManager',payrollObject.attributes.isManager);
                            
    self.model.set('name',payrollObject.attributes.name);
                            
    self.model.set('nationalNumber',payrollObject.attributes.nationalNumber);
                            
    self.model.set('periodeName',payrollObject.attributes.periodeName);
                            
    self.model.set('periodeId',payrollObject.attributes.periodeId);


                        });
                    });
                }
            }
        });
    });
    ​ 
    Last edited by item; 12-15-2022, 07:56 PM.

    Comment


    • rabii
      rabii commented
      Editing a comment
      Thanks @item
      i have tried parentModel->save(); didn't work. still trying to figure out how it could be done.

  • #4
    I have ask to IA chatGPT .. here is response


    Comment


    • rabii
      rabii commented
      Editing a comment
      Thanks i already get the parent model using the code below, i figure out why it was not working though i had the field to be calculated as a read only and that is why the front-end couldn't save the model, i have changed the field to not be ready only and everything works fine. i am still confused why this happens.

      This code works fine now :
      Code:
      actionSetHoldingPaid: function (data) {
      var id = data.id;
      if (!id) {
       return;
      }
      var model = this.collection.get(id);
      var parentModel = this.getParentView().model;
      if (!model) {
       return;
      }
      
      model.set({
        holdingStatus: 'Paid',
        totalStatus: 'Partially Paid',
      });
      
      // Set netSuccessFee on parentView model works fine
      parentModel.set('netSuccessFee',
         parentModel.get('netSuccessFee') - model.get('holdingFee')
      );
      
      this.listenToOnce(model, 'sync', function () {
         this.notify(false);
         this.collection.fetch();
      }, this);
      
      this.notify('Saving...');
      // Save parentModel data is not working
      parentModel.save();​
      model.save();
      },​
      Thanks for your help.
Working...
X