snappymail/dev/Settings/Admin/Domains.js

105 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
(function () {
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
PopupsDomainViewModel = require('View/Popup/Domain'),
2014-08-22 23:08:56 +08:00
DomainStore = require('Stores/Admin/Domain'),
Remote = require('Storage/Admin/Remote')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
function DomainsAdminSettings()
2014-08-21 23:08:34 +08:00
{
this.domains = DomainStore.collection;
2014-08-21 23:08:34 +08:00
this.iDomainForDeletionTimeout = 0;
this.visibility = ko.computed(function () {
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();
}
}
]});
}
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);
};
DomainsAdminSettings.prototype.createDomain = function ()
2014-08-21 23:08:34 +08:00
{
require('Knoin/Knoin').showScreenPopup(PopupsDomainViewModel);
2014-08-21 23:08:34 +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);
};
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());
};
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);
}
})
;
require('App/Admin').reloadDomainList();
2014-08-21 23:08:34 +08:00
};
DomainsAdminSettings.prototype.onDomainLoadRequest = function (sResult, oData)
2014-08-21 23:08:34 +08:00
{
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
require('Knoin/Knoin').showScreenPopup(PopupsDomainViewModel, [oData.Result]);
2014-08-21 23:08:34 +08:00
}
};
DomainsAdminSettings.prototype.onDomainListChangeRequest = function ()
2014-08-21 23:08:34 +08:00
{
require('App/Admin').reloadDomainList();
2014-08-21 23:08:34 +08:00
};
module.exports = DomainsAdminSettings;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());