AHAH enable book module

quicksketch - October 5, 2007 - 17:13
Project:Drupal
Version:6.x-dev
Component:book.module
Category:task
Priority:normal
Assigned:Unassigned
Status:closed
Description

Book module has some obvious places where AHAH can now be added (similar to the blocks page).

- On the node edit form, the Book outline fieldset uses javascript from book.js. This should be able to be removed and use ahah.js instead.
- The book structuring form (admin/content/book/x) can be updated dynamically similar to the blocks page.

#1

dmitrig01 - October 10, 2007 - 01:03

I've already implemented the AHAH API in book module where javascript was already (the admin page isn't done).

AttachmentSize
book_ahahapi.patch 5.63 KB

#2

dmitrig01 - October 10, 2007 - 01:04
Category:feature request» task
Priority:normal» critical
Assigned to:Anonymous» dmitrig01
Status:active» needs review

#3

webchick - October 10, 2007 - 02:19
Priority:critical» normal

Sorry, but there is absolutely no way in the world this is critical. :)

#4

dmitrig01 - October 10, 2007 - 02:40

@webchick - we're duplicating code we don't need to, look how much code this patch removes! :)

but anyway, here's a stab at the admin page. It doesn't work yet

AttachmentSize
book_ahahapi_0.patch 9.41 KB

#5

quicksketch - October 10, 2007 - 02:54

dmitrig01 is rocking this patch so fast I don't dare try to re-roll. Here's a helpful bit of CSS that will eliminate the 'jump' you get when new content appears on the page. It occurs because the top and bottom margins need to be adjusted after they are fully placed on the page, but we can remove these margins and the effect is much smoother with very little visible difference:

.book-outline-form .form-item {
  margin-top: 0;
  margin-bottom: 0;
}

It's looking great! The code the for the node page works amazing... and we can really eliminate the 1 remaining line of code in book.js by a drupal_add_js() inline. One more .js file down! Woot!

#6

dmitrig01 - October 10, 2007 - 02:58

and the re-roll..

AttachmentSize
book_ahahapi_1.patch 9.41 KB

#7

quicksketch - October 10, 2007 - 03:00

Btw, this patch is another one that will not work quite right in Safari until the AHAH bug fixes go in from http://drupal.org/node/181741.

I also like it a lot more with the throbber version, which is another effect of that patch. Neato.

Some more code comments, this declaration can be shortened because of the defaults set for #ahah:

<?php
   
'#ahah' => array(
     
'path' => 'book/js',
     
'wrapper' => 'edit-book-plid-wrapper',
     
'method' => 'replace',
     
'effect' => 'slide',
     
'event' => 'change',
    )
?>

to just
<?php
   
'#ahah' => array(
     
'path' => 'book/js',
     
'wrapper' => 'edit-book-plid-wrapper',
     
'effect' => 'slide',
    )
?>

#8

dmitrig01 - October 10, 2007 - 03:05

re-rolled for quicksketch's suggestions

AttachmentSize
book_ahahapi_2.patch 9.35 KB

#9

Stefan Nagtegaal - October 10, 2007 - 06:49

Nice! Seems to work on Macintosh with FF > 2, Opera > 9, Safari > 2..
Let's get some guys to test this on Windows and set this RTBC..

Remember that this patch relies on http://drupal.org/node/181741, so first apply that patch to the trunk.

#10

quicksketch - October 10, 2007 - 07:09

Here's an update that gets us a little further along. It:
- Hides the button on the node edit form (seems that $(element).hide() didn't work in the header like that).
- Adds classes and asterisks to changed rows, similar to the blocks page.
- Updates the form cache and renders the updated version properly.

What needs to be done:
- The actual sorting of the weights via some PHP function. Due to the data structures for book module, this isn't a trivial task. All the current sorting is done via SQL query, we need to find a way to generate a new in-order list from the new POST values we're given.

AttachmentSize
book_ahahapi_3.patch 11.46 KB

#11

quicksketch - October 14, 2007 - 05:54

Here's a final patch that adds proper sorting of form elements. It bumps up the patch a bit in size, since book module doesn't actually have any code for sorting the book tree structure other than an ORDER BY clause in SQL. This adds the sort function and utilizes it on the AHAH callback after updating the tree with new weight values.

AttachmentSize
book_ahahapi_4.patch 12.38 KB

#12

catch - October 14, 2007 - 14:18
Status:needs review» needs work

I applied this on fresh dev tarball, tested on firefox and IE7 on XP.

In both browsers, when changing the weight of a node at admin/content/book/n, I get the spinner icon, but it just keeps spinning with no update.
Everything else I tried was very nice though!

#13

dmitrig01 - October 14, 2007 - 15:38
Status:needs work» reviewed & tested by the community

@catch - you need to rebuild the menu to get this to work

I've extensively tested this and it passed with flying colors!

#14

catch - October 14, 2007 - 16:21

dmitrig01 is right, oops. Works great, and the little asterixes are loveky.

RTBC!

#15

Gábor Hojtsy - October 15, 2007 - 19:33
Status:reviewed & tested by the community» fixed

Tried the patch, and everything seemed to be right. So looked over the code and all seemed fine, so committed. Thanks.

#16

Anonymous - October 29, 2007 - 19:41
Status:fixed» closed

#17

beginner - January 2, 2008 - 11:48
Category:task» bug report
Priority:normal» critical
Assigned to:dmitrig01» Anonymous
Status:closed» active

I just spent 12 hours trying to understand how book.js works. I just couldn't get it.
I was getting more and more convinced that there was a bug somewhere.
Then I found this issue. The patch that was applied calls for the suppression of book.js. However the patch was not fully applied and book.js is still part of core, and part of a normal D6 install.

To test, simply delete book.js, make sure you don't have cached .js, and the ahah call still works.

#18

Gábor Hojtsy - January 2, 2008 - 12:13
Category:bug report» task
Priority:critical» normal
Status:active» closed

Oh, this was overlooked for sure. Sorry for the confusion, and for your wasted hours. The patch does include a hunk to remove the book.js but I did not properly commit this. Now done. Setting back status to as it was before.

#19

beginner - January 2, 2008 - 12:21

Thanks.
Happy New Year, Gábor.

 
 

Drupal is a registered trademark of Dries Buytaert.