Hi. I was in need of having popups integration, so I developed it myself.
Actually it required some effort and a little rewrite to make it work preserving AHAH behaviors and commentbox layout.
I attach a patch with my implementation. It's working fine; I don't know if you want to commit this, however I submit it in the hope that it can serve as a basis, saving some of your development time...

Comments

icecreamyou’s picture

Status: Needs work » Closed (won't fix)

The Popups module is deprecated in favor of Modal Frame API. (I won't commit integration with a deprecated module.) A related issue for Modal Frame is #937598: Confirm Delete Using AJAX (via ModalFrame)

However, thanks for providing your patch. Hopefully it will be useful to some people. If you're interested in working on Modal Frame integration I would definitely be open to committing that.

dalad’s picture

Title: Popups integration » FBSSC integration with Modal frame
Status: Closed (won't fix) » Needs review
StatusFileSize
new17.93 KB

I have reviewed the popups patch and made a better, cleaner version of fbssc to integrate with modal frame.
To me, it seems to be working.
I had to override facebook_status ahah handler but, in my opinion, fbssc.ahah.js could be merged with facebook_status.ahah.js; I think that also if you plan to add modal frame integration for edit/delete status this replacement could be useful.
I hope this helps.

icecreamyou’s picture

Thanks for the patch, will review when I get a chance. In the mean time, can you provide a quick summary of exactly what this patch provides?

dalad’s picture

  • fbssc.ahah.js is the new AHAH handler: overrides fbss handler so that it can apply Drupal.settings before AHAH success event.
    It also define an ajaxComplete event so that if any AJAX request reload the entire page, the Drupal.settings for that page are extracted from the response. This is needed to attach AHAH behavior to comment submit buttons after facebook status update in user profile triggers an AJAX reload of the recent statuses view.
  • fbssc.css contain minor css fixes.
  • fbssc.js code is the fbssc javascript object:
    labelClickEvent() is needed to view/hide comment list;
    refreshCommentForm() fakes a comment submit to obtain the new form state. I thought that the only way to retrieve comments securely was by form post, so that the form token is checked. If you simply check permissions you don't have a way to distinguish which comment form it is (request can be faked); and looking at the code (fbssc_can_view(), fbssc_can_post()), you would wish to do so - maybe fbssc_save_js() should check fbssc_can_post(), this is missing! - . By the way I had to remove "required" field of the comment textarea to achieve this.
    Lastly, the file contains the modal frame client side integration, which is never activated if that module is not installed.
  • fbssc.module is the big part of the work:
    I fixed the comment box form wrapper and layout so that the comment add/edit/delete cycle was effectively a cycle; as before, it wasn't so you couldn't keep adding then deleting comment without screwing the HTML on the page.
    Then I introduced a cache on theme_fbssc_form_display() - which is called server side both by AHAH refresh and by theming calls - so that a form doesn't get generated multiple times before sending the response, otherwise form token would not be the same on client and on server.
    Also, after fbss update submit, there is an abnormal situation where the function is called for every status on the page to render its comments, but the $sid parameter always refers to the newly inserted status. I think this has to do with the "if not passed in, get the latest status" policy of fbss... anyhow it's good to exclude from render in this condition because immediately afterward submit, fbss triggers an AJAX call to update the recent statuses view.
    Lastly there is the server side integration with modal frame, which consist in altering the edit/delete confirmation forms to operate in the frame.

... and that's all!

EDIT: This patch is a fix for #931358: FsSC: Comments not visible for anonymous users

icecreamyou’s picture

On a much higher level, this patch is supposed to make it so the edit form and delete confirmation pop up in a modal dialog instead of going to a separate page, right?

If so, it seems like you've changed much more than necessary. Probably all that's needed is:

  • Call modalframe_parent_js() in fbssc_box()
  • Call Drupal.modalFrame.open when an edit or delete link is clicked
  • Call modalframe_child_js() in fbssc_edit() and fbssc_delete()
  • Call modalframe_close_dialog() in the submit handler for fbssc_edit() and fbssc_delete(), passing the ID, operation, and result (by which I mean the new comment text for an edit) as arguments
  • In the onSubmit callback used on the call to Drupal.modalFrame.open(), read the arguments passed from modalframe_close_dialog() and either hide() the relevant comment (for a delete operation) or replace the relevant comment text (for an edit operation)

That's probably only about 30 lines of code.

In other words, the patch needs to focus exclusively on the purpose of this issue. It should not address other problems. It should also apply the Occam's Razor principle (the simplest solution is usually the best one).

Also, for future reference, every function needs to be namespaced. Specifically, you introduce the function _append_submit() which could cause problems if other modules have the same function.

Thanks for getting this rolling. :)

dalad’s picture

StatusFileSize
new18.4 KB

The high level analysis is correct :)

The suggested workflow is correct, with the exception that content is replaced on edit and on delete, for simplicity; but of course, you could assign different ids to comments and know what you are hiding... EDIT: but actually you are true the ajax call is redundant.

And up to then there were 30 lines of code!

Then, the problem is: when you change status, the status list (with the respective comments) gets updated by AJAX. Now, it's needed to rebuild all AHAH behaviors, avoid form tokens desync and all the stuff that the patch take care of.

I attach a reviewed patch, that also fixes:
* namespace of _append_submit()
* an issue with comment folding on page statuses/[sid]
* some indentations

This was really the simplest solution I could find to make fbssc work with modal frame everywhere and in any case... but it might not be the best, or the only. Up to you deciding...

icecreamyou’s picture

Then, the problem is: when you change status, the status list (with the respective comments) gets updated by AJAX. Now, it's needed to rebuild all AHAH behaviors, avoid form tokens desync and all the stuff that the patch take care of.

All AHAH behaviors automatically get rebuilt. FBSS calls them all again on context which contains the new status list HTML. You should never be calling $(selector) but instead context.find(selector), and put everything inside Drupal.behaviors.fbssc().

I haven't done a thorough review, I've just glanced through the code, so I could be misguided. I just think there's a lot of redundancy in the patch with re-attaching AHAH behaviors when really core should take care of that for us. And you should definitely not need to fake a form submission because you already know what change is going to be made -- no need to completely regenerate the form.

Also I haven't really looked at what you're doing with labelClickEvent and the CSS changes but that seems unrelated to the purpose of this patch.

dalad’s picture

Ok, nevermind. I understand what you are saying, but it wasn't possible for me to make it work in that way.
I'll wait your next commit to see how differently you would make things. That might turn out to be a good learning occasion to me.

icecreamyou’s picture

Well I'll have to look into it more obviously to see if I was right -- but your code should be helpful either way. :)

dalad’s picture

:) that was my purpose. I'll still be available if we need to discuss about it.

icecreamyou’s picture

Status: Needs review » Fixed

Committed a fix to the fbss_comments submodule in FBSS 6.x-3.x-dev. There is still a bug in that submitting the edit-status form doesn't force the modal frame to close; however, this can be addressed in a new issue against FBSS now that the basics are in. (The delete process works well.)

Regarding the patch, it's basically as simple as I said it would be. There are two lines where I fixed the format of unrelated comments, and I moved the code that refreshes the page after a status is submitted to its own function, and I changed the name of a function and a variable -- but other than that Modal Frame and core essentially do everything for us. :)

dalad’s picture

very good job!

icecreamyou’s picture

Project: Facebook-style Statuses Comments » Facebook-style Statuses (Microblog)
Version: 6.x-1.x-dev » 6.x-3.x-dev
Component: Code » Submodules
Status: Fixed » Needs work

Er, whoops. I wasn't paying attention and added Modal Frame integration for the main module, but not for the comments submodule. :-P

icecreamyou’s picture

Status: Needs work » Fixed

Aaaaaand there we go. Committed to dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.