Refactored user edit view

This commit is contained in:
Fergal Moran
2013-05-25 16:28:37 +01:00
parent 31447390c4
commit dee2201a4f
32 changed files with 330 additions and 865 deletions

View File

@@ -20,7 +20,7 @@ class UserProfileResource(BackboneCompatibleResource):
authentication = Authentication()
def _hydrateBitmapOption(self, source, comparator):
return "checked" if (source & comparator) != 0 else ""
return True if (source & comparator) != 0 else False
def hydrate(self, bundle):
if 'activity_sharing_likes' in bundle.data:

View File

@@ -70,4 +70,4 @@ define ['backbone', 'marionette', 'app.lib/router', 'app.lib/panningRegion', 'vi
sidebarView = new SidebarView();
App.sidebarRegion.show(sidebarView)
App;
return App;

View File

@@ -8,11 +8,12 @@ requirejs.config({
underscore: 'libs/backbone/underscore',
text: 'libs/text',
templates: '/templates',
app: 'app/appv2',
views: 'app/views',
models: 'app/models',
app: 'app/appv2',
'app.lib': 'app/lib',
moment: 'libs/moment'
moment: 'libs/moment',
toastr: 'libs/toastr'
},
shim: {
backbone: {
@@ -25,11 +26,17 @@ requirejs.config({
},
underscore: {
exports: '_'
}
},
'toastr': {
deps: ['jquery'],
exports: 'toastr'
}
}
});
requirejs(['backbone', 'app'], function (Backbone, App) {
requirejs(['toastr', 'underscore', 'backbone', 'app'], function (toastr, _, Backbone, App) {
"require strict"
console.log("Dss.Bootstrapper: primed");
App.start();
});

View File

@@ -1,5 +1,7 @@
define ['app', 'marionette', 'models/mix/item', 'views/mix/list', 'views/mix/detail', 'views/mix/edit'],
(App, Marionette, MixItem, MixListView, MixDetailView, MixEditView)->
define ['app', 'marionette',
'models/mix/item', 'views/mix/list', 'views/mix/detail', 'views/mix/edit',
'models/user/item', 'views/user/userEditView'],
(App, Marionette, MixItem, MixListView, MixDetailView, MixEditView, UserItem, UserEditView)->
class DssController extends Marionette.Controller
home: ->
console.log "Controller: home"
@@ -38,4 +40,14 @@ define ['app', 'marionette', 'models/mix/item', 'views/mix/list', 'views/mix/det
user: (slug) ->
@showMixList('latest', {user: slug})
editUser: () ->
console.log("Controller: editUser")
app = require('app')
user = new UserItem({id: com.podnoms.settings.currentUser })
user.fetch(
success: ->
app.contentRegion.show(new UserEditView(model: user))
)
true
DssController

View File

@@ -1,17 +1,16 @@
// Generated by CoffeeScript 1.6.2
// Generated by CoffeeScript 1.3.3
(function() {
var __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', 'marionette', 'models/mix/item', 'views/mix/list', 'views/mix/detail', 'views/mix/edit'], function(App, Marionette, MixItem, MixListView, MixDetailView, MixEditView) {
var DssController, _ref;
define(['app', 'marionette', 'models/mix/item', 'views/mix/list', 'views/mix/detail', 'views/mix/edit', 'models/user/item', 'views/user/userEditView'], function(App, Marionette, MixItem, MixListView, MixDetailView, MixEditView, UserItem, UserEditView) {
var DssController;
DssController = (function(_super) {
__extends(DssController, _super);
function DssController() {
_ref = DssController.__super__.constructor.apply(this, arguments);
return _ref;
return DssController.__super__.constructor.apply(this, arguments);
}
DssController.prototype.home = function() {
@@ -22,7 +21,6 @@
DssController.prototype.showMixList = function(type, options) {
var app;
console.log("Controller: showMixList");
type = type || "latest";
app = require('app');
@@ -34,7 +32,6 @@
DssController.prototype.showMix = function(slug) {
var app, mix;
console.log("Controller: showMix");
app = require('app');
mix = new MixItem({
@@ -53,7 +50,6 @@
DssController.prototype.editMix = function(slug) {
var app, mix;
console.log("Controller: mixEdit");
app = require('app');
mix = new MixItem({
@@ -75,6 +71,23 @@
});
};
DssController.prototype.editUser = function() {
var app, user;
console.log("Controller: editUser");
app = require('app');
user = new UserItem({
id: com.podnoms.settings.currentUser
});
user.fetch({
success: function() {
return app.contentRegion.show(new UserEditView({
model: user
}));
}
});
return true;
};
return DssController;
})(Marionette.Controller);

View File

@@ -4,6 +4,9 @@ define ["marionette"],
events:
"change input": "changed"
"change textarea": "changed"
templateHelpers:
renderCheckbox: (value) ->
return (if value then "checked" else "")
changeSelect: (evt) ->
changed = evt.currentTarget

View File

@@ -1,17 +1,16 @@
// Generated by CoffeeScript 1.6.2
// Generated by CoffeeScript 1.3.3
(function() {
var __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(["marionette"], function(Marionette) {
var EditableView, _ref;
var EditableView;
EditableView = (function(_super) {
__extends(EditableView, _super);
function EditableView() {
_ref = EditableView.__super__.constructor.apply(this, arguments);
return _ref;
return EditableView.__super__.constructor.apply(this, arguments);
}
EditableView.prototype.events = {
@@ -19,9 +18,14 @@
"change textarea": "changed"
};
EditableView.prototype.templateHelpers = {
renderCheckbox: function(value) {
return (value ? "checked" : "");
}
};
EditableView.prototype.changeSelect = function(evt) {
var changed, obj, objInst, value;
changed = evt.currentTarget;
if (id) {
value = $(evt.currentTarget).val();
@@ -33,7 +37,6 @@
EditableView.prototype.changed = function(evt) {
var changed, obj, objInst, value;
return;
changed = evt.currentTarget;
if (changed.id) {
@@ -53,7 +56,6 @@
EditableView.prototype._bakeForm = function(el, lookups) {
var labels, mapped, model;
model = this.model;
labels = void 0;
mapped = void 0;
@@ -106,7 +108,6 @@
EditableView.prototype._saveChanges = function() {
var args, error, _results;
args = arguments;
if (!this.model.isValid()) {
if (this.model.errors) {

View File

@@ -12,6 +12,7 @@ define ['marionette', 'app.lib/controller'],
"mix/edit/:slug": "editMix",
"user/:slug": "user"
"me": "editUser"

View File

@@ -1,17 +1,16 @@
// Generated by CoffeeScript 1.6.2
// Generated by CoffeeScript 1.3.3
(function() {
var __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(['marionette', 'app.lib/controller'], function(Marionette, Controller) {
var DssRouter, _ref;
var DssRouter;
return DssRouter = (function(_super) {
__extends(DssRouter, _super);
function DssRouter() {
_ref = DssRouter.__super__.constructor.apply(this, arguments);
return _ref;
return DssRouter.__super__.constructor.apply(this, arguments);
}
DssRouter.prototype.controller = new Controller;
@@ -23,7 +22,8 @@
"mixes/:type": "showMixList",
"mix/:slug": "showMix",
"mix/edit/:slug": "editMix",
"user/:slug": "user"
"user/:slug": "user",
"me": "editUser"
};
return DssRouter;

View File

@@ -1,19 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
var Activity = DSSModel.extend({
urlRoot:com.podnoms.settings.urlRoot + "activity/"
});
var ActivityCollection = TastypieCollection.extend({
model: Activity,
url:com.podnoms.settings.urlRoot + "activity/",
comparator: function (activity) {
return -activity.get("id");
}
});

View File

@@ -1,18 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
var Comment = DSSModel.extend({
urlRoot:com.podnoms.settings.urlRoot + "comments/"
});
var CommentCollection = TastypieCollection.extend({
model:Comment,
comparator: function(comment){
return -comment.get("id");
}
});

View File

@@ -1,6 +0,0 @@
// Generated by CoffeeScript 1.3.3
(function() {
}).call(this);

View File

@@ -1,26 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
window.Mix = DSSModel.extend({
urlRoot:com.podnoms.settings.urlRoot + "mix/",
schema:{
title:'Text',
description:'Text'
},
isValid:function () {
this.errors = {};
if (com.podnoms.utils.isEmpty(this.get('title'))) {
return this.addError('title', 'Please enter a title');
}
return "";
}
});
window.MixCollection = TastypieCollection.extend({
url:com.podnoms.settings.urlRoot + "mix/",
model:Mix
});

View File

@@ -1,29 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
var User = DSSModel.extend({
urlRoot:com.podnoms.settings.urlRoot + "user/",
isValid: function () {
this.errors = {};
return "";
},
avatarGravatar: function(){
return this.get('profile').avatar_type == 'gravatar';
},
avatarSocial: function(){
return this.get('profile').avatar_type == 'social';
},
avatarCustom: function(){
return this.get('profile').avatar_type == 'custom';
}
});
var UserCollection = TastypieCollection.extend({
model: User,
url:com.podnoms.settings.urlRoot + "users/"
});

View File

@@ -0,0 +1,8 @@
define ['backbone', 'models/user/item', 'app.lib/backbone.dss.model.collection'], \
(Backbone, UserItem, DssCollection) ->
class UserCollection extends DssCollection
model: UserItem
url:com.podnoms.settings.urlRoot + "user/"
UserCollection

View File

@@ -0,0 +1,26 @@
// Generated by CoffeeScript 1.3.3
(function() {
var __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(['backbone', 'models/user/item', 'app.lib/backbone.dss.model.collection'], function(Backbone, UserItem, DssCollection) {
var UserCollection;
UserCollection = (function(_super) {
__extends(UserCollection, _super);
function UserCollection() {
return UserCollection.__super__.constructor.apply(this, arguments);
}
UserCollection.prototype.model = UserItem;
UserCollection.prototype.url = com.podnoms.settings.urlRoot + "user/";
return UserCollection;
})(DssCollection);
return UserCollection;
});
}).call(this);

View File

@@ -0,0 +1,6 @@
define ['app.lib/backbone.dss.model'], \
(DssModel) ->
class UserItem extends DssModel
urlRoot: com.podnoms.settings.urlRoot + "user/"
UserItem

View File

@@ -0,0 +1,24 @@
// Generated by CoffeeScript 1.3.3
(function() {
var __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.lib/backbone.dss.model'], function(DssModel) {
var UserItem;
UserItem = (function(_super) {
__extends(UserItem, _super);
function UserItem() {
return UserItem.__super__.constructor.apply(this, arguments);
}
UserItem.prototype.urlRoot = com.podnoms.settings.urlRoot + "user/";
return UserItem;
})(DssModel);
return UserItem;
});
}).call(this);

View File

@@ -1,33 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
window.ActivityListItemView = Backbone.View.extend({
tagName:"li",
initialize:function () {
$(this.el).data("id", this.model.get("id"));
$(this.el).addClass("media");
},
render:function () {
$(this.el).html(this.template({"item":this.model.toJSON()}));
return this;
}
});
window.ActivityListView = Backbone.View.extend({
initialize:function () {
//this.collection.bind('add', this.render);
this.render();
},
render:function () {
$(this.el).html(this.template()).append('<ul class="activity-listing media-list"></ul>');
this.collection.each(function (item) {
$('.activity-listing', this.el).append(new ActivityListItemView({model:item}).render().el);
}, this);
return this;
}
});

View File

@@ -1,54 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
window.CommentListItemView = Backbone.View.extend({
tagName:"li",
initialize:function () {
$(this.el).data("id", this.model.get("id"));
$(this.el).addClass("comment-entry");
},
render:function () {
$(this.el).html(this.template({"item":this.model.toJSON()}));
return this;
}
});
window.CommentListView = Backbone.View.extend({
initialize:function () {
//this.collection.bind('add', this.render);
},
events:{
"click #id-btn-add-comment":"addComment"
},
addComment:function (ev) {
var comment = $('textarea[name=new-comment]').val();
var view = this;
if (comment) {
this.collection.create({
mix:this.collection.mix,
comment:comment,
time_index:15
}, {
success:function () {
view.collection.sort();
view.render();
},
error:function () {
com.podnoms.utils.showError("Error", "Unable to save comment");
}});
$('textarea[name=new-comment]').val('');
}
return false;
},
render:function () {
$(this.el).html(this.template()).append('<ul class="comment-listing list-nostyle"></ul>');
this.collection.each(function (item) {
$('.comment-listing', this.el).append(new CommentListItemView({model:item}).render().el);
}, this);
return this;
}
});

View File

@@ -1,383 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
window.MixListItemView = DSSEditableView.extend({
tagName: "li",
events: {
"click .play-button-small-start": "startMix",
"click .play-button-small-resume": "resume",
"click .play-button-small-pause": "pauseMix",
"click .mix-link": "mixLink",
"click .like-button a": "likeMix",
"click .favourite-button a": "favouriteMix",
"click .share-button": "shareLink",
"click .download-button a": "downloadMix"
//"mouseover .mix-profile-insert": "mouseOverProfile"
},
initialize: function () {
$(this.el).attr("id", "mixitem-" + this.model.get("id"));
$(this.el).addClass("audio-listing-item");
$(this.el).data("id", this.model.get("id"));
},
render: function () {
$(this.el).html(this.template({"item": this.model.toJSON()}));
var id = this.model.get("id");
var parent = this;
this.setLikeButton(id, this.model.get('liked'));
this.setFavouriteButton(id, this.model.get('favourited'));
$.each(this.model.get("genre-list"), function (data) {
$('#genre-list', parent.el).append(
'<a href="/mixes/' + this.slug + '" class="dss-tag-button">' + this.text + '</a>');
});
if (this.model.get('duration')){
if (com.podnoms.settings.drawTimelineOnMix) {
com.podnoms.player.drawTimeline(
$('#player-timeline-' + id, this.el),
this.model.get('duration'));
} else {
$('#player-timeline-' + id, this.el).hide();
}
var totalDuration = moment.duration(this.model.get('duration'), "seconds");
var totalDurationText = totalDuration.hours() != 0 ?
moment(totalDuration).format("HH:mm:ss") :
moment(totalDuration).format("mm:ss");
$('#player-duration-' + id, this.el).text(totalDurationText);
}
return this;
},
mouseOverProfile: function () {
var e = $(this.el);
$.get(e.data('poload'), function (d) {
e.popover({content: d}).popover('show');
});
},
setLikeButton: function (id, liked) {
if (liked) {
$('#like-' + id, this.el).html('<i class="icon-heart"></i> Unlike');
$('#like-' + id, this.el).data('loading-text', 'Unliking');
} else {
$('#like-' + id, this.el).html('<i class="icon-heart"></i> Like');
$('#like-' + id, this.el).data('loading-text', 'Liking');
}
},
setFavouriteButton: function (id, liked) {
if (liked) {
$('#favourite-' + id, this.el).html('<i class="icon-star-empty"></i> Unfavourite');
} else
$('#favourite-' + id, this.el).html('<i class="icon-star"></i> Favourite');
},
shareLink: function (e) {
var id = $(e.currentTarget).data("id");
var mode = $(e.currentTarget).data("mode");
if (mode == "facebook")
sharePageToFacebook(this.model);
else if (mode == "twitter")
sharePageToTwitter(this.model);
},
downloadMix: function (e) {
var id = $(e.currentTarget).data("id");
var mode = $(e.currentTarget).data("mode");
com.podnoms.utils.downloadURL("/audio/download/" + id);
return false;
},
mixLink: function (e) {
},
likeMix: function (e) {
var parent = this;
var button = $(e.currentTarget);
var id = button.data("id");
var mode = button.data("mode");
var self = this;
button.button('loading');
$.post(
"/ajax/like/",
{ dataId: id, dataMode: mode },
function (data) {
button.button('reset');
var result = JSON.parse(data);
if (result.value == "Liked") {
parent.setLikeButton(id, true);
com.podnoms.utils.showAlert("Success", "Thanks for liking!!");
} else if (result.value == "Unliked") {
parent.setLikeButton(id, false);
com.podnoms.utils.showAlert("Success", "Mix unliked!!");
}
}
);
},
favouriteMix: function (e) {
var id = $(e.currentTarget).data("id");
var mode = $(e.currentTarget).data("mode");
var self = this;
$.post(
"/ajax/favourite/",
{ dataId: id, dataMode: mode },
function (data) {
var result = $.parseJSON(data);
self.setFavouriteButton(id, result.value == 'Favourited');
if (result.value == 'Favourited')
postFacebookFavourite(this.id);
}
);
},
pauseMix: function () {
com.podnoms.player.pause();
_eventAggregator.trigger("track_paused");
},
resume: function () {
_eventAggregator.trigger("track_playing");
com.podnoms.player.resume();
},
startMix: function () {
var id = $(this.el).data("id");
var mode = "play";
var ref = this;
$.getJSON(
'/ajax/mix_stream_url/' + id + '/',
function (data) {
com.podnoms.settings.setupPlayer(data, id);
com.podnoms.player.startPlaying({
success: function () {
_eventAggregator.trigger("track_playing");
_eventAggregator.trigger("track_changed", data);
com.podnoms.utils.checkPlayCount();
},
error: function () {
com.podnoms.utils.showWarning(
"Ooops",
"Error playing mix. If you have a flash blocker, please disable it for this site. Otherwise, do please try again.");
}
});
com.podnoms.storage.setItem('now_playing', id);
}
);
}
});
window.MixListView = Backbone.View.extend({
itemPlaying: null,
initialize: function () {
_.bindAll(this, "render");
this.render();
this.infiniScroll = new Backbone.InfiniScroll(this.collection, {success: this.appendRender});
},
remove: function () {
this.infiniScroll.destroy();
return Backbone.View.prototype.remove.call(this);
},
render: function () {
var mixes = this.collection;
var el = this.el;
var ref = this;
$(this.el).html(this.template()).append('<ul class="mix-listing audio-listing"></ul>');
this.collection.each(function (item) {
$('.mix-listing', el).append(new MixListItemView({model: item}).render().el);
if (com.podnoms.player.isPlayingId(item.get('id'))) {
ref.itemPlaying = item;
}
});
var type = this.collection.type;
$('#' + type, this.el).parent().addClass('active');
$('a[data-toggle=popover]', el)
.popover({'trigger': 'manual'})
.click(function (e) {
e.preventDefault()
});
return this;
}
});
window.MixView = Backbone.View.extend({
initialize: function () {
this.render();
},
render: function () {
var el = this.el;
$(this.el).html(this.template());
var item = new MixListItemView({model: this.model}).render();
$('.mix-listing', this.el).append(item.el);
$('#mix-description', this.el).html(this.model.get("description"));
/*
var comments = this.model.get("comments");
var content = new CommentListView({collection:comments}).render();
$('#mix-comments', el).html(content.el);
*/
var comments = new CommentCollection();
comments.url = this.model.get("resource_uri") + "comments/";
comments.mix_id = this.model.id;
comments.mix = this.model.get("resource_uri");
comments.fetch({success: function (data) {
var content = new CommentListView({collection: comments}).render();
$('#mix-comments', el).html(content.el);
}});
$('#mix-tab a:first', el).tab('show');
return this;
}
});
window.MixCreateView = DSSEditableView.extend({
events: {
"click #save-changes": "saveChanges",
"change #mix_image": "imageChanged"
},
checkRedirect: function () {
if (this.state == 2) {
Backbone.history.navigate('/mix/' + this.model.get('slug'), {trigger: true});
}
},
initialize: function () {
this.guid = com.podnoms.utils.generateGuid();
this.state = 0;
this.render();
},
render: function () {
this.sendImage = false;
if (!ich['mix'])
ich.addTemplate('mix', this.template());
var renderedTemplate = ich.mix(this.model.toJSON());
$(this.el).html(renderedTemplate);
var parent = this;
if (this.model.id == undefined) {
$('#mix-upload', this.el).uploadifive({
'uploadScript': '/ajax/upload_mix_file_handler/',
buttonText: "Select audio file (mp3 for now please)",
'formData': {
'upload-hash': this.guid,
'sessionid': $.cookie('sessionid')
},
'onUploadFile': function (file) {
$(window).on('beforeunload', function () {
alert('Go on outta that..');
});
},
'onAddQueueItem': function (file) {
$('#upload-extension', this.el).val(file.name.split('.').pop());
$('#mix-details', this.el).show();
},
'onProgress': function (file, e) {
},
'onUploadComplete': function (file, data) {
parent.state++;
parent.checkRedirect();
}
});
$('.fileupload', this.el).fileupload({
'uploadtype': 'image'
});
$('#mix-details', this.el).hide();
$('.upload-hash', this.el).val(this.guid);
} else {
$('#div-upload-mix', this.el).hide();
this.state = 1;
}
$('#image-form-proxy', this.el).ajaxForm({
beforeSubmit: function () {
$('#results').html('Submitting...');
},
success: function (data) {
var $out = $('#results');
$out.html('Your results:');
$out.append('<div><pre>' + data + '</pre></div>');
}
});
$("#genres", this.el).select2({
placeholder: "Start typing and choose or press enter",
minimumInputLength: 1,
multiple: true,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "/ajax/lookup/genre/",
dataType: 'json',
data: function (term, page) {
return {
q: term
};
},
results: function (data, page) { // parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to alter remote JSON data
return {results: data};
}
}, initSelection: function (element, callback) {
var result = [];
var genres = parent.model.get('genre-list');
if (genres != undefined) {
$.each(genres, function (data) {
result.push({id: this.id, text: this.text});
});
}
callback(result);
},
createSearchChoice: function (term, data) {
if ($(data).filter(function () {
return this.text.localeCompare(term) === 0;
}).length === 0) {
return {id: term, text: term};
}
}
});
return this;
},
saveChanges: function () {
var ref = this;
var data = Backbone.Syphon.serialize(this);
this.model.set(data);
this.model.set('upload-hash', this.guid);
this.model.set('upload-extension', $('#upload-extension', this.el).val());
this.model.set('genre-list', $('#genres', this.el).select2('data'));
if (!ref.sendImage)
this.model.set('mix_image', 'DONOTSEND');
this._saveChanges({
success: function () {
if (ref.sendImage) {
$.ajaxFileUpload({
url: '/ajax/upload_image/' + ref.model.get('id') + '/',
secureuri: false,
fileElementId: 'mix_image',
success: function (data, status) {
if (typeof(data.error) != 'undefined') {
if (data.error != '') {
alert(data.error);
} else {
alert(data.msg);
}
} else {
$('#mix-details', this.el).hide();
ref.state++;
ref.checkRedirect();
}
},
error: function (data, status, e) {
alert(e);
}
});
} else {
$('#mix-details', this.el).hide();
ref.state++;
ref.checkRedirect();
}
},
error: function (model, response) {
com.podnoms.utils.showError("Error", "Something went wrong<br />Nerd stuff is: " + response);
}
});
return false;
},
imageChanged: function (evt) {
this.sendImage = true;
}
});

View File

@@ -1,99 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
define(['marionette', 'views/activity/list', 'text!/tpl/SidebarView'],
function (Marionette, ActivityListView, Template) {
return Marionette.View.extend({
template: _.template(Template),
events: {
"click #sidebar-play-pause-button-small": "togglePlayState",
"click #sidebar-listen-live": "playLive"
},
initialize: function () {
this.render();
_.bindAll(this, "trackChanged");
_.bindAll(this, "trackPlaying");
_.bindAll(this, "trackPaused");
window._eventAggregator.bind("track_changed", this.trackChanged);
window._eventAggregator.bind("track_playing", this.trackPlaying);
window._eventAggregator.bind("track_paused", this.trackPaused);
$.getJSON(
'ajax/live_now_playing/',
function (data) {
$("#live-now-playing", this.el).text(data.title);
});
},
render: function () {
console.log("Sidebar: Render");
$(this.el).html(this.template());
var activityListView = new ActivityListView();
$('#sidebar-content-activity', this.el).html(activityListView.el);
/*
var activity = new ActivityCollection();
activity.fetch({
success: function () {
var content = new ActivityListView({
collection: activity
}).el;
$('#sidebar-content-activity', this.el).html(content);
}
});
*/
return this;
},
togglePlayState: function () {
},
trackChanged: function (data) {
$(this.el).find('#now-playing').text(data.title);
if (data.item_url != undefined)
$(this.el).find('#now-playing').attr("href", "#" + data.item_url);
},
trackPlaying: function (data) {
$(this.el).find('#header-play-button-icon').removeClass('icon-play');
$(this.el).find('#header-play-button-icon').addClass('icon-pause');
},
trackPaused: function (data) {
$(this.el).find('#header-play-button-icon').removeClass('icon-pause');
$(this.el).find('#header-play-button-icon').addClass('icon-play');
},
playLive: function () {
var liveButton = $(this.el).find('#sidebar-listen-live');
if ((liveButton).hasClass('btn-danger')) {
com.podnoms.player.stopPlaying();
liveButton.removeClass('btn-danger').addClass('btn-success').text('Listen live');
liveButton.blur();
} else {
liveButton.button('loading');
com.podnoms.player.playLive({
success: function () {
$.getJSON(
'ajax/live_now_playing/',
function (data) {
$('#live-now-playing', el).text(data.title);
data.title += " (live)";
window._eventAggregator.trigger("track_changed", data);
liveButton.button('reset');
liveButton.removeClass('btn-success').addClass('btn-danger').text('Stop listening');
}
);
}
});
}
window._eventAggregator.trigger("track_playing")
var button = $(this.el).find('#sidebar-play-pause-button-small');
var el = this.el;
button
.removeClass('play-button-small-start')
.removeClass('play-button-small-loading')
.addClass('play-button-small-pause');
}
});
});

View File

@@ -1,56 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
window.SidebarViewUser = Backbone.View.extend({
events: {
"click #follow-button": "toggleFollow"
},
render: function () {
ich.addTemplate('sidebaruser', this.template());
this.model.formatDate = function (date) {
return 'Yaaaaaaa....';
};
$(this.el).html(ich.sidebaruser(this.model.toJSON()));
this._renderFollowButton();
return this;
},
_renderFollowButton: function () {
if (this.model.get('profile').following) {
$('#follow-button', this.el).addClass("btn-warning disabled");
$('#follow-button', this.el).removeClass("btn-success");
$('#follow-button', this.el).text("Unfollow");
$('#follow-icon', this.el).addClass("icon-eye-close");
$('#follow-icon', this.el).removeClass("icon-eye-open");
} else {
$('#follow-button', this.el).removeClass("btn-warning disabled");
$('#follow-button', this.el).addClass("btn-success");
$('#follow-button', this.el).text("Follow");
$('#follow-icon', this.el).removeClass("icon-eye-close");
$('#follow-icon', this.el).addClass("icon-eye-open");
}
},
toggleFollow: function () {
var ref = this;
$('#follow-button', this.el).addClass("loading");
$.post(
"/ajax/toggle_follow/",
{ userId: this.model.get("id") },
function (data) {
var result = $.parseJSON(data);
if (result.value == 'Followed')
ref.model.get('profile').following = true;
else
ref.model.get('profile').following = false;
ref._renderFollowButton();
$('#follow-button', this.el).removeClass("loading");
}
);
}
});

View File

@@ -0,0 +1,67 @@
define ['app', 'toastr', 'app.lib/editableView', 'moment', 'libs/backbone/backbone.syphon', 'text!/tpl/UserEditView'],
(App, toastr, EditableView, moment, Syphon, Template) ->
class UserEditView extends EditableView
template: _.template(Template)
events:
"click #save-changes": "saveChanges",
"change input[type=radio]": "selectAvatar"
onRender: ->
console.log("MixEditView: onRender")
avatarType = @model.get('profile').avatar_type
$('#avatar_' + avatarType, @el).attr('checked', true);
if avatarType is "custom"
$("#div_avatar_image_upload", @el).show()
$("#file_upload").uploadifive uploadScript: "ajax/upload_avatar_image/"
else
$("#div_avatar_image_upload", this.el).hide();
true
selectAvatar: (evt) ->
type = $(evt.currentTarget).val()
@model.set "avatar_type", type
if type is "custom"
$("#div_avatar_image_upload", @el).show()
$("#file_upload").uploadifive uploadScript: "ajax/upload_avatar_image/"
else
$("#div_avatar_image_upload", @el).hide()
saveChanges: ->
data = Backbone.Syphon.serialize(this)
@model.set data
ref = this
@_saveChanges
success: ->
if ref.model.get("profile").avatar_type is "custom"
$.ajaxFileUpload
url: "/ajax/upload_avatar_image/"
secureuri: false
fileElementId: "avatar_image"
success: (data, status) ->
unless typeof (data.error) is "undefined"
unless data.error is ""
alert data.error
else
alert data.msg
else
toastr.info "Successfully updated yourself"
Backbone.history.navigate "/",
trigger: true
error: (data, status, e) ->
alert e
else
toastr.info "Successfully updated yourself"
Backbone.history.navigate "/",
trigger: true
true
error: ->
toastr.error "There was an error updating your info. Please try again later."
true
true
false
UserEditView

View File

@@ -0,0 +1,107 @@
// Generated by CoffeeScript 1.3.3
(function() {
var __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', 'toastr', 'app.lib/editableView', 'moment', 'libs/backbone/backbone.syphon', 'text!/tpl/UserEditView'], function(App, toastr, EditableView, moment, Syphon, Template) {
var UserEditView;
UserEditView = (function(_super) {
__extends(UserEditView, _super);
function UserEditView() {
return UserEditView.__super__.constructor.apply(this, arguments);
}
UserEditView.prototype.template = _.template(Template);
UserEditView.prototype.events = {
"click #save-changes": "saveChanges",
"change input[type=radio]": "selectAvatar"
};
UserEditView.prototype.onRender = function() {
var avatarType;
console.log("MixEditView: onRender");
avatarType = this.model.get('profile').avatar_type;
$('#avatar_' + avatarType, this.el).attr('checked', true);
if (avatarType === "custom") {
$("#div_avatar_image_upload", this.el).show();
$("#file_upload").uploadifive({
uploadScript: "ajax/upload_avatar_image/"
});
} else {
$("#div_avatar_image_upload", this.el).hide();
}
return true;
};
UserEditView.prototype.selectAvatar = function(evt) {
var type;
type = $(evt.currentTarget).val();
this.model.set("avatar_type", type);
if (type === "custom") {
$("#div_avatar_image_upload", this.el).show();
return $("#file_upload").uploadifive({
uploadScript: "ajax/upload_avatar_image/"
});
} else {
return $("#div_avatar_image_upload", this.el).hide();
}
};
UserEditView.prototype.saveChanges = function() {
var data, ref;
data = Backbone.Syphon.serialize(this);
this.model.set(data);
ref = this;
this._saveChanges({
success: function() {
if (ref.model.get("profile").avatar_type === "custom") {
$.ajaxFileUpload({
url: "/ajax/upload_avatar_image/",
secureuri: false,
fileElementId: "avatar_image",
success: function(data, status) {
if (typeof data.error !== "undefined") {
if (data.error !== "") {
return alert(data.error);
} else {
return alert(data.msg);
}
} else {
toastr.info("Successfully updated yourself");
return Backbone.history.navigate("/", {
trigger: true
});
}
},
error: function(data, status, e) {
return alert(e);
}
});
} else {
toastr.info("Successfully updated yourself");
Backbone.history.navigate("/", {
trigger: true
});
}
return true;
},
error: function() {
toastr.error("There was an error updating your info. Please try again later.");
return true;
}
});
return true;
};
false;
return UserEditView;
})(EditableView);
return UserEditView;
});
}).call(this);

View File

@@ -1,4 +1,4 @@
define ['marionette'],
(Marionette)->
define ['app', 'marionette'],
(App, Marionette)->
class UserItemView extends Marionette.ItemView
itemView: UserItemView
itemView: UserItemView

View File

@@ -3,7 +3,7 @@
var __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(['marionette'], function(Marionette) {
define(['app', 'marionette'], function(App, Marionette) {
var UserItemView;
return UserItemView = (function(_super) {

View File

@@ -1,13 +1,10 @@
define ['marionette', 'views/user/userItem'],
define ['marionette', 'views/user/userItemView'],
(Marionette, UserItemView) ->
class UserListView extends Marionette.CompositeView
template: "<h1>Hello Sailor</h1"
itemView: UserItemView
itemViewContainer: "#content"
tagName: "li"
initialize: ->
console.log "User list view initializing"
return UserListView

View File

@@ -1,84 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
UserEditView = DSSEditableView.extend({
events: {
"click #save-changes": "saveChanges",
"change input[type=radio]": "selectAvatar"
},
render: function () {
ich.addTemplate('user', this.template());
var renderedTemplate = ich.user(this.model.toJSON());
$(this.el).html(renderedTemplate);
$("#div_avatar_image_upload", this.el).hide();
var avatarType = this.model.get('profile').avatar_type;
if (!com.podnoms.utils.isEmpty(avatarType)){
$('#avatar_' + avatarType, this.el).attr('checked', true);
if (avatarType == 'custom') {
$("#div_avatar_image_upload", this.el).show();
$('#file_upload').uploadifive({
'uploadScript': 'ajax/upload_avatar_image/'
});
}
}
return this;
},
saveChanges: function () {
var data = Backbone.Syphon.serialize(this);
this.model.set(data);
var ref = this;
this._saveChanges({
success: function () {
if (ref.model.get('profile').avatar_type == 'custom'){
$.ajaxFileUpload({
url: '/ajax/upload_avatar_image/',
secureuri: false,
fileElementId: 'avatar_image',
success: function (data, status) {
if (typeof(data.error) != 'undefined') {
if (data.error != '') {
alert(data.error);
} else {
alert(data.msg);
}
} else {
com.podnoms.utils.showAlert("Success", "Successfully updated yourself");
Backbone.history.navigate('/', {trigger:true});
}
},
error: function (data, status, e) {
alert(e);
}
});
}else{
com.podnoms.utils.showAlert("Success", "Successfully updated yourself");
Backbone.history.navigate('/', {trigger:true});
}
},
error: function () {
com.podnoms.utils.showError("Error", "There was an error updating your info. Please try again later.");
}
});
return false;
},
selectAvatar: function (evt) {
var type = $(evt.currentTarget).val();
this.model.set('avatar_type', type);
if (type == 'custom') {
$("#div_avatar_image_upload", this.el).show();
$('#file_upload').uploadifive({
'uploadScript': 'ajax/upload_avatar_image/'
});
}else{
$("#div_avatar_image_upload", this.el).hide();
}
}
});

View File

@@ -1,16 +1,16 @@
/*
* Copyright 2012 John Papa and Hans Fjäemark.
* Copyright 2012 John Papa and Hans Fjällemark.
* All Rights Reserved.
* Use, reproduction, distribution, and modification of this code is subject to the terms and
* conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php
*
* Author: John Papa and Hans Fjäemark
* Author: John Papa and Hans Fjällemark
* Project: https://github.com/CodeSeven/toastr
*/
; (function (define) {
define(['jquery'], function ($) {
return (function () {
var version = '1.2.3',
var version = '1.3.0',
$container,
defaults = {
@@ -229,4 +229,4 @@
} else {
window['toastr'] = factory(window['jQuery']);
}
}));
}));

View File

@@ -5,7 +5,7 @@
<div id="layout-area" class="hero-well">
<div class="row">
<form enctype="multipart/form-data" method="post" class="form-horizontal" id="id-new-user-form">
<input type="hidden" name="profile[id]" value="{{ profile.id }}"/>
<input type="hidden" name="profile[id]" value="<%= profile.id %>"/>
<fieldset>
<div class="span6">
<div class="clearfix control-group" id="div_display_name">
@@ -13,7 +13,7 @@
<div class="controls">
<input type="text" maxlength="75" name="profile[display_name]" class="textinput textInput"
id="profile[display_name]"
value="{{ profile.display_name }}">
value="<%= profile.display_name %>">
</div>
</div>
<div class="clearfix control-group" id="div_slug">
@@ -21,14 +21,14 @@
<div class="controls">
<input type="text" maxlength="75" name="profile[slug]" class="textinput textInput"
id="profile[slug]"
value="{{ profile.slug }}">
value="<%= profile.slug %>">
</div>
</div>
<div class="clearfix control-group" id="div_email">
<label class="control-label" for="email">E-mail address</label>
<div class="controls">
<input type="text" maxlength="75" name="email" class="textinput textInput" id="email"
value="{{ email }}">
value="<%= email %>">
</div>
</div>
<div class="clearfix control-group" id="div_first_name">
@@ -36,7 +36,7 @@
<div class="controls">
<input type="text" maxlength="30" name="first_name" class="textinput textInput"
id="first_name"
value="{{ first_name }}">
value="<%= first_name %>">
</div>
</div>
<div class="clearfix control-group" id="div_last_name">
@@ -44,7 +44,7 @@
<div class="controls">
<input type="text" maxlength="30" name="last_name" class="textinput textInput"
id="last_name"
value="{{ last_name }}">
value="<%= last_name %>">
</div>
</div>
<div class="clearfix control-group" id="div_avatar_image_select">
@@ -62,7 +62,7 @@
<div class="fileupload fileupload-new pull-left" data-provides="fileupload"
id="div_avatar_image">
<div class="fileupload-new thumbnail" style="width: 200px; height: 150px;">
<img src="{{ profile[avatar_image] }}"/>
<img src="<%= profile.avatar_image %>"/>
</div>
<div class="fileupload-preview fileupload-exists thumbnail"
style="max-width: 200px; max-height: 150px; line-height: 20px;">
@@ -87,7 +87,7 @@
<p>
<h5>Tell us a bit about yourself.</h5>
</p>
<textarea style="width: 100%" name="profile[description]" id="profile[description]" rows="5">{{profile.description}}</textarea>
<textarea style="width: 100%" name="profile[description]" id="profile[description]" rows="5"><%= profile.description %></textarea>
</div>
<div class="row">
<p>
@@ -105,15 +105,15 @@
<tr>
<td>
<input type="checkbox" name="profile[activity_sharing_likes]"
id="activity_sharing_likes" {{ profile.activity_sharing_likes }}>
id="activity_sharing_likes" <%= renderCheckbox(profile.activity_sharing_likes) %>>
</td>
<td>
<input type="checkbox" name="profile[activity_sharing_favourites]"
id="activity_sharing_favourites" {{ profile.activity_sharing_favourites }}>
id="activity_sharing_favourites" <%= renderCheckbox(profile.activity_sharing_favourites) %>>
</td>
<td>
<input type="checkbox" name="profile[activity_sharing_comments]"
id="activity_sharing_comments" {{ profile.activity_sharing_comments }}>
id="activity_sharing_comments" <%= renderCheckbox(profile.activity_sharing_comments) %>>
</td>
</tr>
</tbody>
@@ -129,10 +129,10 @@
</tr>
<tr>
<td style="text-align: center; vertical-align: middle">
<input type="checkbox" name="profile[activity_sharing_networks_facebook]" {{ profile.activity_sharing_networks_facebook }}>
<input type="checkbox" name="profile[activity_sharing_networks_facebook]" <%= renderCheckbox(profile.activity_sharing_networks_facebook) %>>
</td>
<td>
<input type="checkbox" name="profile[activity_sharing_networks_twitter]" {{ profile.activity_sharing_networks_twitter }}>
<input type="checkbox" name="profile[activity_sharing_networks_twitter]" <%= renderCheckbox(profile.activity_sharing_networks_twitter) %>>
</td>
</tr>
</tbody>
@@ -149,4 +149,4 @@
</div>
</div>
</div>
{% endverbatim %}
{% endverbatim %}