diff options
| author | julian laplace <julescarbon@gmail.com> | 2022-10-27 23:21:18 +0200 |
|---|---|---|
| committer | julian laplace <julescarbon@gmail.com> | 2022-10-27 23:21:18 +0200 |
| commit | 02bb7181aca0298dbc8b29ba0aeac3e07f643930 (patch) | |
| tree | d8d6143d192c3ad04e2ec6d644582bf3eb5b1ea9 /public/assets/js/lib | |
| parent | 8770ce790d60da984ec7bdbfac7699ca99cb640b (diff) | |
starting form
Diffstat (limited to 'public/assets/js/lib')
| -rw-r--r-- | public/assets/js/lib/views/stream/hootcomment.js | 60 | ||||
| -rw-r--r-- | public/assets/js/lib/views/stream/hootstream.js | 31 |
2 files changed, 80 insertions, 11 deletions
diff --git a/public/assets/js/lib/views/stream/hootcomment.js b/public/assets/js/lib/views/stream/hootcomment.js new file mode 100644 index 0000000..93c57e4 --- /dev/null +++ b/public/assets/js/lib/views/stream/hootcomment.js @@ -0,0 +1,60 @@ +var HootCommentForm = FormView.extend({ + events: { + "focus textarea": "focus", + "mouseup input[type=file]": "focus", + "keydown textarea": "keydown", + }, + + action: "", + + initialize: function (opt) { + this.__super__.initialize.call(this, opt); + this.template = this.$(".template").html(); + this.$comment = this.$("[name=comment]"); + }, + + load: function (thread) { + this.action = "/api/thread/" + thread.id + "/comment"; + this.$comment.addClass("empty"); + if (thread.settings.noupload) { + this.$("[type=file]").hide(); + } + }, + + keydown: function (e) { + if ((e.ctrlKey || e.metaKey || e.altKey) && e.keyCode == 83) { + // "s" key + e.preventDefault(); + e.stopPropagation(); + this.save(); + } + }, + + focus: function () { + this.$el.addClass("focused"); + this.$comment.removeClass("empty"); + $("[name=comment]").prop("required", false); + }, + + validate: function () { + var errors = []; + var comment = $("[name=comment]").val(); + var files = this.$("[name=files]").val(); + if ((!comment || !comment.length) && !files) { + errors.push("Please enter a comment or add some files."); + } + return errors.length ? errors : null; + }, + + success: function (data) { + $("[name=comment").val(""); + $("[name=files").val(""); + // window.location.reload() + console.log(this); + console.log(this.parent); + console.log(data); + data.comment && this.parent.comments.load([data.comment]); + data.files && this.parent.files.add(data.files); + data.files && this.parent.gallery.add(data.files); + }, +}); diff --git a/public/assets/js/lib/views/stream/hootstream.js b/public/assets/js/lib/views/stream/hootstream.js index 37cd4f8..dcac22c 100644 --- a/public/assets/js/lib/views/stream/hootstream.js +++ b/public/assets/js/lib/views/stream/hootstream.js @@ -5,6 +5,7 @@ var HootStream = View.extend({ "click a": "onClickLink", "click .filename": "onClickFilename", "click .action": "onClickAction", + "submit .streamForm form": "onSubmitComment", }, initialize: function ({ parent }) { @@ -15,6 +16,8 @@ var HootStream = View.extend({ this.lastlogTemplate = this.$(".lastlogTemplate").html(); this.fileTemplate = this.$(".fileTemplate").html(); this.imageTemplate = this.$(".imageTemplate").html(); + this.threadFormTemplate = this.$(".threadFormTemplate").html(); + this.commentFormTemplate = this.$(".commentFormTemplate").html(); this.onClickLink = this.onClickLink.bind(this); this.onClickFilename = this.onClickFilename.bind(this); }, @@ -71,7 +74,7 @@ var HootStream = View.extend({ this.onExpand(event, thread); break; case "post": - this.onShowForm(event, thread); + this.onShowCommentForm(event, thread); break; } }, @@ -80,15 +83,13 @@ var HootStream = View.extend({ // $.get(`/api/stream?thread=${thread}`).then((response) => { console.log(response); - let sort; + let settings; try { - const settings = JSON.parse(response.threads[0].settings); - sort = settings.sort; - } catch (error) { - // console.error(error); - sort = null; - } - audio.index(this.sortFiles(response.files, sort)); + settings = JSON.parse(response.threads[0].settings); + } catch (error) {} + audio.index( + this.sortFiles(response.files, settings ? settings.sort : null) + ); audio.play(0); }); }, @@ -116,8 +117,16 @@ var HootStream = View.extend({ ); }, - onPost: function (thread) { - // + onShowCommentForm: function (event, thread) { + const $threadTitle = $(event.target).closest(".threadTitle"); + const $form = $(this.commentFormTemplate); + $form.data("thread", thread); + $form.insertAfter($threadTitle); + $form.find("textarea").focus(); + }, + + onSubmitComment: function (event) { + event.preventDefault(); }, load: function (data, filters) { |
