1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-29 04:32:15 -05:00
kaiwa/clientapp/pages/settings.js

104 lines
3.0 KiB
JavaScript
Raw Normal View History

2013-09-27 01:52:54 -04:00
/*global app, me, client, Resample*/
2013-08-29 23:38:28 -04:00
"use strict";
var BasePage = require('./base');
var templates = require('../templates');
2015-03-19 11:41:32 -04:00
var LDAPUserItem = require('../views/ldapUserItem');
2013-08-29 23:38:28 -04:00
module.exports = BasePage.extend({
2015-02-23 12:24:16 -05:00
template: templates.pages.settings,
2013-09-12 14:18:44 -04:00
classBindings: {
2015-01-25 14:21:57 -05:00
shouldAskForAlertsPermission: '.enableAlerts',
2015-03-19 11:41:32 -04:00
soundEnabledClass: '.soundNotifs',
hasLdapUsers: '#ldapSettings',
isAdmin: '#newLdapUser'
2013-09-18 19:24:40 -04:00
},
srcBindings: {
avatar: '#avatarChanger img'
2013-09-12 14:18:44 -04:00
},
textBindings: {
status: '.status'
},
2013-09-12 14:18:44 -04:00
events: {
2013-09-18 19:24:40 -04:00
'click .enableAlerts': 'enableAlerts',
'click .installFirefox': 'installFirefox',
2015-01-25 14:21:57 -05:00
'click .soundNotifs': 'handleSoundNotifs',
2013-09-18 19:24:40 -04:00
'dragover': 'handleAvatarChangeDragOver',
2013-09-19 00:11:53 -04:00
'drop': 'handleAvatarChange',
2015-03-19 11:41:32 -04:00
'change #uploader': 'handleAvatarChange',
'keydown #newLdapUser': 'addLdapUser',
'click .disconnect': 'handleDisconnect'
2013-09-12 14:18:44 -04:00
},
2013-08-29 23:38:28 -04:00
initialize: function (spec) {
2015-03-19 11:41:32 -04:00
this.listenTo(this, 'deleteLdapUser', this.deleteLdapUser);
var self = this;
app.ldapUsers.fetch(function () {
self.render();
});
2013-10-16 13:48:40 -04:00
},
render: function () {
2013-08-29 23:38:28 -04:00
this.renderAndBind();
2015-03-19 11:41:32 -04:00
this.renderCollection(app.ldapUsers, LDAPUserItem, this.$('#ldapUsers'));
2013-10-16 13:48:40 -04:00
return this;
2013-09-12 14:18:44 -04:00
},
enableAlerts: function () {
2013-10-11 18:40:42 -04:00
if (app.notifications.permissionNeeded()) {
app.notifications.requestPermission(function (perm) {
if (perm === 'granted') {
app.notifications.create('Ok, sweet!', {
body: "You'll now be notified of stuff that happens."
});
}
});
}
2013-09-18 19:24:40 -04:00
},
installFirefox: function () {
2013-10-14 16:36:19 -04:00
if (!app.desktop.installed) {
app.desktop.install();
} else {
app.desktop.uninstall();
}
},
2013-09-18 19:24:40 -04:00
handleAvatarChangeDragOver: function (e) {
e.preventDefault();
return false;
},
handleAvatarChange: function (e) {
2013-09-19 00:11:53 -04:00
var file;
2013-09-18 19:24:40 -04:00
e.preventDefault();
2013-09-19 00:11:53 -04:00
if (e.dataTransfer) {
file = e.dataTransfer.files[0];
} else if (e.target.files) {
file = e.target.files[0];
} else {
return;
}
2013-09-18 19:24:40 -04:00
if (file.type.match('image.*')) {
var fileTracker = new FileReader();
fileTracker.onload = function () {
2015-03-20 15:36:40 -04:00
me.publishAvatar(this.result);
2013-09-18 19:24:40 -04:00
};
fileTracker.readAsDataURL(file);
}
2015-01-25 14:21:57 -05:00
},
handleSoundNotifs: function (e) {
this.model.setSoundNotification(!this.model.soundEnabled);
},
2015-03-19 11:41:32 -04:00
addLdapUser: function (e) {
if (e.which === 13 && !e.shiftKey) {
var id = e.target.value;
e.target.value = '';
app.ldapUsers.addUser(id);
}
},
deleteLdapUser: function (id) {
app.ldapUsers.deleteUser(id);
},
handleDisconnect: function (e) {
client.disconnect();
2015-03-19 11:41:32 -04:00
}
2013-08-29 23:38:28 -04:00
});