common/corpus-common-addon/addon/components/doc-created.js
author ymh <ymh.work@gmail.com>
Wed, 22 Feb 2017 17:58:25 +0100
changeset 521 b3c738a20af8
parent 519 ef3e4841d506
permissions -rw-r--r--
Add transcript right declaration, resolve bug #0026452
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
445
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import Ember from 'ember';
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import layout from '../templates/components/doc-created';
519
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
     3
import * as utils from 'corpus-common-addon/utils/utils';
445
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
export default Ember.Component.extend({
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
  layout: layout,
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
  tagName: 'span',
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
  value: null,
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
  formatDate: function (dateStr, dateParsed) {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    if (!dateStr) {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
      return Ember.String.htmlSafe('');
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    }
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    if (/^\d{4}$/.test(dateStr)) {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
      return Ember.String.htmlSafe(dateStr);
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    }
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    const date = dateParsed || new Date(dateStr);
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    if (isNaN(date.getTime())) {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
      return Ember.String.htmlSafe('Date inconnue');
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    }
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    if (/^\d{4}-\d{2}$/.test(dateStr)) {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
      return Ember.String.htmlSafe((date.getMonth() + 1) + '-' + date.getFullYear());
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    }
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    return Ember.String.htmlSafe(date.getDate() + '-' + (date.getMonth() + 1) + '-' + date.getFullYear());
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
  },
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
  shortDateDate: Ember.computed('value', function () {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    return this.formatDate(this.get('value'));
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
  }),
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
  periodMatches: Ember.computed('value', function () {
519
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    33
    const dateStr = this.get('value');
445
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
519
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    35
    return utils.getPeriodMatches(dateStr);
445
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
  }),
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
  isPeriod: Ember.computed('periodMatches', function () {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    const periodMatches = this.get('periodMatches');
447
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 445
diff changeset
    39
445
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    return Boolean(periodMatches);
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
  }),
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
  shortDateStart: Ember.computed('periodMatches', function () {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    const periodMatches = this.get('periodMatches');
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
    if (!periodMatches) {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
      return null;
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    }
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    // from the periodMatches function we know that we have a valid start date
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    return this.formatDate(periodMatches.start.str, periodMatches.start.date);
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
  }),
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
  shortDateEnd: Ember.computed('periodMatches', function () {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
    const periodMatches = this.get('periodMatches');
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    if (!periodMatches) {
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
      return null;
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
    }
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    // from the periodMatches function we know that we have a valid end date
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    return this.formatDate(periodMatches.end.str, periodMatches.end.date);
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
513
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    63
  }),
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    64
  click() {
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    65
    const action = this.get('action');
445
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
513
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    67
    if (action) {
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    68
      action();
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    69
    }
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    70
  }
445
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
b1e5ad6b2a29 Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
});