Skip to content

Commit 64c9b69

Browse files
schools/mit: allow adding and removing additional classes to your registration
1 parent 7833cef commit 64c9b69

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

app/schools/mit/MITSettings.jsx

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class MITSettings extends Component {
1515
super(props);
1616

1717
this.state = {
18+
loading: false,
1819
registration: props.currentSettings.registration,
1920
peInfo: props.currentSettings.peInfo,
2021
showPE: props.currentSettings.showPE
@@ -84,6 +85,81 @@ export default class MITSettings extends Component {
8485
});
8586
}
8687

88+
addCustomClass() {
89+
const subjectNumber = prompt("What is the number of the class you want to add? (8.02, 18.01, etc.)");
90+
if (!subjectNumber) {
91+
return;
92+
}
93+
94+
this.setState({
95+
loading: true,
96+
error: ""
97+
}, () => {
98+
api.post("schools/settings/callMethod", {
99+
school: "mit",
100+
methodName: "addCustomClass",
101+
methodParams: JSON.stringify({
102+
subjectNumber: subjectNumber
103+
})
104+
}, (data) => {
105+
if (data.status == "ok") {
106+
this.props.loadDetails(() => {
107+
this.setState({
108+
loading: false
109+
});
110+
});
111+
} else if (data.error == "invalid_params") {
112+
this.setState({
113+
loading: false,
114+
error: "We couldn't find the class with that subject number. Make sure it's spelled as it appears in the Course Catalog.\n\nFor help, email [email protected]."
115+
});
116+
} else if (data.error == "already_enrolled") {
117+
this.setState({
118+
loading: false,
119+
error: "You already have that class in your registration."
120+
});
121+
} else {
122+
this.setState({
123+
loading: false,
124+
error: errors.getFriendlyString(data.error)
125+
});
126+
}
127+
});
128+
});
129+
}
130+
131+
removeCustomClass(registeredClass) {
132+
if (!confirm("Remove " + registeredClass.subjectID + " " + registeredClass.title + "?")) {
133+
return;
134+
}
135+
136+
this.setState({
137+
loading: true,
138+
error: ""
139+
}, () => {
140+
api.post("schools/settings/callMethod", {
141+
school: "mit",
142+
methodName: "removeCustomClass",
143+
methodParams: JSON.stringify({
144+
subjectNumber: registeredClass.subjectID
145+
})
146+
}, (data) => {
147+
if (data.status == "ok") {
148+
this.props.loadDetails(() => {
149+
this.setState({
150+
loading: false
151+
});
152+
});
153+
} else {
154+
this.setState({
155+
loading: false,
156+
error: errors.getFriendlyString(data.error)
157+
});
158+
}
159+
});
160+
});
161+
}
162+
87163
render(props, state) {
88164
if (state.loading) {
89165
return <div>
@@ -102,8 +178,16 @@ export default class MITSettings extends Component {
102178
<p>If you believe you're receiving this message in error, please contact us at <a href="mailto:[email protected]">[email protected]</a>.</p>
103179
</div>}
104180
{state.registration.map((registeredClass) => {
105-
return <MITClassSections registeredClass={registeredClass} setSectionForSubject={this.setSectionForSubject.bind(this)} />;
181+
return <MITClassSections
182+
registeredClass={registeredClass}
183+
setSectionForSubject={this.setSectionForSubject.bind(this)}
184+
isCustom={registeredClass.custom}
185+
removeCustomClass={this.removeCustomClass.bind(this)}
186+
/>;
106187
})}
188+
<button class="btn btn-default" onClick={this.addCustomClass.bind(this)}>
189+
<i class="fa fa-fw fa-plus-circle" /> Add another class
190+
</button>
107191

108192
<div>
109193
<h4 class="mitSettingsInfoTitle">PE registration</h4>

app/schools/mit/settings/MITClassSections.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export default class MITClassSections extends Component {
77
this.props.setSectionForSubject(subjectID, sectionCode);
88
}
99

10+
remove() {
11+
this.props.removeCustomClass(this.props.registeredClass);
12+
}
13+
1014
render(props, state) {
1115
var sectionGroups = {};
1216

@@ -46,7 +50,12 @@ export default class MITClassSections extends Component {
4650
}
4751

4852
return <div class="mitClassSections">
49-
<h4 class="mitClassSectionsName">{props.registeredClass.subjectID} {props.registeredClass.title}</h4>
53+
<h4 class="mitClassSectionsName">
54+
{props.registeredClass.subjectID} {props.registeredClass.title}
55+
{props.isCustom && <button class="btn btn-default btn-xs" onClick={this.remove.bind(this)}>
56+
<i class="fa fa-fw fa-minus-circle" /> remove class
57+
</button>}
58+
</h4>
5059
<div class="row">
5160
{sectionGroupCodes.map((sectionGroupCode, i) => {
5261
var codeToName = {

app/schools/mit/settings/MITClassSections.styl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
.mitClassSectionsName
33
margin-bottom: 0.5rem
44

5+
.btn
6+
margin-top: -0.3rem
7+
margin-left: 0.5rem
8+
59
.mitClassSectionGroup
610
.mitClassSectionGroupTitle
711
font-size: 1.6rem

0 commit comments

Comments
 (0)