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 02:49:35 +00:00
|
|
|
// view form submissions
|
|
|
|
$scope.viewSubmissions = false;
|
|
|
|
|
|
|
|
//show submissions of Form
|
|
|
|
$scope.showSubmissions = function(){
|
|
|
|
$scope.viewSubmissions = true;
|
|
|
|
}
|
|
|
|
//hide submissions of Form
|
|
|
|
$scope.hideSubmissions = function(){
|
|
|
|
$scope.viewSubmissions = false;
|
|
|
|
}
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
// Return all user's Forms
|
2015-06-30 08:54:00 +00:00
|
|
|
$scope.findAll = function() {
|
2015-06-29 22:51:29 +00:00
|
|
|
$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
|
2015-07-02 02:49:35 +00:00
|
|
|
$scope.remove = function() {
|
2015-07-02 03:50:57 +00:00
|
|
|
console.log('hello');
|
|
|
|
var form = CurrentForm.getForm()
|
|
|
|
if(!form){
|
|
|
|
form = $scope.form
|
|
|
|
}
|
|
|
|
$http.delete('/forms/'+$scope.form._id)
|
|
|
|
.success(function(data, status, headers){
|
2015-06-29 22:51:29 +00:00
|
|
|
console.log('form deleted successfully');
|
|
|
|
alert('Form deleted..');
|
|
|
|
$state.go('listForms');
|
2015-07-02 03:50:57 +00:00
|
|
|
}).error(function(error){
|
|
|
|
console.log('ERROR: Form could not be deleted.');
|
|
|
|
console.error(error);
|
2015-06-29 22:51:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
]);
|