";
@@ -328,19 +328,19 @@
}
},
- createResultCourseMapping : function () {
+ createResultCourseMapping: function () {
var i;
// create a dummy result-course mapping
// to allow display of courses with no results
if (this.format === rg2.config.FORMAT_NO_RESULTS) {
this.resultCourses.length = 0;
for (i = 0; i < this.courses.length; i += 1) {
- this.resultCourses.push({courseid: this.courses[i].courseid, course: this.courses[i].name});
+ this.resultCourses.push({ courseid: this.courses[i].courseid, course: this.courses[i].name });
}
}
},
- validateData : function () {
+ validateData: function () {
if (!this.eventName) {
return 'Event name is not valid.';
}
@@ -376,7 +376,7 @@
},
- confirmCreateEvent : function () {
+ confirmCreateEvent: function () {
var valid, dlg;
valid = this.validateData();
if (valid !== 'OK') {
@@ -393,7 +393,7 @@
rg2.utils.createModalDialog(dlg);
},
- doCreateEvent : function () {
+ doCreateEvent: function () {
var self, data;
$("#event-create-dialog").dialog("destroy");
self = this;
@@ -401,11 +401,11 @@
$("#rg2-load-progress-label").text("Creating event");
$("#rg2-load-progress").show();
$.ajax({
- data : data,
- type : "POST",
- url : rg2Config.json_url + "?type=createevent",
- dataType : "json",
- success : function (data) {
+ data: data,
+ type: "POST",
+ url: rg2Config.json_url + "?type=createevent",
+ dataType: "json",
+ success: function (data) {
// save new cookie
self.user.y = data.keksi;
if (data.ok) {
@@ -418,17 +418,17 @@
rg2.utils.showWarningDialog("Save failed", data.status_msg + " Failed to create event. Please try again.");
}
},
- error : function () {
+ error: function () {
rg2.utils.showWarningDialog("Save failed", " Failed to create event.");
},
- complete : function () {
+ complete: function () {
$("#rg2-load-progress-label").text("");
$("#rg2-load-progress").hide();
}
});
},
- generateNewEventData : function () {
+ generateNewEventData: function () {
var data, text, user, i;
data = {};
data.name = this.eventName;
@@ -477,14 +477,14 @@
return JSON.stringify(data);
},
- hasZeroTime : function (time) {
+ hasZeroTime: function (time) {
if (time === 0 || time === '0' || time === '0:00' || time === '00:00') {
return true;
}
return false;
},
- sortResultItems : function (a, b) {
+ sortResultItems: function (a, b) {
// called after final courseids allocated so this is safe
if (a.courseid !== b.courseid) {
return a.courseid - b.courseid;
@@ -507,7 +507,7 @@
return a.time - b.time;
},
- renumberResults : function () {
+ renumberResults: function () {
// updates the course id and name when we know the mapping
// and deletes results for courses not required
var i, newResults, id;
@@ -525,7 +525,7 @@
this.results = newResults;
},
- getCourseName : function (id) {
+ getCourseName: function (id) {
var i;
for (i = 0; i < this.courses.length; i += 1) {
if (this.courses[i].courseid === id) {
@@ -535,7 +535,7 @@
return 0;
},
- mapResultsToCourses : function () {
+ mapResultsToCourses: function () {
// read through dropdowns and allocate courseid for each required course
// also delete unwanted courses
var i, selector, id, newCourses, courseid;
@@ -571,7 +571,7 @@
* @param {string} course - Course name from results file.
* @param {integer} courseidx - Course name index.
*/
- createCourseDropdown : function (course, courseidx) {
+ createCourseDropdown: function (course, courseidx) {
var i, j, idx, html;
idx = -1;
// check against list of course names first to default to results by course
@@ -615,7 +615,7 @@
return html;
},
- extractVariants : function () {
+ extractVariants: function () {
// called when saving score/relay courses
// creates all course variants once courseid has been set
var i, j, codes, course;
@@ -639,7 +639,7 @@
}
},
- getVariantID : function (codes, courseid) {
+ getVariantID: function (codes, courseid) {
// checks if a variant array of codes already exists
// adds it if it doesn't
// returns variantid
@@ -670,13 +670,13 @@
x.push(c.x);
y.push(c.y);
}
- this.variants.push({x: x, y: y, id: id, courseid: courseid, name: 'Variant ' + id, codes: codes});
+ this.variants.push({ x: x, y: y, id: id, courseid: courseid, name: 'Variant ' + id, codes: codes });
}
return id;
},
- getCourseIDForResult : function (course) {
+ getCourseIDForResult: function (course) {
var i;
for (i = 0; i < this.resultCourses.length; i += 1) {
if (this.resultCourses[i].course === course) {
@@ -686,7 +686,7 @@
return 0;
},
- setControlLocations : function () {
+ setControlLocations: function () {
// called when saving courses
// reads control locations and updates course details
var i, j, c;
@@ -699,7 +699,7 @@
}
},
- getControlXY : function (code) {
+ getControlXY: function (code) {
var i, c;
c = {};
c.x = 0;
@@ -714,7 +714,7 @@
return c;
},
- confirmUpdateEvent : function () {
+ confirmUpdateEvent: function () {
var dlg;
dlg = {};
dlg.selector = "
Are you sure you want to update this event?
";
@@ -726,7 +726,7 @@
rg2.utils.createModalDialog(dlg);
},
- doUpdateEvent : function () {
+ doUpdateEvent: function () {
var id, $url, data, json, self, user;
$("#event-update-dialog").dialog("destroy");
id = $("#rg2-event-selected").val();
@@ -744,11 +744,11 @@
json = JSON.stringify(data);
self = this;
$.ajax({
- data : json,
- type : "POST",
- url : $url,
- dataType : "json",
- success : function (data) {
+ data: json,
+ type: "POST",
+ url: $url,
+ dataType: "json",
+ success: function (data) {
// save new cookie
self.user.y = data.keksi;
if (data.ok) {
@@ -761,14 +761,14 @@
rg2.utils.showWarningDialog("Update failed", data.status_msg + ". Event update failed. Please try again.");
}
},
- error : function (jqXHR, textStatus) {
+ error: function (jqXHR, textStatus) {
/*jslint unparam:true*/
rg2.utils.showWarningDialog("Update failed", textStatus + ". Event update failed.");
}
});
},
- confirmDeleteRoute : function () {
+ confirmDeleteRoute: function () {
var dlg;
dlg = {};
dlg.selector = "
This route will be permanently deleted. Are you sure?
";
@@ -780,7 +780,7 @@
rg2.utils.createModalDialog(dlg);
},
- doDeleteRoute : function () {
+ doDeleteRoute: function () {
var id, $url, routeid, json, self;
$("#route-delete-dialog").dialog("destroy");
id = $("#rg2-event-selected").val();
@@ -789,11 +789,11 @@
json = JSON.stringify(this.user.encodeUser());
self = this;
$.ajax({
- data : json,
- type : "POST",
- url : $url,
- dataType : "json",
- success : function (data) {
+ data: json,
+ type: "POST",
+ url: $url,
+ dataType: "json",
+ success: function (data) {
// save new cookie
self.user.y = data.keksi;
if (data.ok) {
@@ -802,14 +802,14 @@
rg2.utils.showWarningDialog("Delete failed", data.status_msg + ". Delete failed. Please try again.");
}
},
- error : function (jqXHR, textStatus) {
+ error: function (jqXHR, textStatus) {
/*jslint unparam:true*/
rg2.utils.showWarningDialog("Delete failed", textStatus + ". Delete failed.");
}
});
},
- confirmDeleteEvent : function () {
+ confirmDeleteEvent: function () {
var dlg;
dlg = {};
dlg.selector = "
This event will be deleted. Are you sure?
";
@@ -821,7 +821,7 @@
rg2.utils.createModalDialog(dlg);
},
- doDeleteEvent : function () {
+ doDeleteEvent: function () {
var id, $url, json, self;
$("#event-delete-dialog").dialog("destroy");
id = $("#rg2-event-selected").val();
@@ -829,11 +829,11 @@
json = JSON.stringify(this.user.encodeUser());
self = this;
$.ajax({
- data : json,
- type : "POST",
- url : $url,
- dataType : "json",
- success : function (data) {
+ data: json,
+ type: "POST",
+ url: $url,
+ dataType: "json",
+ success: function (data) {
// save new cookie
self.user.y = data.keksi;
if (data.ok) {
@@ -845,14 +845,14 @@
rg2.utils.showWarningDialog("Delete failed", data.status_msg + ". Event delete failed. Please try again.");
}
},
- error : function (jqXHR, textStatus) {
+ error: function (jqXHR, textStatus) {
/*jslint unparam:true*/
rg2.utils.showWarningDialog("Delete failed", textStatus + ". Delete failed.");
}
});
},
- readResults : function () {
+ readResults: function () {
var format, reader, self;
reader = new FileReader();
self = this;
@@ -871,7 +871,7 @@
}
},
- checkResultsFileEncoding : function (evt) {
+ checkResultsFileEncoding: function (evt) {
// not pretty but it works
// need to use the array of possible encodings that we want to try if the file is not UTF-8
// might be better to use a synchronous read, but that needs a worker thread
@@ -902,7 +902,7 @@
this.readResults();
},
- processResultFile : function (evt) {
+ processResultFile: function (evt) {
var parsedResults = new rg2.ResultParser(evt, this.resultsFileFormat);
this.results = parsedResults.results;
this.resultCourses = parsedResults.resultCourses;
@@ -915,7 +915,7 @@
this.displayCourseAllocations();
},
- readCourses : function (evt) {
+ readCourses: function (evt) {
var reader, self;
reader = new FileReader();
reader.onerror = function () {
@@ -931,12 +931,12 @@
reader.readAsText(evt.target.files[0]);
},
- processCourseFile : function (evt) {
+ processCourseFile: function (evt) {
var parsedCourses;
this.coursesGeoreferenced = false;
this.backgroundLocked = false;
$('#btn-move-map-and-controls').prop('checked', false);
- this.handle = {x: null, y: null};
+ this.handle = { x: null, y: null };
this.newcontrols.deleteAllControls();
parsedCourses = new rg2.CourseParser(evt, this.worldfile, this.localworldfile);
this.courses = parsedCourses.courses;
@@ -950,7 +950,7 @@
rg2.redraw(false);
},
- getCourseInfoAsHTML : function () {
+ getCourseInfoAsHTML: function () {
var info, i;
if (this.courses.length) {
info = "
Course
Name
Controls
";
@@ -965,16 +965,16 @@
return info;
},
- getResultInfoAsHTML : function () {
+ getResultInfoAsHTML: function () {
var info, i, runners, oldcourse;
if (this.results.length) {
- info = "
Course
Winner
Time
Runners
";
+ info = "
Course
Winner
Time
Runners
";
runners = 0;
oldcourse = null;
for (i = 0; i < this.results.length; i += 1) {
if (this.results[i].course !== oldcourse) {
if (oldcourse !== null) {
- info += "
All information you have entered will be removed. Are you sure you want to reset?
",title:"Confirm reset",classes:"rg2-confirm-drawing-reset",doText:"Reset"}).onDo=this.doDrawingReset.bind(this),t.onCancel=this.doCancelDrawingReset.bind(this),rg2.utils.createModalDialog(t)},doChangeCourse:function(){$("#rg2-course-change-dialog").dialog("destroy"),rg2.courses.removeFromDisplay(this.gpstrack.routeData.courseid),null!==this.gpstrack.routeData.resultid&&rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!1),this.doDrawingReset(),this.initialiseCourse(this.pendingCourseid)},doCancelChangeCourse:function(){$("#rg2-course-select").val(this.gpstrack.routeData.courseid),this.pendingCourseid=null,$("#rg2-course-change-dialog").dialog("destroy")},showCourseInProgress:function(){null!==this.gpstrack.routeData.courseid&&(this.isScoreCourse?rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!0):rg2.courses.putOnDisplay(this.gpstrack.routeData.courseid))},setName:function(t){var e,r;isNaN(t)||((e=rg2.results.getFullResult(t)).hasValidTrack&&(r=rg2.t("If you draw a new route it will overwrite the old route for this runner.")+" "+rg2.t("GPS routes are saved separately and will not be overwritten."),rg2.utils.showWarningDialog(rg2.t("Route already drawn"),r)),null!==this.gpstrack.routeData.resultid&&rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!1),this.gpstrack.routeData.resultid=e.resultid,this.gpstrack.routeData.name=e.name,this.gpstrack.routeData.splits=e.splits,this.isScoreCourse?(rg2.results.putScoreCourseOnDisplay(e.resultid,!0),this.controlx=e.scorex,this.controly=e.scorey,this.gpstrack.routeData.x.length=0,this.gpstrack.routeData.y.length=0,this.gpstrack.routeData.x[0]=this.controlx[0],this.gpstrack.routeData.y[0]=this.controly[0],this.gpstrack.routeData.controlx=this.controlx,this.gpstrack.routeData.controly=this.controly,this.nextControl=1,rg2.redraw(!1)):(this.nextControl=this.getNextValidControl(0),this.previousValidControlIndex=0),this.alignMapToAngle(0),this.startDrawing())},setNameAndTime:function(){var t,e;(e=$("#rg2-name-entry").val())?$("#rg2-name").addClass("valid"):$("#rg2-name").removeClass("valid"),(t=$("#rg2-time-entry").val()).match(/\d+[:.][0-5]\d$/)?$("#rg2-time").addClass("valid"):($("#rg2-time").removeClass("valid"),t=null),e&&t&&(t=t.replace(".",":"),this.gpstrack.routeData.name=e,this.gpstrack.routeData.resultid=0,this.gpstrack.routeData.totaltime=t,this.gpstrack.routeData.startsecs=0,this.gpstrack.routeData.time[0]=rg2.utils.getSecsFromHHMMSS(t),this.gpstrack.routeData.totalsecs=rg2.utils.getSecsFromHHMMSS(t),this.nextControl=1,this.gpstrack.routeData.splits=[0,this.gpstrack.routeData.totalsecs],this.previousValidControlIndex=0,rg2.redraw(!1),this.startDrawing())},startDrawing:function(){$("#btn-three-seconds").button("enable"),$("#rg2-load-gps-file").val(null).button("enable"),rg2.redraw(!1)},alignMapToAngle:function(t){var e;!rg2.options.alignMap||tThis route will be permanently deleted. Are you sure?
",title:"Confirm route delete",classes:"rg2-confirm-route-delete-dialog",doText:"Delete route"}).onDo=this.doDeleteRoute.bind(this),e.onCancel=this.doCancelDeleteRoute.bind(this),rg2.utils.createModalDialog(e)},doCancelDeleteRoute:function(){$("#route-delete-dialog").dialog("destroy")},doDeleteRoute:function(){var t,e,r;$("#route-delete-dialog").dialog("destroy"),r=rg2.results.getDeletionInfo(this.routeToDelete),t=rg2Config.json_url+"?type=deletemyroute&id="+rg2.events.getKartatEventID()+"&routeid="+r.id,e=JSON.stringify({token:r.token}),$.ajax({data:e,type:"POST",url:t,dataType:"json",success:function(t){t.ok?(rg2.utils.showWarningDialog(rg2.t("Route deleted"),rg2.t("Route has been deleted")),rg2.removeDrawnRouteDetails({eventid:parseInt(t.eventid,10),id:parseInt(t.routeid,10)}),rg2.getEvents()):rg2.utils.showWarningDialog(rg2.t("Delete failed"),rg2.t("Delete failed"))},error:function(t,e){rg2.utils.showWarningDialog(rg2.t("Delete failed"),rg2.t("Delete failed"))}})},waitThreeSeconds:function(){this.addRouteDataPoint(this.gpstrack.routeData.x[this.gpstrack.routeData.x.length-1],this.gpstrack.routeData.y[this.gpstrack.routeData.y.length-1]),rg2.redraw(!1)},closeEnough:function(t,e){var r;return r=rg2.options.snap?8:2,Math.abs(t-this.controlx[this.nextControl])=i.time?this.scaleRotateAroundSingleLockedPoint(t,e,a,s.handles.getStartHandle().time,a.time):n.time",""!==this.events[r].comment&&(e+=""),this.events[r].worldfile.valid&&(e+=" "),this.events[r].locked&&(e+=" "),e+=this.events[r].date+": "+this.events[r].name+"";return e}},rg2.Events=t}(),function(){function t(){this.lat=[],this.lon=[],this.startOffset=0,this.baseX=[],this.baseY=[],this.handles=new rg2.Handles,this.savedBaseX=[],this.savedBaseY=[],this.fileLoaded=!1,this.fileName="",this.fileType="",this.routeData=new rg2.RouteData,this.xml="",this.autofitOffset=null}t.prototype={Constructor:t,initialiseGPS:function(){this.lat.length=0,this.lon.length=0,this.startOffset=0,this.baseX.length=0,this.baseY.length=0,this.handles.deleteAllHandles(),this.savedBaseX.length=0,this.savedBaseY.length=0,this.fileLoaded=!1,this.routeData.x.length=0,this.routeData.y.length=0,this.routeData.time.length=0},uploadGPS:function(t){var e,r;e=new FileReader,this.fileName=t.target.files[0].name,e.onerror=function(){rg2.utils.showWarningDialog("GPS file problem","Unable to open GPS file.")},r=this,e.onload=function(t){try{if(r.fileType=r.fileName.slice(-3).toLowerCase(),"gpx"!==r.fileType&&"tcx"!==r.fileType)return void rg2.utils.showWarningDialog("GPS file problem","File type not recognised. Please check you have selected the correct file.");$("#rg2-load-gps-file").button("disable"),r.xml=$.parseXML(t.target.result),r.processGPSFile()}catch(t){return void rg2.utils.showWarningDialog("GPS file problem","File is not valid XML. Please check you have selected the correct file.")}},e.readAsText(t.target.files[0])},processGPSFile:function(){this.initialiseGPS(),"gpx"===this.fileType?this.processGPX():this.processTCX(),this.processGPSTrack()},processGPX:function(){var t,e,r,s,i,a;for(t=this.xml.getElementsByTagName("trkseg"),r=0;r=rg2.config.GPS_RESULT_OFFSET?(this.isGPSTrack=!0,e=rg2.results.getTimeAndSplitsForID(this.rawid),this.time=e.time,this.splits=e.splits,this.time===rg2.config.TIME_NOT_FOUND&&(this.time=t.time)):this.isGPSTrack=!1},adjustRawSplits:function(t){var e;for(t.splice(0,0,0),e=1;ei+s?(e=Math.round(255*(this.speedColour[t]-s)/s),r=255):(r=this.speedColour[t]>i?Math.round(255*(this.speedColour[t]-i)/s):0,e=255),this.speedColour[t]="#",e<16&&(this.speedColour[t]+="0"),this.speedColour[t]+=e.toString(16),r<16&&(this.speedColour[t]+="0"),this.speedColour[t]+=r.toString(16)+"00"},getInitials:function(t){var e,r,s,i;if(null===t)return"??";for(s=(t=t.trim().replace(/GPS/g,"*")).length,r=!(i=""),e=0;erg2.config.GPS_RESULT_OFFSET&&""==t[r].coursename&&(t[r].coursename=rg2.courses.getCourseDetails(t[r].courseid).name),i=e?(a=t[r].variant,new rg2.Result(t[r],e,n[a],o[a],l[a])):new rg2.Result(t[r],e),this.results.push(i);this.setDeletionInfo(),this.setScoreCourseInfo(),this.sanitiseSplits(),this.generateLegPositions()},setScoreCourseInfo:function(){var t,e;for(t=0;t=rg2.config.GPS_RESULT_OFFSET&&(void 0===(e=this.getFullResultForRawID(this.results[t].rawid))||void 0!==e.scorex&&(this.results[t].scorex=e.scorex,this.results[t].scorey=e.scorey,this.results[t].scorecodes=e.scorecodes))},setDeletionInfo:function(){var t,e,r,s,i;for(r=rg2.events.getKartatEventID(),s=[],i=rg2.options.drawnRoutes,t=0;tthis.results[e].lastValidSplit?0:this.results[e].splits[r],i.push({time:o,id:e}));for(i.sort(this.sortLegTimes),e=a=n=0;e"+rg2.courses.getCourseName(this.results[t].courseid),e+=": "+this.results[t].name+"");return e},getDisplayedTrackDetails:function(){var t,e,r;for(e=[],t=0;te.courseid?1:e.courseid>t.courseid?-1:t.rawid===e.rawid?t.resultid-e.resultid:t.rawid-e.rawid},formatResultListAsAccordion:function(){var t,e,r,s,i,a;if(0===this.results.length)return"
All information you have entered will be removed. Are you sure you want to reset?
",title:"Confirm reset",classes:"rg2-confirm-drawing-reset",doText:"Reset"}).onDo=this.doDrawingReset.bind(this),t.onCancel=this.doCancelDrawingReset.bind(this),rg2.utils.createModalDialog(t)},doChangeCourse:function(){$("#rg2-course-change-dialog").dialog("destroy"),rg2.courses.removeFromDisplay(this.gpstrack.routeData.courseid),null!==this.gpstrack.routeData.resultid&&rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!1),this.doDrawingReset(),this.initialiseCourse(this.pendingCourseid)},doCancelChangeCourse:function(){$("#rg2-course-select").val(this.gpstrack.routeData.courseid),this.pendingCourseid=null,$("#rg2-course-change-dialog").dialog("destroy")},showCourseInProgress:function(){null!==this.gpstrack.routeData.courseid&&(this.isScoreCourse?rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!0):rg2.courses.putOnDisplay(this.gpstrack.routeData.courseid))},setName:function(t){var e,r;isNaN(t)||((e=rg2.results.getFullResult(t)).hasValidTrack&&(r=rg2.t("If you draw a new route it will overwrite the old route for this runner.")+" "+rg2.t("GPS routes are saved separately and will not be overwritten."),rg2.utils.showWarningDialog(rg2.t("Route already drawn"),r)),null!==this.gpstrack.routeData.resultid&&rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!1),this.gpstrack.routeData.resultid=e.resultid,this.gpstrack.routeData.name=e.name,this.gpstrack.routeData.splits=e.splits,this.isScoreCourse?(rg2.results.putScoreCourseOnDisplay(e.resultid,!0),this.controlx=e.scorex,this.controly=e.scorey,this.gpstrack.routeData.x.length=0,this.gpstrack.routeData.y.length=0,this.gpstrack.routeData.x[0]=this.controlx[0],this.gpstrack.routeData.y[0]=this.controly[0],this.gpstrack.routeData.controlx=this.controlx,this.gpstrack.routeData.controly=this.controly,this.nextControl=1,rg2.redraw(!1)):(this.nextControl=this.getNextValidControl(0),this.previousValidControlIndex=0),this.alignMapToAngle(0),this.startDrawing())},setNameAndTime:function(){var t,e;(e=$("#rg2-name-entry").val())?$("#rg2-name").addClass("valid"):$("#rg2-name").removeClass("valid"),(t=$("#rg2-time-entry").val()).match(/\d+[:.][0-5]\d$/)?$("#rg2-time").addClass("valid"):($("#rg2-time").removeClass("valid"),t=null),e&&t&&(t=t.replace(".",":"),this.gpstrack.routeData.name=e,this.gpstrack.routeData.resultid=0,this.gpstrack.routeData.totaltime=t,this.gpstrack.routeData.startsecs=0,this.gpstrack.routeData.time[0]=rg2.utils.getSecsFromHHMMSS(t),this.gpstrack.routeData.totalsecs=rg2.utils.getSecsFromHHMMSS(t),this.nextControl=1,this.gpstrack.routeData.splits=[0,this.gpstrack.routeData.totalsecs],this.previousValidControlIndex=0,rg2.redraw(!1),this.startDrawing())},startDrawing:function(){$("#btn-three-seconds").button("enable"),$("#rg2-load-gps-file").val(null).button("enable"),rg2.redraw(!1)},alignMapToAngle:function(t){var e;!rg2.options.alignMap||tThis route will be permanently deleted. Are you sure?",title:"Confirm route delete",classes:"rg2-confirm-route-delete-dialog",doText:"Delete route"}).onDo=this.doDeleteRoute.bind(this),e.onCancel=this.doCancelDeleteRoute.bind(this),rg2.utils.createModalDialog(e)},doCancelDeleteRoute:function(){$("#route-delete-dialog").dialog("destroy")},doDeleteRoute:function(){var t,e,r;$("#route-delete-dialog").dialog("destroy"),r=rg2.results.getDeletionInfo(this.routeToDelete),t=rg2Config.json_url+"?type=deletemyroute&id="+rg2.events.getKartatEventID()+"&routeid="+r.id,e=JSON.stringify({token:r.token}),$.ajax({data:e,type:"POST",url:t,dataType:"json",success:function(t){t.ok?(rg2.utils.showWarningDialog(rg2.t("Route deleted"),rg2.t("Route has been deleted")),rg2.removeDrawnRouteDetails({eventid:parseInt(t.eventid,10),id:parseInt(t.routeid,10)}),rg2.getEvents()):rg2.utils.showWarningDialog(rg2.t("Delete failed"),rg2.t("Delete failed"))},error:function(t,e){rg2.utils.showWarningDialog(rg2.t("Delete failed"),rg2.t("Delete failed"))}})},waitThreeSeconds:function(){this.addRouteDataPoint(this.gpstrack.routeData.x[this.gpstrack.routeData.x.length-1],this.gpstrack.routeData.y[this.gpstrack.routeData.y.length-1]),rg2.redraw(!1)},closeEnough:function(t,e){var r;return r=rg2.options.snap?8:2,Math.abs(t-this.controlx[this.nextControl])=i.time?this.scaleRotateAroundSingleLockedPoint(t,e,a,s.handles.getStartHandle().time,a.time):n.time",""!==this.events[r].comment&&(e+=""),this.events[r].worldfile.valid&&(e+=" "),this.events[r].locked&&(e+=" "),e+=this.events[r].date+": "+this.events[r].name+"";return e}},rg2.Events=t}(),function(){function t(){this.lat=[],this.lon=[],this.startOffset=0,this.baseX=[],this.baseY=[],this.handles=new rg2.Handles,this.savedBaseX=[],this.savedBaseY=[],this.fileLoaded=!1,this.fileName="",this.fileType="",this.routeData=new rg2.RouteData,this.xml="",this.autofitOffset=null}t.prototype={Constructor:t,initialiseGPS:function(){this.lat.length=0,this.lon.length=0,this.startOffset=0,this.baseX.length=0,this.baseY.length=0,this.handles.deleteAllHandles(),this.savedBaseX.length=0,this.savedBaseY.length=0,this.fileLoaded=!1,this.routeData.x.length=0,this.routeData.y.length=0,this.routeData.time.length=0},uploadGPS:function(t){var e,r;e=new FileReader,this.fileName=t.target.files[0].name,e.onerror=function(){rg2.utils.showWarningDialog("GPS file problem","Unable to open GPS file.")},r=this,e.onload=function(t){try{if(r.fileType=r.fileName.slice(-3).toLowerCase(),"gpx"!==r.fileType&&"tcx"!==r.fileType)return void rg2.utils.showWarningDialog("GPS file problem","File type not recognised. Please check you have selected the correct file.");$("#rg2-load-gps-file").button("disable"),r.xml=$.parseXML(t.target.result),r.processGPSFile()}catch(t){return void rg2.utils.showWarningDialog("GPS file problem","File is not valid XML. Please check you have selected the correct file.")}},e.readAsText(t.target.files[0])},processGPSFile:function(){this.initialiseGPS(),"gpx"===this.fileType?this.processGPX():this.processTCX(),this.processGPSTrack()},processGPX:function(){var t,e,r,s,i,a;for(t=this.xml.getElementsByTagName("trkseg"),r=0;r=rg2.config.GPS_RESULT_OFFSET?(this.isGPSTrack=!0,e=rg2.results.getTimeAndSplitsForID(this.rawid),this.time=e.time,this.splits=e.splits,this.time===rg2.config.TIME_NOT_FOUND&&(this.time=t.time)):this.isGPSTrack=!1},adjustRawSplits:function(t){var e;for(t.splice(0,0,0),e=1;ei+s?(e=Math.round(255*(this.speedColour[t]-s)/s),r=255):(r=this.speedColour[t]>i?Math.round(255*(this.speedColour[t]-i)/s):0,e=255),this.speedColour[t]="#",e<16&&(this.speedColour[t]+="0"),this.speedColour[t]+=e.toString(16),r<16&&(this.speedColour[t]+="0"),this.speedColour[t]+=r.toString(16)+"00"},getInitials:function(t){var e,r,s,i;if(null===t)return"??";for(s=(t=t.trim().replace(/GPS/g,"*")).length,r=!(i=""),e=0;erg2.config.GPS_RESULT_OFFSET&&""===t[r].coursename&&(t[r].coursename=rg2.courses.getCourseDetails(t[r].courseid).name),i=e?(a=t[r].variant,new rg2.Result(t[r],e,n[a],o[a],l[a])):new rg2.Result(t[r],e),this.results.push(i);this.setDeletionInfo(),this.setScoreCourseInfo(),this.sanitiseSplits(e),this.generateLegPositions()},setScoreCourseInfo:function(){var t,e;for(t=0;t=rg2.config.GPS_RESULT_OFFSET&&(void 0===(e=this.getFullResultForRawID(this.results[t].rawid))||void 0!==e.scorex&&(this.results[t].scorex=e.scorex,this.results[t].scorey=e.scorey,this.results[t].scorecodes=e.scorecodes))},setDeletionInfo:function(){var t,e,r,s,i;for(r=rg2.events.getKartatEventID(),s=[],i=rg2.options.drawnRoutes,t=0;tthis.results[e].lastValidSplit?0:this.results[e].splits[r],i.push({time:o,id:e}));for(i.sort(this.sortLegTimes),e=a=n=0;e"+rg2.courses.getCourseName(this.results[t].courseid),e+=": "+this.results[t].name+"");return e},getDisplayedTrackDetails:function(){var t,e,r;for(e=[],t=0;te.courseid?1:e.courseid>t.courseid?-1:t.rawid===e.rawid?t.resultid-e.resultid:t.rawid-e.rawid},formatResultListAsAccordion:function(){var t,e,r,s,i,a;if(0===this.results.length)return"
",$("#rg2-course-allocations").empty().append(t)}},createResultCourseMapping:function(){var e;if(this.format===rg2.config.FORMAT_NO_RESULTS)for(e=this.resultCourses.length=0;eAre you sure you want to create this event?",title:"Confirm event creation",classes:"rg2-confirm-create-event-dialog",doText:"Create event"}).onDo=this.doCreateEvent.bind(this),t.onCancel=rg2.managerUI.doCancelCreateEvent.bind(this),rg2.utils.createModalDialog(t)):rg2.utils.showWarningDialog("Event set-up incomplete",e+" Please enter all necessary information and make sure controls are aligned before creating the event.")},doCreateEvent:function(){var t,e;$("#event-create-dialog").dialog("destroy"),e=(t=this).generateNewEventData(),$("#rg2-load-progress-label").text("Creating event"),$("#rg2-load-progress").show(),$.ajax({data:e,type:"POST",url:rg2Config.json_url+"?type=createevent",dataType:"json",success:function(e){t.user.y=e.keksi,e.ok?(rg2.utils.showWarningDialog("Event created",t.eventName+" has been added with id "+e.newid+"."),window.open(rg2Config.json_url.replace("rg2api.php","")+"#"+e.newid),rg2.getEvents(),rg2.managerUI.setEvent()):rg2.utils.showWarningDialog("Save failed",e.status_msg+" Failed to create event. Please try again.")},error:function(){rg2.utils.showWarningDialog("Save failed"," Failed to create event.")},complete:function(){$("#rg2-load-progress-label").text(""),$("#rg2-load-progress").hide()}})},generateNewEventData:function(){var e,t,s,r;for((e={}).name=this.eventName,e.mapid=this.maps[this.mapIndex].mapid,e.eventdate=this.eventDate,(t=$("#rg2-event-comments").val())===rg2.config.DEFAULT_EVENT_COMMENT?e.comments="":e.comments=t,e.locked=$("#chk-read-only").prop("checked"),e.club=this.club,e.format=this.format,$("#btn-score-event").prop("checked")&&(e.format=rg2.config.FORMAT_SCORE_EVENT),e.level=this.eventLevel,this.drawingCourses&&(this.courses.push(this.drawnCourse),this.createResultCourseMapping()),this.setControlLocations(),this.mapResultsToCourses(),this.renumberResults(),e.format===rg2.config.FORMAT_SCORE_EVENT&&(this.extractVariants(),e.variants=this.variants.slice(0)),e.courses=this.courses.slice(0),this.sortResults?e.results=this.results.slice(0).sort(this.sortResultItems):e.results=this.results.slice(0),r=0;r",s=0;s"+this.courses[s].name+"";return n+=""},extractVariants:function(){var e,t,s,r;for(e=this.variants.length=0;eAre you sure you want to update this event?",title:"Confirm event update",classes:"rg2-confirm-update-dialog",doText:"Update event"}).onDo=this.doUpdateEvent.bind(this),e.onCancel=rg2.managerUI.doCancelUpdateEvent.bind(this),rg2.utils.createModalDialog(e)},doUpdateEvent:function(){var t,e,s,r,o,n;$("#event-update-dialog").dialog("destroy"),t=$("#rg2-event-selected").val(),e=rg2Config.json_url+"?type=editevent&id="+t,(s={}).comments=$("#rg2-edit-event-comments").val(),s.locked=$("#chk-edit-read-only").prop("checked"),s.name=$("#rg2-event-name-edit").val(),s.type=$("#rg2-event-level-edit").val(),s.eventdate=$("#rg2-event-date-edit").val(),s.club=$("#rg2-club-name-edit").val(),n=this.user.encodeUser(),s.x=n.x,s.y=n.y,r=JSON.stringify(s),o=this,$.ajax({data:r,type:"POST",url:e,dataType:"json",success:function(e){o.user.y=e.keksi,e.ok?(rg2.utils.showWarningDialog("Event updated","Event "+t+" has been updated."),rg2.events.setActiveEventID(null),rg2.ui.setTitleBar(),rg2.getEvents(),rg2.managerUI.setEvent()):rg2.utils.showWarningDialog("Update failed",e.status_msg+". Event update failed. Please try again.")},error:function(e,t){rg2.utils.showWarningDialog("Update failed",t+". Event update failed.")}})},confirmDeleteRoute:function(){var e;(e={selector:"
This route will be permanently deleted. Are you sure?
",title:"Confirm route delete",classes:"rg2-confirm-route-delete-dialog",doText:"Delete route"}).onDo=this.doDeleteRoute.bind(this),e.onCancel=rg2.managerUI.doCancelDeleteRoute.bind(this),rg2.utils.createModalDialog(e)},doDeleteRoute:function(){var e,t,s,r,o;$("#route-delete-dialog").dialog("destroy"),e=$("#rg2-event-selected").val(),s=$("#rg2-route-selected").val(),t=rg2Config.json_url+"?type=deleteroute&id="+e+"&routeid="+s,r=JSON.stringify(this.user.encodeUser()),o=this,$.ajax({data:r,type:"POST",url:t,dataType:"json",success:function(e){o.user.y=e.keksi,e.ok?rg2.utils.showWarningDialog("Route deleted","Route "+s+" has been deleted."):rg2.utils.showWarningDialog("Delete failed",e.status_msg+". Delete failed. Please try again.")},error:function(e,t){rg2.utils.showWarningDialog("Delete failed",t+". Delete failed.")}})},confirmDeleteEvent:function(){var e;(e={selector:"
This event will be deleted. Are you sure?
",title:"Confirm event delete",classes:"rg2-confirm-delete-event-dialog",doText:"Delete event"}).onDo=this.doDeleteEvent.bind(this),e.onCancel=rg2.managerUI.doCancelDeleteEvent.bind(this),rg2.utils.createModalDialog(e)},doDeleteEvent:function(){var t,e,s,r;$("#event-delete-dialog").dialog("destroy"),t=$("#rg2-event-selected").val(),e=rg2Config.json_url+"?type=deleteevent&id="+t,s=JSON.stringify(this.user.encodeUser()),r=this,$.ajax({data:s,type:"POST",url:e,dataType:"json",success:function(e){r.user.y=e.keksi,e.ok?(rg2.utils.showWarningDialog("Event deleted","Event "+t+" has been deleted."),rg2.getEvents(),rg2.managerUI.setEvent(),$("#rg2-event-selected").empty()):rg2.utils.showWarningDialog("Delete failed",e.status_msg+". Event delete failed. Please try again.")},error:function(e,t){rg2.utils.showWarningDialog("Delete failed",t+". Delete failed.")}})},readResults:function(){var e,t,s;t=new FileReader,s=this,t.onerror=function(){rg2.utils.showWarningDialog("Results file error","The selected results file could not be read.")},t.onload=function(e){s.checkResultsFileEncoding(e)},"XML"===(e=this.resultsOrCourseFile.name.substr(-3,3).toUpperCase())||"CSV"===e?(this.resultsFileFormat=e,t.readAsText(this.resultsOrCourseFile,this.encodings[this.encodingIndex])):rg2.utils.showWarningDialog("File type error","Results file type is not recognised. Please select a valid file.")},checkResultsFileEncoding:function(e){var t,s,r;if(0===(t=this.testForInvalidCharacters(e.target.result))||this.useThisEncoding)this.processResultFile(e);else{if(this.errorCount[this.encodingIndex]=t,this.encodingIndex+=1,this.encodingIndex===this.encodings.length){for(s=99999,r=0;rthis.errorCount[r]&&(this.encodingIndex=r,s=this.errorCount[r]);this.useThisEncoding=!0}this.readResults()}},processResultFile:function(e){var t=new rg2.ResultParser(e,this.resultsFileFormat);this.results=t.results,this.resultCourses=t.resultCourses,t.valid?$("#rg2-select-results-file").addClass("valid"):$("#rg2-select-results-file").removeClass("valid"),rg2.managerUI.displayResultInfo(this.getResultInfoAsHTML()),this.displayCourseAllocations()},readCourses:function(e){var t,s;(t=new FileReader).onerror=function(){rg2.utils.showWarningDialog("Course file error","The selected course file could not be read.")},s=this,t.onload=function(e){s.processCourseFile(e)},t.readAsText(e.target.files[0])},processCourseFile:function(e){var t;this.coursesGeoreferenced=!1,this.backgroundLocked=!1,$("#btn-move-map-and-controls").prop("checked",!1),this.handle={x:null,y:null},this.newcontrols.deleteAllControls(),t=new rg2.CourseParser(e,this.worldfile,this.localworldfile),this.courses=t.courses,this.newcontrols=t.newcontrols,this.mapping=t.mapping,this.coursesGeoreferenced=t.georeferenced,rg2.managerUI.displayCourseInfo(this.getCourseInfoAsHTML()),this.createResultCourseMapping(),this.displayCourseAllocations(),this.fitControlsToMap(),rg2.redraw(!1)},getCourseInfoAsHTML:function(){var e,t;if(this.courses.length){for(e="
"}else e="No valid results found.";return e},testForInvalidCharacters:function(e){var t,s;for(t=s=0;tthis.mapWidth||s.minY>this.mapHeight||s.maxY<0?rg2.utils.showWarningDialog("Course file problem","Your course file does not match the map co-ordinates. Please check you have selected the correct file."):t=!0),t)this.backgroundLocked=!0,this.controlsAdjusted=!0,$("#btn-move-map-and-controls").prop("checked",!0);else for(.8,e=0;eAre you sure you want to add this map?",title:"Confirm new map",classes:"rg2-confirm-add-map-dialog",doText:"Add map"}).onDo=this.doUploadMapFile.bind(this),e.onCancel=rg2.managerUI.doCancelAddMap.bind(this),rg2.utils.createModalDialog(e)},doUploadMapFile:function(){var e,t,s,r;$("#add-map-dialog").dialog("destroy"),e=rg2Config.json_url+"?type=uploadmapfile",t=this.user.encodeUser(),s=this,(r=new FormData).append(this.mapFile.name,this.mapFile),r.append("name",this.mapFile.name),r.append("x",t.x),r.append("y",t.y),$("#rg2-load-progress-label").text("Saving map"),$("#rg2-load-progress").show(),$.ajax({url:e,data:r,type:"POST",mimeType:"multipart/form-data",processData:!1,contentType:!1,dataType:"json",success:function(e){s.user.y=e.keksi,e.ok?s.doAddMap():rg2.utils.showWarningDialog("Save failed",e.status_msg+". Failed to save map. Please try again.")},error:function(e,t){console.log(t)},complete:function(){$("#rg2-load-progress-label").text(""),$("#rg2-load-progress").hide()}})},doAddMap:function(){var e,t,s,r,o;e=rg2Config.json_url+"?type=addmap",t={},this.newMap.localworldfile=this.localworldfile,t=this.newMap,s=this.user.encodeUser(),t.x=s.x,t.y=s.y,r=JSON.stringify(t),o=this,$.ajax({data:r,type:"POST",url:e,dataType:"json",success:function(e){o.user.y=e.keksi,e.ok?(rg2.utils.showWarningDialog("Map added",o.newMap.name+" has been added with id "+e.newid+"."),o.getMaps()):rg2.utils.showWarningDialog("Save failed",e.status_msg+". Failed to save map. Please try again.")},error:function(e,t){console.log(t)}})},readGeorefFile:function(e){var t,s;t=new FileReader,s=this;try{t.readAsText(e.target.files[0])}catch(e){return void rg2.utils.showWarningDialog("File read error","Failed to open selected world file.")}t.onerror=function(){rg2.utils.showWarningDialog("World file error","The selected world file could not be read.")},t.onload=function(e){var t;t=e.target.result.split(/[\r\n]+/g),delete s.localworldfile,s.localworldfile=new rg2.Worldfile({A:t[0],B:t[2],C:t[4],D:t[1],E:t[3],F:t[5]}),$("#rg2-georef-selected").val(s.georefsystems.getDefault()),s.convertWorldFile(s.georefsystems.getDefault())}},convertWorldFile:function(e){try{var t,s,r,o,n,i,a,l,g,c,u;if(s=rg2.getMapSize(),this.mapWidth=s.width,this.mapHeight=s.height,!this.localworldfile.valid||0===this.mapWidth||"none"===e)throw"Do not georeference";for(Proj4js.defs[e]=this.georefsystems.getParams(e),r=new Proj4js.Proj(e),o=new Proj4js.Proj("EPSG:4326"),a=[0,this.mapWidth,this.mapWidth,0],l=[0,this.mapHeight,0,this.mapHeight],n=[],i=[],t=0;t<4;t+=1)n[t]=this.localworldfile.getLon(a[t],l[t]),i[t]=this.localworldfile.getLat(a[t],l[t]);for(this.newMap.xpx.length=0,this.newMap.ypx.length=0,this.newMap.lat.length=0,this.newMap.lon.length=0,g=[],t=0;t<4;t+=1)(c={}).x=n[t],c.y=i[t],g.push(c),Proj4js.transform(r,o,g[t]),this.newMap.xpx.push(a[t]),this.newMap.ypx.push(l[t]),this.newMap.lat.push(g[t].y),this.newMap.lon.push(g[t].x);(u={}).C=g[0].x,u.F=g[0].y,u.A=(g[2].x-u.C)/a[2],u.B=(g[3].x-u.C)/l[3],u.D=(g[2].y-u.F)/a[2],u.E=(g[3].y-u.F)/l[3],delete this.newMap.worldfile,this.newMap.worldfile=new rg2.Worldfile(u),this.updateGeorefDisplay(),this.updateGeorefMap()}catch(e){return delete this.newMap.worldfile,this.newMap.worldfile=new rg2.Worldfile(0),this.updateGeorefDisplay(),void this.updateGeorefMap()}},updateGeorefDisplay:function(){var e,t;for(e=["A","B","C","D","E","F"],t=0;t=this.CSVFormat.FIRST_SPLIT_IDX&&(r=this.extractSingleCSVResult(s)).valid&&(delete r.valid,this.results.push(r))},getPosition:function(e){var t;return t=parseInt(e[this.CSVFormat.POSITION_IDX],10),isNaN(t)&&(t=""),t},extractSingleCSVResult:function(e){var t,s;return(t={valid:!0}).chipid=e[this.CSVFormat.CHIP_IDX],t.name=(e[this.CSVFormat.FIRST_NAME_IDX]+" "+e[this.CSVFormat.SURNAME_IDX]).trim().replace(/\"/g,""),t.dbid=e[this.CSVFormat.DB_IDX],t.starttime=rg2.utils.getSecsFromHHMMSS(e[this.CSVFormat.START_TIME_IDX]),t.time=e[this.CSVFormat.TOTAL_TIME_IDX],t.position=this.getPosition(e),t.status=this.getSICSVStatus(e[this.CSVFormat.NC_IDX],e[this.CSVFormat.CLASSIFIER_IDX]),t.club=e[this.CSVFormat.CLUB_IDX].trim().replace(/\"/g,""),t.course=e[this.CSVFormat.COURSE_IDX],""===t.course&&(t.valid=!1),t.controls=parseInt(e[this.CSVFormat.NUM_CONTROLS_IDX],10),s=this.extractSISplits(e,t.controls),t.splits=s.splits,""!==t.splits&&(t.splits+=";"),t.splits+=rg2.utils.getSecsFromHHMMSS(t.time),t.codes=s.codes,t},extractSISplits:function(e,t){var s,r,o,n;for(n=this.CSVFormat.FIRST_SPLIT_IDX,o=this.CSVFormat.FIRST_CODE_IDX,r={splits:"",codes:[]},s=0;sOpenStreetMap'}).addTo(this.georefmap)},logIn:function(){var e,t,s;return e=rg2Config.json_url+"?type=login",t=JSON.stringify(this.user.encodeUser()),s=this,$.ajax({type:"POST",dataType:"json",data:t,url:e,cache:!1,success:function(e){s.user.y=e.keksi,e.ok?s.enableEventEdit():rg2.utils.showWarningDialog("Login failed","Login failed. Please try again.")},error:function(){rg2.utils.showWarningDialog("Login failed","User name or password incorrect. Please try again.")}}),!1},setButtons:function(){var t;t=this,$("#btn-create-event").button().click(function(){t.confirmCreateEvent()}).button("enable"),$("#btn-update-event").button().click(function(){t.confirmUpdateEvent()}).button("disable"),$("#btn-delete-route").button().click(function(){t.confirmDeleteRoute()}).button("disable"),$("#btn-delete-event").button().click(function(){t.confirmDeleteEvent()}).button("disable"),$("#btn-add-map").button().click(function(){t.confirmAddMap()}).button("disable"),$("#btn-draw-courses").button().click(function(){t.startDrawingCourses()}),$("#rg2-load-georef-file").button().change(function(e){t.readGeorefFile(e)}),$("#rg2-load-map-file").button().change(function(e){t.validateMapUpload(this.files[0]),t.readMapFile(e)}),$("#rg2-load-results-file").button().click(function(e){t.mapLoaded||(rg2.utils.showWarningDialog("No map loaded","Please load a map file before adding results."),e.preventDefault())}).change(function(e){t.resultsOrCourseFile=e.target.files[0],t.initialiseEncodings(),t.readResults()}),$("#btn-move-map-and-controls").click(function(e){t.toggleMoveAll(e.target.checked)}),$("#btn-no-results").click(function(e){t.toggleResultsRequired(e.target.checked)}),$("#btn-sort-results").click(function(e){t.toggleSortResults(e.target.checked)}),$("#rg2-load-course-file").button().click(function(e){t.mapLoaded||(rg2.utils.showWarningDialog("No map loaded","Please load a map file before adding courses."),e.preventDefault())}).change(function(e){t.readCourses(e)})},validateMapUpload:function(t){var e,s,r;(e=new FileReader).onload=function(e){(s=new Image).src=e.target.result,s.onload=function(){var e;e="The uploaded map file is "+(r=Math.round(t.size/1024/1024))+"MB ("+this.width,e+=" x "+this.height+"). It is recommended that you only use maps under",e+=" "+rg2.config.FILE_SIZE_WARNING+"MB. Please see the ",e+="RG2 wiki for ",e+="guidance on how to create map files.",r>rg2.config.FILE_SIZE_WARNING&&rg2.utils.showWarningDialog("Oversized map upload",e)}},e.readAsDataURL(t)},initialiseEncodings:function(){this.encodingIndex=0,this.errorCount=[],this.useThisEncoding=!1},enableEventEdit:function(){var t=this;rg2.managerUI.setUIVisibility(),this.getMaps(),this.setButtons(),rg2.managerUI.createEventLevelDropdown("rg2-event-level"),rg2.managerUI.createEventLevelDropdown("rg2-event-level-edit"),rg2.managerUI.createGeorefDropdown(this.georefsystems),rg2.managerUI.createEventEditDropdown(),$("#rg2-event-level").change(function(){t.eventLevel=$("#rg2-event-level").val(),"X"!==t.eventLevel?$("#rg2-select-event-level").addClass("valid"):$("#rg2-select-event-level").removeClass("valid")}),$("#rg2-map-selected").change(function(){t.mapIndex=parseInt($("#rg2-map-selected").val(),10),t.mapIndex!==rg2.config.INVALID_MAP_ID?($("#rg2-manager-map-select").addClass("valid"),rg2.loadNewMap(rg2Config.maps_url+"/"+t.maps[t.mapIndex].mapfilename)):($("#rg2-manager-map-select").removeClass("valid"),t.mapLoaded=!1,t.mapWidth=0,t.mapHeight=0)}),$("#rg2-event-date").datepicker({dateFormat:"yy-mm-dd",onSelect:function(e){t.setDate(e)}}),$("#rg2-event-name").on("change",function(){t.setEventName()}),$("#rg2-map-name").on("change",function(){t.setMapName()}),$("#rg2-club-name").on("change",function(){t.setClub()}),$("#rg2-new-course-name").on("change",function(){t.setCourseName()}),$("#rg2-manager-event-select").change(function(){rg2.managerUI.setEvent(parseInt($("#rg2-event-selected").val(),10))}),$("#rg2-georef-type").change(function(){t.setGeoref($("#rg2-georef-selected").val())}),$("#rg2-info-panel").tabs("option","active",rg2.config.TAB_CREATE)},getMaps:function(){var t,s;s=this,$.getJSON(rg2Config.json_url,{type:"maps",cache:!1}).done(function(e){for(s.maps.length=0,console.log("Maps: "+e.data.maps.length),t=0;t
",$("#rg2-course-allocations").empty().append(t)}},createResultCourseMapping:function(){var e;if(this.format===rg2.config.FORMAT_NO_RESULTS)for(e=this.resultCourses.length=0;eAre you sure you want to create this event?",title:"Confirm event creation",classes:"rg2-confirm-create-event-dialog",doText:"Create event"}).onDo=this.doCreateEvent.bind(this),t.onCancel=rg2.managerUI.doCancelCreateEvent.bind(this),rg2.utils.createModalDialog(t)):rg2.utils.showWarningDialog("Event set-up incomplete",e+" Please enter all necessary information and make sure controls are aligned before creating the event.")},doCreateEvent:function(){var t,e;$("#event-create-dialog").dialog("destroy"),e=(t=this).generateNewEventData(),$("#rg2-load-progress-label").text("Creating event"),$("#rg2-load-progress").show(),$.ajax({data:e,type:"POST",url:rg2Config.json_url+"?type=createevent",dataType:"json",success:function(e){t.user.y=e.keksi,e.ok?(rg2.utils.showWarningDialog("Event created",t.eventName+" has been added with id "+e.newid+"."),window.open(rg2Config.json_url.replace("rg2api.php","")+"#"+e.newid),rg2.getEvents(),rg2.managerUI.setEvent()):rg2.utils.showWarningDialog("Save failed",e.status_msg+" Failed to create event. Please try again.")},error:function(){rg2.utils.showWarningDialog("Save failed"," Failed to create event.")},complete:function(){$("#rg2-load-progress-label").text(""),$("#rg2-load-progress").hide()}})},generateNewEventData:function(){var e,t,s,r;for((e={}).name=this.eventName,e.mapid=this.maps[this.mapIndex].mapid,e.eventdate=this.eventDate,(t=$("#rg2-event-comments").val())===rg2.config.DEFAULT_EVENT_COMMENT?e.comments="":e.comments=t,e.locked=$("#chk-read-only").prop("checked"),e.club=this.club,e.format=this.format,$("#btn-score-event").prop("checked")&&(e.format=rg2.config.FORMAT_SCORE_EVENT),e.level=this.eventLevel,this.drawingCourses&&(this.courses.push(this.drawnCourse),this.createResultCourseMapping()),this.setControlLocations(),this.mapResultsToCourses(),this.renumberResults(),e.format===rg2.config.FORMAT_SCORE_EVENT&&(this.extractVariants(),e.variants=this.variants.slice(0)),e.courses=this.courses.slice(0),this.sortResults?e.results=this.results.slice(0).sort(this.sortResultItems):e.results=this.results.slice(0),r=0;r",s=0;s"+this.courses[s].name+"";return n+=""},extractVariants:function(){var e,t,s,r;for(e=this.variants.length=0;eAre you sure you want to update this event?",title:"Confirm event update",classes:"rg2-confirm-update-dialog",doText:"Update event"}).onDo=this.doUpdateEvent.bind(this),e.onCancel=rg2.managerUI.doCancelUpdateEvent.bind(this),rg2.utils.createModalDialog(e)},doUpdateEvent:function(){var t,e,s,r,o,n;$("#event-update-dialog").dialog("destroy"),t=$("#rg2-event-selected").val(),e=rg2Config.json_url+"?type=editevent&id="+t,(s={}).comments=$("#rg2-edit-event-comments").val(),s.locked=$("#chk-edit-read-only").prop("checked"),s.name=$("#rg2-event-name-edit").val(),s.type=$("#rg2-event-level-edit").val(),s.eventdate=$("#rg2-event-date-edit").val(),s.club=$("#rg2-club-name-edit").val(),n=this.user.encodeUser(),s.x=n.x,s.y=n.y,r=JSON.stringify(s),o=this,$.ajax({data:r,type:"POST",url:e,dataType:"json",success:function(e){o.user.y=e.keksi,e.ok?(rg2.utils.showWarningDialog("Event updated","Event "+t+" has been updated."),rg2.events.setActiveEventID(null),rg2.ui.setTitleBar(),rg2.getEvents(),rg2.managerUI.setEvent()):rg2.utils.showWarningDialog("Update failed",e.status_msg+". Event update failed. Please try again.")},error:function(e,t){rg2.utils.showWarningDialog("Update failed",t+". Event update failed.")}})},confirmDeleteRoute:function(){var e;(e={selector:"
This route will be permanently deleted. Are you sure?
",title:"Confirm route delete",classes:"rg2-confirm-route-delete-dialog",doText:"Delete route"}).onDo=this.doDeleteRoute.bind(this),e.onCancel=rg2.managerUI.doCancelDeleteRoute.bind(this),rg2.utils.createModalDialog(e)},doDeleteRoute:function(){var e,t,s,r,o;$("#route-delete-dialog").dialog("destroy"),e=$("#rg2-event-selected").val(),s=$("#rg2-route-selected").val(),t=rg2Config.json_url+"?type=deleteroute&id="+e+"&routeid="+s,r=JSON.stringify(this.user.encodeUser()),o=this,$.ajax({data:r,type:"POST",url:t,dataType:"json",success:function(e){o.user.y=e.keksi,e.ok?rg2.utils.showWarningDialog("Route deleted","Route "+s+" has been deleted."):rg2.utils.showWarningDialog("Delete failed",e.status_msg+". Delete failed. Please try again.")},error:function(e,t){rg2.utils.showWarningDialog("Delete failed",t+". Delete failed.")}})},confirmDeleteEvent:function(){var e;(e={selector:"
This event will be deleted. Are you sure?
",title:"Confirm event delete",classes:"rg2-confirm-delete-event-dialog",doText:"Delete event"}).onDo=this.doDeleteEvent.bind(this),e.onCancel=rg2.managerUI.doCancelDeleteEvent.bind(this),rg2.utils.createModalDialog(e)},doDeleteEvent:function(){var t,e,s,r;$("#event-delete-dialog").dialog("destroy"),t=$("#rg2-event-selected").val(),e=rg2Config.json_url+"?type=deleteevent&id="+t,s=JSON.stringify(this.user.encodeUser()),r=this,$.ajax({data:s,type:"POST",url:e,dataType:"json",success:function(e){r.user.y=e.keksi,e.ok?(rg2.utils.showWarningDialog("Event deleted","Event "+t+" has been deleted."),rg2.getEvents(),rg2.managerUI.setEvent(),$("#rg2-event-selected").empty()):rg2.utils.showWarningDialog("Delete failed",e.status_msg+". Event delete failed. Please try again.")},error:function(e,t){rg2.utils.showWarningDialog("Delete failed",t+". Delete failed.")}})},readResults:function(){var e,t,s;t=new FileReader,s=this,t.onerror=function(){rg2.utils.showWarningDialog("Results file error","The selected results file could not be read.")},t.onload=function(e){s.checkResultsFileEncoding(e)},"XML"===(e=this.resultsOrCourseFile.name.substr(-3,3).toUpperCase())||"CSV"===e?(this.resultsFileFormat=e,t.readAsText(this.resultsOrCourseFile,this.encodings[this.encodingIndex])):rg2.utils.showWarningDialog("File type error","Results file type is not recognised. Please select a valid file.")},checkResultsFileEncoding:function(e){var t,s,r;if(0===(t=this.testForInvalidCharacters(e.target.result))||this.useThisEncoding)this.processResultFile(e);else{if(this.errorCount[this.encodingIndex]=t,this.encodingIndex+=1,this.encodingIndex===this.encodings.length){for(s=99999,r=0;rthis.errorCount[r]&&(this.encodingIndex=r,s=this.errorCount[r]);this.useThisEncoding=!0}this.readResults()}},processResultFile:function(e){var t=new rg2.ResultParser(e,this.resultsFileFormat);this.results=t.results,this.resultCourses=t.resultCourses,t.valid?$("#rg2-select-results-file").addClass("valid"):$("#rg2-select-results-file").removeClass("valid"),rg2.managerUI.displayResultInfo(this.getResultInfoAsHTML()),this.displayCourseAllocations()},readCourses:function(e){var t,s;(t=new FileReader).onerror=function(){rg2.utils.showWarningDialog("Course file error","The selected course file could not be read.")},s=this,t.onload=function(e){s.processCourseFile(e)},t.readAsText(e.target.files[0])},processCourseFile:function(e){var t;this.coursesGeoreferenced=!1,this.backgroundLocked=!1,$("#btn-move-map-and-controls").prop("checked",!1),this.handle={x:null,y:null},this.newcontrols.deleteAllControls(),t=new rg2.CourseParser(e,this.worldfile,this.localworldfile),this.courses=t.courses,this.newcontrols=t.newcontrols,this.mapping=t.mapping,this.coursesGeoreferenced=t.georeferenced,rg2.managerUI.displayCourseInfo(this.getCourseInfoAsHTML()),this.createResultCourseMapping(),this.displayCourseAllocations(),this.fitControlsToMap(),rg2.redraw(!1)},getCourseInfoAsHTML:function(){var e,t;if(this.courses.length){for(e="