55 * later. See the COPYING file.
66 *
77 * @author Christoph Wurst <[email protected] > 8- * @copyright Christoph Wurst 2015
8+ * @copyright Christoph Wurst 2016
99 */
1010
1111define ( function ( require ) {
@@ -37,6 +37,7 @@ define(function(require) {
3737 autosized : false ,
3838 events : {
3939 'click .submit-message' : 'submitMessage' ,
40+ 'click .submit-message-wrapper-inside' : 'submitMessageWrapperInside' ,
4041 'keypress .message-body' : 'handleKeyPress' ,
4142 'input .to' : 'onInputChanged' ,
4243 'paste .to' : 'onInputChanged' ,
@@ -246,6 +247,43 @@ define(function(require) {
246247
247248 return message ;
248249 } ,
250+ submitMessageWrapperInside : function ( e ) {
251+ // http://stackoverflow.com/questions/487073/check-if-element-is-visible-after-scrolling
252+ if ( this . _isVisible ( ) ) {
253+ this . $ ( '.submit-message' ) . click ( ) ;
254+ } else {
255+ $ ( '#mail-message' ) . animate ( {
256+ scrollTop : this . $el . offset ( ) . top
257+ } , 1000 ) ;
258+ this . $ ( '.submit-message-wrapper-inside' ) . hide ( ) ;
259+ // This function is needed because $('.message-body').focus does not focus the first line
260+ this . _setCaretToPos ( this . $ ( '.message-body' ) [ 0 ] , 0 ) ;
261+ }
262+ } ,
263+ _setSelectionRange : function ( input , selectionStart , selectionEnd ) {
264+ if ( input . setSelectionRange ) {
265+ input . focus ( ) ;
266+ input . setSelectionRange ( selectionStart , selectionEnd ) ;
267+ } else if ( input . createTextRange ) {
268+ var range = input . createTextRange ( ) ;
269+ range . collapse ( true ) ;
270+ range . moveEnd ( 'character' , selectionEnd ) ;
271+ range . moveStart ( 'character' , selectionStart ) ;
272+ range . select ( ) ;
273+ }
274+ } ,
275+ _setCaretToPos : function ( input , pos ) {
276+ this . _setSelectionRange ( input , pos , pos ) ;
277+ } ,
278+ _isVisible : function ( ) {
279+ var $elem = this . $el ;
280+ var $window = $ ( window ) ;
281+ var docViewTop = $window . scrollTop ( ) ;
282+ var docViewBottom = docViewTop + $window . height ( ) ;
283+ var elemTop = $elem . offset ( ) . top ;
284+
285+ return elemTop <= docViewBottom ;
286+ } ,
249287 submitMessage : function ( ) {
250288 clearTimeout ( this . draftTimer ) ;
251289 //
@@ -276,7 +314,8 @@ define(function(require) {
276314
277315 // if available get account from drop-down list
278316 if ( this . $ ( '.mail-account' ) . length > 0 ) {
279- this . account = this . accounts . get ( this . $ ( '.mail-account' ) . find ( ':selected' ) . val ( ) ) ;
317+ this . account = this . accounts . get ( this . $ ( '.mail-account' ) .
318+ find ( ':selected' ) . val ( ) ) ;
280319 }
281320
282321 // send the mail
@@ -303,7 +342,8 @@ define(function(require) {
303342 if ( _this . draftUID !== null ) {
304343 // the sent message was a draft
305344 if ( ! _ . isUndefined ( Radio . ui . request ( 'messagesview:collection' ) ) ) {
306- Radio . ui . request ( 'messagesview:collection' ) . remove ( { id : _this . draftUID } ) ;
345+ Radio . ui . request ( 'messagesview:collection' ) .
346+ remove ( { id : _this . draftUID } ) ;
307347 }
308348 _this . draftUID = null ;
309349 }
@@ -327,7 +367,8 @@ define(function(require) {
327367 cc . prop ( 'disabled' , false ) ;
328368 bcc . prop ( 'disabled' , false ) ;
329369 subject . prop ( 'disabled' , false ) ;
330- _this . $ ( '.new-message-attachments-action' ) . css ( 'display' , 'inline-block' ) ;
370+ _this . $ ( '.new-message-attachments-action' ) .
371+ css ( 'display' , 'inline-block' ) ;
331372 _this . $ ( '#mail_new_attachment' ) . prop ( 'disabled' , false ) ;
332373 newMessageBody . prop ( 'disabled' , false ) ;
333374 newMessageSend . prop ( 'disabled' , false ) ;
@@ -337,7 +378,7 @@ define(function(require) {
337378
338379 if ( this . isReply ( ) ) {
339380 options . messageId = this . messageId ;
340- options . folderId = this . folderId ;
381+ options . folder = this . account . get ( 'folders' ) . get ( this . folderId ) ;
341382 }
342383
343384 this . submitCallback ( this . account , this . getMessage ( ) , options ) ;
@@ -354,14 +395,14 @@ define(function(require) {
354395
355396 // if available get account from drop-down list
356397 if ( this . $ ( '.mail-account' ) . length > 0 ) {
357- this . account = this . accounts . get ( this . $ ( '.mail-account' ) . find ( ':selected' ) . val ( ) ) ;
398+ this . account = this . accounts . get ( this . $ ( '.mail-account' ) .
399+ find ( ':selected' ) . val ( ) ) ;
358400 }
359401
360402 // send the mail
361403 var _this = this ;
362404 this . draftCallback ( this . account , this . getMessage ( ) , {
363- account : this . account ,
364- folderId : this . folderId ,
405+ folder : this . account . get ( 'folders' ) . get ( this . folderId ) ,
365406 messageId : this . messageId ,
366407 draftUID : this . draftUID ,
367408 success : function ( data ) {
@@ -411,7 +452,8 @@ define(function(require) {
411452 function extractLast ( term ) {
412453 return split ( term ) . pop ( ) ;
413454 }
414- if ( ! $ ( this ) . data ( 'autocomplete' ) ) { // If the autocomplete wasn't called yet:
455+ if ( ! $ ( this ) .
456+ data ( 'autocomplete' ) ) { // If the autocomplete wasn't called yet:
415457 // don't navigate away from the field on tab when selecting an item
416458 $ ( this ) . bind ( 'keydown' , function ( event ) {
417459 if ( event . keyCode === $ . ui . keyCode . TAB &&
0 commit comments