|
1 | 1 | define([ |
2 | 2 | 'core/origin', |
| 3 | + 'core/helpers', |
| 4 | + 'core/models/courseAssetModel', |
3 | 5 | 'backbone-forms', |
4 | 6 | 'backbone-forms-lists' |
5 | | -], function(Origin, BackboneForms) { |
| 7 | +], function(Origin, Helpers, CourseAssetModel, BackboneForms) { |
6 | 8 |
|
7 | 9 | var ScaffoldListView = Backbone.Form.editors.List.extend({ |
8 | 10 | defaultValue: [], |
@@ -92,9 +94,42 @@ define([ |
92 | 94 | }, |
93 | 95 |
|
94 | 96 | cloneItem: function(event) { |
| 97 | + var flatItem = Helpers.flattenNestedProperties(this.editor.value); |
| 98 | + var itemValues = _.values(flatItem); |
| 99 | + var parentAttributes = Origin.scaffold.getCurrentModel().attributes; |
| 100 | + itemValues.forEach(function(item) { |
| 101 | + if (typeof item !== 'string' || item.indexOf('course/assets') === -1) return; |
| 102 | + |
| 103 | + var itemFileName = item.substring(item.lastIndexOf('/')+1); |
| 104 | + $.ajax({ |
| 105 | + url: 'api/asset/query', |
| 106 | + type:'GET', |
| 107 | + data: {search: { filename: itemFileName }}, |
| 108 | + success: function (result) { |
| 109 | + (new CourseAssetModel()).save({ |
| 110 | + _courseId : Origin.editor.data.course.get('_id'), |
| 111 | + _contentType : parentAttributes._type, |
| 112 | + _contentTypeId : parentAttributes._id, |
| 113 | + _fieldName : itemFileName, |
| 114 | + _assetId : result[0]._id, |
| 115 | + _contentTypeParentId: parentAttributes._parentId |
| 116 | + }, { |
| 117 | + error: function(error) { |
| 118 | + Origin.Notify.alert({ |
| 119 | + type: 'error', |
| 120 | + text: Origin.l10n.t('app.errorsaveasset') |
| 121 | + }); |
| 122 | + } |
| 123 | + }); |
| 124 | + }, |
| 125 | + error: function() { |
| 126 | + Origin.Notify.alert({ type: 'error', text: Origin.l10n.t('app.errorduplication') }); |
| 127 | + } |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
95 | 131 | this.list.addItem(this.editor.value, true); |
96 | 132 | } |
97 | | - |
98 | 133 | }); |
99 | 134 |
|
100 | 135 | Origin.on('origin:dataReady', function() { |
|
0 commit comments