From 25c2c38284c234439111ad28bccc79152a3faca3 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 19 Jan 2013 17:47:35 +0100 Subject: [PATCH] Package search now runs via AJAX Renamed UpdateServer* -> PackageUpdateServer* --- com.woltlab.wcf/acpMenu.xml | 18 +- wcfsetup/install/files/acp/js/WCF.ACP.js | 277 +++++++++++++++++ .../acp/templates/packageSearchResultList.tpl | 45 +++ .../acp/templates/packageStartInstall.tpl | 133 ++++++--- .../acp/templates/packageUpdateSearch.tpl | 122 -------- .../templates/packageUpdateSearchResult.tpl | 125 -------- ...rverAdd.tpl => packageUpdateServerAdd.tpl} | 4 +- ...erList.tpl => packageUpdateServerList.tpl} | 22 +- wcfsetup/install/files/js/WCF.js | 2 +- .../form/PackageUpdateSearchForm.class.php | 279 ------------------ ...p => PackageUpdateServerAddForm.class.php} | 6 +- ... => PackageUpdateServerEditForm.class.php} | 4 +- .../PackageUpdateSearchResultPage.class.php | 173 ----------- ... => PackageUpdateServerListPage.class.php} | 4 +- .../files/lib/data/package/Package.class.php | 2 +- .../lib/data/package/PackageAction.class.php | 2 +- .../update/PackageUpdateAction.class.php | 240 ++++++++++++++- .../update/PackageUpdateList.class.php | 14 +- .../update/ViewablePackageUpdate.class.php | 69 +++++ wcfsetup/install/lang/de.xml | 11 +- wcfsetup/install/lang/en.xml | 2 - 21 files changed, 771 insertions(+), 783 deletions(-) create mode 100644 wcfsetup/install/files/acp/templates/packageSearchResultList.tpl delete mode 100644 wcfsetup/install/files/acp/templates/packageUpdateSearch.tpl delete mode 100644 wcfsetup/install/files/acp/templates/packageUpdateSearchResult.tpl rename wcfsetup/install/files/acp/templates/{updateServerAdd.tpl => packageUpdateServerAdd.tpl} (85%) rename wcfsetup/install/files/acp/templates/{updateServerList.tpl => packageUpdateServerList.tpl} (52%) delete mode 100644 wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php rename wcfsetup/install/files/lib/acp/form/{UpdateServerAddForm.class.php => PackageUpdateServerAddForm.class.php} (94%) rename wcfsetup/install/files/lib/acp/form/{UpdateServerEditForm.class.php => PackageUpdateServerEditForm.class.php} (95%) delete mode 100755 wcfsetup/install/files/lib/acp/page/PackageUpdateSearchResultPage.class.php rename wcfsetup/install/files/lib/acp/page/{UpdateServerListPage.class.php => PackageUpdateServerListPage.class.php} (95%) create mode 100644 wcfsetup/install/files/lib/data/package/update/ViewablePackageUpdate.class.php diff --git a/com.woltlab.wcf/acpMenu.xml b/com.woltlab.wcf/acpMenu.xml index 1a8f1ba5c4..918faa9cf0 100644 --- a/com.woltlab.wcf/acpMenu.xml +++ b/com.woltlab.wcf/acpMenu.xml @@ -68,31 +68,17 @@ 1 - - - wcf.acp.menu.link.package.update - admin.system.package.canInstallPackage,admin.system.package.canUpdatePackage - 2 - - wcf.acp.menu.link.package - 3 + 2 - + wcf.acp.menu.link.package.server admin.system.package.canEditServer 1 - - - - wcf.acp.menu.link.package.server - admin.system.package.canEditServer - 2 - diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 260f843482..496646946b 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -599,6 +599,283 @@ 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, + + /** + * 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, + + /** + * Initializes the WCF.ACP.Package.Seach class. + */ + init: function() { + this._button = null; + this._cache = { }; + this._container = $('#packageSearch'); + 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._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 '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; + } + }, + + /** + * 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('> header > hgroup > h1 > .badge').html(count); + } + }, + + /** + * Setups pagination for current search. + */ + _setupPagination: function() { + // remove previous instances + this._content = { 1: this._packageSearchResultList.html() }; + this._packageSearchResultContainer.find('.pageNavigation').wcfPages('destroy').remove(); + + if (this._pageCount > 1) { + var $topNavigation = $('
').insertBefore(this._packageSearchResultList).wcfPages({ + activePage: this._pageNo, + maxPage: this._pageCount + }).bind('wcfpagesswitched', $.proxy(this._showPage, this)); + + var $bottomNavigation = $('
').insertAfter(this._packageSearchResultList).wcfPages({ + activePage: this._pageNo, + maxPage: this._pageCount + }).bind('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 { + WCF.DOMNodeInsertedHandler.enable(); + + // show cached content + this._packageSearchResultList.html(this._content[this._pageNo]); + + WCF.DOMNodeInsertedHandler.disable(); + } + } +}); + /** * Handles option selection. */ diff --git a/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl b/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl new file mode 100644 index 0000000000..b2e60df99f --- /dev/null +++ b/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl @@ -0,0 +1,45 @@ +{hascontent} +
+ + + + + + + + + + {event name='headColumns'} + + + + + {content} + {foreach from=$packageUpdates item=$package} + + + + + + + + + {event name='columns'} + + {/foreach} + {/content} + +
{lang}wcf.acp.package.name{/lang}{lang}wcf.acp.package.author{/lang}{lang}wcf.acp.package.version{/lang}{lang}wcf.acp.package.license{/lang}{lang}wcf.acp.package.packageDate{/lang}
+ + + {event name='buttons'} +

{$package->packageName}

{if $package->authorURL}{$package->author}{else}{$package->author}{/if}

+ {$package->getAccessibleVersion()->packageVersion} + {if $package->getAccessibleVersion()->packageUpdateVersionID != $package->getLatestVersion()->packageUpdateVersionID} + + {/if} +

{if $package->getAccessibleVersion()->licenseURL}{$package->getAccessibleVersion()->license}{else}{$package->getAccessibleVersion()->license}{/if}

{@$package->getAccessibleVersion()->packageDate|time}

+
+{hascontentelse} +

{lang}wcf.acp.package.search.error.noMatches{/lang}

+{/hascontent} \ No newline at end of file diff --git a/wcfsetup/install/files/acp/templates/packageStartInstall.tpl b/wcfsetup/install/files/acp/templates/packageStartInstall.tpl index e59a633ae1..4559b798e3 100644 --- a/wcfsetup/install/files/acp/templates/packageStartInstall.tpl +++ b/wcfsetup/install/files/acp/templates/packageStartInstall.tpl @@ -5,6 +5,16 @@ {/if} {include file='header'} + +

{lang}{@$pageTitle}{/lang}

@@ -25,55 +35,100 @@
-
-
+
+ + +
- {lang}wcf.acp.package.source{/lang} + {lang}wcf.acp.package.search.conditions{/lang} - -
-
- - {if $errorField == 'uploadPackage'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {elseif $errorType == 'phpRequirements'} - {* todo: use language variable (-> else) *} -
{$phpRequirements|print_r}
- {else} - {lang}wcf.acp.package.error.{@$errorType}{/lang} - {/if} -
- {/if} - {lang}wcf.acp.package.source.upload.description{/lang} -
+
+
+
- - -
+
+
+
+
+
+
- - {if $errorField == 'downloadPackage'} - - {lang}wcf.acp.package.error.{@$errorType}{/lang} - - {/if} - {lang}wcf.acp.package.source.download.description{/lang} + + {lang}wcf.acp.package.search.package.description{/lang}
- - {event name='sourceFields'}
- {event name='fieldsets'} +
+ +
+ +
-
- - - {if $packageID != 0}{/if} +
+ +
+ {lang}wcf.acp.package.source{/lang} + + +
+
+ + {if $errorField == 'uploadPackage'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {elseif $errorType == 'phpRequirements'} + {* todo: use language variable (-> else) *} +
{$phpRequirements|print_r}
+ {else} + {lang}wcf.acp.package.error.{@$errorType}{/lang} + {/if} +
+ {/if} + {lang}wcf.acp.package.source.upload.description{/lang} +
+ + + +
+
+ + {if $errorField == 'downloadPackage'} + + {lang}wcf.acp.package.error.{@$errorType}{/lang} + + {/if} + {lang}wcf.acp.package.source.download.description{/lang} +
+ + + {event name='sourceFields'} +
+ + {event name='fieldsets'} + +
+ + + {if $packageID != 0}{/if} +
+
- +
{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/packageUpdateSearch.tpl b/wcfsetup/install/files/acp/templates/packageUpdateSearch.tpl deleted file mode 100644 index 5c37b2c7ad..0000000000 --- a/wcfsetup/install/files/acp/templates/packageUpdateSearch.tpl +++ /dev/null @@ -1,122 +0,0 @@ -{include file='header' pageTitle='wcf.acp.packageUpdate.search'} - - - -
-
-

{lang}wcf.acp.packageUpdate.search{/lang}

-
-
- -{if $errorField} -

{lang}wcf.acp.packageUpdate.noneAvailable{/lang}

-{/if} - -{if $updateServers|count} -
-
-
- {lang}wcf.acp.packageUpdate.search.server{/lang} - -
-
-
- -
-
- -
-
- {foreach from=$updateServers item=updateServer} -
- -
- {/foreach} -
- - {event name='serverFields'} -
- -
- {lang}wcf.acp.packageUpdate.search.conditions{/lang} - -
-
-
- -
-
- -
-
- -
-
-
- -
-
- -
-
{lang}wcf.acp.packageUpdate.search.type{/lang}
-
- -
-
- -
-
- -
-
- - {event name='conditionFields'} -
- - {event name='fieldsets'} -
- -
- -
-
-{else} -

{lang}wcf.acp.updateServer.view.noneAvailable{/lang}

-{/if} - -{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/packageUpdateSearchResult.tpl b/wcfsetup/install/files/acp/templates/packageUpdateSearchResult.tpl deleted file mode 100644 index 84d1d21418..0000000000 --- a/wcfsetup/install/files/acp/templates/packageUpdateSearchResult.tpl +++ /dev/null @@ -1,125 +0,0 @@ -{include file='header' pageTitle='wcf.acp.packageUpdate.search'} - -
-
-

{lang}wcf.acp.packageUpdate.search{/lang}

-
-
- -
- {pages print=true assign=pagesLinks controller="PackageUpdateSearchResult" id=$searchID link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"} - - {hascontent} - - {/hascontent} -
- -
- {foreach from=$packages item=package} -
-
-
-

- {if $package[isApplication] == 1} - - {elseif $package[plugin] != ''} - - {else} - - {/if} - {$package[packageName]} -

-
- -
-
-
-
- - -
-
- - {if $package[author] != ''} -
-
-
- {if $package[authorURL]}{$package[author]}{else}{$package[author]}{/if} -
-
- {/if} - - {if $package[packageDescription]} -
-
{lang}wcf.acp.package.description{/lang}
-
{$package[packageDescription]}
-
- {/if} - -
- {lang}wcf.acp.packageUpdate.options{/lang} - -
-
-
- - {* update *} - {foreach from=$package[updatableInstances] item=updatableInstance} -
-
- {/foreach} -
-
-
-
-
-
- {/foreach} - -
- - -
-
- -
- {@$pagesLinks} - - {hascontent} - - {/hascontent} -
- -{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/updateServerAdd.tpl b/wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl similarity index 85% rename from wcfsetup/install/files/acp/templates/updateServerAdd.tpl rename to wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl index ab4d4285a5..bbe5a72a87 100644 --- a/wcfsetup/install/files/acp/templates/updateServerAdd.tpl +++ b/wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl @@ -21,14 +21,14 @@ -
+
{lang}wcf.acp.updateServer.data{/lang} diff --git a/wcfsetup/install/files/acp/templates/updateServerList.tpl b/wcfsetup/install/files/acp/templates/packageUpdateServerList.tpl similarity index 52% rename from wcfsetup/install/files/acp/templates/updateServerList.tpl rename to wcfsetup/install/files/acp/templates/packageUpdateServerList.tpl index b62ffd7fe1..b1926931c6 100644 --- a/wcfsetup/install/files/acp/templates/updateServerList.tpl +++ b/wcfsetup/install/files/acp/templates/packageUpdateServerList.tpl @@ -20,11 +20,11 @@ {/if}
- {pages print=true assign=pagesLinks controller="UpdateServerList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"} + {pages print=true assign=pagesLinks controller="PackageUpdateServerList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"}