Mark item as read views column/button

Events happening in the community are now at Drupal community events on www.drupal.org.
raintonr's picture

Hi,

I'd like to create a view to replace the default 'tracker'.

This replacement ideally would show only unread posts for the logged in user (it would be unavailable to anonymous), previews of the posts and also a 'mark read' column with a large red 'X' or similar. When the 'mark read' 'X' is pressed, that row should be removed with AJAX, and the server should be contacted to mark that content as being seen by this user.

Now, I know how to do the first two parts of this (show only unread and show previews) but the last part ('mark read') is the sticking point.

Does anyone know how this can best be achieved?

Is there a module that would help here?

Would one have to create a custom module which can be used with any view showing nodes and perform the required functions?

I don't mind having a crack at this task if a new module would be needed, but wanted to ask first, and for advice as to how to best go about this.

Thanks in advance :)

Comments

If it's any help,

merlinofchaos's picture

If it's any help, node_tag_new($node->nid) will mark the node read.

Using the CTools AJAX library, the code would look something like (this is non-functional but fairly close):

<?php
function mark_read_page($js, $nid) {
 
node_tag_new($nid)
  if (
$js) {
   
$commands = array();
   
$commands = ctools_ajax_command_remove('.row-class-for-nid-' . $nid);
   
ctools_ajax_render($commands);
  }
  else {
   
drupal_goto('path/of/the/page');
}
?>

Then you'd just need to make sure the view has the right class on the <tr> tag so it can be removed and add the class 'ctools-use-ajax' to the link which leads to the code above. (You'll need associated hook_menu).

Getting the class onto the row in the view is possibly the hardest part. =)

Views side?

raintonr's picture

@merlinofchaos... ah, that's cool. I have written a couple of Drupal AJAX thingos but the library could be useful.

Dunno about the class part being hardest part either. Although it is non-trivial, I have managed to theme view output in the past with some success.

No... the part I was more worried about was the bit where one has to create something to interface with views API so one could add a column which would have the appropriate parts within.

Actually - it's funny how other people can jog your thoughts like this. As I know how to theme views output to add a column, guess I do know how to do it: simply add a column with am image (as button) and a bit of JS to attach to that which fires AJAX/removes row. I wonder even, if one could to this all in JS. I mean... add a column, etc. on the fly.

Do you think to combine theme with Javascript or try and do the whole job in Javascript is the best approach? The latter might be more elegant from an re-use point of view but getting the node ID would be hard.

OG allows something similar.

ajayg's picture

OG allows something similar. There is a view "My unread" which shows as another tab under tracker. And as you read nodes, the list shown under my unread becomes smaller.
Perhaps you can extend that to include all nodes and not just OG managed nodes.

.

michelle's picture

I have on my to do list for Advanced Forum making a more advanced Mark as Read submodule. It's pretty far down on my to do list but I'd be interested in whatever you come up with here.

Michelle

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: