Skip to content

Commit f3f1f8b

Browse files
committed
Removed the global scope of the App and userList variables.
1 parent f770b1e commit f3f1f8b

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

htdocs/js/apps/UserList/userlist.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
/* userlist.js:
2+
This is the base javascript code for the UserList3.pm (Classlist Editor3). This sets up the View and the classlist object.
3+
4+
You must include the User.js code before this in order to user the UserList class.
5+
*/
16

2-
// this variable was defined inside the following, but I think it needs global scope.
3-
4-
var userList;
5-
var App;
67

78

89
$(function(){
@@ -89,9 +90,11 @@ $(function(){
8990
}, this);
9091
this.model.on('all', this.render, this);
9192
this.model.fetch();
93+
this.model.on('add',this.addOne,this);
9294

9395

9496
document.getElementById("filter").addEventListener("keyup", function(){self.el.filter(document.getElementById("filter").value)}, false);
97+
$("input#testButton").click(function() {self.model.trigger("addstudent")});
9598
},
9699

97100
render: function(){
@@ -113,9 +116,9 @@ $(function(){
113116

114117
});
115118

116-
userList = new webwork.UserList;
119+
var userList = new webwork.UserList;
117120

118-
App = new UserListView({model: userList});
121+
var App = new UserListView({model: userList});
119122

120123
// then we attach to the HTML table and render it
121124
//editableGrid.attachToHTMLTable('cltable');
@@ -157,6 +160,6 @@ window.onload = function()
157160
function addStud()
158161
{
159162

160-
var u = new webwork.User({"first_name":"Homer","last_name":"Simpson","user_id":"hsimp"});
161-
userList.add(u);
163+
// var u = new webwork.User({"first_name":"Homer","last_name":"Simpson","user_id":"hsimp"});
164+
// userList.add(u);
162165
}

htdocs/js/lib/webwork/teacher/User.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ webwork.UserList = Backbone.Collection.extend({
6969
$.post(webwork.webserviceURL, requestObject, function(data){
7070
var response = $.parseJSON(data);
7171
console.log(response);
72-
App.model.trigger('reset');
7372
});
7473

7574
}, this);
7675
this.on('remove', function(user){}, this);
76+
77+
// This is used to temporarily add a single (hard coded) student.
78+
this.on('addstudent',function(user){
79+
var u = new webwork.User({"first_name":"Homer","last_name":"Simpson","user_id":"hsimp"});
80+
this.add(u);
81+
})
7782
},
7883

7984
fetch: function(){
@@ -93,5 +98,6 @@ webwork.UserList = Backbone.Collection.extend({
9398
},
9499
email: function(students){
95100

96-
}
101+
}
102+
97103
});

lib/WeBWorK/ContentGenerator/Instructor/UserList3.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ sub body {
503503
\%labels,\%attributes),
504504
"<label for='filter'>Filter :</label><input type='text' id='filter'/>");
505505

506-
print CGI::div(CGI::button(-value=>"Add User",-onClick=>"addStud()"));
506+
print CGI::div(CGI::button(-value=>"Add User",-id=>"testButton"));
507507

508508
$self->printTableHTML(\@Users, \@PermissionLevels, \%prettyFieldNames,
509509
editMode => $editMode,

0 commit comments

Comments
 (0)