From 4ee5c015c35fcb450e7f751edd5e8b533b974d02 Mon Sep 17 00:00:00 2001 From: Dirk van der Laarse Date: Wed, 14 Jun 2023 12:45:49 +0000 Subject: [PATCH] feat: setting for force web capture mode for camera uploads --- cypress/integration/control_attach.js | 45 +++++++++++++++++++ .../system_settings/system_settings.json | 9 +++- frappe/public/js/frappe/ui/capture.js | 11 +++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/cypress/integration/control_attach.js b/cypress/integration/control_attach.js index 96b8c73b6e..d6086c9ed1 100644 --- a/cypress/integration/control_attach.js +++ b/cypress/integration/control_attach.js @@ -92,4 +92,49 @@ 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..5d88a3e466 100644 --- a/frappe/core/doctype/system_settings/system_settings.json +++ b/frappe/core/doctype/system_settings/system_settings.json @@ -563,12 +563,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-06-14 11:19:33.429196", "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..72841885a0 100644 --- a/frappe/public/js/frappe/ui/capture.js +++ b/frappe/public/js/frappe/ui/capture.js @@ -76,11 +76,16 @@ frappe.ui.Capture = class { show() { this.build_dialog(); - if (frappe.is_mobile()) { - this.show_for_mobile(); - } else { + if (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(); + } + } } build_dialog() {