MOBILE-3112 siteplugins: Accept more values in useOtherData

main
Dani Palou 2019-08-02 14:35:45 +02:00
parent d6f30dcd88
commit 2a752cc780
3 changed files with 12 additions and 11 deletions

View File

@ -26,7 +26,7 @@ export class CoreSitePluginsCallWSBaseDirective implements OnInit, OnDestroy {
@Input() name: string; // The name of the WS to call. @Input() name: string; // The name of the WS to call.
@Input() params: any; // The params for the WS call. @Input() params: any; // The params for the WS call.
@Input() preSets: any; // The preSets for the WS call. @Input() preSets: any; // The preSets for the WS call.
@Input() useOtherDataForWS: any[]; // Whether to include other data in the params for the WS. @Input() useOtherDataForWS: any; // Whether to include other data in the params for the WS.
// @see CoreSitePluginsProvider.loadOtherDataInArgs. // @see CoreSitePluginsProvider.loadOtherDataInArgs.
@Input() form: string; // ID or name to identify a form. The form will be obtained from document.forms. @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 WS. // If supplied and form is found, the form data will be retrieved and sent to the WS.

View File

@ -48,7 +48,7 @@ export class CoreSitePluginsNewContentDirective implements OnInit {
@Input() args: any; // The params to get the new content. @Input() args: any; // The params to get the new content.
@Input() title: string; // The title to display with the new content. Only if samePage=false. @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() 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() 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. @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. // 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. @Input() jsData: any; // JS variables to pass to the new page so they can be used in the template or JS.

View File

@ -421,15 +421,15 @@ export class CoreSitePluginsProvider {
/** /**
* Load other data into args as determined by useOtherData list. * Load other data into args as determined by useOtherData list.
* If useOtherData is undefined, it won't add any data. * If useOtherData is undefined, it won't add any data.
* If useOtherData is defined but empty (null, false or empty string) it will copy all the data from otherData to args.
* If useOtherData is an array, it will only copy the properties whose names are in the array. * If useOtherData is an array, it will only copy the properties whose names are in the array.
* If useOtherData is any other value, it will copy all the data from otherData to args.
* *
* @param {any} args The current args. * @param {any} args The current args.
* @param {any} otherData All the other data. * @param {any} otherData All the other data.
* @param {any[]} useOtherData Names of the attributes to include. * @param {any} useOtherData Names of the attributes to include.
* @return {any} New args. * @return {any} New args.
*/ */
loadOtherDataInArgs(args: any, otherData: any, useOtherData: any[]): any { loadOtherDataInArgs(args: any, otherData: any, useOtherData: any): any {
if (!args) { if (!args) {
args = {}; args = {};
} else { } else {
@ -441,14 +441,15 @@ export class CoreSitePluginsProvider {
if (typeof useOtherData == 'undefined') { if (typeof useOtherData == 'undefined') {
// No need to add other data, return args as they are. // No need to add other data, return args as they are.
return args; return args;
} else if (!useOtherData) { } else if (Array.isArray(useOtherData)) {
// Use other data is defined but empty. Add all the data to args. // Include only the properties specified in the array.
for (const name in otherData) { for (const i in useOtherData) {
const name = useOtherData[i];
args[name] = otherData[name]; args[name] = otherData[name];
} }
} else { } else {
for (const i in useOtherData) { // Add all the data to args.
const name = useOtherData[i]; for (const name in otherData) {
args[name] = otherData[name]; args[name] = otherData[name];
} }
} }