Blame view
imports/client/views/org/admin/students/UploadCsv.js
2.55 KB
15998a6af
|
1 2 3 4 5 6 |
import _ from 'lodash'; import { Meteor } from 'meteor/meteor'; import React, { Component } from 'react'; import { Link,browserHistory } from 'react-router'; import { FormGroup,Panel,Table, |
b02441289
|
7 |
ButtonToolbar,Modal,ControlLabel,HelpBlock, |
15998a6af
|
8 |
FormControl,Glyphicon,Button } from 'react-bootstrap'; |
b02441289
|
9 |
// import { AddStudentForm } from './addStudentForm'; |
f3432726e
|
10 11 12 |
import { FilesCollection } from 'meteor/ostrio:files'; const Papa = this.Papa; // console.log(this); |
15998a6af
|
13 14 15 |
const style = { margin: 12, }; |
b02441289
|
16 17 18 19 20 21 22 23 24 |
function FieldGroup({ id, label, help, ...props }) { return ( <FormGroup controlId={id}> <ControlLabel>{label}</ControlLabel> <FormControl {...props} /> {help && <HelpBlock>{help}</HelpBlock>} </FormGroup> ); } |
15998a6af
|
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
export class UploadCsv extends Component { constructor(props) { super(props); this.state = { show: false }; this.showModal = this.showModal.bind(this); this.hideModal = this.hideModal.bind(this); this.onUpdate = this.onUpdate.bind(this); }; showModal() { this.setState({show: true}); } hideModal() { this.setState({show: false}); } onUpdate(key, value) { this.setState({[key]: value}); }; |
d0a93cc6d
|
46 47 48 |
uploadStudentCsv(e){ e.preventDefault(); e.persist(); |
f3432726e
|
49 50 51 52 53 |
var file = $('input[type="file"]').prop("files")[0]; Papa.parse(file, { complete: function(results) { if(results){ Meteor.call('student.uploadCsv', csvData, function (error, result) { |
d0a93cc6d
|
54 |
|
f3432726e
|
55 56 57 58 |
}) } } }); |
d0a93cc6d
|
59 |
} |
15998a6af
|
60 61 |
render() { |
b02441289
|
62 |
console.log(this.props); |
15998a6af
|
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
return ( <ButtonToolbar> <Button bsStyle="primary" onClick={this.showModal}> Upload CSV </Button> <Modal {...this.props} show={this.state.show} onHide={this.hideModal} dialogClassName="custom-modal" > <Modal.Header closeButton> <Modal.Title id="contained-modal-title-lg">New Student</Modal.Title> </Modal.Header> <Modal.Body> |
d0a93cc6d
|
78 |
<form onSubmit={ (e) => this.uploadStudentCsv(e) } > |
15998a6af
|
79 80 81 82 |
<FieldGroup id="formControlsFile" type="file" label="File" |
d5b679c21
|
83 |
help="Upload you CSV here." |
15998a6af
|
84 |
/> |
d0a93cc6d
|
85 |
<Button type="submit" bsStyle="default">Upload File</Button> |
b02441289
|
86 |
</form> |
15998a6af
|
87 88 89 90 91 92 93 94 95 96 |
</Modal.Body> <Modal.Footer> <Button onClick={this.hideModal}>Close</Button> </Modal.Footer> </Modal> </ButtonToolbar> ); }; }; |