open-vault/ui/app/models/key-mixin.js
2018-04-03 09:16:57 -05:00

45 lines
1.1 KiB
JavaScript

import Ember from 'ember';
import utils from '../lib/key-utils';
export default Ember.Mixin.create({
flags: null,
initialParentKey: null,
isCreating: Ember.computed('initialParentKey', function() {
return this.get('initialParentKey') != null;
}),
isFolder: Ember.computed('id', function() {
return utils.keyIsFolder(this.get('id'));
}),
keyParts: Ember.computed('id', function() {
return utils.keyPartsForKey(this.get('id'));
}),
parentKey: Ember.computed('id', 'isCreating', {
get: function() {
return this.get('isCreating') ? this.get('initialParentKey') : utils.parentKeyForKey(this.get('id'));
},
set: function(_, value) {
return value;
},
}),
keyWithoutParent: Ember.computed('id', 'parentKey', {
get: function() {
var key = this.get('id');
return key ? key.replace(this.get('parentKey'), '') : null;
},
set: function(_, value) {
if (value && value.trim()) {
this.set('id', this.get('parentKey') + value);
} else {
this.set('id', null);
}
return value;
},
}),
});