2022-10-31 05:19:52 +08:00
|
|
|
import { koComputable, addObservablesTo } from 'External/ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { Notification } from 'Common/Enums';
|
2020-10-15 01:16:37 +08:00
|
|
|
import { defaultOptionsAfterRender } from 'Common/Utils';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { folderListOptionsBuilder, sortFolders } from 'Common/Folders';
|
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-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';
|
|
|
|
|
2022-02-24 21:01:41 +08:00
|
|
|
export class FolderCreatePopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('FolderCreate');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2022-10-31 05:19:52 +08:00
|
|
|
addObservablesTo(this, {
|
2023-01-30 21:26:42 +08:00
|
|
|
name: '',
|
|
|
|
subscribe: true,
|
|
|
|
parentFolder: ''
|
2020-10-26 19:54:03 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-12-31 20:30:05 +08:00
|
|
|
this.parentFolderSelectList = koComputable(() =>
|
2021-03-24 05:45:30 +08:00
|
|
|
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
|
2022-10-26 22:38:39 +08:00
|
|
|
? item => !item.fullName.startsWith(FolderUserStore.namespace)
|
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;
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-09-24 07:20:02 +08:00
|
|
|
submitForm(form) {
|
|
|
|
if (form.reportValidity()) {
|
|
|
|
const data = new FormData(form);
|
|
|
|
|
2023-01-30 21:26:42 +08:00
|
|
|
let parentFolderName = this.parentFolder();
|
2022-02-25 20:12:44 +08:00
|
|
|
if (!parentFolderName && 1 < FolderUserStore.namespace.length) {
|
2023-01-25 01:58:25 +08:00
|
|
|
data.set('parent', FolderUserStore.namespace.slice(0, FolderUserStore.namespace.length - 1));
|
2022-02-25 20:12:44 +08:00
|
|
|
}
|
|
|
|
|
2022-09-24 07:20:02 +08:00
|
|
|
Remote.abort('Folders').post('FolderCreate', FolderUserStore.foldersCreating, data)
|
2022-02-25 20:12:44 +08:00
|
|
|
.then(
|
|
|
|
data => {
|
|
|
|
const folder = getFolderFromCacheList(parentFolderName),
|
|
|
|
subFolder = FolderModel.reviveFromJson(data.Result),
|
|
|
|
folders = (folder ? folder.subFolders : FolderUserStore.folderList);
|
|
|
|
setFolder(subFolder);
|
|
|
|
folders.push(subFolder);
|
|
|
|
sortFolders(folders);
|
2021-12-08 18:06:42 +08:00
|
|
|
/*
|
2022-02-25 20:12:44 +08:00
|
|
|
var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
|
|
|
|
console.log((folder ? folder.subFolders : FolderUserStore.folderList).sort(collator.compare));
|
2021-12-08 18:06:42 +08:00
|
|
|
*/
|
2022-02-25 20:12:44 +08:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
FolderUserStore.folderListError(
|
|
|
|
getNotification(error.code, '', Notification.CantCreateFolder)
|
|
|
|
+ '.\n' + error.message);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-03-04 16:21:24 +08:00
|
|
|
this.close();
|
2022-02-25 20:12:44 +08:00
|
|
|
}
|
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() {
|
2023-01-30 21:26:42 +08:00
|
|
|
this.name('');
|
|
|
|
this.subscribe(true);
|
|
|
|
this.parentFolder('');
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
}
|