From: avl Date: Sat, 13 Sep 2008 22:42:41 +0000 (+0300) Subject: TupleInput Widget (Textarea to EditableGrid) X-Git-Tag: 0.5~489 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=6a359e844aaafb95f701692aab813e36858781a6;p=ipf.git TupleInput Widget (Textarea to EditableGrid) --- diff --git a/ipf/admin/modelinline.php b/ipf/admin/modelinline.php index 4d43f8e..efa78e0 100644 --- a/ipf/admin/modelinline.php +++ b/ipf/admin/modelinline.php @@ -93,6 +93,7 @@ abstract class IPF_Admin_ModelInline{ } } + /* for($i=0; $i<$this->getAddNum(); $i++ ){ $form = IPF_Shortcuts::GetFormForModel($this->model->copy(), null, array('exclude'=>array($this->getFkName(),$this->getFkLocal()))); $form->fields = array_merge(array(new IPF_Form_Field_Boolean(array('label'=>'Del','name'=>'delete_', 'widget_attrs'=>array('disabled'=>'disabled')))),$form->fields); @@ -107,6 +108,7 @@ abstract class IPF_Admin_ModelInline{ $form->isFirst = false; $this->formset[] = $form; } + */ } function save(){ diff --git a/ipf/form/boundfield.php b/ipf/form/boundfield.php index bc97152..d16f01d 100644 --- a/ipf/form/boundfield.php +++ b/ipf/form/boundfield.php @@ -40,7 +40,7 @@ class IPF_Form_BoundField if (!$this->form->is_bound) { $data = $this->form->initial($this->name); } else { - $data = $this->field->widget->valueFromFormData($this->html_name, $this->form->data); + $data = $this->field->widget->valueToFormData($this->html_name, $this->form->data); } return $widget->render($this->html_name, $data, $attrs); } diff --git a/ipf/form/widget.php b/ipf/form/widget.php index 551fd41..aff7a07 100644 --- a/ipf/form/widget.php +++ b/ipf/form/widget.php @@ -30,6 +30,14 @@ class IPF_Form_Widget return null; } + public function valueToFormData($name, $data) + { + if (isset($data[$name])) { + return $data[$name]; + } + return null; + } + public function idForLabel($id) { return $id; diff --git a/ipf/form/widget/fileinput.php b/ipf/form/widget/fileinput.php index 08f6f75..6d80ef9 100644 --- a/ipf/form/widget/fileinput.php +++ b/ipf/form/widget/fileinput.php @@ -11,7 +11,7 @@ class IPF_Form_Widget_FileInput extends IPF_Form_Widget_Input if (isset($value['data'])){ $value = $value['data']; if (is_string($value) && $value!=''){ - $sim = 'Currently: '.$value.' |
Change:'; + $sim = 'Currently: '.$value.' |  
Change:'; } } $value = ''; @@ -30,6 +30,20 @@ class IPF_Form_Widget_FileInput extends IPF_Form_Widget_Input } return null; } + + public function valueToFormData($name, $data) + { + if (isset($data[$name])) { + $remove = false; + if (isset($data[$name.'_remove'])) + if ($data[$name.'_remove']==1) + $remove = true; + $res = array('data'=>$data[$name], 'remove'=>$remove); + return $res; + } + return null; + } + } \ No newline at end of file diff --git a/ipf/form/widget/tupleinput.php b/ipf/form/widget/tupleinput.php new file mode 100644 index 0000000..e82e484 --- /dev/null +++ b/ipf/form/widget/tupleinput.php @@ -0,0 +1,68 @@ +headers = $attrs['headers']; + + if (isset($attrs['rows'])) + $this->rows = $attrs['rows']; + } + + protected function isHeadLabels(){ + foreach ($this->headers as &$h){ + if ($h=='') + return false; + } + return true; + } + + public function render($name, $value, $extra_attrs=array()) + { + $data = array(); + $lines = explode("\n",$value); + foreach ($lines as $line){ + $data[] = explode('|', $line); + } + if ($value === null) $value = ''; + $s = ''; + if ($this->isHeadLabels()){ + $s .= ''; + foreach ($this->headers as &$h){ + $s .= ''; + } + $s .= ''; + } + for ($i=0; $i<$this->rows; $i++){ + $s .= ''; + for ($j=0; $jheaders); $j++){ + $v = @$data[$i][$j]; + $s .= ''; + } + $s .= ''; + } + $s .= '
'.$h.'
'; + return new IPF_Template_SafeString($s,true); + } + + public function valueFromFormData($name, $data) + { + $s = ''; + for ($i=0; $i<$this->rows; $i++){ + if ($i>0) $s .= "\n"; + for ($j=0; $jheaders); $j++){ + if ($j>0) $s.='|'; + $s .= @$data[$name.'_'.$i.'_'.$j]; + } + } + return $s; + } +} +