diff options
Diffstat (limited to 'public/assets/js')
| -rw-r--r-- | public/assets/js/lib/views/details/settings.js | 501 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/hootbox.js | 1 | ||||
| -rw-r--r-- | public/assets/js/lib/views/mail/mailbox.js | 126 | ||||
| -rw-r--r-- | public/assets/js/lib/views/mail/message.js | 85 | ||||
| -rw-r--r-- | public/assets/js/util/format.js | 3 |
5 files changed, 381 insertions, 335 deletions
diff --git a/public/assets/js/lib/views/details/settings.js b/public/assets/js/lib/views/details/settings.js index c2ff078..fd23c46 100644 --- a/public/assets/js/lib/views/details/settings.js +++ b/public/assets/js/lib/views/details/settings.js @@ -1,9 +1,8 @@ var ThreadSettingsForm = FormView.extend({ - el: "#thread_settings", events: { - "click": "hide", + // click: "hide", "click .inner": "stopPropagation", "click .thread_delete": "deleteThread", "click .file_delete": "deleteFile", @@ -20,152 +19,174 @@ var ThreadSettingsForm = FormView.extend({ }, action: "", - method: 'put', + method: "put", - initialize: function(){ - this.__super__.initialize.call(this) - this.template = this.$(".template").html() - this.allowedTemplate = this.$(".allowedTemplate").html() - this.filesTemplate = this.$(".settingsFilesTemplate").html() + initialize: function () { + this.__super__.initialize.call(this); + this.template = this.$(".template").html(); + this.allowedTemplate = this.$(".allowedTemplate").html(); + this.filesTemplate = this.$(".settingsFilesTemplate").html(); }, - populate: function(){ - 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 + populate: function () { + 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.thread = thread - this.files = data.files - this.action = "/api/thread/" + thread.id - this.allowed = (this.thread.allowed || "").split(" ").map(s => s.trim()).filter(s => !! s) + this.thread = thread; + this.files = data.files; + this.action = "/api/thread/" + thread.id; + this.allowed = (this.thread.allowed || "") + .split(" ") + .map((s) => s.trim()) + .filter((s) => !!s); - this.$(".close_link").attr("href", "/details/" + thread.id) - this.$(".metadata").html(metadata(thread)) - this.$("[name=title]").val(thread.title) + this.$(".close_link").attr("href", "/details/" + thread.id); + this.$(".metadata").html(metadata(thread)); + this.$("[name=title]").val(thread.title); - this.$("[name=hootbox]").prop("checked", !!thread.settings.hootbox) - this.$("[name=shorturls]").prop("checked", !!thread.settings.shorturls) - this.$("[name=noupload]").prop("checked", !!thread.settings.noupload) - this.$("[name=privacy]").prop("checked", !!thread.privacy) + this.$("[name=hootbox]").prop("checked", !!thread.settings.hootbox); + this.$("[name=shorturls]").prop("checked", !!thread.settings.shorturls); + this.$("[name=noupload]").prop("checked", !!thread.settings.noupload); + this.$("[name=privacy]").prop("checked", !!thread.privacy); - var $color = this.$('[name=color]') + 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 && thread.color? thread.color: keyword? keyword.color: "") + var option = document.createElement("option"); + option.value = color; + option.innerHTML = color; + $color.append(option); + }); + $color.val( + thread && thread.color ? thread.color : keyword ? keyword.color : "", + ); - var $sort = this.$('[name=sort]') + var $sort = this.$("[name=sort]"); FILE_SORTS.forEach((sort) => { - var option = document.createElement('option') - option.value = sort.key - option.innerHTML = sort.label - $sort.append(option) - }) - $sort.val(thread.settings.sort || "name_asc") + var option = document.createElement("option"); + option.value = sort.key; + option.innerHTML = sort.label; + $sort.append(option); + }); + $sort.val(thread.settings.sort || "name_asc"); - this.toggleAllowed() - this.fetchKeywords() + this.toggleAllowed(); + this.fetchKeywords(); - var $files = this.$(".files") - $files.empty() - files.sort((a,b) => cmp(a.filename, b.filename)) - .forEach(file => { - var size = hush_size(file.size) - var datetime = verbose_date(file.date, true) - var date_class = carbon_date(file.date) - var link = make_link(file) - var t = this.filesTemplate.replace(/{{username}}/g, file.username) - .replace(/{{link}}/g, link) - .replace(/{{filename}}/g, file.filename) - .replace(/{{date_class}}/g, date_class) - .replace(/{{date}}/g, datetime[0]) - .replace(/{{time}}/g, datetime[1]) - .replace(/{{size_class}}/g, size[0]) - .replace(/{{size}}/g, size[1]) - .replace(/{{id}}/g, file.id) - var $t = $(t) - $files.append($t) - }) + var $files = this.$(".files"); + $files.empty(); + files + .sort((a, b) => cmp(a.filename, b.filename)) + .forEach((file) => { + var size = hush_size(file.size); + var datetime = verbose_date(file.date, true); + var date_class = carbon_date(file.date); + var link = make_link(file); + var t = this.filesTemplate + .replace(/{{username}}/g, file.username) + .replace(/{{link}}/g, link) + .replace(/{{filename}}/g, file.filename) + .replace(/{{date_class}}/g, date_class) + .replace(/{{date}}/g, datetime[0]) + .replace(/{{time}}/g, datetime[1]) + .replace(/{{size_class}}/g, size[0]) + .replace(/{{size}}/g, size[1]) + .replace(/{{id}}/g, file.id); + var $t = $(t); + $files.append($t); + }); - $("body").removeClass("loading") + $("body").removeClass("loading"); }, - fetchKeywords: function(thread){ - $.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(this.thread.keyword) - }.bind(this)) + fetchKeywords: function (thread) { + $.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(this.thread.keyword); + }.bind(this), + ); }, - loadThreads: function(threads){ + loadThreads: function (threads) { // update the dropdown list of threads - var $thread_select = this.$('[name=thread]') + var $thread_select = this.$("[name=thread]"); if (!threads || !threads.length) { - $thread_select.parent().hide() - return + $thread_select.parent().hide(); + return; } - $thread_select.parent().show() + $thread_select.parent().show(); threads - .map( (a) => [a.title.toLowerCase(), a]) - .sort( (a,b) => a[0].localeCompare(b[0]) ) - .forEach((pair) => { - const thread = pair[1] - var option = document.createElement('option') - option.value = thread.id - // console.log(thread, get_revision(thread)) - option.innerHTML = '[' + thread.id + get_revision(thread) + '] ' + sanitize(thread.title) - $thread_select.append(option) - }) + .map((a) => [a.title.toLowerCase(), a]) + .sort((a, b) => a[0].localeCompare(b[0])) + .forEach((pair) => { + const thread = pair[1]; + var option = document.createElement("option"); + option.value = thread.id; + // console.log(thread, get_revision(thread)) + option.innerHTML = + "[" + + thread.id + + get_revision(thread) + + "] " + + sanitize(thread.title); + $thread_select.append(option); + }); // console.log(threads) }, - toggleAllowed: function(e){ - var checked = this.$('[name=privacy]').prop('checked') - this.$(".allowed_field_container").toggle(checked) - this.$(".allowed_names").toggle(checked) - if (! checked) return - this.$("[name=allowed_field]").focus() - this.displayAllowed() + toggleAllowed: function (e) { + var checked = this.$("[name=privacy]").prop("checked"); + this.$(".allowed_field_container").toggle(checked); + this.$(".allowed_names").toggle(checked); + if (!checked) return; + this.$("[name=allowed_field]").focus(); + this.displayAllowed(); }, - displayAllowed: function(e){ - var $allowedNames = this.$(".allowed_names").empty() - this.allowed.forEach(username => { - var t = this.allowedTemplate.replace(/{{username}}/g, username) - $allowedNames.append(t) - }) + displayAllowed: function (e) { + var $allowedNames = this.$(".allowed_names").empty(); + this.allowed.forEach((username) => { + var t = this.allowedTemplate.replace(/{{username}}/g, username); + $allowedNames.append(t); + }); }, - keydownAllowed: function(e){ - if (e.keyCode === 13) { // enter - e.preventDefault() - e.stopPropagation() - this.updateAllowed() + keydownAllowed: function (e) { + if (e.keyCode === 13) { + // enter + e.preventDefault(); + e.stopPropagation(); + this.updateAllowed(); } }, - updateAllowed: function(){ - var usernames = this.$('[name=allowed_field]').val().replace(/,/g, ' ').split(' ').map(s => s.trim()).filter(s => !! s) - this.$('[name=allowed_field]').val('') - usernames = usernames.filter( (name) => this.allowed.indexOf(name) === -1 ) - .map( (name) => sanitizeHTML(name) ) + updateAllowed: function () { + var usernames = this.$("[name=allowed_field]") + .val() + .replace(/,/g, " ") + .split(" ") + .map((s) => s.trim()) + .filter((s) => !!s); + this.$("[name=allowed_field]").val(""); + usernames = usernames + .filter((name) => this.allowed.indexOf(name) === -1) + .map((name) => sanitizeHTML(name)); $.ajax({ method: "PUT", url: "/api/checkUsernames", @@ -173,31 +194,33 @@ var ThreadSettingsForm = FormView.extend({ data: JSON.stringify({ csrf: csrf(), usernames: usernames }), contentType: "application/json", dataType: "json", - success: function(data){ - if (! data.usernames || ! data.usernames.length) return - this.allowed = this.allowed.concat(data.usernames) - this.displayAllowed() + success: function (data) { + if (!data.usernames || !data.usernames.length) return; + this.allowed = this.allowed.concat(data.usernames); + this.displayAllowed(); }.bind(this), - }) + }); }, - removeAllowed: function(){ - this.allowed = this.$("#allowed_names input[type=checkbox]:checked").map(function(){ - return $(this).val() - }) - this.displayAllowed() + removeAllowed: function () { + this.allowed = this.$("#allowed_names input[type=checkbox]:checked").map( + function () { + return $(this).val(); + }, + ); + this.displayAllowed(); }, - validate: function(){ - var errors = [] - var title = $("[name=title]").val() - if (! title || ! title.length) { - errors.push("Please enter a title.") + validate: function () { + var errors = []; + var title = $("[name=title]").val(); + if (!title || !title.length) { + errors.push("Please enter a title."); } - return errors.length ? errors : null + return errors.length ? errors : null; }, - serialize: function(){ + serialize: function () { var data = { title: $("[name=title]").val(), keyword: $("[name=keyword]").val(), @@ -208,115 +231,127 @@ var ThreadSettingsForm = FormView.extend({ hootbox: $("[name=hootbox]:checked").val() ? true : false, shorturls: $("[name=shorturls]:checked").val() ? true : false, noupload: $("[name=noupload]:checked").val() ? true : false, - sort: $("[name=sort]").val() + sort: $("[name=sort]").val(), }, - } - return JSON.stringify(data) + }; + return JSON.stringify(data); }, - success: function(data){ - console.log(data) - window.location.href = "/details/" + this.options.parent.data.thread.id + success: function (data) { + console.log(data); + window.location.href = "/details/" + this.options.parent.data.thread.id; }, visible: false, - show: function(){ - this.visible = true - app.typing = true - this.populate() - this.$el.addClass('visible') - app.router.pushState("/details/" + this.options.parent.data.thread.id + "/settings") + show: function () { + this.visible = true; + app.typing = 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 - app.typing = false - this.$el.removeClass('visible') - app.router.pushState("/details/" + this.options.parent.data.thread.id) + hide: function (e) { + e && e.preventDefault(); + this.visible = false; + app.typing = 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() + toggle: function () { + if (this.visible) this.hide(); + else this.show(); }, - changeColor: function(){ - var color_name = this.$("[name=color]").val() - set_background_color(color_name) + changeColor: function () { + var color_name = this.$("[name=color]").val(); + set_background_color(color_name); }, - changeSort: function(){ - var sort_name = this.$("[name=sort]").val() - console.log(">", sort_name) - app.view.files.resort(sort_name) + changeSort: function () { + var sort_name = this.$("[name=sort]").val(); + console.log(">", sort_name); + app.view.files.resort(sort_name); }, - toggleFile: function(e){ + toggleFile: function (e) { // e.preventDefault() - e.stopPropagation() - const $input = $(e.currentTarget) - const $tr = $input.closest('tr.file') - const value = e.currentTarget.checked + e.stopPropagation(); + const $input = $(e.currentTarget); + const $tr = $input.closest("tr.file"); + const value = e.currentTarget.checked; // $(e.currentTarget).prop('checked', value) // console.log('check', $input, value) - this.toggleFileChecked($tr, null, value) + this.toggleFileChecked($tr, null, value); }, - toggleFileRow: function(e){ + toggleFileRow: function (e) { // e.preventDefault() - e.stopPropagation() - const $tr = $(e.currentTarget) - const $input = $tr.find('input[type="checkbox"]') - const value = ! $input.prop('checked') - this.toggleFileChecked($tr, $input, value) + e.stopPropagation(); + const $tr = $(e.currentTarget); + const $input = $tr.find('input[type="checkbox"]'); + const value = !$input.prop("checked"); + this.toggleFileChecked($tr, $input, value); }, - toggleFileChecked: function($tr, $input, value){ - $tr.toggleClass('checked', value) - if ($input) $input.prop('checked', value) + toggleFileChecked: function ($tr, $input, value) { + $tr.toggleClass("checked", value); + if ($input) $input.prop("checked", value); }, - moveFiles: function(){ - var thread_id = this.$("[name=thread]").val() + moveFiles: function () { + var thread_id = this.$("[name=thread]").val(); // if (!thread_id) return alert("Please choose a thread") - var file_ids = toArray(this.el.querySelectorAll("[name=file_id]:checked")).map(input => input.value) - console.log("thread:", thread_id) - console.log("files:", file_ids) - var promises = file_ids.map(file_id => { + var file_ids = toArray( + this.el.querySelectorAll("[name=file_id]:checked"), + ).map((input) => input.value); + console.log("thread:", thread_id); + console.log("files:", file_ids); + var promises = file_ids.map((file_id) => { return new Promise((resolve, reject) => { $.ajax({ method: "GET", - url: '/api/file/' + file_id + '/move/' + thread_id, + url: "/api/file/" + file_id + "/move/" + thread_id, headers: { "csrf-token": $("[name=_csrf]").attr("value") }, dataType: "json", - success: function(data){ - console.log('moved', file_id) - resolve(data) + success: function (data) { + console.log("moved", file_id); + resolve(data); }, - error: function(){ - console.log('error moving', file_id) - reject() - } - }) + error: function () { + console.log("error moving", file_id); + reject(); + }, + }); + }); + }); + Promise.all(promises) + .then(() => { + window.location.href = "/details/" + thread_id; }) - }) - Promise.all(promises).then( () => { - window.location.href = '/details/' + thread_id - }).catch(() =>{ - console.error('whaaaaa') - alert('there was a problem moving the files...') - }) + .catch(() => { + console.error("whaaaaa"); + alert("there was a problem moving the files..."); + }); }, - deleteThread: function(e){ - var data = this.options.parent.data - var id = data.thread.id - var comment_count = (data.comments || []).length - var file_count = (data.files || []).length - var msg = "Are you sure you want to delete this thread?\n\n#" + id + ' "' + sanitizeHTML(data.thread.title) + '"' - msg += " + " + comment_count + " comment" + courtesy_s(comment_count) - if ( file_count) msg += " + " + file_count + " file" + courtesy_s(file_count) - var should_remove = confirm(msg) + deleteThread: function (e) { + var data = this.options.parent.data; + var id = data.thread.id; + var comment_count = (data.comments || []).length; + var file_count = (data.files || []).length; + var msg = + "Are you sure you want to delete this thread?\n\n#" + + id + + ' "' + + sanitizeHTML(data.thread.title) + + '"'; + msg += " + " + comment_count + " comment" + courtesy_s(comment_count); + if (file_count) + msg += " + " + file_count + " file" + courtesy_s(file_count); + var should_remove = confirm(msg); if (should_remove) { $.ajax({ method: "DELETE", @@ -324,25 +359,30 @@ var ThreadSettingsForm = FormView.extend({ headers: { "csrf-token": $("[name=_csrf]").attr("value") }, data: JSON.stringify({ csrf: csrf() }), dataType: "json", - success: function(){ - window.location.href = "/" - } - }) + success: function () { + window.location.href = "/"; + }, + }); } }, - deleteFile: function(e){ - e.preventDefault() - e.stopPropagation() - var $el = $(e.currentTarget) - var $parent = $el.closest('.file') - var file_id = $el.data('id') - if (! file_id) return - var data = this.options.parent.data - var file = data.files.find(f => f.id === file_id) - if (! file) return - var msg = "Are you sure you want to delete this file?\n\n#" + file_id + ' "' + sanitizeHTML(file.filename) + '"' - var should_remove = confirm(msg) + deleteFile: function (e) { + e.preventDefault(); + e.stopPropagation(); + var $el = $(e.currentTarget); + var $parent = $el.closest(".file"); + var file_id = $el.data("id"); + if (!file_id) return; + var data = this.options.parent.data; + var file = data.files.find((f) => f.id === file_id); + if (!file) return; + var msg = + "Are you sure you want to delete this file?\n\n#" + + file_id + + ' "' + + sanitizeHTML(file.filename) + + '"'; + var should_remove = confirm(msg); if (should_remove) { $.ajax({ method: "DELETE", @@ -350,12 +390,11 @@ var ThreadSettingsForm = FormView.extend({ headers: { "csrf-token": $("[name=_csrf]").attr("value") }, data: JSON.stringify({ csrf: csrf() }), dataType: "json", - success: function(data){ - console.log(data) - $parent.remove() - } - }) + success: function (data) { + console.log(data); + $parent.remove(); + }, + }); } }, - -}) +}); diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js index c874e74..a5d2270 100644 --- a/public/assets/js/lib/views/index/hootbox.js +++ b/public/assets/js/lib/views/index/hootbox.js @@ -29,7 +29,6 @@ var HootBox = FormView.extend({ }, parse: function (comment) { - console.log(comment); var t = this.template .replace(/{{image}}/g, profile_image(comment.username)) .replace(/{{username}}/g, comment.username) diff --git a/public/assets/js/lib/views/mail/mailbox.js b/public/assets/js/lib/views/mail/mailbox.js index c48d948..cae87f0 100644 --- a/public/assets/js/lib/views/mail/mailbox.js +++ b/public/assets/js/lib/views/mail/mailbox.js @@ -2,91 +2,95 @@ var MailboxView = View.extend({ el: "#messages", events: { - 'click .discard_link': 'discard', + "click .discard_link": "discard", }, action: "/api/mailbox/", - initialize: function(){ - this.__super__.initialize.call(this) - this.template = this.$(".template").html() - this.boxlist = new BoxList () + initialize: function () { + this.__super__.initialize.call(this); + this.template = this.$(".template").html(); + this.boxlist = new BoxList(); + this.message = new MessageView(); }, - load: function(name){ - name = sanitizeHTML(name) || "inbox" - $("h1").html(name) - var query = window.location.search.substr(1) - $.get(this.action + name, query, this.populate.bind(this)) + load: function (name) { + name = sanitizeHTML(name) || "inbox"; + $("h1").html(name); + var query = window.location.search.substr(1); + $.get(this.action + name, query, this.populate.bind(this)); }, - populate: function(data){ + populate: function (data) { if (data.boxes) { - this.boxlist.load(data.boxes) + this.boxlist.load(data.boxes); - var user = data.user - var max = data.messages.length-1 + var user = data.user; + var max = data.messages.length - 1; if (data.messages.length) { - var limit = data.query.limit || 50 - var offset = data.query.offset + data.messages.length + var limit = data.query.limit || 50; + var offset = data.query.offset + data.messages.length; if (limit > data.messages.length) { - $(".next_page").hide() + $(".next_page").hide(); + } else { + var query = { limit, offset }; + $(".next_page a").attr("href", "?" + querystring(query)); } - else { - var query = { limit, offset } - $(".next_page a").attr("href", "?" + querystring(query)) - } - } - else { - $("#no_messages").show() - $(".next_page").hide() + } else { + $("#no_messages").show(); + $(".next_page").hide(); } - data.messages.forEach(function(message, i){ - var $row = this.parse(message, user) - if (i === 0) $row.addClass("first") - if (i === max) $row.addClass("last") - this.$el.append($row) - }.bind(this)) + data.messages.forEach( + function (message, i) { + var $row = this.parse(message, user); + if (i === 0) $row.addClass("first"); + if (i === max) $row.addClass("last"); + this.$el.append($row); + }.bind(this), + ); } - $("body").removeClass('loading') + $("body").removeClass("loading"); }, - parse: function(message, user){ - var datetime = verbose_date(message.date) - var size = hush_size(message.size) - var id = message.id + parse: function (message, user) { + var datetime = verbose_date(message.date); + var size = hush_size(message.size); + var id = message.id; - var is_sender = message.sender === user.username + var is_sender = message.sender === user.username; var t = this.template - .replace(/{{id}}/g, message.id) - .replace(/{{to}}/g, is_sender ? "to " : "") - .replace(/{{unread}}/g, message.unread ? "unread" : "") - .replace(/{{username}}/g, is_sender ? message.recipient : message.sender) - .replace(/{{subject}}/g, message.subject) - .replace(/{{date}}/g, datetime[0]) - .replace(/{{time}}/g, datetime[1]) - .replace(/{{date_class}}/g, carbon_date(message.lastmodified) ) - .replace(/{{size}}/g, size[1] ) - .replace(/{{size_class}}/g, size[0] ) - var $t = $(t) + .replace(/{{id}}/g, message.id) + .replace(/{{to}}/g, is_sender ? "to " : "") + .replace(/{{unread}}/g, message.unread ? "unread" : "") + .replace(/{{username}}/g, is_sender ? message.recipient : message.sender) + .replace(/{{subject}}/g, message.subject) + .replace(/{{date}}/g, datetime[0]) + .replace(/{{time}}/g, datetime[1]) + .replace(/{{date_class}}/g, carbon_date(message.lastmodified)) + .replace(/{{size}}/g, size[1]) + .replace(/{{size_class}}/g, size[0]); + var $t = $(t); if (is_sender) { - $t.find('.reply_link').remove() + $t.find(".reply_link").remove(); } - return $t + return $t; }, - discard: function(e){ - var id = $(e.target).data('id') - var ok = confirm("Really delete this message?") - if (! ok) return + discard: function (e) { + var id = $(e.target).data("id"); + var ok = confirm("Really delete this message?"); + if (!ok) return; $.ajax({ - method: 'delete', - url: '/api/message/' + id, + method: "delete", + url: "/api/message/" + id, headers: { "csrf-token": csrf() }, data: { _csrf: csrf() }, - success: function(){ window.location.reload() }, - error: function(){ window.location.reload() }, - }) + success: function () { + window.location.reload(); + }, + error: function () { + window.location.reload(); + }, + }); }, - -}) +}); diff --git a/public/assets/js/lib/views/mail/message.js b/public/assets/js/lib/views/mail/message.js index 6fa3d78..6ea2274 100644 --- a/public/assets/js/lib/views/mail/message.js +++ b/public/assets/js/lib/views/mail/message.js @@ -1,67 +1,70 @@ var MessageView = View.extend({ - el: "#message", events: { - 'click .discard_link': 'discard', + "click .discard_link": "discard", }, - action: '/api/message/', + action: "/api/message/", - initialize: function(){ - this.template = this.$(".template").html() + initialize: function () { + this.template = this.$(".template").html(); + this.$el.empty().hide(); }, - load: function(name){ - name = sanitizeHTML(name) || "inbox" + load: function (name) { + name = sanitizeHTML(name) || "inbox"; $.ajax({ url: this.action + name, - method: 'get', + method: "get", success: this.populate.bind(this), - error: app.router.error404 - }) + error: app.router.error404, + }); }, - populate: function(data){ - this.parse(data) - $("body").removeClass('loading') + populate: function (data) { + this.parse(data); + $("body").removeClass("loading"); }, - parse: function(data){ - var message = data.message -// var user = data.user + parse: function (data) { + var message = data.message; + // var user = data.user - $("h1").html(message.subject) - var datetime = verbose_date(message.date) - var id = message.id - var is_sender = message.sender === auth.user.username + $("h1").html(message.subject); + var datetime = verbose_date(message.date); + var id = message.id; + var is_sender = message.sender === auth.user.username; var t = this.template - .replace(/{{id}}/g, message.id) - .replace(/{{sender}}/g, message.sender) - .replace(/{{avatar}}/g, profile_image(message.sender)) - .replace(/{{subject}}/g, message.subject) - .replace(/{{date}}/g, datetime[0]) - .replace(/{{time}}/g, datetime[1]) - .replace(/{{body}}/g, tidy_urls(message.body) ) - var $t = $(t) + .replace(/{{id}}/g, message.id) + .replace(/{{sender}}/g, message.sender) + .replace(/{{avatar}}/g, profile_image(message.sender)) + .replace(/{{subject}}/g, message.subject) + .replace(/{{date}}/g, datetime[0]) + .replace(/{{time}}/g, datetime[1]) + .replace(/{{body}}/g, tidy_urls(message.body)); + var $t = $(t); if (is_sender) { - $t.find('.reply_link').remove() + $t.find(".reply_link").remove(); } - this.$el.empty().append($t) + this.$el.empty().append($t).show(); }, - discard: function(e){ - var id = $(e.target).data('id') - var ok = confirm("Really delete this message?") - if (! ok) return + discard: function (e) { + var id = $(e.target).data("id"); + var ok = confirm("Really delete this message?"); + if (!ok) return; $.ajax({ - method: 'delete', - url: '/api/message/' + id, + method: "delete", + url: "/api/message/" + id, headers: { "csrf-token": csrf() }, data: { _csrf: csrf() }, - success: function(){ window.location.href = "/mail" }, - error: function(){ window.location.href = "/mail" }, - }) + success: function () { + window.location.href = "/mail"; + }, + error: function () { + window.location.href = "/mail"; + }, + }); }, - -}) +}); diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js index 8920a38..a594bdd 100644 --- a/public/assets/js/util/format.js +++ b/public/assets/js/util/format.js @@ -20,7 +20,8 @@ function csrf() { function bold_terms(s, terms) { s = sanitizeHTML(s); terms.forEach((term) => { - s = s.replace(new RegExp(term, "ig"), "<b>" + term + "</b>"); + const sanitized_term = term.replace(/[^a-zA-Z0-9]/g, ""); + s = s.replace(new RegExp(`(${sanitized_term}\\w*)`, "ig"), "<b>$1</b>"); }); return s; } |
