add_action target _blank
- Single Page
Posted 18 March 2012 - 17:32 PM
Ty
Posted 18 March 2012 - 18:29 PM
Example:
$('#your_element_id').attr("target", "_blank");
EDIT: Just tested one of mine with the following:
$('a[title="Properties"]').attr("target", "_blank");
Works perfect - maybe they guys can add an additional option called "target" - something like the below. But until then jQuery can do sooooo much!!!!!
void add_action( string $label, string $image_url , string $link_url , string $css_class , mixed $url_callback, string $target)
Posted 18 March 2012 - 20:43 PM
$(this).ajaxSubmit({
url: ajax_list_info_url,
dataType: 'json',
success: function(data){
$('#total_items').html( data.total_results);
displaying_and_pages();
this_form.ajaxSubmit({
success: function(data){
$('a.target_blank_class').trigger('add_target_blank'); // THIS IS THE LINE THAT YOU WILL ADD
$('#ajax_list').html(data);
}
});
}
});
and of course the javascript:
$("body").delegate('a.target_blank_class', "add_target_blank", function(){
$(this).attr("target", "_blank");
});
Just don't forget to add the add_target_blank to the 4th argument of the add_action method. For example:
$crud->add_action('Smileys', '/images/Active2.png', 'just_a_test','your_css_class add_target_blank');
It will work fine because if the a.target_blank_class does not even exist, you will not have any problem as the jquery is clever enough to not throw an error.
I think it is a more complicated solution but if you follow it step by step you will be proud of yourself that you made it
Also the $target as 6th argument is a good idea but I don't want just to add arguments for every new feature that I have in mind. Perhaps I will add a new method named "callback_action" to have your own action button. It will work exactly like the callback_column with the only difference that it will appear at the buttons sections. So in your case it will be easy to create your own button with the target blank.
Posted 19 March 2012 - 15:37 PM
Thank you so much guys, i've learned something today.
Posted 09 July 2012 - 01:30 AM
Posted 09 July 2012 - 23:22 PM
The javascript file needs to be called from an html file (the view will generate that html), therefore you have to call if from the view (either grocerycrud view rendered by GC or even flexigrid list view/template)
Cheers
Posted 29 October 2013 - 18:54 PM
can use jQuery to do it if there is no way on GCRUD yet...
Example:
$('#your_element_id').attr("target", "_blank");EDIT: Just tested one of mine with the following:$('a[title="Properties"]').attr("target", "_blank");Works perfect - maybe they guys can add an additional option called "target" - something like the below. But until then jQuery can do sooooo much!!!!!void add_action( string $label, string $image_url , string $link_url , string $css_class , mixed $url_callback, string $target)
Where do you add this jQuery statement? On which page or which function or callback? Thanks.
Posted 04 November 2013 - 13:50 PM
Where do you add this jQuery statement? On which page or which function or callback? Thanks.
Anybody?
Posted 05 March 2014 - 12:46 PM
Here's a quick hack that will do the job without any mods to GC - just add a call to str_replace() before you pass the output to your print function in your controller, e.g.:
In my case the added action has the given class, but you could use the title instead - just load up the relevant page, do a "view source" and take a look at the final output, then work out where to splice in the 'target="_blank"'
Edit:
Darn it, only works once of course!
Posted 30 May 2014 - 10:30 AM
I just had to come back to this, as I really wanted actions to open in a new window - the code is printing out PDF documents - but I just couldn't get the jQuery trickery to work.
Turns out that if you don't mind changing 3 lines of GC core code, it's easy to add the 6th arg to add_action():
In file Grocery_CRUD.php around line 5020 change
Finally in file assets/grocery_crud/themes/flexigrid/views/list.php around line 54 change
And that's it, just add the 6th arg to add_action() in your controller code where the target needs to be other than "_self" - works for me directly (first page view) and via AJAX (after a search or stepping through pages)
Flexigrid only of course, but a simple change to list.php for other themes should be straightforward.
Posted 31 May 2014 - 03:31 AM
exactly.. thats the only place.. directly adding the change into the GC library and not using the jquery ... cuz after the 1st page load, when system reloads the stuff.. the jquery wont execute again. Unless you want it using just jquery then u need to apply this hack / patch to your library
/topic/2260-do-javascript-function-after-ajax-list-finished/
this is helpful for taking control of the additional actions that you might prefer performing. Else.. the above hack provided is best if u want to take in just simple _blank to the add button
Happy GCing:)
Posted 31 May 2014 - 16:48 PM
Here's a slightly more general-purpose version of the hack:
<a href="<?php echo $action_url; ?>" class="<?php echo $action->css_class; ?> crud-action" title="<?php echo $action->label; ?>"<?php echo $action->extra_args; ?>>
This will let you add any number of arbitrary arguments to the add_action href, so you call it in your controller with 6th arg such as ' target="_blank"' - you could even add things like JavaScript triggers for example.
Posted 31 May 2014 - 16:58 PM
While we're on the subject of hacking list.php :-)
If you remove all of the HTML white space inside the <div class='tools'> on lines 37 to 53 or so of list.php, then all of the add_action() hrefs will be output without that white space between them and will behave better if the user resizes the browser window, in that they will stay "lined up" for as long as possible.
Posted 24 July 2014 - 13:06 PM
And if you do decide to open actions in a new tab, try this bit of JavaScript in the head of the view template you are using:
This was posted as a way of refreshing a parent window when a popup window closes, but it works if a "_blank" href target is used as well.
So now I can add an action to flexigid, have it open in a new tab, and then when that tab is closed the original tab updates itself automatically - nice!
Posted 30 September 2014 - 02:08 AM
This is my solution for that (need no changes on core):
<script type="text/javscript"> function openBlank(url) { window.open(url); } </script> <?Php // ... $url_callback_print = function($primary_key, $row) { return "javascript:openBlank('" . base_url('documents/printDocument') . '/' . $primary_key . "')"; }; $crud->add_action('Print Document', base_url('images/print.png'), '', '', $url_callback_print); // ...
Posted 12 May 2015 - 05:49 AM