@andersonalmeidax0/webcomponents 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -0
- package/XButton.jsx +56 -0
- package/XCheckbox.jsx +22 -0
- package/XDateSelect.jsx +22 -0
- package/XInput.jsx +140 -0
- package/XSelect.jsx +59 -0
- package/XTextArea.jsx +31 -0
- package/jzcomponents/ErrorCard.jsx +18 -0
- package/jzcomponents/ErrorCardAuth.jsx +15 -0
- package/jzcomponents/Errors.js +41 -0
- package/jzcomponents/JZEditComponent.jsx +173 -0
- package/jzcomponents/JZInPlaceListComponent.jsx +95 -0
- package/jzcomponents/JZListComponent.jsx +305 -0
- package/jzcomponents/XFormEdit.jsx +105 -0
- package/jzcomponents/XTableRead.jsx +271 -0
- package/package.json +19 -0
- package/releasenotes.txt +37 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {XButton} from "../XButton.jsx"
|
|
3
|
+
import {XInputExternal} from "../XInput.jsx"
|
|
4
|
+
import {XSelect3} from "../XSelect"
|
|
5
|
+
import {XTextArea} from "../XTextArea"
|
|
6
|
+
import {XCheckbox} from "../XCheckbox.jsx"
|
|
7
|
+
import {XDateSelect} from "../XDateSelect.jsx"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
import { XTableRead } from "./XTableRead.jsx";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const DEBUG_ID=false;
|
|
14
|
+
const DEBUG_ID2=DEBUG_ID;
|
|
15
|
+
const DEBUG_ID3=false;
|
|
16
|
+
const DEBUGAPICALL_UTIL=false;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/* ************************************************** */
|
|
22
|
+
// Usa XTableRead !!!!!!!!!!!!!
|
|
23
|
+
// PROPS:
|
|
24
|
+
// list
|
|
25
|
+
// newItemFN: funcao para criar novo objeto
|
|
26
|
+
// listConfig => config de list
|
|
27
|
+
//
|
|
28
|
+
/* ************************************************** */
|
|
29
|
+
class JZInPlaceListComponent extends React.Component {
|
|
30
|
+
constructor() {
|
|
31
|
+
super()
|
|
32
|
+
//this.state = {
|
|
33
|
+
// list: null,
|
|
34
|
+
// message:"",
|
|
35
|
+
//};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
componentDidMount() {
|
|
39
|
+
//this.evtRefresh();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* VIEW METHODS *************************************************************************** */
|
|
43
|
+
/* ******** ####################### ********** */
|
|
44
|
+
evtRefresh = ()=> {
|
|
45
|
+
//this.setState({list:this.state.list});
|
|
46
|
+
this.forceUpdate();
|
|
47
|
+
}
|
|
48
|
+
/* ******** ####################### ********** */
|
|
49
|
+
evtCreate = () => {
|
|
50
|
+
var obj = this.props.newItemFN();
|
|
51
|
+
obj.isInserted=true;
|
|
52
|
+
this.props.list.push(obj)
|
|
53
|
+
this.evtRefresh();
|
|
54
|
+
}
|
|
55
|
+
/* ******** ####################### ********** */
|
|
56
|
+
evtActionDelete = async (i,item) => {
|
|
57
|
+
this.props.list[i].isDeleted=true;
|
|
58
|
+
this.evtRefresh();
|
|
59
|
+
}
|
|
60
|
+
/* ******** ####################### ********** */
|
|
61
|
+
render() {
|
|
62
|
+
|
|
63
|
+
if(this.props.list)
|
|
64
|
+
return (
|
|
65
|
+
<React.Fragment>
|
|
66
|
+
{<React.Fragment>
|
|
67
|
+
{this.props.listConfig.hasInsert&&<XButton label={'Novo_'+this.props._id} id={'Novo_'+this.props._id} textlabel={(this.props.textlabels)?"New":null} icon="fa fa-plus" onClick={this.evtCreate}/>}<span> </span>
|
|
68
|
+
|
|
69
|
+
{<XTableRead
|
|
70
|
+
id={this.props._id}
|
|
71
|
+
metadata={this.props.listConfig}
|
|
72
|
+
list={this.props.list}
|
|
73
|
+
noEdit={true}
|
|
74
|
+
inPlaceEdit={true}
|
|
75
|
+
noDelete={this.props.listConfig.noDelete}
|
|
76
|
+
onDelete={this.evtActionDelete}
|
|
77
|
+
textlabels={this.props.textlabels}
|
|
78
|
+
/>}
|
|
79
|
+
</React.Fragment>}
|
|
80
|
+
</React.Fragment>
|
|
81
|
+
)
|
|
82
|
+
else
|
|
83
|
+
return (<p className="color--blue">Carregando lista...</p>);
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
export {JZInPlaceListComponent};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {XButton} from "../XButton.jsx"
|
|
3
|
+
import {XInputExternal} from "../XInput.jsx"
|
|
4
|
+
import {XSelect3} from "../XSelect"
|
|
5
|
+
import {XTextArea} from "../XTextArea"
|
|
6
|
+
import {XCheckbox} from "../XCheckbox.jsx"
|
|
7
|
+
import {XDateSelect} from "../XDateSelect.jsx"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
//import { withRouter } from 'react-router-dom';
|
|
11
|
+
|
|
12
|
+
import { XTableRead } from "./XTableRead.jsx";
|
|
13
|
+
import { XFormEdit } from "./XFormEdit.jsx";
|
|
14
|
+
import { JZEditComponent } from "./JZEditComponent.jsx";
|
|
15
|
+
import { JZInPlaceListComponent } from "./JZInPlaceListComponent.jsx";
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import {PlatAPIError,PlatAPIReturnCodeError,PlatAPIAuthError,PlatAPIDBNotFound,PlatAPIDBIntegrityConstraint,PlatAPIForbidden} from "./Errors.js";
|
|
19
|
+
import { ErrorCard } from "./ErrorCard";
|
|
20
|
+
import { ErrorCardAuth } from "./ErrorCardAuth";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
//para react v18 (mas nao funcionou, tive que fazer downgrade para react 17)
|
|
25
|
+
/*
|
|
26
|
+
import { useNavigate } from "react-router";
|
|
27
|
+
export const withRouter = (Component) => {
|
|
28
|
+
const Wrapper = (props) => {
|
|
29
|
+
const history = useNavigate();
|
|
30
|
+
return <Component history={history} {...props} />;
|
|
31
|
+
};
|
|
32
|
+
return Wrapper;
|
|
33
|
+
};
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const DEBUG_ID=false;
|
|
38
|
+
const DEBUG_ID2=DEBUG_ID;
|
|
39
|
+
const DEBUG_ID3=false;
|
|
40
|
+
const DEBUGAPICALL_UTIL=false;
|
|
41
|
+
|
|
42
|
+
/* ************************************************** */
|
|
43
|
+
// JZListComponentImpl (usa XTable) => o JZListComponent é withRouter
|
|
44
|
+
// PROPS:
|
|
45
|
+
// api => api de BP
|
|
46
|
+
// apiContext => context object (pass to api calls)
|
|
47
|
+
// listConfig => config de list
|
|
48
|
+
// customEditcomponent
|
|
49
|
+
// editConfig => congig de edit
|
|
50
|
+
// messengerMode => vira messenger!!!!!
|
|
51
|
+
// onSelectItem(vo) => callback quando seleciona para edicao ou insert
|
|
52
|
+
// 2 impls: com e sem router!!
|
|
53
|
+
/* ************************************************** */
|
|
54
|
+
class JZListComponentNoRouter extends React.Component {
|
|
55
|
+
constructor(props) {
|
|
56
|
+
super(props)
|
|
57
|
+
this.state = {
|
|
58
|
+
list: null,
|
|
59
|
+
filterStr:"",
|
|
60
|
+
isFiltered:false,
|
|
61
|
+
message:"",
|
|
62
|
+
showEditModal:false,
|
|
63
|
+
editMode:'I', //'I' insert ou 'U' update
|
|
64
|
+
editKey:null,
|
|
65
|
+
isLoading:false,
|
|
66
|
+
messageInput:'',
|
|
67
|
+
fileSelected:false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
componentDidMount() {
|
|
71
|
+
this.setState({isLoading:true});
|
|
72
|
+
if(this.props.messengerMode) {
|
|
73
|
+
this.interval = setInterval(() => {
|
|
74
|
+
this.setState({ time: Date.now() });
|
|
75
|
+
this.evtRefresh();
|
|
76
|
+
}
|
|
77
|
+
, 5*1000);
|
|
78
|
+
}
|
|
79
|
+
try{
|
|
80
|
+
if(this.props.id) {
|
|
81
|
+
//alert('directEdit');
|
|
82
|
+
this.setState({showEditModal:true,editMode:'U',editKey:this.props.id,exception:null});
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
this.evtRefresh();
|
|
86
|
+
}catch(error){
|
|
87
|
+
this.setState({exception:error});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
componentWillUnmount() {
|
|
91
|
+
if(this.props.messengerMode) {
|
|
92
|
+
clearInterval(this.interval);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* VIEW METHODS *************************************************************************** */
|
|
97
|
+
|
|
98
|
+
/* ******** ####################### ********** */
|
|
99
|
+
listModel2View = (list) => {
|
|
100
|
+
// precisa??
|
|
101
|
+
return list;
|
|
102
|
+
}
|
|
103
|
+
/* ******** ####################### ********** */
|
|
104
|
+
view2ListModel = (list) => {
|
|
105
|
+
// precisa??
|
|
106
|
+
return list;
|
|
107
|
+
}
|
|
108
|
+
/* ******** ####################### ********** */
|
|
109
|
+
evtRefresh = async (pfilterId)=> {
|
|
110
|
+
//console.log('JZtable.evtRefresh filterId'+filterId?(filterId.id?filterId.id:null):null);
|
|
111
|
+
var filterId=null;
|
|
112
|
+
if(pfilterId)
|
|
113
|
+
if(pfilterId.target)
|
|
114
|
+
filterId=pfilterId.target.value;
|
|
115
|
+
|
|
116
|
+
console.log('JZtable.evtRefresh filterId'+JSON.stringify(filterId));
|
|
117
|
+
//alert('LOAD');
|
|
118
|
+
this.setState({isLoading:true,filterId:filterId});
|
|
119
|
+
try{
|
|
120
|
+
var start = new Date();
|
|
121
|
+
var _list=await this.props.api.findAll(this.props.apiContext,filterId); //tem catch
|
|
122
|
+
if(DEBUGAPICALL_UTIL)alert(JSON.stringify(_list, null, 2));
|
|
123
|
+
_list=this.listModel2View(_list);
|
|
124
|
+
var end = new Date() - start;
|
|
125
|
+
console.info('JZTAble REFRESH:Execution time: %dms', end)
|
|
126
|
+
//alert('END LOAD');
|
|
127
|
+
this.setState({list:_list,isLoading:false});
|
|
128
|
+
//Teste
|
|
129
|
+
this.forceUpdate();
|
|
130
|
+
}catch(error){
|
|
131
|
+
if(error instanceof PlatAPIReturnCodeError ||
|
|
132
|
+
error instanceof PlatAPIDBIntegrityConstraint ||
|
|
133
|
+
error instanceof PlatAPIAuthError ||
|
|
134
|
+
error instanceof PlatAPIError)
|
|
135
|
+
this.setState({myException:error});
|
|
136
|
+
else
|
|
137
|
+
this.setState({myException:error});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
evtRefreshFiltered = async ()=> {
|
|
141
|
+
var _list=null;
|
|
142
|
+
try {
|
|
143
|
+
_list=await this.props.api.findAllByFK(this.state.filter,this.props.apiContext);
|
|
144
|
+
if(DEBUGAPICALL_UTIL)alert(JSON.stringify(_list, null, 2));
|
|
145
|
+
_list=this.listModel2View(_list);
|
|
146
|
+
this.setState({list:_list});
|
|
147
|
+
this.forceUpdate();
|
|
148
|
+
}catch(error){
|
|
149
|
+
if(error instanceof PlatAPIReturnCodeError ||
|
|
150
|
+
error instanceof PlatAPIDBIntegrityConstraint ||
|
|
151
|
+
error instanceof PlatAPIAuthError ||
|
|
152
|
+
error instanceof PlatAPIError)
|
|
153
|
+
this.setState({myException:error});
|
|
154
|
+
else
|
|
155
|
+
this.setState({myException:error});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* ******** ####################### ********** */
|
|
160
|
+
evtCreate = () => {
|
|
161
|
+
this.setState({showEditModal:true,editMode:'I'});
|
|
162
|
+
}
|
|
163
|
+
/* ******** ####################### ********** */
|
|
164
|
+
evtEditSelected = () => {
|
|
165
|
+
}
|
|
166
|
+
/* ******** ####################### ********** */
|
|
167
|
+
evtRemove = () => {
|
|
168
|
+
}
|
|
169
|
+
/* ******** ####################### ********** */
|
|
170
|
+
evtFilter = () => {
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* ******** ####################### ********** */
|
|
174
|
+
evtActionEdit = async (i,item) => {
|
|
175
|
+
this.setState({showEditModal:true,editMode:'U',editKey:item._id});
|
|
176
|
+
if(this.props.onSelectItem) this.props.onSelectItem(item);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* ******** ####################### ********** */
|
|
180
|
+
evtActionDelete = async (i,item) => {
|
|
181
|
+
var r=null;
|
|
182
|
+
try {
|
|
183
|
+
r=await this.props.api.removeByPK(item);
|
|
184
|
+
if(DEBUGAPICALL_UTIL)alert(JSON.stringify(r, null, 2));
|
|
185
|
+
this.evtRefresh();
|
|
186
|
+
}catch(error){
|
|
187
|
+
if(error instanceof PlatAPIReturnCodeError ||
|
|
188
|
+
error instanceof PlatAPIDBIntegrityConstraint ||
|
|
189
|
+
error instanceof PlatAPIAuthError ||
|
|
190
|
+
error instanceof PlatAPIError)
|
|
191
|
+
this.setState({myException:error});
|
|
192
|
+
else
|
|
193
|
+
this.setState({myException:error});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/* ******** ####################### ********** */
|
|
197
|
+
evtEndEditMode = async (i,item) => {
|
|
198
|
+
this.setState({showEditModal:false});
|
|
199
|
+
if(this.props.onSelectItem) this.props.onSelectItem(null);
|
|
200
|
+
if(this.props.backEditURL) {
|
|
201
|
+
this.props.history.push(this.props.backEditURL);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
this.evtRefresh();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
evtSend = async() => {
|
|
209
|
+
try{
|
|
210
|
+
this.setState({fileSelectedName:"Uploading..."});
|
|
211
|
+
await this.props.onSend(this.state.messageInput,this.state.fileSelected,this.state.fileData);
|
|
212
|
+
//this.setState({});
|
|
213
|
+
this.setState({messageInput:'asas',fileSelected:false,fileSelectedName:""});
|
|
214
|
+
await this.evtRefresh();
|
|
215
|
+
this.forceUpdate();
|
|
216
|
+
}catch(error){
|
|
217
|
+
if(error instanceof PlatAPIReturnCodeError ||
|
|
218
|
+
error instanceof PlatAPIDBIntegrityConstraint ||
|
|
219
|
+
error instanceof PlatAPIAuthError ||
|
|
220
|
+
error instanceof PlatAPIError)
|
|
221
|
+
this.setState({myException:error+': APIError'});
|
|
222
|
+
else
|
|
223
|
+
this.setState({myException:error+':'+error.msg});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
evtAttach = async(e) => {
|
|
228
|
+
//alert('FielSel'+e.target.files[0])
|
|
229
|
+
this.setState({fileData:e.target.files[0],fileSelectedName:e.target.files[0].name,messageInput:'Arquivo: '+e.target.files[0].name, fileSelected:true});
|
|
230
|
+
this.forceUpdate();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* ******** ####################### ********** */
|
|
234
|
+
render() {
|
|
235
|
+
if (this.state.myException) {
|
|
236
|
+
if(this.state.myException instanceof PlatAPIAuthError)
|
|
237
|
+
return (<ErrorCardAuth/>)
|
|
238
|
+
else
|
|
239
|
+
return (<ErrorCard myException={this.state.myException}/>)
|
|
240
|
+
} //if
|
|
241
|
+
|
|
242
|
+
const CustomEditComponent = this.props.customEditcomponent;
|
|
243
|
+
|
|
244
|
+
var showListTable=this.state.list&&(this.state.showEditModal==false);
|
|
245
|
+
if(this.state.showEditModal)
|
|
246
|
+
return <CustomEditComponent _id={'FORM_'+this.props._id} mode={this.state.editMode} api={this.props.api} apiContext={this.props.apiContext} editKey={this.state.editKey} editConfig={this.props.editConfig} onClose={this.evtEndEditMode} />
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
//https://stackoverflow.com/questions/50891589/how-to-add-a-scroll-bar-to-a-component-in-react
|
|
250
|
+
//https://www.pluralsight.com/guides/scrolling-inside-a-div-in-react
|
|
251
|
+
|
|
252
|
+
//alert('v_util.JZListComponentImpl.render list:'+JSON.stringify(this.state.list,null,2)) ;
|
|
253
|
+
if(this.state.list!=null)
|
|
254
|
+
return (
|
|
255
|
+
<React.Fragment>
|
|
256
|
+
{/*this.state.showEditModal&&<CustomEditComponent _id={'FORM_'+this.props._id} mode={this.state.editMode} api={this.props.api} apiContext={this.props.apiContext} editKey={this.state.editKey} editConfig={this.props.editConfig} onClose={this.evtEndEditMode} />*/}
|
|
257
|
+
|
|
258
|
+
{showListTable&&<React.Fragment>
|
|
259
|
+
<h3>{this.props.listConfig.title}</h3>
|
|
260
|
+
{this.props.listConfig.hasInsert&&<XButton id={'Novo_'+this.props._id} label={'Novo'+(DEBUG_ID&&'_'+this.props._id)} textlabel={(this.props.textlabels)?"New":null} icon="fa fa-plus" onClick={this.evtCreate}/>}<span> </span>
|
|
261
|
+
{true&&<XButton id={'Atualizar_'+this.props._id} label={'Atualizar'+(DEBUG_ID&&'_'+this.props._id)} textlabel={(this.props.textlabels)?"Refresh":null} icon={this.state.isLoading?'fa fa-spinner fa-spin':'fa fa-refresh'} disabled={this.state.isLoading} onClick={()=>{this.evtRefresh()}} />}<span> </span>
|
|
262
|
+
{false&&<XButton label='Edit' icon="fa fa-edit" onClick={this.evtEditSelected}/>} <span> </span>
|
|
263
|
+
{false&&<XButton label='Remove' icon="fa fa-trash" onClick={this.evtRemove}/>} <span> </span>
|
|
264
|
+
<span> </span>{this.props.listConfig.filterLov&&<XSelect3 isFilter={true} list={this.props.listConfig.filterLov} width={110} onChange={this.evtRefresh} ></XSelect3>}
|
|
265
|
+
{false&&<XButton label='Filter' icon="fa fa-search" onClick={this.evtFilter}/>} <span> </span>
|
|
266
|
+
<h5 style={{color:'red'}} >{this.state.message}</h5>
|
|
267
|
+
|
|
268
|
+
{<XTableRead
|
|
269
|
+
id={this.props._id}
|
|
270
|
+
metadata={this.props.listConfig}
|
|
271
|
+
list={this.state.list}
|
|
272
|
+
inPlaceEdit={false}
|
|
273
|
+
onAction={this.evtActionEdit}
|
|
274
|
+
onDelete={this.evtActionDelete}
|
|
275
|
+
noEdit={this.props.noEdit}
|
|
276
|
+
noDelete={this.props.noDelete}
|
|
277
|
+
textlabels={this.props.textlabels}
|
|
278
|
+
/>}
|
|
279
|
+
|
|
280
|
+
{this.props.messengerMode&&<div>
|
|
281
|
+
{!this.state.fileSelected&&<XButton attachFile={true} icon="fa fa-paperclip" onClick={this.evtAttach} ></XButton>}<span> </span>
|
|
282
|
+
{this.state.fileSelected&&<span>{this.state.fileSelectedName}</span>}
|
|
283
|
+
{!this.state.fileSelected&&<XInputExternal width={300} value={this.state.messageInput} label='' readOnly={this.fileSelected}
|
|
284
|
+
onXG={(event)=>this.setState({messageInput: event.target.value})} cellStyle={true} onEnterKey={this.evtSend} />}<span> </span>
|
|
285
|
+
|
|
286
|
+
{/*<input id={this.props.id+'_msg'} xstyle={{/*this.style1(this.state.valid)* /}} readOnly={this.props.readOnly}
|
|
287
|
+
defaultValue={this.state.messageInput} onChange={(e)=>{var value=e.target.value;this.setState({messageInput:value})}}
|
|
288
|
+
onKeyDown ={(e)=>{if (e.keyCode === 13){console.log(e);this.evtSend();this.setState({messageInput:''}); }}} />*/}
|
|
289
|
+
|
|
290
|
+
{<XButton icon="fa fa-send" onClick={this.evtSend} ></XButton> }
|
|
291
|
+
</div>}
|
|
292
|
+
</React.Fragment>}
|
|
293
|
+
</React.Fragment>
|
|
294
|
+
)
|
|
295
|
+
else
|
|
296
|
+
return (<p className="color--blue">Carregando lista...</p>);
|
|
297
|
+
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
//const JZListComponent = withRouter(JZListComponentNoRouter);
|
|
302
|
+
const JZListComponent = (JZListComponentNoRouter);
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
export {JZListComponent,JZListComponentNoRouter};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {XButton} from "../XButton.jsx"
|
|
3
|
+
import {XInputExternal} from "../XInput.jsx"
|
|
4
|
+
import {XSelect3} from "../XSelect"
|
|
5
|
+
import {XTextArea} from "../XTextArea"
|
|
6
|
+
import {XCheckbox} from "../XCheckbox.jsx"
|
|
7
|
+
import {XDateSelect} from "../XDateSelect.jsx"
|
|
8
|
+
|
|
9
|
+
import { JZInPlaceListComponent } from "./JZInPlaceListComponent.jsx";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const DEBUG_ID=false;
|
|
14
|
+
const DEBUG_ID2=DEBUG_ID;
|
|
15
|
+
const DEBUG_ID3=false;
|
|
16
|
+
|
|
17
|
+
//TODO: tirar debug de celulas (DEBUF_2)
|
|
18
|
+
//atualizar e refres
|
|
19
|
+
//colocar ids corretos da pagetest
|
|
20
|
+
//form
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/** *********************************************************
|
|
24
|
+
* XFormEdit: metadata, formData, btn0, btn0.label, btn0.evt
|
|
25
|
+
* altera diretamente a prop, por isso nao tem estado (via input external)
|
|
26
|
+
* ********************************************************* */
|
|
27
|
+
class XFormEdit extends React.Component {
|
|
28
|
+
constructor(props) {
|
|
29
|
+
super(props)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
inputChangeNew = (value,context) => {
|
|
33
|
+
console.log("u.XFormEdit.inputChgNew.context"+context);
|
|
34
|
+
var v=context.v;
|
|
35
|
+
var item=context.item;
|
|
36
|
+
console.log("u.XFormEdit.inputChgNew.value"+value);
|
|
37
|
+
item[v.attr]=value;
|
|
38
|
+
//this.evtRefresh();
|
|
39
|
+
//this.props.notifyChangeFn();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
render () {
|
|
44
|
+
if(!this.props.metadata.fields)
|
|
45
|
+
return <h3>No metadata.fields on XFormEdit</h3>
|
|
46
|
+
else
|
|
47
|
+
return (
|
|
48
|
+
<React.Fragment>
|
|
49
|
+
<h6>{DEBUG_ID2&&'['+this.props.id+']'}</h6>
|
|
50
|
+
<h3>{this.props.metadata.title}</h3>
|
|
51
|
+
|
|
52
|
+
{this.props.metadata.fields.filter((item)=>{return(item.show)}).map((v,i)=> {
|
|
53
|
+
if(v.type==='l') /*list*/ {
|
|
54
|
+
return <React.Fragment key={i}>
|
|
55
|
+
<div xclassName="card">
|
|
56
|
+
<div>{v.label}</div>
|
|
57
|
+
<XSelect3 list={v.lov} value={this.props.formData[v.attr]} disabled={v.readOnly} onChange={(ev)=>this.props.formData[v.attr]=ev.target.value} />
|
|
58
|
+
<br/>
|
|
59
|
+
<p> </p>
|
|
60
|
+
</div>
|
|
61
|
+
</React.Fragment>
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if(v.type==='a') /* array */ {
|
|
65
|
+
return (
|
|
66
|
+
<React.Fragment key={i}>
|
|
67
|
+
<div xclassName="card"><div>{v.label}</div>
|
|
68
|
+
<JZInPlaceListComponent _id={this.props.id+'_F'+i} textlabels={true} list={this.props.formData[v.attr]} listConfig={v.listConfig} newItemFN={v.newItemFN} />
|
|
69
|
+
</div>
|
|
70
|
+
</React.Fragment>)
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
if(v.type==='d') /* date */ {
|
|
74
|
+
return (
|
|
75
|
+
<React.Fragment key={i}>
|
|
76
|
+
<div className=""><div>{v.label}</div>
|
|
77
|
+
<XDateSelect id={this.props.id+'_F'+i} width={v.width} label = {v.label} disabled={v.readOnly} value={this.props.formData[v.attr]} onChange={(v)=>this.props.formData[v.attr]=v} />
|
|
78
|
+
</div>
|
|
79
|
+
</React.Fragment>)
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
if(v.type==='c') /* check */ {
|
|
83
|
+
return (
|
|
84
|
+
<React.Fragment key={i}>
|
|
85
|
+
<div className=""><div>{v.label}</div>
|
|
86
|
+
<XCheckbox id={this.props.id+'_F'+i} width={v.width} label = {v.label} disabled={v.readOnly} value={this.props.formData[v.attr]} onChange={(v)=>this.props.formData[v.attr]=v} />
|
|
87
|
+
</div>
|
|
88
|
+
</React.Fragment>)
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
return (
|
|
92
|
+
<React.Fragment key={i} >{DEBUG_ID2&&'['+this.props.id+'_F'+i+']'}
|
|
93
|
+
<XInputExternal type={v.type=='n'?'number':''} id={this.props.id+'_F'+i} width={v.width} label = {v.label} readOnly={v.readOnly} value={this.props.formData[v.attr]} /*onChangeNew={(value)=>this.props.formData[v.attr]=ev.target.value}*/ onChangeNew={this.inputChangeNew} context={{item:this.props.formData,v:v}} />
|
|
94
|
+
</React.Fragment>)
|
|
95
|
+
}
|
|
96
|
+
})}
|
|
97
|
+
{this.props.btn0&& <XButton label = {this.props.btn0.label} onClick={this.props.btn0.evt} />}
|
|
98
|
+
</React.Fragment>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
export {XFormEdit};
|