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