From f920a4f6ba9e1ad5d050048f2b8c3de8dbd44f41 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 9 Sep 2013 23:10:04 +0800 Subject: [PATCH] filemanager and some update for file uploader . added file uploader to kernel --- app/assets/javascripts/ckeditor/config.js.erb | 7 +- .../file-upload/canvas-to-blob.min.js | 0 .../javascripts/file-upload/drop-zone.js | 0 .../file-upload/jquery.fileupload-fp.js | 0 .../file-upload/jquery.fileupload-ui.js | 0 .../file-upload/jquery.fileupload.js | 0 .../file-upload/jquery.iframe-transport.js | 0 .../javascripts/file-upload/load-image.min.js | 0 .../javascripts/file-upload/tmpl.min.js | 0 .../file-upload/vendor/jquery.ui.widget.js | 0 app/controllers/admin/assets_controller.rb | 40 +- app/helpers/admin/assets_helper.rb | 2 +- app/models/asset.rb | 13 +- app/models/ckeditor/asset.rb | 7 - app/models/ckeditor/attachment_file.rb | 7 - app/models/ckeditor/picture.rb | 7 - app/models/user/user.rb | 1 + app/views/admin/assets/_asset.html.erb | 30 +- app/views/admin/assets/delete_files.js.erb | 3 + app/views/admin/assets/index.html.erb | 498 +++++++++++++++++- app/views/admin/assets/index.js.erb | 4 - app/views/admin/module_tags/index.html.erb | 1 - app/views/layouts/assets.html.erb | 22 + config/routes.rb | 3 +- vendor/built_in_modules/asset/init.rb | 1 + .../assets/javascripts/file-upload/main.js | 13 - .../gallery/app/assets/javascripts/gallery.js | 12 + .../gallery/back_end/albums/show.html.erb | 3 +- 28 files changed, 586 insertions(+), 88 deletions(-) rename {vendor/built_in_modules/gallery/app => app}/assets/javascripts/file-upload/canvas-to-blob.min.js (100%) rename {vendor/built_in_modules/gallery/app => app}/assets/javascripts/file-upload/drop-zone.js (100%) rename {vendor/built_in_modules/gallery/app => app}/assets/javascripts/file-upload/jquery.fileupload-fp.js (100%) rename {vendor/built_in_modules/gallery/app => app}/assets/javascripts/file-upload/jquery.fileupload-ui.js (100%) rename {vendor/built_in_modules/gallery/app => app}/assets/javascripts/file-upload/jquery.fileupload.js (100%) rename {vendor/built_in_modules/gallery/app => app}/assets/javascripts/file-upload/jquery.iframe-transport.js (100%) rename {vendor/built_in_modules/gallery/app => app}/assets/javascripts/file-upload/load-image.min.js (100%) rename {vendor/built_in_modules/gallery/app => app}/assets/javascripts/file-upload/tmpl.min.js (100%) rename {vendor/built_in_modules/gallery/app => app}/assets/javascripts/file-upload/vendor/jquery.ui.widget.js (100%) delete mode 100644 app/models/ckeditor/asset.rb delete mode 100644 app/models/ckeditor/attachment_file.rb delete mode 100644 app/models/ckeditor/picture.rb create mode 100644 app/views/admin/assets/delete_files.js.erb delete mode 100644 app/views/admin/assets/index.js.erb create mode 100644 app/views/layouts/assets.html.erb delete mode 100644 vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/main.js diff --git a/app/assets/javascripts/ckeditor/config.js.erb b/app/assets/javascripts/ckeditor/config.js.erb index 9f51e6070..9a0572341 100644 --- a/app/assets/javascripts/ckeditor/config.js.erb +++ b/app/assets/javascripts/ckeditor/config.js.erb @@ -26,10 +26,11 @@ CKEDITOR.editorConfig = function( config ) { // config.filebrowserImageBrowseUrl = '/browser/browse.php?type=Images'; // config.filebrowserUploadUrl = '/uploader/upload.php'; - config.filebrowserBrowseUrl = "<%= Rails.application.routes.url_helpers.file_upload_admin_assets_path %>" - config.filebrowserUploadUrl = "<%= Rails.application.routes.url_helpers.file_upload_admin_assets_path %>" + config.filebrowserBrowseUrl = "<%= Rails.application.routes.url_helpers.admin_assets_path %>"; + config.filebrowserImageBrowseUrl = "<%= Rails.application.routes.url_helpers.admin_assets_path %>?type=images&module_app_id=<%= ModuleApp.first(conditions: {title: 'Asset'}).id.to_s %>"; + // 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'; + // config.contentsCss = '/orbit_4.0.1/assets/javascripts/lib/ckeditor/plugins/stylesheetparser/samples/assets/sample.css'; // Load from a list of definitions. // config.stylesSet = [ diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/canvas-to-blob.min.js b/app/assets/javascripts/file-upload/canvas-to-blob.min.js similarity index 100% rename from vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/canvas-to-blob.min.js rename to app/assets/javascripts/file-upload/canvas-to-blob.min.js diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/drop-zone.js b/app/assets/javascripts/file-upload/drop-zone.js similarity index 100% rename from vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/drop-zone.js rename to app/assets/javascripts/file-upload/drop-zone.js diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/jquery.fileupload-fp.js b/app/assets/javascripts/file-upload/jquery.fileupload-fp.js similarity index 100% rename from vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/jquery.fileupload-fp.js rename to app/assets/javascripts/file-upload/jquery.fileupload-fp.js diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/jquery.fileupload-ui.js b/app/assets/javascripts/file-upload/jquery.fileupload-ui.js similarity index 100% rename from vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/jquery.fileupload-ui.js rename to app/assets/javascripts/file-upload/jquery.fileupload-ui.js diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/jquery.fileupload.js b/app/assets/javascripts/file-upload/jquery.fileupload.js similarity index 100% rename from vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/jquery.fileupload.js rename to app/assets/javascripts/file-upload/jquery.fileupload.js diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/jquery.iframe-transport.js b/app/assets/javascripts/file-upload/jquery.iframe-transport.js similarity index 100% rename from vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/jquery.iframe-transport.js rename to app/assets/javascripts/file-upload/jquery.iframe-transport.js diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/load-image.min.js b/app/assets/javascripts/file-upload/load-image.min.js similarity index 100% rename from vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/load-image.min.js rename to app/assets/javascripts/file-upload/load-image.min.js diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/tmpl.min.js b/app/assets/javascripts/file-upload/tmpl.min.js similarity index 100% rename from vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/tmpl.min.js rename to app/assets/javascripts/file-upload/tmpl.min.js diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/vendor/jquery.ui.widget.js b/app/assets/javascripts/file-upload/vendor/jquery.ui.widget.js similarity index 100% rename from vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/vendor/jquery.ui.widget.js rename to app/assets/javascripts/file-upload/vendor/jquery.ui.widget.js diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb index 84875da25..96f0e7b93 100644 --- a/app/controllers/admin/assets_controller.rb +++ b/app/controllers/admin/assets_controller.rb @@ -3,7 +3,17 @@ class Admin::AssetsController < OrbitBackendController before_filter :setup_vars def index - @assets = (params[:sort] || @filter) ? get_sorted_and_filtered("asset") : Asset.all.page(params[:page]).per(10) + @assets = (params[:sort] || @filter) ? get_sorted_and_filtered("asset") : Asset.all.desc(:created_at).page(params[:page]).per(10) + if params[:type] == "images" + @assets = @assets.where(:content_type => /^image/) + end + @tag = ModuleTag.new + + @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 + + render :layout => "assets" end def show @@ -95,11 +105,31 @@ class Admin::AssetsController < OrbitBackendController redirect_to assets_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) end + def delete_files + @files = params[:files] + @files.each do |file| + asset = Asset.find(file) + asset.destroy + end + @assets = (params[:sort] || @filter) ? get_sorted_and_filtered("asset") : Asset.all.desc(:created_at).page(params[:page]).per(10) + if params[:type] == "images" + @assets = @assets.where(:content_type => /^image/) + end + # render :json =>{"success"=>true}.to_json + end + def file_upload - @asset = Asset.new - @asset_categories = AssetCategory.all - @tags = get_tags - render :layout => false + @files = params['files'] + a = Array.new + @files.each do |file| + @asset = current_user.assets.new + @asset.data = file + @asset.title_translations = {:en => file.original_filename, :zh_tw => file.original_filename} + # @asset.title_translations[:zh_tw] = file.original_filename + @asset.save! + a << {"url"=>@asset.data.url} + end + render :json=>{"files"=>a}.to_json end def file_select diff --git a/app/helpers/admin/assets_helper.rb b/app/helpers/admin/assets_helper.rb index f6187d522..9a2fd0a36 100644 --- a/app/helpers/admin/assets_helper.rb +++ b/app/helpers/admin/assets_helper.rb @@ -7,5 +7,5 @@ module Admin::AssetsHelper end a.join(' - ') end - + end \ No newline at end of file diff --git a/app/models/asset.rb b/app/models/asset.rb index 87ff514e0..132a4400d 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -5,13 +5,16 @@ class Asset include OrbitTag::Taggable mount_uploader :data, FileAssetUploader + before_save :update_asset_attributes field :filename field :description, localize: true field :title, localize: true + field :content_type + field :file_size validates :title, :at_least_one => true - validates :description, :at_least_one => true + validates_presence_of :data @@ -21,6 +24,14 @@ class Asset before_save :clean_tags protected + + + def update_asset_attributes + if data.present? && data_changed? + self.content_type = data.file.content_type + self.file_size = data.file.size + end + end def clean_tags self.tagged_ids.delete('') diff --git a/app/models/ckeditor/asset.rb b/app/models/ckeditor/asset.rb deleted file mode 100644 index e2cbe077d..000000000 --- a/app/models/ckeditor/asset.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Ckeditor::Asset - include Ckeditor::Orm::Mongoid::AssetBase - - delegate :url, :current_path, :size, :content_type, :filename, :to => :data - - validates_presence_of :data -end diff --git a/app/models/ckeditor/attachment_file.rb b/app/models/ckeditor/attachment_file.rb deleted file mode 100644 index 43a387282..000000000 --- a/app/models/ckeditor/attachment_file.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Ckeditor::AttachmentFile < Ckeditor::Asset - mount_uploader :data, CkeditorAttachmentFileUploader, :mount_on => :data_file_name - - def url_thumb - @url_thumb ||= Ckeditor::Utils.filethumb(filename) - end -end diff --git a/app/models/ckeditor/picture.rb b/app/models/ckeditor/picture.rb deleted file mode 100644 index 74f6da4c6..000000000 --- a/app/models/ckeditor/picture.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Ckeditor::Picture < Ckeditor::Asset - mount_uploader :data, CkeditorPictureUploader, :mount_on => :data_file_name - - def url_content - url(:content) - end -end diff --git a/app/models/user/user.rb b/app/models/user/user.rb index d1a58d536..c8a682c89 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -32,6 +32,7 @@ class User has_one :desktop, :autosave => true, :dependent => :destroy has_one :facebook, :autosave => true, :dependent => :destroy has_many :other_accounts, :autosave => true, :dependent => :destroy + has_many :assets, as: :assetable # has_many :journals, :autosave => true, :dependent => :destroy # has_many :papers, :autosave => true, :dependent => :destroy has_and_belongs_to_many :sub_role_tags diff --git a/app/views/admin/assets/_asset.html.erb b/app/views/admin/assets/_asset.html.erb index 27d4a2059..860d39933 100644 --- a/app/views/admin/assets/_asset.html.erb +++ b/app/views/admin/assets/_asset.html.erb @@ -1,16 +1,23 @@ - <%= check_box_tag 'to_delete[]', asset.id, false, :class => "checkbox_in_list" %> - <%= asset.title rescue nil %> + <%= check_box_tag 'files[]', asset.id, false, :class => "checkbox_in_list" %> + + <% @site_valid_locales.each_with_index do |locale, i| %> + + + <% 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 %> @@ -22,10 +29,7 @@ - - - \ No newline at end of file + + Edit + + \ No newline at end of file diff --git a/app/views/admin/assets/delete_files.js.erb b/app/views/admin/assets/delete_files.js.erb new file mode 100644 index 000000000..a4f57711a --- /dev/null +++ b/app/views/admin/assets/delete_files.js.erb @@ -0,0 +1,3 @@ + +$("#tbody_assets").html("<%= j render :partial => 'asset', :collection => @assets %>"); +$("#asset_pagination").html("<%= j paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>"); \ No newline at end of file diff --git a/app/views/admin/assets/index.html.erb b/app/views/admin/assets/index.html.erb index ff9e2fefb..070c640d1 100644 --- a/app/views/admin/assets/index.html.erb +++ b/app/views/admin/assets/index.html.erb @@ -1,30 +1,482 @@ -<%= render 'filter' %> - - - - - - - - - - - - - - <%= render :partial => 'asset', :collection => @assets %> - -
+ + +
+ Tag Management +
+ preview is here
+
+ + + + + + + + + + + + + <%= render :partial => 'asset', :collection => @assets %> + +
NameSizeDescriptionTagsAction
+
+
+ + +
+ <%= paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]}, :remote => true %> +
+
+
+
+
+ + +
+ + +
+ +
+
+
+ +
+
+
+ +
+
+ Drop files here +
+ +
+ +
+
+ +
+
+
+
+ <% content_for :page_specific_javascript do %> - <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> - <%= javascript_include_tag "inc/modal-preview" %> + <%= javascript_include_tag "file-upload/vendor/jquery.ui.widget.js" %> + <%= javascript_include_tag "file-upload/tmpl.min.js" %> + <%= javascript_include_tag "file-upload/load-image.min.js" %> + <%= javascript_include_tag "file-upload/canvas-to-blob.min.js" %> + <%= javascript_include_tag "file-upload/jquery.iframe-transport.js" %> + <%= javascript_include_tag "file-upload/jquery.fileupload.js" %> + <%= javascript_include_tag "file-upload/jquery.fileupload-fp.js" %> + <%= javascript_include_tag "file-upload/jquery.fileupload-ui.js" %> + <%= javascript_include_tag "file-upload/drop-zone.js" %> <% end %> + + + + \ No newline at end of file diff --git a/app/views/admin/assets/index.js.erb b/app/views/admin/assets/index.js.erb deleted file mode 100644 index e2e87d360..000000000 --- a/app/views/admin/assets/index.js.erb +++ /dev/null @@ -1,4 +0,0 @@ -$("#delete_all").attr("action", "<%= delete_admin_assets_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]) %>"); -$("#sort_headers").html("<%= j render 'sort_headers' %>"); -$("#tbody_assets").html("<%= j render :partial => 'asset', :collection => @assets %>"); -$("#asset_pagination").html("<%= j paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>"); \ No newline at end of file diff --git a/app/views/admin/module_tags/index.html.erb b/app/views/admin/module_tags/index.html.erb index cf8c645e7..683efe8ed 100644 --- a/app/views/admin/module_tags/index.html.erb +++ b/app/views/admin/module_tags/index.html.erb @@ -3,7 +3,6 @@ <% end %> -
<%= render 'index' %>
\ No newline at end of file diff --git a/app/views/layouts/assets.html.erb b/app/views/layouts/assets.html.erb new file mode 100644 index 000000000..810348abd --- /dev/null +++ b/app/views/layouts/assets.html.erb @@ -0,0 +1,22 @@ + + + + <%= @title || APP_CONFIG['orbit'] %> + <%#= render 'layouts/meta' %> + <%#= render 'layouts/google_font' %> + <%= stylesheet_link_tag "back_end" %> + <%= yield :page_specific_css %> + <%= render 'layouts/ie_html5_fix' %> + <%= javascript_include_tag "back_end" %> + <%= yield :page_specific_javascript %> + <%= csrf_meta_tag %> + + +
+
+ + <%= yield %> +
+ + diff --git a/config/routes.rb b/config/routes.rb index 7a0bbdbb0..2263b3c77 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,8 +27,9 @@ Orbit::Application.routes.draw do mount Resque::Server.new, :at => "/resque" resources :assets do collection do - get 'file_upload' + post 'file_upload' get 'delete' + post 'delete_files' end end resources :asset_categories diff --git a/vendor/built_in_modules/asset/init.rb b/vendor/built_in_modules/asset/init.rb index 04865a996..0c621c6a0 100644 --- a/vendor/built_in_modules/asset/init.rb +++ b/vendor/built_in_modules/asset/init.rb @@ -3,6 +3,7 @@ module Asset module_label 'module_name.asset' base_url File.expand_path File.dirname(__FILE__) + taggable # side_bar do # head_label_i18n 'module_name.asset',:icon_class=>"icons-landscape" # available_for [:admin,:guest,:manager,:sub_manager] diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/main.js b/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/main.js deleted file mode 100644 index 0310aa2c2..000000000 --- a/vendor/built_in_modules/gallery/app/assets/javascripts/file-upload/main.js +++ /dev/null @@ -1,13 +0,0 @@ -//https://github.com/blueimp/jQuery-File-Upload -$(function () { - 'use strict'; - // Initialize the jQuery File Upload widget: - $('#fileupload').fileupload({ - maxFileSize: 5000000, - acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, - dropZone: $('#dropzone'), - headers:{ - 'X-CSRF-Token': $('meta[name="csrf-token"]').attr("content") - } - }); -}); \ No newline at end of file diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/gallery.js b/vendor/built_in_modules/gallery/app/assets/javascripts/gallery.js index d1bd1e698..9ac0b842c 100644 --- a/vendor/built_in_modules/gallery/app/assets/javascripts/gallery.js +++ b/vendor/built_in_modules/gallery/app/assets/javascripts/gallery.js @@ -16,6 +16,18 @@ } }(window.jQuery); +$(function () { + 'use strict'; + // Initialize the jQuery File Upload widget: + $('#fileupload').fileupload({ + maxFileSize: 5000000, + acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, + dropZone: $('#dropzone'), + headers:{ + 'X-CSRF-Token': $('meta[name="csrf-token"]').attr("content") + } + }); +}); $(function() { var $container = $('.gallery'), diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/show.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/show.html.erb index 9d75b0d04..22c4955e1 100644 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/show.html.erb +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/show.html.erb @@ -165,7 +165,6 @@ <% content_for :page_specific_javascript do %> <%= javascript_include_tag "jquery.masonry.min.js" %> <%= javascript_include_tag "jquery.lite.image.resize.js" %> - <%= javascript_include_tag "gallery" %> <%= javascript_include_tag "lib/checkbox.card" %> <%= javascript_include_tag "file-upload/vendor/jquery.ui.widget.js" %> <%= javascript_include_tag "file-upload/tmpl.min.js" %> @@ -175,8 +174,8 @@ <%= javascript_include_tag "file-upload/jquery.fileupload.js" %> <%= javascript_include_tag "file-upload/jquery.fileupload-fp.js" %> <%= javascript_include_tag "file-upload/jquery.fileupload-ui.js" %> - <%= javascript_include_tag "file-upload/main.js" %> <%= javascript_include_tag "file-upload/drop-zone.js" %> + <%= javascript_include_tag "gallery" %> <% end %>