}
}
+ /*
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);
$form->isFirst = false;
$this->formset[] = $form;
}
+ */
}
function save(){
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);
}
if (isset($value['data'])){
$value = $value['data'];
if (is_string($value) && $value!=''){
- $sim = '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 for="id_'.$name.'_remove">Remove</label><br />Change:';
+ $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 for="id_'.$name.'_remove">Remove</label></nobr><br />Change:';
}
}
$value = '';
}
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
--- /dev/null
+<?php
+
+class IPF_Form_Widget_TupleInput extends IPF_Form_Widget
+{
+ var $headers = array('');
+ var $rows = 3;
+
+ public function __construct($attrs=array()){
+
+ parent::__construct($attrs);
+
+ if (isset($attrs['headers']))
+ $this->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 = '<table class="tuplegrid">';
+ if ($this->isHeadLabels()){
+ $s .= '<tr>';
+ foreach ($this->headers as &$h){
+ $s .= '<th>'.$h.'</th>';
+ }
+ $s .= '</tr>';
+ }
+ for ($i=0; $i<$this->rows; $i++){
+ $s .= '<tr>';
+ for ($j=0; $j<count($this->headers); $j++){
+ $v = @$data[$i][$j];
+ $s .= '<td><input name="'.$name.'_'.$i.'_'.$j.'" value="'.$v.'"></td>';
+ }
+ $s .= '<tr>';
+ }
+ $s .= '</table>';
+ 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; $j<count($this->headers); $j++){
+ if ($j>0) $s.='|';
+ $s .= @$data[$name.'_'.$i.'_'.$j];
+ }
+ }
+ return $s;
+ }
+}
+