Browse files

fix event synching and views

  • Loading branch information...
1 parent d20d11f commit 12cac752dbf1861b09f2e9b6a6842ec7ec7c16da @ghostandthemachine ghostandthemachine committed Dec 10, 2012
Showing with 65 additions and 41 deletions.
  1. +1 −1 lib/model/user.rb
  2. +1 −1 lib/views/looking_glass/tile.haml
  3. +37 −37 lib/views/user/dashboard.haml
  4. +26 −2 lib/views/user/events.haml
View
2 lib/model/user.rb
@@ -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
View
2 lib/views/looking_glass/tile.haml
@@ -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
View
74 lib/views/user/dashboard.haml
@@ -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();
@@ -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();
+ // });
View
28 lib/views/user/events.haml
@@ -23,7 +23,7 @@
:javascript
$(function() {
var $container = $('#isotope-container');
- var newElements = "start";
+ var newElements = "";
$.ajax({
type: "POST",
url: "/api/user/events",
@@ -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.