forked from ansible/awx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53c6248
commit cc8b5bc
Showing
7 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const templateUrl = require('~components/input/file.partial.html'); | ||
|
||
function atInputFileLink (scope, element, attrs, controllers) { | ||
const formController = controllers[0]; | ||
const inputController = controllers[1]; | ||
|
||
if (scope.tab === '1') { | ||
element.find('input')[0].focus(); | ||
} | ||
|
||
inputController.init(scope, element, formController); | ||
} | ||
|
||
function AtInputFileController (baseInputController, eventService) { | ||
const vm = this || {}; | ||
|
||
let input; | ||
let scope; | ||
|
||
vm.init = (_scope_, element, form) => { | ||
baseInputController.call(vm, 'input', _scope_, element, form); | ||
|
||
scope = _scope_; | ||
[input] = element.find('input'); | ||
|
||
vm.listeners = vm.setFileListeners(input); | ||
|
||
vm.check(); | ||
}; | ||
|
||
vm.onButtonClick = () => { | ||
if (scope.state._value) { | ||
vm.removeFile(); | ||
} else { | ||
input.click(); | ||
} | ||
}; | ||
|
||
vm.setFileListeners = inputEl => eventService.addListeners([ | ||
[inputEl, 'change', event => vm.handleFileChangeEvent(inputEl, event)] | ||
]); | ||
|
||
vm.handleFileChangeEvent = (element, event) => { | ||
if (element.files.length > 0) { | ||
const reader = new FileReader(); | ||
|
||
reader.onload = () => vm.readFile(reader, event); | ||
reader.readAsText(element.files[0]); | ||
} else { | ||
scope.$apply(vm.removeFile); | ||
} | ||
}; | ||
|
||
vm.readFile = (reader, event) => { | ||
scope.$apply(() => { | ||
scope.state._value = reader.result; | ||
scope.state._displayValue = event.target.files[0].name; | ||
|
||
vm.check(); | ||
}); | ||
}; | ||
|
||
vm.removeFile = () => { | ||
delete scope.state._value; | ||
delete scope.state._displayValue; | ||
|
||
input.value = ''; | ||
}; | ||
} | ||
|
||
AtInputFileController.$inject = [ | ||
'BaseInputController', | ||
'EventService' | ||
]; | ||
|
||
function atInputFile () { | ||
return { | ||
restrict: 'E', | ||
transclude: true, | ||
replace: true, | ||
require: ['^^atForm', 'atInputFile'], | ||
templateUrl, | ||
controller: AtInputFileController, | ||
controllerAs: 'vm', | ||
link: atInputFileLink, | ||
scope: { | ||
state: '=', | ||
col: '@', | ||
tab: '@' | ||
} | ||
}; | ||
} | ||
|
||
export default atInputFile; |
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,25 @@ | ||
<div class="col-sm-{{::col}} at-InputContainer"> | ||
<div class="form-group at-u-flat"> | ||
<at-input-label></at-input-label> | ||
<input class="at-InputFile--hidden" type="file"/> | ||
<div class="input-group"> | ||
<span class="input-group-btn"> | ||
<button class="btn at-ButtonHollow--default at-Input-button" | ||
ng-disabled="state._disabled || form.disabled" | ||
ng-click="vm.onButtonClick()"> | ||
<i class="fa fa-folder-open" ng-if="!state._value"></i> | ||
<i class="fa fa-trash" ng-if="state._value"></i> | ||
</button> | ||
</span> | ||
<input class="form-control at-Input" | ||
type="text" | ||
ng-class="{ 'at-Input--rejected': state._rejected }" | ||
ng-model="state._displayValue" | ||
ng-attr-tabindex="{{ tab || undefined }}" | ||
ng-attr-placeholder="{{ state._disabled ? '' : vm.strings.get('file.PLACEHOLDER') }}" | ||
ng-disabled="state._disabled || form.disabled" | ||
readonly/> | ||
</div> | ||
<at-input-message></at-input-message> | ||
</div> | ||
</div> |
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