Skip to content

Commit 685caaf

Browse files
committed
Merge pull request mailru#99 from im-saxo/dev
flash abort timeout
2 parents 46822e8 + b5b3703 commit 685caaf

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

FileAPI.flash.swf

-854 Bytes
Binary file not shown.

flash/src/ru/mail/controller/AppController.as

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package ru.mail.controller
1414
import flash.net.URLRequest;
1515
import flash.system.Security;
1616
import flash.utils.Timer;
17+
import flash.utils.setTimeout;
1718

1819
import ru.mail.commands.LoadFileCommand;
1920
import ru.mail.commands.UploadCommand;
@@ -97,6 +98,9 @@ package ru.mail.controller
9798
if (options["flashId"]) {
9899
JSCaller.flashId = options["flashId"];
99100
}
101+
// abort timeout
102+
_model.timeout = options["timeout"];
103+
LoggerJS.log("timeout="+_model.timeout);
100104

101105
setupChain();
102106
configureListeners();
@@ -630,25 +634,36 @@ package ru.mail.controller
630634
* @param fileID
631635
*
632636
*/
633-
public function cancelFile(fileID:String):void
637+
public function cancelFile(fileID:String, force:Boolean = false):void
634638
{
635639
trace ("{AppController} - cancelFile", fileID);
636640

637641
var file:BaseFileVO = _model.filesBuilder.getFileByID(fileID);
638642
if (!file) {
643+
LoggerJS.log("abort: file with id "+ fileID +" doen't exist");
639644
trace ("file with id "+ fileID +" doen't exist");
640645
return;
641646
}
642647

643648
if (file.uploadCommand) {
644649
(file.uploadCommand as UploadCommand).cancel();
650+
file.uploadCommand = null;
645651
}
646652
if (file.loadCommand) {
647653
(file.loadCommand as LoadFileCommand).cancel();
654+
file.loadCommand = null;
655+
}
656+
if (_model.timeout && !force) {
657+
LoggerJS.log("abort remove set timeout");
658+
file.timeout = setTimeout(function(_model:AttachmentsModel, file:BaseFileVO):void {
659+
LoggerJS.log("abort remove on timeout");
660+
_model.filesBuilder.removeFile(file);
661+
},_model.timeout, _model, file);
662+
} else {
663+
LoggerJS.log("abort remove immediately");
664+
_model.filesBuilder.removeFile(file);
665+
file = null;
648666
}
649-
_model.filesBuilder.removeFile(file);
650-
file = null;
651-
LoggerJS.log("abort complete");
652667
}
653668

654669
/**
@@ -660,7 +675,7 @@ package ru.mail.controller
660675
var files:Vector.<BaseFileVO> = _model.filesBuilder.items;
661676

662677
for each (var file:BaseFileVO in files) {
663-
cancelFile(file.fileID);
678+
cancelFile(file.fileID, true);
664679
}
665680
_model.filesBuilder.removeAllFiles();
666681
}

flash/src/ru/mail/data/AttachmentsModel.as

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ package ru.mail.data
8080
_hasError = false;
8181
}
8282

83+
private var _timeout:int = 0;
84+
/**
85+
* timeout for removing file
86+
* When calling cmd.abort(), do not delete file immediately, but wait for some time.
87+
* If file is called for upload or something, cancel timeout and do not remove file
88+
* @return
89+
*
90+
*/
91+
public function get timeout():int
92+
{
93+
return _timeout;
94+
}
95+
96+
public function set timeout(value:int):void
97+
{
98+
_timeout = int(value) || 0;
99+
}
100+
101+
83102
/**
84103
* @private Constructor
85104
*/

flash/src/ru/mail/data/builder/AbstractDataBuilder.as

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ru.mail.data.builder
22
{
33
import flash.events.EventDispatcher;
4+
import flash.utils.clearTimeout;
45

56
import ru.mail.data.vo.BaseFileVO;
67

@@ -59,6 +60,9 @@ package ru.mail.data.builder
5960
{
6061
if (_items[i].fileID == fileID) {
6162
result = _items[i];
63+
if (result.timeout) {
64+
clearTimeout(result.timeout); // cancel file remove
65+
}
6266
break;
6367
}
6468
}
@@ -123,6 +127,9 @@ package ru.mail.data.builder
123127
result = _items.splice(index, 1)[0];
124128
result.loadCommand = null;
125129
result.uploadCommand = null;
130+
if(result.timeout) {
131+
clearTimeout(result.timeout);
132+
}
126133
}
127134

128135
return result;
@@ -134,6 +141,11 @@ package ru.mail.data.builder
134141
*/
135142
public function removeAllFiles():void
136143
{
144+
for (var i:uint = 0; i < _items.length; i++) { // for garbage collector
145+
if (_items[i].timeout) {
146+
clearTimeout(_items[i].timeout);
147+
}
148+
}
137149
_items.length = 0;
138150
}
139151

flash/src/ru/mail/data/vo/BaseFileVO.as

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ package ru.mail.data.vo
3737
public var loadCommand:Object;
3838
public var uploadCommand:Object;
3939

40+
public var timeout:uint = 0; // timeout that can remove file
41+
4042
private var _abstractImageFactory:AbstractImageFactory;
4143

4244
public function set abstractImageFactory(value:AbstractImageFactory):void

lib/FileAPI.Flash.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
+ '&flashId='+ id
8787
+ '&storeKey='+ navigator.userAgent.match(/\d/ig).join('') +'_'+ api.version
8888
+ (flash.isReady || (api.pingUrl ? '&ping='+api.pingUrl : ''))
89+
+ '&timeout='+api.flashAbortTimeout
8990
});
9091
},
9192

0 commit comments

Comments
 (0)