multiple_files_by_pete 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aac6d941ad34cf9d92aa4902f067f00f1e54650206adc833b9cd4fec2b74e4ef
4
+ data.tar.gz: 6ed6be9196422f609f2f912e294e1fb3a973f68540535e745e682652ae186a43
5
+ SHA512:
6
+ metadata.gz: cd4df6185c93754bc01f5d4ad01ab421905202cb8a077e9cd17783f98db6f741e3ec26eda9b2f9f64fd6eff03cbf95b843b7ee72781d9dec4281675257d7502e
7
+ data.tar.gz: a379682deaf49903c956a3c189dd4b293b8d23604a871d37dad5a96613d278d627eb986547d1bd8ca4d6e5546b146dc52f23f3b9aa3c60397a4b370c3c1092b2
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-01-01
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at pedroconsuegrat@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in multiple_files_by_pete.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.7"
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # MultipleFilesByPete
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/multiple_files_by_pete`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'multiple_files_by_pete'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install multiple_files_by_pete
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/multiple_files_by_pete. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/multiple_files_by_pete/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the MultipleFilesByPete project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/multiple_files_by_pete/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "multiple_files_by_pete"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MultipleFilesByPete
4
+ VERSION = "0.2.1"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "multiple_files_by_pete/version"
4
+
5
+ module MultipleFilesByPete
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
9
+
10
+
11
+ require_relative "railtie" if defined?(Rails::Railtie)
@@ -0,0 +1,68 @@
1
+ require 'colorize'
2
+ require 'fileutils'
3
+ require "tty-file"
4
+
5
+ module PeterConsuegraRecipes
6
+
7
+ def self.move_templates(src_folder,dest_folder,files)
8
+ FileUtils.mkdir_p dest_folder
9
+ files.each do |file_name|
10
+ FileUtils.cp(src_folder+file_name,dest_folder+file_name)
11
+ puts "file copied to: #{dest_folder+file_name}".green
12
+ end
13
+ end
14
+
15
+ def self.move_template(src_folder,dest_folder,file)
16
+ FileUtils.mkdir_p dest_folder
17
+ FileUtils.cp src_folder+file,dest_folder+file
18
+ puts "File copied to: #{dest_folder+file}".green
19
+ end
20
+
21
+ def self.add_route(base_route,action_name,method)
22
+ rails_app_folder = Dir.pwd
23
+ route_file="#{rails_app_folder}/config/routes.rb"
24
+ route_code = "#{method} '/#{base_route}_#{action_name}', to: '#{base_route}##{action_name}'"
25
+ PeterConsuegraRecipes::append_before_last_appearance_of("end",route_code,route_file)
26
+ puts "Adding route: #{route_code}".blue
27
+ end
28
+
29
+ def self.add_concern_to_controller(code,controller_file,controller_class)
30
+ rails_app_folder = Dir.pwd
31
+ file="#{rails_app_folder}/app/controllers/#{controller_file}"
32
+ #puts "class #{controller_class} < ApplicationController"
33
+ #code="include FilesByPete\n"
34
+ TTY::File.inject_into_file file, code, after: "class #{controller_class} < ApplicationController\n"
35
+ puts "Adding concern to controller #{file}: #{code}".blue
36
+ end
37
+
38
+ def self.append_before_last_appearance_of(string,code,file)
39
+ File.open(file, 'r+') do |file|
40
+ lines = file.each_line.to_a
41
+ length = lines.length()
42
+
43
+ lines.reverse.each_with_index do |val, index|
44
+ if val.include?(string)
45
+ aux = lines[length-(index+1)]
46
+ lines[length-(index+1)] = "#{code} \n"
47
+ lines.append(aux)
48
+ file.rewind
49
+ file.write(lines.join)
50
+ break
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.get_scaffold_vars(model)
57
+ hash = Hash.new
58
+ hash["model"] = model
59
+ hash["model_class"] = model.titleize.gsub(' ','')
60
+ hash["table_name"] = eval(hash["model_class"]).table_name
61
+ hash["controller_file"] = hash["table_name"]+"_controller.rb"
62
+ hash["controller_class"] = hash["table_name"].titleize.gsub(' ','')+"Controller"
63
+ hash["base_route"] = hash["table_name"]
64
+ #puts hash
65
+ return hash
66
+ end
67
+
68
+ end
data/lib/railtie.rb ADDED
@@ -0,0 +1,13 @@
1
+ #require 'countries_regions_and_cities_by_peterconsuegra'
2
+ #require 'rails'
3
+
4
+ module MultipleFilesByPete
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :multiple_files_by_pete
7
+
8
+ rake_tasks do
9
+ path = File.expand_path(__dir__)
10
+ Dir.glob("#{path}/tasks/*.rake").each { |f| load f }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ require_relative '../peterconsuegra_recipes'
2
+
3
+ #bundle exec rake 'multiple_files_by_pete[place]'
4
+
5
+ desc 'install multiple_files_by_pete required files'
6
+
7
+ task :multiple_files_by_pete, [:model] do |t, args|
8
+
9
+ #Require all app models
10
+ Dir.glob("#{Rails.root}/app/models/*.rb").each { |file| require file }
11
+
12
+ #Base routes
13
+ rails_app_folder = Dir.pwd
14
+ gem_folder = File.expand_path('../../../.', __FILE__)
15
+ src_folder="#{gem_folder}/templates/"
16
+
17
+ #Get scaffold vars
18
+ hash = PeterConsuegraRecipes::get_scaffold_vars(args[:model])
19
+
20
+ #Adding partials
21
+ PeterConsuegraRecipes::move_templates(src_folder,"#{rails_app_folder}/app/views/shared/",["_files_by_pete_js.html.erb","_files_by_pete.html.erb"])
22
+
23
+ #Adding concern
24
+ PeterConsuegraRecipes::move_template(src_folder,"#{rails_app_folder}/app/controllers/concerns/","files_by_pete.rb")
25
+
26
+ #Adding route to routes.rb
27
+ PeterConsuegraRecipes::add_route(hash['base_route'],"pete_file_upload","post")
28
+ PeterConsuegraRecipes::add_route(hash['base_route'],"pete_file_destroy","post")
29
+
30
+ #Adding concern to controller
31
+ PeterConsuegraRecipes::add_concern_to_controller("include FilesByPete\n",hash['controller_file'],hash['controller_class'])
32
+
33
+ #Adding layouts files
34
+ PeterConsuegraRecipes::move_templates(src_folder,"#{rails_app_folder}/public/multiple_files_by_pete/",["jquery-3.6.0.min.js","bootstrap.min.css"])
35
+
36
+ puts "-----------------------------------------".red
37
+ puts "Copy and paste this code in your project".red
38
+ puts "-----------------------------------------".red
39
+ puts "Add jQuery to your layout file:".red
40
+ puts "<script src='/multiple_files_by_pete/jquery-3.6.0.min.js'></script>".red
41
+ puts "Add bootstrap.min.css to your layout file:".red
42
+ puts '<link rel="stylesheet" href="/multiple_files_by_pete/bootstrap.min.css">'.red
43
+ puts 'Get all the files of that model in the action of the controller you are want:'.red
44
+ puts "@files = PeteFile.get_object_files(@#{args[:model]})".red
45
+ puts "Add the number of fields to upload files you need to your _form.html.erb file:".red
46
+ puts "<%= render partial: 'shared/files_by_pete', locals: {model: @#{args[:model]}, files: @files, section: 'legal_files' ,label: 'Upload legal files'} %>".red
47
+ puts "<%= render partial: 'shared/files_by_pete', locals: {model: @#{args[:model]}, files: @files, section: 'extra_files' ,label: 'Upload extra files'} %>".red
48
+ puts "Add the JS logic for multiple_file_by_pete to your _form.html.erb file:".red
49
+ puts "<%= render 'shared/files_by_pete_js', model: @#{args[:model]}, size_limit: 50%>".red
50
+
51
+ `rails g model PeteFile section:string attachable_id:integer attachable_type:string name:string`
52
+ sleep 2
53
+ `rake db:migrate`
54
+
55
+ #Adding model pete_file.rb
56
+ PeterConsuegraRecipes::move_template(src_folder,"#{rails_app_folder}/app/models/","pete_file.rb")
57
+
58
+ end
Binary file
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/multiple_files_by_pete/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "multiple_files_by_pete"
7
+ spec.version = MultipleFilesByPete::VERSION
8
+ spec.authors = ["Pedro Consuegra"]
9
+ spec.email = ["pedroconsuegrat@gmail.com"]
10
+
11
+ spec.summary = "An agile way to implement multiple files uploads in your ruby on rails scaffold"
12
+ spec.description = "An agile way to implement multiple files uploads in ruby on rails scaffold, without the need to create additional tables"
13
+ spec.homepage = "https://rubygems.org/gems/multiple_files_by_pete"
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/peterconsuegra/multiple_files_by_pete"
20
+ spec.metadata["changelog_uri"] = "https://github.com/peterconsuegra/multiple_files_by_pete/blob/master/CHANGELOG.md"
21
+
22
+ spec.license = 'MIT'
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency("colorize","~> 0.8.0")
34
+ spec.add_dependency("tty-file","~> 0.10.0")
35
+
36
+ # Uncomment to register a new dependency of your gem
37
+ # spec.add_dependency "example-gem", "~> 1.0"
38
+
39
+ # For more information and examples about making a new gem, checkout our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
@@ -0,0 +1,32 @@
1
+
2
+ <%if model.persisted?%>
3
+
4
+ <%
5
+ attachable_id = model.id
6
+ attachable_type = model.class.name
7
+ uniqid= rand(36**8).to_s(36)
8
+ section_files = files[section]
9
+
10
+ %>
11
+
12
+ <div id="upload_brief_area" class="upload_brief_file">
13
+
14
+ <p style="margin-bottom: 10px;margin-top:30px "><%=label%> </p>
15
+
16
+ <ul id="section_<%=section%>" style="margin-left: 20px">
17
+ <%unless section_files.nil?%>
18
+ <% section_files.each do |pete_file| %>
19
+ <li id="pete_file_<%=pete_file.id%>"><%=pete_file.get_file_a.html_safe%> <a pete_file_id="<%=pete_file.id%>" style="color:red" class="delete_file" href="#">X</a></li>
20
+ <%end%>
21
+ <%end%>
22
+ </ul>
23
+
24
+ <form action="/upload_files_by_pete" method="POST" class="form-horizontal frm-logoUpload" enctype="multipart/form-data">
25
+
26
+ <input type="file" id="<%=uniqid%>" section="<%=section%>" name="file" class="Uploadid" multiple="">
27
+
28
+ </form>
29
+
30
+ </div>
31
+
32
+ <%end%>
@@ -0,0 +1,173 @@
1
+ <%size_limit ||= 50 %>
2
+ <%table_name = model.class.table_name%>
3
+ <%delete_route = "#{table_name}_pete_file_destroy"%>
4
+ <%upload_route = "#{table_name}_pete_file_upload"%>
5
+
6
+ <script>
7
+
8
+ function delete_pete_file_logic(){
9
+
10
+ $(".delete_file").click(function() {
11
+
12
+ pete_file_id = $(this).attr("pete_file_id");
13
+
14
+ $.ajax({
15
+ url: "/<%=delete_route%>",
16
+ dataType: 'JSON',
17
+ type: 'POST',
18
+ data: {pete_file_id: pete_file_id, authenticity_token: "<%=form_authenticity_token%>"},
19
+ success : function(data) {
20
+ $("#pete_file_"+data.id).remove();
21
+ }
22
+ });
23
+
24
+ });
25
+
26
+ }
27
+
28
+
29
+ function moveprogressbar(percentage,div_id) {
30
+ var elem = document.getElementById(div_id);
31
+ var width = 10;
32
+ // elem.style.backgroundColor = "blue";
33
+ elem.style.width = percentage + '%';
34
+ //elem.innerHTML = percentage * 1 + '%';
35
+ }
36
+
37
+
38
+ function progressFunction(i,evt){
39
+
40
+ console.log("addEventListener progress")
41
+ console.log("i: "+ i)
42
+
43
+ if (evt.lengthComputable) {
44
+ var percentComplete = evt.loaded / evt.total;
45
+ //Do something with upload progress
46
+ console.log(percentComplete);
47
+ percente_value = percentComplete * 100;
48
+ moveprogressbar(percente_value,"myBar_"+i);
49
+ }
50
+ }
51
+
52
+
53
+ $('.upload_brief_file').each(function () {
54
+
55
+ //Se cargan a esta funciones para cada uploader del brief
56
+
57
+ var uploadField = $(this).find('input')[0];
58
+ console.log("upload_brief_file");
59
+
60
+ $(uploadField).on('change', function (e) {
61
+
62
+ var xhr_array = [];
63
+ var xhr_timestamps = [];
64
+ section = $(this).attr("section");
65
+
66
+ for (var i = 0; i < $(this).get(0).files.length; ++i) {
67
+
68
+ console.log($(this).get(0).files[i].name);
69
+ file_title = $(this).get(0).files[i].name;
70
+
71
+ var fileNameOriginal = $(this).get(0).files[i].name;
72
+ var fileinput = $(this).get(0).files[i];
73
+
74
+ var d = new Date();
75
+ var timestamp = d.getTime();
76
+
77
+ var iSize = ($(this)[0].files[i].size / 1024);
78
+ iSize = (Math.round((iSize / 1024) * 100) / 100)
79
+
80
+ if(iSize<=<%=size_limit%>){
81
+ //var oform = new FormData($(this).parent('form')[0]);
82
+
83
+ console.log("size: "+iSize)
84
+
85
+ var oform = new FormData();
86
+
87
+ oform.append("attachable_id", "<%=model.id%>");
88
+ oform.append("attachable_type", "<%=model.class.name%>");
89
+ oform.append("section", section);
90
+ oform.append("authenticity_token", "<%=form_authenticity_token%>");
91
+ oform.append("file", fileinput);
92
+ oform.append("timestamp", timestamp);
93
+ oform.append("title", file_title);
94
+
95
+
96
+ upload_progress_html = "";
97
+ upload_progress_html += '<div class="row">';
98
+ upload_progress_html += '<div class="col-md-6">';
99
+ upload_progress_html += '<div id ="progress_container_'+timestamp+'">';
100
+ upload_progress_html += '<label>'+fileNameOriginal+'</label>';
101
+ upload_progress_html += '<div class="progress">';
102
+ upload_progress_html += '<div class="progress-bar" id="myBar_'+timestamp+'" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%">';
103
+ upload_progress_html += '</div>';
104
+ upload_progress_html += '</div>';
105
+ upload_progress_html += '</div>';
106
+ upload_progress_html += '</div>';
107
+ upload_progress_html += '</div>';
108
+
109
+
110
+ $("#upload_brief_area").prepend(upload_progress_html);
111
+
112
+ $.ajax({
113
+ xhr: function()
114
+ {
115
+ console.log("entro en xhr")
116
+ xhr_array[i] = new window.XMLHttpRequest();
117
+
118
+ //Upload progress
119
+ xhr_array[i].upload.addEventListener("progress",progressFunction.bind(null, timestamp), false);
120
+ //Download progress
121
+
122
+ xhr_array[i].addEventListener("progress", function(evt){
123
+ if (evt.lengthComputable) {
124
+
125
+
126
+ var percentComplete = evt.loaded / evt.total;
127
+ //Do something with download progress
128
+ console.log("Download")
129
+ console.log(percentComplete,"myBar_"+xhr_timestamps[i]);
130
+
131
+ }
132
+ }, false);
133
+
134
+
135
+ return xhr_array[i];
136
+
137
+ },
138
+ url: "/<%=upload_route%>",
139
+ data: oform,
140
+ dataType: 'html',
141
+ method: 'post',
142
+ cache: false,
143
+ contentType: false,
144
+ processData: false,
145
+ fail: function (dat) {
146
+ console.log(dat);
147
+ console.log("fallo!");
148
+ },
149
+ success: function (data) {
150
+
151
+ parsedjson = JSON.parse(data);
152
+ $("#progress_container_"+parsedjson["timestamp"]).remove();
153
+ delete_link=" <a pete_file_id='"+parsedjson["pete_file"].id+"' style='color:red' class='delete_file' href='#'>X</a>"
154
+ id="id='pete_file_"+parsedjson["pete_file"].id+"'";
155
+ $("#section_"+parsedjson["pete_file"].section).append("<li "+id+">"+parsedjson["file_a"]+delete_link+"</li>")
156
+ delete_pete_file_logic();
157
+ }
158
+
159
+ });
160
+ }else{
161
+ alert("File: "+fileNameOriginal+" is bigger than 50MB")
162
+ return false
163
+ }
164
+
165
+ }
166
+
167
+ });
168
+
169
+ });
170
+
171
+ delete_pete_file_logic();
172
+
173
+ </script>