mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
REFACTOR: Remove Discourse.Ajax
This commit is contained in:
parent
56f07529bb
commit
b8125b3512
111 changed files with 567 additions and 549 deletions
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNames: ["ip-lookup"],
|
||||
|
@ -23,7 +24,7 @@ export default Ember.Component.extend({
|
|||
this.set("show", true);
|
||||
|
||||
if (!this.get("location")) {
|
||||
Discourse.ajax("/admin/users/ip-info", {
|
||||
ajax("/admin/users/ip-info", {
|
||||
data: { ip: this.get("ip") }
|
||||
}).then(function (location) {
|
||||
self.set("location", Em.Object.create(location));
|
||||
|
@ -39,7 +40,7 @@ export default Ember.Component.extend({
|
|||
"order": "trust_level DESC"
|
||||
};
|
||||
|
||||
Discourse.ajax("/admin/users/total-others-with-same-ip", { data }).then(function (result) {
|
||||
ajax("/admin/users/total-others-with-same-ip", { data }).then(function (result) {
|
||||
self.set("totalOthersWithSameIP", result.total);
|
||||
});
|
||||
|
||||
|
@ -67,7 +68,7 @@ export default Ember.Component.extend({
|
|||
totalOthersWithSameIP: null
|
||||
});
|
||||
|
||||
Discourse.ajax("/admin/users/delete-others-with-same-ip.json", {
|
||||
ajax("/admin/users/delete-others-with-same-ip.json", {
|
||||
type: "DELETE",
|
||||
data: {
|
||||
"ip": self.get("ip"),
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
export default Ember.ArrayController.extend({
|
||||
needs: ["adminBackups"],
|
||||
status: Ember.computed.alias("controllers.adminBackups"),
|
||||
|
@ -39,7 +40,7 @@ export default Ember.ArrayController.extend({
|
|||
|
||||
_toggleReadOnlyMode(enable) {
|
||||
var site = this.site;
|
||||
Discourse.ajax("/admin/backups/readonly", {
|
||||
ajax("/admin/backups/readonly", {
|
||||
type: "PUT",
|
||||
data: { enable: enable }
|
||||
}).then(function() {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
export default Ember.Controller.extend({
|
||||
|
||||
/**
|
||||
|
@ -29,7 +30,7 @@ export default Ember.Controller.extend({
|
|||
});
|
||||
|
||||
var self = this;
|
||||
Discourse.ajax("/admin/email/test", {
|
||||
ajax("/admin/email/test", {
|
||||
type: 'POST',
|
||||
data: { email_address: this.get('testEmailAddress') }
|
||||
}).then(function () {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
export default Ember.ArrayController.extend({
|
||||
sortProperties: ["name"],
|
||||
|
||||
|
@ -15,7 +16,7 @@ export default Ember.ArrayController.extend({
|
|||
I18n.t("yes_value"),
|
||||
function(destroy) {
|
||||
if (destroy) {
|
||||
return Discourse.ajax("/admin/customize/emojis/" + emoji.get("name"), { type: "DELETE" }).then(function() {
|
||||
return ajax("/admin/customize/emojis/" + emoji.get("name"), { type: "DELETE" }).then(function() {
|
||||
self.removeObject(emoji);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
|
@ -20,7 +21,7 @@ export default Ember.Controller.extend({
|
|||
.reject(x => x.length === 0);
|
||||
|
||||
this.set('saving', true);
|
||||
Discourse.ajax('/admin/groups/bulk', {
|
||||
ajax('/admin/groups/bulk', {
|
||||
data: { users, group_id: this.get('groupId') },
|
||||
method: 'PUT'
|
||||
}).then(() => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
export default Ember.ArrayController.extend({
|
||||
sortProperties: ['name'],
|
||||
refreshingAutoGroups: false,
|
||||
|
@ -9,7 +10,7 @@ export default Ember.ArrayController.extend({
|
|||
refreshAutoGroups: function(){
|
||||
var self = this;
|
||||
this.set('refreshingAutoGroups', true);
|
||||
Discourse.ajax('/admin/groups/refresh_automatic_groups', {type: 'POST'}).then(function() {
|
||||
ajax('/admin/groups/refresh_automatic_groups', {type: 'POST'}).then(function() {
|
||||
self.transitionToRoute("adminGroupsType", "automatic").then(function() {
|
||||
self.set('refreshingAutoGroups', false);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import CanCheckEmails from 'discourse/mixins/can-check-emails';
|
||||
import { propertyNotEqual, setting } from 'discourse/lib/computed';
|
||||
|
||||
|
@ -38,7 +39,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
saveTitle() {
|
||||
const self = this;
|
||||
|
||||
return Discourse.ajax("/users/" + this.get('model.username').toLowerCase(), {
|
||||
return ajax("/users/" + this.get('model.username').toLowerCase(), {
|
||||
data: {title: this.get('userTitleValue')},
|
||||
type: 'PUT'
|
||||
}).catch(function(e) {
|
||||
|
@ -68,7 +69,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
savePrimaryGroup() {
|
||||
const self = this;
|
||||
|
||||
return Discourse.ajax("/admin/users/" + this.get('model.id') + "/primary_group", {
|
||||
return ajax("/admin/users/" + this.get('model.id') + "/primary_group", {
|
||||
type: 'PUT',
|
||||
data: {primary_group_id: this.get('model.primary_group_id')}
|
||||
}).then(function () {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
export default Ember.Controller.extend({
|
||||
needs: ['modal'],
|
||||
|
||||
|
@ -57,7 +58,7 @@ export default Ember.Controller.extend({
|
|||
const groupIds = items.map(function(i){return i.get("id") || -1;});
|
||||
const names = items.map(function(i){return i.get("name");});
|
||||
|
||||
Discourse.ajax('/admin/badges/badge_groupings',{
|
||||
ajax('/admin/badges/badge_groupings',{
|
||||
data: {ids: groupIds, names: names},
|
||||
method: 'POST'
|
||||
}).then(function(data){
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
|
||||
const AdminDashboard = Discourse.Model.extend({});
|
||||
|
||||
|
@ -11,7 +12,7 @@ AdminDashboard.reopenClass({
|
|||
@return {jqXHR} a jQuery Promise object
|
||||
**/
|
||||
find: function() {
|
||||
return Discourse.ajax("/admin/dashboard.json").then(function(json) {
|
||||
return ajax("/admin/dashboard.json").then(function(json) {
|
||||
var model = AdminDashboard.create(json);
|
||||
model.set('loaded', true);
|
||||
return model;
|
||||
|
@ -26,7 +27,7 @@ AdminDashboard.reopenClass({
|
|||
@return {jqXHR} a jQuery Promise object
|
||||
**/
|
||||
fetchProblems: function() {
|
||||
return Discourse.ajax("/admin/dashboard/problems.json", {
|
||||
return ajax("/admin/dashboard/problems.json", {
|
||||
type: 'GET',
|
||||
dataType: 'json'
|
||||
}).then(function(json) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
import { propertyNotEqual } from 'discourse/lib/computed';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
@ -40,7 +41,7 @@ const AdminUser = Discourse.User.extend({
|
|||
canResetBounceScore: Ember.computed.gt("bounce_score", 0),
|
||||
|
||||
resetBounceScore() {
|
||||
return Discourse.ajax(`/admin/users/${this.get("id")}/reset_bounce_score`, {
|
||||
return ajax(`/admin/users/${this.get("id")}/reset_bounce_score`, {
|
||||
type: 'POST'
|
||||
}).then(() => this.setProperties({
|
||||
"bounce_score": 0,
|
||||
|
@ -50,7 +51,7 @@ const AdminUser = Discourse.User.extend({
|
|||
|
||||
generateApiKey() {
|
||||
const self = this;
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/generate_api_key", {
|
||||
return ajax("/admin/users/" + this.get('id') + "/generate_api_key", {
|
||||
type: 'POST'
|
||||
}).then(function (result) {
|
||||
const apiKey = ApiKey.create(result.api_key);
|
||||
|
@ -60,20 +61,20 @@ const AdminUser = Discourse.User.extend({
|
|||
},
|
||||
|
||||
groupAdded(added) {
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/groups", {
|
||||
return ajax("/admin/users/" + this.get('id') + "/groups", {
|
||||
type: 'POST',
|
||||
data: { group_id: added.id }
|
||||
}).then(() => this.get('groups').pushObject(added));
|
||||
},
|
||||
|
||||
groupRemoved(groupId) {
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/groups/" + groupId, {
|
||||
return ajax("/admin/users/" + this.get('id') + "/groups/" + groupId, {
|
||||
type: 'DELETE'
|
||||
}).then(() => this.set('groups.[]', this.get('groups').rejectBy("id", groupId)));
|
||||
},
|
||||
|
||||
revokeApiKey() {
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/revoke_api_key", {
|
||||
return ajax("/admin/users/" + this.get('id') + "/revoke_api_key", {
|
||||
type: 'DELETE'
|
||||
}).then(() => this.set('api_key', null));
|
||||
},
|
||||
|
@ -104,7 +105,7 @@ const AdminUser = Discourse.User.extend({
|
|||
"label": '<i class="fa fa-exclamation-triangle"></i> ' + I18n.t("admin.user.delete_all_posts"),
|
||||
"class": "btn btn-danger",
|
||||
"callback": function() {
|
||||
Discourse.ajax("/admin/users/" + user.get('id') + "/delete_all_posts", {
|
||||
ajax("/admin/users/" + user.get('id') + "/delete_all_posts", {
|
||||
type: 'PUT'
|
||||
}).then(() => user.set('post_count', 0));
|
||||
}
|
||||
|
@ -114,7 +115,7 @@ const AdminUser = Discourse.User.extend({
|
|||
|
||||
revokeAdmin() {
|
||||
const self = this;
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/revoke_admin", {
|
||||
return ajax("/admin/users/" + this.get('id') + "/revoke_admin", {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
self.setProperties({
|
||||
|
@ -127,7 +128,7 @@ const AdminUser = Discourse.User.extend({
|
|||
|
||||
grantAdmin() {
|
||||
const self = this;
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/grant_admin", {
|
||||
return ajax("/admin/users/" + this.get('id') + "/grant_admin", {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
self.setProperties({
|
||||
|
@ -140,7 +141,7 @@ const AdminUser = Discourse.User.extend({
|
|||
|
||||
revokeModeration() {
|
||||
const self = this;
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/revoke_moderation", {
|
||||
return ajax("/admin/users/" + this.get('id') + "/revoke_moderation", {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
self.setProperties({
|
||||
|
@ -153,7 +154,7 @@ const AdminUser = Discourse.User.extend({
|
|||
|
||||
grantModeration() {
|
||||
const self = this;
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/grant_moderation", {
|
||||
return ajax("/admin/users/" + this.get('id') + "/grant_moderation", {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
self.setProperties({
|
||||
|
@ -165,14 +166,14 @@ const AdminUser = Discourse.User.extend({
|
|||
},
|
||||
|
||||
refreshBrowsers() {
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/refresh_browsers", {
|
||||
return ajax("/admin/users/" + this.get('id') + "/refresh_browsers", {
|
||||
type: 'POST'
|
||||
}).finally(() => bootbox.alert(I18n.t("admin.user.refresh_browsers_message")));
|
||||
},
|
||||
|
||||
approve() {
|
||||
const self = this;
|
||||
return Discourse.ajax("/admin/users/" + this.get('id') + "/approve", {
|
||||
return ajax("/admin/users/" + this.get('id') + "/approve", {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
self.setProperties({
|
||||
|
@ -190,7 +191,7 @@ const AdminUser = Discourse.User.extend({
|
|||
dirty: propertyNotEqual('originalTrustLevel', 'trustLevel.id'),
|
||||
|
||||
saveTrustLevel() {
|
||||
return Discourse.ajax("/admin/users/" + this.id + "/trust_level", {
|
||||
return ajax("/admin/users/" + this.id + "/trust_level", {
|
||||
type: 'PUT',
|
||||
data: { level: this.get('trustLevel.id') }
|
||||
}).then(function() {
|
||||
|
@ -210,7 +211,7 @@ const AdminUser = Discourse.User.extend({
|
|||
},
|
||||
|
||||
lockTrustLevel(locked) {
|
||||
return Discourse.ajax("/admin/users/" + this.id + "/trust_level_lock", {
|
||||
return ajax("/admin/users/" + this.id + "/trust_level_lock", {
|
||||
type: 'PUT',
|
||||
data: { locked: !!locked }
|
||||
}).then(function() {
|
||||
|
@ -239,14 +240,14 @@ const AdminUser = Discourse.User.extend({
|
|||
}.property('suspended_till', 'suspended_at'),
|
||||
|
||||
suspend(duration, reason) {
|
||||
return Discourse.ajax("/admin/users/" + this.id + "/suspend", {
|
||||
return ajax("/admin/users/" + this.id + "/suspend", {
|
||||
type: 'PUT',
|
||||
data: { duration: duration, reason: reason }
|
||||
});
|
||||
},
|
||||
|
||||
unsuspend() {
|
||||
return Discourse.ajax("/admin/users/" + this.id + "/unsuspend", {
|
||||
return ajax("/admin/users/" + this.id + "/unsuspend", {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
window.location.reload();
|
||||
|
@ -257,7 +258,7 @@ const AdminUser = Discourse.User.extend({
|
|||
},
|
||||
|
||||
log_out() {
|
||||
return Discourse.ajax("/admin/users/" + this.id + "/log_out", {
|
||||
return ajax("/admin/users/" + this.id + "/log_out", {
|
||||
type: 'POST',
|
||||
data: { username_or_email: this.get('username') }
|
||||
}).then(function() {
|
||||
|
@ -266,7 +267,7 @@ const AdminUser = Discourse.User.extend({
|
|||
},
|
||||
|
||||
impersonate() {
|
||||
return Discourse.ajax("/admin/impersonate", {
|
||||
return ajax("/admin/impersonate", {
|
||||
type: 'POST',
|
||||
data: { username_or_email: this.get('username') }
|
||||
}).then(function() {
|
||||
|
@ -281,7 +282,7 @@ const AdminUser = Discourse.User.extend({
|
|||
},
|
||||
|
||||
activate() {
|
||||
return Discourse.ajax('/admin/users/' + this.id + '/activate', {
|
||||
return ajax('/admin/users/' + this.id + '/activate', {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
window.location.reload();
|
||||
|
@ -292,7 +293,7 @@ const AdminUser = Discourse.User.extend({
|
|||
},
|
||||
|
||||
deactivate() {
|
||||
return Discourse.ajax('/admin/users/' + this.id + '/deactivate', {
|
||||
return ajax('/admin/users/' + this.id + '/deactivate', {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
window.location.reload();
|
||||
|
@ -304,7 +305,7 @@ const AdminUser = Discourse.User.extend({
|
|||
|
||||
unblock() {
|
||||
this.set('blockingUser', true);
|
||||
return Discourse.ajax('/admin/users/' + this.id + '/unblock', {
|
||||
return ajax('/admin/users/' + this.id + '/unblock', {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
window.location.reload();
|
||||
|
@ -320,7 +321,7 @@ const AdminUser = Discourse.User.extend({
|
|||
|
||||
const performBlock = function() {
|
||||
user.set('blockingUser', true);
|
||||
return Discourse.ajax('/admin/users/' + user.id + '/block', {
|
||||
return ajax('/admin/users/' + user.id + '/block', {
|
||||
type: 'PUT'
|
||||
}).then(function() {
|
||||
window.location.reload();
|
||||
|
@ -345,7 +346,7 @@ const AdminUser = Discourse.User.extend({
|
|||
},
|
||||
|
||||
sendActivationEmail() {
|
||||
return Discourse.ajax('/users/action/send_activation_email', {
|
||||
return ajax('/users/action/send_activation_email', {
|
||||
type: 'POST',
|
||||
data: { username: this.get('username') }
|
||||
}).then(function() {
|
||||
|
@ -360,7 +361,7 @@ const AdminUser = Discourse.User.extend({
|
|||
message = I18n.t("admin.user.anonymize_confirm");
|
||||
|
||||
const performAnonymize = function() {
|
||||
return Discourse.ajax("/admin/users/" + user.get('id') + '/anonymize.json', {
|
||||
return ajax("/admin/users/" + user.get('id') + '/anonymize.json', {
|
||||
type: 'PUT'
|
||||
}).then(function(data) {
|
||||
if (data.success) {
|
||||
|
@ -422,7 +423,7 @@ const AdminUser = Discourse.User.extend({
|
|||
if (opts && opts.deletePosts) {
|
||||
formData["delete_posts"] = true;
|
||||
}
|
||||
return Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
||||
return ajax("/admin/users/" + user.get('id') + '.json', {
|
||||
type: 'DELETE',
|
||||
data: formData
|
||||
}).then(function(data) {
|
||||
|
@ -481,7 +482,7 @@ const AdminUser = Discourse.User.extend({
|
|||
"label": '<i class="fa fa-exclamation-triangle"></i> ' + I18n.t("flagging.yes_delete_spammer"),
|
||||
"class": "btn btn-danger",
|
||||
"callback": function() {
|
||||
return Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
||||
return ajax("/admin/users/" + user.get('id') + '.json', {
|
||||
type: 'DELETE',
|
||||
data: {
|
||||
delete_posts: true,
|
||||
|
@ -549,7 +550,7 @@ AdminUser.reopenClass({
|
|||
});
|
||||
});
|
||||
|
||||
return Discourse.ajax("/admin/users/approve-bulk", {
|
||||
return ajax("/admin/users/approve-bulk", {
|
||||
type: 'PUT',
|
||||
data: { users: users.map((u) => u.id) }
|
||||
}).finally(() => bootbox.alert(I18n.t("admin.user.approve_bulk_success")));
|
||||
|
@ -561,7 +562,7 @@ AdminUser.reopenClass({
|
|||
user.set('selected', false);
|
||||
});
|
||||
|
||||
return Discourse.ajax("/admin/users/reject-bulk", {
|
||||
return ajax("/admin/users/reject-bulk", {
|
||||
type: 'DELETE',
|
||||
data: {
|
||||
users: users.map((u) => u.id),
|
||||
|
@ -571,14 +572,14 @@ AdminUser.reopenClass({
|
|||
},
|
||||
|
||||
find(user_id) {
|
||||
return Discourse.ajax("/admin/users/" + user_id + ".json").then(result => {
|
||||
return ajax("/admin/users/" + user_id + ".json").then(result => {
|
||||
result.loadedDetails = true;
|
||||
return AdminUser.create(result);
|
||||
});
|
||||
},
|
||||
|
||||
findAll(query, filter) {
|
||||
return Discourse.ajax("/admin/users/list/" + query + ".json", {
|
||||
return ajax("/admin/users/list/" + query + ".json", {
|
||||
data: filter
|
||||
}).then(function(users) {
|
||||
return users.map((u) => AdminUser.create(u));
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const ApiKey = Discourse.Model.extend({
|
||||
|
||||
/**
|
||||
|
@ -8,7 +9,7 @@ const ApiKey = Discourse.Model.extend({
|
|||
**/
|
||||
regenerate: function() {
|
||||
var self = this;
|
||||
return Discourse.ajax('/admin/api/key', {type: 'PUT', data: {id: this.get('id')}}).then(function (result) {
|
||||
return ajax('/admin/api/key', {type: 'PUT', data: {id: this.get('id')}}).then(function (result) {
|
||||
self.set('key', result.api_key.key);
|
||||
return self;
|
||||
});
|
||||
|
@ -21,7 +22,7 @@ const ApiKey = Discourse.Model.extend({
|
|||
@returns {Promise} a promise that resolves when the key has been revoked
|
||||
**/
|
||||
revoke: function() {
|
||||
return Discourse.ajax('/admin/api/key', {type: 'DELETE', data: {id: this.get('id')}});
|
||||
return ajax('/admin/api/key', {type: 'DELETE', data: {id: this.get('id')}});
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -51,7 +52,7 @@ ApiKey.reopenClass({
|
|||
@returns {Promise} a promise that resolves to the array of `ApiKey` instances
|
||||
**/
|
||||
find: function() {
|
||||
return Discourse.ajax("/admin/api").then(function(keys) {
|
||||
return ajax("/admin/api").then(function(keys) {
|
||||
return keys.map(function (key) {
|
||||
return ApiKey.create(key);
|
||||
});
|
||||
|
@ -65,7 +66,7 @@ ApiKey.reopenClass({
|
|||
@returns {Promise} a promise that resolves to a master `ApiKey`
|
||||
**/
|
||||
generateMasterKey: function() {
|
||||
return Discourse.ajax("/admin/api/key", {type: 'POST'}).then(function (result) {
|
||||
return ajax("/admin/api/key", {type: 'POST'}).then(function (result) {
|
||||
return ApiKey.create(result.api_key);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const Backup = Discourse.Model.extend({
|
||||
|
||||
destroy() {
|
||||
return Discourse.ajax("/admin/backups/" + this.get("filename"), { type: "DELETE" });
|
||||
return ajax("/admin/backups/" + this.get("filename"), { type: "DELETE" });
|
||||
},
|
||||
|
||||
restore() {
|
||||
return Discourse.ajax("/admin/backups/" + this.get("filename") + "/restore", {
|
||||
return ajax("/admin/backups/" + this.get("filename") + "/restore", {
|
||||
type: "POST",
|
||||
data: { client_id: window.MessageBus.clientId }
|
||||
});
|
||||
|
@ -16,13 +17,13 @@ const Backup = Discourse.Model.extend({
|
|||
Backup.reopenClass({
|
||||
|
||||
find() {
|
||||
return PreloadStore.getAndRemove("backups", () => Discourse.ajax("/admin/backups.json"))
|
||||
return PreloadStore.getAndRemove("backups", () => ajax("/admin/backups.json"))
|
||||
.then(backups => backups.map(backup => Backup.create(backup)));
|
||||
},
|
||||
|
||||
start(withUploads) {
|
||||
if (withUploads === undefined) { withUploads = true; }
|
||||
return Discourse.ajax("/admin/backups", {
|
||||
return ajax("/admin/backups", {
|
||||
type: "POST",
|
||||
data: {
|
||||
with_uploads: withUploads,
|
||||
|
@ -34,14 +35,14 @@ Backup.reopenClass({
|
|||
},
|
||||
|
||||
cancel() {
|
||||
return Discourse.ajax("/admin/backups/cancel.json")
|
||||
return ajax("/admin/backups/cancel.json")
|
||||
.then(result => {
|
||||
if (!result.success) { bootbox.alert(result.message); }
|
||||
});
|
||||
},
|
||||
|
||||
rollback() {
|
||||
return Discourse.ajax("/admin/backups/rollback.json")
|
||||
return ajax("/admin/backups/rollback.json")
|
||||
.then(result => {
|
||||
if (!result.success) {
|
||||
bootbox.alert(result.message);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import ColorSchemeColor from 'admin/models/color-scheme-color';
|
||||
|
||||
const ColorScheme = Discourse.Model.extend(Ember.Copyable, {
|
||||
|
@ -65,7 +66,7 @@ const ColorScheme = Discourse.Model.extend(Ember.Copyable, {
|
|||
});
|
||||
}
|
||||
|
||||
return Discourse.ajax("/admin/color_schemes" + (this.id ? '/' + this.id : '') + '.json', {
|
||||
return ajax("/admin/color_schemes" + (this.id ? '/' + this.id : '') + '.json', {
|
||||
data: JSON.stringify({"color_scheme": data}),
|
||||
type: this.id ? 'PUT' : 'POST',
|
||||
dataType: 'json',
|
||||
|
@ -88,7 +89,7 @@ const ColorScheme = Discourse.Model.extend(Ember.Copyable, {
|
|||
|
||||
destroy: function() {
|
||||
if (this.id) {
|
||||
return Discourse.ajax("/admin/color_schemes/" + this.id, { type: 'DELETE' });
|
||||
return ajax("/admin/color_schemes/" + this.id, { type: 'DELETE' });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +107,7 @@ var ColorSchemes = Ember.ArrayProxy.extend({
|
|||
ColorScheme.reopenClass({
|
||||
findAll: function() {
|
||||
var colorSchemes = ColorSchemes.create({ content: [], loading: true });
|
||||
Discourse.ajax('/admin/color_schemes').then(function(all) {
|
||||
ajax('/admin/color_schemes').then(function(all) {
|
||||
_.each(all, function(colorScheme){
|
||||
colorSchemes.pushObject(ColorScheme.create({
|
||||
id: colorScheme.id,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import AdminUser from 'admin/models/admin-user';
|
||||
|
||||
const EmailLog = Discourse.Model.extend({});
|
||||
|
@ -21,7 +22,7 @@ EmailLog.reopenClass({
|
|||
const status = filter.status || "sent";
|
||||
filter = _.omit(filter, "status");
|
||||
|
||||
return Discourse.ajax(`/admin/email/${status}.json?offset=${offset}`, { data: filter })
|
||||
return ajax(`/admin/email/${status}.json?offset=${offset}`, { data: filter })
|
||||
.then(logs => _.map(logs, log => EmailLog.create(log)));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const EmailPreview = Discourse.Model.extend({});
|
||||
|
||||
EmailPreview.reopenClass({
|
||||
|
@ -11,7 +12,7 @@ EmailPreview.reopenClass({
|
|||
username = Discourse.User.current().username;
|
||||
}
|
||||
|
||||
return Discourse.ajax("/admin/email/preview-digest.json", {
|
||||
return ajax("/admin/email/preview-digest.json", {
|
||||
data: { last_seen_at: lastSeenAt, username: username }
|
||||
}).then(function (result) {
|
||||
return EmailPreview.create(result);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const EmailSettings = Discourse.Model.extend({});
|
||||
|
||||
EmailSettings.reopenClass({
|
||||
find: function() {
|
||||
return Discourse.ajax("/admin/email.json").then(function (settings) {
|
||||
return ajax("/admin/email.json").then(function (settings) {
|
||||
return EmailSettings.create(settings);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
const { getProperties } = Ember;
|
||||
|
||||
export default RestModel.extend({
|
||||
revert() {
|
||||
return Discourse.ajax(`/admin/customize/email_templates/${this.get('id')}`, {
|
||||
return ajax(`/admin/customize/email_templates/${this.get('id')}`, {
|
||||
method: 'DELETE'
|
||||
}).then(result => getProperties(result.email_template, 'subject', 'body', 'can_revert'));
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import AdminUser from 'admin/models/admin-user';
|
||||
import Topic from 'discourse/models/topic';
|
||||
import Post from 'discourse/models/post';
|
||||
|
@ -106,22 +107,22 @@ const FlaggedPost = Post.extend({
|
|||
|
||||
deletePost: function() {
|
||||
if (this.get('post_number') === 1) {
|
||||
return Discourse.ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false });
|
||||
return ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false });
|
||||
} else {
|
||||
return Discourse.ajax('/posts/' + this.id, { type: 'DELETE', cache: false });
|
||||
return ajax('/posts/' + this.id, { type: 'DELETE', cache: false });
|
||||
}
|
||||
},
|
||||
|
||||
disagreeFlags: function () {
|
||||
return Discourse.ajax('/admin/flags/disagree/' + this.id, { type: 'POST', cache: false });
|
||||
return ajax('/admin/flags/disagree/' + this.id, { type: 'POST', cache: false });
|
||||
},
|
||||
|
||||
deferFlags: function (deletePost) {
|
||||
return Discourse.ajax('/admin/flags/defer/' + this.id, { type: 'POST', cache: false, data: { delete_post: deletePost } });
|
||||
return ajax('/admin/flags/defer/' + this.id, { type: 'POST', cache: false, data: { delete_post: deletePost } });
|
||||
},
|
||||
|
||||
agreeFlags: function (actionOnPost) {
|
||||
return Discourse.ajax('/admin/flags/agree/' + this.id, { type: 'POST', cache: false, data: { action_on_post: actionOnPost } });
|
||||
return ajax('/admin/flags/agree/' + this.id, { type: 'POST', cache: false, data: { action_on_post: actionOnPost } });
|
||||
},
|
||||
|
||||
postHidden: Em.computed.alias('hidden'),
|
||||
|
@ -144,7 +145,7 @@ FlaggedPost.reopenClass({
|
|||
var result = Em.A();
|
||||
result.set('loading', true);
|
||||
|
||||
return Discourse.ajax('/admin/flags/' + filter + '.json?offset=' + offset).then(function (data) {
|
||||
return ajax('/admin/flags/' + filter + '.json?offset=' + offset).then(function (data) {
|
||||
// users
|
||||
var userLookup = {};
|
||||
_.each(data.users, function (user) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import AdminUser from 'admin/models/admin-user';
|
||||
|
||||
const IncomingEmail = Discourse.Model.extend({});
|
||||
|
@ -15,7 +16,7 @@ IncomingEmail.reopenClass({
|
|||
},
|
||||
|
||||
find(id) {
|
||||
return Discourse.ajax(`/admin/email/incoming/${id}.json`);
|
||||
return ajax(`/admin/email/incoming/${id}.json`);
|
||||
},
|
||||
|
||||
findAll(filter, offset) {
|
||||
|
@ -25,12 +26,12 @@ IncomingEmail.reopenClass({
|
|||
const status = filter.status || "received";
|
||||
filter = _.omit(filter, "status");
|
||||
|
||||
return Discourse.ajax(`/admin/email/${status}.json?offset=${offset}`, { data: filter })
|
||||
return ajax(`/admin/email/${status}.json?offset=${offset}`, { data: filter })
|
||||
.then(incomings => _.map(incomings, incoming => IncomingEmail.create(incoming)));
|
||||
},
|
||||
|
||||
loadRawEmail(id) {
|
||||
return Discourse.ajax(`/admin/email/incoming/${id}/raw.json`);
|
||||
return ajax(`/admin/email/incoming/${id}/raw.json`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const Permalink = Discourse.Model.extend({
|
||||
save: function() {
|
||||
return Discourse.ajax("/admin/permalinks.json", {
|
||||
return ajax("/admin/permalinks.json", {
|
||||
type: 'POST',
|
||||
data: {url: this.get('url'), permalink_type: this.get('permalink_type'), permalink_type_value: this.get('permalink_type_value')}
|
||||
});
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
return Discourse.ajax("/admin/permalinks/" + this.get('id') + ".json", {type: 'DELETE'});
|
||||
return ajax("/admin/permalinks/" + this.get('id') + ".json", {type: 'DELETE'});
|
||||
}
|
||||
});
|
||||
|
||||
Permalink.reopenClass({
|
||||
findAll: function(filter) {
|
||||
return Discourse.ajax("/admin/permalinks.json", { data: { filter: filter } }).then(function(permalinks) {
|
||||
return ajax("/admin/permalinks.json", { data: { filter: filter } }).then(function(permalinks) {
|
||||
return permalinks.map(p => Permalink.create(p));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import round from "discourse/lib/round";
|
||||
import { fmt } from 'discourse/lib/computed';
|
||||
|
||||
|
@ -132,7 +133,7 @@ const Report = Discourse.Model.extend({
|
|||
Report.reopenClass({
|
||||
|
||||
find(type, startDate, endDate, categoryId, groupId) {
|
||||
return Discourse.ajax("/admin/reports/" + type, {
|
||||
return ajax("/admin/reports/" + type, {
|
||||
data: {
|
||||
start_date: startDate,
|
||||
end_date: endDate,
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const ScreenedEmail = Discourse.Model.extend({
|
||||
actionName: function() {
|
||||
return I18n.t("admin.logs.screened_actions." + this.get('action'));
|
||||
}.property('action'),
|
||||
|
||||
clearBlock: function() {
|
||||
return Discourse.ajax('/admin/logs/screened_emails/' + this.get('id'), {method: 'DELETE'});
|
||||
return ajax('/admin/logs/screened_emails/' + this.get('id'), {method: 'DELETE'});
|
||||
}
|
||||
});
|
||||
|
||||
ScreenedEmail.reopenClass({
|
||||
findAll: function() {
|
||||
return Discourse.ajax("/admin/logs/screened_emails.json").then(function(screened_emails) {
|
||||
return ajax("/admin/logs/screened_emails.json").then(function(screened_emails) {
|
||||
return screened_emails.map(function(b) {
|
||||
return ScreenedEmail.create(b);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
const ScreenedIpAddress = Discourse.Model.extend({
|
||||
|
@ -14,25 +15,25 @@ const ScreenedIpAddress = Discourse.Model.extend({
|
|||
},
|
||||
|
||||
save() {
|
||||
return Discourse.ajax("/admin/logs/screened_ip_addresses" + (this.id ? '/' + this.id : '') + ".json", {
|
||||
return ajax("/admin/logs/screened_ip_addresses" + (this.id ? '/' + this.id : '') + ".json", {
|
||||
type: this.id ? 'PUT' : 'POST',
|
||||
data: {ip_address: this.get('ip_address'), action_name: this.get('action_name')}
|
||||
});
|
||||
},
|
||||
|
||||
destroy() {
|
||||
return Discourse.ajax("/admin/logs/screened_ip_addresses/" + this.get('id') + ".json", {type: 'DELETE'});
|
||||
return ajax("/admin/logs/screened_ip_addresses/" + this.get('id') + ".json", {type: 'DELETE'});
|
||||
}
|
||||
});
|
||||
|
||||
ScreenedIpAddress.reopenClass({
|
||||
findAll(filter) {
|
||||
return Discourse.ajax("/admin/logs/screened_ip_addresses.json", { data: { filter: filter } })
|
||||
return ajax("/admin/logs/screened_ip_addresses.json", { data: { filter: filter } })
|
||||
.then(screened_ips => screened_ips.map(b => ScreenedIpAddress.create(b)));
|
||||
},
|
||||
|
||||
rollUp() {
|
||||
return Discourse.ajax("/admin/logs/screened_ip_addresses/roll_up", { type: "POST" });
|
||||
return ajax("/admin/logs/screened_ip_addresses/roll_up", { type: "POST" });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const ScreenedUrl = Discourse.Model.extend({
|
||||
actionName: function() {
|
||||
return I18n.t("admin.logs.screened_actions." + this.get('action'));
|
||||
|
@ -6,7 +7,7 @@ const ScreenedUrl = Discourse.Model.extend({
|
|||
|
||||
ScreenedUrl.reopenClass({
|
||||
findAll: function() {
|
||||
return Discourse.ajax("/admin/logs/screened_urls.json").then(function(screened_urls) {
|
||||
return ajax("/admin/logs/screened_urls.json").then(function(screened_urls) {
|
||||
return screened_urls.map(function(b) {
|
||||
return ScreenedUrl.create(b);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const SiteSetting = Discourse.Model.extend({
|
||||
overridden: function() {
|
||||
let val = this.get('value'),
|
||||
|
@ -28,7 +29,7 @@ const SiteSetting = Discourse.Model.extend({
|
|||
|
||||
SiteSetting.reopenClass({
|
||||
findAll() {
|
||||
return Discourse.ajax("/admin/site_settings").then(function (settings) {
|
||||
return ajax("/admin/site_settings").then(function (settings) {
|
||||
// Group the results by category
|
||||
const categories = {};
|
||||
settings.site_settings.forEach(function(s) {
|
||||
|
@ -47,7 +48,7 @@ SiteSetting.reopenClass({
|
|||
update(key, value) {
|
||||
const data = {};
|
||||
data[key] = value;
|
||||
return Discourse.ajax("/admin/site_settings/" + key, { type: 'PUT', data });
|
||||
return ajax("/admin/site_settings/" + key, { type: 'PUT', data });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
const { getProperties } = Ember;
|
||||
|
||||
export default RestModel.extend({
|
||||
revert() {
|
||||
return Discourse.ajax(`/admin/customize/site_texts/${this.get('id')}`, {
|
||||
return ajax(`/admin/customize/site_texts/${this.get('id')}`, {
|
||||
method: 'DELETE'
|
||||
}).then(result => getProperties(result.site_text, 'value', 'can_revert'));
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import AdminUser from 'admin/models/admin-user';
|
||||
import { escapeExpression } from 'discourse/lib/utilities';
|
||||
|
||||
|
@ -56,7 +57,7 @@ StaffActionLog.reopenClass({
|
|||
},
|
||||
|
||||
findAll: function(filters) {
|
||||
return Discourse.ajax("/admin/logs/staff_action_logs.json", { data: filters }).then(function(staff_actions) {
|
||||
return ajax("/admin/logs/staff_action_logs.json", { data: filters }).then(function(staff_actions) {
|
||||
return staff_actions.map(function(s) {
|
||||
return StaffActionLog.create(s);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const VersionCheck = Discourse.Model.extend({
|
||||
|
||||
noCheckPerformed: function() {
|
||||
|
@ -33,7 +34,7 @@ const VersionCheck = Discourse.Model.extend({
|
|||
|
||||
VersionCheck.reopenClass({
|
||||
find: function() {
|
||||
return Discourse.ajax('/admin/version_check').then(function(json) {
|
||||
return ajax('/admin/version_check').then(function(json) {
|
||||
return VersionCheck.create(json);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
import BackupStatus from 'admin/models/backup-status';
|
||||
import Backup from 'admin/models/backup';
|
||||
|
@ -31,7 +32,7 @@ export default Discourse.Route.extend({
|
|||
|
||||
model() {
|
||||
return PreloadStore.getAndRemove("operations_status", function() {
|
||||
return Discourse.ajax("/admin/backups/status.json");
|
||||
return ajax("/admin/backups/status.json");
|
||||
}).then(status => {
|
||||
return BackupStatus.create({
|
||||
isOperationRunning: status.is_operation_running,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import Badge from 'discourse/models/badge';
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
|
||||
|
@ -31,7 +32,7 @@ export default Ember.Route.extend({
|
|||
|
||||
preview(badge, explain) {
|
||||
badge.set('preview_loading', true);
|
||||
Discourse.ajax('/admin/badges/preview.json', {
|
||||
ajax('/admin/badges/preview.json', {
|
||||
method: 'post',
|
||||
data: {
|
||||
sql: badge.get('query'),
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import Badge from 'discourse/models/badge';
|
||||
import BadgeGrouping from 'discourse/models/badge-grouping';
|
||||
|
||||
|
@ -6,7 +7,7 @@ export default Discourse.Route.extend({
|
|||
|
||||
model: function() {
|
||||
var self = this;
|
||||
return Discourse.ajax('/admin/badges.json').then(function(json) {
|
||||
return ajax('/admin/badges.json').then(function(json) {
|
||||
self._json = json;
|
||||
return Badge.createFromJson(json);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
export default Discourse.Route.extend({
|
||||
model: function() {
|
||||
return Discourse.ajax("/admin/customize/emojis.json").then(function(emojis) {
|
||||
return ajax("/admin/customize/emojis.json").then(function(emojis) {
|
||||
return emojis.map(function (emoji) { return Ember.Object.create(emoji); });
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ define('ember', ['exports'], function(__exports__) {
|
|||
|
||||
var _pluginCallbacks = [];
|
||||
|
||||
window.Discourse = Ember.Application.extend(Discourse.Ajax, {
|
||||
window.Discourse = Ember.Application.extend({
|
||||
rootElement: '#main',
|
||||
_docTitle: document.title,
|
||||
__TAGS_INCLUDED__: true,
|
||||
|
@ -179,6 +179,12 @@ window.Discourse = Ember.Application.extend(Discourse.Ajax, {
|
|||
})
|
||||
}).create();
|
||||
|
||||
Discourse.ajax = function() {
|
||||
var ajax = require('discourse/lib/ajax').ajax;
|
||||
Ember.warn("Discourse.ajax is deprecated. Import the module and use it instead");
|
||||
return ajax.apply(this, arguments);
|
||||
};
|
||||
|
||||
Discourse.Markdown = {
|
||||
whiteListTag: Ember.K,
|
||||
whiteListIframe: Ember.K
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestAdapter from 'discourse/adapters/rest';
|
||||
|
||||
export default RestAdapter.extend({
|
||||
find(store, type, findArgs) {
|
||||
const maxReplies = Discourse.SiteSettings.max_reply_history;
|
||||
return Discourse.ajax(`/posts/${findArgs.postId}/reply-history?max_replies=${maxReplies}`).then(replies => {
|
||||
return ajax(`/posts/${findArgs.postId}/reply-history?max_replies=${maxReplies}`).then(replies => {
|
||||
return { post_reply_histories: replies };
|
||||
});
|
||||
},
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestAdapter from 'discourse/adapters/rest';
|
||||
|
||||
export default RestAdapter.extend({
|
||||
find(store, type, findArgs) {
|
||||
return Discourse.ajax(`/posts/${findArgs.postId}/replies`).then(replies => {
|
||||
return ajax(`/posts/${findArgs.postId}/replies`).then(replies => {
|
||||
return { post_replies: replies };
|
||||
});
|
||||
},
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestAdapter from 'discourse/adapters/rest';
|
||||
import { Result } from 'discourse/adapters/rest';
|
||||
|
||||
|
@ -12,7 +13,7 @@ export default RestAdapter.extend({
|
|||
createRecord(store, type, args) {
|
||||
const typeField = Ember.String.underscore(type);
|
||||
args.nested_post = true;
|
||||
return Discourse.ajax(this.pathFor(store, type), { method: 'POST', data: args }).then(function (json) {
|
||||
return ajax(this.pathFor(store, type), { method: 'POST', data: args }).then(function (json) {
|
||||
return new Result(json[typeField], json);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { hashString } from 'discourse/lib/hash';
|
||||
|
||||
const ADMIN_MODELS = ['plugin', 'site-customization', 'embeddable-host'];
|
||||
|
@ -9,8 +10,6 @@ export function Result(payload, responseJson) {
|
|||
this.target = null;
|
||||
}
|
||||
|
||||
const ajax = Discourse.ajax;
|
||||
|
||||
// We use this to make sure 404s are caught
|
||||
function rethrow(error) {
|
||||
if (error.status === 404) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestAdapter from 'discourse/adapters/rest';
|
||||
|
||||
export function finderFor(filter, params) {
|
||||
|
@ -19,7 +20,7 @@ export function finderFor(filter, params) {
|
|||
url += "?" + encoded.join('&');
|
||||
}
|
||||
}
|
||||
return Discourse.ajax(url);
|
||||
return ajax(url);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestAdapter from 'discourse/adapters/rest';
|
||||
|
||||
export default RestAdapter.extend({
|
||||
find(store, type, findArgs) {
|
||||
if (findArgs.similar) {
|
||||
return Discourse.ajax("/topics/similar_to", { data: findArgs.similar });
|
||||
return ajax("/topics/similar_to", { data: findArgs.similar });
|
||||
} else {
|
||||
return this._super(store, type, findArgs);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import { linkSeenMentions, fetchUnseenMentions } from 'discourse/lib/link-mentio
|
|||
import { linkSeenCategoryHashtags, fetchUnseenCategoryHashtags } from 'discourse/lib/link-category-hashtags';
|
||||
import { fetchUnseenTagHashtags, linkSeenTagHashtags } from 'discourse/lib/link-tag-hashtag';
|
||||
import { load } from 'pretty-text/oneboxer';
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import InputValidation from 'discourse/models/input-validation';
|
||||
|
||||
import { tinyAvatar,
|
||||
|
@ -499,7 +500,7 @@ export default Ember.Component.extend({
|
|||
}
|
||||
|
||||
// Paint oneboxes
|
||||
$('a.onebox', $preview).each((i, e) => load(e, refresh));
|
||||
$('a.onebox', $preview).each((i, e) => load(e, refresh, ajax));
|
||||
this.trigger('previewRefreshed', $preview);
|
||||
this.sendAction('afterRefresh', $preview);
|
||||
},
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import debounce from 'discourse/lib/debounce';
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
import { setting } from 'discourse/lib/computed';
|
||||
|
@ -336,7 +337,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
|
||||
@on('init')
|
||||
fetchConfirmationValue() {
|
||||
return Discourse.ajax('/users/hp.json').then(json => {
|
||||
return ajax('/users/hp.json').then(json => {
|
||||
this.set('accountPasswordConfirm', json.value);
|
||||
this.set('accountChallenge', json.challenge.split("").reverse().join(""));
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { observes } from "ember-addons/ember-computed-decorators";
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
|
||||
|
@ -32,7 +33,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
setAutoClose(time) {
|
||||
const self = this;
|
||||
this.set('loading', true);
|
||||
Discourse.ajax({
|
||||
ajax({
|
||||
url: `/t/${this.get('model.id')}/autoclose`,
|
||||
type: 'PUT',
|
||||
dataType: 'json',
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
import { categoryLinkHTML } from 'discourse/helpers/category-link';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
@ -91,7 +92,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
onShow() {
|
||||
this.set("loading", true);
|
||||
|
||||
return Discourse.ajax("/topics/feature_stats.json", {
|
||||
return ajax("/topics/feature_stats.json", {
|
||||
data: { category_id: this.get("model.category.id") }
|
||||
}).then(result => {
|
||||
if (result) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
import { escapeExpression } from 'discourse/lib/utilities';
|
||||
|
||||
|
@ -49,7 +50,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
self.flash(e.responseJSON.errors[0], 'error');
|
||||
};
|
||||
|
||||
Discourse.ajax('/session/forgot_password', {
|
||||
ajax('/session/forgot_password', {
|
||||
data: { login: this.get('accountEmailOrUsername').trim() },
|
||||
type: 'POST'
|
||||
}).then(success, fail).finally(function(){
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { translateResults, searchContextDescription, getSearchKey, isValidSearchTerm } from "discourse/lib/search";
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||
|
@ -157,7 +158,7 @@ export default Ember.Controller.extend({
|
|||
|
||||
const searchKey = getSearchKey(args);
|
||||
|
||||
Discourse.ajax("/search", { data: args }).then(results => {
|
||||
ajax("/search", { data: args }).then(results => {
|
||||
const model = translateResults(results) || {};
|
||||
router.transientCache('lastSearch', { searchKey, model }, 5);
|
||||
this.set("model", model);
|
||||
|
@ -194,7 +195,7 @@ export default Ember.Controller.extend({
|
|||
|
||||
showSearchHelp() {
|
||||
// TODO: dupe code should be centralized
|
||||
Discourse.ajax("/static/search_help.html", { dataType: 'html' }).then((model) => {
|
||||
ajax("/static/search_help.html", { dataType: 'html' }).then((model) => {
|
||||
showModal('searchHelp', { model });
|
||||
});
|
||||
},
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
import { setting } from 'discourse/lib/computed';
|
||||
|
@ -55,7 +56,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
|
||||
this.set('loggingIn', true);
|
||||
|
||||
Discourse.ajax("/session", {
|
||||
ajax("/session", {
|
||||
data: { login: this.get('loginName'), password: this.get('loginPassword') },
|
||||
type: 'POST'
|
||||
}).then(function (result) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
|
@ -9,7 +10,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
|
||||
actions: {
|
||||
sendActivationEmail: function() {
|
||||
Discourse.ajax('/users/action/send_activation_email', {data: {username: this.get('username')}, type: 'POST'});
|
||||
ajax('/users/action/send_activation_email', {data: {username: this.get('username')}, type: 'POST'});
|
||||
this.set('emailSent', true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import BadgeSelectController from "discourse/mixins/badge-select-controller";
|
||||
|
||||
export default Ember.ArrayController.extend(BadgeSelectController, {
|
||||
|
@ -11,7 +12,7 @@ export default Ember.ArrayController.extend(BadgeSelectController, {
|
|||
this.setProperties({ saved: false, saving: true });
|
||||
|
||||
var self = this;
|
||||
Discourse.ajax(this.get('user.path') + "/preferences/badge_title", {
|
||||
ajax(this.get('user.path') + "/preferences/badge_title", {
|
||||
type: "PUT",
|
||||
data: { user_badge_id: self.get('selectedUserBadgeId') }
|
||||
}).then(function() {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import BadgeSelectController from "discourse/mixins/badge-select-controller";
|
||||
|
||||
export default Ember.ArrayController.extend(BadgeSelectController, {
|
||||
|
@ -12,7 +13,7 @@ export default Ember.ArrayController.extend(BadgeSelectController, {
|
|||
this.setProperties({ saved: false, saving: true });
|
||||
|
||||
var self = this;
|
||||
Discourse.ajax(this.get('user.path') + "/preferences/card-badge", {
|
||||
ajax(this.get('user.path') + "/preferences/card-badge", {
|
||||
type: "PUT",
|
||||
data: { user_badge_id: self.get('selectedUserBadgeId') }
|
||||
}).then(function() {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
const BufferedProxy = window.BufferedProxy; // import BufferedProxy from 'ember-buffered-proxy/proxy';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
@ -90,7 +91,7 @@ export default Ember.Controller.extend(ModalFunctionality, Ember.Evented, {
|
|||
this.get('categoriesBuffered').forEach((cat) => {
|
||||
data[cat.get('id')] = cat.get('position');
|
||||
});
|
||||
Discourse.ajax('/categories/reorder',
|
||||
ajax('/categories/reorder',
|
||||
{type: 'POST', data: {mapping: JSON.stringify(data)}}).
|
||||
then(() => this.send("closeModal")).
|
||||
catch(popupAjaxError);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
|
@ -15,7 +16,7 @@ export default Ember.Controller.extend({
|
|||
markFaqRead() {
|
||||
const currentUser = this.currentUser;
|
||||
if (currentUser) {
|
||||
Discourse.ajax("/users/read-faq", { method: "POST" }).then(() => {
|
||||
ajax("/users/read-faq", { method: "POST" }).then(() => {
|
||||
currentUser.set('read_faq', true);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { observes } from 'ember-addons/ember-computed-decorators';
|
||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default Ember.ArrayController.extend({
|
||||
|
@ -17,7 +19,7 @@ export default Ember.ArrayController.extend({
|
|||
|
||||
actions: {
|
||||
resetNew() {
|
||||
Discourse.ajax('/notifications/mark-read', { method: 'PUT' }).then(() => {
|
||||
ajax('/notifications/mark-read', { method: 'PUT' }).then(() => {
|
||||
this.setEach('read', true);
|
||||
});
|
||||
},
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { cleanDOM } from 'discourse/routes/discourse';
|
||||
import { startPageTracking, onPageChange } from 'discourse/lib/page-tracker';
|
||||
import { viewTrackingRequired } from 'discourse/lib/ajax';
|
||||
|
||||
export default {
|
||||
name: "page-tracking",
|
||||
|
@ -11,9 +12,7 @@ export default {
|
|||
|
||||
// Tell our AJAX system to track a page transition
|
||||
const router = container.lookup('router:main');
|
||||
router.on('willTransition', function() {
|
||||
Discourse.viewTrackingRequired();
|
||||
});
|
||||
router.on('willTransition', viewTrackingRequired);
|
||||
|
||||
router.on('didTransition', function() {
|
||||
Em.run.scheduleOnce('afterRender', Ember.Route, cleanDOM);
|
||||
|
|
122
app/assets/javascripts/discourse/lib/ajax.js.es6
Normal file
122
app/assets/javascripts/discourse/lib/ajax.js.es6
Normal file
|
@ -0,0 +1,122 @@
|
|||
let _trackView = false;
|
||||
let _transientHeader = null;
|
||||
|
||||
export function setTransientHeader(key, value) {
|
||||
_transientHeader = {key, value};
|
||||
}
|
||||
|
||||
export function viewTrackingRequired() {
|
||||
_trackView = true;
|
||||
}
|
||||
|
||||
/**
|
||||
Our own $.ajax method. Makes sure the .then method executes in an Ember runloop
|
||||
for performance reasons. Also automatically adjusts the URL to support installs
|
||||
in subfolders.
|
||||
**/
|
||||
export function ajax() {
|
||||
let url, args;
|
||||
let ajaxObj;
|
||||
|
||||
if (arguments.length === 1) {
|
||||
if (typeof arguments[0] === "string") {
|
||||
url = arguments[0];
|
||||
args = {};
|
||||
} else {
|
||||
args = arguments[0];
|
||||
url = args.url;
|
||||
delete args.url;
|
||||
}
|
||||
} else if (arguments.length === 2) {
|
||||
url = arguments[0];
|
||||
args = arguments[1];
|
||||
}
|
||||
|
||||
function performAjax(resolve, reject) {
|
||||
|
||||
args.headers = args.headers || {};
|
||||
|
||||
if (_transientHeader) {
|
||||
args.headers[_transientHeader.key] = _transientHeader.value;
|
||||
_transientHeader = null;
|
||||
}
|
||||
|
||||
if (_trackView && (!args.type || args.type === "GET")) {
|
||||
_trackView = false;
|
||||
// DON'T CHANGE: rack is prepending "HTTP_" in the header's name
|
||||
args.headers['Discourse-Track-View'] = "true";
|
||||
}
|
||||
|
||||
args.success = (data, textStatus, xhr) => {
|
||||
if (xhr.getResponseHeader('Discourse-Readonly')) {
|
||||
Ember.run(() => Discourse.Site.currentProp('isReadOnly', true));
|
||||
}
|
||||
|
||||
if (args.returnXHR) {
|
||||
data = { result: data, xhr: xhr };
|
||||
}
|
||||
|
||||
Ember.run(null, resolve, data);
|
||||
};
|
||||
|
||||
args.error = (xhr, textStatus, errorThrown) => {
|
||||
// note: for bad CSRF we don't loop an extra request right away.
|
||||
// this allows us to eliminate the possibility of having a loop.
|
||||
if (xhr.status === 403 && xhr.responseText === "['BAD CSRF']") {
|
||||
Discourse.Session.current().set('csrfToken', null);
|
||||
}
|
||||
|
||||
// If it's a parsererror, don't reject
|
||||
if (xhr.status === 200) return args.success(xhr);
|
||||
|
||||
// Fill in some extra info
|
||||
xhr.jqTextStatus = textStatus;
|
||||
xhr.requestedUrl = url;
|
||||
|
||||
Ember.run(null, reject, {
|
||||
jqXHR: xhr,
|
||||
textStatus: textStatus,
|
||||
errorThrown: errorThrown
|
||||
});
|
||||
};
|
||||
|
||||
// We default to JSON on GET. If we don't, sometimes if the server doesn't return the proper header
|
||||
// it will not be parsed as an object.
|
||||
if (!args.type) args.type = 'GET';
|
||||
if (!args.dataType && args.type.toUpperCase() === 'GET') args.dataType = 'json';
|
||||
|
||||
if (args.dataType === "script") {
|
||||
args.headers['Discourse-Script'] = true;
|
||||
}
|
||||
|
||||
if (args.type === 'GET' && args.cache !== true) {
|
||||
args.cache = false;
|
||||
}
|
||||
|
||||
ajaxObj = $.ajax(Discourse.getURL(url), args);
|
||||
};
|
||||
|
||||
let promise;
|
||||
|
||||
// For cached pages we strip out CSRF tokens, need to round trip to server prior to sending the
|
||||
// request (bypass for GET, not needed)
|
||||
if(args.type && args.type.toUpperCase() !== 'GET' && !Discourse.Session.currentProp('csrfToken')){
|
||||
promise = new Ember.RSVP.Promise((resolve, reject) => {
|
||||
ajaxObj = $.ajax(Discourse.getURL('/session/csrf'), {cache: false})
|
||||
.success(result => {
|
||||
Discourse.Session.currentProp('csrfToken', result.csrf);
|
||||
performAjax(resolve, reject);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
promise = new Ember.RSVP.Promise(performAjax);
|
||||
}
|
||||
|
||||
promise.abort = () => {
|
||||
if (ajaxObj) {
|
||||
ajaxObj.abort();
|
||||
}
|
||||
};
|
||||
|
||||
return promise;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import DiscourseURL from 'discourse/lib/url';
|
||||
import { wantsNewWindow } from 'discourse/lib/intercept-click';
|
||||
import { selectedText } from 'discourse/lib/utilities';
|
||||
|
@ -64,7 +65,7 @@ export default {
|
|||
|
||||
// if they want to open in a new tab, do an AJAX request
|
||||
if (wantsNewWindow(e)) {
|
||||
Discourse.ajax("/clicks/track", {
|
||||
ajax("/clicks/track", {
|
||||
data: {
|
||||
url: href,
|
||||
post_id: postId,
|
||||
|
@ -105,7 +106,7 @@ export default {
|
|||
|
||||
// If we're on the same site, use the router and track via AJAX
|
||||
if (DiscourseURL.isInternal(href) && !$link.hasClass('attachment')) {
|
||||
Discourse.ajax("/clicks/track", {
|
||||
ajax("/clicks/track", {
|
||||
data: {
|
||||
url: href,
|
||||
post_id: postId,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
function exportEntityByType(type, entity, args) {
|
||||
return Discourse.ajax("/export_csv/export_entity.json", {
|
||||
return ajax("/export_csv/export_entity.json", {
|
||||
method: 'POST',
|
||||
data: {entity_type: type, entity, args}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { replaceSpan } from 'discourse/lib/category-hashtags';
|
||||
|
||||
const validCategoryHashtags = {};
|
||||
|
@ -41,7 +42,7 @@ export function linkSeenCategoryHashtags($elem) {
|
|||
};
|
||||
|
||||
export function fetchUnseenCategoryHashtags(categorySlugs) {
|
||||
return Discourse.ajax("/category_hashtags/check", { data: { category_slugs: categorySlugs } })
|
||||
return ajax("/category_hashtags/check", { data: { category_slugs: categorySlugs } })
|
||||
.then((response) => {
|
||||
response.valid.forEach((category) => {
|
||||
validCategoryHashtags[category.slug] = category.url;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
function replaceSpan($e, username, opts) {
|
||||
if (opts && opts.group) {
|
||||
var extra = "", extraClass = "";
|
||||
|
@ -52,7 +53,7 @@ export function linkSeenMentions($elem, siteSettings) {
|
|||
}
|
||||
|
||||
export function fetchUnseenMentions($elem, usernames) {
|
||||
return Discourse.ajax("/users/is_local_username", { data: { usernames } }).then(function(r) {
|
||||
return ajax("/users/is_local_username", { data: { usernames } }).then(function(r) {
|
||||
found.push.apply(found, r.valid);
|
||||
foundGroups.push.apply(foundGroups, r.valid_groups);
|
||||
mentionableGroups.push.apply(mentionableGroups, r.mentionable_groups);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { replaceSpan } from 'discourse/lib/category-hashtags';
|
||||
import { TAG_HASHTAG_POSTFIX } from 'discourse/lib/tag-hashtags';
|
||||
|
||||
|
@ -42,7 +43,7 @@ export function linkSeenTagHashtags($elem) {
|
|||
};
|
||||
|
||||
export function fetchUnseenTagHashtags(tagValues) {
|
||||
return Discourse.ajax("/tags/check", { data: { tag_values: tagValues } })
|
||||
return ajax("/tags/check", { data: { tag_values: tagValues } })
|
||||
.then((response) => {
|
||||
response.valid.forEach((tag) => {
|
||||
validTagHashtags[tag.value] = tag.url;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const _loaded = {};
|
||||
const _loading = {};
|
||||
|
||||
|
@ -58,7 +59,7 @@ export default function loadScript(url, opts) {
|
|||
if (opts.scriptTag) {
|
||||
loadWithTag(cdnUrl, cb);
|
||||
} else {
|
||||
Discourse.ajax({url: cdnUrl, dataType: "script", cache: true}).then(cb);
|
||||
ajax({url: cdnUrl, dataType: "script", cache: true}).then(cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
// We use this class to track how long posts in a topic are on the screen.
|
||||
const PAUSE_UNLESS_SCROLLED = 1000 * 60 * 3;
|
||||
const MAX_TRACKING_TIME = 1000 * 60 * 6;
|
||||
|
@ -107,7 +108,7 @@ export default class {
|
|||
|
||||
if (!$.isEmptyObject(newTimings)) {
|
||||
if (this.currentUser) {
|
||||
Discourse.ajax('/topics/timings', {
|
||||
ajax('/topics/timings', {
|
||||
data: {
|
||||
timings: newTimings,
|
||||
topic_time: this._topicTime,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
|
||||
export function translateResults(results, opts) {
|
||||
|
||||
|
@ -82,7 +83,7 @@ function searchForTerm(term, opts) {
|
|||
};
|
||||
}
|
||||
|
||||
var promise = Discourse.ajax('/search/query', { data: data });
|
||||
var promise = ajax('/search/query', { data: data });
|
||||
|
||||
promise.then(function(results){
|
||||
return translateResults(results, opts);
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
/**
|
||||
This mixin provides an 'ajax' method that can be used to perform ajax requests that
|
||||
respect Discourse paths and the run loop.
|
||||
**/
|
||||
var _trackView = false;
|
||||
var _transientHeader = null;
|
||||
|
||||
Discourse.Ajax = Em.Mixin.create({
|
||||
|
||||
setTransientHeader: function(k, v) {
|
||||
_transientHeader = {key: k, value: v};
|
||||
},
|
||||
|
||||
viewTrackingRequired: function() {
|
||||
_trackView = true;
|
||||
},
|
||||
|
||||
/**
|
||||
Our own $.ajax method. Makes sure the .then method executes in an Ember runloop
|
||||
for performance reasons. Also automatically adjusts the URL to support installs
|
||||
in subfolders.
|
||||
|
||||
@method ajax
|
||||
**/
|
||||
ajax: function() {
|
||||
var url, args;
|
||||
var ajax;
|
||||
|
||||
if (arguments.length === 1) {
|
||||
if (typeof arguments[0] === "string") {
|
||||
url = arguments[0];
|
||||
args = {};
|
||||
} else {
|
||||
args = arguments[0];
|
||||
url = args.url;
|
||||
delete args.url;
|
||||
}
|
||||
} else if (arguments.length === 2) {
|
||||
url = arguments[0];
|
||||
args = arguments[1];
|
||||
}
|
||||
|
||||
if (args.success || args.error) {
|
||||
throw "Discourse.ajax should use promises";
|
||||
}
|
||||
|
||||
var performAjax = function(resolve, reject) {
|
||||
|
||||
args.headers = args.headers || {};
|
||||
|
||||
if (_transientHeader) {
|
||||
args.headers[_transientHeader.key] = _transientHeader.value;
|
||||
_transientHeader = null;
|
||||
}
|
||||
|
||||
if (_trackView && (!args.type || args.type === "GET")) {
|
||||
_trackView = false;
|
||||
// DON'T CHANGE: rack is prepending "HTTP_" in the header's name
|
||||
args.headers['Discourse-Track-View'] = "true";
|
||||
}
|
||||
|
||||
args.success = function(data, textStatus, xhr) {
|
||||
if (xhr.getResponseHeader('Discourse-Readonly')) {
|
||||
Ember.run(function() {
|
||||
Discourse.Site.currentProp('isReadOnly', true);
|
||||
});
|
||||
}
|
||||
|
||||
if (args.returnXHR) {
|
||||
data = { result: data, xhr: xhr };
|
||||
}
|
||||
|
||||
Ember.run(null, resolve, data);
|
||||
};
|
||||
|
||||
args.error = function(xhr, textStatus, errorThrown) {
|
||||
// note: for bad CSRF we don't loop an extra request right away.
|
||||
// this allows us to eliminate the possibility of having a loop.
|
||||
if (xhr.status === 403 && xhr.responseText === "['BAD CSRF']") {
|
||||
Discourse.Session.current().set('csrfToken', null);
|
||||
}
|
||||
|
||||
// If it's a parsererror, don't reject
|
||||
if (xhr.status === 200) return args.success(xhr);
|
||||
|
||||
// Fill in some extra info
|
||||
xhr.jqTextStatus = textStatus;
|
||||
xhr.requestedUrl = url;
|
||||
|
||||
Ember.run(null, reject, {
|
||||
jqXHR: xhr,
|
||||
textStatus: textStatus,
|
||||
errorThrown: errorThrown
|
||||
});
|
||||
};
|
||||
|
||||
// We default to JSON on GET. If we don't, sometimes if the server doesn't return the proper header
|
||||
// it will not be parsed as an object.
|
||||
if (!args.type) args.type = 'GET';
|
||||
if (!args.dataType && args.type.toUpperCase() === 'GET') args.dataType = 'json';
|
||||
|
||||
if (args.dataType === "script") {
|
||||
args.headers['Discourse-Script'] = true;
|
||||
}
|
||||
|
||||
if (args.type === 'GET' && args.cache !== true) {
|
||||
args.cache = false;
|
||||
}
|
||||
|
||||
ajax = $.ajax(Discourse.getURL(url), args);
|
||||
};
|
||||
|
||||
var promise;
|
||||
|
||||
// For cached pages we strip out CSRF tokens, need to round trip to server prior to sending the
|
||||
// request (bypass for GET, not needed)
|
||||
if(args.type && args.type.toUpperCase() !== 'GET' && !Discourse.Session.currentProp('csrfToken')){
|
||||
promise = new Ember.RSVP.Promise(function(resolve, reject){
|
||||
ajax = $.ajax(Discourse.getURL('/session/csrf'), {cache: false})
|
||||
.success(function(result){
|
||||
Discourse.Session.currentProp('csrfToken', result.csrf);
|
||||
performAjax(resolve, reject);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
promise = new Ember.RSVP.Promise(performAjax);
|
||||
}
|
||||
|
||||
promise.abort = function(){
|
||||
if (ajax) {
|
||||
ajax.abort();
|
||||
}
|
||||
};
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
});
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
|
@ -53,7 +54,7 @@ export default RestModel.extend({
|
|||
|
||||
// Create our post action
|
||||
const self = this;
|
||||
return Discourse.ajax("/post_actions", {
|
||||
return ajax("/post_actions", {
|
||||
type: 'POST',
|
||||
data: {
|
||||
id: this.get('flagTopic') ? this.get('flagTopic.id') : post.get('id'),
|
||||
|
@ -82,7 +83,7 @@ export default RestModel.extend({
|
|||
this.removeAction(post);
|
||||
|
||||
// Remove our post action
|
||||
return Discourse.ajax("/post_actions/" + post.get('id'), {
|
||||
return ajax("/post_actions/" + post.get('id'), {
|
||||
type: 'DELETE',
|
||||
data: { post_action_type_id: this.get('id') }
|
||||
}).then(result => {
|
||||
|
@ -92,7 +93,7 @@ export default RestModel.extend({
|
|||
},
|
||||
|
||||
deferFlags(post) {
|
||||
return Discourse.ajax("/post_actions/defer_flags", {
|
||||
return ajax("/post_actions/defer_flags", {
|
||||
type: "POST",
|
||||
data: { post_action_type_id: this.get("id"), id: post.get('id') }
|
||||
}).then(() => this.set('count', 0));
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import BadgeGrouping from 'discourse/models/badge-grouping';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
|
||||
|
@ -53,7 +54,7 @@ const Badge = RestModel.extend({
|
|||
requestType = "PUT";
|
||||
}
|
||||
|
||||
return Discourse.ajax(url, {
|
||||
return ajax(url, {
|
||||
type: requestType,
|
||||
data: data
|
||||
}).then(function(json) {
|
||||
|
@ -72,7 +73,7 @@ const Badge = RestModel.extend({
|
|||
**/
|
||||
destroy: function() {
|
||||
if (this.get('newBadge')) return Ember.RSVP.resolve();
|
||||
return Discourse.ajax("/admin/badges/" + this.get('id'), {
|
||||
return ajax("/admin/badges/" + this.get('id'), {
|
||||
type: "DELETE"
|
||||
});
|
||||
}
|
||||
|
@ -134,7 +135,7 @@ Badge.reopenClass({
|
|||
if(opts && opts.onlyListable){
|
||||
listable = "?only_listable=true";
|
||||
}
|
||||
return Discourse.ajax('/badges.json' + listable).then(function(badgesJson) {
|
||||
return ajax('/badges.json' + listable).then(function(badgesJson) {
|
||||
return Badge.createFromJson(badgesJson);
|
||||
});
|
||||
},
|
||||
|
@ -147,7 +148,7 @@ Badge.reopenClass({
|
|||
@returns {Promise} a promise that resolves to a `Badge`
|
||||
**/
|
||||
findById: function(id) {
|
||||
return Discourse.ajax("/badges/" + id).then(function(badgeJson) {
|
||||
return ajax("/badges/" + id).then(function(badgeJson) {
|
||||
return Badge.createFromJson(badgeJson);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
|
||||
const CategoryList = Ember.ArrayProxy.extend({
|
||||
init() {
|
||||
this.set('content', []);
|
||||
|
@ -34,7 +36,7 @@ CategoryList.reopenClass({
|
|||
},
|
||||
|
||||
listForParent(store, category) {
|
||||
return Discourse.ajax(`/categories.json?parent_category_id=${category.get("id")}`).then(result => {
|
||||
return ajax(`/categories.json?parent_category_id=${category.get("id")}`).then(result => {
|
||||
return CategoryList.create({
|
||||
categories: this.categoriesFrom(store, result),
|
||||
parentCategory: category
|
||||
|
@ -43,7 +45,7 @@ CategoryList.reopenClass({
|
|||
},
|
||||
|
||||
list(store) {
|
||||
const getCategories = () => Discourse.ajax("/categories.json");
|
||||
const getCategories = () => ajax("/categories.json");
|
||||
return PreloadStore.getAndRemove("categories_list", getCategories).then(result => {
|
||||
return CategoryList.create({
|
||||
categories: this.categoriesFrom(store, result),
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import { on } from 'ember-addons/ember-computed-decorators';
|
||||
import PermissionType from 'discourse/models/permission-type';
|
||||
|
@ -67,7 +68,7 @@ const Category = RestModel.extend({
|
|||
url = "/categories/" + this.get('id');
|
||||
}
|
||||
|
||||
return Discourse.ajax(url, {
|
||||
return ajax(url, {
|
||||
data: {
|
||||
name: this.get('name'),
|
||||
slug: this.get('slug'),
|
||||
|
@ -103,7 +104,7 @@ const Category = RestModel.extend({
|
|||
}.property("permissions"),
|
||||
|
||||
destroy: function() {
|
||||
return Discourse.ajax("/categories/" + (this.get('id') || this.get('slug')), { type: 'DELETE' });
|
||||
return ajax("/categories/" + (this.get('id') || this.get('slug')), { type: 'DELETE' });
|
||||
},
|
||||
|
||||
addPermission: function(permission){
|
||||
|
@ -170,7 +171,7 @@ const Category = RestModel.extend({
|
|||
setNotification: function(notification_level) {
|
||||
var url = "/category/" + this.get('id')+"/notifications";
|
||||
this.set('notification_level', notification_level);
|
||||
return Discourse.ajax(url, {
|
||||
return ajax(url, {
|
||||
data: {
|
||||
notification_level: notification_level
|
||||
},
|
||||
|
@ -285,11 +286,11 @@ Category.reopenClass({
|
|||
},
|
||||
|
||||
reloadById(id) {
|
||||
return Discourse.ajax(`/c/${id}/show.json`);
|
||||
return ajax(`/c/${id}/show.json`);
|
||||
},
|
||||
|
||||
reloadBySlug(slug, parentSlug) {
|
||||
return parentSlug ? Discourse.ajax(`/c/${parentSlug}/${slug}/find_by_slug.json`) : Discourse.ajax(`/c/${slug}/find_by_slug.json`);
|
||||
return parentSlug ? ajax(`/c/${parentSlug}/${slug}/find_by_slug.json`) : ajax(`/c/${slug}/find_by_slug.json`);
|
||||
},
|
||||
|
||||
search(term, opts) {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const Draft = Discourse.Model.extend();
|
||||
|
||||
Draft.reopenClass({
|
||||
|
||||
clear(key, sequence) {
|
||||
return Discourse.ajax("/draft.json", {
|
||||
return ajax("/draft.json", {
|
||||
type: 'DELETE',
|
||||
data: {
|
||||
draft_key: key,
|
||||
|
@ -13,7 +14,7 @@ Draft.reopenClass({
|
|||
},
|
||||
|
||||
get(key) {
|
||||
return Discourse.ajax('/draft.json', {
|
||||
return ajax('/draft.json', {
|
||||
data: { draft_key: key },
|
||||
dataType: 'json'
|
||||
});
|
||||
|
@ -26,7 +27,7 @@ Draft.reopenClass({
|
|||
|
||||
save(key, sequence, data) {
|
||||
data = typeof data === "string" ? data : JSON.stringify(data);
|
||||
return Discourse.ajax("/draft.json", {
|
||||
return ajax("/draft.json", {
|
||||
type: 'POST',
|
||||
data: {
|
||||
draft_key: key,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
const Group = Discourse.Model.extend({
|
||||
|
@ -49,7 +50,7 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
removeOwner(member) {
|
||||
var self = this;
|
||||
return Discourse.ajax('/admin/groups/' + this.get('id') + '/owners.json', {
|
||||
return ajax('/admin/groups/' + this.get('id') + '/owners.json', {
|
||||
type: "DELETE",
|
||||
data: { user_id: member.get("id") }
|
||||
}).then(function() {
|
||||
|
@ -60,7 +61,7 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
removeMember(member) {
|
||||
var self = this;
|
||||
return Discourse.ajax('/groups/' + this.get('id') + '/members.json', {
|
||||
return ajax('/groups/' + this.get('id') + '/members.json', {
|
||||
type: "DELETE",
|
||||
data: { user_id: member.get("id") }
|
||||
}).then(function() {
|
||||
|
@ -71,7 +72,7 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
addMembers(usernames) {
|
||||
var self = this;
|
||||
return Discourse.ajax('/groups/' + this.get('id') + '/members.json', {
|
||||
return ajax('/groups/' + this.get('id') + '/members.json', {
|
||||
type: "PUT",
|
||||
data: { usernames: usernames }
|
||||
}).then(function() {
|
||||
|
@ -81,7 +82,7 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
addOwners(usernames) {
|
||||
var self = this;
|
||||
return Discourse.ajax('/admin/groups/' + this.get('id') + '/owners.json', {
|
||||
return ajax('/admin/groups/' + this.get('id') + '/owners.json', {
|
||||
type: "PUT",
|
||||
data: { usernames: usernames }
|
||||
}).then(function() {
|
||||
|
@ -105,18 +106,18 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
create() {
|
||||
var self = this;
|
||||
return Discourse.ajax("/admin/groups", { type: "POST", data: this.asJSON() }).then(function(resp) {
|
||||
return ajax("/admin/groups", { type: "POST", data: this.asJSON() }).then(function(resp) {
|
||||
self.set('id', resp.basic_group.id);
|
||||
});
|
||||
},
|
||||
|
||||
save() {
|
||||
return Discourse.ajax("/admin/groups/" + this.get('id'), { type: "PUT", data: this.asJSON() });
|
||||
return ajax("/admin/groups/" + this.get('id'), { type: "PUT", data: this.asJSON() });
|
||||
},
|
||||
|
||||
destroy() {
|
||||
if (!this.get('id')) { return; }
|
||||
return Discourse.ajax("/admin/groups/" + this.get('id'), { type: "DELETE" });
|
||||
return ajax("/admin/groups/" + this.get('id'), { type: "DELETE" });
|
||||
},
|
||||
|
||||
findPosts(opts) {
|
||||
|
@ -127,7 +128,7 @@ const Group = Discourse.Model.extend({
|
|||
var data = {};
|
||||
if (opts.beforePostId) { data.before_post_id = opts.beforePostId; }
|
||||
|
||||
return Discourse.ajax(`/groups/${this.get('name')}/${type}.json`, { data: data }).then(posts => {
|
||||
return ajax(`/groups/${this.get('name')}/${type}.json`, { data: data }).then(posts => {
|
||||
return posts.map(p => {
|
||||
p.user = Discourse.User.create(p.user);
|
||||
p.topic = Discourse.Topic.create(p.topic);
|
||||
|
@ -138,7 +139,7 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
setNotification(notification_level) {
|
||||
this.set("notification_level", notification_level);
|
||||
return Discourse.ajax(`/groups/${this.get("name")}/notifications`, {
|
||||
return ajax(`/groups/${this.get("name")}/notifications`, {
|
||||
data: { notification_level },
|
||||
type: "POST"
|
||||
});
|
||||
|
@ -147,21 +148,21 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
Group.reopenClass({
|
||||
findAll(opts) {
|
||||
return Discourse.ajax("/admin/groups.json", { data: opts }).then(function (groups){
|
||||
return ajax("/admin/groups.json", { data: opts }).then(function (groups){
|
||||
return groups.map(g => Group.create(g));
|
||||
});
|
||||
},
|
||||
|
||||
findGroupCounts(name) {
|
||||
return Discourse.ajax("/groups/" + name + "/counts.json").then(result => Em.Object.create(result.counts));
|
||||
return ajax("/groups/" + name + "/counts.json").then(result => Em.Object.create(result.counts));
|
||||
},
|
||||
|
||||
find(name) {
|
||||
return Discourse.ajax("/groups/" + name + ".json").then(result => Group.create(result.basic_group));
|
||||
return ajax("/groups/" + name + ".json").then(result => Group.create(result.basic_group));
|
||||
},
|
||||
|
||||
loadMembers(name, offset, limit) {
|
||||
return Discourse.ajax('/groups/' + name + '/members.json', {
|
||||
return ajax('/groups/' + name + '/members.json', {
|
||||
data: {
|
||||
limit: limit || 50,
|
||||
offset: offset || 0
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
const Invite = Discourse.Model.extend({
|
||||
|
||||
rescind() {
|
||||
Discourse.ajax('/invites', {
|
||||
ajax('/invites', {
|
||||
type: 'DELETE',
|
||||
data: { email: this.get('email') }
|
||||
});
|
||||
|
@ -12,7 +13,7 @@ const Invite = Discourse.Model.extend({
|
|||
|
||||
reinvite() {
|
||||
const self = this;
|
||||
return Discourse.ajax('/invites/reinvite', {
|
||||
return ajax('/invites/reinvite', {
|
||||
type: 'POST',
|
||||
data: { email: this.get('email') }
|
||||
}).then(function() {
|
||||
|
@ -40,7 +41,7 @@ Invite.reopenClass({
|
|||
if (!Em.isNone(search)) { data.search = search; }
|
||||
data.offset = offset || 0;
|
||||
|
||||
return Discourse.ajax("/users/" + user.get('username_lower') + "/invited.json", {data}).then(function (result) {
|
||||
return ajax("/users/" + user.get('username_lower') + "/invited.json", {data}).then(function (result) {
|
||||
result.invites = result.invites.map(function (i) {
|
||||
return Invite.create(i);
|
||||
});
|
||||
|
@ -51,11 +52,11 @@ Invite.reopenClass({
|
|||
|
||||
findInvitedCount(user) {
|
||||
if (!user) { return Em.RSVP.resolve(); }
|
||||
return Discourse.ajax("/users/" + user.get('username_lower') + "/invited_count.json").then(result => Em.Object.create(result.counts));
|
||||
return ajax("/users/" + user.get('username_lower') + "/invited_count.json").then(result => Em.Object.create(result.counts));
|
||||
},
|
||||
|
||||
reinviteAll() {
|
||||
return Discourse.ajax('/invites/reinvite-all', { type: 'POST' });
|
||||
return ajax('/invites/reinvite-all', { type: 'POST' });
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const LivePostCounts = Discourse.Model.extend({});
|
||||
|
||||
LivePostCounts.reopenClass({
|
||||
find() {
|
||||
return Discourse.ajax("/about/live_post_counts.json").then(result => LivePostCounts.create(result));
|
||||
return ajax("/about/live_post_counts.json").then(result => LivePostCounts.create(result));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import DiscourseURL from 'discourse/lib/url';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import PostsWithPlaceholders from 'discourse/lib/posts-with-placeholders';
|
||||
|
@ -455,7 +456,7 @@ export default RestModel.extend({
|
|||
const url = "/posts/" + postId;
|
||||
const store = this.store;
|
||||
|
||||
return Discourse.ajax(url).then(p => this.storePost(store.createRecord('post', p)));
|
||||
return ajax(url).then(p => this.storePost(store.createRecord('post', p)));
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -497,7 +498,7 @@ export default RestModel.extend({
|
|||
// need to insert into stream
|
||||
const url = "/posts/" + postId;
|
||||
const store = this.store;
|
||||
return Discourse.ajax(url).then(p => {
|
||||
return ajax(url).then(p => {
|
||||
const post = store.createRecord('post', p);
|
||||
const stream = this.get("stream");
|
||||
const posts = this.get("posts");
|
||||
|
@ -538,7 +539,7 @@ export default RestModel.extend({
|
|||
const url = "/posts/" + postId;
|
||||
const store = this.store;
|
||||
|
||||
return Discourse.ajax(url).then(p => {
|
||||
return ajax(url).then(p => {
|
||||
this.storePost(store.createRecord('post', p));
|
||||
}).catch(() => {
|
||||
this.removePosts([existing]);
|
||||
|
@ -555,7 +556,7 @@ export default RestModel.extend({
|
|||
if (existing && existing.updated_at !== updatedAt) {
|
||||
const url = "/posts/" + postId;
|
||||
const store = this.store;
|
||||
return Discourse.ajax(url).then(p => this.storePost(store.createRecord('post', p)));
|
||||
return ajax(url).then(p => this.storePost(store.createRecord('post', p)));
|
||||
}
|
||||
return resolved;
|
||||
},
|
||||
|
@ -727,7 +728,7 @@ export default RestModel.extend({
|
|||
const url = "/t/" + this.get('topic.id') + "/posts.json";
|
||||
const data = { post_ids: postIds };
|
||||
const store = this.store;
|
||||
return Discourse.ajax(url, {data}).then(result => {
|
||||
return ajax(url, {data}).then(result => {
|
||||
const posts = Ember.get(result, "post_stream.posts");
|
||||
if (posts) {
|
||||
posts.forEach(p => this.storePost(store.createRecord('post', p)));
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
import ActionSummary from 'discourse/models/action-summary';
|
||||
|
@ -67,7 +68,7 @@ const Post = RestModel.extend({
|
|||
const data = {};
|
||||
data[field] = value;
|
||||
|
||||
return Discourse.ajax(`/posts/${this.get('id')}/${field}`, { type: 'PUT', data }).then(() => {
|
||||
return ajax(`/posts/${this.get('id')}/${field}`, { type: 'PUT', data }).then(() => {
|
||||
this.set(field, value);
|
||||
this.incrementProperty("version");
|
||||
}).catch(popupAjaxError);
|
||||
|
@ -119,7 +120,7 @@ const Post = RestModel.extend({
|
|||
// Expands the first post's content, if embedded and shortened.
|
||||
expand() {
|
||||
const self = this;
|
||||
return Discourse.ajax("/posts/" + this.get('id') + "/expand-embed").then(function(post) {
|
||||
return ajax("/posts/" + this.get('id') + "/expand-embed").then(function(post) {
|
||||
self.set('cooked', "<section class='expanded-embed'>" + post.cooked + "</section>" );
|
||||
});
|
||||
},
|
||||
|
@ -136,7 +137,7 @@ const Post = RestModel.extend({
|
|||
can_delete: false
|
||||
});
|
||||
|
||||
return Discourse.ajax("/posts/" + (this.get('id')) + "/recover", { type: 'PUT', cache: false }).then(function(data){
|
||||
return ajax("/posts/" + (this.get('id')) + "/recover", { type: 'PUT', cache: false }).then(function(data){
|
||||
post.setProperties({
|
||||
cooked: data.cooked,
|
||||
raw: data.raw,
|
||||
|
@ -198,7 +199,7 @@ const Post = RestModel.extend({
|
|||
|
||||
destroy(deletedBy) {
|
||||
this.setDeletedState(deletedBy);
|
||||
return Discourse.ajax("/posts/" + this.get('id'), {
|
||||
return ajax("/posts/" + this.get('id'), {
|
||||
data: { context: window.location.pathname },
|
||||
type: 'DELETE'
|
||||
});
|
||||
|
@ -232,17 +233,17 @@ const Post = RestModel.extend({
|
|||
},
|
||||
|
||||
expandHidden() {
|
||||
return Discourse.ajax("/posts/" + this.get('id') + "/cooked.json").then(result => {
|
||||
return ajax("/posts/" + this.get('id') + "/cooked.json").then(result => {
|
||||
this.setProperties({ cooked: result.cooked, cooked_hidden: false });
|
||||
});
|
||||
},
|
||||
|
||||
rebake() {
|
||||
return Discourse.ajax("/posts/" + this.get("id") + "/rebake", { type: "PUT" });
|
||||
return ajax("/posts/" + this.get("id") + "/rebake", { type: "PUT" });
|
||||
},
|
||||
|
||||
unhide() {
|
||||
return Discourse.ajax("/posts/" + this.get("id") + "/unhide", { type: "PUT" });
|
||||
return ajax("/posts/" + this.get("id") + "/unhide", { type: "PUT" });
|
||||
},
|
||||
|
||||
toggleBookmark() {
|
||||
|
@ -277,7 +278,7 @@ const Post = RestModel.extend({
|
|||
},
|
||||
|
||||
revertToRevision(version) {
|
||||
return Discourse.ajax(`/posts/${this.get('id')}/revisions/${version}/revert`, { type: 'PUT' });
|
||||
return ajax(`/posts/${this.get('id')}/revisions/${version}/revert`, { type: 'PUT' });
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -311,14 +312,14 @@ Post.reopenClass({
|
|||
},
|
||||
|
||||
updateBookmark(postId, bookmarked) {
|
||||
return Discourse.ajax("/posts/" + postId + "/bookmark", {
|
||||
return ajax("/posts/" + postId + "/bookmark", {
|
||||
type: 'PUT',
|
||||
data: { bookmarked: bookmarked }
|
||||
});
|
||||
},
|
||||
|
||||
deleteMany(selectedPosts, selectedReplies) {
|
||||
return Discourse.ajax("/posts/destroy_many", {
|
||||
return ajax("/posts/destroy_many", {
|
||||
type: 'DELETE',
|
||||
data: {
|
||||
post_ids: selectedPosts.map(function(p) { return p.get('id'); }),
|
||||
|
@ -328,27 +329,27 @@ Post.reopenClass({
|
|||
},
|
||||
|
||||
loadRevision(postId, version) {
|
||||
return Discourse.ajax("/posts/" + postId + "/revisions/" + version + ".json")
|
||||
return ajax("/posts/" + postId + "/revisions/" + version + ".json")
|
||||
.then(result => Ember.Object.create(result));
|
||||
},
|
||||
|
||||
hideRevision(postId, version) {
|
||||
return Discourse.ajax("/posts/" + postId + "/revisions/" + version + "/hide", { type: 'PUT' });
|
||||
return ajax("/posts/" + postId + "/revisions/" + version + "/hide", { type: 'PUT' });
|
||||
},
|
||||
|
||||
showRevision(postId, version) {
|
||||
return Discourse.ajax("/posts/" + postId + "/revisions/" + version + "/show", { type: 'PUT' });
|
||||
return ajax("/posts/" + postId + "/revisions/" + version + "/show", { type: 'PUT' });
|
||||
},
|
||||
|
||||
loadQuote(postId) {
|
||||
return Discourse.ajax("/posts/" + postId + ".json").then(result => {
|
||||
return ajax("/posts/" + postId + ".json").then(result => {
|
||||
const post = Discourse.Post.create(result);
|
||||
return Quote.build(post, post.get('raw'), {raw: true, full: true});
|
||||
});
|
||||
},
|
||||
|
||||
loadRawEmail(postId) {
|
||||
return Discourse.ajax(`/posts/${postId}/raw-email.json`);
|
||||
return ajax(`/posts/${postId}/raw-email.json`);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
const StaticPage = Ember.Object.extend();
|
||||
|
||||
StaticPage.reopenClass({
|
||||
|
@ -11,7 +12,7 @@ StaticPage.reopenClass({
|
|||
text = text.match(/<!-- preload-content: -->((?:.|[\n\r])*)<!-- :preload-content -->/)[1];
|
||||
resolve(StaticPage.create({path: path, html: text}));
|
||||
} else {
|
||||
Discourse.ajax(path + ".html", {dataType: 'html'}).then(function (result) {
|
||||
ajax(path + ".html", {dataType: 'html'}).then(function (result) {
|
||||
resolve(StaticPage.create({path: path, html: result}));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import ResultSet from 'discourse/models/result-set';
|
||||
|
||||
|
@ -114,7 +115,7 @@ export default Ember.Object.extend({
|
|||
|
||||
refreshResults(resultSet, type, url) {
|
||||
const self = this;
|
||||
return Discourse.ajax(url).then(result => {
|
||||
return ajax(url).then(result => {
|
||||
const typeName = Ember.String.underscore(self.pluralize(type));
|
||||
const content = result[typeName].map(obj => self._hydrate(type, obj, result));
|
||||
resultSet.set('content', content);
|
||||
|
@ -124,7 +125,7 @@ export default Ember.Object.extend({
|
|||
appendResults(resultSet, type, url) {
|
||||
const self = this;
|
||||
|
||||
return Discourse.ajax(url).then(function(result) {
|
||||
return ajax(url).then(function(result) {
|
||||
const typeName = Ember.String.underscore(self.pluralize(type)),
|
||||
totalRows = result["total_rows_" + typeName] || result.get('totalRows'),
|
||||
loadMoreUrl = result["load_more_" + typeName],
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
|
@ -17,7 +18,7 @@ const TagGroup = RestModel.extend({
|
|||
this.set('savingStatus', I18n.t('saving'));
|
||||
this.set('saving', true);
|
||||
|
||||
return Discourse.ajax(url, {
|
||||
return ajax(url, {
|
||||
data: {
|
||||
name: this.get('name'),
|
||||
tag_names: this.get('tag_names'),
|
||||
|
@ -33,7 +34,7 @@ const TagGroup = RestModel.extend({
|
|||
},
|
||||
|
||||
destroy() {
|
||||
return Discourse.ajax("/tag_groups/" + this.get('id'), {type: "DELETE"});
|
||||
return ajax("/tag_groups/" + this.get('id'), {type: "DELETE"});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
/**
|
||||
A model representing a Topic's details that aren't always present, such as a list of participants.
|
||||
When showing topics in lists and such this information should not be required.
|
||||
|
@ -57,7 +58,7 @@ const TopicDetails = RestModel.extend({
|
|||
updateNotifications(v) {
|
||||
this.set('notification_level', v);
|
||||
this.set('notifications_reason_id', null);
|
||||
return Discourse.ajax("/t/" + (this.get('topic.id')) + "/notifications", {
|
||||
return ajax("/t/" + (this.get('topic.id')) + "/notifications", {
|
||||
type: 'POST',
|
||||
data: { notification_level: v }
|
||||
});
|
||||
|
@ -67,7 +68,7 @@ const TopicDetails = RestModel.extend({
|
|||
const groups = this.get('allowed_groups');
|
||||
const name = group.name;
|
||||
|
||||
return Discourse.ajax("/t/" + this.get('topic.id') + "/remove-allowed-group", {
|
||||
return ajax("/t/" + this.get('topic.id') + "/remove-allowed-group", {
|
||||
type: 'PUT',
|
||||
data: { name: name }
|
||||
}).then(() => {
|
||||
|
@ -79,7 +80,7 @@ const TopicDetails = RestModel.extend({
|
|||
const users = this.get('allowed_users');
|
||||
const username = user.get('username');
|
||||
|
||||
return Discourse.ajax("/t/" + this.get('topic.id') + "/remove-allowed-user", {
|
||||
return ajax("/t/" + this.get('topic.id') + "/remove-allowed-user", {
|
||||
type: 'PUT',
|
||||
data: { username: username }
|
||||
}).then(() => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import Model from 'discourse/models/model';
|
||||
|
||||
|
@ -60,7 +61,7 @@ const TopicList = RestModel.extend({
|
|||
this.set('loadingMore', true);
|
||||
|
||||
const store = this.store;
|
||||
return Discourse.ajax({url: moreUrl}).then(function (result) {
|
||||
return ajax({url: moreUrl}).then(function (result) {
|
||||
let topicsAdded = 0;
|
||||
|
||||
if (result) {
|
||||
|
@ -100,7 +101,7 @@ const TopicList = RestModel.extend({
|
|||
const url = `${Discourse.getURL("/")}${this.get('filter')}?topic_ids=${topic_ids.join(",")}`;
|
||||
const store = this.store;
|
||||
|
||||
return Discourse.ajax({ url }).then(result => {
|
||||
return ajax({ url }).then(result => {
|
||||
let i = 0;
|
||||
topicList.forEachNew(topicsFrom(result, store), function(t) {
|
||||
// highlight the first of the new topics so we can get a visual feedback
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { flushMap } from 'discourse/models/store';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import { propertyEqual } from 'discourse/lib/computed';
|
||||
|
@ -19,7 +20,7 @@ export function loadTopicView(topic, args) {
|
|||
delete data.store;
|
||||
|
||||
return PreloadStore.getAndRemove(`topic_${topicId}`, () => {
|
||||
return Discourse.ajax(jsonUrl, {data});
|
||||
return ajax(jsonUrl, {data});
|
||||
}).then(json => {
|
||||
topic.updateFromJson(json);
|
||||
return json;
|
||||
|
@ -225,7 +226,7 @@ const Topic = RestModel.extend({
|
|||
this.set('details.auto_close_at', null);
|
||||
}
|
||||
}
|
||||
return Discourse.ajax(this.get('url') + "/status", {
|
||||
return ajax(this.get('url') + "/status", {
|
||||
type: 'PUT',
|
||||
data: {
|
||||
status: property,
|
||||
|
@ -237,13 +238,13 @@ const Topic = RestModel.extend({
|
|||
|
||||
makeBanner() {
|
||||
const self = this;
|
||||
return Discourse.ajax('/t/' + this.get('id') + '/make-banner', { type: 'PUT' })
|
||||
return ajax('/t/' + this.get('id') + '/make-banner', { type: 'PUT' })
|
||||
.then(function () { self.set('archetype', 'banner'); });
|
||||
},
|
||||
|
||||
removeBanner() {
|
||||
const self = this;
|
||||
return Discourse.ajax('/t/' + this.get('id') + '/remove-banner', { type: 'PUT' })
|
||||
return ajax('/t/' + this.get('id') + '/remove-banner', { type: 'PUT' })
|
||||
.then(function () { self.set('archetype', 'regular'); });
|
||||
},
|
||||
|
||||
|
@ -258,7 +259,7 @@ const Topic = RestModel.extend({
|
|||
const path = bookmark ? '/bookmark' : '/remove_bookmarks';
|
||||
|
||||
const toggleBookmarkOnServer = () => {
|
||||
return Discourse.ajax(`/t/${this.get('id')}${path}`, { type: 'PUT' }).then(() => {
|
||||
return ajax(`/t/${this.get('id')}${path}`, { type: 'PUT' }).then(() => {
|
||||
this.toggleProperty('bookmarked');
|
||||
if (bookmark && firstPost) {
|
||||
firstPost.set('bookmarked', true);
|
||||
|
@ -314,21 +315,21 @@ const Topic = RestModel.extend({
|
|||
},
|
||||
|
||||
createGroupInvite(group) {
|
||||
return Discourse.ajax("/t/" + this.get('id') + "/invite-group", {
|
||||
return ajax("/t/" + this.get('id') + "/invite-group", {
|
||||
type: 'POST',
|
||||
data: { group }
|
||||
});
|
||||
},
|
||||
|
||||
createInvite(user, group_names, custom_message) {
|
||||
return Discourse.ajax("/t/" + this.get('id') + "/invite", {
|
||||
return ajax("/t/" + this.get('id') + "/invite", {
|
||||
type: 'POST',
|
||||
data: { user, group_names, custom_message }
|
||||
});
|
||||
},
|
||||
|
||||
generateInviteLink: function(email, groupNames, topicId) {
|
||||
return Discourse.ajax('/invites/link', {
|
||||
return ajax('/invites/link', {
|
||||
type: 'POST',
|
||||
data: {email: email, group_names: groupNames, topic_id: topicId}
|
||||
});
|
||||
|
@ -342,7 +343,7 @@ const Topic = RestModel.extend({
|
|||
'details.can_delete': false,
|
||||
'details.can_recover': true
|
||||
});
|
||||
return Discourse.ajax("/t/" + this.get('id'), {
|
||||
return ajax("/t/" + this.get('id'), {
|
||||
data: { context: window.location.pathname },
|
||||
type: 'DELETE'
|
||||
});
|
||||
|
@ -356,7 +357,7 @@ const Topic = RestModel.extend({
|
|||
'details.can_delete': true,
|
||||
'details.can_recover': false
|
||||
});
|
||||
return Discourse.ajax("/t/" + this.get('id') + "/recover", { type: 'PUT' });
|
||||
return ajax("/t/" + this.get('id') + "/recover", { type: 'PUT' });
|
||||
},
|
||||
|
||||
// Update our attributes from a JSON result
|
||||
|
@ -372,7 +373,7 @@ const Topic = RestModel.extend({
|
|||
|
||||
reload() {
|
||||
const self = this;
|
||||
return Discourse.ajax('/t/' + this.get('id'), { type: 'GET' }).then(function(topic_json) {
|
||||
return ajax('/t/' + this.get('id'), { type: 'GET' }).then(function(topic_json) {
|
||||
self.updateFromJson(topic_json);
|
||||
});
|
||||
},
|
||||
|
@ -388,7 +389,7 @@ const Topic = RestModel.extend({
|
|||
topic.set('pinned', false);
|
||||
topic.set('unpinned', true);
|
||||
|
||||
Discourse.ajax("/t/" + this.get('id') + "/clear-pin", {
|
||||
ajax("/t/" + this.get('id') + "/clear-pin", {
|
||||
type: 'PUT'
|
||||
}).then(null, function() {
|
||||
// On error, put the pin back
|
||||
|
@ -412,7 +413,7 @@ const Topic = RestModel.extend({
|
|||
topic.set('pinned', true);
|
||||
topic.set('unpinned', false);
|
||||
|
||||
Discourse.ajax("/t/" + this.get('id') + "/re-pin", {
|
||||
ajax("/t/" + this.get('id') + "/re-pin", {
|
||||
type: 'PUT'
|
||||
}).then(null, function() {
|
||||
// On error, put the pin back
|
||||
|
@ -434,7 +435,7 @@ const Topic = RestModel.extend({
|
|||
|
||||
archiveMessage() {
|
||||
this.set("archiving", true);
|
||||
var promise = Discourse.ajax(`/t/${this.get('id')}/archive-message`, {type: 'PUT'});
|
||||
var promise = ajax(`/t/${this.get('id')}/archive-message`, {type: 'PUT'});
|
||||
|
||||
promise.then((msg)=> {
|
||||
this.set('message_archived', true);
|
||||
|
@ -448,7 +449,7 @@ const Topic = RestModel.extend({
|
|||
|
||||
moveToInbox() {
|
||||
this.set("archiving", true);
|
||||
var promise = Discourse.ajax(`/t/${this.get('id')}/move-to-inbox`, {type: 'PUT'});
|
||||
var promise = ajax(`/t/${this.get('id')}/move-to-inbox`, {type: 'PUT'});
|
||||
|
||||
promise.then((msg)=> {
|
||||
this.set('message_archived', false);
|
||||
|
@ -461,7 +462,7 @@ const Topic = RestModel.extend({
|
|||
},
|
||||
|
||||
convertTopic(type) {
|
||||
return Discourse.ajax(`/t/${this.get('id')}/convert-topic/${type}`, {type: 'PUT'}).then(() => {
|
||||
return ajax(`/t/${this.get('id')}/convert-topic/${type}`, {type: 'PUT'}).then(() => {
|
||||
window.location.reload();
|
||||
}).catch(popupAjaxError);
|
||||
}
|
||||
|
@ -511,7 +512,7 @@ Topic.reopenClass({
|
|||
}
|
||||
});
|
||||
|
||||
return Discourse.ajax(topic.get('url'), { type: 'PUT', data: props }).then(function(result) {
|
||||
return ajax(topic.get('url'), { type: 'PUT', data: props }).then(function(result) {
|
||||
// The title can be cleaned up server side
|
||||
props.title = result.basic_topic.title;
|
||||
props.fancy_title = result.basic_topic.fancy_title;
|
||||
|
@ -558,11 +559,11 @@ Topic.reopenClass({
|
|||
}
|
||||
|
||||
// Check the preload store. If not, load it via JSON
|
||||
return Discourse.ajax(url + ".json", {data: data});
|
||||
return ajax(url + ".json", {data: data});
|
||||
},
|
||||
|
||||
changeOwners(topicId, opts) {
|
||||
const promise = Discourse.ajax("/t/" + topicId + "/change-owner", {
|
||||
const promise = ajax("/t/" + topicId + "/change-owner", {
|
||||
type: 'POST',
|
||||
data: opts
|
||||
}).then(function (result) {
|
||||
|
@ -573,7 +574,7 @@ Topic.reopenClass({
|
|||
},
|
||||
|
||||
changeTimestamp(topicId, timestamp) {
|
||||
const promise = Discourse.ajax("/t/" + topicId + '/change-timestamp', {
|
||||
const promise = ajax("/t/" + topicId + '/change-timestamp', {
|
||||
type: 'PUT',
|
||||
data: { timestamp: timestamp },
|
||||
}).then(function(result) {
|
||||
|
@ -584,7 +585,7 @@ Topic.reopenClass({
|
|||
},
|
||||
|
||||
bulkOperation(topics, operation) {
|
||||
return Discourse.ajax("/topics/bulk", {
|
||||
return ajax("/topics/bulk", {
|
||||
type: 'PUT',
|
||||
data: {
|
||||
topic_ids: topics.map(function(t) { return t.get('id'); }),
|
||||
|
@ -596,18 +597,18 @@ Topic.reopenClass({
|
|||
bulkOperationByFilter(filter, operation, categoryId) {
|
||||
const data = { filter: filter, operation: operation };
|
||||
if (categoryId) data['category_id'] = categoryId;
|
||||
return Discourse.ajax("/topics/bulk", {
|
||||
return ajax("/topics/bulk", {
|
||||
type: 'PUT',
|
||||
data: data
|
||||
});
|
||||
},
|
||||
|
||||
resetNew() {
|
||||
return Discourse.ajax("/topics/reset-new", {type: 'PUT'});
|
||||
return ajax("/topics/reset-new", {type: 'PUT'});
|
||||
},
|
||||
|
||||
idForSlug(slug) {
|
||||
return Discourse.ajax("/t/id_for/" + slug);
|
||||
return ajax("/t/id_for/" + slug);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -621,11 +622,11 @@ function moveResult(result) {
|
|||
}
|
||||
|
||||
export function movePosts(topicId, data) {
|
||||
return Discourse.ajax("/t/" + topicId + "/move-posts", { type: 'POST', data }).then(moveResult);
|
||||
return ajax("/t/" + topicId + "/move-posts", { type: 'POST', data }).then(moveResult);
|
||||
}
|
||||
|
||||
export function mergeTopic(topicId, destinationTopicId) {
|
||||
return Discourse.ajax("/t/" + topicId + "/merge-topic", {
|
||||
return ajax("/t/" + topicId + "/merge-topic", {
|
||||
type: 'POST',
|
||||
data: {destination_topic_id: destinationTopicId}
|
||||
}).then(moveResult);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import Badge from 'discourse/models/badge';
|
||||
|
||||
const UserBadge = Discourse.Model.extend({
|
||||
|
@ -8,7 +9,7 @@ const UserBadge = Discourse.Model.extend({
|
|||
}.property(), // avoid the extra bindings for now
|
||||
|
||||
revoke() {
|
||||
return Discourse.ajax("/user_badges/" + this.get('id'), {
|
||||
return ajax("/user_badges/" + this.get('id'), {
|
||||
type: "DELETE"
|
||||
});
|
||||
}
|
||||
|
@ -89,7 +90,7 @@ UserBadge.reopenClass({
|
|||
if (options && options.grouped) {
|
||||
url += "?grouped=true";
|
||||
}
|
||||
return Discourse.ajax(url).then(function(json) {
|
||||
return ajax(url).then(function(json) {
|
||||
return UserBadge.createFromJson(json);
|
||||
});
|
||||
},
|
||||
|
@ -105,7 +106,7 @@ UserBadge.reopenClass({
|
|||
if (!options) { options = {}; }
|
||||
options.badge_id = badgeId;
|
||||
|
||||
return Discourse.ajax("/user_badges.json", {
|
||||
return ajax("/user_badges.json", {
|
||||
data: options
|
||||
}).then(function(json) {
|
||||
return UserBadge.createFromJson(json);
|
||||
|
@ -121,7 +122,7 @@ UserBadge.reopenClass({
|
|||
@returns {Promise} a promise that resolves to an instance of `UserBadge`.
|
||||
**/
|
||||
grant: function(badgeId, username, reason) {
|
||||
return Discourse.ajax("/user_badges", {
|
||||
return ajax("/user_badges", {
|
||||
type: "POST",
|
||||
data: {
|
||||
username: username,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { url } from 'discourse/lib/computed';
|
||||
import AdminPost from 'discourse/models/admin-post';
|
||||
|
||||
|
@ -33,7 +34,7 @@ export default Discourse.Model.extend({
|
|||
|
||||
this.set("loading", true);
|
||||
|
||||
return Discourse.ajax(this.get("url"), { cache: false }).then(function (result) {
|
||||
return ajax(this.get("url"), { cache: false }).then(function (result) {
|
||||
if (result) {
|
||||
const posts = result.map(function (post) { return AdminPost.create(post); });
|
||||
self.get("content").pushObjects(posts);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { url } from 'discourse/lib/computed';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import UserAction from 'discourse/models/user-action';
|
||||
|
@ -67,7 +68,7 @@ export default RestModel.extend({
|
|||
|
||||
if (this.get('loading')) { return Ember.RSVP.resolve(); }
|
||||
this.set('loading', true);
|
||||
return Discourse.ajax(findUrl, {cache: 'false'}).then( function(result) {
|
||||
return ajax(findUrl, {cache: 'false'}).then( function(result) {
|
||||
if (result && result.user_actions) {
|
||||
const copy = Em.A();
|
||||
result.user_actions.forEach(function(action) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { url } from 'discourse/lib/computed';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import UserStream from 'discourse/models/user-stream';
|
||||
|
@ -39,7 +40,7 @@ const User = RestModel.extend({
|
|||
staff: Em.computed.or('admin', 'moderator'),
|
||||
|
||||
destroySession() {
|
||||
return Discourse.ajax(`/session/${this.get('username')}`, { type: 'DELETE'});
|
||||
return ajax(`/session/${this.get('username')}`, { type: 'DELETE'});
|
||||
},
|
||||
|
||||
@computed("username_lower")
|
||||
|
@ -125,14 +126,14 @@ const User = RestModel.extend({
|
|||
},
|
||||
|
||||
changeUsername(new_username) {
|
||||
return Discourse.ajax(`/users/${this.get('username_lower')}/preferences/username`, {
|
||||
return ajax(`/users/${this.get('username_lower')}/preferences/username`, {
|
||||
type: 'PUT',
|
||||
data: { new_username }
|
||||
});
|
||||
},
|
||||
|
||||
changeEmail(email) {
|
||||
return Discourse.ajax(`/users/${this.get('username_lower')}/preferences/email`, {
|
||||
return ajax(`/users/${this.get('username_lower')}/preferences/email`, {
|
||||
type: 'PUT',
|
||||
data: { email }
|
||||
});
|
||||
|
@ -202,7 +203,7 @@ const User = RestModel.extend({
|
|||
|
||||
// TODO: We can remove this when migrated fully to rest model.
|
||||
this.set('isSaving', true);
|
||||
return Discourse.ajax(`/users/${this.get('username_lower')}`, {
|
||||
return ajax(`/users/${this.get('username_lower')}`, {
|
||||
data: data,
|
||||
type: 'PUT'
|
||||
}).then(result => {
|
||||
|
@ -216,7 +217,7 @@ const User = RestModel.extend({
|
|||
},
|
||||
|
||||
changePassword() {
|
||||
return Discourse.ajax("/session/forgot_password", {
|
||||
return ajax("/session/forgot_password", {
|
||||
dataType: 'json',
|
||||
data: { login: this.get('username') },
|
||||
type: 'POST'
|
||||
|
@ -225,7 +226,7 @@ const User = RestModel.extend({
|
|||
|
||||
loadUserAction(id) {
|
||||
const stream = this.get('stream');
|
||||
return Discourse.ajax(`/user_actions/${id}.json`, { cache: 'false' }).then(result => {
|
||||
return ajax(`/user_actions/${id}.json`, { cache: 'false' }).then(result => {
|
||||
if (result && result.user_action) {
|
||||
const ua = result.user_action;
|
||||
|
||||
|
@ -278,7 +279,7 @@ const User = RestModel.extend({
|
|||
const user = this;
|
||||
|
||||
return PreloadStore.getAndRemove(`user_${user.get('username')}`, () => {
|
||||
return Discourse.ajax(`/users/${user.get('username')}.json`, { data: options });
|
||||
return ajax(`/users/${user.get('username')}.json`, { data: options });
|
||||
}).then(json => {
|
||||
|
||||
if (!Em.isEmpty(json.user.stats)) {
|
||||
|
@ -315,13 +316,13 @@ const User = RestModel.extend({
|
|||
|
||||
findStaffInfo() {
|
||||
if (!Discourse.User.currentProp("staff")) { return Ember.RSVP.resolve(null); }
|
||||
return Discourse.ajax(`/users/${this.get("username_lower")}/staff-info.json`).then(info => {
|
||||
return ajax(`/users/${this.get("username_lower")}/staff-info.json`).then(info => {
|
||||
this.setProperties(info);
|
||||
});
|
||||
},
|
||||
|
||||
pickAvatar(upload_id, type, avatar_template) {
|
||||
return Discourse.ajax(`/users/${this.get("username_lower")}/preferences/avatar/pick`, {
|
||||
return ajax(`/users/${this.get("username_lower")}/preferences/avatar/pick`, {
|
||||
type: 'PUT',
|
||||
data: { upload_id, type }
|
||||
}).then(() => this.setProperties({
|
||||
|
@ -337,14 +338,14 @@ const User = RestModel.extend({
|
|||
},
|
||||
|
||||
createInvite(email, group_names, custom_message) {
|
||||
return Discourse.ajax('/invites', {
|
||||
return ajax('/invites', {
|
||||
type: 'POST',
|
||||
data: { email, group_names, custom_message }
|
||||
});
|
||||
},
|
||||
|
||||
generateInviteLink(email, group_names, topic_id) {
|
||||
return Discourse.ajax('/invites/link', {
|
||||
return ajax('/invites/link', {
|
||||
type: 'POST',
|
||||
data: { email, group_names, topic_id }
|
||||
});
|
||||
|
@ -377,7 +378,7 @@ const User = RestModel.extend({
|
|||
|
||||
"delete": function() {
|
||||
if (this.get('can_delete_account')) {
|
||||
return Discourse.ajax("/users/" + this.get('username'), {
|
||||
return ajax("/users/" + this.get('username'), {
|
||||
type: 'DELETE',
|
||||
data: {context: window.location.pathname}
|
||||
});
|
||||
|
@ -388,14 +389,14 @@ const User = RestModel.extend({
|
|||
|
||||
dismissBanner(bannerKey) {
|
||||
this.set("dismissed_banner_key", bannerKey);
|
||||
Discourse.ajax(`/users/${this.get('username')}`, {
|
||||
ajax(`/users/${this.get('username')}`, {
|
||||
type: 'PUT',
|
||||
data: { dismissed_banner_key: bannerKey }
|
||||
});
|
||||
},
|
||||
|
||||
checkEmail() {
|
||||
return Discourse.ajax(`/users/${this.get("username_lower")}/emails.json`, {
|
||||
return ajax(`/users/${this.get("username_lower")}/emails.json`, {
|
||||
type: "PUT",
|
||||
data: { context: window.location.pathname }
|
||||
}).then(result => {
|
||||
|
@ -409,7 +410,7 @@ const User = RestModel.extend({
|
|||
},
|
||||
|
||||
summary() {
|
||||
return Discourse.ajax(`/users/${this.get("username_lower")}/summary.json`)
|
||||
return ajax(`/users/${this.get("username_lower")}/summary.json`)
|
||||
.then(json => {
|
||||
const summary = json["user_summary"];
|
||||
const topicMap = {};
|
||||
|
@ -464,7 +465,7 @@ User.reopenClass(Singleton, {
|
|||
},
|
||||
|
||||
checkUsername(username, email, for_user_id) {
|
||||
return Discourse.ajax('/users/check_username', {
|
||||
return ajax('/users/check_username', {
|
||||
data: { username, email, for_user_id }
|
||||
});
|
||||
},
|
||||
|
@ -495,7 +496,7 @@ User.reopenClass(Singleton, {
|
|||
},
|
||||
|
||||
createAccount(attrs) {
|
||||
return Discourse.ajax("/users", {
|
||||
return ajax("/users", {
|
||||
data: {
|
||||
name: attrs.accountName,
|
||||
email: attrs.accountEmail,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
return Discourse.ajax("/about.json").then(result => result.about);
|
||||
return ajax("/about.json").then(result => result.about);
|
||||
},
|
||||
|
||||
titleToken() {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { setting } from 'discourse/lib/computed';
|
||||
import logout from 'discourse/lib/logout';
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
|
@ -28,13 +29,13 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
|||
actions: {
|
||||
|
||||
showSearchHelp() {
|
||||
Discourse.ajax("/static/search_help.html", { dataType: 'html' }).then(model => {
|
||||
ajax("/static/search_help.html", { dataType: 'html' }).then(model => {
|
||||
showModal('searchHelp', { model });
|
||||
});
|
||||
},
|
||||
|
||||
toggleAnonymous() {
|
||||
Discourse.ajax("/users/toggle-anon", {method: 'POST'}).then(() => {
|
||||
ajax("/users/toggle-anon", {method: 'POST'}).then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
},
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { translateResults, getSearchKey, isValidSearchTerm } from "discourse/lib/search";
|
||||
import Composer from 'discourse/models/composer';
|
||||
|
||||
|
@ -25,7 +26,7 @@ export default Discourse.Route.extend({
|
|||
|
||||
return PreloadStore.getAndRemove("search", function() {
|
||||
if (isValidSearchTerm(params.q)) {
|
||||
return Discourse.ajax("/search", { data: args });
|
||||
return ajax("/search", { data: args });
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
export default Discourse.Route.extend({
|
||||
model: function() {
|
||||
return Discourse.ajax("/404-body", { dataType: 'html' });
|
||||
return ajax("/404-body", { dataType: 'html' });
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@ import DiscourseURL from 'discourse/lib/url';
|
|||
import { h } from 'virtual-dom';
|
||||
import { emojiUnescape } from 'discourse/lib/text';
|
||||
import { postUrl, escapeExpression } from 'discourse/lib/utilities';
|
||||
import { setTransientHeader } from 'discourse/lib/ajax';
|
||||
|
||||
const LIKED_TYPE = 5;
|
||||
const INVITED_TYPE = 8;
|
||||
|
@ -101,7 +102,7 @@ createWidget('notification-item', {
|
|||
click(e) {
|
||||
this.attrs.set('read', true);
|
||||
const id = this.attrs.id;
|
||||
Discourse.setTransientHeader("Discourse-Clear-Notifications", id);
|
||||
setTransientHeader("Discourse-Clear-Notifications", id);
|
||||
if (document && document.cookie) {
|
||||
document.cookie = `cn=${id}; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { isValidLink } from 'discourse/lib/click-track';
|
||||
import { number } from 'discourse/lib/formatter';
|
||||
|
||||
|
@ -130,7 +131,7 @@ export default class PostCooked {
|
|||
const postId = parseInt($aside.data('post'), 10);
|
||||
topicId = parseInt(topicId, 10);
|
||||
|
||||
Discourse.ajax(`/posts/by_number/${topicId}/${postId}`).then(result => {
|
||||
ajax(`/posts/by_number/${topicId}/${postId}`).then(result => {
|
||||
const div = $("<div class='expanded-quote'></div>");
|
||||
div.html(result.cooked);
|
||||
div.highlight(originalText, {caseSensitive: true, element: 'span', className: 'highlighted'});
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
//= require ./discourse/mixins/ajax
|
||||
//= require ./discourse
|
||||
|
||||
// Stuff we need to load first
|
||||
|
@ -7,6 +6,7 @@
|
|||
//= require ./ember-addons/macro-alias
|
||||
//= require ./ember-addons/ember-computed-decorators
|
||||
//= require ./discourse/lib/utilities
|
||||
//= require ./discourse/lib/ajax
|
||||
//= require ./discourse/lib/text
|
||||
//= require ./discourse/lib/hash
|
||||
//= require ./discourse/lib/load-script
|
||||
|
|
|
@ -10,7 +10,7 @@ const failedCache = {};
|
|||
|
||||
// Perform a lookup of a onebox based an anchor element. It will insert a loading
|
||||
// indicator and remove it when the loading is complete or fails.
|
||||
export function load(e, refresh) {
|
||||
export function load(e, refresh, ajax) {
|
||||
var $elem = $(e);
|
||||
|
||||
// If the onebox has loaded, return
|
||||
|
@ -34,7 +34,7 @@ export function load(e, refresh) {
|
|||
$elem.addClass('loading-onebox');
|
||||
|
||||
// Retrieve the onebox
|
||||
return Discourse.ajax("/onebox", {
|
||||
return ajax("/onebox", {
|
||||
dataType: 'html',
|
||||
data: { url, refresh },
|
||||
cache: true
|
||||
|
|
|
@ -245,6 +245,7 @@ define("discourse/initializers/login-method-#{hash}",
|
|||
name: "login-method-#{hash}",
|
||||
after: "inject-objects",
|
||||
initialize: function() {
|
||||
if (Ember.testing) { return; }
|
||||
module.register(#{auth_json});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@ function initializeDetails(api) {
|
|||
};
|
||||
});
|
||||
|
||||
const ComposerController = api.container.lookup("controller:composer");
|
||||
const ComposerController = api.container.lookupFactory("controller:composer");
|
||||
ComposerController.reopen({
|
||||
actions: {
|
||||
insertDetails() {
|
||||
|
@ -27,7 +27,6 @@ function initializeDetails(api) {
|
|||
|
||||
export default {
|
||||
name: "apply-details",
|
||||
after: 'inject-objects',
|
||||
|
||||
initialize() {
|
||||
withPluginApi('0.5', initializeDetails);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
export default Ember.Component.extend({
|
||||
layoutName: "components/poll-voters",
|
||||
tagName: 'ul',
|
||||
|
@ -16,7 +17,7 @@ export default Ember.Component.extend({
|
|||
_fetchUsers() {
|
||||
this.set("loading", true);
|
||||
|
||||
Discourse.ajax("/polls/voters.json", {
|
||||
ajax("/polls/voters.json", {
|
||||
type: "get",
|
||||
data: { user_ids: this.get("voterIds") }
|
||||
}).then(result => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { default as computed, observes } from "ember-addons/ember-computed-decorators";
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
|
@ -137,7 +138,7 @@ export default Ember.Controller.extend({
|
|||
|
||||
this.set("loading", true);
|
||||
|
||||
Discourse.ajax("/polls/vote", {
|
||||
ajax("/polls/vote", {
|
||||
type: "PUT",
|
||||
data: {
|
||||
post_id: this.get("post.id"),
|
||||
|
@ -175,7 +176,7 @@ export default Ember.Controller.extend({
|
|||
if (confirmed) {
|
||||
self.set("loading", true);
|
||||
|
||||
Discourse.ajax("/polls/toggle_status", {
|
||||
ajax("/polls/toggle_status", {
|
||||
type: "PUT",
|
||||
data: {
|
||||
post_id: self.get("post.id"),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
import ComposerController from 'discourse/controllers/composer';
|
||||
|
||||
function initializePollUIBuilder(api) {
|
||||
const ComposerController = api.container.lookupFactory("controller:composer");
|
||||
ComposerController.reopen({
|
||||
actions: {
|
||||
showPollBuilder() {
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
module("adapter:topic-list");
|
||||
|
||||
import { finderFor } from 'discourse/adapters/topic-list';
|
||||
|
||||
test("finderFor", function() {
|
||||
// Mocking instead of using a pretender which decodes the path and thus does
|
||||
// not reflect the behavior of an actual web server.
|
||||
var mock = sandbox.mock(Discourse);
|
||||
mock.expects("ajax").withArgs("/search.json?q=test%25%25");
|
||||
var finderForFunction = finderFor('search', { q: "test%%" });
|
||||
finderForFunction();
|
||||
mock.verify();
|
||||
});
|
|
@ -2,32 +2,23 @@ import { blank, present } from 'helpers/qunit-helpers';
|
|||
import AdminUser from 'admin/models/admin-user';
|
||||
import ApiKey from 'admin/models/api-key';
|
||||
|
||||
module("Discourse.AdminUser");
|
||||
|
||||
asyncTestDiscourse('generate key', function() {
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {id: 1234, key: 'asdfasdf'}}));
|
||||
module("model:admin-user");
|
||||
|
||||
test('generate key', function() {
|
||||
var adminUser = AdminUser.create({id: 333});
|
||||
|
||||
blank(adminUser.get('api_key'), 'it has no api key by default');
|
||||
adminUser.generateApiKey().then(function() {
|
||||
start();
|
||||
ok(Discourse.ajax.calledWith("/admin/users/333/generate_api_key", { type: 'POST' }), "it POSTed to the url");
|
||||
present(adminUser.get('api_key'), 'it has an api_key now');
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse('revoke key', function() {
|
||||
test('revoke key', function() {
|
||||
|
||||
var apiKey = ApiKey.create({id: 1234, key: 'asdfasdf'}),
|
||||
adminUser = AdminUser.create({id: 333, api_key: apiKey});
|
||||
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve());
|
||||
|
||||
equal(adminUser.get('api_key'), apiKey, 'it has the api key in the beginning');
|
||||
adminUser.revokeApiKey().then(function() {
|
||||
start();
|
||||
ok(Discourse.ajax.calledWith("/admin/users/333/revoke_api_key", { type: 'DELETE' }), "it DELETEd to the url");
|
||||
blank(adminUser.get('api_key'), 'it cleared the api_key');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
import { present } from 'helpers/qunit-helpers';
|
||||
import ApiKey from 'admin/models/api-key';
|
||||
|
||||
module("Discourse.ApiKey");
|
||||
|
||||
test('create', function() {
|
||||
var apiKey = ApiKey.create({id: 123, user: {id: 345}});
|
||||
|
||||
present(apiKey, 'it creates the api key');
|
||||
present(apiKey.get('user'), 'it creates the user inside');
|
||||
});
|
||||
|
||||
|
||||
asyncTestDiscourse('find', function() {
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve([]));
|
||||
ApiKey.find().then(function() {
|
||||
start();
|
||||
ok(Discourse.ajax.calledWith("/admin/api"), "it GETs the keys");
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse('generateMasterKey', function() {
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {}}));
|
||||
ApiKey.generateMasterKey().then(function() {
|
||||
start();
|
||||
ok(Discourse.ajax.calledWith("/admin/api/key", {type: 'POST'}), "it POSTs to create a master key");
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse('regenerate', function() {
|
||||
var apiKey = ApiKey.create({id: 3456});
|
||||
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {id: 3456}}));
|
||||
apiKey.regenerate().then(function() {
|
||||
start();
|
||||
ok(Discourse.ajax.calledWith("/admin/api/key", {type: 'PUT', data: {id: 3456}}), "it PUTs the key");
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse('revoke', function() {
|
||||
var apiKey = ApiKey.create({id: 3456});
|
||||
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve([]));
|
||||
apiKey.revoke().then(function() {
|
||||
start();
|
||||
ok(Discourse.ajax.calledWith("/admin/api/key", {type: 'DELETE', data: {id: 3456}}), "it DELETES the key");
|
||||
});
|
||||
});
|
|
@ -1,21 +0,0 @@
|
|||
import FlaggedPost from 'admin/models/flagged-post';
|
||||
|
||||
module("Discourse.FlaggedPost");
|
||||
|
||||
test('delete first post', function() {
|
||||
sandbox.stub(Discourse, 'ajax');
|
||||
|
||||
FlaggedPost.create({ id: 1, topic_id: 2, post_number: 1 })
|
||||
.deletePost();
|
||||
|
||||
ok(Discourse.ajax.calledWith("/t/2", { type: 'DELETE', cache: false }), "it deleted the topic");
|
||||
});
|
||||
|
||||
test('delete second post', function() {
|
||||
sandbox.stub(Discourse, 'ajax');
|
||||
|
||||
FlaggedPost.create({ id: 1, topic_id: 2, post_number: 2 })
|
||||
.deletePost();
|
||||
|
||||
ok(Discourse.ajax.calledWith("/posts/1", { type: 'DELETE', cache: false }), "it deleted the post");
|
||||
});
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue