snappymail/dev/View/Popup/FolderCreate.js
djmaze 6a454ec624 Convert user stores to single object instances
Removed unused ContactUserStore.exportingCsv and ContactUserStore.exportingVcf
2021-03-10 22:41:35 +01:00

80 lines
2.1 KiB
JavaScript

import ko from 'ko';
import { Notification } from 'Common/Enums';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { defaultOptionsAfterRender } from 'Common/Utils';
import { folderListOptionsBuilder } from 'Common/UtilsUser';
import { FolderUserStore } from 'Stores/User/Folder';
import Remote from 'Remote/User/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
class FolderCreatePopupView extends AbstractViewPopup {
constructor() {
super('FolderCreate');
this.addObservables({
folderName: '',
folderNameFocused: false,
selectedParentValue: UNUSED_OPTION_VALUE
});
this.parentFolderSelectList = ko.computed(() => {
const top = [],
list = FolderUserStore.folderList(),
fDisableCallback = FolderUserStore.namespace
? item => FolderUserStore.namespace !== item.fullNameRaw.substr(0, FolderUserStore.namespace.length)
: null,
fRenameCallback = oItem =>
oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
top.push(['', '']);
return folderListOptionsBuilder([], list, [], top, null, fDisableCallback, null, fRenameCallback);
});
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
decorateKoCommands(this, {
createFolderCommand: self => self.simpleFolderNameValidation(self.folderName())
});
}
createFolderCommand() {
let parentFolderName = this.selectedParentValue();
if (!parentFolderName && 1 < FolderUserStore.namespace.length) {
parentFolderName = FolderUserStore.namespace.substr(0, FolderUserStore.namespace.length - 1);
}
rl.app.foldersPromisesActionHelper(
Remote.folderCreate(this.folderName(), parentFolderName),
Notification.CantCreateFolder
);
this.cancelCommand();
}
simpleFolderNameValidation(sName) {
return /^[^\\/]+$/g.test(sName.trim());
}
clearPopup() {
this.folderName('');
this.selectedParentValue('');
this.folderNameFocused(false);
}
onShow() {
this.clearPopup();
}
onShowWithDelay() {
this.folderNameFocused(true);
}
}
export { FolderCreatePopupView, FolderCreatePopupView as default };