2017 © Pedro Peláez
 

library dialog-control

Modal windows for Nette Framework

image

miloslavkostir/dialog-control

Modal windows for Nette Framework

  • Thursday, July 16, 2015
  • by miloslavkostir
  • Repository
  • 1 Watchers
  • 0 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

DialogControl

DialogControl is component for create modal windows in Nette Framework., (*1)

Requirements

DialogControl requires Nette Framework 2.0.0 or higher and PHP 5.3 or later., (*2)

Installation

Install using composer:, (*3)

$ composer require miloslavkostir/dialog-control

And load css files from vendor/miloslavkostir/dialog-control/resources., (*4)

Getting started

1.Create control in presenter, (*5)

protected function createComponentDialog(){
    return new \MiloslavKostir\DialogControl\DialogControl;
}

2.Put control into template, (*6)

{control dialog} 

Usage

Show "Hello world" in modal window

You must init the window (the best place for init is action method) :, (*7)

// presenter
public function defaultAction(){
    $this->getComponent('dialog')->init('show-message', function($dialog){
        $dialog->message('Hello world')->open();
    });
}
<!-- template -->
<a n:href="this dialogDo => show-message">Show message</a>

Click on "Show message" and you should see modal window., (*8)

Self-init or triggering

The callback in second parameter of init() is execute when value of first parameter equal to value of parameter 'dialogDo' in query URL. It's self-initialization. But you can trigger the window by another event:, (*9)

// presenter
public function defaultAction(){
    if(!$this->user->isLoggedIn()){
        // You can write init(NULL, function($dialog){...}); or just init(function($dialog){...});
        $this->getComponent('dialog')->init(NULL, function($dialog){  
            $dialog->message('You are'n logged in', 'error')->open();
        });
    }
}

Not just message

Method message() isn't only one what you can use. Try this:, (*10)

$this->getComponent('dialog')->init(NULL, function($dialog){

    $dialog->html(Nette\Utils\Html::el('span')->setClass('error')->setText('This is error'));  // adds HTML element (see Nette\Utils\Html)
    $dialog->message('In fact, message() is shortcut for html()', 'error', 'span');  // the same as html() above
    $dialog->control($this['myForm']);  // adds control for instant render

    $dialog->open();  // opens window and render all set elements 
}

Rendering block

If you need to render window manualy, you can use method block(). First parameter is name of block, second parameter is path to file. Second parameter is optional, then you must specify directory with dialog templates in constructor., (*11)

$this->getComponent('dialog')->init('show-block', function($dialog){
    $dialog->block('loginDialog', 'path/to/loginDialog.latte')->open();
}

If you want to render control in this block, you must create control in DialogControl component. Use createControl() for it., (*12)

// presenter
protected function createComponentLoginForm(){
    $form = new \Nette\Application\UI\Form;

    $form->addText('login', 'Login');
    $form->addPassword('password', 'Password');
    $form->addSubmit('submit');
    ... 
    return $form;
}


$this->getComponent('dialog')->init('show-block', function($dialog){
    $dialog->block('loginDialog', 'path/to/loginDialog.latte')
            ->createControl('loginForm', $this->createComponentLoginForm())
            ->open();
}

```html {* template loginDialog.latte *} {block loginDialog} , (*13)

Login

{form loginForm} {label login}{input login}
{label password}{input password}
{input submit}
{/form} {/block}

####Advanced useage Whole DialogControl is possible to move into own class. Then you will use method configure instead of callback ```php namespace Components; use Nette; class AdvancedDialogControl extends \MiloslavKostir\DialogControl\DialogControl { protected function configure($presenter){ $this->block('advancedDialog', __DIR__.'/advancedDialogControl.latte'); $this->open(); } protected function createComponentSomeForm(){ $form = new Nette\Application\UI\Form; $form->addText('name', 'Your name'); $form->addSubmit('submit'); $form->onSuccess[] = $this->someFormSucceeded; return $form; } public function someFormSucceeded($form){ $this->presenter->flashMessage('My name is '.$form->value->name); $this->redirect('this'); } }

advancedDialogControl.latte, (*14)

{block advancedDialog}


Advanced usage of DialogControl

{form someForm} {label name}{input name}<br> {input submit}<br> {/form} {/block}

In presenter :, (*15)

protected function createComponentAdvancedDialog(){
    return new \Components\AdvancedDialogControl();
}

public function defaultAction(){
    $this->getComponent('advancedDialog')->init('show');
    // or trigger
    if(!$this->user->isLoggedIn()){
        $this->getComponent('advancedDialog')->init();
    }
}

The Versions

16/07 2015

dev-master

9999999-dev

Modal windows for Nette Framework

  Sources   Download

BSD-3

The Requires

 

by Miloslav Koštíř

nette dialog window modal window dialog-control

14/03 2015

v1.0

1.0.0.0

Modal windows for Nette Framework

  Sources   Download

BSD-3

The Requires

 

by Miloslav Koštíř

nette dialog window modal window dialog-control