samedi 5 mars 2016

Add payload in Ember deleteRecord

I have a requirement to include remarks from user in the payload whenever he tries to delete an item. So far, I have this:

let remarks = this.get('remarks');
let id = this.get('itemID');

this.store.findRecord('item', id).then(function (selectedItem) {

    // TODO - DELETE doesn't accept payload in body?

    selectedItem.destroyRecord({remarks:remarks}).then(function(response){

        Ember.debug('delete successful:'+JSON.stringify(response));

        Ember.$('#confirmDelete').modal('hide');
        Ember.$('#remarks').val('');

        context.set('successful', true);
        context.set('message', context.get('i18n').t('success.role.delete'));                        

    }).catch(function(error){
        Ember.debug('delete failed:'+JSON.stringify(error));

        Ember.$('#confirmDelete').modal('hide');
        Ember.$('#remarks').val('');

        context.send('showErrors', error);
    });
});                 

It doesn't work. So does setting the remarks value in the model like:

...
this.store.findRecord('item', id).then(function (selectedItem) {

    selectedItem.set('remarks', remarks);

    selectedItem.destroyRecord().then(function(response){
...

I am eyeing to override the deleteRecord but I don't know where to start or how to do it.

Anyone have ideas? Thanks!




Aucun commentaire:

Enregistrer un commentaire