home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / form-sample.js < prev    next >
Encoding:
JavaScript  |  2004-07-12  |  1.8 KB  |  56 lines

  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. // This is a simple flow script
  17. // that can be used as an example for building forms
  18. //
  19. // The script gets the coplet id as a parameter. This id can be used
  20. // as a unique key for the coplet.
  21. //
  22. // The script below doesn't use any continuations. It just checks:
  23. // - if the user already has given some input (which is stored in
  24. //   a session attribute)
  25. // - if the user has just submitted some input
  26. // - if a form should be displayed 
  27. // - The function clear() clears the user input
  28. //
  29. function form() {
  30.     // get the coplet id
  31.     var cid = cocoon.parameters["copletId"];
  32.     var pname = cid + "/myform";
  33.  
  34.     if ( cocoon.session.getAttribute(pname) == null ) {
  35.         var name = cocoon.request.getParameter("name");
  36.         if ( name == null ) {
  37.             cocoon.sendPage("page/form", {});
  38.         } else {
  39.             cocoon.session.setAttribute(pname, name);
  40.             cocoon.sendPage("page/received", {"name" : name});         
  41.         }
  42.     } else {
  43.         var name = cocoon.session.getAttribute(pname);
  44.         cocoon.sendPage("page/content", {"name" : name});         
  45.     }
  46. }
  47.  
  48. function clear() {
  49.     // get the coplet id
  50.     var cid = cocoon.parameters["copletId"];
  51.     var pname = cid + "/myform";
  52.  
  53.     cocoon.session.removeAttribute(pname);
  54.     form();
  55. }
  56.