Commit 184795a2 authored by David Metzler's avatar David Metzler
Browse files

Fixed data add.

parent db455e8b
......@@ -326,7 +326,6 @@ class FrxEditor {
NULL,
'type'
);
print_r($this->simplexml);
}
/**
......@@ -660,8 +659,10 @@ class FrxEditor {
$template_class = "FrxTable";
$path = "//*[@id='$id']";
$nodes = $this->simplexml->xpath($path);
if ($nodes) ( $node = dom_import_simplexml($nodes[0]));
if (!$node) {
if ($nodes) {
$node = dom_import_simplexml($nodes[0]);
}
else {
drupal_set_message(t('Could not find %s in report', array('%s' => $id)), 'error');
return '';
}
......@@ -696,9 +697,10 @@ class FrxEditor {
public function applyTemplate($id, $template_class, $config=array()) {
$path = "//*[@id='$id']";
$nodes = $this->simplexml->xpath($path);
if ($nodes) ( $node = dom_import_simplexml($nodes[0]));
if (!$node) {
if ($nodes) {
$node = dom_import_simplexml($nodes[0]);
}
else {
drupal_set_message(t('Could not find %s in report', array('%s' => $id)), 'error');
return;
}
......@@ -736,15 +738,55 @@ class FrxEditor {
$block_name = str_replace('.', '/', $block_name);
if ($id) {
$node = $this->dom->getElementById($id);
drupal_set_message(t('Could not find id: %s', array('%s' => $id)), 'error');
return;
}
else {
$nodes = $this->dom->getElementsByTagName('body');
$pnode = $nodes->item(0);
$node = $this->dom->createElement('div');
$pnode->appendChild($node);
}
$config['block'] = $block_name;
$b = Frx::BlockEditor($block_name, $this->frxReport->block_edit_mode);
$data= $b->data($this->parms);
$this->addParameters($b->tokens());
$this->frxReport->setReport($this->dom);
$c = Frx::Template($template_class);
if ($c) {
$c->initReportNode($node, $this->frxReport);
$c->generate($data, $config);
}
else {
drupal_set_message(t('Could not find template %s', array('%s' => $template_class)), 'error');
}
return $this;
}
/**
* Insert a data block before a node.
* @param unknown $block
* @param unknown $class
* @param unknown $id
* @return FrxEditor
*/
public function prependBlock($block_name, $template_class='FrxTable', $config=array(), $id) {
$block_name = str_replace('.', '/', $block_name);
$path = "//*[@id='$id']";
$nodes = $this->simplexml->xpath($path);
if ($nodes) {
$target = dom_import_simplexml($nodes[0]);
}
else {
drupal_set_message(t('Could not find %s in report', array('%s' => $id)), 'error');
return;
}
$node = $this->dom->createElement('div');
$pnode = $target->parentNode;
$pnode->insertBefore($node, $target);
$config['block'] = $block_name;
$b = Frx::BlockEditor($block_name, $this->frxReport->block_edit_mode);
$data= $b->data($this->parms);
......@@ -761,6 +803,7 @@ class FrxEditor {
return $this;
}
public function preview($parms = array()) {
$r = $this->frxReport;
......@@ -840,7 +883,7 @@ class FrxEditor {
$r_link = str_replace('/', '.', $this->report_name);
$parms = $_GET;
unset($parms['q']);
$links = l('Add data', "reports/$r_link/edit/select-data", array('query' => $parms));
$links = l('Add data', "reports/$r_link/edit/select-data/add-data", array('query' => $parms));
}
Frx::Data()->pop();
$content = array(
......@@ -872,11 +915,11 @@ class FrxEditor {
$block_name = (string)$frx['block'];
$block_link = str_replace('/', '.', $block_name);
$report_name = str_replace('/', '.' , $this->report_name);
//$b=Frx::BlockEditor($block_name)->block;
$b = Frx::RepoMan()->loadBlock($block_name);
$options = array();
if ($context) $options['query'] = $context;
$o = '<div class="forena-edit-links">' . l($block_name, "reports/$report_name/edit/edit-data/$block_link/$id", $options ) . "</div>";
$o .= '<div class="forena-edit-links">' . l('Insert Data', "reports/$report_name/edit/select-data/prepend-data/$id") . "</div>";
$o .= '<div class="forena-edit-links">' . l($block_name, "reports/$report_name/edit/edit-data/$block_link/$id", $options ) . "</div>";
}
return $o;
......
......@@ -185,42 +185,32 @@ function forena_menu() {
'file' => 'forena.admin.inc',
);
$items['reports/%/edit-data/preview'] = array(
'title' => 'Preview',
'page callback' => 'forena_report_preview',
'page arguments' => array(1),
'access arguments' => array('design any report'),
'description' => 'Preview the report',
'file' => 'forena.report.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['reports/%/edit/edit-data/%/%'] = array(
'title' => 'Edit Block',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('forena_report_data_block_form', 1, 4, 5, 'edit-data'),
'page arguments' => array('forena_report_data_block_form', 1, 3, 4, 5, 'edit-data'),
'access arguments' => array('design any report'),
'description' => 'Add a data block to your report',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/select-data'] = array(
$items['reports/%/edit/select-data/%'] = array(
'title' => 'Select Data Block',
'file' => 'forena.report.inc',
'page callback' => 'forena_select_block_list',
'page arguments' => array(1),
'page arguments' => array(1, 4),
'access arguments' => array('design any report'),
'description' => 'Select the data blcok to add',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/select-data/%'] = array(
$items['reports/%/edit/select-data/%/%'] = array(
'title' => 'Select Data Block',
'file' => 'forena.report.inc',
'page callback' => 'forena_select_block_list',
'page arguments' => array(1, 4),
'page arguments' => array(1, 4, 5),
'access arguments' => array('design any report'),
'description' => 'Select the data blcok to add',
'type' => MENU_CALLBACK,
......@@ -250,7 +240,7 @@ function forena_menu() {
'title' => 'Data',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('forena_report_data_block_form', 1, 4),
'page arguments' => array('forena_report_data_block_form', 1, 3, 4),
'access arguments' => array('design any report'),
'description' => 'Edit a data block on the report. ',
'type' => MENU_CALLBACK,
......@@ -260,7 +250,17 @@ function forena_menu() {
'title' => 'Add Data',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('forena_report_data_block_form', 1, 4, 5),
'page arguments' => array('forena_report_data_block_form', 1, 3, 4, 5),
'access arguments' => array('design any report'),
'description' => 'Edit a data block on the report. ',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/prepend-data/%/%'] = array(
'title' => 'Add Data',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('forena_report_data_block_form', 1, 3, 4, 5),
'access arguments' => array('design any report'),
'description' => 'Edit a data block on the report. ',
'type' => MENU_CALLBACK,
......
......@@ -140,7 +140,7 @@ function forena_create_report_submit($form, &$form_state) {
$edit = '/edit';
}
else {
$edit = '/edit/seletc-data';
$edit = '/edit/select-data/add-data';
}
$form_state['redirect']= $desc['i_link'] . $edit;
......@@ -194,7 +194,7 @@ function forena_report_preview($report_name) {
* @param $form_state Array of block type
* @return unknown_type
*/
function forena_report_data_block_form($formid, &$form_state, $report_name, $block_name='', $id='', $action='add-data') {
function forena_report_data_block_form($formid, &$form_state, $report_name, $action, $block_name, $id='') {
$config = array();
$r = Frx::Editor($report_name);
// List of templates
......@@ -215,26 +215,38 @@ function forena_report_data_block_form($formid, &$form_state, $report_name, $blo
}
//The default submit handler
//If someone presses enter, this handler will execute
$form['action'] = array(
'#type' => 'value',
'#value' => $action,
);
$form['add'] = array(
'#type' => 'submit',
'#value' => 'Add',
'#submit' => array('forena_report_add_template_submit'),
'#access' => $action=='add-data',
'#type' => 'submit',
'#value' => 'Add',
'#submit' => array('forena_report_add_template_submit'),
'#access' => $action=='add-data',
);
$form['update'] = array(
'#type' => 'submit',
'#value' => 'Update',
'#submit' => array('forena_report_edit_template_submit'),
'#access' => $action=='edit-data',
'#type' => 'submit',
'#value' => 'Update',
'#submit' => array('forena_report_edit_template_submit'),
'#access' => $action=='edit-data',
);
$form['prepend'] = array(
'#type' => 'submit',
'#value' => 'Insert',
'#submit' => array('forena_report_prepend_template_submit'),
'#access' => $action=='prepend-data',
);
$form['cancel'] = array(
'#type' => 'submit',
'#value' => 'Cancel',
'#submit' => array('forena_update_cancel'),
'#type' => 'submit',
'#value' => 'Cancel',
'#submit' => array('forena_update_cancel'),
);
$form['report_name'] = array(
'#type' => 'value',
'#value' => $report_name,
......@@ -271,7 +283,7 @@ function forena_report_data_block_form($formid, &$form_state, $report_name, $blo
);
$form['template']['config'] = array_merge($form['template']['config'], $r->templateConfigForm($template_class, $config));
$form['template']['config']['preview'] = array('#type' => 'submit', '#value' => t('Preview'), '#submit' => array('forena_template_preview'));
$form['template']['config']['preview'] = array('#type' => 'button', '#value' => t('Preview'));
// Generate a preview
......@@ -306,16 +318,6 @@ function forena_template_callback($form, &$form_state) {
return $form['template'];
}
/**
* PReview the template data
* @param unknown $form
* @param unknown $form_state
*/
function forena_template_preview($form, &$form_state) {
$form_state['storage']['config'] = $form_state['values']['config'];
$form_state['rebuild'] = TRUE;
}
/**
* Edit an existing id based on the template.
* @param unknown $form
......@@ -330,7 +332,7 @@ function forena_report_edit_template_submit($form, &$form_state){
$r->applyTemplate($id, $template_class, $config);
$r->update();
$parms = $_GET;
$unset($parms['q']);
unset($parms['q']);
$form_state['redirect'] = array("reports/$report_name/edit", array('query' => $parms));
}
......@@ -342,14 +344,26 @@ function forena_report_add_template_submit($form, &$form_state) {
Frx::Editor($report_name)->addBlock($block_name, $template_class, (array)$config, $id);
Frx::Editor() ->update();
$parms = $_GET;
$unset($parms['q']);
unset($parms['q']);
$form_state['redirect'] = array("reports/$report_name/edit", array('query' => $parms));
}
function forena_report_prepend_template_submit($form, &$form_state) {
extract($form_state['values']);
$parms = $form_state['storage']['parms'];
$r = Frx::Editor($report_name);
$r->setEditorParms($parms);
Frx::Editor($report_name)->prependBlock($block_name, $template_class, (array)$config, $id);
Frx::Editor() ->update();
$parms = $_GET;
unset($parms['q']);
$form_state['redirect'] = array("reports/$report_name/edit", array('query' => $parms));
}
function forena_update_cancel($form, &$form_state) {
extract($form_state['values']);
$parms = $_GET;
$unset($parms['q']);
unset($parms['q']);
$form_state['redirect'] = array("reports/$report_name/edit", array('query' => $parms));
}
......@@ -359,14 +373,14 @@ function forena_report_save_cancel($form, &$form_state) {
$form_state['redirect'] = 'forena';
}
function forena_select_block_list($report_name, $id='') {
function forena_select_block_list($report_name, $action='add-data', $id='') {
$header = array(t('Block'), t('Access'), t('Keywords'));
$blocks = Frx::DataFile()->userBlocks();
$data=array();
foreach ($blocks as $block_name => $block) {
$blck = str_replace('/', '.', $block_name);
$path = "reports/$report_name/edit/preview-data/add-data/$blck";
$path = "reports/$report_name/edit/preview-data/$action/$blck";
// Build the table.
if ($id) $path .= "/$id";
$data[] = array(
......@@ -389,7 +403,6 @@ function forena_select_block_list($report_name, $id='') {
* @return multitype:string unknown multitype:string unknown multitype:string multitype:string Ambigous <The, string, A, Optional>
*/
function forena_report_block_select_form($form, &$form_state, $report_name, $action, $block_name, $id='') {
$form['action'] = array(
'#type' => 'value',
'#value' => $action,
......
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