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);
var adminEmailLogsController = this;
Discourse.ajax(Discourse.getURL("/admin/email_logs/test"), {
Discourse.ajax("/admin/email_logs/test", {
type: 'POST',
data: { email_address: this.get('testEmailAddress') }
}).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(){
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);
});
},
@@ -20,6 +20,8 @@ Discourse.AdminApi = Discourse.Model.extend({
Discourse.AdminApi.reopenClass({
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
**/
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);
model.set('loaded', true);
return model;
@@ -34,7 +34,7 @@ Discourse.AdminDashboard.reopenClass({
@return {jqXHR} a jQuery Promise object
**/
fetchProblems: function() {
return Discourse.ajax(Discourse.getURL("/admin/dashboard/problems"), {
return Discourse.ajax("/admin/dashboard/problems", {
type: 'GET',
dataType: 'json'
}).then(function(json) {

View File

@@ -6,20 +6,12 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminUser = Discourse.Model.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'),
Discourse.AdminUser = Discourse.User.extend({
deleteAllPosts: function() {
var user = this;
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);
});
},
@@ -29,14 +21,14 @@ Discourse.AdminUser = Discourse.Model.extend({
this.set('admin', false);
this.set('can_grant_admin', true);
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() {
this.set('admin', true);
this.set('can_grant_admin', false);
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
@@ -44,18 +36,18 @@ Discourse.AdminUser = Discourse.Model.extend({
this.set('moderator', false);
this.set('can_grant_moderation', true);
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() {
this.set('moderator', true);
this.set('can_grant_moderation', false);
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() {
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!");
},
@@ -63,7 +55,7 @@ Discourse.AdminUser = Discourse.Model.extend({
this.set('can_approve', false);
this.set('approved', true);
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() {
@@ -91,7 +83,7 @@ Discourse.AdminUser = Discourse.Model.extend({
ban: function() {
var duration = parseInt(window.prompt(Em.String.i18n('admin.user.ban_duration')), 10);
if (duration > 0) {
Discourse.ajax(Discourse.getURL("/admin/users/") + this.id + "/ban", {
Discourse.ajax("/admin/users/" + this.id + "/ban", {
type: 'PUT',
data: {duration: duration}
}).then(function () {
@@ -106,7 +98,7 @@ Discourse.AdminUser = Discourse.Model.extend({
},
unban: function() {
Discourse.ajax(Discourse.getURL("/admin/users/") + this.id + "/unban", {
Discourse.ajax("/admin/users/" + this.id + "/unban", {
type: 'PUT'
}).then(function() {
// succeeded
@@ -119,7 +111,7 @@ Discourse.AdminUser = Discourse.Model.extend({
},
impersonate: function() {
Discourse.ajax(Discourse.getURL("/admin/impersonate"), {
Discourse.ajax("/admin/impersonate", {
type: 'POST',
data: { username_or_email: this.get('username') }
}).then(function() {
@@ -151,7 +143,7 @@ Discourse.AdminUser = Discourse.Model.extend({
var user = this;
bootbox.confirm(Em.String.i18n("admin.user.delete_confirm"), Em.String.i18n("no_value"), Em.String.i18n("yes_value"), function(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) {
bootbox.alert(Em.String.i18n("admin.user.deleted"), function() {
document.location = "/admin/users/list/active";
@@ -180,7 +172,7 @@ Discourse.AdminUser.reopenClass({
user.set('can_approve', false);
return user.set('selected', false);
});
return Discourse.ajax(Discourse.getURL("/admin/users/approve-bulk"), {
return Discourse.ajax("/admin/users/approve-bulk", {
type: 'PUT',
data: {
users: users.map(function(u) {
@@ -191,13 +183,13 @@ Discourse.AdminUser.reopenClass({
},
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);
});
},
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 }
}).then(function(users) {
return users.map(function(u) {

View File

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

View File

@@ -47,14 +47,14 @@ Discourse.FlaggedPost = Discourse.Post.extend({
deletePost: function() {
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 {
return Discourse.ajax(Discourse.getURL("/posts/") + this.id, { type: 'DELETE', cache: false });
return Discourse.ajax("/posts/" + this.id, { type: 'DELETE', cache: false });
}
},
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() {
@@ -65,7 +65,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({
Discourse.FlaggedPost.reopenClass({
findAll: function(filter) {
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 = {};
data.users.each(function(u) {
userLookup[u.id] = Discourse.User.create(u);

View File

@@ -138,7 +138,7 @@ Discourse.Report = Discourse.Model.extend({
Discourse.Report.reopenClass({
find: function(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
var maxY = 0;
json.report.data.forEach(function (row) {

View File

@@ -20,7 +20,7 @@ Discourse.SiteContent = Discourse.Model.extend({
@return {jqXHR} a jQuery Promise object
**/
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',
data: {content: this.get('content')}
});
@@ -31,7 +31,7 @@ Discourse.SiteContent = Discourse.Model.extend({
Discourse.SiteContent.reopenClass({
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);
});
}

View File

@@ -11,7 +11,7 @@ Discourse.SiteContentType = Discourse.Model.extend({});
Discourse.SiteContentType.reopenClass({
findAll: function() {
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) {
contentTypes.pushObject(Discourse.SiteContentType.create(ct));
});

View File

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

View File

@@ -72,7 +72,7 @@ Discourse.SiteSetting = Discourse.Model.extend({
save: function() {
// Update the setting
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') },
type: 'PUT'
}).then(function() {
@@ -90,7 +90,7 @@ Discourse.SiteSetting.reopenClass({
**/
findAll: function() {
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) {
s.originalValue = s.value;
result.pushObject(Discourse.SiteSetting.create(s));
@@ -101,7 +101,7 @@ Discourse.SiteSetting.reopenClass({
},
update: function(key, value) {
return Discourse.ajax(Discourse.getURL("/admin/site_settings/") + key, {
return Discourse.ajax("/admin/site_settings/" + key, {
type: 'PUT',
data: { value: value }
});

View File

@@ -26,7 +26,7 @@ Discourse.VersionCheck = Discourse.Model.extend({
Discourse.VersionCheck.reopenClass({
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);
});
}

View File

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

View File

@@ -230,7 +230,7 @@
{{#each top_referrers.data}}
<tbody>
<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_topics}}</td>
</tr>

View File

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

View File

@@ -4,7 +4,7 @@
<li>{{#linkTo adminFlags.active}}{{i18n admin.flags.active}}{{/linkTo}}</li>
<li>{{#linkTo adminFlags.old}}{{i18n admin.flags.old}}{{/linkTo}}</li>
</ul>
</div>
</div>
</div>
@@ -21,12 +21,12 @@
<tbody>
{{#each content}}
<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>
<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='action'>
<td class='action'>
{{#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.delete_title}}' class='btn' {{action deletePost this}}>{{i18n admin.flags.delete}}</button>
@@ -38,7 +38,7 @@
<tr>
<td></td>
<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>

View File

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

View File

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