Changeset 4361 in subversion


Ignore:
Timestamp:
Dec 22, 2010 1:25:02 PM (2 years ago)
Author:
thomasb
Message:

Add basic error reporting to rcube_addressbook; make warnings and errors appear longer in UI

Location:
branches/devel-addressbook/program
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-addressbook/program/include/rcube_addressbook.php

    r4271 r4361  
    2828abstract class rcube_addressbook 
    2929{ 
     30    /** constants for error reporting **/ 
     31    const ERROR_READ_ONLY = 1; 
     32    const ERROR_NO_CONNECTION = 2; 
     33    const ERROR_INCOMPLETE = 3; 
     34    const ERROR_SAVING = 4; 
     35     
    3036    /** public properties (mandatory) */ 
    3137    public $primary_key; 
     
    3642    public $page_size = 10; 
    3743    public $coltypes = array('name' => array('limit'=>1), 'firstname' => array('limit'=>1), 'surname' => array('limit'=>1), 'email' => array('limit'=>1)); 
     44     
     45    protected $error; 
    3846 
    3947    /** 
     
    100108     */ 
    101109    abstract function get_record($id, $assoc=false); 
     110 
     111    /** 
     112     * Returns the last error occured (e.g. when updating/inserting failed) 
     113     * 
     114     * @return array Hash array with the following fields: type, message 
     115     */ 
     116    function get_error() 
     117    { 
     118      return $this->error; 
     119    } 
     120     
     121    /** 
     122     * Setter for errors for internal use 
     123     * 
     124     * @param int Error type (one of this class' error constants) 
     125     * @param string Error message (name of a text label) 
     126     */ 
     127    protected function set_error($type, $message) 
     128    { 
     129      $this->error = array('type' => $type, 'message' => $message); 
     130    } 
    102131 
    103132    /** 
  • branches/devel-addressbook/program/include/rcube_ldap.php

    r4358 r4361  
    2727class rcube_ldap extends rcube_addressbook 
    2828{ 
    29   var $conn; 
    30   var $prop = array(); 
    31   var $fieldmap = array(); 
    32  
    33   var $filter = ''; 
    34   var $result = null; 
    35   var $ldap_result = null; 
    36   var $sort_col = ''; 
    37   var $mail_domain = ''; 
    38   var $debug = false; 
     29  protected $conn; 
     30  protected $prop = array(); 
     31  protected $fieldmap = array(); 
     32 
     33  protected $filter = ''; 
     34  protected $result = null; 
     35  protected $ldap_result = null; 
     36  protected $sort_col = ''; 
     37  protected $mail_domain = ''; 
     38  protected $debug = false; 
    3939 
    4040  /** public properties */ 
    41   var $primary_key = 'ID'; 
    42   var $readonly = true; 
    43   var $list_page = 1; 
    44   var $page_size = 10; 
    45   var $ready = false; 
    46   var $coltypes = array(); 
     41  public $primary_key = 'ID'; 
     42  public $readonly = true; 
     43  public $list_page = 1; 
     44  public $page_size = 10; 
     45  public $ready = false; 
     46  public $coltypes = array(); 
    4747 
    4848 
     
    524524    // Verify that the required fields are set. 
    525525    foreach ($this->prop['required_fields'] as $fld) { 
    526       $complete = true; 
     526      $missing = null; 
    527527      if (!isset($newentry[$fld])) { 
    528         $complete = true; 
    529       } // end if 
    530     } // end foreach 
     528        $missing[] = $fld; 
     529      } 
     530    } 
    531531     
    532532    // abort process if requiered fields are missing 
    533     if (!$complete) 
     533    // TODO: generate message saying which fields are missing 
     534    if ($missing) { 
     535      $this->set_error(self::ERROR_INCOMPLETE, 'formincomplete'); 
    534536      return false; 
     537    } 
    535538 
    536539    // Build the new entries DN. 
     
    542545    if ($res === FALSE) { 
    543546      $this->_debug("S: ".ldap_error($this->conn)); 
     547      $this->set_error(self::ERROR_SAVING, 'errorsaving'); 
    544548      return false; 
    545549    } // end if 
     
    600604      if (!ldap_mod_del($this->conn, $dn, $deletedata)) { 
    601605        $this->_debug("S: ".ldap_error($this->conn)); 
     606        $this->set_error(self::ERROR_SAVING, 'errorsaving'); 
    602607        return false; 
    603608      } 
     
    633638      if (!ldap_mod_add($this->conn, $dn, $newdata)) { 
    634639        $this->_debug("S: ".ldap_error($this->conn)); 
     640        $this->set_error(self::ERROR_SAVING, 'errorsaving'); 
    635641        return false; 
    636642      } 
     
    672678      if ($res === FALSE) { 
    673679        $this->_debug("S: ".ldap_error($this->conn)); 
     680        $this->set_error(self::ERROR_SAVING, 'errorsaving'); 
    674681        return false; 
    675682      } // end if 
  • branches/devel-addressbook/program/js/app.js

    r4358 r4361  
    48054805    else { 
    48064806      obj.appendTo(cont).bind('mousedown', function(){ return ref.hide_message(obj); }); 
    4807       window.setTimeout(function(){ ref.hide_message(obj, true); }, this.message_time); 
     4807      window.setTimeout(function(){ ref.hide_message(obj, true); }, this.message_time * (type == 'warning' || type == 'error' ? 2 : 1)); 
    48084808      return obj; 
    48094809    } 
  • branches/devel-addressbook/program/steps/addressbook/save.inc

    r4358 r4361  
    207207  else { 
    208208    // show error message 
    209     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); 
     209    $err = $CONTACTS->get_error(); 
     210    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : ($err['message'] ? $err['message'] : 'errorsaving'), 'error', null, false); 
    210211    rcmail_overwrite_action('show'); 
    211212  } 
     
    259260  else { 
    260261    // show error message 
    261     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); 
     262    $err = $CONTACTS->get_error(); 
     263    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : ($err['message'] ? $err['message'] : 'errorsaving'), 'error', null, false); 
    262264    rcmail_overwrite_action('add'); 
    263265  } 
Note: See TracChangeset for help on using the changeset viewer.