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 %>