Skip to content
This repository was archived by the owner on Jan 26, 2025. It is now read-only.

Commit 685f5ca

Browse files
author
Sammy Larbi
committed
initial commit
0 parents  commit 685f5ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+24212
-0
lines changed

MIT-LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2011 Sammy Larbi
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PluploadRails3
2+
==============
3+
4+
Introduction goes here.
5+
6+
7+
Example
8+
=======
9+
10+
Example goes here.
11+
12+
13+
Copyright (c) 2011 Sammy Larbi, released under the MIT license

Rakefile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'rake'
2+
require 'rake/testtask'
3+
require 'rake/rdoctask'
4+
5+
desc 'Default: run unit tests.'
6+
task :default => :test
7+
8+
desc 'Test the plupload_rails3 plugin.'
9+
Rake::TestTask.new(:test) do |t|
10+
t.libs << 'lib'
11+
t.libs << 'test'
12+
t.pattern = 'test/**/*_test.rb'
13+
t.verbose = true
14+
end
15+
16+
desc 'Generate documentation for the plupload_rails3 plugin.'
17+
Rake::RDocTask.new(:rdoc) do |rdoc|
18+
rdoc.rdoc_dir = 'rdoc'
19+
rdoc.title = 'PluploadRails3'
20+
rdoc.options << '--line-numbers' << '--inline-source'
21+
rdoc.rdoc_files.include('README')
22+
rdoc.rdoc_files.include('lib/**/*.rb')
23+
end

init.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'plupload_rails3'
2+
3+
%w{ middleware helpers }.each do |dir|
4+
path = File.join(File.dirname(__FILE__), 'app', dir)
5+
$LOAD_PATH << path
6+
ActiveSupport::Dependencies.autoload_paths << path
7+
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
8+
end
9+
10+
ActionController::Base.append_view_path File.expand_path(File.join(File.dirname(__FILE__), 'lib/app', 'views'))
11+
12+
ActionView::Base.send :include, PluploadHelper
13+
14+
config.middleware.insert_before 'ActionDispatch::ParamsParser', 'PluploadParamsRenamer'

install.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Install hook code here

lib/.DS_Store

6 KB
Binary file not shown.

lib/app/helpers/plupload_helper.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module PluploadHelper
2+
def plupload(model_object, model_object_method, options={})
3+
4+
5+
render :partial=>'plupload/uploader_scripts', :locals=>{
6+
:model_object=>model_object,
7+
:model_object_method=>model_object_method,
8+
:options=>options
9+
}
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'rack/utils'
2+
3+
class PluploadParamsRenamer
4+
def initialize(app)
5+
@app = app
6+
end
7+
8+
def call(env)
9+
req = Rack::Request.new(env)
10+
if req.POST["_plupload_upload"]
11+
object, method = req.params["_plupload_upload"].split(/[\[\]]/)
12+
req.params[object] ||= {}
13+
req.params[object][method] = req.params["file"] #req.POST[req.POST["_plupload_upload"]] = req.POST["file"]
14+
end
15+
16+
@app.call(env)
17+
end
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
<!-- Load Queue widget CSS and jQuery -->
3+
<style type="text/css">@import url(/stylesheets/plupload.queue.css);</style>
4+
5+
6+
7+
8+
<!-- Load plupload and all it's runtimes and finally the jQuery queue widget -->
9+
<script type="text/javascript" src="/javascripts/plupload/js/plupload.full.js"></script>
10+
<script type="text/javascript" src="/javascripts/plupload/js/jquery.plupload.queue/jquery.plupload.queue.js"></script>
11+
12+
<!-- Thirdparty intialization scripts, needed for the Google Gears and BrowserPlus runtimes -->
13+
<script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
14+
<script type="text/javascript" src="/javascripts/plupload/js/plupload.gears.js"></script>
15+
16+
17+
<script type="text/javascript">
18+
19+
// Convert divs to queue widgets when the DOM is ready
20+
$(function() {
21+
var authtoken = $("input[name=authenticity_token]").val();
22+
$("#uploader").pluploadQueue({
23+
// General settings
24+
runtimes : 'html5,flash,silverlight,gears,browserplus',
25+
url : '<%= url_for(model_object) %>',
26+
max_file_size : '10mb',
27+
//chunk_size : '1mb',
28+
//unique_names : true,
29+
multipart: true,
30+
multipart_params : $.extend( {'<%= CGI::unescape(options[:params].to_query.split("=").join("':'")) %>'}, {authenticity_token : authtoken, "_method" : "<%= model_object.new_record? ? 'post' : 'put' %>", "_plupload_upload" : "<%= model_object.class.name.underscore.downcase %>[<%= model_object_method %>]"}),
31+
filters : [
32+
{title : "Image files", extensions : "jpg,gif,png"},
33+
{title : "Zip files", extensions : "zip"},
34+
{title : "Adobe Files", extensions : "pdf,ai"}
35+
],
36+
37+
// Flash settings
38+
flash_swf_url : '/javascripts/plupload/js/plupload.flash.swf',
39+
40+
// Silverlight settings
41+
silverlight_xap_url : '/javascripts/plupload/js/plupload.silverlight.xap'
42+
});
43+
44+
// Client side form validation
45+
/*$('new_library_asset').submit(function(e) {
46+
alert("validating");
47+
var uploader = $('#uploader').pluploadQueue();
48+
49+
// Validate number of uploaded files
50+
if (uploader.total.uploaded == 0) {
51+
// Files in queue upload them first
52+
if (uploader.files.length > 0) {
53+
// When all files are uploaded submit form
54+
uploader.bind('UploadProgress', function() {
55+
if (uploader.total.uploaded == uploader.files.length)
56+
$('new_library_asset').submit();
57+
});
58+
59+
uploader.start();
60+
} else
61+
alert('You must at least upload one file.');
62+
63+
e.preventDefault();
64+
}
65+
});*/
66+
});
67+
</script>

lib/plupload_rails3.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require 'app/helpers/plupload_helper'
2+
require 'app/middleware/plupload_params_renamer'

lib/public/.DS_Store

12 KB
Binary file not shown.

lib/public/images/.DS_Store

6 KB
Binary file not shown.
2.91 KB
Loading
1.26 KB
Loading
1.41 KB
Loading

lib/public/images/plupload/delete.gif

180 Bytes
Loading

lib/public/images/plupload/done.gif

1 KB
Loading

lib/public/images/plupload/error.gif

994 Bytes
Loading
399 Bytes
Loading

lib/public/javascripts/.DS_Store

6 KB
Binary file not shown.

lib/public/javascripts/application.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Place your application-specific JavaScript functions and classes here
2+
// This file is automatically included by javascript_include_tag :defaults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Unobtrusive autocomplete
3+
*
4+
* To use it, you just have to include the HTML attribute autocomplete
5+
* with the autocomplete URL as the value
6+
*
7+
* Example:
8+
* <input type="text" data-autocomplete="/url/to/autocomplete">
9+
*
10+
* Optionally, you can use a jQuery selector to specify a field that can
11+
* be updated with the element id whenever you find a matching value
12+
*
13+
* Example:
14+
* <input type="text" data-autocomplete="/url/to/autocomplete" id_element="#id_field">
15+
*/
16+
17+
$(document).ready(function(){
18+
$('input[data-autocomplete]')
19+
.bind( "keydown", function( event ) {
20+
if ( event.keyCode === $.ui.keyCode.TAB &&
21+
$( this ).data( "autocomplete" ).menu.active ) {
22+
event.preventDefault();
23+
}
24+
})
25+
.railsAutocomplete();
26+
});
27+
28+
(function(jQuery)
29+
{
30+
var self = null;
31+
jQuery.fn.railsAutocomplete = function() {
32+
return this.live('focus',function() {
33+
if (!this.railsAutoCompleter) {
34+
this.railsAutoCompleter = new jQuery.railsAutocomplete(this);
35+
}
36+
});
37+
};
38+
39+
jQuery.railsAutocomplete = function (e) {
40+
_e = e;
41+
this.init(_e);
42+
};
43+
44+
jQuery.railsAutocomplete.fn = jQuery.railsAutocomplete.prototype = {
45+
railsAutocomplete: '0.0.1'
46+
};
47+
48+
jQuery.railsAutocomplete.fn.extend = jQuery.railsAutocomplete.extend = jQuery.extend;
49+
jQuery.railsAutocomplete.fn.extend({
50+
init: function(e) {
51+
e.delimiter = $(e).attr('data-delimiter') || null;
52+
function split( val ) {
53+
return val.split( e.delimiter );
54+
}
55+
function extractLast( term ) {
56+
return split( term ).pop().replace(/^\s+/,"");
57+
}
58+
59+
$(e).autocomplete({
60+
source: function( request, response ) {
61+
$.getJSON( $(e).attr('data-autocomplete'), {
62+
term: extractLast( request.term )
63+
}, function() {
64+
$(arguments[0]).each(function(i, el) {
65+
var obj = {};
66+
obj[el.id] = el;
67+
$(e).data(obj);
68+
});
69+
response.apply(null, arguments);
70+
});
71+
},
72+
search: function() {
73+
// custom minLength
74+
var term = extractLast( this.value );
75+
if ( term.length < 2 ) {
76+
return false;
77+
}
78+
},
79+
focus: function() {
80+
// prevent value inserted on focus
81+
return false;
82+
},
83+
select: function( event, ui ) {
84+
var terms = split( this.value );
85+
// remove the current input
86+
terms.pop();
87+
// add the selected item
88+
terms.push( ui.item.value );
89+
// add placeholder to get the comma-and-space at the end
90+
if (e.delimiter != null) {
91+
terms.push( "" );
92+
this.value = terms.join( e.delimiter );
93+
} else {
94+
this.value = terms.join("");
95+
if ($(this).attr('id_element')) {
96+
$($(this).attr('id_element')).val(ui.item.id);
97+
}
98+
if ($(this).attr('data-update-elements')) {
99+
var data = $(this).data(ui.item.id.toString());
100+
var update_elements = $.parseJSON($(this).attr("data-update-elements"));
101+
for (var key in update_elements) {
102+
$(update_elements[key]).val(data[key]);
103+
}
104+
}
105+
}
106+
$(this).trigger('railsAutocomplete.select');
107+
108+
return false;
109+
}
110+
});
111+
}
112+
});
113+
})(jQuery);

0 commit comments

Comments
 (0)