Skip to content
Extraits de code Groupes Projets
Valider ba9ece00 rédigé par Dan Hansen's avatar Dan Hansen Validation de Dennis Collinson
Parcourir les fichiers

Use routers, remove some hacks

parent d4219799
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -41,16 +41,16 @@ ...@@ -41,16 +41,16 @@
- unless @landing_page - unless @landing_page
= include_javascripts :main = include_javascripts :main
:javascript :javascript
App.user({
current_user: #{current_user.person.as_api_response(:backbone).to_json}
});
Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}"); Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}");
Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}"; Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}";
- if @backbone
:javascript
window.useBackbone = true;
= yield(:head) = yield(:head)
-unless Rails.env == "production" -unless Rails.env == "production"
:css :css
.translation_missing { .translation_missing {
color: purple; color: purple;
...@@ -60,8 +60,7 @@ ...@@ -60,8 +60,7 @@
- if @person - if @person
%link{:rel => "alternate", :href => "#{@person.public_url}.atom", :type => "application/atom+xml", :title => "#{t('.public_feed', :name => @person.name)}"} %link{:rel => "alternate", :href => "#{@person.public_url}.atom", :type => "application/atom+xml", :title => "#{t('.public_feed', :name => @person.name)}"}
- metadata = user_signed_in? ? CGI::escape({:current_user => current_user.person.as_api_response(:backbone)}.to_json) : "" %body{:class => "#{yield(:body_class)}"}
%body{:class => "#{yield(:body_class)}", 'data-current-user-metadata' => metadata }
- unless @page == :logged_out - unless @page == :logged_out
- flash.each do |name, msg| - flash.each do |name, msg|
......
...@@ -20,6 +20,9 @@ javascripts: ...@@ -20,6 +20,9 @@ javascripts:
- public/javascripts/collections/* - public/javascripts/collections/*
- public/javascripts/views/* - public/javascripts/views/*
- public/javascripts/routers/stream.js
- public/javascripts/routers/*
- public/javascripts/rails.validations.js - public/javascripts/rails.validations.js
- public/javascripts/rails.js - public/javascripts/rails.js
- public/javascripts/vendor/jquery.hotkeys.js - public/javascripts/vendor/jquery.hotkeys.js
......
var App = { var App = {
Collections: {}, Collections: {},
Models: {}, Models: {},
routers: {},
Routers: {},
Views: {}, Views: {},
currentUser: function() { user: function(user) {
return $.parseJSON(unescape($("body").data("current-user-metadata"))); if(user) { return this._user = user; }
return this._user;
},
initialize: function() {
_.each(App.Routers, function(Router, name) {
App.routers[name] = new Router;
});
Backbone.history.start({pushState: true});
} }
}; };
$(function() { App.initialize(); });
App.Collections.Stream = Backbone.Collection.extend({ App.Collections.Stream = Backbone.Collection.extend({
url: function() { url: function() {
var path = document.location.pathname; var path = document.location.pathname + ".json";
if(this.models.length) { if(this.models.length) { path += "?max_time=" + _.last(this.models).intTime(); }
return path + ".json?max_time=" + _.last(this.models).intTime();
} return path;
else {
return path + ".json";
}
}, },
model: App.Models.Post, model: App.Models.Post,
......
App.Routers.CommentStream = App.Routers.Stream.extend({
routes: {
"comment_stream": "stream"
}
});
App.Routers.Mentions = App.Routers.Stream.extend({
routes: {
"mentions": "stream"
}
});
App.Routers.Stream = Backbone.Router.extend({
routes: {
"stream": "stream"
},
stream: function() {
App.stream = new App.Views.Stream;
}
});
$(function() { App.Views.Stream = Backbone.View.extend({
App.Views.Stream = Backbone.View.extend({ events: {
"click #paginate": "loadMore"
el: $("#main_stream"), },
template: _.template($('#stream-element-template').html()), initialize: function(){
this.el = $("#main_stream");
events: { this.template = _.template($("#stream-element-template").html());
"click #paginate": "loadMore"
}, _.bindAll(this, "appendPost", "collectionFetched");
initialize: function(){ this.collection = new App.Collections.Stream;
_.bindAll(this, "appendPost", "collectionFetched"); this.collection.bind("add", this.appendPost);
this.loadMore();
this.collection = new App.Collections.Stream; },
this.collection.bind("add", this.appendPost);
this.loadMore(); appendPost: function(model) {
}, var post = $(this.template($.extend(
model.toJSON(),
appendPost: function(model) { App.user()
var post = $(this.template($.extend( )));
model.toJSON(), $(this.el).append(post);
App.currentUser() Diaspora.BaseWidget.instantiate("StreamElement", post);
))); },
$(this.el).append(post);
Diaspora.BaseWidget.instantiate("StreamElement", post); collectionFetched: function() {
}, this.$(".details time").timeago();
this.$("label").inFieldLabels();
collectionFetched: function() {
this.$("time").timeago(); this.$("#paginate").remove();
this.$("label").inFieldLabels(); $(this.el).append($("<a>", {
href: this.collection.url(),
this.$("#paginate").remove(); id: "paginate"
$(this.el).append($("<a>", { }).text('more'));
href: this.collection.url(), },
id: "paginate"
}).text('more')); loadMore: function(evt) {
}, if(evt) {
evt.preventDefault();
loadMore: function(evt) {
if(evt) {
evt.preventDefault();
}
this.collection.fetch({
add: true,
success: this.collectionFetched
});
} }
});
if(window.useBackbone) { this.collection.fetch({
window.stream = new App.Views.Stream; add: true,
success: this.collectionFetched
});
} }
}); });
describe("App", function() {
describe("user", function() {
it("sets the user if given one and returns the current user", function() {
expect(App.user()).toBeUndefined();
App.user({name: "alice"});
expect(App.user()).toEqual({name: "alice"});
});
});
});
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter