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
|
(self.end_datetime.to_date - Date.today).to_i
|
||||||
end
|
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
|
def customizable_attributes_list
|
||||||
campaign_template.customizable_attributes_list if campaign_template
|
campaign_template.customizable_attributes_list if campaign_template
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
class CampaignTemplate < ActiveRecord::Base
|
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)
|
CUSTOMIZABLE_ATTR = %i(goal_amount)
|
||||||
|
|
||||||
attr_accessible \
|
attr_accessible \
|
||||||
|
@ -20,59 +18,13 @@ class CampaignTemplate < ActiveRecord::Base
|
||||||
:goal_customizable,
|
:goal_customizable,
|
||||||
:nonprofit_id
|
:nonprofit_id
|
||||||
|
|
||||||
attr_accessor :goal_amount_dollars
|
|
||||||
attr_accessor :goal_customizable
|
|
||||||
attr_accessor :end_datetime
|
attr_accessor :end_datetime
|
||||||
attr_accessor :hide_activity_feed
|
attr_accessor :goal_amount_dollars
|
||||||
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
|
|
||||||
|
|
||||||
has_many :campaigns
|
has_many :campaigns
|
||||||
belongs_to :nonprofit
|
belongs_to :nonprofit
|
||||||
|
|
||||||
def customizable_attribute?(attribute_name)
|
mount_uploader :main_image, CampaignTemplateMainImageUploader
|
||||||
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
|
|
||||||
|
|
||||||
before_validation do
|
before_validation do
|
||||||
if self.goal_amount_dollars.present?
|
if self.goal_amount_dollars.present?
|
||||||
|
@ -81,19 +33,12 @@ class CampaignTemplate < ActiveRecord::Base
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
after_create do
|
def customizable_attribute?(attribute_name)
|
||||||
# user = self.profile.user
|
CUSTOMIZABLE_ATTR.include? attribute_name.to_sym
|
||||||
# Role.create(name: :campaign_editor, user_id: user.id, host: self)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
before_validation(on: :create) do
|
def customizable_attributes_list
|
||||||
self.set_defaults
|
CUSTOMIZABLE_ATTR
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_defaults
|
|
||||||
# self.total_supporters = 1
|
|
||||||
# self.published = false if self.published.nil?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_campaign_params
|
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'>
|
<div class='prepend--dollar'>
|
||||||
<input class='input--100 u-marginBottom--5' value='1000' type='number' name='campaign_template[goal_amount_dollars]' min='1'>
|
<input class='input--100 u-marginBottom--5' value='1000' type='number' name='campaign_template[goal_amount_dollars]' min='1'>
|
||||||
</div>
|
</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>
|
</fieldset>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -95,7 +93,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class='image-upload u-margin--0 u-floatR' if-branded='border-color, light'>
|
<div class='image-upload u-margin--0 u-floatR' if-branded='border-color, light'>
|
||||||
<span><i class='fa fa-image'></i> Upload</span>
|
<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>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
<% @templates.each do |template|%>
|
<% @templates.each do |template|%>
|
||||||
<tr>
|
<tr>
|
||||||
<td class='u-padding--0 u-width--200 u-hideIf--400'>
|
<td class='u-padding--0 u-width--200 u-hideIf--400'>
|
||||||
#<img src='<%= %>'>
|
<img src='<%= template.main_image_url %>'>
|
||||||
</td>
|
</td>
|
||||||
<td class='u-padding--10'>
|
<td class='u-padding--10'>
|
||||||
<h6 class='u-marginTop--0 u-marginBottom--5'>
|
<h6 class='u-marginTop--0 u-marginBottom--5'>
|
||||||
|
|
Loading…
Reference in a new issue