cms/app-client/app/models/document.js
author ymh <ymh.work@gmail.com>
Mon, 22 Feb 2016 18:06:39 +0100
changeset 126 e87a340711a4
parent 125 e550b10fe3ca
child 209 35cb7200bb0a
permissions -rw-r--r--
improve on dataloading. add fixture management with proper interface to load data.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     1
import DS from 'ember-data';
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     2
import Ember from 'ember';
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
     3
import _ from 'lodash/lodash';
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     4
121
08c99d286e7c Remove Document def warning
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
     5
var CPDocument = DS.Model.extend({
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     6
  // id: DS.attr('string'),
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     7
  uri: DS.attr('string'),
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     8
  title: DS.attr('string'),
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     9
  language: DS.attr('string'),
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    10
  publishers: DS.attr({defaultValue: []}),
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    11
  contributors: DS.attr({defaultValue: []}),
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    12
  mediaArray: DS.attr({defaultValue: []}),
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    13
  mediaList: Ember.computed('mediaArray', function() {
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    14
    var res = [];
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    15
    var mp3 = null;
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    16
    _.forEach(this.get('mediaArray'), function(m) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    17
      if(m.format === 'audio/mpeg') {
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    18
        mp3 = m;
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    19
      } else if (m.format.startsWith('audio/')) {
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    20
        res.push(m);
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    21
      }
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    22
    });
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    23
    if(mp3) {
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    24
      res.unshift(mp3);
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    25
    }
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    26
    return res;
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    27
  })
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    28
});
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    29
121
08c99d286e7c Remove Document def warning
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
    30
CPDocument.reopenClass({
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    31
  FIXTURES: [
126
e87a340711a4 improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
    32
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    33
  ]
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    34
});
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    35
121
08c99d286e7c Remove Document def warning
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
    36
export default CPDocument;