public static function renderEdit($request, $module, $action, afDomAccess $view)
 {
     $fields = $view->wrapAll('fields/field');
     $submitUrl = self::getSubmitUrl($module, $action, $view);
     $validators = afEditView::getValidators($fields);
     $fileTypes = afEditView::getFileTypes($fields);
     $result = array();
     $result['success'] = true;
     $result['af_submitUrl'] = $request->getUriPrefix() . $submitUrl;
     $instance = afEditShowRenderer::fetchDataInstance($view);
     foreach (self::getFieldValues($instance, $fields) as $name => $value) {
         $result[sprintf('edit[%s]', $name)] = $value;
     }
     $result['af_formcfg'] = self::buildFormcfg($submitUrl, $validators, $fileTypes);
     return afOutput::renderText(json_encode($result));
 }
 /**
  * Returns true if the given action could be loaded with widget_load.
  * Wizards do not support that. They want to be displayed without menus.
  */
 protected function isWidgetAction($actionInstance)
 {
     $module = $actionInstance->getModuleName();
     $action = $actionInstance->getActionName();
     $doc = afConfigUtils::getOptionalDoc($module, $action);
     if (!$doc) {
         return false;
     }
     $view = afDomAccess::wrap($doc, 'view', new afVarScope($actionInstance->getVarHolder()->getAll()));
     return $view->get('@type') !== 'wizard';
 }
<?php

include dirname(__FILE__) . '/../bootstrap/dbunit.php';
$t = new lime_test(3, new lime_output_color());
$doc = afConfigUtils::getDoc('networkmonitor_snmp', 'editSnmpPackage');
$view = afDomAccess::wrap($doc, 'view');
$fields = $view->wrapAll('fields/field');
$t->is(count($fields), 3);
$t->is(afEditView::getParams($fields[1], 'validator/param'), array('class' => 'SnmpPackage', 'column' => 'name', 'unique_error' => 'This name is already used. Please choose another one!'));
$validators = json_decode('{"edit[name]":{"immValidatorUnique":{"params":{"class":"SnmpPackage","column":"name","unique_error":"This name is already used. Please choose another one!"}}},"edit[template]":{"immValidatorRequired":[]}}', true);
$t->is(afEditView::getValidators($fields), $validators);
 protected function wrapDoc($doc)
 {
     return afDomAccess::wrap($doc, 'view', new afVarScope($this->actionVars));
 }
 /**
  * Returns the initial value for form field.
  */
 public static function getFieldValue(afDomAccess $field, $object)
 {
     $value = $field->get("@value");
     $selected = $field->get("@selected");
     if (!$value) {
         if ($field->get("@type") == "checkbox" || $field->get("@type") == "radio") {
             $value = $field->get("@checked") ? "yes" : "no";
         } else {
             $source = $field->wrapAll("value");
             if (!empty($source)) {
                 $method = $source[0]->get("source@name");
                 if ($method) {
                     $value = $object->{$method}();
                 } else {
                     $class = $source[0]->get("class");
                     $method = $source[0]->get("method@name");
                     $tmp = $source[0]->wrapAll("method/param");
                     $params = array();
                     foreach ($tmp as $t) {
                         $params[] = $t->get("");
                     }
                     $result = call_user_func_array(array($class, $method), $params);
                     if ($field->get("@type") == "combo" || $field->get("@type") == "extendedCombo" || $field->get("@type") == "multicombo") {
                         if (isset($result[$selected])) {
                             $value = $result[$selected];
                         }
                     } else {
                         if ($field->get("@type") == "doublemulticombo" || $field->get("@type") == "doubletree") {
                             foreach ($result[1] as $r) {
                                 $value .= $r . ",";
                             }
                             $value = trim($value, ",");
                         }
                     }
                 }
             }
         }
     }
     return $value;
 }
 private function renderEdit($object, array $fields, array $grouping)
 {
     $exclude = array("include", "file", "hidden", "password");
     $this->pdf->setWidths(array(90, 90));
     $this->pdf->setBorders(array(0, "L"));
     $this->pdf->setAligns(array("R", "L"));
     $this->pdf->SetFontInfo(array(array("Arial", "B", 11), array("Arial", "", 11)));
     //$this->pdf->setFills(array(array(220,220,220)));
     if ($grouping) {
         foreach ($grouping as $set) {
             $printable = array();
             $refs = $set->wrapAll("ref");
             foreach ($refs as $ref) {
                 $field = afDomAccess::getByAttribute($fields, "name", $ref->get("@to"));
                 if ($field && !in_array($field->get("@type"), $exclude)) {
                     $printable[] = $field;
                 }
             }
             if (!empty($printable)) {
                 $this->printFieldSetTitle($set);
                 foreach ($printable as $field) {
                     $this->pdf->Row(array(str_replace("*", "", $field->get("@label")) . ":", "  " . $this->getFieldValue($field, $object)), true, array(), 0.5, 10);
                 }
             }
         }
     } else {
         $this->printFieldSetTitle();
         foreach ($fields as $k => $field) {
             if (!in_array($field->get("@type"), $exclude)) {
                 $this->pdf->Row(array(str_replace("*", "", $field->get("@label")) . ":", "  " . $this->getFieldValue($field, $object)), true, array(), 0.5, 10);
                 $this->pdf->setLineWidth(0.2);
             }
         }
     }
     $this->pdf->setLineWidth(0.2);
 }
 private function parseMenu(array $nodes = null, $menu = null)
 {
     if ($nodes === null) {
         $doc = $this->readDocumentByPath($this->root . "/apps/" . $this->application . "/config/menu.xml", false);
         $view = afDomAccess::wrap($doc, 'view', new afVarScope($this->attribute_holder));
         $nodes = $view->wrapAll("menu/node");
     }
     /*
     		foreach($nodes as $node) {
     				
     			$childnodes = $node->wrapAll("node");
     			$top = ($node->getParent()->getName() == "menu");
     			
     			if($top) {
     				$button = new afExtjsToolbarButton($this->layout->toolbar,array("label" => $node->get("@label"), "handler" => $node->get("@handler"),
     				"tooltip" => array("text" => $node->get("@tooltip"), "title" => $node->get("@tiptitle"))));
     				$this->buttons[$button->attributes["text"]] = array();
     			}
     			
     			if(count($childnodes)) {
     				if(!$top) {
     					$button = new afExtjsToolbarMenuItem($menu,array("label" => $node->get("@label"), "url" => $node->get("@target")));
     					$this->buttons[$button->attributes["text"]] = array();
     				}
     				$menu = new afExtjsToolbarMenu($button);
     				$this->parseMenu($childnodes,$menu);		
     			} else {
     				if(!$top) {
     					$this->buttons[$menu->containerObject->attributes["text"]][] =  $node->get("@label");
     					$item = new afExtjsToolbarMenuItem($menu,array("label" => $node->get("@label"), "url" => $node->get("@target")));
     					$item->end();	
     				}
     				
     			}
     			
     	
     			$menu = ($menus) ? $this->getMenuForNode($node,$menus) : null;
     			
     			if($node->getParent()->getName() == "menu") {
     				$buttons[] = array("button" => new afExtjsToolbarButton($toolbar,array("label" => $node->get("@label"), "handler" => $node->get("@handler"),
     				"tooltip" => array("text" => $node->get("@tooltip"), "title" => $node->get("@tiptitle")))), 
     				"node" => $node, "last" => count($childnodes) ? $childnodes[count($childnodes)-1] : null);
     			} else {
     				if(count($childnodes)) {
     					$buttons[] = array("button" => new afExtjsToolbarMenuItem($menu["menu"],array("label" => $node->get("@label"), "url" => 
     					$node->get("@target"))),"node" => $node, "last" => $childnodes[count($childnodes)-1]);
     				}
     			} 
     			
     			$button = $this->getMenuForNode($node,$buttons);
     			
     			if(count($childnodes)) {
     				$menus[] = array("menu" => new afExtjsToolbarMenu($button["button"]),"node" => $node, "last" => $childnodes[count($childnodes)-1]);
     				$this->parseMenu($childnodes,$toolbar,$menus,$buttons);	
     			} else {
     				if($menus) {
     					if($menu) {
     						$item = new afExtjsToolbarMenuItem($menu["menu"],array("label" => $node->get("@label"), "url" => $node->get("@target")));
     						$item->end();
     						if($node->getNode() === $menu["last"]->getNode()) {
     							$menu["menu"]->end();	
     						}	
     					}	
     				}
     			}
     			if(!$button["last"] || $node->getNode() === $button["last"]->getNode()) {
     				$button["button"]->end();	
     			}
     			
     		}
     */
 }