From 843bd13281c3cea242516eb25d48ed8284acf199 Mon Sep 17 00:00:00 2001 From: LautaroCesso <59095036+LautaroCesso@users.noreply.github.com> Date: Fri, 20 Dec 2019 16:49:43 -0300 Subject: [PATCH] Allows space in custom fields name (issue #598) (#681) * replace spaces for underscores in edit custom fields * Create function getCustomFieldParamName --- .../dashboard-edit-profile-page.js | 31 ++++++++++++------- client/src/data/languages/en.js | 4 +-- client/src/lib-core/APIUtils.js | 4 +++ server/libs/Controller.php | 4 +-- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/client/src/app/main/dashboard/dashboard-edit-profile/dashboard-edit-profile-page.js b/client/src/app/main/dashboard/dashboard-edit-profile/dashboard-edit-profile-page.js index 6bf28bfb..75fbd39b 100644 --- a/client/src/app/main/dashboard/dashboard-edit-profile/dashboard-edit-profile-page.js +++ b/client/src/app/main/dashboard/dashboard-edit-profile/dashboard-edit-profile-page.js @@ -4,6 +4,7 @@ import _ from 'lodash'; import API from 'lib-app/api-call'; import i18n from 'lib-app/i18n'; +import { getCustomFieldParamName } from 'lib-core/APIUtils'; import SessionActions from 'actions/session-actions'; import AreYouSure from 'app-components/are-you-sure'; @@ -42,15 +43,6 @@ class DashboardEditProfilePage extends React.Component { return (
-
{i18n('ADDITIONAL_FIELDS')}
-
this.setState({customFieldsFrom: form})} onSubmit={this.onCustomFieldsSubmit.bind(this)}> -
- {this.state.customFields.map(this.renderCustomField.bind(this))} -
-
- {i18n('SAVE')} -
-
{i18n('EDIT_EMAIL')}
@@ -65,6 +57,23 @@ class DashboardEditProfilePage extends React.Component { {i18n('CHANGE_PASSWORD')} {this.renderMessagePass()} + {this.state.customFields.length ? this.renderCustomFields() : null} +
+ ); + } + + renderCustomFields() { + return ( +
+
{i18n('ADDITIONAL_FIELDS')}
+
this.setState({customFieldsFrom: form})} onSubmit={this.onCustomFieldsSubmit.bind(this)}> +
+ {this.state.customFields.map(this.renderCustomField.bind(this))} +
+
+ {i18n('SAVE')} +
+
); } @@ -116,9 +125,9 @@ class DashboardEditProfilePage extends React.Component { customFields.forEach(customField => { if(customField.type === 'select') { - parsedFrom[`customfield_${customField.name}`] = customField.options[form[customField.name]].name; + parsedFrom[getCustomFieldParamName(customField.name)] = customField.options[form[customField.name]].name; } else { - parsedFrom[`customfield_${customField.name}`] = form[customField.name]; + parsedFrom[getCustomFieldParamName(customField.name)] = form[customField.name]; } }); diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index f331f06d..361dcb00 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -204,7 +204,7 @@ export default { 'IMAGE_HEADER_URL': 'Image header URL', 'IMAGE_HEADER_DESCRIPTION': 'Image that will be used as header of the email', 'EMAIL_SETTINGS': 'Email Settings', - 'ADDITIONAL_FIELDS': 'Additonal Fields', + 'ADDITIONAL_FIELDS': 'Edit additonal fields', 'NEW_CUSTOM_FIELD': 'New Custom field', 'TYPE': 'Type', 'SELECT_INPUT': 'Select input', @@ -326,7 +326,7 @@ export default { 'REGISTRATION_ENABLED': 'Registration has been enabled', 'ADD_API_KEY_DESCRIPTION': 'Insert the name and a registration api key will be generated.', 'SIGN_UP_VIEW_DESCRIPTION': 'Here you can create an account for our support center. It is required to send tickets and see documentation.', - 'EDIT_PROFILE_VIEW_DESCRIPTION': 'Here you can edit your user by changing your email or your password.', + 'EDIT_PROFILE_VIEW_DESCRIPTION': 'Here you can edit your user preferences.', 'ENABLE_USER_SYSTEM_DESCRIPTION': 'Enable/disable the use of an user system. If you disable it, all users will be deleted but the tickets will be kept. If you enable it, the users of existent tickets will be created.', 'CSV_DESCRIPTION': 'The CSV file must have 3 columns: email, password, name. There is no limit in row count. It will be created one user per row in the file.', 'SMTP_SERVER_DESCRIPTION': 'The configuration of the SMTP server allows the application to send mails. If you do not configure it, no emails will be sent by OpenSupports.', diff --git a/client/src/lib-core/APIUtils.js b/client/src/lib-core/APIUtils.js index c9c544f5..d8ca183e 100644 --- a/client/src/lib-core/APIUtils.js +++ b/client/src/lib-core/APIUtils.js @@ -44,4 +44,8 @@ const APIUtils = { } }; +export const getCustomFieldParamName = function (customFieldName) { + return `customfield_${customFieldName}`.replace(/ /g,'_'); +} + export default APIUtils; diff --git a/server/libs/Controller.php b/server/libs/Controller.php index e8c61ff2..04711b5f 100755 --- a/server/libs/Controller.php +++ b/server/libs/Controller.php @@ -152,9 +152,8 @@ abstract class Controller { public static function getCustomFieldValues() { $customFields = Customfield::getAll(); $customFieldValues = new DataStoreList(); - foreach($customFields as $customField) { - $value = Controller::request('customfield_' . $customField->name); + $value = Controller::request('customfield_' . str_replace(' ', '_', $customField->name)); if($value !== null) { $customFieldValue = new Customfieldvalue(); $customFieldValue->setProperties([ @@ -183,7 +182,6 @@ abstract class Controller { $customFieldValues->add($customFieldValue); } } - return $customFieldValues; } }