0

So, I am using Sailsjs - and I am using a modal form to confirm deletion of an item. What I want to do is to detect a double deletion (someone deleted an item - while it was in someone else's page - and the second person tries to delete it too). I managed to do that - my action is returning "notFound". The problem is - how can I make the Modal close when getting "notFound" back from the action instead of success?

Here is an excerpt of my action code:

  exits: {

    forbidden: {
      description: 'The user making this request is not the owner of this thing and therefore cannot delete it.',
      responseType: 'forbidden'
    },

    notFound: {
      description: 'The item was not found in the database. Maybe it has already been deleted?',
      responseType: 'notFound'
    }

  },


  fn: async function (inputs, exits) {

    var thing = await Thing.findOne({
      id: inputs.id
    });

    if (!thing) {
      throw 'notFound';
    }

    if (thing) {
      if (thing.owner !== this.req.me.id ) {
        throw 'forbidden';
      }
    }

    await Thing.destroy({ id: inputs.id });

    return exits.success();

  }

and here is an excerpt of my modal using ajax-form component:

  <% /* Confirm DeleteThing Modal */%>
  <modal v-if="confirmDeleteThingModalOpen" @close="closeDeleteThingModal()">
    <ajax-form action="destroyOneThing" :syncing.sync="syncing" :cloud-error.sync="cloudError" :handle-parsing.sync="handleParsingDeleteThingForm" @submitted="submittedDeleteThingForm()">
      <div class="modal-header">
        <h3 class="modal-title">Are you sure?</h3>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
AleAssis
  • 376
  • 3
  • 7

1 Answers1

0

You can use @rejected on your ajax-form. So somethinglike:

<ajax-form action="destroyOneThing" @rejected="rejectedDeleteOneThing" 

Then tell it what you want it to do on your page script

something like:

    rejectedDeleteOneThing: function() {
      this.confirmDeleteThingModalVisible = false;
    }
streleck
  • 459
  • 1
  • 3
  • 11
Raqem
  • 424
  • 2
  • 9