Jump to content

fana605

Members
  • Posts

    3
  • Joined

  • Last visited

Profile Information

  • First Name
    Fernando
  • Last Name
    Marques

fana605's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hey Tuni-Soft, thanks for your help! This actually led me into to right direction. With a few tweaks I managed to activate the drag and drop reorder feature of my custom admin module. For anyone interested, this is what I've done, besides the code in the first post: Before the __contruct function, right after opening the class add this: protected $position_identifier = 'id_quicklinks'; * id_quicklinks is the primary key of the database table this module uses. This activates the drag and drop but it's not enough. It still doesn't save the order in the database. For that to work I added two more functions adapted from the controllers/admin/AdminCarriersController.php and classes/Carrier.php: public function ajaxProcessUpdatePositions() { $way = (int)Tools::getValue('way'); $id_quicklinks = (int)Tools::getValue('id'); $positions = Tools::getValue('quicklinks'); if (is_array($positions)) foreach ($positions as $position => $value) { $pos = explode('_', $value); if (isset($pos[2]) && (int)$pos[2] === $id_velcroquicklinks) { if (isset($position) && $this->updatePosition($way, $position, $id_quicklinks)) echo 'ok position '.(int)$position.' for id '.(int)$pos[1].'\r\n'; else echo '{"hasError" : true, "errors" : "Can not update id '.(int)$id_quicklinks.' to position '.(int)$position.' "}'; break; } } } And: public function updatePosition($way, $position, $id) { if (!$res = Db::getInstance()->executeS(' SELECT `id_quicklinks`, `position` FROM `'._DB_PREFIX_.'quicklinks` ORDER BY `position` ASC' )) return false; foreach ($res as $quicklinks) if ((int)$quicklinks['id_quicklinks'] == (int)$id) $moved_quicklinks = $quicklinks; if (!isset($moved_quicklinks) || !isset($position)) return false; var_dump($moved_quicklinks['position']); // < and > statements rather than BETWEEN operator // since BETWEEN is treated differently according to databases return (Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'quicklinks` SET `position`= `position` '.($way ? '- 1' : '+ 1').' WHERE `position` '.($way ? '> '.(int)$moved_quicklinks['position'].' AND `position` <= '.(int)$position : '< '.(int)$moved_quicklinks['position'].' AND `position` >= '.(int)$position.' ')) && Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'quicklinks` SET `position` = '.(int)$position.' WHERE `id_quicklinks` = '.(int)$moved_quicklinks['id_quicklinks'])); } And that's it. Works fine in my case. I'm not sure this will work for every case, but at least it should help to get into the right direction. I may be wrong but I didn't find anything in the docs that made reference to this... Thanks again Tuni-Soft!
  2. Any ideas? I'm still stuck with this one...
  3. Hi, I'm building a very simple module for PS1.6, mostly for learning purposes. It has an admin interface like you can see in this picture: I've added the position field to the list table and it shows perfectly, but the drag and drop feature doesn't work. In my module admin controller, I have this code (just the fields list part): $this->fields_list = array( 'id_quicklinks' => array( 'title' => $this->l('ID'), 'align' => 'center', 'width' => 25 ), 'titulo' => array( 'title' => $this->l('Titulo'), 'width' => 'auto' ) , 'lead' => array( 'title' => $this->l('Subtitulo'), 'width' => 'auto' ), 'position' => array( 'title' => $this->l('Ordem'), 'filter_key' => 'a!position', 'position' => 'position', 'align' => 'center', 'class' => 'fixed-width-md' ), 'active' => array( 'title' => $this->l('Publicado'), 'width' => '25', 'active' => 'status' ) ); This makes the listing table show the position field in the table like you can see in the printscreen above, but I can't drag and drop to reorder... What is missing here? Some javascript? Some option? Appreciate any help.
×
×
  • Create New...