From 706abceffc0daf6e7c768e00b150a01afd02b2e7 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 27 Apr 2016 17:46:53 +0300 Subject: [PATCH 1/2] add public prefix to html2js conf --- gruntfile.js | 2 +- .../forms/directives/field.client.directive.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gruntfile.js b/gruntfile.js index 7ccb1f2c..5007b232 100755 --- a/gruntfile.js +++ b/gruntfile.js @@ -231,7 +231,7 @@ module.exports = function(grunt) { }, html2js: { options: { - base: 'NodeForm', + base: 'public', watch: true, module: 'NodeForm.templates', singleModule: true, diff --git a/public/modules/forms/directives/field.client.directive.js b/public/modules/forms/directives/field.client.directive.js index 1e032fa8..84ae7e58 100644 --- a/public/modules/forms/directives/field.client.directive.js +++ b/public/modules/forms/directives/field.client.directive.js @@ -10,7 +10,7 @@ var __indexOf = [].indexOf || function(item) { angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$rootScope', '$templateCache', function($http, $compile, $rootScope, $templateCache) { - + var getTemplateUrl = function(fieldType) { var type = fieldType; var templateUrl = 'modules/forms/views/directiveViews/field/'; @@ -33,7 +33,7 @@ angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$root templateUrl = templateUrl+type+'.html'; } - return $templateCache.get('../public/'+templateUrl); + return $templateCache.get(templateUrl); }; return { @@ -47,20 +47,20 @@ angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$root }, link: function(scope, element) { scope.setActiveField = $rootScope.setActiveField; - + //Set format only if field is a date if(scope.field.fieldType === 'date'){ scope.dateOptions = { changeYear: true, changeMonth: true, altFormat: 'mm/dd/yyyy', - yearRange: '1900:-0', + yearRange: '1900:-0', defaultDate: 0, }; } - + var fieldType = scope.field.fieldType; - + if(scope.field.fieldType === 'number' || scope.field.fieldType === 'textfield' || scope.field.fieldType === 'email' || scope.field.fieldType === 'link'){ switch(scope.field.fieldType){ case 'textfield': From 113cfddfb84220c2448fab8447081f746f6f10ad Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 27 Apr 2016 18:16:19 +0300 Subject: [PATCH 2/2] use $templateCache into submit-form controller --- .../submit-form.client.directive.js | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/public/modules/forms/directives/submit-form.client.directive.js b/public/modules/forms/directives/submit-form.client.directive.js index ea0d7687..270ead7e 100644 --- a/public/modules/forms/directives/submit-form.client.directive.js +++ b/public/modules/forms/directives/submit-form.client.directive.js @@ -1,9 +1,9 @@ 'use strict'; -angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter', '$filter', '$rootScope', 'Auth', - function ($http, TimeCounter, $filter, $rootScope, Auth) { +angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter', '$filter', '$rootScope', 'Auth', '$templateCache', + function ($http, TimeCounter, $filter, $rootScope, Auth, $templateCache) { return { - templateUrl: 'modules/forms/views/directiveViews/form/submit-form.client.view.html', + template: $templateCache.get('modules/forms/views/directiveViews/form/submit-form.client.view.html'), restrict: 'E', scope: { myform:'=' @@ -11,14 +11,14 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter' controller: function($document, $window, $scope){ $scope.authentication = $rootScope.authentication; $scope.noscroll = false; - $scope.forms = {}; + $scope.forms = {}; $scope.form_fields_count = $scope.myform.visible_form_fields.filter(function(field){ if(field.fieldType === 'statement' || field.fieldType === 'rating'){ return false; - } + } return true; }).length; - + $scope.reloadForm = function(){ //Reset Form $scope.myform.submitted = false; @@ -29,24 +29,24 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter' $scope.loading = false; $scope.error = ''; - + $scope.selected = { _id: '', index: 0 }; - $scope.setActiveField($scope.myform.visible_form_fields[0]._id, 0, false); - + $scope.setActiveField($scope.myform.visible_form_fields[0]._id, 0, false); + console.log($scope.selected); //Reset Timer - TimeCounter.restartClock(); + TimeCounter.restartClock(); }; - + $window.onscroll = function(){ $scope.scrollPos = document.body.scrollTop || document.documentElement.scrollTop || 0; var elemBox = document.getElementsByClassName('activeField')[0].getBoundingClientRect(); $scope.fieldTop = elemBox.top; $scope.fieldBottom = elemBox.bottom; - + //console.log($scope.forms.myForm); if(!$scope.noscroll){ @@ -55,10 +55,10 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter' var field_index = $scope.selected.index+1; var field_id = 'submit_field'; $scope.setActiveField(field_id, field_index, false); - } + } //Focus on field above submit button else if($scope.selected.index === $scope.myform.form_fields.length){ - if($scope.fieldTop > 200){ + if($scope.fieldTop > 200){ var field_index = $scope.selected.index-1; var field_id = $scope.myform.form_fields[field_index]._id; $scope.setActiveField(field_id, field_index, false); @@ -70,11 +70,11 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter' }else if ( $scope.selected.index !== 0 && $scope.fieldTop > 0) { var field_index = $scope.selected.index-1; var field_id = $scope.myform.form_fields[field_index]._id; - $scope.setActiveField(field_id, field_index, false); + $scope.setActiveField(field_id, field_index, false); } //console.log('$scope.selected.index: '+$scope.selected.index); //console.log('scroll pos: '+$scope.scrollPos+' fieldTop: '+$scope.fieldTop+' fieldBottom: '+$scope.fieldBottom); - $scope.$apply(); + $scope.$apply(); } }; @@ -127,23 +127,23 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter' $scope.setActiveField(selected_id, selected_index, true); } }; - + /* ** Form Display Functions */ $scope.exitStartPage = function(){ $scope.myform.startPage.showStart = false; - if($scope.myform.form_fields.length > 0){ + if($scope.myform.form_fields.length > 0){ $scope.selected._id = $scope.myform.form_fields[0]._id; } }; $scope.submitForm = function(){ var _timeElapsed = TimeCounter.stopClock(); - $scope.loading = true; + $scope.loading = true; var form = _.cloneDeep($scope.myform); form.timeElapsed = _timeElapsed; - + form.percentageComplete = $filter('formValidity')($scope.myform)/$scope.myform.visible_form_fields.length*100; delete form.visible_form_fields;