Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions BUTTON_PRESSED_FEATURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Button Pressed Feature

## Overview
The "Button Pressed" mode is a new feature for the EspoCRM Link Button extension that allows buttons to set their field value to "1" and submit the form when pressed. This enables workflow automation based on button clicks.

## How It Works
When a Link Button field is configured with the "Button Pressed" mode:
1. The button appears on the detail view without requiring a URL
2. When clicked, the button sets its field value to "1"
3. The form is automatically saved
4. EspoCRM workflows can detect this field value change and trigger actions

## Use Case Example
**Scenario**: Save as Draft button
1. Create a Link Button field called "saveAsDraft"
2. Set the mode to "Button Pressed"
3. Set the button label to "Save as Draft"
4. Create a workflow that:
- Triggers when the saveAsDraft field equals "1"
- Sets the record status to "Draft"
- Optionally resets the saveAsDraft field back to empty

## Configuration
1. In Entity Manager, add a new Link Button field
2. Set the following parameters:
- **Mode**: Button Pressed
- **Button Label**: Your desired button text (e.g., "Save as Draft")
- **Style**: Choose button appearance (primary, success, etc.)
- **Button Size**: Select size (small, medium, large)
- **Icon Left/Right**: Optional icons for the button

## Workflow Integration
To use with workflows:
1. Create a new workflow for your entity
2. Set trigger type to "After record saved"
3. Add condition: `[Your Button Field Name] equals 1`
4. Add desired actions (e.g., update status field)
5. Optionally add action to reset button field to empty

## Technical Details
- The button field value is set to "1" when pressed
- The record is automatically saved after button click
- After saving, the view automatically returns to detail mode (just like the normal Save button)
- No URL validation is required for this mode
- The button is always visible in detail view (doesn't check for field value)

## Files Modified
- `files/custom/Espo/Modules/LinkButton/Resources/metadata/fields/link-button.json` - Added "buttonPressed" to mode options
- `files/client/custom/modules/link-button/src/views/fields/link-button.js` - Added button press handler and validation logic
- `files/client/custom/modules/link-button/res/templates/fields/detail.tpl` - Added button template for new mode
- `files/custom/Espo/Modules/LinkButton/Resources/i18n/en_US/Admin.json` - Added English translation
- `files/custom/Espo/Modules/LinkButton/Resources/i18n/de_DE/Admin.json` - Added German translation
53 changes: 53 additions & 0 deletions QUICKCREATE_RELATIONSHIP_UPDATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Link Button Extension - Quick Create Relationship Update

## Overview
This update adds the ability to specify a custom relationship name when using the Quick Create mode in the Link Button extension. Previously, the extension assumed the relationship name always followed the pattern `entityType.toLowerCase() + 'Id'`, which was not always correct.

## Bug Fixes
- Fixed button display issues where buttons were showing as text fields
- Ensured proper template loading for all view modes (detail, list, edit)
- Added default values for style and buttonSize to prevent empty button rendering
- Removed URL validation requirement for Quick Create, EspoModal, and Workflow modes
- Now accepts URLs starting with `#` (e.g., `#Notes`, `#Contact/view/123`)

## Changes Made

### 1. Added New Field Parameter
- Added `relationshipName` parameter to the field metadata (`link-button.json`)
- This field is only visible when "quickCreate" mode is selected
- Includes a tooltip explaining its purpose

### 2. Created Conditional View
- Created `relationship-name.js` view that extends varchar field
- Shows/hides the relationship name field based on the selected mode
- Located at: `files/client/custom/modules/link-button/src/views/admin/field-manager/fields/relationship-name.js`

### 3. Updated Quick Create Logic
- Modified `actionQuickCreate()` function in `link-button.js`
- Now checks for the `relationshipName` parameter
- If specified, uses the custom relationship name to link records
- If not specified, falls back to the original behavior (using entity type in lowercase)

### 4. Updated Language Files
- Added label "Relationship Name" in `Admin.json`
- Added tooltip in `FieldManager.json` explaining the field's purpose

## Usage

1. When creating or editing a Link Button field:
- Select "Quick Create" as the mode
- A new field "Relationship Name" will appear
- Enter the exact relationship name (e.g., "account", "contact", "parentAccount")
- If left empty, the system will use the default pattern (entityType.toLowerCase())

2. The relationship will be properly established when creating new records through the Quick Create modal

## Example

If you have a custom relationship where Opportunities are linked to Accounts via a relationship named "primaryAccount" instead of just "account":
- Set Mode: Quick Create
- Set Relationship Name: primaryAccount
- The new record will be linked using `primaryAccountId` and `primaryAccountName`

## Backward Compatibility
This update maintains full backward compatibility. Existing Link Button fields will continue to work as before, using the default entity-based relationship naming pattern.
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,18 @@
<span class="loading-value">...</span>
{{/if}}
{{/if}}
{{/ifEqual}}
{{/ifEqual}}

{{#ifEqual mode 'buttonPressed'}}
<button class="btn btn-{{style}} {{buttonSize}}" title="{{title}}" data-action="button-pressed">
{{#if iconLeft}}
<span class="{{iconLeft}}"></span>
{{/if}}
{{#if buttonLabel}}
<span> {{buttonLabel}} </span>
{{/if}}
{{#if iconRight}}
<span class="{{iconRight}}"></span>
{{/if}}
</button>
{{/ifEqual}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define('link-button:views/admin/field-manager/fields/relationship-name', ['views/fields/varchar'], (Dep) => {
return class extends Dep {

setup() {
super.setup();
this.listenTo(this.model, 'change:mode', this.toggleRelationshipName);
}

afterRender() {
super.afterRender();
this.toggleRelationshipName();
}

toggleRelationshipName() {
if (this.model.get('mode') === 'quickCreate') {
this.getParentView().showField('relationshipName');
} else {
this.getParentView().hideField('relationshipName');
}
}
};
});
Loading