forked from alibaba/anyproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapForm.js
More file actions
120 lines (100 loc) · 3.09 KB
/
mapForm.js
File metadata and controls
120 lines (100 loc) · 3.09 KB
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
require("../lib/jstree");
function init(React){
function fetchTree(root,cb){
if(!root || root == "#"){
root = "";
}
$.getJSON("/filetree?root=" + root,function(resObj){
var ret = [];
try{
$.each(resObj.directory, function(k,item){
if(item.name.indexOf(".") == 0) return;
ret.push({
text : item.name,
id : item.fullPath,
icon : "uk-icon-folder",
children : true
});
});
$.each(resObj.file, function(k,item){
if(item.name.indexOf(".") == 0) return;
ret.push({
text : item.name,
id : item.fullPath,
icon : 'uk-icon-file-o',
children : false
});
});
}catch(e){}
cb && cb.call(null,ret);
});
}
var MapForm = React.createClass({
submitData:function(){
var self = this,
result = {};
var filePathInput = React.findDOMNode(self.refs.localFilePath),
filePath = filePathInput.value,
keywordInput = React.findDOMNode(self.refs.keywordInput),
keyword = keywordInput.value;
if(filePath && keyword){
self.props.onSubmit.call(null,{
keyword : keyword,
local : filePath
});
filePathInput.value = "";
keywordInput.value = "";
}
},
render:function(){
var self = this;
return (
<div>
<form className="uk-form uk-form-stacked mapAddNewForm">
<fieldset>
<div className="uk-form-row">
<label className="uk-form-label" htmlFor="map_keywordInput">keyword</label>
<div className="uk-form-controls">
<input className="mapConfigInputs" type="text" id="map_keywordInput" ref="keywordInput" placeholder="keyword" />
</div>
</div>
<div className="uk-form-row">
<label className="uk-form-label" htmlFor="map_localFilePath">local file</label>
<div className="uk-form-controls">
<input className="mapConfigInputs pathInput" type="text" id="map_localFilePath" ref="localFilePath" placeholder="local file path" />
</div>
<div ref="treeWrapper" className="treeWrapper"></div>
</div>
<div className="uk-form-row">
<button type="button" className="uk-button" onClick={self.submitData}>Add</button>
</div>
</fieldset>
</form>
</div>
);
},
componentDidMount :function(){
var self = this;
var wrapperEl = $(React.findDOMNode(self.refs.treeWrapper)),
filePathInput = React.findDOMNode(self.refs.localFilePath);
wrapperEl.jstree({
'core' : {
'data' : function (node, cb) {
fetchTree(node.id,cb);
}
}
});
wrapperEl.on("changed.jstree", function (e, data) {
if(data && data.selected && data.selected.length){
//is folder
if(/folder/.test(data.node.icon)) return;
var item = data.selected[0];
filePathInput.value = item;
}
});
},
componentDidUpdate:function(){}
});
return MapForm;
}
module.exports.init = init;