AnsweredAssumed Answered

How to rerender dashlet after clicking save button

Question asked by tachi06092 on Mar 21, 2016

I have created a dashlet which can show related record in record view.

However, I do not know how to rerender my dashlet after user edit and save the record.

Anyone can give me the code which can listen "edit and save" event?

 

Follow is the controller js file.

({

  plugins: ['Dashlet'],

  modelRecord: undefined,

  initialize: function(options){

  this._super('initialize',[options]);

  this.modelRecord = {};

  },

  bindDataChange: function(){

  var ctx = this.context;

  console.log(this);

  var collection = ctx.get("collection");

  var children = this.context.children;

  if(_.isEmpty(collection)){

            return;

        }

  console.log(children);

  console.log(collection.models);

 

  collection.on('reset', function(collection) {

            // Ensure that collection exists, has models, then parse out models for display

            if(collection && collection.length) {

                this._parseModels(collection.models);

            }

        }, this);

 

 

  ctx.on('button:save_button:click', function(collection) {

            // Ensure that collection exists, has models, then parse out models for display

            if(collection && collection.length) {

                this._parseModels(collection.models);

            }

        }, this);

 

  collection.on('add remove', function(model, collection, options)  {

            this._parseModels([model]);

        }, this);

 

  if(collection.models && _.isEmpty(this.modelsMap)) {

            // manually cause a parsing of the models

            // this covers the scenario when a user creates a new record

            this._parseModels(collection.models);

        }

  },

  _parseModels : function (models){

  var self = this;

  var model = models[0];

  self.modelRecord[0]={

  id : model.get('id'),

  type : model.get('type'),

  status : model.get('status'),

  account_name : model.get('account_name')

  };

  console.log(self.modelRecord);

 

  app.api.call('GET', app.api.buildURL('case/getAccount/'+ model.get('id')), null, { 

  success: function (data) {

  console.log(data);

  var obj = JSON.parse(data);

  console.log(obj);

  console.log(self.modelRecord[0]);

  self.modelRecord[0]['website'] = obj[0].website;

 

  if (!self.disposed) {

  self.render();

  }

   } 

  }); 

  if (!self.disposed) {

            self.render();

        }

  }

})

Outcomes