1
|
|
|
<?php |
2
|
|
|
namespace Ajax\ui\components; |
3
|
|
|
|
4
|
|
|
use Ajax\JsUtils; |
5
|
|
|
use Ajax\common\components\SimpleComponent; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* JQuery UI Dialog Component |
9
|
|
|
* |
10
|
|
|
* @author jc |
11
|
|
|
* @version 1.001 |
12
|
|
|
*/ |
13
|
|
|
class Dialog extends SimpleComponent { |
14
|
|
|
|
15
|
|
|
protected $attachTo; |
16
|
|
|
|
17
|
|
|
protected $buttons = array(); |
18
|
|
|
|
19
|
|
|
public function __construct(JsUtils $js) { |
20
|
|
|
parent::__construct($js); |
21
|
|
|
$this->params = array( |
22
|
|
|
"dialogClass" => "no-close" |
23
|
|
|
); |
24
|
|
|
$this->addCancelBtn("Annuler"); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getScript() { |
28
|
|
|
$allParams = $this->params; |
29
|
|
|
$jsonButtons = array(); |
30
|
|
|
foreach ($this->buttons as $button) { |
31
|
|
|
$jsonButtons[] = $button->getParams(); |
32
|
|
|
} |
33
|
|
|
$allParams["buttons"] = $jsonButtons; |
34
|
|
|
$this->jquery_code_for_compile[] = "$( '" . $this->attachTo . "' ).dialog(" . $this->getParamsAsJSON($allParams) . ");"; |
|
|
|
|
35
|
|
|
$result = implode("", $this->jquery_code_for_compile); |
36
|
|
|
$result = str_ireplace("\"%", "", $result); |
37
|
|
|
$result = str_ireplace("%\"", "", $result); |
38
|
|
|
$result = str_ireplace("\\n", "", $result); |
39
|
|
|
$result = str_ireplace("\\t", "", $result); |
40
|
|
|
return $result; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* |
45
|
|
|
* @param String $identifier |
46
|
|
|
* identifiant CSS |
47
|
|
|
*/ |
48
|
|
|
public function attach($identifier) { |
49
|
|
|
$this->attachTo = $identifier; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function addCancelBtn($caption = "Annuler", $position = NULL) { |
53
|
|
|
$this->insertBtn(DialogButton::cancelButton($caption), $position); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function addSubmitBtn(JsUtils $js, $url, $form, $responseElement, $caption = "Valider", $position = NULL) { |
57
|
|
|
$this->insertBtn(DialogButton::submitButton($js, $url, $form, $responseElement, $caption), $position); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function addButton($caption, $jsCode, $position = NULL) { |
61
|
|
|
$this->insertBtn(new DialogButton($caption, $jsCode), $position); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function insertBtn($insert, $position = NULL) { |
65
|
|
|
if ($position != NULL) { |
66
|
|
|
$this->buttons = array_splice($this->buttons, $position, 0, $insert); |
67
|
|
|
} else { |
68
|
|
|
$this->buttons[] = $insert; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|