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;
}
this.options = this.field.param1.split('\n').map((option) => {
this.options = this.field.param1.split(/\r?\n/).map((option) => {
return { key: option, value: option };
});
@ -67,7 +67,7 @@ export class AddonModDataFieldCheckboxComponent extends AddonModDataFieldPluginC
* @param {any} value New value to be set.
*/
protected updateValue(value: any): void {
this.value = value;
this.value = value || {};
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 {
const fieldName = 'f_' + field.id;
if (inputData[fieldName] && inputData[fieldName].length > 0) {
return [{
fieldid: field.id,
value: inputData[fieldName]
}];
}
return false;
return [{
fieldid: field.id,
value: inputData[fieldName] || []
}];
}
/**

View File

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

View File

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

View File

@ -40,7 +40,7 @@ export class AddonModDataFieldMultimenuComponent extends AddonModDataFieldPlugin
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 };
});
@ -67,7 +67,7 @@ export class AddonModDataFieldMultimenuComponent extends AddonModDataFieldPlugin
* @param {any} value New value to be set.
*/
protected updateValue(value: any): void {
this.value = value;
this.value = value || {};
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 {
const fieldName = 'f_' + field.id;
if (inputData[fieldName] && inputData[fieldName].length > 0) {
return [{
fieldid: field.id,
value: inputData[fieldName]
}];
}
return false;
return [{
fieldid: field.id,
value: inputData[fieldName] || []
}];
}
/**

View File

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

View File

@ -124,13 +124,12 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginCo
this.entryId = (value && value.recordid) || null;
this.title = (value && value.content1) || '';
this.imageUrl = null;
if (this.image) {
if (this.image.offline) {
this.imageUrl = (this.image && this.image.toURL()) || null;
} else {
this.imageUrl = (this.image && this.image.fileurl) || null;
setTimeout(() => {
if (this.image) {
this.imageUrl = this.image.offline ? this.image.toURL() : this.image.fileurl;
}
}
}, 1);
this.width = this.domUtils.formatPixelsSize(this.field.param1);
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.
*/
getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
const files = this.getFieldEditFiles(field),
values = [],
fieldName = 'f_' + field.id + '_alttext';
const files = this.getFieldEditFiles(field);
const fieldName = 'f_' + field.id + '_alttext';
if (files.length) {
values.push({
return [
{
fieldid: field.id,
subfield: 'file',
files: files
});
}
if (inputData[fieldName]) {
values.push({
},
{
fieldid: field.id,
subfield: 'alttext',
value: inputData[fieldName]
});
}
return values;
}
];
}
/**

View File

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

View File

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

View File

@ -50,32 +50,32 @@ export class AddonModDataFieldTextareaHandler extends AddonModDataFieldTextHandl
*/
getFieldEditData(field: any, inputData: any, originalFieldData: any): any {
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]) {
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);
return [{
fieldid: field.id,
value: text
},
{
fieldid: field.id,
subfield: 'content1',
value: 1
},
{
fieldid: field.id,
subfield: 'itemid',
files: files
}
];
// WS does not properly check if HTML content is blank when the field is required.
if (this.textUtils.htmlIsBlank(text)) {
text = '';
}
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) => {
if (!input.subfield) {
return !!input.value;
}
return false;
return !input.subfield && this.textUtils.htmlIsBlank(input.value);
});
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>
</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 = {
fields: this.fields,
contents: this.entry.contents,
contents: this.utils.clone(this.entry.contents),
form: this.editForm,
data: this.data,
errors: this.errors