N'hésitez pas à me le signaler si nécessaire via le formulaire de contact.
Voici un nouveau module pratique qui va nous permettre de naviguer plus facilement dans l’administration des produits Prestashop. ( versions 1.4)
Dans le cas ou certaines catégories contiennent beaucoup de produits, la navigation au sein de ces produits peut être compliquée.
Dans l’exemple ci-dessus, pour atteindre la page 49 , il serait nécessaire de cliquer pas moins de 48 fois ! ( en conservant la pagination à 50 élément j’en conviens 😉 , mais c’est pour l’exemple )
Nous allons donc remplacer le texte correspondant à la page en cours par un champ texte, qui nous permettra de saisir sur quelle page nous souhaitons nous rendre.
Pour ce faire il est nécessaire de surcharger la fonction displayListHeader de la classe AdminTab.
Voici le contenu de ma surcharge.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | <?php class AdminTab extends AdminTabCore { /** * Display list header (filtering, pagination and column names) * * @global string $currentIndex Current URL in order to keep current Tab */ public function displayListHeader($token = NULL) { global $currentIndex, $cookie; $isCms = false; if (preg_match('/cms/Ui', $this->identifier)) $isCms = true; $id_cat = Tools::getValue('id_'.($isCms ? 'cms_' : '').'category'); if (!isset($token) OR empty($token)) $token = $this->token; /* Determine total page number */ $totalPages = ceil($this->_listTotal / Tools::getValue('pagination', (isset($cookie->{$this->table.'_pagination'}) ? $cookie->{$this->table.'_pagination'} : $this->_pagination[0]))); if (!$totalPages) $totalPages = 1; echo '<a name="'.$this->table.'"> </a>'; echo '<form method="post" action="'.$currentIndex; if (Tools::getIsset($this->identifier)) echo '&'.$this->identifier.'='.(int)(Tools::getValue($this->identifier)); echo '&token='.$token; if (Tools::getIsset($this->table.'Orderby')) echo '&'.$this->table.'Orderby='.urlencode($this->_orderBy).'&'.$this->table.'Orderway='.urlencode(strtolower($this->_orderWay)); echo '#'.$this->table.'"> <input type="hidden" id="submitFilter'.$this->table.'" name="submitFilter'.$this->table.'" value="0"> <table> <tr> <td style="vertical-align: bottom;"> <span style="float: left;">'; /* Determine current page number */ $page = (int)(Tools::getValue('submitFilter'.$this->table)); if (!$page) $page = 1; if ($page > 1) echo ' <input type="image" src="../img/admin/list-prev2.gif" onclick="getE(\'submitFilter'.$this->table.'\').value=1"/> <input type="image" src="../img/admin/list-prev.gif" onclick="getE(\'submitFilter'.$this->table.'\').value='.($page - 1).'"/> '; echo $this->l('Page').' <input type="text" id="changePage'.$this->table.'" value="'.$page.'" style="width:25px;text-align:center;" onblur="getE(\'submitFilter'.$this->table.'\').value=this.value"/> / '.$totalPages; if ($page < $totalPages) echo ' <input type="image" src="../img/admin/list-next.gif" onclick="getE(\'submitFilter'.$this->table.'\').value='.($page + 1).'"/> <input type="image" src="../img/admin/list-next2.gif" onclick="getE(\'submitFilter'.$this->table.'\').value='.$totalPages.'"/>'; echo ' | '.$this->l('Display').' <select name="pagination">'; /* Choose number of results per page */ $selectedPagination = Tools::getValue('pagination', (isset($cookie->{$this->table.'_pagination'}) ? $cookie->{$this->table.'_pagination'} : NULL)); foreach ($this->_pagination AS $value) echo '<option value="'.(int)($value).'"'.($selectedPagination == $value ? ' selected="selected"' : (($selectedPagination == NULL && $value == $this->_pagination[1]) ? ' selected="selected2"' : '')).'>'.(int)($value).'</option>'; echo ' </select> / '.(int)($this->_listTotal).' '.$this->l('result(s)').' </span> <span style="float: right;"> <input type="submit" name="submitReset'.$this->table.'" value="'.$this->l('Reset').'" /> <input type="submit" id="submitFilterButton_'.$this->table.'" name="submitFilter" value="'.$this->l('Filter').'" /> </span> <span></span> </td> </tr> <tr> <td>'; /* Display column names and arrows for ordering (ASC, DESC) */ if (array_key_exists($this->identifier,$this->identifiersDnd) AND $this->_orderBy == 'position') { echo ' <script type="text/javascript" src="../js/jquery/jquery.tablednd_0_5.js"></script> <script type="text/javascript"> var token = \''.($token!=NULL ? $token : $this->token).'\'; var come_from = \''.$this->table.'\'; var alternate = \''.($this->_orderWay == 'DESC' ? '1' : '0' ).'\'; </script> <script type="text/javascript" src="../js/admin-dnd.js"></script> '; } echo '<table'.(array_key_exists($this->identifier,$this->identifiersDnd) ? ' id="'.(((int)(Tools::getValue($this->identifiersDnd[$this->identifier], 1))) ? substr($this->identifier,3,strlen($this->identifier)) : '').'"' : '' ).' cellpadding="0" cellspacing="0"> <thead> <tr> <th>'; if ($this->delete) echo ' <input type="checkbox" name="checkme" onclick="checkDelBoxes(this.form, \''.$this->table.'Box[]\', this.checked)" />'; echo ' </th>'; foreach ($this->fieldsDisplay AS $key => $params) { echo ' <th '.(isset($params['widthColumn']) ? 'style="width: '.$params['widthColumn'].'px"' : '').'>'.$params['title']; if (!isset($params['orderby']) OR $params['orderby']) { // Cleaning links if (Tools::getValue($this->table.'Orderby') && Tools::getValue($this->table.'Orderway')) $currentIndex = preg_replace('/&'.$this->table.'Orderby=([a-z _]*)&'.$this->table.'Orderway=([a-z]*)/i', '', $currentIndex); echo ' <br /> <a href="'.$currentIndex.'&'.$this->identifier.'='.$id_cat.'&'.$this->table.'Orderby='.urlencode($key).'&'.$this->table.'Orderway=desc&token='.$token.'"><img border="0" src="../img/admin/down'.((isset($this->_orderBy) AND ($key == $this->_orderBy) AND ($this->_orderWay == 'DESC')) ? '_d' : '').'.gif" /></a> <a href="'.$currentIndex.'&'.$this->identifier.'='.$id_cat.'&'.$this->table.'Orderby='.urlencode($key).'&'.$this->table.'Orderway=asc&token='.$token.'"><img border="0" src="../img/admin/up'.((isset($this->_orderBy) AND ($key == $this->_orderBy) AND ($this->_orderWay == 'ASC')) ? '_d' : '').'.gif" /></a>'; } echo ' </th>'; } /* Check if object can be modified, deleted or detailed */ if ($this->edit OR $this->delete OR ($this->view AND $this->view !== 'noActionColumn')) echo ' <th style="width: 52px">'.$this->l('Actions').'</th>'; echo ' </tr> <tr style="height: 35px;"> <td>'; if ($this->delete) echo ' --'; echo ' </td>'; /* Javascript hack in order to catch ENTER keypress event */ $keyPress = 'onkeypress="formSubmit(event, \'submitFilterButton_'.$this->table.'\');"'; /* Filters (input, select, date or bool) */ foreach ($this->fieldsDisplay AS $key => $params) { $width = (isset($params['width']) ? ' style="width: '.(int)($params['width']).'px;"' : ''); echo '<td'.(isset($params['align']) ? '' : '').'>'; if (!isset($params['type'])) $params['type'] = 'text'; $value = Tools::getValue($this->table.'Filter_'.(array_key_exists('filter_key', $params) ? $params['filter_key'] : $key)); if (isset($params['search']) AND !$params['search']) { echo '--</td>'; continue; } switch ($params['type']) { case 'bool': echo ' <select name="'.$this->table.'Filter_'.$key.'"> <option value="">--</option> <option value="1"'.($value == 1 ? ' selected="selected"' : '').'>'.$this->l('Yes').'</option> <option value="0"'.(($value == 0 AND $value != '') ? ' selected="selected"' : '').'>'.$this->l('No').'</option> </select>'; break; case 'date': case 'datetime': if (is_string($value)) $value = unserialize($value); if (!Validate::isCleanHtml($value[0]) OR !Validate::isCleanHtml($value[1])) $value = ''; $name = $this->table.'Filter_'.(isset($params['filter_key']) ? $params['filter_key'] : $key); $nameId = str_replace('!', '__', $name); includeDatepicker(array($nameId.'_0', $nameId.'_1')); echo $this->l('From').' <input type="text" id="'.$nameId.'_0" name="'.$name.'[0]" value="'.(isset($value[0]) ? $value[0] : '').'"'.$width.' '.$keyPress.' /><br /> '.$this->l('To').' <input type="text" id="'.$nameId.'_1" name="'.$name.'[1]" value="'.(isset($value[1]) ? $value[1] : '').'"'.$width.' '.$keyPress.' />'; break; case 'select': if (isset($params['filter_key'])) { echo '<select onchange="$(\'#submitFilter'.$this->table.'\').focus();$(\'#submitFilter'.$this->table.'\').click();" name="'.$this->table.'Filter_'.$params['filter_key'].'" '.(isset($params['width']) ? 'style="width: '.$params['width'].'px"' : '').'> <option value=""'.(($value == 0 AND $value != '') ? ' selected="selected"' : '').'>--</option>'; if (isset($params['select']) AND is_array($params['select'])) foreach ($params['select'] AS $optionValue => $optionDisplay) { echo '<option value="'.$optionValue.'"'.((isset($_POST[$this->table.'Filter_'.$params['filter_key']]) AND Tools::getValue($this->table.'Filter_'.$params['filter_key']) == $optionValue AND Tools::getValue($this->table.'Filter_'.$params['filter_key']) != '') ? ' selected="selected"' : '').'>'.$optionDisplay.'</option>'; } echo '</select>'; break; } case 'text': default: if (!Validate::isCleanHtml($value)) $value = ''; echo '<input type="text" name="'.$this->table.'Filter_'.(isset($params['filter_key']) ? $params['filter_key'] : $key).'" value="'.htmlentities($value, ENT_COMPAT, 'UTF-8').'"'.$width.' '.$keyPress.' />'; } echo '</td>'; } if ($this->edit OR $this->delete OR ($this->view AND $this->view !== 'noActionColumn')) echo '<td>--</td>'; echo '</tr> </thead>'; } } ?> |
Le changement se situe à ligne 45 ou le code existant :
echo $this->l('Page').' <b>'.$page.'</b> / '.$totalPages; |
a été remplacé par le code suivant :
echo $this->l('Page').' <input type="text" id="changePage'.$this->table.'" value="'.$page.'" style="width:25px;text-align:center;" onblur="getE(\'submitFilter'.$this->table.'\').value=this.value"/> / '.$totalPages; |
Si vous souhaitez ajouter facilement cette fonctionnalité, vous pouvez au choix copier coller le contenu ci-dessus dans une classe « AdminTab » dans le dossier « override/classes », ou télécharger le module qui le fera tout seul 😉