diff --git a/cypress/integration/control_attach.js b/cypress/integration/control_attach.js index 96b8c73b6e..6714f6c24e 100644 --- a/cypress/integration/control_attach.js +++ b/cypress/integration/control_attach.js @@ -92,4 +92,47 @@ context("Attach Control", () => { cy.get('.actions-btn-group > .dropdown-menu [data-label="Delete"]').click(); cy.click_modal_primary_button("Yes"); }); + + it('Checking that "Camera" button in the "Attach" fieldtype does show if camera is available', () => { + //Navigating to the new form for the newly created doctype + let doctype = "Test Attach Control"; + let dt_in_route = doctype.toLowerCase().replace(/ /g, "-"); + cy.visit(`/app/${dt_in_route}/new`, { + onBeforeLoad(win) { + // Mock "window.navigator.mediaDevices" property + // to return mock mediaDevices object + win.navigator.mediaDevices = { + ondevicechange: null, + }; + }, + }); + cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`); + cy.get("body").should("have.attr", "data-ajax-state", "complete"); + + //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype + cy.findByRole("button", { name: "Attach" }).click(); + + //Clicking on "Camera" button + cy.findByRole("button", { name: "Camera" }).should("exist"); + }); + + it('Checking that "Camera" button in the "Attach" fieldtype does not show if no camera is available', () => { + //Navigating to the new form for the newly created doctype + let doctype = "Test Attach Control"; + let dt_in_route = doctype.toLowerCase().replace(/ /g, "-"); + cy.visit(`/app/${dt_in_route}/new`, { + onBeforeLoad(win) { + // Delete "window.navigator.mediaDevices" property + delete win.navigator.mediaDevices; + }, + }); + cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`); + cy.get("body").should("have.attr", "data-ajax-state", "complete"); + + //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype + cy.findByRole("button", { name: "Attach" }).click(); + + //Clicking on "Camera" button + cy.findByRole("button", { name: "Camera" }).should("not.exist"); + }); }); diff --git a/frappe/core/doctype/system_settings/system_settings.json b/frappe/core/doctype/system_settings/system_settings.json index 5efe87da25..95dc1af924 100644 --- a/frappe/core/doctype/system_settings/system_settings.json +++ b/frappe/core/doctype/system_settings/system_settings.json @@ -33,6 +33,7 @@ "apply_strict_user_permissions", "column_break_21", "allow_guests_to_upload_files", + "force_web_capture_mode_for_uploads", "security", "session_expiry", "document_share_key_expiry", @@ -563,12 +564,19 @@ "fieldtype": "Link", "label": "Reset Password Template", "options": "Email Template" + }, + { + "default": "0", + "description": "When uploading files, force the use of the web-based image capture. If this is unchecked, the default behavior is to use the mobile native camera when use from a mobile is detected.", + "fieldname": "force_web_capture_mode_for_uploads", + "fieldtype": "Check", + "label": "Force Web Capture Mode for Uploads" } ], "icon": "fa fa-cog", "issingle": 1, "links": [], - "modified": "2023-05-25 13:02:54.808773", + "modified": "2023-07-30 17:34:08.292152", "modified_by": "Administrator", "module": "Core", "name": "System Settings", diff --git a/frappe/public/js/frappe/ui/capture.js b/frappe/public/js/frappe/ui/capture.js index bc7ce34149..dc4804be52 100644 --- a/frappe/public/js/frappe/ui/capture.js +++ b/frappe/public/js/frappe/ui/capture.js @@ -76,7 +76,9 @@ frappe.ui.Capture = class { show() { this.build_dialog(); - if (frappe.is_mobile()) { + if (cint(frappe.boot.sysdefaults.force_web_capture_mode_for_uploads)) { + this.show_for_desktop(); + } else if (frappe.is_mobile()) { this.show_for_mobile(); } else { this.show_for_desktop();