snappymail/dev/Settings/Admin/AdminSettingsDomains.js

107 lines
2.5 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +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
window = require('window'),
_ = require('_'),
ko = require('ko'),
2014-08-21 23:08:34 +08:00
2014-08-25 23:49:01 +08:00
Enums = require('Enums'),
2014-08-21 23:08:34 +08:00
2014-08-27 23:59:44 +08:00
PopupsDomainViewModel = require('View:Popup:Domain'),
2014-08-22 23:08:56 +08:00
2014-08-27 23:59:44 +08:00
Data = require('Storage:Admin:Data'),
Remote = require('Storage:Admin:Remote')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
function AdminSettingsDomains()
{
this.domains = Data.domains;
this.domainsLoading = Data.domainsLoading;
this.iDomainForDeletionTimeout = 0;
this.visibility = ko.computed(function () {
return Data.domainsLoading() ? 'visible' : 'hidden';
}, 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();
}
}
]});
}
AdminSettingsDomains.prototype.startDomainForDeletionTimeout = function ()
{
var self = this;
window.clearInterval(this.iDomainForDeletionTimeout);
this.iDomainForDeletionTimeout = window.setTimeout(function () {
self.domainForDeletion(null);
}, 1000 * 3);
};
AdminSettingsDomains.prototype.createDomain = function ()
{
2014-08-27 23:59:44 +08:00
require('App:Knoin').showScreenPopup(PopupsDomainViewModel);
2014-08-21 23:08:34 +08:00
};
AdminSettingsDomains.prototype.deleteDomain = function (oDomain)
{
this.domains.remove(oDomain);
Remote.domainDelete(_.bind(this.onDomainListChangeRequest, this), oDomain.name);
};
AdminSettingsDomains.prototype.disableDomain = function (oDomain)
{
oDomain.disabled(!oDomain.disabled());
Remote.domainDisable(_.bind(this.onDomainListChangeRequest, this), oDomain.name, oDomain.disabled());
};
AdminSettingsDomains.prototype.onBuild = function (oDom)
{
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-08-27 23:59:44 +08:00
require('App:Admin').reloadDomainList();
2014-08-21 23:08:34 +08:00
};
AdminSettingsDomains.prototype.onDomainLoadRequest = function (sResult, oData)
{
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
2014-08-27 23:59:44 +08:00
require('App:Knoin').showScreenPopup(PopupsDomainViewModel, [oData.Result]);
2014-08-21 23:08:34 +08:00
}
};
AdminSettingsDomains.prototype.onDomainListChangeRequest = function ()
{
2014-08-27 23:59:44 +08:00
require('App:Admin').reloadDomainList();
2014-08-21 23:08:34 +08:00
};
module.exports = AdminSettingsDomains;
2014-08-25 23:49:01 +08:00
}(module, require));