Commit 91ac771f by Muhammad Shoaib

added the delete allowance and small tweaks in the internationalization

parent 4bb08cb5
...@@ -15,15 +15,13 @@ var edx = edx || {}; ...@@ -15,15 +15,13 @@ var edx = edx || {};
this.course_id = this.$el.data('course-id'); this.course_id = this.$el.data('course-id');
/* 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/add-allowance.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;
/* 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);
/* make the async call to the backend REST API */ /* Load the static template for rendering. */
/* after it loads, the listenTo event will file and */
/* will call into the rendering */
this.loadTemplateData(); this.loadTemplateData();
this.collection.url = this.allowance_url + '/' + this.course_id; this.collection.url = this.allowance_url + '/' + this.course_id;
...@@ -31,10 +29,23 @@ var edx = edx || {}; ...@@ -31,10 +29,23 @@ var edx = edx || {};
}, },
events: { events: {
'click #add-allowance': 'showAddModal', 'click #add-allowance': 'showAddModal',
'click #remove_allowance': 'removeAllowance' 'click .remove_allowance': 'removeAllowance'
}, },
showAddModal: function(){ getCSRFToken: function() {
alert('here'); var cookieValue = null;
var name='csrftoken';
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}, },
removeAllowance: function(event){ removeAllowance: function(event){
var element = $(event.currentTarget); var element = $(event.currentTarget);
...@@ -55,9 +66,9 @@ var edx = edx || {}; ...@@ -55,9 +66,9 @@ var edx = edx || {};
'key': key 'key': key
}, },
success: function () { success: function () {
// fetch the user preferences again. // fetch the allowances again.
self.collection.url = self.notification_preferences_all; self.collection.url = self.allowance_url + '/' + self.course_id;
self.render(); self.hydrate();
} }
} }
); );
...@@ -97,12 +108,11 @@ var edx = edx || {}; ...@@ -97,12 +108,11 @@ var edx = edx || {};
/* we might - at some point - add a visual element to the */ /* we might - at some point - add a visual element to the */
/* loading, like a spinner */ /* loading, like a spinner */
var self = this; var self = this;
self.collection.fetch().done( self.collection.fetch({
function(){ success: function () {
self.render(); self.render();
}).fail(function(){ }
console.log('fail'); });
});
}, },
collectionChanged: function() { collectionChanged: function() {
this.hydrate(); this.hydrate();
......
...@@ -3,26 +3,34 @@ ...@@ -3,26 +3,34 @@
<a id="add-allowance" href="#" class="add blue-button">+ <%- gettext("Add Allowance") %></a> <a id="add-allowance" href="#" class="add blue-button">+ <%- gettext("Add Allowance") %></a>
</span> </span>
</span> </span>
<% var is_allowances = proctored_exam_allowances.length !== 0 %>
<% if (is_allowances) { %>
<div class="wrapper-content wrapper"> <div class="wrapper-content wrapper">
<section class="content"> <section class="content">
<table class="allowance-table"> <table class="allowance-table">
<thead> <thead>
<tr class="allowance-headings"> <tr class="allowance-headings">
<th class="exam-name">Exam Name</th> <th class="exam-name"><%- gettext("Exam Name") %></th>
<th class="username">Username</th> <th class="username"><%- gettext("Username") %></th>
<th class="email">Email</th> <th class="email"><%- gettext("Email") %></th>
<th class="allowance-name">Allowance Name </th> <th class="allowance-name"><%- gettext("Allowance Name") %> </th>
<th class="allowance-value">Allowance Value</th> <th class="allowance-value"><%- gettext("Allowance Value") %></th>
<th class="c_action">Actions</th> <th class="c_action"><%- gettext("Actions") %> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% _.each(proctored_exam_allowances, function(proctored_exam_allowance){ %> <% _.each(proctored_exam_allowances, function(proctored_exam_allowance){ %>
<tr class="allowance-items"> <tr class="allowance-items">
<td><%= proctored_exam_allowance.proctored_exam.exam_name %></td> <td>
<%- interpolate(gettext(' %(exam_display_name)s '), { exam_display_name: proctored_exam_allowance.proctored_exam.exam_name }, true) %>
</td>
<td> Dummy Username </td> <td> Dummy Username </td>
<td>muhammad.shoaib@gmail.com</td> <td>muhammad.shoaib@gmail.com</td>
<td><%= proctored_exam_allowance.key %></td> <td>
<%- interpolate(gettext(' %(allowance_name)s '), { allowance_name: proctored_exam_allowance.key }, true) %>
</td>
<td><%= proctored_exam_allowance.value %></td> <td><%= proctored_exam_allowance.value %></td>
<td> <td>
<a data-exam-id="<%= proctored_exam_allowance.proctored_exam.id %>" <a data-exam-id="<%= proctored_exam_allowance.proctored_exam.id %>"
...@@ -32,10 +40,10 @@ ...@@ -32,10 +40,10 @@
</td> </td>
</tr> </tr>
<% }); %> <% }); %>
</tbody> </tbody>
</table> </table>
</section> </section>
</div> </div>
<% } %>
...@@ -358,7 +358,7 @@ class ExamAllowanceView(AuthenticatedAPIView): ...@@ -358,7 +358,7 @@ class ExamAllowanceView(AuthenticatedAPIView):
**Response Values** **Response Values**
* returns Nothing. deletes the allowance for the user proctored exam. * returns Nothing. deletes the allowance for the user proctored exam.
""" """
# @method_decorator(require_staff) @method_decorator(require_staff)
def get(self, request, course_id): # pylint: disable=unused-argument def get(self, request, course_id): # pylint: disable=unused-argument
""" """
HTTP GET handler. Get all allowances for a course. HTTP GET handler. Get all allowances for a course.
......
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