mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-15 12:15:20 +08:00
111 lines
2.6 KiB
JavaScript
111 lines
2.6 KiB
JavaScript
|
|
var
|
|
_ = require('_'),
|
|
ko = require('ko'),
|
|
|
|
Enums = require('Common/Enums'),
|
|
Consts = require('Common/Consts'),
|
|
Globals = require('Common/Globals'),
|
|
Utils = require('Common/Utils'),
|
|
|
|
FolderStore = require('Stores/User/Folder'),
|
|
|
|
Promises = require('Promises/User/Ajax'),
|
|
|
|
kn = require('Knoin/Knoin'),
|
|
AbstractView = require('Knoin/AbstractView');
|
|
|
|
/**
|
|
* @constructor
|
|
* @extends AbstractView
|
|
*/
|
|
function FolderCreateView()
|
|
{
|
|
AbstractView.call(this, 'Popups', 'PopupsFolderCreate');
|
|
|
|
this.folderName = ko.observable('');
|
|
this.folderName.focused = ko.observable(false);
|
|
|
|
this.selectedParentValue = ko.observable(Consts.UNUSED_OPTION_VALUE);
|
|
|
|
this.parentFolderSelectList = ko.computed(function() {
|
|
|
|
var
|
|
aTop = [],
|
|
fDisableCallback = null,
|
|
fVisibleCallback = null,
|
|
aList = FolderStore.folderList(),
|
|
fRenameCallback = function(oItem) {
|
|
return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
|
|
};
|
|
|
|
aTop.push(['', '']);
|
|
|
|
if ('' !== FolderStore.namespace)
|
|
{
|
|
fDisableCallback = function(oItem)
|
|
{
|
|
return FolderStore.namespace !== oItem.fullNameRaw.substr(0, FolderStore.namespace.length);
|
|
};
|
|
}
|
|
|
|
return Utils.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
|
|
|
|
}, this);
|
|
|
|
// commands
|
|
this.createFolder = Utils.createCommand(this, function() {
|
|
|
|
var
|
|
sParentFolderName = this.selectedParentValue();
|
|
|
|
if ('' === sParentFolderName && 1 < FolderStore.namespace.length)
|
|
{
|
|
sParentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
|
|
}
|
|
|
|
require('App/User').default.foldersPromisesActionHelper(
|
|
Promises.folderCreate(this.folderName(), sParentFolderName, FolderStore.foldersCreating),
|
|
Enums.Notification.CantCreateFolder
|
|
);
|
|
|
|
this.cancelCommand();
|
|
|
|
}, function() {
|
|
return this.simpleFolderNameValidation(this.folderName());
|
|
});
|
|
|
|
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
|
|
|
kn.constructorEnd(this);
|
|
}
|
|
|
|
kn.extendAsViewModel(['View/Popup/FolderCreate', 'PopupsFolderCreateViewModel'], FolderCreateView);
|
|
_.extend(FolderCreateView.prototype, AbstractView.prototype);
|
|
|
|
FolderCreateView.prototype.simpleFolderNameValidation = function(sName)
|
|
{
|
|
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
|
|
};
|
|
|
|
FolderCreateView.prototype.clearPopup = function()
|
|
{
|
|
this.folderName('');
|
|
this.selectedParentValue('');
|
|
this.folderName.focused(false);
|
|
};
|
|
|
|
FolderCreateView.prototype.onShow = function()
|
|
{
|
|
this.clearPopup();
|
|
};
|
|
|
|
FolderCreateView.prototype.onShowWithDelay = function()
|
|
{
|
|
if (!Globals.bMobile)
|
|
{
|
|
this.folderName.focused(true);
|
|
}
|
|
};
|
|
|
|
module.exports = FolderCreateView;
|