Skip to content

Commit a38eced

Browse files
Add JS for deleting major projects; fixed some strings and typos.
1 parent a2f476d commit a38eced

File tree

9 files changed

+115
-78
lines changed

9 files changed

+115
-78
lines changed

conditional/blueprints/dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def display_dashboard():
9696
user_name = request.headers.get('x-webauth-user')
9797

9898
can_vote = get_voting_members()
99-
logger.info('backend', action=can_vote)
10099
data = dict()
101100
data['username'] = user_name
102101
data['name'] = ldap_get_name(user_name)
@@ -142,6 +141,7 @@ def display_dashboard():
142141

143142
data['major_projects'] = [
144143
{
144+
'id': p.id,
145145
'name': p.name,
146146
'status': p.status,
147147
'description': p.description

conditional/templates/dashboard.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,24 +201,24 @@ <h3 class="panel-title">Conditionals</h3>
201201
<div class="panel-heading">
202202
<h3 class="panel-title">Major Projects</h3>
203203
</div>
204-
<table>
205-
{% for p in major_projects %}
206-
<tr>
204+
<div class="panel-body">
205+
{% for p in major_projects %}
206+
<div class="mp-container">
207207
{% if p['status'] == "Passed" %}
208-
<span class="title"><span style="padding-left:15px; padding-top:15px;" class="glyphicon glyphicon-ok-sign green"></span> {{p['name']}}
209-
</span>
208+
<div class="title"><span class="glyphicon glyphicon-ok-sign green"></span> {{p['name']}}</div>
210209
{% elif p['status'] == "Pending" %}
211-
<span class="title"><span style="padding-left:15px; padding-top:15px;" class="glyphicon glyphicon-hourglass yellow"></span> {{p['name']}}
212-
<button class="btn-xs btn-danger btn-mp"><span class="glyphicon glyphicon-trash"></span> Delete</button>
213-
</span>
210+
<div class="title">
211+
<span class="glyphicon glyphicon-hourglass yellow"></span> {{p['name']}}
212+
<button class="btn-xs btn-danger pull-right" data-module="majorProjectStatus" data-id="{{p['id']}}"><span class="glyphicon glyphicon-trash"></span> Delete</button>
213+
</div>
214214
{% else %}
215-
<span class="title"><span style="padding-left:15px; padding-top:15px;" class="glyphicon glyphicon-minus-sign red"></span> {{p['name']}}
216-
</span>
215+
<div class="title"><span class="glyphicon glyphicon-minus-sign red"></span> {{p['name']}}</div>
217216
{% endif %}
218-
<div class="panel-body" style="word-wrap:break-word">{{p['description']}}</div>
219-
</tr>
220-
{% endfor %}
221-
</table>
217+
<div class="mp-description">{{p['description']}}</div>
218+
</div>
219+
</tr>
220+
{% endfor %}
221+
</div>
222222
</div>
223223
{% endif %}
224224

conditional/templates/major_project_submission.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ <h5 style="padding:15px 20px;float:right"><span class="glyphicon glyphicon-remov
7474
<h5 style="padding:15px 20px;float:right"><span class="glyphicon glyphicon-hourglass yellow"></span></h5>
7575
{% endif %}
7676
{% if p.is_owner and p['status'] == 'Pending' %}
77-
<button class="btn btn-danger btn-mp"><span class="glyphicon glyphicon-trash"></span> Delete</button>
77+
<button class="btn btn-danger btn-mp" data-module="majorProjectStatus" data-id="{{p['id']}}"><span class="glyphicon glyphicon-trash"></span> Delete</button>
7878
{% endif %}
7979
{% endif %}
8080
</div>

frontend/javascript/modules/attendanceForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class AttendanceForm {
5353
});
5454

5555
FetchUtil.postWithWarning(this.endpoint, payload, {
56-
warningText: "You will not be able to edit this event once" +
56+
warningText: "You will not be able to edit this event once " +
5757
"attendance has been recorded.",
5858
successText: "Attendance has been submitted."
5959
});

frontend/javascript/modules/editUser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ export default class EditUser {
352352

353353
FetchUtil.fetchWithWarning(this.endpoints.userDetails + this.uid, {
354354
method: 'DELETE',
355-
warningText: 'This account\'s data will be permanently deleted.',
356-
successText: 'Freshman account has been deleted.'
355+
warningText: "This account's data will be permanently deleted.",
356+
successText: "Freshman account has been deleted."
357357
}, () => {
358358
$(modal).modal('hide');
359359
window.location.reload();
@@ -371,9 +371,9 @@ export default class EditUser {
371371
};
372372

373373
FetchUtil.postWithWarning(this.endpoints.userUpgrade, payload, {
374-
warningText: 'This will irreversibly migrate all of this ' +
375-
'freshman\'s data to the specified member account.',
376-
successText: 'Account has been upgraded.'
374+
warningText: "This will irreversibly migrate all of this " +
375+
"freshman's data to the specified member account.",
376+
successText: "Account has been upgraded."
377377
}, () => {
378378
$(modal).modal('hide');
379379
window.location.reload();

frontend/javascript/modules/hmForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class HouseMeetingForm {
5858
payload.members = upperclassmen;
5959

6060
FetchUtil.postWithWarning(this.endpoint, payload, {
61-
warningText: "You will not be able to unmark a member as present" +
61+
warningText: "You will not be able to unmark a member as present " +
6262
"once attendance has been recorded.",
6363
successText: "Attendance has been submitted."
6464
});

frontend/javascript/modules/majorProjectStatus.js

Lines changed: 80 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,95 @@ import FetchUtil from "../utils/fetchUtil";
66
import sweetAlert from "../../../node_modules/bootstrap-sweetalert/dev/sweetalert.es6.js"; // eslint-disable-line max-len
77

88
export default class MajorProjectStatus {
9-
constructor(dropdown) {
10-
this.dropdown = dropdown;
11-
this.id = this.dropdown.dataset.id;
9+
constructor(control) {
10+
this.control = control;
11+
this.id = this.control.dataset.id;
1212
this.endpoint = '/major_project/review';
13+
this.deleteEndpoint = '/major_project/delete/';
1314
this.render();
1415
}
1516

1617
render() {
17-
const options = this.dropdown.querySelectorAll('[data-option]');
18-
options.forEach(option => {
19-
option.addEventListener('click', e => this._changeStatus(e));
20-
});
18+
if (this.control.tagName.toLowerCase() === "div") {
19+
// Evals director dropdown
20+
const options = this.control.querySelectorAll('[data-option]');
21+
options.forEach(option => {
22+
option.addEventListener('click', e => {
23+
e.preventDefault();
24+
this._changeStatus(e.target.dataset.option);
25+
});
26+
});
27+
} else {
28+
// Member self-delete button
29+
this.control.addEventListener('click',
30+
() => this._changeStatus('Delete'));
31+
}
2132
}
2233

23-
_changeStatus(e) {
24-
e.preventDefault();
25-
26-
let option = e.target.dataset.option;
27-
let payload = {
28-
id: this.id,
29-
status: option
30-
};
31-
32-
fetch(this.endpoint, {
33-
method: 'POST',
34-
headers: {
35-
'Accept': 'application/json',
36-
'Content-Type': 'application/json'
37-
},
38-
credentials: "same-origin",
39-
body: JSON.stringify(payload)
40-
})
41-
.then(FetchUtil.checkStatus)
42-
.then(FetchUtil.parseJSON)
43-
.then(response => {
44-
if (response.hasOwnProperty('success') && response.success === true) {
45-
let toggle = this.dropdown.querySelector('.dropdown-toggle');
46-
["btn-success", "btn-danger", "btn-warning"].forEach(classToRemove =>
47-
toggle.classList.remove(classToRemove));
48-
49-
const caret = document.createElement('span');
50-
caret.classList.add('caret');
51-
toggle.text = option + " ";
52-
toggle.appendChild(caret);
53-
54-
if (option === "Passed") {
55-
toggle.classList.add("btn-success");
56-
} else if (option === "Failed") {
57-
toggle.classList.add("btn-danger");
58-
} else {
59-
toggle.classList.add("btn-warning");
60-
}
34+
_changeStatus(option) {
35+
if (option === "Delete") {
36+
FetchUtil.fetchWithWarning(this.deleteEndpoint + this.id, {
37+
method: 'DELETE',
38+
warningText: 'This action cannot be undone.',
39+
successText: 'Major project deleted.'
40+
}, () => {
41+
let dashboardContainer = this.control.closest(".mp-container");
42+
if (dashboardContainer) {
43+
// Dashboard button
44+
$(dashboardContainer).hide();
6145
} else {
62-
sweetAlert("Uh oh...", "We're having trouble updating this project " +
63-
"right now. Please try again later.", "error");
64-
throw new Exception(FetchException.REQUEST_FAILED, response);
46+
// Major projects page button
47+
$(this.control.closest(".panel")).fadeOut();
6548
}
66-
})
67-
.catch(error => {
68-
sweetAlert("Uh oh...", "We're having trouble updating this project " +
69-
"right now. Please try again later.", "error");
70-
throw new Exception(FetchException.REQUEST_FAILED, error);
7149
});
50+
} else {
51+
let payload = {
52+
id: this.id,
53+
status: option
54+
};
55+
56+
fetch(this.endpoint, {
57+
method: 'POST',
58+
headers: {
59+
'Accept': 'application/json',
60+
'Content-Type': 'application/json'
61+
},
62+
credentials: "same-origin",
63+
body: JSON.stringify(payload)
64+
})
65+
.then(FetchUtil.checkStatus)
66+
.then(FetchUtil.parseJSON)
67+
.then(response => {
68+
if (response.hasOwnProperty('success') &&
69+
response.success === true) {
70+
let toggle = this.control.querySelector('.dropdown-toggle');
71+
["btn-success", "btn-danger", "btn-warning"]
72+
.forEach(classToRemove =>
73+
toggle.classList.remove(classToRemove));
74+
75+
const caret = document.createElement('span');
76+
caret.classList.add('caret');
77+
toggle.text = option + " ";
78+
toggle.appendChild(caret);
79+
80+
if (option === "Passed") {
81+
toggle.classList.add("btn-success");
82+
} else if (option === "Failed") {
83+
toggle.classList.add("btn-danger");
84+
} else {
85+
toggle.classList.add("btn-warning");
86+
}
87+
} else {
88+
sweetAlert("Uh oh...", "We're having trouble updating " +
89+
"this project right now. Please try again later.", "error");
90+
throw new Exception(FetchException.REQUEST_FAILED, response);
91+
}
92+
})
93+
.catch(error => {
94+
sweetAlert("Uh oh...", "We're having trouble updating " +
95+
"this project right now. Please try again later.", "error");
96+
throw new Exception(FetchException.REQUEST_FAILED, error);
97+
});
98+
}
7299
}
73100
}

frontend/stylesheets/pages/_dashboard.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@
3131
.profile-container {
3232
padding: 0 0 0 15px;
3333
}
34+
35+
.mp-description {
36+
margin: 5px 0 15px;
37+
38+
word-wrap: break-word;
39+
40+
&:last-of-type {
41+
margin: 5px 0;
42+
}
43+
}

frontend/stylesheets/pages/_management.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@
124124
}
125125

126126
.btn-mp {
127-
margin-top: 20px;
128-
margin-right:15px;
129127
float: right;
128+
margin-top: 20px;
129+
margin-right: 15px;
130130
}
131131

132132
.stat-number {

0 commit comments

Comments
 (0)