Skip to content

Commit

Permalink
v2-Beta8 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 committed Feb 5, 2023
1 parent 0bd8a5d commit afa2619
Show file tree
Hide file tree
Showing 37 changed files with 118 additions and 44 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bench build --app frappe_better_attach_control
bench --site [sitename] install-app frappe_better_attach_control
```

5. Check the usage section below
5. Check the [usage](#usage) section below

#### Update
1. Go to app directory
Expand Down Expand Up @@ -131,13 +131,16 @@ bench restart
### Usage
1. Go to Customization > Customize Form
2. Enter the form type/name (Ex: 'User')
3. Scroll down to the form fields area and create an **Attach** or **Attach Image** field or edit an existing custom field
4. In the **options** property of the field, add a JSON object of the customizations you want. Example:
3. Scroll down to the form fields area
4. Create an **Attach** or **Attach Image** field or edit an existing custom field
5. Inside the field's custom property, **Better Attach Options**, add a JSON object of the customizations you want. Example:
```
{"allowed_file_types": ["jpg", "png", "gif"]}
```

ℹ️ **Note: You can't modify the original fields of a doctype, so create a new field or clone and modify the entire doctype.**
ℹ️ **Notes**
1. **You can't modify the original fields of a doctype, so create a new field or clone and modify the entire doctype.**
2. **The plugin creates a custom field property called Better Attach Options to protect the plugin customizations from any modification and to make the plugin work in web forms.**

---

Expand All @@ -150,7 +153,7 @@ bench restart
| `allowed_file_types` | Array of allowed file types (mimes) or extensions to upload.<br/><br/>- Example: `["image/*", "video/*", ".pdf", ".doc"]`<br/>- Default: `null` or `["image/*"]` |
| `max_number_of_files` | Maximum number of files allowed to be uploaded if multiple upload is allowed.<br/><br/>⚠️ *(Bypassing the maximum attachments of doctype might not work)*<br/>- Example: `4`<br/>- Default: `Value of maximum attachments set for the doctype` |
| `crop_image_aspect_ratio` | Crop aspect ratio for images (Frappe >= v14.0.0).<br/><br/>- Example: `1` or `16/9` or `4/3`<br/>- Default: `null` |
| `as_public` | Force uploads to be saved in public folder.<br/><br/>- Default: `false` |
| `as_public` | Force uploads to be saved in public folder by default.<br/><br/>- Default: `false` |
| `allow_reload` | Allow reloading attachments (Frappe >= v13.0.0).<br>ℹ️ Affect the visibility of the reload button.ℹ️<br/><br/>- Default: `true` |
| `allow_remove` | Allow removing and clearing attachments.<br>ℹ️ Affect the visibility of the remove and clear buttons.ℹ️<br/><br/>- Default: `true` |

Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/api/attachment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/api/file_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
2 changes: 1 addition & 1 deletion frappe_better_attach_control/config/desktop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/config/docs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
9 changes: 7 additions & 2 deletions frappe_better_attach_control/hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Frappe Better Attach Control © 2022
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
Expand Down Expand Up @@ -35,4 +35,9 @@
'/assets/frappe_better_attach_control/js/better_attach.js'
] if is_frappe_above_v12 else [
'/assets/frappe_better_attach_control/js/better_attach_v12.js'
])
])


after_install = "frappe_better_attach_control.setup.install.after_install"
after_migrate = "frappe_better_attach_control.setup.install.after_install"
after_uninstall = "frappe_better_attach_control.setup.uninstall.after_uninstall"
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
*/


.ba-link, .ba-link:hover {
text-decoration: none;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
5 changes: 4 additions & 1 deletion frappe_better_attach_control/public/js/controls/attach.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down Expand Up @@ -115,6 +115,7 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro
if (this.upload_options) return;
this._update_options();
if (this._options) this.df.options = this._options;
console.log('Attach Control Options', this.df.options);
super.set_upload_options();
if (this._options) this.df.options = this._latest_options;
}
Expand Down Expand Up @@ -218,6 +219,8 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro
// Private Methods
_setup_control() {
if (this._is_better) return;
if (!isEmpty(this.df.better_attach_options))
this.df.options = this.df.better_attach_options;
this._is_better = 1;
this._options = null;
this._latest_options = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down Expand Up @@ -88,6 +88,7 @@ frappe.ui.form.ControlAttach = frappe.ui.form.ControlAttach.extend({
if (this.upload_options) return;
this._update_options();
if (this._options) this.df.options = this._options;
console.log('Attach Control Options', this.df.options);
this._super();
if (this._options) this.df.options = this._latest_options;
if (this._images_only) {
Expand Down Expand Up @@ -189,6 +190,8 @@ frappe.ui.form.ControlAttach = frappe.ui.form.ControlAttach.extend({
// Private Methods
_setup_control: function() {
if (this._is_better) return;
if (!isEmpty(this.df.better_attach_options))
this.df.options = this.df.better_attach_options;
this._is_better = 1;
this._options = null;
this._latest_options = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down Expand Up @@ -93,6 +93,7 @@ frappe.ui.form.ControlAttach = frappe.ui.form.ControlAttach.extend({
if (this.upload_options) return;
this._update_options();
if (this._options) this.df.options = this._options;
console.log('Attach Control Options', this.df.options);
this._super();
if (this._options) this.df.options = this._latest_options;
if (this._images_only) {
Expand Down Expand Up @@ -208,6 +209,8 @@ frappe.ui.form.ControlAttach = frappe.ui.form.ControlAttach.extend({
// Private Methods
_setup_control: function() {
if (this._is_better) return;
if (!isEmpty(this.df.better_attach_options))
this.df.options = this.df.better_attach_options;
this._is_better = 1;
this._options = null;
this._latest_options = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/public/js/filetypes/audio.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/public/js/filetypes/image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/public/js/filetypes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/public/js/filetypes/pdf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/public/js/filetypes/text.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/public/js/filetypes/types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/public/js/filetypes/video.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/public/js/filetypes/word.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
5 changes: 2 additions & 3 deletions frappe_better_attach_control/public/js/uploader/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down Expand Up @@ -42,8 +42,7 @@ frappe.ui.FileUploader = class FileUploader extends frappe.ui.FileUploader {
}
_override_uploader(opts) {
var up = this.uploader;
if (isPlainObject(opts)) {
up.restrictions = opts.restrictions;
if (isPlainObject(opts) && !isEmpty(opts.restrictions)) {
up.restrictions.as_public = !!opts.restrictions.as_public;
}
up.dropfiles = function(e) {
Expand Down
5 changes: 2 additions & 3 deletions frappe_better_attach_control/public/js/uploader/v12/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down Expand Up @@ -41,8 +41,7 @@ frappe.ui.FileUploader = class FileUploader extends frappe.ui.FileUploader {
}
_override_uploader(opts) {
var up = this.uploader;
if (isPlainObject(opts)) {
up.restrictions = opts.restrictions;
if (isPlainObject(opts) && !isEmpty(opts.restrictions)) {
up.restrictions.as_public = !!opts.restrictions.as_public;
}
up.dropfiles = function(e) {
Expand Down
5 changes: 2 additions & 3 deletions frappe_better_attach_control/public/js/uploader/v13/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down Expand Up @@ -41,8 +41,7 @@ frappe.ui.FileUploader = class FileUploader extends frappe.ui.FileUploader {
}
_override_uploader(opts) {
var up = this.uploader;
if (isPlainObject(opts)) {
up.restrictions = opts.restrictions;
if (isPlainObject(opts) && !isEmpty(opts.restrictions)) {
up.restrictions.as_public = !!opts.restrictions.as_public;
}
up.dropfiles = function(e) {
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_attach_control/public/js/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Frappe Better Attach Control © 2022
* Frappe Better Attach Control © 2023
* Author: Ameen Ahmed
* Company: Level Up Marketing & Software Development Services
* Licence: Please refer to LICENSE file
Expand Down
4 changes: 4 additions & 0 deletions frappe_better_attach_control/setup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file
26 changes: 26 additions & 0 deletions frappe_better_attach_control/setup/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Frappe Better Attach Control © 2023
# Author: Ameen Ahmed
# Company: Level Up Marketing & Software Development Services
# Licence: Please refer to LICENSE file


import frappe
from frappe import _
from frappe.custom.doctype.custom_field.custom_field import create_custom_field


def after_install():
dt = "DocField"
field = {
"label": _("Better Attach Options"),
"fieldname": "better_attach_options",
"fieldtype": "Small Text",
"no_copy": 1,
"depends_on": "eval:in_list(['Attach', 'Attach Image'], doc.fieldtype)",
"insert_after": "options",
}
existing = frappe.db.get_value("Custom Field", {"dt": dt, "fieldname": field["fieldname"]})
if not existing:
create_custom_field(dt, field, is_system_generated=False)
frappe.clear_cache(doctype=dt)
frappe.db.updatedb(dt)
Loading

0 comments on commit afa2619

Please sign in to comment.