PageRenderTime 47ms CodeModel.GetById 10ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 1ms

/source/Plug-in/xajax/xajax_plugins/response/tableUpdater.inc.php

http://prosporous.googlecode.com/
PHP | 292 lines | 217 code | 13 blank | 62 comment | 56 complexity | f97baaf28b11e00662a28c2a2fa60782 MD5 | raw file
  1<?php
  2/*
  3	File: tableUpdater.inc.php
  4
  5	Contains a class that can be used to invoke DOM calls on the browser which
  6	will create or update an HTML table.
  7
  8	Title: clsTableUpdater class
  9
 10	Please see <copyright.inc.php> for a detailed description, copyright
 11	and license information.
 12*/
 13
 14if (false == class_exists('xajaxPlugin') || false == class_exists('xajaxPluginManager'))
 15{
 16	$sBaseFolder = dirname(dirname(dirname(__FILE__)));
 17	$sXajaxCore = $sBaseFolder . '/xajax_core';
 18	
 19	if (false == class_exists('xajaxPlugin'))
 20		require $sXajaxCore . '/xajaxPlugin.inc.php';
 21	if (false == class_exists('xajaxPluginManager'))
 22		require $sXajaxCore . '/xajaxPluginManager.inc.php';
 23}
 24
 25/*
 26	Class: clsTableUpdater
 27*/
 28class clsTableUpdater extends xajaxResponsePlugin
 29{
 30	/*
 31		String: sDefer
 32		
 33		Used to store the state of the scriptDeferral configuration setting.  When
 34		script deferral is desired, this member contains 'defer' which will request
 35		that the browser defer loading of the javascript until the rest of the page 
 36		has been loaded.
 37	*/
 38	var $sDefer;
 39	
 40	/*
 41		String: sJavascriptURI
 42		
 43		Used to store the base URI for where the javascript files are located.  This
 44		enables the plugin to generate a script reference to it's javascript file
 45		if the javascript code is NOT inlined.
 46	*/
 47	var $sJavascriptURI;
 48	
 49	/*
 50		Boolean: bInlineScript
 51		
 52		Used to store the value of the inlineScript configuration option.  When true,
 53		the plugin will return it's javascript code as part of the javascript header
 54		for the page, else, it will generate a script tag referencing the file by
 55		using the <clsTableUpdater->sJavascriptURI>.
 56	*/
 57	var $bInlineScript;
 58	
 59	/*
 60		Function: clsTableUpdater
 61		
 62		Constructs and initializes an instance of the table updater class.
 63	*/
 64	function clsTableUpdater()
 65	{
 66		$this->sDefer = '';
 67		$this->sJavascriptURI = '';
 68		$this->bInlineScript = true;
 69	}
 70	
 71	/*
 72		Function: configure
 73		
 74		Receives configuration settings set by <xajax> or user script calls to 
 75		<xajax->configure>.
 76		
 77		sName - (string):  The name of the configuration option being set.
 78		mValue - (mixed):  The value being associated with the configuration option.
 79	*/
 80	function configure($sName, $mValue)
 81	{
 82		if ('scriptDeferral' == $sName) {
 83			if (true === $mValue || false === $mValue) {
 84				if ($mValue) $this->sDefer = 'defer ';
 85				else $this->sDefer = '';
 86			}
 87		} else if ('javascript URI' == $sName) {
 88			$this->sJavascriptURI = $mValue;
 89		} else if ('inlineScript' == $sName) {
 90				if (true === $mValue || false === $mValue)
 91					$this->bInlineScript = $mValue;
 92			}
 93	}
 94	
 95	/*
 96		Function: generateClientScript
 97		
 98		Called by the <xajaxPluginManager> during the script generation phase.  This
 99		will either inline the script or insert a script tag which references the
100		<tableUpdater.js> file based on the value of the <clsTableUpdater->bInlineScript>
101		configuration option.
102	*/
103	function generateClientScript()
104	{
105		if ($this->bInlineScript)
106		{
107			echo "\n<script type='text/javascript' " . $this->sDefer . "charset='UTF-8'>\n";
108			echo "/* <![CDATA[ */\n";
109			
110			include(dirname(__FILE__) . '/tableUpdater.js');
111			
112			echo "/* ]]> */\n";
113			echo "</script>\n";
114		} else {
115			echo "\n<script type='text/javascript' src='" . $this->sJavascriptURI . "tableUpdater.js' " . $this->sDefer . "charset='UTF-8'>\n";
116		}
117	}
118	
119	function getName()
120	{
121		return get_class($this);
122	}
123	
124	// tables
125	function appendTable($table, $parent) {
126		$command = array(
127				'cmd'=>'et_at', 
128				'id'=>$parent
129				);
130		$this->addCommand($command, $table);	
131	}
132	function insertTable($table, $parent, $position) {
133		$command = array(
134				'cmd'=>'et_it', 
135				'id'=>$parent, 
136				'pos'=>$position
137				);
138		$this->addCommand($command, $table);
139	}
140	function deleteTable($table) {
141		$this->addCommand(
142				array(
143					'cmd'=>'et_dt'
144					), 
145				$table
146				);
147	}
148	// rows
149	function appendRow($row, $parent, $position = null) {
150		$command = array(
151				'cmd'=>'et_ar', 
152				'id'=>$parent
153				);
154		if (null != $position)
155			$command['pos'] = $position;
156		$this->addCommand($command, $row);
157	}
158	function insertRow($row, $parent, $position = null, $before = null) {
159		$command = array(
160				'cmd'=>'et_ir', 
161				'id'=>$parent
162				);
163		if (null != $position)
164			$command['pos'] = $position;
165		if (null != $before)
166			$command['type'] = $before;
167		$this->addCommand($command, $row);
168	}
169	function replaceRow($row, $parent, $position = null, $before = null) {
170		$command = array(
171				'cmd'=>'et_rr', 
172				'id'=>$parent
173				);
174		if (null != $position)
175			$command['pos'] = $position;
176		if (null != $before)
177			$command['type'] = $before;
178		$this->addCommand($command, $row);
179	}
180	function deleteRow($parent, $position = null) {
181		$command = array(
182				'cmd'=>'et_dr', 
183				'id'=>$parent
184				);
185		if (null != $position)
186			$command['pos'] = $position;
187		$this->addCommand($command, null);
188	}
189	function assignRow($values, $parent, $position = null, $start_column = null) {
190		$command = array(
191				'cmd'=>'et_asr', 
192				'id'=>$parent
193				);
194		if (null != $position)
195			$command['pos'] = $position;
196		if (null != $start_column)
197			$command['type'] = $start_column;
198		$this->addCommand($command, $values);
199	}
200	function assignRowProperty($property, $value, $parent, $position = null) {
201		$command = array(
202				'cmd'=>'et_asrp', 
203				'id'=>$parent,
204				'prop'=>$property
205				);
206		if (null != $position)
207			$command['pos'] = $position;
208		$this->addCommand($command, $value);
209	}
210	// columns
211	function appendColumn($column, $parent, $position = null) {
212		$command = array(
213				'cmd'=>'et_acol', 
214				'id'=>$parent
215				);
216		if (null != $position)
217			$command['pos'] = $position;
218		$this->addCommand($command, $column);
219	}
220	function insertColumn($column, $parent, $position = null) {
221		$command = array(
222				'cmd'=>'et_icol', 
223				'id'=>$parent
224				);
225		if (null != $position)
226			$command['pos'] = $position;
227		$this->addCommand($command, $column);
228	}
229	function replaceColumn($column, $parent, $position = null) {
230		$command = array(
231				'cmd'=>'et_rcol', 
232				'id'=>$parent
233				);
234		if (null != $position)
235			$command['pos'] = $position;
236		$this->addCommand($command, $column);
237	}
238	function deleteColumn($parent, $position = null) {
239		$command = array(
240				'cmd'=>'et_dcol', 
241				'id'=>$parent
242				);
243		if (null != $position)
244			$command['pos'] = $position;
245		$this->addCommand($command, null);
246	}
247	function assignColumn($values, $parent, $position = null, $start_row = null) {
248		$command = array(
249				'cmd'=>'et_ascol', 
250				'id'=>$parent
251				);
252		if (null != $position)
253			$command['pos'] = $position;
254		if (null != $start_row)
255			$command['type'] = $start_row;
256		$this->addCommand($command, $values);
257	}
258	function assignColumnProperty($property, $value, $parent, $position = null) {
259		$command = array(
260				'cmd'=>'et_ascolp', 
261				'id'=>$parent,
262				'prop'=>$property
263				);
264		if (null != $position)
265			$command['pos'] = $position;
266		$this->addCommand($command, $value);
267	}
268	function assignCell($row, $column, $value) {
269		$this->addCommand(
270				array(
271					'cmd'=>'et_asc', 
272					'id'=>$row, 
273					'pos'=>$column
274					), 
275				$value
276				);
277	}
278	function assignCellProperty($row, $column, $property, $value) {
279		$this->addCommand(
280				array(
281					'cmd'=>'et_ascp', 
282					'id'=>$row, 
283					'pos'=>$column,
284					'prop'=>$property
285					), 
286				$value
287				);
288	}
289}
290
291$objPluginManager =& xajaxPluginManager::getInstance();
292$objPluginManager->registerPlugin(new clsTableUpdater());