ui/app/models/apikey.js

69 lines
2.1 KiB
JavaScript

import Resource from 'ember-api-store/models/resource';
import PolledResource from 'ui/mixins/cattle-polled-resource';
import C from 'ui/utils/constants';
var ApiKey = Resource.extend(PolledResource,{
type: 'apiKey',
publicValue: null,
secretValue: null,
actions: {
deactivate: function() {
return this.doAction('deactivate');
},
activate: function() {
return this.doAction('activate');
},
edit: function() {
this.get('application').setProperties({
editApikey: true,
originalModel: this
});
},
},
isForAccount: function() {
return this.get('accountId') === this.get(`session.${C.SESSION.ACCOUNT_ID}`);
}.property('accountId', `session.${C.SESSION.ACCOUNT_ID}`),
reloadOpts: function() {
if ( this.get('isForAccount') )
{
return {
headers: {
[C.HEADER.PROJECT]: undefined
}
};
}
}.property('isForAccount'),
displayName: function() {
return this.get('name') || this.get('publicValue') || '('+this.get('id')+')';
}.property('name','publicValue','id'),
availableActions: function() {
var a = this.get('actionLinks');
return [
{ label: 'Activate', icon: 'icon icon-play', action: 'activate', enabled: !!a.activate },
{ label: 'Deactivate', icon: 'icon icon-pause', action: 'deactivate', enabled: !!a.deactivate },
{ label: 'Delete', icon: 'icon icon-trash', action: 'promptDelete', enabled: !!a.remove, altAction: 'delete' },
{ divider: true },
{ label: 'Purge', icon: '', action: 'purge', enabled: !!a.purge },
{ label: 'Restore', icon: '', action: 'restore', enabled: !!a.restore },
{ divider: true },
{ label: 'Edit', icon: 'icon icon-edit', action: 'edit', enabled: !!a.update },
];
}.property('actionLinks.{update,activate,deactivate,restore,remove,purge}'),
});
ApiKey.reopenClass({
pollTransitioningDelay: 1000,
pollTransitioningInterval: 5000,
});
export default ApiKey;