-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApproverApp.html
220 lines (215 loc) · 8.71 KB
/
ApproverApp.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script src="https://unpkg.com/vue/dist/vue.js"></script> <!-- vue -->
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> <!-- add-ons styles -->
<style>
.busy {cursor: wait}
.left {width: 60%;}
.right {width: 40%;}
.small {font-size: x-small}
.normal {cursor: normal}
.instructions {font-style: italic; font-size: 8px; color: #acacac}
ul {padding-left: 0px}
li {border: 1px solid; padding: 16px; position: relative; font-size: 10pt; list-style-type: none;}
.block {margin-left: 1em; margin-right: 1em; display: inline-block; padding-top: 15px; position: relative; vertical-align: top;}
.block .label {position: absolute; top: 2px; left: 2px; font-size: 7px; color: #787878;}
.detail {font-size: 80%; font-style: italic;}
.block .sub {font-size: 6px; display: block; }
.itemInfo {display: inline-block; max-width: 350px;}
.message {position: absolute; top: 25px; width: 80%; margin-left: auto; margin-right: auto; padding: 30px;
background-color: white; opacity: 0.8; color: black; font-weight: bold; font-size: 24pt; border: 10px solid black; text-align: center; z-index: 2;}
.hide {display: none;}
.buttonbox button {font-size: 7pt;}
.approval {max-width: 100px}
.cost-box {max-width: 150px}
.approval {position: relative; padding-bottom: 14px; font-size: 10px;}
.sig {border-bottom: 1px dotted; min-width: 150px; display: inline-block; font-family: cursive;}
.cost {font-weight: heavy; color: #050; max-width: 130px;}
.cost::before {content: "$"}
#ui {position: fixed; top: 0px; width: 100%; background-color: #B3E5FC; box-shadow: 0px 3px #01579B;
font-weight: bold; padding: 20px; height: 30px;}
.wrapped {width: 700px; margin: auto;}
#items {margin-top: 25px;}
#formchooser {margin-top:70px}
</style> <!-- style -->
</head>
<body>
<div id="approver" :class="{busy:busy}">
<div v-if="error">Error: {{error}}</div>
<div>
<div class="message" v-if="isAllDone()">All done!</div>
<div class="message" v-if="busy">{{message}}
<button @click="busy=false;" v-if="showCancel">Ok</button>
</div>
<div id="items" :class="{hide: forms.length==0}">
<div class="buttonbox"><label>Items to Approve:</label>
<button @click="checkAll">Check All</button> <button @click="uncheckAll()">Uncheck All</button>
</div>
<ul v-for="form in forms">
<!-- <li>FORM: {{form.form}}</li> -->
<li v-for="item in form.items">
<input @change="$forceUpdate()" v-model="item.toUpdate" type="checkbox">
<div v-for="f in fields" :class="'block '+f.label.toLowerCase()">
<span class="label" >{{f.label}}</span>
<span class="value">
{{item[f.field]}}
</span>
<span v-if="f.detail" class="detail">
<br>{{item[f.detail]}}
</span>
</div>
<div class="block approval">
<span class="label">Approval:</span>
<span v-if="item.toUpdate" class="sig">{{signature}}</span>
<span v-else class="sig"></span>
<span class="sub email">{{item.Approver}}</span>
</div>
</li>
</ul>
<div id="ui">
<table>
<tr>
<td class="left" >
<div style="display:inline-block; vertical-align: top;">
<div>Signature: <input v-model="signature"></div>
<div class="instructions">Type initials and date to approve, or type initials and REJECT to reject.</div>
</div>
<button class="create" @click="sign()">Submit Signatures</button>
</td>
<td class="right">
<div class="small">
(Only show items <input type="number" v-model="daysAgo"> days old or newer)
<button @click="loadData()">Reload Data</button>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="hide"> Items: {{forms}}</div>
</div>
</body>
<script>
app = new Vue({
el : '#approver',
data : ()=>{
return {
daysAgo : 120,
fields : [
{label:'Account',
field:'Cost Account Type',
detail:'Cost Sub-Account Type'
},
{label:'Requested By',
field:'Requester',
detail:'Request Type'
},
{label:'Time of Request',
field:'Request Timestamp'},
{label:'Item',
field:'Item Description',
detail:'Vendor'},
{label:'Cost',
field:'Total Cost',
detail:'Total Type'},
],
busy : false,
showCancel : false,
message : 'Loading data from form... this may take a while...',
error : '',
forms : [{form:'',items:[{toUpdate:false,id:0}]}],
master : '',
signature : '',
}
},
created () {
this.forms = []
console.log('Created thingy');
google.script.url.getLocation(
(l)=>{
if (l.parameter.master) {
console.log('Got master: %s',l.parameter.master)
this.master = l.parameter.master;
}
else {
console.log('Default master');
this.master = '1YECCtTGxgpMo-aO_VIszvzJmJAA18qlWsF0Rov3OYqU';
}
this.loadData(); // now load the data!
}
)
},
methods : {
checkAll () {
this.forms.forEach((f)=>{
f.items.forEach((i)=>i.toUpdate=true);
});
this.$forceUpdate();
},
uncheckAll () {
console.log('Uncheck all!');
this.forms.forEach((f)=>{
f.items.forEach((i)=>i.toUpdate=false)
});
this.$forceUpdate();
},
sign () {
console.log('Sign!');
this.forms.forEach((f)=>{
var toUpdate = f.items.filter((i)=>i.toUpdate);
console.log('We should update: %s',toUpdate);
this.busy = true;
this.message = 'Signing items...';
google.script.run
.withSuccessHandler((d)=>{
toUpdate.forEach((itm)=>{
var idx = f.items.indexOf(itm);
if (idx!==-1) {
f.items.splice(idx,1);
}
}
);
this.busy = false;
})
.withFailureHandler((e)=>{
this.message='Error signing: '+e;
this.showCancel=true;
})
.approveItems(
f.form,
toUpdate.map((i)=>i.id),
{'Signature':this.signature}
);
});
},
isAllDone () {
for (var f of this.forms) {
if (f.items.length>0) {
return false
}
}
return true;
},
loadData () {
this.busy = true;
this.message = 'Loading data from form... this may take a while.';
google.script.run
.withSuccessHandler((d)=>{
this.forms=d;
this.forms.forEach((f)=>{
f.items.forEach((i)=>{
i.toUpdate = false;
});
});;
this.busy = false;
})
.withFailureHandler((e)=>{this.error=e;this.busy=false;})
.getUnapproved(this.master,this.daysAgo)
},
},
});
</script>
</html>