Models.WallPostComment = Models.Value.extend({ classType: "MODELS.WALLPOSTCOMMENT", postInitialize: function() { if (!this.get("comment")) { this.set("comment", ""); } }, getAdditionalJSONObject: function() { var comments = ""; var istherecomments = false; var nbcomments = 0; var isgroupactormessage = false; nbcomments = this.get("nbcomment"); if (nbcomments > 0) { istherecomments = true; } if (this.get("comments")) { if (istherecomments) { comments = JSON.stringify(this.get("comments")); } } var comment = ""; if (this.get("comment")) { //comment = unescape(this.get("comment")); comment = this.get("comment"); } var nbchanges = 0; var istherechanges = false; if (this.get("changes")) { //comment = unescape(this.get("comment")); nbchanges = this.get("changes").length; if (nbchanges > 0) { istherechanges = true; } } if (this.get("targetobject")) { if (this.get("targetobject").object == "GroupActor") { isgroupactormessage = true; } } var toReturn = { date: this.get("date"), targetobject: this.get("targetobject"), actor: this.get("actor"), isgroupactormessage: isgroupactormessage, eventtype: this.get("eventtype"), changes: this.get("changes"), iscreationevent: (this.get("eventtype")=="CREATION"), isfusionevent: (this.get("eventtype")=="FUSION"), isdeletable: this.get("isdeletable"), iscommentable: this.get("iscommentable"), amiowner: (this.get("actor").id==edContext().actorId), comments: comments, comment: comment, //comment: this.get("comment"), nbcomments: nbcomments, istherecomments: istherecomments, nbchanges: nbchanges, istherechanges: istherechanges }; //toReturn.targetobject.objectName = JSON.stringify(toReturn.targetobject.objectName); //console.log(toReturn.targetobject.objectName); //console.log(toReturn.targetobject.objectName.replace(new RegExp('"', 'g'), '\"')); return toReturn; } }); Models.WallPostCommentCollection = Models.BaseCollection.extend({ classType: "MODELS.WALLPOSTCOMMENTCOLLECTION", model: Models.WallPostComment, sortByDate: function(o1, o2) { var o1Date = o1.get("date").split(" ")[0]; var o1Time = o1.get("date").split(" ")[1]; var o1DateSplitted = o1Date.split("/"); var o1TimeSplitted = o1Time.split(":"); var o1RealDate = new Date(o1DateSplitted[2], o1DateSplitted[1], o1DateSplitted[0], o1TimeSplitted[0], o1TimeSplitted[1], o1TimeSplitted[2]); var o2Date = o2.get("date").split(" ")[0]; var o2Time = o2.get("date").split(" ")[1]; var o2DateSplitted = o2Date.split("/"); var o2TimeSplitted = o2Time.split(":"); var o2RealDate = new Date(o2DateSplitted[2], o2DateSplitted[1], o2DateSplitted[0], o2TimeSplitted[0], o2TimeSplitted[1], o2TimeSplitted[2]); return (o1RealDate >= o2RealDate); } });