app/views/components/lolita/configuration/tab/files/_upload_script.html.erb in lolita-file-upload-0.1.3 vs app/views/components/lolita/configuration/tab/files/_upload_script.html.erb in lolita-file-upload-0.1.4

- old
+ new

@@ -6,37 +6,54 @@ <script type="text/javascript" src="/javascripts/lolita/upload/plupload.full.js"></script> <script type="text/javascript" src="/javascripts/lolita/upload/jquery.ui.plupload.js"></script> <% unless Lolita.locale.to_s.downcase=="en" %> <script type="text/javascript" src="/javascripts/lolita/upload/I18n/<%=Lolita.locale%>.js"></script> <% end %> - <script type="text/javascript"> $(function(){ $("#<%=container%>").plupload({ // General settings runtimes : 'html5,flash', url : '<%=send(:"lolita_upload_#{tab.type}_path")%>', max_file_size : '10mb', chunk_size : '1mb', unique_names : true, rename: true, + <% if tab.extensions.any? %> + filters:[ + <% tab.extensions.each do |ext_data| %> + {title: "<%=ext_data[:title]%>", extensions: "<%= ext_data[:extensions].is_a?(Array) ? ext_data[:extensions].join(",") : ext_data[:extensions] %>"}, + <% end %> + ], + <% end %> multipart: true, multipart_params: { "authenticity_token" : '<%= form_authenticity_token %>', - "<%="upload[#{tab.association.name.to_s.singularize}able_type]"%>": "<%=resource.class%>", - "<%="upload[#{tab.association.name.to_s.singularize}able_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>" + "<%="upload[#{tab.association.options[:as]}_type]"%>": "<%=resource.class%>", + "<%="upload[#{tab.association.options[:as]}_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>" }, headers:{ "X-CSRF-Token": $("meta[name='csrf-token']").attr("content") }, // Flash settings flash_swf_url : '/javascripts/lolita/upload/plupload.flash.swf', init:{ FileUploaded:function(uploader, file, info){ - $("#file_list_for_<%=tab.type%>>tbody").append(info.response) + <% if tab.association_type == :one %> + uploader.splice(0,10); + $("#file_list_for_<%=tab.type%>>tbody").html("") + $("#file_list_for_<%=tab.type%>>tbody").append(info.response) + <% else %> + $("#file_list_for_<%=tab.type%>>tbody").append(info.response) + <% end %> - var ids="<%="#{resource_name}[#{tab.type.to_s.singularize}_ids][]"%>" + <% if tab.association_type == :many %> + var ids="<%="#{resource_name}[#{tab.association.name}_ids][]"%>" + <% else %> + var ids = "<%="#{resource_name}[#{tab.association.name}_new]"%>" + <% end %> + var existing_ids=[] $("input.<%=tab.type%>-ids").each(function(){ existing_ids.push($(this).val()) })