1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 05:09:42 +02:00
documize/gui/app/pods/folders/controller.js

118 lines
2.9 KiB
JavaScript
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
2016-11-06 20:11:21 -08:00
// This software (Documize Community Edition) is licensed under
2016-07-07 18:54:16 -07:00
// 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
2016-11-06 20:11:21 -08:00
// by contacting <sales@documize.com>.
2016-07-07 18:54:16 -07:00
//
// https://documize.com
import $ from 'jquery';
import { inject as service } from '@ember/service';
import { notEmpty } from '@ember/object/computed';
import AuthMixin from '../../mixins/auth';
import Modals from '../../mixins/modal';
import Controller from '@ember/controller';
2016-07-07 18:54:16 -07:00
export default Controller.extend(AuthMixin, Modals, {
2018-05-23 15:57:30 +01:00
appMeta: service(),
folderService: service('folder'),
copyTemplate: true,
copyPermission: true,
copyDocument: false,
hasClone: notEmpty('clonedSpace.id'),
clonedSpace: null,
2018-12-12 13:35:16 +00:00
selectedView: 'all',
selectedSpaces: null,
publicSpaces: null,
protectedSpaces: null,
personalSpaces: null,
spaceIcon: '',
spaceLabel: '',
spaceDesc: '',
spaceName: '',
2018-12-12 13:35:16 +00:00
2016-11-06 20:11:21 -08:00
actions: {
onShowModal() {
this.modalOpen('#add-space-modal', {'show': true}, '#new-space-name');
},
onCloneSpaceSelect(sp) {
this.set('clonedSpace', sp)
},
onSetIcon(icon) {
this.set('spaceIcon', icon);
},
onSetLabel(id) {
this.set('spaceLabel', id);
},
onAddSpace(e) {
e.preventDefault();
let spaceName = this.get('spaceName');
let spaceDesc = this.get('spaceDesc');
let spaceIcon = this.get('spaceIcon');
let spaceLabel = this.get('spaceLabel');
let clonedId = this.get('clonedSpace.id');
if (is.empty(spaceName)) {
$("#new-space-name").addClass("is-invalid").focus();
return false;
}
let payload = {
name: spaceName,
desc: spaceDesc,
icon: spaceIcon,
labelId: spaceLabel,
cloneId: clonedId,
copyTemplate: this.get('copyTemplate'),
copyPermission: this.get('copyPermission'),
copyDocument: this.get('copyDocument'),
}
this.set('spaceName', '');
this.set('spaceDesc', '');
this.set('spaceIcon', '');
this.set('spaceLabel', '');
this.set('clonedSpace', null);
$("#new-space-name").removeClass("is-invalid");
this.modalClose('#add-space-modal');
this.get('folderService').add(payload).then((sp) => {
this.get('folderService').setCurrentFolder(sp);
this.transitionToRoute('folder', sp.get('id'), sp.get('slug'));
2016-11-06 20:11:21 -08:00
});
2018-12-12 13:35:16 +00:00
},
onSelect(view) {
this.set('selectedView', view);
switch(view) {
case 'all':
this.set('selectedSpaces', this.get('model.spaces'));
2018-12-12 13:35:16 +00:00
break;
case 'public':
this.set('selectedSpaces', this.get('publicSpaces'));
break;
case 'protected':
this.set('selectedSpaces', this.get('protectedSpaces'));
break;
case 'personal':
this.set('selectedSpaces', this.get('personalSpaces'));
break;
default:
this.set('selectedSpaces', this.get(view));
break;
2018-12-12 13:35:16 +00:00
}
2016-11-06 20:11:21 -08:00
}
}
});