}
};
+/**
+ * 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,
this._pluginLists.push($wcfPages);
}, this));
+ // initialize
if (this._pluginLists.length > 0) {
this._proxy = new WCF.Action.Proxy({
success: $.proxy(this._success, this)
}
},
+ /**
+ * 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;
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 });
* @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
*
*/
_actionName: '',
+ /**
+ * dialog api
+ * @var $.ui.wcfDialog
+ */
_api: null,
/**
*/
_dialog: null,
+ /**
+ * action proxy
+ * @var WCF.Action.Proxy
+ */
+ _proxy: null,
+
/**
* queue id
*
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();
* 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('<div class="formSubmit"><input type="button" id="' + $id + '" value="' + WCF.Language.get('wcf.global.button.next') + '" class="default" /></div>');
- $('#' + $id).click($.proxy(function() {
+ $('#' + $id).click(function() {
window.location.href = "index.php/PackageList/" + SID_ARG_1ST;
- }, this));
+ });
$('#packageInstallationInnerContentContainer').wcfBlindIn();
});
}
// 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('<div class="formSubmit"><input type="button" id="' + $id + '" value="' + WCF.Language.get('wcf.global.button.next') + '" class="default" /></div>');
$('#' + $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');
$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));
},
if ($('#packageInstallationInnerContent').children().length > 1) {
$('#packageInstallationInnerContentContainer').wcfBlindOut('vertical', $.proxy(function() {
$('#packageInstallationInnerContent').empty();
- this._api.redraw();
+ this._api.render();
// execute callback
callback();
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();
}
};
*
* @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,
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
});
$('#workerInnerContentContainer').wcfBlindIn();
- this._dialog.wcfDialog('redraw');
+ this._dialog.wcfDialog('render');
}
}
};
},
/**
+ * 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
*/
_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($('<div id="' + dialogID + '"></div>'));
+ $('<div id="' + dialogID + '"></div>').appendTo(document.body);
}
var dialog = $('#' + $.wcfEscapeID(dialogID));
dialog.empty();
}
- dialog.addClass('overlayLoading');
-
var dialogOptions = arguments[2] || {};
- return dialog.wcfAJAXDialog(dialogOptions);
+ dialog.wcfDialog(dialogOptions);
+
+ return dialog;
},
/**
// 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'));
}
});
-
-/**
- * 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 = $('<div><iframe></iframe></div>').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.
*/