Source for file OCSP_FRMCONTR_JQUERY.phpclass

Documentation is available at OCSP_FRMCONTR_JQUERY.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_FRMCONTR_JQUERY.phpclass
  4.   *
  5.   *
  6.   * @project    Open CSP-Management
  7.   * @package    forms
  8.   * @category   dbms_form
  9.   *
  10.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   * @since  pk-07-07-02
  14.   *
  15.   * @version $Id: OCSP_FRMCONTR_JQUERY.phpclass,v 1.16 2008/10/12 14:55:25 pitlinz Exp $
  16.   */
  17.  
  18. if (!class_exists('OCSP_FRMCONTR_FORM'))
  19. {
  20.     require_once dirname(__FILE__)._OCSP_DIRSEP_."OCSP_FRMCONTR_FORM.phpclass";
  21. }
  22.  
  23.  
  24.  
  25. /**
  26.   * class OCSP_FRMCONTR_JQUERY
  27.   *
  28.   * @project    Open CSP-Management
  29.   * @package    forms
  30.   * @category   dbms_form
  31.   *
  32.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  33.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  34.   *
  35.   * @since  pk-07-07-02
  36.   *
  37.   * @version $Id: OCSP_FRMCONTR_JQUERY.phpclass,v 1.16 2008/10/12 14:55:25 pitlinz Exp $
  38.   */
  39. {
  40.  
  41.     /*** Aggregations: */
  42.  
  43.  
  44.     /*** Compositions: */
  45.  
  46.  
  47.     /*** Attributes: */
  48.  
  49.     /**
  50.       * @var string $myJQFormArgs arguments passed $('#".$this->getFormHTMLId()."').ajaxForm(".$this->myJQFormArgs.")
  51.       * @access protected
  52.       */
  53.     protected $myJQFormArgs="";
  54.  
  55.  
  56.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  57.     // init methods
  58.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59.  
  60.  
  61.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62.     // getter/setter methods
  63.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64.  
  65.     /**
  66.       * returns the action URL if set otherwise the default action for $this->myMode
  67.       *
  68.       * @param boolean $debug 
  69.       *
  70.       * @global array $OCSP_CONF (['SYSTEMURL'])
  71.       * @return string 
  72.       *
  73.       */
  74.     function getActionURL($debug=FALSE)
  75.     {
  76.         global $OCSP_CONF;
  77.  
  78.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::getAction()","MODE: ".$this->myMode);
  79.         if (!empty($this->myActionURL))
  80.         {
  81.             return $this->myActionURL;
  82.         else if ($this->myActionURL = $this->myForm->getSubmitAction($this->myForm->getFrmMode(),'ACTION')) {
  83.             return $this->myActionURL;
  84.         else {
  85.             return $OCSP_CONF['SYSTEMURL']."forms/jQuerySave.php?".$_SERVER['QUERY_STRING'];
  86.         }
  87.     }
  88.  
  89.     /**
  90.       * @param int $aMode 
  91.       * @param boolean $debug 
  92.       *
  93.       * @return string 
  94.       *
  95.       * @access public
  96.       */
  97.     function getFormEvents($aMode=FRM_MODE_READONLY,$debug=FALSE)
  98.     {
  99.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_JQUERY::getFormEvents()");
  100.         $str_ret=parent::getFormEvents($aMode,$debug);
  101.         if (!stristr($str_ret," id=\""))
  102.         {
  103.             $str_ret.=" id=\"".$this->myForm->getHTMLName()."\"";
  104.         }
  105.         return $str_ret;
  106.     }
  107.  
  108.     /**
  109.       * returns the jQueryForm args
  110.       * NOTE if empty a default string is returned
  111.       *
  112.       * @return string 
  113.       *
  114.       * @todo add js field checks beforeSubmit
  115.       *
  116.       */
  117.     function getMyJQFormArgs()
  118.     {
  119.         if (!empty($this->myJQFormArgs))
  120.         {
  121.             return $this->myJQFormArgs;
  122.         else {
  123.             return "{
  124.                 async: false,
  125.                 dataType: 'json',
  126.                 beforeSubmit: function(formArray, jqForm) {
  127.                     jOCSP.logFormSubmit('" $_SERVER['REQUEST_URI'"',formArray);
  128.                     window.status='&Uuml;bertrage Daten';
  129.                 },
  130.                 error: function(xml, status, e) {
  131.                     jOCSP.addError('Submit Form: " $this->myForm->getId("', + xml.responseText + '\\n--------------\\n' + e);
  132.                     alert('Fehler:'+xml.responseText+e);
  133.                 },
  134.                 success: function(data) {
  135.                     try {
  136.                         if (data.jscmd)
  137.                         {
  138.                             try {
  139.                                 eval(data.jscmd)
  140.                             }  catch (e) {
  141.                                 ocspAjax_showErrMsg('Caught error ' + e + ': Could not eval ' + data.jscmd );
  142.                             }
  143.                         }
  144.     
  145.                         if (data.errors)
  146.                         {
  147.                             ocspAjax_setIdHtml('errors_form_".$this->myForm->getHTMLName()."',data.errors);
  148.                         }
  149.     
  150.                         if (data.fldErrors)
  151.                         {                                               
  152.                             try {
  153.                                 if (obj_form = jOCSP.getFormByHash('" $this->jOCSP_getfrmHash("'))
  154.                                 {
  155.                                     obj_form.showFieldErrors(data.fldErrors)
  156.                                 } else {
  157.                                     ocsp_form_ShowFldErrors(data.fldErrors);
  158.                                 }
  159.                             } catch(e) {
  160.                                 alert('error getting form: " $this->jOCSP_getfrmHash("\\nin " basename(__FILE__" Line : " . __LINE__ . "\\n' + e);
  161.                             }                            
  162.                         }
  163.     
  164.                         if (data.message)
  165.                         {
  166.                             alert(data.message);
  167.                         }
  168.                         if (data.b64message)
  169.                         {
  170.                             alert(base64decode(data.b64message));
  171.                         }
  172.     
  173.                         if (data.debug)
  174.                         {
  175.                             ocspAjax_setIdHtml('ocsp_debugOutput',data.debug);
  176.                         }
  177.                     } catch(e) {
  178.                            alert('errors in " basename(__FILE__" Line : " . __LINE__ . "\\n' + e);
  179.                     }
  180.                  }
  181.                 
  182.             }";
  183.         }
  184.     }
  185.  
  186.     /**
  187.       * @param string $args 
  188.       */
  189.     function setMyJQFormArgs($args)
  190.     {
  191.         $this->myJQFormArgs=$args;
  192.     }
  193.  
  194.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195.     // form db methods
  196.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  197.  
  198.  
  199.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  200.     // controll elementes
  201.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  202.  
  203.     // javascript to add (after </form>);
  204.  
  205.     /**
  206.       * @param boolean $debug 
  207.       * @return string 
  208.       */
  209.     function getFormJavaScript($debug=FALSE)
  210.     {
  211.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_JQUERY::getFormJavaScript()");
  212.         $str_args=(empty($this->myJQFormArgs"function() {}" $this->myJQFormArgs);
  213.  
  214.         $str_ret="
  215.             jQuery(function() {jQuery('#".$this->getFormHTMLId()."').ajaxForm(".$this->myJQFormArgs.")});
  216.         ";
  217.         return $str_ret;
  218.     }
  219.  
  220.     // form tag <form ...>
  221.  
  222.     /**
  223.      * returns the html code for the submit button
  224.      *  
  225.      * @param boolean $debug 
  226.      * 
  227.      * @global array $OCSP_CONF 
  228.      * 
  229.      * @return string 
  230.      */
  231.     function getSubmitButton($debug=FALSE)
  232.     {
  233.         global $OCSP_CONF;
  234.         
  235.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_JQUERY::getSubmitButton()");
  236.         $str_ret=$this->myView->getButtonOuterDiv($debug);
  237.         $str_ret.="<a href=\"#\" onClick=\"";
  238.         
  239.         $str_ret.="
  240.                 if (obj_form = jOCSP.getFormByHash('" $this->jOCSP_getfrmHash("'))
  241.                 {
  242.                     for (str_fldId in obj_form.myFields)
  243.                     {
  244.                         if (typeof(obj_form.myFields[str_fldId].beforeSubmit) == 'function')
  245.                         {
  246.                             obj_form.myFields[str_fldId].beforeSubmit();
  247.                         }
  248.                     }
  249.                 }
  250.             ";
  251.         
  252.         
  253.         if ($this->myTarget == "_debug")
  254.         {
  255.             $str_ret.="document.forms['".$this->getFormHTMLId()."'].submit();";
  256.         else {
  257.             $str_ret.=$this->getFormJavaScript($debug);
  258.             $str_ret.="jQuery('#".$this->getFormHTMLId()."').ajaxSubmit(".$this->getMyJQFormArgs().");";
  259.         }
  260.         $str_ret.="\">";
  261.         $str_ret.=$this->myView->getButton('SAVE');
  262.         $str_ret.="</a></div>\n";
  263.         
  264.         /*
  265.         if ($obj_ajax=$this->myForm->ajax_getObj(FALSE))
  266.         {
  267.             $obj_ajax->addJsCode($str_javaScript);
  268.             if ($debug) $str_ret.="<p><strong>ajax jsCode:</strong></p><pre>".$str_javaScript."</pre>";
  269.         } else {
  270.             $str_ret.="<script language=\"javascript\" type=\"text/javascript\">\n<!--";
  271.             $str_ret.=$str_javaScript;
  272.             $str_ret.="\n//-->\n</script>\n";
  273.         }        
  274.         */          
  275.       
  276.         return $str_ret;
  277.     }
  278.  
  279.     /**
  280.       * @param boolea $debug 
  281.       * @return string 
  282.       */
  283.     function getResetButton($debug=FALSE)
  284.     {
  285.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_JQUERY::getResetButton()");
  286.         $str_ret=$this->myView->getButtonOuterDiv($debug);
  287.         $str_ret.="<a href=\"#\" onClick=\"\$('#".$this->getFormHTMLId()."').resetForm();\">";
  288.         $str_ret.=$this->myView->getButton('RESET');
  289.         $str_ret.="</a></div>\n";
  290.         return $str_ret;
  291.     }
  292.  
  293.  
  294.     // footer
  295.  
  296. // end of OCSP_FRMCONTR_FORM
  297. ?>

Documentation generated on Thu, 08 Jan 2009 17:46:26 +0100 by phpDocumentor 1.4.0a2