Zend_ProgressBar_Adapter_JsPush.xml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. <acronym>HTML</acronym>. 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 finish
  67. </para>
  68. </listitem>
  69. <listitem>
  70. <para>
  71. <code>text</code>: The optional status message, if given
  72. </para>
  73. </listitem>
  74. </itemizedlist>
  75. <example id="zend.progressbar-adapter.jspush.example">
  76. <title>Basic example for the client-side stuff</title>
  77. <para>
  78. This example illustrates a basic setup of <acronym>HTML</acronym>,
  79. <acronym>CSS</acronym> and JavaScript for the JsPush adapter
  80. </para>
  81. <programlisting language="html"><![CDATA[
  82. <div id="zend-progressbar-container">
  83. <div id="zend-progressbar-done"></div>
  84. </div>
  85. <iframe src="long-running-process.php" id="long-running-process"></iframe>
  86. ]]></programlisting>
  87. <programlisting language="css"><![CDATA[
  88. #long-running-process {
  89. position: absolute;
  90. left: -100px;
  91. top: -100px;
  92. width: 1px;
  93. height: 1px;
  94. }
  95. #zend-progressbar-container {
  96. width: 100px;
  97. height: 30px;
  98. border: 1px solid #000000;
  99. background-color: #ffffff;
  100. }
  101. #zend-progressbar-done {
  102. width: 0;
  103. height: 30px;
  104. background-color: #000000;
  105. }
  106. ]]></programlisting>
  107. <programlisting language="javascript"><![CDATA[
  108. function Zend_ProgressBar_Update(data)
  109. {
  110. document.getElementById('zend-progressbar-done').style.width =
  111. 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>
  128. Dojo: <ulink
  129. url="http://dojotoolkit.org/reference-guide/dijit/ProgressBar.html"/>
  130. </para>
  131. </listitem>
  132. <listitem>
  133. <para>
  134. jQuery: <ulink url="http://t.wits.sg/2008/06/20/jquery-progress-bar-11/" />
  135. </para>
  136. </listitem>
  137. <listitem>
  138. <para>
  139. MooTools: <ulink url="http://davidwalsh.name/dw-content/progress-bar.php" />
  140. </para>
  141. </listitem>
  142. <listitem>
  143. <para>
  144. Prototype: <ulink url="http://livepipe.net/control/progressbar" />
  145. </para>
  146. </listitem>
  147. </itemizedlist>
  148. </example>
  149. <note>
  150. <title>Interval of updates</title>
  151. <para>
  152. You should take care of not sending too many updates, as every update
  153. has a min-size of 1kb. This is a requirement for the Safari browser
  154. to actually render and execute the function call. Internet Explorer
  155. has a similar limitation of 256 bytes.
  156. </para>
  157. </note>
  158. </sect3>
  159. <!--
  160. vim:se ts=4 sw=4 et:
  161. -->