summaryrefslogtreecommitdiff
path: root/modules/book/book.js
blob: ada21404dff9e29b6c8fe053b954637345f302d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// $Id$

Drupal.behaviors.bookSelect = function(context) {
   // This behavior attaches by ID, so is only valid once on a page.
  if ($('#edit-book-bid.book-select-processed').size()) {
    return;
  }
  // Hide the button in the node form, since it's not needed when JS is enabled.
  $('#edit-book-pick-book').css('display', 'none');

  // Binds a function to the keyup and change actions of the book select to
  // retrieve parent options. Mark as processed so this binding is only done once.
  $('#edit-book-bid')
    .keyup(Drupal.bookFillSelect)
    .change(Drupal.bookFillSelect)
    .addClass('book-select-processed');
};

// This function passes the form information and the book ID to a Drupal callback
// and retrieves a parent select with changed options to replace the one in the form.
Drupal.bookFillSelect = function() {
  // Create a progress bar and substitute it for the parent select.
  pb = new Drupal.progressBar('book_progress');
  pb.setProgress(-1, Drupal.t('Updating parents...'));
  $('#edit-book-plid-wrapper').html(pb.element);

  $.ajax({
    url: Drupal.settings.book.formCallback +'/'+ $('#'+ Drupal.settings.book.formId +' input[name=form_build_id]').val() +'/'+ $('#edit-book-bid').val(),
    dataType: 'json',
    success: function(data) {
      // Insert the new select, and remove the progress bar.
      $('#edit-book-plid-wrapper').after(data['book']).remove();
    }
  });
};