Deprecate success and error in Discourse.ajax

This commit is contained in:
Robin Ward 2013-05-07 11:15:28 -04:00
parent 6cbcd6e4a6
commit 0b4fc5d81c
17 changed files with 61 additions and 56 deletions

View file

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

View file

@ -1,11 +1,11 @@
/** /**
This controller supports the interface for listing users in the admin section. This controller supports the interface for listing users in the admin section.
@class AdminUsersListController @class AdminUsersListController
@extends Ember.ArrayController @extends Ember.ArrayController
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Presence, { Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Presence, {
username: null, username: null,
query: null, query: null,
@ -88,9 +88,13 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres
@method refreshUsers @method refreshUsers
**/ **/
refreshUsers: function() { refreshUsers: function() {
this.set('loading', true); var adminUsersListController = this;
var _this = this; adminUsersListController.set('loading', true);
this.set('content', Discourse.AdminUser.findAll(this.get('query'), this.get('username'), function() { _this.set('loading', false); }));
Discourse.AdminUser.findAll(this.get('query'), this.get('username')).then(function (result) {
adminUsersListController.set('content', result);
adminUsersListController.set('loading', false);
})
}, },
@ -115,5 +119,5 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres
approveUsers: function() { approveUsers: function() {
Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected')); Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected'));
} }
}); });

View file

@ -20,6 +20,6 @@ Discourse.AdminApi = Discourse.Model.extend({
Discourse.AdminApi.reopenClass({ Discourse.AdminApi.reopenClass({
find: function() { find: function() {
return this.getModelAjax('/admin/api'); return this.getModelAjax(Discourse.getURL('/admin/api'));
} }
}); });

View file

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

View file

@ -191,22 +191,18 @@ Discourse.AdminUser.reopenClass({
}, },
find: function(username) { find: function(username) {
return Discourse.ajax({url: Discourse.getURL("/admin/users/") + username}).then(function (result) { return Discourse.ajax(Discourse.getURL("/admin/users/") + username).then(function (result) {
return Discourse.AdminUser.create(result); return Discourse.AdminUser.create(result);
}); });
}, },
findAll: function(query, filter, doneCallback) { findAll: function(query, filter) {
var result = Em.A(); return Discourse.ajax(Discourse.getURL("/admin/users/list/") + query + ".json", {
Discourse.ajax({
url: Discourse.getURL("/admin/users/list/") + query + ".json",
data: { filter: filter } data: { filter: filter }
}).then(function(users) { }).then(function(users) {
users.each(function(u) { return users.map(function(u) {
result.pushObject(Discourse.AdminUser.create(u)); return Discourse.AdminUser.create(u);
}); });
if( doneCallback ) { doneCallback(); }
}); });
return result;
} }
}); });

View file

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

View file

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

View file

@ -90,7 +90,7 @@ Discourse.SiteSetting.reopenClass({
**/ **/
findAll: function() { findAll: function() {
var result = Em.A(); var result = Em.A();
Discourse.ajax({url: Discourse.getURL("/admin/site_settings")}).then(function (settings) { Discourse.ajax(Discourse.getURL("/admin/site_settings")).then(function (settings) {
settings.site_settings.each(function(s) { settings.site_settings.each(function(s) {
s.originalValue = s.value; s.originalValue = s.value;
result.pushObject(Discourse.SiteSetting.create(s)); result.pushObject(Discourse.SiteSetting.create(s));

View file

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

View file

@ -194,7 +194,30 @@ Discourse = Ember.Application.createWithMixins({
@method ajax @method ajax
**/ **/
ajax: function() { ajax: function() {
return $.ajax.apply(this, arguments);
var url, args;
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) {
console.log("DEPRECATION: Discourse.ajax should use promises, received 'success' callback");
}
if (args.error) {
console.log("DEPRECATION: Discourse.ajax should use promises, received 'error' callback");
}
return $.ajax(url, args);
}, },
/** /**

View file

@ -49,9 +49,7 @@ Discourse.Onebox = {
$elem.addClass('loading-onebox'); $elem.addClass('loading-onebox');
// Retrieve the onebox // Retrieve the onebox
var promise = Discourse.ajax({ var promise = Discourse.ajax(Discourse.getURL("/onebox"), {
type: 'GET',
url: "/onebox",
data: { url: url, refresh: refresh } data: { url: url, refresh: refresh }
}); });

View file

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

View file

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

View file

@ -54,7 +54,7 @@ Discourse.Category = Discourse.Model.extend({
Discourse.Category.reopenClass({ Discourse.Category.reopenClass({
findBySlugOrId: function(slugOrId) { findBySlugOrId: function(slugOrId) {
return Discourse.ajax({url: Discourse.getURL("/categories/") + slugOrId + ".json"}).then(function (result) { return Discourse.ajax(Discourse.getURL("/categories/") + slugOrId + ".json").then(function (result) {
return Discourse.Category.create(result.category); return Discourse.Category.create(result.category);
}); });
} }

View file

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

View file

@ -44,7 +44,7 @@ Discourse.Model.reopenClass({
**/ **/
getModelAjax: function(url) { getModelAjax: function(url) {
var modelClass = this; var modelClass = this;
return Discourse.ajax({ url: url, cache: false, dataType: 'json' }).then(function (result) { return Discourse.ajax(url, { cache: false }).then(function (result) {
return modelClass.create(result); return modelClass.create(result);
}); });
}, },

View file

@ -13,19 +13,19 @@ Discourse.Notification = Discourse.Model.extend({
return ''; return '';
}).property('read'), }).property('read'),
url: (function() { url: function() {
if (this.blank('data.topic_title')) return ""; if (this.blank('data.topic_title')) return "";
return Discourse.Utilities.postUrl(this.get('slug'), this.get('topic_id'), this.get('post_number')); return Discourse.Utilities.postUrl(this.get('slug'), this.get('topic_id'), this.get('post_number'));
}).property(), }.property(),
rendered: (function() { rendered: function() {
var notificationName; var notificationName;
notificationName = Discourse.get('site.notificationLookup')[this.notification_type]; notificationName = Discourse.get('site.notificationLookup')[this.notification_type];
return Em.String.i18n("notifications." + notificationName, { return Em.String.i18n("notifications." + notificationName, {
username: this.data.display_username, username: this.data.display_username,
link: "<a href='" + (this.get('url')) + "'>" + this.data.topic_title + "</a>" link: "<a href='" + (this.get('url')) + "'>" + this.data.topic_title + "</a>"
}); });
}).property() }.property()
}); });