-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.userregistration.js.html
More file actions
131 lines (110 loc) · 3.44 KB
/
Copy pathmodule.userregistration.js.html
File metadata and controls
131 lines (110 loc) · 3.44 KB
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
<script src="https://cdn.rawgit.com/thanashyam/2309671/raw/5168575d69cd84588c52aa183dbfb3d932b9d4f9/jquery.md5.js"></script>
<script>
$(function() {
function showUserRegistrationScreen(){
$(".appSection").hide();
$(".userRegistration").show();
$(".formelem",".userRegistrationContent").val("");
$(".registrationMessage").empty();
$(".registrationError").empty();
}
$(".checkboxitem").click(function(){
var checkbox = $(".checkbox", this);
console.log($(checkbox).prop("checked"));
$(".checkyesno", this).text($(checkbox).prop("checked") ? "Yes" : "No");
});
var submitting = false;
$("#userRegistrationSubmit").click(function(){
console.log("submit");
if(submitting){
console.log("already submitting");
return false;
}
submitting = true;
$(".registrationMessage").empty();
$(".registrationError").empty();
var user = {};
var errors = [];
$(".formelem", ".userRegistrationContent").each(function(index){
var colname = $(this).data("colname");
var val = $(this).val();
var required = $(this).data("required");
if(required && val.trim() == ""){
errors.push("Field '" + $(this).attr('name') + "' is required");
}
if($(this).attr("type") == "checkbox"){
val = ($(this).prop("checked") == "TRUE" ? "Yes" : "No");
}
if(colname == "swipemd5"){
// encrypt netid
val = $.md5(val + "Shift");
}
user[colname] = val;
});
if(!user.netid){
errors.push("netid required");
}
var found = GLOBALS.user.findUser(user.netid);
var update = false;
if(found){
update = true;
var keys = Object.keys(user);
$.each(keys, function(index, key){
found[key] = user[key];
});
user = found;
}
if(errors.length > 0){
registrationError(errors.join("<BR>"));
submitting = false;
return false;
}
console.log("update : " + update);
console.log(user);
if(!update){
// insert user into table
google.script.run.withSuccessHandler(function(response){
console.log(response);
$(this).off("keydown");
registrationComplete(user);
})
.withFailureHandler(function(message){
console.log(message);
registrationError(message);
})
.insertUserData(user);
}else{
// insert user into table
google.script.run.withSuccessHandler(function(response){
console.log(response);
$(this).off("keydown");
registrationComplete(user);
})
.withFailureHandler(function(message){
console.log(message);
registrationError(message);
})
.updateUserData(user.netid, user);
}
return false;
});
function registrationComplete(user){
// reload all users
submitting = false;
$(".formelem",".userRegistrationContent").val("");
GLOBALS.user.getAllUserData(function(){
$(".registrationMessage").text("Registration Complete!");
GLOBALS.user.getSessionUser(GLOBALS.user.updateAppForSessionUser);
GLOBALS.user.getThisUserData(user.netid);
});
}
function registrationError(message){
submitting = false;
$(".registrationError").html("Registration Error: " +message);
}
$(".showUserRegistration").click(function(){
showUserRegistrationScreen();
return false;
});
});
</script>