<commit_before>import './_custom-button-menu.sass'
import templateUrl from './custom-button-menu.html'

export const CustomButtonMenuComponent = {
  bindings: {
    customActions: '<',
    serviceId: '<',
    vmId: '<'
  },
  controller: CustomButtonMenuController,
  controllerAs: 'vm',
  templateUrl
}

/** @ngInject */
function CustomButtonMenuController ($state, EventNotifications, CollectionsApi, RBAC) {
  const vm = this
  vm.hasRequiredRole = hasRequiredRole
  vm.invokeCustomAction = invokeCustomAction
  function hasRequiredRole (button) {
    const acceptableRoles = button.visibility.roles

    return RBAC.hasRole(...acceptableRoles)
  }

  function invokeCustomAction (button) {
    if (button.enabled) {
      if (button.resource_action && button.resource_action.dialog_id) {
        const options = {
          button: button,
          serviceId: vm.serviceId
        }
        if (vm.vmId) {
          options.vmId = vm.vmId
        }
        $state.go('services.custom_button_details', options)
      } else if (vm.vmId) {
        const data = { action: button.name }
        CollectionsApi.post('vms', vm.vmId, {}, data)
          .then(postSuccess)
          .catch(postFailure)
      } else {
        const data = { action: button.name }
        CollectionsApi.post('services', vm.serviceId, {}, data)
          .then(postSuccess)
          .catch(postFailure)
      }
    }

    function postSuccess (response) {
      if (response.success === false) {
        EventNotifications.error(response.message)
      } else {
        EventNotifications.success(response.message)
      }
    }

    function postFailure () {
      EventNotifications.error(__('Action not able to submit.'))
    }
  }
}<commit_msg>Updated error response message<commit_after>import './_custom-button-menu.sass'
import templateUrl from './custom-button-menu.html'

export const CustomButtonMenuComponent = {
  bindings: {
    customActions: '<',
    serviceId: '<',
    vmId: '<'
  },
  controller: CustomButtonMenuController,
  controllerAs: 'vm',
  templateUrl
}

/** @ngInject */
function CustomButtonMenuController ($state, EventNotifications, CollectionsApi, RBAC) {
  const vm = this
  vm.hasRequiredRole = hasRequiredRole
  vm.invokeCustomAction = invokeCustomAction
  function hasRequiredRole (button) {
    const acceptableRoles = button.visibility.roles

    return RBAC.hasRole(...acceptableRoles)
  }

  function invokeCustomAction (button) {
    if (button.enabled) {
      if (button.resource_action && button.resource_action.dialog_id) {
        const options = {
          button: button,
          serviceId: vm.serviceId
        }
        if (vm.vmId) {
          options.vmId = vm.vmId
        }
        $state.go('services.custom_button_details', options)
      } else if (vm.vmId) {
        const data = { action: button.name }
        CollectionsApi.post('vms', vm.vmId, {}, data)
          .then(postSuccess)
          .catch(postFailure)
      } else {
        const data = { action: button.name }
        CollectionsApi.post('services', vm.serviceId, {}, data)
          .then(postSuccess)
          .catch(postFailure)
      }
    }

    function postSuccess (response) {
      if (response.success === false) {
        EventNotifications.error(response.message)
      } else {
        EventNotifications.success(response.message)
      }
    }

    function postFailure (response) {
      EventNotifications.error(__('There was an error submitting the custom button. ') + response.message);
    }
  }
}
{'fraction_non_alphanumeric': 0.11542824730572887, 'fraction_numerical': 0.0, 'mean_word_length': 2.6473629782833505, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '1464704', 'n_tokens_mistral': 1025, 'n_tokens_neox': 1008, 'n_words': 204}