Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add support for recess week
  • Loading branch information
BenMQ committed Nov 8, 2014
commit de0255c58a0e3c16bf3722b8f98e3b5fd516bfbf
2 changes: 1 addition & 1 deletion claims/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Configuration
**Activity Object**

- `activity_type`: Use the pre-defined constants: **ASSIGNMENT_MARKING** | **COURSE_MATERIAL_PREPARATION** | **TUTORIAL** | **CONSULTATION**
- `week`: An integer, indicating the week number of the sem. This is to facilitate convenient calculation of the date of activity. The script only supports activities performed from week 1 onwards, excluding recess week and reading week. If your activity falls on recess/reading week, you will have to add them into the system yourself manually.
- `week`: A positive integer, or string `'RECESS'`, indicating the week number of the sem. This is to facilitate convenient calculation of the date of activity. The script only supports activities performed from week 1 onwards.
- `day`: A string, with one of these values: **"MONDAY"**, **"TUESDAY"**, **"WEDNESDAY"**, **"THURSDAY"**, **"FRIDAY"**, **"SATURDAY"**, **"SUNDAY"**.
- `start_time`: A 4-character string, representing the starting time of the activity in 24-hour format. The minute value has to be 00 or 30.
- `end_time`: Similar to `start_time`, but represents the ending time of the activity.
Expand Down
22 changes: 13 additions & 9 deletions claims/claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ function Claim(config) {
this.remarks = config.duties;
this.first_day_of_sem = config.first_day_of_sem;
this.error = false;

var that = this;

// Ensure claiming for correct module!
if ($('h3:contains("Module")').text().substr(8) !== config.module) {
alert('Ensure that the module in config matches that of this page.');
Expand All @@ -116,8 +116,8 @@ function Claim(config) {
if (ACTIVITY_DICT[activity_type] === undefined || typeof activity_type !== 'string') {
throw 'Activity error: ' + activity_type + '. Activity type not supported.';
}
if (typeof week !== 'number' || week <= 0) {
throw 'Week error: ' + week + '. Week value has to be a positive number.';
if (typeof week !== 'number' && week !== 'RECESS' || week <= 0) {
throw 'Week error: ' + week + '. Week value has to be a positive number or RECESS.';
}
if (DAY_DICT[day_upper] === undefined || typeof day_upper !== 'string') {
throw 'Day error: ' + day + '. Day value has to be a valid day string.';
Expand All @@ -126,7 +126,7 @@ function Claim(config) {
function checkTime(time) {
var start_time_hour = time.slice(0,2);
var start_time_min = time.slice(2);
if (typeof time !== 'string' ||
if (typeof time !== 'string' ||
time.length != 4 ||
!(parseInt(start_time_hour) >= 0 && parseInt(start_time_hour) <= 23) ||
!(start_time_min === '00' || start_time_min === '30')) {
Expand All @@ -143,13 +143,13 @@ function Claim(config) {
throw 'Time error: end_time: ' + end_time + ' must be after start_time: ' + start_time + '.';
} else if (end_time_hour - start_time_hour > 8) {
throw 'Time error: ' + start_time + ' - ' + end_time + '. Activity cannot be more than 8 hours.';
}
}
} catch (err) {
error = true;
console.log(err);
}

return function() {
return function() {
that.makeClaim(activity_type, week, day, start_time, end_time);
};
}
Expand Down Expand Up @@ -179,7 +179,11 @@ function Claim(config) {

Claim.prototype.makeClaim = function(activity_type, week, day, start_time, end_time) {
var day_num = DAY_DICT[day];
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
if (week === 'RECESS') {
var number_of_days = 6*7 + day_num;
} else {
var number_of_days = (week < 7 ? week - 1 : week)*7 + day_num;
}
var activity_date = new Date();
activity_date.setTime(this.first_day_of_sem.getTime() + (number_of_days * 24 * 60 * 60 * 1000));
var claim_date_array = activity_date.toDateString().split(' ');
Expand Down Expand Up @@ -216,7 +220,7 @@ Claim.prototype.makeClaim = function(activity_type, week, day, start_time, end_t
Claim.prototype.deleteAllClaims = function() {
var that = this;
function deleteClaim(claim_id) {
$.post(POST_URL, {
$.post(POST_URL, {
mod_c: that.module,
claim_id: claim_id,
action: 'DELETE',
Expand Down