Skip to content
Extraits de code Groupes Projets
Valider 27d4fd81 rédigé par Dan Hansen's avatar Dan Hansen
Parcourir les fichiers

fix retractions, fix likes, backfill likes widget tests, remove typo from...

fix retractions, fix likes, backfill likes widget tests, remove typo from jasmine.yml, remove unneeded js files
require confirmation for comments in js, get rid of rails helper
parent 2d45a428
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 131 ajouts et 135 suppressions
......@@ -31,16 +31,16 @@ class LikesController < ApplicationController
end
def destroy
if @like = Like.where(:id => params[:id], :author_id => current_user.person.id).first
if target && @like = Like.where(:id => params[:id], :author_id => current_user.person.id).first
current_user.retract(@like)
respond_to do |format|
format.all{}
format.js{ render 'likes/update' }
format.all { }
format.js { render 'likes/update' }
end
else
respond_to do |format|
format.mobile {redirect_to :back}
format.js {render :nothing => true, :status => 403}
format.mobile { redirect_to :back }
format.js { render :nothing => true, :status => 403 }
end
end
end
......
......@@ -5,7 +5,7 @@
%li.comment.posted{:id => comment.guid, :class => ("hidden" if(defined? hidden))}
- if current_user && (current_user.owns?(comment) || current_user.owns?(post))
.right.controls
= link_to image_tag('deletelabel.png'), post_comment_path(comment.post_id, comment), :class => "delete comment_delete", :title => t('delete'), :confirm => t('are_you_sure')
= link_to image_tag('deletelabel.png'), post_comment_path(comment.post_id, comment), :class => "delete comment_delete", :title => t('delete')
= person_image_link(comment.author, :size => :thumb_small)
.content
%span.from
......
$(".like_action", "#<%=@like.target.guid%>").first().html("<%= escape_javascript(like_action(@like.target))%>");
ContentUpdater.addLikesToPost("<%=@like.target.guid%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.likes_count, :target_type => @like.target_type)) %>");
$(".like_action", "#<%=@target.guid%>").first().html("<%= escape_javascript(like_action(@like.target))%>");
ContentUpdater.addLikesToPost("<%=@like.target.guid%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @target.reload.likes_count, :target_type => @like.target_type)) %>");
\ No newline at end of file
......@@ -8,18 +8,18 @@ javascripts:
- public/javascripts/vendor/swfobject.js
- public/javascripts/vendor/web_socket.js
jquery:
- public/javascripts/vendor/jquery152.min.js
- public/javascripts/vendor/jquery162.min.js
main:
- public/javascripts/rails.js
- public/javascripts/vendor/jquery.tipsy.js
- public/javascripts/vendor/jquery.hotkeys.js
- public/javascripts/vendor/jquery.autoresize.min.js
- public/javascripts/vendor/jquery-ui-1.8.9.custom.min.js
- public/javascripts/vendor/jquery.charcount.js
- public/javascripts/vendor/jquery-debounce.js
- public/javascripts/vendor/jquery.expander.js
- public/javascripts/vendor/timeago.js
- public/javascripts/vendor/Mustache.js
- public/javascripts/vendor/charCount.js
- public/javascripts/vendor/facebox.js
- public/javascripts/jquery.infinitescroll-custom.js
- public/javascripts/jquery.autocomplete-custom.js
......
......@@ -46,9 +46,12 @@ var ContentUpdater = {
},
addLikesToPost: function(postGUID, html) {
$(".likes_container", "#" + postGUID)
var likesContainer = $(".likes_container", "#" + postGUID)
.fadeOut("fast")
.html(html)
.fadeIn("fast");
.html(html);
Diaspora.page.stream.streamElements[postGUID].likes.publish("widget/ready", [likesContainer]);
likesContainer.fadeIn("fast");
}
};
......@@ -68,20 +68,22 @@
});
};
window.Diaspora = Diaspora;
})();
Diaspora.instantiatePage = function() {
if (typeof Diaspora.Pages[Diaspora.Page] === "undefined") {
Diaspora.page = Diaspora.EventBroker.extend(Diaspora.BaseWidget);
} else {
var Page = Diaspora.Pages[Diaspora.Page];
$.extend(Page.prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget));
Diaspora.page = new Page();
}
$.extend(Diaspora.page, new Diaspora.BasePage($(document.body)));
Diaspora.page.publish("page/ready", [$(document.body)])
};
$(function() {
if (typeof Diaspora.Pages[Diaspora.Page] === "undefined") {
Diaspora.page = Diaspora.EventBroker.extend(Diaspora.BaseWidget);
} else {
var Page = Diaspora.Pages[Diaspora.Page];
$.extend(Page.prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget));
window.Diaspora = Diaspora;
})();
Diaspora.page = new Page();
}
$.extend(Diaspora.page, new Diaspora.BasePage($(document.body)));
Diaspora.page.publish("page/ready", [$(document.body)])
});
\ No newline at end of file
$(Diaspora.instantiatePage);
\ No newline at end of file
......@@ -67,22 +67,6 @@ var Stream = {
Stream.focusNewComment($(this), evt);
});
$(".comment .comment_delete", this.selector).live("ajax:success", function() {
var element = $(this),
target = element.parents(".comment"),
post = element.closest(".stream_element"),
toggler = post.find(".toggle_post_comments");
target.hide("blind", { direction: "vertical" }, 300, function() {
$(this).remove();
toggler.html(
toggler.html().replace(/\d+/, $(".comments li", post).length - 1)
);
});
});
$("textarea.comment_box", this.selector).live("focus", function(evt) {
if (this.value === undefined || this.value === ''){
var commentBox = $(this);
......@@ -146,8 +130,7 @@ var Stream = {
textarea.focus();
}
}
},
}
};
$(document).ready(function() {
......
/*
* Character Count Plugin - jQuery plugin
* Dynamic character count for text areas and input fields
* written by Alen Grakalic
* http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas
*
* Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Built for jQuery library
* http://jquery.com
*
*/
(function($) {
$.fn.charCount = function(options){
// default configuration properties
var defaults = {
allowed: 140,
warning: 25,
css: 'counter',
counterElement: 'span',
cssWarning: 'warning',
cssExceeded: 'exceeded',
counterText: ''
};
var options = $.extend(defaults, options);
function calculate(obj){
var count = $(obj).val().length;
var available = options.allowed - count;
if(available <= options.warning && available >= 0){
$(obj).next().addClass(options.cssWarning);
} else {
$(obj).next().removeClass(options.cssWarning);
}
if(available < 0){
$(obj).next().addClass(options.cssExceeded);
} else {
$(obj).next().removeClass(options.cssExceeded);
}
$(obj).next().html(options.counterText + available);
};
this.each(function() {
$(this).after('<'+ options.counterElement +' class="' + options.css + '">'+ options.counterText +'</'+ options.counterElement +'>');
calculate(this);
$(this).keyup(function(){calculate(this)});
$(this).change(function(){calculate(this)});
});
};
})(jQuery);
Ce diff est replié.
......@@ -17,7 +17,7 @@ var WSR = WebSocketReceiver = {
else {
switch(message["class"]) {
case "retractions":
ContentUpdater.removePostFromStream(message.post_guid);
ContentUpdater.removePostFromStream(message.post_id);
break;
case "comments":
ContentUpdater.addCommentToPost(message.post_guid, message.comment_guid, message.html);
......
......@@ -15,13 +15,15 @@
this.removeComment = function(evt) {
evt.preventDefault();
$.post(self.deleteCommentLink.attr("href"), {
_method: "delete"
}, function() {
self.comment.hide("blind", { direction: "vertical" }, 300, function() {
self.comment.remove();
if(confirm(Diaspora.I18n.t("confirm_dialog"))) {
$.post(self.deleteCommentLink.attr("href"), {
_method: "delete"
}, function() {
self.comment.hide("blind", { direction: "vertical" }, 300, function() {
self.comment.remove();
});
});
});
}
};
};
......
......@@ -13,10 +13,11 @@
this.expandLikes = function(evt) {
evt.preventDefault();
var likesList = $(this).siblings(".likes_list");
var likesList = self.expander.siblings(".likes_list");
if(likesList.children().length == 0) {
self.loadingImage.appendTo(likesList.parent());
$.get(this.href, function(data) {
$.get(self.expander.href, function(data) {
self.loadingImage.fadeOut(100, function() {
likesList.html(data)
.fadeToggle(100);
......
......@@ -89,6 +89,15 @@ describe AspectsController do
save_fixture(html_for("body"), "aspects_index_with_video_post")
end
it "generates a jasmine fixture with a post that has been liked", :fixture => true do
message = alice.post(:status_message, :text => "hello "*800, :to => @alices_aspect_2.id)
alice.build_like(:positive => true, :target => message).save
bob.build_like(:positive => true, :target => message).save
get :index
save_fixture(html_for("body"), "aspects_index_with_a_post_with_likes")
end
context 'with getting_started = true' do
before do
alice.getting_started = true
......
......@@ -69,12 +69,11 @@ describe("ContentUpdater", function() {
it("adds a comment to a post only if it doesn't already exist", function() {
var comments = post.find("ul.comments li");
expect(comments.length).toEqual(0);
ContentUpdater.addCommentToPost(postGUID, "YEAH", "<li id='YEAH'>Comment</li>");
expect(post.find("ul.comments li").length).toEqual(1);
expect(post.find("ul.comments li").length).toEqual(comments.length + 1);
ContentUpdater.addCommentToPost(postGUID, "YEAH", "<li id='YEAH'>Comment</li>");
expect(post.find("ul.comments li").length).toEqual(1);
expect(post.find("ul.comments li").length).toEqual(comments.length + 1);
});
});
......@@ -83,13 +82,29 @@ describe("ContentUpdater", function() {
var post, postGUID;
beforeEach(function() {
spec.loadFixture("aspects_index_with_posts");
Diaspora.Page = "AspectsIndex";
Diaspora.instantiatePage();
console.log(Diaspora, $("#main_stream"), $("#jasmine_content"));
post = $(".stream_element:first"),
postGUID = post.attr("id");
});
it("adds the given html to a post's likes container", function() {
jasmine.Clock.useMock();
ContentUpdater.addLikesToPost(postGUID, "<p>1 like</p>");
jasmine.Clock.tick(250);
expect(post.find(".likes .likes_container").html()).toEqual("<p>1 like</p>");
});
afterEach(function() {
$.fx.off = false;
});
});
});
......@@ -23,6 +23,7 @@ beforeEach(function() {
self.directionDetector = self.instantiate("DirectionDetector");
});
};
var Page = Diaspora.Pages["TestPage"];
$.extend(Page.prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget));
......
......@@ -11,22 +11,24 @@
# - dist/**/*.js
#
src_files:
- public/javascripts/vendor/jquery152.min.js
- public/javascripts/vendor/jquery162.min.js
- public/javascripts/vendor/jquery-ui-1.8.9.custom.min.js
- public/javascripts/vendor/jquery.tipsy.js
- public/javascripts/jquery.infieldlabel-custom.js
- public/javascripts/vendor/jquery.infinitescroll.min.js
- public/javascripts/vendor/jquery.autoresize.min.js
- public/javascripts/vendor/jquery.expander.js]
- public/javascripts/vendor/jquery.expander.js
- public/javascripts/vendor/jquery-debounce.js
- public/javascripts/vendor/Mustache.js
- public/javascripts/vendor/charCount.js
- public/javascripts/vendor/jquery.charcount.js
- public/javascripts/vendor/timeago.js
- public/javascripts/vendor/facebox.js
- public/javascripts/jquery.infieldlabel-custom.js
- public/javascripts/fileuploader-custom.js
- public/javascripts/jquery.autocomplete-custom.js
- public/javascripts/diaspora.js
- public/javascripts/keycodes.js
- public/javascripts/pages/*
- public/javascripts/helpers/*
- public/javascripts/widgets/*
......
describe("Diaspora.Widgets.Likes", function() {
var likes;
beforeEach(function() {
spec.loadFixture("aspects_index_with_a_post_with_likes");
likes = Diaspora.BaseWidget.instantiate("Likes", $(".stream_element .likes_container"));
});
describe("integration", function() {
beforeEach(function() {
likes = new Diaspora.Widgets.Likes();
spyOn(likes, "expandLikes");
likes.publish("widget/ready", [$(".stream_element .likes_container")]);
});
it("calls expandLikes when you click on the expand likes link", function() {
$(".stream_element a.expand_likes").click();
expect(likes.expandLikes).toHaveBeenCalled();
});
});
describe("expandLikes", function() {
it("makes an ajax request if the list does not have children", function() {
spyOn($, "ajax");
likes.expandLikes($.Event());
expect($.ajax).toHaveBeenCalled();
});
it("does not make an ajax request if the list has children", function() {
spyOn($, "ajax");
$(".stream_element .likes_list").html("<span></span>");
likes.expandLikes($.Event());
expect($.ajax).not.toHaveBeenCalled();
});
it("makes the likes list's html the response of the request", function() {
spyOn($, "ajax");
likes.expandLikes($.Event());
$.ajax.mostRecentCall.args[0].success("some html response");
expect($(".stream_element .likes_list").html()).toEqual("some html response");
});
});
});
\ 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