Need to modify the add and edit links
- Single Page
Posted 22 July 2012 - 12:39 PM
I have created my custom add and edit methods. I want to retain the view and delete of groceryCrud.
Please tell me how can I redirect the add and edit links to my the controller method which I created.
Thanks.
Posted 24 July 2012 - 03:44 AM
i don't know is posible...
Posted 24 July 2012 - 17:30 PM
so i use jquery in the grocery view to change the href of the add link, i use this code:
<?php
if (isset($nuevaRuta)) {
?>
<script type="text/javascript">
$(document).ready(function(){
$("a").each(function(i){
var titulo = $(this).attr("title");
if(titulo=='Agregar Ruta diaria'){ //this title is the title of i want to change the default GC option
$(this).attr('href', '<?php echo base_url().$nuevaRuta ?>');
}
});
});
</script>
<?php } ?>
so in the controler after the render i create a new atribute in the $output
$output=$crud->render();
$output->nuevaRuta='rutasMensajero/formularioCreacionRuta';
$this->_example_output($output);
the atribute nuevaRuta is the controller/function that i want to do.
so in the view if this atribute isset, the javascript code run.
this solution work for me, the other forms that i need to use grocery crud work ok, becouse i use the title of the form that i need to modify.
so, i don't know if this is a good solution, but work for me.
Posted 25 July 2012 - 16:48 PM
var titulo = $(this).attr("title");
So,how do you set the TITLE name in the <a></a> tag ?
[quote name='carlinchisart' timestamp='1343151020' post='2833']
hi @r00tkiit i'm work in this topic, i found a solution!!!
so i use jquery in the grocery view to change the href of the add link, i use this code:
<?php
if (isset($nuevaRuta)) {
?>
<script type="text/javascript">
$(document).ready(function(){
$("a").each(function(i){
var titulo = $(this).attr("title");
if(titulo=='Agregar Ruta diaria'){ //this title is the title of i want to change the default GC option
$(this).attr('href', '<?php echo base_url().$nuevaRuta ?>');
}
});
});
</script>
<?php } ?>
so in the controler after the render i create a new atribute in the $output
$output=$crud->render();
$output->nuevaRuta='rutasMensajero/formularioCreacionRuta';
$this->_example_output($output);
the atribute nuevaRuta is the controller/function that i want to do.
so in the view if this atribute isset, the javascript code run.
this solution work for me, the other forms that i need to use grocery crud work ok, becouse i use the title of the form that i need to modify.
so, i don't know if this is a good solution, but work for me.
[/quote]
Posted 26 July 2012 - 03:53 AM
i use the title for know what subject i want to change the default option, i set the href option of <a> tag.
Posted 26 July 2012 - 15:58 PM
[quote name='carlinchisart' timestamp='1343274784' post='2848']
hi, i'm not set the title option in <a> tag.
i use the title for know what subject i want to change the default option, i set the href option of <a> tag.
[/quote]
Posted 26 July 2012 - 16:14 PM
(this).attr('href', '<?php echo base_url().$nuevaRuta ?>');
the metoth attr() of jquery. The first parameter is the atribute that i want modify and second parameter is the value that i want to put in the atribute.
so i open php and put the rute of controller/function that i need.
i define this in $nuevaRuta in my controller.
Posted 28 July 2012 - 08:33 AM
Can you please share the entire code with me.
Thanks .
[quote name='carlinchisart' timestamp='1343319281' post='2855']
with this option.
(this).attr('href', '<?php echo base_url().$nuevaRuta ?>');
the metoth attr() of jquery. The first parameter is the atribute that i want modify and second parameter is the value that i want to put in the atribute.
so i open php and put the rute of controller/function that i need.
i define this in $nuevaRuta in my controller.
[/quote]
Posted 28 July 2012 - 13:25 PM
this is the controller function, only the function that i change the default add option.
function rutaMensajero() {
$crud = new grocery_CRUD();
$crud->set_table('rutaMensajero');
$crud->set_subject('Ruta diaria');
$crud->unset_edit();
$crud->unset_delete();
$crud->add_action('Generar PDF de ruta', base_url().'/images/pdf.png','','ui-icon-image', array($this,'generarPdfRuta'));
$crud->add_action('Marcar rutas realizadas', base_url().'/images/rutaRealizada.png','','ui-icon-image', array($this,'redirecMarcarRuta'));
$output = $crud->render();
$output->nuevaRuta = 'rutasMensajero/formularioCreacionRuta';
$this->_example_output($output);
}
the function _example_output is the function that load the view, is the same of example of GC
and this is the view
<html>
<head>
<meta charset="utf-8" />
<?php foreach ($css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach ($js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach;
if (isset($nuevaRuta)) {
?>
<script type="text/javascript">
$(document).ready(function(){
$("a").each(function(i){
var titulo = $(this).attr("title");
if(titulo=='Agregar Ruta diaria'){
$(this).attr('href', '<?php echo base_url().$nuevaRuta ?>');
}
});
});
</script>
<?php } ?>
<style type='text/css'>
body
{
font-family: Arial;
font-size: 14px;
}
a {
color: blue;
text-decoration: none;
font-size: 14px;
}
a:hover
{
text-decoration: underline;
}
</style>
</head>
<body>
<div>
<?php echo $output; ?>
</div>
</body>
</html>
Posted 30 July 2012 - 16:45 PM
But still I have a problem with these statements:
[color=#ff0000][size=4][b]var titulo = $(this).attr("title");[/b][/size][/color]
[color=#FF0000][size=4][b]alert(titulo);
if(titulo=='Agregar Ruta diaria'){[/b][/size][/color]
[color=#FF0000][size=4][b]...[/b][/size][/color]
[size=4]I am getting "titulo" as undefined. [/size]I am not able to understand where are we setting the value of the title attribute.
[quote name='carlinchisart' timestamp='1343481923' post='2874']
ok, no problem
this is the controller function, only the function that i change the default add option.
function rutaMensajero() {
$crud = new grocery_CRUD();
$crud->set_table('rutaMensajero');
$crud->set_subject('Ruta diaria');
$crud->unset_edit();
$crud->unset_delete();
$crud->add_action('Generar PDF de ruta', base_url().'/images/pdf.png','','ui-icon-image', array($this,'generarPdfRuta'));
$crud->add_action('Marcar rutas realizadas', base_url().'/images/rutaRealizada.png','','ui-icon-image', array($this,'redirecMarcarRuta'));
$output = $crud->render();
$output->nuevaRuta = 'rutasMensajero/formularioCreacionRuta';
$this->_example_output($output);
}
the function _example_output is the function that load the view, is the same of example of GC
and this is the view
<html>
<head>
<meta charset="utf-8" />
<?php foreach ($css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach ($js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach;
if (isset($nuevaRuta)) {
?>
<script type="text/javascript">
$(document).ready(function(){
$("a").each(function(i){
[color=#ff0000] [size=4][b] var titulo = $(this).attr("title");
if(titulo=='Agregar Ruta diaria'){[/b][/size][/color]
$(this).attr('href', '<?php echo base_url().$nuevaRuta ?>');
}
});
});
</script>
<?php } ?>
<style type='text/css'>
body
{
font-family: Arial;
font-size: 14px;
}
a {
color: blue;
text-decoration: none;
font-size: 14px;
}
a:hover
{
text-decoration: underline;
}
</style>
</head>
<body>
<div>
<?php echo $output; ?>
</div>
</body>
</html>
[/quote]
Posted 30 July 2012 - 22:37 PM
the title of add option is defined in the controler with the opcion [color=#000000][size=2]$crud[/size][/color][color=#666600][size=2]->[/size][/color][color=#000000][size=2]set_subject('someting);[/size][/color]
so for this reason i check what title i want to change in the if
[color=#000088]if[/color][color=#666600]([/color][color=#000000]titulo[/color][color=#666600]==[/color][color=#008800]'someting'[/color][color=#666600])[/color]
Posted 31 July 2012 - 16:27 PM
Though this didnt work out for me but definitely helped me in arriving to a solution to my problem.
$("a").each(function(i){
var href = $(this).attr("href");
if(href=='http://localhost/something/crud/add'){
$(this).attr('href', '<?php echo base_url().$newLink; ?>');
}
});
Now, what the code does is checks the 'href' attribute of each anchor tag (<a>) . If this matches with the href of the 'add' option of my crud i.e. 'http://localhost/something/crud/add' , then I am setting its href attribute to the newLink I want.
Seems to be working fine for me now.
Finally.
[quote name='carlinchisart' timestamp='1343687876' post='2907']
yess the first time appears undefined, but in the next two or tree times the title appears,
the title of add option is defined in the controler with the opcion [color=#000000][size=2]$crud[/size][/color][color=#666600][size=2]->[/size][/color][color=#000000][size=2]set_subject('someting);[/size][/color]
so for this reason i check what title i want to change in the if
[color=#000088]if[/color][color=#666600]([/color][color=#000000]titulo[/color][color=#666600]==[/color][color=#008800]'someting'[/color][color=#666600])[/color]
[/quote]