This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conditions.html
161 lines (139 loc) · 3.12 KB
/
conditions.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
152
153
154
155
156
157
158
159
160
161
<style>
p button {
float:left;
margin-right:2px;
}
/* tbl (list) */
#cond td > * {
display: block;
}
#cond tr:first-child {
display: none;
}
#cond td:nth-child(2):hover {
background-color: #C3C8C8;
cursor: pointer;
}
</style>
<div style='display: inline-block'>
<h1>Pump Conditions</h1>
<ul style='font-style:italic'>
<li>Click to edit description</li>
<li>Select to edit input parameters or export</li>
</ul>
<table id=cond>
<tr>
<td><input type="checkbox" onclick="selCond(this)"></td>
<td onclick='edit(this)'></td>
<td><button onclick='rm(this)'><i class="fa fa-trash-o"></i></button></td>
<td><button onclick='cpCon(this)'><i class="fa fa-plus"></i></button></td>
</tr>
<tr>
<td><input type="checkbox" onclick='chkAll(this)' checked></input></td>
</tr>
</table>
<p>
<button class=prime onclick='nu()'>NEW</button>
<span id=grid>
<button class=prime onclick='grid()'>PARAMETERS</button>
<button onclick='xprt()'>EXPORT</i></button>
</span>
<button style='float:right' onclick='removeAll()'>REMOVE ALL</button>
</p>
</div>
<script>
// list selection
function listIdx(e) {
return parIdx(e.parentElement,-2);
}
function chkAll(e) {
chk(':checkbox',e.checked);
$.each(Conds,function(i,d) {
d.grid = e.checked;
});
save();
setBtns();
}
function setBtns() {
$('#grid').toggle($('#cond :checkbox:gt(1):checked').length>0);
}
function selCond(e) {// select condition
Conds[listIdx(e)].grid = e.checked;
save();
setBtns();
}
// operations
function grid() {
go('grid');
}
function rm(e) {// remove
Conds.splice(listIdx(e),1);
save();
loadPg();
}
function removeAll() {
Conds = D.Conds = [];
save();
loadPg();
}
function cpCon(e) {// copy condition
let o = cp(Conds[listIdx(e)]);
o.name+=' (copy)';
Conds.push(o);
save();
loadPg();
}
function edit(e) {
Cond = Conds[parIdx(e,-2)];
go('notes');
}
function nu() {// new
Cond = cp(DefCond);
Conds.push(Cond);
Cond.name = 'Condition ' + Conds.length;
const dt = new Date();
dt.setMinutes(dt.getMinutes()-dt.getTimezoneOffset());
Cond.date = dt.toJSON().slice(0,10);
save();
go('notes');
}
function xprt() {// selective export
Dlg.showSaveDialog(dlgFil('csv'),
function (fn) {
if (fn) {
let hd, lines;
Conds.forEach(function(c,i) {
let r = crunch(cvtArg(c));
if (i==0) {
hd = Object.keys(c).sort().concat(Object.keys(r).sort());
lines=[hd.join(',')];
}
if (c.grid) {
$.each(r, (k,v) => {
r[k] = JSON.stringify(v);
});
cp(c,r);
lines.push(
hd.map((nm,i)=> {
return JSON.stringify(r[nm]);
}).join(',')
);
}
});
require('fs').writeFile(fn,lines.join('\n'));
}
});
}
// init
$.each(Conds,function(i,d) {
const nu = $('#cond tr').first().clone();
nu.children().eq(1).text(d.name);
chk(nu.find(':checkbox'),d.grid);
$('#cond').append(nu);
});
if (Conds.length==0) {
$('#cond').html('<span style="font-style:italic">None</span>');
pg('button:gt(0)').hide();
}
setBtns();
</script>