Пример #1
0
    def fetchcomments(self, uid, itemindex, lasttimestamp, commentcount,
                      lastcommentid, viewtype):
        query = {'UID': uid}
        pdt = getToolByName(self.context, 'portal_discussion', None)
        cat = getToolByName(self.context, 'uid_catalog')
        resbrains = cat.searchResults(query)
        if len(resbrains) == 1:
            zopecommands = self.getCommandSet('zope')
            ksscore = self.getCommandSet('core')
            jq = self.getCommandSet('jquery')

            listcommentcontainer = ksscore.getHtmlIdSelector(
                'comcynapselistcommentscontainer' + itemindex)
            listcountspan = ksscore.getHtmlIdSelector('commentcountspan' +
                                                      itemindex)
            nocommentsyet = ksscore.getCssSelector('.nocommentsyet')
            listtimeoutuid = ksscore.getHtmlIdSelector(
                'comcynapsecyninfetchUID')
            listtimeoutindex = ksscore.getHtmlIdSelector(
                'comcynapsecyninfetchindex')
            listtimeouttimestamp = ksscore.getHtmlIdSelector(
                'comcynapselasttimestamp')
            listtimeoutlastcommentid = ksscore.getHtmlIdSelector(
                'comcynapselastcommentid')
            listtimeoutcommentcount = ksscore.getHtmlIdSelector(
                'comcynapsecommentcount')

            listcommentscount = ksscore.getHtmlIdSelector(
                'listdiscussioncount' + itemindex)

            contobj = resbrains[0].getObject()
            isDiscussable = contobj.isDiscussable()
            canReply = self.canreply(contobj)
            if isDiscussable and canReply:
                passedcommentcount = 0
                passedcommentcount = int(commentcount)
                flasttimestamp = float(lasttimestamp)
                datefromlasttimestamp = DateTime(flasttimestamp)
                newlastdate = datefromlasttimestamp.timeTime()

                disc_container = pdt.getDiscussionFor(contobj)
                newreplycount = disc_container.replyCount(contobj)
                allreplies = self.get_replies(pdt, contobj)

                if passedcommentcount <> newreplycount:
                    alldiscussions = disc_container.objectValues()
                    newlastcommentid = lastcommentid

                    newlyaddedcomments = [
                        k for k in alldiscussions
                        if k.modified().greaterThan(datefromlasttimestamp)
                        and k.id not in (lastcommentid)
                    ]
                    newlyaddedcomments.sort(
                        lambda x, y: cmp(x.modified(), y.modified()))

                    lenofnewcomments = len(newlyaddedcomments)
                    display_count = self.get_displaycountforlist()

                    lastxdiscussions = []
                    if lenofnewcomments >= display_count:
                        newlyaddedcomments.sort(
                            lambda x, y: cmp(x.modified(), y.modified()),
                            reverse=True)
                        lastxdiscussions = newlyaddedcomments[:display_count]
                        lastxdiscussions.sort(
                            lambda x, y: cmp(x.modified(), y.modified()))
                        ksscore.clearChildNodes(listcommentcontainer)
                    else:
                        lastxdiscussions = newlyaddedcomments
                        if lenofnewcomments > 0 and len(
                                alldiscussions) > display_count:
                            alldiscussions.sort(
                                lambda x, y: cmp(x.modified(), y.modified()),
                                reverse=True)
                            marker_discussion = alldiscussions[display_count -
                                                               1:display_count]
                            if len(marker_discussion) > 0:
                                #delete nodes before this item
                                marker_node = ksscore.getHtmlIdSelector(
                                    'commenttable' + marker_discussion[0].id)
                                ksscore.deleteNodeBefore(marker_node)

                    complete_output = ''
                    list_reply_ids = []
                    for eachcomment in lastxdiscussions:
                        reply = disc_container.getReply(eachcomment.id)
                        if reply <> None:
                            parentsInThread = reply.parentsInThread()
                            depthvalue = 0
                            if viewtype.lower() == 'threadedview':
                                lenofparents = len(parentsInThread)
                                depthvalue = lenofparents - 1

                            prev_reply_id = self.findpreviouscommentid(
                                allreplies, reply)

                            newlastdate = reply.modified().timeTime()
                            newlastcommentid = reply.id
                            commenttemplate = ViewPageTemplateFile(
                                'ksstemplates/commentrow.pt')
                            commenttemplate = commenttemplate.__of__(
                                self.context)

                            replydict = [
                                {
                                    'depth': depthvalue,
                                    'object': reply,
                                    'prev_id': prev_reply_id,
                                    'view_type': viewtype,
                                    'showoutput': False
                                },
                            ]
                            output = commenttemplate.render(
                                reply_dict=replydict,
                                allowdiscussion=isDiscussable,
                                usercanreply=canReply)
                            list_reply_ids.append(reply.id)
                            complete_output += output

                    if complete_output <> '' and len(lastxdiscussions) > 0:
                        ksscore.insertHTMLAsLastChild(listcommentcontainer,
                                                      complete_output)
                        for erid in list_reply_ids:
                            newcomment = ksscore.getHtmlIdSelector(
                                'commenttable' + erid)
                            jq.serverEffect(newcomment, "fadeIn", "slow")

                    ksscore.setAttribute(listtimeoutuid, 'value', uid)
                    ksscore.setAttribute(listtimeoutindex, 'value', itemindex)
                    ksscore.setAttribute(listtimeouttimestamp, 'value',
                                         str(newlastdate))
                    ksscore.setAttribute(listtimeoutlastcommentid, 'value',
                                         newlastcommentid)
                    ksscore.setAttribute(listtimeoutcommentcount, 'value',
                                         str(newreplycount))
                    ksscore.setAttribute(listtimeoutuid, 'value', uid)

                    if newreplycount > display_count:
                        xmorecomments = newreplycount - display_count
                        ksscore.replaceInnerHTML(listcommentscount,
                                                 str(xmorecomments))
                        jq.serverEffect(nocommentsyet, "fadeOut", "fast")
                        jq.serverEffect(listcountspan, "fadeIn", "slow")
                    elif newreplycount > 0 and newreplycount <= display_count:
                        jq.serverEffect(nocommentsyet, "fadeOut", "fast")

                    jq.serverCall(listcommentcontainer,
                                  'truncatetextonitemexpand')
Пример #2
0
    def toggleCommentsView(self, viewtype):
        zopecommands = self.getCommandSet('zope')
        ksscore = self.getCommandSet('core')
        jq = self.getCommandSet('jquery')
        commentshiddencontainer = ksscore.getHtmlIdSelector(
            'comcynapsehiddencomments')
        commentscontainer = ksscore.getHtmlIdSelector(
            'comcynapsecyninitemcommentscontainer')
        addnewlasttimestamp = ksscore.getHtmlIdSelector(
            'comcynapselasttimestamp')
        addnewlastcommentid = ksscore.getHtmlIdSelector(
            'comcynapselastcommentid')
        addnewcommentcount = ksscore.getHtmlIdSelector(
            'comcynapsecommentcount')

        objcommentslist = []
        pdt = getToolByName(self.context, 'portal_discussion', None)
        if pdt <> None:
            disc_container = pdt.getDiscussionFor(self.context)
            alldiscussions = disc_container.objectValues()
            allreplies = self.get_replies(pdt, self.context)
            newreplycount = disc_container.replyCount(self.context)
            newlastdate = DateTime().timeTime()

            if viewtype == 'flatview':
                alldiscussions.sort(
                    lambda x, y: cmp(x.modified(), y.modified()))
                objcommentslist.extend(alldiscussions)
            else:
                objcommentslist.extend(allreplies)

            ksscore.replaceInnerHTML(commentscontainer, '')
            complete_output = ''
            for eachcomment in objcommentslist:
                if hasattr(eachcomment, 'id'):
                    id = eachcomment.id
                elif eachcomment.has_key('id'):
                    id = eachcomment['id']

                reply = disc_container.getReply(id)
                if reply <> None:
                    parentsInThread = reply.parentsInThread()
                    depthvalue = 0
                    if viewtype.lower() == 'threadedview':
                        lenofparents = len(parentsInThread)
                        depthvalue = lenofparents - 1

                    prev_reply_id = self.findpreviouscommentid(
                        allreplies, reply)

                    newlastdate = reply.modified().timeTime()
                    commenttemplate = ViewPageTemplateFile(
                        'ksstemplates/commentrow.pt')
                    commenttemplate = commenttemplate.__of__(self.context)
                    replydict = [
                        {
                            'depth': depthvalue,
                            'object': reply,
                            'prev_id': prev_reply_id,
                            'view_type': viewtype,
                            'showoutput': True
                        },
                    ]
                    output = commenttemplate.render(reply_dict=replydict)

                    #if there is no prev id found for new comment then insert it as last item to commentscontainer
                    #else insert it after prev id comments table.
                    if viewtype == 'flatview':
                        complete_output += output
                    else:
                        complete_output += output

            if complete_output <> '' and len(objcommentslist) > 0:
                ksscore.replaceInnerHTML(commentscontainer, complete_output)
                jq.serverCall(commentscontainer, 'truncatetextonitemexpand')
            if len(alldiscussions) > 0:
                strlastcommentid = str(alldiscussions[-1].id)
                ksscore.setKssAttribute(commentshiddencontainer,
                                        'lastcommentid', strlastcommentid)
                ksscore.setAttribute(addnewlastcommentid, 'value',
                                     strlastcommentid)

            newlasttimestamp = str(newlastdate)
            strcommentcount = str(newreplycount)
            ksscore.setKssAttribute(commentshiddencontainer, 'lasttimestamp',
                                    newlasttimestamp)
            ksscore.setKssAttribute(commentshiddencontainer, 'commentcount',
                                    strcommentcount)

            ksscore.setAttribute(addnewlasttimestamp, 'value',
                                 newlasttimestamp)
            ksscore.setAttribute(addnewcommentcount, 'value', strcommentcount)

            itemcountcommentcount = ksscore.getHtmlIdSelector(
                'itemcountcommentcount')
            discussionlabel = ksscore.getHtmlIdSelector('discussionlabel')
            ksscore.replaceInnerHTML(discussionlabel, strcommentcount)
            ksscore.replaceInnerHTML(itemcountcommentcount, strcommentcount)

        ksscore.setKssAttribute(commentshiddencontainer, 'viewtype', viewtype)
        addnewcommentviewtype = ksscore.getHtmlIdSelector('comcynapseviewtype')
        ksscore.setAttribute(addnewcommentviewtype, 'value', viewtype)
        ksscore.setStyle(commentscontainer, 'display', 'block')
Пример #3
0
    def getDiscussionView(self, uid, itemindex, state, openeditemindex):
        ksscore = self.getCommandSet('core')
        zopecore = self.getCommandSet('zope')
        jq = self.getCommandSet('jquery')

        clickednode = ksscore.getHtmlIdSelector('listitemdiscusslinktop' +
                                                itemindex)
        listcommentcontainer = ksscore.getHtmlIdSelector('listitemdiscussrow' +
                                                         itemindex)
        listtimeoutuid = ksscore.getHtmlIdSelector('comcynapsecyninfetchUID')
        listtimeoutindex = ksscore.getHtmlIdSelector(
            'comcynapsecyninfetchindex')
        listtimeouttimestamp = ksscore.getHtmlIdSelector(
            'comcynapselasttimestamp')
        listtimeoutlastcommentid = ksscore.getHtmlIdSelector(
            'comcynapselastcommentid')
        listtimeoutcommentcount = ksscore.getHtmlIdSelector(
            'comcynapsecommentcount')
        listitemdetailright = ksscore.getHtmlIdSelector('listitemdetail' +
                                                        itemindex)

        if openeditemindex != itemindex:
            openednode = ksscore.getHtmlIdSelector('listitemdiscusslinktop' +
                                                   openeditemindex)
            listopenedcommentcontainer = ksscore.getHtmlIdSelector(
                'listitemdiscussrow' + openeditemindex)
            ksscore.setKssAttribute(openednode, 'state', 'closed')
            ksscore.replaceInnerHTML(listopenedcommentcontainer, '')

        if state.lower() != 'closed':
            ksscore.setKssAttribute(clickednode, 'state', 'closed')
            ksscore.replaceInnerHTML(listcommentcontainer, '')
            return

        query = {'UID': uid}
        pdt = getToolByName(self.context, 'portal_discussion')
        cat = getToolByName(self.context, 'uid_catalog')
        resbrains = cat.searchResults(query)
        if len(resbrains) == 1:
            contobj = resbrains[0].getObject()
            isDiscussable = contobj.isDiscussable()
            canReply = self.canreply(contobj)
            if isDiscussable and canReply:
                dobj = pdt.getDiscussionFor(contobj)
                alldiscussions = dobj.objectValues()
                alldiscussions.sort(
                    lambda x, y: cmp(x.modified(), y.modified()), reverse=True)
                maxdispcomments = self.get_displaycountforlist()
                lastxdiscussions = alldiscussions[:maxdispcomments]

                commentscount = dobj.replyCount(contobj)
                if commentscount > maxdispcomments:
                    showxmorelink = True
                    xmorecomments = commentscount - maxdispcomments
                elif commentscount > 0 and commentscount <= maxdispcomments:
                    showxmorelink = False
                    xmorecomments = 0
                else:
                    showxmorelink = True
                    commentscount = 0
                    xmorecomments = 0
                lasttimestamp = DateTime().timeTime()
                lastcommentid = '0'
                if len(alldiscussions) > 0:
                    lasttimestamp = alldiscussions[0].modified().timeTime()
                    lastcommentid = alldiscussions[0].id

                commenttemplate = ViewPageTemplateFile(
                    'ksstemplates/listcomment.pt')
                commenttemplate = commenttemplate.__of__(self.context)

                replydict = []
                lastxdiscussions.sort(
                    lambda x, y: cmp(x.modified(), y.modified()))
                for eachdisc in lastxdiscussions:
                    reply = dobj.getReply(eachdisc.id)
                    if reply <> None:
                        replydict.append({
                            'depth': 0,
                            'object': reply,
                            'view_type': 'listview',
                            'showoutput': True
                        })

                output = commenttemplate.render(contobj=contobj,
                                                showxmorelink=showxmorelink,
                                                xmorecomments=xmorecomments,
                                                itemindex=itemindex,
                                                uid=uid,
                                                reply_dict=replydict,
                                                title=contobj.Title(),
                                                commentcount=commentscount,
                                                lasttimestamp=lasttimestamp,
                                                lastcommentid=lastcommentid,
                                                allowdiscussion=isDiscussable,
                                                usercanreply=canReply)

                detailtemplate = ViewPageTemplateFile(
                    'ksstemplates/listitemdetails.pt')
                detailtemplate = detailtemplate.__of__(self.context)

                item = resbrains[0]
                fullpath = item.getPath()
                splitpath = fullpath.split('/')[:-1]
                prettypath = '/' + '/'.join(splitpath)
                URLsuffix = getListingTemplateForContextParent(item)
                pathlink = self.context.portal_url(
                ) + prettypath + '/' + URLsuffix
                pathtitle = prettypath

                detail = detailtemplate.render(
                    item_type=contobj.portal_type,
                    portal_url=self.context.portal_url(),
                    item_type_title=contobj.Type(),
                    item=item,
                    pathlink=pathlink,
                    pathtitle=pathtitle,
                    contobj=contobj)
                ksscore.replaceInnerHTML(listitemdetailright,
                                         force_unicode(detail, 'utf'))
                ksscore.replaceInnerHTML(listcommentcontainer, output)

                ksscore.setKssAttribute(clickednode, 'state', 'opened')

                ksscore.setAttribute(listtimeoutuid, 'value', uid)
                ksscore.setAttribute(listtimeoutindex, 'value', itemindex)
                ksscore.setAttribute(listtimeouttimestamp, 'value',
                                     str(lasttimestamp))
                ksscore.setAttribute(listtimeoutlastcommentid, 'value',
                                     lastcommentid)
                ksscore.setAttribute(listtimeoutcommentcount, 'value',
                                     str(commentscount))
                jq.serverCall(clickednode, 'truncatetextonitemexpand')
                jq.serverCall(clickednode, 'marklistedtags')
                jq.serverCall(listcommentcontainer, 'activateinputlabel')
Пример #4
0
    def replyToComment(self, viewtype, lasttimestamp, commentcount,
                       lastcommentid):
        query = {'UID': self.request['cont_uid']}
        pdt = getToolByName(self.context, 'portal_discussion', None)
        cat = getToolByName(self.context, 'uid_catalog')
        resbrains = cat.searchResults(query)
        ksscore = self.getCommandSet('core')
        zopecore = self.getCommandSet('zope')
        jq = self.getCommandSet('jquery')
        if len(resbrains) == 1:
            contobj = resbrains[0].getObject()
            if contobj.isDiscussable() and self.canreply(contobj):
                mtool = getToolByName(self.context, 'portal_membership')
                username = mtool.getAuthenticatedMember().getId()
                dobj = pdt.getDiscussionFor(contobj)
                if len(self.request['commentbody'].strip(
                        ' ')) == 0 or self.request['commentbody'].lower(
                        ) == self.request['comcynapsenewcommenttitle'].lower():
                    comcynapsecommenterrorlabel = ksscore.getHtmlIdSelector(
                        'comcynapsecommenterror' + self.request['inreplyto'])
                    ksscore.setStyle(comcynapsecommenterrorlabel, 'display',
                                     'block')
                else:
                    id = dobj.createReply(title="",
                                          text=self.request['commentbody'],
                                          Creator=username)
                    reply = dobj.getReply(id)
                    reply.cooked_text = convertWebIntelligentPlainTextToHtml(
                        reply.text)
                    replyto = dobj.getReply(self.request['inreplyto'])
                    reply.setReplyTo(replyto)
                    if reply <> None:
                        from ubify.cyninv2theme import triggerAddOnDiscussionItem
                        triggerAddOnDiscussionItem(reply)

                        #################Determine full reply to discussion to get placement peer of current comment
                        view_type = self.request['cviewtype']
                        replies = []

                        def getRs(obj, replies, counter):
                            rs = pdt.getDiscussionFor(obj).getReplies()
                            if len(rs) > 0:
                                rs.sort(lambda x, y: cmp(
                                    x.modified(), y.modified()))
                                for r in rs:
                                    replies.append({
                                        'depth': counter,
                                        'object': r
                                    })
                                    getRs(r, replies, counter=counter + 1)

                        getRs(replyto, replies, 0)

                        if len(
                                replies
                        ) > 1:  ##There are more than 1 comments already children of the comment we just replied to, so the current comment can't have been the first reply
                            prevrep = replies[0]['object']
                        else:
                            prevrep = replyto

                        for rep in replies:
                            if rep['object'].id == reply.id:
                                belowreply = prevrep
                            else:
                                prevrep = rep['object']

                        mi = mtool.getMemberInfo()
                        commenttemplate = ViewPageTemplateFile(
                            'ksstemplates/commentrow.pt')
                        commenttemplate = commenttemplate.__of__(self.context)
                        depthvalue = 0
                        if view_type == 'threadedview':
                            depthvalue = int(self.request['depth']) + 1

                        replydict = [
                            {
                                'depth': depthvalue,
                                'object': reply,
                                'view_type': view_type
                            },
                        ]
                        output = commenttemplate.render(
                            indent=int(self.request['depth']) + 2,
                            fullname=mi['fullname'],
                            avatarurl=self.context.portal_membership.
                            getPersonalPortrait(username).absolute_url(),
                            creator=username,
                            showreply=self.canreply(self.context),
                            showdelete=getSecurityManager().checkPermission(
                                'Manage portal', aq_inner(self.context)),
                            commenttime=self.context.toLocalizedTime(
                                reply.created, True),
                            replyid=reply.id,
                            replytitle=reply.Title(),
                            replybody=reply.CookedBody(),
                            replyurl=reply.absolute_url(),
                            reply_dict=replydict)

                        if view_type == 'threadedview':
                            commentscontainer = ksscore.getHtmlIdSelector(
                                'commenttable' + prevrep.id)
                            ksscore.insertHTMLAfter(commentscontainer, output)
                        else:
                            commentsoutercontainer = ksscore.getHtmlIdSelector(
                                'comcynapsecyninitemcommentscontainer')
                            ksscore.insertHTMLAsLastChild(
                                commentsoutercontainer, output)

                        taAddNewComment = ksscore.getCssSelector(
                            'textarea.commentbodyta')
                        ksscore.setAttribute(taAddNewComment, "value", "")
                        itemcountcommentcount = ksscore.getHtmlIdSelector(
                            'itemcountcommentcount')
                        countofcomments = dobj.replyCount(self.context)
                        discussionlabel = ksscore.getHtmlIdSelector(
                            'discussionlabel')
                        ksscore.replaceInnerHTML(discussionlabel,
                                                 str(countofcomments))
                        ksscore.replaceInnerHTML(itemcountcommentcount,
                                                 str(countofcomments))
                        newcomment = ksscore.getHtmlIdSelector('commenttable' +
                                                               reply.id)
                        frmreply = ksscore.getHtmlIdSelector(
                            'replyform' + self.request['inreplyto'])
                        ksscore.setStyle(frmreply, 'display', 'none')
                        comcynapsecommenterrorlabel = ksscore.getHtmlIdSelector(
                            'comcynapsecommenterror' +
                            self.request['inreplyto'])
                        ksscore.setStyle(comcynapsecommenterrorlabel,
                                         'display', 'none')
                        self.fetchnewcomments(lasttimestamp, commentcount,
                                              lastcommentid, viewtype)
Пример #5
0
    def fetchnewcomments(self, lasttimestamp, commentcount, lastcommentid,
                         viewtype):
        passedcommentcount = 0
        passedcommentcount = int(commentcount)

        flasttimestamp = float(lasttimestamp)
        datefromlasttimestamp = DateTime(flasttimestamp)

        newlastdate = datefromlasttimestamp.timeTime()

        zopecommands = self.getCommandSet('zope')
        ksscore = self.getCommandSet('core')
        jq = self.getCommandSet('jquery')

        pdt = getToolByName(self.context, 'portal_discussion', None)

        if pdt <> None:
            allreplies = self.get_replies(pdt, self.context)

            disc_container = pdt.getDiscussionFor(self.context)
            replies = disc_container.getReplies()
            newreplycount = disc_container.replyCount(self.context)
            commentshiddencontainer = ksscore.getHtmlIdSelector(
                'comcynapsehiddencomments')
            commentscontainer = ksscore.getHtmlIdSelector(
                'comcynapsecyninitemcommentscontainer')
            addnewlasttimestamp = ksscore.getHtmlIdSelector(
                'comcynapselasttimestamp')
            addnewlastcommentid = ksscore.getHtmlIdSelector(
                'comcynapselastcommentid')
            addnewcommentcount = ksscore.getHtmlIdSelector(
                'comcynapsecommentcount')

            if passedcommentcount <> newreplycount:
                #if comment count mismatch then only modify the stuff
                alldiscussions = disc_container.objectValues()
                newlyaddedcomments = [
                    k for k in alldiscussions
                    if k.modified().greaterThan(datefromlasttimestamp)
                    and k.id not in (lastcommentid)
                ]
                newlyaddedcomments.sort(
                    lambda x, y: cmp(x.modified(), y.modified()))
                for eachcomment in newlyaddedcomments:
                    reply = disc_container.getReply(eachcomment.id)
                    if reply <> None:
                        parentsInThread = reply.parentsInThread()
                        depthvalue = 0
                        if viewtype.lower() == 'threadedview':
                            lenofparents = len(parentsInThread)
                            depthvalue = lenofparents - 1

                        prev_reply_id = self.findpreviouscommentid(
                            allreplies, reply)

                        newlastdate = reply.modified().timeTime()
                        commenttemplate = ViewPageTemplateFile(
                            'ksstemplates/commentrow.pt')
                        commenttemplate = commenttemplate.__of__(self.context)
                        replydict = [
                            {
                                'depth': depthvalue,
                                'object': reply,
                                'prev_id': prev_reply_id,
                                'view_type': viewtype
                            },
                        ]
                        output = commenttemplate.render(reply_dict=replydict)

                        #delete the node if already exists
                        old_comment = ksscore.getHtmlIdSelector(
                            'commenttable' + reply.id)
                        ksscore.deleteNode(old_comment)

                        #if there is no prev id found for new comment then insert it as last item to commentscontainer
                        #else insert it after prev id comments table.
                        if viewtype == 'flatview':
                            ksscore.insertHTMLAsLastChild(
                                commentscontainer, output)
                        else:
                            if prev_reply_id == '':
                                ksscore.insertHTMLAsLastChild(
                                    commentscontainer, output)
                            else:
                                prevcommentcontainer = ksscore.getHtmlIdSelector(
                                    'commenttable' + prev_reply_id)
                                ksscore.insertHTMLAfter(
                                    prevcommentcontainer, output)

                        newcomment = ksscore.getHtmlIdSelector('commenttable' +
                                                               reply.id)

                if len(newlyaddedcomments) > 0:
                    strlastcommentid = str(newlyaddedcomments[-1].id)
                    ksscore.setKssAttribute(commentshiddencontainer,
                                            'lastcommentid', strlastcommentid)
                    ksscore.setAttribute(addnewlastcommentid, 'value',
                                         strlastcommentid)
                    jq.serverCall(commentscontainer,
                                  'truncatetextonitemexpand')

            newlasttimestamp = str(newlastdate)
            strcommentcount = str(newreplycount)
            ksscore.setKssAttribute(commentshiddencontainer, 'lasttimestamp',
                                    newlasttimestamp)
            ksscore.setKssAttribute(commentshiddencontainer, 'commentcount',
                                    strcommentcount)
            ksscore.setAttribute(addnewlasttimestamp, 'value',
                                 newlasttimestamp)
            ksscore.setAttribute(addnewcommentcount, 'value', strcommentcount)

            itemcountcommentcount = ksscore.getHtmlIdSelector(
                'itemcountcommentcount')
            discussionlabel = ksscore.getHtmlIdSelector('discussionlabel')
            ksscore.replaceInnerHTML(discussionlabel, strcommentcount)
            ksscore.replaceInnerHTML(itemcountcommentcount, strcommentcount)
    def fetchcomments(self,uid,itemindex,lasttimestamp,commentcount,lastcommentid,viewtype):
        query = {'UID':uid}
        pdt = getToolByName(self.context, 'portal_discussion', None)
        cat = getToolByName(self.context, 'uid_catalog')
        resbrains = cat.searchResults(query)
        if len(resbrains) == 1:
            zopecommands = self.getCommandSet('zope')
            ksscore = self.getCommandSet('core')
            jq = self.getCommandSet('jquery')
            
            listcommentcontainer = ksscore.getHtmlIdSelector('comcynapselistcommentscontainer' + itemindex)
	    listcountspan = ksscore.getHtmlIdSelector('commentcountspan' + itemindex)
	    nocommentsyet = ksscore.getCssSelector('.nocommentsyet')
            listtimeoutuid = ksscore.getHtmlIdSelector('comcynapsecyninfetchUID')
            listtimeoutindex = ksscore.getHtmlIdSelector('comcynapsecyninfetchindex')
            listtimeouttimestamp = ksscore.getHtmlIdSelector('comcynapselasttimestamp')
            listtimeoutlastcommentid = ksscore.getHtmlIdSelector('comcynapselastcommentid')
            listtimeoutcommentcount = ksscore.getHtmlIdSelector('comcynapsecommentcount')
	    
            
            listcommentscount = ksscore.getHtmlIdSelector('listdiscussioncount' + itemindex)            
            
            contobj = resbrains[0].getObject()
            isDiscussable = contobj.isDiscussable()
            canReply = self.canreply(contobj)
            if isDiscussable and canReply:                
                passedcommentcount = 0
                passedcommentcount = int(commentcount)
                flasttimestamp = float(lasttimestamp)
                datefromlasttimestamp = DateTime(flasttimestamp)
                newlastdate = datefromlasttimestamp.timeTime()
                
                disc_container = pdt.getDiscussionFor(contobj)
                newreplycount = disc_container.replyCount(contobj)
                allreplies = self.get_replies(pdt,contobj)
                
                if passedcommentcount <> newreplycount:
                    alldiscussions = disc_container.objectValues()
                    newlastcommentid = lastcommentid
                    
                    newlyaddedcomments = [k for k in alldiscussions if k.modified().greaterThan(datefromlasttimestamp) and k.id not in (lastcommentid)]
                    newlyaddedcomments.sort(lambda x,y:cmp(x.modified(),y.modified()))
                    
                    lenofnewcomments = len(newlyaddedcomments)
                    display_count = self.get_displaycountforlist()
                    
                    lastxdiscussions = []
                    if lenofnewcomments >= display_count:
                        newlyaddedcomments.sort(lambda x,y:cmp(x.modified(),y.modified()),reverse=True)
                        lastxdiscussions = newlyaddedcomments[:display_count]
                        lastxdiscussions.sort(lambda x,y:cmp(x.modified(),y.modified()))
                        ksscore.clearChildNodes(listcommentcontainer)
                    else:
                        lastxdiscussions = newlyaddedcomments
                        if lenofnewcomments > 0 and len(alldiscussions) > display_count:
                            alldiscussions.sort(lambda x,y:cmp(x.modified(),y.modified()),reverse=True)
                            marker_discussion = alldiscussions[display_count-1: display_count]
                            if len(marker_discussion) > 0:
                                #delete nodes before this item
                                marker_node = ksscore.getHtmlIdSelector('commenttable' + marker_discussion[0].id)
                                ksscore.deleteNodeBefore(marker_node)
                    
                    complete_output = ''
                    list_reply_ids = []
                    for eachcomment in lastxdiscussions:                    
                        reply = disc_container.getReply(eachcomment.id)
                        if reply <> None:     
                            parentsInThread = reply.parentsInThread()
                            depthvalue = 0
                            if viewtype.lower() == 'threadedview':
                                lenofparents = len(parentsInThread)
                                depthvalue = lenofparents - 1
                            
                            prev_reply_id = self.findpreviouscommentid(allreplies,reply)
                            
                            newlastdate = reply.modified().timeTime()
                            newlastcommentid = reply.id
                            commenttemplate = ViewPageTemplateFile('ksstemplates/commentrow.pt')
                            commenttemplate = commenttemplate.__of__(self.context)
                            
                            replydict = [{'depth': depthvalue, 'object': reply,'prev_id':prev_reply_id,'view_type':viewtype, 'showoutput':False},]
                            output = commenttemplate.render(reply_dict=replydict,allowdiscussion = isDiscussable,usercanreply = canReply)
                            list_reply_ids.append(reply.id)
                            complete_output += output
                            
                    if complete_output <> '' and len(lastxdiscussions) > 0:
                        ksscore.insertHTMLAsLastChild(listcommentcontainer,complete_output)
                        for erid in list_reply_ids:
                            newcomment = ksscore.getHtmlIdSelector('commenttable' + erid)
                            jq.serverEffect(newcomment,"fadeIn", "slow")			    
                        
                    ksscore.setAttribute(listtimeoutuid,'value',uid)
                    ksscore.setAttribute(listtimeoutindex,'value',itemindex)
                    ksscore.setAttribute(listtimeouttimestamp,'value',str(newlastdate))
                    ksscore.setAttribute(listtimeoutlastcommentid,'value',newlastcommentid)
                    ksscore.setAttribute(listtimeoutcommentcount,'value',str(newreplycount))
		    ksscore.setAttribute(listtimeoutuid,'value',uid)
		    
		    if newreplycount > display_count:
			xmorecomments = newreplycount - display_count
			ksscore.replaceInnerHTML(listcommentscount,str(xmorecomments))
			jq.serverEffect(nocommentsyet,"fadeOut", "fast")
			jq.serverEffect(listcountspan,"fadeIn", "slow")
		    elif newreplycount > 0 and newreplycount <= display_count:
			jq.serverEffect(nocommentsyet,"fadeOut", "fast")
		    
		    jq.serverCall(listcommentcontainer,'truncatetextonitemexpand')
    def getDiscussionView(self,uid,itemindex,state,openeditemindex):
        ksscore = self.getCommandSet('core')
        zopecore = self.getCommandSet('zope')
        jq = self.getCommandSet('jquery')
        
        clickednode = ksscore.getHtmlIdSelector('listitemdiscusslinktop' + itemindex)
        listcommentcontainer = ksscore.getHtmlIdSelector('listitemdiscussrow' + itemindex)
        listtimeoutuid = ksscore.getHtmlIdSelector('comcynapsecyninfetchUID')
        listtimeoutindex = ksscore.getHtmlIdSelector('comcynapsecyninfetchindex')
        listtimeouttimestamp = ksscore.getHtmlIdSelector('comcynapselasttimestamp')
        listtimeoutlastcommentid = ksscore.getHtmlIdSelector('comcynapselastcommentid')
        listtimeoutcommentcount = ksscore.getHtmlIdSelector('comcynapsecommentcount')
        listitemdetailright = ksscore.getHtmlIdSelector('listitemdetail' + itemindex)
        
        if openeditemindex != itemindex:            
            openednode = ksscore.getHtmlIdSelector('listitemdiscusslinktop' + openeditemindex)
            listopenedcommentcontainer = ksscore.getHtmlIdSelector('listitemdiscussrow' + openeditemindex)
            ksscore.setKssAttribute(openednode,'state','closed')
            ksscore.replaceInnerHTML(listopenedcommentcontainer,'')
            
        if state.lower() != 'closed':
            ksscore.setKssAttribute(clickednode,'state','closed')
            ksscore.replaceInnerHTML(listcommentcontainer,'')
            return
        
        query = {'UID':uid}
        pdt = getToolByName(self.context,'portal_discussion')
        cat = getToolByName(self.context, 'uid_catalog')
        resbrains = cat.searchResults(query)
        if len(resbrains) == 1:
            contobj = resbrains[0].getObject()
            isDiscussable = contobj.isDiscussable()
            canReply = self.canreply(contobj)
            if isDiscussable and canReply:
                dobj = pdt.getDiscussionFor(contobj)                
                alldiscussions = dobj.objectValues()
                alldiscussions.sort(lambda x,y:cmp(x.modified(),y.modified()),reverse=True)
		maxdispcomments = self.get_displaycountforlist()
                lastxdiscussions = alldiscussions[:maxdispcomments]
                
                commentscount = dobj.replyCount(contobj)
		if commentscount > maxdispcomments:
		    showxmorelink = True
		    xmorecomments = commentscount - maxdispcomments
		elif commentscount > 0 and commentscount <= maxdispcomments:
		    showxmorelink = False
		    xmorecomments = 0
		else:
		    showxmorelink = True
		    commentscount = 0
		    xmorecomments = 0
                lasttimestamp = DateTime().timeTime()
                lastcommentid = '0'
                if len(alldiscussions) > 0:
                    lasttimestamp = alldiscussions[0].modified().timeTime()
                    lastcommentid = alldiscussions[0].id
                    
                commenttemplate = ViewPageTemplateFile('ksstemplates/listcomment.pt')
                commenttemplate = commenttemplate.__of__(self.context)
                
                
                replydict = []
                lastxdiscussions.sort(lambda x,y:cmp(x.modified(),y.modified()))
                for eachdisc in lastxdiscussions:
                    reply = dobj.getReply(eachdisc.id)
                    if reply <> None:
                        replydict.append({'depth': 0,'object':reply,'view_type':'listview','showoutput':True})
                
                output = commenttemplate.render(contobj=contobj, showxmorelink = showxmorelink, xmorecomments = xmorecomments, itemindex=itemindex,uid=uid,reply_dict=replydict,title=contobj.Title(),commentcount=commentscount,lasttimestamp = lasttimestamp,lastcommentid = lastcommentid,allowdiscussion = isDiscussable,usercanreply = canReply)
                
                detailtemplate = ViewPageTemplateFile('ksstemplates/listitemdetails.pt')
                detailtemplate = detailtemplate.__of__(self.context)
                
                
                item = resbrains[0]
                fullpath = item.getPath()
                splitpath = fullpath.split('/')[:-1]
                prettypath = '/' + '/'.join(splitpath)
                URLsuffix = getListingTemplateForContextParent(item)
                pathlink = self.context.portal_url() + prettypath + '/' + URLsuffix
                pathtitle = prettypath
                
                detail = detailtemplate.render(item_type=contobj.portal_type,portal_url=self.context.portal_url(),item_type_title=contobj.Type(),item=item,pathlink=pathlink,pathtitle=pathtitle,contobj=contobj)
                ksscore.replaceInnerHTML(listitemdetailright,force_unicode(detail,'utf'))
                ksscore.replaceInnerHTML(listcommentcontainer,output)
                
                ksscore.setKssAttribute(clickednode,'state','opened')
                
                ksscore.setAttribute(listtimeoutuid,'value',uid)
                ksscore.setAttribute(listtimeoutindex,'value',itemindex)
                ksscore.setAttribute(listtimeouttimestamp,'value',str(lasttimestamp))
                ksscore.setAttribute(listtimeoutlastcommentid,'value',lastcommentid)
                ksscore.setAttribute(listtimeoutcommentcount,'value',str(commentscount))
		jq.serverCall(clickednode,'truncatetextonitemexpand')
		jq.serverCall(clickednode,'marklistedtags')
		jq.serverCall(listcommentcontainer,'activateinputlabel')
 def toggleCommentsView(self,viewtype):
     zopecommands = self.getCommandSet('zope')
     ksscore = self.getCommandSet('core')
     jq = self.getCommandSet('jquery')
     commentshiddencontainer = ksscore.getHtmlIdSelector('comcynapsehiddencomments')
     commentscontainer = ksscore.getHtmlIdSelector('comcynapsecyninitemcommentscontainer')
     addnewlasttimestamp = ksscore.getHtmlIdSelector('comcynapselasttimestamp')
     addnewlastcommentid = ksscore.getHtmlIdSelector('comcynapselastcommentid')
     addnewcommentcount = ksscore.getHtmlIdSelector('comcynapsecommentcount')
         
     objcommentslist = []
     pdt = getToolByName(self.context, 'portal_discussion', None)
     if pdt <> None:
         disc_container = pdt.getDiscussionFor(self.context)
         alldiscussions = disc_container.objectValues()
         allreplies = self.get_replies(pdt,self.context)
         newreplycount = disc_container.replyCount(self.context)
         newlastdate = DateTime().timeTime()
         
         if viewtype == 'flatview':
             alldiscussions.sort(lambda x,y:cmp(x.modified(),y.modified()))
             objcommentslist.extend(alldiscussions)
         else:
             objcommentslist.extend(allreplies)
         
         ksscore.replaceInnerHTML(commentscontainer,'')
         complete_output = ''
         for eachcomment in objcommentslist:
             if hasattr(eachcomment,'id'):
                 id = eachcomment.id
             elif eachcomment.has_key('id'):
                 id = eachcomment['id']
                 
             reply = disc_container.getReply(id)
             if reply <> None:                        
                 parentsInThread = reply.parentsInThread()
                 depthvalue = 0
                 if viewtype.lower() == 'threadedview':
                     lenofparents = len(parentsInThread)
                     depthvalue = lenofparents - 1
                 
                 prev_reply_id = self.findpreviouscommentid(allreplies,reply)
                 
                 newlastdate = reply.modified().timeTime()
                 commenttemplate = ViewPageTemplateFile('ksstemplates/commentrow.pt')
                 commenttemplate = commenttemplate.__of__(self.context)
                 replydict = [{'depth': depthvalue, 'object': reply,'prev_id':prev_reply_id,'view_type':viewtype,'showoutput':True},]
                 output = commenttemplate.render(reply_dict=replydict)
                 
                 #if there is no prev id found for new comment then insert it as last item to commentscontainer
                 #else insert it after prev id comments table.
                 if viewtype == 'flatview':                        
                     complete_output += output
                 else:
                     complete_output += output                        
         
         if complete_output <> '' and len(objcommentslist) > 0:
             ksscore.replaceInnerHTML(commentscontainer,complete_output)
             jq.serverCall(commentscontainer,'truncatetextonitemexpand')
         if len(alldiscussions) > 0:
             strlastcommentid = str(alldiscussions[-1].id)
             ksscore.setKssAttribute(commentshiddencontainer,'lastcommentid',strlastcommentid)
             ksscore.setAttribute(addnewlastcommentid,'value',strlastcommentid)
     
     
         newlasttimestamp = str(newlastdate)
         strcommentcount = str(newreplycount)
         ksscore.setKssAttribute(commentshiddencontainer,'lasttimestamp',newlasttimestamp)            
         ksscore.setKssAttribute(commentshiddencontainer,'commentcount',strcommentcount)            
         
         ksscore.setAttribute(addnewlasttimestamp,'value',newlasttimestamp)
         ksscore.setAttribute(addnewcommentcount,'value',strcommentcount)
         
         itemcountcommentcount = ksscore.getHtmlIdSelector('itemcountcommentcount')            
         discussionlabel = ksscore.getHtmlIdSelector('discussionlabel')
         ksscore.replaceInnerHTML(discussionlabel,strcommentcount)
         ksscore.replaceInnerHTML(itemcountcommentcount,strcommentcount)            
         
     ksscore.setKssAttribute(commentshiddencontainer,'viewtype',viewtype)
     addnewcommentviewtype = ksscore.getHtmlIdSelector('comcynapseviewtype')
     ksscore.setAttribute(addnewcommentviewtype,'value',viewtype)
     ksscore.setStyle(commentscontainer,'display','block')
    def fetchnewcomments(self,lasttimestamp,commentcount,lastcommentid,viewtype):        
        passedcommentcount = 0
        passedcommentcount = int(commentcount)
        
        flasttimestamp = float(lasttimestamp)
        datefromlasttimestamp = DateTime(flasttimestamp)
        
        newlastdate = datefromlasttimestamp.timeTime()
        
        zopecommands = self.getCommandSet('zope')
        ksscore = self.getCommandSet('core')
        jq = self.getCommandSet('jquery')
        
        pdt = getToolByName(self.context, 'portal_discussion', None)        
        
        if pdt <> None:
            allreplies = self.get_replies(pdt,self.context)
            
            disc_container = pdt.getDiscussionFor(self.context)
            replies = disc_container.getReplies()
            newreplycount = disc_container.replyCount(self.context)
            commentshiddencontainer = ksscore.getHtmlIdSelector('comcynapsehiddencomments')
            commentscontainer = ksscore.getHtmlIdSelector('comcynapsecyninitemcommentscontainer')
            addnewlasttimestamp = ksscore.getHtmlIdSelector('comcynapselasttimestamp')
            addnewlastcommentid = ksscore.getHtmlIdSelector('comcynapselastcommentid')
            addnewcommentcount = ksscore.getHtmlIdSelector('comcynapsecommentcount')
            
            if passedcommentcount <> newreplycount:
                #if comment count mismatch then only modify the stuff
                alldiscussions = disc_container.objectValues()                
                newlyaddedcomments = [k for k in alldiscussions if k.modified().greaterThan(datefromlasttimestamp) and k.id not in (lastcommentid)]
                newlyaddedcomments.sort(lambda x,y:cmp(x.modified(),y.modified()))
                for eachcomment in newlyaddedcomments:                    
                    reply = disc_container.getReply(eachcomment.id)
                    if reply <> None:                        
                        parentsInThread = reply.parentsInThread()
                        depthvalue = 0
                        if viewtype.lower() == 'threadedview':
                            lenofparents = len(parentsInThread)
                            depthvalue = lenofparents - 1
                        
                        prev_reply_id = self.findpreviouscommentid(allreplies,reply)
                        
                        newlastdate = reply.modified().timeTime()
                        commenttemplate = ViewPageTemplateFile('ksstemplates/commentrow.pt')
                        commenttemplate = commenttemplate.__of__(self.context)
                        replydict = [{'depth': depthvalue, 'object': reply,'prev_id':prev_reply_id,'view_type':viewtype},]
                        output = commenttemplate.render(reply_dict=replydict)
                        
                        #delete the node if already exists
                        old_comment = ksscore.getHtmlIdSelector('commenttable' + reply.id)
                        ksscore.deleteNode(old_comment)
                        
                        
                        #if there is no prev id found for new comment then insert it as last item to commentscontainer
                        #else insert it after prev id comments table.
                        if viewtype == 'flatview':
                            ksscore.insertHTMLAsLastChild(commentscontainer,output)
                        else:
                            if prev_reply_id == '':
                                ksscore.insertHTMLAsLastChild(commentscontainer,output)
                            else:
                                prevcommentcontainer = ksscore.getHtmlIdSelector('commenttable' + prev_reply_id)
                                ksscore.insertHTMLAfter(prevcommentcontainer,output)
                        
                        newcomment = ksscore.getHtmlIdSelector('commenttable' + reply.id)
                
                if len(newlyaddedcomments) > 0:
                    strlastcommentid = str(newlyaddedcomments[-1].id)
                    ksscore.setKssAttribute(commentshiddencontainer,'lastcommentid',strlastcommentid)
                    ksscore.setAttribute(addnewlastcommentid,'value',strlastcommentid)
		    jq.serverCall(commentscontainer,'truncatetextonitemexpand')
		    
            newlasttimestamp = str(newlastdate)
            strcommentcount = str(newreplycount)
            ksscore.setKssAttribute(commentshiddencontainer,'lasttimestamp',newlasttimestamp)
            ksscore.setKssAttribute(commentshiddencontainer,'commentcount',strcommentcount)
            ksscore.setAttribute(addnewlasttimestamp,'value',newlasttimestamp)
            ksscore.setAttribute(addnewcommentcount,'value',strcommentcount)
            
            
            itemcountcommentcount = ksscore.getHtmlIdSelector('itemcountcommentcount')            
            discussionlabel = ksscore.getHtmlIdSelector('discussionlabel')
            ksscore.replaceInnerHTML(discussionlabel,strcommentcount)
            ksscore.replaceInnerHTML(itemcountcommentcount,strcommentcount)
    def replyToComment(self,viewtype,lasttimestamp,commentcount,lastcommentid):
        query = {'UID':self.request['cont_uid']}
        pdt = getToolByName(self.context, 'portal_discussion', None)
        cat = getToolByName(self.context, 'uid_catalog')
        resbrains = cat.searchResults(query)
	ksscore = self.getCommandSet('core')
        zopecore = self.getCommandSet('zope')
        jq = self.getCommandSet('jquery')
        if len(resbrains) == 1:
            contobj = resbrains[0].getObject()
            if contobj.isDiscussable() and self.canreply(contobj):
                mtool = getToolByName(self.context, 'portal_membership')
                username = mtool.getAuthenticatedMember().getId()
                dobj = pdt.getDiscussionFor(contobj)
                if len(self.request['commentbody'].strip(' ')) == 0 or self.request['commentbody'].lower() == self.request['comcynapsenewcommenttitle'].lower():
                    comcynapsecommenterrorlabel = ksscore.getHtmlIdSelector('comcynapsecommenterror'+ self.request['inreplyto'])
		    ksscore.setStyle(comcynapsecommenterrorlabel,'display','block')		    
                else:
                    id = dobj.createReply(title="", text=self.request['commentbody'], Creator=username)
                    reply = dobj.getReply(id)
                    reply.cooked_text = convertWebIntelligentPlainTextToHtml(reply.text)
                    replyto = dobj.getReply(self.request['inreplyto'])
                    reply.setReplyTo(replyto)
                    if reply <> None:
                        from ubify.cyninv2theme import triggerAddOnDiscussionItem
                        triggerAddOnDiscussionItem(reply)

                        #################Determine full reply to discussion to get placement peer of current comment
                        view_type = self.request['cviewtype']
                        replies = []
                        def getRs(obj, replies, counter):
                            rs = pdt.getDiscussionFor(obj).getReplies()
                            if len(rs) > 0:
                                rs.sort(lambda x, y: cmp(x.modified(), y.modified()))
                                for r in rs:
                                    replies.append({'depth':counter, 'object':r})
                                    getRs(r, replies, counter=counter + 1)

                        getRs(replyto, replies, 0)

                        if len(replies) > 1: ##There are more than 1 comments already children of the comment we just replied to, so the current comment can't have been the first reply
                            prevrep = replies[0]['object']
                        else:
                            prevrep = replyto

                        for rep in replies:
                            if rep['object'].id == reply.id:
                                belowreply = prevrep
                            else:
                                prevrep = rep['object']

                        mi = mtool.getMemberInfo();
                        commenttemplate = ViewPageTemplateFile('ksstemplates/commentrow.pt')
                        commenttemplate = commenttemplate.__of__(self.context)
                        depthvalue = 0
                        if view_type == 'threadedview':
                            depthvalue = int(self.request['depth']) + 1
                            
                        replydict = [{'depth': depthvalue, 'object': reply,'view_type':view_type},]
                        output = commenttemplate.render(indent=int(self.request['depth'])+2,fullname = mi['fullname'], avatarurl=self.context.portal_membership.getPersonalPortrait(username).absolute_url(),creator=username,showreply=self.canreply(self.context),showdelete=getSecurityManager().checkPermission('Manage portal',aq_inner(self.context)),commenttime=self.context.toLocalizedTime(reply.created,True),replyid=reply.id,replytitle=reply.Title(),replybody=reply.CookedBody(),replyurl=reply.absolute_url(),reply_dict=replydict)
                        
                        if view_type == 'threadedview':
                            commentscontainer = ksscore.getHtmlIdSelector('commenttable' + prevrep.id)
                            ksscore.insertHTMLAfter(commentscontainer,output)
                        else:
                            commentsoutercontainer = ksscore.getHtmlIdSelector('comcynapsecyninitemcommentscontainer')
                            ksscore.insertHTMLAsLastChild(commentsoutercontainer,output)
                        
                        taAddNewComment = ksscore.getCssSelector('textarea.commentbodyta')
                        ksscore.setAttribute(taAddNewComment,"value","")
                        itemcountcommentcount = ksscore.getHtmlIdSelector('itemcountcommentcount')
                        countofcomments = dobj.replyCount(self.context)
                        discussionlabel = ksscore.getHtmlIdSelector('discussionlabel')
                        ksscore.replaceInnerHTML(discussionlabel,str(countofcomments))
                        ksscore.replaceInnerHTML(itemcountcommentcount,str(countofcomments))
                        newcomment = ksscore.getHtmlIdSelector('commenttable' + reply.id)
                        frmreply = ksscore.getHtmlIdSelector('replyform' + self.request['inreplyto'])			
			ksscore.setStyle(frmreply,'display','none')
			comcynapsecommenterrorlabel = ksscore.getHtmlIdSelector('comcynapsecommenterror'+ self.request['inreplyto'])
			ksscore.setStyle(comcynapsecommenterrorlabel,'display','none')
                        self.fetchnewcomments(lasttimestamp,commentcount,lastcommentid,viewtype)