* rename profile header view to make name more accurate

* include 'js-routes' for rails routes in javascript
  (TODO: config options?)
* add handlebars helper for rails routes
This commit is contained in:
Florian Staudacher 2014-09-06 19:18:08 +02:00
parent 0092c9c483
commit 9a16560d8d
15 changed files with 131 additions and 81 deletions

View file

@ -81,6 +81,7 @@ gem 'handlebars_assets', '0.18.0'
gem 'jquery-rails', '3.1.2' gem 'jquery-rails', '3.1.2'
gem 'rails-assets-jquery', '1.11.1' # Should be kept in sync with jquery-rails gem 'rails-assets-jquery', '1.11.1' # Should be kept in sync with jquery-rails
gem 'js_image_paths', '0.0.1' gem 'js_image_paths', '0.0.1'
gem 'js-routes', '0.9.9'
# jQuery plugins # jQuery plugins

View file

@ -238,6 +238,9 @@ GEM
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
jquery-ui-rails (4.2.1) jquery-ui-rails (4.2.1)
railties (>= 3.2.16) railties (>= 3.2.16)
js-routes (0.9.9)
railties (>= 3.2)
sprockets-rails
js_image_paths (0.0.1) js_image_paths (0.0.1)
rails (~> 4.0) rails (~> 4.0)
json (1.8.1) json (1.8.1)
@ -533,6 +536,7 @@ DEPENDENCIES
jasmine (= 2.0.2) jasmine (= 2.0.2)
jasmine-jquery-rails (= 2.0.3) jasmine-jquery-rails (= 2.0.3)
jquery-rails (= 3.1.2) jquery-rails (= 3.1.2)
js-routes (= 0.9.9)
js_image_paths (= 0.0.1) js_image_paths (= 0.0.1)
json (= 1.8.1) json (= 1.8.1)
markerb (= 1.0.2) markerb (= 1.0.2)

View file

@ -6,6 +6,15 @@ Handlebars.registerHelper('imageUrl', function(path){
return ImagePaths.get(path); return ImagePaths.get(path);
}); });
Handlebars.registerHelper('urlTo', function(path_helper, id, data){
if( !data ) {
// only one argument given to helper, mangle parameters
data = id;
return Routes[path_helper+'_path'](data.hash);
}
return Routes[path_helper+'_path'](id, data.hash);
});
Handlebars.registerHelper('linkToPerson', function(context, block) { Handlebars.registerHelper('linkToPerson', function(context, block) {
if( !context ) context = this; if( !context ) context = this;
var html = "<a href=\"/people/" + context.guid + "\" class=\"author-name "; var html = "<a href=\"/people/" + context.guid + "\" class=\"author-name ";

View file

@ -1,5 +1,4 @@
// TODO: update the aspect_membership dropdown, too, every time we render the view...
app.pages.Profile = app.views.Base.extend({ app.pages.Profile = app.views.Base.extend({
events: { events: {
'click #block_user_button': 'blockPerson', 'click #block_user_button': 'blockPerson',
@ -8,7 +7,7 @@ app.pages.Profile = app.views.Base.extend({
subviews: { subviews: {
'#profile .badge': 'sidebarView', '#profile .badge': 'sidebarView',
'.stream_container': 'streamView' '.profile_header': 'headerView'
}, },
tooltipSelector: '.profile_button div, .sharing_message_container', tooltipSelector: '.profile_button div, .sharing_message_container',
@ -30,8 +29,8 @@ app.pages.Profile = app.views.Base.extend({
return new app.views.ProfileSidebar({model: this.model}); return new app.views.ProfileSidebar({model: this.model});
}, },
streamView: function() { headerView: function() {
return new app.views.ProfileStream({model: this.model}); return new app.views.ProfileHeader({model: this.model});
}, },
blockPerson: function(evt) { blockPerson: function(evt) {

View file

@ -119,6 +119,7 @@ app.views.Hovercard = app.views.Base.extend({
})) ); })) );
// set aspect dropdown // set aspect dropdown
// TODO render me client side!!!
var href = this.href(); var href = this.href();
href += "/aspect_membership_button"; href += "/aspect_membership_button";
if(gon.bootstrap == true){ if(gon.bootstrap == true){

View file

@ -0,0 +1,25 @@
app.views.ProfileHeader = app.views.Base.extend({
templateName: 'profile_header',
presenter: function() {
return _.extend({}, this.defaultPresenter(), {
is_blocked: this.model.isBlocked()
});
},
postRenderTemplate: function() {
var self = this;
var dropdownEl = this.$('.aspect_membership_dropdown.placeholder');
if( dropdownEl.length == 0 ) return;
// TODO render me client side!!!
var href = this.model.url() + '/aspect_membership_button?create=true';
if( gon.bootstrap ) href += '&bootstrap=true';
$.get(href, function(resp) {
dropdownEl.html(resp);
new app.views.AspectMembership({el: dropdownEl});
})
}
});

View file

@ -15,4 +15,9 @@ app.views.ProfileSidebar = app.views.Base.extend({
_shouldDoProfileBtns: function() { _shouldDoProfileBtns: function() {
return (app.currentUser.authenticated() && !this.model.get('is_own_profile')); return (app.currentUser.authenticated() && !this.model.get('is_own_profile'));
}, },
postRenderTemplate: function() {
// UGLY (re-)attach the facebox
this.$('a[rel*=facebox]').facebox();
}
}); });

View file

@ -1,10 +0,0 @@
app.views.ProfileStream = app.views.Base.extend({
templateName: 'profile_stream',
presenter: function() {
return _.extend({}, this.defaultPresenter(), {
is_blocked: this.model.isBlocked()
});
}
});

View file

@ -3,6 +3,7 @@
* the COPYRIGHT file. * the COPYRIGHT file.
*/ */
//= require js_image_paths //= require js_image_paths
//= require js-routes
//= require underscore //= require underscore
//= require backbone //= require backbone
//= require jquery.hotkeys //= require jquery.hotkeys

View file

@ -3,13 +3,12 @@
{{#if loggedIn}} {{#if loggedIn}}
{{#if is_own_profile}} {{#if is_own_profile}}
{{!-- can't block myself, so don't check it here --}} {{!-- can't block myself, so don't check it here --}}
<a href="TODO" class="button creation">{{t 'people.edit_my_profile'}}</a> <a href="{{urlTo 'edit_profile'}}" class="button creation">{{t 'people.edit_my_profile'}}</a>
{{/if}} {{else}} {{#if is_blocked}}
{{#if is_blocked}}
<a href="#" id="unblock_user_button" class="button">{{t 'people.stop_ignoring'}}</a> <a href="#" id="unblock_user_button" class="button">{{t 'people.stop_ignoring'}}</a>
{{else}} {{else}}
<div class="placeholder aspect_membership_dropdown"></div> <div class="placeholder aspect_membership_dropdown"></div>
{{/if}} {{/if}}{{/if}}
{{/if}} {{/if}}
</div> </div>
@ -17,6 +16,10 @@
<span class="diaspora_handle">{{diaspora_id}}</span> <span class="diaspora_handle">{{diaspora_id}}</span>
<div class="description"> <div class="description">
{{#if loggedIn}}
TODO
{{/if}}
</div> </div>
</div> </div>
<hr />

View file

@ -10,22 +10,25 @@
{{{sharingBadge this}}} {{{sharingBadge this}}}
{{#if is_receiving}} {{#if is_receiving}}
{{!-- create status message with mention --}}
<div class="profile_button"> <div class="profile_button">
<a href="TODO" rel="facebox"> <a href="{{urlTo 'new_status_message' person_id=id}}" rel="facebox">
<div id="mention_button" class="icons-mention" title="{{t 'people.mention'}}" data-placement="bottom"></div> <div id="mention_button" class="icons-mention" title="{{t 'people.mention'}}" data-placement="bottom"></div>
</a> </a>
</div> </div>
{{/if}} {{/if}}
{{#if is_mutual}} {{#if is_mutual}}
{{!-- create private conversation with person --}}
<div class="profile_button"> <div class="profile_button">
<a href="TODO" rel="facebox"> <a href="{{urlTo 'new_conversation' contact_id=contact.id name=name facebox=true}}" rel="facebox">
<div id="message_button" class="icons-message" title="{{t 'people.message'}}" data-placement="bottom"></div> <div id="message_button" class="icons-message" title="{{t 'people.message'}}" data-placement="bottom"></div>
</a> </a>
</div> </div>
{{/if}} {{/if}}
{{#if is_not_blocked}} {{#if is_not_blocked}}
{{!-- ignore the person --}}
<div class="profile_button"> <div class="profile_button">
<a href="#" rel="nofollow"> <a href="#" rel="nofollow">
<div id="block_user_button" class="icons-ignoreuser block_user" title="{{t 'ignore'}}" data-placement="bottom"></div> <div id="block_user_button" class="icons-ignoreuser block_user" title="{{t 'ignore'}}" data-placement="bottom"></div>

View file

@ -82,8 +82,8 @@ class PeopleController < ApplicationController
mark_corresponding_notifications_read if user_signed_in? mark_corresponding_notifications_read if user_signed_in?
@aspect = :profile # what does this do? @aspect = :profile # let aspect dropdown create new aspects
@post_type = :all # for mobile @post_type = :all # for mobile
@person_json = PersonPresenter.new(@person, current_user).full_hash_with_profile @person_json = PersonPresenter.new(@person, current_user).full_hash_with_profile
respond_to do |format| respond_to do |format|
@ -179,7 +179,9 @@ class PeopleController < ApplicationController
return render :text => I18n.t('people.person.thats_you') if @person == current_user.person return render :text => I18n.t('people.person.thats_you') if @person == current_user.person
@contact = current_user.contact_for(@person) || Contact.new @contact = current_user.contact_for(@person) || Contact.new
@aspect = :profile if params[:create] # let aspect dropdown create new aspects
bootstrap = params[:bootstrap] || false bootstrap = params[:bootstrap] || false
render :partial => 'aspect_membership_dropdown', :locals => {:contact => @contact, :person => @person, :hang => 'left', :bootstrap => bootstrap} render :partial => 'aspect_membership_dropdown', :locals => {:contact => @contact, :person => @person, :hang => 'left', :bootstrap => bootstrap}
end end

View file

@ -11,6 +11,7 @@ class PersonPresenter < BasePresenter
base_hash.merge({ base_hash.merge({
relationship: relationship, relationship: relationship,
block: is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false, block: is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false,
contact: { id: current_user_person_contact.id },
is_own_profile: own_profile? is_own_profile: own_profile?
}) })
end end
@ -44,7 +45,7 @@ class PersonPresenter < BasePresenter
end end
def relationship def relationship
contact = current_user.contact_for(@presentable) contact = current_user_person_contact
is_mutual = contact ? contact.mutual? : false is_mutual = contact ? contact.mutual? : false
is_sharing = contact ? contact.sharing? : false is_sharing = contact ? contact.sharing? : false
@ -68,6 +69,10 @@ class PersonPresenter < BasePresenter
@block ||= current_user.blocks.where(person_id: id).limit(1).first @block ||= current_user.blocks.where(person_id: id).limit(1).first
end end
def current_user_person_contact
@contact ||= current_user.contact_for(@presentable)
end
def is_blocked? def is_blocked?
current_user_person_block.present? current_user_person_block.present?
end end

View file

@ -27,64 +27,64 @@
.profile_button .profile_button
= link_to content_tag(:div, nil, :class => 'icons-ignoreuser block_user', :title => t('ignore'), :id => 'block_user_button', :data => { :person_id => @person.id }), '#', :rel => "nofollow" if @block.blank? = link_to content_tag(:div, nil, :class => 'icons-ignoreuser block_user', :title => t('ignore'), :id => 'block_user_button', :data => { :person_id => @person.id }), '#', :rel => "nofollow" if @block.blank?
-if contact.sharing? || person == current_user.person -if contact.sharing? || person == current_user.person
%ul#profile_information %ul#profile_information
- unless person.bio.blank? - unless person.bio.blank?
%li %li
%h4 %h4
=t('.bio') =t('.bio')
%div{ :class => direction_for(person.bio) } %div{ :class => direction_for(person.bio) }
= person.profile.bio_message.markdownified = person.profile.bio_message.markdownified
- unless person.profile.location.blank? - unless person.profile.location.blank?
%li %li
%h4 %h4
=t('.location') =t('.location')
%div{ :class => direction_for(person.location) } %div{ :class => direction_for(person.location) }
= person.profile.location_message.markdownified = person.profile.location_message.markdownified
- unless person.gender.blank? - unless person.gender.blank?
%li %li
%h4 %h4
=t('.gender') =t('.gender')
= person.gender = person.gender
- unless person.birthday.blank? - unless person.birthday.blank?
%li %li
%h4 %h4
=t('.born') =t('.born')
= birthday_format(person.birthday) = birthday_format(person.birthday)
- if @photos.present? - if @photos.present?
%li.image_list %li.image_list
%h4 %h4
= t('.photos') = t('.photos')
.item_count .item_count
= "#{@photos.count(:all)}" = "#{@photos.count(:all)}"
- @photos.limit(8).each do |photo| - @photos.limit(8).each do |photo|
= image_tag(photo.url(:thumb_small)) = image_tag(photo.url(:thumb_small))
%br %br
= link_to t('layouts.header.view_all'), person_photos_path(person) = link_to t('layouts.header.view_all'), person_photos_path(person)
- if person == current_user.person - if person == current_user.person
%li.image_list %li.image_list
%h4 %h4
= t('_contacts') = t('_contacts')
.item_count .item_count
= all_contacts_count = all_contacts_count
.section.contact_pictures .section.contact_pictures
- current_user.contacts.limit(8).each do |contact| - current_user.contacts.limit(8).each do |contact|
= person_image_link contact.person, :size => :thumb_small = person_image_link contact.person, :size => :thumb_small
%p.see_all= link_to t('layouts.header.view_all'), contacts_path %p.see_all= link_to t('layouts.header.view_all'), contacts_path
- elsif @contact.persisted? && @contacts_of_contact_count > 0 - elsif @contact.persisted? && @contacts_of_contact_count > 0
%li.image_list %li.image_list
%h4 %h4
= t('_contacts') = t('_contacts')
.item_count .item_count
= @contacts_of_contact_count = @contacts_of_contact_count
.section.contact_pictures .section.contact_pictures
-@contacts_of_contact.limit(8).each do |person| -@contacts_of_contact.limit(8).each do |person|
= person_image_link person, :size => :thumb_small = person_image_link person, :size => :thumb_small
%p.see_all= link_to t('layouts.header.view_all'), person_contacts_path(@person) %p.see_all= link_to t('layouts.header.view_all'), person_contacts_path(@person)
%br %br
%br %br

View file

@ -15,9 +15,11 @@
= render :partial => 'people/profile_sidebar', :locals => {:person => @person, :contact => @contact } = render :partial => 'people/profile_sidebar', :locals => {:person => @person, :contact => @contact }
.span-18.last .span-18.last
.stream_container .profile_header
= render 'people/sub_header', :person => @person, :contact => @contact = render 'people/sub_header', :person => @person, :contact => @contact
.stream_container
#main_stream.stream #main_stream.stream
- if @block.present? - if @block.present?
.dull .dull