Skip to content
Extraits de code Groupes Projets
Valider c11ffe93 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Actually close the publisher on and with Publisher.close()

parent cb67c14a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#publisher_textarea_wrapper #publisher_textarea_wrapper
%ul#photodropzone %ul#photodropzone
= status.text_area :fake_message, :rows => 2, :value => h(params[:prefill]) = status.text_area :fake_message, :rows => 2, :value => h(params[:prefill])
= status.hidden_field :message, :value => '' = status.hidden_field :message, :value => '', :class => 'clear_on_submit'
- 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
......
...@@ -8,10 +8,12 @@ var Publisher = { ...@@ -8,10 +8,12 @@ var Publisher = {
close: function(){ close: function(){
Publisher.form().addClass('closed'); Publisher.form().addClass('closed');
Publisher.form().find(".options_and_submit").hide(); Publisher.form().find(".options_and_submit").hide();
}, Publisher.form().find("textarea").css('min-height', '');
},
open: function(){ open: function(){
Publisher.form().removeClass('closed'); Publisher.form().removeClass('closed');
Publisher.form().find(".options_and_submit").show(); Publisher.form().find(".options_and_submit").show();
Publisher.form().find("textarea").css('min-height', '42px');
}, },
cachedForm : false, cachedForm : false,
form: function(){ form: function(){
...@@ -133,6 +135,9 @@ var Publisher = { ...@@ -133,6 +135,9 @@ var Publisher = {
} }
} }
}, },
clear: function(){
this.mentions = [];
},
destroyMentionAt : function(effectiveCursorIndex){ destroyMentionAt : function(effectiveCursorIndex){
var mentionIndex = this.mentionAt(effectiveCursorIndex); var mentionIndex = this.mentionAt(effectiveCursorIndex);
...@@ -245,6 +250,11 @@ var Publisher = { ...@@ -245,6 +250,11 @@ var Publisher = {
Publisher.oldInputContent = Publisher.input().val(); Publisher.oldInputContent = Publisher.input().val();
} }
}, },
clear: function(){
this.autocompletion.mentionList.clear();
$("#photodropzone").find('li').remove();
$("#publisher textarea").removeClass("with_attachments");
},
initialize: function() { initialize: function() {
Publisher.cachedForm = false; Publisher.cachedForm = false;
Publisher.cachedInput = false; Publisher.cachedInput = false;
...@@ -266,7 +276,6 @@ var Publisher = { ...@@ -266,7 +276,6 @@ var Publisher = {
Publisher.input().keyup(Publisher.autocompletion.keyUpHandler); Publisher.input().keyup(Publisher.autocompletion.keyUpHandler);
Publisher.form().find("textarea").bind("focus", function(evt) { Publisher.form().find("textarea").bind("focus", function(evt) {
Publisher.open(); Publisher.open();
$(this).css('min-height', '42px');
}); });
} }
}; };
......
...@@ -4,7 +4,7 @@ $.fn.clearForm = function() { ...@@ -4,7 +4,7 @@ $.fn.clearForm = function() {
if ($(this).is('form')) { if ($(this).is('form')) {
return $(':input', this).clearForm(); return $(':input', this).clearForm();
} }
if ($(this).is(':text') || $(this).is(':password') || $(this).is('textarea')) { if ($(this).hasClass('clear_on_submit') || $(this).is(':text') || $(this).is(':password') || $(this).is('textarea')) {
$(this).val(''); $(this).val('');
} else if ($(this).is(':checkbox') || $(this).is(':radio')) { } else if ($(this).is(':checkbox') || $(this).is(':radio')) {
$(this).attr('checked', false); $(this).attr('checked', false);
......
...@@ -73,9 +73,8 @@ var Stream = { ...@@ -73,9 +73,8 @@ var Stream = {
json = $.parseJSON(json); json = $.parseJSON(json);
WebSocketReceiver.addPostToStream(json.post_id, json.html); WebSocketReceiver.addPostToStream(json.post_id, json.html);
//collapse publisher //collapse publisher
$("#publisher").addClass("closed"); Publisher.close();
$("#photodropzone").find('li').remove(); Publisher.clear();
$("#publisher textarea").removeClass("with_attachments");
}); });
$(".new_status_message").bind('ajax:failure', function(data, html, xhr) { $(".new_status_message").bind('ajax:failure', function(data, html, xhr) {
......
...@@ -5,6 +5,8 @@ describe("rails", function() { ...@@ -5,6 +5,8 @@ describe("rails", function() {
'<form accept-charset="UTF-8" id="form" action="/status_messages" data-remote="true" method="post">' + '<form accept-charset="UTF-8" id="form" action="/status_messages" data-remote="true" method="post">' +
'<textarea id="status_message_message" name="status_message[message]">Some status message</textarea>' + '<textarea id="status_message_message" name="status_message[message]">Some status message</textarea>' +
'<input type="submit">' + '<input type="submit">' +
'<input id="standard_hidden" type="hidden" value="keep this value">' +
'<input id="clearable_hidden" type="hidden" class="clear_on_submit" value="clear this value">' +
'</form>' '</form>'
); );
}); });
...@@ -14,9 +16,17 @@ describe("rails", function() { ...@@ -14,9 +16,17 @@ describe("rails", function() {
}); });
it("should clear form on ajax:success", function() { it("should clear form on ajax:success", function() {
$('#form').trigger('ajax:success'); $('#form').trigger('ajax:success');
expect($('#status_message_message').val()).toEqual(""); expect($('#status_message_message').val()).toEqual("");
}); });
it('should not clear normal hidden fields', function(){
$('#form').trigger('ajax:success');
expect($('#standard_hidden').val()).toEqual("keep this value");
})
it('should clear hidden fields marked clear_on_submit', function(){
$('#form').trigger('ajax:success');
expect($('#clearable_hidden').val()).toEqual("");
})
}); });
}); });
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter