5
5
* later. See the COPYING file.
6
6
*
7
7
* @author Christoph Wurst <[email protected] >
8
- * @copyright Christoph Wurst 2015
8
+ * @copyright Christoph Wurst 2016
9
9
*/
10
10
11
11
define ( function ( require ) {
@@ -37,6 +37,7 @@ define(function(require) {
37
37
autosized : false ,
38
38
events : {
39
39
'click .submit-message' : 'submitMessage' ,
40
+ 'click .submit-message-wrapper-inside' : 'submitMessageWrapperInside' ,
40
41
'keypress .message-body' : 'handleKeyPress' ,
41
42
'input .to' : 'onInputChanged' ,
42
43
'paste .to' : 'onInputChanged' ,
@@ -246,6 +247,43 @@ define(function(require) {
246
247
247
248
return message ;
248
249
} ,
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
+ } ,
249
287
submitMessage : function ( ) {
250
288
clearTimeout ( this . draftTimer ) ;
251
289
//
@@ -276,7 +314,8 @@ define(function(require) {
276
314
277
315
// if available get account from drop-down list
278
316
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 ( ) ) ;
280
319
}
281
320
282
321
// send the mail
@@ -303,7 +342,8 @@ define(function(require) {
303
342
if ( _this . draftUID !== null ) {
304
343
// the sent message was a draft
305
344
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 } ) ;
307
347
}
308
348
_this . draftUID = null ;
309
349
}
@@ -327,7 +367,8 @@ define(function(require) {
327
367
cc . prop ( 'disabled' , false ) ;
328
368
bcc . prop ( 'disabled' , false ) ;
329
369
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' ) ;
331
372
_this . $ ( '#mail_new_attachment' ) . prop ( 'disabled' , false ) ;
332
373
newMessageBody . prop ( 'disabled' , false ) ;
333
374
newMessageSend . prop ( 'disabled' , false ) ;
@@ -337,7 +378,7 @@ define(function(require) {
337
378
338
379
if ( this . isReply ( ) ) {
339
380
options . messageId = this . messageId ;
340
- options . folderId = this . folderId ;
381
+ options . folder = this . account . get ( 'folders' ) . get ( this . folderId ) ;
341
382
}
342
383
343
384
this . submitCallback ( this . account , this . getMessage ( ) , options ) ;
@@ -354,14 +395,14 @@ define(function(require) {
354
395
355
396
// if available get account from drop-down list
356
397
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 ( ) ) ;
358
400
}
359
401
360
402
// send the mail
361
403
var _this = this ;
362
404
this . draftCallback ( this . account , this . getMessage ( ) , {
363
- account : this . account ,
364
- folderId : this . folderId ,
405
+ folder : this . account . get ( 'folders' ) . get ( this . folderId ) ,
365
406
messageId : this . messageId ,
366
407
draftUID : this . draftUID ,
367
408
success : function ( data ) {
@@ -411,7 +452,8 @@ define(function(require) {
411
452
function extractLast ( term ) {
412
453
return split ( term ) . pop ( ) ;
413
454
}
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:
415
457
// don't navigate away from the field on tab when selecting an item
416
458
$ ( this ) . bind ( 'keydown' , function ( event ) {
417
459
if ( event . keyCode === $ . ui . keyCode . TAB &&
0 commit comments