Clean up templates, fix main image upload
This commit is contained in:
parent
a5bc158628
commit
546b37f098
5 changed files with 37 additions and 70 deletions
|
@ -164,11 +164,6 @@ class Campaign < ActiveRecord::Base
|
|||
(self.end_datetime.to_date - Date.today).to_i
|
||||
end
|
||||
|
||||
def self.create_from_template(template_id)
|
||||
# building params handled by another object
|
||||
# not sure this method is needed eventually
|
||||
end
|
||||
|
||||
def customizable_attributes_list
|
||||
campaign_template.customizable_attributes_list if campaign_template
|
||||
end
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
class CampaignTemplate < ActiveRecord::Base
|
||||
# these are very arbitrary names – some are attrs of campaign, some are not
|
||||
# might be a good idea to get the default list from settings
|
||||
CUSTOMIZABLE_ATTR = %i(goal_amount)
|
||||
|
||||
attr_accessible \
|
||||
|
@ -20,59 +18,13 @@ class CampaignTemplate < ActiveRecord::Base
|
|||
:goal_customizable,
|
||||
:nonprofit_id
|
||||
|
||||
attr_accessor :goal_amount_dollars
|
||||
attr_accessor :goal_customizable
|
||||
attr_accessor :end_datetime
|
||||
attr_accessor :hide_activity_feed
|
||||
attr_accessor :deleted
|
||||
attr_accessor :hide_title
|
||||
attr_accessor :slug
|
||||
attr_accessor :custom_banner_url
|
||||
attr_accessor :published
|
||||
attr_accessor :show_total_raised
|
||||
attr_accessor :show_total_count
|
||||
attr_accessor :hide_goal
|
||||
attr_accessor :hide_thermometer
|
||||
attr_accessor :hide_custom_amounts
|
||||
attr_accessor :receipt_message
|
||||
attr_accessor :goal_amount_dollars
|
||||
|
||||
has_many :campaigns
|
||||
belongs_to :nonprofit
|
||||
|
||||
def customizable_attribute?(attribute_name)
|
||||
CUSTOMIZABLE_ATTR.include? attribute_name.to_sym
|
||||
end
|
||||
|
||||
def recurring_fund?
|
||||
end
|
||||
|
||||
def main_image_url(url)
|
||||
end
|
||||
|
||||
def slug
|
||||
Format::Url.convert_to_slug(template_name)
|
||||
end
|
||||
|
||||
def customizable_attributes_list
|
||||
CUSTOMIZABLE_ATTR
|
||||
end
|
||||
|
||||
def name
|
||||
if self[:name]
|
||||
self[:name]
|
||||
else
|
||||
'no name'
|
||||
end
|
||||
end
|
||||
|
||||
def url
|
||||
"#{self.nonprofit.url}/campaigns/#{self.slug}"
|
||||
end
|
||||
|
||||
def days_left
|
||||
return 0 if self.end_datetime.nil?
|
||||
(self.end_datetime.to_date - Date.today).to_i
|
||||
end
|
||||
mount_uploader :main_image, CampaignTemplateMainImageUploader
|
||||
|
||||
before_validation do
|
||||
if self.goal_amount_dollars.present?
|
||||
|
@ -81,19 +33,12 @@ class CampaignTemplate < ActiveRecord::Base
|
|||
self
|
||||
end
|
||||
|
||||
after_create do
|
||||
# user = self.profile.user
|
||||
# Role.create(name: :campaign_editor, user_id: user.id, host: self)
|
||||
def customizable_attribute?(attribute_name)
|
||||
CUSTOMIZABLE_ATTR.include? attribute_name.to_sym
|
||||
end
|
||||
|
||||
before_validation(on: :create) do
|
||||
self.set_defaults
|
||||
self
|
||||
end
|
||||
|
||||
def set_defaults
|
||||
# self.total_supporters = 1
|
||||
# self.published = false if self.published.nil?
|
||||
def customizable_attributes_list
|
||||
CUSTOMIZABLE_ATTR
|
||||
end
|
||||
|
||||
def create_campaign_params
|
||||
|
|
29
app/uploaders/campaign_template_main_image_uploader.rb
Normal file
29
app/uploaders/campaign_template_main_image_uploader.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
||||
|
||||
class CampaignTemplateMainImageUploader < CarrierWave::Uploader::Base
|
||||
include CarrierWave::MiniMagick
|
||||
|
||||
def store_dir
|
||||
"uploads/campaign_templates/#{mounted_as}/#{model.id}"
|
||||
end
|
||||
|
||||
def default_url
|
||||
return Image::DefaultProfileUrl
|
||||
end
|
||||
|
||||
version :normal do
|
||||
process :resize_to_fill => [524, 360]
|
||||
end
|
||||
|
||||
version :thumb do
|
||||
process :resize_to_fill => [180, 150]
|
||||
end
|
||||
|
||||
def extension_white_list
|
||||
%w(jpg jpeg png)
|
||||
end
|
||||
|
||||
def cache_dir
|
||||
"#{Rails.root}/tmp/uploads"
|
||||
end
|
||||
end
|
|
@ -57,8 +57,6 @@
|
|||
<div class='prepend--dollar'>
|
||||
<input class='input--100 u-marginBottom--5' value='1000' type='number' name='campaign_template[goal_amount_dollars]' min='1'>
|
||||
</div>
|
||||
<input id='goal_customizable-checkbox' type='checkbox' name='campaign_template[goal_customizable]'>
|
||||
<label class='u-marginBottom--10' for='goal_customizable-checkbox'>Allow peer-to-peer campaigners to set their own goal</label>
|
||||
</fieldset>
|
||||
|
||||
<hr>
|
||||
|
@ -95,7 +93,7 @@
|
|||
</div>
|
||||
<div class='image-upload u-margin--0 u-floatR' if-branded='border-color, light'>
|
||||
<span><i class='fa fa-image'></i> Upload</span>
|
||||
<input type='file' name='campaign[main_image]' parsley-trigger='change'>
|
||||
<input type='file' name='campaign_template[main_image]' parsley-trigger='change'>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<% @templates.each do |template|%>
|
||||
<tr>
|
||||
<td class='u-padding--0 u-width--200 u-hideIf--400'>
|
||||
#<img src='<%= %>'>
|
||||
<img src='<%= template.main_image_url %>'>
|
||||
</td>
|
||||
<td class='u-padding--10'>
|
||||
<h6 class='u-marginTop--0 u-marginBottom--5'>
|
||||
|
|
Loading…
Reference in a new issue