Calls to Discourse.ajax no longer need `getURL` -- will be done automatically.

This commit is contained in:
Robin Ward 2013-05-07 13:30:12 -04:00
parent 0b4fc5d81c
commit bd99d5a40c
54 changed files with 202 additions and 248 deletions

View File

@ -26,7 +26,7 @@ Discourse.AdminEmailLogsController = Ember.ArrayController.extend(Discourse.Pres
this.set('sentTestEmail', false); this.set('sentTestEmail', false);
var adminEmailLogsController = this; var adminEmailLogsController = this;
Discourse.ajax(Discourse.getURL("/admin/email_logs/test"), { Discourse.ajax("/admin/email_logs/test", {
type: 'POST', type: 'POST',
data: { email_address: this.get('testEmailAddress') } data: { email_address: this.get('testEmailAddress') }
}).then(function () { }).then(function () {

View File

@ -1,12 +0,0 @@
/**
Return the url to a user's admin page given the username.
For example:
<a href="{{unbound adminUserPath username}}">{{unbound username}}</a>
@method adminUserPath
@for Handlebars
**/
Handlebars.registerHelper('adminUserPath', function(username) {
return Discourse.getURL("/admin/users/") + Ember.Handlebars.get(this, username);
});

View File

@ -8,7 +8,7 @@ Discourse.AdminApi = Discourse.Model.extend({
generateKey: function(){ generateKey: function(){
var adminApi = this; var adminApi = this;
Discourse.ajax(Discourse.getURL('/admin/api/generate_key'),{type: 'POST'}).then(function (result) { Discourse.ajax('/admin/api/generate_key', {type: 'POST'}).then(function (result) {
adminApi.set('key', result.key); adminApi.set('key', result.key);
}); });
}, },
@ -20,6 +20,8 @@ Discourse.AdminApi = Discourse.Model.extend({
Discourse.AdminApi.reopenClass({ Discourse.AdminApi.reopenClass({
find: function() { find: function() {
return this.getModelAjax(Discourse.getURL('/admin/api')); return Discourse.ajax("/admin/api").then(function(data) {
return Discourse.AdminApi.create(data);
});
} }
}); });

View File

@ -19,7 +19,7 @@ Discourse.AdminDashboard.reopenClass({
@return {jqXHR} a jQuery Promise object @return {jqXHR} a jQuery Promise object
**/ **/
find: function() { find: function() {
return Discourse.ajax(Discourse.getURL("/admin/dashboard")).then(function(json) { return Discourse.ajax("/admin/dashboard").then(function(json) {
var model = Discourse.AdminDashboard.create(json); var model = Discourse.AdminDashboard.create(json);
model.set('loaded', true); model.set('loaded', true);
return model; return model;
@ -34,7 +34,7 @@ Discourse.AdminDashboard.reopenClass({
@return {jqXHR} a jQuery Promise object @return {jqXHR} a jQuery Promise object
**/ **/
fetchProblems: function() { fetchProblems: function() {
return Discourse.ajax(Discourse.getURL("/admin/dashboard/problems"), { return Discourse.ajax("/admin/dashboard/problems", {
type: 'GET', type: 'GET',
dataType: 'json' dataType: 'json'
}).then(function(json) { }).then(function(json) {

View File

@ -6,20 +6,12 @@
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.AdminUser = Discourse.Model.extend({ Discourse.AdminUser = Discourse.User.extend({
path: (function() {
return Discourse.getURL("/users/") + (this.get('username_lower'));
}).property('username'),
adminPath: (function() {
return Discourse.getURL("/admin/users/") + (this.get('username_lower'));
}).property('username'),
deleteAllPosts: function() { deleteAllPosts: function() {
var user = this; var user = this;
this.set('can_delete_all_posts', false); this.set('can_delete_all_posts', false);
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/delete_all_posts", {type: 'PUT'}).then(function(result){ Discourse.ajax("/admin/users/" + (this.get('id')) + "/delete_all_posts", {type: 'PUT'}).then(function(result){
user.set('post_count', 0); user.set('post_count', 0);
}); });
}, },
@ -29,14 +21,14 @@ Discourse.AdminUser = Discourse.Model.extend({
this.set('admin', false); this.set('admin', false);
this.set('can_grant_admin', true); this.set('can_grant_admin', true);
this.set('can_revoke_admin', false); this.set('can_revoke_admin', false);
return Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/revoke_admin", {type: 'PUT'}); return Discourse.ajax("/admin/users/" + (this.get('id')) + "/revoke_admin", {type: 'PUT'});
}, },
grantAdmin: function() { grantAdmin: function() {
this.set('admin', true); this.set('admin', true);
this.set('can_grant_admin', false); this.set('can_grant_admin', false);
this.set('can_revoke_admin', true); this.set('can_revoke_admin', true);
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/grant_admin", {type: 'PUT'}); Discourse.ajax("/admin/users/" + (this.get('id')) + "/grant_admin", {type: 'PUT'});
}, },
// Revoke the user's moderation access // Revoke the user's moderation access
@ -44,18 +36,18 @@ Discourse.AdminUser = Discourse.Model.extend({
this.set('moderator', false); this.set('moderator', false);
this.set('can_grant_moderation', true); this.set('can_grant_moderation', true);
this.set('can_revoke_moderation', false); this.set('can_revoke_moderation', false);
return Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/revoke_moderation", {type: 'PUT'}); return Discourse.ajax("/admin/users/" + (this.get('id')) + "/revoke_moderation", {type: 'PUT'});
}, },
grantModeration: function() { grantModeration: function() {
this.set('moderator', true); this.set('moderator', true);
this.set('can_grant_moderation', false); this.set('can_grant_moderation', false);
this.set('can_revoke_moderation', true); this.set('can_revoke_moderation', true);
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/grant_moderation", {type: 'PUT'}); Discourse.ajax("/admin/users/" + (this.get('id')) + "/grant_moderation", {type: 'PUT'});
}, },
refreshBrowsers: function() { refreshBrowsers: function() {
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/refresh_browsers", {type: 'POST'}); Discourse.ajax("/admin/users/" + (this.get('id')) + "/refresh_browsers", {type: 'POST'});
bootbox.alert("Message sent to all clients!"); bootbox.alert("Message sent to all clients!");
}, },
@ -63,7 +55,7 @@ Discourse.AdminUser = Discourse.Model.extend({
this.set('can_approve', false); this.set('can_approve', false);
this.set('approved', true); this.set('approved', true);
this.set('approved_by', Discourse.get('currentUser')); this.set('approved_by', Discourse.get('currentUser'));
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/approve", {type: 'PUT'}); Discourse.ajax("/admin/users/" + (this.get('id')) + "/approve", {type: 'PUT'});
}, },
username_lower: (function() { username_lower: (function() {
@ -91,7 +83,7 @@ Discourse.AdminUser = Discourse.Model.extend({
ban: function() { ban: function() {
var duration = parseInt(window.prompt(Em.String.i18n('admin.user.ban_duration')), 10); var duration = parseInt(window.prompt(Em.String.i18n('admin.user.ban_duration')), 10);
if (duration > 0) { if (duration > 0) {
Discourse.ajax(Discourse.getURL("/admin/users/") + this.id + "/ban", { Discourse.ajax("/admin/users/" + this.id + "/ban", {
type: 'PUT', type: 'PUT',
data: {duration: duration} data: {duration: duration}
}).then(function () { }).then(function () {
@ -106,7 +98,7 @@ Discourse.AdminUser = Discourse.Model.extend({
}, },
unban: function() { unban: function() {
Discourse.ajax(Discourse.getURL("/admin/users/") + this.id + "/unban", { Discourse.ajax("/admin/users/" + this.id + "/unban", {
type: 'PUT' type: 'PUT'
}).then(function() { }).then(function() {
// succeeded // succeeded
@ -119,7 +111,7 @@ Discourse.AdminUser = Discourse.Model.extend({
}, },
impersonate: function() { impersonate: function() {
Discourse.ajax(Discourse.getURL("/admin/impersonate"), { Discourse.ajax("/admin/impersonate", {
type: 'POST', type: 'POST',
data: { username_or_email: this.get('username') } data: { username_or_email: this.get('username') }
}).then(function() { }).then(function() {
@ -151,7 +143,7 @@ Discourse.AdminUser = Discourse.Model.extend({
var user = this; var user = this;
bootbox.confirm(Em.String.i18n("admin.user.delete_confirm"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) { bootbox.confirm(Em.String.i18n("admin.user.delete_confirm"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) {
if(result) { if(result) {
Discourse.ajax(Discourse.getURL("/admin/users/") + user.get('id') + '.json', { type: 'DELETE' }).then(function(data) { Discourse.ajax("/admin/users/" + user.get('id') + '.json', { type: 'DELETE' }).then(function(data) {
if (data.deleted) { if (data.deleted) {
bootbox.alert(Em.String.i18n("admin.user.deleted"), function() { bootbox.alert(Em.String.i18n("admin.user.deleted"), function() {
document.location = "/admin/users/list/active"; document.location = "/admin/users/list/active";
@ -180,7 +172,7 @@ Discourse.AdminUser.reopenClass({
user.set('can_approve', false); user.set('can_approve', false);
return user.set('selected', false); return user.set('selected', false);
}); });
return Discourse.ajax(Discourse.getURL("/admin/users/approve-bulk"), { return Discourse.ajax("/admin/users/approve-bulk", {
type: 'PUT', type: 'PUT',
data: { data: {
users: users.map(function(u) { users: users.map(function(u) {
@ -191,13 +183,13 @@ Discourse.AdminUser.reopenClass({
}, },
find: function(username) { find: function(username) {
return Discourse.ajax(Discourse.getURL("/admin/users/") + username).then(function (result) { return Discourse.ajax("/admin/users/" + username).then(function (result) {
return Discourse.AdminUser.create(result); return Discourse.AdminUser.create(result);
}); });
}, },
findAll: function(query, filter) { findAll: function(query, filter) {
return Discourse.ajax(Discourse.getURL("/admin/users/list/") + query + ".json", { return Discourse.ajax("/admin/users/list/" + query + ".json", {
data: { filter: filter } data: { filter: filter }
}).then(function(users) { }).then(function(users) {
return users.map(function(u) { return users.map(function(u) {

View File

@ -18,7 +18,7 @@ Discourse.EmailLog.reopenClass({
findAll: function(filter) { findAll: function(filter) {
var result = Em.A(); var result = Em.A();
Discourse.ajax(Discourse.getURL("/admin/email_logs.json"), { Discourse.ajax("/admin/email_logs.json", {
data: { filter: filter } data: { filter: filter }
}).then(function(logs) { }).then(function(logs) {
logs.each(function(log) { logs.each(function(log) {

View File

@ -47,14 +47,14 @@ Discourse.FlaggedPost = Discourse.Post.extend({
deletePost: function() { deletePost: function() {
if (this.get('post_number') === "1") { if (this.get('post_number') === "1") {
return Discourse.ajax(Discourse.getURL("/t/") + this.topic_id, { type: 'DELETE', cache: false }); return Discourse.ajax("/t/" + this.topic_id, { type: 'DELETE', cache: false });
} else { } else {
return Discourse.ajax(Discourse.getURL("/posts/") + this.id, { type: 'DELETE', cache: false }); return Discourse.ajax("/posts/" + this.id, { type: 'DELETE', cache: false });
} }
}, },
clearFlags: function() { clearFlags: function() {
return Discourse.ajax(Discourse.getURL("/admin/flags/clear/") + this.id, { type: 'POST', cache: false }); return Discourse.ajax("/admin/flags/clear/" + this.id, { type: 'POST', cache: false });
}, },
hiddenClass: function() { hiddenClass: function() {
@ -65,7 +65,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({
Discourse.FlaggedPost.reopenClass({ Discourse.FlaggedPost.reopenClass({
findAll: function(filter) { findAll: function(filter) {
var result = Em.A(); var result = Em.A();
Discourse.ajax(Discourse.getURL("/admin/flags/") + filter + ".json").then(function(data) { Discourse.ajax("/admin/flags/" + filter + ".json").then(function(data) {
var userLookup = {}; var userLookup = {};
data.users.each(function(u) { data.users.each(function(u) {
userLookup[u.id] = Discourse.User.create(u); userLookup[u.id] = Discourse.User.create(u);

View File

@ -138,7 +138,7 @@ Discourse.Report = Discourse.Model.extend({
Discourse.Report.reopenClass({ Discourse.Report.reopenClass({
find: function(type) { find: function(type) {
var model = Discourse.Report.create({type: type}); var model = Discourse.Report.create({type: type});
Discourse.ajax(Discourse.getURL("/admin/reports/") + type).then(function (json) { Discourse.ajax("/admin/reports/" + type).then(function (json) {
// Add a percent field to each tuple // Add a percent field to each tuple
var maxY = 0; var maxY = 0;
json.report.data.forEach(function (row) { json.report.data.forEach(function (row) {

View File

@ -20,7 +20,7 @@ Discourse.SiteContent = Discourse.Model.extend({
@return {jqXHR} a jQuery Promise object @return {jqXHR} a jQuery Promise object
**/ **/
save: function() { save: function() {
return Discourse.ajax(Discourse.getURL("/admin/site_contents/" + this.get('content_type')), { return Discourse.ajax("/admin/site_contents/" + this.get('content_type'), {
type: 'PUT', type: 'PUT',
data: {content: this.get('content')} data: {content: this.get('content')}
}); });
@ -31,7 +31,7 @@ Discourse.SiteContent = Discourse.Model.extend({
Discourse.SiteContent.reopenClass({ Discourse.SiteContent.reopenClass({
find: function(type) { find: function(type) {
return Discourse.ajax(Discourse.getURL("/admin/site_contents/" + type)).then(function (data) { return Discourse.ajax("/admin/site_contents/" + type).then(function (data) {
return Discourse.SiteContent.create(data.site_content); return Discourse.SiteContent.create(data.site_content);
}); });
} }

View File

@ -11,7 +11,7 @@ Discourse.SiteContentType = Discourse.Model.extend({});
Discourse.SiteContentType.reopenClass({ Discourse.SiteContentType.reopenClass({
findAll: function() { findAll: function() {
var contentTypes = Em.A(); var contentTypes = Em.A();
Discourse.ajax(Discourse.getURL("/admin/site_content_types")).then(function(data) { Discourse.ajax("/admin/site_content_types").then(function(data) {
data.forEach(function (ct) { data.forEach(function (ct) {
contentTypes.pushObject(Discourse.SiteContentType.create(ct)); contentTypes.pushObject(Discourse.SiteContentType.create(ct));
}); });

View File

@ -66,7 +66,7 @@ Discourse.SiteCustomization = Discourse.Model.extend({
}; };
var siteCustomization = this; var siteCustomization = this;
return Discourse.ajax(Discourse.getURL("/admin/site_customizations") + (this.id ? '/' + this.id : ''), { return Discourse.ajax("/admin/site_customizations" + (this.id ? '/' + this.id : ''), {
data: { site_customization: data }, data: { site_customization: data },
type: this.id ? 'PUT' : 'POST' type: this.id ? 'PUT' : 'POST'
}).then(function (result) { }).then(function (result) {
@ -80,7 +80,7 @@ Discourse.SiteCustomization = Discourse.Model.extend({
destroy: function() { destroy: function() {
if(!this.id) return; if(!this.id) return;
return Discourse.ajax(Discourse.getURL("/admin/site_customizations/") + this.id, { return Discourse.ajax("/admin/site_customizations/" + this.id, {
type: 'DELETE' type: 'DELETE'
}); });
} }
@ -99,7 +99,7 @@ var SiteCustomizations = Ember.ArrayProxy.extend({
Discourse.SiteCustomization.reopenClass({ Discourse.SiteCustomization.reopenClass({
findAll: function() { findAll: function() {
var customizations = SiteCustomizations.create({ content: [], loading: true }); var customizations = SiteCustomizations.create({ content: [], loading: true });
Discourse.ajax(Discourse.getURL("/admin/site_customizations")).then(function (data) { Discourse.ajax("/admin/site_customizations").then(function (data) {
if (data) { if (data) {
data.site_customizations.each(function(c) { data.site_customizations.each(function(c) {
customizations.pushObject(Discourse.SiteCustomization.create(c.site_customizations)); customizations.pushObject(Discourse.SiteCustomization.create(c.site_customizations));

View File

@ -72,7 +72,7 @@ Discourse.SiteSetting = Discourse.Model.extend({
save: function() { save: function() {
// Update the setting // Update the setting
var setting = this; var setting = this;
return Discourse.ajax(Discourse.getURL("/admin/site_settings/") + (this.get('setting')), { return Discourse.ajax("/admin/site_settings/" + (this.get('setting')), {
data: { value: this.get('value') }, data: { value: this.get('value') },
type: 'PUT' type: 'PUT'
}).then(function() { }).then(function() {
@ -90,7 +90,7 @@ Discourse.SiteSetting.reopenClass({
**/ **/
findAll: function() { findAll: function() {
var result = Em.A(); var result = Em.A();
Discourse.ajax(Discourse.getURL("/admin/site_settings")).then(function (settings) { Discourse.ajax("/admin/site_settings").then(function (settings) {
settings.site_settings.each(function(s) { settings.site_settings.each(function(s) {
s.originalValue = s.value; s.originalValue = s.value;
result.pushObject(Discourse.SiteSetting.create(s)); result.pushObject(Discourse.SiteSetting.create(s));
@ -101,7 +101,7 @@ Discourse.SiteSetting.reopenClass({
}, },
update: function(key, value) { update: function(key, value) {
return Discourse.ajax(Discourse.getURL("/admin/site_settings/") + key, { return Discourse.ajax("/admin/site_settings/" + key, {
type: 'PUT', type: 'PUT',
data: { value: value } data: { value: value }
}); });

View File

@ -26,7 +26,7 @@ Discourse.VersionCheck = Discourse.Model.extend({
Discourse.VersionCheck.reopenClass({ Discourse.VersionCheck.reopenClass({
find: function() { find: function() {
return Discourse.ajax(Discourse.getURL('/admin/version_check')).then(function(json) { return Discourse.ajax('/admin/version_check').then(function(json) {
return Discourse.VersionCheck.create(json); return Discourse.VersionCheck.create(json);
}); });
} }

View File

@ -1,7 +1,7 @@
/** /**
Handles routes related to users in the admin section. Handles routes related to users in the admin section.
@class AdminUserRoute @class AdminUserRoute
@extends Discourse.Route @extends Discourse.Route
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
@ -11,6 +11,10 @@ Discourse.AdminUserRoute = Discourse.Route.extend({
return Discourse.AdminUser.find(params.username); return Discourse.AdminUser.find(params.username);
}, },
serialize: function(params) {
return { username: Em.get(params, 'username').toLowerCase() };
},
renderTemplate: function() { renderTemplate: function() {
this.render('admin/templates/user', {into: 'admin/templates/admin'}); this.render('admin/templates/user', {into: 'admin/templates/admin'});
} }

View File

@ -230,7 +230,7 @@
{{#each top_referrers.data}} {{#each top_referrers.data}}
<tbody> <tbody>
<tr> <tr>
<td class="title"><a href="{{unbound adminUserPath username}}">{{unbound username}}</a></td> <td class="title">{{#linkTo 'adminUser' this}}{{unbound username}}{{/linkTo}}</td>
<td class="value">{{num_clicks}}</td> <td class="value">{{num_clicks}}</td>
<td class="value">{{num_topics}}</td> <td class="value">{{num_topics}}</td>
</tr> </tr>

View File

@ -22,8 +22,8 @@
<td>{{date view.content.created_at}}</td> <td>{{date view.content.created_at}}</td>
<td> <td>
{{#if view.content.user}} {{#if view.content.user}}
<a href="{{unbound view.content.user.adminPath}}">{{avatar view.content.user imageSize="tiny"}}</a> {{#linkTo 'adminUser' view.content.user}}{{avatar view.content.user imageSize="tiny"}}{{/linkTo}}
<a href="{{unbound view.content.user.adminPath}}">{{view.content.user.username}}</a> {{#linkTo 'adminUser' view.content.user}}{{view.content.user.username}}{{/linkTo}}
{{else}} {{else}}
&mdash; &mdash;
{{/if}} {{/if}}

View File

@ -4,7 +4,7 @@
<li>{{#linkTo adminFlags.active}}{{i18n admin.flags.active}}{{/linkTo}}</li> <li>{{#linkTo adminFlags.active}}{{i18n admin.flags.active}}{{/linkTo}}</li>
<li>{{#linkTo adminFlags.old}}{{i18n admin.flags.old}}{{/linkTo}}</li> <li>{{#linkTo adminFlags.old}}{{i18n admin.flags.old}}{{/linkTo}}</li>
</ul> </ul>
</div> </div>
</div> </div>
@ -21,12 +21,12 @@
<tbody> <tbody>
{{#each content}} {{#each content}}
<tr {{bindAttr class="hiddenClass"}}> <tr {{bindAttr class="hiddenClass"}}>
<td class='user'><a href="/admin{{unbound user.path}}">{{avatar user imageSize="small"}}</a></td> <td class='user'>{{#linkTo 'adminUser' user}}{{avatar user imageSize="small"}}{{/linkTo}}</td>
<td class='excerpt'>{{#if topicHidden}}<i title='{{i18n topic_statuses.invisible.help}}' class='icon icon-eye-close'></i> {{/if}}<h3><a href='{{unbound url}}'>{{title}}</a></h3><br>{{{excerpt}}} <td class='excerpt'>{{#if topicHidden}}<i title='{{i18n topic_statuses.invisible.help}}' class='icon icon-eye-close'></i> {{/if}}<h3><a href='{{unbound url}}'>{{title}}</a></h3><br>{{{excerpt}}}
</td> </td>
<td class='flaggers'>{{#each flaggers}}<a href="/admin{{unbound path}}">{{avatar this imageSize="small"}}</a>{{/each}}</td> <td class='flaggers'>{{#each flaggers}}{{#linkTo 'adminUser' this}}{{avatar this imageSize="small"}} {{/linkTo}}{{/each}}</td>
<td class='last-flagged'>{{date lastFlagged}}</td> <td class='last-flagged'>{{date lastFlagged}}</td>
<td class='action'> <td class='action'>
{{#if controller.adminActiveFlagsView}} {{#if controller.adminActiveFlagsView}}
<button title='{{i18n admin.flags.clear_title}}' class='btn' {{action clearFlags this}}>{{i18n admin.flags.clear}}</button> <button title='{{i18n admin.flags.clear_title}}' class='btn' {{action clearFlags this}}>{{i18n admin.flags.clear}}</button>
<button title='{{i18n admin.flags.delete_title}}' class='btn' {{action deletePost this}}>{{i18n admin.flags.delete}}</button> <button title='{{i18n admin.flags.delete_title}}' class='btn' {{action deletePost this}}>{{i18n admin.flags.delete}}</button>
@ -38,7 +38,7 @@
<tr> <tr>
<td></td> <td></td>
<td class='message'> <td class='message'>
<div><a href="/admin{{unbound user.path}}">{{avatar user imageSize="small"}}</a> {{message}}</div> <div>{{#linkTo 'adminUser' user}}{{avatar user imageSize="small"}}{{/linkTo}} {{message}}</div>
</td> </td>
<td></td> <td></td>
<td></td> <td></td>

View File

@ -4,10 +4,10 @@
<div class='field'>{{i18n user.username.title}}</div> <div class='field'>{{i18n user.username.title}}</div>
<div class='value'>{{content.username}}</div> <div class='value'>{{content.username}}</div>
<div class='controls'> <div class='controls'>
<a href="{{unbound content.path}}" class='btn'> {{#linkTo 'user.activity' content class="btn"}}
<i class='icon icon-user'></i> <i class='icon icon-user'></i>
{{i18n admin.user.show_public_profile}} {{i18n admin.user.show_public_profile}}
</a> {{/linkTo}}
{{#if content.can_impersonate}} {{#if content.can_impersonate}}
<button class='btn' {{action impersonate target="content"}}> <button class='btn' {{action impersonate target="content"}}>
<i class='icon icon-screenshot'></i> <i class='icon icon-screenshot'></i>
@ -50,8 +50,9 @@
<div class='value'> <div class='value'>
{{#if content.approved}} {{#if content.approved}}
{{i18n admin.user.approved_by}} {{i18n admin.user.approved_by}}
<a href="{{unbound content.approved_by.adminPath}}">{{avatar approved_by imageSize="small"}}</a>
<a href="{{unbound adminPath}}">{{content.approved_by.username}}</a> {{#linkTo 'adminUser' content.approved_by}}{{avatar approved_by imageSize="small"}}{{/linkTo}}
{{#linkTo 'adminUser' content.approved_by}}{{content.approved_by.username}}{{/linkTo}}
{{else}} {{else}}
{{i18n no_value}} {{i18n no_value}}
{{/if}} {{/if}}

View File

@ -56,10 +56,8 @@
{{/if}} {{/if}}
</td> </td>
{{/if}} {{/if}}
<td> <td>{{#linkTo 'adminUser' this}}{{avatar this imageSize="small"}}{{/linkTo}}</td>
<a href="{{unbound adminPath}}">{{avatar this imageSize="small"}}</a> <td>{{#linkTo 'adminUser' this}}{{unbound username}}{{/linkTo}}</td>
</td>
<td><a href="{{unbound adminPath}}">{{unbound username}}</a></td>
<td>{{shorten email}}</td> <td>{{shorten email}}</td>
<td>{{{unbound last_emailed_age}}}</td> <td>{{{unbound last_emailed_age}}}</td>
<td>{{{unbound last_seen_age}}}</td> <td>{{{unbound last_seen_age}}}</td>

View File

@ -23,6 +23,10 @@ Discourse = Ember.Application.createWithMixins({
highestSeenByTopic: {}, highestSeenByTopic: {},
getURL: function(url) { getURL: function(url) {
// If it's a non relative URL, return it.
if (url.indexOf('http') === 0) return url;
var u = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri); var u = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
if (u[u.length-1] === '/') { if (u[u.length-1] === '/') {
u = u.substring(0, u.length-1); u = u.substring(0, u.length-1);
@ -173,7 +177,7 @@ Discourse = Ember.Application.createWithMixins({
**/ **/
logout: function() { logout: function() {
Discourse.KeyValueStore.abandonLocal(); Discourse.KeyValueStore.abandonLocal();
Discourse.ajax(Discourse.getURL("/session/") + this.get('currentUser.username'), { Discourse.ajax("/session/" + this.get('currentUser.username'), {
type: 'DELETE' type: 'DELETE'
}).then(function() { }).then(function() {
// Reloading will refresh unbound properties // Reloading will refresh unbound properties
@ -189,7 +193,8 @@ Discourse = Ember.Application.createWithMixins({
/** /**
Our own $.ajax method. Makes sure the .then method executes in an Ember runloop Our own $.ajax method. Makes sure the .then method executes in an Ember runloop
for performance reasons. for performance reasons. Also automatically adjusts the URL to support installs
in subfolders.
@method ajax @method ajax
**/ **/
@ -211,13 +216,27 @@ Discourse = Ember.Application.createWithMixins({
} }
if (args.success) { if (args.success) {
console.log("DEPRECATION: Discourse.ajax should use promises, received 'success' callback"); console.warning("DEPRECATION: Discourse.ajax should use promises, received 'success' callback");
} }
if (args.error) { if (args.error) {
console.log("DEPRECATION: Discourse.ajax should use promises, received 'error' callback"); console.warning("DEPRECATION: Discourse.ajax should use promises, received 'error' callback");
} }
return $.ajax(url, args); return Ember.Deferred.promise(function (promise) {
var oldSuccess = args.success;
args.success = function(xhr) {
Ember.run(promise, promise.resolve, xhr);
if (oldSuccess) oldSuccess(xhr);
}
var oldError = args.error;
args.error = function(xhr) {
promise.reject(xhr);
if (oldError) oldError(xhr);
}
$.ajax(Discourse.getURL(url), args);
});
}, },
/** /**

View File

@ -72,7 +72,7 @@ Discourse.ClickTrack = {
// if they want to open in a new tab, do an AJAX request // if they want to open in a new tab, do an AJAX request
if (e.shiftKey || e.metaKey || e.ctrlKey || e.which === 2) { if (e.shiftKey || e.metaKey || e.ctrlKey || e.which === 2) {
Discourse.ajax(Discourse.getURL("/clicks/track"), { Discourse.ajax("/clicks/track", {
data: { data: {
url: href, url: href,
post_id: postId, post_id: postId,
@ -86,7 +86,7 @@ Discourse.ClickTrack = {
// If we're on the same site, use the router and track via AJAX // If we're on the same site, use the router and track via AJAX
if (href.indexOf(Discourse.URL.origin()) === 0) { if (href.indexOf(Discourse.URL.origin()) === 0) {
Discourse.ajax(Discourse.getURL("/clicks/track"), { Discourse.ajax("/clicks/track", {
data: { data: {
url: href, url: href,
post_id: postId, post_id: postId,

View File

@ -22,7 +22,7 @@ Discourse.Mention = (function() {
callback(cached); callback(cached);
return false; return false;
} else { } else {
Discourse.ajax(Discourse.getURL("/users/is_local_username"), { data: { username: name } }).then(function(r) { Discourse.ajax("/users/is_local_username", { data: { username: name } }).then(function(r) {
cache(name, r.valid); cache(name, r.valid);
callback(r.valid); callback(r.valid);
}); });

View File

@ -49,9 +49,7 @@ Discourse.Onebox = {
$elem.addClass('loading-onebox'); $elem.addClass('loading-onebox');
// Retrieve the onebox // Retrieve the onebox
var promise = Discourse.ajax(Discourse.getURL("/onebox"), { var promise = Discourse.ajax("/onebox", { data: { url: url, refresh: refresh } });
data: { url: url, refresh: refresh }
});
// We can call this when loading is complete // We can call this when loading is complete
var loadingFinished = function() { var loadingFinished = function() {

View File

@ -98,7 +98,7 @@ Discourse.ScreenTrack = Ember.Object.extend({
highestSeenByTopic[topicId] = highestSeen; highestSeenByTopic[topicId] = highestSeen;
} }
if (!Object.isEmpty(newTimings)) { if (!Object.isEmpty(newTimings)) {
Discourse.ajax(Discourse.getURL('/topics/timings'), { Discourse.ajax('/topics/timings', {
data: { data: {
timings: newTimings, timings: newTimings,
topic_time: this.topicTime, topic_time: this.topicTime,

View File

@ -128,7 +128,7 @@ Discourse.URL = {
@method redirectTo @method redirectTo
**/ **/
redirectTo: function(url) { redirectTo: function(url) {
window.location = url; window.location = Discourse.getURL(url);
} }
}; };

View File

@ -10,7 +10,7 @@ var cacheTopicId = null;
var cacheTime = null; var cacheTime = null;
var debouncedSearch = Discourse.debouncePromise(function(term, topicId) { var debouncedSearch = Discourse.debouncePromise(function(term, topicId) {
return Discourse.ajax(Discourse.getURL('/users/search/users'), { return Discourse.ajax('/users/search/users', {
data: { data: {
term: term, term: term,
topic_id: topicId topic_id: topicId

View File

@ -44,15 +44,10 @@ Discourse.Utilities = {
}, },
avatarUrl: function(username, size, template) { avatarUrl: function(username, size, template) {
var rawSize; if (!username) return "";
if (!username) {
return "";
}
size = Discourse.Utilities.translateSize(size); size = Discourse.Utilities.translateSize(size);
rawSize = (size * (window.devicePixelRatio || 1)).toFixed(); var rawSize = (size * (window.devicePixelRatio || 1)).toFixed();
if (template) { if (template) return template.replace(/\{size\}/g, rawSize);
return template.replace(/\{size\}/g, rawSize);
}
return Discourse.getURL("/users/") + (username.toLowerCase()) + "/avatar/" + rawSize + "?__ws=" + (encodeURIComponent(Discourse.BaseUrl || "")); return Discourse.getURL("/users/") + (username.toLowerCase()) + "/avatar/" + rawSize + "?__ws=" + (encodeURIComponent(Discourse.BaseUrl || ""));
}, },
@ -71,8 +66,7 @@ Discourse.Utilities = {
}, },
postUrl: function(slug, topicId, postNumber) { postUrl: function(slug, topicId, postNumber) {
var url; var url = Discourse.getURL("/t/");
url = Discourse.getURL("/t/");
if (slug) { if (slug) {
url += slug + "/"; url += slug + "/";
} else { } else {

View File

@ -132,7 +132,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
// If visible update the text // If visible update the text
var educationKey = this.get('content.creatingTopic') ? 'new-topic' : 'new-reply'; var educationKey = this.get('content.creatingTopic') ? 'new-topic' : 'new-reply';
var composerController = this; var composerController = this;
Discourse.ajax(Discourse.getURL("/education/") + educationKey).then(function(result) { Discourse.ajax("/education/" + educationKey).then(function(result) {
composerController.set('educationContents', result); composerController.set('educationContents', result);
}); });
}.observes('typedReply', 'content.creatingTopic', 'Discourse.currentUser.reply_count'), }.observes('typedReply', 'content.creatingTopic', 'Discourse.currentUser.reply_count'),

View File

@ -29,16 +29,16 @@ Discourse.PreferencesUsernameController = Discourse.ObjectController.extend({
if( this.get('newUsername') && this.get('newUsername').length < 3 ) { if( this.get('newUsername') && this.get('newUsername').length < 3 ) {
this.set('errorMessage', Em.String.i18n('user.name.too_short')); this.set('errorMessage', Em.String.i18n('user.name.too_short'));
} else { } else {
var _this = this; var preferencesUsernameController = this;
this.set('taken', false); this.set('taken', false);
this.set('errorMessage', null); this.set('errorMessage', null);
if (this.blank('newUsername')) return; if (this.blank('newUsername')) return;
if (this.get('unchanged')) return; if (this.get('unchanged')) return;
Discourse.User.checkUsername(this.get('newUsername')).then(function(result) { Discourse.User.checkUsername(this.get('newUsername')).then(function(result) {
if (result.errors) { if (result.errors) {
return _this.set('errorMessage', result.errors.join(' ')); preferencesUsernameController.set('errorMessage', result.errors.join(' '));
} else if (result.available === false) { } else if (result.available === false) {
return _this.set('taken', true); preferencesUsernameController.set('taken', true);
} }
}); });
} }
@ -50,17 +50,16 @@ Discourse.PreferencesUsernameController = Discourse.ObjectController.extend({
}).property('saving'), }).property('saving'),
changeUsername: function() { changeUsername: function() {
var _this = this; var preferencesUsernameController = this;
return bootbox.confirm(Em.String.i18n("user.change_username.confirm"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) { return bootbox.confirm(Em.String.i18n("user.change_username.confirm"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(result) {
if (result) { if (result) {
_this.set('saving', true); preferencesUsernameController.set('saving', true);
return _this.get('content').changeUsername(_this.get('newUsername')).then(function() { preferencesUsernameController.get('content').changeUsername(preferencesUsernameController.get('newUsername')).then(function() {
var url = Discourse.getURL("/users/") + _this.get('newUsername').toLowerCase() + "/preferences"; Discourse.URL.redirectTo("/users/" + preferencesUsernameController.get('newUsername').toLowerCase() + "/preferences");
Discourse.URL.redirectTo(url);
}, function() { }, function() {
// error // error
_this.set('error', true); preferencesUsernameController.set('error', true);
_this.set('saving', false); preferencesUsernameController.set('saving', false);
}); });
} }
}); });

View File

@ -20,7 +20,7 @@ Discourse.StaticController = Discourse.Controller.extend({
text = text[1]; text = text[1];
this.set('content', text); this.set('content', text);
} else { } else {
return Discourse.ajax(Discourse.getURL(path + ".json")).then(function (result) { return Discourse.ajax(path + ".json").then(function (result) {
staticController.set('content', result); staticController.set('content', result);
}); });
} }

View File

@ -58,7 +58,7 @@ Discourse.ActionSummary = Discourse.Model.extend({
// Create our post action // Create our post action
var actionSummary = this; var actionSummary = this;
return Discourse.ajax(Discourse.getURL("/post_actions"), { return Discourse.ajax("/post_actions", {
type: 'POST', type: 'POST',
data: { data: {
id: this.get('post.id'), id: this.get('post.id'),
@ -77,7 +77,7 @@ Discourse.ActionSummary = Discourse.Model.extend({
this.removeAction(); this.removeAction();
// Remove our post action // Remove our post action
return Discourse.ajax(Discourse.getURL("/post_actions/") + (this.get('post.id')), { return Discourse.ajax("/post_actions/" + (this.get('post.id')), {
type: 'DELETE', type: 'DELETE',
data: { data: {
post_action_type_id: this.get('id') post_action_type_id: this.get('id')
@ -87,7 +87,7 @@ Discourse.ActionSummary = Discourse.Model.extend({
clearFlags: function() { clearFlags: function() {
var actionSummary = this; var actionSummary = this;
return Discourse.ajax(Discourse.getURL("/post_actions/clear_flags"), { return Discourse.ajax("/post_actions/clear_flags", {
type: "POST", type: "POST",
data: { data: {
post_action_type_id: this.get('id'), post_action_type_id: this.get('id'),
@ -101,7 +101,7 @@ Discourse.ActionSummary = Discourse.Model.extend({
loadUsers: function() { loadUsers: function() {
var actionSummary = this; var actionSummary = this;
Discourse.ajax(Discourse.getURL("/post_actions/users"), { Discourse.ajax("/post_actions/users", {
data: { data: {
id: this.get('post.id'), id: this.get('post.id'),
post_action_type_id: this.get('id') post_action_type_id: this.get('id')

View File

@ -30,9 +30,9 @@ Discourse.Category = Discourse.Model.extend({
}.property('topic_count'), }.property('topic_count'),
save: function(args) { save: function(args) {
var url = Discourse.getURL("/categories"); var url = "/categories";
if (this.get('id')) { if (this.get('id')) {
url = Discourse.getURL("/categories/") + (this.get('id')); url = "/categories/" + (this.get('id'));
} }
return Discourse.ajax(url, { return Discourse.ajax(url, {
@ -47,14 +47,14 @@ Discourse.Category = Discourse.Model.extend({
}, },
destroy: function(callback) { destroy: function(callback) {
return Discourse.ajax(Discourse.getURL("/categories/") + (this.get('slug') || this.get('id')), { type: 'DELETE' }); return Discourse.ajax("/categories/" + (this.get('slug') || this.get('id')), { type: 'DELETE' });
} }
}); });
Discourse.Category.reopenClass({ Discourse.Category.reopenClass({
findBySlugOrId: function(slugOrId) { findBySlugOrId: function(slugOrId) {
return Discourse.ajax(Discourse.getURL("/categories/") + slugOrId + ".json").then(function (result) { return Discourse.ajax("/categories/" + slugOrId + ".json").then(function (result) {
return Discourse.Category.create(result.category); return Discourse.Category.create(result.category);
}); });
} }

View File

@ -33,7 +33,7 @@ Discourse.CategoryList.reopenClass({
list: function(filter) { list: function(filter) {
var route = this; var route = this;
return Discourse.ajax(Discourse.getURL("/") + filter + ".json").then(function(result) { return Discourse.ajax("/" + filter + ".json").then(function(result) {
var categoryList = Discourse.TopicList.create(); var categoryList = Discourse.TopicList.create();
categoryList.set('can_create_category', result.category_list.can_create_category); categoryList.set('can_create_category', result.category_list.can_create_category);
categoryList.set('categories', route.categoriesFrom(result)); categoryList.set('categories', route.categoriesFrom(result));

View File

@ -11,7 +11,7 @@ Discourse.Draft = Discourse.Model.extend({});
Discourse.Draft.reopenClass({ Discourse.Draft.reopenClass({
clear: function(key, sequence) { clear: function(key, sequence) {
return Discourse.ajax(Discourse.getURL("/draft"), { return Discourse.ajax("/draft", {
type: 'DELETE', type: 'DELETE',
data: { data: {
draft_key: key, draft_key: key,
@ -21,7 +21,7 @@ Discourse.Draft.reopenClass({
}, },
get: function(key) { get: function(key) {
return Discourse.ajax(Discourse.getURL('/draft'), { return Discourse.ajax('/draft', {
data: { draft_key: key }, data: { draft_key: key },
dataType: 'json' dataType: 'json'
}); });
@ -34,7 +34,7 @@ Discourse.Draft.reopenClass({
save: function(key, sequence, data) { save: function(key, sequence, data) {
data = typeof data === "string" ? data : JSON.stringify(data); data = typeof data === "string" ? data : JSON.stringify(data);
return Discourse.ajax(Discourse.getURL("/draft"), { return Discourse.ajax("/draft", {
type: 'POST', type: 'POST',
data: { data: {
draft_key: key, draft_key: key,

View File

@ -10,7 +10,7 @@
Discourse.Invite = Discourse.Model.extend({ Discourse.Invite = Discourse.Model.extend({
rescind: function() { rescind: function() {
Discourse.ajax(Discourse.getURL('/invites'), { Discourse.ajax('/invites', {
type: 'DELETE', type: 'DELETE',
data: { email: this.get('email') } data: { email: this.get('email') }
}); });

View File

@ -15,7 +15,7 @@ Discourse.InviteList = Discourse.Model.extend({
Discourse.InviteList.reopenClass({ Discourse.InviteList.reopenClass({
findInvitedBy: function(user) { findInvitedBy: function(user) {
return Discourse.ajax({ url: Discourse.getURL("/users/") + (user.get('username_lower')) + "/invited.json" }).then(function (result) { return Discourse.ajax("/users/" + (user.get('username_lower')) + "/invited.json").then(function (result) {
var invitedList = result.invited_list; var invitedList = result.invited_list;
if (invitedList.pending) { if (invitedList.pending) {
invitedList.pending = invitedList.pending.map(function(i) { invitedList.pending = invitedList.pending.map(function(i) {

View File

@ -39,17 +39,6 @@ Discourse.Model = Ember.Object.extend(Discourse.Presence, {
Discourse.Model.reopenClass({ Discourse.Model.reopenClass({
/**
$.get shortcut that uses Discourse.Url and returns a promise
**/
getModelAjax: function(url) {
var modelClass = this;
return Discourse.ajax(url, { cache: false }).then(function (result) {
return modelClass.create(result);
});
},
/** /**
Given an array of values, return them in a hash Given an array of values, return them in a hash

View File

@ -8,7 +8,7 @@
**/ **/
Discourse.Post = Discourse.Model.extend({ Discourse.Post = Discourse.Model.extend({
shareUrl: function(){ shareUrl: function() {
var user = Discourse.get('currentUser'); var user = Discourse.get('currentUser');
if (this.get('postnumber') === 1){ if (this.get('postnumber') === 1){
return this.get('topic.url'); return this.get('topic.url');
@ -17,9 +17,9 @@ Discourse.Post = Discourse.Model.extend({
} }
}.property('url'), }.property('url'),
new_user:(function(){ new_user: function() {
return this.get('trust_level') === 0; return this.get('trust_level') === 0;
}).property('trust_level'), }.property('trust_level'),
url: function() { url: function() {
return Discourse.Utilities.postUrl(this.get('topic.slug') || this.get('topic_slug'), this.get('topic_id'), this.get('post_number')); return Discourse.Utilities.postUrl(this.get('topic.slug') || this.get('topic_slug'), this.get('topic_id'), this.get('post_number'));
@ -29,34 +29,34 @@ Discourse.Post = Discourse.Model.extend({
return Discourse.getURL("/t/") + (this.get('topic_id')) + "/" + (this.get('reply_to_post_number')); return Discourse.getURL("/t/") + (this.get('topic_id')) + "/" + (this.get('reply_to_post_number'));
}.property('reply_to_post_number'), }.property('reply_to_post_number'),
usernameUrl: (function() { usernameUrl: function() {
return Discourse.getURL("/users/" + this.get('username')); return Discourse.getURL("/users/" + this.get('username'));
}).property('username'), }.property('username'),
showUserReplyTab: (function() { showUserReplyTab: function() {
return this.get('reply_to_user') && (this.get('reply_to_post_number') < (this.get('post_number') - 1)); return this.get('reply_to_user') && (this.get('reply_to_post_number') < (this.get('post_number') - 1));
}).property('reply_to_user', 'reply_to_post_number', 'post_number'), }.property('reply_to_user', 'reply_to_post_number', 'post_number'),
firstPost: (function() { firstPost: function() {
if (this.get('bestOfFirst') === true) return true; if (this.get('bestOfFirst') === true) return true;
return this.get('post_number') === 1; return this.get('post_number') === 1;
}).property('post_number'), }.property('post_number'),
byTopicCreator: function() { byTopicCreator: function() {
return this.get('topic.created_by.id') === this.get('user_id'); return this.get('topic.created_by.id') === this.get('user_id');
}.property('topic.created_by.id', 'user_id'), }.property('topic.created_by.id', 'user_id'),
hasHistory: (function() { hasHistory: function() {
return this.get('version') > 1; return this.get('version') > 1;
}).property('version'), }.property('version'),
postElementId: (function() { postElementId: function() {
return "post_" + (this.get('post_number')); return "post_" + (this.get('post_number'));
}).property(), }.property(),
// The class for the read icon of the post. It starts with read-icon then adds 'seen' or // The class for the read icon of the post. It starts with read-icon then adds 'seen' or
// 'last-read' if the post has been seen or is the highest post number seen so far respectively. // 'last-read' if the post has been seen or is the highest post number seen so far respectively.
bookmarkClass: (function() { bookmarkClass: function() {
var result, topic; var result, topic;
result = 'read-icon'; result = 'read-icon';
if (this.get('bookmarked')) return result + ' bookmarked'; if (this.get('bookmarked')) return result + ' bookmarked';
@ -69,7 +69,7 @@ Discourse.Post = Discourse.Model.extend({
} }
} }
return result; return result;
}).property('read', 'topic.last_read_post_number', 'bookmarked'), }.property('read', 'topic.last_read_post_number', 'bookmarked'),
// Custom tooltips for the bookmark icons // Custom tooltips for the bookmark icons
bookmarkTooltip: (function() { bookmarkTooltip: (function() {
@ -85,13 +85,12 @@ Discourse.Post = Discourse.Model.extend({
bookmarkedChanged: function() { bookmarkedChanged: function() {
var post = this; var post = this;
Discourse.ajax({ Discourse.ajax("/posts/" + (this.get('id')) + "/bookmark", {
url: Discourse.getURL("/posts/") + (this.get('id')) + "/bookmark",
type: 'PUT', type: 'PUT',
data: { data: {
bookmarked: this.get('bookmarked') ? true : false bookmarked: this.get('bookmarked') ? true : false
} }
}).fail(function (error) { }).then(null, function (error) {
if (error && error.responseText) { if (error && error.responseText) {
bootbox.alert($.parseJSON(error.responseText).errors[0]); bootbox.alert($.parseJSON(error.responseText).errors[0]);
} else { } else {
@ -101,17 +100,17 @@ Discourse.Post = Discourse.Model.extend({
}.observes('bookmarked'), }.observes('bookmarked'),
internalLinks: (function() { internalLinks: function() {
if (this.blank('link_counts')) return null; if (this.blank('link_counts')) return null;
return this.get('link_counts').filterProperty('internal').filterProperty('title'); return this.get('link_counts').filterProperty('internal').filterProperty('title');
}).property('link_counts.@each.internal'), }.property('link_counts.@each.internal'),
// Edits are the version - 1, so version 2 = 1 edit // Edits are the version - 1, so version 2 = 1 edit
editCount: (function() { editCount: function() {
return this.get('version') - 1; return this.get('version') - 1;
}).property('version'), }.property('version'),
historyHeat: (function() { historyHeat: function() {
var rightNow, updatedAt, updatedAtDate; var rightNow, updatedAt, updatedAtDate;
if (!(updatedAt = this.get('updated_at'))) return; if (!(updatedAt = this.get('updated_at'))) return;
rightNow = new Date().getTime(); rightNow = new Date().getTime();
@ -121,17 +120,17 @@ Discourse.Post = Discourse.Model.extend({
if (updatedAtDate > (rightNow - 60 * 60 * 1000 * 12)) return 'heatmap-high'; 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 * 24)) return 'heatmap-med';
if (updatedAtDate > (rightNow - 60 * 60 * 1000 * 48)) return 'heatmap-low'; if (updatedAtDate > (rightNow - 60 * 60 * 1000 * 48)) return 'heatmap-low';
}).property('updated_at'), }.property('updated_at'),
flagsAvailable: (function() { flagsAvailable: function() {
var _this = this; var _this = this;
var flags = Discourse.get('site.flagTypes').filter(function(item) { var flags = Discourse.get('site.flagTypes').filter(function(item) {
return _this.get("actionByName." + (item.get('name_key')) + ".can_act"); return _this.get("actionByName." + (item.get('name_key')) + ".can_act");
}); });
return flags; return flags;
}).property('Discourse.site.flagTypes', 'actions_summary.@each.can_act'), }.property('Discourse.site.flagTypes', 'actions_summary.@each.can_act'),
actionsHistory: (function() { actionsHistory: function() {
if (!this.present('actions_summary')) return null; if (!this.present('actions_summary')) return null;
return this.get('actions_summary').filter(function(i) { return this.get('actions_summary').filter(function(i) {
@ -139,15 +138,14 @@ Discourse.Post = Discourse.Model.extend({
if (i.get('users') && i.get('users').length > 0) return true; if (i.get('users') && i.get('users').length > 0) return true;
return !i.get('hidden'); return !i.get('hidden');
}); });
}).property('actions_summary.@each.users', 'actions_summary.@each.count'), }.property('actions_summary.@each.users', 'actions_summary.@each.count'),
// Save a post and call the callback when done. // Save a post and call the callback when done.
save: function(complete, error) { save: function(complete, error) {
var data, metaData; var data, metaData;
if (!this.get('newPost')) { if (!this.get('newPost')) {
// We're updating a post // We're updating a post
return Discourse.ajax({ return Discourse.ajax("/posts/" + (this.get('id')), {
url: Discourse.getURL("/posts/") + (this.get('id')),
type: 'PUT', type: 'PUT',
data: { data: {
post: { raw: this.get('raw') }, post: { raw: this.get('raw') },
@ -178,9 +176,8 @@ Discourse.Post = Discourse.Model.extend({
data.meta_data = {}; data.meta_data = {};
Ember.keys(metaData).forEach(function(key) { data.meta_data[key] = metaData.get(key); }); Ember.keys(metaData).forEach(function(key) { data.meta_data[key] = metaData.get(key); });
} }
return Discourse.ajax({ return Discourse.ajax("/posts", {
type: 'POST', type: 'POST',
url: Discourse.getURL("/posts"),
data: data data: data
}).then(function(result) { }).then(function(result) {
// Post created // Post created
@ -193,11 +190,11 @@ Discourse.Post = Discourse.Model.extend({
}, },
recover: function() { recover: function() {
return Discourse.ajax(Discourse.getURL("/posts/") + (this.get('id')) + "/recover", { type: 'PUT', cache: false }); return Discourse.ajax("/posts/" + (this.get('id')) + "/recover", { type: 'PUT', cache: false });
}, },
destroy: function(complete) { destroy: function(complete) {
return Discourse.ajax(Discourse.getURL("/posts/") + (this.get('id')), { type: 'DELETE' }); return Discourse.ajax("/posts/" + (this.get('id')), { type: 'DELETE' });
}, },
// Update the properties of this post from an obj, ignoring cooked as we should already // Update the properties of this post from an obj, ignoring cooked as we should already
@ -237,7 +234,7 @@ Discourse.Post = Discourse.Model.extend({
this.set('replies', []); this.set('replies', []);
var parent = this; var parent = this;
return Discourse.ajax({url: Discourse.getURL("/posts/") + (this.get('id')) + "/replies"}).then(function(loaded) { return Discourse.ajax("/posts/" + (this.get('id')) + "/replies").then(function(loaded) {
var replies = parent.get('replies'); var replies = parent.get('replies');
loaded.each(function(reply) { loaded.each(function(reply) {
var post = Discourse.Post.create(reply); var post = Discourse.Post.create(reply);
@ -249,7 +246,7 @@ Discourse.Post = Discourse.Model.extend({
}, },
loadVersions: function() { loadVersions: function() {
return Discourse.ajax(Discourse.getURL("/posts/") + (this.get('id')) + "/versions.json"); return Discourse.ajax("/posts/" + (this.get('id')) + "/versions.json");
}, },
// Whether to show replies directly below // Whether to show replies directly below
@ -303,7 +300,7 @@ Discourse.Post.reopenClass({
}, },
deleteMany: function(posts) { deleteMany: function(posts) {
return Discourse.ajax(Discourse.getURL("/posts/destroy_many"), { return Discourse.ajax("/posts/destroy_many", {
type: 'DELETE', type: 'DELETE',
data: { data: {
post_ids: posts.map(function(p) { return p.get('id'); }) post_ids: posts.map(function(p) { return p.get('id'); })
@ -312,26 +309,26 @@ Discourse.Post.reopenClass({
}, },
loadVersion: function(postId, version, callback) { loadVersion: function(postId, version, callback) {
return Discourse.ajax({url: Discourse.getURL("/posts/") + postId + ".json?version=" + version}).then(function(result) { return Discourse.ajax("/posts/" + postId + ".json?version=" + version).then(function(result) {
return Discourse.Post.create(result); return Discourse.Post.create(result);
}); });
}, },
loadByPostNumber: function(topicId, postId) { loadByPostNumber: function(topicId, postId) {
return Discourse.ajax({url: Discourse.getURL("/posts/by_number/") + topicId + "/" + postId + ".json"}).then(function (result) { return Discourse.ajax("/posts/by_number/" + topicId + "/" + postId + ".json").then(function (result) {
return Discourse.Post.create(result); return Discourse.Post.create(result);
}); });
}, },
loadQuote: function(postId) { loadQuote: function(postId) {
return Discourse.ajax({url: Discourse.getURL("/posts/") + postId + ".json"}).then(function(result) { return Discourse.ajax("/posts/" + postId + ".json").then(function(result) {
var post = Discourse.Post.create(result); var post = Discourse.Post.create(result);
return Discourse.BBCode.buildQuoteBBCode(post, post.get('raw')); return Discourse.BBCode.buildQuoteBBCode(post, post.get('raw'));
}); });
}, },
load: function(postId) { load: function(postId) {
return Discourse.ajax({url: Discourse.getURL("/posts/") + postId + ".json"}).then(function (result) { return Discourse.ajax("/posts/" + postId + ".json").then(function (result) {
return Discourse.Post.create(result); return Discourse.Post.create(result);
}); });
} }

View File

@ -161,7 +161,7 @@ Discourse.Topic = Discourse.Model.extend({
url: "" + (this.get('url')) + "/star", url: "" + (this.get('url')) + "/star",
type: 'PUT', type: 'PUT',
data: { starred: topic.get('starred') ? true : false } data: { starred: topic.get('starred') ? true : false }
}).fail(function (error) { }).then(null, function (error) {
topic.toggleProperty('starred'); topic.toggleProperty('starred');
if (error && error.responseText) { if (error && error.responseText) {
@ -185,25 +185,22 @@ Discourse.Topic = Discourse.Model.extend({
// Reset our read data for this topic // Reset our read data for this topic
resetRead: function() { resetRead: function() {
return Discourse.ajax(Discourse.getURL("/t/") + (this.get('id')) + "/timings", { return Discourse.ajax("/t/" + (this.get('id')) + "/timings", {
type: 'DELETE' type: 'DELETE'
}); });
}, },
// Invite a user to this topic // Invite a user to this topic
inviteUser: function(user) { inviteUser: function(user) {
return Discourse.ajax({ return Discourse.ajax("/t/" + (this.get('id')) + "/invite", {
type: 'POST', type: 'POST',
url: Discourse.getURL("/t/") + (this.get('id')) + "/invite", data: { user: user }
data: {
user: user
}
}); });
}, },
// Delete this topic // Delete this topic
destroy: function() { destroy: function() {
return Discourse.ajax(Discourse.getURL("/t/") + (this.get('id')), { type: 'DELETE' }); return Discourse.ajax("/t/" + (this.get('id')), { type: 'DELETE' });
}, },
// Load the posts for this topic // Load the posts for this topic
@ -315,12 +312,9 @@ Discourse.Topic = Discourse.Model.extend({
updateNotifications: function(v) { updateNotifications: function(v) {
this.set('notification_level', v); this.set('notification_level', v);
this.set('notifications_reason_id', null); this.set('notifications_reason_id', null);
return Discourse.ajax({ return Discourse.ajax("/t/" + (this.get('id')) + "/notifications", {
url: Discourse.getURL("/t/") + (this.get('id')) + "/notifications",
type: 'POST', type: 'POST',
data: { data: { notification_level: v }
notification_level: v
}
}); });
}, },
@ -351,9 +345,9 @@ Discourse.Topic = Discourse.Model.extend({
// Clear the pin optimistically from the object // Clear the pin optimistically from the object
topic.set('pinned', false); topic.set('pinned', false);
Discourse.ajax(Discourse.getURL("/t/") + this.get('id') + "/clear-pin", { Discourse.ajax("/t/" + this.get('id') + "/clear-pin", {
type: 'PUT' type: 'PUT'
}).fail(function() { }).then(null, function() {
// On error, put the pin back // On error, put the pin back
topic.set('pinned', true); topic.set('pinned', true);
}); });
@ -403,7 +397,7 @@ Discourse.Topic.reopenClass({
@returns A promise that will resolve to the topics @returns A promise that will resolve to the topics
**/ **/
findSimilarTo: function(title, body) { findSimilarTo: function(title, body) {
return Discourse.ajax({url: Discourse.getURL("/topics/similar_to"), data: {title: title, raw: body} }).then(function (results) { return Discourse.ajax("/topics/similar_to", { data: {title: title, raw: body} }).then(function (results) {
return results.map(function(topic) { return Discourse.Topic.create(topic) }); return results.map(function(topic) { return Discourse.Topic.create(topic) });
}); });
}, },
@ -457,7 +451,7 @@ Discourse.Topic.reopenClass({
// Create a topic from posts // Create a topic from posts
movePosts: function(topicId, title, postIds) { movePosts: function(topicId, title, postIds) {
return Discourse.ajax(Discourse.getURL(Discourse.getURL("/t/")) + topicId + "/move-posts", { return Discourse.ajax("/t/" + topicId + "/move-posts", {
type: 'POST', type: 'POST',
data: { title: title, post_ids: postIds } data: { title: title, post_ids: postIds }
}); });

View File

@ -61,9 +61,9 @@ Discourse.User = Discourse.Model.extend({
@property path @property path
@type {String} @type {String}
**/ **/
path: (function() { path: function() {
return Discourse.getURL("/users/") + (this.get('username_lower')); return Discourse.getURL("/users/") + (this.get('username_lower'));
}).property('username'), }.property('username'),
/** /**
Path to this user's administration Path to this user's administration
@ -71,9 +71,9 @@ Discourse.User = Discourse.Model.extend({
@property adminPath @property adminPath
@type {String} @type {String}
**/ **/
adminPath: (function() { adminPath: function() {
return Discourse.getURL("/admin/users/") + (this.get('username_lower')); return Discourse.getURL("/admin/users/") + (this.get('username_lower'));
}).property('username'), }.property('username'),
/** /**
This user's username in lowercase. This user's username in lowercase.
@ -81,9 +81,9 @@ Discourse.User = Discourse.Model.extend({
@property username_lower @property username_lower
@type {String} @type {String}
**/ **/
username_lower: (function() { username_lower: function() {
return this.get('username').toLowerCase(); return this.get('username').toLowerCase();
}).property('username'), }.property('username'),
/** /**
This user's trust level. This user's trust level.
@ -91,9 +91,9 @@ Discourse.User = Discourse.Model.extend({
@property trustLevel @property trustLevel
@type {Integer} @type {Integer}
**/ **/
trustLevel: (function() { trustLevel: function() {
return Discourse.get('site.trust_levels').findProperty('id', this.get('trust_level')); return Discourse.get('site.trust_levels').findProperty('id', this.get('trust_level'));
}).property('trust_level'), }.property('trust_level'),
/** /**
Changes this user's username. Changes this user's username.
@ -103,12 +103,9 @@ Discourse.User = Discourse.Model.extend({
@returns Result of ajax call @returns Result of ajax call
**/ **/
changeUsername: function(newUsername) { changeUsername: function(newUsername) {
return Discourse.ajax({ return Discourse.ajax("/users/" + (this.get('username_lower')) + "/preferences/username", {
url: Discourse.getURL("/users/") + (this.get('username_lower')) + "/preferences/username",
type: 'PUT', type: 'PUT',
data: { data: { new_username: newUsername }
new_username: newUsername
}
}); });
}, },
@ -120,12 +117,9 @@ Discourse.User = Discourse.Model.extend({
@returns Result of ajax call @returns Result of ajax call
**/ **/
changeEmail: function(email) { changeEmail: function(email) {
return Discourse.ajax({ return Discourse.ajax("/users/" + (this.get('username_lower')) + "/preferences/email", {
url: Discourse.getURL("/users/") + (this.get('username_lower')) + "/preferences/email",
type: 'PUT', type: 'PUT',
data: { data: { email: email }
email: email
}
}); });
}, },
@ -147,7 +141,7 @@ Discourse.User = Discourse.Model.extend({
**/ **/
save: function() { save: function() {
var user = this; var user = this;
return Discourse.ajax(Discourse.getURL("/users/") + this.get('username').toLowerCase(), { return Discourse.ajax("/users/" + this.get('username').toLowerCase(), {
data: this.getProperties('auto_track_topics_after_msecs', data: this.getProperties('auto_track_topics_after_msecs',
'bio_raw', 'bio_raw',
'website', 'website',
@ -174,7 +168,7 @@ Discourse.User = Discourse.Model.extend({
@returns {Promise} the result of the change password operation @returns {Promise} the result of the change password operation
**/ **/
changePassword: function() { changePassword: function() {
return Discourse.ajax(Discourse.getURL("/session/forgot_password"), { return Discourse.ajax("/session/forgot_password", {
dataType: 'json', dataType: 'json',
data: { data: {
login: this.get('username') login: this.get('username')
@ -209,13 +203,8 @@ Discourse.User = Discourse.Model.extend({
loadUserAction: function(id) { loadUserAction: function(id) {
var user = this; var user = this;
var stream = this.get('stream'); var stream = this.get('stream');
return Discourse.ajax({ return Discourse.ajax("/user_actions/" + id + ".json", { cache: 'false' }).then(function(result) {
url: Discourse.getURL("/user_actions/") + id + ".json",
dataType: 'json',
cache: 'false'
}).then(function(result) {
if (result) { if (result) {
if ((user.get('streamFilter') || result.action_type) !== result.action_type) return; if ((user.get('streamFilter') || result.action_type) !== result.action_type) return;
var action = Em.A(); var action = Em.A();
@ -374,7 +363,7 @@ Discourse.User = Discourse.Model.extend({
var user = this; var user = this;
var username = this.get('username'); var username = this.get('username');
PreloadStore.getAndRemove("user_" + username, function() { PreloadStore.getAndRemove("user_" + username, function() {
return Discourse.ajax({ url: Discourse.getURL("/users/") + username + '.json' }); return Discourse.ajax("/users/" + username + '.json');
}).then(function (json) { }).then(function (json) {
// Create a user from the resulting JSON // Create a user from the resulting JSON
json.user.stats = Discourse.User.groupStats(json.user.stats.map(function(s) { json.user.stats = Discourse.User.groupStats(json.user.stats.map(function(s) {
@ -410,13 +399,8 @@ Discourse.User.reopenClass({
@param {String} email An email address to check @param {String} email An email address to check
**/ **/
checkUsername: function(username, email) { checkUsername: function(username, email) {
return Discourse.ajax({ return Discourse.ajax('/users/check_username', {
url: Discourse.getURL('/users/check_username'), data: { username: username, email: email }
type: 'GET',
data: {
username: username,
email: email
}
}); });
}, },
@ -477,9 +461,7 @@ Discourse.User.reopenClass({
@returns Result of ajax call @returns Result of ajax call
**/ **/
createAccount: function(name, email, password, username, passwordConfirm, challenge) { createAccount: function(name, email, password, username, passwordConfirm, challenge) {
return Discourse.ajax({ return Discourse.ajax("/users", {
url: Discourse.getURL("/users"),
dataType: 'json',
data: { data: {
name: name, name: name,
email: email, email: email,

View File

@ -54,7 +54,7 @@ Discourse.HeaderView = Discourse.View.extend({
showNotifications: function() { showNotifications: function() {
var headerView = this; var headerView = this;
Discourse.ajax(Discourse.getURL('/notifications')).then(function(result) { Discourse.ajax('/notifications').then(function(result) {
headerView.set('notifications', result.map(function(n) { headerView.set('notifications', result.map(function(n) {
return Discourse.Notification.create(n); return Discourse.Notification.create(n);
})); }));

View File

@ -242,7 +242,7 @@ Discourse.CreateAccountView = Discourse.ModalBodyView.extend({
fetchConfirmationValue: function() { fetchConfirmationValue: function() {
var createAccountView = this; var createAccountView = this;
return Discourse.ajax(Discourse.getURL('/users/hp.json')).then(function (json) { return Discourse.ajax('/users/hp.json').then(function (json) {
createAccountView.set('accountPasswordConfirm', json.value); createAccountView.set('accountPasswordConfirm', json.value);
createAccountView.set('accountChallenge', json.challenge.split("").reverse().join("")); createAccountView.set('accountChallenge', json.challenge.split("").reverse().join(""));
}); });

View File

@ -104,8 +104,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
).then(function() { ).then(function() {
// success // success
$('#discourse-modal').modal('hide'); $('#discourse-modal').modal('hide');
var url = Discourse.getURL("/category/") + categoryView.get('category.name'); Discourse.URL.redirectTo("/category/" + categoryView.get('category.name'));
Discourse.URL.redirectTo(url);
}, function(errors) { }, function(errors) {
// errors // errors
if(errors.length === 0) errors.push(Em.String.i18n("category.save_error")); if(errors.length === 0) errors.push(Em.String.i18n("category.save_error"));
@ -116,8 +115,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
this.get('category').save().then(function(result) { this.get('category').save().then(function(result) {
// success // success
$('#discourse-modal').modal('hide'); $('#discourse-modal').modal('hide');
var url = Discourse.getURL("/category/") + (Discourse.Utilities.categoryUrlId(result.category)); Discourse.URL.redirectTo("/category/" + Discourse.Utilities.categoryUrlId(result.category));
Discourse.URL.redirectTo(url);
}, function(errors) { }, function(errors) {
// errors // errors
if(errors.length === 0) errors.push(Em.String.i18n("category.creation_error")); if(errors.length === 0) errors.push(Em.String.i18n("category.creation_error"));
@ -135,7 +133,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
if (result) { if (result) {
categoryView.get('category').destroy().then(function(){ categoryView.get('category').destroy().then(function(){
// success // success
Discourse.URL.redirectTo(Discourse.getURL("/categories")); Discourse.URL.redirectTo("/categories");
}, function(jqXHR){ }, function(jqXHR){
// error // error
$('#discourse-modal').modal('show'); $('#discourse-modal').modal('show');

View File

@ -17,7 +17,7 @@ Discourse.ForgotPasswordView = Discourse.ModalBodyView.extend({
submit: function() { submit: function() {
Discourse.ajax(Discourse.getURL("/session/forgot_password"), { Discourse.ajax("/session/forgot_password", {
data: { login: this.get('accountEmailOrUsername') }, data: { login: this.get('accountEmailOrUsername') },
type: 'POST' type: 'POST'
}); });

View File

@ -49,7 +49,7 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({
this.set('loggingIn', true); this.set('loggingIn', true);
var loginView = this; var loginView = this;
Discourse.ajax(Discourse.getURL("/session"), { Discourse.ajax("/session", {
data: { login: this.get('loginName'), password: this.get('loginPassword') }, data: { login: this.get('loginName'), password: this.get('loginPassword') },
type: 'POST' type: 'POST'
}).then(function (result) { }).then(function (result) {

View File

@ -12,7 +12,7 @@ Discourse.NotActivatedView = Discourse.ModalBodyView.extend({
emailSent: false, emailSent: false,
sendActivationEmail: function() { sendActivationEmail: function() {
Discourse.ajax(Discourse.getURL('/users/') + this.get('username') + '/send_activation_email'); Discourse.ajax('/users/' + this.get('username') + '/send_activation_email');
this.set('emailSent', true); this.set('emailSent', true);
} }
}); });

View File

@ -146,7 +146,7 @@ Discourse.PostView = Discourse.View.extend({
if ($aside.data('topic')) { if ($aside.data('topic')) {
topic_id = $aside.data('topic'); topic_id = $aside.data('topic');
} }
Discourse.ajax(Discourse.getURL("/posts/by_number/") + topic_id + "/" + ($aside.data('post'))).then(function (result) { Discourse.ajax("/posts/by_number/" + topic_id + "/" + ($aside.data('post'))).then(function (result) {
var parsed = $(result.cooked); var parsed = $(result.cooked);
parsed.replaceText(originalText, "<span class='highlighted'>" + originalText + "</span>"); parsed.replaceText(originalText, "<span class='highlighted'>" + originalText + "</span>");
$blockQuote.showHtml(parsed); $blockQuote.showHtml(parsed);

View File

@ -90,7 +90,7 @@ Discourse.SearchView = Discourse.View.extend({
searchTerm: Discourse.debouncePromise(function(term, typeFilter) { searchTerm: Discourse.debouncePromise(function(term, typeFilter) {
var searchView = this; var searchView = this;
return Discourse.ajax(Discourse.getURL('/search'), { return Discourse.ajax('/search', {
data: { data: {
term: term, term: term,
type_filter: typeFilter type_filter: typeFilter

View File

@ -7,9 +7,8 @@
onlogin: function(assertion) { onlogin: function(assertion) {
if (readyCalled) { if (readyCalled) {
Discourse.ajax({ Discourse.ajax('/auth/persona/callback', {
type: 'POST', type: 'POST',
url: Discourse.getURL('/auth/persona/callback'),
data: { 'assertion': assertion }, data: { 'assertion': assertion },
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
Discourse.authenticationComplete(data); Discourse.authenticationComplete(data);

View File

@ -1,6 +1,6 @@
class CreateAdminLogs < ActiveRecord::Migration class CreateAdminLogs < ActiveRecord::Migration
def up def up
create_table :admin_logs do |t| create_table :admin_logs, force: true do |t|
t.integer :action, null: false t.integer :action, null: false
t.integer :admin_id, null: false t.integer :admin_id, null: false
t.integer :target_user_id t.integer :target_user_id

View File

@ -1,6 +1,6 @@
class CreateGroups < ActiveRecord::Migration class CreateGroups < ActiveRecord::Migration
def change def change
create_table :groups do |t| create_table :groups, force: true do |t|
t.string :name, null: false t.string :name, null: false
t.timestamps t.timestamps
end end

View File

@ -1,6 +1,6 @@
class GroupUsers < ActiveRecord::Migration class GroupUsers < ActiveRecord::Migration
def change def change
create_table :group_users do |t| create_table :group_users, force: true do |t|
t.integer :group_id, null: false t.integer :group_id, null: false
t.integer :user_id, null: false t.integer :user_id, null: false
t.timestamps t.timestamps

View File

@ -2,7 +2,7 @@ class AddSecurityToCategories < ActiveRecord::Migration
def change def change
add_column :categories, :secure, :boolean, default: false, null: false add_column :categories, :secure, :boolean, default: false, null: false
create_table :category_groups do |t| create_table :category_groups, force: true do |t|
t.integer :category_id, null: false t.integer :category_id, null: false
t.integer :group_id, null: false t.integer :group_id, null: false
t.timestamps t.timestamps

View File

@ -1,6 +1,6 @@
class AddTopicAllowedGroups < ActiveRecord::Migration class AddTopicAllowedGroups < ActiveRecord::Migration
def change def change
create_table :topic_allowed_groups do |t| create_table :topic_allowed_groups, force: true do |t|
# oops # oops
t.integer :group_id, :integer, null: false t.integer :group_id, :integer, null: false
t.integer :topic_id, :integer, null: false t.integer :topic_id, :integer, null: false