2015-05-20 21:09:21 +08:00
|
|
|
|
|
|
|
(function () {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-06-28 04:54:38 +08:00
|
|
|
this.packagesCurrent = this.packages.filter(function (item) {
|
|
|
|
return item && '' !== item.installed && !item.compare;
|
2015-05-20 21:09:21 +08:00
|
|
|
});
|
|
|
|
|
2016-06-28 04:54:38 +08:00
|
|
|
this.packagesAvailableForUpdate = this.packages.filter(function (item) {
|
|
|
|
return item && '' !== item.installed && !!item.compare;
|
2015-05-20 21:09:21 +08:00
|
|
|
});
|
|
|
|
|
2016-06-28 04:54:38 +08:00
|
|
|
this.packagesAvailableForInstallation = this.packages.filter(function (item) {
|
|
|
|
return item && '' === item.installed;
|
2015-05-20 21:09:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.visibility = ko.computed(function () {
|
|
|
|
return PackageStore.packages.loading() ? 'visible' : 'hidden';
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
PackagesAdminSettings.prototype.onShow = function ()
|
|
|
|
{
|
|
|
|
this.packagesError('');
|
|
|
|
};
|
|
|
|
|
|
|
|
PackagesAdminSettings.prototype.onBuild = function ()
|
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
require('App/Admin').default.reloadPackagesList();
|
2015-05-20 21:09:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
self.packagesError(Translator.getNotification(oData.ErrorCode));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.packagesError(Translator.getNotification(
|
|
|
|
bInstall ? Enums.Notification.CantInstallPackage : Enums.Notification.CantDeletePackage));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 04:54:38 +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-28 04:54:38 +08:00
|
|
|
oPackage.loading(false);
|
|
|
|
item.loading(false);
|
2015-05-20 21:09:21 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-28 04:54:38 +08:00
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.Reload)
|
2015-05-20 21:09:21 +08:00
|
|
|
{
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
require('App/Admin').default.reloadPackagesList();
|
2015-05-20 21:09:21 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
PackagesAdminSettings.prototype.deletePackage = function (oPackage)
|
|
|
|
{
|
|
|
|
if (oPackage)
|
|
|
|
{
|
2016-06-28 04:54:38 +08:00
|
|
|
oPackage.loading(true);
|
2015-05-20 21:09:21 +08:00
|
|
|
Remote.packageDelete(this.requestHelper(oPackage, false), oPackage);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
PackagesAdminSettings.prototype.installPackage = function (oPackage)
|
|
|
|
{
|
|
|
|
if (oPackage)
|
|
|
|
{
|
2016-06-28 04:54:38 +08:00
|
|
|
oPackage.loading(true);
|
2015-05-20 21:09:21 +08:00
|
|
|
Remote.packageInstall(this.requestHelper(oPackage, true), oPackage);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = PackagesAdminSettings;
|
|
|
|
|
2016-06-28 04:54:38 +08:00
|
|
|
}());
|