From fb6b8e8c36de30053ff66a227c6ba44952bdc9d4 Mon Sep 17 00:00:00 2001 From: Jason Hedrick Date: Mon, 3 Aug 2015 14:11:04 -0700 Subject: [PATCH] learning material files now persisting through refresh --- app/components/detail-learning-materials.js | 6 +----- app/models/learning-material.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/components/detail-learning-materials.js b/app/components/detail-learning-materials.js index f45ba1d358..a1293023b5 100644 --- a/app/components/detail-learning-materials.js +++ b/app/components/detail-learning-materials.js @@ -130,7 +130,7 @@ export default Ember.Component.extend({ addNewLearningMaterial: function(type){ var self = this; if(type === 'file' || type === 'citation' || type === 'link'){ - this.get('learningMaterialStatuses').then(function(statuses){ + self.get('learningMaterialStatuses').then(function(statuses){ self.get('learningMaterialUserRoles').then(function(roles){ //default the status to Final if that status exists var defaultStatus = statuses.find(function(status){ @@ -157,14 +157,12 @@ export default Ember.Component.extend({ self.get('newLearningMaterials').removeObject(lm); if(this.get('isCourse')){ subjectLm = this.get('store').createRecord('course-learning-material', { - learningMaterial: lm, course: this.get('subject') }); lmCollectionType = 'courseLearningMaterials'; } if(this.get('isSession')){ subjectLm = this.get('store').createRecord('session-learning-material', { - learningMaterial: lm, session: this.get('subject') }); lmCollectionType = 'sessionLearningMaterials'; @@ -178,8 +176,6 @@ export default Ember.Component.extend({ self.get('subject.learningMaterials').then(function(lms){ lms.addObject(savedSubjectLm); - lms.save(); - lm.save(); }); }); }); diff --git a/app/models/learning-material.js b/app/models/learning-material.js index b9bf9095c9..712ffffb16 100644 --- a/app/models/learning-material.js +++ b/app/models/learning-material.js @@ -1,11 +1,22 @@ import DS from 'ember-data'; +import Ember from 'ember'; export default DS.Model.extend({ title: DS.attr('string'), description: DS.attr('string'), uploadDate: DS.attr('date'), originalAuthor: DS.attr('string'), - type: DS.attr('string'), + type: Ember.computed('filename', 'citation', 'link', function(){ + if (this.get('filename')) { + return 'file'; + } + if (this.get('citation')) { + return 'citation'; + } + if (this.get('link')) { + return 'link'; + } + }), token: DS.attr('string'), path: DS.attr('string'), copyrightPermission: DS.attr('boolean'),