<commit_before>$ = jQuery.sub()

class Index extends App.Controller
  events:
    'click .submit':                          'update',
    'click [data-type=reply]':                'reply',
    'click [data-type=reply-all]':            'replyall',
    'click [data-type=public]':               'public_internal',
    'click [data-type=internal]':             'public_internal',
    'click [data-type=history]':              'history_view',
    'change [name="ticket_article_type_id"]': 'form_update',
    'click .show_toogle':                     'show_toogle',

  constructor: (params) ->
    super
    @log 'zoom', params

    # check authentication
    return if !@authenticate()

    @navupdate '#'

    @edit_form = undefined
#    @render()
    @ticket_id = params.ticket_id
    @fetch(@ticket_id)

  fetch: (ticket_id) ->
    # get data
    @ajax = new App.Ajax
    @ajax.ajax(
      type:  'GET',
      url:   '/ticket_full/' + ticket_id,
      data:  {
        view: @view
      }
      processData: true,
      success: (data, status, xhr) =>
        # reset old indexes
        @ticket = undefined
        @articles = undefined
        
        # get edit form attributes
        @edit_form = data.edit_form

        # load user collection
        @loadCollection( type: 'User', data: data.users )

        # load ticket collection
        @loadCollection( type: 'Ticket', data: [data.ticket] )

        # load article collections
        @loadCollection( type: 'TicketArticle', data: data.articles || [] )

        # render page
        @render()
    )

  render: =>

    if !App.Ticket.exists(@ticket_id)
      return

    # get data
    if !@ticket
      @ticket = App.Ticket.find(@ticket_id)
    if !@articles
      @articles = []
      for article_id in @ticket.article_ids
        article = App.TicketArticle.find(article_id)
        
        # build html body
        # cleanup body
        article['html'] = article.body.trim()
        article['html'].replace(/\n\r/g, "\n");
        article['html'].replace(/\n\n\n/g, "\n\n");
        
        # if body has more then x lines / else search for signature
        preview       = 15
        preview_mode  = false
        article_lines = article['html'].split(/\n/)
        if article_lines.length > preview
          preview_mode = true
          if article_lines[preview] is ''
            article_lines.splice( preview-1, 0, "----SEEMORE----" )
          else
            article_lines.splice( preview, 0, "----SEEMORE----" )
          article['html'] = article_lines.join("\n")
        article['html'] = window.linkify( article['html'] )
        notify = "<a href=\"#\" class=\"show_toogle\">" + T('See more') + "</a>"

        # preview mode
        if preview_mode
          article['html'] = article['html'].replace /^----SEEMORE----\n/m, (match) =>
            notify + '<div class="hide">'
          article['html'] = article['html'] + '</div>'
          
        # hide signatures and so on
        else
          @article_changed = false
          article['html'] = article['html'].replace /^(--|__)/m, (match) =>
            @article_changed = true
            notify + '<div class="hide">' + match
          if @article_changed
            article['html'] = article['html'] + '</div>'

        @articles.push article

    # check attachments
    for article in @articles
      if article.attachments
        for attachment in article.attachments
          attachment.size = @humanFileSize(attachment.size)

    # define actions
    for article in @articles<commit_msg>Next try to fix see more feature.<commit_after>$ = jQuery.sub()

class Index extends App.Controller
  events:
    'click .submit':                          'update',
    'click [data-type=reply]':                'reply',
    'click [data-type=reply-all]':            'replyall',
    'click [data-type=public]':               'public_internal',
    'click [data-type=internal]':             'public_internal',
    'click [data-type=history]':              'history_view',
    'change [name="ticket_article_type_id"]': 'form_update',
    'click .show_toogle':                     'show_toogle',

  constructor: (params) ->
    super
    @log 'zoom', params

    # check authentication
    return if !@authenticate()

    @navupdate '#'

    @edit_form = undefined
#    @render()
    @ticket_id = params.ticket_id
    @fetch(@ticket_id)

  fetch: (ticket_id) ->
    # get data
    @ajax = new App.Ajax
    @ajax.ajax(
      type:  'GET',
      url:   '/ticket_full/' + ticket_id,
      data:  {
        view: @view
      }
      processData: true,
      success: (data, status, xhr) =>
        # reset old indexes
        @ticket = undefined
        @articles = undefined
        
        # get edit form attributes
        @edit_form = data.edit_form

        # load user collection
        @loadCollection( type: 'User', data: data.users )

        # load ticket collection
        @loadCollection( type: 'Ticket', data: [data.ticket] )

        # load article collections
        @loadCollection( type: 'TicketArticle', data: data.articles || [] )

        # render page
        @render()
    )

  render: =>

    if !App.Ticket.exists(@ticket_id)
      return

    # get data
    if !@ticket
      @ticket = App.Ticket.find(@ticket_id)
    if !@articles
      @articles = []
      for article_id in @ticket.article_ids
        article = App.TicketArticle.find(article_id)
        
        # build html body
        # cleanup body
        article['html'] = article.body.trim()
        article['html'].replace(/\n\r/g, "\n");
        article['html'].replace(/\n\n\n/g, "\n\n");
        
        # if body has more then x lines / else search for signature
        preview       = 15
        preview_mode  = false
        article_lines = article['html'].split(/\n/)
        if article_lines.length > preview
          preview_mode = true
          if article_lines[preview] is ''
            article_lines.splice( preview, 0, "----SEEMORE----" )
          else
            article_lines.splice( preview + 1, 0, "----SEEMORE----" )
          article['html'] = article_lines.join("\n")
        article['html'] = window.linkify( article['html'] )
        notify = "<a href=\"#\" class=\"show_toogle\">" + T('See more') + "</a>"

        # preview mode
        if preview_mode
          article['html'] = article['html'].replace /^----SEEMORE----\n/m, (match) =>
            notify + '<div class="hide">'
          article['html'] = article['html'] + '</div>'
          
        # hide signatures and so on
        else
          @article_changed = false
          article['html'] = article['html'].replace /^(--|__)/m, (match) =>
            @article_changed = true
            notify + '<div class="hide">' + match
          if @article_changed
            article['html'] = article['html'] + '</div>'

        @articles.push article

    # check attachments
    for article in @articles
      if article.attachments
        for attachment in article.attachments
          attachment.size = @humanFileSize(attachment.size)

    # define actions
    for article in @articles
{'fraction_non_alphanumeric': 0.1412707337644082, 'fraction_numerical': 0.0014056789429294349, 'mean_word_length': 1.9076420106252554, 'pattern_counts': {'":': 0, '<': 15, '<?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': '6743739', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2026, 'n_words': 498}