Install packages from the result list
authorAlexander Ebert <ebert@woltlab.com>
Wed, 17 Apr 2019 18:48:30 +0000 (20:48 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 17 Apr 2019 18:48:30 +0000 (20:48 +0200)
wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Package/PrepareInstallation.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Package/Search.js

index 8e6ac621861b5f53d994bc58418bd32902a40949..9e2911117c3b9ef9ba73659ea63c715a12e119cf 100644 (file)
@@ -663,397 +663,6 @@ WCF.ACP.Package.Uninstallation = WCF.ACP.Package.Installation.extend({
        }
 });
 
-/**
- * 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({
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Package/PrepareInstallation.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Package/PrepareInstallation.js
new file mode 100644 (file)
index 0000000..824ffa8
--- /dev/null
@@ -0,0 +1,111 @@
+/**
+ * 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;
+});
index 96ab6bd1acee36191a9b865b391a0149ffbb6cbf..50b1dc25c5c8cfdf718570fddaf1942441e04506 100644 (file)
@@ -1,18 +1,19 @@
 /**
- * 
+ * Search interface for the package server lists.
  * 
  * @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/Search
  */
-define(['Ajax'], function(Ajax) {
+define(['Ajax', 'WoltLabSuite/Core/Acp/Ui/Package/PrepareInstallation'], function(Ajax, AcpUiPackagePrepareInstallation) {
        'use strict';
        
        function AcpUiPackageSearch() { this.init(); }
        AcpUiPackageSearch.prototype = {
                init: function () {
                        this._input = elById('packageSearchInput');
+                       this._installation = new AcpUiPackagePrepareInstallation();
                        this._isBusy = false;
                        this._isFirstRequest = true;
                        this._lastValue = '';
@@ -97,6 +98,18 @@ define(['Ajax'], function(Ajax) {
                                                this._resultCounter.textContent = data.returnValues.count;
                                                
                                                this._setStatus('showResults');
+                                               
+                                               elBySelAll('.jsInstallPackage', this._resultList, (function(button) {
+                                                       button.addEventListener(WCF_CLICK_EVENT, (function (event) {
+                                                               event.preventDefault();
+                                                               button.blur();
+                                                               
+                                                               this._installation.start(
+                                                                       elData(button, 'package'),
+                                                                       elData(button, 'package-version')
+                                                               );
+                                                       }).bind(this));
+                                               }).bind(this));
                                        }
                                        else {
                                                this._setStatus('noResults');