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
|
def aspect_membership_dropdown
|
||||||
@person = Person.find(params[:person_id])
|
@person = Person.find(params[:person_id])
|
||||||
@contact = current_user.contact_for(@person) || Contact.new
|
@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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,24 @@ module AspectGlobalHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def aspect_dropdown_list_item(aspect, contact, person)
|
def aspectmembership_dropdown(contact, person, hang, aspect=nil)
|
||||||
checked = (contact.persisted? && contact.aspect_memberships.detect{ |am| am.aspect_id == aspect.id})
|
@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" : ""
|
klass = checked ? "selected" : ""
|
||||||
|
|
||||||
str = <<LISTITEM
|
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
|
= contact.person.diaspora_handle
|
||||||
|
|
||||||
.right
|
.right
|
||||||
= render 'aspect_memberships/aspect_dropdown', :contact => contact, :person => contact.person, :hang => 'right'
|
= aspectmembership_dropdown(contact, contact.person, 'right')
|
||||||
|
|
||||||
%br
|
%br
|
||||||
%div{:style => "text-align:right;"}
|
%div{:style => "text-align:right;"}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
.stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : ''}"}
|
.stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : ''}"}
|
||||||
- if note.type == "Notifications::StartedSharing" && contact = current_user.contact_for(note[:target])
|
- if note.type == "Notifications::StartedSharing" && contact = current_user.contact_for(note[:target])
|
||||||
.right
|
.right
|
||||||
= render 'aspect_memberships/aspect_dropdown', :contact => contact, :person => note[:target], :hang => 'left'
|
= aspectmembership_dropdown(contact, note[:target], 'left')
|
||||||
|
|
||||||
%span.from
|
%span.from
|
||||||
= notification_message_for(note)
|
= 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
|
- unless person == current_user.person
|
||||||
- contact = current_user.contacts.find_by_person_id(person.id)
|
- contact = current_user.contacts.find_by_person_id(person.id)
|
||||||
- contact ||= Contact.new(:person => person)
|
- contact ||= Contact.new(:person => person)
|
||||||
= render 'aspect_memberships/aspect_dropdown', :contact => contact, :person => person, :hang => 'left'
|
= aspectmembership_dropdown(contact, person, 'left')
|
||||||
-else
|
-else
|
||||||
= t('people.person.thats_you')
|
= 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
|
= hidden_field_tag 'aspect_ids[]', aspect_id.to_s
|
||||||
|
|
||||||
.options_and_submit
|
.options_and_submit
|
||||||
- if aspect == :profile
|
|
||||||
.mention_helper
|
|
||||||
.badges
|
|
||||||
%i= t('.publishing_to')
|
|
||||||
= aspect_badges(aspects_with_person, :link => false)
|
|
||||||
|
|
||||||
.public_toggle
|
.public_toggle
|
||||||
%span#publisher_service_icons
|
%span#publisher_service_icons
|
||||||
= t("shared.publisher.click_to_share_with")
|
= t("shared.publisher.click_to_share_with")
|
||||||
|
|
@ -45,6 +39,7 @@
|
||||||
- for service in current_user.services
|
- 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}"
|
= 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')
|
= 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
|
= status.submit t('.share'), :disable_with => t('.posting'), :class => 'button creation', :tabindex => 2
|
||||||
|
|
||||||
.facebox_content
|
.facebox_content
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ javascripts:
|
||||||
- public/javascripts/stream.js
|
- public/javascripts/stream.js
|
||||||
- public/javascripts/content-updater.js
|
- public/javascripts/content-updater.js
|
||||||
- public/javascripts/search.js
|
- public/javascripts/search.js
|
||||||
|
- public/javascripts/aspects-dropdown.js
|
||||||
- public/javascripts/contact-edit.js
|
- public/javascripts/contact-edit.js
|
||||||
- public/javascripts/contact-list.js
|
- public/javascripts/contact-list.js
|
||||||
- public/javascripts/aspect-sorting.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 = {
|
var ContactEdit = {
|
||||||
init: function(){
|
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);
|
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){
|
processClick: function(li, evt){
|
||||||
var button = li.find('.button');
|
var button = li.find('.button');
|
||||||
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }
|
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }
|
||||||
|
|
@ -50,13 +24,13 @@ var ContactEdit = {
|
||||||
"_method": (selected) ? "DELETE" : "POST"
|
"_method": (selected) ? "DELETE" : "POST"
|
||||||
}, function(aspectMembership) {
|
}, function(aspectMembership) {
|
||||||
ContactEdit.toggleCheckbox(checkbox);
|
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()]);
|
Diaspora.widgets.publish("aspectDropdown/updated", [li.parent().data("person_id"), li.parents(".dropdown").parent(".right").html()]);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
ContactEdit.init();
|
ContactEdit.init();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -340,16 +340,24 @@ var Publisher = {
|
||||||
},
|
},
|
||||||
|
|
||||||
bindAspectToggles: function() {
|
bindAspectToggles: function() {
|
||||||
$('#publisher .aspect_badge').bind("click", function(){
|
$('#publisher .dropdown .dropdown_list li').bind("click", function(evt){
|
||||||
var unremovedAspects = $(this).parent().children('.aspect_badge').length - $(this).parent().children(".aspect_badge.removed").length;
|
var li = $(this),
|
||||||
if(!$(this).hasClass('removed') && ( unremovedAspects == 1 )){
|
button = li.find('.button'),
|
||||||
alert(Diaspora.widgets.i18n.t('publisher.at_least_one_aspect'));
|
checkbox = li.find('img.check');
|
||||||
}else{
|
if(button.hasClass('disabled')) { return; }
|
||||||
Publisher.toggleAspectIds($(this).children('a').attr('data-guid'));
|
|
||||||
$(this).toggleClass("removed");
|
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){
|
onSubmit: function(data, json, xhr){
|
||||||
$("#photodropzone").find('li').remove();
|
$("#photodropzone").find('li').remove();
|
||||||
$("#publisher textarea").removeClass("with_attachments").css('paddingBottom', '');
|
$("#publisher textarea").removeClass("with_attachments").css('paddingBottom', '');
|
||||||
|
|
@ -371,6 +379,7 @@ var Publisher = {
|
||||||
Stream.setUpAudioLinks();
|
Stream.setUpAudioLinks();
|
||||||
},
|
},
|
||||||
bindAjax: function(){
|
bindAjax: function(){
|
||||||
|
Publisher.form().bind('submit', Publisher.beforeSubmit);
|
||||||
Publisher.form().bind('ajax:loading', Publisher.onSubmit);
|
Publisher.form().bind('ajax:loading', Publisher.onSubmit);
|
||||||
Publisher.form().bind('ajax:failure', Publisher.onFailure);
|
Publisher.form().bind('ajax:failure', Publisher.onFailure);
|
||||||
Publisher.form().bind('ajax:success', Publisher.onSuccess);
|
Publisher.form().bind('ajax:success', Publisher.onSuccess);
|
||||||
|
|
|
||||||
|
|
@ -765,8 +765,12 @@ a.paginate, #infscr-loading
|
||||||
&:hover
|
&:hover
|
||||||
:border 1px solid #1C6D99
|
:border 1px solid #1C6D99
|
||||||
|
|
||||||
#main_stream .pagination
|
#main_stream
|
||||||
:display none
|
:position relative
|
||||||
|
:z-index 0
|
||||||
|
|
||||||
|
.pagination
|
||||||
|
:display none
|
||||||
|
|
||||||
.request_buttons
|
.request_buttons
|
||||||
:position absolute
|
:position absolute
|
||||||
|
|
@ -866,7 +870,7 @@ label
|
||||||
|
|
||||||
#publisher
|
#publisher
|
||||||
|
|
||||||
:z-index 0
|
:z-index 1
|
||||||
:color #999
|
:color #999
|
||||||
:position relative
|
:position relative
|
||||||
:margin
|
:margin
|
||||||
|
|
@ -930,6 +934,9 @@ label
|
||||||
.public_toggle
|
.public_toggle
|
||||||
:text
|
:text
|
||||||
:align right
|
:align right
|
||||||
|
.dropdown
|
||||||
|
:text
|
||||||
|
:align left
|
||||||
|
|
||||||
#publisher_service_icons
|
#publisher_service_icons
|
||||||
:position relative
|
:position relative
|
||||||
|
|
@ -945,6 +952,7 @@ label
|
||||||
:position relative
|
:position relative
|
||||||
:top -2px
|
:top -2px
|
||||||
|
|
||||||
|
|
||||||
.content_creation
|
.content_creation
|
||||||
:margin
|
:margin
|
||||||
:top 1em
|
:top 1em
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue