protected function renderContextItem($arr) { $items = ""; $def_items = array('add' => array('fn' => "function(){ \${$this->grid_full_id}.jqGrid('editGridRow','new', {serializeEditData:function(post) { post.className = \${$this->grid_full_id}.jqGrid('getPostDataItem', 'className'); return post;}, closeAfterAdd:true}); }", 'text' => 'Добавить', 'iconClass' => 'add_icon'), 'edit' => array('fn' => "function(id){ \${$this->grid_full_id}.jqGrid('editGridRow',id, {serializeEditData:function(post) { post.className = \${$this->grid_full_id}.jqGrid('getPostDataItem', 'className'); return post;}, closeAfterEdit:true}); }", 'text' => 'Редактировать', 'iconClass' => 'edit_icon'), 'del' => array('fn' => "function(id){ \${$this->grid_full_id}.jqGrid('delGridRow',id, {serializeDelData:function(post) { post.className = \${$this->grid_full_id}.jqGrid('getPostDataItem', 'className'); return post;}}); }", 'text' => 'Удалить', 'iconClass' => 'delete_icon')); foreach ($arr as $k => $v) { $id = is_numeric($k) ? $v : $k; $def = is_numeric($k) ? array() : $v; if (!empty($def_items[$id])) { $def = array_merge($def_items[$id], $def); } if (!empty($def['grant']) && !user_bo::grant($def['grant'], false)) { continue; } $items .= "'{$id}': {name: '{$def['text']}',"; if (isset($def['fn'])) { $items .= "callback: function() { var fn={$def['fn']}; fn(\${$this->grid_full_id}.jqGrid('getSelected')); },"; } if (isset($def['iconClass'])) { $items .= "className: '{$def['iconClass']}',"; } // условие hideIf if (isset($def['hideIf'])) { foreach ($def['hideIf'] as $k => &$v) { if (!is_array($v)) { $v = array($v); } foreach ($v as &$i) { $i = strval($i); } } $items .= "hideIf:" . json_encode($def['hideIf']); } // условие showIf if (isset($def['showIf'])) { foreach ($def['showIf'] as $k => &$v) { if (!is_array($v)) { $v = array($v); } foreach ($v as &$i) { $i = strval($i); } } $items .= "showIf:" . json_encode($def['showIf']); } if (!empty($def['items'])) { $items .= "items:" . $this->renderContextItem($def['items']); } $items .= "},"; } $items = "{" . trim($items, ',') . "}"; return $items; }