cms/app-client/app/components/doc-rights.js
author ymh <ymh.work@gmail.com>
Fri, 08 Sep 2017 15:03:29 +0200
changeset 543 aaaf9b0b09f6
parent 502 74fba571487e
permissions -rw-r--r--
upgrade ember

import Ember from 'ember';

const CC_LICENCE_URL_REGEXP = /http:\/\/creativecommons\.org\/licenses\/([byndsac-]+)\/([\d\.]+)\//; // eslint-disable-line no-useless-escape
const CC_LICENCE_TEXT = {
  'by': 'Attribution',
  'by-nd': 'Attribution - Pas de Modification',
  'by-sa': 'Attribution - Partage dans les Mêmes Conditions',
  'by-nc': 'Attribution - Pas d’Utilisation Commerciale',
  'by-nc-nd': 'Attribution - Pas d\'Utilisation Commerciale - Pas de Modification',
  'by-nc-sa': 'Attribution - Pas d\'Utilisation Commerciale - Partage dans les Mêmes Conditions'
};

export default Ember.Component.extend({
  tagName: 'span',
  code: Ember.computed('matches', function() {
    return this.get('matches')[1];
  }),
  version: Ember.computed('matches', function() {
    return this.get('matches')[2];
  }),
  matches: Ember.computed('url', function() {
    const url = this.get('url');
    if(!url) {
      return [url,'by', '4.0'];
    }
    let m = url.match(CC_LICENCE_URL_REGEXP);
    if(m === null || m.length !== 3) {
      return [url,'by', '4.0'];
    }
    return m;
  }),
  text: Ember.computed('code', function() {
    const code = this.get('code');
    return CC_LICENCE_TEXT[code];
  })

});