Guest User

Untitled

a guest
Nov 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. // Import
  2. import React, { Component } from 'react';
  3. import {connect} from 'react-redux';
  4. import * as actions from '../actions';
  5. import Dialog from 'material-ui/Dialog'
  6. import FlatButton from 'material-ui/FlatButton';
  7. import IconButton from 'material-ui/IconButton';
  8. import LinearProgress from 'material-ui/LinearProgress';
  9. import ActionBackup from 'material-ui/svg-icons/action/backup';
  10. import * as Styles from '../constants/Styles';
  11.  
  12. class Uploader extends Component {
  13. _clearUploader(e){
  14. if(e) e.preventDefault();
  15. this.props.dispatch(actions.toggleUploader(null));
  16. }
  17. _upload(){
  18. this.props.dispatch(actions.upload('PDF', documents.bucket, this.file));
  19. }
  20. _openSelectorFile(e){
  21. if(e) e.preventDefault();
  22. this.inputFile.click();
  23. }
  24. _selectFile(e){
  25. e.preventDefault();
  26. this.file = this.inputFile.files[0];
  27. this._upload();
  28. }
  29. _dropFile(e){
  30. e.preventDefault();
  31. e.stopPropagation();
  32. this.file = e.dataTransfer.files[0];
  33. this._upload();
  34. }
  35. _handleDragOver(e){
  36. e.stopPropagation();
  37. e.preventDefault();
  38. e.dataTransfer.dropEffect = 'copy';
  39. }
  40. render() {
  41. const {documents} = this.props;
  42. const uploadActions = [
  43. <FlatButton label="Cancelar" primary={true} className="buttonsecondary" onTouchTap={this._clearUploader.bind(this)} />
  44. ]
  45. return (
  46. <Dialog title="Subir Documento"
  47. actions={uploadActions}
  48. modal={true}
  49. open={documents.document_type !== null}>
  50. <div className="row middle-xs center-xs">
  51. <div className="col-xs-12">
  52. <div ref={(dropzone) => {this.dropzone = dropzone}}
  53. onTouchTap={this._openSelectorFile.bind(this)}
  54. onDrop={this._dropFile.bind(this)}
  55. onDragOver={this._handleDragOver.bind(this)}
  56. style={Styles.Dropzone}>
  57. <input hidden
  58. type="file"
  59. ref={(input) => {this.inputFile = input}}
  60. accept="application/pdf"
  61. onChange={this._selectFile.bind(this)}/>
  62. <label>Arrastra tu archivo aquí o seleccionalo desde tu computadora.</label>
  63. <br />
  64. <IconButton
  65. tooltip="Selecciona tu archivo dando clic aquí"
  66. iconStyle={Styles.Dropzone.IconButton}>
  67. <ActionBackup color={Styles.Dropzone.ActionBackup.color} />
  68. </IconButton>
  69. <LinearProgress mode="determinate" value={documents.current_progress} />
  70. </div>
  71. </div>
  72. </div>
  73. </Dialog>
  74. );
  75. }
  76. }
  77. // Export
  78. function mapStateToProps(state, ownProps){
  79. return { documents: state.Documents }
  80. }
  81.  
  82. export default connect(mapStateToProps)(Uploader)
Add Comment
Please, Sign In to add comment