port profile page to backbone.js

This commit is contained in:
Florian Staudacher 2014-08-29 21:29:59 +02:00
parent cb3db09a5d
commit d00d69814e
8 changed files with 60 additions and 41 deletions

View file

@ -0,0 +1,44 @@
// TODO: this view should be model-driven an re-render when it was updated,
// instead of changing classes/attributes on elements.
app.pages.Profile = Backbone.View.extend({
events: {
'click #block_user_button': 'blockPerson'
},
initialize: function(opts) {
// cache element references
this.el_profile_btns = this.$('#profile_buttons');
this.el_sharing_msg = this.$('#sharing_message');
// init tooltips
this.el_profile_btns.find('.profile_button div, .sharin_message_container')
.tooltip({placement: 'bottom'});
// respond to global events
var person_id = this.$('#profile .avatar:first').data('person_id');
app.events.on('person:block:'+person_id, this._markBlocked, this);
},
blockPerson: function(evt) {
if( !confirm(Diaspora.I18n.t('ignore_user')) ) return;
var person_id = $(evt.target).data('person-id');
var block = new app.models.Block({block: {person_id: person_id}});
block.save()
.done(function() { app.events.trigger('person:block:'+person_id); })
.fail(function() { Diaspora.page.flashMessages.render({
success: false,
notice: Diaspora.I18n.t('ignore_failed')
}); });
return false;
},
_markBlocked: function() {
this.el_profile_btns.attr('class', 'blocked');
this.el_sharing_msg.attr('class', 'icons-circle');
this.el_profile_btns.find('.profile_button, .white_bar').remove();
}
});

View file

@ -22,8 +22,8 @@ app.Router = Backbone.Router.extend({
"tags/:name": "followed_tags",
"people/:id/photos": "photos",
"people/:id": "stream",
"u/:name": "stream"
"people/:id": "profile",
"u/:name": "profile"
},
initialize: function() {
@ -52,9 +52,13 @@ app.Router = Backbone.Router.extend({
},
renderPage : function(pageConstructor){
app.page && app.page.unbind && app.page.unbind() //old page might mutate global events $(document).keypress, so unbind before creating
app.page = pageConstructor() //create new page after the world is clean (like that will ever happen)
$("#container").html(app.page.render().el)
app.page && app.page.unbind && app.page.unbind(); //old page might mutate global events $(document).keypress, so unbind before creating
app.page = pageConstructor(); //create new page after the world is clean (like that will ever happen)
if( !$.contains(document, app.page.el) ) {
// view element isn't already attached to the DOM, insert it
$("#container").empty().append(app.page.render().el);
}
},
//below here is oldness
@ -133,6 +137,13 @@ app.Router = Backbone.Router.extend({
app.bookmarklet = new app.views.Bookmarklet(
_.extend({}, {el: $('#bookmarklet')}, contents)
).render();
},
profile: function() {
this.renderPage(function() { return new app.pages.Profile({
el: $('body > .container')
}); });
// TODO call `this.stream()`
}
});

View file

@ -1,25 +0,0 @@
/* Copyright (c) 2010-2011, Diaspora Inc. This file is
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
//= require fileuploader-custom
//= require jquery.autoSuggest.custom
$(document).ready(function() {
$('#profile_buttons .profile_button div').tooltip({placement: 'bottom'});
$('#profile_buttons .sharing_message_container').tooltip({placement: 'bottom'});
$("#block_user_button").click(function(evt) {
if(!confirm(Diaspora.I18n.t('ignore_user'))) { return; }
var personId = $(this).data('person-id');
var block = new app.models.Block();
block.save({block : {person_id : personId}}, {
success: function() {
$('#profile_buttons').attr('class', 'blocked');
$('#sharing_message').attr('class', 'icons-circle');
$('.profile_button, .white_bar').remove();
}
});
return false;
});
});

View file

@ -1,9 +1,6 @@
- content_for :page_title do
= t('.title')
- content_for :head do
= javascript_include_tag :people
.container-fluid#contacts_container
.row-fluid
.span3

View file

@ -5,9 +5,6 @@
- content_for :page_title do
= t('.title')
- content_for :head do
= javascript_include_tag :people
#section_header
%h2
= t('.title')

View file

@ -1,9 +1,6 @@
- content_for :page_title do
= t('contacts.spotlight.community_spotlight')
- content_for :head do
= javascript_include_tag :people
.container-fluid#contacts_container
.row-fluid

View file

@ -6,7 +6,6 @@
= t('search')
- content_for :head do
= javascript_include_tag :people
= javascript_include_tag 'contact-list'
.container-fluid#people_search

View file

@ -4,7 +4,6 @@
- content_for :head do
= javascript_include_tag :people
- if user_signed_in? && @person != current_user.person
:javascript
Mentions.options.prefillMention = Mentions._contactToMention(#{j @person.to_json});