Jump to content


Need to modify the add and edit links

modify add edit

  • Please log in to reply
11 replies to this topic

#1 r00tkiit

r00tkiit

    Member

  • Members
  • PipPip
  • 14 posts

Posted 22 July 2012 - 12:39 PM

Hi all.

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.

#2 carlinchisart

carlinchisart

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 24 July 2012 - 03:44 AM

i have the same situation, so i don't know if is posible in other version, include a option like add_action but general, no fo the record only, i think this option display when the buton add is display.....

i don't know is posible... :)

#3 carlinchisart

carlinchisart

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 24 July 2012 - 05:30 PM

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.

#4 r00tkiit

r00tkiit

    Member

  • Members
  • PipPip
  • 14 posts

Posted 25 July 2012 - 04:48 PM


var titulo = $(this).attr("title");
So,how do you set the TITLE name in the <a></a> tag ?

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)) {
?>
                    &lt;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.



#5 carlinchisart

carlinchisart

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 26 July 2012 - 03:53 AM

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.

#6 r00tkiit

r00tkiit

    Member

  • Members
  • PipPip
  • 14 posts

Posted 26 July 2012 - 03:58 PM

Thats what I am asking you. How are you modifying the <href> thing. We have a common view file for all the controllers.


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.



#7 carlinchisart

carlinchisart

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 26 July 2012 - 04:14 PM

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.

#8 r00tkiit

r00tkiit

    Member

  • Members
  • PipPip
  • 14 posts

Posted 28 July 2012 - 08:33 AM

Sorry. I am unable to get the desired output.
Can you please share the entire code with me.

Thanks .

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.



#9 carlinchisart

carlinchisart

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 28 July 2012 - 01:25 PM

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){
							    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>


#10 r00tkiit

r00tkiit

    Member

  • Members
  • PipPip
  • 14 posts

Posted 30 July 2012 - 04:45 PM

Thanks for the reply.

But still I have a problem with these statements:
var titulo = $(this).attr("title");
alert(titulo);
if(titulo=='Agregar Ruta diaria'){

...

I am getting "titulo" as undefined. I am not able to understand where are we setting the value of the title attribute.


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>



#11 carlinchisart

carlinchisart

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 30 July 2012 - 10:37 PM

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 $crud->set_subject('someting);
so for this reason i check what title i want to change in the if


if(titulo=='someting')

#12 r00tkiit

r00tkiit

    Member

  • Members
  • PipPip
  • 14 posts

Posted 31 July 2012 - 04:27 PM

Thanks again for the patient reply.
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. :)



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 $crud->set_subject('someting);
so for this reason i check what title i want to change in the if


if(titulo=='someting')







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users