Posts Tagged ‘Languages’

Zend_Dojo_View_Helper_Dialog

Friday, March 12th, 2010

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)

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

Pretty simple view helper that renders a dialog using the regular (dijit.Dialog) method or the dojox (dojox.widget.Dialog) method.

Usage

// Regular dialog
dialog('myDialog', array('title' => 'w00t!', 'content' => 'I am a w00tastic dialog'));?>

// Enhanced dojox dialog
dialog('myDialog', array('title' => 'w00t!', 'content' => 'I am a w00tastic dialog'), array('useDojox' => true);?>

Code

dojo->requireModule($dialogType);

                // Add styles
                if ($dialogType == self::DIALOG_DOJOX) {
                        self::addStylesheet('/dojox/widget/Dialog/Dialog.css');
                }

                // Programmatic
                if ($this->_useProgrammatic()) {
                        if (!$this->_useProgrammaticNoScript()) {
                                $this->dojo->addJavascript('var ' . $id . ";\n");
                                $js = $id . ' = ' . 'new ' . $dialogType . '(' . Zend_Json::encode($attribs) . ");";
                                $this->dojo->_addZendLoad("function(){{$js}}");
                        }
                        return '';
                }

                // Set extra attribs for declarative
                if (!array_key_exists('id', $attribs)) {
                        $attribs['id'] = $id;
                }

                if (!array_key_exists('jsId', $attribs)) {
                        $attribs['jsId'] = $id;
                }

                if (!array_key_exists('dojoType', $attribs)) {
                        $attribs['dojoType'] = $dialogType;
                }

                if (array_key_exists('content', $attribs)) {
                        $content = $attribs['content'];
                        unset($attribs['content']);
                }

                return '_htmlAttribs($attribs) . '>' . $content . "
\n"; } }

Hope it makes life a little easier. Enjoy!