Several ‘Add to’ on one page
Posted: 29 November 2007 12:48 PM   [ Ignore ]
Member
RankRankRank
Total Posts:  59
Joined  2005-07-18

Can Ajax w/ Favorites be used for several entries on one pages.

I tried Favorites w/ Ajax according to:

http://www.solspace.com/forums/viewreply/743/

That works on “one-entry” pages {‘more’}.

But if I add an entry on the index page, after adding it all entries show the same string ‘Your favorite has been successfully added.‘ It is shown even in the entries which were not added to favorites..

So, can that be changed only one entry (added) would show the above message? I think Ajax should use the ‘entry_id’ parameter.

 Signature 

tulks.com

Profile
 
 
Posted: 29 November 2007 07:34 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3717
Joined  2006-10-18

Can I see a page you have this on? smile

 Signature 

Check out the new Solspace Blog!

Profile
 
 
Posted: 29 November 2007 11:04 PM   [ Ignore ]   [ # 2 ]
Member
RankRankRank
Total Posts:  59
Joined  2005-07-18

The page under construction:

(I removed this test link after solving the problem)

(there are only 2 test entries now)

Each Member will be able to add words to his/her personal list to learn the selected words in the online e-learning system.

 Signature 

tulks.com

Profile
 
 
Posted: 13 January 2008 11:49 PM   [ Ignore ]   [ # 3 ]
Member
RankRankRank
Total Posts:  59
Joined  2005-07-18

ok, I rewrote the code by Bill Warters, so, my solution for the ‘index’ pages:

Between HEAD tags

$().ready(function() {
{exp
:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" limit="15" disable="member_data|trackbacks"}
$('a.Favorites_Trigger_{entry_id}') .click (function() {
$.get(this.href, function(data{
$('span.favoritesspan_{entry_id}')
.
html(data);
});
return 
false;
});
{/exp:weblog:entries}
}
); 

Between BODY tags

{exp:favorites:saved entry_id="{entry_id}"}
{if saved}
<span class="favoritesspan_{entry_id}"><em>Saved as a favorite.</em>&nbsp;<class="Favorites_Trigger_{entry_id}" href="{path='{my_template_group}/favorite_add/'}{entry_id}/delete">Remove from favorites list?</a></span>
{/if}
{if not_saved}
<span class="favoritesspan_{entry_id}"><class="Favorites_Trigger_{entry_id}" href="{path='{my_template_group}/favorite_add/'}{entry_id}">Add this item to your favorites?</a></span
{/if}
{
/exp:favorites:saved} 

exp:weblog:entries should be identical to get the same ‘entry_id’ in both parts

 Signature 

tulks.com

Profile
 
 
Posted: 14 January 2008 08:17 AM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3717
Joined  2006-10-18

So that works now? Nice! smile

 Signature 

Check out the new Solspace Blog!

Profile
 
 
Posted: 14 January 2008 08:25 AM   [ Ignore ]   [ # 5 ]
Member
RankRankRank
Total Posts:  59
Joined  2005-07-18
Pie Man - 14 January 2008 08:17 AM

So that works now? Nice! smile

Yes, now I use this code here (index pages):

http://tulks.valsts.lv/site/

http://tulks.valsts.lv/english/

 Signature 

tulks.com

Profile
 
 
Posted: 14 January 2008 08:29 AM   [ Ignore ]   [ # 6 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3717
Joined  2006-10-18

Excellent work wink

And thank you for posting the revised code smile

 Signature 

Check out the new Solspace Blog!

Profile
 
 
Posted: 24 July 2008 11:50 AM   [ Ignore ]   [ # 7 ]
Member
RankRankRank
Total Posts:  59
Joined  2005-07-18

I’d like to mention that after fixing a bug in ExpressionEngine 1.6.3 (“Fixed a bug where the Trackback RDF was no longer being outputted“), the above code should include rdf=“off”. That is, for example:

...
$().
ready(function() {
{exp
:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" limit="15" disable="member_data|trackbacks" rdf="off"}
... 

 Signature 

tulks.com

Profile
 
 
Posted: 24 July 2008 12:16 PM   [ Ignore ]   [ # 8 ]
Member
RankRankRank
Total Posts:  59
Joined  2005-07-18

AJAX Favorites + AJAX Favorites Counter

HEAD:

script type="text/javascript" src="/jquery/jquery.js">< / script>
script>
$().
ready(function() {
{exp
:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" limit="10" rdf="off" disable="member_data|trackbacks"}
$('a.Favorites_Trigger_{entry_id}') .click (function() {
$.get(this.href, function(data{
$('span.favoritesspan_{entry_id}')
.
html(data);
});
return 
false;
});
{/exp:weblog:entries}
}
);
< / 
script


BODY:

{if logged_in}
{exp
:favorites:saved entry_id="{entry_id}"}
{if saved}
<span class="favoritesspan_{entry_id}"><em>Saved as a favorite.</em>&nbsp;<class="Favorites_Trigger_{entry_id}" href="{path='{my_template_group}/favorite_add/'}{entry_id}/delete">Remove from favorites list?</a><br />Favorites{exp:favorites:entry_count entry_id="{entry_id}"}{favorites_count}{/exp:favorites:entry_count}<br /></span></a>
{/if}
{if not_saved}
<span class="favoritesspan_{entry_id}"><class="Favorites_Trigger_{entry_id}" href="{path='{my_template_group}/favorite_add/'}{entry_id}">Add this item to your favorites?</a><br />Favorites{exp:favorites:entry_count entry_id="{entry_id}"}{favorites_count}{/exp:favorites:entry_count}</span></li>
{/if}
{
/exp:favorites:saved}
<br />
{/if} 

favorite_add:

{exp:favorites:save}<br />Favorites{exp:favorites:entry_count}{favorites_count}{/exp:favorites:entry_count} 


And you get:


1)

Add this item to your favorites?
Favorites: 0

2) After adding a favorite with AJAX:

Your favorite has been successfully added.
Favorites: 1

3) And after reloading the page:

Saved as a favorite. Remove from favorites list?
Favorites: 1

4) After removing with AJAX:

Your favorite has been successfully deleted.
Favorites: 0

 Signature 

tulks.com

Profile
 
 
Posted: 24 July 2008 09:15 PM   [ Ignore ]   [ # 9 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3717
Joined  2006-10-18

Nice work sigork! Thanks smile

 Signature 

Check out the new Solspace Blog!

Profile