Featured Posts

Updated Zend_Dojo_View_Helper_Dialog Update! I've been tinkering around with view helpers quite a bit now and I realized that a lot of what I did in the Dialog could be done much easier by extending the DijitContainer view helper. So, I...

Read more

Zend_Dojo_View_Helper_Dialog Quickie I'm going to make this one short & sweet. I've created a view helper for Dialogs (and an extended Dijit view helper). Zend_Dojo_View_Helper_Dijit_Extended (wtb: namespaces) [sourcecode language="php"] <?php /** ...

Read more

dataStore and dataGrid view helpers. Introduction Grid's are used everywhere and one thing the Zend Framework really lacks is a useful view helper to quickly generate grids and their stores. I saw that  Matthew Weier O'Phinney had a proposal...

Read more

Blitzaroo event view teaser Two weeks ago I promised a screenshot on event signups and I finally have something worth showing. Stay tuned for more shots!

Read more

Blitzaroo signups Dum da dum! So, I spent most of last night working on event signups in Blitzaroo and I ran into a situation where I'm trying to decide what features I want to implement. This blog is my attempt to get...

Read more

Updated Zend_Dojo_View_Helper_Dialog

Posted by SpiffyJr | Posted in Random | Posted on 15-03-2010

0

Update!

I’ve been tinkering around with view helpers quite a bit now and I realized that a lot of what I did in the Dialog could be done much easier by extending the DijitContainer view helper. So, I rewrote the dialog view helper to extend DijitContainer and moved Zend_Dojo_View_Helper_Dijit_Extended to Zend_Dojo_View_Helper_Dojo_Extended because the methods are meant to be used statically similar to Zend_Dojo_View_Helper::setUseDeclarative(). For those of you that have no idea what I’m talking about you should read Zend_Dojo_View_Helper_Dialog first.

New code!

Zend_Dojo_View_Helper_Dojo_Extended

This little puppy exists for the sole purpose of adding stylesheets based on the set dojo path (local/CDN) and version (if CDN).

Usage

// Code from Zend_Dojo_View_Helper_Dialog which adds the stylesheet for enhanced dialogs
Zend_Dojo_View_Helper_Dojo_Extended::addStylesheet('/dojox/widget/Dialog/Dialog.css');

Code

/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * Zend_Calendar
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Dojo_View_Helper_Dojo_Extended extends Zend_Dojo_View_Helper_Dojo
{
	/**
	 * Holds the base path for scripts.
	 */
	protected static $_scriptBase = null;

	/**
	 * Dojo for <a class="zem_slink freebase/en/method" title="Method (computer science)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Method_%28computer_science%29">static methods</a>.
	 */
	protected static $_dojo = null;

	/**
	 * View for static methods.
	 */
	protected static $_view = null;

	/**
	 * Static setting for script base.
	 * @param string $scriptBase Path to the base script directory.
	 */
	public static function setScriptBase($scriptBase)
	{
		self::$_scriptBase = $scriptBase;
	}

	/**
	 * Static getter for script base.
	 * @return string
	 */
	public static function getScriptBase()
	{
		return self::$_scriptBase;
	}

	/**
	 * Adds a stylesheet based on the dojo path (local or cdn).
	 * Method is static for situations where you need the stylesheets
	 * to render even if even the dijits haven't been called but
	 * will during execution (AJAX calls).
	 *
	 * @param string $stylesheet Path to stylesheet from base path.
	 */
	public static function addStylesheet($path)
	{
		// Set static view if necessary
		if (null === self::$_view) {
			$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
			self::$_view = $viewRenderer->view;
			self::$_dojo = self::$_view->dojo();
		}

		// Determine path to use
		if (null === self::getScriptBase()) {
			if (self::$_dojo->useLocalPath()) {
				self::setScriptBase(self::$_dojo->getLocalPath());
			} else {
				self::setScriptBase(self::$_dojo->getCdnBase() . self::$_dojo->getCdnVersion());
			}
		}

		self::$_dojo->addStylesheet(self::getScriptBase() . $path);
	}
}

Zend_Dojo_View_Helper_Dialog

Usage

This view helper can be used similar to other layout view helpers.

// Simple dialog with premade content
<?=$this->dialog('myDialog', 'I am a dialog with some content.', array('title' => 'I am a title'), array('style' => 'height: 50%; width: 50%'));

// Enhanced (dojox.widget.Dialog) dialog
<?=$this->dialog('myDialog', 'I am a dialog with some content.', array('enhanced' => true, 'title' => 'I am a title'), array('style' => 'height: 50%; width: 50%'));

// Dialog using capturing
<?php $this->dialog()->captureStart('dialog', array('title' => 'I am a title'), array());?>
I am a dialog with some content!
<?=$this->dialog()->captureEnd('dialog');?>

Code

/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_Dialog
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * Zend_Calendar
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper_Dialog
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Dojo_View_Helper_Dialog extends Zend_Dojo_View_Helper_DijitContainer
{
	const DIALOG_DOJO = 'dijit.Dialog';
	const DIALOG_DOJOX = 'dojox.widget.Dialog';

	/**
	 * Holds the default dialog type.
	 */
	public static $_dialogType = self::DIALOG_DOJO;

	/**
	 * Sets the default dialog type to use.
	 *
	 * @param string $dojoType Type of dijit to use.
	 */
	public static function setDialogType($dojoType)
	{
		switch ($dojoType) {
			case self::DIALOG_DOJOX:
				self::$_dialogType = $dojoType;
				break;
			default:
				self::$_dialogType = self::DIALOG_DOJO;
				break;
		}
	}

	/**
	 * Dialog view helper.
	 *
	 * @param string $id JavaScript id for the dialog.
	 * @param array $attribs Attributes for the dialog.
	 * @param array $options Options for the dialog.
	 */
	public function dialog($id = null, $content = '', array $params = array(), array $attribs = array())
	{
		if (0 === func_num_args()) {
			return $this;
		}

		$this->_setup($params);
		return $this->_createLayoutContainer($id, $content, $params, $attribs);
	}

	/**
	 * Begin capturing content for layout container
	 *
	 * @param  string $id
	 * @param  array $params
	 * @param  array $attribs
	 * @return void
	 */
	public function captureStart($id, array $params = array(), array $attribs = array())
	{
		$this->_setup($params);
		return parent::captureStart($id, $params, $attribs);
	}

	/**
	 * Setup the dialog type and add stylesheets if needed.
	 */
	protected function _setup($params)
	{
		$this->_module = self::$_dialogType;
		if (array_key_exists('enhanced', $params)) {
			switch ($params['enhanced']) {
				case self::DIALOG_DOJOX:
					Zend_Dojo_View_Helper_Dojo_Extended::addStylesheet('/dojox/widget/Dialog/Dialog.css');
					$this->_module = self::DIALOG_DOJOX;
					break;
				default:
					$this->_module = self::DIALOG_DOJO;
			}
			unset($params['enhanced']);
		}

		$this->_dijit = $this->_module;
	}
}

Cya’s

Thanks for reading! Keep in touch for updates to the DataGrid view helper.

Reblog this post [with Zemanta]
GD Star Rating
loading...

Write a comment

Switch to our mobile site