Added JS-based pagination for phrase management
authorAlexander Ebert <ebert@woltlab.com>
Thu, 18 Dec 2014 14:58:35 +0000 (15:58 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 18 Dec 2014 14:58:35 +0000 (15:58 +0100)
wcfsetup/install/files/acp/js/WCF.ACP.Language.js
wcfsetup/install/files/acp/templates/languageItemList.tpl
wcfsetup/install/files/lib/acp/page/LanguageItemListPage.class.php

index 78286bfde10bd7753a024886f1d46bc5630ff617..8f11d52372a8ff7d3aaadd5b19b8d4098a8c439b 100644 (file)
@@ -9,6 +9,9 @@ WCF.ACP.Language = { };
 
 /**
  * Handles language item list management.
+ * 
+ * @param      integer         count
+ * @param      integer         pageNo
  */
 WCF.ACP.Language.ItemList = Class.extend({
        /**
@@ -31,8 +34,11 @@ WCF.ACP.Language.ItemList = Class.extend({
        
        /**
         * Initializes the WCF.ACP.Style.List class.
+        * 
+        * @param       integer         count
+        * @param       integer         pageNo
         */
-       init: function() {
+       init: function(count, pageNo) {
                this._proxy = new WCF.Action.Proxy({
                        success: $.proxy(this._success, this)
                });
@@ -44,6 +50,33 @@ WCF.ACP.Language.ItemList = Class.extend({
                        var self = this;
                        $button.click(function() { self._click($languageItemID); });
                }, this));
+               
+               count = parseInt(count) || 0;
+               if (count > 100) {
+                       this._createPagination(count, pageNo);
+               }
+       },
+       
+       /**
+        * Creates a pagination for current search result.
+        * 
+        * @param       integer         count
+        * @param       integer         pageNo
+        */
+       _createPagination: function(count, pageNo) {
+               $('.contentNavigation').each(function(index, contentNavigation) {
+                       var $contentNavigation = $(contentNavigation);
+                       var $nav = $('<nav />').prependTo($contentNavigation);
+                       
+                       $nav.wcfPages({
+                               activePage: parseInt(pageNo) || 1,
+                               maxPage: Math.ceil(count / 100)
+                       }).on('wcfpagesswitched', function(event, data) {
+                               var $form = $('#languageItemSearchForm');
+                               $('<input type="hidden" name="pageNo" value="' + data.activePage + '" />').appendTo($form);
+                               $form.submit();
+                       });
+               });
        },
        
        /**
index 1957a091139288eb5164372c138513769037130f..afe9dafc08041a3ff97ae34bfb5a9dcf1a630cbd 100644 (file)
@@ -4,7 +4,7 @@
 <script data-relocate="true">
        //<![CDATA[
        $(function() {
-               new WCF.ACP.Language.ItemList();
+               new WCF.ACP.Language.ItemList({@$count}, {@$pageNo});
        });
        //]]>
 </script>
@@ -15,7 +15,7 @@
 
 {include file='formError'}
 
-<form method="post" action="{link controller='LanguageItemList'}{/link}">
+<form method="post" action="{link controller='LanguageItemList'}{/link}" id="languageItemSearchForm">
        <div class="container containerPadding marginTop">
                <fieldset>
                        <legend>{lang}wcf.global.filter{/lang}</legend>
index e2239224dd07b562783e13d1e26ebcef102dd9e0..e09452da5d7883f027d65088ff5940934ada3468 100644 (file)
@@ -23,6 +23,12 @@ class LanguageItemListPage extends AbstractPage {
         */
        public $activeMenuItem = 'wcf.acp.menu.link.language.item.list';
        
+       /**
+        * number of matching phrases
+        * @var integer
+        */
+       public $count = 0;
+       
        /**
         * @see \wcf\page\AbstractPage::$neededPermissions
         */
@@ -76,6 +82,12 @@ class LanguageItemListPage extends AbstractPage {
         */
        public $availableLanguageCategories = array();
        
+       /**
+        * current page no
+        * @var integer
+        */
+       public $pageNo = 1;
+       
        /**
         * @see \wcf\page\IPage::readParameters()
         */
@@ -87,6 +99,7 @@ class LanguageItemListPage extends AbstractPage {
                if (isset($_REQUEST['languageItem'])) $this->languageItem = StringUtil::trim($_REQUEST['languageItem']);
                if (isset($_REQUEST['languageItemValue'])) $this->languageItemValue = $_REQUEST['languageItemValue'];
                if (!empty($_REQUEST['hasCustomValue'])) $this->hasCustomValue = 1;
+               if (isset($_REQUEST['pageNo'])) $this->pageNo = intval($_REQUEST['pageNo']);
        }
        
        /**
@@ -119,6 +132,17 @@ class LanguageItemListPage extends AbstractPage {
                if ($this->languageItemValue) $this->languageItemList->getConditionBuilder()->add('((languageUseCustomValue = 0 AND languageItemValue LIKE ?) OR languageCustomItemValue LIKE ?)', array('%'.$this->languageItemValue.'%', '%'.$this->languageItemValue.'%'));
                if ($this->hasCustomValue) $this->languageItemList->getConditionBuilder()->add("languageCustomItemValue IS NOT NULL");
                if (!$this->languageCategoryID) $this->languageItemList->sqlLimit = 100;
+               
+               if (!empty($_POST)) {
+                       $this->count = $this->languageItemList->countObjects();
+                       $maxPages = ceil($this->count / 100);
+                       $this->pageNo = max(min($this->pageNo, $maxPages), 1);
+                       
+                       if ($this->pageNo > 1) {
+                               $this->languageItemList->sqlOffset = ($this->pageNo - 1) * 100;
+                       }
+               }
+               
                $this->languageItemList->readObjects();
        }
        
@@ -130,6 +154,8 @@ class LanguageItemListPage extends AbstractPage {
                
                WCF::getTPL()->assign(array(
                        'objects' => $this->languageItemList,
+                       'count' => $this->count,
+                       'pageNo' => $this->pageNo,
                        'languageID' => $this->languageID,
                        'languageCategoryID' => $this->languageCategoryID,
                        'languageItem' => $this->languageItem,