Completed
Push — namespace2 ( 8a6673...791eac )
by Fabio
08:25
created

TJuiDialogButton   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getActiveControl() 0 4 1
A getPostBackOptions() 0 7 1
A getText() 0 4 1
A setText() 0 4 1
A onClick() 0 4 1
A raiseCallbackEvent() 0 5 2
1
<?php
2
/**
3
 * TJuiDialog class file.
4
 *
5
 * @author  David Otto <ottodavid[at]gmx[dot]net>
6
 * @link https://github.com/pradosoft/prado
7
 * @copyright Copyright &copy; 2013-2015 PradoSoft
8
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
 * @package Prado\Web\UI\JuiControls
10
 */
11
12
namespace Prado\Web\UI\JuiControls;
13
14
use Prado\Web\UI\TControl;
15
use Prado\Web\UI\ActiveControls\ICallbackEventHandler;
16
use Prado\Web\UI\ActiveControls\IActiveControl;
17
use Prado\Web\UI\ActiveControls\TActiveControlAdapter;
18
use Prado\Web\Javascripts\TJavaScriptLiteral;
19
20
/**
21
 * TJuiDialogButton class
22
 *
23
 * This button must be child of a TJuiDialog. It can be used to bind an callback
24
 * to the buttons of the dialog.
25
 *
26
 * <code>
27
 * <com:TJuiDialog> * >
28
 * Text
29
 * 	<com:TJuiDialogButton Text="Ok" OnClick="Ok" />
30
 *
31
 * </com:TJuiDialog>
32
 * </code>
33
 *
34
 * @author David Otto <ottodavid[at]gmx[dot]net>
35
 * @package Prado\Web\UI\JuiControls
36
 * @since 3.3
37
 */
38
class TJuiDialogButton extends TControl implements ICallbackEventHandler, IActiveControl
39
{
40
41
	/**
42
	 * Creates a new callback control, sets the adapter to
43
	 * TActiveControlAdapter. If you override this class, be sure to set the
44
	 * adapter appropriately by, for example, by calling this constructor.
45
	 */
46
	public function __construct()
47
	{
48
		parent::__construct();
49
		$this->setAdapter(new TActiveControlAdapter($this));
50
	}
51
52
	/**
53
	 * @return TBaseActiveCallbackControl standard callback control options.
54
	 */
55
	public function getActiveControl()
56
	{
57
		return $this->getAdapter()->getBaseActiveControl();
58
	}
59
60
	/**
61
	 * Array containing defined javascript options
62
	 * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string|TJavaScriptLiteral>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
63
	 */
64
	public function getPostBackOptions()
65
	{
66
		return array(
67
			'text' => $this->getText(),
68
			'click' => new TJavaScriptLiteral("function(){new Prado.Callback('".$this->getUniqueID()."', 'onClick');}"
69
			)) ;
70
	}
71
72
	/**
73
	 * @return string caption of the button
74
	 */
75
	public function getText()
76
	{
77
		return $this->getViewState('Text','');
78
	}
79
80
	/**
81
	 * @param string caption of the button
82
	 */
83
	public function setText($value)
84
	{
85
		$this->setViewState('Text',$value,'');
86
	}
87
88
	/**
89
	 * Raises the OnClick event
90
	 * @param object $params event parameters
91
	 */
92
	public function onClick ($params)
93
	{
94
		$this->raiseEvent('OnClick', $this, $params);
95
	}
96
97
	/**
98
	 * Raises callback event.
99
	 * raises the appropriate event(s) (e.g. OnClick)
100
	 * @param TCallbackEventParameter the parameter associated with the callback event
101
	 */
102
	public function raiseCallbackEvent($param)
103
	{
104
		if($param->CallbackParameter === 'onClick')
105
			$this->onClick($param);
106
	}
107
108
}