Blame view

imports/client/views/org/admin/staff/UploadCsvStaff.js 2.83 KB
dbafa68d2   Deepak   added teachers mo...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  // import {UploadCsv } from '/imports/collections/students/UploadCsv'
  import _                                  from 'lodash';
  import { Meteor }                         from 'meteor/meteor';
  
  import React, { Component }               from 'react';
  import { Link,browserHistory }            from 'react-router';
  import { FormGroup,Panel,Table,
    ButtonToolbar,Modal,ControlLabel,HelpBlock,
    FormControl,Glyphicon,Button }          from 'react-bootstrap';
  // import { AddStudentForm }                 from './addStudentForm';
  import { FilesCollection } from 'meteor/ostrio:files';
  const Papa = this.Papa;
  // console.log(this);
  const style = {
    margin: 12,
  };
  function FieldGroup({ id, label, help, ...props }) {
    return (
      <FormGroup controlId={id}>
        <ControlLabel>{label}</ControlLabel>
        <FormControl {...props} />
        {help && <HelpBlock>{help}</HelpBlock>}
      </FormGroup>
    );
  }
82e73280a   Deepak   changed remaining...
26
  export class UploadCsvStaff extends Component {
dbafa68d2   Deepak   added teachers mo...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    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});
    };
7ca753f37   Deepak   added staff uploa...
47
    uploadStaffCsv(e){
dbafa68d2   Deepak   added teachers mo...
48
49
50
51
52
53
54
55
56
      e.preventDefault();
      e.persist();
      var file = $('input[type="file"]').prop("files")[0];
      Papa.parse(file, {
        header: true,
      	complete: function(csvData) {
          console.log("csvData");
          console.log(csvData);
      		if(csvData){
7ca753f37   Deepak   added staff uploa...
57
            Meteor.call('staff.uploadCsv', csvData, function (error, result) {
dbafa68d2   Deepak   added teachers mo...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
              console.log("error");
              console.log(error);
              console.log("result");
              console.log(result);
             })
          }
      	}
      });
    }
  
    render() {
      console.log(this.props);
      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>
925ffa9d3   Deepak   changed teachers ...
82
              <Modal.Title id="contained-modal-title-lg">Upload Csv</Modal.Title>
dbafa68d2   Deepak   added teachers mo...
83
84
            </Modal.Header>
            <Modal.Body>
7ca753f37   Deepak   added staff uploa...
85
            <form onSubmit={ (e) => this.uploadStaffCsv(e) } >
dbafa68d2   Deepak   added teachers mo...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
            <FieldGroup
              id="formControlsFile"
              type="file"
              label="File"
              help="Upload you CSV here."
            />
            <Button type="submit" bsStyle="default">Upload File</Button>
            </form>
            </Modal.Body>
            <Modal.Footer>
              <Button onClick={this.hideModal}>Close</Button>
            </Modal.Footer>
          </Modal>
        </ButtonToolbar>
      );
    };
  
  };