Commit f040c95f by Muhammad Shoaib

add allowance call

parent 20d65815
...@@ -8,8 +8,8 @@ var edx = edx || {}; ...@@ -8,8 +8,8 @@ var edx = edx || {};
edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {}; edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {};
edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel = Backbone.Model.extend({ edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel = Backbone.Model.extend({
url: '/api/edx_proctoring/v1/proctored_exam/allowance'
/* we should probably pull this from a data attribute on the HTML */
}); });
this.edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel = edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel; this.edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel = edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel;
}).call(this, Backbone); }).call(this, Backbone);
...@@ -10,10 +10,12 @@ var edx = edx || {}; ...@@ -10,10 +10,12 @@ var edx = edx || {};
{ {
name: "AddAllowanceView", name: "AddAllowanceView",
template: null, template: null,
model: edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel, template_url: '/static/proctoring/templates/add-new-allowance.underscore',
tempate_url: '/static/proctoring/templates/add-new-allowance.underscore',
initialize: function(options) { initialize: function(options) {
this.proctored_exams = options.proctored_exams; this.proctored_exams = options.proctored_exams;
this.proctored_exam_allowance_view = options.proctored_exam_allowance_view;
this.course_id = options.course_id;
this.model = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel();
_.bindAll( this, "render"); _.bindAll( this, "render");
this.loadTemplateData(); this.loadTemplateData();
//Backbone.Validation.bind( this, {valid:this.hideError, invalid:this.showError}); //Backbone.Validation.bind( this, {valid:this.hideError, invalid:this.showError});
...@@ -23,7 +25,7 @@ var edx = edx || {}; ...@@ -23,7 +25,7 @@ var edx = edx || {};
}, },
loadTemplateData: function(){ loadTemplateData: function(){
var self = this; var self = this;
$.ajax({url: self.tempate_url, dataType: "html"}) $.ajax({url: self.template_url, dataType: "html"})
.error(function(jqXHR, textStatus, errorThrown){ .error(function(jqXHR, textStatus, errorThrown){
}) })
...@@ -38,7 +40,7 @@ var edx = edx || {}; ...@@ -38,7 +40,7 @@ var edx = edx || {};
return { return {
proctored_exam: $("select#proctored_exam").val(), proctored_exam: $("select#proctored_exam").val(),
allowance_type: $("select#allowance_type").val(), allowance_type: $("select#allowance_type").val(),
value: $("#allowance_value").val(), allowance_value: $("#allowance_value").val(),
user_info: $("#user_info").val() user_info: $("#user_info").val()
}; };
}, },
...@@ -70,30 +72,49 @@ var edx = edx || {}; ...@@ -70,30 +72,49 @@ var edx = edx || {};
{ {
event.preventDefault(); event.preventDefault();
var values = this.getCurrentFormValues(); var values = this.getCurrentFormValues();
var self = this;
self.model.fetch(
{
headers: {
"X-CSRFToken": self.proctored_exam_allowance_view.getCSRFToken()
},
type: 'PUT',
data: {
'exam_id': values.proctored_exam,
'user_id': values.user_info,
'key': values.allowance_type,
'value': values.allowance_value
},
success: function () {
// fetch the allowances again.
self.proctored_exam_allowance_view.collection.url = self.proctored_exam_allowance_view.initial_url + self.course_id + '/allowance';
self.proctored_exam_allowance_view.hydrate();
self.hideModal();
}
});
// if( this.model.set( this.getCurrentFormValues())) // if( this.model.set( this.getCurrentFormValues()))
// { // {
this.hideModal();
// } // }
}, },
render: render: function() {
function() var allowance_types = ['Additional time (minutes)'];
{
var exams_data = [{'exam_name':'exam12'},{'exam_name':'exam22'},{'exam_name':'exam32'}];
var allowance_types = ['Additional time (minutes)'];
$(this.el).html( this.template({ $(this.el).html( this.template({
proctored_exams: this.proctored_exams, proctored_exams: this.proctored_exams,
allowance_types: allowance_types allowance_types: allowance_types
})); }));
this.$form = { this.$form = {
name: this.$("#name"), proctored_exam: this.$("select#proctored_exam"),
email: this.$("#email"), allowance_type: this.$("select#allowance_type"),
phone: this.$("#phone") allowance_value: this.$("#allowance_value"),
}; user_info: this.$("#user_info").val()
return this; };
} return this;
}
}); });
}).call(this, Backbone, $, _); }).call(this, Backbone, $, _);
...@@ -17,7 +17,8 @@ var edx = edx || {}; ...@@ -17,7 +17,8 @@ var edx = edx || {};
/* this should be moved to a 'data' attribute in HTML */ /* this should be moved to a 'data' attribute in HTML */
this.tempate_url = '/static/proctoring/templates/course_allowances.underscore'; this.tempate_url = '/static/proctoring/templates/course_allowances.underscore';
this.template = null; this.template = null;
this.allowance_url = this.collection.url; this.allowance_url = this.collection.url + 'allowance';
this.initial_url = this.collection.url;
/* re-render if the model changes */ /* re-render if the model changes */
this.listenTo(this.collection, 'change', this.collectionChanged); this.listenTo(this.collection, 'change', this.collectionChanged);
...@@ -25,7 +26,7 @@ var edx = edx || {}; ...@@ -25,7 +26,7 @@ var edx = edx || {};
this.loadTemplateData(); this.loadTemplateData();
this.proctoredExamCollection.url = this.proctoredExamCollection.url + this.course_id; this.proctoredExamCollection.url = this.proctoredExamCollection.url + this.course_id;
this.collection.url = this.allowance_url + this.course_id + '/allowance'; this.collection.url = this.initial_url + this.course_id + '/allowance';
}, },
events: { events: {
...@@ -68,7 +69,7 @@ var edx = edx || {}; ...@@ -68,7 +69,7 @@ var edx = edx || {};
}, },
success: function () { success: function () {
// fetch the allowances again. // fetch the allowances again.
self.collection.url = self.allowance_url + self.course_id + '/allowance'; self.collection.url = self.initial_url + self.course_id + '/allowance';
self.hydrate(); self.hydrate();
} }
} }
...@@ -125,16 +126,19 @@ var edx = edx || {}; ...@@ -125,16 +126,19 @@ var edx = edx || {};
this.$el.show(); this.$el.show();
} }
}, },
showAddModal: function() { showAddModal: function(event) {
var self = this; var self = this;
self.proctoredExamCollection.fetch({ self.proctoredExamCollection.fetch({
success: function () { success: function () {
var add_allowance_view = new edx.instructor_dashboard.proctoring.AddAllowanceView({ var add_allowance_view = new edx.instructor_dashboard.proctoring.AddAllowanceView({
course_id: self.course_id, course_id: self.course_id,
proctored_exams: self.proctoredExamCollection.toJSON() proctored_exams: self.proctoredExamCollection.toJSON(),
proctored_exam_allowance_view: self
}); });
} }
}); });
event.stopPropagation();
event.preventDefault();
} }
}); });
}).call(this, Backbone, $, _); }).call(this, Backbone, $, _);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment