2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { Notification } from 'Common/Enums';
|
|
|
|
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
2020-10-15 01:16:37 +08:00
|
|
|
import { defaultOptionsAfterRender } from 'Common/Utils';
|
2021-12-09 18:24:30 +08:00
|
|
|
import { folderListOptionsBuilder, sortFolders } from 'Common/UtilsUser';
|
2021-12-08 18:06:42 +08:00
|
|
|
import { getNotification } from 'Common/Translator';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { FolderUserStore } from 'Stores/User/Folder';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
import { decorateKoCommands } from 'Knoin/Knoin';
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|
|
|
|
2021-12-08 18:06:42 +08:00
|
|
|
import { setFolder, getFolderFromCacheList } from 'Common/Cache';
|
|
|
|
import { FolderModel } from 'Model/FolderCollection';
|
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
class FolderCreatePopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('FolderCreate');
|
2021-11-08 00:06:08 +08:00
|
|
|
this.viewNoUserSelect = true;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
folderName: '',
|
2014-04-27 05:53:37 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
selectedParentValue: UNUSED_OPTION_VALUE
|
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-24 05:45:30 +08:00
|
|
|
this.parentFolderSelectList = ko.computed(() =>
|
|
|
|
folderListOptionsBuilder(
|
|
|
|
[],
|
|
|
|
[['', '']],
|
2021-08-19 21:14:47 +08:00
|
|
|
oItem =>
|
|
|
|
oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '',
|
2021-03-24 05:45:30 +08:00
|
|
|
FolderUserStore.namespace
|
2021-12-08 18:35:41 +08:00
|
|
|
? item => FolderUserStore.namespace !== item.fullName.slice(0, FolderUserStore.namespace.length)
|
2021-03-11 05:41:35 +08:00
|
|
|
: null,
|
2021-08-19 21:14:47 +08:00
|
|
|
true
|
2021-03-24 05:45:30 +08:00
|
|
|
)
|
|
|
|
);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-10-15 01:16:37 +08:00
|
|
|
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
|
2021-02-19 19:09:20 +08:00
|
|
|
|
|
|
|
decorateKoCommands(this, {
|
|
|
|
createFolderCommand: self => self.simpleFolderNameValidation(self.folderName())
|
|
|
|
});
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
createFolderCommand() {
|
|
|
|
let parentFolderName = this.selectedParentValue();
|
2021-03-11 05:41:35 +08:00
|
|
|
if (!parentFolderName && 1 < FolderUserStore.namespace.length) {
|
2021-12-08 18:35:41 +08:00
|
|
|
parentFolderName = FolderUserStore.namespace.slice(0, FolderUserStore.namespace.length - 1);
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-12-08 18:06:42 +08:00
|
|
|
Remote.abort('Folders').post('FolderCreate', FolderUserStore.foldersCreating, {
|
2021-12-03 06:15:24 +08:00
|
|
|
Folder: this.folderName(),
|
|
|
|
Parent: parentFolderName
|
2021-12-08 18:06:42 +08:00
|
|
|
})
|
|
|
|
.then(
|
|
|
|
data => {
|
|
|
|
const folder = getFolderFromCacheList(parentFolderName),
|
2021-12-09 18:24:30 +08:00
|
|
|
subFolder = FolderModel.reviveFromJson(data.Result),
|
|
|
|
folders = (folder ? folder.subFolders : FolderUserStore.folderList);
|
2021-12-08 18:06:42 +08:00
|
|
|
setFolder(subFolder);
|
2021-12-09 18:24:30 +08:00
|
|
|
folders.push(subFolder);
|
|
|
|
sortFolders(folders);
|
2021-12-08 18:06:42 +08:00
|
|
|
/*
|
|
|
|
var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
|
|
|
|
console.log((folder ? folder.subFolders : FolderUserStore.folderList).sort(collator.compare));
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
FolderUserStore.folderListError(
|
|
|
|
getNotification(error.code, '', Notification.CantCreateFolder)
|
|
|
|
+ '.\n' + error.message);
|
|
|
|
}
|
|
|
|
);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
this.cancelCommand();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
simpleFolderNameValidation(sName) {
|
2021-03-24 05:57:40 +08:00
|
|
|
return /^[^\\/]+$/g.test(sName);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-11-03 21:58:34 +08:00
|
|
|
onShow() {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.folderName('');
|
|
|
|
this.selectedParentValue('');
|
|
|
|
}
|
|
|
|
}
|
2013-12-29 04:42:07 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
export { FolderCreatePopupView, FolderCreatePopupView as default };
|