Refactor publisher JS, use hidden field for submitting
This commit is contained in:
parent
a687f26961
commit
cd8d9989cf
7 changed files with 117 additions and 42 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
-# the COPYRIGHT file.
|
-# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
#publisher{:class => ("closed" unless params[:op] || params[:prefill])}
|
#publisher
|
||||||
|
|
||||||
#click_to_share
|
#click_to_share
|
||||||
= image_tag 'icons/doc_edit.png'
|
= image_tag 'icons/doc_edit.png'
|
||||||
|
|
@ -27,8 +27,8 @@
|
||||||
%params
|
%params
|
||||||
#publisher_textarea_wrapper
|
#publisher_textarea_wrapper
|
||||||
%ul#photodropzone
|
%ul#photodropzone
|
||||||
= status.text_area :message, :rows => 2, :value => h(params[:prefill])
|
= status.text_area :fake_message, :rows => 2, :value => h(params[:prefill])
|
||||||
= javascript_tag "if ($('textarea#status_message_message').val() != ''){ $('textarea#status_message_message').focus();}"
|
= status.hidden_field :message, :value => ''
|
||||||
|
|
||||||
- for aspect_id in @aspect_ids
|
- for aspect_id in @aspect_ids
|
||||||
= hidden_field_tag 'aspect_ids[]', aspect_id.to_s
|
= hidden_field_tag 'aspect_ids[]', aspect_id.to_s
|
||||||
|
|
@ -1,27 +1,26 @@
|
||||||
|
@javascript
|
||||||
Feature: posting
|
Feature: posting
|
||||||
In order to enlighten humanity for the good of society
|
In order to enlighten humanity for the good of society
|
||||||
As a rock star
|
As a rock star
|
||||||
I want to tell the world I am eating a yogurt
|
I want to tell the world I am eating a yogurt
|
||||||
|
|
||||||
@javascript
|
|
||||||
Scenario: post to all aspects
|
Scenario: post to all aspects
|
||||||
Given I am signed in
|
Given I am signed in
|
||||||
And I have an aspect called "Family"
|
And I have an aspect called "Family"
|
||||||
And I am on the home page
|
And I am on the home page
|
||||||
And I expand the publisher
|
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 press "Share"
|
||||||
|
|
||||||
And I am on the home page
|
And I am on the home page
|
||||||
Then I should see "I am eating a yogurt" within ".stream_element"
|
Then I should see "I am eating a yogurt" within ".stream_element"
|
||||||
|
|
||||||
@javascript
|
|
||||||
Scenario: delete a post
|
Scenario: delete a post
|
||||||
Given I am signed in
|
Given I am signed in
|
||||||
And I have an aspect called "Family"
|
And I have an aspect called "Family"
|
||||||
And I am on the home page
|
And I am on the home page
|
||||||
And I expand the publisher
|
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 press "Share"
|
||||||
And I am on the home page
|
And I am on the home page
|
||||||
And I hover over the post
|
And I hover over the post
|
||||||
|
|
@ -32,12 +31,13 @@ Feature: posting
|
||||||
|
|
||||||
|
|
||||||
Scenario Outline: post to one aspect
|
Scenario Outline: post to one aspect
|
||||||
|
Given I have no open aspects saved
|
||||||
Given I am signed in
|
Given I am signed in
|
||||||
And I have an aspect called "PostTo"
|
And I have an aspect called "PostTo"
|
||||||
And I have an aspect called "DidntPostTo"
|
And I have an aspect called "DidntPostTo"
|
||||||
And I am on the home page
|
And I am on the home page
|
||||||
When I follow "PostTo"
|
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 press "Share"
|
||||||
And I follow "<aspect>"
|
And I follow "<aspect>"
|
||||||
Then I should <see> "I am eating a yogurt"
|
Then I should <see> "I am eating a yogurt"
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,11 @@ When /^I click on the contact request$/ do
|
||||||
find(".person.request.ui-draggable a").click
|
find(".person.request.ui-draggable a").click
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Given /^I have no open aspects saved$/ do
|
||||||
|
@me.aspects.update_all(:open => false)
|
||||||
|
end
|
||||||
Then /^I should have aspect "([^"]*)" "([^"]*)"$/ do |arg1, arg2|
|
Then /^I should have aspect "([^"]*)" "([^"]*)"$/ do |arg1, arg2|
|
||||||
val = evaluate_script("$('a:contains(\"#{arg1}\")').parent('li').hasClass('selected');") #
|
val = evaluate_script("$('a:contains(\"#{arg1}\")').parent('li').hasClass('selected');") #
|
||||||
if arg2 == "selected"
|
if arg2 == "selected"
|
||||||
val.should == true
|
val.should == true
|
||||||
elsif arg2 == "not selected"
|
elsif arg2 == "not selected"
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,21 @@
|
||||||
|
|
||||||
//TODO: make this a widget
|
//TODO: make this a widget
|
||||||
var Publisher = {
|
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() {
|
initialize: function() {
|
||||||
var $publisher = $("#publisher");
|
var $publisher = Publisher.form();
|
||||||
$("div.public_toggle input").live("click", function(evt) {
|
$("div.public_toggle input").live("click", function(evt) {
|
||||||
$("#publisher_service_icons").toggleClass("dim");
|
$("#publisher_service_icons").toggleClass("dim");
|
||||||
if ($(this).attr('checked') == true) {
|
if ($(this).attr('checked') == true) {
|
||||||
|
|
@ -14,38 +27,16 @@ var Publisher = {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($("#status_message_message").val() != "") {
|
if ($("#status_message_fake_message").val() == "") {
|
||||||
$publisher
|
Publisher.close();
|
||||||
.removeClass("closed")
|
};
|
||||||
.find("textarea")
|
|
||||||
.focus();
|
|
||||||
|
|
||||||
$publisher
|
Publisher.updateHiddenField();
|
||||||
.find(".options_and_submit")
|
$publisher.find('#status_message_fake_message').change(
|
||||||
.show();
|
Publisher.updateHiddenField);
|
||||||
}
|
$publisher.find("textarea").bind("focus", function(evt) {
|
||||||
|
Publisher.open();
|
||||||
$publisher.find("textarea").live("focus", function(evt) {
|
$(this).css('min-height', '42px');
|
||||||
$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');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,14 @@ describe AspectsController do
|
||||||
get :index
|
get :index
|
||||||
assigns[:contacts].map{|c| c.id}.should == @user.contacts.map{|c| c.id}
|
assigns[:contacts].map{|c| c.id}.should == @user.contacts.map{|c| c.id}
|
||||||
end
|
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
|
context 'filtering' do
|
||||||
before do
|
before do
|
||||||
@posts = []
|
@posts = []
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,77 @@
|
||||||
|
|
||||||
describe("Publisher", function() {
|
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());
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ src_files:
|
||||||
- public/javascripts/aspect-contacts.js
|
- public/javascripts/aspect-contacts.js
|
||||||
- public/javascripts/web-socket-receiver.js
|
- public/javascripts/web-socket-receiver.js
|
||||||
- public/javascripts/view.js
|
- public/javascripts/view.js
|
||||||
|
- public/javascripts/publisher.js
|
||||||
- public/javascripts/stream.js
|
- public/javascripts/stream.js
|
||||||
- public/javascripts/validation.js
|
- public/javascripts/validation.js
|
||||||
- public/javascripts/rails.js
|
- public/javascripts/rails.js
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue