From 9d6c8312e81d632e9d93e4ac8ddb165d919b27b7 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Wed, 17 Oct 2018 14:23:50 +0200 Subject: [PATCH 1/7] MOBILE-2693 data: Fix options of checkbox/multimenu fields --- src/addon/mod/data/fields/checkbox/component/checkbox.ts | 4 ++-- src/addon/mod/data/fields/multimenu/component/multimenu.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/addon/mod/data/fields/checkbox/component/checkbox.ts b/src/addon/mod/data/fields/checkbox/component/checkbox.ts index 98cbe5cc7..2db02302a 100644 --- a/src/addon/mod/data/fields/checkbox/component/checkbox.ts +++ b/src/addon/mod/data/fields/checkbox/component/checkbox.ts @@ -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('
'); } } diff --git a/src/addon/mod/data/fields/multimenu/component/multimenu.ts b/src/addon/mod/data/fields/multimenu/component/multimenu.ts index c642895f9..b31800229 100644 --- a/src/addon/mod/data/fields/multimenu/component/multimenu.ts +++ b/src/addon/mod/data/fields/multimenu/component/multimenu.ts @@ -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('
'); } } From dc023afa37b93b7f9793b248e3ae20c3e4a184d0 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Wed, 17 Oct 2018 14:29:37 +0200 Subject: [PATCH 2/7] MOBILE-2693 data: Allow changing fields to a blank value --- .../data/fields/checkbox/providers/handler.ts | 12 ++--- .../mod/data/fields/file/providers/handler.ts | 14 +++--- .../data/fields/latlong/providers/handler.ts | 24 ++++------ .../fields/multimenu/providers/handler.ts | 12 ++--- .../data/fields/picture/providers/handler.ts | 22 ++++----- .../fields/radiobutton/providers/handler.ts | 12 ++--- .../mod/data/fields/text/providers/handler.ts | 12 ++--- .../data/fields/textarea/providers/handler.ts | 45 +++++++++---------- 8 files changed, 58 insertions(+), 95 deletions(-) diff --git a/src/addon/mod/data/fields/checkbox/providers/handler.ts b/src/addon/mod/data/fields/checkbox/providers/handler.ts index 48c50d8d7..3c3009394 100644 --- a/src/addon/mod/data/fields/checkbox/providers/handler.ts +++ b/src/addon/mod/data/fields/checkbox/providers/handler.ts @@ -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] || [] + }]; } /** diff --git a/src/addon/mod/data/fields/file/providers/handler.ts b/src/addon/mod/data/fields/file/providers/handler.ts index 38a58e7de..d6e10b4b1 100644 --- a/src/addon/mod/data/fields/file/providers/handler.ts +++ b/src/addon/mod/data/fields/file/providers/handler.ts @@ -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 + }]; } /** diff --git a/src/addon/mod/data/fields/latlong/providers/handler.ts b/src/addon/mod/data/fields/latlong/providers/handler.ts index fb549c7c4..606db2878 100644 --- a/src/addon/mod/data/fields/latlong/providers/handler.ts +++ b/src/addon/mod/data/fields/latlong/providers/handler.ts @@ -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'] || '' + } + ]; } /** diff --git a/src/addon/mod/data/fields/multimenu/providers/handler.ts b/src/addon/mod/data/fields/multimenu/providers/handler.ts index 716da06bf..7c98f1b8c 100644 --- a/src/addon/mod/data/fields/multimenu/providers/handler.ts +++ b/src/addon/mod/data/fields/multimenu/providers/handler.ts @@ -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] || [] + }]; } /** diff --git a/src/addon/mod/data/fields/picture/providers/handler.ts b/src/addon/mod/data/fields/picture/providers/handler.ts index a5eab43b0..89abf7009 100644 --- a/src/addon/mod/data/fields/picture/providers/handler.ts +++ b/src/addon/mod/data/fields/picture/providers/handler.ts @@ -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; + } + ]; } /** diff --git a/src/addon/mod/data/fields/radiobutton/providers/handler.ts b/src/addon/mod/data/fields/radiobutton/providers/handler.ts index 6efbd744b..a58b407bf 100644 --- a/src/addon/mod/data/fields/radiobutton/providers/handler.ts +++ b/src/addon/mod/data/fields/radiobutton/providers/handler.ts @@ -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] || '' + }]; } /** diff --git a/src/addon/mod/data/fields/text/providers/handler.ts b/src/addon/mod/data/fields/text/providers/handler.ts index 19d49b713..1a4fa8c26 100644 --- a/src/addon/mod/data/fields/text/providers/handler.ts +++ b/src/addon/mod/data/fields/text/providers/handler.ts @@ -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] || '' + }]; } /** diff --git a/src/addon/mod/data/fields/textarea/providers/handler.ts b/src/addon/mod/data/fields/textarea/providers/handler.ts index 8ffcdcf4b..6bbc7d9d8 100644 --- a/src/addon/mod/data/fields/textarea/providers/handler.ts +++ b/src/addon/mod/data/fields/textarea/providers/handler.ts @@ -50,32 +50,27 @@ 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 - } - ]; - } - - return false; + return [ + { + fieldid: field.id, + value: text + }, + { + fieldid: field.id, + subfield: 'content1', + value: 1 + }, + { + fieldid: field.id, + subfield: 'itemid', + files: files + } + ]; } /** From 2537e06a241b1e578ab2ce825417fc82a29df54c Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Wed, 17 Oct 2018 14:33:08 +0200 Subject: [PATCH 3/7] MOBILE-2693 data: Fix updating entries with changed files --- src/addon/mod/data/pages/edit/edit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addon/mod/data/pages/edit/edit.ts b/src/addon/mod/data/pages/edit/edit.ts index 270caa0dc..c311a7137 100644 --- a/src/addon/mod/data/pages/edit/edit.ts +++ b/src/addon/mod/data/pages/edit/edit.ts @@ -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 From c54d061e556b14cb0f32cfb5bd458adb5ec1eea9 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Wed, 17 Oct 2018 14:34:22 +0200 Subject: [PATCH 4/7] MOBILE-2693 data: Fix broken image after updating a picture field --- .../mod/data/fields/picture/component/picture.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/addon/mod/data/fields/picture/component/picture.ts b/src/addon/mod/data/fields/picture/component/picture.ts index dddf848d3..0c5836efa 100644 --- a/src/addon/mod/data/fields/picture/component/picture.ts +++ b/src/addon/mod/data/fields/picture/component/picture.ts @@ -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); } From 0d646e738eb47efd4b179fdd7d995e4770844bf4 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Wed, 17 Oct 2018 14:37:05 +0200 Subject: [PATCH 5/7] MOBILE-2693 data: Do not allow saving blank required textarea fields --- .../mod/data/fields/textarea/providers/handler.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/addon/mod/data/fields/textarea/providers/handler.ts b/src/addon/mod/data/fields/textarea/providers/handler.ts index 6bbc7d9d8..1c1a0bc0d 100644 --- a/src/addon/mod/data/fields/textarea/providers/handler.ts +++ b/src/addon/mod/data/fields/textarea/providers/handler.ts @@ -55,6 +55,11 @@ export class AddonModDataFieldTextareaHandler extends AddonModDataFieldTextHandl // Add some HTML to the text if needed. text = this.textUtils.formatHtmlLines(text); + // WS does not properly check if HTML content is blank when the field is required. + if (this.textUtils.htmlIsBlank(text)) { + text = ''; + } + return [ { fieldid: field.id, @@ -99,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) { From 44d782680fcdf76f934e33356961ad9d5bc43d68 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Wed, 17 Oct 2018 14:38:45 +0200 Subject: [PATCH 6/7] MOBILE-2693 data: Display URLs instead of the field name --- .../mod/data/fields/url/component/addon-mod-data-field-url.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addon/mod/data/fields/url/component/addon-mod-data-field-url.html b/src/addon/mod/data/fields/url/component/addon-mod-data-field-url.html index f1c018713..90283fe72 100644 --- a/src/addon/mod/data/fields/url/component/addon-mod-data-field-url.html +++ b/src/addon/mod/data/fields/url/component/addon-mod-data-field-url.html @@ -4,4 +4,4 @@ -{{field.name}} \ No newline at end of file +{{value.content}} \ No newline at end of file From efb2298452c42bdc0af8fcfbd3ff545b069bc8f2 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Wed, 17 Oct 2018 14:39:14 +0200 Subject: [PATCH 7/7] MOBILE-2693 data: Fix change detection of number fields --- src/addon/mod/data/fields/number/providers/handler.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/addon/mod/data/fields/number/providers/handler.ts b/src/addon/mod/data/fields/number/providers/handler.ts index fbf3fe68a..62308e6b5 100644 --- a/src/addon/mod/data/fields/number/providers/handler.ts +++ b/src/addon/mod/data/fields/number/providers/handler.ts @@ -49,12 +49,9 @@ export class AddonModDataFieldNumberHandler extends AddonModDataFieldTextHandler * @return {Promise | boolean} If the field has changes. */ hasFieldDataChanged(field: any, inputData: any, originalFieldData: any): Promise | 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; }