This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
forked from 18F/dol-whd-14c
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from AppliedIS/feature-attachmentcomponent
add component for uploading attachments
- Loading branch information
Showing
8 changed files
with
74 additions
and
34 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
DOL.WHD.Section14c.Web/src/modules/components/attachmentField/attachmentFieldController.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
module.exports = function(ngModule) { | ||
ngModule.controller('attachmentFieldController', function($scope, apiService, stateService) { | ||
'ngInject'; | ||
'use strict'; | ||
|
||
var vm = this; | ||
vm.attachmentApiURL = apiService.attachmentApiURL + stateService.ein; | ||
vm.access_token = stateService.access_token; | ||
|
||
this.onAttachmentSelected = function(fileinput) { | ||
if(fileinput.files.length > 0){ | ||
apiService.uploadAttachment(stateService.access_token, stateService.ein, fileinput.files[0]).then(function (result){ | ||
$scope.attachmentId = result.data[0].id; | ||
$scope.attachmentName = result.data[0].originalFileName; | ||
fileinput.value = ''; | ||
}, function(error){ | ||
//TODO: Display error | ||
fileinput.value = ''; | ||
}) | ||
} | ||
}; | ||
|
||
this.deleteAttachment = function(id){ | ||
apiService.deleteAttachment(stateService.access_token, stateService.ein, id).then(function (result){ | ||
$scope.attachmentId = undefined; | ||
$scope.attachmentName = undefined; | ||
}, function(error){ | ||
//TODO: Display error | ||
$scope.attachmentId = undefined; | ||
$scope.attachmentName = undefined; | ||
}) | ||
}; | ||
}); | ||
} |
19 changes: 19 additions & 0 deletions
19
DOL.WHD.Section14c.Web/src/modules/components/attachmentField/attachmentFieldDirective.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
module.exports = function(ngModule) { | ||
ngModule.directive('attachmentField', function() { | ||
|
||
'use strict'; | ||
|
||
return { | ||
restrict: 'EA', | ||
template: require('./attachmentFieldTemplate.html'), | ||
controller: 'attachmentFieldController', | ||
scope: { | ||
attachmentId: '=', | ||
attachmentName: '=' | ||
}, | ||
controllerAs: 'vm' | ||
}; | ||
}); | ||
} |
9 changes: 9 additions & 0 deletions
9
DOL.WHD.Section14c.Web/src/modules/components/attachmentField/attachmentFieldTemplate.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div ng-show="attachmentId == undefined"> | ||
<input id="{{::$id}}_FileUpload" class="upload-file-input" type="file" ng-hide="true" onchange="angular.element(this).scope().vm.onAttachmentSelected(this)" accept=".doc,.docx,.xls,.xlsx,.pdf,.jpg,.jpeg,.png"> | ||
<label for="{{::$id}}_FileUpload" class="upload-label usa-button-primary">Browse</label><input id="{{::$id}}" name="{{::$id}}" class="upload-input" type="text" disabled> | ||
<label class="underlabel" for="{{::$id}}">File types accepted: PDF, Word, Excel, JPG, PNG</label> | ||
</div> | ||
<div ng-show="attachmentId != undefined"> | ||
<a ng-href="{{vm.attachmentApiURL}}/{{scaAttachmentId}}?access_token={{vm.access_token}}">{{attachmentName}}</a> | ||
<button class="usa-button-secondary" ng-click="vm.deleteAttachment(attachmentId)">Delete</button> | ||
</div> |
6 changes: 6 additions & 0 deletions
6
DOL.WHD.Section14c.Web/src/modules/components/attachmentField/index.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = function(ngModule) { | ||
require('./attachmentFieldController')(ngModule); | ||
require('./attachmentFieldDirective')(ngModule); | ||
}; |
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
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
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
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