Пример #1
0
 /**
  * Returns the HTML rendered field as '<input type="text"'.
  * @return string
  */
 public function getAsText()
 {
     $id = $this->getId();
     $header = "<input id='{$id}input' type='text' ";
     $close_header = '/>';
     if (!$this->isEnabled()) {
         $header .= 'disabled="disabled" ';
     }
     $sReturn = $this->composeLabel() . $header . $this->composeStringProperties() . $this->composeStringValue() . $this->composeStringActions() . $close_header;
     if ($this->isEnabled()) {
         if (is_object($this->data) and $this->data instanceof P4A_DB_Source) {
             $sReturn .= "<script type='text/javascript'>\$(function(){p4a_autocomplete_load(function(){\$('#{$id}input').autocomplete({source:'index.php?_p4a_autocomplete&_object={$id}',minLength:2})});});</script>";
         } elseif ($this->input_mask !== null) {
             $sReturn .= "<script type='text/javascript'>\$(function(){p4a_maskedinput('{$id}','" . P4A_Quote_Javascript_String($this->input_mask) . "')});</script>";
         }
     }
     return $sReturn;
 }
Пример #2
0
 /**
  * Composes a string containing all the actions implemented by the widget.
  * Note: it will also contain the name and the value.
  * @param array $params
  * @param boolean $check_enabled_state
  * @return string
  */
 public function composeStringActions($params = null, $check_enabled_state = true)
 {
     if ($check_enabled_state and !$this->isEnabled()) {
         return '';
     }
     $sParams = '';
     $sActions = '';
     if (is_string($params) or is_numeric($params)) {
         $params = P4A_Quote_Javascript_String($params);
         $params = str_replace('\\', '\\\\', $params);
         $sParams .= ", '{$params}'";
     } elseif (is_array($params) and count($params)) {
         $sParams = ', ';
         foreach ($params as $param) {
             $param = P4A_Quote_Javascript_String($param);
             $params = str_replace('\\', '\\\\', $param);
             $sParams .= "'{$param}', ";
         }
         $sParams = substr($sParams, 0, -2);
     }
     foreach ($this->actions as $action => $action_data) {
         $browser_action = $action;
         $return = 'false';
         $prefix = '';
         $suffix = '';
         if ($action == 'onreturnpress') {
             $browser_action = 'onkeypress';
             $return = 'true';
             $prefix .= 'if(p4a_keypressed_is_return(event)){';
             $suffix .= 'return false;}';
         } elseif ($action == 'onkeypress' or $action == 'onkeydown' or $action == 'onkeyup') {
             $sParams .= ", p4a_keypressed_get(event)";
         }
         if ($action_data['confirm'] !== null) {
             $prefix .= 'if(confirm(\'' . P4A_Quote_Javascript_String(__($action_data['confirm'])) . '\')){';
             $suffix .= '}';
         }
         if (isset($action_data['ajax']) and $action_data['ajax'] == 1) {
             $execute = 'p4a_event_execute_ajax';
         } else {
             $execute = 'p4a_event_execute';
         }
         if (isset($action_data['event'])) {
             $action_data_event = $action_data['event'];
         } else {
             $action_data_event = '';
         }
         $sActions .= $browser_action . '="' . $prefix . "{$execute}('" . $this->getId() . '\', \'' . $action_data_event . '\'' . $sParams . ');' . $suffix . ' return ' . $return . ';" ';
     }
     return $sActions;
 }