2015-07-15 15:52:27 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
propTypes: {
|
|
|
|
onValueChanged: React.PropTypes.func,
|
2015-09-16 16:18:25 +03:00
|
|
|
initialValue: React.PropTypes.string,
|
|
|
|
label: React.PropTypes.string,
|
|
|
|
placeHolder: React.PropTypes.string,
|
2015-07-15 15:52:27 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
Phases: {
|
|
|
|
Display: "display",
|
|
|
|
Edit: "edit",
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
onValueChanged: function() {},
|
2015-09-16 16:18:25 +03:00
|
|
|
initialValue: '',
|
|
|
|
label: 'Click to set',
|
|
|
|
placeholder: '',
|
2015-07-15 15:52:27 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2015-09-16 16:18:25 +03:00
|
|
|
value: this.props.initialValue,
|
2015-07-15 15:52:27 +03:00
|
|
|
phase: this.Phases.Display,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-09-16 16:18:25 +03:00
|
|
|
componentWillReceiveProps: function(nextProps) {
|
|
|
|
this.setState({
|
|
|
|
value: nextProps.initialValue
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-07-15 15:52:27 +03:00
|
|
|
getValue: function() {
|
|
|
|
return this.state.value;
|
|
|
|
},
|
|
|
|
|
2015-09-16 16:18:25 +03:00
|
|
|
setValue: function(val, shouldSubmit, suppressListener) {
|
|
|
|
var self = this;
|
2015-07-15 15:52:27 +03:00
|
|
|
this.setState({
|
|
|
|
value: val,
|
|
|
|
phase: this.Phases.Display,
|
2015-09-16 16:18:25 +03:00
|
|
|
}, function() {
|
|
|
|
if (!suppressListener) {
|
|
|
|
self.onValueChanged(shouldSubmit);
|
|
|
|
}
|
2015-07-15 15:52:27 +03:00
|
|
|
});
|
2015-09-16 16:18:25 +03:00
|
|
|
},
|
2015-07-15 15:52:27 +03:00
|
|
|
|
2015-09-16 16:18:25 +03:00
|
|
|
edit: function() {
|
|
|
|
this.setState({
|
|
|
|
phase: this.Phases.Edit,
|
|
|
|
});
|
2015-07-15 15:52:27 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
cancelEdit: function() {
|
|
|
|
this.setState({
|
|
|
|
phase: this.Phases.Display,
|
|
|
|
});
|
2015-09-16 16:18:25 +03:00
|
|
|
this.onValueChanged(false);
|
2015-07-15 15:52:27 +03:00
|
|
|
},
|
|
|
|
|
2015-09-16 16:18:25 +03:00
|
|
|
onValueChanged: function(shouldSubmit) {
|
|
|
|
this.props.onValueChanged(this.state.value, shouldSubmit);
|
2015-07-15 15:52:27 +03:00
|
|
|
},
|
|
|
|
};
|