1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-02 13:24:20 +01:00
fab-manager/app/assets/javascripts/controllers/admin/open_api_clients.coffee.erb
2016-05-09 18:15:04 +02:00

88 lines
2.6 KiB
Plaintext

Application.Controllers.controller "OpenAPIClientsController", ["$scope", 'clientsPromise', 'growl', 'OpenAPIClient', 'dialogs', '_t'
, ($scope, clientsPromise, growl, OpenAPIClient, dialogs, _t) ->
### PUBLIC SCOPE ###
## clients list
$scope.clients = clientsPromise
$scope.order = null
$scope.clientFormVisible = false
$scope.client = {}
$scope.toggleForm = ->
$scope.clientFormVisible = !$scope.clientFormVisible
# Change the order criterion to the one provided
# @param orderBy {string} ordering criterion
##
$scope.setOrder = (orderBy)->
if $scope.order == orderBy
$scope.order = '-'+orderBy
else
$scope.order = orderBy
$scope.saveClient = (client)->
if client.id?
OpenAPIClient.update { id: client.id }, open_api_client: client, (clientResp)->
client = clientResp
growl.success(_t('client_successfully_updated'))
else
OpenAPIClient.save open_api_client: client, (client)->
$scope.clients.push client
growl.success(_t('client_successfully_created'))
$scope.clientFormVisible = false
$scope.clientForm.$setPristine()
$scope.client = {}
$scope.editClient = (client)->
$scope.clientFormVisible = true
$scope.client = client
$scope.deleteClient = (index)->
dialogs.confirm
resolve:
object: ->
title: _t('confirmation_required')
msg: _t('do_you_really_want_to_delete_this_open_api_client')
, ->
OpenAPIClient.delete { id: $scope.clients[index].id }, ->
$scope.clients.splice(index, 1)
growl.success(_t('client_successfully_deleted'))
$scope.resetToken = (client)->
dialogs.confirm
resolve:
object: ->
title: _t('confirmation_required')
msg: _t('do_you_really_want_to_revoke_this_open_api_access')
, ->
OpenAPIClient.resetToken { id: client.id }, {}, (clientResp)->
client.token = clientResp.token
growl.success(_t('access_successfully_revoked'))
##
# Ask for confirmation then delete the specified administrator
# @param admins {Array} full list of administrators
# @param admin {Object} administrator to delete
##
$scope.destroyAdmin = (admins, admin)->
dialogs.confirm
resolve:
object: ->
title: _t('confirmation_required')
msg: _t('do_you_really_want_to_delete_this_administrator_this_cannot_be_undone')
, -> # cancel confirmed
Admin.delete id: admin.id, ->
admins.splice(findAdminIdxById(admins, admin.id), 1)
growl.success(_t('administrator_successfully_deleted'))
, (error)->
growl.error(_t('unable_to_delete_the_administrator'))
]