| Module | MultiBitShiftHelper |
| In: |
lib/multi_bit_shift_helper.rb
|
This module contains helper methods to assist in including the multi bit shift flash applet for attributes created with the acts_as_mbs_files method. It will be automatically included into ActionView::Base, thereby making this module�s methods available in all your views.
Note: This documentation heavily influenced by the open source plugin FileColumn‘s documentation.
Returns a multi bit shift field input tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object). A hidden field is used to persist the guid over multiple validation attempts. The width and height options are set to 420 and 240 by default, and the applicationToken is automatically set to guid of the field. In addition, the actions for the uploadURL and removeFileURL are automatically set, to upload_file, and remove_files respectively. Finally, the existing files are passed into the applet. A validation object can be passed using the validation_object index of the options hash.
By default, this helper is used with the Multi Bit Shift applet. To use with the advanced applet, mbs_version option should be set to ‘Advanced’, and the width and height should be set to pixel values. Addtionally, the done button should be disabled.
The other options that can be specified using the options hash can be found in the queryStringLoader parameters documentation of the flash applet, which can be located at multibitshift.com/documentation/view. These options will be passed to the flash applet and can be used to customize the applet at runtime.
# File lib/multi_bit_shift_helper.rb, line 19
19: def multi_bit_shift_field(object_name, method, options={})
20: if options['width'].nil?
21: options['width'] = '420'
22: end
23: if options['height'].nil?
24: options['height'] = '240'
25: end
26: if options['applicationToken'].nil?
27: options['applicationToken'] = self.instance_variable_get("@#{object_name}").method("#{method}_guid").call
28: end
29: if options['uploadURL'].nil?
30: options['uploadURL'] = url_for(:action => 'upload_file')
31: end
32: if options['removeFileURL'].nil?
33: options['removeFileURL'] = url_for(:action => 'remove_files')
34: end
35: if !options['validation_object'].nil?
36: count = 1
37: for file in Object.const_get(options['validation_object'].file_class).find_all_by_associated_with(options['applicationToken'])
38: options["uploadedFileName#{count}"] = file["file_name"]
39: options["uploadedFileSize#{count}"] = File.size(file.file_name).to_s
40: count = count + 1
41: end
42: options = options['validation_object'].convert_to_flash_params.merge(options)
43: options.delete('validation_object')
44: end
45:
46: output = []
47: output << hidden_field(object_name, method)
48: output << multi_bit_shift_flash(options)
49: output.join('')
50: end
Inserts the javascript and HTML to present the multi bit shift flash file. The options hash contains the options (for all options, see multibitshift.com/docs/multi_bit_shift/docs/files/as/queryStringLoader-as.html) to pass to the flash file, as well as additional options as listed below:
The other options can be found in the queryStringLoader parameters documentation of the flash applet, which can be located at multibitshift.com/documentation/view.
The code that is generated is based entirely on output from Macromedia Flex.
# File lib/multi_bit_shift_helper.rb, line 78
78: def multi_bit_shift_flash(options={})
79: if options['width'].nil?
80: width = '100%'
81: else
82: width = options['width']
83: end
84:
85: if options['height'].nil?
86: height = '100%'
87: else
88: height = options['height']
89: end
90:
91: if options['ajax_safe'].nil?
92: options['ajax_safe'] = false.to_s
93: else
94: options['ajax_safe'] = options['ajax_safe'].to_s
95: end
96:
97: if !options['mbs_version'].nil? and options['mbs_version'] == "Advanced"
98: options['file_name'] = "flashFileHelperAdvanced"
99: end
100:
101: if options['file_name'].nil?
102: file_name = "flashFileHelper"
103: else
104: file_name = options['file_name']
105: options.delete('file_name')
106: end
107:
108: if options['uploadURL'].nil?
109: options['uploadURL'] = url_for(:action => 'upload_file')
110: end
111:
112: if options['removeFileURL'].nil?
113: options['removeFileURL'] = url_for(:action => 'remove_files')
114: end
115:
116: if options['fileListURL'].nil?
117: options['fileListURL'] = url_for(:action => 'files_on_server')
118: end
119:
120: if options['renameFileURL'].nil?
121: options['renameFileURL'] = url_for(:action => 'rename_file')
122: end
123:
124: if options['doneURL'].nil?
125: options['doneURL'] = url_for(:action => 'index')
126: end
127:
128: if options['flashCSS'].nil?
129: options['flashCSS'] = '/flash/css/siu.swf'
130: end
131:
132: if options['rotateCWImageURL'].nil?
133: options['rotateCWImageURL'] = '/flash/cw.gif'
134: end
135:
136: if options['rotateCCWImageURL'].nil?
137: options['rotateCCWImageURL'] = '/flash/ccw.gif'
138: end
139:
140:
141: options.each{ |key,value|
142: options[key] = URI.escape(value)
143: }
144: parameters = []
145: options.each{ |key,value|
146: parameters << "#{key}=#{value}"
147: }
148: parameters = parameters.join('&')
149:
150: if options['ajax_safe'] == "true"
151: insert_string = " <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n id=\"\#{file_name}\" width=\"\#{width}\" height=\"\#{height}\"\n codebase=\"http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab\">\n <param name=\"movie\" value=\"\#{file_path(file_name + '.swf')}?\#{parameters}\" />\n <param name=\"quality\" value=\"high\" />\n <param name=\"bgcolor\" value=\"#ffffff\" />\n <param name=\"flashvars\" value=\"\#{parameters}\" />\n <param name=\"allowScriptAccess\" value=\"sameDomain\" />\n <embed src=\"\#{file_path(file_name + '.swf')}\" quality=\"high\" bgcolor=\"#ffffff\"\n width=\"\#{width}\" height=\"\#{height}\" name=\"\#{file_name}\" align=\"middle\" flashvars=\"\#{parameters}\"\n play=\"true\"\n loop=\"false\"\n quality=\"high\"\n allowScriptAccess=\"sameDomain\"\n type=\"application/x-shockwave-flash\"\n pluginspage=\"http://www.adobe.com/go/getflashplayer\">\n </embed>\n </object>\n"
152: else
153: insert_string = "<script language=\"JavaScript\" type=\"text/javascript\">\n<!--\n// -----------------------------------------------------------------------------\n// Globals\n// Major version of Flash required\nvar requiredMajorVersion = 9;\n// Minor version of Flash required\nvar requiredMinorVersion = 0;\n// Minor version of Flash required\nvar requiredRevision = 0;\n// -----------------------------------------------------------------------------\n// -->\n</script>\n<script src=\"\#{file_path('AC_OETags.js')}\" language=\"javascript\"></script>\n<script language=\"JavaScript\" type=\"text/javascript\">\n<!--\n// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)\nvar hasProductInstall = DetectFlashVer(6, 0, 65);\n\n// Version check based upon the values defined in globals\nvar hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);\n\n\n// Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback\nif ( hasProductInstall && !hasRequestedVersion ) {\n // MMdoctitle is the stored document.title value used by the installation process to close the window that started the process\n // This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed\n // DO NOT MODIFY THE FOLLOWING FOUR LINES\n // Location visited after installation is complete if installation is required\n var MMPlayerType = (isIE == true) ? \"ActiveX\" : \"PlugIn\";\n var MMredirectURL = window.location;\n document.title = document.title.slice(0, 47) + \" - Flash Player Installation\";\n var MMdoctitle = document.title;\n\n AC_FL_RunContent(\n \"src\", \"\#{file_path('playerProductInstall')}\",\n \"FlashVars\", \"MMredirectURL=\"+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+\"\",\n \"width\", \"\#{width}\",\n \"height\", \"\#{height}\",\n \"align\", \"middle\",\n \"id\", \"\#{file_name}\",\n \"quality\", \"high\",\n \"bgcolor\", \"#ffffff\",\n \"name\", \"\#{file_name}\",\n \"allowScriptAccess\",\"sameDomain\",\n \"type\", \"application/x-shockwave-flash\",\n \"pluginspage\", \"http://www.adobe.com/go/getflashplayer\"\n );\n} else if (hasRequestedVersion) {\n // if we've detected an acceptable version\n // embed the Flash Content SWF when all tests are passed\n AC_FL_RunContent(\n \"src\", \"\#{file_path(file_name)}\",\n \"width\", \"\#{width}\",\n \"height\", \"\#{height}\",\n \"align\", \"middle\",\n \"id\", \"\#{file_name}\",\n \"quality\", \"high\",\n \"bgcolor\", \"#ffffff\",\n \"name\", \"\#{file_name}\",\n \"flashvars\",'\#{parameters}',\n \"allowScriptAccess\",\"sameDomain\",\n \"type\", \"application/x-shockwave-flash\",\n \"pluginspage\", \"http://www.adobe.com/go/getflashplayer\"\n );\n } else { // flash is too old or we can't detect the plugin\n var alternateContent = 'Alternate HTML content should be placed here. '\n + 'This content requires the Adobe Flash Player. '\n + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';\n document.write(alternateContent); // insert non-flash content\n }\n// -->\n</script>\n<noscript>\n <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n id=\"\#{file_name}\" width=\"\#{width}\" height=\"\#{height}\"\n codebase=\"http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab\">\n <param name=\"movie\" value=\"\#{file_path(file_name + '.swf')}?\#{parameters}\" />\n <param name=\"quality\" value=\"high\" />\n <param name=\"bgcolor\" value=\"#ffffff\" />\n <param name=\"flashvars\" value=\"\#{parameters}\" />\n <param name=\"allowScriptAccess\" value=\"sameDomain\" />\n <embed src=\"\#{file_path(file_name + '.swf')}\" quality=\"high\" bgcolor=\"#ffffff\"\n width=\"\#{width}\" height=\"\#{height}\" name=\"\#{file_name}\" align=\"middle\" flashvars=\"\#{parameters}\"\n play=\"true\"\n loop=\"false\"\n quality=\"high\"\n allowScriptAccess=\"sameDomain\"\n type=\"application/x-shockwave-flash\"\n pluginspage=\"http://www.adobe.com/go/getflashplayer\">\n </embed>\n </object>\n</noscript>\n"
154: end
155:
156: return insert_string
157: end