|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\modules; |
|
4
|
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
|
6
|
|
|
use Ajax\JsUtils; |
|
7
|
|
|
use Ajax\service\JArray; |
|
8
|
|
|
|
|
9
|
|
|
use Ajax\semantic\html\base\constants\State; |
|
10
|
|
|
|
|
11
|
|
|
class HtmlProgress extends HtmlSemDoubleElement { |
|
12
|
|
|
private $_params=array (); |
|
13
|
|
|
|
|
14
|
|
|
public function __construct($identifier, $value=NULL, $label=NULL, $attributes=array()) { |
|
15
|
|
|
parent::__construct($identifier, "div", "ui progress"); |
|
16
|
|
|
if (isset($value) === true) |
|
17
|
|
|
$this->setProperty("data-percent", $value); |
|
18
|
|
|
$this->createBar(); |
|
19
|
|
|
if (isset($label) === true) |
|
20
|
|
|
$this->setLabel($label); |
|
21
|
|
|
$this->_states=[ State::SUCCESS,State::WARNING,State::ERROR,State::ACTIVE,State::DISABLED ]; |
|
22
|
|
|
$this->addToProperty("class", $attributes); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function setLabel($label) { |
|
26
|
|
|
$this->content["label"]=new HtmlSemDoubleElement("lbl-" . $this->identifier, "div", "label", $label); |
|
27
|
|
|
return $this; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
private function createBar() { |
|
31
|
|
|
$bar=new HtmlSemDoubleElement("bar-" . $this->identifier, "div", "bar", new HtmlSemDoubleElement("progress-" . $this->identifier, "div", "progress")); |
|
32
|
|
|
$this->content["bar"]=$bar; |
|
33
|
|
|
return $this; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function setTotal($value) { |
|
37
|
|
|
return $this->setProperty("data-total", $value); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function setValue($value) { |
|
41
|
|
|
return $this->setProperty("data-value", $value); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function setPercent($value) { |
|
45
|
|
|
return $this->setProperty("data-percent", $value); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function setIndicating() { |
|
49
|
|
|
return $this->addToProperty("class", "indicating"); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function setWarning() { |
|
53
|
|
|
return $this->addToProperty("class", "warning"); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setError() { |
|
57
|
|
|
return $this->addToProperty("class", "error"); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* |
|
62
|
|
|
* {@inheritDoc} |
|
63
|
|
|
* |
|
64
|
|
|
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
|
65
|
|
|
*/ |
|
66
|
|
|
public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
67
|
|
|
$this->content=JArray::sortAssociative($this->content, [ "bar","label" ]); |
|
68
|
|
|
return parent::compile($js, $view); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function jsSetValue($value) { |
|
72
|
|
|
return '$("#' . $this->identifier . '").progress({value:' . $value . '});'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function jsIncValue() { |
|
76
|
|
|
return '$("#' . $this->identifier . '").progress("increment");'; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function jsDecValue() { |
|
80
|
|
|
return '$("#' . $this->identifier . '").progress("decrement");'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* |
|
85
|
|
|
* @param mixed $active |
|
86
|
|
|
* @param mixed $error |
|
87
|
|
|
* @param mixed $success |
|
88
|
|
|
* @param mixed $warning |
|
89
|
|
|
* @param mixed $percent |
|
90
|
|
|
* @param mixed $ratio |
|
91
|
|
|
* @return HtmlProgress |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setTextValues($active=false, $error=false, $success=false, $warning=false, $percent="{percent}%", $ratio="{value} of {total}") { |
|
94
|
|
|
if (\is_array($active) == true) { |
|
|
|
|
|
|
95
|
|
|
$array=$active; |
|
96
|
|
|
$active=JArray::getDefaultValue($array, "active", false); |
|
97
|
|
|
$success=JArray::getDefaultValue($array, "success", $success); |
|
98
|
|
|
$warning=JArray::getDefaultValue($array, "warning", $warning); |
|
99
|
|
|
$percent=JArray::getDefaultValue($array, "percent", $percent); |
|
100
|
|
|
$ratio=JArray::getDefaultValue($array, "ratio", $ratio); |
|
101
|
|
|
} |
|
102
|
|
|
$this->_params["text"]="%{active : " . \var_export($active, true) . ",error: " . \var_export($error, true) . ",success : " . \var_export($success, true) . ",warning : " . \var_export($warning, true) . ",percent : " . \var_export($percent, true) . ",ratio : " . \var_export($ratio, true) . "}%"; |
|
103
|
|
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function onChange($jsCode) { |
|
107
|
|
|
return $this->_params["onChange"]="%function(percent, value, total){" . $jsCode . "}%"; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/* |
|
111
|
|
|
* (non-PHPdoc) |
|
112
|
|
|
* @see BaseHtml::run() |
|
113
|
|
|
*/ |
|
114
|
|
|
public function run(JsUtils $js) { |
|
115
|
|
View Code Duplication |
if (isset($this->_bsComponent) === false) |
|
|
|
|
|
|
116
|
|
|
$this->_bsComponent=$js->semantic()->progress("#" . $this->identifier, $this->_params); |
|
117
|
|
|
$this->addEventsOnRun($js); |
|
118
|
|
|
return $this->_bsComponent; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public static function create($identifier, $value=NULL, $label=NULL, $attributes=array()) { |
|
122
|
|
|
return new HtmlProgress($identifier, $value, $label, $attributes); |
|
123
|
|
|
} |
|
124
|
|
|
} |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.