diff options
| -rw-r--r-- | public/assets/javascripts/ui/site/StaffView.js | 29 | ||||
| -rw-r--r-- | server/lib/views/staff.js | 22 | ||||
| -rw-r--r-- | views/staff/_header.ejs | 1 | ||||
| -rw-r--r-- | views/staff/_users.ejs | 6 | ||||
| -rw-r--r-- | views/staff/_users_recent.ejs | 8 | ||||
| -rw-r--r-- | views/staff/users/show.ejs | 70 |
6 files changed, 125 insertions, 11 deletions
diff --git a/public/assets/javascripts/ui/site/StaffView.js b/public/assets/javascripts/ui/site/StaffView.js index 115d417..8f677cb 100644 --- a/public/assets/javascripts/ui/site/StaffView.js +++ b/public/assets/javascripts/ui/site/StaffView.js @@ -1,6 +1,15 @@ var StaffView = View.extend({ + el: ".page", + + events: { + "click #toggle-staff": "toggleStaff", + }, initialize: function() { + this.$toggleStaff = $("#toggle-staff") + if (this.$toggleStaff.data().isstaff) { + this.$toggleStaff.html("Is Staff") + } }, load: function() { @@ -9,6 +18,24 @@ var StaffView = View.extend({ }) this.projectList = new ProjectList () - } + }, + + toggleStaff: function(){ + var state = ! this.$toggleStaff.data().isstaff + $.ajax({ + type: "put", + dataType: "json", + url: window.location.href + "/bless", + data: { + state: state, + _csrf: $("#_csrf").val(), + }, + success: function(data){ + this.$toggleStaff.data("isstaff", data.state) + this.$toggleStaff.html(data.state ? "Is Staff" : "Make Staff") + $("#is-staff").html(data.state ? "yes" : "no") + }.bind(this) + }) + }, }) diff --git a/server/lib/views/staff.js b/server/lib/views/staff.js index ae414d7..b78fd5a 100644 --- a/server/lib/views/staff.js +++ b/server/lib/views/staff.js @@ -111,7 +111,7 @@ var staff = module.exports = { if (username) { User.findOne({ username: username }, function (err, user) { if (user) { - res.locals.profile = staff.helpers.user(user) + res.locals.profile = req.method == "GET" ? staff.helpers.user(user) : user } else { res.locals.profile = null @@ -236,6 +236,14 @@ var staff = module.exports = { staff.users.show ); + app.put('/staff/users/:username/bless', + middleware.ensureAuthenticated, + middleware.ensureIsStaff, + + staff.middleware.ensureProfile, + + staff.users.bless + ); app.get('/staff/projects', middleware.ensureAuthenticated, middleware.ensureIsStaff, @@ -259,12 +267,6 @@ var staff = module.exports = { staff.projects.show ); - app.put('/staff/users/:username/bless', - middleware.ensureAuthenticated, - middleware.ensureIsStaff, - - staff.users.bless - ); }, index: function(req, res){ @@ -288,9 +290,9 @@ var staff = module.exports = { } }, bless: function(req, res){ - res.locals.profile.isStaff = req.body.isStaff - res.locals.profile.save(function(){ - res.redirect("/staff") + res.locals.profile.isStaff = req.body.state == "true" + res.locals.profile.save(function(err, user){ + res.json({ state: user.isStaff }) }) }, }, diff --git a/views/staff/_header.ejs b/views/staff/_header.ejs index 1880c98..3bbf4f1 100644 --- a/views/staff/_header.ejs +++ b/views/staff/_header.ejs @@ -5,6 +5,7 @@ [[ include ../partials/meta ]] <link rel="stylesheet" href="/assets/javascripts/vendor/bower_components/jquery-jsonview/dist/jquery.jsonview.css"></script> <link rel="stylesheet" href="/assets/stylesheets/staff.css"></script> + <input type="hidden" id="_csrf" name="_csrf" value="[[- token ]]"> </head> <body class="loading"> <div class="rapper page staff"> diff --git a/views/staff/_users.ejs b/views/staff/_users.ejs index ab8c9b3..344ee0c 100644 --- a/views/staff/_users.ejs +++ b/views/staff/_users.ejs @@ -2,11 +2,17 @@ [[ users.forEach(function(user){ ]] <tr> <td> + <a href="/staff/users/[[- user.username ]]"><div style="background-image:url([[- user.photo ]])" class="avatar"></div></a> + </td> + <td> <a href="/staff/users/[[- user.username ]]">[[- user.username ]]</a> </td> <td> [[- user.displayName ]] </td> + <td class="editLinks"> + <a href="/staff/users/[[- user.username ]]">[view profile]</a> + </td> <td> [[- user.last_seen ]] </td> diff --git a/views/staff/_users_recent.ejs b/views/staff/_users_recent.ejs index ff3fd55..e55fe28 100644 --- a/views/staff/_users_recent.ejs +++ b/views/staff/_users_recent.ejs @@ -7,8 +7,16 @@ [[ users.forEach(function(user){ ]] <tr> <td> + [[ if (user.photo) { ]] + <a href="/staff/users/[[- user.username ]]"><div style="background-image:url([[- user.photo ]])" class="avatar"></div></a> + [[ } ]] + </td> + <td> <a href="/staff/users/[[- user.username ]]">[[- user.username ]]</a> </td> + <td class="editLinks"> + <a href="/staff/users/[[- user.username ]]">[view profile]</a> + </td> <td> [[- user.displayName ]] </td> diff --git a/views/staff/users/show.ejs b/views/staff/users/show.ejs index d306443..2315043 100644 --- a/views/staff/users/show.ejs +++ b/views/staff/users/show.ejs @@ -9,8 +9,78 @@ <hr> + <table id="users"> + <tr> + <td rowspan="999" valign="top"> + <a href="/staff/users/[[- profile.username ]]"><div style="background-image:url([[- profile.photo ]])" class="avatar"></div></a> + </td> + <td> + <a href="/staff/users/[[- profile.username ]]">[[- profile.username ]]</a> + </td> + <td> + [[- profile.displayName ]] + </td> + <td class="editLinks"> + <a href="/staff/users/[[- profile.username ]]">[view profile]</a> + </td> + </tr> + </table> + <br> + <table style="margin-left: 50px;"> + <tr> + <th> + location + </th> + <td> + [[- profile.location ]] + </td> + </tr> + <tr> + <th> + last seen + </th> + <td> + [[- profile.last_seen ]] + </td> + </tr> + <tr> + <th> + ip addresses + </th> + <td> + [[- profile.created_ip ]] + [[- profile.last_ip ]] + </td> + </tr> + <tr> + <th> + is admin? + </th> + <td id="is-staff"> + [[- profile.isStaff ? "yes" : "no" ]] + </td> + </tr> + </tr> + <tr> + <th> + </th> + <td id="actions"> + [[ if (String(user._id) != String(profile._id)) { ]] + <button id="toggle-staff" data-isStaff="[[- !! profile.isStaff ]]">Make Staff</button> + [[ } ]] + </td> + </tr> + </table> + <br><br> <div class="json"> [[- profileJSON ]] </div> [[ include ../_footer ]] +<style> +#actions button { + float: none; + width: auto; +} +} +</style>
\ No newline at end of file |
