Merge pull request #4075 from alfonso-salces/MOBILE-4470
Mobile 4470 blog: Fix activity associations and clear rich text in new entriesmain
commit
f6667abd38
|
@ -11,7 +11,7 @@
|
||||||
</ion-header>
|
</ion-header>
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<core-loading [hideUntil]="loaded">
|
<core-loading [hideUntil]="loaded">
|
||||||
<form [formGroup]="form">
|
<form [formGroup]="form" #editEntryForm>
|
||||||
<ion-item>
|
<ion-item>
|
||||||
<ion-input labelPlacement="stacked" formControlName="subject" type="text"
|
<ion-input labelPlacement="stacked" formControlName="subject" type="text"
|
||||||
[placeholder]="'addon.blog.entrytitle' | translate" name="title" [label]="'addon.blog.entrytitle' | translate" />
|
[placeholder]="'addon.blog.entrytitle' | translate" name="title" [label]="'addon.blog.entrytitle' | translate" />
|
||||||
|
|
|
@ -22,7 +22,7 @@ import {
|
||||||
AddonBlogProvider,
|
AddonBlogProvider,
|
||||||
AddonBlogPublishState,
|
AddonBlogPublishState,
|
||||||
} from '@addons/blog/services/blog';
|
} from '@addons/blog/services/blog';
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||||
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { CoreCommentsComponentsModule } from '@features/comments/components/components.module';
|
import { CoreCommentsComponentsModule } from '@features/comments/components/components.module';
|
||||||
|
@ -40,6 +40,7 @@ import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreWSFile } from '@services/ws';
|
import { CoreWSFile } from '@services/ws';
|
||||||
import { Translate } from '@singletons';
|
import { Translate } from '@singletons';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
|
import { CoreForms } from '@singletons/form';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'addon-blog-edit-entry',
|
selector: 'addon-blog-edit-entry',
|
||||||
|
@ -54,6 +55,8 @@ import { CoreEvents } from '@singletons/events';
|
||||||
})
|
})
|
||||||
export class AddonBlogEditEntryPage implements CanLeave, OnInit {
|
export class AddonBlogEditEntryPage implements CanLeave, OnInit {
|
||||||
|
|
||||||
|
@ViewChild('editEntryForm') formElement!: ElementRef;
|
||||||
|
|
||||||
publishState = AddonBlogPublishState;
|
publishState = AddonBlogPublishState;
|
||||||
form = new FormGroup({
|
form = new FormGroup({
|
||||||
subject: new FormControl<string>('', { nonNullable: true, validators: [Validators.required] }),
|
subject: new FormControl<string>('', { nonNullable: true, validators: [Validators.required] }),
|
||||||
|
@ -130,19 +133,30 @@ export class AddonBlogEditEntryPage implements CanLeave, OnInit {
|
||||||
const lastModified = CoreNavigator.getRouteNumberParam('lastModified');
|
const lastModified = CoreNavigator.getRouteNumberParam('lastModified');
|
||||||
const filters: AddonBlogFilter | undefined = CoreNavigator.getRouteParam('filters');
|
const filters: AddonBlogFilter | undefined = CoreNavigator.getRouteParam('filters');
|
||||||
const courseId = CoreNavigator.getRouteNumberParam('courseId');
|
const courseId = CoreNavigator.getRouteNumberParam('courseId');
|
||||||
|
const cmId = CoreNavigator.getRouteNumberParam('cmId');
|
||||||
this.userId = CoreNavigator.getRouteNumberParam('userId');
|
this.userId = CoreNavigator.getRouteNumberParam('userId');
|
||||||
this.siteHomeId = CoreSites.getCurrentSiteHomeId();
|
this.siteHomeId = CoreSites.getCurrentSiteHomeId();
|
||||||
|
|
||||||
if (courseId) {
|
|
||||||
this.courseId = courseId;
|
|
||||||
this.form.controls.associateWithCourse.setValue(true);
|
|
||||||
const { course } = await CoreCourseHelper.getCourse(this.courseId);
|
|
||||||
this.associatedCourse = course;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!entryId) {
|
if (!entryId) {
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (cmId) {
|
||||||
|
this.modId = cmId;
|
||||||
|
this.form.controls.associateWithModule.setValue(true);
|
||||||
|
this.associatedModule = await CoreCourse.getModule(this.modId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (courseId) {
|
||||||
|
this.courseId = courseId;
|
||||||
|
this.form.controls.associateWithCourse.setValue(true);
|
||||||
|
const { course } = await CoreCourseHelper.getCourse(this.courseId);
|
||||||
|
this.associatedCourse = course;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
CoreDomUtils.showErrorModalDefault(error, 'Error getting associations, they may not be displayed correctly.');
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +165,7 @@ export class AddonBlogEditEntryPage implements CanLeave, OnInit {
|
||||||
this.files = this.entry.attachmentfiles ?? [];
|
this.files = this.entry.attachmentfiles ?? [];
|
||||||
this.initialFiles = [...this.files];
|
this.initialFiles = [...this.files];
|
||||||
this.courseId = this.courseId || this.entry.courseid;
|
this.courseId = this.courseId || this.entry.courseid;
|
||||||
this.modId = this.entry.coursemoduleid ? this.entry.coursemoduleid : CoreNavigator.getRouteNumberParam('cmId');
|
this.modId = CoreNavigator.getRouteNumberParam('cmId') || this.entry.coursemoduleid;
|
||||||
|
|
||||||
if (this.courseId) {
|
if (this.courseId) {
|
||||||
this.form.controls.associateWithCourse.setValue(true);
|
this.form.controls.associateWithCourse.setValue(true);
|
||||||
|
@ -316,6 +330,8 @@ export class AddonBlogEditEntryPage implements CanLeave, OnInit {
|
||||||
await CoreDomUtils.showConfirm(Translate.instant('core.confirmcanceledit'));
|
await CoreDomUtils.showConfirm(Translate.instant('core.confirmcanceledit'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoreForms.triggerFormCancelledEvent(this.formElement, CoreSites.getCurrentSiteId());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,6 +376,7 @@ export class AddonBlogEditEntryPage implements CanLeave, OnInit {
|
||||||
|
|
||||||
CoreEvents.trigger(ADDON_BLOG_ENTRY_UPDATED);
|
CoreEvents.trigger(ADDON_BLOG_ENTRY_UPDATED);
|
||||||
this.forceLeave = true;
|
this.forceLeave = true;
|
||||||
|
CoreForms.triggerFormSubmittedEvent(this.formElement, true, CoreSites.getCurrentSiteId());
|
||||||
|
|
||||||
return CoreNavigator.back();
|
return CoreNavigator.back();
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy {
|
||||||
* Redirect to entry creation form.
|
* Redirect to entry creation form.
|
||||||
*/
|
*/
|
||||||
createNewEntry(): void {
|
createNewEntry(): void {
|
||||||
CoreNavigator.navigateToSitePath('blog/edit/0');
|
CoreNavigator.navigateToSitePath('blog/edit/0', { params: { cmId: this.filter.cmid } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue