snappymail/dev/Settings/Admin/Packages.js

113 lines
2.6 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('_'),
2014-08-25 23:49:01 +08:00
ko = require('ko'),
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
Enums = require('Common/Enums'),
Translator = require('Common/Translator'),
2014-08-21 23:08:34 +08:00
PackageStore = require('Stores/Admin/Package'),
Remote = require('Storage/Admin/Remote')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
function PackagesAdminSettings()
2014-08-21 23:08:34 +08:00
{
this.packagesError = ko.observable('');
2015-02-03 07:58:58 +08:00
this.packages = PackageStore.packages;
this.packagesReal = PackageStore.packagesReal;
this.packagesMainUpdatable = PackageStore.packagesMainUpdatable;
2014-08-21 23:08:34 +08:00
this.packagesCurrent = this.packages.filter(function (oItem) {
return oItem && '' !== oItem['installed'] && !oItem['compare'];
});
this.packagesAvailableForUpdate = this.packages.filter(function (oItem) {
return oItem && '' !== oItem['installed'] && !!oItem['compare'];
});
this.packagesAvailableForInstallation = this.packages.filter(function (oItem) {
return oItem && '' === oItem['installed'];
});
this.visibility = ko.computed(function () {
2015-02-03 07:58:58 +08:00
return PackageStore.packages.loading() ? 'visible' : 'hidden';
2014-08-21 23:08:34 +08:00
}, this);
}
PackagesAdminSettings.prototype.onShow = function ()
2014-08-21 23:08:34 +08:00
{
this.packagesError('');
};
PackagesAdminSettings.prototype.onBuild = function ()
2014-08-21 23:08:34 +08:00
{
require('App/Admin').reloadPackagesList();
2014-08-21 23:08:34 +08:00
};
PackagesAdminSettings.prototype.requestHelper = function (oPackage, bInstall)
2014-08-21 23:08:34 +08:00
{
var self = this;
return function (sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
if (oData && oData.ErrorCode)
{
self.packagesError(Translator.getNotification(oData.ErrorCode));
2014-08-21 23:08:34 +08:00
}
else
{
self.packagesError(Translator.getNotification(
2014-08-21 23:08:34 +08:00
bInstall ? Enums.Notification.CantInstallPackage : Enums.Notification.CantDeletePackage));
}
}
_.each(self.packages(), function (oItem) {
2014-08-21 23:08:34 +08:00
if (oItem && oPackage && oItem['loading']() && oPackage['file'] === oItem['file'])
{
oPackage['loading'](false);
oItem['loading'](false);
}
});
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result['Reload'])
{
window.location.reload();
}
else
{
require('App/Admin').reloadPackagesList();
2014-08-21 23:08:34 +08:00
}
};
};
PackagesAdminSettings.prototype.deletePackage = function (oPackage)
2014-08-21 23:08:34 +08:00
{
if (oPackage)
{
oPackage['loading'](true);
Remote.packageDelete(this.requestHelper(oPackage, false), oPackage);
}
};
PackagesAdminSettings.prototype.installPackage = function (oPackage)
2014-08-21 23:08:34 +08:00
{
if (oPackage)
{
oPackage['loading'](true);
Remote.packageInstall(this.requestHelper(oPackage, true), oPackage);
}
};
module.exports = PackagesAdminSettings;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());