Skip to content

Commit

Permalink
Added error handling to TinSubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
garemoko committed May 6, 2013
1 parent 74ddbfa commit c235a12
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
68 changes: 62 additions & 6 deletions TinSubmit/TinSubmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ $(function(){
$('#activityDescriptionRemove').click({elementId: 'activity', propertyClass: 'description', minimum:0},removeProperty);


//send statement
//Add events to buttons
$('#sendStatement').click(statementGeneratorSendStatement);
$('#addAnother').click(hideFeedback);
$('#toTheRepository').click(launchRepository);

//Set debug defaults
var setDebugDefaults = true;
Expand Down Expand Up @@ -86,6 +88,9 @@ function statementGeneratorSendStatement()
version: '0.95',
auth: 'Basic ' + Base64.encode('uomcAcOeWBxCF6NvWUDh' + ':' + 'Weyr9VvZoGKic40lzNTv')
});
//don't pop up alerts on errors.
myLRS.alertOnRequestFailure = false;

myTinCan.recordStores[0]= myLRS;

switch($('#actorObjectType').val())
Expand Down Expand Up @@ -148,15 +153,66 @@ function statementGeneratorSendStatement()
myTarget = myActivity;

var stmt = new TinCan.Statement({
actor : deleteEmptyProperties(myActor),
verb : deleteEmptyProperties(myVerb),
target : deleteEmptyProperties(myTarget)
actor : myActor,
verb : myVerb,
target : myTarget
},true);

console.log ('sending: ' + JSON.stringify(stmt));

//TODO: add callback confirming that the extension has been registered.
myTinCan.sendStatement(stmt, function(err, xhr) {
});
try{
myTinCan.sendStatement(stmt, statementSent);
}
catch (err)
{
//mimic the relevant bit of the returned http response
statementSent([{
err : 'JS error',
xhr : {responseText : '<p>JavaScript error: ' + err.message + '</p>'}
}],null);
}
}

//handle statement sending result
function statementSent (err,result){
console.log(err);
console.log(result);
//hide all section divs
$("div.section").addClass("displayNone");
$("#sendStatement").addClass("displayNone");
//show result div
$("#feedback").removeClass("displayNone");
//display an appropriate message
if (!err[0].err){
$("#feedback").find(".background_div").text('Success');
$("#feedback").find("h2").text('Item added');
$("#feedback").find("p").html('Congratulations, your item has been added to the respository.</p><p> Click <strong>Back</strong> to add another item. Click <strong>Onwards!</strong> to continue to the repository.');
}
else
{
var errorText;
errorText = $(err[0].xhr.responseText).text();
$("#feedback").find(".background_div").text('Error');
$("#feedback").find("h2").text('Adding item failed');
$("#feedback").find("p").html('An error has occured. Please make sure you are conencted to the internet and that you completed all the fields correctly. The error message was:</p><p class="errorText">'+ errorText +'</p><p> Click <strong>Back</strong> to try again. Click <strong>Onwards!</strong> to continue to the repository anyway.');

}

}

function hideFeedback()
{
//show all section divs
$("div.section").removeClass("displayNone");
$("#sendStatement").removeClass("displayNone");
//hide result div
$("#feedback").addClass("displayNone");
}

function launchRepository()
{
window.location.href = "../TinReport/tinreport.htm";
}


13 changes: 13 additions & 0 deletions TinSubmit/tinsubmit.htm
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ <h2>Extension details</h2>
</table>
</div>
</div>

<div class="section displayNone" id="feedback">
<div class="background_div">
TO BE UPDATED
</div>

<h2>TO BE UPDATED</h2>
<p>
TO BE UPDATED
</p>
<input type="button" value="Back" name="addAnother" id="addAnother" class="button"/>
<input type="button" value="Onwards!" name="toTheRepository" id="toTheRepository" class="button"/>
</div>

<input type="button" value="Send!" name="sendStatement" id="sendStatement" class="button"/>

Expand Down
3 changes: 3 additions & 0 deletions tinrepo.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ font-weight:bold;
display: none;
}

.errorText{
color:red;
}

0 comments on commit c235a12

Please sign in to comment.