mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-10 06:58:27 +03:00
CommonJS (research/2)
This commit is contained in:
parent
56607de87c
commit
586abbb802
115 changed files with 16201 additions and 9943 deletions
|
|
@ -1,111 +1,128 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsFolderCreateViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderCreate');
|
||||
(function (module) {
|
||||
|
||||
Utils.initOnStartOrLangChange(function () {
|
||||
this.sNoParentText = Utils.i18n('POPUPS_CREATE_FOLDER/SELECT_NO_PARENT');
|
||||
}, this);
|
||||
'use strict';
|
||||
|
||||
this.folderName = ko.observable('');
|
||||
this.folderName.focused = ko.observable(false);
|
||||
|
||||
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]);
|
||||
var
|
||||
ko = require('../../External/ko.js'),
|
||||
|
||||
if ('' !== oData.namespace)
|
||||
{
|
||||
fDisableCallback = function (oItem)
|
||||
Enums = require('../../Common/Enums.js'),
|
||||
Consts = require('../../Common/Consts.js'),
|
||||
Utils = require('../../Common/Utils.js'),
|
||||
|
||||
Data = require('../../Storages/WebMailDataStorage.js'),
|
||||
Remote = require('../../Storages/WebMailAjaxRemoteStorage.js'),
|
||||
|
||||
kn = require('../../Knoin/Knoin.js'),
|
||||
KnoinAbstractViewModel = require('../../Knoin/KnoinAbstractViewModel.js')
|
||||
;
|
||||
|
||||
/**
|
||||
* @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('');
|
||||
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)
|
||||
{
|
||||
return oData.namespace !== oItem.fullNameRaw.substr(0, oData.namespace.length);
|
||||
};
|
||||
}
|
||||
|
||||
return RL.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
|
||||
|
||||
}, this);
|
||||
|
||||
// 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)
|
||||
{
|
||||
RL.folders();
|
||||
fDisableCallback = function (oItem)
|
||||
{
|
||||
return Data.namespace !== oItem.fullNameRaw.substr(0, Data.namespace.length);
|
||||
};
|
||||
}
|
||||
else
|
||||
|
||||
return RL.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
|
||||
|
||||
}, this);
|
||||
|
||||
// commands
|
||||
this.createFolder = Utils.createCommand(this, function () {
|
||||
|
||||
var sParentFolderName = this.selectedParentValue();
|
||||
if ('' === sParentFolderName && 1 < Data.namespace.length)
|
||||
{
|
||||
RL.data().foldersListError(
|
||||
oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) : Utils.i18n('NOTIFICATIONS/CANT_CREATE_FOLDER'));
|
||||
sParentFolderName = Data.namespace.substr(0, Data.namespace.length - 1);
|
||||
}
|
||||
|
||||
}, this.folderName(), sParentFolderName);
|
||||
|
||||
this.cancelCommand();
|
||||
|
||||
}, function () {
|
||||
return this.simpleFolderNameValidation(this.folderName());
|
||||
});
|
||||
Data.foldersCreating(true);
|
||||
Remote.folderCreate(function (sResult, oData) {
|
||||
|
||||
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
||||
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'));
|
||||
}
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
}, this.folderName(), sParentFolderName);
|
||||
|
||||
Utils.extendAsViewModel('PopupsFolderCreateViewModel', PopupsFolderCreateViewModel);
|
||||
this.cancelCommand();
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.sNoParentText = '';
|
||||
}, function () {
|
||||
return this.simpleFolderNameValidation(this.folderName());
|
||||
});
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.simpleFolderNameValidation = function (sName)
|
||||
{
|
||||
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
|
||||
};
|
||||
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.folderName('');
|
||||
this.selectedParentValue('');
|
||||
this.folderName.focused(false);
|
||||
};
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
kn.extendAsViewModel('PopupsFolderCreateViewModel', PopupsFolderCreateViewModel);
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.folderName.focused(true);
|
||||
};
|
||||
PopupsFolderCreateViewModel.prototype.sNoParentText = '';
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.simpleFolderNameValidation = function (sName)
|
||||
{
|
||||
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
|
||||
};
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.folderName('');
|
||||
this.selectedParentValue('');
|
||||
this.folderName.focused(false);
|
||||
};
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.folderName.focused(true);
|
||||
};
|
||||
|
||||
module.exports = new PopupsFolderCreateViewModel();
|
||||
|
||||
}(module));
|
||||
Loading…
Add table
Add a link
Reference in a new issue