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...
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | fbssc.modalframe.patch | 18.4 KB | dalad |
| #2 | fbssc.modalframe.patch | 17.93 KB | dalad |
| fbssc.popups.patch | 15.16 KB | dalad |
Comments
Comment #1
icecreamyou commentedThe 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.
Comment #2
dalad commentedI 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.
Comment #3
icecreamyou commentedThanks 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?
Comment #4
dalad commentedIt 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.
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.
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
Comment #5
icecreamyou commentedOn 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:
Drupal.modalFrame.openwhen an edit or delete link is clickedmodalframe_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 argumentsmodalframe_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. :)
Comment #6
dalad commentedThe 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...
Comment #7
icecreamyou commentedAll AHAH behaviors automatically get rebuilt. FBSS calls them all again on
contextwhich contains the new status list HTML. You should never be calling$(selector)but insteadcontext.find(selector), and put everything insideDrupal.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.
Comment #8
dalad commentedOk, 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.
Comment #9
icecreamyou commentedWell I'll have to look into it more obviously to see if I was right -- but your code should be helpful either way. :)
Comment #10
dalad commented:) that was my purpose. I'll still be available if we need to discuss about it.
Comment #11
icecreamyou commentedCommitted 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. :)
Comment #12
dalad commentedvery good job!
Comment #13
icecreamyou commentedEr, whoops. I wasn't paying attention and added Modal Frame integration for the main module, but not for the comments submodule. :-P
Comment #14
icecreamyou commentedAaaaaand there we go. Committed to dev.