}
public function ListItemsHeader(){
-
-
-
$this->header = array();
if (method_exists($this,'list_display'))
$this->names = $this->list_display();
$this->errors = array();
$form_methods = get_class_methods($this);
foreach ($this->fields as $name=>$field) {
- $value = $field->widget->valueFromFormData($this->addPrefix($name),
- $this->data);
+ $value = $field->widget->valueFromFormData($this->addPrefix($name), &$this->data);
try {
$value = $field->clean($value);
$this->cleaned_data[$name] = $value;
public function clean()
{
+ foreach ($this->fields as $name=>$field) {
+ $field->LateClean(&$this->data, &$this->cleaned_data);
+ }
return $this->cleaned_data;
}
public $widget = 'IPF_Form_Widget_TextInput';
public $label = '';
- public $required = false;
+ public $required = false;
public $help_text = '';
public $initial = '';
public $choices = null;
foreach ($params as $key=>$in) {
if ($key !== 'widget_attrs')
if (isset($this->$key))
- $default[$key] = $this->$key;
+ $default[$key] = $this->$key;
}
$m = array_merge($default, $params);
foreach ($params as $key=>$in) {
}
return $value;
}
-
+
+ function LateClean($data, $cleaned_data){
+ }
+
protected function getWidget(){
return $this->widget;
}
--- /dev/null
+<?php
+
+class IPF_Form_Field_TreeModelChoice extends IPF_Form_Field_Choice{
+
+ public $widget = 'IPF_Form_Widget_TreeSelectInput';
+ protected $_models;
+
+ function __construct($params=array()){
+ parent::__construct($params);
+ $this->_models = $params['models'];
+ $choices = array('--------'=>'');
+ $levels = array();
+ foreach($this->_models as &$m){
+ $m['objects'] = IPF_ORM_Query::create()->from($m['model'])->orderby('ord')->execute();
+ $levels[] = $m['field'];
+ }
+ $this->_collectTreeRecursive(&$choices);
+ $this->setChoices($choices);
+ $this->widget->setLevels($levels);
+ }
+
+ protected function _collectTreeRecursive(&$choices,$level=0,$parent_id=null,$valname=''){
+ foreach($this->_models[$level]['objects'] as $o){
+ if ($parent_id){
+ $foreign = $this->_models[$level]['foreign'];
+ if ($parent_id!=$o->$foreign)
+ continue;
+ }
+ $name = str_repeat("-", $level).$o['name'];
+ $choices[$name] = $valname.$o->id;
+ if ($level<(count($this->_models)-1)){
+ $this->_collectTreeRecursive(&$choices,$level+1,$o->id,$valname.$o->id.'.');
+ }
+ }
+ }
+
+ function LateClean($data, $cleaned_data){
+ foreach($this->_models as &$m){
+ $cleaned_data[$m['field']] = $data[$m['field']];
+ }
+ }
+
+
+ /*
+ public function clean($value){
+ parent::clean($value);
+ if (in_array($value, $this->empty_values)) {
+ return null;
+ }
+ $o = $this->_model->getTable()->find($value);
+ return $o;
+ }
+ */
+}
}
}
}
- throw new IPF_Exception_Form(__('Cannot save the model from an invalid form.'));
+ //throw new IPF_Exception_Form(__('Cannot save the model from an invalid form.'));
}
}
{
public $input_type = 'file';
public $needs_multipart_form = true;
+ public $allow_extended = true;
public function render($name, $value, $extra_attrs=array())
{
if (isset($value['data'])){
$value = $value['data'];
if (is_string($value) && $value!=''){
- $sim = '<nobr>Currently: <a target="_blank" href="'.IPF::get('upload_url').$value.'">'.$value.'</a> | <input name="'.$name.'_remove" value="1" id="id_'.$name.'_remove" type="checkbox" /> <label class="file_remove" for="id_'.$name.'_remove">Remove</label></nobr>Change:';
+ if ($this->allow_extended)
+ $sim = '<nobr>Currently: <a target="_blank" href="'.IPF::get('upload_url').$value.'">'.$value.'</a> | <input name="'.$name.'_remove" value="1" id="id_'.$name.'_remove" type="checkbox" /> <label class="file_remove" for="id_'.$name.'_remove">Remove</label></nobr>Change:';
+ else
+ $sim = '<nobr>Currently: <b>'.$value.'</b><br> Change: ';
}
}
$value = '';
--- /dev/null
+<?php
+
+class IPF_Form_Widget_TreeSelectInput extends IPF_Form_Widget_SelectInput
+{
+ protected $_levels = null;
+
+ public function setLevels($levels){
+ $this->_levels = $levels;
+ }
+
+ public function valueToFormData($name, $data)
+ {
+ $val = null;
+ foreach($this->_levels as $l){
+ if ( (!isset($data[$l])) || ($data[$l]=='')){
+ return $val;
+ }
+ if ($val==null)
+ $val = '';
+ else
+ $val .= '.';
+ $val .= $data[$l];
+ }
+ return $val;
+ }
+
+ public function valueFromFormData($name, $data)
+ {
+ if (isset($data[$name])) {
+ $vals = split("\.",(string)$data[$name]);
+ for($i=0; $i<count($this->_levels); $i++){
+ if ( ($i<count($vals)) && ($data[$name]!='')){
+ $data[$this->_levels[$i]] = $vals[$i];
+ }
+ else
+ $data[$this->_levels[$i]] = null;
+ }
+ return $data[$name];
+ }
+ return null;
+ }
+}
\ No newline at end of file