Fix uploader, ie9 ok, not ie8

This commit is contained in:
Christophe Vilayphiou 2012-08-07 17:32:15 +08:00
parent 73b2cd1035
commit 8ea7bf75cd
6 changed files with 79 additions and 18 deletions

View File

@ -1,7 +1,43 @@
$(document).on('click', '#ajax_form_submit', function(){
$('#ajaxForm').ajaxSubmit({
beforeSubmit: function(a,f,o) {
o.dataType = 'script';
// $('#ajaxForm').ajaxSubmit({
// beforeSubmit: function(a,f,o) {
// o.dataType = 'script';
// if (o.dataType == 'script') {
// o.url = o.url.split('?'); // split on GET params
// if (o.url[0].substr(-3) != '.js') o.url[0] += '.js'; // force rails to respond to respond to the request with :format = js
// o.url = o.url.join('?'); // join on GET params
// }
// },
// success: function(response,status,xhr){
// alert(response);
// alert(status);
// alert(xhr);
// },
// error:function(){
// alert("error");
// }
// });
var o = {
// dataType: 'script',
dataType: 'html',
url:$("#ajaxForm").attr("action"),
success: function(response,status,xhr){
alert(response);
eval(response);
},
error:function(){
alert("error");
}
});
}
if (o.dataType == 'script') {
o.url = o.url.split('?'); // split on GET params
if (o.url[0].substr(-3) != '.js') o.url[0] += '.js'; // force rails to respond to respond to the request with :format = js
o.url = o.url.join('?'); // join on GET params
}
$('#ajaxForm').ajaxSubmit(o);
});

View File

@ -47,7 +47,7 @@ function myFileBrowser(field_name, url, type, win) {
var cmsURL = window.location.toString();
cmsURL = cmsURL.split("/");
cmsURL = "<%= Rails.application.routes.url_helpers.file_upload_admin_assets_path %>";
console.log(cmsURL);
// console.log(cmsURL);
// script URL - use an absolute path!
if (cmsURL.indexOf("?") < 0) {
//add the type as the only query parameter

View File

@ -32,15 +32,16 @@ class Admin::AssetsController < OrbitBackendController
@asset = Asset.new(params[:asset])
@asset.filename = @asset.title rescue nil
if @asset.filename && @asset.save
respond_to do |format|
format.js {
if params[:uploader]
render 'create'
else
render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'replaceWith', :id => "asset_#{@asset.id}", :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil}
end
}
end
# respond_to do |format|
# format.js {
# if params[:uploader]
# render 'create'
# else
# render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'replaceWith', :id => "asset_#{@asset.id}", :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil}
# end
# }
# end
render :layout => false
else
flash[:error] = t(:create_fail)
@asset_categories = AssetCategory.all

View File

@ -0,0 +1,21 @@
// Uncomment and change this document.domain value if you are loading the script cross subdomains
// document.domain = 'moxiecode.com';
(function(){
var returnurl = "<%= @asset.data.url %>";
var returntitle = "<%= show_all_fields(@asset, 'title') %>";
var returndescription = "<%= show_all_fields(@asset, 'description') %>";
var win = tinyMCEPopup.getWindowArg("window");
win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = returnurl;
win.document.getElementById(tinyMCEPopup.getWindowArg("alt")).value = returndescription;
win.document.getElementById(tinyMCEPopup.getWindowArg("title")).value = returntitle;
if (typeof(win.ImageDialog) != "undefined") {
// we are, so update image dimensions...
if (win.ImageDialog.getImageData)
win.ImageDialog.getImageData();
// ... and preview if necessary
if (win.ImageDialog.showPreviewImage)
win.ImageDialog.showPreviewImage(returnurl);
}
tinyMCEPopup.close();})()

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,10 @@
<%= javascript_include_tag "new_admin" %>
<%= stylesheet_link_tag "new_admin" %>
<%= javascript_include_tag "tinymce/tiny_mce_popup" %>
<%= flash_messages %>
<body onload="tinyMCEPopup.executeOnLoad('init();')">
<%= form_for :asset, :url => admin_assets_path(:uploader => true), :html => {:id => 'ajaxForm', :multipart => true } do |f| %>
<div class="modal-header">
<h3><%= t 'admin.file_upload' %></h3>
@ -56,3 +58,4 @@
</div>
<% end %>
</body>