2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import {Notification} from 'Common/Enums';
|
|
|
|
import {UNUSED_OPTION_VALUE} from 'Common/Consts';
|
|
|
|
import {bMobileDevice} from 'Common/Globals';
|
|
|
|
import {trim, createCommand, defautOptionsAfterRender, folderListOptionsBuilder} from 'Common/Utils';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import FolderStore from 'Stores/User/Folder';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import Promises from 'Promises/User/Ajax';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import {getApp} from 'Helper/Apps/User';
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import {view, ViewType} from 'Knoin/Knoin';
|
|
|
|
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
|
|
|
|
|
|
|
@view({
|
|
|
|
name: 'View/Popup/FolderCreate',
|
|
|
|
type: ViewType.Popup,
|
|
|
|
templateID: 'PopupsFolderCreate'
|
|
|
|
})
|
|
|
|
class FolderCreateView extends AbstractViewNext
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
|
|
|
super();
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.folderName = ko.observable('');
|
|
|
|
this.folderName.focused = ko.observable(false);
|
2014-04-27 05:53:37 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.selectedParentValue = ko.observable(UNUSED_OPTION_VALUE);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.parentFolderSelectList = ko.computed(() => {
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
const
|
|
|
|
top = [],
|
|
|
|
list = FolderStore.folderList(),
|
|
|
|
fRenameCallback = (oItem) => (oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
top.push(['', '']);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
let fDisableCallback = null;
|
|
|
|
if ('' !== FolderStore.namespace)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
fDisableCallback = (item) => FolderStore.namespace !== item.fullNameRaw.substr(0, FolderStore.namespace.length);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
return folderListOptionsBuilder([], list, [], top, null, fDisableCallback, null, fRenameCallback);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
// commands
|
|
|
|
this.createFolder = createCommand(() => {
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
let parentFolderName = this.selectedParentValue();
|
|
|
|
if ('' === parentFolderName && 1 < FolderStore.namespace.length)
|
|
|
|
{
|
|
|
|
parentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
getApp().foldersPromisesActionHelper(
|
|
|
|
Promises.folderCreate(this.folderName(), parentFolderName, FolderStore.foldersCreating),
|
|
|
|
Notification.CantCreateFolder
|
|
|
|
);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.cancelCommand();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
}, () => this.simpleFolderNameValidation(this.folderName()));
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.defautOptionsAfterRender = defautOptionsAfterRender;
|
|
|
|
}
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
simpleFolderNameValidation(sName) {
|
|
|
|
return (/^[^\\\/]+$/g).test(trim(sName));
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
clearPopup() {
|
|
|
|
this.folderName('');
|
|
|
|
this.selectedParentValue('');
|
|
|
|
this.folderName.focused(false);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShow() {
|
|
|
|
this.clearPopup();
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShowWithDelay() {
|
|
|
|
if (!bMobileDevice)
|
|
|
|
{
|
|
|
|
this.folderName.focused(true);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-12-29 04:42:07 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
module.exports = FolderCreateView;
|