use $templateCache into submit-form controller
This commit is contained in:
parent
42e9b7564e
commit
3694cab7bb
|
@ -1,9 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter', '$filter', '$rootScope', 'Auth',
|
angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter', '$filter', '$rootScope', 'Auth', '$templateCache',
|
||||||
function ($http, TimeCounter, $filter, $rootScope, Auth) {
|
function ($http, TimeCounter, $filter, $rootScope, Auth, $templateCache) {
|
||||||
return {
|
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',
|
restrict: 'E',
|
||||||
scope: {
|
scope: {
|
||||||
myform:'='
|
myform:'='
|
||||||
|
@ -11,14 +11,14 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
|
||||||
controller: function($document, $window, $scope){
|
controller: function($document, $window, $scope){
|
||||||
$scope.authentication = $rootScope.authentication;
|
$scope.authentication = $rootScope.authentication;
|
||||||
$scope.noscroll = false;
|
$scope.noscroll = false;
|
||||||
$scope.forms = {};
|
$scope.forms = {};
|
||||||
$scope.form_fields_count = $scope.myform.visible_form_fields.filter(function(field){
|
$scope.form_fields_count = $scope.myform.visible_form_fields.filter(function(field){
|
||||||
if(field.fieldType === 'statement' || field.fieldType === 'rating'){
|
if(field.fieldType === 'statement' || field.fieldType === 'rating'){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}).length;
|
}).length;
|
||||||
|
|
||||||
$scope.reloadForm = function(){
|
$scope.reloadForm = function(){
|
||||||
//Reset Form
|
//Reset Form
|
||||||
$scope.myform.submitted = false;
|
$scope.myform.submitted = false;
|
||||||
|
@ -29,24 +29,24 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
|
||||||
|
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$scope.error = '';
|
$scope.error = '';
|
||||||
|
|
||||||
$scope.selected = {
|
$scope.selected = {
|
||||||
_id: '',
|
_id: '',
|
||||||
index: 0
|
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);
|
console.log($scope.selected);
|
||||||
//Reset Timer
|
//Reset Timer
|
||||||
TimeCounter.restartClock();
|
TimeCounter.restartClock();
|
||||||
};
|
};
|
||||||
|
|
||||||
$window.onscroll = function(){
|
$window.onscroll = function(){
|
||||||
$scope.scrollPos = document.body.scrollTop || document.documentElement.scrollTop || 0;
|
$scope.scrollPos = document.body.scrollTop || document.documentElement.scrollTop || 0;
|
||||||
var elemBox = document.getElementsByClassName('activeField')[0].getBoundingClientRect();
|
var elemBox = document.getElementsByClassName('activeField')[0].getBoundingClientRect();
|
||||||
$scope.fieldTop = elemBox.top;
|
$scope.fieldTop = elemBox.top;
|
||||||
$scope.fieldBottom = elemBox.bottom;
|
$scope.fieldBottom = elemBox.bottom;
|
||||||
|
|
||||||
//console.log($scope.forms.myForm);
|
//console.log($scope.forms.myForm);
|
||||||
|
|
||||||
if(!$scope.noscroll){
|
if(!$scope.noscroll){
|
||||||
|
@ -55,10 +55,10 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
|
||||||
var field_index = $scope.selected.index+1;
|
var field_index = $scope.selected.index+1;
|
||||||
var field_id = 'submit_field';
|
var field_id = 'submit_field';
|
||||||
$scope.setActiveField(field_id, field_index, false);
|
$scope.setActiveField(field_id, field_index, false);
|
||||||
}
|
}
|
||||||
//Focus on field above submit button
|
//Focus on field above submit button
|
||||||
else if($scope.selected.index === $scope.myform.form_fields.length){
|
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_index = $scope.selected.index-1;
|
||||||
var field_id = $scope.myform.form_fields[field_index]._id;
|
var field_id = $scope.myform.form_fields[field_index]._id;
|
||||||
$scope.setActiveField(field_id, field_index, false);
|
$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) {
|
}else if ( $scope.selected.index !== 0 && $scope.fieldTop > 0) {
|
||||||
var field_index = $scope.selected.index-1;
|
var field_index = $scope.selected.index-1;
|
||||||
var field_id = $scope.myform.form_fields[field_index]._id;
|
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('$scope.selected.index: '+$scope.selected.index);
|
||||||
//console.log('scroll pos: '+$scope.scrollPos+' fieldTop: '+$scope.fieldTop+' fieldBottom: '+$scope.fieldBottom);
|
//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);
|
$scope.setActiveField(selected_id, selected_index, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Form Display Functions
|
** Form Display Functions
|
||||||
*/
|
*/
|
||||||
$scope.exitStartPage = function(){
|
$scope.exitStartPage = function(){
|
||||||
$scope.myform.startPage.showStart = false;
|
$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.selected._id = $scope.myform.form_fields[0]._id;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.submitForm = function(){
|
$scope.submitForm = function(){
|
||||||
var _timeElapsed = TimeCounter.stopClock();
|
var _timeElapsed = TimeCounter.stopClock();
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
var form = _.cloneDeep($scope.myform);
|
var form = _.cloneDeep($scope.myform);
|
||||||
form.timeElapsed = _timeElapsed;
|
form.timeElapsed = _timeElapsed;
|
||||||
|
|
||||||
form.percentageComplete = $filter('formValidity')($scope.myform)/$scope.myform.visible_form_fields.length*100;
|
form.percentageComplete = $filter('formValidity')($scope.myform)/$scope.myform.visible_form_fields.length*100;
|
||||||
delete form.visible_form_fields;
|
delete form.visible_form_fields;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue