Changeset 4071 in subversion


Ignore:
Timestamp:
Oct 10, 2010 12:01:31 PM (3 years ago)
Author:
alec
Message:
  • Added popups with form errors
  • Removed nonexisting 'wrongformat' label usage
Location:
trunk/plugins/managesieve
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/managesieve/Changelog

    r4068 r4071  
     1* version 2.10 [2010-10-10] 
     2----------------------------------------------------------- 
    13- Fixed import from Avelsieve 
    24- Use localized size units (#1486976) 
    35- Added support for relational operators and i;ascii-numeric comparator 
     6- Added popups with form errors 
    47 
    58* version 2.9 [2010-08-02] 
  • trunk/plugins/managesieve/managesieve.js

    r3593 r4071  
    3535      } 
    3636 
     37      // Create layer for form tips 
     38      if (!rcmail.env.framed) { 
     39        rcmail.env.ms_tip_layer = $('<div id="managesieve-tip" class="popupmenu"></div>'); 
     40        rcmail.env.ms_tip_layer.appendTo(document.body); 
     41      } 
     42 
    3743      if (rcmail.gui_objects.filterslist) { 
    3844        var p = rcmail; 
     
    473479}; 
    474480 
     481// Register onmouse(leave/enter) events for tips on specified form element 
     482rcube_webmail.prototype.managesieve_tip_register = function(tips) 
     483{ 
     484  for (var n in tips) { 
     485    $('#'+tips[n][0]) 
     486      .bind('mouseenter', {str: tips[n][1]}, 
     487        function(e) { 
     488          var offset = $(this).offset(), 
     489            tip = rcmail.env.framed ? parent.rcmail.env.ms_tip_layer : rcmail.env.ms_tip_layer, 
     490            left = offset.left, 
     491            top = offset.top - 12; 
     492 
     493          if (rcmail.env.framed) { 
     494            offset = $(parent.document.getElementById('filter-box')).offset(); 
     495            top  += offset.top; 
     496            left += offset.left; 
     497          } 
     498 
     499          tip.html(e.data.str) 
     500          top -= tip.height(); 
     501           
     502          tip.css({left: left, top: top}).show(); 
     503        }) 
     504      .bind('mouseleave', 
     505        function(e) { 
     506          var tip = parent.rcmail && parent.rcmail.env.ms_tip_layer ?  
     507            parent.rcmail.env.ms_tip_layer : rcmail.env.ms_tip_layer; 
     508          tip.hide(); 
     509      }); 
     510  } 
     511}; 
  • trunk/plugins/managesieve/managesieve.php

    r4068 r4071  
    88 * with server using managesieve protocol. Adds Filters tab in Settings. 
    99 * 
    10  * @version 2.9 
     10 * @version 2.10 
    1111 * @author Aleksander 'A.L.E.C' Machniak <alec@alec.pl> 
    1212 * 
     
    2424    private $errors; 
    2525    private $form; 
     26    private $tips = array(); 
    2627    private $script = array(); 
    2728    private $exts = array(); 
     
    422423                            $this->form['tests'][$i]['arg']  = $sizetarget.$sizeitem; 
    423424 
    424                             if (!preg_match('/^[0-9]+(K|M|G)*$/i', $sizetarget)) 
    425                                 $this->errors['tests'][$i]['sizetarget'] = $this->gettext('wrongformat'); 
     425                            if ($sizetarget == '') 
     426                                $this->errors['tests'][$i]['sizetarget'] = $this->gettext('cannotbeempty'); 
     427                            else if (!preg_match('/^[0-9]+(K|M|G)*$/i', $sizetarget)) 
     428                                $this->errors['tests'][$i]['sizetarget'] = $this->gettext('forbiddenchars'); 
    426429                            break; 
    427430                        case '...': 
     
    824827        $out .= "</fieldset>\n"; 
    825828 
     829        $this->print_tips(); 
     830 
    826831        if ($scr['disabled']) { 
    827832            $this->rc->output->set_env('rule_disabled', true); 
     
    878883 
    879884        $out .= '<div id="custom_header' .$id. '" style="display:' .(isset($custom) ? 'inline' : 'none'). '"> 
    880             <input type="text" name="_custom_header[]" '. $this->error_class($id, 'test', 'header') 
     885            <input type="text" name="_custom_header[]" id="custom_header_i'.$id.'" ' 
     886            . $this->error_class($id, 'test', 'header', 'custom_header_i') 
    881887            .' value="' .Q($custom). '" size="20" />&nbsp;</div>' . "\n"; 
    882888 
     
    927933 
    928934        $out .= '<input type="text" name="_rule_target[]" id="rule_target' .$id. '" 
    929             value="' .Q($target). '" size="20" ' . $this->error_class($id, 'test', 'target') 
     935            value="' .Q($target). '" size="20" ' . $this->error_class($id, 'test', 'target', 'rule_target') 
    930936            . ' style="display:' . ($rule['test']!='size' && $rule['test'] != 'exists' ? 'inline' : 'none') . '" />'."\n"; 
    931937 
     
    936942        $out .= '<div id="rule_size' .$id. '" style="display:' . ($rule['test']=='size' ? 'inline' : 'none') .'">'; 
    937943        $out .= $select_size_op->show($rule['test']=='size' ? $rule['type'] : ''); 
    938         $out .= '<input type="text" name="_rule_size_target[]" value="'.$sizetarget.'" size="10" '  
    939             . $this->error_class($id, 'test', 'sizetarget') .' /> 
     944        $out .= '<input type="text" name="_rule_size_target[]" id="rule_size_i'.$id.'" value="'.$sizetarget.'" size="10" '  
     945            . $this->error_class($id, 'test', 'sizetarget', 'rule_size_i') .' /> 
    940946            <input type="radio" name="_rule_size_item['.$id.']" value=""' 
    941947                . (!$sizeitem ? ' checked="checked"' : '') .' class="radio" />'.rcube_label('B').' 
     
    10051011            .'value="' .($action['type']=='redirect' ? Q($action['target'], 'strict', false) : ''). '" size="40" ' 
    10061012            .'style="display:' .($action['type']=='redirect' ? 'inline' : 'none') .'" ' 
    1007             . $this->error_class($id, 'action', 'target') .' />'; 
     1013            . $this->error_class($id, 'action', 'target', 'action_target') .' />'; 
    10081014        $out .= '<textarea name="_action_target_area[]" id="action_target_area' .$id. '" ' 
    1009             .'rows="3" cols="40" '. $this->error_class($id, 'action', 'targetarea') 
     1015            .'rows="3" cols="40" '. $this->error_class($id, 'action', 'targetarea', 'action_target_area') 
    10101016            .'style="display:' .(in_array($action['type'], array('reject', 'ereject')) ? 'inline' : 'none') .'">' 
    10111017            . (in_array($action['type'], array('reject', 'ereject')) ? Q($action['target'], 'strict', false) : '') 
     
    10161022        $out .= '<span class="label">'. Q($this->gettext('vacationreason')) .'</span><br />' 
    10171023            .'<textarea name="_action_reason[]" id="action_reason' .$id. '" ' 
    1018             .'rows="3" cols="40" '. $this->error_class($id, 'action', 'reason') . '>' 
     1024            .'rows="3" cols="40" '. $this->error_class($id, 'action', 'reason', 'action_reason') . '>' 
    10191025            . Q($action['reason'], 'strict', false) . "</textarea>\n"; 
    10201026        $out .= '<br /><span class="label">' .Q($this->gettext('vacationaddresses')) . '</span><br />' 
    1021             .'<input type="text" name="_action_addresses[]" ' 
     1027            .'<input type="text" name="_action_addresses[]" id="action_addr'.$id.'" ' 
    10221028            .'value="' . (is_array($action['addresses']) ? Q(implode(', ', $action['addresses']), 'strict', false) : $action['addresses']) . '" size="40" ' 
    1023             . $this->error_class($id, 'action', 'addresses') .' />'; 
     1029            . $this->error_class($id, 'action', 'addresses', 'action_addr') .' />'; 
    10241030        $out .= '<br /><span class="label">' . Q($this->gettext('vacationdays')) . '</span><br />' 
    1025             .'<input type="text" name="_action_days[]" ' 
     1031            .'<input type="text" name="_action_days[]" id="action_days'.$id.'" ' 
    10261032            .'value="' .Q($action['days'], 'strict', false) . '" size="2" ' 
    1027             . $this->error_class($id, 'action', 'days') .' />'; 
     1033            . $this->error_class($id, 'action', 'days', 'action_days') .' />'; 
    10281034        $out .= '</div>'; 
    10291035 
     
    11001106    } 
    11011107 
    1102     private function error_class($id, $type, $target, $name_only=false) 
     1108    private function error_class($id, $type, $target, $elem_prefix='') 
    11031109    { 
    11041110        // TODO: tooltips 
    1105         if ($type == 'test' && isset($this->errors['tests'][$id][$target])) 
    1106             return ($name_only ? 'error' : ' class="error"'); 
    1107         else if ($type == 'action' && isset($this->errors['actions'][$id][$target])) 
    1108             return ($name_only ? 'error' : ' class="error"'); 
     1111        if (($type == 'test' && ($str = $this->errors['tests'][$id][$target])) || 
     1112            ($type == 'action' && ($str = $this->errors['actions'][$id][$target])) 
     1113        ) { 
     1114            $this->add_tip($elem_prefix.$id, $str, true); 
     1115            return ' class="error"'; 
     1116        } 
    11091117 
    11101118        return ''; 
     
    11151123        return rcube_charset_convert($text, 'UTF7-IMAP', $encoding); 
    11161124    } 
     1125 
     1126    private function add_tip($id, $str, $error=false) 
     1127    { 
     1128        if ($error) 
     1129            $str = html::span('sieve error', $str); 
     1130 
     1131        $this->tips[] = array($id, $str); 
     1132    } 
     1133 
     1134    private function print_tips() 
     1135    { 
     1136        if (empty($this->tips)) 
     1137            return; 
     1138 
     1139        $script = JS_OBJECT_NAME.'.managesieve_tip_register('.json_encode($this->tips).');'; 
     1140        $this->rc->output->add_script($script, 'foot'); 
     1141    } 
     1142 
    11171143} 
  • trunk/plugins/managesieve/skins/default/managesieve.css

    r3989 r4071  
    290290  vertical-align: middle; 
    291291} 
     292 
     293span.sieve.error 
     294{ 
     295  color: red; 
     296} 
     297 
     298#managesieve-tip 
     299{ 
     300  width: 200px; 
     301} 
Note: See TracChangeset for help on using the changeset viewer.