v7‰PNG  IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ± üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0A­ºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT PKC\Aˢww Abstract.phpnu[hasPermissions()) { $grid->addCallback(Am_Grid_ReadOnly::CB_TR_ATTRIBS, array($this, 'getTrAttribs')); $grid->addCallback(Am_Grid_Editable::CB_RENDER_CONTENT, array($this, 'renderContent')); $grid->prependField(new Am_Grid_Field_Sort('_sort')); } } final public function getTrAttribs(array & $attribs, $obj) { $grid_id = $this->grid->getId(); $params = array( $grid_id . '_' . Am_Grid_ReadOnly::ACTION_KEY => $this->getId(), $grid_id . '_' . Am_Grid_ReadOnly::ID_KEY => $this->grid->getDataSource()->getIdForRecord($obj), ); $attribs['data-params'] = json_encode($params); $attribs['data-sort-record'] = json_encode($this->getRecordParams($obj)); } public function renderContent(& $out, Am_Grid_Editable $grid) { $url = json_encode($grid->makeUrl()); $grid_id = $this->grid->getId(); $msg = ___("Drag&Drop rows to change display order. You may want to temporary change setting '%sRecords per Page (for grids)%s' to some big value so all records were on one page and you can arrange all items.", '',''); $out .= <<$msg CUT; } public function run() { $request = $this->grid->getRequest(); $id = $request->getFiltered('id'); $move_before = $request->getParam('move_before', null); $move_after = $request->getParam('move_after', null); $move_item = $request->getParam('move_item'); $resp = array( 'ok' => true, ); if ($this->callback) $resp['callback'] = $this->callback; try { $this->setSortBetween($move_item, $move_after, $move_before); } catch (Exception $e) { throw $e; $resp = array('ok' => false, ); } Am_Di::getInstance()->response->ajaxResponse($resp); exit(); } protected function getRecordParams($obj) { return array( 'id' => $this->grid->getDataSource()->getIdForRecord($obj), ); } abstract protected function setSortBetween($item, $after, $before); } class Am_Grid_Field_Sort extends Am_Grid_Field { public function __construct($field='_', $title=null, $sortable = true, $align = null, $renderFunc = null, $width = null) { parent::__construct($field, '', false); $this->addDecorator(new Am_Grid_Field_Decorator_Sort()); } public function render($obj, $grid) { /* @var $grid Am_Grid_ReadOnly */ return $grid->getRequest()->getParam('sort') ? '' : ' '; } } class Am_Grid_Field_Decorator_Sort extends Am_Grid_Field_Decorator_Abstract { function renderTitle(& $out, $controller) { /* @var $controller Am_Grid_ReadOnly */ $out = $controller->getRequest()->getParam('sort') ? '' : preg_replace('#^(table = $table->getName(true); } protected function getRecordParams($obj) { return array( 'id' => $obj->name, ); } protected function setSortBetween($item, $after, $before) { $after = $after ? $after['id'] : null; $before = $before ? $before['id'] : null; $id = $item['id']; $db = Am_Di::getInstance()->db; $item = $db->selectRow("SELECT * FROM ?_custom_field_sort WHERE custom_field_name=? AND custom_field_table=? ", $id, $this->table); if ($before) { $beforeItem = $db->selectRow("SELECT * FROM ?_custom_field_sort WHERE custom_field_name=? AND custom_field_table=? ", $before, $this->table); $sign = $beforeItem['sort_order'] > $item['sort_order'] ? '-': '+'; $newSortOrder = $beforeItem['sort_order'] > $item['sort_order'] ? $beforeItem['sort_order']-1: $beforeItem['sort_order']; $db->query("UPDATE ?_custom_field_sort SET sort_order=sort_order{$sign}1 WHERE sort_order BETWEEN ? AND ? AND custom_field_name<>? AND custom_field_table=?", min($newSortOrder, $item['sort_order']), max($newSortOrder, $item['sort_order']), $id, $this->table); $db->query("UPDATE ?_custom_field_sort SET sort_order=? WHERE custom_field_name=? AND custom_field_table=?", $newSortOrder, $id, $this->table); } elseif ($after) { $afterItem = $db->selectRow("SELECT * FROM ?_custom_field_sort WHERE custom_field_name=? AND custom_field_table=? ", $after, $this->table); $sign = $afterItem['sort_order'] > $item['sort_order'] ? '-': '+'; $newSortOrder = $afterItem['sort_order'] > $item['sort_order'] ? $afterItem['sort_order']: $afterItem['sort_order']+1; $db->query("UPDATE ?_custom_field_sort SET sort_order=sort_order{$sign}1 WHERE sort_order BETWEEN ? AND ? AND custom_field_name<>? AND custom_field_table=?", min($newSortOrder, $item['sort_order']), max($newSortOrder, $item['sort_order']), $id, $this->table); $db->query("UPDATE ?_custom_field_sort SET sort_order=? WHERE custom_field_name=? AND custom_field_table=?", $newSortOrder, $id, $this->table); } } }PKC\Aˢww Abstract.phpnu[PKC\) CustomField.phpnu[PK#