Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TDraggable class file
4
 *
5
 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
6
 * @copyright Copyright &copy; 2008, PradoSoft
7
 * @license http://www.pradosoft.com/license
8
 * @version $Id: TDraggable.php 2517 2008-10-13 13:40:34Z tof $
9
 */
10
 
11
/**
12
 * TDraggable is a control which can be dragged
13
 *
14
 * This control will make "draggable" control.
15
 *
16
 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
17
 * @copyright Copyright &copy; 2008, PradoSoft
18
 * @license http://www.pradosoft.com/license
19
 * @version $Id: TDraggable.php 2517 2008-10-13 13:40:34Z tof $
20
 */
21
class TDraggable extends TPanel
22
{
23
	/**
24
	 * Set the handle id or css class
25
	 * @param string
26
	 */
27
	public function setHandle ($value)
28
	{
29
		$this->setViewState('DragHandle', TPropertyValue::ensureString($value), null);
30
	}
31
 
32
	/**
33
	 * Get the handle id or css class
34
	 * @return string
35
	 */
36
	public function getHandle ()
37
	{
38
		return $this->getViewState('DragHandle', null);
39
	}
40
 
41
	/**
42
	 * Determine if draggable element should revert to it orginal position
43
	 * upon release in an non-droppable container.
44
	 * @return boolean true to revert
45
	 */
46
	public function getRevert()
47
	{
48
		return $this->getViewState('Revert', true);
49
	}
50
 
51
	/**
52
	 * Sets whether the draggable element should revert to it orginal position
53
	 * upon release in an non-droppable container.
54
	 * @param boolean true to revert
55
	 */
56
	public function setRevert($value)
57
	{
58
		$this->setViewState('Revert', TPropertyValue::ensureBoolean($value), true);
59
	}
60
 
61
	/**
62
	 * Determine if the element should be cloned when dragged
63
	 * If true, Clones the element and drags the clone, leaving the original in place until the clone is dropped.
64
	 * Defaults to false
65
	 * @return boolean true to clone the element
66
	 */
67
	public function getGhosting ()
68
	{
69
		return $this->getViewState('Ghosting', false);
70
	}
71
 
72
	/**
73
	 * Sets wether the element should be cloned when dragged
74
	 * If true, Clones the element and drags the clone, leaving the original in place until the clone is dropped.
75
	 * Defaults to false
76
	 * @return boolean true to clone the element
77
	 */
78
	public function setGhosting ($value)
79
	{
80
		$this->setViewState('Ghosting', TPropertyValue::ensureBoolean($value), false);
81
	}
82
 
83
	/**
84
	 * Determine if the element should be constrainted in one direction or not
85
	 * @return CDraggableConstraint
86
	 */
87
	public function getConstraint()
88
	{
89
		return $this->getViewState('Constraint', TDraggableConstraint::None);
90
	}
91
 
92
	/**
93
	 * Set wether the element should be constrainted in one direction
94
	 * @param CDraggableConstraint
95
	 */
96
	public function setConstraint($value)
97
	{
98
		$this->setViewState('Constraint', TPropertyValue::ensureEnum($value, 'TDraggableConstraint'), TDraggableConstraint::None);
99
	}
100
 
101
 
102
	/**
103
	 * Ensure that the ID attribute is rendered and registers the javascript code
104
	 * for initializing the active control.
105
	 */
106
	protected function addAttributesToRender($writer)
107
	{
108
		parent::addAttributesToRender($writer);
109
		$writer->addAttribute('id',$this->getClientID());
110
		$cs=$this->getPage()->getClientScript();
111
		$cs->registerPradoScript('dragdrop');
112
		$options=TJavascript::encode($this->getPostBackOptions());
113
		$class=$this->getClientClassName();
114
		$code="new {$class}('{$this->getClientId()}', {$options}) ";
115
		$cs->registerEndScript(sprintf('%08X', crc32($code)), $code);
116
	}
117
 
118
	/**
119
	 * Gets the name of the javascript class responsible for performing postback for this control.
120
	 * This method overrides the parent implementation.
121
	 * @return string the javascript class name
122
	 */
123
	protected function getClientClassName ()
124
	{
125
		return 'Draggable';
126
	}
127
 
128
	/**
129
	 * Gets the post back options for this textbox.
130
	 * @return array
131
	 */
132
	protected function getPostBackOptions()
133
	{
134
		$options['ID'] = $this->getClientID();
135
 
136
		if (($handle=$this->getHandle())!== null) $options['handle']=$handle;
137
		$options['revert']=$this->getRevert();
138
		if (($constraint=$this->getConstraint())!==TDraggableConstraint::None) $options['constraint']=strtolower($constraint);
139
		$options['ghosting']=$this->getGhosting();
140
 
141
		return $options;
142
	}
143
 
144
}
145
 
146
class TDraggableConstraint extends TEnumerable
147
{
148
	const None='None';
149
	const Horizontal='Horizontal';
150
	const Vertical='Vertical';
151
}
152
?>