-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.html
262 lines (241 loc) · 8.35 KB
/
settings.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<apex:page docType="html-5.0"
sidebar="false"
showheader="false"
standardStylesheets="false"
Controller="SettingsController"
applyHtmlTag="false"
applyBodyTag="false">
<head>
<apex:stylesheet value="https://fonts.googleapis.com/css?family=Source+Sans+Pro:600"/>
<apex:stylesheet value="{!URLFOR($Resource.RollCallAssets, 'front_end_assets/style.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.RollCallAssets, 'fastclick/fastclick.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.RollCallAssets, 'jquery/jquery-2.0.3.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.RollCallAssets, 'forceTK/forceTK.js')}"/>
<title>RollCall Settings</title>
<style type="text/css">
p, input, li {
font-family: Source Sans Pro, sans-serif;
font-weight: 600;
}
.custom-file-input {
margin-top: 25px;
color: transparent;
}
.custom-file-input::-webkit-file-upload-button {
visibility: hidden;
}
.custom-file-input::before {
content: 'Upload Image';
color: black;
display: inline-block;
background: -webkit-linear-gradient(top, #f9f9f9, #e3e3e3);
border: 1px solid #999;
border-radius: 3px;
padding: 15px 18px;
outline: none;
white-space: nowrap;
-webkit-user-select: none;
cursor: pointer;
text-shadow: 1px 1px #fff;
font-weight: 700;
font-size: 10pt;
}
.custom-file-input:hover::before {
border-color: black;
}
.custom-file-input:active {
outline: 0;
}
.custom-file-input:active::before {
background: -webkit-linear-gradient(top, #e3e3e3, #f9f9f9);
}
.label {
font-size: 1em;
}
@media (max-width: 900px) {
.input {width: 300px;}
}
</style>
</head>
<body>
<div id="container">
<div class="checkin">
<p class="chart_title"> RollCall Settings </p>
<div class="column" >
<p class="label"> Campaign Members status for <br></br> <span class="blue_text">Registered</span> attendees </p>
<p class="label"> Campaign Members status for <br></br> <span class="blue_text">Checked-in</span> attendees </p>
<p class="label"> Show Parent Campaigns of <span class="blue_text">Type</span> </p>
<p class="label"> Background Image (optional) </p>
<p class="label" style="margin-top:10px;"> Logo (optional) </p>
</div>
<div class="column" style="padding-left:60px;">
<input class="input normal" type="text" name="register" autocorrect="off" autocomplete="off" id="register"/>
<input class="input normal" type="text" name="checkin" autocorrect="off" autocomplete="off" id="checkin"/>
<select class="input normal" id="campaignType">
<apex:repeat value="{!campaignTypes}" var="type">
<option value="{!type}">{!type}</option>
</apex:repeat>
</select>
<div>
<input class="custom-file-input" style="padding:0px; margin-top: 20px;" type="file" id="photoFile" accept="image/*"/>
<img id="uploadPreview" style="width: 40px; height: 40px;float:left; margin-top:-50px; margin-left:200px" src="{!$Resource.RollCall_Background_Img}"/>
</div>
<!-- Logo -->
<div>
<input class="custom-file-input" style="padding:0px;" type="file" id="photoFileLogo" accept="image/*"/>
<img id="uploadPreviewLogo" style="width: 40px; height: 40px;float:left; margin-top:-50px; margin-left:200px" src="{!$Resource.RollCall_Logo_Img}"/>
</div>
</div>
<a id="update" onclick="update_settings();"><p> Update </p></a>
<p id="messages" class="chart_title blue_text"></p>
<img id="loading" src="{!URLFOR($Resource.RollCallAssets, 'front_end_assets/ajax-loader.gif')}" style="margin: auto; margin-top: 25px; width: 30px; height: 30px; display:none"></img>
</div>
</div>
<script>
var imageData;
var imageDataLogo;
var forcetkClient = new forcetk.Client();
forcetkClient.setSessionToken('{!$Api.Session_ID}');
var loading = document.getElementById('loading');
function update_settings() {
$("#messages").text('');
var checkin = $("#checkin").val();
var register = $("#register").val();
if (checkin == '' || register == '') {
$("#messages").text('Please enter valid values for Registered and Checked-in statuses');
return;
}
$("#update").prop('disabled', true);
loading.style.display = 'block';
if ((typeof imageData != 'undefined') && imageData != ''){
forcetkClient.query("SELECT Id FROM StaticResource where name LIKE '%RollCall_Background_Img%' LIMIT 1", function(response){
var image = {'Body':imageData};
forcetkClient.update('StaticResource',
response.records[0].Id,
image,
function(){
imageData = '';
},
function (err) {
}
);
});
}
if ((typeof imageDataLogo != 'undefined') && imageDataLogo != '') {
forcetkClient.query("SELECT Id FROM StaticResource where name LIKE '%RollCall_Logo_Img%' LIMIT 1", function(response){
var image = {'Body':imageDataLogo};
forcetkClient.update('StaticResource',
response.records[0].Id,
image,
function(){
imageDataLogo = '';
},
function (err) {
}
);
});
}
updateSettings();
}
function handlePhoto(evt){
var file = evt.target.files[0];
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
// Extract raw base64 data from data URL
$("#uploadPreview").attr('src',e.target.result);
imageData = e.target.result.split(',')[1];
};
})(file);
reader.readAsDataURL(file);
}
function handlePhotoLogo(evt){
var file = evt.target.files[0];
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
// Extract raw base64 data from data URL
$("#uploadPreviewLogo").attr('src',e.target.result);
imageDataLogo = e.target.result.split(',')[1];
};
})(file);
reader.readAsDataURL(file);
}
function updateSettings(){
var checkin = $("#checkin").val();
var register = $("#register").val();
var campaignType = $("#campaignType").val();
// javascript escape
var entityMap = {
"&": "&",
"<": "<",
">": ">",
'"': '"',
"'": ''',
"/": '/'
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}
checkin = escapeHtml(checkin);
register = escapeHtml(register);
campaignType = escapeHtml(campaignType);
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.SettingsController.update_settings}',
checkin, register, campaignType,
function(result, event){
if (event.status) {
setTimeout(function() {
loading.style.display = 'none'
$("#messages").text('Your settings have been updated');
$("#update").prop('disabled', false);
$("#update").blur();
}, 2000);
} else if (event.type === 'exception') {
$("#messages").text('There was an exception!');
} else {
$("#messages").text('There was an exception!');
}
},
{escape: true}
);
}
$(document).ready(function(){
FastClick.attach(document.body);
$("#photoFile").change(handlePhoto);
$("#photoFileLogo").change(handlePhotoLogo);
// Remoting call to get current status values
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.SettingsController.check_settings}',
function(result, event){
if (event.status) {
$('#checkin').val(result[0]);
$('#register').val(result[1]);
$('#campaignType').val(result[2]);
} else if (event.type === 'exception') {
$("#messages").text('There was an exception!');
} else {
document.getElementById("responseErrors").innerHTML = event.message;
}
},
{escape: true}
);
})
window.onkeydown = function(e){
var $focused = $(':focus');
window.focus();
$focused.focus();
var code = e.keyCode || e.which;
if(code == 13) {
update_settings();
$("#register").blur();
$("#checkin").blur();
$("#photoFile").blur();
$("#photoFileLogo").blur();
}
}
</script>
</body>
</apex:page>