Views.Wall = Views.Base.extend({
classType: "Views.Wall",
tagName: "div",
nowLoadingImage: "./skins/default/images/nowLoading.gif",
nowLoadingLabel: edApplication().labels.DEFAULTNOWLOADINGLABEL,
nowLoadingPosition: {
my: "bottom",
at: "top"
},
listenEvents: function() {
//See Views.Base listenDefaultEvents()
this.on("onrender", this.onRender);
},
onRender: function() {
//Manage follow link
this.manageWallTargetLink();
this.mapScrollEvent();
},
mapScrollEvent: function() {
if (this.options.enableloadonscroll) {
this.options.doscroll = {};
this.$el.scrollParent().scroll({viewList: this}, function(event){
var viewList = event.data.viewList;
clearTimeout(viewList.options.doscroll);
viewList.options.doscroll = setTimeout(function(){viewList.loadNextPost();}, 250);
});
} else {
var postListView = edManager.getViewByID(this.id + "_postlist");
if (postListView.model.length == this.options.async.parameters.top){
$("#wallShowMoreImage").show();
$("#wallShowMoreLink").show();
$("#wallShowMoreLink").on("click", {viewList: this}, function(event) {
var viewList = event.data.viewList;
viewList.loadNextPost();
});
} else {
this.options.allPostDisplayed = true;
$("#wallShowMoreLink").show();
$("#wallShowMoreImage").show();
$("#wallShowMoreLink").off("click");
$("#wallShowMoreLink").html(edApplication().labels.LABELNOMOREPOSTTOLOAD);
setTimeout(function(){$("#wallShowMoreLink").fadeOut(1000);$("#wallShowMoreImage").fadeOut(1000);}, 5000);
}
}
},
loadNextPost:function () {
var view = this;//event.data.view;
view.options.parentScrollObject = view.$el.scrollParent();
if ((!view.options.currentlyLoading) && (!view.options.allPostDisplayed)) {
var postListView = edManager.getViewByID(view.id + "_postlist");
var lastViewInList = postListView.getLastView();
if (lastViewInList) {
var mustLaunchEvent = (lastViewInList.$el.position().top < (view.options.parentScrollObject.height() + view.options.parentScrollObject.scrollTop()));
view.options.previousScrollTop = view.options.parentScrollObject.scrollTop();
if (mustLaunchEvent) {
view.options.currentlyLoading = true;
var url = edApplication().path + view.options.async.url;
//console.log(JSON.stringify(sComment));
var objId = view.options.async.parameters.objId;
var objType = view.options.async.parameters.objType;
var top = 20;
//get the older post to get its date
var toDate = lastViewInList.model.get("date");
var aData = {objId: objId, objType: objType, top: top, toDate: toDate};
view.displayNowLoading();
$.ajax({
url: url,
data: aData,
context: view,
dataType:"json",
success: function(data) {
this.removeNowLoading();
if (data) {
if (data["posts"].length > 0) {
//data contains the Json model of the post, so refresh the model and render the view
var newPosts = postListView.getCollectionFromJSON(data);
newPosts.each(function(postItem){
postListView.model.add(postItem);
});
//this.options.viewsinlist.reset();
//this.renderViewList();
this.options.parentScrollObject.scrollTop(view.previousScrollTop);
if (data["posts"].length < top) {
this.options.allPostDisplayed = true;
$("#wallShowMoreLink").show();
$("#wallShowMoreImage").show();
$("#wallShowMoreLink").off("click");
$("#wallShowMoreLink").html(edApplication().labels.LABELNOMOREPOSTTOLOAD);
setTimeout(function(){$("#wallShowMoreLink").fadeOut(1000);$("#wallShowMoreImage").fadeOut(1000);}, 5000);
}
} else {
this.options.allPostDisplayed = true;
}
}
this.options.currentlyLoading = false;
},
error: function(jqXHR, textStatus, errorThrown) {
view.currentlyLoading = false;
console.log("error :");
console.log("jqXHR :");
console.log(jqXHR);
console.log("textStatus :");
console.log(textStatus);
console.log("errorThrown :");
console.log(errorThrown);
}
});
}
}
view.options.currentlyLoading = false;
}
},
/*
* WALL TARGET MANAGEMENT
*
* */
manageWallTargetLink: function() {
if (!this.options.walltargetlinkview) {
this.options.walltargetlinkview = edManager.getViewByID("wallTargetLink");
this.options.walltargetimageview = edManager.getViewByID("wallTargetImage");
}
if (!this.options.walltargetlinkview) {
return false;
}
this.options.walltargetlinkview.$el.hide();
this.options.walltargetimageview.$el.hide();
var objId = this.options.async.parameters.objId;
var objType = this.options.async.parameters.objType;
if (objId) {
var data = {objId: objId, objType: objType};
$.ajax({
url: edApplication().path + "howIFollowThisObject.fl" ,
data: data,
dataType:"json",
context: this,
success: function(data, textStatus, jqXHR) {
if (data) {
this.options.walltargetlinkview.$el.show();
this.options.walltargetimageview.$el.show();
if (data.isInMyTarget) {
this.setImageDetails(data.isInMyTarget, data.isInSelection);
$("#wallTargetLink").on("click", {view: this}, this.removeTarget);
} else {
this.setImageDetails(data.isInMyTarget, data.isInSelection);
$("#wallTargetLink").on("click", {view: this}, this.addTarget);
}
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error :");
console.log("jqXHR :");
console.log(jqXHR);
console.log("textStatus :");
console.log(textStatus);
console.log("errorThrown :");
console.log(errorThrown);
}
});
}
},
setImageDetails: function(isInMyTarget, isInSelection) {
if (!this.options.walltargetlinkview.options.isInSelection) this.options.walltargetlinkview.options.isInSelection = isInSelection;
isInSelection = this.options.walltargetlinkview.options.isInSelection;
var title = "";
var tooltip = "";
if (isInMyTarget) {
//title = edApplication().labels.LABELSTOPFOLLOW;
title = edApplication().labels.LABELFOLLOWED;
tooltip = edApplication().labels.LABELSTOPFOLLOW;
if (this.options.walltargetlinkview.options.isInSelection) {
tooltip += "
" + edApplication().labels.LABELKEEPFOLLOW;
}
//this.options.walltargetlinkview.options.src= './skins/default/images/wall/unpin.png';
if (this.options.walltargetlinkview.options.edtooltip) {
this.options.walltargetlinkview.options.edtooltip.content = tooltip;
this.options.walltargetlinkview.options.edtooltip.loaded = false;
}
$("#wallTargetLink").html(title);
$("#wallTargetLink").attr({title:tooltip, alt:tooltip});
} else {
title = edApplication().labels.LABELFOLLOW;
tooltip = edApplication().labels.LABELFOLLOW;
if (this.options.walltargetlinkview.options.isInSelection) {
tooltip += "
" + edApplication().labels.LABELYOUFOLLOWED;
}
//this.options.walltargetlinkview.options.src= './skins/default/images/wall/pin.png';
if (this.options.walltargetlinkview.options.edtooltip) {
this.options.walltargetlinkview.options.edtooltip.content = tooltip;
this.options.walltargetlinkview.options.edtooltip.loaded = false;
}
//Fermer le tooltip ici s'il est ouvert !!!!!!!!!!!
$("#wallTargetLink").html(title);
$("#wallTargetLink").attr({title:title, alt:title});
}
//this.options.walltargetlinkview.render();
},
addTarget: function(event) {
var view = event.data.view;
var objId = view.options.async.parameters.objId;
var objType = view.options.async.parameters.objType;
$.ajax({
url: "add_target.fl",
data: {objType: objType, objId: objId},
context: view,
success: function(data) {
$("#wallTargetLink").off("click");
$("#wallTargetLink").on("click", {view: this}, this.removeTarget);
this.setImageDetails(true);
if (this.options.displayinfonotification) {
Utils.openDialog(edApplication().labels.LABELINFORMATION, edApplication().labels.LABELNOWFOLLOW, {closetimeout: 5000, linkTo: $("#wallTargetLink"), position: "STACK"});
}
}
});
},
removeTarget: function(event) {
var view = event.data.view;
var objId = view.options.async.parameters.objId;
var objType = view.options.async.parameters.objType;
$.ajax({
url: "delete_target.fl",
data: {objType: objType, objId: objId},
context: view,
success: function(data) {
$("#wallTargetLink").off("click");
$("#wallTargetLink").on("click", {view: this}, this.addTarget);
this.setImageDetails(false);
if (this.options.displayinfonotification) {
Utils.openDialog(edApplication().labels.LABELINFORMATION, edApplication().labels.LABELNOWNOTFOLLOW, {closetimeout: 5000, linkTo: $("#wallTargetLink"), position: "STACK"});
}
}
});
},
/*
* END WALL TARGET MANAGEMENT
*
* */
removePost: function(event) {
var view = event.data.view;
var url = edApplication().path + "delete_post.fl";
var aData = {postID: event.data.postModel.id};
$.ajax({
url: url,
data: aData,
context: event.data.view,
dataType:"json",
success: function(data) {
if (this.options.displayinfonotification) {
Utils.openDialog(edApplication().labels.LABELINFORMATION, edApplication().labels.LABELDELETESUCCESS, {closetimeout: 5000, linkTo: this.deleteImg, position: "STACK"});
}
this.options.parentview.model.remove(this.model);
this.options.parentview.renderViewList();
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error :");
console.log("jqXHR :");
console.log(jqXHR);
console.log("textStatus :");
console.log(textStatus);
console.log("errorThrown :");
console.log(errorThrown);
}
});
},
postComment: function(sComment) {
var url = edApplication().path + "add_comment.fl";
//console.log(JSON.stringify(sComment));
var aData = {objId: this.model.id, comment: encodeURIComponent(sComment)};
$.ajax({
url: url,
data: aData,
context: this,
dataType:"json",
success: function(data) {
//data contains the Json model of the post, so refresh the model and render the view
var newComment = this.getModelFromJSON(data);
if (!this.options.commentsview) {
this.options.commentsview = edManager.getViewByID(this.id + "_comments");
}
this.options.commentsview.model.add(newComment);
this.model.set("nbcomment", this.model.get("nbcomment") + 1);
this.generateCommentLink();
this.options.commentsview.renderViewList();
//this.options.commentsview.options.viewsinlist.reset();
//this.options.commentsview.render(true);
if (this.options.displayinfonotification) {
Utils.openDialog(edApplication().labels.LABELINFORMATION, edApplication().labels.LABELCOMMENTPUBLISHSUCCESS, {closetimeout: 5000, linkTo: $("#" + this.id + "_commentLink"), position: "STACK"});
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error :");
console.log("jqXHR :");
console.log(jqXHR);
console.log("textStatus :");
console.log(textStatus);
console.log("errorThrown :");
console.log(errorThrown);
}
});
}
});
Views.WallList = Views.BaseList.extend({
classType: "Views.WallList"
});