summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/TClientScript.php
blob: 5047959dd45320e72e7b90eb8725e0d3df432787 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php


/**
 * PradoClientScript class.
 *
 * Resolves Prado client script dependencies. e.g. TPradoClientScript::getScripts("dom");
 *
 * - <b>base</b> basic javascript utilities, e.g. $()
 * - <b>dom</b> DOM and Form functions, e.g. $F(inputID) to retrive form input values.
 * - <b>effects</b> Effects such as fade, shake, move
 * - <b>controls</b> Prado client-side components, e.g. Slider, AJAX components
 * - <b>validator</b> Prado client-side validators.
 * - <b>ajax</b> Prado AJAX library including Prototype's AJAX and JSON.
 *
 * Dependencies for each library are automatically resolved.
 *
 * Namespace: System.Web.UI
 *
 * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
 * @version $Revision: 1.1 $  $Date: 2005/11/06 23:02:33 $
 * @package System.Web.UI
 */
class TClientScript
{
	protected $_manager;
	
	/**
	 * Client-side javascript library dependencies
	 * @var array
	 */
	protected static $_dependencies = array(
		'prado' => array('prado'),
		'effects' => array('prado', 'effects'),
		'ajax' => array('prado', 'effects', 'ajax'),
		'validator' => array('prado', 'validator'),
		'logger' => array('prado', 'logger'),
		'datepicker' => array('prado', 'datepicker'),
		'rico' => array('prado', 'effects', 'ajax', 'rico'),
		'colorpicker' => array('prado', 'colorpicker')
		);

	public function __construct($manager)
	{
		$this->_manager = $manager;
	}

	/**
	 * Resolve dependencies for the given library.
	 * @param array list of libraries to load.
	 * @return array list of libraries including its dependencies.
	 */
	public function getScripts($scripts)
	{
		$files = array();
		if(!is_array($scripts)) $scripts = array($scripts);
		foreach($scripts as $script)
		{
			if(isset(self::$_dependencies[$script]))
				$files = array_merge($files, self::$_dependencies[$script]);
			$files[] = $script;
		}
		$files = array_unique($files);
		return $files;
	}
	
	
	/**
	 * TODO: clean up
	 *
	public function getPostBackEventReference($control,$parameter='',$options=null,$javascriptPrefix=true)
	{
		if(!$options || (!$options->getPerformValidation() && !$options->getTrackFocus() && $options->getClientSubmit() && $options->getActionUrl()==''))
		{
			$this->registerPostBackScript();
			if(($form=$this->_page->getForm())!==null)
				$formID=$form->getClientID();
			else
				throw new TConfigurationException('clientscriptmanager_form_required');
			$postback=self::POSTBACK_FUNC.'(\''.$formID.'\',\''.$control->getUniqueID().'\',\''.THttpUtility::quoteJavaScriptString($parameter).'\')';
			if($options && $options->getAutoPostBack())
				$postback='setTimeout(\''.THttpUtility::quoteJavaScriptString($postback).'\',0)';
			return $javascriptPrefix?'javascript:'.$postback:$postback;
		}
		$opt='';
		$flag=false;
		if($options->getPerformValidation())
		{
			$flag=true;
			$this->registerValidationScript();
			$opt.=',true,';
		}
		else
			$opt.=',false,';
		if($options->getValidationGroup()!=='')
		{
			$flag=true;
			$opt.='"'.$options->getValidationGroup().'",';
		}
		else
			$opt.='\'\',';
		if($options->getActionUrl()!=='')
		{
			$flag=true;
			$this->_page->setCrossPagePostBack(true);
			$opt.='"'.$options->getActionUrl().'",';
		}
		else
			$opt.='null,';
		if($options->getTrackFocus())
		{
			$flag=true;
			$this->registerFocusScript();
			$opt.='true,';
		}
		else
			$opt.='false,';
		if($options->getClientSubmit())
		{
			$flag=true;
			$opt.='true';
		}
		else
			$opt.='false';
		if(!$flag)
			return '';
		$this->registerPostBackScript();
		if(($form=$this->_page->getForm())!==null)
			$formID=$form->getClientID();
		else
			throw new TConfigurationException('clientscriptmanager_form_required');
		$postback=self::POSTBACK_FUNC.'(\''.$formID.'\',\''.$control->getUniqueID().'\',\''.THttpUtility::quoteJavaScriptString($parameter).'\''.$opt.')';
		if($options && $options->getAutoPostBack())
			$postback='setTimeout(\''.THttpUtility::quoteJavaScriptString($postback).'\',0)';
		return $javascriptPrefix?'javascript:'.$postback:$postback;
	}*/	
	
}

?>