diff --git a/.gitignore b/.gitignore index 59dd548..0d8da22 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ # Ignore all logfiles, tempfiles, public assets, /log/*.log /tmp +public/system/* public/assets/* public/apidocs/* diff --git a/Gemfile b/Gemfile index 41541aa..9947167 100644 --- a/Gemfile +++ b/Gemfile @@ -80,6 +80,10 @@ gem 'turbolinks' #implementation of forms gem 'activeadmin', github: 'activeadmin' +# +# LOGO UPLOAD +# +gem 'dragonfly' # # EXPORTING PLANS diff --git a/Gemfile.lock b/Gemfile.lock index b4c911a..afb8242 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -116,6 +116,10 @@ devise_invitable (1.7.0) actionmailer (>= 4.0.0) devise (>= 4.0.0) + dragonfly (1.0.12) + addressable (~> 2.3) + multi_json (~> 1.0) + rack (>= 1.3.0) email_validator (1.6.0) activemodel erubis (2.7.0) @@ -343,6 +347,7 @@ contact_us (>= 1.2.0) devise devise_invitable + dragonfly email_validator exception_notification feedjira diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 45121e5..7caca1c 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -25,7 +25,7 @@ # POST /organisations.json def create @organisation = Organisation.new(params[:organisation]) - + @organisation.logo = param[:organisation][:logo] respond_to do |format| if @organisation.save format.html { redirect_to @organisation, notice: I18n.t("admin.org_created_message") } @@ -71,14 +71,17 @@ if user_signed_in? && current_user.is_org_admin? then @organisation = Organisation.find(params[:id]) @organisation.banner_text = params["org_banner_text"] - + @organisation.logo = params[:organisation][:logo] if params[:organisation][:logo] + assign_params = params[:organisation].dup + assign_params.delete(:logo) respond_to do |format| - if @organisation.update_attributes(params[:organisation]) + if @organisation.update_attributes(assign_params) format.html { redirect_to admin_show_organisation_path(params[:id]), notice: I18n.t("admin.org_updated_message") } format.json { head :no_content } else - format.html { render action: "edit" } + flash[:alert] = I18n.t("org_admin.org_logo_failed_message") + format.html { render action: "admin_edit" } format.json { render json: @organisation.errors, status: :unprocessable_entity } end end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index a1eef16..71515c9 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -1,4 +1,5 @@ class Organisation < ActiveRecord::Base + extend Dragonfly::Model::Validations #associations between tables belongs_to :organisation_type has_many :guidance_groups @@ -19,11 +20,18 @@ accepts_nested_attributes_for :dmptemplates accepts_nested_attributes_for :token_permission_types - attr_accessible :abbreviation, :banner_text, :description, :domain, + attr_accessible :abbreviation, :banner_text, :logo, :remove_logo, :description, :domain, :logo_file_name, :name, :stylesheet_file_id, :target_url, :organisation_type_id, :wayfless_entity, :parent_id, :sort_name, :token_permission_type_ids + ## + # allow validations for logo upload + dragonfly_accessor :logo + validates_property :height, of: :logo, in: (0..100) + validates_property :format, of: :logo, in: ['jpeg', 'png', 'gif','jpg','bmp'] + validates_size_of :logo, maximum: 500.kilobytes + def to_s name end diff --git a/app/views/layouts/_dmponline_header.html.erb b/app/views/layouts/_dmponline_header.html.erb index 44a58af..b80c58b 100644 --- a/app/views/layouts/_dmponline_header.html.erb +++ b/app/views/layouts/_dmponline_header.html.erb @@ -3,7 +3,11 @@
| <%= t('org_admin.org_logo') %> | +<%= image_tag @organisation.logo.url %> | +||||
| + | <%= f.check_box :remove_logo %> <%= t('org_admin.remove_logo') %> | +||||
| <%= t('org_admin.new_org_logo') %> | +<%= f.file_field :logo %> | +||||
| <%= t('org_admin.org_desc') %> | <%= f.text_area :description, {
diff --git a/app/views/organisations/admin_show.html.erb b/app/views/organisations/admin_show.html.erb
index 501fce5..e502a8a 100644
--- a/app/views/organisations/admin_show.html.erb
+++ b/app/views/organisations/admin_show.html.erb
@@ -13,13 +13,6 @@
-
- <% if @organisation.logo_file_name.present? then%>
-
- <%= image_tag("#{@organisation.logo_file_name}", class: "org_logo_admin_area" )%>
-
- <%end%>
-
|