diff --git a/app/controllers/admin/admin_modules_controller.rb b/app/controllers/admin/admin_modules_controller.rb index 8f3e014..50ef0e3 100644 --- a/app/controllers/admin/admin_modules_controller.rb +++ b/app/controllers/admin/admin_modules_controller.rb @@ -13,6 +13,12 @@ class Admin::AdminModulesController < OrbitAdminController end end + def uploadfiles + @rm = RegisteredModule.find(params[:module_id]) + @categories = @module_app.categories.enabled + @tags = @module_app.tags + end + def approve_modules @rm = RegisteredModule.find(params[:module_id]) @categories = @module_app.categories.enabled @@ -52,9 +58,19 @@ class Admin::AdminModulesController < OrbitAdminController def update rm = RegisteredModule.find(params[:id]) - rm.update_attributes(registered_module_params) + p = registered_module_params + p[:module_show_files] = rm.module_show_files + p[:module_show_files] + rm.update_attributes(p) rm.save - render :json => {"success" => true}.to_json + if !params[:images_to_destroy].blank? + images = ModuleShowFile.where(:id.in => params[:images_to_destroy]) + images.destroy_all + end + if request.xhr? + render :json => {"success" => true}.to_json + else + redirect_to admin_admin_modules_path + end end def install_module @@ -104,8 +120,17 @@ class Admin::AdminModulesController < OrbitAdminController render :json=>{"success" => true}.to_json end + def upload_module_image + file = ModuleShowFile.create(show_file_params) + render :json => {"success" => true,"id" => file.id.to_s}.to_json + end - private + + private + + def show_file_params + params.require(:module_show_file).permit! + end def site_list_without_module(rm) registered_sites = [] @@ -143,7 +168,16 @@ class Admin::AdminModulesController < OrbitAdminController def registered_module_params - params.require(:registered_module).permit! + p = params.require(:registered_module).permit! + if p[:module_show_files].present? + images = [] + p[:module_show_files].each do |id| + image = ModuleShowFile.find(id) rescue nil + images << image if !image.nil? + end + p[:module_show_files] = images + end + p end def table_fields diff --git a/app/models/module_show_file.rb b/app/models/module_show_file.rb new file mode 100644 index 0000000..69f5681 --- /dev/null +++ b/app/models/module_show_file.rb @@ -0,0 +1,8 @@ +class ModuleShowFile + include Mongoid::Document + include Mongoid::Timestamps + + mount_uploader :image, ImageUploader + + belongs_to :registered_module +end \ No newline at end of file diff --git a/app/models/registered_module.rb b/app/models/registered_module.rb index 30ce16a..1c48196 100644 --- a/app/models/registered_module.rb +++ b/app/models/registered_module.rb @@ -8,6 +8,7 @@ class RegisteredModule field :module_key field :git_path field :name, as: :slug_title, localize: true + field :description, localize: true field :create_user_id, type: BSON::ObjectId field :update_user_id, type: BSON::ObjectId field :approved, type: Boolean, :default => false @@ -17,6 +18,7 @@ class RegisteredModule mount_uploader :template, TemplateUploader + has_many :module_show_files, :dependent => :destroy def reject self.completed = false diff --git a/app/views/admin/admin_modules/_index.html.erb b/app/views/admin/admin_modules/_index.html.erb index c29f186..0486c75 100644 --- a/app/views/admin/admin_modules/_index.html.erb +++ b/app/views/admin/admin_modules/_index.html.erb @@ -30,7 +30,7 @@ Uninstall Revoke Access Grant Access - Edit + Edit <% else %> diff --git a/app/views/admin/admin_modules/uploadfiles.html.erb b/app/views/admin/admin_modules/uploadfiles.html.erb new file mode 100644 index 0000000..ce6eb31 --- /dev/null +++ b/app/views/admin/admin_modules/uploadfiles.html.erb @@ -0,0 +1,257 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/dropzone" %> + <%= stylesheet_link_tag "//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" %> + <%= stylesheet_link_tag "//cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/dropzone" %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> + +<%= form_for @rm, url: admin_admin_module_path(@rm.id), html: {class: "form-horizontal main-forms previewable", id: "module_edit_form"} do |f| %> +
+
+ + Uploading... +
+ +
+ + + + + + +
+ + +
+ + +
+ +
+ <%= select_category(f, @module_app) %> +
+
+ + +
+ +
+ <%= f.text_field :git_path, :class => "input-xxlarge" %> +
+
+ +
+ + +
+
+ + <%= select_tags(f, @module_app) %> +
+
+ +
+
+ +
+
+ <% @rm.module_show_files.each do |image| %> +
+
+ +
+ +
+
+ +
+ <% end %> +
+
+
+
+ +
+
+ +
+
+
+
+ + + + + +
+ + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
"> + + +
+ +
+
+ <%= f.fields_for :description_translations do |f| %> + <%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@rm.description_translations[locale] rescue nil) %> + <% end %> +
+
+
+ +
+ + <% end %> + +
+
+
+ <%= f.submit t('submit'), class: 'btn btn-primary', :id => "module-form-btn" %> +
+
+<% end %> + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 6b092ef..3f879ba 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,4 +20,5 @@ en: email_not_confirmed: Email not confirmed. site_permission_revoked: Site permission revoked. site_active: Site Active + git_path: Git Path diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 81023f5..2bc8eb3 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -17,7 +17,7 @@ zh_tw: admin_area: Admin Area new_module: Register Module new_widget: Register Widget - + git_path: Git Path email_not_confirmed: Email not confirmed. site_permission_revoked: Site permission revoked. site_active: Site Active diff --git a/config/routes.rb b/config/routes.rb index e10bf60..027ee9a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,8 @@ Rails.application.routes.draw do post "/admin_modules/uninstall" => "admin_modules#uninstall_module" post "/admin_modules/revoke" => "admin_modules#revoke_module" post "/admin_modules/grant" => "admin_modules#grant_module" + get "/admin_modules/uploadfiles" => "admin_modules#uploadfiles" + post "/admin_modules/upload_module_image" => "admin_modules#upload_module_image" get "/register_desktop_widgets/approve_widget" => "register_desktop_widgets#approve_widget" resources :register_modules resources :admin_modules