This patch can live in contrib, as flag-dialog module, but I think it's general enough to be considered as a patch for Flag.
Patch adds another "link type" if Dialog module exists, that allows flag/ unflag via a jquery UI dialog.

To test:
1) Enable Dialog module
2) Add a a new flag and set the link type to "Confirmation dialog"
3) Click on the flag link and see a dialog opens in Ajax. yay! :)

To test it without JS , check #858530: Fix non-ajax for dialog_get_form()

Comments

quicksketch’s picture

Yes, my preference would be to not have this included with Flag itself directly. However if any API changes are necessary to support this flag type then I'd be open to including them. Right now you can already create your own link types through hook_flag_link_types() and hook_flag_link(), there's no need to include this code directly in flag.module as far as I can tell.

amitaibu’s picture

StatusFileSize
new3.75 KB
new737 bytes

> Yes, my preference would be to not have this included with Flag itself directly

I can understand that, but you should admit it a very cool feature ;)

This patch is more of a"hardcoding" cleanup -- it allows modules to declare more stuff in hook_flag_link_types() and makes flag_flag_link() more generic, so for example flag_dialog module doesn't even need to implement it own hook_flag_link.

quicksketch’s picture

Nice! The only thing I see in here is that you're only adding in $attributes if a class is set:

+  // Add class attributes, if they exist in the link type.
+  if (!empty($link['attributes']['class'])) {
+    $attributes = array('class' => $link_types[$flag->link_type]['attributes']['class']);
+  }

Why wouldn't you just check for $link['attributes'] instead? Other properties (like "rel") might still be used here for various purposes. Also, it looks like $attributes is going to be undefined unless a class is specified, causing a PHP notice when $attributes is used later.

amitaibu’s picture

StatusFileSize
new3.56 KB

Re-rolled with comments from #3

amitaibu’s picture

StatusFileSize
new749 bytes
new6.66 KB

More work, to allow link type to add own JS. I didn't really need it but also made CSS possible to load by implementing modules.

btw, why is drupal_add_js and drupal_add_css in the tpl file?

amitaibu’s picture

StatusFileSize
new23.21 KB

And here's a screenshot to see how it looks like.

amitaibu’s picture

Title: Add integration with Dialog API module » Allow integration with Dialog API module

Better title.

mooffie’s picture

(For #871064: Making flaggings fieldable we will obviously want the option to show the flagging form in a dialog (this functionality could be in a separate module).)

drewish’s picture

Seems like the patch on #5 needs some work. The things that jumped out at me:
- tabs rather than spaces used for indenting
- 'js callback' => FALSE, is duplicated

amitaibu’s picture

StatusFileSize
new6.8 KB

Yikes, tabs. Something probably went wrong with my Eclipse conf.

Re-rolled, and replaced the 2nd 'js callbak' with 'css callback'

amitaibu’s picture

StatusFileSize
new6.77 KB

*sigh*

amitaibu’s picture

bump :)

mooffie’s picture

Amitai, let's wait till #871064: Making flaggings fieldable advances a bit because I'm dealing there with a similar issue.

mooffie’s picture

While cleaning the issue queue (well, trying to) I stumbled upon #587040: New Flag type, CTools Confirm. Amitai, should we mark that other issue a duplicate of this one?

amitaibu’s picture

Title: Allow integration with Dialog API module » Improve API to allow implementing modules easier access to flag

Changing the title to better explain the motivation of the issue, as it is not Dialog specific == bump, only with more words ;)

mooffie’s picture

(I downloaded the patches and will look at them later today.)

mooffie’s picture

Amitai, here's some feedback:

There are two parts to your patch. One I consider bad, the other good.

Part 1: Making it possible to include 'href', 'attributes' and 'token' in a link-type definition.

I don't see the merit in this.

You say that now programmers won't "even need to implement [their] own hook_flag_link".

But how is the proposed feature much better?

Look for example at 'href' (which should more accurately be named 'base href'): it only works if it's at the beginning of the URL. So, for example, I won't be able to use this feature for #871064: Making flaggings fieldable because there I tuck the '/nojs' at the end of the URL, not at the beginning.

Indeed, when you arrive at the CSS/JS handling you notice this disadvantage of static properties and you resort to callbacks. But here I think you prove my point: Why not simply put the logic (the code) in hook_flag_link() ?

Part 2: Making the CSS/JS inclusion better.

That's good.

btw, why is drupal_add_js and drupal_add_css in the tpl file?

I think that's an inheritance from the D5 days where you couldn't override either the CSS or the JS so to make life easier for themers it was put in the tpl. But I believe we should remove it from there. Moreover, I see that 'dman' warns in api.drupal.org/drupal_add_css that calling drupal_add_css() from a tpl is "incompatible with css caching".

We could add two flags to the link-type definition: 'use standard css' and 'use standard js'. These will tell us whether to load the standard flag.css and flag.js for this link.

But instead of putting 'css' and 'js' slots in the link-type definition, why not return an #attached from hook_flag_link()? For D6 we can write a very minimal support for this structure (like the Vertical Tabs module does). On the other hand, one can ask a good question: Why bother? After all, modules can add their CSS/JS in hook_flag_link() or in a theme preprocess. (One answer to that could be: Our template_preprocess_flag() also includes a mechanism (the $first_time variable) that prevents inclusion multiple times so this is more efficient. On the other hand, modules could mimic this mechanism...)

==========

(Of course, the integration with the Dialog API module (or similar) is a an excellent idea. It's a must in 2010! Unfortunately, our "confirmation form", even when ajaxified, is not very satisfying.)

amitaibu’s picture

Status: Needs review » Needs work

mooffie,

As always I enjoy your reviews!

hook_flag_link() sounds as a good option, that I didn't think of. I should revisit the code.

> why not return an #attached from hook_flag_link()
...
> Why bother?

I think this is more of a concept (which I learned much from working on CTools' export-ui) -- Have a plugin/ hook declaration and let the module do the heavy lifting. What I mean is, that currently flag_dialog module is just 2 hooks implementation, and flag (with this patch) does all the heavy lifting. It's flexible (using the callbacks), yet it has sensible defaults.

Maybe we should do it on D7 first and back port it D6?

mooffie’s picture

Maybe we should do it on D7 first and back port it D6?

I think first we need to do some cleanup on our existing code. The way our own CSS/JS is loaded isn't very nice. I opened a new issue:

#956800: Cleanup the CSS / JS inclusion

That #956800 issue is not supposed to address the issues you mention here (we'll revisit them afterwards), that's why I opened a new issue.

mooffie’s picture

Marked #956800: Cleanup the CSS / JS inclusion a duplicate of this issue.

mooffie’s picture

Amitai, perhaps there's some misunderstanding. I thought, and still think, that #956800: Cleanup the CSS / JS inclusion was a very good idea. The purpose of #956800 was cleanup only, not to introduce any new feature(s). If you support #956800 as-is, let me know.

amitaibu’s picture

> The purpose of #956800 was cleanup only

Tackling this issue in smaller steps is fine by me, as there's some hardcoding going on in flag, and maybe one patch to deal with it all is too much.

mooffie’s picture

[Comment deleted: I accidentally typed my comment here instead of the other issue. IGNORE THIS EMPTY COMMENT.]

joachim’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

#871064: Making flaggings fieldable is now in.

Are any of the people working on this feature still interested? Is it still relevant on 3.x?

ivnish’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Drupal 7 is EOL. No more new features will be added. Issue will be closed, but patches are still here