<commit_before>PageView = require 'views/base/page'
Template = require 'models/template'
_ = require 'underscore'
mediator = require('chaplin').mediator
FormMixin = require 'views/base/mixins/form'

tpl = require 'templates/templates/editor'

module.exports = class TemplateEditor extends PageView
  @mixin FormMixin

  template: tpl

  listen:
    'sync collection': 'render'

  events:
    'click [href="#new"]': 'clickNew'
    'click [href="#delete"]': 'clickDelete'
    'submit form': 'submitForm'

  getTemplateData: ->
    _.extend super,
      items: @collection.toJSON()

  render: ->
    super
    @$code = @$('textarea.code')

    Modernizr.load
      load: ["/#{mediator.options.adminSegment}/js/ace/ace.js"]
      complete: @bindAceEditor

  bindAceEditor: =>
    ace.config.set 'basePath', "/#{mediator.options.adminSegment}/js/ace/"
    @editor = ace.edit(@$('.code.editor')[0])
    @editor.setTheme 'ace/theme/tomorrow'
    @editor.renderer.setShowGutter no

    @editorSession = @editor.getSession()
    @editorSession.setMode 'ace/mode/handlebars'

    @selectTemplate @model.get('filename')

  selectTemplate: (filename) -><commit_msg>Fix async loading of TemplateEditor<commit_after>PageView = require 'views/base/page'
Template = require 'models/template'
_ = require 'underscore'
mediator = require('chaplin').mediator
FormMixin = require 'views/base/mixins/form'

tpl = require 'templates/templates/editor'

module.exports = class TemplateEditor extends PageView
  @mixin FormMixin

  template: tpl

  listen:
    'sync collection': 'render'

  events:
    'click [href="#new"]': 'clickNew'
    'click [href="#delete"]': 'clickDelete'
    'submit form': 'submitForm'

  getTemplateData: ->
    _.extend super,
      items: @collection.toJSON()

  render: ->
    super
    @$code = @$('textarea.code')

    Modernizr.load
      load: ["/#{mediator.options.adminSegment}/js/ace/ace.js"]
      complete: @bindAceEditor

  bindAceEditor: =>
    return if @disposed

    ace.config.set 'basePath', "/#{mediator.options.adminSegment}/js/ace/"
    @editor = ace.edit(@$('.code.editor')[0])
    @editor.setTheme 'ace/theme/tomorrow'
    @editor.renderer.setShowGutter no

    @editorSession = @editor.getSession()
    @editorSession.setMode 'ace/mode/handlebars'

    @selectTemplate @model.get('filename')

  selectTemplate: (filename) ->
{'fraction_non_alphanumeric': 0.15172120696982574, 'fraction_numerical': 0.0008499787505312367, 'mean_word_length': 3.8536082474226805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4321969', 'n_tokens_mistral': 770, 'n_tokens_neox': 754, 'n_words': 149}