0

In my web app, I have a page where users can copy books from their library.

On the website, when a user clicks the copy button, the app executes this bit of Backbone.js code:

clonebook: function () {
    var self = this;
    this.book.clone().then((r) => {
        self.model.collection.add(r);
    });
},
    

In My SQL Server database, book looks like this:

bookId, bookTitle, authorId, libraryId, rowOrderNumber

The problem is, if the user tries to clone multiple books really fast by hitting the copy button, the rowOrderNumber can get out of whack.

Is there a way to tell the Backbone clone method to wait until the database or server has completed a clone process before going on to the next one?

Thanks!

SkyeBoniwell
  • 6,345
  • 12
  • 81
  • 185

2 Answers2

2

The most common UX pattern for this is to disable the button when the process starts, and enable when finished.

clonebook: function () {
    var self = this;
    // disable clone button
    this.book.clone().then((r) => {
        self.model.collection.add(r);
        // enable clone button
    });
},
Slava Knyazev
  • 5,377
  • 1
  • 22
  • 43
1

I didn't use backbone, but

clonebook: function () {
    var self = this;
    self.loading = true
    this.book.clone().then((r) => {
        self.model.collection.add(r).then(() => {
          self.loading = false
        });
    });
},

Not you have to use this loading somehow to disable the button

Konrad
  • 21,590
  • 4
  • 28
  • 64