Skip to content

Commit

Permalink
fix event synching and views
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostandthemachine committed Dec 10, 2012
1 parent d20d11f commit 12cac75
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/model/user.rb
Expand Up @@ -83,6 +83,6 @@ def stream_events(args=100)
return events = Event.all(args)
end
events = self.events if events.count == 0
return events
return events.uniq
end
end
2 changes: 1 addition & 1 deletion lib/views/looking_glass/tile.haml
Expand Up @@ -37,5 +37,5 @@
%span.open-event-btn{href: ""}
%a.event-load-btn{href: "/user/#{map[:user_name]}/event/#{map[:id]}"}
More Info
%a.google-event-btn{id: "google-btn-#{map[:id]}", href:"#", class: "#{map[:event].google_calendar_id ? "synched-btn-decoration" : ""}"}
%a.google-event-btn{id: "google-btn-#{map[:id]}", "data-event-id" => map[:event].id, href:"#", class: "#{map[:event].google_calendar_id ? "synched-btn-decoration" : ""}"}
Add to calendar
74 changes: 37 additions & 37 deletions lib/views/user/dashboard.haml
Expand Up @@ -42,6 +42,7 @@
$container.isotope('insert', html);
// add the click handlers for the new elements
$('.google-event-btn').click(function(e) {
console.log("sync event")
var event_id = $(this).parent().parent().parent().parent().parent().parent().attr('data-symbol');
console.log(event_id);
e.preventDefault();
Expand Down Expand Up @@ -74,40 +75,39 @@
});
});

$(function() {
var loop = true;
var $container = $('#isotope-container');
function doStuff() {
if (loop) {
var now = Date();
$.ajax({
type: "POST",
url: "/api/user/stream/update",
data: {user_id: "#{@user.id}",
user_salt: "#{@user.salt}",
time: now,
range: "0 10"}
}).done(function (response) {
if (response.length > 0) {
var html = $('<div>').html(response);
// add the new elements to the isotope container
$container.prepend(html).isotope( 'reloadItems' ).isotope({ sortBy: 'original-order' });
// add the click handlers for the new elements
$('.element').click(function(e) {
if ($(e.target).hasClass('event-load-btn')) {
} else {
$(this).toggleClass('large');
$container.isotope('reLayout');
}
});
}
console.log($('.element > img').addClass("moz-tile-img"));
if ($.browser.mozilla) {
$('.element > img').addClass("moz-tile-img");
}
});
setTimeout(doStuff, 10000);
}
};
doStuff();
});
// $(function() {
// var loop = true;
// var $container = $('#isotope-container');
// function doStuff() {
// if (loop) {
// var now = Date();
// $.ajax({
// type: "POST",
// url: "/api/user/stream/update",
// data: {user_id: "#{@user.id}",
// user_salt: "#{@user.salt}",
// time: now,
// range: "0 10"}
// }).done(function (response) {
// if (response.length > 0) {
// var html = $('<div>').html(response);
// // add the new elements to the isotope container
// $container.prepend(html).isotope( 'reloadItems' ).isotope({ sortBy: 'original-order' });
// // add the click handlers for the new elements
// $('.element').click(function(e) {
// if ($(e.target).hasClass('event-load-btn')) {
// } else {
// $(this).toggleClass('large');
// $container.isotope('reLayout');
// }
// });
// }
// if ($.browser.mozilla) {
// $('.element > img').addClass("moz-tile-img");
// }
// });
// setTimeout(doStuff, 10000);
// }
// };
// doStuff();
// });
28 changes: 26 additions & 2 deletions lib/views/user/events.haml
Expand Up @@ -23,7 +23,7 @@
:javascript
$(function() {
var $container = $('#isotope-container');
var newElements = "start";
var newElements = "";
$.ajax({
type: "POST",
url: "/api/user/events",
Expand All @@ -39,12 +39,36 @@
// add the new elements to the isotope container
$container.isotope('insert', html);
// add the click handlers for the new elements
$('.google-event-btn').click(function(e) {
console.log("sync event")
var event_id = $(this).parent().parent().parent().parent().parent().parent().attr('data-symbol');
console.log(event_id);
e.preventDefault();
$.ajax({
type: "POST",
url: "/api/sync/toggle_event",
data: {event_id: event_id}
}).done(function(response){
console.log(response);
var div_id_name = '#google-btn-' + event_id;
if (response == "synched") {
$(div_id_name).addClass("synched-btn-decoration");
} else {
$(div_id_name).removeClass("synched-btn-decoration");
}
if ($.browser.mozilla) {
$('.element > img').addClass("moz-tile-img");
}
});
});

$('.element').click(function(e) {
if ($(e.target).hasClass('event-load-btn')) {
} else if ($(e.target).hasClass('google-event-btn')) {
} else {
$(this).toggleClass('large');
$container.isotope('reLayout');
}
});
});
});
});

0 comments on commit 12cac75

Please sign in to comment.