snappymail/dev/View/Popup/FolderCreate.js
djmaze efcefbaf78 Cleanup CSS and drop bMobileDevice detection.
Touch devices can be any size and can use (bluetooth/usb-c mouse/keyboard) these days.
It's all about pixels and currently if the mode is mobile/no-mobile (this can be improved later).
2020-09-30 12:31:34 +02:00

81 lines
2.2 KiB
JavaScript

import ko from 'ko';
import { Notification } from 'Common/Enums';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { defautOptionsAfterRender, folderListOptionsBuilder } from 'Common/Utils';
import FolderStore from 'Stores/User/Folder';
import Remote from 'Remote/User/Fetch';
import { popup, command } from 'Knoin/Knoin';
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
@popup({
name: 'View/Popup/FolderCreate',
templateID: 'PopupsFolderCreate'
})
class FolderCreateView extends AbstractViewNext {
constructor() {
super();
this.folderName = ko.observable('');
this.folderName.focused = ko.observable(false);
this.selectedParentValue = ko.observable(UNUSED_OPTION_VALUE);
this.parentFolderSelectList = ko.computed(() => {
const top = [],
list = FolderStore.folderList(),
fRenameCallback = (oItem) =>
oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
top.push(['', '']);
let fDisableCallback = null;
if (FolderStore.namespace) {
fDisableCallback = (item) => FolderStore.namespace !== item.fullNameRaw.substr(0, FolderStore.namespace.length);
}
return folderListOptionsBuilder([], list, [], top, null, fDisableCallback, null, fRenameCallback);
});
this.defautOptionsAfterRender = defautOptionsAfterRender;
}
@command((self) => self.simpleFolderNameValidation(self.folderName()))
createFolderCommand() {
let parentFolderName = this.selectedParentValue();
if (!parentFolderName && 1 < FolderStore.namespace.length) {
parentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
}
rl.app.foldersPromisesActionHelper(
Remote.folderCreate(this.folderName(), parentFolderName, FolderStore.foldersCreating),
Notification.CantCreateFolder
);
this.cancelCommand();
}
simpleFolderNameValidation(sName) {
return /^[^\\/]+$/g.test(sName.trim());
}
clearPopup() {
this.folderName('');
this.selectedParentValue('');
this.folderName.focused(false);
}
onShow() {
this.clearPopup();
}
onShowWithDelay() {
// rl.settings.app('mobile') ||
this.folderName.focused(true);
}
}
export { FolderCreateView, FolderCreateView as default };