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