]> _ Git - fluidbook-html5.git/commitdiff
wip #2208 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Sep 2018 12:02:19 +0000 (14:02 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Sep 2018 12:02:19 +0000 (14:02 +0200)
js/libs/fluidbook/forms/fluidbook.form.avery.js
style/form/avery.less

index 0efab23c1a69b536bf471e69a5a5e933e397b93d..d1179acad183a77fd38d09149c30355d4be760b8 100644 (file)
@@ -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 = '<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;
@@ -92,12 +88,12 @@ FluidbookAveryForm.prototype = {
         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>' +
@@ -122,11 +118,11 @@ FluidbookAveryForm.prototype = {
         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) {
@@ -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('<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);
             }
         });
     },
index 76bfe6653ddf61fe6609da1e21a440de4f438294..e46a5f737a50783b70e892b3188060787414a02f 100644 (file)
@@ -38,4 +38,8 @@
                        margin-right: 20px;
                }
        }
+
+       .parsley-errors-list{
+               display: none;
+       }
 }