# HG changeset patch # User veltr # Date 1381485093 -7200 # Node ID 3fef455d214a55cd8748a722c9f2f7d6bcc74e86 # Parent b9a417017e19f9612eaf144b7c7d1fa380b32858 Added contribution & favorite data diff -r b9a417017e19 -r 3fef455d214a timeline/js/timeline.js --- a/timeline/js/timeline.js Fri Oct 04 16:01:38 2013 +0200 +++ b/timeline/js/timeline.js Fri Oct 11 11:51:33 2013 +0200 @@ -134,31 +134,34 @@ span : 7 * 86400 * 1000, grid_interval : 86400 * 1000, grid_date_format : '{{dayOfMonth}} {{monthName}}', - min_importance : 3 //0 //pour les tests, mettre à 0 pour tout afficher + max_importance : 0 }, { label : "3 jours", span : 3 * 86400 * 1000, grid_interval : 6 * 3600 * 1000, grid_date_format : '{{^isDayStart}}{{0hours}}h{{0minutes}}{{/isDayStart}}{{#isDayStart}}{{dayOfMonth}} {{shortMonthName}}{{/isDayStart}}', - min_importance : 2 //0 //pour les tests, mettre à 0 pour tout afficher + max_importance : 1 }, { label : "Journée", span : 86400 * 1000, grid_interval : 2 * 3600 * 1000, grid_date_format : '{{^isDayStart}}{{0hours}}h{{0minutes}}{{/isDayStart}}{{#isDayStart}}{{dayOfMonth}} {{shortMonthName}}{{/isDayStart}}', - min_importance : 1 //0 //pour les tests, mettre à 0 pour tout afficher + max_importance : 2 }, { label : "Demi-Journée", span : 6 * 3600 * 1000, grid_interval : 3600 * 1000, grid_date_format : '{{^isDayStart}}{{0hours}}h{{0minutes}}{{/isDayStart}}{{#isDayStart}}{{dayOfMonth}} {{shortMonthName}}{{/isDayStart}}', - min_importance : 0 + max_importance : 3 }], level: 0, central_time: 0, sync_now: true, - api_endpoint: "", - api_method: "searchForTimelineEdito", + contents_endpoint: "http://anarchy2.solicis.fr/api/cms/content?method=searchForTimelinePublish", + get_favorite_endpoint: "http://anarchy2.solicis.fr/stream/timeline/favorites", + set_favorite_endpoint: "http://anarchy2.solicis.fr/stream/timeline/favorite", + contribution_endpoint: "http://anarchy2.solicis.fr/stream/timeline/contribs", + use_auth: true, occurrences: [], grid_spacing: 12, tooltip_date_format: '{{dayOfMonth}} {{monthName}} {{year}} à {{0hours}}:{{0minutes}}', @@ -216,7 +219,9 @@ } }, maxtime: false, - url_base: "" + url_base: "http://anarchy2.solicis.fr", + user_id: false, + use_jsonp: false }; for (var _i = 0; _i < Tlns.Defaults.Timeline.timescales.length; _i++) { @@ -360,6 +365,46 @@ this.onUniversLoaded(this.linelabels); + this.favoriteContents = []; + this.participationCounts = []; + + $.getJSON( + this.jsonpify(this.get_favorite_endpoint), + { + uid: this.user_id || undefined, + api_key: _this.use_auth ? _this.token : undefined, + mail: _this.use_auth ? _this.email : undefined + }, + function(d) { + _this.favoriteContents = _(d.data).map(function(f) { + return f.id; + }); + _(_this.favoriteContents).each(function(f) { + var o = _this.getOccurrence(f); + if (o) { + o.isFavorite = true; + } + }); + } + ); + + $.getJSON( + this.jsonpify(this.contribution_endpoint), + { + api_key: _this.use_auth ? _this.token : undefined, + mail: _this.use_auth ? _this.email : undefined + }, + function(d) { + _(d.data).each(function(c) { + _this.participationCounts[c.id] = c.nb; + var o = _this.getOccurrence(c.id); + if (o) { + o.participationCount = c.nb; + } + }); + } + ); + }; Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { @@ -475,18 +520,25 @@ this.drawOccurrences(); }; +Tlns.Classes.Timeline.prototype.jsonpify = function(url) { + if (this.use_jsonp) { + return url + (/\?/.test(url) ? "&" : "?" ) + "callback=?"; + } else { + return url; + } +}; + Tlns.Classes.Timeline.prototype.loadOccurrences = function() { var _this = this; function getData(cursor) { - $.getJSON(_this.api_endpoint, { - method: _this.api_method, - api_key: _this.token, - mail: _this.email, + $.getJSON(_this.jsonpify(_this.contents_endpoint), { + api_key: _this.use_auth ? _this.token : undefined, + mail: _this.use_auth ? _this.email : undefined, cursor: cursor }, function(_data) { _this.onOccurrencesLoaded(_data); - if (_data.cursor.hasNext) { + if (_data.cursor && _data.cursor.hasNext) { getData(_data.cursor.next); } }); @@ -553,9 +605,9 @@ _occ.y = _occ.univers.y; }); var minT = this.timeFromX(-32), - minI = this.timescales[this.level].min_importance; + maxI = this.timescales[this.level].max_importance; var _visible = _(this.occurrences).filter(function(_occ) { - _occ.visible = (_occ.date >= minT && _occ.date <= _this.end_time && (_occ.importance >= minI)); + _occ.visible = (_occ.date >= minT && _occ.date <= _this.end_time && (_occ.importance <= maxI)); return _occ.visible; }); @@ -718,14 +770,24 @@ if (typeinfo.picto) { this.image = this.timeline.picto_url + typeinfo.picto; } + var taxonomy = _(_data.contentHasTaxonomys).find(function(t) { + return !!t.taxonomy.taxonomyHasMedias; + }); + if (taxonomy) { + var taxonomyMedia = _(taxonomy.taxonomy.taxonomyHasMedias).find(function(m) { + return !!m.media.carre; + }); + if (taxonomyMedia) { + this.image = taxonomyMedia.media.carre.replace(/carre\/[\d]+\/[\d]+/,'carre/32/32'); + } + } this.univers = this.timeline.univers[this.univers_id]; this.format = typeinfo.label; - /* Données temporaires aléatoires */ - this.isFavorite = (Math.random() > 1/2); // A random Boolean ;-) - if (this.univers_id >= 2) { - this.participationCount = Math.floor(12*Math.random()); + if (this.timeline.favoriteContents.indexOf(this.id) !== -1) { + this.isFavorite = true; } + this.participationCount = this.timeline.participationCounts[this.id]; /* End Temporary Data */ var _tmp = $('
').html(_data.resume || ""); @@ -741,9 +803,21 @@ 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(); + $.ajax({ + type: "POST", + url: this.timeline.set_favorite_endpoint, + data: { + type: this.type, + conId: this.id, + status: +newFavStatus, + uid: this.timeline.user_id || undefined + }, + success: function(r) { + console.log(r); + _this.isFavorite = newFavStatus; + _this.timeline.throttledDrawGrid(); + } + }); + }; diff -r b9a417017e19 -r 3fef455d214a timeline/timeline-back.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/timeline/timeline-back.html Fri Oct 11 11:51:33 2013 +0200 @@ -0,0 +1,47 @@ + + +
+ + +