Mokuji /www/app/AdminModule/presenters/AdminCategoriesPresenter.php

Language PHP Lines 132
MD5 Hash d9c6b5d2a199cfbc8ba3e4e3daabf11c
Repository https://github.com/bazo/Mokuji.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
class Admin_CategoriesPresenter extends Admin_SecurePresenter
{
	protected $item;
	
	public function actionDefault()
	{
		$this->view = 'categories';
        $this->template->edit = false;
        $this->template->link = $this->createAddNewLink();
	}

    public function createAddNewLink()
    {
        $link = Html::el('a')->href($this->link('newCategory!'))->class('ajax')->add(Html::el('div')->id('create-new-link')->add(Html::el('div')->id('icon'))->add(Html::el('span')->add('Create new')));
        return $link;
    }

	//GRID
	public function createComponentCategoriesGrid($name)
	{
            $grid = new DataGrid($this, $name);
            $ds = $this->model('categories')->getDs();
            $grid->bindDataTable($ds);

            $grid->keyName = 'id';
            $grid->addColumn('title', 'Title')->addFilter();

            $grid->addActionColumn('Actions');
            $grid->addAction('Edit', 'editCategory!', Html::el('span')->class('icon icon-edit'), $useAjax = TRUE);
            $grid->addAction('Delete', 'confirmForm:confirmDelete!', Html::el('span')->class('icon icon-delete'), $useAjax = TRUE);

            return $grid;
	}
	
	function createComponentConfirmForm()
    {
        $form = new ConfirmationDialog();
        $form->addConfirmer(
                        'delete', // název signálu bude 'confirmDelete!'
                        array($this, 'deleteCategory'), // callback na funkci při kliku na YES
                        'Really delete category?'  // otázka (může být i callback vracející string)
                        );
        return $form;
    }
	
	public function deleteCategory($params, $dialog)
	{
            $id = $params;
            try{
                    $this->model('categories')->delete($id);
                    $this->flash('Category deleted!');
                    if(!$this->isAjax()) $this->redirect('Categories:');
                    else
                    {
                            $this['page']->refresh('categories');
                    }
            }
            catch(DibiDriverException $e)
            {
                    $this->flash($e->getMessage());
            }
		
	}
	//END GRID
		
	//Form New Category
	public function createComponentFormCategory($name)
	{
        $form = new LiveForm($this, $name);
        $form->addText('title','Title')->addRule(Form::FILLED, 'Fill title');
        try{
                $categories = $this->model('categories')->getIdLevel();
        }
        catch(DibiDriverException $e)
        {
                $this->flash($e->getMessage());
                $categories = array();
        }
        $categories = array('0;0' => 'none') + $categories;
        $form->addSelect('parent', 'Parent', $categories);
        $form->addTextarea('description', 'Description');
        $templates = array('category' => 'default');
        $form->addSelect('template', 'template', $templates);
        $form->addButton('btnClose', 'Close');
        $form->addSubmit('btnSave', 'Save')->onClick[] =array($this, 'formNewCategorySubmitted');
	    return $form;
	} 
	
	public function formNewCategorySubmitted($button)
	{
            $form = $button->getForm();
            $values = $form->getValues();
            unset($values['btnClose']);
            try
            {
                $this->model('categories')->save($values);
                $this->flash('Category '.$values['title'].' created');
                if(!$this->isAjax())$this->redirect('Categories:');
                else
                {
                    $this->invalidateControl('grid');
                    $this->invalidateControl('form');
                }
            }
            catch(DibiDriverException $e)
            {
                    $this->flash($e->getMessage());
            }
	}
	//END Form New Category
    public function formClose(Button $button)
    {
        $this->invalidateControl('form');
    }

    public function handleNewCategory()
    {
        $this->template->edit = true;
        $this->invalidateControl('form');
        $this->flashCmd('openForm');
    }

    public function handleEditCategory()
    {
        $this->template->edit = true;
        $this->invalidateControl('form');
        $this->flashCmd('openForm');
    }
}
?>
Back to Top