From 863fda91fbfbe3b39a28be3dec8196dc31679800 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Thu, 9 Jan 2014 23:00:37 +0000 Subject: [PATCH] Fixed follow link in UserDetailView --- static/js/app/appv2.js | 269 +++++++++--------- static/js/app/views/user/userItemView.js | 61 ++-- static/js/app/views/user/userListView.coffee | 1 - static/js/app/views/user/userListView.js | 1 - .../js/app/views/user/userProfileView.coffee | 7 + static/js/app/views/user/userProfileView.js | 17 +- templates/views/UserListItemView.html | 2 +- templates/views/UserProfileView.html | 176 ++++++------ 8 files changed, 274 insertions(+), 260 deletions(-) diff --git a/static/js/app/appv2.js b/static/js/app/appv2.js index 98e4a07..dc650d4 100755 --- a/static/js/app/appv2.js +++ b/static/js/app/appv2.js @@ -1,140 +1,137 @@ // Generated by CoffeeScript 1.4.0 -(function() { - define(['backbone', 'marionette', 'vent', 'utils', 'app.lib/social', 'app.lib/router', 'app.lib/panningRegion', 'app.lib/realtimeController', 'app.lib/audioController', 'models/user/userItem', 'models/mix/mixCollection', 'views/widgets/headerView', 'views/sidebar/sidebarView'], function(Backbone, Marionette, vent, utils, social, DssRouter, PanningRegion, RealtimeController, AudioController, UserItem, MixCollection, HeaderView, SidebarView) { - var App, sidebarView; - App = new Marionette.Application(); - App.audioController = new AudioController(); - App.realtimeController = new RealtimeController(); - App.realtimeController.startSocketIO(); - App.vent.on("routing:started", function() { - var enablePushState, pushState; - console.log("App(vent): routing:started"); - enablePushState = true; - pushState = !!(enablePushState && window.history && window.history.pushState); - Backbone.history.start({ - pushState: pushState, - hashChange: true - }); - return true; +define(['backbone', 'marionette', 'vent', 'utils', 'app.lib/social', 'app.lib/router', 'app.lib/panningRegion', 'app.lib/realtimeController', 'app.lib/audioController', 'models/user/userItem', 'models/mix/mixCollection', 'views/widgets/headerView', 'views/sidebar/sidebarView'], function(Backbone, Marionette, vent, utils, social, DssRouter, PanningRegion, RealtimeController, AudioController, UserItem, MixCollection, HeaderView, SidebarView) { + var App, sidebarView; + App = new Marionette.Application(); + App.audioController = new AudioController(); + App.realtimeController = new RealtimeController(); + App.realtimeController.startSocketIO(); + App.vent.on("routing:started", function() { + var enablePushState, pushState; + console.log("App(vent): routing:started"); + enablePushState = true; + pushState = !!(enablePushState && window.history && window.history.pushState); + Backbone.history.start({ + pushState: pushState, + hashChange: true }); - App.addRegions({ - headerRegion: "#header", - contentRegion: { - selector: "#content" - }, - footerRegion: "#footer", - sidebarRegion: "#sidebar" - }); - App.addInitializer(function() { - console.log("App: routing starting"); - App.Router = new DssRouter(); - return App.vent.trigger("routing:started"); - }); - App.addInitializer(function() { - $(document).on("click", "a[href]:not([data-bypass])", function(evt) { - var href, root; - href = { - prop: $(this).prop("href"), - attr: $(this).attr("href") - }; - root = location.protocol + "//" + location.host + (App.root || '/'); - if (href.prop.slice(0, root.length) === root) { - evt.preventDefault(); - App.Router.navigate(href.attr, true); - return true; - } - }); - return true; - }); - App.addInitializer(function() { - this.listenTo(vent, "app:login", function() { - utils.modal("/dlg/LoginView"); - return true; - }); - this.listenTo(vent, "app:donate", function() { - console.log("App: donate"); - utils.modal("/dlg/Donate"); - return true; - }); - this.listenTo(vent, "mix:favourite", function(model) { - console.log("App(vent): mix:favourite"); - model.save('favourited', !model.get('favourited'), { - patch: true - }); - return true; - }); - this.listenTo(vent, "mix:like", function(model, id, success, favourite) { - console.log("App(vent): mix:like"); - model.save('liked', !model.get('liked'), { - patch: true - }); - return true; - }); - this.listenTo(vent, "mix:delete", function(model) { - console.log("App(vent): mix:like"); - return utils.messageBox("/dlg/DeleteMixConfirm", { - yes: function() { - console.log("Controller: mixDeleteYES!!"); - mix.destroy(); - return Backbone.history.navigate("/", { - trigger: true - }); - }, - no: function() { - return console.log("Controller: mixDeleteNO!!"); - } - }); - }); - this.listenTo(vent, "user:follow", function(model) { - var target, user, - _this = this; - console.log("App(vent): user:follow"); - user = new UserItem({ - id: com.podnoms.settings.currentUser - }); - target = com.podnoms.settings.urlRoot + "user/" + model.get("id") + "/"; - user.fetch({ - success: function() { - var f, newFollowers; - if (!model.get("is_following")) { - newFollowers = user.get("following").concat([target]); - user.save({ - "following": newFollowers, - "is_following": true, - patch: true - }); - model.set("is_following", true); - } else { - f = user.get("following"); - f.splice(f.indexOf(target), 1); - user.save({ - "following": f, - "is_following": false, - patch: true - }); - model.set("is_following", false); - } - } - }); - return true; - }); - return this.listenTo(vent, "mix:share", function(mode, model) { - console.log("App(vent): mix:share (" + mode + ")"); - if (mode === "facebook") { - social.sharePageToFacebook(model); - } else if (mode === "twitter") { - social.sharePageToTwitter(model); - } else if (mode === "embed") { - social.generateEmbedCode(model); - } - return true; - }); - }); - App.headerRegion.show(new HeaderView()); - sidebarView = new SidebarView(); - App.sidebarRegion.show(sidebarView); - return App; + return true; }); - -}).call(this); + App.addRegions({ + headerRegion: "#header", + contentRegion: { + selector: "#content" + }, + footerRegion: "#footer", + sidebarRegion: "#sidebar" + }); + App.addInitializer(function() { + console.log("App: routing starting"); + App.Router = new DssRouter(); + return App.vent.trigger("routing:started"); + }); + App.addInitializer(function() { + $(document).on("click", "a[href]:not([data-bypass])", function(evt) { + var href, root; + href = { + prop: $(this).prop("href"), + attr: $(this).attr("href") + }; + root = location.protocol + "//" + location.host + (App.root || '/'); + if (href.prop.slice(0, root.length) === root) { + evt.preventDefault(); + App.Router.navigate(href.attr, true); + return true; + } + }); + return true; + }); + App.addInitializer(function() { + this.listenTo(vent, "app:login", function() { + utils.modal("/dlg/LoginView"); + return true; + }); + this.listenTo(vent, "app:donate", function() { + console.log("App: donate"); + utils.modal("/dlg/Donate"); + return true; + }); + this.listenTo(vent, "mix:favourite", function(model) { + console.log("App(vent): mix:favourite"); + model.save('favourited', !model.get('favourited'), { + patch: true + }); + return true; + }); + this.listenTo(vent, "mix:like", function(model, id, success, favourite) { + console.log("App(vent): mix:like"); + model.save('liked', !model.get('liked'), { + patch: true + }); + return true; + }); + this.listenTo(vent, "mix:delete", function(model) { + console.log("App(vent): mix:like"); + return utils.messageBox("/dlg/DeleteMixConfirm", { + yes: function() { + console.log("Controller: mixDeleteYES!!"); + mix.destroy(); + return Backbone.history.navigate("/", { + trigger: true + }); + }, + no: function() { + return console.log("Controller: mixDeleteNO!!"); + } + }); + }); + this.listenTo(vent, "user:follow", function(model) { + var target, user, + _this = this; + console.log("App(vent): user:follow"); + user = new UserItem({ + id: com.podnoms.settings.currentUser + }); + target = com.podnoms.settings.urlRoot + "user/" + model.get("id") + "/"; + user.fetch({ + success: function() { + var f, newFollowers; + if (!model.get("is_following")) { + newFollowers = user.get("following").concat([target]); + user.save({ + "following": newFollowers, + "is_following": true, + patch: true + }); + model.set("is_following", true); + } else { + f = user.get("following"); + f.splice(f.indexOf(target), 1); + user.save({ + "following": f, + "is_following": false, + patch: true + }); + model.set("is_following", false); + } + } + }); + return true; + }); + return this.listenTo(vent, "mix:share", function(mode, model) { + console.log("App(vent): mix:share (" + mode + ")"); + if (mode === "facebook") { + social.sharePageToFacebook(model); + } else if (mode === "twitter") { + social.sharePageToTwitter(model); + } else if (mode === "embed") { + social.generateEmbedCode(model); + } + return true; + }); + }); + App.headerRegion.show(new HeaderView()); + sidebarView = new SidebarView(); + App.sidebarRegion.show(sidebarView); + return App; +}); diff --git a/static/js/app/views/user/userItemView.js b/static/js/app/views/user/userItemView.js index cf0e4c8..84b09c0 100755 --- a/static/js/app/views/user/userItemView.js +++ b/static/js/app/views/user/userItemView.js @@ -1,41 +1,38 @@ // Generated by CoffeeScript 1.4.0 -(function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; +var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - define(['app', 'moment', 'app.lib/dssView', 'vent', 'text!/tpl/UserListItemView'], function(App, moment, DssView, vent, Template) { - var UserItemView; - UserItemView = (function(_super) { +define(['app', 'moment', 'app.lib/dssView', 'vent', 'text!/tpl/UserListItemView'], function(App, moment, DssView, vent, Template) { + var UserItemView; + UserItemView = (function(_super) { - __extends(UserItemView, _super); + __extends(UserItemView, _super); - function UserItemView() { - this.initialize = __bind(this.initialize, this); - return UserItemView.__super__.constructor.apply(this, arguments); + function UserItemView() { + this.initialize = __bind(this.initialize, this); + return UserItemView.__super__.constructor.apply(this, arguments); + } + + UserItemView.prototype.template = _.template(Template); + + UserItemView.prototype.className = "row"; + + UserItemView.prototype.events = { + "click #follow-button": function() { + return vent.trigger("user:follow", this.model); + }, + "click #follow-button-login": function() { + return vent.trigger("app:login", this.model); } + }; - UserItemView.prototype.template = _.template(Template); + UserItemView.prototype.initialize = function() { + return this.listenTo(this.model, 'change:is_following', this.render); + }; - UserItemView.prototype.className = "row"; - - UserItemView.prototype.events = { - "click #follow-button": function() { - return vent.trigger("user:follow", this.model); - }, - "click #follow-button-login": function() { - return vent.trigger("app:login", this.model); - } - }; - - UserItemView.prototype.initialize = function() { - return this.listenTo(this.model, 'change:is_following', this.render); - }; - - return UserItemView; - - })(DssView); return UserItemView; - }); -}).call(this); + })(DssView); + return UserItemView; +}); diff --git a/static/js/app/views/user/userListView.coffee b/static/js/app/views/user/userListView.coffee index 7ef3946..fd415d8 100755 --- a/static/js/app/views/user/userListView.coffee +++ b/static/js/app/views/user/userListView.coffee @@ -19,7 +19,6 @@ define ['jquery', 'marionette', 'models/user/userCollection', 'views/user/userIt return _fetchCollection: (options) => - debugger @collection.fetch( data: options success: => diff --git a/static/js/app/views/user/userListView.js b/static/js/app/views/user/userListView.js index 9beb33a..4a28d23 100755 --- a/static/js/app/views/user/userListView.js +++ b/static/js/app/views/user/userListView.js @@ -41,7 +41,6 @@ define(['jquery', 'marionette', 'models/user/userCollection', 'views/user/userIt }; UserListView.prototype._fetchCollection = function(options) { - debugger; var _this = this; return this.collection.fetch({ data: options, diff --git a/static/js/app/views/user/userProfileView.coffee b/static/js/app/views/user/userProfileView.coffee index 1c2b71c..f9219d7 100644 --- a/static/js/app/views/user/userProfileView.coffee +++ b/static/js/app/views/user/userProfileView.coffee @@ -4,6 +4,13 @@ define ['app', 'utils', 'moment', 'marionette', 'vent', 'app.lib/editableView', class UserProfileView extends EditableView template: _.template(Template) + events: + "click #follow-button": -> vent.trigger("user:follow", @model) + "click #follow-button-login": -> vent.trigger("app:login", @model) + + initialize: => + @listenTo(@model, 'change:is_following', @render) + templateHelpers: humanise: (date)-> moment(date).fromNow() diff --git a/static/js/app/views/user/userProfileView.js b/static/js/app/views/user/userProfileView.js index fc1a429..de6143d 100644 --- a/static/js/app/views/user/userProfileView.js +++ b/static/js/app/views/user/userProfileView.js @@ -1,5 +1,6 @@ // Generated by CoffeeScript 1.4.0 -var __hasProp = {}.hasOwnProperty, +var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; define(['app', 'utils', 'moment', 'marionette', 'vent', 'app.lib/editableView', 'models/user/userItem', 'text!/tpl/UserProfileView', 'ace-editable', 'wysiwyg'], function(App, utils, moment, Marionette, vent, EditableView, UserItem, Template) { @@ -9,11 +10,25 @@ define(['app', 'utils', 'moment', 'marionette', 'vent', 'app.lib/editableView', __extends(UserProfileView, _super); function UserProfileView() { + this.initialize = __bind(this.initialize, this); return UserProfileView.__super__.constructor.apply(this, arguments); } UserProfileView.prototype.template = _.template(Template); + UserProfileView.prototype.events = { + "click #follow-button": function() { + return vent.trigger("user:follow", this.model); + }, + "click #follow-button-login": function() { + return vent.trigger("app:login", this.model); + } + }; + + UserProfileView.prototype.initialize = function() { + return this.listenTo(this.model, 'change:is_following', this.render); + }; + UserProfileView.prototype.templateHelpers = { humanise: function(date) { return moment(date).fromNow(); diff --git a/templates/views/UserListItemView.html b/templates/views/UserListItemView.html index 24b31b6..e220dde 100755 --- a/templates/views/UserListItemView.html +++ b/templates/views/UserListItemView.html @@ -107,4 +107,4 @@
-
\ No newline at end of file + diff --git a/templates/views/UserProfileView.html b/templates/views/UserProfileView.html index 1ea004a..bc80cca 100644 --- a/templates/views/UserProfileView.html +++ b/templates/views/UserProfileView.html @@ -6,9 +6,9 @@
+ class="editable img-responsive image-user-profile" + alt="Avatar Image" + src="<%= avatar_image %>">
@@ -51,106 +51,106 @@ -
+
{% comment %} - + + + Send a message + {% endcomment %} + + + Profile Link +
- +
+ {% comment %} + + +
+ +
+ +
+
+