Drupal6 VBO – 'Open Edit Links' link added to header

Update 4-13-11: Developments » Drupal6 VBO – ‘Open Links’ header link option updated.

I took the bookmarklet that opens all the ‘Edit’ links on the Views Bulk Operations content management page and updated it to work in the header of the view.

Here are some screenshots of what it looks like and the code I placed in the header of the view.

Here you see the link in the header of the view at the top of the Content VBO page

When you hover over the link you get an explanation:

Screen shot of Open Edit Links button

Click to open ALL edit links or highlight a group of edit links to limit the number of links that open.

Just clicking the link defaults to all the edit links in the available results. You see in the confirmation pop up that there were 24 results in the report.

If you select some text in the report then the 'Edit' links with in that selection will be the only ones acted upon

Again you get a confirmation pop up asking if you want to open the 3 selected edit links


If we take a look at the view. The content I added was all in the header:

I set the input type to php

Here i entered my php and javascript that uses drupal_add_js to append the javascript to the doc head


Here’s the code I pasted in:

<?php
/* ########## Add JS ############ */
$openEditLinkScript = <<<javascript
/* ########## Add open edit link JS ########## */
function openEditLinks(){
	var n_to_open,dl,dll,i;
	 function linkIsSafe(u) {
		 if (u.substr(0,7)=='mailto:') return false;
		 if (u.substr(0,11)=='javascript:') return false;
		 return true;
	}
	 n_to_open = 0;
	 dl = $('#views-bulk-operations-form--1 .views-field-edit-node a');
	 dll = dl.length;
	 if (window.getSelection && window.getSelection().containsNode) {
		 /* mozilla */
	for(i=0; i<dll; ++i) {
			 if (window.getSelection().containsNode(dl[i], true) && linkIsSafe(dl[i].href)) ++n_to_open;
		}
		 if (n_to_open && confirm('Open ' + n_to_open + ' selected Edit links in new windows?')) {
			 for(i=0; i<dll; ++i) if (window.getSelection().containsNode(dl[i], true) && linkIsSafe(dl[i].href)) window.open(dl[i].href);
		}
	}
	 /* /mozilla */
	if (!n_to_open) {
		 /*ie, or mozilla with no links selected: this section matches open_all_links, except for the alert text */
	for(i = 0; i < dll; ++i) {
			 if (linkIsSafe(dl[i].href)) ++n_to_open;
		}
		 if (!n_to_open) alert ('no links');
		 else {
			 if (confirm('No links selected.  Open ' + n_to_open + ' Edit links in new windows?')) for (i = 0; i 
<a href="#" title="Click to open ALL edit links or highlight a group of edit links to limit the number of links that open.">Open Edit Links</a>

I started out with a HEREDOC:

$openEditLinkScript = <<<JAVASCRIPT
...
JAVASCRIPT;

And I inserted that js content into the head with

drupal_add_js($openEditLinkScript, 'inline');
Comments
  • Vid says:

    I decided I’d like to use this in other views reports and so I changed the jquery line to: dl = $(‘.views-field-edit-node a’);

Leave a Comment