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' )
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."
} )
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
appl . def ( 'remove_this_image' , function ( ) {
appl . remove _background _image ( path , 'campaign' )
} )
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 + "')" )
} )
}