common/corpus-common-addon/addon/components/doc-location.js
changeset 304 20071981ba2a
child 391 4f6118afabee
equal deleted inserted replaced
303:2fef8007c2b2 304:20071981ba2a
       
     1 import Ember from 'ember';
       
     2 import * as constants from 'corpus-common-addon/utils/constants';
       
     3 import layout from '../templates/components/doc-location';
       
     4 
       
     5 export default Ember.Component.extend({
       
     6   layout: layout,
       
     7   tagName: 'span',
       
     8 
       
     9   geonamesResolver: Ember.inject.service(),
       
    10 
       
    11   _resolveGeonamesIds: Ember.on('init', Ember.observer('url', function() {
       
    12     this.get('geonamesResolver').getLabel(this.get('url')).then(function(str) {
       
    13       this.set('resolvedLabel', str);
       
    14     }.bind(this));
       
    15   })),
       
    16 
       
    17   code: Ember.computed('url', function() {
       
    18     var rawLocation = this.get('url');
       
    19     var m = rawLocation.match(constants.GEONAMES_BASE_URLS);
       
    20 
       
    21     if (m) {
       
    22       rawLocation = rawLocation.slice(m[0].length);
       
    23     }
       
    24 
       
    25     return rawLocation.replace(/\/+$/, '');
       
    26   }),
       
    27   isLocationLink: Ember.computed.match('url', /^http:\/\//)
       
    28 
       
    29 });