mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-02 08:09:19 +08:00
provide cancel action button from the subpanel create record view
This commit is contained in:
parent
8ac20ca1df
commit
5e4786f60a
6 changed files with 156 additions and 56 deletions
|
@ -28,6 +28,9 @@ import {Injectable} from '@angular/core';
|
|||
import {Router} from '@angular/router';
|
||||
import {ModuleAction, NavbarModule, Navigation} from '../../../store/navigation/navigation.store';
|
||||
import {LanguageListStringMap, LanguageStrings} from '../../../store/language/language.store';
|
||||
import {Record} from 'common';
|
||||
import {ModuleNameMapper} from '../module-name-mapper/module-name-mapper.service';
|
||||
import {ActionNameMapper} from '../action-name-mapper/action-name-mapper.service';
|
||||
|
||||
export interface NavigationRoute {
|
||||
route: string;
|
||||
|
@ -40,7 +43,11 @@ const ROUTE_PREFIX = './#';
|
|||
@Injectable({providedIn: 'root'})
|
||||
export class ModuleNavigation {
|
||||
|
||||
constructor(protected router: Router) {
|
||||
constructor(
|
||||
protected router: Router,
|
||||
protected moduleNameMapper: ModuleNameMapper,
|
||||
protected actionNameMapper: ActionNameMapper
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,4 +188,84 @@ export class ModuleNavigation {
|
|||
|
||||
return `/${module}/record/${id}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate back using return params
|
||||
* @param record
|
||||
* @param moduleName
|
||||
* @param params
|
||||
*/
|
||||
public navigateBack(
|
||||
record: Record,
|
||||
moduleName: string,
|
||||
params: { [key: string]: string }
|
||||
) {
|
||||
|
||||
let returnModule = this.getReturnModule(params);
|
||||
let returnAction = this.getReturnAction(params);
|
||||
const returnId = this.getReturnId(params);
|
||||
|
||||
let route = '';
|
||||
if (returnModule) {
|
||||
route += '/' + returnModule;
|
||||
}
|
||||
|
||||
if (returnAction) {
|
||||
route += '/' + returnAction;
|
||||
}
|
||||
|
||||
if (returnId) {
|
||||
route += '/' + returnId;
|
||||
}
|
||||
|
||||
if (returnModule === moduleName && returnAction === 'record') {
|
||||
const rid = !returnId ? record.id : returnId;
|
||||
route = '/' + moduleName + '/record/' + rid;
|
||||
}
|
||||
|
||||
if (!route && record && record.id) {
|
||||
route = '/' + moduleName + '/record/' + record.id;
|
||||
}
|
||||
|
||||
if (!route && record && record.id) {
|
||||
route = '/' + moduleName;
|
||||
}
|
||||
|
||||
this.router.navigate([route]).then();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract return id
|
||||
* @param params
|
||||
*/
|
||||
public getReturnId(params: { [p: string]: string }) {
|
||||
return params.return_id || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract and map return action
|
||||
* @param params
|
||||
*/
|
||||
public getReturnAction(params: { [p: string]: string }) {
|
||||
let returnAction = '';
|
||||
|
||||
if (params.return_action) {
|
||||
returnAction = this.actionNameMapper.toFrontend(params.return_action);
|
||||
}
|
||||
return returnAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract and map return action
|
||||
* @param params
|
||||
*/
|
||||
public getReturnModule(params: { [p: string]: string }) {
|
||||
let returnModule = '';
|
||||
|
||||
if (params.return_module) {
|
||||
returnModule = this.moduleNameMapper.toFrontend(params.return_module);
|
||||
}
|
||||
|
||||
return returnModule;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import {ModalButtonInterface, ViewMode} from 'common';
|
|||
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
|
||||
import {RecordActionData, RecordActionHandler} from '../record.action';
|
||||
import {MessageModalComponent} from '../../../../components/modal/components/message-modal/message-modal.component';
|
||||
import {ModuleNavigation} from '../../../../services/navigation/module-navigation/module-navigation.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -38,7 +39,7 @@ export class RecordCancelAction extends RecordActionHandler {
|
|||
key = 'cancel';
|
||||
modes = ['edit' as ViewMode, 'detail' as ViewMode];
|
||||
|
||||
constructor(private modalService: NgbModal) {
|
||||
constructor(private modalService: NgbModal, protected navigation: ModuleNavigation) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
@ -57,6 +58,14 @@ export class RecordCancelAction extends RecordActionHandler {
|
|||
}
|
||||
|
||||
protected cancel(data: RecordActionData): void {
|
||||
|
||||
const params = data.store.params;
|
||||
const moduleName = data.store.getModuleName();
|
||||
const id = data.store.getRecordId();
|
||||
const record = data.store.getBaseRecord();
|
||||
|
||||
this.navigateBack(this.navigation, params, id, moduleName, record);
|
||||
|
||||
data.store.recordStore.resetStaging();
|
||||
data.store.setMode('detail' as ViewMode);
|
||||
}
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
* the words "Supercharged by SuiteCRM".
|
||||
*/
|
||||
|
||||
import {Action, ActionData, ActionHandler} from 'common';
|
||||
import {Action, ActionData, ActionHandler, Record} from 'common';
|
||||
import {RecordViewStore} from '../store/record-view/record-view.store';
|
||||
import {ModuleNavigation} from '../../../services/navigation/module-navigation/module-navigation.service';
|
||||
|
||||
export interface RecordActionData extends ActionData {
|
||||
store: RecordViewStore;
|
||||
|
@ -51,4 +52,42 @@ export abstract class RecordActionHandler extends ActionHandler<RecordActionData
|
|||
|
||||
return this.checkAccess(action, acls, defaultAcls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate back
|
||||
* @param navigation
|
||||
* @param params
|
||||
* @param id
|
||||
* @param moduleName
|
||||
* @param record
|
||||
*/
|
||||
protected navigateBack(
|
||||
navigation: ModuleNavigation,
|
||||
params: { [p: string]: string },
|
||||
id: string,
|
||||
moduleName: string,
|
||||
record: Record
|
||||
) {
|
||||
let returnModule = navigation.getReturnModule(params);
|
||||
let returnAction = navigation.getReturnAction(params);
|
||||
let returnId = navigation.getReturnId(params);
|
||||
|
||||
if (id === returnId) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (returnModule === moduleName &&
|
||||
returnAction === 'record' &&
|
||||
returnId !== id
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!returnModule || !returnAction) {
|
||||
return;
|
||||
}
|
||||
|
||||
navigation.navigateBack(record, moduleName, params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,11 +27,9 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {ViewMode} from 'common';
|
||||
import {take} from 'rxjs/operators';
|
||||
import {ModuleNameMapper} from '../../../../services/navigation/module-name-mapper/module-name-mapper.service';
|
||||
import {RecordActionData, RecordActionHandler} from '../record.action';
|
||||
import {ActionNameMapper} from '../../../../services/navigation/action-name-mapper/action-name-mapper.service';
|
||||
import {Router} from '@angular/router';
|
||||
import {MessageService} from '../../../../services/message/message.service';
|
||||
import {ModuleNavigation} from '../../../../services/navigation/module-navigation/module-navigation.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -43,9 +41,7 @@ export class RecordSaveNewAction extends RecordActionHandler {
|
|||
|
||||
constructor(
|
||||
protected message: MessageService,
|
||||
protected router: Router,
|
||||
protected moduleNameMapper: ModuleNameMapper,
|
||||
protected actionNameMapper: ActionNameMapper
|
||||
protected navigation: ModuleNavigation
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
@ -56,48 +52,9 @@ export class RecordSaveNewAction extends RecordActionHandler {
|
|||
data.store.save().pipe(take(1)).subscribe(
|
||||
record => {
|
||||
const store = data.store;
|
||||
|
||||
let returnModule = '';
|
||||
|
||||
if (store.params.return_module) {
|
||||
returnModule = this.moduleNameMapper.toFrontend(store.params.return_module);
|
||||
}
|
||||
|
||||
let returnAction = '';
|
||||
|
||||
if (store.params.return_action) {
|
||||
returnAction = this.actionNameMapper.toFrontend(store.params.return_action);
|
||||
}
|
||||
|
||||
const returnId = store.params.return_id || '';
|
||||
|
||||
let route = '';
|
||||
if (returnModule) {
|
||||
route += '/' + returnModule;
|
||||
}
|
||||
|
||||
if (returnAction) {
|
||||
route += '/' + returnAction;
|
||||
}
|
||||
|
||||
if (returnId) {
|
||||
route += '/' + returnId;
|
||||
}
|
||||
|
||||
if (returnModule === store.getModuleName() && returnAction === 'record') {
|
||||
const rid = !returnId ? record.id : returnId;
|
||||
route = '/' + store.getModuleName() + '/record/' + rid;
|
||||
}
|
||||
|
||||
if (!route && record && record.id) {
|
||||
route = '/' + store.getModuleName() + '/record/' + record.id;
|
||||
}
|
||||
|
||||
if (!route && record && record.id) {
|
||||
route = '/' + store.getModuleName();
|
||||
}
|
||||
|
||||
this.router.navigate([route]).then();
|
||||
const params = store.params;
|
||||
const moduleName = store.getModuleName();
|
||||
this.navigation.navigateBack(record, moduleName, params);
|
||||
}
|
||||
);
|
||||
return;
|
||||
|
|
|
@ -25,10 +25,11 @@
|
|||
*/
|
||||
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ViewMode} from 'common';
|
||||
import {Record, ViewMode} from 'common';
|
||||
import {take} from 'rxjs/operators';
|
||||
import {RecordActionData, RecordActionHandler} from '../record.action';
|
||||
import {MessageService} from '../../../../services/message/message.service';
|
||||
import {ModuleNavigation} from '../../../../services/navigation/module-navigation/module-navigation.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -38,14 +39,19 @@ export class RecordSaveAction extends RecordActionHandler {
|
|||
key = 'save';
|
||||
modes = ['edit' as ViewMode];
|
||||
|
||||
constructor(protected message: MessageService) {
|
||||
constructor(protected message: MessageService, protected navigation: ModuleNavigation) {
|
||||
super();
|
||||
}
|
||||
|
||||
run(data: RecordActionData): void {
|
||||
data.store.recordStore.validate().pipe(take(1)).subscribe(valid => {
|
||||
if (valid) {
|
||||
data.store.save().pipe(take(1)).subscribe();
|
||||
data.store.save().pipe(take(1)).subscribe(record => {
|
||||
const params = data.store.params;
|
||||
const moduleName = data.store.getModuleName();
|
||||
const id = record.id;
|
||||
this.navigateBack(this.navigation, params, id, moduleName, record);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import {Component, OnDestroy, OnInit} from '@angular/core';
|
|||
import {AppStateStore} from '../../../../store/app-state/app-state.store';
|
||||
import {Observable, Subscription} from 'rxjs';
|
||||
import {RecordViewStore} from '../../store/record-view/record-view.store';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {ActivatedRoute, Params} from '@angular/router';
|
||||
import {RecordViewModel} from '../../store/record-view/record-view.store.model';
|
||||
import {ViewMode} from 'common';
|
||||
|
||||
|
@ -54,7 +54,9 @@ export class RecordComponent implements OnInit, OnDestroy {
|
|||
mode = data.mode;
|
||||
}
|
||||
|
||||
this.recordSub = this.recordStore.init(this.appState.getModule(), this.route.snapshot.params.record, mode).subscribe();
|
||||
const params = (this.route.snapshot && this.route.snapshot.queryParams) || {} as Params;
|
||||
|
||||
this.recordSub = this.recordStore.init(this.appState.getModule(), this.route.snapshot.params.record, mode, params).subscribe();
|
||||
this.vm$ = this.recordStore.vm$;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue