(function () { 'use strict'; var window = require('window'), ko = require('ko'), Enums = require('Common/Enums'), Translator = require('Common/Translator'), Data = require('Storage/Admin/Data'), Remote = require('Storage/Admin/Remote') ; /** * @constructor */ function PackagesAdminSettings() { this.packagesError = ko.observable(''); this.packages = Data.packages; this.packagesReal = Data.packagesReal; this.packagesMainUpdatable = Data.packagesMainUpdatable; 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 () { return Data.packages.loading() ? 'visible' : 'hidden'; }, this); } PackagesAdminSettings.prototype.onShow = function () { this.packagesError(''); }; PackagesAdminSettings.prototype.onBuild = function () { require('App/Admin').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) { self.packagesError(Translator.getNotification(oData.ErrorCode)); } else { self.packagesError(Translator.getNotification( bInstall ? Enums.Notification.CantInstallPackage : Enums.Notification.CantDeletePackage)); } } _.each(Data.packages(), function (oItem) { 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(); } }; }; 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); } }; module.exports = PackagesAdminSettings; }());