-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathaccount.js
More file actions
181 lines (146 loc) · 5.29 KB
/
account.js
File metadata and controls
181 lines (146 loc) · 5.29 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
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
/* global QamineUtils */
"use strict";
(function($, window) {
var utils = QamineUtils.getInstance();
$(document).ready(function() {
//Profile
var bindProfileEdit = function(textClass, buttonClass, feedbackClass) {
$(textClass).keyup(function() {
$(buttonClass).prop("disabled", false);
});
$(buttonClass).click(function() {
var $this = $(this);
var postVariable = {};
postVariable.name = $(textClass).val();
var url = $this.data("url");
utils.JSend(url, postVariable, function(data) {
$(feedbackClass).showSuccess("Saved");
}, function(error) {
$(feedbackClass).addError(error);
},
"Could not save. please try again.");
});
};
bindProfileEdit(".NameText", ".NameButton", ".NameFeedback");
bindProfileEdit(".jsUsernameText", ".jsUsernameButton", ".jsUsernameFeedback");
$(".help-tooltip").popover();
//Vouchers
$(".VoucherText").bind("keyup paste", function() {
$(".VoucherButton").prop("disabled", false);
});
$(".VoucherButton").click(function(e) {
e.preventDefault();
var $this = $(this);
var postVariable = {};
postVariable.code = $(".VoucherText").val();
var url = $this.data("url");
utils.JSend(url, postVariable, function(data) {
$(".VoucherFeedback").addSuccess("Promocode added. Your trial was extended.");
$(".VoucherText").val("");
$(".VoucherButton").prop("disabled", true);
}, function(error) {
$(".VoucherFeedback").showError(error);
},
"Could not add the promocode, please try again.");
});
$(".BtnGenerateToken").click(function() {
var $this = $(this);
var url = $this.data("url");
utils.JSend(url, {}, function(data) {
$(".ApiTokensFeedback").showSuccess("New token generated");
location.reload();
}, function(error) {
$this.blur();
$(".ApiTokensFeedback").showError(error);
},
"could not save. please try again.");
});
$(".BtnRemoveToken").click(function(e) {
e.preventDefault();
var $this = $(this);
var url = $this.data("url");
var postVariable = {};
postVariable.tokenId = $this.data("tokenid").toString();
utils.JSend(url, postVariable, function(data) {
$(".ApiTokensFeedback").showSuccess("Token removed");
$this.closest(".js-token").fadeOut();
}, function(error) {
$(".ApiTokensFeedback").showError(error);
},
"Could not remove token, please try again.");
});
//Notifications
$(".jsDropdownEmail a").click(function(e) {
e.preventDefault();
var postVariable = {};
postVariable.email = $(this).text();
var url = $(".jsDropdownEmail").data("url");
utils.post(url, postVariable, function(e) {
if (e.error) {
$(".jsMainEmailFeedback").showError(e.error);
} else {
$('.jsSelectedMainEmail').text(postVariable.email);
$(".jsMainEmailFeedback").showSuccess("Saved");
}
}, function() {
$(".jsMainEmailFeedback").showError("Could not save. Please try again.");
});
});
$(".jsAccountEmail").change(function() {
var postVariable = {};
postVariable.emailNotification = $(this).prop('checked') ? true : false;
var url = $(this).data("url");
var feedback = $(this).closest('tr').find('.jsEmailFeedback');
utils.JSend(url, postVariable, function(data) {
feedback.showSuccess("Saved");
}, function(error) {
feedback.showError(error);
},
"Could not save. Please try again.");
utils.JSend(url, postVariable, function(data) {
feedback.showSuccess("Saved");
}, function(error) {
feedback.showError(error);
},
"Could not save. Please try again.");
utils.JSend(url, postVariable, function(data) {
feedback.showSuccess("Saved");
}, function(error) {
feedback.showError(error);
},
"Could not save. Please try again.");
});
$(".jsCommitEmail").change(function() {
var postVariable = {};
postVariable.projectId = $(this).data("project-id");
postVariable.commitNotifications = $(this).prop('checked');
var url = $(".jsEmailNotifications").data("url");
var feedback = $(this).closest('tr').find('.jsEmailFeedback');
utils.post(url, postVariable, function(e) {
if (e.error) {
feedback.showError(e.error);
} else {
feedback.showSuccess("Saved");
}
}, function() {
feedback.showError("Could not save. Please try again.");
});
});
function checkCookie(type) {
var alert = Cookies.get(type);
if(alert == "true") {
$("." + type).removeClass("hidden").show();
} else if(alert == "false") {
$("." + type).hide();
} else {
$("." + type).removeClass("hidden").show();
Cookies.set("CodacyStartupAlert", "true");
}
}
checkCookie("CodacyStartupAlert");
$(".CodacyStartupAlert .close").on("click", function () {
Cookies.set("CodacyStartupAlert", "false");
});
$('[data-toggle="tooltip"]').tooltip();
});
})(jQuery, window);