This repository has been archived by the owner on Dec 1, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Minimal backbone version #11
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a176a13
drafted a base backbone app layout
n1k0 8cf1617
indentation, cs
n1k0 61468a9
auth form now handled through backbone
n1k0 f9ef6f4
Auth model; mv lib/ vendor/
n1k0 2516ec7
merge with fqueze/login
n1k0 84e50d5
minimal backbone version
n1k0 349c3c1
Merge remote-tracking branch 'upstream/master' into backbone-minimal
n1k0 dc4074e
sync with master
n1k0 b80fcb8
removed dependency to bower
n1k0 87669e9
Merge branch 'backbone-vendor' into backbone-minimal
n1k0 26a8196
Merge branch 'backbone-vendor' into backbone-minimal
n1k0 a880a14
updated links to static assets
n1k0 9857fb9
Merge branch 'backbone-vendor' into backbone-minimal
n1k0 6c56d4d
removed versioned vendors (grrr)
n1k0 1fbc521
fixed user wasn't removed from list on sign out
n1k0 79b3c6b
Merge remote-tracking branch 'upstream/master' into backbone-minimal
n1k0 9ffb28d
updated README.md
n1k0 49261b7
removed remaining references to bower
n1k0 f1a37dc
fixed coding standards
n1k0 4bf10e7
rethinking app modularization
n1k0 d262aac
avoid being to much defensive on the client side
n1k0 f9c591a
lighter CONTRIBUTING.md
n1k0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
test: mocha jshint | ||
|
||
mocha: | ||
@./node_modules/mocha/bin/mocha --reporter spec | ||
install: | ||
@npm install | ||
|
||
jshint: | ||
@jshint *.js static test | ||
|
||
mocha: | ||
@./node_modules/mocha/bin/mocha --reporter spec | ||
|
||
runserver: | ||
@env PORT=5000 node app.js | ||
|
||
.PHONY: test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/*global jQuery, Backbone*/ | ||
/* jshint unused: false */ | ||
var Talkilla = (function($, Backbone) { | ||
"use strict"; | ||
var app = {data: {}}; | ||
|
||
function login(nick, cb) { | ||
$.ajax({ | ||
type: "POST", | ||
url: '/signin', | ||
data: {nick: nick}, | ||
dataType: 'json' | ||
}) | ||
.done(function(auth) { | ||
return cb(null, | ||
new app.User({nick: auth.nick}), | ||
new app.UserSet(auth.users)); | ||
}) | ||
.fail(function(xhr, textStatus, error) { | ||
return cb(error); | ||
}); | ||
} | ||
|
||
function logout(cb) { | ||
$.ajax({ | ||
type: "POST", | ||
url: '/signout', | ||
data: {nick: app.data.user && app.data.user.get('nick')}, | ||
dataType: 'json' | ||
}) | ||
.done(function(result) { | ||
return cb(null, result); | ||
}) | ||
.fail(function(xhr, textStatus, error) { | ||
return cb(error); | ||
}); | ||
} | ||
|
||
app.Router = Backbone.Router.extend({ | ||
routes: { | ||
'': 'index' | ||
}, | ||
|
||
index: function() { | ||
// login form | ||
if (this.loginView) | ||
this.loginView.undelegateEvents(); | ||
this.loginView = new app.LoginView(app.data); | ||
this.loginView.render(); | ||
|
||
// users list | ||
if (this.usersView) | ||
this.usersView.undelegateEvents(); | ||
this.usersView = new app.UsersView(app.data); | ||
this.usersView.render(); | ||
} | ||
}); | ||
|
||
app.User = Backbone.Model.extend({ | ||
defaults: {nick: undefined} | ||
}); | ||
|
||
app.UserSet = Backbone.Collection.extend({ | ||
url: '/users', | ||
model: app.User | ||
}); | ||
|
||
app.UsersView = Backbone.View.extend({ | ||
el: '#users', | ||
|
||
initialize: function(options) { | ||
this.collection = options && options.users; | ||
if (this.collection) | ||
return this.render(); | ||
this.collection = new app.UserSet(); | ||
this.collection.fetch({ | ||
error: function() { | ||
alert('Could not load connected users list'); | ||
}, | ||
success: function(users) { | ||
this.render(); | ||
}.bind(this) | ||
}); | ||
}, | ||
|
||
render: function() { | ||
var $list = this.$el.find('ul'); | ||
$list.find('li:not([class=nav-header])').remove(); | ||
this.collection.each(function(user) { | ||
$list.append($('<li/>').text(user.get('nick'))); | ||
}); | ||
return this; | ||
} | ||
}); | ||
|
||
app.LoginView = Backbone.View.extend({ | ||
el: '#login', | ||
|
||
events: { | ||
'submit form#signin': 'signin', | ||
'submit form#signout': 'signout' | ||
}, | ||
|
||
initialize: function(options) { | ||
this.user = options && options.user; | ||
}, | ||
|
||
render: function() { | ||
if (!this.user) { | ||
this.$el.find('#signin').show(); | ||
this.$el.find('#signout').hide().find('.nick').text(''); | ||
} else { | ||
this.$el.find('#signin').hide(); | ||
this.$el.find('#signout').show().find('.nick') | ||
.text(this.user.get('nick')); | ||
} | ||
return this; | ||
}, | ||
|
||
signin: function(event) { | ||
event.preventDefault(); | ||
var nick = $.trim($(event.currentTarget).find('[name="nick"]').val()); | ||
if (!nick) | ||
return alert('please enter a nickname'); | ||
login(nick, function(err, user, users) { | ||
if (err) | ||
return alert(err); | ||
app.data.user = user; | ||
app.data.users = users; | ||
app.router.index(); | ||
}); | ||
}, | ||
|
||
signout: function(event) { | ||
event.preventDefault(); | ||
logout(function(err) { | ||
if (err) | ||
return alert(err); | ||
app.data.user = app.data.users = undefined; | ||
app.router.index(); | ||
}); | ||
} | ||
}); | ||
|
||
app.router = new app.Router(); | ||
Backbone.history.start(); | ||
return app; | ||
})(jQuery, Backbone); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why this was sending the reply before pushing the new nick to the users array is that this way I didn't have to filter the user's nick out of the received list of contacts on the front-end side (offering a user to call himself doesn't make sense).
I haven't searched very hard, but I didn't see any code in the front-end here that filters out the user's nick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of adding no link to the user's own entry adn maybe suffixing it with
(me)
… a bit like what some irc clients do, but now I'm not so sure :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now there is no UI to call someone, so it's not a bug (yet). We can decide what to do when the feature will be implemented.
For me it's not a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the "As the first user logged in, I see a message that I am the only person logged in, and see an offer to invite friends" story is no longer done, then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! I implemented it in other prs but not in this one. I'll be fixing that right now. Should I create a new PR for the fix?