tellform/public/modules/forms/directives/configure-form.client.directive.js

95 lines
3.3 KiB
JavaScript
Raw Normal View History

2015-07-03 23:47:14 +00:00
'use strict';
2015-11-12 22:24:26 +00:00
angular.module('forms').directive('configureFormDirective', ['$rootScope', '$http', 'Upload', 'CurrentForm',
function ($rootScope, $http, Upload, CurrentForm) {
2015-07-03 23:47:14 +00:00
return {
2015-08-21 00:17:14 +00:00
templateUrl: 'modules/forms/views/directiveViews/form/configure-form.client.view.html',
2015-08-04 21:06:16 +00:00
restrict: 'E',
scope: {
myform:'=',
user:'=',
pdfFields:'@',
formFields:'@'
},
2015-07-03 23:47:14 +00:00
controller: function($scope){
2015-10-30 18:40:02 +00:00
console.log($scope.myform);
if( CurrentForm.getForm().plugins){
if(CurrentForm.getForm().plugins.oscarhost.baseUrl) $scope.oscarhostAPI = true;
}else{
$scope.oscarhostAPI = false;
}
2015-07-03 23:47:14 +00:00
$scope.log = '';
$scope.pdfLoading = false;
$scope.languages = $rootScope.languages;
2016-04-29 02:48:02 +00:00
2015-08-21 00:17:14 +00:00
this._current_upload = null;
2015-07-06 04:29:05 +00:00
$scope.resetForm = $rootScope.resetForm;
$scope.update = $rootScope.update;
2015-07-04 04:57:06 +00:00
2015-08-21 00:17:14 +00:00
this._unbindedPdfFields = $scope.pdfFields;
2015-07-04 04:57:06 +00:00
//DAVID: TODO: finish this so we can create a Form.pdfFieldMap
// $scope.getUnbindedPdfFields = function(fieldType){
2015-08-21 00:17:14 +00:00
// this._unbindedPdfFields = $scope.pdfFields
2015-07-04 04:57:06 +00:00
// }
2015-07-03 23:47:14 +00:00
//PDF Functions
$scope.cancelUpload = function(){
2015-08-21 00:17:14 +00:00
this._current_upload.abort();
2015-07-03 23:47:14 +00:00
$scope.pdfLoading = false;
$scope.removePDF();
};
$scope.removePDF = function(){
$scope.myform.pdf = null;
$scope.myform.isGenerated = false;
$scope.myform.autofillPDFs = false;
2015-07-03 23:47:14 +00:00
console.log('form.pdf: '+$scope.myform.pdf+' REMOVED');
2015-07-03 23:47:14 +00:00
};
2016-04-29 02:48:02 +00:00
$scope.uploadPDF = function(file) {
2015-07-03 23:47:14 +00:00
2016-04-29 02:48:02 +00:00
if (file) {
2015-07-27 18:11:43 +00:00
console.log(file);
2016-04-29 02:48:02 +00:00
Upload.upload({
2015-07-03 23:47:14 +00:00
url: '/upload/pdf',
2016-04-29 02:48:02 +00:00
data: {
2015-07-03 23:47:14 +00:00
'user': $scope.user,
2016-04-29 02:48:02 +00:00
file: file
}
}).then(function (resp) {
var data = resp.data;
$scope.log = 'file ' + data.originalname + ' uploaded as ' + data.filename + '. JSON: ' + JSON.stringify(data) + '\n' + $scope.log;
$scope.myform.pdf = angular.fromJson(angular.toJson(data));
2015-07-27 18:11:43 +00:00
2016-04-29 02:48:02 +00:00
//console.log($scope.myform.pdf);
$scope.pdfLoading = false;
2015-07-03 23:47:14 +00:00
2016-04-29 02:48:02 +00:00
console.log($scope.log);
if (!$scope.$$phase && !$scope.$digest) {
$scope.$apply();
}
}, function(resp){
2015-07-03 23:47:14 +00:00
$scope.pdfLoading = false;
console.log('Error occured during upload.\n');
2016-04-29 02:48:02 +00:00
console.log(resp.status);
}, function (evt) {
2016-04-29 06:00:41 +00:00
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total, 10);
2016-04-29 02:48:02 +00:00
$scope.log = 'progress: ' + progressPercentage + '% ' +
evt.config.data.file.name + '\n' + $scope.log;
console.log($scope.log);
$scope.pdfLoading = true;
});
2015-07-03 23:47:14 +00:00
}
};
}
};
}
2016-04-29 02:48:02 +00:00
]);