@@ -853,7 +853,6 @@ define([
853
853
854
854
// Set a beforeunload event only if there isn't one already
855
855
if ( ! this . beforeunloadCallback ) {
856
- const view = this ;
857
856
// When the Window is about to be closed, show a confirmation message
858
857
this . beforeunloadCallback = ( e ) => {
859
858
if ( ! view . canClose ( ) ) {
@@ -1103,71 +1102,98 @@ define([
1103
1102
*/
1104
1103
showEntity ( e ) {
1105
1104
if ( ! e || ! e . target ) return ;
1105
+ if ( this . model . type !== "EML" ) return ;
1106
1106
1107
- // For EML metadata docs
1108
- if ( this . model . type === "EML" ) {
1109
- // Get the Entity View
1110
- const row = $ ( e . target ) . parents ( ".data-package-item" ) ;
1111
- let entityView = row . data ( "entityView" ) ;
1112
- const dataONEObject = row . data ( "model" ) ;
1107
+ // Get the Entity View
1108
+ const row = $ ( e . target ) . parents ( ".data-package-item" ) ;
1109
+ let entityView = row . data ( "entityView" ) ;
1110
+ const dataONEObject = row . data ( "model" ) ;
1113
1111
1114
- if (
1115
- dataONEObject . get ( "uploadStatus" ) === "p" ||
1116
- dataONEObject . get ( "uploadStatus" ) === "l" ||
1117
- dataONEObject . get ( "uploadStatus" ) === "e"
1118
- )
1119
- return ;
1120
-
1121
- // If there isn't a view yet, create one
1122
- if ( ! entityView ) {
1123
- // Get the entity model for this data package item
1124
- let entityModel = this . model . getEntity ( row . data ( "model" ) ) ;
1125
-
1126
- // Create a new EMLOtherEntity if it doesn't exist
1127
- if ( ! entityModel ) {
1128
- entityModel = new EMLOtherEntity ( {
1129
- entityName : dataONEObject . get ( "fileName" ) ,
1130
- entityType :
1131
- dataONEObject . get ( "formatId" ) ||
1132
- dataONEObject . get ( "mediaType" ) ,
1133
- parentModel : this . model ,
1134
- xmlID : dataONEObject . getXMLSafeID ( ) ,
1135
- } ) ;
1112
+ if (
1113
+ dataONEObject . get ( "uploadStatus" ) === "p" ||
1114
+ dataONEObject . get ( "uploadStatus" ) === "l" ||
1115
+ dataONEObject . get ( "uploadStatus" ) === "e"
1116
+ )
1117
+ return ;
1136
1118
1137
- if ( ! dataONEObject . get ( "fileName" ) ) {
1138
- // Listen to changes to required fields on the otherEntity
1139
- // models
1140
- this . listenTo ( entityModel , "change:entityName" , ( ) => {
1141
- if ( ! entityModel . isValid ( ) ) return ;
1119
+ // If there isn't a view yet, create one
1120
+ if ( ! entityView ) {
1121
+ // Get the entity model for this data package item
1122
+ let entityModel = this . model . getEntity ( row . data ( "model" ) ) ;
1123
+
1124
+ // Create a new EMLOtherEntity if it doesn't exist
1125
+ if ( ! entityModel ) {
1126
+ entityModel = new EMLOtherEntity ( {
1127
+ entityName : dataONEObject . get ( "fileName" ) ,
1128
+ entityType :
1129
+ dataONEObject . get ( "formatId" ) || dataONEObject . get ( "mediaType" ) ,
1130
+ parentModel : this . model ,
1131
+ xmlID : dataONEObject . getXMLSafeID ( ) ,
1132
+ } ) ;
1142
1133
1143
- // Get the position this entity will be in
1144
- const position = $ ( ".data-package-item.data" ) . index ( row ) ;
1134
+ if ( ! dataONEObject . get ( "fileName" ) ) {
1135
+ // Listen to changes to required fields on the otherEntity
1136
+ // models
1137
+ this . listenTo ( entityModel , "change:entityName" , ( ) => {
1138
+ if ( ! entityModel . isValid ( ) ) return ;
1145
1139
1146
- this . model . addEntity ( entityModel , position ) ;
1147
- } ) ;
1148
- } else {
1149
1140
// Get the position this entity will be in
1150
1141
const position = $ ( ".data-package-item.data" ) . index ( row ) ;
1151
1142
1152
1143
this . model . addEntity ( entityModel , position ) ;
1153
- }
1154
- } else {
1155
- entityView = new EMLEntityView ( {
1156
- model : entityModel ,
1157
- DataONEObject : dataONEObject ,
1158
- edit : true ,
1159
1144
} ) ;
1145
+ } else {
1146
+ // Get the position this entity will be in
1147
+ const position = $ ( ".data-package-item.data" ) . index ( row ) ;
1148
+
1149
+ this . model . addEntity ( entityModel , position ) ;
1160
1150
}
1151
+ } else {
1152
+ entityView = new EMLEntityView ( {
1153
+ model : entityModel ,
1154
+ DataONEObject : dataONEObject ,
1155
+ edit : true ,
1156
+ parentView : this ,
1157
+ } ) ;
1158
+ }
1161
1159
1162
- // Attach the view to the edit button so we can access it again
1163
- row . data ( "entityView" , entityView ) ;
1160
+ // Attach the view to the edit button so we can access it again
1161
+ row . data ( "entityView" , entityView ) ;
1164
1162
1165
- // Render the view
1166
- entityView . render ( ) ;
1167
- }
1163
+ // Render the view
1164
+ entityView . render ( ) ;
1165
+ }
1168
1166
1169
- // Show the modal window editor for this entity
1170
- if ( entityView ) entityView . show ( ) ;
1167
+ // Show the modal window editor for this entity
1168
+ if ( entityView ) entityView . show ( ) ;
1169
+ } ,
1170
+
1171
+ /**
1172
+ * Show the entity editor for a model
1173
+ * @param {EMLEntity|EMLOtherEntity } model - The model to show
1174
+ * @param {boolean } [switchToAttrTab] - Set to true to automatically
1175
+ * switch to the attributes tab instead of default overview tab
1176
+ * @since 0.0.0
1177
+ */
1178
+ showEntityFromModel ( model , switchToAttrTab = false ) {
1179
+ const pid = model . get ( "dataONEObject" ) . get ( "id" ) ;
1180
+ const rows = this . $ ( ".data-package-item" ) ;
1181
+ const row = rows . filter ( ( i , el ) => {
1182
+ const rowModel = $ ( el ) . data ( "model" ) ;
1183
+ const rowId = $ ( el ) . data ( "id" ) ;
1184
+ return rowId === pid || rowModel === model ;
1185
+ } ) ;
1186
+ if ( row . length ) {
1187
+ // Get button to mock a click event which calls showEntity(e)
1188
+ const button = row . find ( "button.edit" ) ;
1189
+ if ( button ?. length ) {
1190
+ button . click ( ) ;
1191
+ if ( switchToAttrTab ) {
1192
+ setTimeout ( ( ) => {
1193
+ row . data ( "entityView" ) ?. showAttributesTab ( ) ;
1194
+ } , 100 ) ;
1195
+ }
1196
+ }
1171
1197
}
1172
1198
} ,
1173
1199
0 commit comments