MOBILE-2548 siteplugins: Allow passing JS variables to new pages
parent
a7919c1d9a
commit
47f20a6774
|
@ -9,4 +9,4 @@
|
|||
</core-context-menu>
|
||||
</core-navbar-buttons>
|
||||
|
||||
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args" [initResult]="initResult" (onContentLoaded)="contentLoaded($event)" (onLoadingContent)="contentLoading($event)"></core-site-plugins-plugin-content>
|
||||
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args" [initResult]="initResult" [data]="jsData" (onContentLoaded)="contentLoaded($event)" (onLoadingContent)="contentLoading($event)"></core-site-plugins-plugin-content>
|
||||
|
|
|
@ -46,6 +46,7 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
|
|||
prefetchStatusIcon: string;
|
||||
prefetchText: string;
|
||||
size: string;
|
||||
jsData: any; // Data to pass to the component.
|
||||
|
||||
protected isDestroyed = false;
|
||||
protected statusObserver;
|
||||
|
@ -70,6 +71,10 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
|
|||
cmid: this.module.id
|
||||
};
|
||||
this.initResult = handler.initResult;
|
||||
this.jsData = {
|
||||
module: this.module,
|
||||
courseId: this.courseId
|
||||
};
|
||||
}
|
||||
|
||||
// Get the data for the context menu.
|
||||
|
|
|
@ -110,14 +110,21 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
|
|||
* @param {any} args New params.
|
||||
* @param {string} [component] New component. If not provided, current component
|
||||
* @param {string} [method] New method. If not provided, current method
|
||||
* @param {any} [jsData] JS variables to pass to the new view so they can be used in the template or JS.
|
||||
* If true is supplied instead of an object, all initial variables from current page will be copied.
|
||||
*/
|
||||
openContent(title: string, args: any, component?: string, method?: string): void {
|
||||
openContent(title: string, args: any, component?: string, method?: string, jsData?: any): void {
|
||||
if (jsData === true) {
|
||||
jsData = this.data;
|
||||
}
|
||||
|
||||
this.navCtrl.push('CoreSitePluginsPluginPage', {
|
||||
title: title,
|
||||
component: component || this.component,
|
||||
method: method || this.method,
|
||||
args: args,
|
||||
initResult: this.initResult
|
||||
initResult: this.initResult,
|
||||
jsData: jsData
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -144,12 +151,16 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
|
|||
* @param {any} args New params.
|
||||
* @param {string} [component] New component. If not provided, current component
|
||||
* @param {string} [method] New method. If not provided, current method
|
||||
* @param {string} [jsData] JS variables to pass to the new view so they can be used in the template or JS.
|
||||
*/
|
||||
updateContent(args: any, component?: string, method?: string): void {
|
||||
updateContent(args: any, component?: string, method?: string, jsData?: any): void {
|
||||
this.component = component || this.component;
|
||||
this.method = method || this.method;
|
||||
this.args = args;
|
||||
this.dataLoaded = false;
|
||||
if (jsData) {
|
||||
Object.assign(this.data, jsData);
|
||||
}
|
||||
|
||||
this.fetchContent();
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@ export class CoreSitePluginsCallWSNewContentDirective extends CoreSitePluginsCal
|
|||
@Input() title: string; // The title to display with the new content. Only if samePage=false.
|
||||
@Input() samePage: boolean | string; // Whether to display the content in same page or open a new one. Defaults to new page.
|
||||
@Input() useOtherData: any[]; // Whether to include other data in the args. @see CoreSitePluginsProvider.loadOtherDataInArgs.
|
||||
@Input() jsData: any; // JS variables to pass to the new page so they can be used in the template or JS.
|
||||
// If true is supplied instead of an object, all initial variables from current page will be copied.
|
||||
|
||||
constructor(element: ElementRef, translate: TranslateService, domUtils: CoreDomUtilsProvider,
|
||||
sitePluginsProvider: CoreSitePluginsProvider, @Optional() parentContent: CoreSitePluginsPluginContentComponent,
|
||||
|
@ -84,15 +86,21 @@ export class CoreSitePluginsCallWSNewContentDirective extends CoreSitePluginsCal
|
|||
if (this.utils.isTrueOrOne(this.samePage)) {
|
||||
// Update the parent content (if it exists).
|
||||
if (this.parentContent) {
|
||||
this.parentContent.updateContent(args, this.component, this.method);
|
||||
this.parentContent.updateContent(args, this.component, this.method, this.jsData);
|
||||
}
|
||||
} else {
|
||||
let jsData = this.jsData;
|
||||
if (jsData === true && this.parentContent) {
|
||||
jsData = this.parentContent.data;
|
||||
}
|
||||
|
||||
this.navCtrl.push('CoreSitePluginsPluginPage', {
|
||||
title: this.title,
|
||||
component: this.component || (this.parentContent && this.parentContent.component),
|
||||
method: this.method || (this.parentContent && this.parentContent.method),
|
||||
args: args,
|
||||
initResult: this.parentContent && this.parentContent.initResult
|
||||
initResult: this.parentContent && this.parentContent.initResult,
|
||||
jsData: jsData
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ export class CoreSitePluginsNewContentDirective implements OnInit {
|
|||
@Input() useOtherData: any[]; // Whether to include other data in the args. @see CoreSitePluginsProvider.loadOtherDataInArgs.
|
||||
@Input() form: string; // ID or name to identify a form. The form will be obtained from document.forms.
|
||||
// If supplied and form is found, the form data will be retrieved and sent to the new content.
|
||||
@Input() jsData: any; // JS variables to pass to the new page so they can be used in the template or JS.
|
||||
// If true is supplied instead of an object, all initial variables from current page will be copied.
|
||||
|
||||
protected element: HTMLElement;
|
||||
|
||||
|
@ -81,15 +83,21 @@ export class CoreSitePluginsNewContentDirective implements OnInit {
|
|||
if (this.utils.isTrueOrOne(this.samePage)) {
|
||||
// Update the parent content (if it exists).
|
||||
if (this.parentContent) {
|
||||
this.parentContent.updateContent(args, this.component, this.method);
|
||||
this.parentContent.updateContent(args, this.component, this.method, this.jsData);
|
||||
}
|
||||
} else {
|
||||
let jsData = this.jsData;
|
||||
if (jsData === true) {
|
||||
jsData = this.parentContent && this.parentContent.data || {};
|
||||
}
|
||||
|
||||
this.navCtrl.push('CoreSitePluginsPluginPage', {
|
||||
title: this.title,
|
||||
component: this.component || (this.parentContent && this.parentContent.component),
|
||||
method: this.method || (this.parentContent && this.parentContent.method),
|
||||
args: args,
|
||||
initResult: this.parentContent && this.parentContent.initResult
|
||||
initResult: this.parentContent && this.parentContent.initResult,
|
||||
jsData: jsData
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -11,5 +11,5 @@
|
|||
<ion-refresher [enabled]="content && content.dataLoaded" (ionRefresh)="refreshData($event)">
|
||||
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
||||
</ion-refresher>
|
||||
<core-site-plugins-plugin-content [component]="component" [method]="method" [args]="args" [initResult]="initResult"></core-site-plugins-plugin-content>
|
||||
<core-site-plugins-plugin-content [component]="component" [method]="method" [args]="args" [initResult]="initResult" [data]="jsData"></core-site-plugins-plugin-content>
|
||||
</ion-content>
|
||||
|
|
|
@ -33,6 +33,7 @@ export class CoreSitePluginsPluginPage {
|
|||
method: string;
|
||||
args: any;
|
||||
initResult: any;
|
||||
jsData: any; // JS variables to pass to the plugin so they can be used in the template or JS.
|
||||
|
||||
constructor(params: NavParams) {
|
||||
this.title = params.get('title');
|
||||
|
@ -40,6 +41,7 @@ export class CoreSitePluginsPluginPage {
|
|||
this.method = params.get('method');
|
||||
this.args = params.get('args');
|
||||
this.initResult = params.get('initResult');
|
||||
this.jsData = params.get('jsData');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue