public function start_control($compiler, $node) { echo "<?"; ?> if(!($_formControlModel->modelCache->hasField('<?php echo $node->getAttribute("name"); ?> '))) { echo '<div class="mvcControlWarning" style="color: red">Warning, model ' . $_formControlModel->modelName . ' has no member ' . 'named <?php echo $node->getAttribute("name"); ?> </div>'; } <?php echo "?>"; /* * If the node has children, then we assume that a label is also defined in the tag and we create the div and all. * If not, we create just the input -elemnt */ if ($node->hasChildNodes()) { echo $this->html->element("div", $this->html->element("label", ViewCompiler::collect($node), array("for" => $node->getAttribute("name"))) . $this->generateErrorCode($node->getAttribute("name")) . $this->html->element("input", null, ViewCompiler::attributesAsArray($node->attributes)), array("class" => "mvcInput", "id" => "inputFld" . $node->getAttribute("name"))); } else { echo $this->html->element("input", null, ViewCompiler::attributesAsArray($node->attributes)); } return false; }
public function start_control($compiler, $node) { echo "<?"; ?> if(!($_formControlModel->modelCache->hasField('<?php echo $node->getAttribute("name"); ?> '))) { echo '<div class="mvcControlWarning" style="color: red">Warning, model ' . $_formControlModel->modelName . ' has no member ' . 'named <?php echo $node->getAttribute("name"); ?> </div>'; } <?php echo "?>"; $labelNodes = $node->getElementsByTagNameNS("http://simplemvc.org/ns/2010", "label"); $labels = array(); for ($i = 0; $i < $labelNodes->length; $i++) { $label = $labelNodes->item($i); $labels[$label->getAttribute("for")] = ViewCompiler::collect($label); } ?> <div class="mvcInput" id="inputFld<?php echo $node->getAttribute("name"); ?> "> <label for="<?php echo $node->getAttribute("name"); ?> "><?php echo $labels["password"]; ?> </label> <input type="password" name="<?php echo $node->getAttribute("name"); ?> " /> </div> <div class="mvcInput" id="inputFld<?php echo $node->getAttribute("name"); ?> _verify"> <label for="<?php echo $node->getAttribute("name"); ?> "><?php echo $labels["password_verify"]; ?> </label> <input type="password" name="<?php echo $node->getAttribute("name"); ?> _verify" /> </div> <?php return false; }
public function start_control($compiler, $node) { /* Generate the controller based on the code */ $code = ViewCompiler::collect($node); $path = ControllerGenerator::generateBasicController($compiler->controller, $compiler->method, $code); // If we don't have a parent, we create a hidden DIV that we can use to find our parent // and attach result to the parent of that div $divName = "mvcHiddenDiv" . time() . rand(100, 999); if (!$node->hasAttribute("target")) { ?> <div id="<?php echo $divName; ?> " style="display: none"></div> <?php } /* * Create JavaScript -functions to invoke this Ajax-script. If we have execute-on -defined, we automatically * create a <script>-wrapper and a function, if not, we assume the tag's inside a <script>-tag */ if ($node->hasAttribute("execute-on")) { ob_start(); } ?> $.post('<?php echo $path; ?> ', { <?php /* * See which JS -variables to export to the PHP -script. If the code automatically generates * a function, then we export any parameters, if it's embedded in JS -code, we can * define the exported variables with the "export" parameter. Both expect a comma-separated * list */ $exportVariables = $node->hasAttribute("parameters") ? explode(", ", $node->getAttribute("parameters")) : ($node->hasAttribute("export") ? explode(",", $node->getAttribute("export")) : array()); if (!empty($exportVariables)) { foreach ($exportVariables as &$param) { $param = "'{$param}': {$param}"; } echo join($exportVariables, ","); } ?> }, function(data) { <?php if ($node->hasAttribute("target")) { ?> $('<?php echo $node->getAttribute("target"); ?> ').append(data); <?php } else { ?> $('#<?php echo $divName; ?> ').parent().append(data) $('#<?php echo $divName; ?> ').remove(); <?php } ?> }); <?php /* * If we define the "execute-on" -parameter, then we create a function automatically. * * TODO: Would be nice if this could be automatically bound to events, e.g: * * execute-on="$('#foo').blur" */ if ($node->hasAttribute("execute-on")) { $script = ob_get_contents(); ob_end_clean(); ?> <script language="JavaScript" type="text/javascript"> <!-- function <?php echo $node->getAttribute("execute-on"); ?> (<?php echo $node->getAttribute("parameters"); ?> ) { <?php echo $script; ?> } //--> </script> <?php } return false; }
/** * Generates a HTML-fragment from the children of the node. */ public static function collect($elem) { $string = ""; foreach ($elem->childNodes as $node) { if ($node->nodeType == XML_ELEMENT_NODE) { // Create normal HTML -element $elemBase = "<%s" . ($node->hasAttributes() ? " %s" : "") . ($node->hasChildNodes() ? ">" : "/>"); $attributes = array(); foreach ($node->attributes as $attribute) { $attributes[] = $attribute->name . "=\"" . $attribute->value . "\""; } if ($node->hasChildNodes()) { $string .= sprintf($elemBase, $node->tagName, join($attributes, " ")); $string .= ViewCompiler::collect($node); $string .= "</" . $node->tagName . ">"; } else { $string .= sprintf($elemBase, $node->tagName, join($attributes, " ")); } } else { $string .= (string) $node->nodeValue; } } return $string; }