2014-08-21 23:08:34 +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-08-25 23:49:01 +08:00
|
|
|
window = require('window'),
|
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Enums = require('Common/Enums'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
PopupsDomainViewModel = require('View/Popup/Domain'),
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
DomainStore = require('Stores/Admin/Domain'),
|
2014-09-06 05:44:29 +08:00
|
|
|
Remote = require('Storage/Admin/Remote')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-10-30 21:59:25 +08:00
|
|
|
function DomainsAdminSettings()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-01-27 05:06:00 +08:00
|
|
|
this.domains = DomainStore.collection;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
this.iDomainForDeletionTimeout = 0;
|
|
|
|
|
|
|
|
this.visibility = ko.computed(function () {
|
2015-01-27 05:06:00 +08:00
|
|
|
return this.domains.loading() ? 'visible' : 'hidden';
|
2014-08-21 23:08:34 +08:00
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.domainForDeletion = ko.observable(null).extend({'toggleSubscribe': [this,
|
|
|
|
function (oPrev) {
|
|
|
|
if (oPrev)
|
|
|
|
{
|
|
|
|
oPrev.deleteAccess(false);
|
|
|
|
}
|
|
|
|
}, function (oNext) {
|
|
|
|
if (oNext)
|
|
|
|
{
|
|
|
|
oNext.deleteAccess(true);
|
|
|
|
this.startDomainForDeletionTimeout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]});
|
|
|
|
}
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
DomainsAdminSettings.prototype.startDomainForDeletionTimeout = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
window.clearInterval(this.iDomainForDeletionTimeout);
|
|
|
|
this.iDomainForDeletionTimeout = window.setTimeout(function () {
|
|
|
|
self.domainForDeletion(null);
|
|
|
|
}, 1000 * 3);
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
DomainsAdminSettings.prototype.createDomain = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(PopupsDomainViewModel);
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
DomainsAdminSettings.prototype.deleteDomain = function (oDomain)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.domains.remove(oDomain);
|
|
|
|
Remote.domainDelete(_.bind(this.onDomainListChangeRequest, this), oDomain.name);
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
DomainsAdminSettings.prototype.disableDomain = function (oDomain)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
oDomain.disabled(!oDomain.disabled());
|
|
|
|
Remote.domainDisable(_.bind(this.onDomainListChangeRequest, this), oDomain.name, oDomain.disabled());
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
DomainsAdminSettings.prototype.onBuild = function (oDom)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
oDom
|
|
|
|
.on('click', '.b-admin-domains-list-table .e-item .e-action', function () {
|
|
|
|
var oDomainItem = ko.dataFor(this);
|
|
|
|
if (oDomainItem)
|
|
|
|
{
|
|
|
|
Remote.domain(_.bind(self.onDomainLoadRequest, self), oDomainItem.name);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
;
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
require('App/Admin').reloadDomainList();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
DomainsAdminSettings.prototype.onDomainLoadRequest = function (sResult, oData)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(PopupsDomainViewModel, [oData.Result]);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
DomainsAdminSettings.prototype.onDomainListChangeRequest = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
require('App/Admin').reloadDomainList();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
module.exports = DomainsAdminSettings;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|