Example #1
0
 /**
  * @param  string  caption
  */
 public function __construct($caption = NULL)
 {
     $this->monitor('Nette\\Forms\\Form');
     parent::__construct();
     $this->control = Html::el('input');
     $this->label = Html::el('label');
     $this->caption = $caption;
     $this->rules = new Rules($this);
 }
Example #2
0
 /**
  * Data grid column constructor.
  * @param  string  textual caption of column
  * @param  int     maximum number of dislayed characters
  */
 public function __construct($caption = NULL, $maxLength = NULL)
 {
     parent::__construct();
     $this->header = \Nette\Web\Html::el();
     $this->cell = \Nette\Web\Html::el();
     $this->caption = $caption;
     if ($maxLength !== NULL) {
         $this->maxLength = $maxLength;
     }
     $this->monitor('\\DataGrid\\DataGrid');
 }
Example #3
0
 public static function getHtml($path, $alt = "")
 {
     $path = realpath($path);
     if (!$path) {
         throw new \FileNotFoundException("File '{$path}' does not exist.");
     }
     $imageSize = @getimagesize($path);
     if (!$imageSize) {
         throw new \InvalidStateException("File '{$path}' is not image.");
     }
     return Html::el("img", array("src" => WebPath::getSrc($path), "width" => $imageSize[0], "height" => $imageSize[1], "alt" => $alt));
 }
Example #4
0
	/**
	 * Get html object
	 * @return \Nette\Web\Html
	 */
	public function getHtml()
	{
		if (empty($this->html)) {
			$this->html = Html::el("img", array(
				"src" => $this->getSrc(),
				"width" => $this->getWidth(),
				"height" => $this->getHeight(),
				"alt" => $this->getAlt(),
			));
		}
		
		return $this->html;
	}
Example #5
0
 protected function createPageFormBase($name, $new)
 {
     $form = new AppForm($this, $name);
     if (!$new) {
         $form->addHidden("id");
     }
     $form->addText("name", "Name", 40, 50);
     $form->addTextArea("description", "Description", 40, 3);
     $form->addTextArea("text", "Text", 40, 15);
     $form->addMultiSelect("tags", "Tags", Tag::findAll()->fetchPairs("id", "name"))->setOption("description", Html::el("a")->href($this->link("Tag:"))->setText("Edit tags"));
     $form->addCheckbox("allowed", "Allowed");
     $form->addSubmit("s", "Save");
     return $form;
 }
Example #6
0
 protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $grid->setModel($this->service->getGriditoModel());
     $grid->setItemsPerPage($this->service->count());
     $grid->addColumn("name", "Popis", array("renderer" => function ($node) {
         echo str_repeat(" ", $node->getLevel() * 4);
         echo Html::el("a")->href($node->getNode()->getUrl())->setText($node->getNode()->getName());
     }));
     $presenter = $this;
     $grid->addButton("add", "Přidat", array("icon" => "ui-icon-plusthick", "link" => function ($node) use($presenter) {
         return $presenter->link("add", $node->getId());
     }, "showText" => false));
     $grid->addButton("edit", "Upravit", array("icon" => "ui-icon-pencil", "link" => function ($node) use($presenter) {
         return $presenter->link("edit", $node->getId());
     }, "showText" => false));
     $grid->addButton("delete", "Smazat", array("icon" => "ui-icon-closethick", "handler" => function ($node) use($grid) {
         $node->delete();
         $grid->flashMessage("Položka menu byla smazána.");
     }, "confirmationQuestion" => function ($node) {
         return "Opravdu smazat položku " . $node->getNode()->getName() . "?";
     }, "visible" => function ($node) {
         return !$node->isRoot();
     }, "showText" => false, "ajax" => true));
     $grid->addButton("up", "Nahoru", array("icon" => "ui-icon-arrowthick-1-n", "handler" => function ($node) use($grid) {
         $node->moveAsPrevSiblingOf($node->getPrevSibling());
         $grid->flashMessage("Odkaz přesunut.");
     }, "visible" => function ($node) {
         return $node->getPrevSibling() !== null;
     }, "showText" => false, "ajax" => true));
     $grid->addButton("down", "Dolů", array("icon" => "ui-icon-arrowthick-1-s", "handler" => function ($node) use($grid) {
         $node->moveAsNextSiblingOf($node->getNextSibling());
         $grid->flashMessage("Odkaz přesunut.");
     }, "visible" => function ($node) {
         return $node->getNextSibling() !== null;
     }, "showText" => false, "ajax" => true));
 }
Example #7
0
 /**
  * Form constructor.
  * @param  string
  */
 public function __construct($name = NULL)
 {
     $this->element = Nette\Web\Html::el('form');
     $this->element->action = '';
     // RFC 1808 -> empty uri means 'this'
     $this->element->method = self::POST;
     $this->element->id = 'frm-' . $name;
     $this->monitor(__CLASS__);
     if ($name !== NULL) {
         $tracker = new HiddenField($name);
         $tracker->unmonitor(__CLASS__);
         $this[self::TRACKER_ID] = $tracker;
     }
     parent::__construct(NULL, $name);
 }
Example #8
0
	/**
	 * @param  string
	 * @return Nette\Web\Html
	 */
	protected function getWrapper($name)
	{
		$data = $this->getValue($name);
		return $data instanceof Html ? clone $data : Html::el($data);
	}
Example #9
0
$renderer->wrappers['label']['container'] = 'dt';
$renderer->wrappers['label']['suffix'] = ':';
$renderer->wrappers['control']['requiredsuffix'] = " •";
// group Personal data
$form->addGroup('Personal data');
$form->addText('name', 'Your name')->addRule(Form::FILLED, 'Enter your name');
$form->addText('age', 'Your age')->addRule(Form::FILLED, 'Enter your age')->addRule(Form::INTEGER, 'Age must be numeric value')->addRule(Form::RANGE, 'Age must be in range from %d to %d', array(10, 100));
$form->addSelect('gender', 'Your gender', $sex);
$form->addText('email', 'E-mail')->setEmptyValue('@')->addCondition(Form::FILLED)->addRule(Form::EMAIL, 'Incorrect E-mail Address');
// ... then check email
// group Shipping address
$form->addGroup('Shipping address')->setOption('embedNext', TRUE);
$form->addCheckbox('send', 'Ship to address')->addCondition(Form::EQUAL, TRUE)->toggle('sendBox');
// toggle div #sendBox
// subgroup
$form->addGroup()->setOption('container', Html::el('div')->id('sendBox'));
$form->addText('street', 'Street');
$form->addText('city', 'City')->addConditionOn($form['send'], Form::EQUAL, TRUE)->addRule(Form::FILLED, 'Enter your shipping address');
$form->addSelect('country', 'Country', $countries)->skipFirst()->addConditionOn($form['send'], Form::EQUAL, TRUE)->addRule(Form::FILLED, 'Select your country');
// group Your account
$form->addGroup('Your account');
$form->addPassword('password', 'Choose password')->addRule(Form::FILLED, 'Choose your password')->addRule(Form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3)->setOption('description', '(at least 3 characters)');
$form->addPassword('password2', 'Reenter password')->addConditionOn($form['password'], Form::VALID)->addRule(Form::FILLED, 'Reenter your password')->addRule(Form::EQUAL, 'Passwords do not match', $form['password']);
$form->addFile('avatar', 'Picture');
$form->addHidden('userid');
$form->addTextArea('note', 'Comment');
// group for buttons
$form->addGroup();
$form->addSubmit('submit', 'Send');
// Step 2: Check if form was submitted?
if ($form->isSubmitted()) {
Example #10
0
 /**
  * Get link element
  * @param string $uri
  * @param string $title
  * @return Html|string
  */
 public function getElement($uri, $title = null)
 {
     return Html::el("link")->href($uri)->type("application/rss+xml")->title($title);
 }
Example #11
0
 /**
  * Generates control's HTML element.
  * @param  mixed
  * @return Nette\Web\Html
  */
 public function getControl($key = NULL)
 {
     if ($key === NULL) {
         $container = clone $this->container;
         $separator = (string) $this->separator;
     } elseif (!isset($this->items[$key])) {
         return NULL;
     }
     $control = parent::getControl();
     $id = $control->id;
     $counter = -1;
     $value = $this->value === NULL ? NULL : (string) $this->getValue();
     $label = Html::el('label');
     foreach ($this->items as $k => $val) {
         $counter++;
         if ($key !== NULL && $key != $k) {
             continue;
         }
         // intentionally ==
         $control->id = $label->for = $id . '-' . $counter;
         $control->checked = (string) $k === $value;
         $control->value = $k;
         if ($val instanceof Html) {
             $label->setHtml($val);
         } else {
             $label->setText($this->translate($val));
         }
         if ($key !== NULL) {
             return (string) $control . (string) $label;
         }
         $container->add((string) $control . (string) $label . $separator);
         // TODO: separator after last item?
     }
     return $container;
 }
Example #12
0
 /**
  * Generates control's HTML element.
  * @return Nette\Web\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $selected = $this->getValue();
     $selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
     $option = Nette\Web\Html::el('option');
     foreach ($this->items as $key => $value) {
         if (!is_array($value)) {
             $value = array($key => $value);
             $dest = $control;
         } else {
             $dest = $control->create('optgroup')->label($key);
         }
         foreach ($value as $key2 => $value2) {
             if ($value2 instanceof Nette\Web\Html) {
                 $dest->add((string) $value2->selected(isset($selected[$key2])));
             } elseif ($this->useKeys) {
                 $dest->add((string) $option->value($key2)->selected(isset($selected[$key2]))->setText($this->translate($value2)));
             } else {
                 $dest->add((string) $option->selected(isset($selected[$value2]))->setText($this->translate($value2)));
             }
         }
     }
     return $control;
 }
Example #13
0
	protected function createComponentGrid($name)
	{
		$grid = new Grid($this, $name);

		$photoService = $this->getPhotogalleryService()->getPhotoService();
		$model = $photoService->getFinder()->whereGallery($this->getGallery())->getGriditoModel();

		$grid->setModel($model);

		// columns

		$grid->addColumn("image", "Náhled")->setRenderer(function ($photo) {
			$thumb = ThumbnailHelper::createThumbnail($photo->getImage(), 80, 80);
			echo Html::el("a")->href($photo->image->src)->target("_blank")->add($thumb->getHtml());
		});
		$grid->addColumn("description", "Popis")->setSortable(true);

		// buttons

		$presenter = $this;
		$service = $this->service;

		$grid->addButton("delete", "Smazat", array(
			"handler" => function ($entity) use ($service, $presenter, $grid) {
				$service->delete($entity);
				$galleryId = $entity->getGallery()->getId();
				$presenter->flashMessage("Fotografie byl úspěšně smazána.");
				$grid->redirect("this");
			},
			"icon" => "ui-icon-closethick",
			"confirmationQuestion" => "Opravdu chcete smazat fotografii?"
		));
	}
Example #14
0
 /**
  * Get script element
  * @param string $source
  * @return Html
  */
 public function getElement($source)
 {
     return Html::el("script")->type("text/javascript")->src($source);
 }
Example #15
0
	/**
	 * Generates control's HTML element.
	 * @return Nette\Web\Html
	 */
	public function getControl()
	{
		$control = parent::getControl();
		if ($this->skipFirst) {
			reset($this->items);
			$control->data('nette-empty-value', $this->useKeys ? key($this->items) : current($this->items));
		}
		$selected = $this->getValue();
		$selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
		$option = Nette\Web\Html::el('option');

		foreach ($this->items as $key => $value) {
			if (!is_array($value)) {
				$value = array($key => $value);
				$dest = $control;

			} else {
				$dest = $control->create('optgroup')->label($key);
			}

			foreach ($value as $key2 => $value2) {
				if ($value2 instanceof Nette\Web\Html) {
					$dest->add((string) $value2->selected(isset($selected[$key2])));

				} else {
					$key2 = $this->useKeys ? $key2 : $value2;
					$value2 = $this->translate((string) $value2);
					$dest->add((string) $option->value($key2 === $value2 ? NULL : $key2)->selected(isset($selected[$key2]))->setText($value2));
				}
			}
		}
		return $control;
	}
Example #16
0
 /**
  * @param TreeViewNode
  * @param string name
  * @return Nette\Web\Html
  */
 public function renderLink(TreeViewNode $node, $name)
 {
     $pres = $this->tree->getPresenter();
     $id = $node->getDataRow()->id;
     $nname = $this->tree->getName();
     $link = $node[$name];
     $label = $link->getLabel();
     $el = Html::el('div');
     $el->add(Html::el('img', array('src' => $this->img_move, 'height' => '16', 'class' => 'handler', 'alt' => 'move', 'style' => 'cursor: move;')));
     if ($this->useCB) {
         $cbx = Html::el('input', array('type' => 'checkbox', 'name' => $nname . '[]', 'id' => 'cbx-' . $id, 'style' => 'cursor: default;'));
         $ck = $this->checkColumn;
         if ($node->getDataRow()->{$ck}) {
             $cbx->checked = 'checked';
         }
         $url = $pres->link($this->onCB . '!');
         $cbx->onChange = "jQuery.ajax({ url: '{$url}', type: 'POST', data: { tid: {$id}, vis: this.checked}})";
         $el->add($cbx);
     }
     if (!$this->enableEditName) {
         $el->add($label);
     } else {
         if ($this->useUI) {
             //				$el->add($label);
             $el->add(Html::el('span', array('style' => 'cursor: text;', 'onClick' => "\$('#{$nname}-dform').dialog('option', 'dlgvals', { id: {$id}, meno: '{$label}'}); \$('#{$nname}-dform').dialog('option', 'nop', 'update'); \$('#{$nname}-dform').dialog('open');"))->add($label));
         } else {
             $el->add(Html::el('span', array('class' => $nname . '_click', 'id' => $id))->add($label));
         }
     }
     if ($this->enableDel) {
         $el->add(Html::el('input', array('type' => 'button', 'class' => 'etbtn_del', 'onClick' => "jQuery.ajax({ url: '" . $pres->link($this->onDel . '!', array('id' => $id)) . "', type: 'post', complete: function(data){ window.location.reload();}});")));
     }
     if ($this->useUI) {
         if ($this->enableEditName) {
             /* editBTN
             				$el->add(Html::el('input', array(
             											'type' => 'button',
             											'class' => 'etbtn_edit',
             											'onClick' => "$('#$nname-dform').dialog('option', 'dlgvals', { id: $id, meno: '$label'}); $('#$nname-dform').dialog('option', 'nop', 'update'); $('#$nname-dform').dialog('open');"
             											)));
             */
             $el->add(Html::el('input', array('type' => 'button', 'class' => 'etbtn_add', 'onClick' => "\$('#{$nname}-dform').dialog('option', 'dlgvals', { id: {$id}, meno: '{$label}'}); \$('#{$nname}-dform').dialog('option', 'nop', 'add'); \$('#{$nname}-dform').dialog('open');")));
         }
     } elseif ($this->enableAdd) {
         $el->add(Html::el('input', array('type' => 'button', 'class' => 'etbtn_add', 'onClick' => "jQuery.ajax({ url: '" . $pres->link($this->onAdd . '!', array('id' => $id)) . "', type: 'post', complete: function(data){ window.location.reload();}});")));
     }
     return $el;
 }
Example #17
0
 public static function getImageTag($mail, $size = 32)
 {
     $hash = md5(\Nette\String::lower($mail));
     $src = "http://www.gravatar.com/avatar/{$hash}?d=mm&s={$size}";
     return Html::el('img')->src($src)->alt('')->width($size)->height($size);
 }
Example #18
0

// Load libraries
require LIBS_DIR . '/Nette/loader.php';
require APP_DIR . '/routers/StaticRouter.php';
require APP_DIR . '/managers/PageManager.php';
require APP_DIR . '/classes/TemplateLocator.php';
require APP_DIR . '/classes/PresenterFactory.php';

// Enable and setup Nette\Debug
Debug::enable();
Debug::$strictMode = !Debug::$productionMode;

// Configure environment
date_default_timezone_set('Europe/Prague');
Html::$xhtml = FALSE;

// Configure application
$application = Env::getApplication();
$application->errorPresenter = 'Error';
$application->catchExceptions = Debug::$productionMode;

// Configure application context
$context = $application->getContext();
$context->addService('StaticWeb\\TemplateLocator', 'StaticWeb\\TemplateLocator');
$context->addService('StaticWeb\\PageManager', function() use ($context) {
	$manager = new PageManager();
	$manager->setContext($context);
	return $manager;
});
$context->addService('Nette\\Application\\IPresenterFactory', function() use ($context) {
Example #19
0
 /**
  * Create button element
  * @param mixed $row
  * @return Html
  */
 protected function createButton($row = null)
 {
     $el = Html::el("a")->href($this->getButtonLink($row))->setText($this->label);
     if ($this->icon) {
         $el->icon("ui-icon-" . $this->icon);
     }
     return $el;
 }
Example #20
0
 /**
  * Get link element
  * @param string $source
  * @return Html
  */
 public function getElement($source)
 {
     return Html::el("link")->rel("stylesheet")->type("text/css")->media($this->media)->href($source);
 }
Example #21
0
 /**
  * @param  string
  * @return Html
  */
 protected function getWrapper($name)
 {
     $data = $this->getValue($name);
     if ($data instanceof \Nette\Web\Html) {
         return clone $data;
     } elseif ($data === NULL) {
         return NULL;
     }
     $el = \Nette\Web\Html::el($data);
     $pattern = '/(?<attr>[\\w]+)="(?<value>[\\w|\\s|_| |-]+)"/i';
     if (preg_match_all($pattern, $data, $matches)) {
         $attrs = array();
         foreach ($matches['attr'] as $key => $attr) {
             $attrs[$attr] = explode(' ', $matches['value'][$key]);
         }
         $el->attrs = $attrs;
     }
     return $el;
 }
Example #22
0
 /**
  * Create button element
  * @param mixed row
  * @return Nette\Web\Html
  */
 protected function createButton($row = null)
 {
     return Html::el("a")->href($this->getLink($row))->data("gridito-icon", $this->icon)->class(array("gridito-button", $this->showText ? null : "gridito-hide-text"))->setText($this->label);
 }