diff --git a/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js b/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js index c9c35b26d73..3e2cb869615 100644 --- a/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js @@ -9,7 +9,7 @@ Discourse.AdminDashboardController = Ember.Controller.extend({ loading: true, versionCheck: null, - problemsCheckInterval: '1 minute ago', + problemsCheckMinutes: 1, foundProblems: function() { return(Discourse.User.current('admin') && this.get('problems') && this.get('problems').length > 0); @@ -33,9 +33,9 @@ Discourse.AdminDashboardController = Ember.Controller.extend({ c.set('problems', d.problems); c.set('loadingProblems', false); if( d.problems && d.problems.length > 0 ) { - c.problemsCheckInterval = '1 minute ago'; + c.problemsCheckInterval = 1; } else { - c.problemsCheckInterval = '10 minutes ago'; + c.problemsCheckInterval = 10; } }); }, diff --git a/app/assets/javascripts/admin/controllers/admin_users_list_controller.js b/app/assets/javascripts/admin/controllers/admin_users_list_controller.js index eda5ea44d15..946be4955f7 100644 --- a/app/assets/javascripts/admin/controllers/admin_users_list_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_users_list_controller.js @@ -20,7 +20,7 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres **/ selectAllChanged: function() { var _this = this; - this.get('content').each(function(user) { + _.each(this.get('content'),function(user) { user.set('selected', _this.get('selectAll')); }); }.observes('selectAll'), diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index 414936be91e..e66f22dd7fa 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -76,9 +76,9 @@ Discourse.AdminUser = Discourse.User.extend({ }).property('admin', 'moderator'), banDuration: (function() { - var banned_at = Date.create(this.banned_at); - var banned_till = Date.create(this.banned_till); - return banned_at.short() + " - " + banned_till.short(); + var banned_at = moment(this.banned_at); + var banned_till = moment(this.banned_till); + return banned_at.format('L') + " - " + banned_till.format('L'); }).property('banned_till', 'banned_at'), ban: function() { diff --git a/app/assets/javascripts/admin/models/email_log.js b/app/assets/javascripts/admin/models/email_log.js index d954eeb0440..15f282eae7a 100644 --- a/app/assets/javascripts/admin/models/email_log.js +++ b/app/assets/javascripts/admin/models/email_log.js @@ -21,7 +21,7 @@ Discourse.EmailLog.reopenClass({ Discourse.ajax("/admin/email/logs.json", { data: { filter: filter } }).then(function(logs) { - logs.each(function(log) { + _.each(logs,function(log) { result.pushObject(Discourse.EmailLog.create(log)); }); }); diff --git a/app/assets/javascripts/admin/models/flagged_post.js b/app/assets/javascripts/admin/models/flagged_post.js index 2f335a6b306..439d1f73a46 100644 --- a/app/assets/javascripts/admin/models/flagged_post.js +++ b/app/assets/javascripts/admin/models/flagged_post.js @@ -12,8 +12,8 @@ Discourse.FlaggedPost = Discourse.Post.extend({ var r, _this = this; r = []; - this.post_actions.each(function(a) { - return r.push(_this.userLookup[a.user_id]); + _.each(this.post_actions, function(action) { + r.push(_this.userLookup[action.user_id]); }); return r; }.property(), @@ -22,12 +22,12 @@ Discourse.FlaggedPost = Discourse.Post.extend({ var r, _this = this; r = []; - this.post_actions.each(function(a) { - if (a.message) { - return r.push({ - user: _this.userLookup[a.user_id], - message: a.message, - permalink: a.permalink + _.each(this.post_actions,function(action) { + if (action.message) { + r.push({ + user: _this.userLookup[action.user_id], + message: action.message, + permalink: action.permalink }); } }); @@ -69,11 +69,11 @@ Discourse.FlaggedPost.reopenClass({ result.set('loading', true); Discourse.ajax("/admin/flags/" + filter + ".json").then(function(data) { var userLookup = {}; - data.users.each(function(u) { - userLookup[u.id] = Discourse.User.create(u); + _.each(data.users,function(user) { + userLookup[user.id] = Discourse.User.create(user); }); - data.posts.each(function(p) { - var f = Discourse.FlaggedPost.create(p); + _.each(data.posts,function(post) { + var f = Discourse.FlaggedPost.create(post); f.userLookup = userLookup; result.pushObject(f); }); diff --git a/app/assets/javascripts/admin/models/github_commit.js b/app/assets/javascripts/admin/models/github_commit.js index 51fb92156b3..40d40e6304a 100644 --- a/app/assets/javascripts/admin/models/github_commit.js +++ b/app/assets/javascripts/admin/models/github_commit.js @@ -20,7 +20,7 @@ Discourse.GithubCommit = Discourse.Model.extend({ }.property("sha"), timeAgo: function() { - return Date.create(this.get('commit.committer.date')).relative(); + return Discourse.Formatter.relativeAge(new Date(this.get('commit.committer.date'), {format: 'medium', leaveAgo: true})); }.property("commit.committer.date") }); @@ -32,10 +32,10 @@ Discourse.GithubCommit.reopenClass({ type: 'get', data: { per_page: 40 } }).then(function (response) { - response.data.each(function(commit) { + _.each(response.data,function(commit) { result.pushObject( Discourse.GithubCommit.create(commit) ); }); }); return result; } -}); \ No newline at end of file +}); diff --git a/app/assets/javascripts/admin/models/group.js b/app/assets/javascripts/admin/models/group.js index 6947e61be76..1f7d0173b82 100644 --- a/app/assets/javascripts/admin/models/group.js +++ b/app/assets/javascripts/admin/models/group.js @@ -15,7 +15,7 @@ Discourse.Group = Discourse.Model.extend({ var group = this; Discourse.ajax('/admin/groups/' + this.get('id') + '/users').then(function(payload){ var users = Em.A() - payload.each(function(user){ + _.each(payload,function(user){ users.addObject(Discourse.User.create(user)); }); group.set('users', users) @@ -28,7 +28,7 @@ Discourse.Group = Discourse.Model.extend({ var users = this.get('users'); var usernames = ""; if(users) { - usernames = $.map(users, function(user){ + usernames = _.map(users, function(user){ return user.get('username'); }).join(',') } @@ -82,7 +82,7 @@ Discourse.Group.reopenClass({ var list = Discourse.SelectableArray.create(); Discourse.ajax("/admin/groups.json").then(function(groups){ - groups.each(function(group){ + _.each(groups,function(group){ list.addObject(Discourse.Group.create(group)); }); }); diff --git a/app/assets/javascripts/admin/models/report.js b/app/assets/javascripts/admin/models/report.js index 4ea6dfe31c1..0352336f3a3 100644 --- a/app/assets/javascripts/admin/models/report.js +++ b/app/assets/javascripts/admin/models/report.js @@ -5,7 +5,7 @@ Discourse.Report = Discourse.Model.extend({ valueAt: function(numDaysAgo) { if (this.data) { - var wantedDate = Date.create(numDaysAgo + ' days ago', 'en').format('{yyyy}-{MM}-{dd}'); + var wantedDate = moment().subtract('days', numDaysAgo).format('YYYY-MM-DD'); var item = this.data.find( function(d, i, arr) { return d.x === wantedDate; } ); if (item) { return item.y; @@ -16,11 +16,11 @@ Discourse.Report = Discourse.Model.extend({ sumDays: function(startDaysAgo, endDaysAgo) { if (this.data) { - var earliestDate = Date.create(endDaysAgo + ' days ago', 'en').beginningOfDay(); - var latestDate = Date.create(startDaysAgo + ' days ago', 'en').beginningOfDay(); + var earliestDate = moment().subtract('days', endDaysAgo).startOf('day'); + var latestDate = moment().subtract('days',startDaysAgo).startOf('day'); var d, sum = 0; - this.data.each(function(datum){ - d = Date.create(datum.x); + _.each(this.data,function(datum){ + d = moment(datum.x); if(d >= earliestDate && d <= latestDate) { sum += datum.y; } diff --git a/app/assets/javascripts/admin/models/site_customization.js b/app/assets/javascripts/admin/models/site_customization.js index d7dc273fe65..93799f33ef0 100644 --- a/app/assets/javascripts/admin/models/site_customization.js +++ b/app/assets/javascripts/admin/models/site_customization.js @@ -23,7 +23,7 @@ Discourse.SiteCustomization = Discourse.Model.extend({ var _this = this; if(!this.originals) return false; - var changed = this.trackedProperties.any(function(p) { + var changed = _.some(this.trackedProperties,function(p) { return _this.originals[p] !== _this.get(p); }); @@ -38,8 +38,8 @@ Discourse.SiteCustomization = Discourse.Model.extend({ startTrackingChanges: function() { var _this = this; var originals = {}; - this.trackedProperties.each(function(p) { - originals[p] = _this.get(p); + _.each(this.trackedProperties,function(prop) { + originals[prop] = _this.get(prop); return true; }); this.set('originals', originals); @@ -90,7 +90,7 @@ Discourse.SiteCustomization = Discourse.Model.extend({ var SiteCustomizations = Ember.ArrayProxy.extend({ selectedItemChanged: function() { var selected = this.get('selectedItem'); - return this.get('content').each(function(i) { + _.each(this.get('content'),function(i) { return i.set('selected', selected === i); }); }.observes('selectedItem') @@ -101,7 +101,7 @@ Discourse.SiteCustomization.reopenClass({ var customizations = SiteCustomizations.create({ content: [], loading: true }); Discourse.ajax("/admin/site_customizations").then(function (data) { if (data) { - data.site_customizations.each(function(c) { + _.each(data.site_customizations,function(c) { customizations.pushObject(Discourse.SiteCustomization.create(c.site_customizations)); }); } diff --git a/app/assets/javascripts/admin/models/site_setting.js b/app/assets/javascripts/admin/models/site_setting.js index 23c016586ae..5e0ac79c106 100644 --- a/app/assets/javascripts/admin/models/site_setting.js +++ b/app/assets/javascripts/admin/models/site_setting.js @@ -91,7 +91,7 @@ Discourse.SiteSetting.reopenClass({ findAll: function() { var result = Em.A(); Discourse.ajax("/admin/site_settings").then(function (settings) { - settings.site_settings.each(function(s) { + _.each(settings.site_settings,function(s) { s.originalValue = s.value; result.pushObject(Discourse.SiteSetting.create(s)); }); diff --git a/app/assets/javascripts/admin/routes/admin_dashboard_route.js b/app/assets/javascripts/admin/routes/admin_dashboard_route.js index 54d10f09c04..1cd10c02784 100644 --- a/app/assets/javascripts/admin/routes/admin_dashboard_route.js +++ b/app/assets/javascripts/admin/routes/admin_dashboard_route.js @@ -14,13 +14,13 @@ Discourse.AdminDashboardRoute = Discourse.Route.extend({ }, fetchDashboardData: function(c) { - if( !c.get('dashboardFetchedAt') || Date.create('1 hour ago', 'en') > c.get('dashboardFetchedAt') ) { + if( !c.get('dashboardFetchedAt') || moment().subtract('hour', 1).toDate() > c.get('dashboardFetchedAt') ) { c.set('dashboardFetchedAt', new Date()); Discourse.AdminDashboard.find().then(function(d) { if( Discourse.SiteSettings.version_checks ){ c.set('versionCheck', Discourse.VersionCheck.create(d.version_check)); } - d.reports.each(function(report){ + _.each(d.reports,function(report){ c.set(report.type, Discourse.Report.create(report)); }); c.set('admins', d.admins); @@ -33,14 +33,14 @@ Discourse.AdminDashboardRoute = Discourse.Route.extend({ }); } - if( !c.get('problemsFetchedAt') || Date.create(c.problemsCheckInterval, 'en') > c.get('problemsFetchedAt') ) { + if( !c.get('problemsFetchedAt') || moment.subtract('minute',c.problemsCheckMinutes).toDate() > c.get('problemsFetchedAt') ) { c.set('problemsFetchedAt', new Date()); c.loadProblems(); } }, fetchGithubCommits: function(c) { - if( !c.get('commitsCheckedAt') || Date.create('1 hour ago', 'en') > c.get('commitsCheckedAt') ) { + if( !c.get('commitsCheckedAt') || moment().subtract('hour',1).toDate() > c.get('commitsCheckedAt') ) { c.set('commitsCheckedAt', new Date()); c.set('githubCommits', Discourse.GithubCommit.findAll()); } diff --git a/app/assets/javascripts/admin/routes/admin_email_preview_digest_route.js b/app/assets/javascripts/admin/routes/admin_email_preview_digest_route.js index 96d90a8cddf..08b4327ce51 100644 --- a/app/assets/javascripts/admin/routes/admin_email_preview_digest_route.js +++ b/app/assets/javascripts/admin/routes/admin_email_preview_digest_route.js @@ -8,8 +8,8 @@ **/ var oneWeekAgo = function() { - // TODO: Take out due to being evil sugar js? - return Date.create(7 + ' days ago', 'en').format('{yyyy}-{MM}-{dd}'); + // TODO localize date format? + return moment().subtract('days',7).format('yyyy-MM-dd'); } Discourse.AdminEmailPreviewDigestRoute = Discourse.Route.extend(Discourse.ModelReady, { diff --git a/app/assets/javascripts/admin/views/ace_editor_view.js b/app/assets/javascripts/admin/views/ace_editor_view.js index 023f0e3a84e..1fd1d707cf0 100644 --- a/app/assets/javascripts/admin/views/ace_editor_view.js +++ b/app/assets/javascripts/admin/views/ace_editor_view.js @@ -52,10 +52,10 @@ Discourse.AceEditorView = Discourse.View.extend({ if (window.ace) { initAce(); } else { - $LAB.script('http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js').wait(initAce); + $LAB.script('/javascripts/ace/ace.js').wait(initAce); } } }); -Discourse.View.registerHelper('aceEditor', Discourse.AceEditorView); \ No newline at end of file +Discourse.View.registerHelper('aceEditor', Discourse.AceEditorView); diff --git a/app/assets/javascripts/application.js.erb b/app/assets/javascripts/application.js.erb index 4e76ea1ba85..a078ac15f6e 100644 --- a/app/assets/javascripts/application.js.erb +++ b/app/assets/javascripts/application.js.erb @@ -16,11 +16,9 @@ <% if Rails.env.development? require_asset ("./external_development/ember.js") - require_asset ("./external_development/sugar-1.3.5.js") require_asset ("./external_development/group-helper.js") else require_asset ("./external_production/ember.js") - require_asset ("./external_production/sugar-1.3.5.js") require_asset ("./external_production/group-helper.js") end diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index 33e1627ce39..85d55af8b5a 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -294,7 +294,7 @@ Discourse = Ember.Application.createWithMixins({ bus.subscribe("/categories", function(data){ var site = Discourse.Site.instance(); - data.categories.each(function(c){ + _.each(data.categories,function(c){ site.updateCategory(c) }); }); diff --git a/app/assets/javascripts/discourse/components/autocomplete.js b/app/assets/javascripts/discourse/components/autocomplete.js index 8a3485b9f5d..ac370bc5e17 100644 --- a/app/assets/javascripts/discourse/components/autocomplete.js +++ b/app/assets/javascripts/discourse/components/autocomplete.js @@ -92,7 +92,7 @@ $.fn.autocomplete = function(options) { this.width(150); this.attr('name', this.attr('name') + "-renamed"); var vals = this.val().split(","); - vals.each(function(x) { + _.each(vals,function(x) { if (x !== "") { if (options.reverseTransform) { x = options.reverseTransform(x); diff --git a/app/assets/javascripts/discourse/components/bbcode.js b/app/assets/javascripts/discourse/components/bbcode.js index 7a17830544f..0a150759c14 100644 --- a/app/assets/javascripts/discourse/components/bbcode.js +++ b/app/assets/javascripts/discourse/components/bbcode.js @@ -91,15 +91,15 @@ Discourse.BBCode = { var result = {}; - Object.keys(Discourse.BBCode.replacers, function(name, rules) { + _.each(Discourse.BBCode.replacers, function(rules, name) { var parsed = result[name] = []; - Object.keys(Object.merge(Discourse.BBCode.replacers.base.withoutArgs, rules.withoutArgs), function(tag, val) { + _.each(_.extend(Discourse.BBCode.replacers.base.withoutArgs, rules.withoutArgs), function(val, tag) { parsed.push({ regexp: new RegExp("\\[" + tag + "\\]([\\s\\S]*?)\\[\\/" + tag + "\\]", "igm"), fn: val }); }); - Object.keys(Object.merge(Discourse.BBCode.replacers.base.withArgs, rules.withArgs), function(tag, val) { + _.each(_.extend(Discourse.BBCode.replacers.base.withArgs, rules.withArgs), function(val, tag) { parsed.push({ regexp: new RegExp("\\[" + tag + "=?(.+?)\\]([\\s\\S]*?)\\[\\/" + tag + "\\]", "igm"), fn: val }); }); @@ -172,7 +172,7 @@ Discourse.BBCode = { } result.template = function(input) { - replacements.each(function(r) { + _.each(replacements,function(r) { var val = r.value.trim(); val = val.replace(r.content, r.content.replace(/\n/g, '
')); input = input.replace(r.key, val); @@ -196,7 +196,7 @@ Discourse.BBCode = { paramsString = matches[1].replace(/\"/g, ''); paramsSplit = paramsString.split(/\, */); params = []; - paramsSplit.each(function(p, i) { + _.each(paramsSplit,function(p,i) { if (i > 0) { var assignment = p.split(':'); if (assignment[0] && assignment[1]) { diff --git a/app/assets/javascripts/discourse/components/development.js b/app/assets/javascripts/discourse/components/development.js index 34dfa466376..30e9abd2ac6 100644 --- a/app/assets/javascripts/discourse/components/development.js +++ b/app/assets/javascripts/discourse/components/development.js @@ -53,10 +53,12 @@ Discourse.Development = { if (n === name || v.time < 1) continue; ary.push({ k: n, v: v }); } - ary.sortBy(function(item) { - if (item.v && item.v.time) return -item.v.time; - return 0; - }).each(function(item) { + ary.sort(function(x,y) { + x = x.v && x.v.time ? -x.v.time : 0; + y = y.v && y.v.time ? -y.v.time : 0; + return x > y; + }); + _.each(ary, function(item,idx) { var output = f("" + item.k, item.v); if (output) { console.log(output); @@ -114,7 +116,7 @@ Discourse.Development = { // Observe file changes return Discourse.MessageBus.subscribe("/file-change", function(data) { Ember.TEMPLATES.empty = Handlebars.compile("
"); - return data.each(function(me) { + _.each(data,function(me,idx) { var js; if (me === "refresh") { return document.location.reload(true); @@ -123,14 +125,13 @@ Discourse.Development = { return $LAB.script(js + "?hash=" + me.hash).wait(function() { var templateName; templateName = js.replace(".js", "").replace("/assets/", ""); - return $.each(Ember.View.views, function() { - var _this = this; - if (this.get('templateName') === templateName) { - this.set('templateName', 'empty'); - this.rerender(); + return _.each(Ember.View.views, function(view) { + if (view.get('templateName') === templateName) { + view.set('templateName', 'empty'); + view.rerender(); Em.run.schedule('afterRender', function() { - _this.set('templateName', templateName); - _this.rerender(); + view.set('templateName', templateName); + view.rerender(); }); } }); @@ -149,4 +150,4 @@ Discourse.Development = { }); } -}; \ No newline at end of file +}; diff --git a/app/assets/javascripts/discourse/components/formatter.js b/app/assets/javascripts/discourse/components/formatter.js index 3047722df1b..891aed9daab 100644 --- a/app/assets/javascripts/discourse/components/formatter.js +++ b/app/assets/javascripts/discourse/components/formatter.js @@ -1,16 +1,33 @@ Discourse.Formatter = (function(){ - var updateRelativeAge, autoUpdatingRelativeAge, relativeAge, relativeAgeTiny, relativeAgeMedium, relativeAgeMediumSpan, longDate; + var updateRelativeAge, autoUpdatingRelativeAge, relativeAge, relativeAgeTiny, + relativeAgeMedium, relativeAgeMediumSpan, longDate, toTitleCase, + shortDate; var shortDateNoYearFormat = Ember.String.i18n("dates.short_date_no_year"); var longDateFormat = Ember.String.i18n("dates.long_date"); var shortDateFormat = Ember.String.i18n("dates.short_date"); + shortDate = function(date){ + return moment(date).format(shortDateFormat); + }; + + + // http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript + // TODO: locale support ? + toTitleCase = function toTitleCase(str) + { + return str.replace(/\w\S*/g, function(txt){ + return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); + }); + } + longDate = function(dt) { return moment(dt).format(longDateFormat); }; updateRelativeAge = function(elems) { + // jQuery .each elems.each(function(){ var $this = $(this); $this.html(relativeAge(new Date($this.data('time')), $this.data('format'))); @@ -97,7 +114,6 @@ Discourse.Formatter = (function(){ formatted = t("x_days", {count: Math.round((distanceInMinutes - 720.0) / 1440.0)}); break; } - return formatted || '&mdash'; }; @@ -121,7 +137,7 @@ Discourse.Formatter = (function(){ displayDate = Em.String.i18n("now"); } else if (distance > fiveDaysAgo) { if ((new Date()).getFullYear() !== date.getFullYear()) { - displayDate = moment(date).format(shortDateFormat); + displayDate = shortDate(date); } else { displayDate = moment(date).format(shortDateNoYearFormat); } @@ -153,6 +169,8 @@ Discourse.Formatter = (function(){ longDate: longDate, relativeAge: relativeAge, autoUpdatingRelativeAge: autoUpdatingRelativeAge, - updateRelativeAge: updateRelativeAge + updateRelativeAge: updateRelativeAge, + toTitleCase: toTitleCase, + shortDate: shortDate }; })(); diff --git a/app/assets/javascripts/discourse/components/markdown.js b/app/assets/javascripts/discourse/components/markdown.js index 7ceee45a0d7..0fc5f0a19a3 100644 --- a/app/assets/javascripts/discourse/components/markdown.js +++ b/app/assets/javascripts/discourse/components/markdown.js @@ -166,7 +166,7 @@ Discourse.Markdown = { if (Discourse && Discourse.Onebox) { onebox = Discourse.Onebox.lookupCache(url); } - if (onebox && !onebox.isBlank()) { + if (onebox && onebox.trim().length > 0) { return arguments[2] + onebox; } else { return arguments[2] + arguments[4] + " class=\"onebox\" target=\"_blank\">" + arguments[6]; diff --git a/app/assets/javascripts/discourse/components/message_bus.js b/app/assets/javascripts/discourse/components/message_bus.js index e0d48979397..817f197aec0 100644 --- a/app/assets/javascripts/discourse/components/message_bus.js +++ b/app/assets/javascripts/discourse/components/message_bus.js @@ -69,8 +69,8 @@ Discourse.MessageBus = (function() { return; } data = {}; - callbacks.each(function(c) { - data[c.channel] = c.last_id === void 0 ? -1 : c.last_id; + _.each(callbacks, function(callback) { + data[callback.channel] = callback.last_id === void 0 ? -1 : callback.last_id; }); gotData = false; _this.longPoll = $.ajax(Discourse.getURL("/message-bus/") + clientId + "/poll?" + (!shouldLongPoll() || !_this.enableLongPolling ? "dlp=t" : ""), { @@ -83,9 +83,9 @@ Discourse.MessageBus = (function() { }, success: function(messages) { failCount = 0; - return messages.each(function(message) { + _.each(messages,function(message) { gotData = true; - return callbacks.each(function(callback) { + _.each(callbacks, function(callback) { if (callback.channel === message.channel) { callback.last_id = message.message_id; callback.func(message.data); @@ -139,11 +139,11 @@ Discourse.MessageBus = (function() { unsubscribe: function(channel) { // TODO proper globbing var glob; - if (channel.endsWith("*")) { + if (channel.indexOf("*", channel.length - 1) !== -1) { channel = channel.substr(0, channel.length - 1); glob = true; } - callbacks = callbacks.filter(function(callback) { + callbacks = $.grep(callbacks,function(callback) { if (glob) { return callback.channel.substr(0, channel.length) !== channel; } else { diff --git a/app/assets/javascripts/discourse/components/screen_track.js b/app/assets/javascripts/discourse/components/screen_track.js index a635a8a7e73..1e0860a7717 100644 --- a/app/assets/javascripts/discourse/components/screen_track.js +++ b/app/assets/javascripts/discourse/components/screen_track.js @@ -77,7 +77,7 @@ Discourse.ScreenTrack = Ember.Object.extend({ // Update our total timings var totalTimings = this.get('totalTimings'); - Object.values(this.get('timings'), function(timing) { + _.each(this.get('timings'), function(timing,key) { if (!totalTimings[timing.postNumber]) totalTimings[timing.postNumber] = 0; @@ -90,15 +90,16 @@ Discourse.ScreenTrack = Ember.Object.extend({ var topicId = parseInt(this.get('topicId'), 10); var highestSeen = 0; - Object.keys(newTimings, function(postNumber) { + _.each(newTimings, function(time,postNumber) { highestSeen = Math.max(highestSeen, parseInt(postNumber, 10)); }); var highestSeenByTopic = Discourse.get('highestSeenByTopic'); if ((highestSeenByTopic[topicId] || 0) < highestSeen) { highestSeenByTopic[topicId] = highestSeen; + Discourse.TopicTrackingState.current().updateSeen(topicId, highestSeen); } - if (!Object.isEmpty(newTimings)) { + if (!$.isEmptyObject(newTimings)) { Discourse.ajax('/topics/timings', { data: { @@ -144,8 +145,8 @@ Discourse.ScreenTrack = Ember.Object.extend({ // TODO: Eyeline has a smarter more accurate function here. It's bad to do jQuery // in a model like component, so we should refactor this out later. var screenTrack = this; - return Object.keys(this.get('timings'), function(id) { - var $element, elemBottom, elemTop, timing; + _.each(this.get('timings'),function(timing,id) { + var $element, elemBottom, elemTop; $element = $(id); if ($element.length === 1) { elemTop = $element.offset().top; @@ -153,7 +154,6 @@ Discourse.ScreenTrack = Ember.Object.extend({ // If part of the element is on the screen, increase the counter if (((docViewTop <= elemTop && elemTop <= docViewBottom)) || ((docViewTop <= elemBottom && elemBottom <= docViewBottom))) { - timing = screenTrack.timings[id]; timing.time = timing.time + diff; } } diff --git a/app/assets/javascripts/discourse/components/user_search.js b/app/assets/javascripts/discourse/components/user_search.js index 8b827f9551d..3a8aae6dd29 100644 --- a/app/assets/javascripts/discourse/components/user_search.js +++ b/app/assets/javascripts/discourse/components/user_search.js @@ -47,7 +47,7 @@ Discourse.UserSearch = { var organizeResults = function(r) { var result = []; - r.users.each(function(u) { + _.each(r.users,function(u) { if (exclude.indexOf(u.username) === -1) { result.push(u); } diff --git a/app/assets/javascripts/discourse/controllers/edit_topic_auto_close_controller.js b/app/assets/javascripts/discourse/controllers/edit_topic_auto_close_controller.js index 45c9129bb4b..9371c873364 100644 --- a/app/assets/javascripts/discourse/controllers/edit_topic_auto_close_controller.js +++ b/app/assets/javascripts/discourse/controllers/edit_topic_auto_close_controller.js @@ -11,12 +11,12 @@ Discourse.EditTopicAutoCloseController = Discourse.ObjectController.extend(Disco setDays: function() { if( this.get('auto_close_at') ) { - var closeTime = Date.create( this.get('auto_close_at') ); - if (closeTime.isFuture()) { + var closeTime = new Date( this.get('auto_close_at') ); + if (closeTime > new Date()) { this.set('auto_close_days', closeTime.daysSince()); } } else { - this.set('auto_close_days', ""); + this.set('auto_close_days', ''); } }.observes('auto_close_at'), @@ -31,15 +31,15 @@ Discourse.EditTopicAutoCloseController = Discourse.ObjectController.extend(Disco setAutoClose: function(days) { var editTopicAutoCloseController = this; Discourse.ajax({ - url: "/t/" + this.get('id') + "/autoclose", + url: '/t/' + this.get('id') + '/autoclose', type: 'PUT', dataType: 'json', data: { auto_close_days: days > 0 ? days : null } }).then(function(){ - editTopicAutoCloseController.set('auto_close_at', Date.create(days + ' days from now').toJSON()); + editTopicAutoCloseController.set('auto_close_at', moment().add('days', days).format()); }, function (error) { bootbox.alert(Em.String.i18n('generic_error')); }); } -}); \ No newline at end of file +}); diff --git a/app/assets/javascripts/discourse/controllers/history_controller.js b/app/assets/javascripts/discourse/controllers/history_controller.js index 7704aa11ca9..8f4d686f45c 100644 --- a/app/assets/javascripts/discourse/controllers/history_controller.js +++ b/app/assets/javascripts/discourse/controllers/history_controller.js @@ -65,15 +65,15 @@ Discourse.HistoryController = Discourse.ObjectController.extend(Discourse.ModalF var historyController = this; this.get('model').loadVersions().then(function(result) { - result.each(function(item) { - item.description = "v" + item.number + " - " + Date.create(item.created_at).relative() + " - " + + _.each(result,function(item) { + item.description = "v" + item.number + " - " + Discourse.Formatter.relativeAge(new Date(item.created_at), {format: 'medium', leaveAgo: true}) + " - " + Em.String.i18n("changed_by", { author: item.display_username }); }); historyController.setProperties({ loading: false, - versionLeft: result.first(), - versionRight: result.last(), + versionLeft: result[0], + versionRight: result[result.length-1], versions: result }); }); diff --git a/app/assets/javascripts/discourse/controllers/search_controller.js b/app/assets/javascripts/discourse/controllers/search_controller.js index c93fbc80a41..b9e02f09bb5 100644 --- a/app/assets/javascripts/discourse/controllers/search_controller.js +++ b/app/assets/javascripts/discourse/controllers/search_controller.js @@ -41,11 +41,11 @@ Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, { // Default order var order = ['topic', 'category', 'user']; - results = order.map(function(o) { return results_hashed[o] }).without(void 0); + results = _(order).map(function(o) { return results_hashed[o] }).without(void 0); var index = 0; results.forEach(function(r) { - r.results.each(function(item) { + _.each(r.results,function(item) { item.index = index++; }); }); @@ -92,4 +92,4 @@ Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, { } } -}); \ No newline at end of file +}); diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 71d519ad7be..dd49cbbbc7b 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -127,7 +127,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected jumpTop: function() { if (this.get('bestOf')) { - Discourse.TopicView.scrollTo(this.get('id'), this.get('posts').first().get('post_number')); + Discourse.TopicView.scrollTo(this.get('id'), this.get('posts')[0].get('post_number')); } else { Discourse.URL.routeTo(this.get('url')); } @@ -253,12 +253,12 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected var topicController = this; var postFilters = this.get('postFilters'); return Discourse.Topic.find(this.get('id'), postFilters).then(function(result) { - var first = result.posts.first(); + var first = result.posts[0]; if (first) { topicController.set('currentPost', first.post_number); } $('#topic-progress .solid').data('progress', false); - result.posts.each(function(p) { + _.each(result.posts,function(p) { // Skip the first post if (p.post_number === 1) return; posts.pushObject(Discourse.Post.create(p, topic)); diff --git a/app/assets/javascripts/discourse/helpers/application_helpers.js b/app/assets/javascripts/discourse/helpers/application_helpers.js index 79e51360ec5..d95b4fdd15f 100644 --- a/app/assets/javascripts/discourse/helpers/application_helpers.js +++ b/app/assets/javascripts/discourse/helpers/application_helpers.js @@ -13,7 +13,7 @@ Handlebars.registerHelper('breakUp', function(property, options) { if (tokens.length === 1) return prop; result = ""; - tokens.each(function(token, index) { + _.each(tokens,function(token,index) { result += token; if (token.indexOf(' ') === -1 && (index < tokens.length - 1)) { result += "- "; @@ -29,7 +29,7 @@ Handlebars.registerHelper('breakUp', function(property, options) { @for Handlebars **/ Handlebars.registerHelper('shorten', function(property, options) { - return Ember.Handlebars.get(this, property, options).truncate(35); + return Ember.Handlebars.get(this, property, options).substring(0,35); }); /** @@ -100,7 +100,7 @@ Handlebars.registerHelper('shortenUrl', function(property, options) { } url = url.replace(/^https?:\/\//, ''); url = url.replace(/^www\./, ''); - return url.truncate(80); + return url.substring(0,80); }); /** diff --git a/app/assets/javascripts/discourse/mixins/presence.js b/app/assets/javascripts/discourse/mixins/presence.js index 80cecc0ad14..9576c16ea9d 100644 --- a/app/assets/javascripts/discourse/mixins/presence.js +++ b/app/assets/javascripts/discourse/mixins/presence.js @@ -23,10 +23,10 @@ Discourse.Presence = Em.Mixin.create({ if (!prop) return true; switch (typeof prop) { - case "string": - return prop.trim().isBlank(); - case "object": - return Object.isEmpty(prop); + case "string": + return prop.trim().length === 0; + case "object": + return $.isEmptyObject(prop); } return false; }, diff --git a/app/assets/javascripts/discourse/models/action_summary.js b/app/assets/javascripts/discourse/models/action_summary.js index 7b6cc03597a..e9aa2a30fe0 100644 --- a/app/assets/javascripts/discourse/models/action_summary.js +++ b/app/assets/javascripts/discourse/models/action_summary.js @@ -112,8 +112,8 @@ Discourse.ActionSummary = Discourse.Model.extend({ }).then(function (result) { var users = Em.A(); actionSummary.set('users', users); - result.each(function(u) { - users.pushObject(Discourse.User.create(u)); + _.each(result,function(user) { + users.pushObject(Discourse.User.create(user)); }); }); } diff --git a/app/assets/javascripts/discourse/models/category.js b/app/assets/javascripts/discourse/models/category.js index 76c04dc71bd..7ba6aaf78af 100644 --- a/app/assets/javascripts/discourse/models/category.js +++ b/app/assets/javascripts/discourse/models/category.js @@ -86,7 +86,7 @@ Discourse.Category.reopenClass({ if (!category) return ""; var id = Em.get(category, 'id'); var slug = Em.get(category, 'slug'); - if ((!slug) || slug.isBlank()) return "" + id + "-category"; + if (!slug || slug.trim().length === 0) return "" + id + "-category"; return slug; }, diff --git a/app/assets/javascripts/discourse/models/category_list.js b/app/assets/javascripts/discourse/models/category_list.js index f90df5e9d44..ac7a0033007 100644 --- a/app/assets/javascripts/discourse/models/category_list.js +++ b/app/assets/javascripts/discourse/models/category_list.js @@ -15,14 +15,14 @@ Discourse.CategoryList.reopenClass({ var users = this.extractByKey(result.featured_users, Discourse.User); - result.category_list.categories.each(function(c) { + _.each(result.category_list.categories,function(c) { if (c.featured_user_ids) { - c.featured_users = c.featured_user_ids.map(function(u) { + c.featured_users = _.map(c.featured_user_ids,function(u) { return users[u]; }); } if (c.topics) { - c.topics = c.topics.map(function(t) { + c.topics = _.map(c.topics,function(t) { return Discourse.Topic.create(t); }); } diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index d7092eaa810..a9dda18c5ac 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -328,7 +328,7 @@ Discourse.Composer = Discourse.Model.extend({ // perhaps our post came from elsewhere eg. draft var idx = -1; var postNumber = post.get('post_number'); - posts.each(function(p, i) { + _.each(posts,function(p,i) { if (p.get('post_number') === postNumber) { idx = i; } @@ -408,7 +408,7 @@ Discourse.Composer = Discourse.Model.extend({ createdPost.set('created_at', new Date()); // If we're near the end of the topic, load new posts - var lastPost = topic.posts.last(); + var lastPost = topic.posts[topic.posts.length-1]; if (lastPost) { var diff = topic.get('highest_post_number') - lastPost.get('post_number'); diff --git a/app/assets/javascripts/discourse/models/model.js b/app/assets/javascripts/discourse/models/model.js index 8750ee2b399..31f1f289850 100644 --- a/app/assets/javascripts/discourse/models/model.js +++ b/app/assets/javascripts/discourse/models/model.js @@ -18,7 +18,7 @@ Discourse.Model = Ember.Object.extend(Discourse.Presence, { **/ mergeAttributes: function(attrs, builders) { var _this = this; - return Object.keys(attrs, function(k, v) { + _.each(attrs, function(v,k) { // If they're in a builder we use that var builder, col; if (typeof v === 'object' && builders && (builder = builders[k])) { @@ -26,7 +26,7 @@ Discourse.Model = Ember.Object.extend(Discourse.Presence, { _this.set(k, Em.A()); } col = _this.get(k); - return v.each(function(obj) { + _.each(v,function(obj) { col.pushObject(builder.create(obj)); }); } else { @@ -49,7 +49,7 @@ Discourse.Model.reopenClass({ extractByKey: function(collection, klass) { var retval = {}; if (!collection) return retval; - collection.each(function(c) { + _.each(collection,function(c) { retval[c.id] = klass.create(c); }); return retval; diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index 60a34fe1a09..2812412f963 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -114,7 +114,7 @@ Discourse.Post = Discourse.Model.extend({ rightNow = new Date().getTime(); // Show heat on age - updatedAtDate = Date.create(updatedAt).getTime(); + updatedAtDate = new Date(updatedAt).getTime(); if (updatedAtDate > (rightNow - 60 * 60 * 1000 * 12)) return 'heatmap-high'; if (updatedAtDate > (rightNow - 60 * 60 * 1000 * 24)) return 'heatmap-med'; if (updatedAtDate > (rightNow - 60 * 60 * 1000 * 48)) return 'heatmap-low'; @@ -207,10 +207,11 @@ Discourse.Post = Discourse.Model.extend({ // Update all the properties if (!obj) return; - Object.each(obj, function(key, val) { - if (key === 'actions_summary') return false; - if (val) { - post.set(key, val); + _.each(obj, function(val,key) { + if (key !== 'actions_summary'){ + if (val) { + post.set(key, val); + } } }); @@ -218,7 +219,7 @@ Discourse.Post = Discourse.Model.extend({ this.set('actions_summary', Em.A()); if (obj.actions_summary) { var lookup = Em.Object.create(); - obj.actions_summary.each(function(a) { + _.each(obj.actions_summary,function(a) { var actionSummary; a.post = post; a.actionType = Discourse.Site.instance().postActionTypeById(a.id); @@ -238,7 +239,7 @@ Discourse.Post = Discourse.Model.extend({ var parent = this; return Discourse.ajax("/posts/" + (this.get('id')) + "/replies").then(function(loaded) { var replies = parent.get('replies'); - loaded.each(function(reply) { + _.each(loaded,function(reply) { var post = Discourse.Post.create(reply); post.set('topic', parent.get('topic')); replies.pushObject(post); diff --git a/app/assets/javascripts/discourse/models/selectable_array.js b/app/assets/javascripts/discourse/models/selectable_array.js index a57d77b82ca..07eca704b21 100644 --- a/app/assets/javascripts/discourse/models/selectable_array.js +++ b/app/assets/javascripts/discourse/models/selectable_array.js @@ -8,7 +8,7 @@ Discourse.SelectableArray = Em.ArrayProxy.extend({ this.select(this[index]); }, select: function(selected){ - this.content.each(function(item){ + _.each(this.content,function(item){ if(item === selected){ Em.set(item, "active", true) } else { diff --git a/app/assets/javascripts/discourse/models/site.js b/app/assets/javascripts/discourse/models/site.js index 861fbf32fad..46311444ea6 100644 --- a/app/assets/javascripts/discourse/models/site.js +++ b/app/assets/javascripts/discourse/models/site.js @@ -10,7 +10,7 @@ Discourse.Site = Discourse.Model.extend({ notificationLookup: function() { var result = []; - Object.keys(this.get('notification_types'), function(k, v) { + _.each(this.get('notification_types'), function(v,k) { result[v] = k; }); return result; @@ -40,28 +40,29 @@ Discourse.Site.reopenClass({ create: function(obj) { var _this = this; - return Object.tap(this._super(obj), function(result) { + var result = this._super(obj); - if (result.categories) { - result.categories = result.categories.map(function(c) { - return Discourse.Category.create(c); - }); - } - if (result.post_action_types) { - result.postActionByIdLookup = Em.Object.create(); - result.post_action_types = result.post_action_types.map(function(p) { - var actionType; - actionType = Discourse.PostActionType.create(p); - result.postActionByIdLookup.set("action" + p.id, actionType); - return actionType; - }); - } - if (result.archetypes) { - result.archetypes = result.archetypes.map(function(a) { - return Discourse.Archetype.create(a); - }); - } - }); + if (result.categories) { + result.categories = _.map(result.categories, function(c) { + return Discourse.Category.create(c); + }); + } + if (result.post_action_types) { + result.postActionByIdLookup = Em.Object.create(); + result.post_action_types = _.map(result.post_action_types,function(p) { + var actionType; + actionType = Discourse.PostActionType.create(p); + result.postActionByIdLookup.set("action" + p.id, actionType); + return actionType; + }); + } + if (result.archetypes) { + result.archetypes = _.map(result.archetypes,function(a) { + return Discourse.Archetype.create(a); + }); + } + + return result; } }); diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index 28fbfe09de7..19863e49015 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -44,7 +44,7 @@ Discourse.Topic = Discourse.Model.extend({ url: function() { var slug = this.get('slug'); - if (slug.isBlank()) { + if (slug.trim().length === 0) { slug = "topic"; } return Discourse.getURL("/t/") + slug + "/" + (this.get('id')); @@ -69,16 +69,19 @@ Discourse.Topic = Discourse.Model.extend({ // The last post in the topic lastPost: function() { - return this.get('posts').last(); + var posts = this.get('posts') + return posts[posts.length-1]; }, postsChanged: function() { var last, posts; posts = this.get('posts'); - last = posts.last(); + last = posts[posts.length - 1]; if (!(last && last.set && !last.lastPost)) return; - posts.each(function(p) { - if (p.lastPost) return p.set('lastPost', false); + _.each(posts,function(p) { + if (p.lastPost) { + p.set('lastPost', false); + } }); last.set('lastPost', true); return true; @@ -232,7 +235,7 @@ Discourse.Topic = Discourse.Model.extend({ opts.nearPost = parseInt(opts.nearPost, 10); closestPostNumber = 0; postDiff = Number.MAX_VALUE; - result.posts.each(function(p) { + _.each(result.posts,function(p) { var diff = Math.abs(p.post_number - opts.nearPost); if (diff < postDiff) { postDiff = diff; @@ -263,7 +266,7 @@ Discourse.Topic = Discourse.Model.extend({ // Okay this is weird, but let's store the length of the next post when there lastPost = null; - result.posts.each(function(p) { + _.each(result.posts,function(p) { p.scrollToAfterInsert = opts.nearPost; var post = Discourse.Post.create(p); post.set('topic', topic); @@ -327,12 +330,12 @@ Discourse.Topic = Discourse.Model.extend({ var map, posts; map = {}; posts = this.get('posts'); - posts.each(function(p) { - map["" + p.post_number] = true; + _.each(posts,function(post) { + map["" + post.post_number] = true; }); - return newPosts.each(function(p) { - if (!map[p.get('post_number')]) { - return posts.pushObject(p); + _.each(newPosts,function(post) { + if (!map[post.get('post_number')]) { + posts.pushObject(post); } }); }, @@ -445,7 +448,7 @@ Discourse.Topic.reopenClass({ return PreloadStore.getAndRemove("topic_" + topicId, function() { return Discourse.ajax(url + ".json", {data: data}); }).then(function(result) { - var first = result.posts.first(); + var first = result.posts[0]; if (first && opts && opts.bestOf) { first.bestOfFirst = true; } @@ -476,19 +479,21 @@ Discourse.Topic.reopenClass({ }, create: function(obj, topicView) { - return Object.tap(this._super(obj), function(result) { - if (result.participants) { - result.participants = result.participants.map(function(u) { - return Discourse.User.create(u); - }); - result.fewParticipants = Em.A(); - return result.participants.each(function(p) { - if (result.fewParticipants.length >= 8) return false; - result.fewParticipants.pushObject(p); - return true; - }); - } - }); + var result = this._super(obj); + + if (result.participants) { + result.participants = _.map(result.participants,function(u) { + return Discourse.User.create(u); + }); + result.fewParticipants = Em.A(); + _.each(result.participants,function(p) { + // TODO should not be hardcoded + if (result.fewParticipants.length >= 8) return false; + result.fewParticipants.pushObject(p); + }); + } + + return result; } }); diff --git a/app/assets/javascripts/discourse/models/topic_list.js b/app/assets/javascripts/discourse/models/topic_list.js index 33da16c3ab3..773e427c24a 100644 --- a/app/assets/javascripts/discourse/models/topic_list.js +++ b/app/assets/javascripts/discourse/models/topic_list.js @@ -11,13 +11,13 @@ Discourse.TopicList = Discourse.Model.extend({ forEachNew: function(topics, callback) { var topicIds = []; - this.get('topics').each(function(t) { - topicIds[t.get('id')] = true; + _.each(this.get('topics'),function(topic) { + topicIds[topic.get('id')] = true; }); - topics.each(function(t) { - if(!topicIds[t.id]) { - callback(t); + _.each(topics,function(topic) { + if(!topicIds[topic.id]) { + callback(topic); } }); }, @@ -99,12 +99,12 @@ Discourse.TopicList.reopenClass({ categories = this.extractByKey(result.categories, Discourse.Category); users = this.extractByKey(result.users, Discourse.User); topics = Em.A(); - result.topic_list.topics.each(function(ft) { + _.each(result.topic_list.topics,function(ft) { ft.category = categories[ft.category_id]; - ft.posters.each(function(p) { + _.each(ft.posters,function(p) { p.user = users[p.user_id]; }); - return topics.pushObject(Discourse.Topic.create(ft)); + topics.pushObject(Discourse.Topic.create(ft)); }); return topics; }, diff --git a/app/assets/javascripts/discourse/models/topic_tracking_state.js b/app/assets/javascripts/discourse/models/topic_tracking_state.js index 3958587c20e..d7555d054b8 100644 --- a/app/assets/javascripts/discourse/models/topic_tracking_state.js +++ b/app/assets/javascripts/discourse/models/topic_tracking_state.js @@ -32,6 +32,14 @@ Discourse.TopicTrackingState = Discourse.Model.extend({ } }, + updateSeen: function(topicId, highestSeen) { + var state = this.states["t" + topicId]; + if(state && state.last_read_post_number < highestSeen) { + state.last_read_post_number = highestSeen; + this.incrementMessageCount(); + } + }, + notify: function(data){ if (!this.newIncoming) { return; } @@ -75,25 +83,24 @@ Discourse.TopicTrackingState = Discourse.Model.extend({ if(filter === "new" && !list.more_topics_url){ // scrub all new rows and reload from list - $.each(this.states, function(){ - if(this.last_read_post_number === null) { - tracker.removeTopic(this.topic_id); + _.each(this.states, function(state){ + if(state.last_read_post_number === null) { + tracker.removeTopic(state.topic_id); } }); } if(filter === "unread" && !list.more_topics_url){ // scrub all new rows and reload from list - $.each(this.states, function(){ - if(this.last_read_post_number !== null) { - tracker.removeTopic(this.topic_id); + _.each(this.states, function(state){ + if(state.last_read_post_number !== null) { + tracker.removeTopic(state.topic_id); } }); } - $.each(list.topics, function(){ + _.each(list.topics, function(topic){ var row = {}; - var topic = this; row.topic_id = topic.id; if(topic.unseen) { @@ -123,28 +130,27 @@ Discourse.TopicTrackingState = Discourse.Model.extend({ }, countNew: function(){ - var count = 0; - $.each(this.states, function(){ - count += this.last_read_post_number === null ? 1 : 0; - }); - return count; + return _.chain(this.states) + .where({last_read_post_number: null}) + .value() + .length; }, countUnread: function(){ var count = 0; - $.each(this.states, function(){ - count += (this.last_read_post_number !== null && - this.last_read_post_number < this.highest_post_number) ? 1 : 0; + _.each(this.states, function(topic){ + count += (topic.last_read_post_number !== null && + topic.last_read_post_number < topic.highest_post_number) ? 1 : 0; }); return count; }, countCategory: function(category) { var count = 0; - $.each(this.states, function(){ - if (this.category_name === category) { - count += (this.last_read_post_number === null || - this.last_read_post_number < this.highest_post_number) ? 1 : 0; + _.each(this.states, function(topic){ + if (topic.category_name === category) { + count += (topic.last_read_post_number === null || + topic.last_read_post_number < topic.highest_post_number) ? 1 : 0; } }); return count; @@ -167,8 +173,8 @@ Discourse.TopicTrackingState = Discourse.Model.extend({ var states = this.states; if(data) { - data.each(function(row){ - states["t" + row.topic_id] = row; + _.each(data,function(topic){ + states["t" + topic.topic_id] = topic; }); } } diff --git a/app/assets/javascripts/discourse/models/user.js b/app/assets/javascripts/discourse/models/user.js index 3ba11f68b54..6cfa31ccf7c 100644 --- a/app/assets/javascripts/discourse/models/user.js +++ b/app/assets/javascripts/discourse/models/user.js @@ -209,9 +209,11 @@ Discourse.User = Discourse.Model.extend({ **/ statsCountNonPM: function() { if (this.blank('statsExcludingPms')) return 0; - return this.get('statsExcludingPms').getEach('count').reduce(function (accum, val) { - return accum + val; + var count = 0; + _.each(this.get('statsExcludingPms'), function(val) { + count += val.count; }); + return count; }.property('statsExcludingPms.@each.count'), /** @@ -242,7 +244,7 @@ Discourse.User = Discourse.Model.extend({ return PreloadStore.getAndRemove("user_" + user.get('username'), function() { return Discourse.ajax("/users/" + user.get('username') + '.json'); }).then(function (json) { - json.user.stats = Discourse.User.groupStats(json.user.stats.map(function(s) { + json.user.stats = Discourse.User.groupStats(_.map(json.user.stats,function(s) { if (s.count) s.count = parseInt(s.count, 10); return Discourse.UserActionStat.create(s); })); diff --git a/app/assets/javascripts/discourse/models/user_action.js b/app/assets/javascripts/discourse/models/user_action.js index 3e827e99253..9d57dcbe815 100644 --- a/app/assets/javascripts/discourse/models/user_action.js +++ b/app/assets/javascripts/discourse/models/user_action.js @@ -158,7 +158,7 @@ Discourse.UserAction.reopenClass({ uniq = {}; collapsed = Em.A(); pos = 0; - stream.each(function(item) { + _.each(stream, function(item) { var current, found, key; key = "" + item.topic_id + "-" + item.post_number; found = uniq[key]; diff --git a/app/assets/javascripts/discourse/models/user_stream.js b/app/assets/javascripts/discourse/models/user_stream.js index 5784c5c2e1e..3bd5010033d 100644 --- a/app/assets/javascripts/discourse/models/user_stream.js +++ b/app/assets/javascripts/discourse/models/user_stream.js @@ -24,10 +24,10 @@ Discourse.UserStream = Discourse.Model.extend({ var stream = this; return Discourse.ajax(url, {cache: 'false'}).then( function(result) { - if (result && result.user_actions && result.user_actions.each) { + if (result && result.user_actions) { var copy = Em.A(); - result.user_actions.each(function(i) { - return copy.pushObject(Discourse.UserAction.create(i)); + _.each(result.user_actions,function(action) { + copy.pushObject(Discourse.UserAction.create(action)); }); copy = Discourse.UserAction.collapseStream(copy); stream.get('content').pushObjects(copy); @@ -36,4 +36,4 @@ Discourse.UserStream = Discourse.Model.extend({ }); } -}); \ No newline at end of file +}); diff --git a/app/assets/javascripts/discourse/routes/filtered_list_route.js b/app/assets/javascripts/discourse/routes/filtered_list_route.js index a612724afdc..f1cdac355ea 100644 --- a/app/assets/javascripts/discourse/routes/filtered_list_route.js +++ b/app/assets/javascripts/discourse/routes/filtered_list_route.js @@ -44,7 +44,7 @@ Discourse.FilteredListRoute = Discourse.Route.extend({ } }); -Discourse.ListController.filters.each(function(filter) { +Discourse.ListController.filters.forEach(function(filter) { Discourse["List" + (filter.capitalize()) + "Route"] = Discourse.FilteredListRoute.extend({ filter: filter }); }); diff --git a/app/assets/javascripts/discourse/views/buttons/dropdown_button_view.js b/app/assets/javascripts/discourse/views/buttons/dropdown_button_view.js index ea12526f774..4cdd5a587c1 100644 --- a/app/assets/javascripts/discourse/views/buttons/dropdown_button_view.js +++ b/app/assets/javascripts/discourse/views/buttons/dropdown_button_view.js @@ -37,7 +37,7 @@ Discourse.DropdownButtonView = Discourse.View.extend({ buffer.push(""); buffer.push("