Thursday, September 29, 2011

Re: Ajax Link - How to exchange/toogle a link?

Hi heohni,

In these instances I normally include both links in the original view
& then use CSS to hide 1, & JS to toggle them when required. you can
change the class on a parent element using JS to make the toggle
happen...

HTML...
<span id="link_container" class="show_link_1">
<a id="link_1">Link 1</a>
<a id="link_2">Link 2</a>
</spam>

CSS...
#link_container.show_link_1 #link_2 {
display: none;
}
#link_container.show_link_2 #link_1 {
display: none;
}

And then use the JS (in jquery format)...
if ( $( '#link_container' ).hasClass( 'show_link_1' ) ) {
$
( '#link_container' ).removeClass( 'show_link_1' ).addClass( 'show_link_2' );
} else {
$
( '#link_container' ).removeClass( 'show_link_2' ).addClass( 'show_link_1' );
}

There are, of course a couple of other options, including hiding 1 of
the links & using

$( '#link_container a' ).toggle();

... but I prefer the 1st option in case a browser hiccup causes both
links to show at once, meaning they both appear & re-apear at the same
time. Not sure how common a problem this would be though.

T

On Sep 29, 10:49 am, heohni <heidi.anselstet...@consultingteam.de>
wrote:
> Hi,
>
> I have this part of code in my view
>
> <div class="add_details" id="dynbookmark">
>             <?php if($this->Bookmark->checkBookmarkStatus($objects[0]
> ['Gesamtobjekt']['OBJ_ID']) == 'bookmark'){
>                 $image = 'bookmark.png';
>                 $text = __('Immobilie merken', true);
>                 $action = 'add';
>             }else{
>                 $image = 'bookmarked.png';
>                 $text = __('Immobilie vorgemerkt', true);
>                 $action = 'delete';
>             }
>             ?>
>             <?=$ajax->link($this->Html->image($image).$text,
> array('controller'=>'bookmark', 'action'=>$action, $objects[0]
> ['Gesamtobjekt']['OBJ_ID']), array('escape' => false, 'update' =>
> 'dynbookmark'));?>
>         </div>
>
> This shows me on page load if this item is saved on "bookmark" list,
> or not.
> With the Ajax Link I can toogle this t save or to delete this item
> from the bookmarks list.
>
> But to display the correct link I need 3 important infos:
> - the right picture
> - link text ("add me" + "delete me")
> - the controller action name (add / delete)
>
> As far as I understand the ajax link stuff, I can return only a simple
> string?
> How could I create the entire link with all my needed information?
>
> Any ideas or help?
>
> Thanks!!

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: