2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-08-06 05:52:59 +00:00
|
|
|
angular.module('forms').directive('formDirective', ['$http', '$timeout', 'timeCounter', 'Auth', '$filter', '$rootScope',
|
|
|
|
function ($http, $timeout, timeCounter, Auth, $filter, $rootScope) {
|
2015-06-29 22:51:29 +00:00
|
|
|
return {
|
2015-08-04 21:06:16 +00:00
|
|
|
templateUrl: './modules/forms/views/directiveViews/form/submit-form.html',
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
|
|
|
form:'='
|
|
|
|
},
|
2015-06-29 22:51:29 +00:00
|
|
|
controller: function($scope){
|
2015-08-06 05:52:59 +00:00
|
|
|
angular.element(document).ready(function() {
|
|
|
|
|
|
|
|
$scope.selected = null;
|
|
|
|
$scope.startPage = true;
|
|
|
|
|
|
|
|
$rootScope.setActiveField = function (field_id) {
|
|
|
|
console.log('form field clicked: '+field_id);
|
|
|
|
$scope.selected = field_id;
|
|
|
|
console.log($scope.selected);
|
|
|
|
}
|
|
|
|
$scope.hideOverlay = function (){
|
|
|
|
$scope.selected = null;
|
|
|
|
console.log($scope.myForm);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.submit = function(){
|
|
|
|
var _timeElapsed = timeCounter.stopClock();
|
|
|
|
$scope.form.timeElapsed = _timeElapsed;
|
|
|
|
|
|
|
|
// console.log('percentageComplete: '+$filter('formValidity')($scope.form)/$scope.form.visible_form_fields.length*100+'%');
|
|
|
|
$scope.form.percentageComplete = $filter('formValidity')($scope.form)/$scope.form.visible_form_fields.length*100;
|
|
|
|
console.log($scope.form.percentageComplete);
|
|
|
|
// delete $scope.form.visible_form_fields;
|
|
|
|
|
|
|
|
$scope.authentication = Auth;
|
|
|
|
|
|
|
|
$scope.submitPromise = $http.post('/forms/'+$scope.form._id,$scope.form)
|
|
|
|
.success(function(data, status, headers){
|
|
|
|
console.log('form submitted successfully');
|
|
|
|
// alert('Form submitted..');
|
|
|
|
$scope.form.submitted = true;
|
|
|
|
})
|
|
|
|
.error(function(error){
|
|
|
|
console.log(error);
|
|
|
|
$scope.error = error.message;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$scope.exitStartPage = function () {
|
|
|
|
$scope.startPage = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.reloadForm = function(){
|
|
|
|
timeCounter.stopClock();
|
|
|
|
timeCounter.startClock();
|
|
|
|
$scope.form.submitted = false;
|
|
|
|
$scope.form.form_fields = _.chain($scope.form.form_fields).map(function(field){
|
|
|
|
field.fieldValue = '';
|
|
|
|
return field;
|
|
|
|
}).value();
|
|
|
|
};
|
|
|
|
});
|
2015-07-21 23:25:45 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
]);
|