snappymail/dev/View/Popup/FolderCreate.js

112 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-06-30 08:02:45 +08:00
var
_ = require('_'),
ko = require('ko'),
2016-06-30 08:02:45 +08:00
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
FolderStore = require('Stores/User/Folder'),
2014-08-25 15:10:51 +08:00
2016-06-30 08:02:45 +08:00
Promises = require('Promises/User/Ajax'),
2016-06-30 08:02:45 +08:00
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
2015-02-22 06:00:51 +08:00
2016-06-30 08:02:45 +08:00
/**
* @constructor
* @extends AbstractView
*/
function FolderCreateView()
{
AbstractView.call(this, 'Popups', 'PopupsFolderCreate');
2016-06-30 08:02:45 +08:00
this.folderName = ko.observable('');
this.folderName.focused = ko.observable(false);
2014-04-27 05:53:37 +08:00
2016-06-30 08:02:45 +08:00
this.selectedParentValue = ko.observable(Consts.UNUSED_OPTION_VALUE);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.parentFolderSelectList = ko.computed(function() {
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
var
aTop = [],
fDisableCallback = null,
fVisibleCallback = null,
aList = FolderStore.folderList(),
fRenameCallback = function(oItem) {
return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
aTop.push(['', '']);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
if ('' !== FolderStore.namespace)
{
fDisableCallback = function(oItem)
{
2016-06-30 08:02:45 +08:00
return FolderStore.namespace !== oItem.fullNameRaw.substr(0, FolderStore.namespace.length);
};
}
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
return Utils.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
}, this);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
// commands
this.createFolder = Utils.createCommand(this, function() {
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
var
sParentFolderName = this.selectedParentValue();
2014-08-25 15:10:51 +08:00
2016-06-30 08:02:45 +08:00
if ('' === sParentFolderName && 1 < FolderStore.namespace.length)
{
sParentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
}
2016-06-30 08:02:45 +08:00
require('App/User').default.foldersPromisesActionHelper(
Promises.folderCreate(this.folderName(), sParentFolderName, FolderStore.foldersCreating),
Enums.Notification.CantCreateFolder
);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.cancelCommand();
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
}, function() {
return this.simpleFolderNameValidation(this.folderName());
});
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
kn.constructorEnd(this);
}
2016-06-30 08:02:45 +08:00
kn.extendAsViewModel(['View/Popup/FolderCreate', 'PopupsFolderCreateViewModel'], FolderCreateView);
_.extend(FolderCreateView.prototype, AbstractView.prototype);
2016-06-30 08:02:45 +08:00
FolderCreateView.prototype.simpleFolderNameValidation = function(sName)
{
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
};
2016-06-30 08:02:45 +08:00
FolderCreateView.prototype.clearPopup = function()
{
this.folderName('');
this.selectedParentValue('');
this.folderName.focused(false);
};
2016-06-30 08:02:45 +08:00
FolderCreateView.prototype.onShow = function()
{
this.clearPopup();
};
2016-06-30 08:02:45 +08:00
FolderCreateView.prototype.onShowWithDelay = function()
{
if (!Globals.bMobile)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
this.folderName.focused(true);
}
};
2013-12-29 04:42:07 +08:00
2016-06-30 08:02:45 +08:00
module.exports = FolderCreateView;