Merge pull request #1720 from albertgasset/MOBILE-2795
MOBILE-2795 data: Use default templates as fallbackmain
commit
fee1dde1dc
|
@ -313,13 +313,14 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
|||
this.firstEntry = entries[0].id;
|
||||
}
|
||||
|
||||
const template = this.data.listtemplate || this.dataHelper.getDefaultTemplate('list', this.fieldsArray);
|
||||
|
||||
entries.forEach((entry) => {
|
||||
this.entries[entry.id] = entry;
|
||||
|
||||
const actions = this.dataHelper.getActions(this.data, this.access, entry);
|
||||
|
||||
entriesHTML += this.dataHelper.displayShowFields(this.data.listtemplate, this.fieldsArray, entry, 'list',
|
||||
actions);
|
||||
entriesHTML += this.dataHelper.displayShowFields(template, this.fieldsArray, entry, 'list', actions);
|
||||
});
|
||||
entriesHTML += this.data.listtemplatefooter || '';
|
||||
|
||||
|
|
|
@ -298,10 +298,6 @@ export class AddonModDataEditPage {
|
|||
* @return {string} Generated HTML.
|
||||
*/
|
||||
protected displayEditFields(): string {
|
||||
if (!this.data.addtemplate) {
|
||||
return '';
|
||||
}
|
||||
|
||||
this.jsData = {
|
||||
fields: this.fields,
|
||||
contents: this.utils.clone(this.entry.contents),
|
||||
|
@ -312,7 +308,7 @@ export class AddonModDataEditPage {
|
|||
|
||||
let replace,
|
||||
render,
|
||||
template = this.data.addtemplate;
|
||||
template = this.data.addtemplate || this.dataHelper.getDefaultTemplate('add', this.fieldsArray);
|
||||
|
||||
// Replace the fields found on template.
|
||||
this.fieldsArray.forEach((field) => {
|
||||
|
|
|
@ -176,8 +176,8 @@ export class AddonModDataEntryPage implements OnDestroy {
|
|||
|
||||
const actions = this.dataHelper.getActions(this.data, this.access, this.entry);
|
||||
|
||||
this.entryRendered = this.dataHelper.displayShowFields(this.data.singletemplate, fieldsArray,
|
||||
this.entry, 'show', actions);
|
||||
const templte = this.data.singletemplate || this.dataHelper.getDefaultTemplate('single', fieldsArray);
|
||||
this.entryRendered = this.dataHelper.displayShowFields(templte, fieldsArray, this.entry, 'show', actions);
|
||||
this.showComments = actions.comments;
|
||||
|
||||
const entries = {};
|
||||
|
|
|
@ -20,6 +20,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
|||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
||||
import { AddonModDataComponentsModule } from '../../components/components.module';
|
||||
import { AddonModDataFieldsDelegate } from '../../providers/fields-delegate';
|
||||
import { AddonModDataHelperProvider } from '../../providers/helper';
|
||||
|
||||
/**
|
||||
* Page that displays the search modal.
|
||||
|
@ -41,7 +42,7 @@ export class AddonModDataSearchPage {
|
|||
|
||||
constructor(params: NavParams, private viewCtrl: ViewController, fb: FormBuilder, protected utils: CoreUtilsProvider,
|
||||
protected domUtils: CoreDomUtilsProvider, protected fieldsDelegate: AddonModDataFieldsDelegate,
|
||||
protected textUtils: CoreTextUtilsProvider) {
|
||||
protected textUtils: CoreTextUtilsProvider, protected dataHelper: AddonModDataHelperProvider) {
|
||||
this.search = params.get('search');
|
||||
this.fields = params.get('fields');
|
||||
this.data = params.get('data');
|
||||
|
@ -82,17 +83,13 @@ export class AddonModDataSearchPage {
|
|||
* @return {string} Generated HTML.
|
||||
*/
|
||||
protected renderAdvancedSearchFields(): string {
|
||||
if (!this.data.asearchtemplate) {
|
||||
return '';
|
||||
}
|
||||
|
||||
this.jsData = {
|
||||
fields: this.fields,
|
||||
form: this.searchForm,
|
||||
search: this.search.advanced
|
||||
};
|
||||
|
||||
let template = this.data.asearchtemplate,
|
||||
let template = this.data.asearchtemplate || this.dataHelper.getDefaultTemplate('asearch', this.fieldsArray),
|
||||
replace, render;
|
||||
|
||||
// Replace the fields found on template.
|
||||
|
|
|
@ -195,6 +195,79 @@ export class AddonModDataHelperProvider {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default template of a certain type.
|
||||
*
|
||||
* Based on Moodle function data_generate_default_template.
|
||||
*
|
||||
* @param {string} type Type of template.
|
||||
* @param {any[]} fields List of database fields.
|
||||
* @return {string} Template HTML.
|
||||
*/
|
||||
getDefaultTemplate( type: 'add' | 'list' | 'single' | 'asearch', fields: any[]): string {
|
||||
const html = [];
|
||||
|
||||
if (type == 'list') {
|
||||
html.push('##delcheck##<br />');
|
||||
}
|
||||
|
||||
html.push(
|
||||
'<div class="defaulttemplate">',
|
||||
'<table class="mod-data-default-template ##approvalstatus##">',
|
||||
'<tbody>'
|
||||
);
|
||||
|
||||
fields.forEach((field) => {
|
||||
html.push(
|
||||
'<tr class="">',
|
||||
'<td class="template-field cell c0" style="">', field.name, ': </td>',
|
||||
'<td class="template-token cell c1 lastcol" style="">[[', field.name, ']]</td>',
|
||||
'</tr>'
|
||||
);
|
||||
});
|
||||
|
||||
if (type == 'list') {
|
||||
html.push(
|
||||
'<tr class="lastrow">',
|
||||
'<td class="controls template-field cell c0 lastcol" style="" colspan="2">',
|
||||
'##edit## ##more## ##delete## ##approve## ##disapprove## ##export##',
|
||||
'</td>',
|
||||
'</tr>'
|
||||
);
|
||||
} else if (type == 'single') {
|
||||
html.push(
|
||||
'<tr class="lastrow">',
|
||||
'<td class="controls template-field cell c0 lastcol" style="" colspan="2">',
|
||||
'##edit## ##delete## ##approve## ##disapprove## ##export##',
|
||||
'</td>',
|
||||
'</tr>'
|
||||
);
|
||||
} else if (type == 'asearch') {
|
||||
html.push(
|
||||
'<tr class="searchcontrols">',
|
||||
'<td class="template-field cell c0" style="">Author first name: </td>',
|
||||
'<td class="template-token cell c1 lastcol" style="">##firstname##</td>',
|
||||
'</tr>',
|
||||
'<tr class="searchcontrols lastrow">',
|
||||
'<td class="template-field cell c0" style="">Author surname: </td>',
|
||||
'<td class="template-token cell c1 lastcol" style="">##lastname##</td>',
|
||||
'</tr>'
|
||||
);
|
||||
}
|
||||
|
||||
html.push(
|
||||
'</tbody>',
|
||||
'</table>',
|
||||
'</div>'
|
||||
);
|
||||
|
||||
if (type == 'list') {
|
||||
html.push('<hr />');
|
||||
}
|
||||
|
||||
return html.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the entered data in the edit form.
|
||||
* We don't use ng-model because it doesn't detect changes done by JavaScript.
|
||||
|
|
Loading…
Reference in New Issue