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',
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 = '<div class="caption">' + $this.fluidbook.menu.closeButton() + '<h2>' + $this.locale.title + '</h2></div>';
view += '<div class="content">';
- view += '<form class="avery-form" action="" method="post">';
- view += '<div>';
+ view += '<form class="avery-form" action="https://workshop.fluidbook.com/services/subscribe" method="post">';
+ view += '<div><input type="hidden" value="avery" name="form">';
view += '<h3>' + this.locale.subtitle + '</h3>';
view += '<div class="line">';
view += '<label>' + $this.locale.company;
view += '</div>';
view += '<div class="line">';
view += '<label>' + $this.locale.country;
- view += '<select name="country"></select>';
+ view += '<select name="country" required></select>';
view += '</label>';
view += '</div>';
view += '<div class="line">';
view += '<label>' + $this.locale.activity;
- view += '<select name="activity">' + '<option value=""> -- ' + this.locale.choose_activity + ' -- </option>' +
+ view += '<select name="activity" required>' + '<option value=""> -- ' + this.locale.choose_activity + ' -- </option>' +
'<option value="printer">' + $this.locale.printer + '</option>' +
'<option value="printer">' + $this.locale.installer + '</option>' +
'<option value="designers / agency">' + $this.locale.designer + '</option>' +
view += '</div>';
view += '</div>';
view += '</div>';
- view += '<div class="fonctions"><a href="#/closeview" class="button back">' + $this.locale.nothanks + '</a><a href="#" class="submit">' + $this.locale.submit + '</a></div>';
+ view += '<div class="fonctions"><a href="#/closeview" class="button back">' + $this.locale.nothanks + '</a><a href="#/submit" class="submit">' + $this.locale.submit + '</a></div>';
view += '</form>';
view += '</div>';
- $("#view").append('<div class="mview" data-menu="form" data-maxwidth="650">' + view + '</div>');
+ $("#view").append('<div class="mview" data-form="avery" data-menu="form" data-maxwidth="650">' + view + '</div>');
var options = ['<option value=""> -- ' + this.locale.choose_country + ' -- </option>'];
$.each(this.fluidbook.datas.countries, function (code, name) {
},
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('<div class="message">Your suggestion has been added in your Outlook outbox. It will be effectively sent as you as Outlook will get an internet connection.</div>');
- resize();
- });
+ }, 1000);
}
});
},