diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-12-12 02:09:15 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-12-12 02:09:15 +0100 |
| commit | 41d0bd185c19c8a51ed9b85700f52181b6cc5012 (patch) | |
| tree | 76d4524fff4221da47e57ea0bcdb0917d592b5d1 /public/assets/js/lib/views/details/settings.js | |
| parent | ce73133c4e982db99f218bf930d82eb991ce81e3 (diff) | |
color stuff, building settings form
Diffstat (limited to 'public/assets/js/lib/views/details/settings.js')
| -rw-r--r-- | public/assets/js/lib/views/details/settings.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/details/settings.js b/public/assets/js/lib/views/details/settings.js new file mode 100644 index 0000000..6e6b0b2 --- /dev/null +++ b/public/assets/js/lib/views/details/settings.js @@ -0,0 +1,95 @@ +var ThreadSettingsForm = FormView.extend({ + + el: "#thread_settings", + + events: { + "click": "hide", + "click .inner": "stopPropagation", + "click .close_link": "hide" + }, + + action: "", + method: 'put', + + initialize: function(){ + this.__super__.initialize.call(this) + this.template = this.$(".template").html() + }, + + populate: function(){ + // this.action = "/api/thread/" + data.id + $("body").removeClass("loading") + + var data = this.options.parent.data + var keywords = data.keywords + var keyword = data.keyword + var thread = data.thread + var comments = data.comments + var files = data.files + var settings = thread.settings + var display = thread.display + + this.$(".close_link").attr("href", "/details/" + thread.id) + this.$(".metadata").html(metadata(thread)) + this.$("[name=title]").val(sanitize(thread.title)) + + var $color = this.$('[name=color]') + Object.keys(COLORS).forEach((color) => { + var option = document.createElement('option') + option.value = color + option.innerHTML = color + $color.append(option) + }) + $color.val(thread.color || keyword.color) + + $.get('/api/keywords', function(data){ + var $keyword = this.$('[name=keyword]') + data.keywords + .map( (a) => a.keyword) + .sort( (a,b) => a < b ? -1 : a === b ? 0 : 1 ) + .forEach((keyword) => { + var option = document.createElement('option') + option.value = keyword + option.innerHTML = keyword + $keyword.append(option) + }) + $keyword.val(thread.keyword) + }.bind(this)) + console.log(thread) + }, + + validate: function(){ + var errors = [] + var comment = $("[name=comment]").val() + if (! comment || ! comment.length) { + errors.push("Please enter a comment.") + } + return errors.length ? errors : null + }, + + success: function(data){ + window.location.href = "/details/" + data.comment.thread + }, + + visible: false, + + show: function(){ + this.visible = true + this.populate() + this.$el.addClass('visible') + app.router.pushState("/details/" + this.options.parent.data.thread.id + "/settings") + }, + + hide: function(e){ + e && e.preventDefault() + this.visible = false + this.$el.removeClass('visible') + app.router.pushState("/details/" + this.options.parent.data.thread.id) + }, + + toggle: function(){ + if (this.visible) this.hide() + else this.show() + }, + +})
\ No newline at end of file |
