2018-03-25 18:03:08 +00:00
// License: LGPL-3.0-or-later
2018-03-25 17:30:42 +00:00
require ( '../../common/pikaday-timepicker' )
require ( '../../common/restful_resource' )
const request = require ( '../../common/client' )
const formatErr = require ( '../../common/format_response_error' )
require ( '../../common/image_uploader' )
require ( './tour' )
const dupeIt = require ( '../../components/duplicate_fundraiser' )
dupeIt ( ` /nonprofits/ ${ app . nonprofit _id } /campaigns ` , app . campaign _id )
var url = '/nonprofits/' + app . nonprofit _id + '/campaigns/' + app . campaign _id
var create _supporter = require ( '../../nonprofits/supporters/create' )
var create _offline _donation = require ( '../../donations/create_offline' )
require ( '../../components/ajax/toggle_soft_delete' ) ( url , 'campaign' )
// Initialize the froala wysiwyg
var editable = require ( '../../common/editable' )
2018-07-06 17:06:39 +00:00
if ( app . is _parent _campaign ) {
editable ( $ ( '#js-campaignBody' ) , {
sticky : true ,
placeholder : "Add your campaign's story here. We strongly recommend that this section is filled out with at least 250 words. It will be saved automatically as you type. You can add images, videos and custom HTML too."
} )
}
2018-03-25 17:30:42 +00:00
editable ( $ ( '#js-customReceipt' ) , {
button : [ "bold" , "italic" , "formatBlock" , "align" , "createLink" ,
"insertImage" , "insertUnorderedList" , "insertOrderedList" ,
"undo" , "redo" , "insert_donate_button" , "html" ]
, placeholder : "Add optional message here. It will be saved automatically as you type."
} )
var path = '/nonprofits/' + app . nonprofit _id + '/campaigns/' + app . campaign _id
2018-07-05 15:58:00 +00:00
appl . def ( 'remove_banner_image' , function ( ) {
var url = '/nonprofits/' + app . nonprofit _id + '/campaigns/' + app . campaign _id
var notification = 'Removing banner image...'
var payload = { remove _banner _image : true }
appl . remove _image ( url , 'campaign' , notification , payload )
} )
appl . def ( 'remove_background_image' , function ( url , resource ) {
var notification = 'Removing background image...'
var payload = { remove _background _image : true }
appl . remove _image ( url , resource , notification , payload )
2018-03-25 17:30:42 +00:00
} )
appl . def ( 'count_story_words' , function ( ) {
var wysiwyg = document . querySelector ( ".editable" )
appl . def ( 'has_story' , wysiwyg . textContent . split ( ' ' ) . length > 60 )
} )
appl . def ( 'highlight_body' , function ( ) {
appl . def ( 'body_is_highlighted' , true )
appl . close _modal ( )
} )
appl . count _story _words ( document . querySelector ( '.campaign-body' ) )
appl . def ( 'track_launch' , function ( ) {
window . location . reload ( )
} )
appl . def ( 'create_offline_donation' , function ( data , el ) {
create _supporter ( { supporter : data . supporter } , createSupporterUI )
. then ( function ( resp ) {
data . supporter _id = resp . body . id
delete data . supporter
return create _offline _donation ( data , createDonationUI )
} ) . then ( function ( el ) {
appl . ajax _metrics . index ( )
appl . prev _elem ( el ) . reset ( )
} )
} )
var createSupporterUI = {
start : function ( ) {
appl . is _loading ( )
} ,
success : function ( ) {
return this
} ,
fail : function ( msg ) {
appl . def ( 'error' , formatErr ( msg ) )
appl . not _loading ( )
}
}
var createDonationUI = {
start : function ( ) { } ,
success : function ( resp ) {
appl . not _loading ( )
appl . close _modal ( )
appl . notify ( 'Campaign Donation Saved!' )
} ,
fail : function ( msg ) {
appl . def ( 'error' , formatErr ( msg ) )
appl . not _loading ( )
}
}
if ( app . vimeo _id ) {
request . get ( 'http://vimeo.com/api/v2/video/' + app . vimeo _id + '.json' )
. end ( function ( err , resp ) {
appl . def ( 'vimeo_image_url' , "background-image:url('" + resp . body [ 0 ] . thumbnail _small + "')" )
} )
}