Permalink
Browse files

add Approval Object Model to JS, add Approval fmatDate method; use fm…

…atDate method on return response from server on approval action
  • Loading branch information...
michaelsimon committed Oct 11, 2016
1 parent 516d72c commit 9afd79afab2ae4f313bb4adfc94105f8a5f8190b
Showing with 21 additions and 3 deletions.
  1. +21 −3 app/assets/javascripts/approval.js
@@ -1,3 +1,20 @@
var Approval = function(attr) {
this.id = attr.id;
this.contract_id = attr.contract_id;
this.user_id = attr.uder_id;
this.date_requested = attr.date_requested;
this.date_answered = attr.date_answered;
this.status = attr.status;
}
Approval.prototype.fmatDate = function(dt) {
d = Date.parse(dt);
d = new Date(d);
var dayShortNames = ["Sun", "Mon", "Tues", "Weds", "Thurs", "Fri", "Sat"];
return dayShortNames[d.getUTCDay()] + " " +(d.getUTCMonth()+1)+"/"+d.getUTCDate()+"/"+d.getUTCFullYear();
}
var approvalResponse = function(event){
event.preventDefault();
answer = event.currentTarget.getAttribute("data-approval-answer");
@@ -7,9 +24,10 @@ var approvalResponse = function(event){
dataType: 'JSON',
data: {id: event.currentTarget.getAttribute("data-approval-id")}
}).done(function(response, stat){
$(`[data-approval-id="${response.id}"] > td#date_answered`).text(response.date_answered);
$(`[data-approval-id="${response.id}"] > td#status`).text(response.status);
$(`[data-approval-id="${response.id}"] > td#buttons`).text("")
approvalObject = new Approval(response);
$(`[data-approval-id="${approvalObject.id}"] > td#date_answered`).text(approvalObject.fmatDate(approvalObject.date_answered));
$(`[data-approval-id="${approvalObject.id}"] > td#status`).text(approvalObject.status);
$(`[data-approval-id="${approvalObject.id}"] > td#buttons`).text("")
}).error(function() {
alert("There was an error processing your response submission. Please try again.")
});

0 comments on commit 9afd79a

Please sign in to comment.