<commit_before>kd                     = require 'kd'
JView                  = require 'app/jview'
KDButtonView           = kd.ButtonView
KDListItemView         = kd.ListItemView
KDCustomHTMLView       = kd.CustomHTMLView
KDCheckBox             = kd.CheckBox
KDListViewController   = kd.ListViewController
KDHitEnterInputView    = kd.HitEnterInputView

TopicLeafItemView      = require './topicleafitemview'
SelectableItemView     = require './selectableitemview'


module.exports = class TopicItemView extends KDListItemView

  JView.mixin @prototype

  constructor: (options = {}, data) ->

    options.type                or= 'topic'
    options.noItemFoundWidget   or= new KDCustomHTMLView
    options.listViewItemClass   or= TopicLeafItemView
    options.listViewItemOptions or= {}
    options.itemLimit            ?= 10
    
    @leafSkip    = 0
    @similarSkip = 0
    
    super options, data
    
    @createLabels data
    @createSettingsView data
 
 
  createLabels: (data)->
    
    @moderationLabel = new KDCustomHTMLView
      cssClass : 'moderate-role'
      partial  : "Moderate <span class='settings-icon'></span>"
      click    : =>
        @settings.toggleClass  'hidden'
        @moderationLabel.toggleClass 'active'
    
    @typeLabel = new KDCustomHTMLView
      cssClass : 'type-label hidden'


  createSettingsView : (data) ->

    @settings  = new KDCustomHTMLView
      cssClass : 'settings hidden'
    
    if data.typeConstant is "topic" then @createAllTopicView data else @createDeletedTopicView data
    
    @createLeafChannelSetting data
            
    @createSimilarChannelSetting data


  createAllTopicView : (data) ->
      @settings.addSubView deleteButton = new KDCustomHTMLView
        tagName  : 'a'
        cssClass : 'delete-topic'
        click    :=>
          options = 
            rootId  : kd.singletons.groupsController.getCurrentGroup().socialApiChannelId
            leafId  : data.id
          
          kd.singletons.socialapi.moderation.blacklist options, (err, data) =>
            if err
              return kd.warn err
              
  createDeletedTopicView: (data) ->
      options = 
        rootId  : kd.singletons.groupsController.getCurrentGroup().socialApiChannelId
        leafId  : data.id
      
      kd.singletons.socialapi.moderation.fetchRoot options, (err, rootChannel) =>
       
        if err 
          return kd.warn err
        
        if rootChannel
          text = "Blacklisted"
          if kd.singletons.groupsController.getCurrentGroup().socialApiChannelId isnt rootChannel.id 
            text = "##{rootChannel.name}"
          
        @typeLabel.setPartial "#{text}"
        @typeLabel.show()
        
        @settings.addSubView whitelistButton = new KDButtonView
          cssClass : 'solid compact outline whitelist-topic'
          title    : 'WHITELIST CHANNEL'
          callback : -> 
            options = 
              rootId  : kd.singletons.groupsController.getCurrentGroup().socialApiChannelId
              leafId  : data.id

            kd.singletons.socialapi.moderation.unlink options, (err, data) ->
              return kd.warn err if err<commit_msg>moderation: channel is removed when clicked cross button<commit_after>kd                     = require 'kd'
JView                  = require 'app/jview'
KDButtonView           = kd.ButtonView
KDListItemView         = kd.ListItemView
KDCustomHTMLView       = kd.CustomHTMLView
KDCheckBox             = kd.CheckBox
KDListViewController   = kd.ListViewController
KDHitEnterInputView    = kd.HitEnterInputView

TopicLeafItemView      = require './topicleafitemview'
SelectableItemView     = require './selectableitemview'


module.exports = class TopicItemView extends KDListItemView

  JView.mixin @prototype

  constructor: (options = {}, data) ->

    options.type                or= 'topic'
    options.noItemFoundWidget   or= new KDCustomHTMLView
    options.listViewItemClass   or= TopicLeafItemView
    options.listViewItemOptions or= {}
    options.itemLimit            ?= 10
    
    @leafSkip    = 0
    @similarSkip = 0
    
    super options, data
    
    @createLabels data
    @createSettingsView data
 
 
  createLabels: (data)->
    
    @moderationLabel = new KDCustomHTMLView
      cssClass : 'moderate-role'
      partial  : "Moderate <span class='settings-icon'></span>"
      click    : =>
        @settings.toggleClass  'hidden'
        @moderationLabel.toggleClass 'active'
    
    @typeLabel = new KDCustomHTMLView
      cssClass : 'type-label hidden'


  createSettingsView : (data) ->

    @settings  = new KDCustomHTMLView
      cssClass : 'settings hidden'
    
    if data.typeConstant is "topic" then @createAllTopicView data else @createDeletedTopicView data
    
    @createLeafChannelSetting data
            
    @createSimilarChannelSetting data


  createAllTopicView : (data) ->
      @settings.addSubView deleteButton = new KDCustomHTMLView
        tagName  : 'a'
        cssClass : 'delete-topic'
        click    :=>
          @setClass 'hidden'
          options = 
            rootId  : kd.singletons.groupsController.getCurrentGroup().socialApiChannelId
            leafId  : data.id
          
          kd.singletons.socialapi.moderation.blacklist options, (err, data) =>
            return kd.warn err if err
          
          # TO-DO
          # Send removed data into DELETED Topics
          
            
              
  createDeletedTopicView: (data) ->
      options = 
        rootId  : kd.singletons.groupsController.getCurrentGroup().socialApiChannelId
        leafId  : data.id
      
      kd.singletons.socialapi.moderation.fetchRoot options, (err, rootChannel) =>
       
        if err 
          return kd.warn err
        
        if rootChannel
          text = "Blacklisted"
          if kd.singletons.groupsController.getCurrentGroup().socialApiChannelId isnt rootChannel.id 
            text = "##{rootChannel.name}"
          
        @typeLabel.setPartial "#{text}"
        @typeLabel.show()
        
        @settings.addSubView whitelistButton = new KDButtonView
          cssClass : 'solid compact outline whitelist-topic'
          title    : 'WHITELIST CHANNEL'
          callback : -> 
            options = 
              rootId  : kd.singletons.groupsController.getCurrentGroup().socialApiChannelId
              leafId  : data.id

            kd.singletons.socialapi.moderation.unlink options, (err, data) ->
              return kd.warn err if err
{'fraction_non_alphanumeric': 0.07870013861081164, 'fraction_numerical': 0.0012320961034960726, 'mean_word_length': 2.0791844476055004, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '4328684', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1795, 'n_words': 383}