diff --git a/src/addon/mod/forum/components/post/addon-mod-forum-post.html b/src/addon/mod/forum/components/post/addon-mod-forum-post.html index cafe72514..10c1f36fc 100644 --- a/src/addon/mod/forum/components/post/addon-mod-forum-post.html +++ b/src/addon/mod/forum/components/post/addon-mod-forum-post.html @@ -57,10 +57,10 @@ - +
{{ 'addon.mod_forum.subject' | translate }} - + {{ 'addon.mod_forum.message' | translate }} @@ -68,7 +68,7 @@ {{ 'addon.mod_forum.privatereply' | translate }} - + @@ -88,5 +88,5 @@ - + diff --git a/src/addon/mod/forum/components/post/post.ts b/src/addon/mod/forum/components/post/post.ts index 8900dc980..997e8a015 100644 --- a/src/addon/mod/forum/components/post/post.ts +++ b/src/addon/mod/forum/components/post/post.ts @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input, Output, Optional, EventEmitter, OnInit, OnDestroy } from '@angular/core'; +import { + Component, Input, Output, Optional, EventEmitter, OnInit, OnDestroy, ViewChild, ElementRef, OnChanges, SimpleChange +} from '@angular/core'; import { FormControl } from '@angular/forms'; import { Content, PopoverController, ModalController } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; @@ -37,7 +39,7 @@ import { AddonForumPostOptionsMenuComponent } from '../post-options-menu/post-op selector: 'addon-mod-forum-post', templateUrl: 'addon-mod-forum-post.html', }) -export class AddonModForumPostComponent implements OnInit, OnDestroy { +export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges { @Input() post: any; // Post. @Input() courseId: number; // Post's course ID. @Input() discussionId: number; // Post's' discussion ID. @@ -50,8 +52,11 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { @Input() accessInfo: any; // Forum access information. @Input() parentSubject?: string; // Subject of parent post. @Input() ratingInfo?: CoreRatingInfo; // Rating info item. + @Input() leavingPage?: boolean; // Whether the page that contains this post is being left and will be destroyed. @Output() onPostChange: EventEmitter; // Event emitted when a reply is posted or modified. + @ViewChild('replyFormEl') formElement: ElementRef; + messageControl = new FormControl(); uniqueId: string; @@ -100,6 +105,16 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { (this.forumProvider.isDeletePostAvailable() || this.forumProvider.isUpdatePostAvailable())); } + /** + * Detect changes on input properties. + */ + ngOnChanges(changes: {[name: string]: SimpleChange}): void { + if (changes.leavingPage && this.leavingPage && this.formElement) { + // Download all courses is enabled now, initialize it. + this.domUtils.triggerFormCancelledEvent(this.formElement.nativeElement, this.sitesProvider.getCurrentSiteId()); + } + } + /** * Deletes an online post. */ @@ -408,6 +423,8 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { this.onPostChange.emit(); + this.domUtils.triggerFormSubmittedEvent(this.formElement.nativeElement, sent, this.sitesProvider.getCurrentSiteId()); + if (this.syncId) { this.syncProvider.unblockOperation(AddonModForumProvider.COMPONENT, this.syncId); } @@ -426,6 +443,8 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy { // Reset data. this.setReplyFormData(); + this.domUtils.triggerFormCancelledEvent(this.formElement.nativeElement, this.sitesProvider.getCurrentSiteId()); + if (this.syncId) { this.syncProvider.unblockOperation(AddonModForumProvider.COMPONENT, this.syncId); } diff --git a/src/addon/mod/forum/pages/discussion/discussion.html b/src/addon/mod/forum/pages/discussion/discussion.html index 577fe6c57..2cb0c0e84 100644 --- a/src/addon/mod/forum/pages/discussion/discussion.html +++ b/src/addon/mod/forum/pages/discussion/discussion.html @@ -42,13 +42,13 @@
- +
- + @@ -60,7 +60,7 @@ - +
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 @@ - +
{{ 'addon.mod_forum.subject' | translate }} - + {{ 'addon.mod_forum.message' | translate }} @@ -36,5 +36,5 @@ - +
\ 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 @@ - +
{{ 'addon.mod_forum.subject' | translate }} - + {{ 'addon.mod_forum.message' | translate }} @@ -29,21 +29,21 @@ {{ 'addon.mod_forum.posttomygroups' | translate }} - + {{ 'addon.mod_forum.group' | translate }} - + {{ group.name }} {{ 'addon.mod_forum.discussionsubscription' | translate }} - + {{ 'addon.mod_forum.discussionpinned' | translate }} - + @@ -57,6 +57,6 @@ - +
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 @@ - +
{{ 'addon.mod_glossary.concept' | translate }} - + {{ 'addon.mod_glossary.definition' | translate }} @@ -19,13 +19,13 @@ {{ 'addon.mod_glossary.categories' | translate }} - + {{ category.name }} {{ 'addon.mod_glossary.aliases' | translate }} - + {{ 'addon.mod_glossary.attachment' | translate }} @@ -33,17 +33,17 @@ {{ 'addon.mod_glossary.linking' | translate }} {{ 'addon.mod_glossary.entryusedynalink' | translate }} - + {{ 'addon.mod_glossary.casesensitive' | translate }} - + {{ 'addon.mod_glossary.fullmatch' | translate }} - + - +
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) => {