summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/stream
diff options
context:
space:
mode:
authorjulian laplace <julescarbon@gmail.com>2022-10-28 13:47:06 +0200
committerjulian laplace <julescarbon@gmail.com>2022-10-28 13:47:06 +0200
commitb39de8cc12c83029168f311a7d3e4ddd96d52635 (patch)
tree0aa3f141e050187821e82f787f37a30e9157ea62 /public/assets/js/lib/views/stream
parent02bb7181aca0298dbc8b29ba0aeac3e07f643930 (diff)
toggle form
Diffstat (limited to 'public/assets/js/lib/views/stream')
-rw-r--r--public/assets/js/lib/views/stream/hootcomment.js60
-rw-r--r--public/assets/js/lib/views/stream/hootstream.js18
2 files changed, 17 insertions, 61 deletions
diff --git a/public/assets/js/lib/views/stream/hootcomment.js b/public/assets/js/lib/views/stream/hootcomment.js
deleted file mode 100644
index 93c57e4..0000000
--- a/public/assets/js/lib/views/stream/hootcomment.js
+++ /dev/null
@@ -1,60 +0,0 @@
-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 dcac22c..4a846d7 100644
--- a/public/assets/js/lib/views/stream/hootstream.js
+++ b/public/assets/js/lib/views/stream/hootstream.js
@@ -5,7 +5,6 @@ var HootStream = View.extend({
"click a": "onClickLink",
"click .filename": "onClickFilename",
"click .action": "onClickAction",
- "submit .streamForm form": "onSubmitComment",
},
initialize: function ({ parent }) {
@@ -20,6 +19,7 @@ var HootStream = View.extend({
this.commentFormTemplate = this.$(".commentFormTemplate").html();
this.onClickLink = this.onClickLink.bind(this);
this.onClickFilename = this.onClickFilename.bind(this);
+ this.forms = {};
},
onClickLink: function (event) {
@@ -118,15 +118,31 @@ var HootStream = View.extend({
},
onShowCommentForm: function (event, thread) {
+ if (this.forms[thread]) {
+ this.forms[thread].hide();
+ this.forms[thread].$el.remove();
+ this.forms[thread] = null;
+ return;
+ }
const $threadTitle = $(event.target).closest(".threadTitle");
const $form = $(this.commentFormTemplate);
$form.data("thread", thread);
$form.insertAfter($threadTitle);
$form.find("textarea").focus();
+ const commentForm = new CommentForm({ parent: this });
+ commentForm.action = `/api/thread/${thread}/comment`;
+ commentForm.setElement($form);
+ commentForm.initialize({
+ parent: this,
+ onSubmit: this.onSubmitComment.bind(this),
+ });
+ this.forms[thread] = commentForm;
},
onSubmitComment: function (event) {
event.preventDefault();
+ console.log("onsubmit");
+ this.forms[thread] = null;
},
load: function (data, filters) {