var DetailsView = View.extend({ events: { }, action: "/api/thread/", keywordAction: "/api/keyword/", initialize: function(opt){ this.comments = new CommentsView ({ parent: this }) this.files = new FilesView ({ parent: this }) this.gallery = new GalleryView ({ parent: this }) this.form = new CommentForm ({ parent: this }) this.threadbox = new ThreadBox ({ parent: this }) this.settings = new ThreadSettingsForm ({ parent: this }) $(".settings_link").click(this.openSettings.bind(this)) }, load: function(id){ id = id.replace(/\D/g, "") $.ajax({ method: "get", url: this.action + id, success: this.populate.bind(this), error: app.router.error404, }) }, populate: function(data){ this.data = data console.log(data) set_background_color(data.thread.color || data.keyword.color) $("body").removeClass('loading') var thread = data.thread $("h1").html(sanitize(thread.title)) $("title").html(sanitize(thread.title)) $(".metadata").html(metadata(thread)) $(".settings_link").attr("href", "/details/" + thread.id + "/settings") this.form.load(data.thread) this.comments.load(data.comments) this.files.load(data.files) this.gallery.load(data.files) if (data.thread.keyword) { $.get(this.keywordAction + data.thread.keyword, this.populateKeyword.bind(this)) } if (this.options.settings) { this.openSettings() } }, populateKeyword: function(data){ this.threadbox.load(data) }, openSettings: function(e){ e && e.preventDefault() this.settings.show() }, }) var metadataTemplate = $(".metadata_template").html() function metadata(thread){ var datetime = verbose_date(thread.createdate, true) var age = get_age(thread.lastmodified, true) var t = metadataTemplate .replace(/{{ username }}/g, thread.username) .replace(/{{ date }}/g, datetime[0]) .replace(/{{ time }}/g, datetime[1]) .replace(/{{ active }}/g, age + " ago") .replace(/{{ views }}/g, thread.viewed + " view" + courtesy_s(thread.viewed)) return t }