예제 #1
0
파일: DDList.php 프로젝트: brussens/cogear2
 /**
  * Вывод
  */
 public function render()
 {
     jqueryui();
     $items = array();
     if ($this->options->class) {
         if (!class_exists($this->options->class)) {
             return error(t('Класс <b>%s</b> не существует.', $this->options->class));
         }
         $object = new $this->options->class();
         $items = $object->findAll();
     } elseif ($this->options->items) {
         $items = $this->options->items;
     }
     if ($items) {
         $template = new Template($this->template);
         $template->options = $this->options;
         $template->items = $items;
         js(cogear()->db->folder . '/js/inline/jquery.mjs.nestedSortable.js');
         js(cogear()->db->folder . '/js/inline/nest.js');
         return $template->render();
     }
 }
예제 #2
0
파일: Gear.php 프로젝트: brussens/cogear2
 /**
  * Панель управления меню
  *
  * @param type $action
  */
 public function admin_action($action = NULL, $subaction = NULL, $param = NULL)
 {
     $this->theme->hookAdminMenu();
     $this->hookAdminMenu();
     if (!$action) {
         $menus = menu();
         $menus->order('position', 'ASC');
         if ($result = $menus->findAll()) {
             jqueryui();
             $tpl = new Template('Menu/Db/templates/list');
             $tpl->menus = $result;
             $tpl->show();
         } else {
             return event('empty');
         }
     } else {
         Menu_Db::template('Menu/templates/simple', t('Простой список'));
         Menu_Db::template('Bootstrap/templates/tabs', t('Табы Bootstrap'));
         Menu_Db::template('Bootstrap/templates/pills', t('Пилюли Bootstrap'));
         $form = new Form('Menu/forms/menu');
         $form->template->setValues(Menu_Db::$templates);
         $menu = new Menu_Db();
         if ($action == 'create') {
             $menu->object()->options = new Core_ArrayObject(array('template' => 'Bootstrap/templates/navbar', 'multiple' => 0, 'title' => 0));
             $form->remove('delete');
         } else {
             $menu->id = $action;
             if ($menu->find()) {
                 $form->object($menu);
                 $form->template->setValue($menu->object()->options->template);
                 $form->multiple->setValue($menu->object()->options->multiple);
                 $form->title->setValue($menu->object()->options->title);
             } else {
                 return event('empty');
             }
         }
         if ($result = $form->result()) {
             if ($result->delete && $menu->delete()) {
                 flash_success(t('Меню «%s» удалено!', $menu->name));
                 redirect(l('/admin/theme/menu'));
             }
             $menu->object()->options->template = $result->template;
             $menu->object()->options->multiple = $result->multiple;
             $menu->object()->options->title = $result->title;
             $menu->object()->name = $result->name;
             $menu->object()->machine_name = $result->machine_name;
             if ($menu->save()) {
                 flash_success($action == 'create' ? t('Меню «%s» создано успешно!', $menu->name) : t('Меню «%s» было успешно отредактировано!', $menu->name), '', 'growl');
                 redirect(l('/admin/theme/menu'));
             }
         }
         $form->show();
     }
 }
예제 #3
0
파일: Gear.php 프로젝트: brussens/cogear2
 /**
  * Управление виджетами
  *
  * @param mixed $action
  */
 public function widgets_action($action = 'list', $subaction = NULL)
 {
     $this->hookAdminMenu();
     new Menu_Tabs(array('name' => 'admin.theme.widgets', 'elements' => array(array('label' => icon('list') . ' ' . t('Список'), 'link' => l('/admin/theme/widgets')), array('label' => icon('plus') . ' ' . t('Добавить'), 'link' => l('/admin/theme/widgets/add') . e('uri', $this->input->get('uri')), 'class' => 'fl_r'), array('label' => icon('pencil') . ' ' . t('Редактировать'), 'link' => l('/admin/theme/widgets/' . $this->router->getSegments(3)), 'access' => check_route('widgets/(\\d+)'), 'active' => check_route('widgets/(\\d+)$'), 'class' => 'fl_r'), array('label' => icon('wrench') . ' ' . t('Настройки'), 'link' => l('/admin/theme/widgets/' . $this->router->getSegments(3) . '/options'), 'access' => check_route('widgets/(\\d+)'), 'active' => check_route('widgets/(\\d+)/options'), 'class' => 'fl_r'))));
     if ($action == 'ajax' && ($widgets = $this->input->post('widgets'))) {
         $ajax = new Ajax();
         $position = 0;
         foreach ($widgets as $config) {
             if ($widget = widget($config['id'])) {
                 $widget->region = $config['region'];
                 $widget->position = ++$position;
                 $widget->save();
             }
         }
         $this->cache->remove('widgets');
         $ajax->success = TRUE;
         $ajax->json();
     } else {
         if ($action == 'list') {
             jqueryui();
             template('Theme/templates/widgets/search')->show();
             $widget = widget();
             $widget->order('position');
             $widgets = $widget->findAll();
             // Фильтруем, если задан параметр
             if ($uri = $this->input->get('uri')) {
                 $remove_ids = array();
                 foreach ($widgets as $key => $widget) {
                     if (!check_route($widget->route, $uri)) {
                         $remove_ids[] = $key;
                     }
                 }
                 foreach ($remove_ids as $id) {
                     $widgets->offsetUnset($id);
                 }
             }
             template('Theme/templates/widgets/list', array('regions' => $this->regions, 'widgets' => $widgets))->show();
         } else {
             $form = new Form('Theme/forms/widget');
             $form->callback->setValues($this->getWidgets());
             $form->region->setValues(array_combine($this->regions, $this->regions));
             if (is_numeric($action) && ($widget = widget($action))) {
                 if ($subaction === 'options') {
                     template('Theme/templates/widgets/options.header', array('widget' => $widget))->show();
                     $class = $widget->callback;
                     $current_widget = new $class($widget->object()->options);
                     $current_widget->object($widget);
                     if ($current_widget->settings()) {
                         $this->cache->remove('widgets');
                         flash_success(t('Настройки виджета <b>%s</b> сохранены!', $widget->name), '', 'growl');
                         redirect(l(TRUE));
                     }
                     return;
                 }
                 $form->object($widget);
                 $form->callback->options->disabled = TRUE;
             } elseif ($action == 'add') {
                 if ($uri = $this->input->get('uri')) {
                     $form->route->setValue($uri);
                 }
                 if ($region = $this->input->get('region')) {
                     $form->region->setValue($region);
                 }
                 $form->remove('delete');
                 $widget = widget();
             } else {
                 return event('empty');
             }
             if ($result = $form->result()) {
                 $this->cache->remove('widgets');
                 if ($result->delete && $widget->delete()) {
                     flash_success(t('Виджет «<b>%s</b>»успешно удалён!', $widget->name), '', 'growl');
                     redirect(l('/admin/theme/widgets'));
                 }
                 if ($action == 'add') {
                     $result->position = 1 + widget()->where('region', $result->region)->countAll();
                 }
                 $widget->object()->extend($result);
                 if ($widget->save()) {
                     if ($action == 'add') {
                         flash_success(t('Виджет «<b>%s</b>» успешно добавлен!', $widget->name), '', 'growl');
                         redirect(l('/admin/theme/widgets/' . $widget->id . '/options'));
                     } else {
                         flash_success(t('Виджет  «<b>%s</b>» успешно отредактирован!', $widget->name));
                         redirect(l(TRUE));
                     }
                 }
             }
             $form->show();
         }
     }
 }