<commit_before>kd                        = require 'kd'
timeago                   = require 'timeago'

BaseStackTemplateListItem = require './basestacktemplatelistitem'


module.exports = class StackTemplateListItem extends BaseStackTemplateListItem

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

    options.cssClass = kd.utils.curry "stacktemplate-item clearfix", options.cssClass
    super options, data

    { inuse, accessLevel, config } = @getData()

    @inuseView = new kd.CustomHTMLView
      cssClass : 'custom-tag'
      partial  : 'IN USE'
      tooltip  :
        title  : 'This group currently using this template'

    @notReadyView = new kd.CustomHTMLView
      cssClass : 'custom-tag not-ready'
      partial  : 'NOT READY'
      tooltip  :
        title  : 'Template is not verified or credential data is missing'

    @accessLevelView = new kd.CustomHTMLView
      cssClass : "custom-tag #{accessLevel}"
      partial  : accessLevel.toUpperCase()
      tooltip  :
        title  : switch accessLevel
          when 'public'
            'This group currently using this template'
          when 'group'
            'This template can be used in group'
          when 'private'
            'Only you can use this template'

    @inuseView.hide()     unless inuse
    @notReadyView.hide()  if config.verified


  editStackTemplate: ->
    @getDelegate().emit 'ItemSelected', @getData()


  settingsMenu: ->

    listView      = @getDelegate()
    stackTemplate = @getData()

    if not stackTemplate.inuse and stackTemplate.config.verified
      @addMenuItem 'Apply to Team', ->
        listView.emit 'ItemSelectedAsDefault', stackTemplate

    super


  pistachio: ->

    { meta } = @getData()

    """
    <div class='stacktemplate-info clearfix'>
      {div.title{#(title)}} {{> @inuseView}} {{> @notReadyView}} {{> @accessLevelView}}
      <cite>#{timeago meta.createdAt}</cite>
    </div>
    <div class='buttons'>{{> @settings}}</div>
    """
<commit_msg>StackTemplateListItem: ask for clone if edit requested stack template is in use<commit_after>kd                        = require 'kd'
timeago                   = require 'timeago'

BaseStackTemplateListItem = require './basestacktemplatelistitem'


module.exports = class StackTemplateListItem extends BaseStackTemplateListItem

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

    options.cssClass = kd.utils.curry "stacktemplate-item clearfix", options.cssClass
    super options, data

    { inuse, accessLevel, config } = @getData()

    @inuseView = new kd.CustomHTMLView
      cssClass : 'custom-tag'
      partial  : 'IN USE'
      tooltip  :
        title  : 'This group currently using this template'

    @notReadyView = new kd.CustomHTMLView
      cssClass : 'custom-tag not-ready'
      partial  : 'NOT READY'
      tooltip  :
        title  : 'Template is not verified or credential data is missing'

    @accessLevelView = new kd.CustomHTMLView
      cssClass : "custom-tag #{accessLevel}"
      partial  : accessLevel.toUpperCase()
      tooltip  :
        title  : switch accessLevel
          when 'public'
            'This group currently using this template'
          when 'group'
            'This template can be used in group'
          when 'private'
            'Only you can use this template'

    @inuseView.hide()     unless inuse
    @notReadyView.hide()  if config.verified


  editStackTemplate: ->

    { inuse } = @getData()

    if inuse

      modal = new kd.ModalView
        title          : 'Editing in-use stack template ?'
        overlay        : yes
        overlayOptions :
          cssClass     : 'second-overlay'
          overlayClick : yes
        content        : "
          This stack template is currently using by the Team, if you continue
          to edit, all the changes you've made will be applied to all members,
          we highly recommend you to create a clone of this stack template
          first and do your updates on that clone. Once you finish your work
          with the cloned version, you can easily apply the changes to your
          team.
        "
        buttons      :

          "Clone and Open Editor":
            style    : 'solid medium green'
            callback : ->
              new kd.NotificationView title: 'Coming soon!'

          "I know what I'm doing, Open Editor":
            style    : 'solid medium red'
            callback : =>
              @_itemSelected()
              modal.destroy()

    else
      @_itemSelected()



  _itemSelected: ->
    @getDelegate().emit 'ItemSelected', @getData()


  settingsMenu: ->

    listView      = @getDelegate()
    stackTemplate = @getData()

    if not stackTemplate.inuse and stackTemplate.config.verified
      @addMenuItem 'Apply to Team', ->
        listView.emit 'ItemSelectedAsDefault', stackTemplate

    super


  pistachio: ->

    { meta } = @getData()

    """
    <div class='stacktemplate-info clearfix'>
      {div.title{#(title)}} {{> @inuseView}} {{> @notReadyView}} {{> @accessLevelView}}
      <cite>#{timeago meta.createdAt}</cite>
    </div>
    <div class='buttons'>{{> @settings}}</div>
    """

{'fraction_non_alphanumeric': 0.09884967829986352, 'fraction_numerical': 0.0, 'mean_word_length': 2.2468354430379747, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 36, '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': '1454964', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1394, 'n_words': 418}