2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-07-30 00:22:53 +00:00
|
|
|
angular.module('forms').directive('formDirective', ['$http', '$timeout', 'timeCounter', 'Auth', '$filter',
|
|
|
|
function ($http, $timeout, timeCounter, Auth, $filter) {
|
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-04 21:06:16 +00:00
|
|
|
console.log('rendering submitFormDirective');
|
2015-06-29 22:51:29 +00:00
|
|
|
timeCounter.startClock();
|
|
|
|
|
|
|
|
$scope.submit = function(){
|
|
|
|
var _timeElapsed = timeCounter.stopClock();
|
|
|
|
$scope.form.timeElapsed = _timeElapsed;
|
|
|
|
|
2015-07-30 00:22:53 +00:00
|
|
|
$scope.form.percentageComplete = $filter('formValidity')($scope.form.visible_form_fields)/$scope.visible_form_fields.length;
|
|
|
|
delete $scope.form.visible_form_fields;
|
|
|
|
|
2015-07-02 03:50:57 +00:00
|
|
|
$scope.authentication = Auth;
|
2015-06-30 02:14:43 +00:00
|
|
|
|
2015-08-04 21:06:16 +00:00
|
|
|
$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;
|
|
|
|
});
|
2015-06-29 22:51:29 +00:00
|
|
|
};
|
|
|
|
|
2015-07-21 23:25:45 +00:00
|
|
|
$scope.reloadForm = function(){
|
2015-07-30 01:27:46 +00:00
|
|
|
timeCounter.stopClock();
|
|
|
|
timeCounter.startClock();
|
2015-07-21 23:25:45 +00:00
|
|
|
$scope.form.submitted = false;
|
2015-07-27 18:11:43 +00:00
|
|
|
$scope.form.form_fields = _.chain($scope.form.form_fields).map(function(field){
|
|
|
|
field.fieldValue = '';
|
|
|
|
return field;
|
|
|
|
}).value();
|
2015-07-30 00:22:53 +00:00
|
|
|
};
|
2015-07-21 23:25:45 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
]);
|