2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
'use strict';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
var
|
2014-09-02 08:15:31 +08:00
|
|
|
_ = require('_'),
|
2014-08-25 23:49:01 +08:00
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Enums = require('Common/Enums'),
|
|
|
|
Consts = require('Common/Consts'),
|
2015-02-17 21:16:38 +08:00
|
|
|
Globals = require('Common/Globals'),
|
2014-09-05 06:49:03 +08:00
|
|
|
Utils = require('Common/Utils'),
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator = require('Common/Translator'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-22 06:00:51 +08:00
|
|
|
FolderStore = require('Stores/User/Folder'),
|
|
|
|
|
2015-03-17 22:12:19 +08:00
|
|
|
Promises = require('Promises/User/Ajax'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
|
|
|
AbstractView = require('Knoin/AbstractView')
|
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
|
2014-09-06 05:44:29 +08:00
|
|
|
* @extends AbstractView
|
2014-08-21 23:08:34 +08:00
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
function FolderCreateView()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.call(this, 'Popups', 'PopupsFolderCreate');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator.initOnStartOrLangChange(function () {
|
|
|
|
this.sNoParentText = Translator.i18n('POPUPS_CREATE_FOLDER/SELECT_NO_PARENT');
|
2014-08-21 23:08:34 +08:00
|
|
|
}, 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,
|
2015-02-22 06:00:51 +08:00
|
|
|
aList = FolderStore.folderList(),
|
2014-08-21 23:08:34 +08:00
|
|
|
fRenameCallback = function (oItem) {
|
|
|
|
return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
aTop.push(['', this.sNoParentText]);
|
|
|
|
|
2015-02-22 06:00:51 +08:00
|
|
|
if ('' !== FolderStore.namespace)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
fDisableCallback = function (oItem)
|
|
|
|
{
|
2015-02-22 06:00:51 +08:00
|
|
|
return FolderStore.namespace !== oItem.fullNameRaw.substr(0, FolderStore.namespace.length);
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
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
|
|
|
|
sParentFolderName = this.selectedParentValue()
|
|
|
|
;
|
|
|
|
|
2015-02-22 06:00:51 +08:00
|
|
|
if ('' === sParentFolderName && 1 < FolderStore.namespace.length)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2015-02-22 06:00:51 +08:00
|
|
|
sParentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2015-03-17 22:12:19 +08:00
|
|
|
require('App/User').foldersPromisesActionHelper(
|
|
|
|
Promises.folderCreate(this.folderName(), sParentFolderName, FolderStore.foldersCreating),
|
|
|
|
Enums.Notification.CantCreateFolder);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
this.cancelCommand();
|
|
|
|
|
|
|
|
}, function () {
|
|
|
|
return this.simpleFolderNameValidation(this.folderName());
|
|
|
|
});
|
|
|
|
|
|
|
|
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
|
|
|
|
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn.extendAsViewModel(['View/Popup/FolderCreate', 'PopupsFolderCreateViewModel'], FolderCreateView);
|
|
|
|
_.extend(FolderCreateView.prototype, AbstractView.prototype);
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
FolderCreateView.prototype.sNoParentText = '';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
FolderCreateView.prototype.simpleFolderNameValidation = function (sName)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
FolderCreateView.prototype.clearPopup = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.folderName('');
|
|
|
|
this.selectedParentValue('');
|
|
|
|
this.folderName.focused(false);
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
FolderCreateView.prototype.onShow = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.clearPopup();
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-16 05:55:59 +08:00
|
|
|
FolderCreateView.prototype.onShowWithDelay = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-02-17 21:16:38 +08:00
|
|
|
if (!Globals.bMobile)
|
|
|
|
{
|
|
|
|
this.folderName.focused(true);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
module.exports = FolderCreateView;
|
2013-12-29 04:42:07 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|