2015-02-12 21:22:32 -07:00
|
|
|
import Ember from 'ember';
|
2015-05-26 19:41:12 -05:00
|
|
|
import {request as ajax} from 'ic-ajax';
|
|
|
|
|
|
|
|
export default Ember.Object.extend({
|
2014-07-31 00:25:42 -04:00
|
|
|
slugType: null,
|
2014-06-08 14:48:14 -06:00
|
|
|
value: null,
|
2015-05-26 19:41:12 -05:00
|
|
|
|
2015-05-25 21:10:50 -05:00
|
|
|
ghostPaths: Ember.inject.service('ghost-paths'),
|
|
|
|
|
2014-06-08 14:48:14 -06:00
|
|
|
toString: function () {
|
|
|
|
return this.get('value');
|
|
|
|
},
|
2015-05-26 19:41:12 -05:00
|
|
|
|
2014-06-08 14:48:14 -06:00
|
|
|
generateSlug: function (textToSlugify) {
|
|
|
|
var self = this,
|
|
|
|
url;
|
|
|
|
|
|
|
|
if (!textToSlugify) {
|
|
|
|
return Ember.RSVP.resolve('');
|
|
|
|
}
|
|
|
|
|
2014-07-31 00:25:42 -04:00
|
|
|
url = this.get('ghostPaths.url').api('slugs', this.get('slugType'), encodeURIComponent(textToSlugify));
|
2014-06-08 14:48:14 -06:00
|
|
|
|
2015-05-26 19:41:12 -05:00
|
|
|
return ajax(url, {
|
2014-06-08 14:48:14 -06:00
|
|
|
type: 'GET'
|
|
|
|
}).then(function (response) {
|
|
|
|
var slug = response.slugs[0].slug;
|
2015-05-26 19:41:12 -05:00
|
|
|
|
2014-06-08 14:48:14 -06:00
|
|
|
self.set('value', slug);
|
2015-05-26 19:41:12 -05:00
|
|
|
|
2014-06-08 14:48:14 -06:00
|
|
|
return slug;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|