Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

204 rindas
9.1 KiB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Client Side Scripts &mdash; Documentation</title>
  7. <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '',
  12. VERSION: '',
  13. COLLAPSE_MODINDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/doctools.js"></script>
  20. <link rel="top" title="Documentation" href="index.html" />
  21. <link rel="up" title="Writing Scripts" href="writing_scripts.html" />
  22. <link rel="next" title="Creating Pages" href="creating_pages.html" />
  23. <link rel="prev" title="Server Side Scripts" href="server_side_script.html" />
  24. </head>
  25. <body>
  26. <div style="background-color: #FFF; text-align: left; padding: 8px 0px"><img src="_static/banner300910.gif"></div>
  27. <div class="related">
  28. <h3>Navigation</h3>
  29. <ul>
  30. <li class="right" style="margin-right: 10px">
  31. <a href="genindex.html" title="General Index"
  32. accesskey="I">index</a></li>
  33. <li class="right" >
  34. <a href="modindex.html" title="Global Module Index"
  35. accesskey="M">modules</a> |</li>
  36. <li class="right" >
  37. <a href="creating_pages.html" title="Creating Pages"
  38. accesskey="N">next</a> |</li>
  39. <li class="right" >
  40. <a href="server_side_script.html" title="Server Side Scripts"
  41. accesskey="P">previous</a> |</li>
  42. <li><a href="index.html">Documentation</a> &raquo;</li>
  43. <li><a href="build_app.html" >2. Building an Application</a> &raquo;</li>
  44. <li><a href="writing_scripts.html" accesskey="U">Writing Scripts</a> &raquo;</li>
  45. </ul>
  46. </div>
  47. <div class="sphinxsidebar">
  48. <div class="sphinxsidebarwrapper">
  49. <h3><a href="index.html">Table Of Contents</a></h3>
  50. <ul>
  51. <li><a class="reference external" href="">Client Side Scripts</a><ul>
  52. <li><a class="reference external" href="#introduction">Introduction</a></li>
  53. <li><a class="reference external" href="#cur-frm-object">cur_frm Object</a></li>
  54. <li><a class="reference external" href="#onload-event">onload event</a></li>
  55. <li><a class="reference external" href="#refersh-event">refersh event</a></li>
  56. <li><a class="reference external" href="#server-calls">Server Calls</a></li>
  57. <li><a class="reference external" href="#field-level-triggers">Field Level Triggers</a></li>
  58. <li><a class="reference external" href="#fetch-pattern">Fetch Pattern</a></li>
  59. </ul>
  60. </li>
  61. </ul>
  62. <h4>Previous topic</h4>
  63. <p class="topless"><a href="server_side_script.html"
  64. title="previous chapter">Server Side Scripts</a></p>
  65. <h4>Next topic</h4>
  66. <p class="topless"><a href="creating_pages.html"
  67. title="next chapter">Creating Pages</a></p>
  68. <h3>This Page</h3>
  69. <ul class="this-page-menu">
  70. <li><a href="_sources/client_side_script.txt"
  71. rel="nofollow">Show Source</a></li>
  72. </ul>
  73. <div id="searchbox" style="display: none">
  74. <h3>Quick search</h3>
  75. <form class="search" action="search.html" method="get">
  76. <input type="text" name="q" size="18" />
  77. <input type="submit" value="Go" />
  78. <input type="hidden" name="check_keywords" value="yes" />
  79. <input type="hidden" name="area" value="default" />
  80. </form>
  81. <p class="searchtip" style="font-size: 90%">
  82. Enter search terms or a module, class or function name.
  83. </p>
  84. </div>
  85. <script type="text/javascript">$('#searchbox').show(0);</script>
  86. </div>
  87. </div>
  88. <div class="document">
  89. <div class="documentwrapper">
  90. <div class="bodywrapper">
  91. <div class="body">
  92. <div class="section" id="client-side-scripts">
  93. <h1>Client Side Scripts<a class="headerlink" href="#client-side-scripts" title="Permalink to this headline">¶</a></h1>
  94. <div class="section" id="introduction">
  95. <h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
  96. <p>Client side scripts are written in javascript and they are used to execute function on event triggers.
  97. These scripts can be used to:</p>
  98. <ul class="simple">
  99. <li>Manipulate views</li>
  100. <li>Do server calls (AJAX)</li>
  101. <li>Validate entries</li>
  102. <li>Do calculations</li>
  103. </ul>
  104. <p>Client scripts can be written inside of DocType in the &#8220;Client Script&#8221; tab</p>
  105. </div>
  106. <div class="section" id="cur-frm-object">
  107. <h2>cur_frm Object<a class="headerlink" href="#cur-frm-object" title="Permalink to this headline">¶</a></h2>
  108. <p>All client script functions are attached to the cur_frm.cscript object. This object holds the functions
  109. relating to a DocType (form)</p>
  110. </div>
  111. <div class="section" id="onload-event">
  112. <h2>onload event<a class="headerlink" href="#onload-event" title="Permalink to this headline">¶</a></h2>
  113. <p>onload is called when the a record is loaded for the first time. Example:</p>
  114. <div class="highlight-python"><pre>cur_frm.cscript.onload = function(doc, doctype, docname) {
  115. if(!doc.from) {
  116. doc.from_user = user;
  117. refresh_field('user')
  118. }
  119. }</pre>
  120. </div>
  121. </div>
  122. <div class="section" id="refersh-event">
  123. <h2>refersh event<a class="headerlink" href="#refersh-event" title="Permalink to this headline">¶</a></h2>
  124. <p>refresh event is similar to the onload event. Except that it is also called each time the page is refreshed
  125. either via a user refresh, save or otherwise.</p>
  126. </div>
  127. <div class="section" id="server-calls">
  128. <h2>Server Calls<a class="headerlink" href="#server-calls" title="Permalink to this headline">¶</a></h2>
  129. <p>A typical use is to get/set data at server side. To do this, the framework has built-in AJAX interface using
  130. the $c_obj (call server object) function. The typical pattern is as follows:</p>
  131. <div class="highlight-python"><pre>// function will be called when the server responds
  132. var callback = function(response, responseInText) {
  133. // set the new value
  134. // re-assign the doc record because you are inside the callback
  135. var doc = locals[doc.doctype][doc.docname]
  136. doc.new_value = response.message
  137. refresh_field('new_value');
  138. }
  139. // call this object on the server
  140. $c_obj([doc], 'get_my_value', doc.based_on, callback);</pre>
  141. </div>
  142. </div>
  143. <div class="section" id="field-level-triggers">
  144. <h2>Field Level Triggers<a class="headerlink" href="#field-level-triggers" title="Permalink to this headline">¶</a></h2>
  145. <p>You can set functions to be called when values are changed in the form, at the &#8220;onchange&#8221; event.</p>
  146. <p>To set a trigger, in the Field table, set the value of the Trigger column to &#8220;Client&#8221;.</p>
  147. <p>Declare a function to be called by its fieldname:</p>
  148. <div class="highlight-python"><pre>// attach a trigger on the "my_value" field
  149. cur_frm.cscript.my_value = function(doc, doctype, docname) {
  150. msgrint("My value has been changed")
  151. // do something
  152. }</pre>
  153. </div>
  154. </div>
  155. <div class="section" id="fetch-pattern">
  156. <h2>Fetch Pattern<a class="headerlink" href="#fetch-pattern" title="Permalink to this headline">¶</a></h2>
  157. <p>Another typical pattern is to get values based on other values, like when you select a Customer, its type and
  158. contact info should come automatically, to do this, you can use the standard fetch pattern on link fields:</p>
  159. <div class="highlight-python"><pre>// add_fetch(link, source_field_name, target_field_name)</pre>
  160. </div>
  161. <p>add_fetch(&#8216;customer&#8217;, &#8216;contact_details&#8217;, &#8216;contact_details&#8217;)</p>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. <div class="clearer"></div>
  168. </div>
  169. <div class="related">
  170. <h3>Navigation</h3>
  171. <ul>
  172. <li class="right" style="margin-right: 10px">
  173. <a href="genindex.html" title="General Index"
  174. >index</a></li>
  175. <li class="right" >
  176. <a href="modindex.html" title="Global Module Index"
  177. >modules</a> |</li>
  178. <li class="right" >
  179. <a href="creating_pages.html" title="Creating Pages"
  180. >next</a> |</li>
  181. <li class="right" >
  182. <a href="server_side_script.html" title="Server Side Scripts"
  183. >previous</a> |</li>
  184. <li><a href="index.html">Documentation</a> &raquo;</li>
  185. <li><a href="build_app.html" >2. Building an Application</a> &raquo;</li>
  186. <li><a href="writing_scripts.html" >Writing Scripts</a> &raquo;</li>
  187. </ul>
  188. </div>
  189. <div class="footer">
  190. &copy; Copyright 2010, Rushabh Mehta.
  191. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
  192. </div>
  193. </body>
  194. </html>