snappymail/dev/View/Popup/FolderCreate.js

80 lines
2.1 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2019-07-05 03:19:24 +08:00
import { Notification } from 'Common/Enums';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { defaultOptionsAfterRender } from 'Common/Utils';
import { folderListOptionsBuilder } from 'Common/UtilsUser';
2014-08-21 23:08:34 +08:00
import FolderStore from 'Stores/User/Folder';
2014-08-25 15:10:51 +08:00
import Remote from 'Remote/User/Fetch';
import { command } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
class FolderCreatePopupView extends AbstractViewPopup {
constructor() {
super('FolderCreate');
this.addObservables({
folderName: '',
folderNameFocused: false,
2014-04-27 05:53:37 +08:00
selectedParentValue: UNUSED_OPTION_VALUE
});
2014-08-21 23:08:34 +08:00
this.parentFolderSelectList = ko.computed(() => {
2019-07-05 03:19:24 +08:00
const top = [],
list = FolderStore.folderList(),
2019-07-05 03:19:24 +08:00
fRenameCallback = (oItem) =>
oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
2014-08-21 23:08:34 +08:00
top.push(['', '']);
2014-08-21 23:08:34 +08:00
let fDisableCallback = null;
if (FolderStore.namespace) {
fDisableCallback = (item) => FolderStore.namespace !== item.fullNameRaw.substr(0, FolderStore.namespace.length);
}
2014-08-21 23:08:34 +08:00
return folderListOptionsBuilder([], list, [], top, null, fDisableCallback, null, fRenameCallback);
});
2014-08-21 23:08:34 +08:00
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
2016-09-10 06:38:16 +08:00
}
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
@command((self) => self.simpleFolderNameValidation(self.folderName()))
createFolderCommand() {
let parentFolderName = this.selectedParentValue();
if (!parentFolderName && 1 < FolderStore.namespace.length) {
2016-09-10 06:38:16 +08:00
parentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
}
2014-08-21 23:08:34 +08:00
2020-09-15 15:29:25 +08:00
rl.app.foldersPromisesActionHelper(
Remote.folderCreate(this.folderName(), parentFolderName, FolderStore.foldersCreating),
2016-09-10 06:38:16 +08:00
Notification.CantCreateFolder
);
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
this.cancelCommand();
}
simpleFolderNameValidation(sName) {
return /^[^\\/]+$/g.test(sName.trim());
}
clearPopup() {
this.folderName('');
this.selectedParentValue('');
this.folderNameFocused(false);
}
onShow() {
this.clearPopup();
}
onShowWithDelay() {
this.folderNameFocused(true);
2016-06-30 08:02:45 +08:00
}
}
2013-12-29 04:42:07 +08:00
export { FolderCreatePopupView, FolderCreatePopupView as default };