zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import React from 'react';
import ErrorMessage from 'webodm/components/ErrorMessage';
import FormDialog from 'webodm/components/FormDialog';
import PropTypes from 'prop-types';
import $ from 'jquery';
 
class ShareDialog extends React.Component {
    static defaultProps = {
        task: null,
        taskInfo: null,
        title: "Share To OpenAerialMap",
        saveLabel: "Share",
        savingLabel: "Sharing...",
        saveIcon: "fa fa-share",
        show: false
    };
 
    static propTypes = {
        task: PropTypes.object.isRequired,
        taskInfo: PropTypes.object.isRequired,
        saveAction: PropTypes.func.isRequired,
        title: PropTypes.string,
        saveLabel: PropTypes.string,
        savingLabel: PropTypes.string,
        saveIcon: PropTypes.string,
        show: PropTypes.bool
    };
 
    constructor(props){
        super(props);
 
        this.state = this.getInitialState(props);
 
        this.reset = this.reset.bind(this);
        this.getFormData = this.getFormData.bind(this);
        this.onShow = this.onShow.bind(this);
        this.handleChange = this.handleChange.bind(this);
    }
 
    getInitialState = (props) => {
        return {
          sensor: props.taskInfo.sensor,
          startDate: this.toDatetimeLocal(new Date(props.taskInfo.startDate)),
          endDate: this.toDatetimeLocal(new Date(props.taskInfo.endDate)),
          title: props.taskInfo.title,
          provider: props.taskInfo.provider,
          tags: ""
        };
    }
 
    // Credits to https://gist.github.com/WebReflection/6076a40777b65c397b2b9b97247520f0
    toDatetimeLocal = (date) => {
        const ten = function (i) {
            return (i < 10 ? '0' : '') + i;
        };
 
        const YYYY = date.getFullYear(),
        MM = ten(date.getMonth() + 1),
        DD = ten(date.getDate()),
        HH = ten(date.getHours()),
        II = ten(date.getMinutes()),
        SS = ten(date.getSeconds())
 
        return YYYY + '-' + MM + '-' + DD + 'T' +
                 HH + ':' + II + ':' + SS;
    };
 
    reset(){
      this.setState(this.getInitialState(this.props));
    }
 
    getFormData(){
      return this.state;
    }
 
    onShow(){
      this.titleInput.focus();
    }
 
    show(){
      this.dialog.show();
    }
 
    hide(){
      this.dialog.hide();
    }
 
    handleChange(field){
      return (e) => {
        let state = {};
        state[field] = e.target.value;
        this.setState(state);
      }
    }
 
    render(){
        // TODO: tags are currently not being parsed properly
        // by the OAM endpoint, so we'll leave them out.
 
        return (
            <FormDialog {...this.props} 
                getFormData={this.getFormData} 
                reset={this.reset}
                ref={(domNode) => { this.dialog = domNode; }}>
              <div className="form-group">
                <label className="col-sm-3 control-label">Title</label>
                <div className="col-sm-9">
                  <input type="text" className="form-control" ref={(domNode) => { this.titleInput = domNode; }} value={this.state.title} onChange={this.handleChange('title')} />
                </div>
              </div>
              <div className="form-group">
                <label className="col-sm-3 control-label">Sensor</label>
                <div className="col-sm-9">
                  <input type="text" className="form-control" ref={(domNode) => { this.sensorInput = domNode; }} value={this.state.sensor} onChange={this.handleChange('sensor')} />
                </div>
              </div>
              <div className="form-group">
                <label className="col-sm-3 control-label">Provider</label>
                <div className="col-sm-9">
                  <input type="text" className="form-control" ref={(domNode) => { this.providerInput = domNode; }} value={this.state.provider} onChange={this.handleChange('provider')} />
                </div>
              </div>
              <div className="form-group">
                <label className="col-sm-3 control-label">Flight Start Date</label>
                <div className="col-sm-9">
                  <input type="datetime-local" className="form-control" ref={(domNode) => { this.startDateInput = domNode; }} value={this.state.startDate} onChange={this.handleChange('startDate')} />
                </div>
              </div>
              <div className="form-group">
                <label className="col-sm-3 control-label">Flight End Date</label>
                <div className="col-sm-9">
                  <input type="datetime-local" className="form-control" ref={(domNode) => { this.endDateInput = domNode; }} value={this.state.endDate} onChange={this.handleChange('endDate')} />
                </div>
              </div>
{/*              <div className="form-group">
                <label className="col-sm-3 control-label">Tags (comma separated)</label>
                <div className="col-sm-9">
                  <input type="text" className="form-control" ref={(domNode) => { this.tagsInput = domNode; }} value={this.state.tags} onChange={this.handleChange('tags')} />
                </div>
              </div>*/}
            </FormDialog>
        );
    }
}
 
export default ShareDialog;