Simulate click on favorite star
authorveltr
Fri, 04 Oct 2013 16:01:38 +0200
changeset 103 b9a417017e19
parent 102 2f1ef2ded30c
child 104 3fef455d214a
Simulate click on favorite star
timeline/css/timeline.css
timeline/js/timeline.js
--- a/timeline/css/timeline.css	Fri Oct 04 15:39:08 2013 +0200
+++ b/timeline/css/timeline.css	Fri Oct 04 16:01:38 2013 +0200
@@ -160,17 +160,13 @@
 }
 
 .Tl-Detail-Favorite {
-    float: right; width: 20px; height: 20px; background-image: url(../img/favstars-large.png);
+    float: right; width: 20px; height: 20px; background-image: url(../img/favstars-large.png); cursor: pointer;
 }
 
-.Tl-Detail-Favorite:hover, .Tl-Detail-isFavorite {
+.Tl-Detail-isFavorite {
     background-position: -20px 0;
 }
 
-.Tl-Detail-isFavorite:hover  {
-    background-position: 0 0;
-}
-
 .Tl-Detail-Participation {
     position: absolute; bottom: 0; right: 0; padding: 10px; background: rgba(0,0,0,.5); color: #ffffff; font-size: 12px;
 }
--- a/timeline/js/timeline.js	Fri Oct 04 15:39:08 2013 +0200
+++ b/timeline/js/timeline.js	Fri Oct 04 16:01:38 2013 +0200
@@ -621,6 +621,13 @@
                 });
                 _this.editing_occurrence.editing = true;
                 _this.$.find(".Tl-Details").html(Mustache.to_html(Tlns.Templates.OccurrenceDetails, _this.editing_occurrence));
+                _this.$.find(".Tl-Detail-Favorite").click(function() {
+                    _this.editing_occurrence.toggleFavorite();
+                }).hover(function() {
+                    $(this)[_this.editing_occurrence.isFavorite ? "removeClass" : "addClass" ]("Tl-Detail-isFavorite");
+                }, function() {
+                    $(this)[_this.editing_occurrence.isFavorite ? "addClass" : "removeClass"]("Tl-Detail-isFavorite");
+                });
             }
             _this.throttledDrawGrid();
         }
@@ -731,3 +738,12 @@
 Tlns.Classes.Occurrence.prototype.toString = function() {
     return "Occurrence " + this.type + ': "' + this.title + '"';
 };
+
+Tlns.Classes.Occurrence.prototype.toggleFavorite = function() {
+    var newFavStatus = !this.isFavorite;
+    /* Add API Call HERE */
+    
+    /* The Following status update should be moved to the SUCCESS callback of the API call */
+    this.isFavorite = newFavStatus;
+    this.timeline.throttledDrawGrid();
+};