2013-11-16 06:21:12 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
(function (module, require) {
|
|
|
|
|
|
|
|
'use strict';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
var
|
2014-08-25 23:49:01 +08:00
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
Enums = require('Enums'),
|
|
|
|
Consts = require('Consts'),
|
|
|
|
Utils = require('Utils'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
Data = require('../../Storages/WebMailDataStorage.js'),
|
|
|
|
Remote = require('../../Storages/WebMailAjaxRemoteStorage.js'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
kn = require('kn'),
|
|
|
|
KnoinAbstractViewModel = require('KnoinAbstractViewModel')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
2014-04-27 05:53:37 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends KnoinAbstractViewModel
|
|
|
|
*/
|
|
|
|
function PopupsFolderCreateViewModel()
|
|
|
|
{
|
|
|
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderCreate');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
Utils.initOnStartOrLangChange(function () {
|
|
|
|
this.sNoParentText = Utils.i18n('POPUPS_CREATE_FOLDER/SELECT_NO_PARENT');
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.folderName = ko.observable('');
|
|
|
|
this.folderName.focused = ko.observable(false);
|
|
|
|
|
|
|
|
this.selectedParentValue = ko.observable(Consts.Values.UnuseOptionValue);
|
|
|
|
|
|
|
|
this.parentFolderSelectList = ko.computed(function () {
|
|
|
|
|
|
|
|
var
|
|
|
|
aTop = [],
|
|
|
|
fDisableCallback = null,
|
|
|
|
fVisibleCallback = null,
|
|
|
|
aList = Data.folderList(),
|
|
|
|
fRenameCallback = function (oItem) {
|
|
|
|
return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
aTop.push(['', this.sNoParentText]);
|
|
|
|
|
|
|
|
if ('' !== Data.namespace)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
fDisableCallback = function (oItem)
|
|
|
|
{
|
|
|
|
return Data.namespace !== oItem.fullNameRaw.substr(0, Data.namespace.length);
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
return Utils.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
// commands
|
|
|
|
this.createFolder = Utils.createCommand(this, function () {
|
|
|
|
|
2014-08-25 15:10:51 +08:00
|
|
|
var
|
|
|
|
RL = require('../../Boots/RainLoopApp.js'),
|
|
|
|
sParentFolderName = this.selectedParentValue()
|
|
|
|
;
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
if ('' === sParentFolderName && 1 < Data.namespace.length)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
sParentFolderName = Data.namespace.substr(0, Data.namespace.length - 1);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
Data.foldersCreating(true);
|
|
|
|
Remote.folderCreate(function (sResult, oData) {
|
|
|
|
|
|
|
|
Data.foldersCreating(false);
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
|
|
|
{
|
|
|
|
RL.folders();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
kn.extendAsViewModel('PopupsFolderCreateViewModel', PopupsFolderCreateViewModel);
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsFolderCreateViewModel.prototype.sNoParentText = '';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsFolderCreateViewModel.prototype.simpleFolderNameValidation = function (sName)
|
|
|
|
{
|
|
|
|
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsFolderCreateViewModel.prototype.clearPopup = function ()
|
|
|
|
{
|
|
|
|
this.folderName('');
|
|
|
|
this.selectedParentValue('');
|
|
|
|
this.folderName.focused(false);
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsFolderCreateViewModel.prototype.onShow = function ()
|
|
|
|
{
|
|
|
|
this.clearPopup();
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsFolderCreateViewModel.prototype.onFocus = function ()
|
|
|
|
{
|
|
|
|
this.folderName.focused(true);
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
module.exports = PopupsFolderCreateViewModel;
|
2013-12-29 04:42:07 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
}(module, require));
|