diff --git a/app/models/form.server.model.js b/app/models/form.server.model.js index 236d0ddd..5727903c 100644 --- a/app/models/form.server.model.js +++ b/app/models/form.server.model.js @@ -254,9 +254,11 @@ function getDeletedIndexes(needle, haystack){ } function formFieldsAllHaveIds(form_fields){ - for(var i=0; i this.ratingOptions.steps || this.fieldValue+0 < 0){ - this.fieldValue = 1; - } } diff --git a/app/views/form.server.view.pug b/app/views/form.server.view.pug index 2c44f399..43d515f6 100644 --- a/app/views/form.server.view.pug +++ b/app/views/form.server.view.pug @@ -79,13 +79,11 @@ html(lang='en', xmlns='http://www.w3.org/1999/xhtml') //Socket.io Client Dependency script(src='/static/lib/socket.io-client/dist/socket.io.min.js') - //Minified Bower Dependencies - script(src='/static/lib/angular/angular.min.js') - script(src='/static/dist/vendor.min.js') - script(src='/static/lib/angular-ui-date/src/date.js', type='text/javascript') + //Bower JS dependencies + each bowerJSFile in bowerFormJSFiles + script(type='text/javascript', src=bowerJSFile) + // end Bower JS dependencies - script(src='/static/lib/jquery-ui/jquery-ui.js', type='text/javascript') - script(src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', integrity='sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa', crossorigin='anonymous') //Application JavaScript Files each jsFile in formJSFiles @@ -96,7 +94,7 @@ html(lang='en', xmlns='http://www.w3.org/1999/xhtml') //Livereload script rendered script(async='', type='text/javascript', src='http://#{request.hostname}:35729/livereload.js') - script Raven.config('https://825fefd6b4ed4a4da199c1b832ca845c@sentry.tellform.com/2').install(); + //script Raven.config('https://825fefd6b4ed4a4da199c1b832ca845c@sentry.tellform.com/2').install(); if google_analytics_id script window.ga=function(){ga.q.push(arguments)};ga.q=[];ga.l=+new Date;ga('create','{{google_analytics_id}}','auto');ga('send','pageview') diff --git a/config/config.js b/config/config.js index a39c29fb..d304f42b 100755 --- a/config/config.js +++ b/config/config.js @@ -62,6 +62,12 @@ module.exports.removeRootDir = function(files, removeRoot, addRoot) { /** * Get the app's bower dependencies */ +module.exports.getBowerFormJSAssets = function() { + if(process.env.NODE_ENV === 'production'){ + return '/static/dist/vendor.min.js' + } + return this.removeRootDir(minBowerFiles('**/**.js'), 'public/', 'static/'); +}; module.exports.getBowerJSAssets = function() { return this.removeRootDir(minBowerFiles('**/**.js'), 'public/', 'static/'); }; diff --git a/config/env/production.js b/config/env/production.js index 0f8a72a5..08ebc529 100755 --- a/config/env/production.js +++ b/config/env/production.js @@ -30,6 +30,6 @@ module.exports = { assets: { css: ['public/dist/application.min.css'], js: ['public/dist/application.min.js', 'public/dist/populate_template_cache.js'], - form_js: ['public/dist/form-application.min.js', 'public/dist/form_populate_template_cache.js', 'public/dist/form-vendor.min.js'] + form_js: ['public/dist/form-application.min.js', 'public/dist/form_populate_template_cache.js'] } }; diff --git a/config/express.js b/config/express.js index 99357774..d5f21587 100755 --- a/config/express.js +++ b/config/express.js @@ -78,6 +78,7 @@ module.exports = function(db) { app.locals.socketUrl = config.socketUrl; } + app.locals.bowerFormJSFiles = config.getBowerFormJSAssets(); app.locals.bowerJSFiles = config.getBowerJSAssets(); app.locals.bowerCssFiles = config.getBowerCSSAssets(); app.locals.bowerOtherFiles = config.getBowerOtherAssets(); diff --git a/public/form_modules/forms/base/directives/submit-form.client.directive.js b/public/form_modules/forms/base/directives/submit-form.client.directive.js index 77af2ff0..5c3a809a 100644 --- a/public/form_modules/forms/base/directives/submit-form.client.directive.js +++ b/public/form_modules/forms/base/directives/submit-form.client.directive.js @@ -19,7 +19,6 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun ispreview: '=' }, controller: function($document, $window, $scope){ - var NOSCROLL = false; var FORM_ACTION_ID = 'submit_field'; $scope.forms = {}; @@ -32,12 +31,26 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun return field.fieldType !== 'statement'; }).length; - var nb_valid = $filter('formValidity')($scope.myform); - $scope.translateAdvancementData = { - done: nb_valid, - total: form_fields_count, - answers_not_completed: form_fields_count - nb_valid - }; + $scope.$watch('myform', function(oldVal, newVal){ + $scope.myform.visible_form_fields = $scope.myform.form_fields.filter(function(field){ + return !field.deletePreserved; + }); + console.log($scope.myform.visible_form_fields); + }) + + $scope.updateFormValidity = function(){ + $timeout(function(){ + var nb_valid = $scope.myform.form_fields.filter(function(field){ + return (field.fieldType === 'statement' || field.fieldValue !== '' || !field.required); + }).length; + $scope.translateAdvancementData = { + done: nb_valid, + total: $scope.myform.visible_form_fields.length + }; + }); + } + + $scope.updateFormValidity(); $scope.reloadForm = function(){ //Reset Form @@ -135,19 +148,14 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun return $scope.selected.index; }; - $scope.isActiveField = function(field){ - if($scope.selected._id === field._id) { - return true - } - return false; - }; - $scope.setActiveField = $rootScope.setActiveField = function(field_id, field_index, animateScroll) { if($scope.selected === null || (!field_id && field_index === null) ) { return; } - if(!field_id){ + if(field_id === FORM_ACTION_ID){ + field_index = $scope.myform.visible_form_fields.length; + } else if(!field_id) { field_id = $scope.myform.visible_form_fields[field_index]._id; } else if(field_index === null){ field_index = $scope.myform.visible_form_fields.length @@ -168,108 +176,31 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun $scope.selected._id = field_id; $scope.selected.index = field_index; - var nb_valid = $filter('formValidity')($scope.myform); - $scope.translateAdvancementData = { - done: nb_valid, - total: form_fields_count, - answers_not_completed: form_fields_count - nb_valid - }; - if(animateScroll){ - NOSCROLL=true; - setTimeout(function() { - $document.scrollToElement(angular.element('#'+field_id), -10, 50).then(function() { - NOSCROLL = false; - setTimeout(function() { - if (document.querySelectorAll('#'+field_id+' .focusOn').length) { - //Handle default case - document.querySelectorAll('#'+field_id+' .focusOn')[0].focus(); - } else if(document.querySelectorAll('#'+field_id+' input').length) { - //Handle case for rating input - document.querySelectorAll('#'+field_id+' input')[0].focus(); - } else { - //Handle case for dropdown input - document.querySelectorAll('#'+field_id+'.selectize-input')[0].focus(); - } - }); - }); + $document.scrollToElement(angular.element('#'+field_id), -10, 50).then(function() { + if (angular.element('#'+field_id+' .focusOn').length) { + //Handle default case + angular.element('#'+field_id+' .focusOn')[0].focus(); + } else if(angular.element('#'+field_id+' input').length) { + //Handle case for rating input + angular.element('#'+field_id+' input')[0].focus(); + } else { + //Handle case for dropdown input + angular.element('#'+field_id+'.selectize-input')[0].focus(); + } }); - } + } }; - $scope.$watch('selected.index', function(oldValue, newValue){ - if(oldValue !== newValue && newValue < $scope.myform.form_fields.length){ - //Only send analytics data if form has not been submitted - if(!$scope.myform.submitted){ - //SendVisitorData.send($scope.myform, newValue, TimeCounter.getTimeElapsed()); - } - } - }); - $rootScope.$on('duScrollspy:becameActive', function($event, $element, $target){ - console.log($element.prop('id')); $scope.setActiveField($element.prop('id'), null, false); - console.log($scope.selected.index); - $scope.$apply(); + $scope.updateFormValidity(); + $scope.$apply() + if(!$scope.myform.submitted){ + SendVisitorData.send($scope.myform, newValue, TimeCounter.getTimeElapsed()); + } }); - //Fire event when window is scrolled - /*$window.onscroll = function(){ - if(!NOSCROLL){ - - var scrollTop = $(window).scrollTop(); - var elemBox = document.getElementsByClassName('activeField')[0].getBoundingClientRect(); - var fieldTop = elemBox.top; - var fieldBottom = elemBox.bottom; - - var field_id, field_index; - var elemHeight = $('.activeField').height(); - - var submitSectionHeight = $('.form-actions').height(); - var maxScrollTop = $(document).height() - $(window).height(); - var fieldWrapperHeight = $('form_fields').height(); - - var selector = 'form > .field-directive:nth-of-type(' + String($scope.myform.visible_form_fields.length - 1)+ ')' - var fieldDirectiveHeight = $(selector).height() - var scrollPosition = maxScrollTop - submitSectionHeight - fieldDirectiveHeight*1.2; - - var fractionToJump = 0.9; - - console.log("fieldBottom < elemHeight * fractionToJump: "+fieldBottom + " < " + elemHeight * fractionToJump); - - console.log("fieldTop > elemHeight * fractionToJump: "+fieldTop + " > " + elemHeight * fractionToJump); - - console.log('fieldTop: '+fieldTop); - console.log('fieldBottom: '+fieldBottom); - console.log('scrollPosition: '+scrollPosition) - - //Focus on field above submit form button - if($scope.selected.index === $scope.myform.visible_form_fields.length){ - if(scrollTop < scrollPosition){ - field_index = $scope.selected.index-1; - $scope.setActiveField(null, field_index, false); - } - } - //Focus on submit form button - else if($scope.selected.index === $scope.myform.visible_form_fields.length-1 && scrollTop > scrollPosition){ - field_index = $scope.selected.index+1; - $scope.setActiveField(FORM_ACTION_ID, field_index, false); - } - //If we scrolled bellow the current field, move to next field - else if(fieldBottom < elemHeight * fractionToJump && $scope.selected.index < $scope.myform.visible_form_fields.length-1){ - field_index = $scope.selected.index+1; - $scope.setActiveField(null, field_index, false); - } - //If we scrolled above the current field, move to prev field - else if ( $scope.selected.index !== 0 && fieldTop > elemHeight * fractionToJump) { - field_index = $scope.selected.index-1; - $scope.setActiveField(null, field_index, false); - } - } - - $scope.$apply(); - };*/ - $rootScope.nextField = $scope.nextField = function(){ if($scope.selected && $scope.selected.index > -1){ @@ -287,7 +218,7 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun } } else { //If selected is not defined go to the first field - $rootScope.setActiveField(null, 0, true); + $scope.setActiveField(null, 0, true); } }; @@ -299,7 +230,7 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun }; $rootScope.goToInvalid = $scope.goToInvalid = function() { - var field_id = $('.row.field-directive .ng-invalid.focusOn, .row.field-directive .ng-untouched.focusOn:not(.ng-valid)').first().parents('.row.field-directive').first().attr('data-id'); + var field_id = $('.ng-invalid, .ng-untouched').first().parents('.row.field-directive').first().attr('id'); $scope.setActiveField(field_id, null, true); }; diff --git a/public/form_modules/forms/base/views/directiveViews/field/date.html b/public/form_modules/forms/base/views/directiveViews/field/date.html index c2d74a20..705a38f4 100755 --- a/public/form_modules/forms/base/views/directiveViews/field/date.html +++ b/public/form_modules/forms/base/views/directiveViews/field/date.html @@ -16,6 +16,7 @@
diff --git a/public/form_modules/forms/base/views/directiveViews/field/rating.html b/public/form_modules/forms/base/views/directiveViews/field/rating.html index 41319b7f..6f5cc78f 100644 --- a/public/form_modules/forms/base/views/directiveViews/field/rating.html +++ b/public/form_modules/forms/base/views/directiveViews/field/rating.html @@ -15,14 +15,13 @@