snappymail/dev/Settings/Admin/Packages.jsx

107 lines
2.5 KiB
React
Raw Normal View History

2015-05-20 21:09:21 +08:00
2016-06-30 08:02:45 +08:00
var
window = require('window'),
_ = require('_'),
ko = require('ko'),
Enums = require('Common/Enums'),
Translator = require('Common/Translator'),
PackageStore = require('Stores/Admin/Package'),
Remote = require('Remote/Admin/Ajax');
/**
* @constructor
*/
function PackagesAdminSettings()
{
this.packagesError = ko.observable('');
this.packages = PackageStore.packages;
this.packagesReal = PackageStore.packagesReal;
this.packagesMainUpdatable = PackageStore.packagesMainUpdatable;
this.packagesCurrent = this.packages.filter(function(item) {
return item && '' !== item.installed && !item.compare;
});
this.packagesAvailableForUpdate = this.packages.filter(function(item) {
return item && '' !== item.installed && !!item.compare;
});
this.packagesAvailableForInstallation = this.packages.filter(function(item) {
return item && '' === item.installed;
});
this.visibility = ko.computed(function() {
return PackageStore.packages.loading() ? 'visible' : 'hidden';
}, this);
}
PackagesAdminSettings.prototype.onShow = function()
{
this.packagesError('');
};
PackagesAdminSettings.prototype.onBuild = function()
{
require('App/Admin').default.reloadPackagesList();
};
PackagesAdminSettings.prototype.requestHelper = function(oPackage, bInstall)
{
var self = this;
return function(sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
if (oData && oData.ErrorCode)
2015-05-20 21:09:21 +08:00
{
2016-06-30 08:02:45 +08:00
self.packagesError(Translator.getNotification(oData.ErrorCode));
2015-05-20 21:09:21 +08:00
}
2016-06-30 08:02:45 +08:00
else
2015-05-20 21:09:21 +08:00
{
2016-06-30 08:02:45 +08:00
self.packagesError(Translator.getNotification(
bInstall ? Enums.Notification.CantInstallPackage : Enums.Notification.CantDeletePackage));
2015-05-20 21:09:21 +08:00
}
2016-06-30 08:02:45 +08:00
}
_.each(self.packages(), function(item) {
if (item && oPackage && item.loading && item.loading() && oPackage.file === item.file)
2015-05-20 21:09:21 +08:00
{
2016-06-30 08:02:45 +08:00
oPackage.loading(false);
item.loading(false);
2015-05-20 21:09:21 +08:00
}
2016-06-30 08:02:45 +08:00
});
2015-05-20 21:09:21 +08:00
2016-06-30 08:02:45 +08:00
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.Reload)
2015-05-20 21:09:21 +08:00
{
2016-06-30 08:02:45 +08:00
window.location.reload();
2015-05-20 21:09:21 +08:00
}
2016-06-30 08:02:45 +08:00
else
2015-05-20 21:09:21 +08:00
{
2016-06-30 08:02:45 +08:00
require('App/Admin').default.reloadPackagesList();
2015-05-20 21:09:21 +08:00
}
};
2016-06-30 08:02:45 +08:00
};
2015-05-20 21:09:21 +08:00
2016-06-30 08:02:45 +08:00
PackagesAdminSettings.prototype.deletePackage = function(oPackage)
{
if (oPackage)
{
oPackage.loading(true);
Remote.packageDelete(this.requestHelper(oPackage, false), oPackage);
}
};
PackagesAdminSettings.prototype.installPackage = function(oPackage)
{
if (oPackage)
{
oPackage.loading(true);
Remote.packageInstall(this.requestHelper(oPackage, true), oPackage);
}
};
2015-05-20 21:09:21 +08:00
2016-07-16 03:54:37 +08:00
export {PackagesAdminSettings, PackagesAdminSettings as default};