bolg comment becomes ok
This commit is contained in:
parent
3ca7870456
commit
14f57906eb
135 changed files with 27883 additions and 58 deletions
|
|
@ -7,15 +7,24 @@ if (typeof jQuery === 'undefined') {
|
|||
$.widget("psc.blogcomment", {
|
||||
options: {
|
||||
apictrlr: null,
|
||||
authorId: null,
|
||||
authorName: null,
|
||||
omob: '#ffe08030',
|
||||
omof: '#501208',
|
||||
bgc: '#fff',
|
||||
fgc: '#000',
|
||||
lang: 'fr-FR'
|
||||
lang: 'fr-FR',
|
||||
allowCoc: true
|
||||
},
|
||||
editable: false,
|
||||
editting: false,
|
||||
edctrl: null,
|
||||
hideBtn: null,
|
||||
delBtn: null,
|
||||
cmtInput: null,
|
||||
cmtBtn: null,
|
||||
ctlBtn: null,
|
||||
collapsed: false,
|
||||
subCmts: null,
|
||||
_create: function() {
|
||||
var _this = this;
|
||||
this.element.addClass("blogcomment");
|
||||
|
|
@ -26,18 +35,51 @@ if (typeof jQuery === 'undefined') {
|
|||
date.toLocaleDateString(this.options.lang) + ' ' + date.toLocaleTimeString(this.options.lang) + '</div></div>')
|
||||
this.element.on("mouseenter", this.onMouseEnter);
|
||||
this.element.on("mouseleave", this.onMouseLeave);
|
||||
if (this.editable) {
|
||||
this.element.on("click", function(ev) { _this.toggleEdit(_this, ev) })
|
||||
|
||||
this.ctlBtn = $('<button class="btn glyphicon-collapse-down"></button>').on("click", function(ev) { _this.toggleCollapse(_this, ev) }).appendTo(_this.element);
|
||||
},
|
||||
toggleCollapse: function(_this, ev) {
|
||||
_this.collapsed = !_this.collapsed;
|
||||
if (_this.collapsed) {
|
||||
$(_this.ctlBtn).removeClass('glyphicon-collapse-down');
|
||||
$(_this.ctlBtn).addClass('glyphicon-collapse-up');
|
||||
} else {
|
||||
$(_this.ctlBtn).removeClass('glyphicon-collapse-up');
|
||||
$(_this.ctlBtn).addClass('glyphicon-collapse-down');
|
||||
}
|
||||
if (_this.editable) {
|
||||
_this.toggleEdit(_this, ev)
|
||||
}
|
||||
if (_this.options.allowCoc) {
|
||||
_this.toggleComment(_this, ev)
|
||||
}
|
||||
},
|
||||
toggleEdit: function(_this, ev) {
|
||||
if (!_this.edctrl) {
|
||||
// TODO click on button
|
||||
_this.edctrl = $("<button class=\"btn btn-default\">Delete</button>");
|
||||
_this.edctrl.on("click", function(ev) { _this.doDeleteComment(_this, ev) }).appendTo(_this.element);
|
||||
if (!_this.delBtn) {
|
||||
_this.delBtn = $("<button class=\"btn btn-warning\">Supprimer</button>");
|
||||
_this.delBtn.on("click", function(ev) { _this.doDeleteComment(_this, ev) }).appendTo(_this.element);
|
||||
} else {
|
||||
_this.edctrl.remove();
|
||||
_this.edctrl = null;
|
||||
_this.delBtn.remove();
|
||||
_this.delBtn = null;
|
||||
}
|
||||
},
|
||||
toggleComment: function(_this, ev) {
|
||||
if (!_this.cmtBtn) {
|
||||
if (!_this.subCmts) {
|
||||
_this.subCmts = $(_this.element).children('div.subcomments');
|
||||
if (_this.subCmts.length == 0) {
|
||||
_this.subCmts = $('<div></div>').addClass('subcomments');
|
||||
_this.subCmts.appendTo(_this.element);
|
||||
}
|
||||
}
|
||||
_this.cmtInput = $('<input type="text" placeholder="Votre réponse"/>');
|
||||
_this.cmtInput.appendTo(_this.element);
|
||||
_this.cmtBtn = $("<button class=\"btn btn-default\">Répondre</button>");
|
||||
_this.cmtBtn.on("click", function(ev) { _this.doCoC(_this, ev) }).appendTo(_this.element);
|
||||
} else {
|
||||
_this.cmtInput.remove();
|
||||
_this.cmtBtn.remove();
|
||||
_this.cmtBtn = null;
|
||||
}
|
||||
},
|
||||
onMouseEnter: function() {
|
||||
|
|
@ -70,6 +112,45 @@ if (typeof jQuery === 'undefined') {
|
|||
},
|
||||
url: cmtapi + '/' + cmtid
|
||||
});
|
||||
},
|
||||
doCoC: function(_this, ev) {
|
||||
var postid = $('#cmtBtn').data('receiverid');
|
||||
var comment = _this.cmtInput.val();
|
||||
var cmtid = $(_this.element).data("id");
|
||||
var data = {
|
||||
Content: comment,
|
||||
PostId: postid,
|
||||
ParentId: cmtid,
|
||||
AuthorId: _this.options.authorId
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
async: true,
|
||||
cache: false,
|
||||
type: 'POST',
|
||||
method: 'POST',
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
error: function(xhr, erd) {
|
||||
console.log('err');
|
||||
console.log(xhr);
|
||||
console.log(erd);
|
||||
$('span.field-validation-valid[data-valmsg-for="Content"]').html(
|
||||
"Une erreur est survenue : " + xhr.status + "<br/>" +
|
||||
"<code><pre>" + xhr.responseText + "</pre></code>"
|
||||
)
|
||||
},
|
||||
success: function(data) {
|
||||
var comment = data.Content;
|
||||
_this.cmtInput.val('');
|
||||
$('span.field-validation-valid[data-valmsg-for="Content"]').empty();
|
||||
var htmlcmt = htmlize(comment);
|
||||
$('<div data-type="blogcomment" data-id="' + data.Id + '" data-allow-edit="True" data-date="' + data.DateCreated + '" data-username="' + _this.options.authorName + '">' + htmlcmt + '</div>')
|
||||
.blogcomment().appendTo(_this.subCmts);
|
||||
},
|
||||
url: _this.options.apictrlr
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue