}
});
-/**
- * Manages package search.
- */
-WCF.ACP.Package.Search = Class.extend({
- /**
- * search button
- * @var jQuery
- */
- _button: null,
-
- /**
- * list of cached pages
- * @var object
- */
- _cache: { },
-
- /**
- * search container
- * @var jQuery
- */
- _container: null,
-
- /**
- * dialog overlay
- * @var jQuery
- */
- _dialog: null,
-
- /**
- * package input field
- * @var jQuery
- */
- _package: null,
-
- /**
- * package description input field
- * @var jQuery
- */
- _packageDescription: null,
-
- /**
- * package name input field
- * @var jQuery
- */
- _packageName: null,
-
- /**
- * package search result container
- * @var jQuery
- */
- _packageSearchResultContainer: null,
-
- /**
- * package search result list
- * @var jQuery
- */
- _packageSearchResultList: null,
-
- /**
- * number of pages
- * @var integer
- */
- _pageCount: 0,
-
- /**
- * current page
- * @var integer
- */
- _pageNo: 1,
-
- /**
- * action proxy
- * @var WCF.Action:proxy
- */
- _proxy: null,
-
- /**
- * search id
- * @var integer
- */
- _searchID: 0,
-
- /**
- * currently selected package
- * @var string
- */
- _selectedPackage: '',
-
- /**
- * currently selected package's version
- */
- _selectedPackageVersion: '',
-
- /**
- * Initializes the WCF.ACP.Package.Search class.
- */
- init: function() {
- this._button = null;
- this._cache = { };
- this._container = $('#packageSearch');
- this._dialog = null;
- this._package = null;
- this._packageName = null;
- this._packageSearchResultContainer = $('#packageSearchResultContainer');
- this._packageSearchResultList = $('#packageSearchResultList');
- this._pageCount = 0;
- this._pageNo = 1;
- this._searchDescription = null;
- this._searchID = 0;
- this._selectedPackage = '';
- this._selectedPackageVersion = '';
-
- this._proxy = new WCF.Action.Proxy({
- success: $.proxy(this._success, this)
- });
-
- this._initElements();
- },
-
- /**
- * Initializes search elements.
- */
- _initElements: function() {
- this._button = this._container.find('.formSubmit > button.jsButtonPackageSearch').disable().click($.proxy(this._search, this));
-
- this._package = $('#package').keyup($.proxy(this._keyUp, this));
- this._packageDescription = $('#packageDescription').keyup($.proxy(this._keyUp, this));
- this._packageName = $('#packageName').keyup($.proxy(this._keyUp, this));
- },
-
- /**
- * Handles the 'keyup' event.
- */
- _keyUp: function(event) {
- if (this._package.val() === '' && this._packageDescription.val() === '' && this._packageName.val() === '') {
- this._button.disable();
- }
- else {
- this._button.enable();
-
- // submit on [Enter]
- if (event.which === 13) {
- this._button.trigger('click');
- }
- }
- },
-
- /**
- * Performs a new search.
- */
- _search: function() {
- var $values = this._getSearchValues();
- if (!this._validate($values)) {
- return false;
- }
-
- $values.pageNo = this._pageNo;
- this._proxy.setOption('data', {
- actionName: 'search',
- className: 'wcf\\data\\package\\update\\PackageUpdateAction',
- parameters: $values
- });
- this._proxy.sendRequest();
- },
-
- /**
- * Returns search values.
- *
- * @return object
- */
- _getSearchValues: function() {
- return {
- 'package': $.trim(this._package.val()),
- packageDescription: $.trim(this._packageDescription.val()),
- packageName: $.trim(this._packageName.val())
- };
- },
-
- /**
- * Validates search values.
- *
- * @param object values
- * @return boolean
- */
- _validate: function(values) {
- if (values['package'] === '' && values['packageDescription'] === '' && values['packageName'] === '') {
- return false;
- }
-
- return true;
- },
-
- /**
- * Handles successful AJAX requests.
- *
- * @param object data
- * @param string textStatus
- * @param jQuery jqXHR
- */
- _success: function(data, textStatus, jqXHR) {
- switch (data.actionName) {
- case 'getResultList':
- this._insertTemplate(data.returnValues.template);
- break;
-
- case 'prepareInstallation':
- if (data.returnValues.queueID) {
- if (this._dialog !== null) {
- this._dialog.wcfDialog('close');
- }
-
- var $installation = new WCF.ACP.Package.Installation(data.returnValues.queueID, undefined, false);
- $installation.prepareInstallation();
- }
- else if (data.returnValues.template) {
- if (this._dialog === null) {
- this._dialog = $('<div>' + data.returnValues.template + '</div>').hide().appendTo(document.body);
- this._dialog.wcfDialog({
- title: WCF.Language.get('wcf.acp.package.update.unauthorized')
- });
- }
- else {
- this._dialog.html(data.returnValues.template).wcfDialog('open');
- }
-
- this._dialog.find('.formSubmit > button').click($.proxy(this._submitAuthentication, this));
- }
- break;
-
- case 'search':
- this._pageCount = data.returnValues.pageCount;
- this._searchID = data.returnValues.searchID;
-
- this._insertTemplate(data.returnValues.template, (data.returnValues.count === undefined ? undefined : data.returnValues.count));
- this._setupPagination();
- break;
- }
- },
-
- /**
- * Submits authentication data for current update server.
- *
- * @param object event
- */
- _submitAuthentication: function(event) {
- var $usernameField = $('#packageUpdateServerUsername');
- var $passwordField = $('#packageUpdateServerPassword');
-
- // remove error messages if any
- $usernameField.next('small.innerError').remove();
- $passwordField.next('small.innerError').remove();
-
- var $continue = true;
- if ($.trim($usernameField.val()) === '') {
- $('<small class="innerError">' + WCF.Language.get('wcf.global.form.error.empty') + '</small>').insertAfter($usernameField);
- $continue = false;
- }
-
- if ($.trim($passwordField.val()) === '') {
- $('<small class="innerError">' + WCF.Language.get('wcf.global.form.error.empty') + '</small>').insertAfter($passwordField);
- $continue = false;
- }
-
- if ($continue) {
- this._prepareInstallation($(event.currentTarget).data('packageUpdateServerID'));
- }
- },
-
- /**
- * Inserts search result list template.
- *
- * @param string template
- * @param integer count
- */
- _insertTemplate: function(template, count) {
- this._packageSearchResultContainer.show();
-
- this._packageSearchResultList.html(template);
- if (count === undefined) {
- this._content[this._pageNo] = template;
- }
-
- // update badge count
- if (count !== undefined) {
- this._content = { 1: template };
- this._packageSearchResultContainer.find('h2.sectionTitle > .badge').html(count);
- }
-
- // bind listener
- this._packageSearchResultList.find('.jsInstallPackage').click($.proxy(this._click, this));
- },
-
- /**
- * Prepares a package installation.
- *
- * @param object event
- */
- _click: function(event) {
- var $button = $(event.currentTarget);
- WCF.System.Confirmation.show($button.data('confirmMessage'), $.proxy(function(action) {
- if (action === 'confirm') {
- this._selectedPackage = $button.data('package');
- this._selectedPackageVersion = $button.data('packageVersion');
- this._prepareInstallation();
- }
- }, this), undefined, undefined, true);
- },
-
- /**
- * Prepares package installation.
- *
- * @param integer packageUpdateServerID
- */
- _prepareInstallation: function(packageUpdateServerID) {
- var $parameters = {
- 'packages': { }
- };
- $parameters['packages'][this._selectedPackage] = this._selectedPackageVersion;
-
- if (packageUpdateServerID) {
- $parameters.authData = {
- packageUpdateServerID: packageUpdateServerID,
- password: $.trim($('#packageUpdateServerPassword').val()),
- saveCredentials: ($('#packageUpdateServerSaveCredentials:checked').length ? true : false),
- username: $.trim($('#packageUpdateServerUsername').val())
- };
- }
-
- this._proxy.setOption('data', {
- actionName: 'prepareInstallation',
- className: 'wcf\\data\\package\\update\\PackageUpdateAction',
- parameters: $parameters
- });
- this._proxy.sendRequest();
- },
-
- /**
- * Setups pagination for current search.
- */
- _setupPagination: function() {
- // remove previous instances
- this._content = { 1: this._packageSearchResultList.html() };
- this._packageSearchResultContainer.find('.pagination').wcfPages('destroy').remove();
-
- if (this._pageCount > 1) {
- var $contentFooter = $('<footer class="contentFooter"><div class="paginationBottom"><nav /></div></footer>').insertAfter(this._packageSearchResultList);
- $contentFooter.find('nav').wcfPages({
- activePage: this._pageNo,
- maxPage: this._pageCount
- }).on('wcfpagesswitched', $.proxy(this._showPage, this));
- }
- },
-
- /**
- * Displays requested pages or loads it.
- *
- * @param object event
- * @param object data
- */
- _showPage: function(event, data) {
- if (data && data.activePage) {
- this._pageNo = data.activePage;
- }
-
- // validate page no
- if (this._pageNo < 1 || this._pageNo > this._pageCount) {
- console.debug("[WCF.ACP.Package.Search] Cannot access page " + this._pageNo + " of " + this._pageCount);
- return;
- }
-
- // load content
- if (this._content[this._pageNo] === undefined) {
- this._proxy.setOption('data', {
- actionName: 'getResultList',
- className: 'wcf\\data\\package\\update\\PackageUpdateAction',
- parameters: {
- pageNo: this._pageNo,
- searchID: this._searchID
- }
- });
- this._proxy.sendRequest();
- }
- else {
- // show cached content
- this._packageSearchResultList.html(this._content[this._pageNo]);
-
- WCF.DOMNodeInsertedHandler.execute();
- }
- }
-});
-
WCF.ACP.Package.Server = { };
WCF.ACP.Package.Server.Installation = Class.extend({
--- /dev/null
+/**
+ * Attempts to download the requested package from the file and prompts for the
+ * authentication credentials on rejection.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Acp/Ui/Package/PrepareInstallation
+ */
+define(['Ajax', 'Core', 'Language', 'Ui/Dialog'], function(Ajax, Core, Language, UiDialog) {
+ 'use strict';
+
+ function AcpUiPackagePrepareInstallation() { }
+ AcpUiPackagePrepareInstallation.prototype = {
+ /**
+ * @param {string} identifier
+ * @param {string} version
+ */
+ start: function (identifier, version) {
+ this._identifier = identifier;
+ this._version = version;
+
+ this._prepare({});
+ },
+
+ /**
+ * @param {Object} authData
+ */
+ _prepare: function(authData) {
+ var packages = {};
+ packages[this._identifier] = this._version;
+
+ Ajax.api(this, {
+ parameters: {
+ authData: authData,
+ packages: packages
+ }
+ });
+ },
+
+ /**
+ * @param {number} packageUpdateServerId
+ * @param {Event} event
+ */
+ _submit: function(packageUpdateServerId, event) {
+ event.preventDefault();
+
+ var usernameInput = elById('packageUpdateServerUsername');
+ var passwordInput = elById('packageUpdateServerPassword');
+
+ elInnerError(usernameInput, false);
+ elInnerError(passwordInput, false);
+
+ var username = usernameInput.value.trim();
+ if (username === '') {
+ elInnerError(usernameInput, Language.get('wcf.global.form.error.empty'));
+ }
+ else {
+ var password = passwordInput.value.trim();
+ if (password === '') {
+ elInnerError(passwordInput, Language.get('wcf.global.form.error.empty'));
+ }
+ else {
+ this._prepare({
+ packageUpdateServerID: packageUpdateServerId,
+ password: password,
+ saveCredentials: elById('packageUpdateServerSaveCredentials').checked,
+ username: username
+ });
+ }
+ }
+ },
+
+ _ajaxSuccess: function(data) {
+ if (data.returnValues.queueID) {
+ UiDialog.close(this);
+
+ var installation = new window.WCF.ACP.Package.Installation(data.returnValues.queueID, undefined, false);
+ installation.prepareInstallation();
+ }
+ else if (data.returnValues.template) {
+ UiDialog.open(this, data.returnValues.template);
+ }
+ },
+
+ _ajaxSetup: function () {
+ return {
+ data: {
+ actionName: 'prepareInstallation',
+ className: 'wcf\\data\\package\\update\\PackageUpdateAction'
+ }
+ }
+ },
+
+ _dialogSetup: function() {
+ return {
+ id: 'packageDownloadAuthorization',
+ options: {
+ onSetup: (function(content) {
+ var button = elBySel('.formSubmit > button', content);
+ button.addEventListener(WCF_CLICK_EVENT, this._submit.bind(this, elData(button, 'package-update-server-id')));
+ }).bind(this),
+ title: Language.get('wcf.acp.package.update.unauthorized')
+ },
+ source: null
+ }
+ }
+ };
+
+ return AcpUiPackagePrepareInstallation;
+});