<commit_before>#============================================================================
# Modal dialog controllers
#============================================================================

modals = angular.module('cases.modals', []);

URN_SCHEMES = {tel: "Phone", twitter: "Twitter"}


#=====================================================================
# Simple confirmation modal
#=====================================================================
modals.controller 'ConfirmModalController', ['$scope', '$modalInstance', 'prompt', 'style', ($scope, $modalInstance, prompt, style) ->
  $scope.title = "Confirm"
  $scope.prompt = prompt
  $scope.style = style or 'primary'

  $scope.ok = () -> $modalInstance.close(true)
  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Confirm with note modal
#=====================================================================
modals.controller 'NoteModalController', ['$scope', '$modalInstance', 'title', 'prompt', 'style', 'maxLength', ($scope, $modalInstance, title, prompt, style, maxLength) ->
  $scope.title = title
  $scope.prompt = prompt
  $scope.style = style or 'primary'
  $scope.fields = {note: {val: '', maxLength: maxLength}}

  $scope.ok = () ->
    $scope.form.submitted = true

    if $scope.form.$valid
      $modalInstance.close($scope.fields.note.val)

  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Edit text modal
#=====================================================================
modals.controller 'EditModalController', ['$scope', '$modalInstance', 'title', 'initial', 'maxLength', ($scope, $modalInstance, title, initial, maxLength) ->
  $scope.title = title
  $scope.fields = {text: {val: initial, maxLength: maxLength}}

  $scope.ok = () ->
    if $scope.form.$valid
      $modalInstance.close($scope.fields.text.val)

  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Reply to contacts modal
#=====================================================================
modals.controller('ReplyModalController', ['$scope', '$modalInstance', 'maxLength', ($scope, $modalInstance, maxLength) ->
  $scope.fields = {text: {val: '', maxLength: maxLength}}

  $scope.ok = () ->
    $scope.form.submitted = true
    if $scope.form.$valid
      $modalInstance.close($scope.fields.text.val)

  $scope.cancel = () -> $modalInstance.dismiss('cancel')
])


#=====================================================================
# Open new case modal
#=====================================================================
modals.controller 'NewCaseModalController', ['$scope', '$modalInstance', 'message', 'summaryMaxLength', 'partners', ($scope, $modalInstance, message, summaryMaxLength, partners) ->
  $scope.partners = partners
  $scope.fields = {
    summary: {val: message.text, maxLength: summaryMaxLength},
    assignee: {val: if partners then partners[0] else null}
  }

  $scope.ok = () ->
    $scope.form.submitted = true
    if $scope.form.$valid
      $modalInstance.close({summary: $scope.fields.summary.val, assignee: $scope.fields.assignee.val})
  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Assign to partner modal
#=====================================================================
modals.controller 'AssignModalController', ['$scope', '$modalInstance', 'title', 'prompt', 'partners', ($scope, $modalInstance, title, prompt, partners) ->
  $scope.title = title
  $scope.prompt = prompt
  $scope.partners = partners
  $scope.fields = { assignee: partners[0] }

  $scope.ok = () -> $modalInstance.close($scope.fields.assignee)
  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Edit item labels modal
#=====================================================================
modals.controller('LabelModalController', ['$scope', '$modalInstance', 'title', 'prompt', 'labels', 'initial', ($scope, $modalInstance, title, prompt, labels, initial) ->
  $scope.title = title
  $scope.prompt = prompt
  $scope.selection = ({label: l, selected: (l.id in (i.id for i in initial))} for l in labels)

  $scope.ok = () ->
    selectedLabels = (item.label for item in $scope.selection when item.selected)
    $modalInstance.close(selectedLabels)

  $scope.cancel = () -> $modalInstance.dismiss('cancel')
])


#=====================================================================
# Compose message to URN modal
#=====================================================================
modals.controller('ComposeModalController', ['$scope', '$modalInstance', 'title', 'initialText', 'maxLength', ($scope, $modalInstance, title, initialText, maxLength) ->
  $scope.title = title
  $scope.fields = {
    urn: {scheme: null, path: ''},
    text: {val: initialText, maxLength: maxLength}
  }

  $scope.setScheme = (scheme) ->
    $scope.fields.urn.scheme = scheme
    $scope.urn_scheme_label = URN_SCHEMES[scheme]

  $scope.ok = () ->
    $scope.form.submitted = true

    if $scope.form.$valid
      urn = {scheme: $scope.fields.urn.scheme, path: $scope.fields.urn.path, urn: ($scope.fields.urn.scheme + ':' + $scope.fields.urn.path)}
      $modalInstance.close({text: $scope.fields.text, urn: urn})<commit_msg>Fixed bug on forward message modal<commit_after>#============================================================================
# Modal dialog controllers
#============================================================================

modals = angular.module('cases.modals', []);

URN_SCHEMES = {tel: "Phone", twitter: "Twitter"}


#=====================================================================
# Simple confirmation modal
#=====================================================================
modals.controller 'ConfirmModalController', ['$scope', '$modalInstance', 'prompt', 'style', ($scope, $modalInstance, prompt, style) ->
  $scope.title = "Confirm"
  $scope.prompt = prompt
  $scope.style = style or 'primary'

  $scope.ok = () -> $modalInstance.close(true)
  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Confirm with note modal
#=====================================================================
modals.controller 'NoteModalController', ['$scope', '$modalInstance', 'title', 'prompt', 'style', 'maxLength', ($scope, $modalInstance, title, prompt, style, maxLength) ->
  $scope.title = title
  $scope.prompt = prompt
  $scope.style = style or 'primary'
  $scope.fields = {note: {val: '', maxLength: maxLength}}

  $scope.ok = () ->
    $scope.form.submitted = true

    if $scope.form.$valid
      $modalInstance.close($scope.fields.note.val)

  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Edit text modal
#=====================================================================
modals.controller 'EditModalController', ['$scope', '$modalInstance', 'title', 'initial', 'maxLength', ($scope, $modalInstance, title, initial, maxLength) ->
  $scope.title = title
  $scope.fields = {text: {val: initial, maxLength: maxLength}}

  $scope.ok = () ->
    if $scope.form.$valid
      $modalInstance.close($scope.fields.text.val)

  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Reply to contacts modal
#=====================================================================
modals.controller('ReplyModalController', ['$scope', '$modalInstance', 'maxLength', ($scope, $modalInstance, maxLength) ->
  $scope.fields = {text: {val: '', maxLength: maxLength}}

  $scope.ok = () ->
    $scope.form.submitted = true
    if $scope.form.$valid
      $modalInstance.close($scope.fields.text.val)

  $scope.cancel = () -> $modalInstance.dismiss('cancel')
])


#=====================================================================
# Open new case modal
#=====================================================================
modals.controller 'NewCaseModalController', ['$scope', '$modalInstance', 'message', 'summaryMaxLength', 'partners', ($scope, $modalInstance, message, summaryMaxLength, partners) ->
  $scope.partners = partners
  $scope.fields = {
    summary: {val: message.text, maxLength: summaryMaxLength},
    assignee: {val: if partners then partners[0] else null}
  }

  $scope.ok = () ->
    $scope.form.submitted = true
    if $scope.form.$valid
      $modalInstance.close({summary: $scope.fields.summary.val, assignee: $scope.fields.assignee.val})
  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Assign to partner modal
#=====================================================================
modals.controller 'AssignModalController', ['$scope', '$modalInstance', 'title', 'prompt', 'partners', ($scope, $modalInstance, title, prompt, partners) ->
  $scope.title = title
  $scope.prompt = prompt
  $scope.partners = partners
  $scope.fields = { assignee: partners[0] }

  $scope.ok = () -> $modalInstance.close($scope.fields.assignee)
  $scope.cancel = () -> $modalInstance.dismiss('cancel')
]


#=====================================================================
# Edit item labels modal
#=====================================================================
modals.controller('LabelModalController', ['$scope', '$modalInstance', 'title', 'prompt', 'labels', 'initial', ($scope, $modalInstance, title, prompt, labels, initial) ->
  $scope.title = title
  $scope.prompt = prompt
  $scope.selection = ({label: l, selected: (l.id in (i.id for i in initial))} for l in labels)

  $scope.ok = () ->
    selectedLabels = (item.label for item in $scope.selection when item.selected)
    $modalInstance.close(selectedLabels)

  $scope.cancel = () -> $modalInstance.dismiss('cancel')
])


#=====================================================================
# Compose message to URN modal
#=====================================================================
modals.controller('ComposeModalController', ['$scope', '$modalInstance', 'title', 'initialText', 'maxLength', ($scope, $modalInstance, title, initialText, maxLength) ->
  $scope.title = title
  $scope.fields = {
    urn: {scheme: null, path: ''},
    text: {val: initialText, maxLength: maxLength}
  }

  $scope.setScheme = (scheme) ->
    $scope.fields.urn.scheme = scheme
    $scope.urn_scheme_label = URN_SCHEMES[scheme]

  $scope.ok = () ->
    $scope.form.submitted = true

    if $scope.form.$valid
      urn = {scheme: $scope.fields.urn.scheme, path: $scope.fields.urn.path, urn: ($scope.fields.urn.scheme + ':' + $scope.fields.urn.path)}
      $modalInstance.close({text: $scope.fields.text.val, urn: urn})
{'fraction_non_alphanumeric': 0.36737099845832955, 'fraction_numerical': 0.00036274598712251744, 'mean_word_length': 5.948960302457467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, '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': '5258026', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2785, 'n_words': 602}