Views.WallPost = Views.Base.extend({ classType: "Views.WallPost", tagName: "div", listenEvents: function() { //See Views.Base listenDefaultEvents() this.on("onrender", this.onRender); this.on("onmouseenter", this.manageDeleteIcon); }, manageDeleteIcon: function() { if (this.model.get("isdeletable") == false) { $("#remove_" + this.model.cid).remove(); } }, hide: function(callback) { //this.$el.animate({height:'0px'}, 100, callback); var that = this; this.$el.animate({height:'toggle'}, 300, function() { if (callback) { callback(); } that.trigger("onhide"); }); this.options.isShowed = false; }, show: function(callback) { //this.$el.animate({height:'0px'}, 100, callback); var that = this; this.$el.animate({height:'toggle'}, 300, function() { if (callback) { callback(); } that.trigger("onshow"); }); this.options.isShowed = true; }, onRender: function() { this.generateCommentLink(); //this.options.commentsview = edManager.getViewByID(this.cid + "_comments"); //this.options.commentinputview = edManager.getViewByID(this.cid + "_commentText"); var commentsInputView = edManager.getViewByID(this.cid + "_commentText"); if (commentsInputView) { commentsInputView.$el.on("keyup", {view: this}, this.commentKeyUp); commentsInputView.hide = function() { this.options.isShowed = false; this.$el.animate({height:'toggle'}, 100); }; commentsInputView.show = function() { this.options.isShowed = true; this.$el.animate({height:'toggle'}, 100, function(){ if ($(this).val() == "") { $(this).val(" "); $(this).val(""); } else { $(this).val($(this).val()); } }); }; } }, commentKeyUp: function(event) { var view = event.data.view; if (event.keyCode == 13) { if (event.target.value != ""){ view.postComment(event.target.value); $(event.target).val(""); } } }, toggleCommentsZone: function() { //console.log(this.options.commentsview.$el); var commentsView = edManager.getViewByID(this.cid + "_comments"); if (commentsView) { if (commentsView.options.isShowed) { commentsView.hide(); } else { commentsView.show(); if ((!commentsView.options.allCommentsLoaded) && (commentsView.options.parentview.model.get("nbcomment") > 0)) { this.loadComments(); } if (commentsView.options.parentview.model.get("nbcomment")==0) { commentsView.options.allCommentsLoaded = true; } } } var commentsInputView = edManager.getViewByID(this.cid + "_commentText"); if (commentsInputView) { if (commentsInputView.options.isShowed) { commentsInputView.hide(); } else { commentsInputView.show(); } } }, generateCommentLink: function() { if (!this.options.commentLinkView) { this.options.commentLinkView = edManager.getViewByID(this.id + "_commentLink"); } if (this.options.commentLinkView) { var edtooltip = this.options.commentLinkView.options.edtooltip; if (edtooltip) { edtooltip.loaded = false; } if (this.model.get("nbcomment") > 0) { this.options.commentLinkView.model.set("label", this.model.get("nbcomment") + " " + edApplication().labels.LABELCOMMENT); if (edtooltip) { edtooltip.content= edApplication().labels.LABELSEECOMMENT; } } else { if (this.model.get("iscommentable")) { this.options.commentLinkView.model.set("label", edApplication().labels.LABELNOCOMMENT); if (edtooltip) { this.options.commentLinkView.options.edtooltip.content= ''; } } else { this.options.commentLinkView.model.set("label", ""); } } this.options.commentLinkView.render(); } }, 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.cid + "_comments"); } this.options.commentsview.model.add(newComment); this.options.commentsview.trigger("onaddmodeltocollection"); //edManager.getViewByID(this.options.commentsview.id).model.add(newComment); this.model.set("nbcomment", this.model.get("nbcomment") + 1); this.generateCommentLink(); 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); } }); }, loadComments: function() { var url = edApplication().path + "post_comment.fl"; //console.log(JSON.stringify(sComment)); var aData = {postID: this.model.id}; var commentsView = edManager.getViewByID(this.cid + "_comments"); commentsView.displayNowLoading(); $.ajax({ url: url, data: aData, context: this, dataType:"json", success: function(data) { commentsView.removeNowLoading(); //data contains the collection of the comment, so refresh the model and render the view //this.options.commentsview.model = this.options.commentsview.getCollectionFromJSON(data); commentsView.model = commentsView.getCollectionFromJSON(data); commentsView.model.comparator = commentsView.model.sortByDate; commentsView.model.sort(); commentsView.renderList(); commentsView.options.allCommentsLoaded = true; }, 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); } }); }, blink: function() { this.$el.blink("background-color", "#d0eff7", 700); } }); Views.WallPostList = Views.BaseList.extend({ classType: "Views.WallPostList", listenEvents: function() { //See Views.Base listenDefaultEvents() this.on("onrender", this.onRender); this.on("oninitialize", this.onInitialize); }, onInitialize: function() { if (!this.options.actions) { this.options.actions = {}; } if (this.options.actions.sort) { if (!this.options.actions.sort.moveupbutton) { this.options.actions.sort.moveupbutton = {}; this.options.actions.sort.moveupbutton.position = { my: "left top", at: "right top", offset: "0 0", collision: "none" }; } if (!this.options.actions.sort.movedownbutton) { this.options.actions.sort.movedownbutton = {}; this.options.actions.sort.movedownbutton.position = { my: "left bottom", at: "right bottom", offset: "0 0", collision: "none" }; } } if (!this.options.actions.remove.button) { this.options.actions.remove.button = {}; } this.options.actions.remove.button.position = { my: "right top", at: "right top", collision: "none" }; }, onRender: function() { if (this.options.parentview) { this.options.displayinfonotification = this.options.parentview.options.displayinfonotification; } var that = this; this.model.on("remove", function(event) { that.removePost(event); }); }, addPost: function(event, newPostView) { if (newPostView.model.get("value") != ""){ this.postNewPost(newPostView.model.get("value")); newPostView.model.set("value", ""); newPostView.render(); } }, removePost: function(aModel) { var url = edApplication().path + "delete_post.fl"; var aData = {postID: aModel.id}; $.ajax({ url: url, data: aData, context: this, dataType:"json", success: function(data) { if (this.options.displayinfonotification) { Utils.openDialog(edApplication().labels.LABELINFORMATION, edApplication().labels.LABELDELETESUCCESS, {closetimeout: 5000, linkTo: this.deleteImg, 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); } }); }, postNewPost: function(sContent) { var objId = this.options.parentview.options.async.parameters.objId; var objType = this.options.parentview.options.async.parameters.objType; if (!objId) { var url = edApplication().path + "publish_mywallconfig.fl"; var aData = {content: encodeURIComponent(sContent)}; } else { var url = edApplication().path + "create_post.fl"; var aData = {objId: objId, objType: objType, content: encodeURIComponent(sContent)}; } $.ajax({ url: url, data: aData, context: this, dataType:"json", success: function(data) { if (this.options.displayinfonotification) { Utils.openDialog(edApplication().labels.LABELINFORMATION, edApplication().labels.LABELPUBLISHSUCCESS, {closetimeout: 5000, linkTo: $("#" + this.id + "_publishLink"), position: "STACK"}); } //data contains the Json model of the post, so refresh the model and render the view //var newPost = this.getModelFromJSON(data); var modelValue = new this.options.descriptor["viewItem"]["model"](data); this.model.add(modelValue, {at:0}); }, 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); } }); }, getCollectionFromJSON: function(str) { var parsedValues = str; var modelValue = new this.options.descriptor["model"](); modelValue.iscommentable = parsedValues["iscommentable"]; if (!$.isArray(parsedValues["posts"])) { modelValue.add(new this.options.descriptor["viewItem"]["model"](parsedValues["posts"])); } else { for (var j=0; j