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

- old
+ new

@@ -1,8 +1,8 @@ <%= stylesheet_link_tag "lolita/upload/application_vendor.css" %> <%= javascript_include_tag "lolita/upload/application_vendor.js" %> -<% unless Lolita.locale.to_s.downcase=="en" %> +<% unless ::I18n.locale.to_s.downcase=="en" %> <%= javascript_include_tag "lolita/upload/I18n/#{Lolita.locale}.js"%> <% end %> <script type="text/javascript"> $(function(){ $("#<%=container%>").plupload({ @@ -22,17 +22,21 @@ {title: "<%=fdata[:title]%>", extensions: "<%= fdata[:extensions].is_a?(Array) ? fdata[:extensions].join(",") : fdata[:extensions] %>"}, <% end %> ], <% end %> multipart: true, + <% if tab.association_type == :one %> + max_file_count: 1, + multi_selection: false, + <% end %> multipart_params: { "authenticity_token" : '<%= form_authenticity_token %>', <% if tab.association.options[:as] -%> "<%="upload[#{tab.association.options[:as]}_type]"%>": "<%=resource.class%>", "<%="upload[#{tab.association.options[:as]}_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>" <% else -%> - "<%="upload[#{lolita_mapping.singular}_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>" + "<%="upload[#{tab.association.foreign_key}]"%>": "<%=resource.new_record? ? 0 : resource.id%>" <% end -%> }, headers:{ "X-CSRF-Token": $("meta[name='csrf-token']").attr("content") }, @@ -40,15 +44,15 @@ // Flash settings flash_swf_url : "<%=asset_path("lolita/upload/plupload.flash.swf")%>", init:{ FileUploaded:function(uploader, file, info){ <% if tab.association_type == :many %> - $("#file_list_for_<%=tab.association.name%>>tbody").append(info.response) + $("#file_list_for_<%=tab.association.name%>").append(info.response) <% else %> uploader.splice(0,10); - $("#file_list_for_<%=tab.association.name%>>tbody").html("") - $("#file_list_for_<%=tab.association.name%>>tbody").append(info.response) + $("#file_list_for_<%=tab.association.name%>").html("") + $("#file_list_for_<%=tab.association.name%>").append(info.response) <% end %> <% if tab.association_type == :many %> var ids="<%="#{resource_name}[#{tab.association.name.to_s.singularize}_ids][]"%>" <% else %> @@ -59,16 +63,16 @@ $("input.<%=tab.association.name%>-ids").each(function(){ existing_ids.push($(this).val()) }) var new_ids=[] - $("#file_list_for_<%=tab.association.name%> tr[data-<%=tab.association.name%>-id]").each(function(){ + $("#file_list_for_<%=tab.association.name%> .file-item[data-<%=tab.association.name%>-id]").each(function(){ if($.inArray($(this).attr("data-<%=tab.association.name%>-id"),existing_ids)<0){ new_ids.push($(this).attr("data-<%=tab.association.name%>-id")) } }) for(var i in new_ids){ - $("#<%=tab.association.name%>_form").append('<input type="hidden" class="<%=tab.association.name%>-ids" name="'+ids+'" value="'+new_ids[i]+'" />') + $(".tabs form:first").append('<input type="hidden" class="<%=tab.association.name%>-ids" name="'+ids+'" value="'+new_ids[i]+'" />') } } },