From: Vincent Vanwaelscappel Date: Fri, 28 Sep 2018 12:02:19 +0000 (+0200) Subject: wip #2208 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=55b7e505a214111b937003311371fe0c5c83a2d5;p=fluidbook-html5.git wip #2208 @1 --- diff --git a/js/libs/fluidbook/forms/fluidbook.form.avery.js b/js/libs/fluidbook/forms/fluidbook.form.avery.js index 0efab23c..d1179aca 100644 --- a/js/libs/fluidbook/forms/fluidbook.form.avery.js +++ b/js/libs/fluidbook/forms/fluidbook.form.avery.js @@ -22,6 +22,7 @@ function FluidbookAveryForm(fluidbook) { nothanks: 'No, thanks', choose_country: 'Please choose a country', choose_activity: 'Please an activity', + error: 'Please fill all the fields', }, fr: { title: 'Discover what our full Avery Dennison portfolio can do for you', @@ -54,36 +55,31 @@ FluidbookAveryForm.prototype = { init: function () { var $this = this; - $(this.fluidbook).on('fluidbook.splash.hide', function () { - $this.openForm('', '', function () { - - }); - }); - - $(document).on('click', '.avery-form .submit', function () { + $(document).on('click', '.mview[data-form="avery"] a.submit', function () { $this.formInstance = $(".avery-form").parsley(); if ($this.formInstance.validate()) { - $this.sendSuggestion(); + $this.submitForm(); + } else { + alert($this.locale.error); } return false; }); - $(document).on('click', '.avery-form .submit', function () { - $this.formInstance = $(".avery-form").parsley(); - if ($this.formInstance.validate()) { - $this.sendSuggestion(); - } - return false; + $(this.fluidbook).on('fluidbook.splash.hide', function () { + $this.openForm('', '', function () { + + }); }); + }, openForm: function (p1, p2, callback) { var $this = this; var view = '
' + $this.fluidbook.menu.closeButton() + '

' + $this.locale.title + '

'; view += '
'; - view += '
'; - view += '
'; + view += ''; + view += '
'; view += '

' + this.locale.subtitle + '

'; view += '
'; view += '
'; view += '
'; view += ''; view += '
'; view += '
'; view += '
'; view += '
'; view += '
'; - view += ''; + view += ''; view += '
'; view += '
'; - $("#view").append('
' + view + '
'); + $("#view").append('
' + view + '
'); var options = ['']; $.each(this.fluidbook.datas.countries, function (code, name) { @@ -140,38 +136,21 @@ FluidbookAveryForm.prototype = { }, submitForm: function () { + this.fluidbook.displayLoader(); var $this = this; - console.log('sendSuggestion'); - var fs = require('fs'); - var path = require('path'); + var form = $("form.avery-form"); + var url = form.attr('action'); - 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) { + $.ajax({ + type: "POST", + url: url, + data: form.serialize(), // serializes the form's elements. + success: function (data) { + setTimeout(function () { + $this.fluidbook.menu.closeView(function () { + }, true, true); $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(); - }); + }, 1000); } }); }, diff --git a/style/form/avery.less b/style/form/avery.less index 76bfe665..e46a5f73 100644 --- a/style/form/avery.less +++ b/style/form/avery.less @@ -38,4 +38,8 @@ margin-right: 20px; } } + + .parsley-errors-list{ + display: none; + } }