From e5b88a7f129f2e619130da92d3375a2279e73686 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 25 Nov 2011 00:43:57 +0100 Subject: [PATCH] Updated to use new dialog API, removed old API --- wcfsetup/install/files/acp/js/WCF.ACP.js | 181 +++++++---- .../templates/packageInstallationConfirm.tpl | 2 +- .../templates/packageInstallationSetup.tpl | 2 +- .../acp/templates/packageListDetailed.tpl | 2 +- wcfsetup/install/files/js/WCF.js | 294 +----------------- 5 files changed, 133 insertions(+), 348 deletions(-) diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index d1fbca6a62..3e2b319f85 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -123,16 +123,49 @@ WCF.ACP.Menu.prototype = { } }; +/** + * Namespace for ACP package management. + */ WCF.ACP.Package = {}; +/** + * Paginated package list. + * + * @param integer pages + */ WCF.ACP.Package.List = function(pages) { this.init(pages); }; WCF.ACP.Package.List.prototype = { + /** + * page cache + * @var object + */ _pages: {}, + + /** + * plugin list references + * @var object + */ _pluginLists: [], + + /** + * action proxy + * @var WCF.Action.Proxy + */ _proxy: null, + + /** + * target container + * @var jQuery + */ _template: null, + /** + * Initializes the package list. + * + * @param integer pages + */ init: function(pages) { + // handle pagination $('.pluginList').each($.proxy(function(index, pluginList) { var $wcfPages = $(pluginList).wcfPages({ activePage: 1, @@ -142,6 +175,7 @@ WCF.ACP.Package.List.prototype = { this._pluginLists.push($wcfPages); }, this)); + // initialize if (this._pluginLists.length > 0) { this._proxy = new WCF.Action.Proxy({ success: $.proxy(this._success, this) @@ -150,18 +184,31 @@ WCF.ACP.Package.List.prototype = { } }, + /** + * Caches currently active page. + * + * @param object event + * @param object data + */ _cachePage: function(event, data) { if (!this._pages[data.currentPage]) { this._pages[data.currentPage] = $('#plugins ol').html(); } }, + /** + * Loads the request page using AJAX. + * + * @param object event + * @param object data + */ _loadPage: function(event, data) { // update active page for (var $i = 0, $size = this._pluginLists.length; $i < $size; $i++) { this._pluginLists[$i].wcfPages('overridePage', data.activePage); } + // load page from cache if applicable if (this._pages[data.activePage]) { this._template.html(this._pages[data.activePage]); return; @@ -178,6 +225,13 @@ WCF.ACP.Package.List.prototype = { this._proxy.sendRequest(); }, + /** + * Displays the fetched page. + * + * @param object data + * @param string textStatus + * @param jQuery jqXHR + */ _success: function(data, textStatus, jqXHR) { this._pages[data.returnValues.activePage] = data.returnValues.template; this._loadPage(null, { activePage: data.returnValues.activePage }); @@ -191,8 +245,8 @@ WCF.ACP.Package.List.prototype = { * @param integer queueID * @param boolean initialize */ -WCF.ACP.PackageInstallation = function(actionName, queueID, initialize) { this.init(actionName, queueID, initialize); }; -WCF.ACP.PackageInstallation.prototype = { +WCF.ACP.Package.Installation = function(actionName, queueID, initialize) { this.init(actionName, queueID, initialize); }; +WCF.ACP.Package.Installation.prototype = { /** * package installation type * @@ -200,6 +254,10 @@ WCF.ACP.PackageInstallation.prototype = { */ _actionName: '', + /** + * dialog api + * @var $.ui.wcfDialog + */ _api: null, /** @@ -209,6 +267,12 @@ WCF.ACP.PackageInstallation.prototype = { */ _dialog: null, + /** + * action proxy + * @var WCF.Action.Proxy + */ + _proxy: null, + /** * queue id * @@ -226,7 +290,11 @@ WCF.ACP.PackageInstallation.prototype = { init: function(actionName, queueID, initialize) { this._actionName = WCF.String.ucfirst(actionName) + 'Package'; this._queueID = queueID; - + this._proxy = new WCF.Action.Proxy({ + success: $.proxy(this._handleResponse, this), + url: 'index.php/' + this._actionName + '/?t=' + SECURITY_TOKEN + SID_ARG_2ND + }); + if (initialize) { $('#submitButton').click($.proxy(function(event) { this.prepareInstallation(); @@ -239,53 +307,54 @@ WCF.ACP.PackageInstallation.prototype = { * Prepares installation dialog. */ prepareInstallation: function() { - this._api = WCF.showAJAXDialog('packageInstallationDialog', true, { - ajax: { - url: 'index.php/' + this._actionName + '/?t=' + SECURITY_TOKEN + SID_ARG_2ND, - type: 'POST', - data: { queueID: this._queueID, step: 'prepare' }, - success: $.proxy(this._handleResponse, this) - }, + var $dialog = WCF.showAJAXDialog('packageInstallationDialog', true, { + url: 'index.php/' + this._actionName + '/?t=' + SECURITY_TOKEN + SID_ARG_2ND, + data: { queueID: this._queueID, step: 'prepare' }, + success: $.proxy(this._handleResponse, this), preventClose: true, hideTitle: true }); + + this._api = $dialog.data('wcfDialog'); }, /** * Executes response instructions. + * + * @param object data + * @param string textStatus + * @param jQuery jqXHR */ - _handleResponse: function() { + _handleResponse: function(data. textStatus, jqXHR) { if (this._dialog == null) { this._dialog = $('#packageInstallationDialog'); } - var $data = this._dialog.data('responseData'); - // receive new queue id - if ($data.queueID) { - this._queueID = $data.queueID; + if (data.queueID) { + this._queueID = data.queueID; } // update progress - if ($data.progress) { - $('#packageInstallationProgress').attr('value', $data.progress).text($data.progress + '%'); - $('#packageInstallationProgressLabel').text($data.progress + '%'); + if (data.progress) { + $('#packageInstallationProgress').attr('value', data.progress).text(data.progress + '%'); + $('#packageInstallationProgressLabel').text(data.progress + '%'); } // update action - if ($data.currentAction) { - $('#packageInstallationAction').html($data.currentAction); + if (data.currentAction) { + $('#packageInstallationAction').html(data.currentAction); } // handle success - if ($data.step == 'success') { + if (data.step == 'success') { this._purgeTemplateContent(function() { var $id = WCF.getRandomID(); $('#packageInstallationInnerContent').append('
'); - $('#' + $id).click($.proxy(function() { + $('#' + $id).click(function() { window.location.href = "index.php/PackageList/" + SID_ARG_1ST; - }, this)); + }); $('#packageInstallationInnerContentContainer').wcfBlindIn(); }); @@ -294,24 +363,24 @@ WCF.ACP.PackageInstallation.prototype = { } // update template - if ($data.template && !$data.ignoreTemplate) { - this._dialog.html($data.template); - this._api.redraw(); + if (data.template && !data.ignoreTemplate) { + this._dialog.html(data.template); + this._api.render(); } // handle inner template - if ($data.innerTemplate) { - $('#packageInstallationInnerContent').html($data.innerTemplate); + if (data.innerTemplate) { + $('#packageInstallationInnerContent').html(data.innerTemplate); // create button to handle next step - if ($data.step && $data.node) { + if (data.step && data.node) { var $id = WCF.getRandomID(); $('#packageInstallationInnerContent').append('
'); $('#' + $id).click($.proxy(function() { // collect form values var $additionalData = {}; - $('#packageInstallationInnerContent').find('input').each(function(index, inputElement) { + $('#packageInstallationInnerContent input').each(function(index, inputElement) { var $inputElement = $(inputElement); var $type = $inputElement.attr('type'); @@ -322,24 +391,24 @@ WCF.ACP.PackageInstallation.prototype = { $additionalData[$inputElement.attr('name')] = $inputElement.val(); }); - this._executeStep($data.step, $data.node, $additionalData); + this._executeStep(data.step, data.node, $additionalData); }, this)); } $('#packageInstallationInnerContentContainer').wcfBlindIn(); - this._api.redraw(); + this._api.render(); return; } // purge content this._purgeTemplateContent($.proxy(function() { - // redraw container - this._api.redraw(); + // render container + this._api.render(); // execute next step - if ($data.step && $data.node) { - this._executeStep($data.step, $data.node); + if (data.step && data.node) { + this._executeStep(data.step, data.node); } }, this)); }, @@ -353,7 +422,7 @@ WCF.ACP.PackageInstallation.prototype = { if ($('#packageInstallationInnerContent').children().length > 1) { $('#packageInstallationInnerContentContainer').wcfBlindOut('vertical', $.proxy(function() { $('#packageInstallationInnerContent').empty(); - this._api.redraw(); + this._api.render(); // execute callback callback(); @@ -379,20 +448,9 @@ WCF.ACP.PackageInstallation.prototype = { queueID: this._queueID, step: step }, additionalData); - - $.ajax({ - url: 'index.php/' + this._actionName + '/?t=' + SECURITY_TOKEN + SID_ARG_2ND, - dataType: 'json', - type: 'POST', - data: $data, - success: $.proxy(function(data) { - this._dialog.data('responseData', data); - this._handleResponse(); - }, this), - error: function(transport) { - alert(transport.responseText); - } - }); + + this._proxy.setOption('data', $data); + this._proxy.sendRequest(); } }; @@ -401,12 +459,12 @@ WCF.ACP.PackageInstallation.prototype = { * * @param jQuery elements */ -WCF.ACP.PackageUninstallation = function(elements) { this.init(elements); }; -WCF.ACP.PackageUninstallation.prototype = { +WCF.ACP.Package.Uninstallation = function(elements) { this.init(elements); }; +WCF.ACP.Package.Uninstallation.prototype = { /** - * WCF.ACP.PackageInstallation object + * WCF.ACP.Package.Installation object * - * @var WCF.ACP.PackageInstallation + * @var WCF.ACP.Package.Installation */ _installation: null, @@ -434,16 +492,13 @@ WCF.ACP.PackageUninstallation.prototype = { var packageID = $element.data('objectID'); if (confirm(WCF.Language.get('wcf.acp.package.view.button.uninstall.sure'))) { - this._installation = new WCF.ACP.PackageInstallation('uninstall', 0, false); + this._installation = new WCF.ACP.Package.Installation('uninstall', 0, false); // initialize dialog WCF.showAJAXDialog('packageInstallationDialog', true, { - ajax: { - url: 'index.php/UninstallPackage/?t=' + SECURITY_TOKEN + SID_ARG_2ND, - type: 'POST', - data: { packageID: packageID, step: 'prepare' }, - success: $.proxy(this._installation._handleResponse, this._installation) - }, + url: 'index.php/UninstallPackage/?t=' + SECURITY_TOKEN + SID_ARG_2ND, + data: { packageID: packageID, step: 'prepare' }, + success: $.proxy(this._installation._handleResponse, this._installation), preventClose: true, hideTitle: true }); @@ -715,7 +770,7 @@ WCF.ACP.Worker.prototype = { $('#workerInnerContentContainer').wcfBlindIn(); - this._dialog.wcfDialog('redraw'); + this._dialog.wcfDialog('render'); } } }; diff --git a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl index 0769390449..d1a64eac81 100644 --- a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl +++ b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl @@ -3,7 +3,7 @@ diff --git a/wcfsetup/install/files/acp/templates/packageInstallationSetup.tpl b/wcfsetup/install/files/acp/templates/packageInstallationSetup.tpl index a08e9e4141..7205be99a7 100644 --- a/wcfsetup/install/files/acp/templates/packageInstallationSetup.tpl +++ b/wcfsetup/install/files/acp/templates/packageInstallationSetup.tpl @@ -2,7 +2,7 @@ diff --git a/wcfsetup/install/files/acp/templates/packageListDetailed.tpl b/wcfsetup/install/files/acp/templates/packageListDetailed.tpl index 73a26ba346..c7cd5fb8f8 100644 --- a/wcfsetup/install/files/acp/templates/packageListDetailed.tpl +++ b/wcfsetup/install/files/acp/templates/packageListDetailed.tpl @@ -5,7 +5,7 @@ $(function() { WCF.Language.add('wcf.acp.package.view.button.uninstall.sure', '{lang}wcf.acp.package.view.button.uninstall.sure{/lang}'); - new WCF.ACP.PackageUninstallation($('.packageRow .uninstallButton')); + new WCF.ACP.Package.Uninstallation($('.packageRow .uninstallButton')); }); //]]> diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index d10bde64c1..32ff80ffcd 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -259,11 +259,18 @@ $.fn.extend({ }, /** + * CAUTION: This method does not work properly, you should not rely + * on it for now. It seems to work with the old jQuery UI- + * based dialog, but no longer works with usual elements. + * I will either try to fix it or remove it later, thus + * this method will be deprecated for now. -Alexander + * * Applies a grow-effect by resizing element while moving the element * appropriately. Make sure the passed data.content element contains * all elements which affect this indirectly, this includes outer * containers which may apply an obstrusive padding. * + * @deprecated * @param object data * @param object options * @return jQuery @@ -409,33 +416,20 @@ $.extend(WCF, { */ _idCounter: 0, - /** - * Set to true after first dialog was initialized - * @var boolean - */ - _didInitDialogs: false, - /** * Shows a modal dialog with a built-in AJAX-loader. * * @param string dialogID * @param boolean resetDialog - * @return $.ui.wcfAJAXDialog + * @return jQuery */ showAJAXDialog: function(dialogID, resetDialog) { - if (!this._didInitDialogs) { - $('.ui-widget-overlay').live('click', function() { - $('.ui-dialog-titlebar-close').trigger('click'); - }); - this._didInitDialogs = true; - } - if (!dialogID) { dialogID = this.getRandomID(); } if (!$.wcfIsset(dialogID)) { - $('body').append($('
')); + $('
').appendTo(document.body); } var dialog = $('#' + $.wcfEscapeID(dialogID)); @@ -444,10 +438,10 @@ $.extend(WCF, { dialog.empty(); } - dialog.addClass('overlayLoading'); - var dialogOptions = arguments[2] || {}; - return dialog.wcfAJAXDialog(dialogOptions); + dialog.wcfDialog(dialogOptions); + + return dialog; }, /** @@ -460,13 +454,6 @@ $.extend(WCF, { // load content via AJAX, see showAJAXDialog() instead if (!$.wcfIsset(dialogID)) return; - if (!this._didInitDialogs) { - $('.ui-widget-overlay').live('click', function() { - $('.ui-dialog-titlebar-close').trigger('click'); - }); - this._didInitDialogs = true; - } - var $dialog = $('#' + $.wcfEscapeID(dialogID)); if (moveToBody) { $dialog.remove().appendTo($('body')); @@ -3439,263 +3426,6 @@ $.widget('ui.wcfDialog', { } }); - -/** - * Basic implementation for WCF dialogs. - */ -$.widget('ui.wcfDialog_old', $.ui.dialog, { - _init: function() { - this.options.autoOpen = true; - this.options.hide = { - effect: 'fade' - }; - - if (this.options.hideTitle) { - // remove title element - this.element.prev().empty().remove(); - } - - this.options.close = function() { - // "display: inline-block" is set by stylesheet, but additionally flagged - // with important, thus we have to force the dialog to stay hidden - $(this).parent('.ui-dialog').css({ display: 'none !important'}); - }; - - this.options.height = 'auto'; - this.options.minHeight = 0; - this.options.modal = true; - this.options.width = 'auto'; - - $.ui.dialog.prototype._init.apply(this, arguments); - - // center dialog on resize - $(window).resize($.proxy(function() { - this.option('position', 'center'); - }, this)); - }, - - /** - * Redraws dialog, should be executed everytime content is changed. - */ - redraw: function() { - var $dimensions = this.element.getDimensions(); - - if ($dimensions.height > 200) { - this.element.wcfGrow({ - content: this.element,//.html(), - parent: this.element.parent('.ui-dialog') - }, { - duration: 600, - complete: function() { - $(this).css({ height: 'auto' }); - } - }); - } - } -}); - -/** - * Basic implementation for WCF dialogs loading content - * via AJAX before calling dialog itself. - */ -$.widget('ui.wcfAJAXDialog_old', $.ui.dialog, { - /** - * Indicates wether callback was already executed - * - * @var boolean - */ - _callbackExecuted: false, - - /** - * Initializes AJAX-request to fetch content. - */ - _init: function() { - if (this.options.ajax) { - this._loadContent(); - } - - // force dialog to be placed centered - this.options.position = { - my: 'center center', - at: 'center center' - }; - - // dialog should display a spinner-like image, thus immediately fire up dialog - this.options.autoOpen = true; - this.options.width = 'auto'; - this.options.minHeight = 80; - - // disable ability to move dialog - this.options.resizable = false; - this.options.draggable = false; - - this.options.modal = true; - this.options.hide = { - effect: 'fade' - }; - - this.options.close = function() { - // "display: inline-block" is set by stylesheet, but additionally flagged - // with important, thus we have to force the dialog to stay hidden - $(this).parent('.ui-dialog').css({ display: 'none !important'}); - }; - - if (this.options.preventClose) { - this.options.closeOnEscape = false; - } - - $.ui.dialog.prototype._init.apply(this, arguments); - - // remove complete node instead of removing node-by-node - if (this.options.hideTitle && this.options.preventClose) { - this.element.parent('.ui-dialog').find('div.ui-dialog-titlebar').empty().remove(); - } - else { - if (this.options.hideTitle) { - // remove title element - $('#ui-dialog-title-' + this.element.attr('id')).empty().remove(); - } - - if (this.options.preventClose) { - // remove close-button - this.element.parent('.ui-dialog').find('a.ui-dialog-titlebar-close').empty().remove(); - } - } - - // center dialog on window resize - $(window).resize($.proxy(function() { - this.option('position', 'center'); - }, this)); - }, - - /** - * Loads content via AJAX. - * - * @todo Enforce JSON - */ - _loadContent: function() { - var $type = 'GET'; - if (this.options.ajax.type) { - $type = this.options.ajax.type; - - if (this.options.ajax.type != 'GET' && this.options.ajax.type != 'POST') { - $type = 'GET'; - } - } - - var $data = this.options.ajax.data || {}; - - $.ajax({ - url: this.options.ajax.url, - context: this, - dataType: 'json', - type: $type, - data: $data, - success: $.proxy(this._createDialog, this), - error: $.proxy(this._showError, this) - }); - }, - - _showError: function(transport) { - var $iframe = $('
').appendTo($('body')).wcfDialog(); - $iframe = $iframe.children('iframe'); - $iframe.contents().find('body').append(transport.responseText); - - // force dimensions - $iframe.css({ height: '500px', width: '860px' }); - - // DO NOT execute redraw until it properly works with iframes. Sadly - // cloning the item causes the content to be lost, resulting in zero - // dimensions. Fix this! - - // redraw dialog - $iframe.parent('div').wcfDialog('redraw'); - }, - - /** - * Inserts content. - * - * @param string data - */ - _createDialog: function(data) { - data.ignoreTemplate = true; - this.element.data('responseData', data); - - // work-around for AJAXProxy's different return values - - this.element.wcfGrow({ - content: this._getResponseValue('template'), - parent: this.element.parent('.ui-dialog') - }, { - duration: 600, - complete: $.proxy(function(data) { - this.element.css({ - height: 'auto' - }); - - // prevent double execution due to two complete-calls (two times animate) - if (this._callbackExecuted) { - return; - } - - this._callbackExecuted = true; - - this.element.removeClass('overlayLoading'); - this.element.html(this._getResponseValue('template')); - - if (this.options.ajax.success) { - this.options.ajax.success(); - } - }, this) - }); - }, - - /** - * Returns specific AJAX response value. - * - * @param string key - * @return mixed - */ - _getResponseValue: function(key) { - var $data = this.element.data('responseData'); - - // no response data stored - if (!$data) { - return null; - } - - // AJAXProxy - if ($data.returnValues && $data.returnValues[key]) { - return $data.returnValues[key]; - } - // PackageInstallation - else if ($data[key]) { - return $data[key]; - } - - return null; - }, - - /** - * Redraws dialog, should be executed everytime content is changed. - */ - redraw: function() { - var $dimensions = this.element.getDimensions(); - - if ($dimensions.height > 200) { - this.element.wcfGrow({ - content: this.element,//.html(), - parent: this.element.parent('.ui-dialog') - }, { - duration: 600, - complete: function() { - $(this).css({ height: 'auto' }); - } - }); - } - } -}); - /** * Custom tab menu implementation for WCF. */ -- 2.20.1