phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
DataElement.php
Go to the documentation of this file.
1<?php
2
4
12
20class DataElement extends Widget , BaseTrait {
21 protected $_colWidths;
22
23 public function __construct($identifier, $modelInstance=NULL) {
24 parent::__construct($identifier, null,$modelInstance);
25 $this->_init(new DeInstanceViewer($identifier), "table", new HtmlTable($identifier, 0,2), false);
26 $this->content["table"]->setDefinition()->addClass("_element");
27 }
28
29 public function compile(JsUtils $js=NULL,&$view=NULL){
30 if(!$this->_generated){
31 $this->_instanceViewer->setInstance($this->_modelInstance);
32
33 $table=$this->content["table"];
34 $this->_generateContent($table);
35
36 if(isset($this->_toolbar)){
37 $this->_setToolbarPosition($table);
38 }
39 if(isset($this->_colWidths)){
40 $this->_applyStyleAttributes($table);
41 }
42 $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]);
43 $this->_compileForm();
44 $this->_generated=true;
45 }
46 return parent::compile($js,$view);
47 }
48
52 protected function _generateContent($table){
53 $values= $this->_instanceViewer->getValues();
54 $captions=$this->_instanceViewer->getCaptions();
55 $fields=$this->_instanceViewer->getVisibleProperties();
56 $count=$this->_instanceViewer->count();
57 $this->setProperty("data-ajax", $this->_instanceViewer->getIdentifier());
58 for($i=0;$i<$count;$i++){
59 $row=$table->addRow([$captions[$i],$values[$i]]);
60 $row->getItem(1)->setProperty("data-field", $fields[$i]);
61 }
62 }
63
64 public function getFieldValue($index){
65 if(is_string($index)){
66 $fields=$this->_instanceViewer->getVisibleProperties();
67 $index=array_search($index, $fields);
68 }
69 if(is_numeric($index)){
70 $values= $this->_instanceViewer->getValues();
71 if(isset($values[$index])){
72 return $values[$index];
73 }
74 }
75 return null;
76 }
77
78 protected function _applyStyleAttributes(HtmlTable $table){
79 $table->setColWidths($this->_colWidths);
80 }
81 protected function _getFieldName($index){
82 return $this->_instanceViewer->getFieldName($index);
83 }
84
85 protected function _getFieldCaption($index){
86 return null;
87 }
88
89 protected function _getFieldIdentifier($prefix,$name=""){
90 return $this->identifier."-{$prefix}-".$name;
91 }
92
98 public function getHtmlComponent() {
99 return $this->content["table"];
100 }
101
106 protected function _setToolbarPosition($table, $captions=NULL) {
108 }
109
116 public function onNewRow($callback) {
117 $this->content["table"]->onNewRow($callback);
118 return $this;
119 }
120
121 public function asForm(){
122 return $this->getForm();
123 }
124
125 public function setColCaptionWidth($width){
126 $this->_colWidths[0]=$width;
127 return $this;
128 }
129
130 public function setColValueWidth($width) {
131 $this->_colWidths[1]=$width;
132 return $this;
133 }
134
135 public function setColWidths($widths){
136 $this->_colWidths=$widths;
137 return $this;
138 }
139
140 public function run(JsUtils $js){
141 if(JString::isNotNull($this->_identifier))
142 $js->execOn("click", "#".$this->_identifier." .ui.toggle", 'var active=$(this).hasClass("active");$(this).children("i").toggleClass("up",active).toggleClass("down",!active);var nextTd=$(this).closest("td").next("td");nextTd.children(":not(.toggle-caption)").toggle(active);nextTd.children(".toggle-caption").toggle(!active);$(this).trigger({type:"toggled",active: active,caption: nextTd.children(".toggle-caption")});');
143 parent::run($js);
144 }
145}
JQuery PHP library.
Definition JsUtils.php:23
_init($instanceViewer, $contentKey, $content, $edition)
Definition Widget.php:81
execOn($event, $element, $js, $parameters=array())
Executes the javascript code $js when $event fires on $element.
DataElement widget for displaying an instance of model.
__construct($identifier, $modelInstance=NULL)
run(JsUtils $js)
SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\Bas...
_setToolbarPosition($table, $captions=NULL)
{}
compile(JsUtils $js=NULL, &$view=NULL)
onNewRow($callback)
The callback function called after the insertion of each row when fromDatabaseObjects is called callb...