2018-06-05 14:04:14 +01:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
|
|
|
import { A } from '@ember/array';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { schedule } from '@ember/runloop';
|
|
|
|
import { computed } from '@ember/object';
|
2018-06-21 12:38:13 +01:00
|
|
|
import { empty } from '@ember/object/computed';
|
2018-06-05 14:04:14 +01:00
|
|
|
import AuthMixin from '../../mixins/auth';
|
|
|
|
import Notifier from '../../mixins/notifier';
|
|
|
|
import Component from '@ember/component';
|
|
|
|
|
|
|
|
export default Component.extend(AuthMixin, Notifier, {
|
|
|
|
router: service(),
|
|
|
|
spaceSvc: service('folder'),
|
|
|
|
localStorage: service('localStorage'),
|
|
|
|
|
|
|
|
isSpaceAdmin: computed('permissions', function() {
|
|
|
|
return this.get('permissions.spaceOwner') || this.get('permissions.spaceManage');
|
|
|
|
}),
|
|
|
|
|
2018-06-21 12:38:13 +01:00
|
|
|
spaceName: '',
|
|
|
|
hasNameError: empty('spaceName'),
|
2018-06-05 14:04:14 +01:00
|
|
|
spaceTypeOptions: A([]),
|
|
|
|
spaceType: 0,
|
2018-06-08 13:43:46 +01:00
|
|
|
likes: '',
|
2018-06-05 14:04:14 +01:00
|
|
|
allowLikes: false,
|
|
|
|
|
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
let constants = this.get('constants');
|
|
|
|
let folder = this.get('space');
|
|
|
|
|
|
|
|
let spaceTypeOptions = A([]);
|
2018-10-12 17:54:15 +01:00
|
|
|
spaceTypeOptions.pushObject({id: constants.SpaceType.Private, label: 'Private - viewable only by me'});
|
|
|
|
spaceTypeOptions.pushObject({id: constants.SpaceType.Protected, label: 'Protected - access is restricted to selected users'});
|
|
|
|
spaceTypeOptions.pushObject({id: constants.SpaceType.Public, label: 'Public - can be seen by everyone'});
|
2018-06-05 14:04:14 +01:00
|
|
|
this.set('spaceTypeOptions', spaceTypeOptions);
|
2018-10-12 17:54:15 +01:00
|
|
|
this.set('spaceType', spaceTypeOptions.findBy('id', folder.get('spaceType')));
|
2018-06-05 14:04:14 +01:00
|
|
|
|
|
|
|
this.set('allowLikes', folder.get('allowLikes'));
|
2018-06-08 13:43:46 +01:00
|
|
|
|
|
|
|
if (this.get('allowLikes')) {
|
|
|
|
this.set('likes', folder.get('likes'));
|
|
|
|
} else {
|
|
|
|
this.set('likes', 'Did this help you?');
|
|
|
|
}
|
2018-06-21 12:38:13 +01:00
|
|
|
|
|
|
|
this.set('spaceName', this.get('space.name'));
|
2018-06-05 14:04:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
onSetSpaceType(t) {
|
|
|
|
this.set('spaceType', t);
|
|
|
|
},
|
|
|
|
|
|
|
|
onSetLikes(l) {
|
|
|
|
this.set('allowLikes', l);
|
|
|
|
|
|
|
|
schedule('afterRender', () => {
|
|
|
|
if (l) this.$('#space-likes-prompt').focus();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onSave() {
|
|
|
|
if (!this.get('isSpaceAdmin')) return;
|
|
|
|
|
|
|
|
let space = this.get('space');
|
2018-10-12 17:54:15 +01:00
|
|
|
space.set('spaceType', this.get('spaceType.id'));
|
2018-06-05 14:04:14 +01:00
|
|
|
|
|
|
|
let allowLikes = this.get('allowLikes');
|
|
|
|
space.set('likes', allowLikes ? this.get('likes') : '');
|
|
|
|
|
2018-06-21 12:38:13 +01:00
|
|
|
let spaceName = this.get('spaceName').trim();
|
|
|
|
if (spaceName.length === 0) return;
|
|
|
|
space.set('name', spaceName);
|
|
|
|
|
2018-06-05 14:04:14 +01:00
|
|
|
this.showWait();
|
|
|
|
|
|
|
|
this.get('spaceSvc').save(space).then(() => {
|
|
|
|
this.showDone();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|