-
+
diff --git a/src/addon/mod/forum/pages/discussion/discussion.ts b/src/addon/mod/forum/pages/discussion/discussion.ts
index 48fa5d18a..adf2ebbe2 100644
--- a/src/addon/mod/forum/pages/discussion/discussion.ts
+++ b/src/addon/mod/forum/pages/discussion/discussion.ts
@@ -81,6 +81,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
cmId: number;
canPin = false;
availabilityMessage: string;
+ leavingPage = false;
protected forumId: number;
protected postId: number;
@@ -251,20 +252,17 @@ export class AddonModForumDiscussionPage implements OnDestroy {
*
* @return Resolved if we can leave it, rejected if not.
*/
- ionViewCanLeave(): boolean | Promise {
- let promise: any;
+ async ionViewCanLeave(): Promise {
if (this.forumHelper.hasPostDataChanged(this.replyData, this.originalData)) {
// Show confirmation if some data has been modified.
- promise = this.domUtils.showConfirm(this.translate.instant('core.confirmcanceledit'));
- } else {
- promise = Promise.resolve();
+ await this.domUtils.showConfirm(this.translate.instant('core.confirmcanceledit'));
}
- return promise.then(() => {
- // Delete the local files from the tmp folder.
- this.uploaderProvider.clearTmpFiles(this.replyData.files);
- });
+ // Delete the local files from the tmp folder.
+ this.uploaderProvider.clearTmpFiles(this.replyData.files);
+
+ this.leavingPage = true;
}
/**
diff --git a/src/addon/mod/forum/pages/edit-post/addon-mod-forum-edit-post.html b/src/addon/mod/forum/pages/edit-post/addon-mod-forum-edit-post.html
index 3fd8d6e4a..4ffd4c50e 100644
--- a/src/addon/mod/forum/pages/edit-post/addon-mod-forum-edit-post.html
+++ b/src/addon/mod/forum/pages/edit-post/addon-mod-forum-edit-post.html
@@ -9,10 +9,10 @@
-
+
+
\ No newline at end of file
diff --git a/src/addon/mod/forum/pages/edit-post/edit-post.ts b/src/addon/mod/forum/pages/edit-post/edit-post.ts
index 6795c92dc..5b5a0cd17 100644
--- a/src/addon/mod/forum/pages/edit-post/edit-post.ts
+++ b/src/addon/mod/forum/pages/edit-post/edit-post.ts
@@ -12,11 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import { Component } from '@angular/core';
+import { Component, ViewChild, ElementRef } from '@angular/core';
import { FormControl } from '@angular/forms';
import { IonicPage, ViewController, NavParams } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { CoreFileUploaderProvider } from '@core/fileuploader/providers/fileuploader';
+import { CoreSitesProvider } from '@providers/sites';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { AddonModForumProvider } from '../../providers/forum';
import { AddonModForumHelperProvider } from '../../providers/helper';
@@ -30,6 +31,8 @@ import { AddonModForumHelperProvider } from '../../providers/helper';
templateUrl: 'addon-mod-forum-edit-post.html',
})
export class AddonModForumEditPostPage {
+ @ViewChild('editFormEl') formElement: ElementRef;
+
component: string; // Component this post belong to.
componentId: number; // Component ID.
forum: any; // The forum the post belongs to. Required for attachments and offline posts.
@@ -48,7 +51,8 @@ export class AddonModForumEditPostPage {
protected domUtils: CoreDomUtilsProvider,
protected uploaderProvider: CoreFileUploaderProvider,
protected forumHelper: AddonModForumHelperProvider,
- protected translate: TranslateService) {
+ protected translate: TranslateService,
+ protected sitesProvider: CoreSitesProvider) {
const post = params.get('post');
this.component = params.get('component');
@@ -114,7 +118,13 @@ export class AddonModForumEditPostPage {
*
* @param data Data to return to the page.
*/
- closeModal(data: any): void {
+ closeModal(data: any, ): void {
+ if (data) {
+ this.domUtils.triggerFormSubmittedEvent(this.formElement.nativeElement, false, this.sitesProvider.getCurrentSiteId());
+ } else {
+ this.domUtils.triggerFormCancelledEvent(this.formElement.nativeElement, this.sitesProvider.getCurrentSiteId());
+ }
+
this.viewCtrl.dismiss(data);
}
diff --git a/src/addon/mod/forum/pages/new-discussion/new-discussion.html b/src/addon/mod/forum/pages/new-discussion/new-discussion.html
index 6cfeb39f8..dfed2ccbe 100644
--- a/src/addon/mod/forum/pages/new-discussion/new-discussion.html
+++ b/src/addon/mod/forum/pages/new-discussion/new-discussion.html
@@ -12,10 +12,10 @@
-
+
+
diff --git a/src/addon/mod/forum/pages/new-discussion/new-discussion.ts b/src/addon/mod/forum/pages/new-discussion/new-discussion.ts
index 68b44837b..c41f0153f 100644
--- a/src/addon/mod/forum/pages/new-discussion/new-discussion.ts
+++ b/src/addon/mod/forum/pages/new-discussion/new-discussion.ts
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import { Component, OnDestroy, Optional, ViewChild } from '@angular/core';
+import { Component, OnDestroy, Optional, ViewChild, ElementRef } from '@angular/core';
import { FormControl } from '@angular/forms';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
@@ -41,6 +41,7 @@ import { AddonModForumSyncProvider } from '../../providers/sync';
})
export class AddonModForumNewDiscussionPage implements OnDestroy {
+ @ViewChild('newDiscFormEl') formElement: ElementRef;
@ViewChild(CoreEditorRichTextEditorComponent) messageEditor: CoreEditorRichTextEditorComponent;
component = AddonModForumProvider.COMPONENT;
@@ -74,6 +75,7 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
protected syncObserver: any;
protected isDestroyed = false;
protected originalData: any;
+ protected forceLeave = false;
constructor(navParams: NavParams,
private navCtrl: NavController,
@@ -408,6 +410,7 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
this.newDiscussion.postToAllGroups = false;
this.messageEditor.clearText();
this.originalData = this.utils.clone(this.newDiscussion);
+ this.forceLeave = true; // Avoid asking for confirmation.
// Trigger view event, to highlight the current opened discussion in the split view.
this.eventsProvider.trigger(AddonModForumProvider.VIEW_DISCUSSION_EVENT, {
@@ -415,7 +418,7 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
discussion: 0
}, this.sitesProvider.getCurrentSiteId());
} else {
- this.originalData = null; // Avoid asking for confirmation.
+ this.forceLeave = true; // Avoid asking for confirmation.
this.navCtrl.pop();
}
}
@@ -477,6 +480,9 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
this.domUtils.showErrorModalDefault(null, 'addon.mod_forum.errorposttoallgroups', true);
}
+ this.domUtils.triggerFormSubmittedEvent(this.formElement.nativeElement, !!discussionIds,
+ this.sitesProvider.getCurrentSiteId());
+
this.returnToDiscussions(discussionIds, discTimecreated);
}).catch((message) => {
this.domUtils.showErrorModalDefault(message, 'addon.mod_forum.cannotcreatediscussion', true);
@@ -498,6 +504,8 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
}));
return Promise.all(promises).then(() => {
+ this.domUtils.triggerFormCancelledEvent(this.formElement.nativeElement, this.sitesProvider.getCurrentSiteId());
+
this.returnToDiscussions();
});
}).catch(() => {
@@ -517,20 +525,22 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
*
* @return Resolved if we can leave it, rejected if not.
*/
- ionViewCanLeave(): boolean | Promise {
- let promise: any;
+ async ionViewCanLeave(): Promise {
+ if (this.forceLeave) {
+ return;
+ }
if (this.forumHelper.hasPostDataChanged(this.newDiscussion, this.originalData)) {
// Show confirmation if some data has been modified.
- promise = this.domUtils.showConfirm(this.translate.instant('core.confirmcanceledit'));
- } else {
- promise = Promise.resolve();
+ await this.domUtils.showConfirm(this.translate.instant('core.confirmcanceledit'));
}
- return promise.then(() => {
- // Delete the local files from the tmp folder.
- this.uploaderProvider.clearTmpFiles(this.newDiscussion.files);
- });
+ // Delete the local files from the tmp folder.
+ this.uploaderProvider.clearTmpFiles(this.newDiscussion.files);
+
+ if (this.formElement) {
+ this.domUtils.triggerFormCancelledEvent(this.formElement.nativeElement, this.sitesProvider.getCurrentSiteId());
+ }
}
/**
diff --git a/src/addon/mod/forum/providers/forum.ts b/src/addon/mod/forum/providers/forum.ts
index 40bfeb59f..3e5f6f956 100644
--- a/src/addon/mod/forum/providers/forum.ts
+++ b/src/addon/mod/forum/providers/forum.ts
@@ -37,6 +37,7 @@ export class AddonModForumProvider {
static VIEW_DISCUSSION_EVENT = 'addon_mod_forum_view_discussion';
static CHANGE_DISCUSSION_EVENT = 'addon_mod_forum_change_discussion_status';
static MARK_READ_EVENT = 'addon_mod_forum_mark_read';
+ static LEAVING_POSTS_PAGE = 'addon_mod_forum_leaving_posts_page';
static PREFERENCE_SORTORDER = 'forum_discussionlistsortorder';
static SORTORDER_LASTPOST_DESC = 1;
diff --git a/src/addon/mod/glossary/pages/edit/edit.html b/src/addon/mod/glossary/pages/edit/edit.html
index 0bf02b458..98bf66757 100644
--- a/src/addon/mod/glossary/pages/edit/edit.html
+++ b/src/addon/mod/glossary/pages/edit/edit.html
@@ -8,10 +8,10 @@
-
+
-
+
diff --git a/src/addon/mod/glossary/pages/edit/edit.ts b/src/addon/mod/glossary/pages/edit/edit.ts
index 9cf8b4355..c8b252a4c 100644
--- a/src/addon/mod/glossary/pages/edit/edit.ts
+++ b/src/addon/mod/glossary/pages/edit/edit.ts
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import { Component, OnInit } from '@angular/core';
+import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { FormControl } from '@angular/forms';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
@@ -34,6 +34,8 @@ import { AddonModGlossaryHelperProvider } from '../../providers/helper';
templateUrl: 'edit.html',
})
export class AddonModGlossaryEditPage implements OnInit {
+ @ViewChild('editFormEl') formElement: ElementRef;
+
component = AddonModGlossaryProvider.COMPONENT;
loaded = false;
entry = {
@@ -145,20 +147,20 @@ export class AddonModGlossaryEditPage implements OnInit {
*
* @return Resolved if we can leave it, rejected if not.
*/
- ionViewCanLeave(): boolean | Promise {
- let promise: any;
-
- if (!this.saved && this.glossaryHelper.hasEntryDataChanged(this.entry, this.attachments, this.originalData)) {
- // Show confirmation if some data has been modified.
- promise = this.domUtils.showConfirm(this.translate.instant('core.confirmcanceledit'));
- } else {
- promise = Promise.resolve();
+ async ionViewCanLeave(): Promise {
+ if (this.saved) {
+ return;
}
- return promise.then(() => {
- // Delete the local files from the tmp folder.
- this.uploaderProvider.clearTmpFiles(this.attachments);
- });
+ if (this.glossaryHelper.hasEntryDataChanged(this.entry, this.attachments, this.originalData)) {
+ // Show confirmation if some data has been modified.
+ await this.domUtils.showConfirm(this.translate.instant('core.confirmcanceledit'));
+ }
+
+ // Delete the local files from the tmp folder.
+ this.uploaderProvider.clearTmpFiles(this.attachments);
+
+ this.domUtils.triggerFormCancelledEvent(this.formElement.nativeElement, this.sitesProvider.getCurrentSiteId());
}
/**
@@ -251,6 +253,9 @@ export class AddonModGlossaryEditPage implements OnInit {
};
this.eventsProvider.trigger(AddonModGlossaryProvider.ADD_ENTRY_EVENT, data, this.sitesProvider.getCurrentSiteId());
+ this.domUtils.triggerFormSubmittedEvent(this.formElement.nativeElement, !!entryId,
+ this.sitesProvider.getCurrentSiteId());
+
this.saved = true;
this.navCtrl.pop();
}).catch((error) => {