Zend_ProgressBar_Adapter_JsPush.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.progressbar.adapter.jspush">
  4. <title>Zend_ProgressBar_Adapter_JsPush</title>
  5. <para>
  6. <classname>Zend_ProgressBar_Adapter_JsPush</classname> is an adapter which let's
  7. you update a progressbar in a browser via Javascript Push. This means
  8. that no second connection is required to gather the status about a
  9. running process, but that the process itself sends its status directly
  10. to the browser.
  11. </para>
  12. <para>
  13. You can set the adapter options either via the <code>set*</code> methods
  14. or give an array or a <classname>Zend_Config</classname> instance with options as first
  15. parameter to the constructor. The available options are:
  16. </para>
  17. <itemizedlist>
  18. <listitem>
  19. <para>
  20. <code>updateMethodName</code>: The javascript method which
  21. should be called on every update. Default value is
  22. <classname>Zend_ProgressBar_Update</classname>.
  23. </para>
  24. </listitem>
  25. <listitem>
  26. <para>
  27. <code>finishMethodName</code>: The javascript method which
  28. should be called after finish status was set. Default value is
  29. <constant>NULL</constant>, which means nothing is done.
  30. </para>
  31. </listitem>
  32. </itemizedlist>
  33. <para>
  34. The usage of this adapter is quite simple. First you create a progressbar
  35. in your browser, either with JavaScript or previously created with plain
  36. HTML. Then you define the update method and optionally the finish method
  37. in JavaScript, both taking a json object as single argument. Then you
  38. call a webpage with the long-running process in a hidden
  39. <code>iframe</code> or <code>object</code> tag. While the process is
  40. running, the adapter will call the update method on every update with
  41. a json object, containing the following parameters:
  42. </para>
  43. <itemizedlist>
  44. <listitem>
  45. <para>
  46. <code>current</code>: The current absolute value
  47. </para>
  48. </listitem>
  49. <listitem>
  50. <para>
  51. <code>max</code>: The max absolute value
  52. </para>
  53. </listitem>
  54. <listitem>
  55. <para>
  56. <code>percent</code>: The calculated percentage
  57. </para>
  58. </listitem>
  59. <listitem>
  60. <para>
  61. <code>timeTaken</code>: The time how long the process ran yet
  62. </para>
  63. </listitem>
  64. <listitem>
  65. <para>
  66. <code>timeRemaining</code>: The expected time for the process to
  67. finish
  68. </para>
  69. </listitem>
  70. <listitem>
  71. <para>
  72. <code>text</code>: The optional status message, if given
  73. </para>
  74. </listitem>
  75. </itemizedlist>
  76. <example id="zend.progressbar-adapter.jspush.example">
  77. <title>Basic example for the client-side stuff</title>
  78. <para>
  79. This example illustrates a basic setup of HTML, <acronym>CSS</acronym> and JavaScript
  80. for the JsPush adapter
  81. </para>
  82. <programlisting language="html"><![CDATA[
  83. <div id="zend-progressbar-container">
  84. <div id="zend-progressbar-done"></div>
  85. </div>
  86. <iframe src="long-running-process.php" id="long-running-process"></iframe>
  87. ]]></programlisting>
  88. <programlisting language="css"><![CDATA[
  89. #long-running-process {
  90. position: absolute;
  91. left: -100px;
  92. top: -100px;
  93. width: 1px;
  94. height: 1px;
  95. }
  96. #zend-progressbar-container {
  97. width: 100px;
  98. height: 30px;
  99. border: 1px solid #000000;
  100. background-color: #ffffff;
  101. }
  102. #zend-progressbar-done {
  103. width: 0;
  104. height: 30px;
  105. background-color: #000000;
  106. }
  107. ]]></programlisting>
  108. <programlisting language="javascript"><![CDATA[
  109. function Zend_ProgressBar_Update(data)
  110. {
  111. document.getElementById('zend-progressbar-done').style.width = data.percent + '%';
  112. }
  113. ]]></programlisting>
  114. <para>
  115. This will create a simple container with a black border and a
  116. block which indicates the current process. You should not hide
  117. the <code>iframe</code> or <code>object</code> by <code>display: none;</code>,
  118. as some browsers like Safari 2 will not load the actual content then.
  119. </para>
  120. <para>
  121. Instead of creating your custom progressbar, you may want to use
  122. one of the available JavaScript libraries like Dojo, jQuery etc.
  123. For example, there are:
  124. </para>
  125. <itemizedlist>
  126. <listitem>
  127. <para>Dojo: <ulink url="http://dojotoolkit.org/book/dojo-book-0-9/part-2-dijit/user-assistance-and-feedback/progress-bar" /></para>
  128. </listitem>
  129. <listitem>
  130. <para>jQuery: <ulink url="http://t.wits.sg/2008/06/20/jquery-progress-bar-11/" /></para>
  131. </listitem>
  132. <listitem>
  133. <para>MooTools: <ulink url="http://davidwalsh.name/dw-content/progress-bar.php" /></para>
  134. </listitem>
  135. <listitem>
  136. <para>Prototype: <ulink url="http://livepipe.net/control/progressbar" /></para>
  137. </listitem>
  138. </itemizedlist>
  139. </example>
  140. <note>
  141. <title>Interval of updates</title>
  142. <para>
  143. You should take care of not sending too many updates, as every update
  144. has a min-size of 1kb. This is a requirement for the Safari browser
  145. to actually render and execute the function call. Internet Explorer
  146. has a similar limitation of 256 bytes.
  147. </para>
  148. </note>
  149. </sect3>
  150. <!--
  151. vim:se ts=4 sw=4 et:
  152. -->