From 7b8c345d80e1f8c68d80f49ee03403603bee0086 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 17 Sep 2018 19:03:40 +0200 Subject: [PATCH] wip #2208 @0.5 --- .../fluidbook/forms/fluidbook.form.avery.js | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 js/libs/fluidbook/forms/fluidbook.form.avery.js diff --git a/js/libs/fluidbook/forms/fluidbook.form.avery.js b/js/libs/fluidbook/forms/fluidbook.form.avery.js new file mode 100644 index 00000000..24f95d87 --- /dev/null +++ b/js/libs/fluidbook/forms/fluidbook.form.avery.js @@ -0,0 +1,118 @@ +function FluidbookAveryForm(fluidbook) { + this.fluidbook = fluidbook; + + this.locales = { + en: { + title: 'Discover what our full Avery Dennison portfolio can do for you', + subtitle: 'Register using this form for access to our current and future digital catalogues.', + company: 'Company', + country: 'Country', + activity: 'Activity', + printer: 'Printer', + installer: 'Installer', + designer: 'Designer / Agency', + brandowner: 'Brand owner', + other: 'Other', + email_address: 'E-mail address', + receive: 'Do you want to receive our free monthly e-newsletter', + yes: 'Yes', + no: 'No', + consent: 'I have read and agree to the Avery Dennison Legal and Privacy Notices', + submit: 'Submit', + nothanks: 'No, thanks' + } + }; + + this.locale = this.locales[this.fluidbook.datas.lang]; + + + this.formInstance; + this.init(); +} + +FluidbookAveryForm.prototype = { + init: function () { + var $this = this; + + $(document).on('click', '.avery-form .submit', function () { + $this.formInstance = $(".avery-form").parsley(); + if ($this.formInstance.validate()) { + $this.sendSuggestion(); + } + return false; + }); + + }, + + openSuggest: function (p1, p2, callback) { + var view = '
' + this.closeButton() + '

' + this.locale.title + '

'; + view += '
'; + view += '
'; + view += '
'; + view += ''; + view += ''; + view += ''; + view += ''; + view += '
'; + view += this.locale.receive; + view += ''; + view += ''; + view += '
'; + view += '
'; + view += ''; + view += '
'; + view += '
'; + + $("#view").append('
' + view + '
'); + + callback(); + }, + submitForm: function () { + var $this = this; + console.log('sendSuggestion'); + var fs = require('fs'); + var path = require('path'); + + var file = 'suggestion.txt'; + var filePath = path.join(nw.App.dataPath, file); + var data = $("#bourbon-suggestion-page").val() + "/|!/" + Date.now() + "/|!/" + $("#bourbon-suggestion-type").val() + "/|!/" + $("#bourbon-suggestion-body").val(); + console.log('Data to send: ' + data); + this.fluidbook.displayLoader(); + fs.writeFile(filePath, data, function (err) { + if (err) { + console.info("There was an error attempting to save your data."); + console.warn(err.message); + return; + } else { + console.log('File written'); + var exec = require('child_process').exec; + var path = require('path'); + var cmd = '"' + path.join(process.cwd(), 'exe/sendemail.exe') + '" "bourbon+2018@fluidbook.com" "Bourbon SMS Suggestion" "Please see attached suggestion" "' + filePath + '" "' + file + '"'; + console.log('exec ' + cmd); + exec(cmd, function (error, stdout, stderr) { + $this.fluidbook.hideLoader(); + if (error) { + console.error("exec error: ${error}"); + return; + } + console.log('output: ' + stdout.toString()); + console.log('Email sent'); + $(".cart-bourbon-suggest").html('
Your suggestion has been added in your Outlook outbox. It will be effectively sent as you as Outlook will get an internet connection.
'); + resize(); + }); + } + }); + }, +}; \ No newline at end of file -- 2.39.5