Merge pull request #1571 from albertgasset/MOBILE-2693

Mobile 2693
main
Juan Leyva 2018-10-19 16:21:36 +02:00 committed by GitHub
commit acaf25e53b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 76 additions and 116 deletions

View File

@ -40,7 +40,7 @@ export class AddonModDataFieldCheckboxComponent extends AddonModDataFieldPluginC
return; return;
} }
this.options = this.field.param1.split('\n').map((option) => { this.options = this.field.param1.split(/\r?\n/).map((option) => {
return { key: option, value: option }; return { key: option, value: option };
}); });
@ -67,7 +67,7 @@ export class AddonModDataFieldCheckboxComponent extends AddonModDataFieldPluginC
* @param {any} value New value to be set. * @param {any} value New value to be set.
*/ */
protected updateValue(value: any): void { protected updateValue(value: any): void {
this.value = value; this.value = value || {};
this.value.content = value && value.content && value.content.split('##').join('<br>'); this.value.content = value && value.content && value.content.split('##').join('<br>');
} }
} }

View File

@ -80,14 +80,10 @@ export class AddonModDataFieldCheckboxHandler implements AddonModDataFieldHandle
getFieldEditData(field: any, inputData: any, originalFieldData: any): any { getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
const fieldName = 'f_' + field.id; const fieldName = 'f_' + field.id;
if (inputData[fieldName] && inputData[fieldName].length > 0) { return [{
return [{ fieldid: field.id,
fieldid: field.id, value: inputData[fieldName] || []
value: inputData[fieldName] }];
}];
}
return false;
} }
/** /**

View File

@ -72,15 +72,11 @@ export class AddonModDataFieldFileHandler implements AddonModDataFieldHandler {
getFieldEditData(field: any, inputData: any, originalFieldData: any): any { getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
const files = this.getFieldEditFiles(field); const files = this.getFieldEditFiles(field);
if (files.length) { return [{
return [{ fieldid: field.id,
fieldid: field.id, subfield: 'file',
subfield: 'file', files: files
files: files }];
}];
}
return false;
} }
/** /**

View File

@ -66,26 +66,20 @@ export class AddonModDataFieldLatlongHandler implements AddonModDataFieldHandler
* @return {any} With name and value of the data to be sent. * @return {any} With name and value of the data to be sent.
*/ */
getFieldEditData(field: any, inputData: any, originalFieldData: any): any { getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
const fieldName = 'f_' + field.id, const fieldName = 'f_' + field.id;
values = [];
if (inputData[fieldName + '_0']) { return [
values.push({ {
fieldid: field.id, fieldid: field.id,
subfield: '0', subfield: '0',
value: inputData[fieldName + '_0'] value: inputData[fieldName + '_0'] || ''
}); },
} {
if (inputData[fieldName + '_1']) {
values.push({
fieldid: field.id, fieldid: field.id,
subfield: '1', subfield: '1',
value: inputData[fieldName + '_1'] value: inputData[fieldName + '_1'] || ''
}); }
} ];
return values;
} }
/** /**

View File

@ -40,7 +40,7 @@ export class AddonModDataFieldMultimenuComponent extends AddonModDataFieldPlugin
return; return;
} }
this.options = this.field.param1.split('\n').map((option) => { this.options = this.field.param1.split(/\r?\n/).map((option) => {
return { key: option, value: option }; return { key: option, value: option };
}); });
@ -67,7 +67,7 @@ export class AddonModDataFieldMultimenuComponent extends AddonModDataFieldPlugin
* @param {any} value New value to be set. * @param {any} value New value to be set.
*/ */
protected updateValue(value: any): void { protected updateValue(value: any): void {
this.value = value; this.value = value || {};
this.value.content = value && value.content && value.content.split('##').join('<br>'); this.value.content = value && value.content && value.content.split('##').join('<br>');
} }
} }

View File

@ -80,14 +80,10 @@ export class AddonModDataFieldMultimenuHandler implements AddonModDataFieldHandl
getFieldEditData(field: any, inputData: any, originalFieldData: any): any { getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
const fieldName = 'f_' + field.id; const fieldName = 'f_' + field.id;
if (inputData[fieldName] && inputData[fieldName].length > 0) { return [{
return [{ fieldid: field.id,
fieldid: field.id, value: inputData[fieldName] || []
value: inputData[fieldName] }];
}];
}
return false;
} }
/** /**

View File

@ -49,12 +49,9 @@ export class AddonModDataFieldNumberHandler extends AddonModDataFieldTextHandler
* @return {Promise<boolean> | boolean} If the field has changes. * @return {Promise<boolean> | boolean} If the field has changes.
*/ */
hasFieldDataChanged(field: any, inputData: any, originalFieldData: any): Promise<boolean> | boolean { hasFieldDataChanged(field: any, inputData: any, originalFieldData: any): Promise<boolean> | boolean {
const fieldName = 'f_' + field.id, const fieldName = 'f_' + field.id;
input = typeof inputData[fieldName] != 'undefined' && inputData[fieldName] !== null ? const input = inputData[fieldName] || '';
parseFloat(inputData[fieldName]) : ''; originalFieldData = originalFieldData && originalFieldData.content || '';
originalFieldData = (originalFieldData && typeof originalFieldData.content != 'undefined' && originalFieldData !== null) ?
parseFloat(originalFieldData.content) : '';
return input != originalFieldData; return input != originalFieldData;
} }

View File

@ -124,13 +124,12 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginCo
this.entryId = (value && value.recordid) || null; this.entryId = (value && value.recordid) || null;
this.title = (value && value.content1) || ''; this.title = (value && value.content1) || '';
this.imageUrl = null; this.imageUrl = null;
if (this.image) { setTimeout(() => {
if (this.image.offline) { if (this.image) {
this.imageUrl = (this.image && this.image.toURL()) || null; this.imageUrl = this.image.offline ? this.image.toURL() : this.image.fileurl;
} else {
this.imageUrl = (this.image && this.image.fileurl) || null;
} }
} }, 1);
this.width = this.domUtils.formatPixelsSize(this.field.param1); this.width = this.domUtils.formatPixelsSize(this.field.param1);
this.height = this.domUtils.formatPixelsSize(this.field.param2); this.height = this.domUtils.formatPixelsSize(this.field.param2);
} }

View File

@ -70,27 +70,21 @@ export class AddonModDataFieldPictureHandler implements AddonModDataFieldHandler
* @return {any} With name and value of the data to be sent. * @return {any} With name and value of the data to be sent.
*/ */
getFieldEditData(field: any, inputData: any, originalFieldData: any): any { getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
const files = this.getFieldEditFiles(field), const files = this.getFieldEditFiles(field);
values = [], const fieldName = 'f_' + field.id + '_alttext';
fieldName = 'f_' + field.id + '_alttext';
if (files.length) { return [
values.push({ {
fieldid: field.id, fieldid: field.id,
subfield: 'file', subfield: 'file',
files: files files: files
}); },
} {
if (inputData[fieldName]) {
values.push({
fieldid: field.id, fieldid: field.id,
subfield: 'alttext', subfield: 'alttext',
value: inputData[fieldName] value: inputData[fieldName]
}); }
} ];
return values;
} }
/** /**

View File

@ -67,14 +67,10 @@ export class AddonModDataFieldRadiobuttonHandler implements AddonModDataFieldHan
getFieldEditData(field: any, inputData: any, originalFieldData: any): any { getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
const fieldName = 'f_' + field.id; const fieldName = 'f_' + field.id;
if (inputData[fieldName]) { return [{
return [{ fieldid: field.id,
fieldid: field.id, value: inputData[fieldName] || ''
value: inputData[fieldName] }];
}];
}
return false;
} }
/** /**

View File

@ -68,14 +68,10 @@ export class AddonModDataFieldTextHandler implements AddonModDataFieldHandler {
getFieldEditData(field: any, inputData: any, originalFieldData: any): any { getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
const fieldName = 'f_' + field.id; const fieldName = 'f_' + field.id;
if (inputData[fieldName]) { return [{
return [{ fieldid: field.id,
fieldid: field.id, value: inputData[fieldName] || ''
value: inputData[fieldName] }];
}];
}
return false;
} }
/** /**

View File

@ -50,32 +50,32 @@ export class AddonModDataFieldTextareaHandler extends AddonModDataFieldTextHandl
*/ */
getFieldEditData(field: any, inputData: any, originalFieldData: any): any { getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
const fieldName = 'f_' + field.id; const fieldName = 'f_' + field.id;
const files = this.getFieldEditFiles(field, inputData, originalFieldData);
let text = this.textUtils.restorePluginfileUrls(inputData[fieldName] || '', files);
// Add some HTML to the text if needed.
text = this.textUtils.formatHtmlLines(text);
if (inputData[fieldName]) { // WS does not properly check if HTML content is blank when the field is required.
const files = this.getFieldEditFiles(field, inputData, originalFieldData); if (this.textUtils.htmlIsBlank(text)) {
let text = this.textUtils.restorePluginfileUrls(inputData[fieldName], files); text = '';
// Add some HTML to the text if needed.
text = this.textUtils.formatHtmlLines(text);
return [{
fieldid: field.id,
value: text
},
{
fieldid: field.id,
subfield: 'content1',
value: 1
},
{
fieldid: field.id,
subfield: 'itemid',
files: files
}
];
} }
return false; return [
{
fieldid: field.id,
value: text
},
{
fieldid: field.id,
subfield: 'content1',
value: 1
},
{
fieldid: field.id,
subfield: 'itemid',
files: files
}
];
} }
/** /**
@ -104,11 +104,7 @@ export class AddonModDataFieldTextareaHandler extends AddonModDataFieldTextHandl
} }
const found = inputData.some((input) => { const found = inputData.some((input) => {
if (!input.subfield) { return !input.subfield && this.textUtils.htmlIsBlank(input.value);
return !!input.value;
}
return false;
}); });
if (!found) { if (!found) {

View File

@ -4,4 +4,4 @@
<core-input-errors *ngIf="error && mode == 'edit'" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors> <core-input-errors *ngIf="error && mode == 'edit'" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors>
</span> </span>
<a *ngIf="isShowOrListMode() && value && value.content" [href]="value.content" core-link capture="true">{{field.name}}</a> <a *ngIf="isShowOrListMode() && value && value.content" [href]="value.content" core-link capture="true">{{value.content}}</a>

View File

@ -303,7 +303,7 @@ export class AddonModDataEditPage {
this.jsData = { this.jsData = {
fields: this.fields, fields: this.fields,
contents: this.entry.contents, contents: this.utils.clone(this.entry.contents),
form: this.editForm, form: this.editForm,
data: this.data, data: this.data,
errors: this.errors errors: this.errors