@@ -52,6 +52,8 @@ export class AddonModDataEditPage {
5252 protected siteId : string ;
5353 protected offline : boolean ;
5454 protected forceLeave = false ; // To allow leaving the page without checking for changes.
55+ protected initialSelectedGroup = null ;
56+ protected isEditing = false ;
5557
5658 title = '' ;
5759 component = AddonModDataProvider . COMPONENT ;
@@ -75,7 +77,10 @@ export class AddonModDataEditPage {
7577 this . module = params . get ( 'module' ) || { } ;
7678 this . entryId = params . get ( 'entryId' ) || null ;
7779 this . courseId = params . get ( 'courseId' ) ;
78- this . selectedGroup = params . get ( 'group' ) || 0 ;
80+ this . selectedGroup = this . entryId ? null : ( params . get ( 'group' ) || 0 ) ;
81+
82+ // If entryId is lower than 0 or null, it is a new entry or an offline entry.
83+ this . isEditing = this . entryId && this . entryId > 0 ;
7984
8085 this . siteId = sitesProvider . getCurrentSiteId ( ) ;
8186
@@ -103,7 +108,8 @@ export class AddonModDataEditPage {
103108
104109 const inputData = this . editForm . value ;
105110
106- const changed = await this . dataHelper . hasEditDataChanged ( inputData , this . fieldsArray , this . data . id , this . entry . contents ) ;
111+ let changed = await this . dataHelper . hasEditDataChanged ( inputData , this . fieldsArray , this . data . id , this . entry . contents ) ;
112+ changed = changed || ( ! this . isEditing && this . initialSelectedGroup != this . selectedGroup ) ;
107113
108114 if ( changed ) {
109115 // Show confirmation if some data has been modified.
@@ -169,6 +175,7 @@ export class AddonModDataEditPage {
169175 return this . dataHelper . hasEditDataChanged ( inputData , this . fieldsArray , this . data . id ,
170176 this . entry . contents ) . then ( ( changed ) => {
171177
178+ changed = changed || ( ! this . isEditing && this . initialSelectedGroup != this . selectedGroup ) ;
172179 if ( ! changed ) {
173180 if ( this . entryId ) {
174181 return this . returnToEntryList ( ) ;
@@ -196,7 +203,7 @@ export class AddonModDataEditPage {
196203 return Promise . reject ( e ) ;
197204 } ) . then ( ( editData ) => {
198205 if ( editData . length > 0 ) {
199- if ( this . entryId ) {
206+ if ( this . isEditing ) {
200207 return this . dataProvider . editEntry ( this . data . id , this . entryId , this . courseId , editData , this . fields ,
201208 undefined , this . offline ) ;
202209 }
@@ -213,20 +220,20 @@ export class AddonModDataEditPage {
213220 }
214221
215222 // This is done if entry is updated when editing or creating if not.
216- if ( ( this . entryId && result . updated ) || ( ! this . entryId && result . newentryid ) ) {
223+ if ( ( this . isEditing && result . updated ) || ( ! this . isEditing && result . newentryid ) ) {
217224
218225 this . domUtils . triggerFormSubmittedEvent ( this . formElement , result . sent , this . siteId ) ;
219226
220- if ( result . sent ) {
221- this . eventsProvider . trigger ( CoreEventsProvider . ACTIVITY_DATA_SENT , { module : 'data' } ) ;
222- }
223-
224227 const promises = [ ] ;
225228
226- this . entryId = this . entryId || result . newentryid ;
229+ if ( result . sent ) {
230+ this . eventsProvider . trigger ( CoreEventsProvider . ACTIVITY_DATA_SENT , { module : 'data' } ) ;
227231
228- promises . push ( this . dataProvider . invalidateEntryData ( this . data . id , this . entryId , this . siteId ) ) ;
229- promises . push ( this . dataProvider . invalidateEntriesData ( this . data . id , this . siteId ) ) ;
232+ if ( this . isEditing ) {
233+ promises . push ( this . dataProvider . invalidateEntryData ( this . data . id , this . entryId , this . siteId ) ) ;
234+ }
235+ promises . push ( this . dataProvider . invalidateEntriesData ( this . data . id , this . siteId ) ) ;
236+ }
230237
231238 return Promise . all ( promises ) . then ( ( ) => {
232239 this . eventsProvider . trigger ( AddonModDataProvider . ENTRY_CHANGED ,
@@ -264,7 +271,7 @@ export class AddonModDataEditPage {
264271 * @param groupId Group identifier to set.
265272 * @return Resolved when done.
266273 */
267- setGroup ( groupId : number ) : Promise < any > {
274+ setGroup ( groupId : number ) : Promise < void > {
268275 this . selectedGroup = groupId ;
269276 this . loaded = false ;
270277
@@ -322,7 +329,7 @@ export class AddonModDataEditPage {
322329 *
323330 * @return Resolved when done.
324331 */
325- protected returnToEntryList ( ) : Promise < any > {
332+ protected returnToEntryList ( ) : Promise < void > {
326333 const inputData = this . editForm . value ;
327334
328335 return this . dataHelper . getEditTmpFiles ( inputData , this . fieldsArray , this . data . id ,
0 commit comments