Blame view

imports/ui/components/document.js 1.65 KB
f0c912bf1   tmcdeveloper   add method tests ...
1
  import React from 'react';
cac7cbc73   tmcdeveloper   4.1.0 release
2
3
  import { Row, Col, ListGroupItem, FormControl, Button } from 'react-bootstrap';
  import { Bert } from 'meteor/themeteorchef:bert';
f0c912bf1   tmcdeveloper   add method tests ...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  import { updateDocument, removeDocument } from '../../api/documents/methods.js';
  
  const handleUpdateDocument = (documentId, event) => {
    const title = event.target.value.trim();
    if (title !== '' && event.keyCode === 13) {
      updateDocument.call({
        _id: documentId,
        update: { title },
      }, (error) => {
        if (error) {
          Bert.alert(error.reason, 'danger');
        } else {
          Bert.alert('Document updated!', 'success');
        }
      });
    }
  };
  
  const handleRemoveDocument = (documentId, event) => {
    event.preventDefault();
cac7cbc73   tmcdeveloper   4.1.0 release
24
25
26
    // this should be replaced with a styled solution so for now we will
    // disable the eslint `no-alert`
    // eslint-disable-next-line no-alert
f0c912bf1   tmcdeveloper   add method tests ...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    if (confirm('Are you sure? This is permanent.')) {
      removeDocument.call({
        _id: documentId,
      }, (error) => {
        if (error) {
          Bert.alert(error.reason, 'danger');
        } else {
          Bert.alert('Document removed!', 'success');
        }
      });
    }
  };
  
  export const Document = ({ document }) => (
    <ListGroupItem key={ document._id }>
      <Row>
        <Col xs={ 8 } sm={ 10 }>
cac7cbc73   tmcdeveloper   4.1.0 release
44
          <FormControl
f0c912bf1   tmcdeveloper   add method tests ...
45
            type="text"
f0c912bf1   tmcdeveloper   add method tests ...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
            defaultValue={ document.title }
            onKeyUp={ handleUpdateDocument.bind(this, document._id) }
          />
        </Col>
        <Col xs={ 4 } sm={ 2 }>
          <Button
            bsStyle="danger"
            className="btn-block"
            onClick={ handleRemoveDocument.bind(this, document._id) }>
            Remove
          </Button>
        </Col>
      </Row>
    </ListGroupItem>
  );