diff --git a/app/assets/javascripts/admin/filemanager.js b/app/assets/javascripts/admin/filemanager.js index 2558cb46..9abd9d17 100644 --- a/app/assets/javascripts/admin/filemanager.js +++ b/app/assets/javascripts/admin/filemanager.js @@ -33,14 +33,47 @@ $(document).ready(function(){ var insertBtn = $("#insert_btn"), deleteBtn = $("#delete_btn"), url = null; + + var showPreview = function(elem){ + var type = $("#ext_" + elem.val()).val(), + imgexp = new RegExp(/(\.|\/)(gif|jpe?g|png)$/i), + otherexp = new RegExp(/(\.|\/)(pdf|doc|docx|ppt|pptx|xls|xlsx)$/i) + img = $(""), + preview = $( ".preview-area" ); + preview.text("Preview is loading..."); + if( imgexp.test(type) ){ + var url = $("#url_" + elem.val()).val(); + img.attr("src",url).load(function(){ + var ratio = this.width / this.height, + targetWidth = targetHeight = 200; + if( ratio < 1 ){ + targetWidth = targetHeight * ratio; + }else{ + targetHeight = targetWidth / ratio; + } + img.height(targetHeight).width(targetWidth); + preview.html(img); + }) + }else if( otherexp.test(type) ) { + var t = type.replace(".",""), + url = "/assets/ft-icons/" + t + "/" + t + "-128_32.png"; + img.attr('src', url).load(function(){ + preview.html(img); + }); + }else{ + preview.html("Preview not available."); + } + } $("#asset_sort_list").on(clickEvent,"input[type=checkbox]",function(){ if($("#asset_sort_list input[type=checkbox]:checked").length == 1){ url = window.location.protocol + "//" + window.location.host + $("#url_" + $("input[type=checkbox]:checked").val()).val(); insertBtn.show(); + showPreview($("input[type=checkbox]:checked")) }else{ insertBtn.hide(); url = null; + $( ".preview-area" ).empty(); } if($("#asset_sort_list input[type=checkbox]:checked").length) deleteBtn.show(); diff --git a/app/assets/javascripts/ckeditor/config.js.erb b/app/assets/javascripts/ckeditor/config.js.erb index a3a474fa..199ec326 100644 --- a/app/assets/javascripts/ckeditor/config.js.erb +++ b/app/assets/javascripts/ckeditor/config.js.erb @@ -26,8 +26,8 @@ CKEDITOR.editorConfig = function( config ) { // config.filebrowserImageBrowseUrl = '/browser/browse.php?type=Images'; // config.filebrowserUploadUrl = '/uploader/upload.php'; - config.filebrowserBrowseUrl = "<%= Rails.application.routes.url_helpers.admin_assets_path %>?module_app_id=<%= ModuleApp.first(conditions: {title: 'Asset'}).id.to_s %>"; - config.filebrowserImageBrowseUrl = "<%= Rails.application.routes.url_helpers.admin_assets_path %>?type=images&module_app_id=<%= ModuleApp.first(conditions: {title: 'Asset'}).id.to_s %>"; + config.filebrowserBrowseUrl = "<%= Rails.application.routes.url_helpers.admin_assets_path(:module_app_id=>ModuleApp.where(:key=>'asset').first.id) %>"; + config.filebrowserImageBrowseUrl = "<%= Rails.application.routes.url_helpers.admin_assets_path(:type=>'image',:module_app_id=>ModuleApp.where(:key=>'asset').first.id) %>"; // config.filebrowserUploadUrl = "<%= Rails.application.routes.url_helpers.file_upload_admin_assets_path %>"; // config.contentsCss = '/orbit_4.0.1/assets/javascripts/lib/ckeditor/plugins/stylesheetparser/samples/assets/sample.css'; diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb index ef054a1d..f91be58a 100644 --- a/app/controllers/admin/assets_controller.rb +++ b/app/controllers/admin/assets_controller.rb @@ -3,8 +3,8 @@ class Admin::AssetsController < OrbitBackendController before_filter :setup_vars def index - @assets = (params[:sort] || @filter) ? get_sorted_and_filtered("asset") : Asset.all.desc(:created_at).page(params[:page]).per(10) - if params[:type] == "images" + @assets = (params[:sort] || @filter) ? get_sorted_and_filtered("asset") : Asset.all.desc(:created_at) + if params[:type] == "image" @assets = @assets.where(:content_type => /^image/) end @tag = ModuleTag.new @@ -12,6 +12,8 @@ class Admin::AssetsController < OrbitBackendController @module_app = ModuleApp.find(params[:module_app_id]) rescue nil raise ModuleAppError, 'Can not find ModuleApp' if @module_app.nil? @module_app_id = @module_app.id rescue nil + + @assets = @assets.page(params[:page]).per(10) render :layout => "assets" end diff --git a/app/views/admin/assets/_asset.html.erb b/app/views/admin/assets/_asset.html.erb index fd76be26..0a319c24 100644 --- a/app/views/admin/assets/_asset.html.erb +++ b/app/views/admin/assets/_asset.html.erb @@ -6,6 +6,7 @@ <% end %> + <%= asset.title_translations[I18n.locale.to_s] rescue nil %> <%= number_to_human_size(asset.data.file.file_length) rescue nil %> <%= asset.description rescue nil %> - + Edit diff --git a/app/views/admin/assets/index.html.erb b/app/views/admin/assets/index.html.erb index 59ea57e2..8fcdf52c 100644 --- a/app/views/admin/assets/index.html.erb +++ b/app/views/admin/assets/index.html.erb @@ -214,11 +214,14 @@
-
- preview is here + +
+
+ Search Box : + @@ -226,7 +229,6 @@ - @@ -235,24 +237,13 @@
Name Size DescriptionTags Action
-
- <%= paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]}, :remote => true %> -
diff --git a/app/views/admin/assets/index.js.erb b/app/views/admin/assets/index.js.erb new file mode 100644 index 00000000..a02b5aff --- /dev/null +++ b/app/views/admin/assets/index.js.erb @@ -0,0 +1,3 @@ +$("#tbody_assets").html("<%= j render :partial => 'asset', :collection => @assets %>"); +$(".pagination").html("<%= j paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :type => params[:type]}, :remote => true %>"); +$( ".preview-area" ).empty(); \ No newline at end of file