-
Notifications
You must be signed in to change notification settings - Fork 9
/
node_edit.html
151 lines (142 loc) · 4.68 KB
/
node_edit.html
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
147
148
149
150
151
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>node_edit</title>
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!--标准mui.css-->
<link rel="stylesheet" href="css/mui.min.css">
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
<link href="css/mui.picker.css" rel="stylesheet" />
<link href="css/mui.poppicker.css" rel="stylesheet" />
<style>
h5 {
margin: 5px 7px;
}
</style>
</head>
<body>
<header class="mui-bar mui-bar-nav">
<h1 class="mui-title" id="lb_hubinfotitle">修改节点(Node)</h1>
</header>
<div class="mui-content">
<div class="mui-content-padded" style="margin: 5px;">
<form class="mui-input-group">
<div class="mui-input-row">
<label>节点编号</label>
<input type="text" class="mui-input-clear" id="tb_nodeid" disabled>
</div>
<div class="mui-input-row">
<label>节点名称</label>
<input type="text" class="mui-input-clear" id="tb_nodetitle">
</div>
<div class="mui-input-row">
<label>节点标签</label>
<input type="text" class="mui-input-clear" id="tb_nodetags">
</div>
<div class="mui-input-row mui-plus-visible">
<label>节点描述</label>
<input type="text" class="mui-input-clear" id="tb_nodeabout">
</div>
<div class="mui-input-row">
<label>节点类型</label>
<input type="text" class="mui-input-clear" id="tb_hubtype" disabled>
</div>
<br>
<div class="mui-button-row">
<button type="button" class="mui-btn mui-btn-primary" onclick="return false;" id="bt_editnode">确认</button>
<button type="button" class="mui-btn mui-btn-danger" onclick="return false;" id="bt_node_edit_cancel">取消</button>
</div>
</form>
</div>
</div>
<script src="js/mui.min.js"></script>
<script src="js/mui.picker.js"></script>
<script src="js/mui.poppicker.js"></script>
<script src="js/app.js"></script>
<script>
mui.init({
swipeBack: true //启用右滑关闭功能
});
var hubid;
var nodeid;
var ntype;
window.addEventListener('sethubid', function(event) {
var obj = JSON.parse(event.detail.nodeobj);
hubid = obj.HubId;
nodeid = obj.Id;
ntype = obj.Type;
document.getElementById('tb_nodeid').value = nodeid;
document.getElementById('tb_nodetitle').value = obj.Title;
document.getElementById('tb_nodeabout').value = obj.About;
document.getElementById('tb_nodetags').value = obj.Tags;
document.getElementById('tb_hubtype').value = types[obj.Type - 1].text;
});
document.getElementById('bt_editnode').addEventListener('tap', function() {
var obj = Object();
obj.Title = document.getElementById('tb_nodetitle').value;
obj.About = document.getElementById('tb_nodeabout').value;
obj.Tags = document.getElementById('tb_nodetags').value.split(",");
obj.Type = ntype;
if(obj.Title.length == 0 || obj.Title.length > 64 ||
obj.About.length == 0 || obj.About.length > 64 ||
document.getElementById('tb_nodetags').value.length == 0 || document.getElementById('tb_nodetags').value.length > 64 ||
obj.Type == undefined) {
plus.nativeUI.toast('数据不符合规范');
return;
}
var state = app.getState();
mui.ajax(localStorage.getItem('$svc') + '/api/hub/' + hubid + '/node/' + nodeid, {
dataType: 'json',
type: 'put',
data: JSON.stringify(obj),
headers: {
'Content-Type': 'application/json',
"Authorization": state.token
},
success: function(data) {
if(data.ok == 1) {
plus.nativeUI.toast('提交成功');
var mg = plus.webview.getWebviewById('node_mg.html');
mui.fire(mg, 'reload')
plus.webview.show(mg, "fade-in", 300);
} else {
plus.nativeUI.toast(data.err);
}
},
error: function(xhr, type, errorThrown) {
plus.nativeUI.toast(Error(xhr.responseText));
}
});
})
document.getElementById('bt_node_edit_cancel').addEventListener("tap", function() {
var goback = plus.webview.getWebviewById('node_mg.html');
plus.webview.show(goback, "fade-in", 300);
})
var types = [{
value: 1,
text: '控制器-开关'
}, {
value: 2,
text: '控制器-自定义型'
}, {
value: 3,
text: '控制器-约束型'
}, {
value: 4,
text: '传感器-数值型'
}, {
value: 5,
text: '传感器-GPS'
}, {
value: 6,
text: '传感器-自定义型'
}, {
value: 7,
text: '传感器-图片'
}];
</script>
</body>
</html>