Example #1
0
 /**
  * DataStore view helper.
  * 
  * @param string $id JavaScript id for the data store.
  * @param string $dojoType DojoType of the data store (e.g., dojox.data.QueryReadStore)
  * @param array $attribs Attributes for the data store.
  */
 public function dataStore($id = '', $dojoType = '', array $attribs = array())
 {
     if (!$id || !$dojoType) {
         throw new SZend_Exception('Invalid arguments: required jsId and dojoType.');
     }
     $this->dojo->requireModule($dojoType);
     // Programmatic
     if ($this->_useProgrammatic()) {
         if (!$this->_useProgrammaticNoScript()) {
             $this->dojo->addJavascript('var ' . $id . ";\n");
             $js = $id . ' = ' . 'new ' . $dojoType . '(' . SZend_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'] = $dojoType;
     }
     return '<div' . $this->_htmlAttribs($attribs) . "></div>\n";
 }
Example #2
0
 /**
  * Renders javascript for programmatic declaration.
  */
 protected function _renderJavascript()
 {
     $tab = $this->_tab;
     // Grid names
     $gridName = $this->_attribs['id'] . 'Grid';
     $layoutName = $this->_attribs['id'] . 'Layout';
     $this->dojo->addJavascript('var ' . $gridName . ";\n");
     // Setup layout
     $js = $tab . 'var ' . $layoutName . " = [\n";
     foreach ($this->_fields as $f) {
         $f['attribs']['name'] = $f['label'];
         $f['attribs'] = $this->_jsonExpr($f['attribs']);
         $js .= "{$tab}{$tab}{$tab}" . SZend_Json::encode($f['attribs'], false, array('enableJsonExprFinder' => true)) . ",\n";
     }
     $js = substr($js, 0, -2);
     $js .= "];\n\n";
     // Use expressions for structure, store, formatter, and get
     $this->_attribs = $this->_jsonExpr($this->_attribs);
     $this->_attribs['structure'] = new SZend_Json_Expr($layoutName);
     // Generate grid
     $js .= $tab . $tab . $gridName . ' = ' . 'new dojox.grid.DataGrid(' . SZend_Json::encode($this->_attribs, false, array('enableJsonExprFinder' => true)) . "), document.createElement('div');\n";
     $js .= $tab . $tab . 'dojo.byId("' . $this->_attribs['id'] . '").appendChild(' . $gridName . '.domNode);' . "\n";
     $js .= $tab . $tab . $gridName . ".startup();\n";
     // Generate connects for script captures
     foreach ($this->_scriptCapture as $s) {
         $s['data'] = trim($s['data'], "\r\n");
         $args = isset($s['attribs']['args']) ? $s['attribs']['args'] : '';
         $js .= "{$tab}{$tab}dojo.connect({$gridName}, \"{$s['event']}\", function({$args}){{$s['data']}});\n";
     }
     $this->dojo->_addZendLoad("function(){\n{$tab}{$js}\n{$tab}}");
 }