<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of site_menu_admin
 *
 * @author Igor Ratsun
 */
class site_menu_admin extends MX_Controller {

    public function manager() {
        // Acceess check
        if (!$this->rt_user->isAllowed('site_menu', 'edit_user_menu')) {
            $this->admin_lib->show_denied();
        }

        $this->lang->load('site_menu/admin');
        $this->load->model('site_menu/site_menu_model');
        $this->load->library('rtgrid/rtgrid_api');

        $crud = & $this->rtgrid_api;
        $crud->set_table('site_menu');
        $crud->set_primery_key('id_site_menu');

        $crud->columns('translate_name, site_menu.parent_id, site_menu.view_order, site_menu.active');
        $crud->fields('site_menu.parent_id, site_menu.href, site_menu.view_order, site_menu.active');

        foreach ($this->lang->line('field_list') as $k => $v) {
            $crud->display_as($k, $v);
        }

        $crud->multilang(new multilang('translate_name', 'site_menu_translate', 'name'));

        $crud->callback('view_order', 'spinner');
        $crud->callback('active', 'active');
        $crud->callback_column('parent_id', array($this->site_menu_model, 'get_parent_column'));
        $crud->callback_field('href', array($this->site_menu_model, 'get_pages'));
        $crud->callback_field('parent_id', array($this->site_menu_model, 'get_edit_parent_column'));
        
        // Add observers
        $this->load->helper('rtgrid/rtgrid_obs');
        $crud->attach(make_rtgrid_add_obs('site_menu', 'edit_user_menu'));
        $crud->attach(make_rtgrid_edit_obs('site_menu', 'edit_user_menu'));
        $crud->attach(make_rtgrid_delete_obs('site_menu', 'edit_user_menu'));

        return array('content' => $crud->render(), 'title' => $this->lang->line('module_name'));
    }

}
