Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
#88 - clear comment list widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Sharov committed Nov 2, 2012
1 parent 00493f6 commit 42c4f38
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
54 changes: 24 additions & 30 deletions js/comments/commentsPortlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ $.widget('cmsUI.commentList', {
form_selector: '#comment-form',
label_selector: "#comment-label",
comments_list_selector: "#comments-div",
create_comments_url: "/comments/comment/create",
comments_list_url: "/comments/comment/list",
is_hidden: false
},
Expand All @@ -26,18 +25,6 @@ $.widget('cmsUI.commentList', {
widget.loadCommentsList();
}
},
bindTo: function(link)
{
var widget = this;
$("input[name='Comment[model_id]']", widget.form).val(link.data('model-id'));
$("input[name='Comment[object_id]']", widget.form).val(link.data('object-id'));
widget.form.attr('action', link.data('comments-url'));
},
setLoading: function() {
var widget = this;
var $loading_div = $('<div>загрузка комментариев...</div>').css('text-align', 'center');
widget.list.html($loading_div);
},
_initForm:function()
{
var widget = this;
Expand All @@ -51,7 +38,7 @@ $.widget('cmsUI.commentList', {
params[$(this).attr('name')] = $(this).val();
});

$.post(widget.options.create_comments_url, params, function(res)
$.post(widget.form.attr('action'), params, function(res)
{
widget.loadCommentsList();
$("textarea[name='Comment[text]']", widget.form).val("");
Expand All @@ -78,25 +65,32 @@ $.widget('cmsUI.commentList', {
return false;
});
},
bindToLink: function(link)
{
var widget = this;
$("input[name='Comment[model_id]']", widget.form).val(link.data('model-id'));
$("input[name='Comment[object_id]']", widget.form).val(link.data('object-id'));
widget.options.comments_list_url = link.data('comments-url');

},
setLoading: function()
{
var widget = this;
var $loading_div = $('<div>Загрузка комментариев...</div>').css('text-align', 'center');
widget.list.html($loading_div);
},
loadCommentsList: function (opts)
{
//TODO: add cache! or make it outside?
var widget = this;
var update_url = widget.options.comments_list_url;
if (opts && opts.url) {
update_url = opts.url;
}

var oid = $("input[name='Comment[object_id]']", widget.form).val(),
mid = $("input[name='Comment[model_id]']", widget.form).val();

$.get(update_url, {
object_id : oid,
model_id : mid
},
function(html)
{
widget.list.html(html);
}, 'html');
$.get( widget.options.comments_list_url, {
object_id : $("input[name='Comment[object_id]']", widget.form).val(),
model_id : $("input[name='Comment[model_id]']", widget.form).val()
},
function(html)
{
widget.list.html(html);
}, 'html'
);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
//comments
var comments_widget = $('#' + opts.comment_widget_id);
F.current.skin.append(comments_widget.show());
comments_widget.commentList('bindTo', F.current.element);
comments_widget.commentList('bindToLink', F.current.element);
comments_widget.commentList('setLoading');
comments_widget.commentList('loadCommentsList', {
url: F.current.element.data('comments-url')
});
comments_widget.commentList('loadCommentsList');
},
beforeClose: function(opts)
{
Expand Down

0 comments on commit 42c4f38

Please sign in to comment.