remove last of campaign template features
This commit is contained in:
parent
a838f45cbe
commit
87dc491ef4
12 changed files with 7 additions and 378 deletions
|
@ -66,23 +66,6 @@ class CampaignsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def create_from_template
|
||||
Qx.transaction do
|
||||
campaign_template = current_nonprofit.campaign_templates.find(params[:campaign_template_id])
|
||||
|
||||
save_params = campaign_template.create_campaign_params
|
||||
|
||||
save_params['slug'] = SlugCopyNamingAlgorithm.new(Campaign, current_nonprofit.id).create_copy_name(Format::Url.convert_to_slug(save_params['name']))
|
||||
|
||||
save_params['name'] = NameCopyNamingAlgorithm.new(Campaign, current_nonprofit.id).create_copy_name(save_params['name'])
|
||||
save_params['profile_id'] = params[:profile_id]
|
||||
campaign = current_nonprofit.campaigns.create save_params
|
||||
campaign.update_attribute(:main_image, campaign_template.main_image) unless !campaign_template.main_image rescue AWS::S3::Errors::NoSuchKey
|
||||
|
||||
json_saved campaign, 'Campaign created! Well done.'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
Time.use_zone(current_nonprofit.timezone || 'UTC') do
|
||||
params[:campaign][:end_datetime] = Chronic.parse(params[:campaign][:end_datetime]) if params[:campaign][:end_datetime].present?
|
||||
|
@ -91,7 +74,6 @@ class CampaignsController < ApplicationController
|
|||
json_saved current_campaign, 'Successfully updated!'
|
||||
end
|
||||
|
||||
|
||||
# post 'nonprofits/:np_id/campaigns/:campaign_id/duplicate'
|
||||
def duplicate
|
||||
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
||||
module Nonprofits
|
||||
class CampaignTemplatesController < ApplicationController
|
||||
include Controllers::NonprofitHelper
|
||||
|
||||
before_filter :authenticate_nonprofit_admin!, only: :create
|
||||
before_filter :authenticate_nonprofit_user!, only: [:index, :show]
|
||||
|
||||
def index
|
||||
@nonprofit = current_nonprofit
|
||||
@templates = @nonprofit.campaign_templates
|
||||
end
|
||||
|
||||
def create
|
||||
template = CampaignTemplate.create(params[:campaign_template])
|
||||
|
||||
json_saved template
|
||||
end
|
||||
|
||||
def destroy
|
||||
campaign = CampaignTemplate.find(params[:id])
|
||||
campaign.destroy
|
||||
|
||||
render json: {}, status: :no_content
|
||||
end
|
||||
end
|
||||
end
|
|
@ -66,6 +66,7 @@ class Campaign < ActiveRecord::Base
|
|||
has_many :activities, as: :host, dependent: :destroy
|
||||
belongs_to :profile
|
||||
belongs_to :nonprofit
|
||||
belongs_to :campaign_template
|
||||
|
||||
belongs_to :parent_campaign, class_name: 'Campaign'
|
||||
has_many :children_campaigns, class_name: 'Campaign', foreign_key: 'parent_campaign_id'
|
||||
|
@ -179,7 +180,11 @@ class Campaign < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def child_campaign?
|
||||
parent_campaign.present?
|
||||
if parent_campaign.present?
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def parent_campaign?
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
# 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
|
|
@ -25,10 +25,6 @@ has_mosaic: true %>
|
|||
<a class='button orange u-marginY--10' open-modal='newCampaign' data-when-confirmed><i class='fa fa-plus'></i> New Campaign</a>
|
||||
<% end %>
|
||||
|
||||
<a class='button green u-marginY--10' href='<%= nonprofits_campaign_templates_path(@nonprofit.id) %>'>
|
||||
Campaign templates
|
||||
</a>
|
||||
|
||||
<% if @active_campaigns.empty? %>
|
||||
<p class='fundraiser--active u-padding--15 u-marginTop--15'>No active campaigns</p>
|
||||
<% else %>
|
||||
|
|
|
@ -69,7 +69,6 @@
|
|||
<p class='strong u-marginBottom--15'>My campaign</p>
|
||||
<div class='u-paddingLeft--20 u-maxWidth--500'>
|
||||
<h4><%= @parent_campaign.name %></h4>
|
||||
<p>See our other <%= link_to 'active campaigns', @parent_campaign.nonprofit.url || @nonprofit.url %>.</p>
|
||||
</div>
|
||||
</li>
|
||||
<% else %>
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
<!-- partial campaigns/new-modal -->
|
||||
<!-- include 'campaigns/new/index' -->
|
||||
|
||||
<div class='modal' id='newCampaignTemplate'>
|
||||
|
||||
<%= render 'common/modal_header', title: 'New Campaign Template' %>
|
||||
|
||||
<!-- <div class='wizard-steps'> -->
|
||||
<div class='wizard-steps' style='display:none;'>
|
||||
<!--= wizard.init 'new_campaign_template_wiz' -->
|
||||
|
||||
<%= render 'components/wizard/step_index', wizard_name: 'new_campaign_template_wiz' %>
|
||||
|
||||
<div class='modal-body' style='display: table;'>
|
||||
|
||||
<div class='wizard-step name-step'>
|
||||
<!--= wizard.set_step 'new_campaign_template_wiz' 'Name' -->
|
||||
|
||||
<form parsley-validate>
|
||||
<!--= on 'submit' (def 'new_campaign_template' form_object) (wizard.advance 'new_campaign_template_wiz') -->
|
||||
<input type='hidden' name='campaign_template[nonprofit_id]' value='<%= @nonprofit.id %>'>
|
||||
|
||||
<fieldset>
|
||||
<label>Template Name</label>
|
||||
<input type='text' name='campaign_template[template_name]' required parsley-trigger='change'>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label>Campaign Name</label>
|
||||
<input type='text' name='campaign_template[name]' parsley-trigger='change'>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label>Short Tagline</label>
|
||||
<input type='text' name='campaign_template[tagline]' parsley-trigger='change'>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label>Short Description <small>(used for sharing on social media)</small></label>
|
||||
<textarea name='campaign_template[summary]' parsley-maxlength='300' parsley-trigger='change'></textarea>
|
||||
</fieldset>
|
||||
|
||||
<%= render 'components/forms/submit_button', button_text: 'Next', scope: 'new_campaign_template_wiz', branded: true %>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class='wizard-step amount-step'>
|
||||
<!--= wizard.set_step 'new_campaign_template_wiz' 'Goals' -->
|
||||
|
||||
<form parsley-validate>
|
||||
<!--= on 'submit' (def 'new_campaign_template' form_object) (wizard.advance 'new_campaign_template_wiz') -->
|
||||
|
||||
|
||||
<div class='u-margin--auto'>
|
||||
<fieldset class='group u-marginBottom--0'>
|
||||
<label class='u-paddingTop--5'>Goal Amount</label>
|
||||
<div class='prepend--dollar'>
|
||||
<input class='input--100 u-marginBottom--5' value='1000' type='number' name='campaign_template[goal_amount_dollars]' min='1'>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<hr>
|
||||
|
||||
<fieldset class='group'>
|
||||
<label class='u-paddingTop--5'>End Date & Time</label>
|
||||
<div pikaday-timepicker='MM/DD/YYYY hh:mm a'>
|
||||
<input class='u-width--200 u-bold u-inlineBlock' type='text' name='campaign_template[end_datetime]' parsley-trigger='change' placeholder='MM/DD/YYYY HH:MM'>
|
||||
<a class='button edit u-inlineBlock'>Set</a>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<%= render 'components/forms/submit_button', button_text: 'Next', scope: 'new_campaign_template_wiz', branded: true %>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class='wizard-step media-step'>
|
||||
<!--= wizard.set_step 'new_campaign_template_wiz' 'Media' -->
|
||||
|
||||
<form parsley-validate>
|
||||
<!--= on 'submit' create_campaign_template -->
|
||||
|
||||
<fieldset>
|
||||
|
||||
<p class='u-color--red'>
|
||||
<!--= show_if (length image_upload.error) -->
|
||||
<small><!--= put image_upload.error --></small>
|
||||
</p>
|
||||
|
||||
<div class='col-left-8'>
|
||||
<label>Image <small>(recommended width: 500px)</small></label>
|
||||
<p>This image appears below the campaign's header as well as on the campaign's preview card. You'll have a chance to upload an additional header image once you've created your campaign.</p>
|
||||
</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_template[main_image]' parsley-trigger='change'>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<hr>
|
||||
<label>Video</label>
|
||||
<p>If you have a video, it can greatly boost your success. Copy and paste the URL from Vimeo or Youtube.</p>
|
||||
<input type='text' class='u-marginBottom--10' name='campaign_template[video_url]' placeholder='Youtube or Vimeo URL' />
|
||||
</fieldset>
|
||||
|
||||
<%= render 'components/forms/submit_button', button_text: 'Preview Template!', scope: 'new_campaign_template_wiz', branded: true %>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- end partial campaigns/new-modal -->
|
|
@ -1,72 +0,0 @@
|
|||
<%= content_for :stylesheets do %>
|
||||
<%= stylesheet_link_tag 'campaigns/index/page' %>
|
||||
<%= stylesheet_link_tag 'campaign_templates' %>
|
||||
<% end %>
|
||||
|
||||
<%= content_for :javascripts do %>
|
||||
<script>
|
||||
app.current_nonprofit_user = "<%= current_nonprofit_user? %>"
|
||||
app.nonprofit_id = <%= @nonprofit.id %>
|
||||
app.profile_id = '<%= raw current_user.profile.id %>'
|
||||
</script>
|
||||
<%= IncludeAsset.js '/client/js/campaign_templates/index/page.js' %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<%= render 'components/header',
|
||||
icon_class: 'icon-thermometer-medium',
|
||||
title: 'Campaign Templates',
|
||||
profile: @nonprofit,
|
||||
has_mosaic: true
|
||||
%>
|
||||
|
||||
<main class='container u-padding--15'>
|
||||
<% if current_user %>
|
||||
<a class='button orange u-marginY--10' open-modal='newCampaignTemplate' data-when-confirmed><i class='fa fa-plus'></i> New Template</a>
|
||||
<% end %>
|
||||
|
||||
<% if @templates.empty? %>
|
||||
<p class='fundraiser--active u-padding--15 u-marginTop--15'>No templates yet</p>
|
||||
<% else %>
|
||||
<section class='fundraiser--unpublished u-marginTop--15 u-marginBottom--30'>
|
||||
|
||||
<!-- TODO: extract to partial -->
|
||||
<table class='table--striped u-marginBottom--0'>
|
||||
<% @templates.each do |template|%>
|
||||
<tr>
|
||||
<td class='u-padding--0 u-width--200 u-hideIf--400'>
|
||||
<img src='<%= template.main_image_url %>'>
|
||||
</td>
|
||||
<td class='u-padding--10'>
|
||||
<h6 class='u-marginTop--0 u-marginBottom--5'>
|
||||
<%= template.template_name %>
|
||||
</h6>
|
||||
<p class='u-marginBottom--15'>
|
||||
<small>Campaign title: <%= template.name %></small>
|
||||
</p>
|
||||
|
||||
<p class='u-marginBottom--15'>
|
||||
<small>Campaign summary:<%= template.summary ? strip_tags(template.summary) : strip_tags(template.tagline) %></small>
|
||||
</p>
|
||||
|
||||
<p class='u-marginBottom--15'>
|
||||
<small>Customizable attributes: <%= template.customizable_attributes_list %></small>
|
||||
</p>
|
||||
|
||||
<a class="button">Create campaign from template</a>
|
||||
<!--= on 'click' (create_campaign_from_template '<%= raw({'campaign_template_id' => template.id}.to_json) %>') -->
|
||||
|
||||
<a class="button red">Delete template</a>
|
||||
<!--= on 'click' (delete_template <%= template.id %>) -->
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
</section>
|
||||
<% end %>
|
||||
</main>
|
||||
|
||||
<% if current_user %>
|
||||
<%= render 'nonprofits/campaign_templates/new_modal' %>
|
||||
<% end %>
|
|
@ -1,2 +0,0 @@
|
|||
if(app.user)
|
||||
require('../new/wizard')
|
|
@ -1,107 +0,0 @@
|
|||
require('../../common/pikaday-timepicker')
|
||||
require('../../components/wizard')
|
||||
require('../../common/image_uploader')
|
||||
var confirmation = require('../../common/confirmation')
|
||||
var format_err = require('../../common/format_response_error')
|
||||
|
||||
appl.def('advance_campaign_template_name_step', function(form_obj) {
|
||||
appl.def('new_campaign_template', form_obj)
|
||||
appl.wizard.advance('new_campaign_template_wiz')
|
||||
})
|
||||
|
||||
// Post a new campaign template
|
||||
appl.def('create_campaign_template', function(el) {
|
||||
var form_data = utils.toFormData(appl.prev_elem(el))
|
||||
form_data = utils.mergeFormData(form_data, appl.new_campaign_template)
|
||||
appl.def('new_campaign_template_wiz.loading', true)
|
||||
|
||||
post_campaign_template(form_data)
|
||||
.then(function(req) {
|
||||
appl.notify("Campaign template created!")
|
||||
var template_id = JSON.parse(req.response).id
|
||||
appl.redirect('/nonprofits/' + app.nonprofit_id + '/campaign_templates')
|
||||
})
|
||||
.catch(function(req) {
|
||||
appl.def('new_campaign_template_wiz.loading', false)
|
||||
appl.def('new_campaign_template_wiz.error', req.responseText)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
var Pikaday = require('pikaday')
|
||||
var moment = require('moment')
|
||||
new Pikaday({
|
||||
field: document.querySelector('.js-date-picker'),
|
||||
format: 'M/D/YYYY',
|
||||
minDate: moment().toDate()
|
||||
})
|
||||
|
||||
// Using the bare-bones XMLHttpRequest API so we can post form data and upload the image
|
||||
function post_campaign_template(form_data) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var req = new XMLHttpRequest()
|
||||
req.open("POST", '/nonprofits/' + app.nonprofit_id + '/campaign_templates')
|
||||
req.setRequestHeader('X-CSRF-Token', window._csrf)
|
||||
req.send(form_data)
|
||||
req.onload = function(ev) {
|
||||
if(req.status === 200) resolve(req)
|
||||
else reject(req)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
appl.def('delete_template', function(id) {
|
||||
var result = confirmation('Are you sure?')
|
||||
result.confirmed = function() {
|
||||
appl.def('loading', true)
|
||||
var url = '/nonprofits/' + app.nonprofit_id + '/campaign_templates/' + id
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
var req = new XMLHttpRequest()
|
||||
req.open("DELETE", url)
|
||||
req.setRequestHeader('X-CSRF-Token', window._csrf)
|
||||
req.send({ campaign_template: {id: id} })
|
||||
req.onload = function(ev) {
|
||||
if(req.status === 204) resolve(req)
|
||||
else reject(req)
|
||||
}
|
||||
}).then(function() {
|
||||
appl.def('loading', false)
|
||||
appl.notify('Successfully deleted template.')
|
||||
appl.redirect('/nonprofits/' + app.nonprofit_id + '/campaign_templates')
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
appl.def('create_campaign_from_template', function(campaign_params) {
|
||||
appl.def('loading', true)
|
||||
|
||||
var url = '/nonprofits/' + app.nonprofit_id + '/campaigns/create_from_template'
|
||||
var params = new Object
|
||||
params = JSON.parse(campaign_params)
|
||||
params.profile_id = app.profile_id
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
var req = new XMLHttpRequest()
|
||||
req.open("POST", url)
|
||||
req.setRequestHeader('X-CSRF-Token', window._csrf)
|
||||
req.setRequestHeader('Content-Type', 'application/json')
|
||||
req.send(JSON.stringify(params))
|
||||
req.onload = function(ev) {
|
||||
if(req.status === 200) resolve(req)
|
||||
else reject(req)
|
||||
}
|
||||
}).then(function(req) {
|
||||
appl.def('loading', false)
|
||||
appl.notify('Redirecting you to your campaign…')
|
||||
var campaign_id = JSON.parse(req.response).id
|
||||
appl.redirect('/nonprofits/' + app.nonprofit_id + '/campaigns/' + campaign_id)
|
||||
})
|
||||
.catch(function(req) {
|
||||
appl.def('loading', false)
|
||||
appl.notify(req.responseText)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -110,8 +110,6 @@ Commitchange::Application.routes.draw do
|
|||
post(:send_code)
|
||||
end
|
||||
|
||||
resources(:campaign_templates, {only: [:index, :create, :show, :destroy]})
|
||||
|
||||
post 'tracking', controller: 'trackings', action: 'create'
|
||||
end
|
||||
|
||||
|
|
|
@ -115,8 +115,7 @@ describe InsertDuplicate do
|
|||
{
|
||||
id: result.id,
|
||||
end_datetime: nil,
|
||||
banner_image: nil,
|
||||
campaign_template_id: nil
|
||||
banner_image: nil
|
||||
}).with_indifferent_access)
|
||||
validate_cgo(result)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue