Arek,
Thanks for the reply. I have this working now for the most part. I created a very simply module to test the functionality. Here is the code in case anyone else is trying to solve this as well.
Calculator Module.
Calculator_0.php
<?php
defined("_VALID_ACCESS") || die('Direct access forbidden'); // This is a security feature.
class Custom_Calculator extends Module { // Note, how the class' name reflects module's path.
private $rb;
public function body() {
$this->rb = $this->init_module('Utils/RecordBrowser','custom_calculator','custom_calculator');
$this->rb->set_filters_defaults(array('active'=>true));
$this->rb->set_header_properties(array(
'shares'=>array('width'=>10),
'price'=>array('width'=>10),
'total'=>array('width'=>15),
));
$this->display_module($this->rb, array(array('shares'=>'ASC'),array(),array('active'=>false)));
}
}
?>
CalculatorInstall.php
<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
class Custom_CalculatorInstall extends ModuleInstall {
public function install() {
Base_LangCommon::install_translations($this->get_type());
$fields = array(
array(
'name'=>'Quote Name',
'type'=>'text',
'param'=>'128',
'extra'=>false,
'visible'=>true,
'required'=>true,
'QFfield_callback'=>array('Custom_CalculatorCommon', 'QFfield_quote_name')
),
array(
'name'=>'Shares',
'type'=>'float',
'extra'=>false,
'visible'=>true,
'filter'=>true
),
array(
'name'=>'Price',
'type'=>'currency',
'extra'=>false,
'visible'=>true,
'filter'=>true,
),
array(
'name'=>'Total',
'type'=>'currency',
'extra'=>false,
'visible'=>true,
'filter'=>true
),
);
Utils_RecordBrowserCommon::install_new_recordset('custom_calculator', $fields);
Utils_RecordBrowserCommon::set_recent('custom_calculator', 10);
Utils_RecordBrowserCommon::set_favorites('custom_calculator', true);
Utils_RecordBrowserCommon::set_caption('custom_calculator', 'Calculator');
Utils_RecordBrowserCommon::set_quickjump('custom_calculator', 'Calculator');
return true;
}
public function uninstall() {
Utils_AttachmentCommon::persistent_mass_delete('custom_calculator');
Utils_RecordBrowserCommon::uninstall_recordset('custom_calculator');
return true;
}
public function info() {
// Returns basic information about the module which will be available in the epesi Main Setup
return array( 'Author'=>'<Place your name here>',
'License'=>'<Place type of the license here>',
'Description'=>'<Place description here>');
}
public function simple_setup() {
// Indicates if this module should be visible on the module list in Main Setup's simple view
return true;
}
public function requires($v) {
return array();
}
public function version() {
// Return version name of the module
return array('0.1');
}
}
?>
CalculatorCommon_0.php
<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
class Custom_CalculatorCommon extends ModuleCommon {
public static function menu() {
return array('Custom'=>array('__submenu__'=>1,'Calculator'=>array()));
}
public static function QFfield_quote_name(&$form, $field, $label, $mode, $default, $desc, $rb_obj) {
if ($mode=='add' || $mode=='edit') {
$form->addElement('text', $field, $label, $default);
eval_js('Event.observe(\'price\',\'change\', update_total);'.
'Event.observe(\'shares\',\'change\', update_total);'.
'function update_total() {'.
'document.forms[\''.$form->getAttribute('name').'\'].total.value = document.forms[\''.$form->getAttribute('name').'\'].shares.value * document.forms[\''.$form->getAttribute('name').'\'].price.value;'.
'}');
} else {
$form->addElement('static', $field, $label, $default);
}
}
}
?>
There is only one item left to try and resolve. When I try to edit an entry the quote name field shows up blank. It should show the quote name that was previously saved. I played with the $default variable for addElement in the QFfield_quote_name function when $mode = edit. However I can't seem to get the quote name to show up. Otherwise everything works.
What I learned through the process. I could not get the fields to calculate if the fields I wanted to calculate were part of a QFfield function. For example I started with a QFfield function for price but could not get the code to work. I then decided to move the QFfield function to quote_name, a field that is not part of the calculations, and the updates worked.
The last issue on this question is how to populate the quote name field when editing a previously saved record.
Thanks,
Jon