summaryrefslogtreecommitdiff
path: root/public/js/lib/views/room/settings.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-06 16:54:40 -0400
committerJules Laplace <jules@okfoc.us>2015-08-06 16:54:40 -0400
commit6276fd8df4a0faa37b92496a6f47a35ba8312de6 (patch)
tree0ecb1313fedaf475790574980f512de390174072 /public/js/lib/views/room/settings.js
parent277e73e9d7e118b5cc1bd5888eb502b3d7380ec8 (diff)
store settings state
Diffstat (limited to 'public/js/lib/views/room/settings.js')
-rw-r--r--public/js/lib/views/room/settings.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/public/js/lib/views/room/settings.js b/public/js/lib/views/room/settings.js
new file mode 100644
index 0000000..e192503
--- /dev/null
+++ b/public/js/lib/views/room/settings.js
@@ -0,0 +1,82 @@
+var SettingsView = View.extend({
+
+ el: "#settings",
+
+ events: {
+ "click": "stopPropagation",
+ "click .open": "open",
+ "blur [name=bg]": "updateBackground",
+ "submit form": "save",
+ },
+
+ initialize: function(socket){
+ this.$bg = this.$("[name=bg]")
+ socket.on("settings", this.update.bind(this))
+ },
+
+ open: function(){
+ if (this.isOpen) {
+ return this.close()
+ }
+ this.isOpen = true
+ this.$el.addClass("active")
+ this._close = this.close.bind(this)
+ $(document.body).on("click", this._close)
+ },
+
+ close: function(){
+ this.isOpen = false
+ this.$el.addClass("active")
+ $(document.body).off("click", this._close)
+ },
+
+ serialize: function(){
+ var fd = {}
+
+ this.$("input[name], select[name], textarea[name]").each( function(){
+ if (this.type == "password") {
+ if (this.value.length > 0) {
+ fd[this.name] = SHA1.hex('lol$' + this.value + '$asdf')
+ }
+ }
+ else {
+ fd[this.name] = sanitize(this.value)
+ }
+ })
+
+ return fd
+ },
+
+ save: function(e){
+ if (this.saving) { return }
+ this.saving = true
+ e.preventDefault()
+ var data = this.serialize()
+ app.socket.emit("settings", data)
+ },
+
+ update: function(data){
+ var base = this
+ if (this.saving) {
+ this.saving = false
+ return
+ }
+ Object.keys(data).forEach(function(key){
+ switch (key) {
+ case 'bg':
+ console.log(data.bg)
+ base.$bg.val(data.bg.url)
+ bg.change(data.bg)
+ break
+ }
+ })
+ },
+
+ updateBackground: function(){
+ if (this.saving) { return }
+ var url = this.$bg.stripHTML()
+ bg.change(url)
+ app.socket.emit("settings", { bg: { url: url, tile: false } })
+ }
+})
+