Changeset 7f5a849 in github


Ignore:
Timestamp:
Jul 7, 2011 7:44:26 AM (23 months ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
65b61cd
Parents:
632528f
Message:
  • Added possibility to undo last contact delete operation
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r1564d4e r7f5a849  
    22=========================== 
    33 
     4- Added possibility to undo last contact delete operation 
    45- Fix sorting of contact groups after group create (#1487747) 
    56- Add optional textual upload progress indicator (#1486039) 
  • program/include/rcmail.php

    r77406bb r7f5a849  
    508508    $this->output->set_charset(RCMAIL_CHARSET); 
    509509 
    510     // add some basic label to client 
     510    // add some basic labels to client 
    511511    $this->output->add_label('loading', 'servererror'); 
    512512 
  • program/include/rcube_addressbook.php

    rcc90ed1 r7f5a849  
    3939    public $groups = false; 
    4040    public $readonly = true; 
     41    public $undelete = false; 
    4142    public $ready = false; 
    4243    public $group_id = null; 
     
    257258 
    258259    /** 
    259      * Remove all records from the database 
     260     * Unmark delete flag on contact record(s) 
     261     * 
     262     * @param array  Record identifiers 
     263     */ 
     264    function undelete($ids) 
     265    { 
     266        /* empty for read-only address books */ 
     267    } 
     268 
     269    /** 
     270     * Mark all records in database as deleted 
    260271     */ 
    261272    function delete_all() 
  • program/include/rcube_contacts.php

    rcc90ed1 r7f5a849  
    5353    public $readonly = false; 
    5454    public $groups = true; 
     55    public $undelete = true; 
    5556    public $list_page = 1; 
    5657    public $page_size = 10; 
     
    693694 
    694695    /** 
     696     * Undelete one or more contact records 
     697     * 
     698     * @param array  Record identifiers 
     699     */ 
     700    function undelete($ids) 
     701    { 
     702        if (!is_array($ids)) 
     703            $ids = explode(',', $ids); 
     704 
     705        $ids = $this->db->array2list($ids, 'integer'); 
     706 
     707        // flag record as deleted 
     708        $this->db->query( 
     709            "UPDATE ".get_table_name($this->db_name). 
     710            " SET del=0, changed=".$this->db->now(). 
     711            " WHERE user_id=?". 
     712                " AND contact_id IN ($ids)", 
     713            $this->user_id 
     714        ); 
     715 
     716        $this->cache = null; 
     717 
     718        return $this->db->affected_rows(); 
     719    } 
     720 
     721 
     722    /** 
    695723     * Remove all records from the database 
    696724     */ 
    697725    function delete_all() 
    698726    { 
    699         $this->db->query("DELETE FROM ".get_table_name($this->db_name)." WHERE user_id = ?", $this->user_id); 
    700727        $this->cache = null; 
     728 
     729        $this->db->query("UPDATE ".get_table_name($this->db_name). 
     730            " SET del=1, changed=".$this->db->now(). 
     731            " WHERE user_id = ?", $this->user_id); 
     732 
    701733        return $this->db->affected_rows(); 
    702734    } 
  • program/include/rcube_json_output.php

    r07b95dc r7f5a849  
    165165     * @param array   $vars     Key-value pairs to be replaced in localized text 
    166166     * @param boolean $override Override last set message 
     167     * @param int     $timeout  Message displaying time in seconds 
    167168     * @uses self::command() 
    168169     */ 
    169     public function show_message($message, $type='notice', $vars=null, $override=true) 
     170    public function show_message($message, $type='notice', $vars=null, $override=true, $timeout=0) 
    170171    { 
    171172        if ($override || !$this->message) { 
    172173            $this->message = $message; 
    173174            $msgtext = rcube_label_exists($message) ? rcube_label(array('name' => $message, 'vars' => $vars)) : $message; 
    174             $this->command('display_message', $msgtext, $type); 
     175            $this->command('display_message', $msgtext, $type, $timeout * 1000); 
    175176        } 
    176177    } 
  • program/include/rcube_template.php

    r5bfa444 r7f5a849  
    239239     * Invoke display_message command 
    240240     * 
    241      * @param string Message to display 
    242      * @param string Message type [notice|confirm|error] 
    243      * @param array Key-value pairs to be replaced in localized text 
    244      * @param boolean Override last set message 
     241     * @param string  $message  Message to display 
     242     * @param string  $type     Message type [notice|confirm|error] 
     243     * @param array   $vars     Key-value pairs to be replaced in localized text 
     244     * @param boolean $override Override last set message 
     245     * @param int     $timeout  Message display time in seconds 
    245246     * @uses self::command() 
    246247     */ 
    247     public function show_message($message, $type='notice', $vars=null, $override=true) 
     248    public function show_message($message, $type='notice', $vars=null, $override=true, $timeout=0) 
    248249    { 
    249250        if ($override || !$this->message) { 
    250251            $this->message = $message; 
    251252            $msgtext = rcube_label_exists($message) ? rcube_label(array('name' => $message, 'vars' => $vars)) : $message; 
    252             $this->command('display_message', $msgtext, $type); 
     253            $this->command('display_message', $msgtext, $type, $timeout * 1000); 
    253254        } 
    254255    } 
  • program/js/app.js

    r1a3c911 r7f5a849  
    165165 
    166166    // enable general commands 
    167     this.enable_command('logout', 'mail', 'addressbook', 'settings', 'save-pref', true); 
     167    this.enable_command('logout', 'mail', 'addressbook', 'settings', 'save-pref', 'undo', true); 
    168168 
    169169    if (this.env.permaurl) 
     
    412412    // show message 
    413413    if (this.pending_message) 
    414       this.display_message(this.pending_message[0], this.pending_message[1]); 
     414      this.display_message(this.pending_message[0], this.pending_message[1], this.pending_message[2]); 
    415415 
    416416    // map implicit containers 
     
    10471047        break; 
    10481048 
     1049      case 'undo': 
     1050        this.http_request('undo', '', this.display_message('', 'loading')); 
     1051        break; 
     1052 
    10491053      // unified command call (command name == function name) 
    10501054      default: 
     
    12971301      var li, div, pos, mouse, check, oldclass, 
    12981302        layerclass = 'draglayernormal'; 
    1299        
     1303 
    13001304      if (this.contact_list && this.contact_list.draglayer) 
    13011305        oldclass = this.contact_list.draglayer.attr('class'); 
     
    49814985      $elem.addClass('placeholder').attr('spellcheck', false).val(elem._placeholder); 
    49824986  }; 
    4983    
     4987 
    49844988  // write to the document/window title 
    49854989  this.set_pagetitle = function(title) 
     
    49904994 
    49914995  // display a system message, list of types in common.css (below #message definition) 
    4992   this.display_message = function(msg, type) 
     4996  this.display_message = function(msg, type, timeout) 
    49934997  { 
    49944998    // pass command to parent window 
    49954999    if (this.is_framed()) 
    4996       return parent.rcmail.display_message(msg, type); 
     5000      return parent.rcmail.display_message(msg, type, timeout); 
    49975001 
    49985002    if (!this.gui_objects.message) { 
    49995003      // save message in order to display after page loaded 
    50005004      if (type != 'loading') 
    5001         this.pending_message = new Array(msg, type); 
     5005        this.pending_message = new Array(msg, type, timeout); 
    50025006      return false; 
    50035007    } 
     
    50065010 
    50075011    var ref = this, 
    5008       key = msg, 
     5012      key = String(msg).replace(this.identifier_expr, '_'), 
    50095013      date = new Date(), 
    5010       id = type + date.getTime(), 
     5014      id = type + date.getTime(); 
     5015 
     5016    if (!timeout) 
    50115017      timeout = this.message_time * (type == 'error' || type == 'warning' ? 2 : 1); 
    5012        
     5018 
    50135019    if (type == 'loading') { 
    50145020      key = 'loading'; 
  • program/localization/en_US/labels.inc

    r4171c59 r7f5a849  
    449449$labels['sortasc']  = 'Sort ascending'; 
    450450$labels['sortdesc'] = 'Sort descending'; 
     451$labels['undo'] = 'Undo'; 
    451452 
    452453// units 
  • program/localization/en_US/messages.inc

    r1d5779b r7f5a849  
    129129$messages['contactdelerror'] = 'Could not delete contact(s)'; 
    130130$messages['contactdeleted'] = 'Contact(s) deleted successfully'; 
     131$messages['contactrestoreerror'] = 'Could not restore deleted contact(s)'; 
     132$messages['contactrestored'] = 'Contact(s) restored successfully'; 
    131133$messages['groupdeleted'] = 'Group deleted successfully'; 
    132134$messages['grouprenamed'] = 'Group renamed successfully'; 
     
    143145$messages['invalidimageformat'] = 'Not a valid image format'; 
    144146$messages['mispellingsfound'] = 'Spelling errors detected in the message'; 
     147$messages['itemsdeleted'] = '$num item(s) has been deleted.'; 
    145148 
    146149?> 
  • program/localization/pl_PL/labels.inc

    r81a0cfb r7f5a849  
    468468$labels['grouprename'] = 'Zmień nazwę grupy'; 
    469469$labels['groupdelete'] = 'Usuń grupę'; 
     470$labels['undo'] = 'Cofnij'; 
    470471 
    471472?> 
  • program/localization/pl_PL/messages.inc

    r12bfc55e r7f5a849  
    194194$messages['invalidimageformat'] = 'Niepoprawny format obrazka'; 
    195195$messages['mispellingsfound'] = 'Wykryto błędy pisowni w tej wiadomości'; 
     196$messages['itemsdeleted'] = '$num elemenów zostało usuniętych.'; 
     197$messages['contactrestoreerror'] = 'Przywracanie kontaktów nie powiodło się'; 
     198$messages['contactrestored'] = 'Kontakt(y) zostały przywrócone'; 
    196199 
    197200?> 
  • program/steps/addressbook/delete.inc

    recf295f r7f5a849  
    2727$delcnt = 0; 
    2828 
     29// remove previous deletes 
     30$RCMAIL->session->remove('contact_undo'); 
     31 
    2932foreach ($cids as $source => $cid) 
    3033{ 
     
    3740            $OUTPUT->show_message('contactdelerror', 'error'); 
    3841            $OUTPUT->command('list_contacts'); 
     42            $OUTPUT->send(); 
    3943        } 
    4044        continue; 
     
    5357    else { 
    5458        $delcnt += $deleted; 
     59 
     60        // store deleted contacts IDs in session for undelete 
     61        if ($CONTACTS->undelete) { 
     62            $_SESSION['contact_undo']['data'][$source] = $cid; 
     63        } 
    5564    } 
    5665} 
    57  
    58 $OUTPUT->show_message('contactdeleted', 'confirmation'); 
    5966 
    6067$page = isset($_SESSION['page']) ? $_SESSION['page'] : 1; 
     
    136143$OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result)); 
    137144 
     145if (!empty($_SESSION['contact_undo'])) { 
     146    $_SESSION['contact_undo']['ts'] = time(); 
     147    $msg = html::span(null, rcube_label(array('name' => 'itemsdeleted', 'vars' => array('num' => $deleted)))) 
     148        . ' ' . html::a(array('onclick' => JS_OBJECT_NAME.".command('undo', '', this)"), rcube_label('undo')); 
     149 
     150    $OUTPUT->show_message($msg, 'confirmation', null, true, $RCMAIL->config->get('undo_timeout', 15)); 
     151} 
     152else { 
     153    $OUTPUT->show_message('contactdeleted', 'confirmation'); 
     154} 
     155 
    138156// add new rows from next page (if any) 
    139157if (!empty($records)) { 
  • program/steps/addressbook/func.inc

    r5b3ac324 r7f5a849  
    8989} 
    9090 
     91// remove undo information... 
     92if ($undo = $_SESSION['contact_undo']) { 
     93    // ...after 30 seconds 
     94    if ($undo['ts'] < time() - 30) 
     95        $RCMAIL->session->remove('contact_undo'); 
     96} 
    9197 
    9298// instantiate a contacts object according to the given source 
  • skins/default/common.css

    r39d8ccd r7f5a849  
    251251  background-color: #EBEBEB; 
    252252  border: 1px solid #CCCCCC; 
     253} 
     254 
     255#message a 
     256{ 
     257  cursor: pointer; 
     258  text-decoration: underline; 
    253259} 
    254260 
  • skins/default/templates/mail.html

    r8e99ffb r7f5a849  
    197197</div> 
    198198</div> 
    199  
     199<div id="undelete-message">11 item(s) has been deleted. <a href="#">Undo</a></div> 
    200200</body> 
    201201</html> 
Note: See TracChangeset for help on using the changeset viewer.