<commit_before>class OpinionListItemView extends KDListItemView

  constructor:(options,data)->
    options = $.extend
      type      : "opinion"
      cssClass  : "kdlistitemview kdlistitemview-comment"
    ,options

    super options,data

    data = @getData()

    originId    = data.getAt('originId')
    originType  = data.getAt('originType')
    deleterId   = data.getAt('deletedBy')?.getId?()

    origin = {
      constructorName  : originType
      id               : originId
    }

    @avatar = new AvatarView {
      size    : {width: 30, height: 30}
      origin
    }

    @author = new ProfileLinkView {
      origin
    }

    if deleterId? and deleterId isnt originId
      @deleter = new ProfileLinkView {}, data.getAt('deletedBy')

    @deleteLink = new KDCustomHTMLView
      tagName     : 'a'
      attributes  :
        title     : "Delete your opinion"
        href      : '#'
      cssClass    : 'delete-link hidden'

    @editLink = new KDCustomHTMLView
      tagName     : 'a'
      attributes  :
        title     : "Edit your opinion"
        href      : '#'
      cssClass    : 'edit-link hidden'

    @commentBox = new CommentView null, data

    @actionLinks = new ActivityActionsView
      delegate : @commentBox.commentList
      cssClass : "comment-header"
    , data

    @tags = new ActivityChildViewTagGroup
      itemsToShow   : 3
      subItemClass  : TagLinkView
    , data.meta.tags

    activity = @getDelegate().getData()
    bongo.cacheable data.originId, "JAccount", (err, account)=>
      loggedInId = KD.whoami().getId()
      if loggedInId is data.originId or       # if comment owner
         loggedInId is activity.originId or   # if activity owner
         KD.checkFlag "super-admin", account  # if super-admin

        # push that into the click even , destroy if exists, create if not

        @editForm = new OpinionFormView
          title : "edit-opinion"
          cssClass : "edit-opinion-form hidden opinion-container"
          callback : (data)=>
            @getData().modify data, (err, opinion) =>
              callback? err, opinion
              if err
                new KDNotificationView title : "Your changes weren't saved.", type :"mini"
              else
                # new KDNotificationView title : "modified!"
                @emit "OwnOpinionWasAdded", opinion
                @editForm.setClass "hidden"
        , data

        log "adding editform"
        @addSubView @editForm, "p.opinion-body-edit", yes
        log @editForm

        @editLink.unsetClass "hidden"

        @listenTo
          KDEventTypes       : "click"
          listenedToInstance : @editLink
          callback           : =>
            log "clicked me", @editForm
            if @editForm.$().hasClass "hidden"
              log "has hidden"
              @editForm.unsetClass "hidden"
            else
              @editForm.setClass "hidden"

        @deleteLink.unsetClass "hidden"
        @listenTo
          KDEventTypes       : "click"
          listenedToInstance : @deleteLink
          callback           : => @confirmDeleteOpinion data

      # workaround: how would this be solved better?

  viewAppended:->
    @setTemplate @pistachio()
    @template.update()

  click:(event)->
    if $(event.target).is "span.avatar a, a.user-fullname"
      {originType, originId} = @getData()
      bongo.cacheable originType, originId, (err, origin)->
        unless err
          appManager.tell "Members", "createContentDisplay", origin<commit_msg>making the edit click work<commit_after>class OpinionListItemView extends KDListItemView

  constructor:(options,data)->
    options = $.extend
      type      : "opinion"
      cssClass  : "kdlistitemview kdlistitemview-comment"
    ,options

    super options,data

    data = @getData()

    originId    = data.getAt('originId')
    originType  = data.getAt('originType')
    deleterId   = data.getAt('deletedBy')?.getId?()

    origin = {
      constructorName  : originType
      id               : originId
    }

    @avatar = new AvatarView {
      size    : {width: 30, height: 30}
      origin
    }

    @author = new ProfileLinkView {
      origin
    }

    if deleterId? and deleterId isnt originId
      @deleter = new ProfileLinkView {}, data.getAt('deletedBy')

    @deleteLink = new KDCustomHTMLView
      tagName     : 'a'
      attributes  :
        title     : "Delete your opinion"
        href      : '#'
      cssClass    : 'delete-link hidden'

    @editLink = new KDCustomHTMLView
      tagName     : 'a'
      attributes  :
        title     : "Edit your opinion"
        href      : '#'
      cssClass    : 'edit-link hidden'

    @commentBox = new CommentView null, data

    @actionLinks = new ActivityActionsView
      delegate : @commentBox.commentList
      cssClass : "comment-header"
    , data

    @tags = new ActivityChildViewTagGroup
      itemsToShow   : 3
      subItemClass  : TagLinkView
    , data.meta.tags

    activity = @getDelegate().getData()
    bongo.cacheable data.originId, "JAccount", (err, account)=>
      loggedInId = KD.whoami().getId()
      if loggedInId is data.originId or       # if comment owner
         loggedInId is activity.originId or   # if activity owner
         KD.checkFlag "super-admin", account  # if super-admin

        # push that into the click even , destroy if exists, create if not



        @editLink.unsetClass "hidden"

        @listenTo
          KDEventTypes       : "click"
          listenedToInstance : @editLink
          callback           : =>
            if @editForm?
              @editForm?.destroy()
              delete @editForm
            else
              # only works once, why!?
              @editForm = new OpinionFormView
                title : "edit-opinion"
                cssClass : "edit-opinion-form opinion-container"
                callback : (data)=>
                  @getData().modify data, (err, opinion) =>
                    callback? err, opinion
                    if err
                      new KDNotificationView title : "Your changes weren't saved.", type :"mini"
                    else
                      # new KDNotificationView title : "modified!"
                      @emit "OwnOpinionWasAdded", opinion
                      @editForm.setClass "hidden"
              , data

              @addSubView @editForm, "p.opinion-body-edit", yes

        @deleteLink.unsetClass "hidden"
        @listenTo
          KDEventTypes       : "click"
          listenedToInstance : @deleteLink
          callback           : => @confirmDeleteOpinion data

      # workaround: how would this be solved better?

  viewAppended:->
    @setTemplate @pistachio()
    @template.update()

  click:(event)->
    if $(event.target).is "span.avatar a, a.user-fullname"
      {originType, originId} = @getData()
      bongo.cacheable originType, originId, (err, origin)->
        unless err
          appManager.tell "Members", "createContentDisplay", origin
{'fraction_non_alphanumeric': 0.09419668381932533, 'fraction_numerical': 0.001429388221841052, 'mean_word_length': 1.8877424680148576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3518137', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1918, 'n_words': 500}