Commit da61e1d3 authored by metzlerd's avatar metzlerd
Browse files

Made a section renderer that manipulates sections.

parent 5e099cdf
......@@ -701,6 +701,7 @@ class FrxEditor {
$block_name = $node->getAttributeNS($this->xmlns, 'block');
$class = $node->getAttribute("class");
$templates = $this->templateOptions();
$config['id'] = $id;
foreach ($templates as $tclass => $desc) {
if (strpos($class, $tclass)!==FALSE) {
$template_class = $tclass;
......@@ -709,6 +710,7 @@ class FrxEditor {
}
if ($template_class) {
$c = Frx::Template($template_class);
$config['class'] = $template_class;
if ($c && method_exists($c, 'scrapeConfig')) {
$c->initReportNode($node, $this->frxReport);
$config = array_merge($config,$c->scrapeConfig());
......@@ -1036,6 +1038,7 @@ class FrxEditor {
$templates[get_class($control)] = $control->templateName;
}
}
asort($templates);
return $templates;
}
......
......@@ -1172,6 +1172,11 @@ function forena_forena_controls() {
'class' => 'FrxDrupalControls',
);
$controls[] = array(
'file' => 'renderers/FrxSection.inc',
'class' => 'FrxSection',
);
$controls[] = array(
'file' => 'renderers/FrxCrosstab.inc',
'class' => 'FrxCrosstab',
......
......@@ -653,7 +653,9 @@ function forena_report_data_block_form($formid, &$form_state, $report_name, $act
function forena_report_data_block_form_validate($form, &$form_state) {
$r = Frx::Editor($form_state['values']['report_name']);
$template_class = $form_state['values']['template_class'];
$errors = $r->templateConfigFormValidate($template_class, $form_state['values']['config'], 'template][config][');
$config = array_merge($form_state['storage']['config'], $form_state['values']['config']);
$errors = $r->templateConfigFormValidate($template_class, $config, 'template][config][');
$form_state['storage']['config'] = $config;
if ($errors) foreach ($errors as $key => $message) {
form_set_error($key, $message);
}
......@@ -1402,11 +1404,11 @@ function theme_forena_element_draggable($variables) {
if (isset($element[$e_key][$ctl]['#title'])) {
$headers[$ctl] = $element[$e_key][$ctl]['#title'];
$element[$e_key][$ctl]['#title_display'] = 'invisible';
$e = drupal_render($element[$e_key][$ctl]);
$row[] = $e;
}
$e = drupal_render($element[$e_key][$ctl]);
$row[] = $e;
}
$rows[] = array('data' => $row, 'class' => array('draggable'));
......
......@@ -14,6 +14,7 @@ class FrxEmailMerge extends FrxRenderer {
public function scrapeConfig() {
$config=array();
$config['class'] = get_class($this);
$config['from'] = $this->extractXPathInnerHTML("//*[@class='email-header-from']", $this->reportDocDomNode);
$config['to']= $this->extractXPathInnerHTML("//*[@class='email-header-to']", $this->reportDocDomNode);
$config['cc'] = $this->extractXPathInnerHTML("//*[@class='email-header-cc']", $this->reportDocDomNode);
......
......@@ -26,6 +26,7 @@ class FrxMergeDocument extends FrxRenderer {
public function scrapeConfig() {
$config = array();
$config['class'] = get_class($this);
$this->extractTemplateHTML($this->reportDocDomNode, $config);
return $config;
}
......
......@@ -153,7 +153,7 @@ class FrxRenderer {
}
// Test to see if we have any nodes that contain data url
if ($node->xpath('*//@frx:*') || $frx!==NULL) {
if ($node->xpath('*//@frx:*') || $frx!==NULL || $node->xpath('*//@class')) {
$attrs = $node->attributes();
$id = (string)$attrs['id'];
$tag = $node->getName();
......@@ -545,6 +545,7 @@ class FrxRenderer {
public function scrapeConfig() {
$content = array();
$this->extractTemplateHTML($this->reportDocDomNode, $content);
return $content;
}
/**
......
<?php
class FrxSection extends FrxRenderer {
public $templateName = 'Section';
public $lastClass = '';
/**
* oull configs.
*/
public function scrapeConfig() {
$content = array();
// Determine if we are starting from a dom node
$sec=0;
$config['sections'] = array();
// put the divs in next
$nodes = $this->reportDocNode->xpath('div');
if ($nodes) foreach ($nodes as $node) {
$dom_node = dom_import_simplexml($node);
$sec++;
$id = (string) @$node['id'] ? (string)$node['id'] : 'section-' . $sec;
$config['sections'][$id] = array(
'id' => $id,
'markup' => $node->asXML(),
'class' => @(string) $node['class'] ? (string)$node['class'] : 'FrxMergeDocument',
'weight' => $sec,
);
}
return $config;
}
/**
* Generate configuration.
*/
public function configForm($config) {
$form['sections'] = array('#theme' => 'forena_element_draggable', '#draggable_id' => 'FrxContainer-sections');
if (isset($config['sections'])) foreach ($config['sections'] as $id => $section) {
$ctl = array();
$ctl['id'] = array('#type' => 'item', '#markup' => $id, '#title' => 'id');
$ctl['markup'] = array('#type' => 'value', '#value' => $section['markup']);
$ctl['class_label'] = array('#type' => 'item', '#markup' => @$section['class'], '#title' => t('Type'));
$ctl['class'] = array('#type' => 'value', '#value' => @$section['class']);
// $ctl['display'] = array('#type' => 'item', '#title' => 'html', '#markup' =>$section['markup']);
$form['sections'][$id] = $ctl;
}
return $form;
}
/**
* Validate the configuration
*/
public function configValidate(&$config) {
}
/**
* Build the template
* @param $xml
* @param $config
*/
public function generate($xml, &$config) {
if (!isset($config['sections']) || !count($config['sections'])) {
$class = @$config['class'];
$frx = '';
if (!$class || $class== 'FrxMergeDocument') {
$frx = isset($config['foreach']) ? ' frx:foreach="' . $config['foreach'] . '"' : ' frx:foreach="*"';
}
$id = isset($config['id']) ? $config['id'] : 'section-1';
$id .= '-' . strtolower(str_replace('Frx', '', $class));
$o = "<div id='$id' class='$class'$frx>";
foreach(array('header', 'content', 'footer') as $content) {
if(isset($config[$content]['value']) && trim($config[$content]['value'])) {
$o .= $config[$content]['value'];
}
}
$o .= '</div>';
$config['sections'][$id] = array(
'id' => $id,
'markup' => $o,
'class' => $class,
'weight' => 1,
);
}
$config['class'] = get_class($this);
$div = $this->blockDiv($config);
$this->removeChildren($div);
if (isset($config['sections'])) foreach ($config['sections'] as $id => $section){
$this->addFragment($div, $section['markup']);
}
}
}
\ No newline at end of file
......@@ -31,7 +31,6 @@ class FrxTable extends FrxRenderer {
}
public function generate($xml, &$config) {
$config['class'] = get_class($this);
$block = @$config['block'];
$id = @$config['id'];
if ($block) {
......
......@@ -14,7 +14,7 @@
</head>
<body>
<div frx:block="sampledb/states" id="state-block">
<div frx:block="sampledb/states" id="state-block" class="FrxTable">
<table>
<thead>
<tr>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment