cms/app-client/app/components/doc-rights.js
changeset 502 74fba571487e
child 543 aaaf9b0b09f6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cms/app-client/app/components/doc-rights.js	Wed Feb 08 15:25:24 2017 +0100
@@ -0,0 +1,37 @@
+import Ember from 'ember';
+
+const CC_LICENCE_URL_REGEXP = /http:\/\/creativecommons\.org\/licenses\/([byndsac-]+)\/([\d\.]+)\//;
+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];
+  })
+
+});