1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\widgets\dataform; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\widgets\base\InstanceViewer; |
6
|
|
|
use Ajax\service\JString; |
7
|
|
|
use Ajax\semantic\html\collections\form\HtmlFormInput; |
8
|
|
|
|
9
|
|
|
class FormInstanceViewer extends InstanceViewer { |
10
|
|
|
protected $separators; |
11
|
|
|
|
12
|
|
|
public function __construct($identifier,$instance=NULL, $captions=NULL) { |
13
|
|
|
parent::__construct($identifier,$instance=NULL, $captions=NULL); |
14
|
|
|
$this->separators=[-1]; |
15
|
|
|
$this->defaultValueFunction=function($name,$value,$index){ |
16
|
|
|
$caption=$this->getCaption($index); |
17
|
|
|
$input=new HtmlFormInput($this->widgetIdentifier."-".$name,$caption,"text",$value); |
18
|
|
|
$input->setName($name); |
19
|
|
|
return $input; |
20
|
|
|
}; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function _beforeAddProperty($index,&$field){ |
24
|
|
|
if(JString::endswith($field, "\n")===true){ |
25
|
|
|
$this->addSeparatorAfter($index); |
26
|
|
|
} |
27
|
|
|
if($index>1 && JString::startswith($field, "\n")===true){ |
28
|
|
|
$this->addSeparatorAfter($index-1); |
29
|
|
|
} |
30
|
|
|
$field=\str_replace("\n", "", $field); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getFieldName($index){ |
34
|
|
|
$property=$this->getProperty($index); |
35
|
|
|
if($property instanceof \ReflectionProperty){ |
36
|
|
|
$result=$property->getName(); |
37
|
|
|
}elseif(\is_callable($property)){ |
38
|
|
|
$result=$this->visibleProperties[$index]; |
39
|
|
|
}else{ |
40
|
|
|
$result=$property; |
41
|
|
|
} |
42
|
|
|
return $result; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function addSeparatorAfter($fieldNum){ |
46
|
|
|
if(\array_search($fieldNum, $this->separators)===false) |
47
|
|
|
$this->separators[]=$fieldNum; |
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getSeparators() { |
52
|
|
|
return $this->separators; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setSeparators($separators) { |
56
|
|
|
$this->separators=\array_merge([-1], $separators); |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |