@@ -97,35 +97,35 @@ define([
9797 var flatItem = Helpers . flattenNestedProperties ( this . editor . value ) ;
9898 var itemValues = _ . values ( flatItem ) ;
9999 var parentAttributes = Origin . scaffold . getCurrentModel ( ) . attributes ;
100- _ . each ( itemValues , function ( item ) {
101- if ( typeof item === 'string' && item . indexOf ( 'course/assets' ) !== - 1 ) {
102- var itemFileName = item . substring ( item . lastIndexOf ( '/' ) + 1 ) ;
103- $ . ajax ( {
104- url : 'api/asset/query' ,
105- type : 'GET ',
106- data : { search : { filename : itemFileName } } ,
107- success : function ( result ) {
108- ( new CourseAssetModel ( ) ) . save ( {
109- _courseId : Origin . editor . data . course . get ( '_id' ) ,
110- _contentType : parentAttributes . _type ,
111- _contentTypeId : parentAttributes . _id ,
112- _fieldName : itemFileName ,
113- _assetId : result [ 0 ] . _id ,
114- _contentTypeParentId : parentAttributes . _parentId
115- } , {
116- error : function ( error ) {
117- Origin . Notify . alert ( {
118- type : 'error' ,
119- text : Origin . l10n . t ( 'app.errorsaveasset' )
120- } ) ;
121- }
122- } ) ;
123- } ,
124- error : function ( ) {
125- Origin . Notify . alert ( { type : ' error' , text : Origin . l10n . t ( 'app.errorduplication' ) } ) ;
126- }
127- } ) ;
128- }
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+ } ) ;
129129 } ) ;
130130
131131 this . list . addItem ( this . editor . value , true ) ;
0 commit comments