tellform/public/modules/forms/controllers/view-form.client.controller.js

76 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-06-29 22:51:29 +00:00
'use strict';
// Forms controller
2015-06-30 16:15:16 +00:00
angular.module('forms').controller('ViewFormController', ['$scope', '$stateParams', '$state', 'Forms', 'CurrentForm','$http',
function($scope, $stateParams, $state, Forms, CurrentForm, $http) {
2015-06-29 22:51:29 +00:00
2015-07-02 04:54:46 +00:00
// view form submissions
$scope.form = CurrentForm.getForm();
$scope.submissions = undefined;
$scope.viewSubmissions = false;
2015-07-02 02:49:35 +00:00
2015-06-29 22:51:29 +00:00
2015-07-02 04:54:46 +00:00
//show submissions of Form
$scope.showSubmissions = function(){
$scope.viewSubmissions = true;
if(!$scope.submissions){
$http.get('/forms/'+$scope.form._id+'/submissions')
2015-07-02 03:50:57 +00:00
.success(function(data, status, headers){
2015-07-02 04:54:46 +00:00
console.log(data);
$scope.submissions = data;
console.log('form submissions successfully fetched');
})
.error(function(err){
console.log('Could not fetch form submissions.\nError: '+err);
});
} else if(!$scope.submissions.length){
$http.get('/forms/'+$scope.form._id+'/submissions')
.success(function(data, status, headers){
$scope.submissions = data;
console.log('form submissions successfully fetched');
})
.error(function(err){
console.log('Could not fetch form submissions.\nError: '+err);
2015-06-29 22:51:29 +00:00
});
2015-07-02 04:54:46 +00:00
}
console.log($scope.submissions);
}
2015-06-29 22:51:29 +00:00
2015-07-02 04:54:46 +00:00
//hide submissions of Form
$scope.hideSubmissions = function(){
$scope.viewSubmissions = false;
}
// Return all user's Forms
$scope.findAll = function() {
$scope.forms = Forms.query();
};
// Find a specific Form
$scope.findOne = function() {
$scope.form = Forms.get({
formId: $stateParams.formId
});
CurrentForm.setForm($scope.form);
};
// Remove existing Form
$scope.remove = function() {
console.log('hello');
var form = CurrentForm.getForm()
if(!form){
form = $scope.form
}
$http.delete('/forms/'+$scope.form._id)
.success(function(data, status, headers){
console.log('form deleted successfully');
alert('Form deleted..');
$state.go('listForms');
}).error(function(error){
console.log('ERROR: Form could not be deleted.');
console.error(error);
});
2015-06-29 22:51:29 +00:00
2015-07-02 04:54:46 +00:00
};
2015-06-29 22:51:29 +00:00
}
]);