2013-11-16 06:21:12 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends KnoinAbstractViewModel
|
|
|
|
*/
|
|
|
|
function PopupsFolderCreateViewModel()
|
|
|
|
{
|
|
|
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderCreate');
|
|
|
|
|
|
|
|
Utils.initOnStartOrLangChange(function () {
|
|
|
|
this.sNoParentText = Utils.i18n('POPUPS_CREATE_FOLDER/SELECT_NO_PARENT');
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.folderName = ko.observable('');
|
2013-12-29 04:42:07 +08:00
|
|
|
this.folderName.focused = ko.observable(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
|
|
|
this.selectedParentValue = ko.observable(Consts.Values.UnuseOptionValue);
|
|
|
|
|
|
|
|
this.parentFolderSelectList = ko.computed(function () {
|
|
|
|
|
|
|
|
var
|
|
|
|
oData = RL.data(),
|
|
|
|
aTop = [],
|
|
|
|
fDisableCallback = null,
|
|
|
|
fVisibleCallback = null,
|
|
|
|
aList = oData.folderList(),
|
|
|
|
fRenameCallback = function (oItem) {
|
|
|
|
return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
aTop.push(['', this.sNoParentText]);
|
|
|
|
|
|
|
|
if ('' !== oData.namespace)
|
|
|
|
{
|
|
|
|
fDisableCallback = function (oItem)
|
|
|
|
{
|
|
|
|
return oData.namespace !== oItem.fullNameRaw.substr(0, oData.namespace.length);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return RL.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
|
|
|
|
|
|
|
|
}, this);
|
2014-04-27 05:53:37 +08:00
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
// commands
|
|
|
|
this.createFolder = Utils.createCommand(this, function () {
|
|
|
|
|
|
|
|
var
|
|
|
|
oData = RL.data(),
|
|
|
|
sParentFolderName = this.selectedParentValue()
|
|
|
|
;
|
|
|
|
|
|
|
|
if ('' === sParentFolderName && 1 < oData.namespace.length)
|
|
|
|
{
|
|
|
|
sParentFolderName = oData.namespace.substr(0, oData.namespace.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
oData.foldersCreating(true);
|
|
|
|
RL.remote().folderCreate(function (sResult, oData) {
|
|
|
|
|
|
|
|
RL.data().foldersCreating(false);
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
|
|
|
{
|
2013-12-18 07:00:57 +08:00
|
|
|
RL.folders();
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RL.data().foldersListError(
|
|
|
|
oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) : Utils.i18n('NOTIFICATIONS/CANT_CREATE_FOLDER'));
|
|
|
|
}
|
|
|
|
|
|
|
|
}, this.folderName(), sParentFolderName);
|
|
|
|
|
|
|
|
this.cancelCommand();
|
|
|
|
|
|
|
|
}, function () {
|
|
|
|
return this.simpleFolderNameValidation(this.folderName());
|
|
|
|
});
|
|
|
|
|
|
|
|
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
2013-12-09 23:16:58 +08:00
|
|
|
|
|
|
|
Knoin.constructorEnd(this);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Utils.extendAsViewModel('PopupsFolderCreateViewModel', PopupsFolderCreateViewModel);
|
|
|
|
|
|
|
|
PopupsFolderCreateViewModel.prototype.sNoParentText = '';
|
|
|
|
|
|
|
|
PopupsFolderCreateViewModel.prototype.simpleFolderNameValidation = function (sName)
|
|
|
|
{
|
|
|
|
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
|
|
|
|
};
|
|
|
|
|
|
|
|
PopupsFolderCreateViewModel.prototype.clearPopup = function ()
|
|
|
|
{
|
|
|
|
this.folderName('');
|
|
|
|
this.selectedParentValue('');
|
2013-12-29 04:42:07 +08:00
|
|
|
this.folderName.focused(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
PopupsFolderCreateViewModel.prototype.onShow = function ()
|
|
|
|
{
|
|
|
|
this.clearPopup();
|
2013-12-29 04:42:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
PopupsFolderCreateViewModel.prototype.onFocus = function ()
|
|
|
|
{
|
|
|
|
this.folderName.focused(true);
|
2013-11-16 06:21:12 +08:00
|
|
|
};
|