mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:49:14 +08:00
REFACTOR: ajax
defaults to json data type for GET requests.
This commit is contained in:
parent
4efb3069e2
commit
af0b6ce53d
|
@ -50,7 +50,7 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
removeOwner(member) {
|
||||
var self = this;
|
||||
return ajax('/admin/groups/' + this.get('id') + '/owners.json', {
|
||||
return ajax(`/admin/groups/${this.get('id')}/owners`, {
|
||||
type: "DELETE",
|
||||
data: { user_id: member.get("id") }
|
||||
}).then(function() {
|
||||
|
@ -61,7 +61,7 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
removeMember(member) {
|
||||
var self = this;
|
||||
return ajax('/groups/' + this.get('id') + '/members.json', {
|
||||
return ajax(`/groups/${this.get('id')}/members`, {
|
||||
type: "DELETE",
|
||||
data: { user_id: member.get("id") }
|
||||
}).then(function() {
|
||||
|
@ -72,7 +72,7 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
addMembers(usernames) {
|
||||
var self = this;
|
||||
return ajax('/groups/' + this.get('id') + '/members.json', {
|
||||
return ajax(`/groups/${this.get('id')}/members`, {
|
||||
type: "PUT",
|
||||
data: { usernames: usernames }
|
||||
}).then(function() {
|
||||
|
@ -82,7 +82,7 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
addOwners(usernames) {
|
||||
var self = this;
|
||||
return ajax('/admin/groups/' + this.get('id') + '/owners.json', {
|
||||
return ajax(`/admin/groups/${this.get('id')}/owners`, {
|
||||
type: "PUT",
|
||||
data: { usernames: usernames }
|
||||
}).then(function() {
|
||||
|
@ -141,7 +141,7 @@ const Group = Discourse.Model.extend({
|
|||
var data = {};
|
||||
if (opts.beforePostId) { data.before_post_id = opts.beforePostId; }
|
||||
|
||||
return ajax(`/groups/${this.get('name')}/${type}.json`, { data: data }).then(posts => {
|
||||
return ajax(`/groups/${this.get('name')}/${type}`, { data: data }).then(posts => {
|
||||
return posts.map(p => {
|
||||
p.user = Discourse.User.create(p.user);
|
||||
p.topic = Discourse.Topic.create(p.topic);
|
||||
|
@ -161,21 +161,21 @@ const Group = Discourse.Model.extend({
|
|||
|
||||
Group.reopenClass({
|
||||
findAll(opts) {
|
||||
return ajax("/admin/groups.json", { data: opts }).then(function (groups){
|
||||
return ajax("/admin/groups", { data: opts }).then(function (groups){
|
||||
return groups.map(g => Group.create(g));
|
||||
});
|
||||
},
|
||||
|
||||
findGroupCounts(name) {
|
||||
return ajax("/groups/" + name + "/counts.json").then(result => Em.Object.create(result.counts));
|
||||
return ajax(`/groups/${name}/counts`).then(result => Em.Object.create(result.counts));
|
||||
},
|
||||
|
||||
find(name) {
|
||||
return ajax("/groups/" + name + ".json").then(result => Group.create(result.basic_group));
|
||||
return ajax(`/groups/${name}`).then(result => Group.create(result.basic_group));
|
||||
},
|
||||
|
||||
loadMembers(name, offset, limit) {
|
||||
return ajax('/groups/' + name + '/members.json', {
|
||||
return ajax(`/groups/${name}/members`, {
|
||||
data: {
|
||||
limit: limit || 50,
|
||||
offset: offset || 0
|
||||
|
|
|
@ -397,8 +397,6 @@ Discourse::Application.routes.draw do
|
|||
get "posts/:username/deleted" => "posts#deleted_posts", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "posts/:username/flagged" => "posts#flagged_posts", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
|
||||
get "groups/:id.json" => 'groups#show', constraints: {id: USERNAME_ROUTE_FORMAT}, defaults: {format: 'json'}
|
||||
|
||||
resources :groups, id: USERNAME_ROUTE_FORMAT do
|
||||
get "posts.rss" => "groups#posts_feed", format: :rss
|
||||
get "mentions.rss" => "groups#mentions_feed", format: :rss
|
||||
|
|
Loading…
Reference in New Issue
Block a user