Refactor publisher JS, use hidden field for submitting

This commit is contained in:
Raphael 2011-02-02 14:26:41 -08:00
parent a687f26961
commit cd8d9989cf
7 changed files with 117 additions and 42 deletions

View file

@ -3,7 +3,7 @@
-# the COPYRIGHT file.
#publisher{:class => ("closed" unless params[:op] || params[:prefill])}
#publisher
#click_to_share
= image_tag 'icons/doc_edit.png'
@ -27,8 +27,8 @@
%params
#publisher_textarea_wrapper
%ul#photodropzone
= status.text_area :message, :rows => 2, :value => h(params[:prefill])
= javascript_tag "if ($('textarea#status_message_message').val() != ''){ $('textarea#status_message_message').focus();}"
= status.text_area :fake_message, :rows => 2, :value => h(params[:prefill])
= status.hidden_field :message, :value => ''
- for aspect_id in @aspect_ids
= hidden_field_tag 'aspect_ids[]', aspect_id.to_s

View file

@ -1,27 +1,26 @@
@javascript
Feature: posting
In order to enlighten humanity for the good of society
As a rock star
I want to tell the world I am eating a yogurt
@javascript
Scenario: post to all aspects
Given I am signed in
And I have an aspect called "Family"
And I am on the home page
And I expand the publisher
When I fill in "status_message_message" with "I am eating a yogurt"
When I fill in "status_message_fake_message" with "I am eating a yogurt"
And I press "Share"
And I am on the home page
Then I should see "I am eating a yogurt" within ".stream_element"
@javascript
Scenario: delete a post
Given I am signed in
And I have an aspect called "Family"
And I am on the home page
And I expand the publisher
When I fill in "status_message_message" with "I am eating a yogurt"
When I fill in "status_message_fake_message" with "I am eating a yogurt"
And I press "Share"
And I am on the home page
And I hover over the post
@ -32,12 +31,13 @@ Feature: posting
Scenario Outline: post to one aspect
Given I have no open aspects saved
Given I am signed in
And I have an aspect called "PostTo"
And I have an aspect called "DidntPostTo"
And I am on the home page
When I follow "PostTo"
And I fill in "status_message_message" with "I am eating a yogurt"
And I fill in "status_message_fake_message" with "I am eating a yogurt"
And I press "Share"
And I follow "<aspect>"
Then I should <see> "I am eating a yogurt"

View file

@ -72,6 +72,9 @@ When /^I click on the contact request$/ do
find(".person.request.ui-draggable a").click
end
Given /^I have no open aspects saved$/ do
@me.aspects.update_all(:open => false)
end
Then /^I should have aspect "([^"]*)" "([^"]*)"$/ do |arg1, arg2|
val = evaluate_script("$('a:contains(\"#{arg1}\")').parent('li').hasClass('selected');") #
if arg2 == "selected"

View file

@ -5,8 +5,21 @@
//TODO: make this a widget
var Publisher = {
close: function(){
Publisher.form().addClass('closed');
Publisher.form().find(".options_and_submit").hide();
},
open: function(){
Publisher.form().removeClass('closed');
Publisher.form().find(".options_and_submit").show();
},
form: function(){return $('#publisher');},
updateHiddenField: function(evt){
Publisher.form().find('#status_message_message').val(
Publisher.form().find('#status_message_fake_message').val());
},
initialize: function() {
var $publisher = $("#publisher");
var $publisher = Publisher.form();
$("div.public_toggle input").live("click", function(evt) {
$("#publisher_service_icons").toggleClass("dim");
if ($(this).attr('checked') == true) {
@ -14,38 +27,16 @@ var Publisher = {
}
});
if ($("#status_message_message").val() != "") {
$publisher
.removeClass("closed")
.find("textarea")
.focus();
if ($("#status_message_fake_message").val() == "") {
Publisher.close();
};
$publisher
.find(".options_and_submit")
.show();
}
$publisher.find("textarea").live("focus", function(evt) {
$publisher.find(".options_and_submit").show();
});
$publisher.find("textarea").live("click", function(evt) {
$publisher
.removeClass("closed")
.find("textarea")
.focus();
});
$publisher.find("textarea").bind("focus", function() {
$(this)
.css('min-height', '42px');
});
$publisher.find("form").bind("blur", function() {
$publisher
.find("textarea")
.css('min-height', '2px');
Publisher.updateHiddenField();
$publisher.find('#status_message_fake_message').change(
Publisher.updateHiddenField);
$publisher.find("textarea").bind("focus", function(evt) {
Publisher.open();
$(this).css('min-height', '42px');
});
}
};

View file

@ -57,7 +57,14 @@ describe AspectsController do
get :index
assigns[:contacts].map{|c| c.id}.should == @user.contacts.map{|c| c.id}
end
it "generates a jasmine fixture" do
get :index
save_fixture(html_for("body"), "aspects_index")
end
it "generates a jasmine fixture with a prefill" do
get :index, :prefill => "reshare things"
save_fixture(html_for("body"), "aspects_index_prefill")
end
context 'filtering' do
before do
@posts = []

View file

@ -5,4 +5,77 @@
describe("Publisher", function() {
describe("initialize", function(){
it("calls updateHiddenField", function(){
spec.loadFixture('aspects_index_prefill');
spyOn(Publisher, 'updateHiddenField');
Publisher.initialize();
expect(Publisher.updateHiddenField).toHaveBeenCalled();
});
it("attaches updateHiddenField to the change handler on fake_message", function(){
spec.loadFixture('aspects_index_prefill');
spyOn(Publisher, 'updateHiddenField');
Publisher.initialize();
Publisher.form().find('#status_message_fake_message').change();
expect(Publisher.updateHiddenField.mostRecentCall.args[0].type).toBe('change');
});
it("calls close when it does not have text", function(){
spec.loadFixture('aspects_index');
spyOn(Publisher, 'close');
Publisher.initialize();
expect(Publisher.close).toHaveBeenCalled();
});
it("does not call close when there is prefilled text", function(){
spec.loadFixture('aspects_index_prefill');
spyOn(Publisher, 'close');
Publisher.initialize();
expect(Publisher.close).wasNotCalled();
});
});
describe("open", function() {
beforeEach(function() {
spec.loadFixture('aspects_index');
Publisher.initialize();
});
it("removes the closed class", function() {
expect(Publisher.form().hasClass('closed')).toBeTruthy();
Publisher.open();
expect(Publisher.form().hasClass('closed')).toBeFalsy();
});
it("shows the options_and_submit div", function() {
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(0);
Publisher.open();
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(1);
});
});
describe("close", function() {
beforeEach(function() {
spec.loadFixture('aspects_index_prefill');
Publisher.initialize();
});
it("adds the closed class", function() {
expect(Publisher.form().hasClass('closed')).toBeFalsy();
Publisher.close();
expect(Publisher.form().hasClass('closed')).toBeTruthy();
});
it("hides the options_and_submit div", function() {
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(1);
Publisher.close();
expect(Publisher.form().find(".options_and_submit:visible").length).toBe(0);
});
});
describe("updateHiddenField", function(){
beforeEach(function(){
spec.loadFixture('aspects_index_prefill');
});
it("copies the value of fake_message to message",function(){
Publisher.updateHiddenField();
expect(Publisher.form().find('#status_message_message').val()).toBe(
Publisher.form().find('#status_message_fake_message').val());
});
});
});

View file

@ -29,6 +29,7 @@ src_files:
- public/javascripts/aspect-contacts.js
- public/javascripts/web-socket-receiver.js
- public/javascripts/view.js
- public/javascripts/publisher.js
- public/javascripts/stream.js
- public/javascripts/validation.js
- public/javascripts/rails.js