diff options
Diffstat (limited to 'public/assets/js')
| -rw-r--r-- | public/assets/js/lib/views/mail/mailbox.js | 17 | ||||
| -rw-r--r-- | public/assets/js/lib/views/search/results.js | 23 | ||||
| -rw-r--r-- | public/assets/js/util/format.js | 12 |
3 files changed, 32 insertions, 20 deletions
diff --git a/public/assets/js/lib/views/mail/mailbox.js b/public/assets/js/lib/views/mail/mailbox.js index 5635a7d..9d988cb 100644 --- a/public/assets/js/lib/views/mail/mailbox.js +++ b/public/assets/js/lib/views/mail/mailbox.js @@ -16,7 +16,8 @@ var MailboxView = View.extend({ load: function(name){ name = sanitize(name) || "inbox" $("h1").html(name) - $.get(this.action + name, this.populate.bind(this)) + var query = window.location.search.substr(1) + $.get(this.action + name, query, this.populate.bind(this)) }, populate: function(data){ @@ -26,7 +27,19 @@ var MailboxView = View.extend({ var user = data.user var max = data.messages.length-1 if (data.messages.length) { - $("#no_messages").hide() + var limit = data.query.limit || 50 + var offset = data.query.offset + data.messages.length + if (limit > data.messages.length) { + $(".next_page").hide() + } + else { + var query = { limit, offset } + $(".next_page a").attr("href", "?" + querystring(query)) + } + } + else { + $("#no_messages").show() + $(".next_page").hide() } data.messages.forEach(function(message, i){ var $row = this.parse(message, user) diff --git a/public/assets/js/lib/views/search/results.js b/public/assets/js/lib/views/search/results.js index 0af68ba..0f34845 100644 --- a/public/assets/js/lib/views/search/results.js +++ b/public/assets/js/lib/views/search/results.js @@ -2,15 +2,15 @@ var SearchResults = View.extend({ el: "#search", template: $("#search .template").html(), - + events: { }, - + action: "/api/search", - + initialize: function(opt){ }, - + load: function(){ var query = window.location.search.substr(1) if (! query || ! query.length) { @@ -19,7 +19,7 @@ var SearchResults = View.extend({ } $.get(this.action, query, this.populate.bind(this)) }, - + populate: function(res){ var query = sanitize(res.meta.query) var terms = res.meta.terms @@ -63,16 +63,3 @@ var SearchResults = View.extend({ }, }) - -function bold_terms (s, terms) { - s = sanitize(s) - terms.forEach( (term) => { - s = s.replace(new RegExp(term, "ig"), "<b>" + term + "</b>") - }) - return s -} -function querystring(opt){ - return '?' + Object.keys(opt).map((key) => { - return encodeURIComponent(key) + "=" + encodeURIComponent(opt[key]) - }).join("&") -} diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js index c765052..7032305 100644 --- a/public/assets/js/util/format.js +++ b/public/assets/js/util/format.js @@ -10,6 +10,18 @@ function choice(a){ return a[randint(a.length)] } function csrf() { return $("[name=_csrf]").attr("value") } +function bold_terms (s, terms) { + s = sanitize(s) + terms.forEach( (term) => { + s = s.replace(new RegExp(term, "ig"), "<b>" + term + "</b>") + }) + return s +} +function querystring(opt){ + return '?' + Object.keys(opt).map((key) => { + return encodeURIComponent(key) + "=" + encodeURIComponent(opt[key]) + }).join("&") +} function commatize (n, radix) { radix = radix || 1024 var nums = [], i, counter = 0, r = Math.floor |
