/** Manipulate XML when writing to cache. Call RedModel_Form::getFields */ public function markup($parser) { $doc = $parser->currentDocument; $node = $parser->currentNode; $frag = $doc->createDocumentFragment(); $html = RedModel_Form::getFields($this->attribs['class']); $html = $parser->parseXml($html); $frag->appendXML($html); // die ($doc->saveXML($frag)); $node->parentNode->replaceChild($frag, $node); }
public function __construct() { //if ($_REQUEST['_rv:data']) die('asdasd'); $this->beanType = RedView::args(1); $this->id = RedView::args(2); $model = "Model_{$this->beanType}"; if (!class_exists($model)) { return; } $this->name = ucwords($this->beanType); $bean = null; if ($this->id) { $bean = R::load($this->beanType, $this->id); if (!$bean->id) { return RedView::end('error', "{$this->name} not found."); } } $gridFields; $gridCols; $gridRows; $fields = RedModel_Form::getFields($model); $o = new $model(); $fieldList = explode(',', $o->getFieldList($this->id ? 'update' : 'create')); $listFieldList = explode(',', $o->getFieldList('list')); $class = get_class($this); $html = ''; $gridFields[] = array('name' => 'id', 'type' => 'text'); $gridCols[] = array('id' => 'id', 'header' => 'ID'); foreach ($fields as $k => $v) { $gridField; $gridField['name'] = $k; $gridField['type'] = 'text'; $gc; $gc['width'] = 100; $gc['id'] = $k; $gc['header'] = @$v->constraints['title']->value; $gc['header'] || ($gc['header'] = ucwords($k)); $value = htmlentities('' . @$_SESSION['_rv']['fields'][$class][$k]); $value || ($value = $value = @$bean->{$k}); $fieldType = @$v->constraints['type']->value; if ($fieldType && ucwords($fieldType[0]) == $fieldType[0]) { $gridField['type'] = 'select'; $beans = R::find(strtolower($fieldType)); $gc['editor'] = array('type' => 'select', 'options' => array()); foreach ($beans as $b) { $gc['editor']['options'][$b->id] = $b->name; } // sentinel... needs to be js identifier, but JSON can only store strings $gc['renderer'] = '~~~FK~~~'; $opts = ''; foreach ($beans as $b) { $sel = $b->id == $value ? ' selected="selected"' : ''; $opts .= "<option value='{$b->id}'{$sel}>{$b->name}</option>"; } $html .= "<label>{$v->title}<select name=\"{$k}\">{$opts}</select></label>"; } else { $click = ''; switch ($fieldType) { case 'int': case 'integer': case 'integral': //Valid rules. Array element could be 'R' - Required 'N' - Number 'E' - Email 'F' - Float $gc['editor'] = array('type' => 'text', 'validRule' => array('N')); break; case 'numeric': case 'number': case 'decimal': case 'real': case 'float': case 'double': $gc['editor'] = array('type' => 'text', 'validRule' => array('F')); break; case 'date': $gc['editor'] = array('type' => 'date'); $fmt = '%y-%m-%d'; $click = "onclick='Calendar.trigger({inputField:this})' onchange='this.value=this.value.replace(/\\//g,\"-\")'"; break; default: $gc['editor'] = array('type' => 'text'); } if (in_array($k, $fieldList)) { $html .= "<label>{$v->title}<input type=\"text\" name=\"{$k}\" value=\"{$value}\" {$click}/></label>"; } } if (in_array($k, $listFieldList)) { $gridFields[] = $gridField; $gridCols[] = $gc; } } unset($_SESSION['_rv']['fields'][$class]); $this->set('fields', $html); $this->set('gridFields', $gridFields); $this->set('gridCols', str_replace('"~~~FK~~~"', 'renderOptionText', json_encode($gridCols))); $this->set('gridAction', urlencode(RedView_Action::encodeRequest($this, 'gridAction'))); $this->getListData(); }