-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfigurationDialog.html
175 lines (162 loc) · 6.56 KB
/
ConfigurationDialog.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
<!DOCTYPE html>
<html ng-app="WorkflowJacknifePref">
<head>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>
<script>
</script>
<script>
var wApp = angular.module('WorkflowJacknifePref',[]);
console.log('created app:',wApp);
wApp.controller('ConfigCtrl', function ($scope) {
var vm = this;
vm.action = "<?!= action ?>";
vm.form = "<?!= form ?>";
vm.prefs = 'NONE YET';
vm.type = {}
vm.type.TEXT = 1
vm.type.FOLDER = 2
vm.type.FIELDCONVERSION = 3
vm.type.FIELDLIST = 4
vm.type.PARA = 5
vm.type.FIELD = 6
vm.actionName = "Waiting..."
// GLOBALS COPIED FROM TOP OF CODE.GS
// Convenience methods...
vm.addFieldToVal = function (pref, field) {
console.log('Adding field %s',field)
pref.val += ' <<'+field+'>>'
console.log('pref=%s',pref)
}
function gotFormLayout (actionDetails) {
console.log('gotFormLayout got %s',JSON.stringify(actionDetails));
vm.prefs = actionDetails.params;
vm.actionName = actionDetails.name
// prefList = [];
// for (var p in actionDetails.params) {
// if (actionDetails.hasOwnProperty(p)) {
// val = actionDetails[p]
// val['name'] = p
// prefList.push(val);
// }
// }
// vm.prefs = prefList;
$scope.$apply();
} // end gotFormLayout
function allDone () {
google.script.host.close()
}
vm.doAction = function () {
console.log('doAction!');
console.log("Do actions with prefs %s",JSON.stringify(vm.prefs));
myprefs = {}
for (var key in vm.prefs) {
try {
if (vm.prefs[key].type==vm.type.FIELD) {
console.log('Got FIELD');
switch (vm.prefs[key].mode) {
case 'field':
console.log('FIELD field');
myprefs[key] = '%' + vm.prefs[key].val
break;
case 'lookup':
console.log('FIELD lookup');
myprefs[key] = '@'+vm.prefs[key].val+'>>'+key
break;
case 'value':
console.log('FIELD value');
myprefs[key] = vm.prefs[key].val
}
}
else {
myprefs[key]=vm.prefs[key].val
}
}
catch (err) {
console.log('Unable to add pref %s (ERR: %s)',key, err)
}
}
google.script.run.withSuccessHandler(allDone).sidebarDoAction(vm.action,vm.form,myprefs);
}
google.script.run.withSuccessHandler(gotFormLayout).getActionDetails(vm.action,vm.form);
}); // end ConfigCtrl
</script>
</head>
<body ng-controller="ConfigCtrl as cc">
{{cc.prefs}}
<div ng-if="! cc.prefs">
Loading preference information...
</div>
<div ng-if="cc.prefs">
<form>
<table>
<tr ng-repeat="pref in cc.prefs">
<td> <label>{{pref.label}}</label></td>
<td><input ng-if="pref.type==cc.type.TEXT"
type="text" ng-model="pref.val" size="80">
<div ng-if="pref.type==cc.type.PARA">
<textarea ng-model="pref.val"></textarea><br>
Add field: <select ng-model="pref.selectedField" ng-options="field for field in pref.fields"> </select><button ng-click='pref.val = pref.val+"<<"+pref.selectedField+">>"'>Add Field to Paragraph</button>
</div> <!-- end PARA -->
<div ng-if="pref.type==cc.type.FIELDCONVERSION">
Convert from...
<table>
<tr><th>From</th><th>To</th></tr>
<tr ng-repeat="conversion in pref.val">
<td>
<select ng-model="conversion.from" ng-options="field for field in pref.fields"></select>
<!--<option value="conversion.from">{{conversion.from}}</option>
</select>-->
</td>
<td>
<input type="text" ng-model="conversion.to">
<!--<option value="conversion.to">{{conversion.to}}</option>
</select>-->
</td>
<td>
<button ng-click="pref.val.splice($index,1)">-</button>
</td>
</tr>
</table>
<button ng-click="pref.val.push({from:'',to:''})">+Add Conversion+</button>
</div>
<!--'val':[{'type':'textField','title':'Signature','helpText':'Write initials and date here to approve.'}]}, -->
<div ng-if="pref.type==cc.type.FIELDLIST">
Field List
<table>
<tr><th>Type</th><th>Field</th><th>Help Text</th></tr>
<tr ng-repeat="field in pref.val">
<td><input type="text" ng-model="field.type"></td>
<td><input type="text" ng-model="field.title"></td>
<td><input type="text" ng-model="field.helpText"></td>
</tr>
</table>
<button ng-click="pref.val.push({type:'textField',title:'New Field','helpText':'help text here'})">+Add Field+</button>
</div> <!-- end FIELDLIST -->
<div ng-if="pref.type==cc.type.FIELD">
<!-- Standard field... we map types of... -->
<!-- %FIELDNAME => Field from form -->
<!-- VALUE ==> plain old value -->
<!-- @FieldName >> Lookup Keys -->
<!-- In this case, we add a lookup to the configuration table -->
<input type="radio" name="{{pref.name}}mode" ng-model="pref.mode" value="field"><label>Field</label>
<input type="radio" name="{{pref.name}}mode" ng-model="pref.mode" value="value"><label>Raw Value</label>
<input type="radio" name="{{pref.name}}mode" ng-model="pref.mode" value="lookup"><label>Lookup</label>
<div ng-show="pref.mode=='field'">
Field: <select ng-model="pref.val" ng-options="'%'+field for field in pref.fields"></select>
</div>
<div ng-show="pref.mode=='lookup'">
Lookup: <select ng-model="pref.val" ng-options="'@'+field+'>>'+'Lookup' for field in pref.fields"></select>
</div>
<div ng-show="pref.mode=='value'">
Text: <input type="text" ng-model="pref.val">
</div>
</div> <!-- end FIELD -->
</td>
</tr>
</table>
<button ng-click="cc.doAction()">{{cc.actionName}}</button>
</form>
</div>
</body>
</html>