* @param {boolean} un Whether to perform an activity removal instead of creation
*/
function doActivityItemAction(ident, verb, un) {
- if (verb.indexOf("attend") === 0) {
- $(".item-" + ident + " .button-event:not(#" + verb + "-" + ident + ")").removeClass("active");
- }
- $("#" + verb + "-" + ident).toggleClass("active");
+ console.log(ident, verb, un);
+ _verb = un ? 'un' + verb : verb;
+ $('#like-rotator-' + ident.toString()).show();
+ $.post('item/' + ident.toString() + '/activity/' + _verb)
+ .success(
+ function(data){
+ console.log("data.status: " + data.status);
+ if (data.status == "ok") {
+ console.log("connection: " + data.status);
+ $('#like-rotator-' + ident.toString()).hide();
+ if (verb.indexOf("announce") === 0 ) {
+ console.log("announce")
+ if (data.verb == "un" + verb) {
+ $("button[id^=shareMenuOptions-" + ident.toString() + "]" ).removeClass("active");
+ $("button[id^=shareMenuOptions-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + false + ")").change();
+ $("button[id^=" + verb + "-" + ident.toString() + "]" ).removeClass("active");
+ $("button[id^=" + verb + "-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + false + ")").change();
+ } else {
+ $("button[id^=shareMenuOptions-" + ident.toString() + "]" ).addClass("active");
+ $("button[id^=shareMenuOptions-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + true + ")").change();
+ $("button[id^=" + verb + "-" + ident.toString() + "]" ).addClass("active");
+ $("button[id^=" + verb + "-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + true + ")").change();
+ }
+ } else {
+ console.log("likes")
+ if (data.verb == "un" + verb) {
+ console.log(data.state);
+ $("button[id^=" + verb + "-" + ident.toString() + "]" ).removeClass("active");
+ $("button[id^=" + verb + "-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + false + ")").change();
+ } else {
+ $("button[id^=" + verb + "-" + ident.toString() + "]" ).addClass("active");
+ $("button[id^=" + verb + "-" + ident.toString() + "]" ).attr("onclick", "doActivityItemAction(" + ident +", '" + verb + "', " + true + ")").change();
+ }
+ $("button[id^=" + verb + "-" + ident.toString() + "]" ).button('refresh');
+ }
+ } else {
+ $.jGrowl("No connection to host for like or share", {sticky: false, theme: 'info', life: 5000});
+ console.err("No connection to host");
+ }
+ })
+ .error(
+ function(data){
+ $.jGrowl("Network not reachable", {sticky: false, theme: 'info', life: 5000});
+ console.log("POST unsuccessfull " + data.toString());
+ });
- doActivityItem(ident, verb, un);
}
// Decodes a hexadecimally encoded binary string
<button type="button"
class="btn-link button-likes{{if $responses.like.self}} active" aria-pressed="true{{/if}}" id="like-{{$id}}"
title="{{$like_title}}"
- onclick="doActivityItemAction({{$id}}, 'like'{{if $responses.like.self}}, true{{/if}});"
- data-toggle="button">
+ onclick="doActivityItemAction({{$id}}, 'like'{{if $responses.like.self}}, true{{/if}});">
<i class="fa fa-thumbs-up" aria-hidden="true"></i> {{$like}}
</button>
{{if !$hide_dislike}}
class="btn-link button-likes{{if $responses.dislike.self}} active" aria-pressed="true{{/if}}"
id="dislike-{{$id}}"
title="{{$dislike_title}}"
- onclick="doActivityItemAction({{$id}}, 'dislike'{{if $responses.dislike.self}}, true{{/if}});"
- data-toggle="button"><i class="fa fa-thumbs-down" aria-hidden="true"></i> {{$dislike}}
+ onclick="doActivityItemAction({{$id}}, 'dislike'{{if $responses.dislike.self}}, true{{/if}});">
+ <i class="fa fa-thumbs-down" aria-hidden="true"></i> {{$dislike}}
</button>
{{/if}}
<img id="like-rotator-{{$id}}" class="like-rotator" src="images/rotator.gif" alt="{{$wait}}" title="{{$wait}}" style="display: none;" />
{{* Buttons for like and dislike *}}
{{if $item.vote}}
{{if $item.vote.like}}
- <button type="button" class="btn-link button-likes{{if $item.responses.like.self}} active" aria-pressed="true{{/if}}" id="like-{{$item.id}}" title="{{$item.vote.like.0}}" onclick="doActivityItemAction({{$item.id}}, 'like'{{if $item.responses.like.self}}, true{{/if}});" data-toggle="button"><i class="fa fa-thumbs-up" aria-hidden="true"></i> {{$item.vote.like.1}}</button>
+ <button type="button" class="btn-link button-likes{{if $item.responses.like.self}} active" aria-pressed="true{{/if}}" id="like-{{$item.id}}" title="{{$item.vote.like.0}}" onclick="doActivityItemAction({{$item.id}}, 'like'{{if $item.responses.like.self}}, true{{/if}});" ><i class="fa fa-thumbs-up" aria-hidden="true"></i> {{$item.vote.like.1}}</button>
{{/if}}
{{if $item.vote.like AND $item.vote.dislike}}
<span role="presentation" class="separator"></span>
{{/if}}
{{if $item.vote.dislike}}
- <button type="button" class="btn-link button-likes{{if $item.responses.dislike.self}} active" aria-pressed="true{{/if}}" id="dislike-{{$item.id}}" title="{{$item.vote.dislike.0}}" onclick="doActivityItemAction({{$item.id}}, 'dislike'{{if $item.responses.dislike.self}}, true{{/if}});" data-toggle="button"><i class="fa fa-thumbs-down" aria-hidden="true"></i> {{$item.vote.dislike.1}}</button>
+ <button type="button" class="btn-link button-likes{{if $item.responses.dislike.self}} active" aria-pressed="true{{/if}}" id="dislike-{{$item.id}}" title="{{$item.vote.dislike.0}}" onclick="doActivityItemAction({{$item.id}}, 'dislike'{{if $item.responses.dislike.self}}, true{{/if}});" ><i class="fa fa-thumbs-down" aria-hidden="true"></i> {{$item.vote.dislike.1}}</button>
{{/if}}
{{if ($item.vote.like OR $item.vote.dislike) AND $item.comment_html}}
{{/if}}
{{/if}}
{{if $item.vote.announce}}
- <button type="button" class="btn-link button-announces{{if $item.responses.announce.self}} active" aria-pressed="true{{/if}}" id="announce-{{$item.id}}" title="{{$item.vote.announce.0}}" onclick="doActivityItemAction({{$item.id}}, 'announce'{{if $item.responses.announce.self}}, true{{/if}});" data-toggle="button"><i class="fa fa-retweet" aria-hidden="true"></i> {{$item.vote.announce.1}}</button>
+ <button type="button" class="btn-link button-announces{{if $item.responses.announce.self}} active" aria-pressed="true{{/if}}" id="announce-{{$item.id}}" title="{{$item.vote.announce.0}}" onclick="doActivityItemAction({{$item.id}}, 'announce'{{if $item.responses.announce.self}}, true{{/if}});" ><i class="fa fa-retweet" aria-hidden="true"></i> {{$item.vote.announce.1}}</button>
<span role="presentation" class="separator"></span>
{{/if}}
{{if $item.vote.share}}
{{* Buttons for like and dislike *}}
{{if $item.vote}}
{{if $item.vote.like}}
- <button type="button" class="btn button-likes{{if $item.responses.like.self}} active" aria-pressed="true{{/if}}" id="like-{{$item.id}}" title="{{$item.vote.like.0}}" onclick="doActivityItemAction({{$item.id}}, 'like'{{if $item.responses.like.self}}, true{{/if}});" data-toggle="button"><i class="fa fa-thumbs-up" aria-hidden="true"></i></button>
+ <button type="button" class="btn button-likes{{if $item.responses.like.self}} active" aria-pressed="true{{/if}}" id="like-{{$item.id}}" title="{{$item.vote.like.0}}" onclick="doActivityItemAction({{$item.id}}, 'like'{{if $item.responses.like.self}}, true{{/if}});" ><i class="fa fa-thumbs-up" aria-hidden="true"></i></button>
{{/if}}
{{if $item.vote.dislike}}
- <button type="button" class="btn button-likes{{if $item.responses.dislike.self}} active" aria-pressed="true{{/if}}" id="dislike-{{$item.id}}" title="{{$item.vote.dislike.0}}" onclick="doActivityItemAction({{$item.id}}, 'dislike'{{if $item.responses.dislike.self}}, true{{/if}});" data-toggle="button"><i class="fa fa-thumbs-down" aria-hidden="true"></i></button>
+ <button type="button" class="btn button-likes{{if $item.responses.dislike.self}} active" aria-pressed="true{{/if}}" id="dislike-{{$item.id}}" title="{{$item.vote.dislike.0}}" onclick="doActivityItemAction({{$item.id}}, 'dislike'{{if $item.responses.dislike.self}}, true{{/if}});" ><i class="fa fa-thumbs-down" aria-hidden="true"></i></button>
{{/if}}
{{/if}}