Issue 1586: added a aspect drop down next to the submit button in the publisher
This commit is contained in:
parent
6c512cbfa9
commit
fead6032f7
15 changed files with 116 additions and 76 deletions
|
|
@ -148,7 +148,7 @@ class PeopleController < ApplicationController
|
|||
def aspect_membership_dropdown
|
||||
@person = Person.find(params[:person_id])
|
||||
@contact = current_user.contact_for(@person) || Contact.new
|
||||
render :partial => 'aspect_memberships/aspect_dropdown', :locals => {:contact => @contact, :person => @person, :hang => 'left'}
|
||||
render :partial => 'aspect_membership_dropdown', :locals => {:contact => @contact, :person => @person}
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -65,8 +65,24 @@ module AspectGlobalHelper
|
|||
end
|
||||
end
|
||||
|
||||
def aspect_dropdown_list_item(aspect, contact, person)
|
||||
checked = (contact.persisted? && contact.aspect_memberships.detect{ |am| am.aspect_id == aspect.id})
|
||||
def aspectmembership_dropdown(contact, person, hang, aspect=nil)
|
||||
@selected_aspects = []
|
||||
if contact.persisted?
|
||||
@selected_aspects = all_aspects.find_all{|aspect| contact.aspect_memberships.detect{ |am| am.aspect_id == aspect.id}}
|
||||
end
|
||||
@selected_aspects = [@selected_aspects] if @selected_aspects.kind_of? Aspect
|
||||
|
||||
render "shared/aspect_dropdown",
|
||||
:contact => @contact,
|
||||
:selected_aspects => @selected_aspects,
|
||||
:person => person,
|
||||
:hang => hang,
|
||||
:dropdown_class => "aspect_membership",
|
||||
:button_class => ("in_aspects" if @selected_aspects.size > 0),
|
||||
:may_create_new_aspect => ( @aspect == :profile || @aspect == :tag || @aspect == :search || @aspect == :notification)
|
||||
end
|
||||
|
||||
def aspect_dropdown_list_item(aspect, checked)
|
||||
klass = checked ? "selected" : ""
|
||||
|
||||
str = <<LISTITEM
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
-# Copyright (c) 2011, Diaspora Inc. This file is
|
||||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
.dropdown{:class => "hang_#{hang}"}
|
||||
.button.toggle{:class => ("in_aspects" if contact.aspects.size > 0)}
|
||||
- if contact.aspects.size == 1
|
||||
= contact.aspects.first.name
|
||||
- else
|
||||
= t('.toggle', :count => contact.aspects.size)
|
||||
▼
|
||||
|
||||
.wrapper
|
||||
%ul.dropdown_list{:unSelectable => 'on', 'data-person_id' => ((person.id) if person)}
|
||||
- for aspect in all_aspects
|
||||
= aspect_dropdown_list_item(aspect, contact, person)
|
||||
|
||||
- if defined?(@aspect) && ( @aspect == :profile || @aspect == :getting_started || @aspect == :tag || @aspect == :search || @aspect == :notification)
|
||||
%li.newItem
|
||||
.add_aspect
|
||||
= link_to t('contacts.index.add_a_new_aspect'), new_aspect_path(:person_id => person.id), :rel => 'facebox', :class => 'new_aspect'
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
= contact.person.diaspora_handle
|
||||
|
||||
.right
|
||||
= render 'aspect_memberships/aspect_dropdown', :contact => contact, :person => contact.person, :hang => 'right'
|
||||
= aspectmembership_dropdown(contact, contact.person, 'right')
|
||||
|
||||
%br
|
||||
%div{:style => "text-align:right;"}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
.stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : ''}"}
|
||||
- if note.type == "Notifications::StartedSharing" && contact = current_user.contact_for(note[:target])
|
||||
.right
|
||||
= render 'aspect_memberships/aspect_dropdown', :contact => contact, :person => note[:target], :hang => 'left'
|
||||
= aspectmembership_dropdown(contact, note[:target], 'left')
|
||||
|
||||
%span.from
|
||||
= notification_message_for(note)
|
||||
|
|
|
|||
1
app/views/people/_aspect_membership_dropdown.haml
Normal file
1
app/views/people/_aspect_membership_dropdown.haml
Normal file
|
|
@ -0,0 +1 @@
|
|||
= aspectmembership_dropdown(@contact, @person, 'left')
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
- unless person == current_user.person
|
||||
- contact = current_user.contacts.find_by_person_id(person.id)
|
||||
- contact ||= Contact.new(:person => person)
|
||||
= render 'aspect_memberships/aspect_dropdown', :contact => contact, :person => person, :hang => 'left'
|
||||
= aspectmembership_dropdown(contact, person, 'left')
|
||||
-else
|
||||
= t('people.person.thats_you')
|
||||
|
|
|
|||
24
app/views/shared/_aspect_dropdown.html.haml
Normal file
24
app/views/shared/_aspect_dropdown.html.haml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
-# Copyright (c) 2011, Diaspora Inc. This file is
|
||||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
.dropdown{:class => ["hang_#{hang}", defined?(dropdown_class) && dropdown_class]}
|
||||
- selected_aspects = [selected_aspects] if selected_aspects.kind_of? Aspect
|
||||
- if !selected_aspects.kind_of? Array
|
||||
- selected_aspects = all_aspects
|
||||
.button.toggle{:class => (button_class if defined?(button_class))}
|
||||
- if selected_aspects.size == 1
|
||||
= selected_aspects.first.name
|
||||
- else
|
||||
= t('.toggle', :count => selected_aspects.size)
|
||||
▼
|
||||
|
||||
.wrapper
|
||||
%ul.dropdown_list{:unSelectable => 'on', 'data-person_id' => (person.id if defined?person && person)}
|
||||
- for aspect in all_aspects
|
||||
= aspect_dropdown_list_item(aspect, selected_aspects.include?(aspect) )
|
||||
|
||||
- if (defined?may_create_new_aspect && may_create_new_aspect) && (defined?person && person)
|
||||
%li.newItem
|
||||
.add_aspect
|
||||
= link_to t('contacts.index.add_a_new_aspect'), new_aspect_path(:person_id => person.id), :rel => 'facebox'
|
||||
|
|
@ -29,12 +29,6 @@
|
|||
= hidden_field_tag 'aspect_ids[]', aspect_id.to_s
|
||||
|
||||
.options_and_submit
|
||||
- if aspect == :profile
|
||||
.mention_helper
|
||||
.badges
|
||||
%i= t('.publishing_to')
|
||||
= aspect_badges(aspects_with_person, :link => false)
|
||||
|
||||
.public_toggle
|
||||
%span#publisher_service_icons
|
||||
= t("shared.publisher.click_to_share_with")
|
||||
|
|
@ -45,6 +39,7 @@
|
|||
- for service in current_user.services
|
||||
= image_tag "social_media_logos/#{service.provider}-16x16.png", :title => service.provider.titleize, :class => "service_icon dim", :id =>"#{service.provider}", :maxchar => "#{service.class::MAX_CHARACTERS}"
|
||||
= link_to (image_tag "icons/monotone_wrench_settings.png"), "#question_mark_pane", :class => 'question_mark', :rel => 'facebox', :title => t('shared.public_explain.manage')
|
||||
= render "shared/aspect_dropdown", :selected_aspects => Aspect.find(aspect_ids), :hang => 'left'
|
||||
= status.submit t('.share'), :disable_with => t('.posting'), :class => 'button creation', :tabindex => 2
|
||||
|
||||
.facebox_content
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ javascripts:
|
|||
- public/javascripts/stream.js
|
||||
- public/javascripts/content-updater.js
|
||||
- public/javascripts/search.js
|
||||
- public/javascripts/aspects-dropdown.js
|
||||
- public/javascripts/contact-edit.js
|
||||
- public/javascripts/contact-list.js
|
||||
- public/javascripts/aspect-sorting.js
|
||||
|
|
|
|||
33
public/javascripts/aspects-dropdown.js
Normal file
33
public/javascripts/aspects-dropdown.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2011, Diaspora Inc. This file is
|
||||
// licensed under the Affero General Public License version 3 or later. See
|
||||
// the COPYRIGHT file.
|
||||
|
||||
var AspectsDropdown = {
|
||||
updateNumber: function(dropdown, personId, number, inAspectClass){
|
||||
var button = dropdown.parents(".dropdown").children('.button.toggle'),
|
||||
replacement;
|
||||
|
||||
if (number == 0) {
|
||||
button.removeClass(inAspectClass);
|
||||
replacement = Diaspora.widgets.i18n.t("aspect_dropdown.toggle.zero");
|
||||
}else if (number == 1) {
|
||||
button.addClass(inAspectClass);
|
||||
replacement = dropdown.find(".selected").first().text();
|
||||
}else if (number < 3) {
|
||||
replacement = Diaspora.widgets.i18n.t('aspect_dropdown.toggle.few', { count: number.toString()})
|
||||
}else if (number > 3) {
|
||||
replacement = Diaspora.widgets.i18n.t('aspect_dropdown.toggle.many', { count: number.toString()})
|
||||
}else {
|
||||
//the above one are a tautology, but I want to have them here once for once we figure out a neat way i18n them
|
||||
replacement = Diaspora.widgets.i18n.t('aspect_dropdown.toggle.other', { count: number.toString()})
|
||||
}
|
||||
|
||||
button.html(replacement + ' ▼');
|
||||
},
|
||||
|
||||
toggleCheckbox:
|
||||
function(check){
|
||||
check.parent('li').toggleClass('selected');
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -4,38 +4,12 @@
|
|||
|
||||
var ContactEdit = {
|
||||
init: function(){
|
||||
$('.dropdown .dropdown_list > li').live('click', function(evt){
|
||||
$.extend(ContactEdit, AspectsDropdown);
|
||||
$('.dropdown.aspect_membership .dropdown_list > li').live('click', function(evt){
|
||||
ContactEdit.processClick($(this), evt);
|
||||
});
|
||||
},
|
||||
|
||||
updateNumber: function(dropdown, personId, number){
|
||||
var button = dropdown.parents(".dropdown").children('.button.toggle'),
|
||||
replacement;
|
||||
|
||||
if (number == 0) {
|
||||
button.removeClass("in_aspects");
|
||||
replacement = Diaspora.widgets.i18n.t("aspect_dropdown.toggle.zero");
|
||||
}else if (number == 1) {
|
||||
button.addClass("in_aspects");
|
||||
replacement = dropdown.find(".selected").first().text();
|
||||
}else if (number < 3) {
|
||||
replacement = Diaspora.widgets.i18n.t('aspect_dropdown.toggle.few', { count: number.toString()})
|
||||
}else if (number > 3) {
|
||||
replacement = Diaspora.widgets.i18n.t('aspect_dropdown.toggle.many', { count: number.toString()})
|
||||
}else {
|
||||
//the above one are a tautology, but I want to have them here once for once we figure out a neat way i18n them
|
||||
replacement = Diaspora.widgets.i18n.t('aspect_dropdown.toggle.other', { count: number.toString()})
|
||||
}
|
||||
|
||||
button.html(replacement + ' ▼');
|
||||
},
|
||||
|
||||
toggleCheckbox:
|
||||
function(check){
|
||||
check.parent('li').toggleClass('selected');
|
||||
},
|
||||
|
||||
processClick: function(li, evt){
|
||||
var button = li.find('.button');
|
||||
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }
|
||||
|
|
@ -50,13 +24,13 @@ var ContactEdit = {
|
|||
"_method": (selected) ? "DELETE" : "POST"
|
||||
}, function(aspectMembership) {
|
||||
ContactEdit.toggleCheckbox(checkbox);
|
||||
ContactEdit.updateNumber(li.closest(".dropdown_list"), li.parent().data("person_id"), aspectMembership.aspect_ids.length);
|
||||
ContactEdit.updateNumber(li.closest(".dropdown_list"), li.parent().data("person_id"), aspectMembership.aspect_ids.length, 'in_aspect');
|
||||
|
||||
Diaspora.widgets.publish("aspectDropdown/updated", [li.parent().data("person_id"), li.parents(".dropdown").parent(".right").html()]);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
$(document).ready(function(){
|
||||
ContactEdit.init();
|
||||
});
|
||||
$(document).ready(function(){
|
||||
ContactEdit.init();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -340,16 +340,24 @@ var Publisher = {
|
|||
},
|
||||
|
||||
bindAspectToggles: function() {
|
||||
$('#publisher .aspect_badge').bind("click", function(){
|
||||
var unremovedAspects = $(this).parent().children('.aspect_badge').length - $(this).parent().children(".aspect_badge.removed").length;
|
||||
if(!$(this).hasClass('removed') && ( unremovedAspects == 1 )){
|
||||
alert(Diaspora.widgets.i18n.t('publisher.at_least_one_aspect'));
|
||||
}else{
|
||||
Publisher.toggleAspectIds($(this).children('a').attr('data-guid'));
|
||||
$(this).toggleClass("removed");
|
||||
}
|
||||
$('#publisher .dropdown .dropdown_list li').bind("click", function(evt){
|
||||
var li = $(this),
|
||||
button = li.find('.button'),
|
||||
checkbox = li.find('img.check');
|
||||
if(button.hasClass('disabled')) { return; }
|
||||
|
||||
AspectsDropdown.toggleCheckbox(checkbox);
|
||||
AspectsDropdown.updateNumber(li.closest(".dropdown_list"), null, li.parent().find('li.selected').length, '');
|
||||
|
||||
Publisher.toggleAspectIds(li.attr('data-aspect_id'));
|
||||
});
|
||||
},
|
||||
beforeSubmit: function(){
|
||||
if($("#publisher .content_creation form #aspect_ids_").length == 0){
|
||||
alert(Diaspora.widgets.i18n.t('publisher.at_least_one_aspect'));
|
||||
return false;
|
||||
}
|
||||
},
|
||||
onSubmit: function(data, json, xhr){
|
||||
$("#photodropzone").find('li').remove();
|
||||
$("#publisher textarea").removeClass("with_attachments").css('paddingBottom', '');
|
||||
|
|
@ -371,6 +379,7 @@ var Publisher = {
|
|||
Stream.setUpAudioLinks();
|
||||
},
|
||||
bindAjax: function(){
|
||||
Publisher.form().bind('submit', Publisher.beforeSubmit);
|
||||
Publisher.form().bind('ajax:loading', Publisher.onSubmit);
|
||||
Publisher.form().bind('ajax:failure', Publisher.onFailure);
|
||||
Publisher.form().bind('ajax:success', Publisher.onSuccess);
|
||||
|
|
|
|||
|
|
@ -765,8 +765,12 @@ a.paginate, #infscr-loading
|
|||
&:hover
|
||||
:border 1px solid #1C6D99
|
||||
|
||||
#main_stream .pagination
|
||||
:display none
|
||||
#main_stream
|
||||
:position relative
|
||||
:z-index 0
|
||||
|
||||
.pagination
|
||||
:display none
|
||||
|
||||
.request_buttons
|
||||
:position absolute
|
||||
|
|
@ -866,7 +870,7 @@ label
|
|||
|
||||
#publisher
|
||||
|
||||
:z-index 0
|
||||
:z-index 1
|
||||
:color #999
|
||||
:position relative
|
||||
:margin
|
||||
|
|
@ -930,6 +934,9 @@ label
|
|||
.public_toggle
|
||||
:text
|
||||
:align right
|
||||
.dropdown
|
||||
:text
|
||||
:align left
|
||||
|
||||
#publisher_service_icons
|
||||
:position relative
|
||||
|
|
@ -945,6 +952,7 @@ label
|
|||
:position relative
|
||||
:top -2px
|
||||
|
||||
|
||||
.content_creation
|
||||
:margin
|
||||
:top 1em
|
||||
|
|
|
|||
Loading…
Reference in a new issue