mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Convert all Ajax calls to use Discourse.ajax()
This commit is contained in:
@@ -4,21 +4,18 @@ Discourse.AdminApi = Discourse.Model.extend({
|
||||
keyExists: function(){
|
||||
var key = this.get('key') || '';
|
||||
return key && key.length === this.VALID_KEY_LENGTH;
|
||||
}.property('key'),
|
||||
}.property('key'),
|
||||
|
||||
generateKey: function(){
|
||||
var _this = this;
|
||||
|
||||
$.ajax(Discourse.getURL('/admin/api/generate_key'),{
|
||||
type: 'POST'
|
||||
}).success(function(result){
|
||||
_this.set('key', result.key);
|
||||
});
|
||||
var adminApi = this;
|
||||
Discourse.ajax(Discourse.getURL('/admin/api/generate_key'),{type: 'POST'}).then(function (result) {
|
||||
adminApi.set('key', result.key);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.AdminApi.reopenClass({
|
||||
find: function(){
|
||||
return this.getAjax('/admin/api');
|
||||
find: function() {
|
||||
return this.getModelAjax('/admin/api');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ Discourse.AdminDashboard.reopenClass({
|
||||
**/
|
||||
find: function() {
|
||||
var model = Discourse.AdminDashboard.create();
|
||||
return $.ajax(Discourse.getURL("/admin/dashboard"), {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/dashboard"), {
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(json) {
|
||||
@@ -39,7 +39,7 @@ Discourse.AdminDashboard.reopenClass({
|
||||
**/
|
||||
fetchProblems: function() {
|
||||
var model = Discourse.AdminDashboard.create();
|
||||
return $.ajax(Discourse.getURL("/admin/dashboard/problems"), {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/dashboard/problems"), {
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(json) {
|
||||
|
||||
@@ -18,7 +18,7 @@ Discourse.AdminUser = Discourse.Model.extend({
|
||||
|
||||
deleteAllPosts: function() {
|
||||
this.set('can_delete_all_posts', false);
|
||||
$.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/delete_all_posts", {type: 'PUT'});
|
||||
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/delete_all_posts", {type: 'PUT'});
|
||||
},
|
||||
|
||||
// Revoke the user's admin access
|
||||
@@ -26,14 +26,14 @@ Discourse.AdminUser = Discourse.Model.extend({
|
||||
this.set('admin', false);
|
||||
this.set('can_grant_admin', true);
|
||||
this.set('can_revoke_admin', false);
|
||||
return $.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/revoke_admin", {type: 'PUT'});
|
||||
return Discourse.ajax(Discourse.getURL("/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);
|
||||
$.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/grant_admin", {type: 'PUT'});
|
||||
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/grant_admin", {type: 'PUT'});
|
||||
},
|
||||
|
||||
// Revoke the user's moderation access
|
||||
@@ -41,18 +41,18 @@ Discourse.AdminUser = Discourse.Model.extend({
|
||||
this.set('moderator', false);
|
||||
this.set('can_grant_moderation', true);
|
||||
this.set('can_revoke_moderation', false);
|
||||
return $.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/revoke_moderation", {type: 'PUT'});
|
||||
return Discourse.ajax(Discourse.getURL("/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);
|
||||
$.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/grant_moderation", {type: 'PUT'});
|
||||
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/grant_moderation", {type: 'PUT'});
|
||||
},
|
||||
|
||||
refreshBrowsers: function() {
|
||||
$.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/refresh_browsers", {type: 'POST'});
|
||||
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/refresh_browsers", {type: 'POST'});
|
||||
bootbox.alert("Message sent to all clients!");
|
||||
},
|
||||
|
||||
@@ -60,7 +60,7 @@ Discourse.AdminUser = Discourse.Model.extend({
|
||||
this.set('can_approve', false);
|
||||
this.set('approved', true);
|
||||
this.set('approved_by', Discourse.get('currentUser'));
|
||||
$.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/approve", {type: 'PUT'});
|
||||
Discourse.ajax(Discourse.getURL("/admin/users/") + (this.get('id')) + "/approve", {type: 'PUT'});
|
||||
},
|
||||
|
||||
username_lower: (function() {
|
||||
@@ -90,7 +90,7 @@ Discourse.AdminUser = Discourse.Model.extend({
|
||||
_this = this;
|
||||
if (duration = parseInt(window.prompt(Em.String.i18n('admin.user.ban_duration')), 10)) {
|
||||
if (duration > 0) {
|
||||
return $.ajax(Discourse.getURL("/admin/users/") + this.id + "/ban", {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/users/") + this.id + "/ban", {
|
||||
type: 'PUT',
|
||||
data: {duration: duration},
|
||||
success: function() {
|
||||
@@ -107,7 +107,7 @@ Discourse.AdminUser = Discourse.Model.extend({
|
||||
|
||||
unban: function() {
|
||||
var _this = this;
|
||||
return $.ajax(Discourse.getURL("/admin/users/") + this.id + "/unban", {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/users/") + this.id + "/unban", {
|
||||
type: 'PUT',
|
||||
success: function() {
|
||||
window.location.reload();
|
||||
@@ -121,7 +121,7 @@ Discourse.AdminUser = Discourse.Model.extend({
|
||||
|
||||
impersonate: function() {
|
||||
var _this = this;
|
||||
return $.ajax(Discourse.getURL("/admin/impersonate"), {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/impersonate"), {
|
||||
type: 'POST',
|
||||
data: {
|
||||
username_or_email: this.get('username')
|
||||
@@ -150,7 +150,7 @@ Discourse.AdminUser.reopenClass({
|
||||
user.set('can_approve', false);
|
||||
return user.set('selected', false);
|
||||
});
|
||||
return $.ajax(Discourse.getURL("/admin/users/approve-bulk"), {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/users/approve-bulk"), {
|
||||
type: 'PUT',
|
||||
data: {
|
||||
users: users.map(function(u) {
|
||||
@@ -161,7 +161,7 @@ Discourse.AdminUser.reopenClass({
|
||||
},
|
||||
|
||||
find: function(username) {
|
||||
return $.ajax({url: Discourse.getURL("/admin/users/") + username}).then(function (result) {
|
||||
return Discourse.ajax({url: Discourse.getURL("/admin/users/") + username}).then(function (result) {
|
||||
return Discourse.AdminUser.create(result);
|
||||
})
|
||||
},
|
||||
@@ -169,7 +169,7 @@ Discourse.AdminUser.reopenClass({
|
||||
findAll: function(query, filter) {
|
||||
var result;
|
||||
result = Em.A();
|
||||
$.ajax({
|
||||
Discourse.ajax({
|
||||
url: Discourse.getURL("/admin/users/list/") + query + ".json",
|
||||
data: {
|
||||
filter: filter
|
||||
|
||||
@@ -19,7 +19,7 @@ Discourse.EmailLog.reopenClass({
|
||||
findAll: function(filter) {
|
||||
var result;
|
||||
result = Em.A();
|
||||
$.ajax({
|
||||
Discourse.ajax({
|
||||
url: Discourse.getURL("/admin/email_logs.json"),
|
||||
data: { filter: filter },
|
||||
success: function(logs) {
|
||||
|
||||
@@ -47,14 +47,14 @@ Discourse.FlaggedPost = Discourse.Post.extend({
|
||||
|
||||
deletePost: function() {
|
||||
if (this.get('post_number') === "1") {
|
||||
return $.ajax(Discourse.getURL("/t/") + this.topic_id, { type: 'DELETE', cache: false });
|
||||
return Discourse.ajax(Discourse.getURL("/t/") + this.topic_id, { type: 'DELETE', cache: false });
|
||||
} else {
|
||||
return $.ajax(Discourse.getURL("/posts/") + this.id, { type: 'DELETE', cache: false });
|
||||
return Discourse.ajax(Discourse.getURL("/posts/") + this.id, { type: 'DELETE', cache: false });
|
||||
}
|
||||
},
|
||||
|
||||
clearFlags: function() {
|
||||
return $.ajax(Discourse.getURL("/admin/flags/clear/") + this.id, { type: 'POST', cache: false });
|
||||
return Discourse.ajax(Discourse.getURL("/admin/flags/clear/") + this.id, { type: 'POST', cache: false });
|
||||
},
|
||||
|
||||
hiddenClass: (function() {
|
||||
@@ -67,7 +67,7 @@ Discourse.FlaggedPost.reopenClass({
|
||||
findAll: function(filter) {
|
||||
var result;
|
||||
result = Em.A();
|
||||
$.ajax({
|
||||
Discourse.ajax({
|
||||
url: Discourse.getURL("/admin/flags/") + filter + ".json",
|
||||
success: function(data) {
|
||||
var userLookup;
|
||||
|
||||
@@ -28,7 +28,7 @@ Discourse.GithubCommit.reopenClass({
|
||||
findAll: function() {
|
||||
var result;
|
||||
result = Em.A();
|
||||
$.ajax( "https://api.github.com/repos/discourse/discourse/commits?callback=callback", {
|
||||
Discourse.ajax( "https://api.github.com/repos/discourse/discourse/commits?callback=callback", {
|
||||
dataType: 'jsonp',
|
||||
type: 'get',
|
||||
data: { per_page: 25 },
|
||||
|
||||
@@ -69,7 +69,7 @@ Discourse.Report = Discourse.Model.extend({
|
||||
Discourse.Report.reopenClass({
|
||||
find: function(type) {
|
||||
var model = Discourse.Report.create({type: type});
|
||||
$.ajax(Discourse.getURL("/admin/reports/") + type, {
|
||||
Discourse.ajax(Discourse.getURL("/admin/reports/") + type, {
|
||||
type: 'GET',
|
||||
success: function(json) {
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ Discourse.SiteCustomization = Discourse.Model.extend({
|
||||
header: this.header,
|
||||
override_default_style: this.override_default_style
|
||||
};
|
||||
return $.ajax({
|
||||
return Discourse.ajax({
|
||||
url: Discourse.getURL("/admin/site_customizations") + (this.id ? '/' + this.id : ''),
|
||||
data: {
|
||||
site_customization: data
|
||||
@@ -67,7 +67,7 @@ Discourse.SiteCustomization = Discourse.Model.extend({
|
||||
destroy: function() {
|
||||
if (!this.id) return;
|
||||
|
||||
return $.ajax({
|
||||
return Discourse.ajax({
|
||||
url: Discourse.getURL("/admin/site_customizations/") + this.id,
|
||||
type: 'DELETE'
|
||||
});
|
||||
@@ -93,7 +93,7 @@ Discourse.SiteCustomization.reopenClass({
|
||||
content: [],
|
||||
loading: true
|
||||
});
|
||||
$.ajax({
|
||||
Discourse.ajax({
|
||||
url: Discourse.getURL("/admin/site_customizations"),
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
|
||||
@@ -72,7 +72,7 @@ Discourse.SiteSetting = Discourse.Model.extend({
|
||||
save: function() {
|
||||
// Update the setting
|
||||
var setting = this;
|
||||
return $.ajax(Discourse.getURL("/admin/site_settings/") + (this.get('setting')), {
|
||||
return Discourse.ajax(Discourse.getURL("/admin/site_settings/") + (this.get('setting')), {
|
||||
data: { value: this.get('value') },
|
||||
type: 'PUT',
|
||||
success: function() {
|
||||
@@ -91,10 +91,10 @@ Discourse.SiteSetting.reopenClass({
|
||||
**/
|
||||
findAll: function() {
|
||||
var result = Em.A();
|
||||
$.get(Discourse.getURL("/admin/site_settings"), function(settings) {
|
||||
return settings.each(function(s) {
|
||||
Discourse.ajax({url: Discourse.getURL("/admin/site_settings")}).then(function (settings) {
|
||||
settings.each(function(s) {
|
||||
s.originalValue = s.value;
|
||||
return result.pushObject(Discourse.SiteSetting.create(s));
|
||||
result.pushObject(Discourse.SiteSetting.create(s));
|
||||
});
|
||||
});
|
||||
return result;
|
||||
|
||||
@@ -26,7 +26,7 @@ Discourse.VersionCheck = Discourse.Model.extend({
|
||||
|
||||
Discourse.VersionCheck.reopenClass({
|
||||
find: function() {
|
||||
return $.ajax({ url: Discourse.getURL('/admin/version_check'), dataType: 'json' }).then(function(json) {
|
||||
return Discourse.ajax({ url: Discourse.getURL('/admin/version_check'), dataType: 'json' }).then(function(json) {
|
||||
return Discourse.VersionCheck.create(json);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user