Created
February 11, 2017 21:28
-
-
Save binnyg/5fd57ee814c8584653203dd01cc981ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular | |
.module('loanDoxApp') | |
.controller('DocumentDialogController', DocumentDialogController); | |
DocumentDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$uibModalInstance', 'entity', 'Document', 'Exam']; | |
function DocumentDialogController ($timeout, $scope, $stateParams, $uibModalInstance, entity, Document, Exam) { | |
var vm = this; | |
vm.document = entity; | |
vm.clear = clear; | |
vm.save = save; | |
vm.exams = Exam.query(); | |
$timeout(function (){ | |
angular.element('.form-group:eq(1)>input').focus(); | |
}); | |
function clear () { | |
$uibModalInstance.dismiss('cancel'); | |
} | |
function save () { | |
vm.isSaving = true; | |
if (vm.document.id !== null) { | |
Document.update(vm.document, onSaveSuccess, onSaveError); | |
} else { | |
Document.save(vm.document, onSaveSuccess, onSaveError); | |
} | |
} | |
function onSaveSuccess (result) { | |
$scope.$emit('loanDoxApp:documentUpdate', result); | |
$uibModalInstance.close(result); | |
vm.isSaving = false; | |
} | |
function onSaveError () { | |
vm.isSaving = false; | |
} | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form name="editForm" role="form" novalidate ng-submit="vm.save()"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" | |
ng-click="vm.clear()">×</button> | |
<h4 class="modal-title" id="myDocumentLabel" data-translate="loanDoxApp.document.home.createOrEditLabel">Create or edit a Document</h4> | |
</div> | |
<div class="modal-body"> | |
<jhi-alert-error></jhi-alert-error> | |
<div class="form-group" ng-show="vm.document.id"> | |
<label for="id" data-translate="global.field.id">ID</label> | |
<input type="text" class="form-control" id="id" name="id" | |
ng-model="vm.document.id" readonly /> | |
</div> | |
<div class="form-group"> | |
<label class="control-label" data-translate="loanDoxApp.document.name" for="field_name">Name</label> | |
<input type="text" class="form-control" name="name" id="field_name" | |
ng-model="vm.document.name" | |
/> | |
</div> | |
<div class="form-group"> | |
<label class="control-label" data-translate="loanDoxApp.document.mimeType" for="field_mimeType">Mime Type</label> | |
<input type="text" class="form-control" name="mimeType" id="field_mimeType" | |
ng-model="vm.document.mimeType" | |
/> | |
</div> | |
<div class="form-group"> | |
<label class="control-label" data-translate="loanDoxApp.document.size" for="field_size">Size</label> | |
<input type="text" class="form-control" name="size" id="field_size" | |
ng-model="vm.document.size" | |
/> | |
</div> | |
<div class="form-group"> | |
<label class="control-label" data-translate="loanDoxApp.document.note" for="field_note">Note</label> | |
<input type="text" class="form-control" name="note" id="field_note" | |
ng-model="vm.document.note" | |
/> | |
</div> | |
<div class="form-group"> | |
<label data-translate="loanDoxApp.document.exam" for="field_exam">Exam</label> | |
<select class="form-control" id="field_exam" name="exam" ng-model="vm.document.exam" ng-options="exam as exam.id for exam in vm.exams track by exam.id"> | |
<option value=""></option> | |
</select> | |
</div> | |
<div class="form-group"> | |
<label class="control-label" data-translate="loanDoxApp.document.file" for="field_examFile">Exam</label> | |
<input type="file" id="field_examFile" ngf-select ng-model="vm.document.examFile" name="file" | |
accept="image/*" ngf-max-size="2MB" required | |
ngf-model-invalid="errorFile"> | |
</div> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="vm.clear()"> | |
<span class="glyphicon glyphicon-ban-circle"></span> <span data-translate="entity.action.cancel">Cancel</span> | |
</button> | |
<button type="submit" ng-disabled="editForm.$invalid || vm.isSaving" class="btn btn-primary"> | |
<span class="glyphicon glyphicon-save"></span> <span data-translate="entity.action.save">Save</span> | |
</button> | |
</div> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular | |
.module('loanDoxApp') | |
.factory('Document', Document); | |
Document.$inject = ['$resource']; | |
function Document ($resource) { | |
var resourceUrl = 'api/documents/:id'; | |
return $resource(resourceUrl, {}, { | |
'query': { method: 'GET', isArray: true}, | |
'get': { | |
method: 'GET', | |
transformResponse: function (data) { | |
if (data) { | |
data = angular.fromJson(data); | |
} | |
return data; | |
} | |
}, | |
'update': { method:'PUT' } | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment