Fork me on GitHub

Mesour Nette Bridges

Nette bridges for session, link and application

Packagist

  • None
  • None

Installation

Suggests

  • None

Sandbox

composer create-project mesour/nette-sandbox -s beta

Extension in config.neon

extensions:
    mesourApplication: Mesour\Bridges\Nette\DI\ApplicationExtension

Can change application name, default is mesourapp

mesourApplication:
    name: my_app_name

Usage

Info Best way is create own implementation for components and use it as Nette Control. Example here below for DataGrid:

For DataGrid

Info You may create BaseGridControl for all applications grids. See next code:
abstract class BaseGridControl extends Mesour\Bridges\Nette\DataGridControl
{

    public function attached($presenter)
    {
        parent::attached($presenter);

        $grid = $this->getGrid();

        //!set translator and everything you want
        $grid->setTranslator($translator);
    }

    public function setSource(IGridSource $source)
    {
        $this->getGrid()->setSource($source);
    }

}

FooDataGridControl

/**
  * @method onCellEdited(FooDataGridControl $control, $lineId, $columnName, $newValue, $oldValue, $dataValue = null)
  */
class FooDataGridControl extends BaseGridControl
{

    public $onCellEdited = [];

    public function attached($presenter)
    {
        parent::attached($presenter);

        $grid = $this->getGrid();

        //!set columns, enable extensions, etc.
        $grid->addText('name', 'Name');

        $grid->addDate('last_login', 'Last login')
            ->setFormat('Y-m-d H:i:s');

        $grid->enablePager();

        // set events
        $grid->onEditCell[] = [$this, 'processOnEditCell']

        //! ...
    }

    public function processOnEditCell($lineId, $columnName, $newValue, $oldValue, $dataValue = null)
    {
        //! save to database

        $this->onCellEdited($this, $lineId, $columnName, $newValue, $oldValue, $dataValue);
    }

}

FooPresenter

class FooPresenter extends BasePresenter
{

    public function createComponentFooDataGrid($name)
    {
        $gridControl = new FooDataGridControl($this, $name);

        //! set some events for example
        $gridControl->onCellEdited[] = function(FooDataGridControl $control, $lineId, $columnName, $newValue, $oldValue) {
            $this->flashMessage(
                sprintf('Column %s was changed from %s to %s.', $columnName, $oldValue, $newValue)
            );

            $this->redrawControl();
        };

        return $gridControl->create(); //! important! Call method create before render
    }

}

default.latte

{control fooDataGrid}