Skip to content

Commit

Permalink
feat: New counter setting Textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Oct 11, 2024
1 parent a66e98e commit 25344d1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
15 changes: 10 additions & 5 deletions packages/server/assets/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ const optionHTML = `
</div>
<select class="{class}" id="{ID}___type">
<option {text_SELECTED} value="text">Text</option>
<option {textarea_SELECTED} value="textarea">Text area</option>
<option {number_SELECTED} value="number">Number</option>
<option {color_SELECTED} value="color">Color</option>
<option {checkbox_SELECTED} value="checkbox">Toggle</option>
Expand Down Expand Up @@ -768,9 +769,11 @@ async function startBuilderModal(element) {
.replace("{ADDON}", `onchange="sanitize(this);"`)
.replace(/{text_SELECTED}/gm, '')
.replace(/{number_SELECTED}/gm, '')
.replace(/{password_SELECTED}/gm, '')
.replace(/{color_SELECTED}/gm, '')
.replace(/{checkbox_SELECTED}/gm, '')
.replace(/{options_SELECTED}/gm, '');
.replace(/{options_SELECTED}/gm, '')
.replace(/{password_SELECTED}/gm, '')
.replace(/{textarea_SELECTED}/gm, '');

if (json.error == null) {
for (let i = 0; i < json.length; i++) {
Expand All @@ -794,9 +797,10 @@ async function startBuilderModal(element) {
.replace(/{text_SELECTED}/gm, option.type == 'text' ? `selected="selected"` : '')
.replace(/{number_SELECTED}/gm, option.type == 'number' ? `selected="selected"` : '')
.replace(/{color_SELECTED}/gm, option.type == 'color' ? `selected="selected"` : '')
.replace(/{password_SELECTED}/gm, option.type == 'password' ? `selected="selected"` : '')
.replace(/{checkbox_SELECTED}/gm, option.type == 'checkbox' ? `selected="selected"` : '')
.replace(/{options_SELECTED}/gm, option.type == 'options' ? `selected="selected"` : '');
.replace(/{options_SELECTED}/gm, option.type == 'options' ? `selected="selected"` : '')
.replace(/{password_SELECTED}/gm, option.type == 'password' ? `selected="selected"` : '')
.replace(/{textarea_SELECTED}/gm, option.type == 'textarea' ? `selected="selected"` : '');

// if (i != json.length - 1)
// html += '\n<hr class="modal-space">\n'
Expand Down Expand Up @@ -865,7 +869,7 @@ async function builderNewOption(element) {
return;
};

if (payload.value == '' && payload.setting.type != 'password') {
if (payload.value == '' && (payload.setting.type != 'password' && payload.setting.type != 'textarea')) {
displayNotification({
element: element,
text: `Specify default value`,
Expand Down Expand Up @@ -923,6 +927,7 @@ async function builderNewOption(element) {
.replace(/{password_SELECTED}/gm, payload.setting.type == 'password' ? `selected="selected"` : '')
.replace(/{checkbox_SELECTED}/gm, payload.setting.type == 'checkbox' ? `selected="selected"` : '')
.replace(/{options_SELECTED}/gm, payload.setting.type == 'options' ? `selected="selected"` : '')
.replace(/{textarea_SELECTED}/gm, payload.setting.type == 'textarea' ? `selected="selected"` : '')

displayNotification({
element: element,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/assets/homepage.min.css

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions packages/server/utils/counters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export function createSetting(setting: ISettings, value: any) {
switch (setting.type) {
case 'text': {
return settingsItemHTML
.replace('{CLASSES}', '')
.replace('{NAME}', title)
.replace('{DESCRIPTION}', description)
.replace(
Expand All @@ -136,6 +137,7 @@ export function createSetting(setting: ISettings, value: any) {

case 'number': {
return settingsItemHTML
.replace('{CLASSES}', '')
.replace('{NAME}', title)
.replace('{DESCRIPTION}', description)
.replace(
Expand All @@ -150,6 +152,7 @@ export function createSetting(setting: ISettings, value: any) {

case 'password': {
return settingsItemHTML
.replace('{CLASSES}', '')
.replace('{NAME}', title)
.replace('{DESCRIPTION}', description)
.replace(
Expand All @@ -164,6 +167,7 @@ export function createSetting(setting: ISettings, value: any) {

case 'checkbox': {
return settingsItemHTML
.replace('{CLASSES}', '')
.replace('{NAME}', title)
.replace('{DESCRIPTION}', description)
.replace(
Expand All @@ -183,6 +187,7 @@ export function createSetting(setting: ISettings, value: any) {

case 'color': {
return settingsItemHTML
.replace('{CLASSES}', '')
.replace('{NAME}', title)
.replace('{DESCRIPTION}', description)
.replace(
Expand All @@ -206,6 +211,7 @@ export function createSetting(setting: ISettings, value: any) {
.join('\n')
: '';
return settingsItemHTML
.replace('{CLASSES}', '')
.replace('{NAME}', title)
.replace('{DESCRIPTION}', description)
.replace(
Expand All @@ -216,6 +222,21 @@ export function createSetting(setting: ISettings, value: any) {
.replace('{OPTIONS}', options)
);
}

case 'textarea': {
return settingsItemHTML
.replace('{CLASSES}', 'txt-area')
.replace('{NAME}', title)
.replace('{DESCRIPTION}', description)
.replace(
'{INPUT}',
textareaHTML
.replace('{TYPE}', 'text')
.replace(/{ID}/gm, setting.uniqueID)
.replace('{ADDON}', `ucs t="${setting.type}"`)
.replace('{VALUE}', value)
);
}
}

return '';
Expand Down
3 changes: 2 additions & 1 deletion packages/server/utils/counters.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export type ISettingsType =
| 'checkbox'
| 'options'
| 'color'
| 'note';
| 'note'
| 'textarea';

export interface ICounter {
_downloaded?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/server/utils/htmls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const resultItemHTML = `
</div>`;

export const settingsItemHTML = `
<div class="si flexer">
<div class="si flexer {CLASSES}">
<div>
<h4>{NAME}</h4>
<p>{DESCRIPTION}</p>
Expand Down

0 comments on commit 25344d1

Please sign in to comment.