From 996eb6508c80c96acae0b7875d2e7101e5d89259 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 3 May 2013 16:39:08 +0200 Subject: [PATCH] Added ability to install packages through search --- wcfsetup/install/files/acp/js/WCF.ACP.js | 128 +++++++++++++++++- .../install/files/acp/templates/header.tpl | 1 + .../acp/templates/packageSearchResultList.tpl | 2 +- .../acp/templates/packageStartInstall.tpl | 4 + .../update/PackageUpdateAction.class.php | 50 ++++++- 5 files changed, 176 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 81d70fade3..3e686ff6f7 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -746,6 +746,12 @@ WCF.ACP.Package.Search = Class.extend({ */ _container: null, + /** + * dialog overlay + * @var jQuery + */ + _dialog: null, + /** * package input field * @var jQuery @@ -800,6 +806,17 @@ WCF.ACP.Package.Search = Class.extend({ */ _searchID: 0, + /** + * currently selected package + * @var string + */ + _selectedPackage: '', + + /** + * currently selected package's version + */ + _selectedPackageVersion: '', + /** * Initializes the WCF.ACP.Package.Seach class. */ @@ -807,6 +824,7 @@ WCF.ACP.Package.Search = Class.extend({ this._button = null; this._cache = { }; this._container = $('#packageSearch'); + this._dialog = null; this._package = null; this._packageName = null; this._packageSearchResultContainer = $('#packageSearchResultContainer'); @@ -815,6 +833,8 @@ WCF.ACP.Package.Search = Class.extend({ this._pageNo = 1; this._searchDescription = null; this._searchID = 0; + this._selectedPackage = ''; + this._selectedPackageVersion = ''; this._proxy = new WCF.Action.Proxy({ success: $.proxy(this._success, this) @@ -909,6 +929,30 @@ WCF.ACP.Package.Search = Class.extend({ 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 = $('
' + data.returnValues.template + '
').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; @@ -919,6 +963,35 @@ WCF.ACP.Package.Search = Class.extend({ } }, + /** + * 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()) === '') { + $('' + WCF.Language.get('wcf.global.form.error.empty') + '').insertAfter($usernameField); + $continue = false; + } + + if ($.trim($passwordField.val()) === '') { + $('' + WCF.Language.get('wcf.global.form.error.empty') + '').insertAfter($passwordField); + $continue = false; + } + + if ($continue) { + this._prepareInstallation($(event.currentTarget).data('packageUpdateServerID')); + } + }, + /** * Inserts search result list template. * @@ -936,8 +1009,55 @@ WCF.ACP.Package.Search = Class.extend({ // update badge count if (count !== undefined) { this._content = { 1: template }; - this._packageSearchResultContainer.find('> header > h1 > .badge').html(count); + this._packageSearchResultContainer.find('> header > h2 > .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)); + }, + + /** + * Prepares package installation. + * + * @param integer packageUpdateServerID + */ + _prepareInstallation: function(packageUpdateServerID) { + var $parameters = { + 'package': { } + }; + $parameters['package'][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(); }, /** @@ -949,12 +1069,12 @@ WCF.ACP.Package.Search = Class.extend({ this._packageSearchResultContainer.find('.pageNavigation').wcfPages('destroy').remove(); if (this._pageCount > 1) { - var $topNavigation = $('
').insertBefore(this._packageSearchResultList).wcfPages({ + $('
').insertBefore(this._packageSearchResultList).wcfPages({ activePage: this._pageNo, maxPage: this._pageCount }).bind('wcfpagesswitched', $.proxy(this._showPage, this)); - var $bottomNavigation = $('
').insertAfter(this._packageSearchResultList).wcfPages({ + $('
').insertAfter(this._packageSearchResultList).wcfPages({ activePage: this._pageNo, maxPage: this._pageCount }).bind('wcfpagesswitched', $.proxy(this._showPage, this)); @@ -1093,7 +1213,7 @@ WCF.ACP.Package.Update.Manager = Class.extend({ password: $.trim($('#packageUpdateServerPassword').val()), saveCredentials: ($('#packageUpdateServerSaveCredentials:checked').length ? true : false), username: $.trim($('#packageUpdateServerUsername').val()) - } + }; } this._proxy.setOption('data', { diff --git a/wcfsetup/install/files/acp/templates/header.tpl b/wcfsetup/install/files/acp/templates/header.tpl index 9ca9398070..72caf6461a 100644 --- a/wcfsetup/install/files/acp/templates/header.tpl +++ b/wcfsetup/install/files/acp/templates/header.tpl @@ -75,6 +75,7 @@ 'wcf.global.decimalPoint': '{capture assign=decimalPoint}{lang}wcf.global.decimalPoint{/lang}{/capture}{$decimalPoint|encodeJS}', 'wcf.global.error.timeout': '{lang}wcf.global.error.timeout{/lang}', 'wcf.global.error.title': '{lang}wcf.global.error.title{/lang}', + 'wcf.global.form.error.empty': '{lang}wcf.global.form.error.empty{/lang}', 'wcf.global.loading': '{lang}wcf.global.loading{/lang}', 'wcf.global.page.jumpTo': '{lang}wcf.global.page.jumpTo{/lang}', 'wcf.global.page.jumpTo.description': '{lang}wcf.global.page.jumpTo.description{/lang}', diff --git a/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl b/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl index 32ac1bd4b0..b726275320 100644 --- a/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl +++ b/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl @@ -18,7 +18,7 @@ {foreach from=$packageUpdates item=$package} - + {event name='buttons'} diff --git a/wcfsetup/install/files/acp/templates/packageStartInstall.tpl b/wcfsetup/install/files/acp/templates/packageStartInstall.tpl index 297531e67e..b893de0420 100644 --- a/wcfsetup/install/files/acp/templates/packageStartInstall.tpl +++ b/wcfsetup/install/files/acp/templates/packageStartInstall.tpl @@ -8,6 +8,10 @@