1apos.define('contact-form-tandt-widgets', { 2 3 extend: 'apostrophe-widgets', 4 5 construct: function (self, options) { 6 self.play = function ($widget, data, options) { 7 var $form = $widget.find('[data-contact-form-tandt]'); 8 var schema = self.options.submitSchema; 9 var piece = _.cloneDeep(self.options.piece); 10 11 var picker = new Pikaday({ field: $('[name="dob"]')[0] }); 12 $('#submit-button').hide(); 13 $('.apos-field-tandc > label').html($('.apos-field-tandc > label').text().replace('[tac]', '<a href="somewhere">Terms and Conditions</a>')); 14 $('[name="tandc"]').on('click', function() { 15 $('#submit-button').fadeIn(); 16 }); 17 return apos.schemas.populate($form, self.schema, self.piece, function (err) { 18 if (err) { 19 alert('A problem occurred setting up the contact form.'); 20 return; 21 } 22 enableSubmit(); 23 }); 24 25 function enableSubmit () { 26 $form.on('submit', function () { 27 $('#submit-button').hide(); 28 submit(); 29 return false; 30 }); 31 } 32 33 function submit () { 34 console.dir($form) 35 return async.series([ 36 convert, 37 submitToServer 38 ], function (err) { 39 if (err) { 40 if (!Array.isArray(err)) { 41 $('#the-error').text(err.status); 42 $form.find('[data-error-you]').fadeIn(); 43 } else { 44 $('#submit-button').fadeIn(); 45 } 46 } else { 47 48 $form.find('.info-holder').fadeOut('fast', function() { 49 $form.find('[data-thank-you]').fadeIn(); 50 }); 51 52 } 53 }); 54 function convert (callback) { 55 return apos.schemas.convert($form, schema, piece, callback); 56 } 57 function submitToServer (callback) { 58 return self.api('submit', piece, function (data) { 59 if (data.status === 'ok') { 60 // All is well 61 return callback(null); 62 } 63 // API-level error 64 return callback(data); 65 }, function (err) { 66 $('#submit-button').show(); 67 // Transport-level error 68 return callback(err); 69 }); 70 } 71 } 72 }; 73 } 74});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.