diff skins/larry/ui.js @ 8:bf99236cc5cd default tip

try to recover from upgrade fail
author Charlie Root
date Sat, 29 Dec 2018 07:07:34 -0500
parents 4681f974d28b
children
line wrap: on
line diff
--- a/skins/larry/ui.js	Sat Dec 29 06:32:49 2018 -0500
+++ b/skins/larry/ui.js	Sat Dec 29 07:07:34 2018 -0500
@@ -28,6 +28,7 @@
 
   var me = this;
   var mailviewsplit;
+  var mailviewsplit2;
   var compose_headers = {};
   var prefs;
 
@@ -60,6 +61,8 @@
     if (bw.tablet) {
       $('#viewport').attr('content', "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0");
     }
+
+    $(document).ready(function() { me.init(); });
   }
 
 
@@ -136,6 +139,7 @@
       rcmail.addEventListener('menu-open', menu_toggle)
         .addEventListener('menu-close', menu_toggle)
         .addEventListener('menu-save', save_listoptions)
+        .addEventListener('enable-command', enable_command)
         .addEventListener('responseafterlist', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list', true) })
         .addEventListener('responseaftersearch', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list', true) });
 
@@ -146,9 +150,9 @@
       }
 
       if (rcmail.env.action == 'show' || rcmail.env.action == 'preview') {
-        rcmail.addEventListener('enable-command', enable_command)
-          .addEventListener('aftershow-headers', function() { layout_messageview(); })
+        rcmail.addEventListener('aftershow-headers', function() { layout_messageview(); })
           .addEventListener('afterhide-headers', function() { layout_messageview(); });
+
         $('#previewheaderstoggle').click(function(e) {
             toggle_preview_headers();
             if (this.blur && !rcube_event.is_keyboard(e))
@@ -158,26 +162,29 @@
 
         // add menu link for each attachment
         $('#attachment-list > li').each(function() {
-          $(this).append($('<a class="drop" tabindex="0" aria-haspopup="true">Show options</a>')
-              .bind('click keypress', function(e) {
-                  if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) {
-                      attachmentmenu(this, e);
-                      return false;
-                  }
-              })
-          );
+          attachmentmenu_append(this);
         });
 
         if (get_pref('previewheaders') == '1') {
           toggle_preview_headers();
         }
+
+        if (rcmail.env.action == 'show') {
+          $('#messagecontent').focus();
+        }
       }
       else if (rcmail.env.action == 'compose') {
         rcmail.addEventListener('aftersend-attachment', show_uploadform)
-          .addEventListener('aftertoggle-editor', function(e){
-            window.setTimeout(function(){ layout_composeview() }, 200);
+          .addEventListener('fileappended', function(e) { if (e.attachment.complete) attachmentmenu_append(e.item); })
+          .addEventListener('aftertoggle-editor', function(e) {
+            window.setTimeout(function() { layout_composeview() }, 200);
             if (e && e.mode)
               $("select[name='editorSelector']").val(e.mode);
+          })
+          .addEventListener('compose-encrypted', function(e) {
+            $("select[name='editorSelector']").prop('disabled', e.active);
+            $('a.button.attach, a.button.responses')[(e.active?'addClass':'removeClass')]('disabled');
+            $('#responseslist a.insertresponse')[(e.active?'removeClass':'addClass')]('active');
           });
 
         // Show input elements with non-empty value
@@ -216,22 +223,22 @@
 
         new rcube_splitter({ id:'composesplitterv', p1:'#composeview-left', p2:'#composeview-right',
           orientation:'v', relative:true, start:206, min:170, size:12, render:layout_composeview }).init();
+
+        // add menu link for each attachment
+        $('#attachment-list > li').each(function() {
+          attachmentmenu_append(this);
+        });
       }
       else if (rcmail.env.action == 'list' || !rcmail.env.action) {
-        var previewframe = $('#mailpreviewframe').is(':visible');
+        mail_layout();
 
-        $('#mailpreviewtoggle').addClass(previewframe ? 'enabled' : 'closed').attr('aria-expanded', previewframe ? 'true' : 'false')
-          .click(function(e) { toggle_preview_pane(e); return false; });
         $('#maillistmode').addClass(rcmail.env.threading ? '' : 'selected').click(function(e) { switch_view_mode('list'); return false; });
         $('#mailthreadmode').addClass(rcmail.env.threading ? 'selected' : '').click(function(e) { switch_view_mode('thread'); return false; });
 
-        mailviewsplit = new rcube_splitter({ id:'mailviewsplitter', p1:'#mailview-top', p2:'#mailview-bottom',
-          orientation:'h', relative:true, start:310, min:150, size:12, offset:4 });
-        if (previewframe)
-          mailviewsplit.init();
+        rcmail.init_pagejumper('#pagejumper');
 
         rcmail.addEventListener('setquota', update_quota)
-          .addEventListener('enable-command', enable_command)
+          .addEventListener('layout-change', mail_layout)
           .addEventListener('afterimport-messages', show_uploadform);
       }
       else if (rcmail.env.action == 'get') {
@@ -278,8 +285,8 @@
       else if (rcmail.env.action == 'edit-prefs') {
         var legend = $('#preferences-details fieldset.advanced legend'),
           toggle = $('<a href="#toggle"></a>')
-            .text(env.toggleoptions)
-            .attr('title', env.toggleoptions)
+            .text(rcmail.gettext('toggleadvancedoptions'))
+            .attr('title', rcmail.gettext('toggleadvancedoptions'))
             .addClass('advanced-toggle');
 
         legend.click(function(e) {
@@ -298,7 +305,9 @@
     else if (rcmail.env.task == 'addressbook') {
       rcmail.addEventListener('afterupload-photo', show_uploadform)
         .addEventListener('beforepushgroup', push_contactgroup)
-        .addEventListener('beforepopgroup', pop_contactgroup);
+        .addEventListener('beforepopgroup', pop_contactgroup)
+        .addEventListener('menu-open', menu_toggle)
+        .addEventListener('menu-close', menu_toggle);
 
       if (rcmail.env.action == '') {
         new rcube_splitter({ id:'addressviewsplitterd', p1:'#addressview-left', p2:'#addressview-right',
@@ -436,10 +445,9 @@
         .dialog({
           resizable: false,
           closeOnEscape: true,
-          dialogClass: 'popupmessage ' + p.type,
-          title: env.errortitle,
+          dialogClass: p.type,
+          title: rcmail.gettext('errortitle'),
           close: dialog_close,
-          position: ['center', 'center'],
           hide: {effect: 'fadeOut'},
           width: 420,
           minHeight: 90
@@ -452,6 +460,53 @@
     }
   }
 
+  // Mail view layout initialization and change handler
+  function mail_layout(p)
+  {
+    var layout = p ? p.new_layout : rcmail.env.layout,
+      top = $('#mailview-top'),
+      bottom = $('#mailview-bottom');
+
+    if (p)
+      $('#mainscreencontent').removeClass().addClass(layout);
+
+    $('#mailviewsplitter')[layout == 'desktop' ? 'show' : 'hide']();
+    $('#mailviewsplitter2')[layout == 'widescreen' ? 'show' : 'hide']();
+    $('#mailpreviewframe')[layout != 'list' ? 'show' : 'hide']();
+    rcmail.env.contentframe = layout == 'list' ? null : 'messagecontframe';
+
+    if (layout == 'widescreen') {
+      $('#countcontrols').detach().appendTo($('#messagelistheader'));
+      top.css({height: 'auto', width: 394});
+      bottom.css({top: 0, left: 406, height: 'auto'}).show();
+      if (!mailviewsplit2) {
+        mailviewsplit2 = new rcube_splitter({ id:'mailviewsplitter2', p1:'#mailview-top', p2:'#mailview-bottom',
+          orientation:'v', relative:true, start:416, min:400, size:12});
+        mailviewsplit2.init();
+      }
+      else
+        mailviewsplit2.resize();
+    }
+    else if (layout == 'desktop') {
+      top.css({height: 270, width: 'auto'});
+      bottom.css({left: 0, top: 284, height: 'auto'}).show();
+      if (!mailviewsplit) {
+        mailviewsplit = new rcube_splitter({ id:'mailviewsplitter', p1:'#mailview-top', p2:'#mailview-bottom',
+          orientation:'h', relative:true, start:276, min:150, size:12, offset:4 });
+        mailviewsplit.init();
+      }
+      else
+        mailviewsplit.resize();
+    }
+    else { // layout == 'list'
+      top.css({height: 'auto', width: 'auto'});
+      bottom.hide();
+    }
+
+    if (p && p.old_layout == 'widescreen') {
+      $('#countcontrols').detach().appendTo($('#messagelistfooter'));
+    }
+  }
 
   /**
    * Adjust UI objects of the mail view screen
@@ -465,6 +520,14 @@
       $('div.rightcol').hide().attr('aria-hidden', 'true');
       $('div.leftcol').css('margin-right', '0');
     }
+
+    var mvlpe = $('#messagebody.mailvelope, #messagebody > .mailvelope');
+    if (mvlpe.length) {
+      var h = $('#messagecontent').length ?
+        $('#messagecontent').height() - 16 :
+        $(window).height() - mvlpe.offset().top - 2;
+      mvlpe.height(h);
+    }
   }
 
 
@@ -531,6 +594,7 @@
       y -= step;
 
     element.css('background-position', '0 -' + y + 'px');
+    element.attr('class', 'countdisplay p' + (Math.round(p.percent / 10) * 10));
 
     if (p.table) {
       if (!menu.length)
@@ -585,6 +649,10 @@
       else
         $('a.button.reply-all').text(label).attr('title', label);
     }
+    else if (p.command == 'compose-encrypted') {
+      // show the toolbar button for Mailvelope
+      $('a.button.encrypt').show();
+    }
   }
 
 
@@ -634,58 +702,6 @@
       $.Event('click', { target:ref.get(0), pageX:pos.left, pageY:pos.top, clientX:pos.left, clientY:pos.top }));
   }
 
-
-  /**
-   * Show/hide the preview pane
-   */
-  function toggle_preview_pane(e)
-  {
-    var button = $(e.target),
-      frame = $('#mailpreviewframe'),
-      visible = !frame.is(':visible'),
-      splitter = mailviewsplit.pos || parseInt(get_pref('mailviewsplitter') || 320),
-      topstyles, bottomstyles, uid;
-
-    frame.toggle();
-    button.toggleClass('enabled closed').attr('aria-expanded', visible ? 'true' : 'false');
-
-    if (visible) {
-      $('#mailview-top').removeClass('fullheight').css({ bottom:'auto' });
-      $('#mailview-bottom').css({ height:'auto' }).show();
-
-      rcmail.env.contentframe = 'messagecontframe';
-      if (uid = rcmail.message_list.get_single_selection())
-        rcmail.show_message(uid, false, true);
-
-      // let the splitter set the correct size and position
-      if (mailviewsplit.handle) {
-        mailviewsplit.handle.show();
-        mailviewsplit.resize();
-      }
-      else
-        mailviewsplit.init();
-    }
-    else {
-      rcmail.env.contentframe = null;
-      rcmail.show_contentframe(false);
-
-      $('#mailview-top').addClass('fullheight').css({ height:'auto', bottom:'0px' });
-      $('#mailview-bottom').css({ top:'auto', height:'0px' }).hide();
-
-      if (mailviewsplit.handle)
-        mailviewsplit.handle.hide();
-    }
-
-    if (rcmail.message_list) {
-      if (visible && uid)
-          rcmail.message_list.scrollto(uid);
-      rcmail.message_list.resize();
-    }
-
-    rcmail.command('save-pref', { name:'preview_pane', value:(visible?1:0) });
-  }
-
-
   /**
    * Switch between short and full headers display in message preview
    */
@@ -802,12 +818,11 @@
   {
     var id = elem.parentNode.id.replace(/^attach/, '');
 
-    $('#attachmenuopen').unbind('click').attr('onclick', '').click(function(e) {
-      return rcmail.command('open-attachment', id, this);
-    });
-
-    $('#attachmenudownload').unbind('click').attr('onclick', '').click(function() {
-      rcmail.command('download-attachment', id, this);
+    $.each(['open', 'download', 'rename'], function() {
+      var action = this;
+      $('#attachmenu' + action).off('click').attr('onclick', '').click(function(e) {
+        return rcmail.command(action + '-attachment', id, this);
+      });
     });
 
     popupconfig.attachmentmenu.link = elem;
@@ -827,7 +842,7 @@
         li = $('<li role="menuitem">');
         link = $('<a href="#'+k+'" tabindex="0"></a>').text(rcmail.env.spell_langs[k])
           .addClass('active').data('lang', k)
-          .bind('click keypress', function(e) {
+          .on('click keypress', function(e) {
               if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) {
                   rcmail.spellcheck_lang_set($(this).data('lang'));
                   rcmail.hide_menu('spellmenu', e);
@@ -852,6 +867,20 @@
     });
   }
 
+  // append drop-icon to attachments list item (to invoke attachment menu)
+  function attachmentmenu_append(item)
+  {
+    item = $(item);
+
+    if (!item.children('.drop').length)
+      item.append($('<a class="drop skip-content" tabindex="0" aria-haspopup="true">Show options</a>')
+          .on('click keypress', function(e) {
+            if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) {
+              attachmentmenu(this, e);
+              return false;
+            }
+          }));
+  }
 
   /**
    *
@@ -871,6 +900,11 @@
     $('input[name="sort_ord"][value="DESC"]').prop('checked', rcmail.env.sort_order == 'DESC');
     $('input[name="sort_ord"][value="ASC"]').prop('checked', rcmail.env.sort_order != 'DESC');
 
+    $.each(['widescreen', 'desktop', 'list'], function() {
+      $('input[name="layout"][value="' + this + '"]').prop('checked', rcmail.env.layout == this);
+    });
+    $('#listoptions-columns', $dialog)[rcmail.env.layout == 'widescreen' ? 'hide' : 'show']();
+
     // set checkboxes
     $('input[name="list_col[]"]').each(function() {
       $(this).prop('checked', $.inArray(this.value, rcmail.env.listcols) != -1);
@@ -907,10 +941,11 @@
 
     var sort = $('input[name="sort_col"]:checked').val(),
       ord = $('input[name="sort_ord"]:checked').val(),
+      layout = $('input[name="layout"]:checked').val(),
       cols = $('input[name="list_col[]"]:checked')
         .map(function(){ return this.value; }).get();
 
-    rcmail.set_list_options(cols, sort, ord, rcmail.env.threading);
+    rcmail.set_list_options(cols, sort, ord, rcmail.env.threading, layout);
   }
 
 
@@ -1012,6 +1047,10 @@
       return;
     }
 
+    // do nothing if mailvelope editor is active
+    if (rcmail.mailvelope_editor)
+      return;
+
     // add icons to clone file input field
     if (rcmail.env.action == 'compose' && !$dialog.data('extended')) {
       $('<a>')
@@ -1251,7 +1290,7 @@
       .attr('role', 'presentation')
       .addClass('splitter ' + (this.horizontal ? 'splitter-h' : 'splitter-v'))
       .appendTo(this.parent)
-      .bind('mousedown', onDragStart);
+      .mousedown(onDragStart);
 
     if (this.horizontal) {
       var top = this.p1pos.top + this.p1.outerHeight();
@@ -1289,7 +1328,7 @@
       this.p2.css('top', Math.ceil(this.pos + Math.ceil(this.halfsize) + 2) + 'px');
       this.handle.css('top', Math.round(this.pos - this.halfsize + this.offset)+'px');
       if (bw.ie) {
-        var new_height = parseInt(this.parent.outerHeight(), 10) - parseInt(this.p2.css('top'), 10) - (bw.ie8 ? 2 : 0);
+        var new_height = parseInt(this.parent.outerHeight(), 10) - parseInt(this.p2.css('top'), 10);
         this.p2.css('height', (new_height > 0 ? new_height : 0) + 'px');
       }
     }
@@ -1332,7 +1371,11 @@
     me.drag_active = true;
 
     // start listening to mousemove events
-    $(document).bind('mousemove.'+this.id, onDrag).bind('mouseup.'+this.id, onDragStop);
+    $(document).on('mousemove.' + this.id, onDrag).on('mouseup.' + this.id, onDragStop);
+
+    // hack messages list so it will propagate the mouseup event over the list
+    if (rcmail.message_list)
+      rcmail.message_list.drag_active = true;
 
     // enable dragging above iframes
     $('iframe').each(function(i, elem) {
@@ -1409,9 +1452,12 @@
       document.body.style.webkitUserSelect = 'auto';
 
     // cancel the listening for drag events
-    $(document).unbind('.'+me.id);
+    $(document).off('.' + me.id);
     me.drag_active = false;
 
+    if (rcmail.message_list)
+      rcmail.message_list.drag_active = false;
+
     // remove temp divs
     $('div.iframe-splitter-fix').remove();
 
@@ -1429,7 +1475,7 @@
   function onResize(e)
   {
     if (me.horizontal) {
-      var new_height = parseInt(me.parent.outerHeight(), 10) - parseInt(me.p2[0].style.top, 10) - (bw.ie8 ? 2 : 0);
+      var new_height = parseInt(me.parent.outerHeight(), 10) - parseInt(me.p2[0].style.top, 10);
       me.p2.css('height', (new_height > 0 ? new_height : 0) +'px');
     }
     else {