This repository was archived by the owner on Sep 6, 2021. It is now read-only.
forked from PRX/s3-swf-upload-plugin
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathview_helpers.rb
173 lines (156 loc) · 7.97 KB
/
view_helpers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
module S3SwfUpload
module ViewHelpers
def s3_swf_upload_tag(options = {})
buttonWidth = options[:buttonWidth] || 100
buttonHeight = options[:buttonHeight] || 30
flashVersion = options[:height] || '9.0.0'
queueSizeLimit = options[:queueSizeLimit] || 100
fileSizeLimit = options[:fileSizeLimit] || 524288000
fileTypes = options[:fileTypes] || '*.*'
fileTypeDescs = options[:fileTypeDescs] || 'All Files'
selectMultipleFiles = options.has_key?(:selectMultipleFiles) ? options[:selectMultipleFiles] : true
keyPrefix = options[:keyPrefix] || ''
signaturePath = options[:signaturePath] || '/s3_uploads.xml'
swfFilePath = options[:swfFilePath] || '/flash/s3_upload.swf'
buttonUpPath = options[:buttonUpPath] || '/flash/s3_up_button.gif'
buttonOverPath = options[:buttonOverPath] || '/flash/s3_over_button.gif'
buttonDownPath = options[:buttonDownPath] || '/flash/s3_down_button.gif'
onFileAdd = options[:onFileAdd] || false
onFileRemove = options[:onFileRemove] || false
onFileSizeLimitReached = options[:onFileSizeLimitReached] || false
onFileNotInQueue = options[:onFileNotInQueue] || false
onQueueChange = options[:onQueueChange] || false
onQueueClear = options[:onQueueClear] || false
onQueueSizeLimitReached = options[:onQueueSizeLimitReached] || false
onQueueEmpty = options[:onQueueEmpty] || false
onUploadingStop = options[:onUploadingStop] || false
onUploadingStart = options[:onUploadingStart] || false
onUploadingFinish = options[:onUploadingFinish] || false
onSignatureOpen = options[:onSignatureOpen] || false
onSignatureProgress = options[:onSignatureProgress] || false
onSignatureHttpStatus = options[:onSignatureHttpStatus] || false
onSignatureComplete = options[:onSignatureComplete] || false
onSignatureSecurityError= options[:onSignatureSecurityError] || false
onSignatureIOError = options[:onSignatureIOError] || false
onSignatureXMLError = options[:onSignatureXMLError] || false
onUploadOpen = options[:onUploadOpen] || false
onUploadProgress = options[:onUploadProgress] || false
onUploadHttpStatus = options[:onUploadHttpStatus] || false
onUploadComplete = options[:onUploadComplete] || false
onUploadIOError = options[:onUploadIOError] || false
onUploadSecurityError = options[:onUploadSecurityError] || false
onUploadError = options[:onUploadError] || false
@include_s3_upload ||= false
@count ||= 1
out = ''
if Rails.version < '3.1.0'
if !@include_s3_upload
out << javascript_include_tag('s3_upload')
@include_s3_upload = true
end
end
out << "\n<script type=\"text/javascript\">\n"
out << "var s3_swf_#{@count}_object = s3_swf_init('s3_swf_#{@count}', {\n"
out << "buttonWidth: #{buttonWidth},\n" if buttonWidth
out << "buttonHeight: #{buttonHeight},\n" if buttonHeight
out << "flashVersion: '#{flashVersion}',\n" if flashVersion
out << "queueSizeLimit: #{queueSizeLimit},\n" if queueSizeLimit
out << "fileSizeLimit: #{fileSizeLimit},\n" if fileSizeLimit
out << "fileTypes: '#{fileTypes}',\n" if fileTypes
out << "fileTypeDescs: '#{fileTypeDescs}',\n" if fileTypeDescs
out << "selectMultipleFiles: #{selectMultipleFiles.to_s},\n"
out << "keyPrefix: '#{keyPrefix}',\n" if keyPrefix
out << "signaturePath: '#{signaturePath}',\n" if signaturePath
out << "swfFilePath: '#{swfFilePath}',\n" if swfFilePath
out << "buttonUpPath: '#{buttonUpPath}',\n" if buttonUpPath
out << "buttonOverPath: '#{buttonOverPath}',\n" if buttonOverPath
out << "buttonDownPath: '#{buttonDownPath}',\n" if buttonDownPath
out << "swfVarObj: 's3_swf_#{@count}_object',\n"
out << %(onFileAdd: function(file){
#{onFileAdd}
},) if onFileAdd
out << %(onFileRemove: function(file){
#{onFileRemove}
},) if onFileRemove
out << %(onFileSizeLimitReached: function(file){
#{onFileSizeLimitReached}
},) if onFileSizeLimitReached
out << %(onFileNotInQueue: function(file){
#{onFileNotInQueue}
},) if onFileNotInQueue
out << %(onQueueChange: function(queue){
#{onQueueChange}
},) if onQueueChange
out << %(onQueueSizeLimitReached: function(queue){
#{onQueueSizeLimitReached}
},) if onQueueSizeLimitReached
out << %(onQueueEmpty: function(queue){
#{onQueueEmpty}
},) if onQueueEmpty
out << %(onQueueClear: function(queue){
#{onQueueClear}
},) if onQueueClear
out << %(onUploadingStart: function(){
#{onUploadingStart}
},) if onUploadingStart
out << %(onUploadingStop: function(){
#{onUploadingStop}
},) if onUploadingStop
out << %(onUploadingFinish: function(){
#{onUploadingFinish}
},) if onUploadingFinish
out << %(onSignatureOpen: function(file,event){
#{onSignatureOpen}
},) if onSignatureOpen
out << %(onSignatureProgress: function(file,progress_event){
#{onSignatureProgress}
},) if onSignatureProgress
out << %(onSignatureSecurityError: function(file,security_error_event){
#{onSignatureSecurityError}
},) if onSignatureSecurityError
out << %(onSignatureComplete: function(file,event){
#{onSignatureComplete}
},) if onSignatureComplete
out << %(onSignatureIOError: function(file,io_error_event){
#{onSignatureIOError}
},) if onSignatureIOError
out << %(onSignatureHttpStatus: function(file,http_status_event){
#{onSignatureHttpStatus}
},) if onSignatureHttpStatus
out << %(onSignatureXMLError: function(file,error_message){
#{onSignatureXMLError}
},) if onSignatureXMLError
out << %(onUploadError: function(upload_options,error){
#{onUploadError}
},) if onUploadError
out << %(onUploadOpen: function(upload_options,event){
#{onUploadOpen}
},) if onUploadOpen
out << %(onUploadProgress: function(upload_options,progress_event){
#{onUploadProgress}
},) if onUploadProgress
out << %(onUploadIOError: function(upload_options,io_error_event){
#{onUploadIOError}
},) if onUploadIOError
out << %(onUploadHttpStatus: function(upload_options,http_status_event){
#{onUploadHttpStatus}
},) if onUploadHttpStatus
out << %(onUploadSecurityError: function(upload_options,security_error_event){
#{onUploadSecurityError}
},) if onUploadSecurityError
out << %(onUploadComplete: function(upload_options,event){
#{onUploadComplete}
},) if onUploadComplete
# This closes out the object (no comma)
out << "foo: 'bar'"
out << "});\n"
out << "</script>\n"
out << "<div id=\"s3_swf_#{@count}\">\n"
out << "Please <a href=\"http://www.adobe.com/go/getflashplayer\">Update</a> your Flash Player to Flash v#{flashVersion} or higher...\n"
out << "</div>\n"
@count += 1
out
end
end
end
ActionView::Base.send(:include, S3SwfUpload::ViewHelpers)