Skip to content

Commit

Permalink
Merge pull request #5348 from jaswilli/es6-ajax
Browse files Browse the repository at this point in the history
ES6 module version of ic-ajax instead of global
  • Loading branch information
novaugust committed May 27, 2015
2 parents 78041cd + d864fcb commit 3ece83f
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 122 deletions.
1 change: 0 additions & 1 deletion core/client/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"-Notification",
"$",
"validator",
"ic",
"moment"
],
"browser": true,
Expand Down
1 change: 0 additions & 1 deletion core/client/Brocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ app = new EmberApp({
// 'dem Scripts
app.import('bower_components/loader.js/loader.js');
app.import('bower_components/jquery/dist/jquery.js');
app.import('bower_components/ic-ajax/dist/globals/main.js');
app.import('bower_components/ember-load-initializers/ember-load-initializers.js');
app.import('bower_components/validator-js/validator.js');
app.import('bower_components/rangyinputs/rangyinputs-jquery-src.js');
Expand Down
8 changes: 4 additions & 4 deletions core/client/app/controllers/modals/delete-all.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Ember from 'ember';
var DeleteAllController = Ember.Controller.extend({
import {request as ajax} from 'ic-ajax';

export default Ember.Controller.extend({
actions: {
confirmAccept: function () {
var self = this;

ic.ajax.request(this.get('ghostPaths.url').api('db'), {
ajax(this.get('ghostPaths.url').api('db'), {
type: 'DELETE'
}).then(function () {
self.notifications.showSuccess('All content deleted from database.');
Expand All @@ -31,5 +33,3 @@ var DeleteAllController = Ember.Controller.extend({
}
}
});

export default DeleteAllController;
8 changes: 4 additions & 4 deletions core/client/app/controllers/modals/transfer-owner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Ember from 'ember';
var TransferOwnerController = Ember.Controller.extend({
import {request as ajax} from 'ic-ajax';

export default Ember.Controller.extend({
actions: {
confirmAccept: function () {
var user = this.get('model'),
Expand All @@ -8,7 +10,7 @@ var TransferOwnerController = Ember.Controller.extend({

self.get('dropdown').closeDropdowns();

ic.ajax.request(url, {
ajax(url, {
type: 'PUT',
data: {
owner: [{
Expand Down Expand Up @@ -49,5 +51,3 @@ var TransferOwnerController = Ember.Controller.extend({
}
}
});

export default TransferOwnerController;
116 changes: 57 additions & 59 deletions core/client/app/controllers/reset.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,58 @@
import Ember from 'ember';
import ajax from 'ghost/utils/ajax';
import ValidationEngine from 'ghost/mixins/validation-engine';

var ResetController = Ember.Controller.extend(ValidationEngine, {
newPassword: '',
ne2Password: '',
token: '',
submitting: false,

validationType: 'reset',

email: Ember.computed('token', function () {
// The token base64 encodes the email (and some other stuff),
// each section is divided by a '|'. Email comes second.
return atob(this.get('token')).split('|')[1];
}),

// Used to clear sensitive information
clearData: function () {
this.setProperties({
newPassword: '',
ne2Password: '',
token: ''
});
},

actions: {
submit: function () {
var credentials = this.getProperties('newPassword', 'ne2Password', 'token'),
self = this;

this.toggleProperty('submitting');
this.validate({format: false}).then(function () {
ajax({
url: self.get('ghostPaths.url').api('authentication', 'passwordreset'),
type: 'PUT',
data: {
passwordreset: [credentials]
}
}).then(function (resp) {
self.toggleProperty('submitting');
self.notifications.showSuccess(resp.passwordreset[0].message, true);
self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', {
identification: self.get('email'),
password: credentials.newPassword
});
}).catch(function (response) {
self.notifications.showAPIError(response);
self.toggleProperty('submitting');
});
}).catch(function (error) {
self.toggleProperty('submitting');
self.notifications.showErrors(error);
});
}
}
});

export default ResetController;
import {request as ajax} from 'ic-ajax';
import ValidationEngine from 'ghost/mixins/validation-engine';

export default Ember.Controller.extend(ValidationEngine, {
newPassword: '',
ne2Password: '',
token: '',
submitting: false,

validationType: 'reset',

email: Ember.computed('token', function () {
// The token base64 encodes the email (and some other stuff),
// each section is divided by a '|'. Email comes second.
return atob(this.get('token')).split('|')[1];
}),

// Used to clear sensitive information
clearData: function () {
this.setProperties({
newPassword: '',
ne2Password: '',
token: ''
});
},

actions: {
submit: function () {
var credentials = this.getProperties('newPassword', 'ne2Password', 'token'),
self = this;

this.toggleProperty('submitting');
this.validate({format: false}).then(function () {
ajax({
url: self.get('ghostPaths.url').api('authentication', 'passwordreset'),
type: 'PUT',
data: {
passwordreset: [credentials]
}
}).then(function (resp) {
self.toggleProperty('submitting');
self.notifications.showSuccess(resp.passwordreset[0].message, true);
self.get('session').authenticate('simple-auth-authenticator:oauth2-password-grant', {
identification: self.get('email'),
password: credentials.newPassword
});
}).catch(function (response) {
self.notifications.showAPIError(response);
self.toggleProperty('submitting');
});
}).catch(function (error) {
self.toggleProperty('submitting');
self.notifications.showErrors(error);
});
}
}
});
10 changes: 5 additions & 5 deletions core/client/app/controllers/settings/labs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Ember from 'ember';
var LabsController = Ember.Controller.extend(Ember.Evented, {
import {request as ajax} from 'ic-ajax';

export default Ember.Controller.extend(Ember.Evented, {
needs: ['feature'],

uploadButtonText: 'Import',
Expand Down Expand Up @@ -34,7 +36,7 @@ var LabsController = Ember.Controller.extend(Ember.Evented, {

formData.append('importfile', file);

ic.ajax.request(this.get('ghostPaths.url').api('db'), {
ajax(this.get('ghostPaths.url').api('db'), {
type: 'POST',
data: formData,
dataType: 'json',
Expand Down Expand Up @@ -77,7 +79,7 @@ var LabsController = Ember.Controller.extend(Ember.Evented, {
sendTestEmail: function () {
var self = this;

ic.ajax.request(this.get('ghostPaths.url').api('mail', 'test'), {
ajax(this.get('ghostPaths.url').api('mail', 'test'), {
type: 'POST'
}).then(function () {
self.notifications.showSuccess('Check your email for the test message.');
Expand All @@ -91,5 +93,3 @@ var LabsController = Ember.Controller.extend(Ember.Evented, {
}
}
});

export default LabsController;
6 changes: 2 additions & 4 deletions core/client/app/controllers/setup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ember from 'ember';
import ajax from 'ghost/utils/ajax';
import {request as ajax} from 'ic-ajax';
import ValidationEngine from 'ghost/mixins/validation-engine';

var SetupController = Ember.Controller.extend(ValidationEngine, {
export default Ember.Controller.extend(ValidationEngine, {
blogTitle: null,
name: null,
email: null,
Expand Down Expand Up @@ -48,5 +48,3 @@ var SetupController = Ember.Controller.extend(ValidationEngine, {
}
}
});

export default SetupController;
6 changes: 2 additions & 4 deletions core/client/app/controllers/signin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ember from 'ember';
import ValidationEngine from 'ghost/mixins/validation-engine';
import ajax from 'ghost/utils/ajax';
import {request as ajax} from 'ic-ajax';

var SigninController = Ember.Controller.extend(ValidationEngine, {
export default Ember.Controller.extend(ValidationEngine, {
validationType: 'signin',

submitting: false,
Expand Down Expand Up @@ -63,5 +63,3 @@ var SigninController = Ember.Controller.extend(ValidationEngine, {
}
}
});

export default SigninController;
6 changes: 2 additions & 4 deletions core/client/app/controllers/signup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ember from 'ember';
import ajax from 'ghost/utils/ajax';
import {request as ajax} from 'ic-ajax';
import ValidationEngine from 'ghost/mixins/validation-engine';

var SignupController = Ember.Controller.extend(ValidationEngine, {
export default Ember.Controller.extend(ValidationEngine, {
submitting: false,

// ValidationEngine settings
Expand Down Expand Up @@ -46,5 +46,3 @@ var SignupController = Ember.Controller.extend(ValidationEngine, {
}
}
});

export default SignupController;
6 changes: 2 additions & 4 deletions core/client/app/mixins/pagination-controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import { getRequestErrorMessage } from 'ghost/utils/ajax';
import getRequestErrorMessage from 'ghost/utils/ajax';

var PaginationControllerMixin = Ember.Mixin.create({
export default Ember.Mixin.create({
// set from PaginationRouteMixin
paginationSettings: null,

Expand Down Expand Up @@ -57,5 +57,3 @@ var PaginationControllerMixin = Ember.Mixin.create({
}
}
});

export default PaginationControllerMixin;
6 changes: 2 additions & 4 deletions core/client/app/mixins/validation-engine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from 'ember';
import DS from 'ember-data';
import {getRequestErrorMessage} from 'ghost/utils/ajax';
import getRequestErrorMessage from 'ghost/utils/ajax';

import ValidatorExtensions from 'ghost/utils/validator-extensions';
import PostValidator from 'ghost/validators/post';
Expand Down Expand Up @@ -61,7 +61,7 @@ function formatErrors(errors, opts) {
* It will be able to validate any properties on itself (or the model it passes to validate())
* with the use of a declared validator.
*/
var ValidationEngine = Ember.Mixin.create({
export default Ember.Mixin.create({
// these validators can be passed a model to validate when the class that
// mixes in the ValidationEngine declares a validationType equal to a key on this object.
// the model is either passed in via `this.validate({ model: object })`
Expand Down Expand Up @@ -174,5 +174,3 @@ var ValidationEngine = Ember.Mixin.create({
});
}
});

export default ValidationEngine;
12 changes: 8 additions & 4 deletions core/client/app/models/slug-generator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import Ember from 'ember';
var SlugGenerator = Ember.Object.extend({
import {request as ajax} from 'ic-ajax';

export default Ember.Object.extend({
ghostPaths: null,
slugType: null,
value: null,

toString: function () {
return this.get('value');
},

generateSlug: function (textToSlugify) {
var self = this,
url;
Expand All @@ -16,14 +20,14 @@ var SlugGenerator = Ember.Object.extend({

url = this.get('ghostPaths.url').api('slugs', this.get('slugType'), encodeURIComponent(textToSlugify));

return ic.ajax.request(url, {
return ajax(url, {
type: 'GET'
}).then(function (response) {
var slug = response.slugs[0].slug;

self.set('value', slug);

return slug;
});
}
});

export default SlugGenerator;
9 changes: 4 additions & 5 deletions core/client/app/models/user.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Ember from 'ember';
import DS from 'ember-data';
import {request as ajax} from 'ic-ajax';
import ValidationEngine from 'ghost/mixins/validation-engine';
import SelectiveSaveMixin from 'ghost/mixins/selective-save';

var User = DS.Model.extend(SelectiveSaveMixin, ValidationEngine, {
export default DS.Model.extend(SelectiveSaveMixin, ValidationEngine, {
validationType: 'user',

uuid: DS.attr('string'),
Expand Down Expand Up @@ -49,7 +50,7 @@ var User = DS.Model.extend(SelectiveSaveMixin, ValidationEngine, {
saveNewPassword: function () {
var url = this.get('ghostPaths.url').api('users', 'password');

return ic.ajax.request(url, {
return ajax(url, {
type: 'PUT',
data: {
password: [{
Expand All @@ -69,7 +70,7 @@ var User = DS.Model.extend(SelectiveSaveMixin, ValidationEngine, {
roles: fullUserData.roles
};

return ic.ajax.request(this.get('ghostPaths.url').api('users'), {
return ajax(this.get('ghostPaths.url').api('users'), {
type: 'POST',
data: JSON.stringify({users: [userData]}),
contentType: 'application/json'
Expand Down Expand Up @@ -102,5 +103,3 @@ var User = DS.Model.extend(SelectiveSaveMixin, ValidationEngine, {

pending: Ember.computed.equal('status', 'invited-pending').property('status')
});

export default User;
3 changes: 2 additions & 1 deletion core/client/app/routes/about.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {request as ajax} from 'ic-ajax';
import AuthenticatedRoute from 'ghost/routes/authenticated';
import styleBody from 'ghost/mixins/style-body';

Expand All @@ -16,7 +17,7 @@ export default AuthenticatedRoute.extend(styleBody, {
return cachedConfig;
}

return ic.ajax.request(this.get('ghostPaths.url').api('configuration'))
return ajax(this.get('ghostPaths.url').api('configuration'))
.then(function (configurationResponse) {
var configKeyValues = configurationResponse.configuration;

Expand Down
Loading

0 comments on commit 3ece83f

Please sign in to comment.