diff --git a/commitlint.config.js b/commitlint.config.js index 8847564e53..09de8b8272 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,24 +1,24 @@ module.exports = { - parserPreset: 'conventional-changelog-conventionalcommits', + parserPreset: "conventional-changelog-conventionalcommits", rules: { - 'subject-empty': [2, 'never'], - 'type-case': [2, 'always', 'lower-case'], - 'type-empty': [2, 'never'], - 'type-enum': [ + "subject-empty": [2, "never"], + "type-case": [2, "always", "lower-case"], + "type-empty": [2, "never"], + "type-enum": [ 2, - 'always', + "always", [ - 'build', - 'chore', - 'ci', - 'docs', - 'feat', - 'fix', - 'perf', - 'refactor', - 'revert', - 'style', - 'test', + "build", + "chore", + "ci", + "docs", + "feat", + "fix", + "perf", + "refactor", + "revert", + "style", + "test", ], ], }, diff --git a/cypress/fixtures/child_table_doctype.js b/cypress/fixtures/child_table_doctype.js index f65e5d1765..88a925aca3 100644 --- a/cypress/fixtures/child_table_doctype.js +++ b/cypress/fixtures/child_table_doctype.js @@ -13,8 +13,8 @@ export default { fieldtype: "Data", in_list_view: 1, label: "Title", - unique: 1 - } + unique: 1, + }, ], links: [], istable: 1, @@ -24,7 +24,7 @@ export default { naming_rule: "By fieldname", owner: "Administrator", permissions: [], - sort_field: 'modified', - sort_order: 'ASC', - track_changes: 1 -}; \ No newline at end of file + sort_field: "modified", + sort_order: "ASC", + track_changes: 1, +}; diff --git a/cypress/fixtures/child_table_doctype_1.js b/cypress/fixtures/child_table_doctype_1.js index 4657d63e2e..abf8873bff 100644 --- a/cypress/fixtures/child_table_doctype_1.js +++ b/cypress/fixtures/child_table_doctype_1.js @@ -12,38 +12,38 @@ export default { fieldname: "data", fieldtype: "Data", in_list_view: 1, - label: "Data" + label: "Data", }, { fieldname: "barcode", fieldtype: "Barcode", in_list_view: 1, - label: "Barcode" + label: "Barcode", }, { fieldname: "check", fieldtype: "Check", in_list_view: 1, - label: "Check" + label: "Check", }, { fieldname: "rating", fieldtype: "Rating", in_list_view: 1, - label: "Rating" + label: "Rating", }, { fieldname: "duration", fieldtype: "Duration", in_list_view: 1, - label: "Duration" + label: "Duration", }, { fieldname: "date", fieldtype: "Date", in_list_view: 1, - label: "Date" - } + label: "Date", + }, ], links: [], istable: 1, @@ -53,7 +53,7 @@ export default { naming_rule: "By fieldname", owner: "Administrator", permissions: [], - sort_field: 'modified', - sort_order: 'ASC', - track_changes: 1 -}; \ No newline at end of file + sort_field: "modified", + sort_order: "ASC", + track_changes: 1, +}; diff --git a/cypress/fixtures/custom_submittable_doctype.js b/cypress/fixtures/custom_submittable_doctype.js index c88d37b373..30aa698db4 100644 --- a/cypress/fixtures/custom_submittable_doctype.js +++ b/cypress/fixtures/custom_submittable_doctype.js @@ -1,37 +1,37 @@ export default { - name: 'Custom Submittable DocType', + name: "Custom Submittable DocType", custom: 1, actions: [], is_submittable: 1, - creation: '2019-12-10 06:29:07.215072', - doctype: 'DocType', + creation: "2019-12-10 06:29:07.215072", + doctype: "DocType", editable_grid: 1, - engine: 'InnoDB', + engine: "InnoDB", fields: [ { - fieldname: 'enabled', - fieldtype: 'Check', - label: 'Enabled', + fieldname: "enabled", + fieldtype: "Check", + label: "Enabled", allow_on_submit: 1, - reqd: 1 + reqd: 1, }, { - fieldname: 'title', - fieldtype: 'Data', - label: 'title', - reqd: 1 + fieldname: "title", + fieldtype: "Data", + label: "title", + reqd: 1, }, { - fieldname: 'description', - fieldtype: 'Text Editor', - label: 'Description' - } + fieldname: "description", + fieldtype: "Text Editor", + label: "Description", + }, ], links: [], - modified: '2019-12-10 14:40:53.127615', - modified_by: 'Administrator', - module: 'Custom', - owner: 'Administrator', + modified: "2019-12-10 14:40:53.127615", + modified_by: "Administrator", + module: "Custom", + owner: "Administrator", permissions: [ { create: 1, @@ -39,15 +39,15 @@ export default { email: 1, print: 1, read: 1, - role: 'System Manager', + role: "System Manager", share: 1, write: 1, submit: 1, - cancel: 1 - } + cancel: 1, + }, ], quick_entry: 1, - sort_field: 'modified', - sort_order: 'ASC', - track_changes: 1 -}; \ No newline at end of file + sort_field: "modified", + sort_order: "ASC", + track_changes: 1, +}; diff --git a/cypress/fixtures/data_field_validation_doctype.js b/cypress/fixtures/data_field_validation_doctype.js index da091af7e5..2901630d3f 100644 --- a/cypress/fixtures/data_field_validation_doctype.js +++ b/cypress/fixtures/data_field_validation_doctype.js @@ -1,51 +1,51 @@ export default { - name: 'Validation Test', + name: "Validation Test", custom: 1, actions: [], - creation: '2019-03-15 06:29:07.215072', - doctype: 'DocType', + creation: "2019-03-15 06:29:07.215072", + doctype: "DocType", editable_grid: 1, - engine: 'InnoDB', + engine: "InnoDB", fields: [ { - fieldname: 'email', - fieldtype: 'Data', - label: 'Email', - options: 'Email' + fieldname: "email", + fieldtype: "Data", + label: "Email", + options: "Email", }, { - fieldname: 'URL', - fieldtype: 'Data', - label: 'URL', - options: 'URL' + fieldname: "URL", + fieldtype: "Data", + label: "URL", + options: "URL", }, { - fieldname: 'Phone', - fieldtype: 'Data', - label: 'Phone', - options: 'Phone' + fieldname: "Phone", + fieldtype: "Data", + label: "Phone", + options: "Phone", }, { - fieldname: 'person_name', - fieldtype: 'Data', - label: 'Person Name', - options: 'Name' + fieldname: "person_name", + fieldtype: "Data", + label: "Person Name", + options: "Name", }, { - fieldname: 'read_only_url', - fieldtype: 'Data', - label: 'Read Only URL', - options: 'URL', - read_only: '1', - default: 'https://frappe.io' - } + fieldname: "read_only_url", + fieldtype: "Data", + label: "Read Only URL", + options: "URL", + read_only: "1", + default: "https://frappe.io", + }, ], issingle: 1, links: [], - modified: '2021-04-19 14:40:53.127615', - modified_by: 'Administrator', - module: 'Custom', - owner: 'Administrator', + modified: "2021-04-19 14:40:53.127615", + modified_by: "Administrator", + module: "Custom", + owner: "Administrator", permissions: [ { create: 1, @@ -53,13 +53,13 @@ export default { email: 1, print: 1, read: 1, - role: 'System Manager', + role: "System Manager", share: 1, - write: 1 - } + write: 1, + }, ], quick_entry: 1, - sort_field: 'modified', - sort_order: 'ASC', - track_changes: 1 + sort_field: "modified", + sort_order: "ASC", + track_changes: 1, }; diff --git a/cypress/fixtures/datetime_doctype.js b/cypress/fixtures/datetime_doctype.js index b8c89ced5c..f1a77ba6bb 100644 --- a/cypress/fixtures/datetime_doctype.js +++ b/cypress/fixtures/datetime_doctype.js @@ -1,34 +1,34 @@ export default { - name: 'DateTime Test', + name: "DateTime Test", custom: 1, actions: [], - creation: '2019-03-15 06:29:07.215072', - doctype: 'DocType', + creation: "2019-03-15 06:29:07.215072", + doctype: "DocType", editable_grid: 1, - engine: 'InnoDB', + engine: "InnoDB", fields: [ { - fieldname: 'date', - fieldtype: 'Date', - label: 'Date' + fieldname: "date", + fieldtype: "Date", + label: "Date", }, { - fieldname: 'time', - fieldtype: 'Time', - label: 'Time' + fieldname: "time", + fieldtype: "Time", + label: "Time", }, { - fieldname: 'datetime', - fieldtype: 'Datetime', - label: 'Datetime' - } + fieldname: "datetime", + fieldtype: "Datetime", + label: "Datetime", + }, ], issingle: 1, links: [], - modified: '2019-12-09 14:40:53.127615', - modified_by: 'Administrator', - module: 'Custom', - owner: 'Administrator', + modified: "2019-12-09 14:40:53.127615", + modified_by: "Administrator", + module: "Custom", + owner: "Administrator", permissions: [ { create: 1, @@ -36,13 +36,13 @@ export default { email: 1, print: 1, read: 1, - role: 'System Manager', + role: "System Manager", share: 1, - write: 1 - } + write: 1, + }, ], quick_entry: 1, - sort_field: 'modified', - sort_order: 'ASC', - track_changes: 1 + sort_field: "modified", + sort_order: "ASC", + track_changes: 1, }; diff --git a/cypress/fixtures/doctype_to_link.js b/cypress/fixtures/doctype_to_link.js index f5335b1755..ff5d1b5c68 100644 --- a/cypress/fixtures/doctype_to_link.js +++ b/cypress/fixtures/doctype_to_link.js @@ -10,18 +10,18 @@ export default { engine: "InnoDB", fields: [ { - "fieldname": "title", - "fieldtype": "Data", - "label": "Title", - "unique": 1 - } + fieldname: "title", + fieldtype: "Data", + label: "Title", + unique: 1, + }, ], links: [ { - "group": "Child Doctype", - "link_doctype": "Doctype With Child Table", - "link_fieldname": "title" - } + group: "Child Doctype", + link_doctype: "Doctype With Child Table", + link_fieldname: "title", + }, ], modified: "2022-02-10 12:03:12.603763", modified_by: "Administrator", @@ -34,12 +34,12 @@ export default { email: 1, print: 1, read: 1, - role: 'System Manager', + role: "System Manager", share: 1, - write: 1 - } + write: 1, + }, ], - sort_field: 'modified', - sort_order: 'ASC', - track_changes: 1 -}; \ No newline at end of file + sort_field: "modified", + sort_order: "ASC", + track_changes: 1, +}; diff --git a/cypress/fixtures/doctype_with_child_table.js b/cypress/fixtures/doctype_with_child_table.js index 014074b0b5..7caba516cf 100644 --- a/cypress/fixtures/doctype_with_child_table.js +++ b/cypress/fixtures/doctype_with_child_table.js @@ -12,21 +12,21 @@ export default { fieldname: "title", fieldtype: "Data", label: "Title", - unique: 1 + unique: 1, }, { fieldname: "child_table", fieldtype: "Table", label: "Child Table", options: "Child Table Doctype", - reqd: 1 + reqd: 1, }, { fieldname: "child_table_1", fieldtype: "Table", label: "Child Table 1", - options: "Child Table Doctype 1" - } + options: "Child Table Doctype 1", + }, ], links: [], modified: "2022-02-10 12:03:12.603763", @@ -41,12 +41,12 @@ export default { email: 1, print: 1, read: 1, - role: 'System Manager', + role: "System Manager", share: 1, - write: 1 - } + write: 1, + }, ], - sort_field: 'modified', - sort_order: 'ASC', - track_changes: 1 + sort_field: "modified", + sort_order: "ASC", + track_changes: 1, }; diff --git a/cypress/fixtures/doctype_with_phone.js b/cypress/fixtures/doctype_with_phone.js index c62922ade2..06a24a5be5 100644 --- a/cypress/fixtures/doctype_with_phone.js +++ b/cypress/fixtures/doctype_with_phone.js @@ -4,29 +4,28 @@ export default { custom: 1, is_submittable: 1, autoname: "field:title", - creation: '2022-03-30 06:29:07.215072', - doctype: 'DocType', - engine: 'InnoDB', + creation: "2022-03-30 06:29:07.215072", + doctype: "DocType", + engine: "InnoDB", fields: [ - { - fieldname: 'title', - fieldtype: 'Data', - label: 'title', + fieldname: "title", + fieldtype: "Data", + label: "title", unique: 1, }, { - fieldname: 'phone', - fieldtype: 'Phone', - label: 'Phone' - } + fieldname: "phone", + fieldtype: "Phone", + label: "Phone", + }, ], links: [], - modified: '2019-03-30 14:40:53.127615', - modified_by: 'Administrator', + modified: "2019-03-30 14:40:53.127615", + modified_by: "Administrator", naming_rule: "By fieldname", - module: 'Custom', - owner: 'Administrator', + module: "Custom", + owner: "Administrator", permissions: [ { create: 1, @@ -34,14 +33,14 @@ export default { email: 1, print: 1, read: 1, - role: 'System Manager', + role: "System Manager", share: 1, write: 1, submit: 1, - cancel: 1 - } + cancel: 1, + }, ], - sort_field: 'modified', - sort_order: 'ASC', - track_changes: 1 + sort_field: "modified", + sort_order: "ASC", + track_changes: 1, }; diff --git a/cypress/fixtures/doctype_with_tab_break.js b/cypress/fixtures/doctype_with_tab_break.js index 74e5e6abba..44d6c16682 100644 --- a/cypress/fixtures/doctype_with_tab_break.js +++ b/cypress/fixtures/doctype_with_tab_break.js @@ -1,39 +1,39 @@ export default { - name: 'Form With Tab Break', + name: "Form With Tab Break", custom: 1, actions: [], - doctype: 'DocType', - engine: 'InnoDB', + doctype: "DocType", + engine: "InnoDB", fields: [ { - fieldname: 'username', - fieldtype: 'Data', - label: 'Name', - options: 'Name' + fieldname: "username", + fieldtype: "Data", + label: "Name", + options: "Name", }, { - fieldname: 'tab', - fieldtype: 'Tab Break', - label: 'Tab 2', + fieldname: "tab", + fieldtype: "Tab Break", + label: "Tab 2", }, { - fieldname: 'Phone', - fieldtype: 'Data', - label: 'Phone', - options: 'Phone', - reqd: 1 + fieldname: "Phone", + fieldtype: "Data", + label: "Phone", + options: "Phone", + reqd: 1, }, ], links: [ { - "group": "Profile", - "link_doctype": "Contact", - "link_fieldname": "user" + group: "Profile", + link_doctype: "Contact", + link_fieldname: "user", }, ], - modified_by: 'Administrator', - module: 'Custom', - owner: 'Administrator', + modified_by: "Administrator", + module: "Custom", + owner: "Administrator", permissions: [ { create: 1, @@ -41,14 +41,14 @@ export default { email: 1, print: 1, read: 1, - role: 'System Manager', + role: "System Manager", share: 1, - write: 1 - } + write: 1, + }, ], quick_entry: 1, autoname: "format: Test-{####}", - sort_field: 'modified', - sort_order: 'ASC', - track_changes: 1 + sort_field: "modified", + sort_order: "ASC", + track_changes: 1, }; diff --git a/cypress/integration/api.js b/cypress/integration/api.js index e8c39e6e25..420cea25fd 100644 --- a/cypress/integration/api.js +++ b/cypress/integration/api.js @@ -1,42 +1,43 @@ -context('API Resources', () => { +context("API Resources", () => { before(() => { - cy.visit('/login'); + cy.visit("/login"); cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); - it('Creates two Comments', () => { - cy.insert_doc('Comment', { comment_type: 'Comment', content: "hello" }); - cy.insert_doc('Comment', { comment_type: 'Comment', content: "world" }); + it("Creates two Comments", () => { + cy.insert_doc("Comment", { comment_type: "Comment", content: "hello" }); + cy.insert_doc("Comment", { comment_type: "Comment", content: "world" }); }); - it('Lists the Comments', () => { - cy.get_list('Comment') - .its('data') - .then(data => expect(data.length).to.be.at.least(2)); + it("Lists the Comments", () => { + cy.get_list("Comment") + .its("data") + .then((data) => expect(data.length).to.be.at.least(2)); - cy.get_list('Comment', ['name', 'content'], [['content', '=', 'hello']]) - .then(body => { - expect(body).to.have.property('data'); - expect(body.data).to.have.lengthOf(1); - expect(body.data[0]).to.have.property('content'); - expect(body.data[0]).to.have.property('name'); - }); + cy.get_list("Comment", ["name", "content"], [["content", "=", "hello"]]).then((body) => { + expect(body).to.have.property("data"); + expect(body.data).to.have.lengthOf(1); + expect(body.data[0]).to.have.property("content"); + expect(body.data[0]).to.have.property("name"); + }); }); - it('Gets each Comment', () => { - cy.get_list('Comment').then(body => body.data.forEach(comment => { - cy.get_doc('Comment', comment.name); - })); + it("Gets each Comment", () => { + cy.get_list("Comment").then((body) => + body.data.forEach((comment) => { + cy.get_doc("Comment", comment.name); + }) + ); }); - it('Removes the Comments', () => { - cy.get_list('Comment').then(body => { + it("Removes the Comments", () => { + cy.get_list("Comment").then((body) => { let comment_names = []; - body.data.map(comment => comment_names.push(comment.name)); + body.data.map((comment) => comment_names.push(comment.name)); comment_names = [...new Set(comment_names)]; // remove duplicates comment_names.forEach((comment_name) => { - cy.remove_doc('Comment', comment_name); + cy.remove_doc("Comment", comment_name); }); }); }); diff --git a/cypress/integration/awesome_bar.js b/cypress/integration/awesome_bar.js index 938034a34a..71e5e498cf 100644 --- a/cypress/integration/awesome_bar.js +++ b/cypress/integration/awesome_bar.js @@ -1,48 +1,57 @@ -context('Awesome Bar', () => { +context("Awesome Bar", () => { before(() => { - cy.visit('/login'); + cy.visit("/login"); cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); beforeEach(() => { - cy.get('.navbar .navbar-home').click(); - cy.findByPlaceholderText('Search or type a command (Ctrl + G)').clear(); + cy.get(".navbar .navbar-home").click(); + cy.findByPlaceholderText("Search or type a command (Ctrl + G)").clear(); }); - it('navigates to doctype list', () => { - cy.findByPlaceholderText('Search or type a command (Ctrl + G)').type('todo', { delay: 700 }); - cy.get('.awesomplete').findByRole('listbox').should('be.visible'); - cy.findByPlaceholderText('Search or type a command (Ctrl + G)').type('{enter}', { delay: 700 }); + it("navigates to doctype list", () => { + cy.findByPlaceholderText("Search or type a command (Ctrl + G)").type("todo", { + delay: 700, + }); + cy.get(".awesomplete").findByRole("listbox").should("be.visible"); + cy.findByPlaceholderText("Search or type a command (Ctrl + G)").type("{enter}", { + delay: 700, + }); - cy.get('.title-text').should('contain', 'To Do'); + cy.get(".title-text").should("contain", "To Do"); - cy.location('pathname').should('eq', '/app/todo'); + cy.location("pathname").should("eq", "/app/todo"); }); - it('find text in doctype list', () => { - cy.findByPlaceholderText('Search or type a command (Ctrl + G)') - .type('test in todo{enter}', { delay: 700 }); + it("find text in doctype list", () => { + cy.findByPlaceholderText("Search or type a command (Ctrl + G)").type( + "test in todo{enter}", + { delay: 700 } + ); - cy.get('.title-text').should('contain', 'To Do'); + cy.get(".title-text").should("contain", "To Do"); - cy.findByPlaceholderText('ID') - .should('have.value', '%test%'); + cy.findByPlaceholderText("ID").should("have.value", "%test%"); cy.clear_filters(); }); - it('navigates to new form', () => { - cy.findByPlaceholderText('Search or type a command (Ctrl + G)') - .type('new blog post{enter}', { delay: 700 }); + it("navigates to new form", () => { + cy.findByPlaceholderText("Search or type a command (Ctrl + G)").type( + "new blog post{enter}", + { delay: 700 } + ); - cy.get('.title-text:visible').should('have.text', 'New Blog Post'); + cy.get(".title-text:visible").should("have.text", "New Blog Post"); }); - it('calculates math expressions', () => { - cy.findByPlaceholderText('Search or type a command (Ctrl + G)') - .type('55 + 32{downarrow}{enter}', { delay: 700 }); + it("calculates math expressions", () => { + cy.findByPlaceholderText("Search or type a command (Ctrl + G)").type( + "55 + 32{downarrow}{enter}", + { delay: 700 } + ); - cy.get('.modal-title').should('contain', 'Result'); - cy.get('.msgprint').should('contain', '55 + 32 = 87'); + cy.get(".modal-title").should("contain", "Result"); + cy.get(".msgprint").should("contain", "55 + 32 = 87"); }); }); diff --git a/cypress/integration/control_attach.js b/cypress/integration/control_attach.js index 0552780737..96b8c73b6e 100644 --- a/cypress/integration/control_attach.js +++ b/cypress/integration/control_attach.js @@ -1,90 +1,95 @@ -context('Attach Control', () => { +context("Attach Control", () => { before(() => { cy.login(); - cy.visit('/app/doctype'); - return cy.window().its('frappe').then(frappe => { - return frappe.xcall('frappe.tests.ui_test_helpers.create_doctype', { - name: 'Test Attach Control', - fields: [ - { - "label": "Attach File or Image", - "fieldname": "attach", - "fieldtype": "Attach", - "in_list_view": 1, - }, - ] + cy.visit("/app/doctype"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.xcall("frappe.tests.ui_test_helpers.create_doctype", { + name: "Test Attach Control", + fields: [ + { + label: "Attach File or Image", + fieldname: "attach", + fieldtype: "Attach", + in_list_view: 1, + }, + ], + }); }); - }); }); it('Checking functionality for "Link" button in the "Attach" fieldtype', () => { //Navigating to the new form for the newly created doctype - cy.new_form('Test Attach Control'); + cy.new_form("Test Attach Control"); //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype - cy.findByRole('button', {name: 'Attach'}).click(); + cy.findByRole("button", { name: "Attach" }).click(); //Clicking on "Link" button to attach a file using the "Link" button - cy.findByRole('button', {name: 'Link'}).click(); - cy.findByPlaceholderText('Attach a web link').type('https://wallpaperplay.com/walls/full/8/2/b/72402.jpg'); - + cy.findByRole("button", { name: "Link" }).click(); + cy.findByPlaceholderText("Attach a web link").type( + "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg" + ); + //Clicking on the Upload button to upload the file cy.intercept("POST", "/api/method/upload_file").as("upload_image"); - cy.get('.modal-footer').findByRole("button", {name: "Upload"}).click({delay: 500}); + cy.get(".modal-footer").findByRole("button", { name: "Upload" }).click({ delay: 500 }); cy.wait("@upload_image"); - cy.findByRole('button', {name: 'Save'}).click(); + cy.findByRole("button", { name: "Save" }).click(); //Checking if the URL of the attached image is getting displayed in the field of the newly created doctype - cy.get('.attached-file > .ellipsis > .attached-file-link') - .should('have.attr', 'href') - .and('equal', 'https://wallpaperplay.com/walls/full/8/2/b/72402.jpg'); + cy.get(".attached-file > .ellipsis > .attached-file-link") + .should("have.attr", "href") + .and("equal", "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg"); //Clicking on the "Clear" button cy.get('[data-action="clear_attachment"]').click(); //Checking if clicking on the clear button clears the field of the doctype form and again displays the attach button - cy.get('.control-input > .btn-sm').should('contain', 'Attach'); + cy.get(".control-input > .btn-sm").should("contain", "Attach"); //Deleting the doc - cy.go_to_list('Test Attach Control'); - cy.get('.list-row-checkbox').eq(0).click(); - cy.get('.actions-btn-group > .btn').contains('Actions').click(); + cy.go_to_list("Test Attach Control"); + cy.get(".list-row-checkbox").eq(0).click(); + cy.get(".actions-btn-group > .btn").contains("Actions").click(); cy.get('.actions-btn-group > .dropdown-menu [data-label="Delete"]').click(); - cy.click_modal_primary_button('Yes'); + cy.click_modal_primary_button("Yes"); }); it('Checking functionality for "Library" button in the "Attach" fieldtype', () => { //Navigating to the new form for the newly created doctype - cy.new_form('Test Attach Control'); + cy.new_form("Test Attach Control"); //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype - cy.findByRole('button', {name: 'Attach'}).click(); + cy.findByRole("button", { name: "Attach" }).click(); //Clicking on "Library" button to attach a file using the "Library" button - cy.findByRole('button', {name: 'Library'}).click(); - cy.contains('72402.jpg').click(); + cy.findByRole("button", { name: "Library" }).click(); + cy.contains("72402.jpg").click(); //Clicking on the Upload button to upload the file cy.intercept("POST", "/api/method/upload_file").as("upload_image"); - cy.get('.modal-footer').findByRole("button", {name: "Upload"}).click({delay: 500}); + cy.get(".modal-footer").findByRole("button", { name: "Upload" }).click({ delay: 500 }); cy.wait("@upload_image"); - cy.findByRole('button', {name: 'Save'}).click(); + cy.findByRole("button", { name: "Save" }).click(); //Checking if the URL of the attached image is getting displayed in the field of the newly created doctype - cy.get('.attached-file > .ellipsis > .attached-file-link') - .should('have.attr', 'href') - .and('equal', 'https://wallpaperplay.com/walls/full/8/2/b/72402.jpg'); + cy.get(".attached-file > .ellipsis > .attached-file-link") + .should("have.attr", "href") + .and("equal", "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg"); //Clicking on the "Clear" button cy.get('[data-action="clear_attachment"]').click(); //Checking if clicking on the clear button clears the field of the doctype form and again displays the attach button - cy.get('.control-input > .btn-sm').should('contain', 'Attach'); + cy.get(".control-input > .btn-sm").should("contain", "Attach"); //Deleting the doc - cy.go_to_list('Test Attach Control'); - cy.get('.list-row-checkbox').eq(0).click(); - cy.get('.actions-btn-group > .btn').contains('Actions').click(); + cy.go_to_list("Test Attach Control"); + cy.get(".list-row-checkbox").eq(0).click(); + cy.get(".actions-btn-group > .btn").contains("Actions").click(); cy.get('.actions-btn-group > .dropdown-menu [data-label="Delete"]').click(); - cy.click_modal_primary_button('Yes'); + cy.click_modal_primary_button("Yes"); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/control_autocomplete.js b/cypress/integration/control_autocomplete.js index 3bf3e829f9..6dc57fcf43 100644 --- a/cypress/integration/control_autocomplete.js +++ b/cypress/integration/control_autocomplete.js @@ -1,57 +1,64 @@ -context('Control Autocomplete', () => { +context("Control Autocomplete", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); function get_dialog_with_autocomplete(options) { - cy.visit('/app/website'); + cy.visit("/app/website"); return cy.dialog({ - title: 'Autocomplete', + title: "Autocomplete", fields: [ { - 'label': 'Select an option', - 'fieldname': 'autocomplete', - 'fieldtype': 'Autocomplete', - 'options': options || ['Option 1', 'Option 2', 'Option 3'], - } - ] + label: "Select an option", + fieldname: "autocomplete", + fieldtype: "Autocomplete", + options: options || ["Option 1", "Option 2", "Option 3"], + }, + ], }); } - it('should set the valid value', () => { - get_dialog_with_autocomplete().as('dialog'); + it("should set the valid value", () => { + get_dialog_with_autocomplete().as("dialog"); - cy.get('.frappe-control[data-fieldname=autocomplete] input').focus().as('input'); + cy.get(".frappe-control[data-fieldname=autocomplete] input").focus().as("input"); cy.wait(1000); - cy.get('@input').type('2', { delay: 300 }); - cy.get('.frappe-control[data-fieldname=autocomplete]').findByRole('listbox').should('be.visible'); - cy.get('.frappe-control[data-fieldname=autocomplete] input').type('{enter}', { delay: 300 }); - cy.get('.frappe-control[data-fieldname=autocomplete] input').blur(); - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('autocomplete'); - expect(value).to.eq('Option 2'); + cy.get("@input").type("2", { delay: 300 }); + cy.get(".frappe-control[data-fieldname=autocomplete]") + .findByRole("listbox") + .should("be.visible"); + cy.get(".frappe-control[data-fieldname=autocomplete] input").type("{enter}", { + delay: 300, + }); + cy.get(".frappe-control[data-fieldname=autocomplete] input").blur(); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("autocomplete"); + expect(value).to.eq("Option 2"); dialog.clear(); }); }); - it('should set the valid value with different label', () => { + it("should set the valid value with different label", () => { const options_with_label = [ { label: "Option 1", value: "option_1" }, - { label: "Option 2", value: "option_2" } + { label: "Option 2", value: "option_2" }, ]; - get_dialog_with_autocomplete(options_with_label).as('dialog'); + get_dialog_with_autocomplete(options_with_label).as("dialog"); - cy.get('.frappe-control[data-fieldname=autocomplete] input').focus().as('input'); - cy.get('.frappe-control[data-fieldname=autocomplete]').findByRole('listbox').should('be.visible'); - cy.get('@input').type('2', { delay: 300 }); - cy.get('.frappe-control[data-fieldname=autocomplete] input').type('{enter}', { delay: 300 }); - cy.get('.frappe-control[data-fieldname=autocomplete] input').blur(); - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('autocomplete'); - expect(value).to.eq('option_2'); + cy.get(".frappe-control[data-fieldname=autocomplete] input").focus().as("input"); + cy.get(".frappe-control[data-fieldname=autocomplete]") + .findByRole("listbox") + .should("be.visible"); + cy.get("@input").type("2", { delay: 300 }); + cy.get(".frappe-control[data-fieldname=autocomplete] input").type("{enter}", { + delay: 300, + }); + cy.get(".frappe-control[data-fieldname=autocomplete] input").blur(); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("autocomplete"); + expect(value).to.eq("option_2"); dialog.clear(); }); }); - }); diff --git a/cypress/integration/control_barcode.js b/cypress/integration/control_barcode.js index 85a3182397..96a1bb43d4 100644 --- a/cypress/integration/control_barcode.js +++ b/cypress/integration/control_barcode.js @@ -1,55 +1,57 @@ -context('Control Barcode', () => { +context("Control Barcode", () => { beforeEach(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); function get_dialog_with_barcode() { return cy.dialog({ - title: 'Barcode', + title: "Barcode", fields: [ { - label: 'Barcode', - fieldname: 'barcode', - fieldtype: 'Barcode' - } - ] + label: "Barcode", + fieldname: "barcode", + fieldtype: "Barcode", + }, + ], }); } - it('should generate barcode on setting a value', () => { - get_dialog_with_barcode().as('dialog'); + it("should generate barcode on setting a value", () => { + get_dialog_with_barcode().as("dialog"); cy.focused().blur(); - cy.get('.frappe-control[data-fieldname=barcode]').findByRole('textbox') - .type('123456789') + cy.get(".frappe-control[data-fieldname=barcode]") + .findByRole("textbox") + .type("123456789") .blur(); - cy.get('.frappe-control[data-fieldname=barcode] svg[data-barcode-value="123456789"]') - .should('exist'); + cy.get( + '.frappe-control[data-fieldname=barcode] svg[data-barcode-value="123456789"]' + ).should("exist"); - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('barcode'); - expect(value).to.contain(' { + let value = dialog.get_value("barcode"); + expect(value).to.contain(" { - get_dialog_with_barcode().as('dialog'); + it("should reset when input is cleared", () => { + get_dialog_with_barcode().as("dialog"); cy.focused().blur(); - cy.get('.frappe-control[data-fieldname=barcode]').findByRole('textbox') - .type('123456789') + cy.get(".frappe-control[data-fieldname=barcode]") + .findByRole("textbox") + .type("123456789") .blur(); - cy.get('.frappe-control[data-fieldname=barcode]').findByRole('textbox') - .clear() - .blur(); - cy.get('.frappe-control[data-fieldname=barcode] svg[data-barcode-value="123456789"]') - .should('not.exist'); + cy.get(".frappe-control[data-fieldname=barcode]").findByRole("textbox").clear().blur(); + cy.get( + '.frappe-control[data-fieldname=barcode] svg[data-barcode-value="123456789"]' + ).should("not.exist"); - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('barcode'); - expect(value).to.equal(''); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("barcode"); + expect(value).to.equal(""); }); }); }); diff --git a/cypress/integration/control_color.js b/cypress/integration/control_color.js index 8d55003618..aa3a45eed8 100644 --- a/cypress/integration/control_color.js +++ b/cypress/integration/control_color.js @@ -1,77 +1,80 @@ -context('Control Color', () => { +context("Control Color", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); function get_dialog_with_color() { return cy.dialog({ - title: 'Color', - fields: [{ - label: 'Color', - fieldname: 'color', - fieldtype: 'Color' - }] + title: "Color", + fields: [ + { + label: "Color", + fieldname: "color", + fieldtype: "Color", + }, + ], }); } - it('Verifying if the color control is selecting correct', () => { - get_dialog_with_color().as('dialog'); - cy.findByPlaceholderText('Choose a color').click(); + it("Verifying if the color control is selecting correct", () => { + get_dialog_with_color().as("dialog"); + cy.findByPlaceholderText("Choose a color").click(); ///Selecting a color from the color palette cy.get('[style="background-color: rgb(79, 157, 217);"]').click(); //Checking if the css attribute is correct - cy.get('.color-map').should('have.css', 'color', 'rgb(79, 157, 217)'); - cy.get('.hue-map').should('have.css', 'color', 'rgb(0, 145, 255)'); + cy.get(".color-map").should("have.css", "color", "rgb(79, 157, 217)"); + cy.get(".hue-map").should("have.css", "color", "rgb(0, 145, 255)"); //Checking if the correct color is being selected - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('color'); - expect(value).to.equal('#4F9DD9'); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("color"); + expect(value).to.equal("#4F9DD9"); }); //Selecting a color cy.get('[style="background-color: rgb(203, 41, 41);"]').click(); //Checking if the correct css is being selected - cy.get('.color-map').should('have.css', 'color', 'rgb(203, 41, 41)'); - cy.get('.hue-map').should('have.css', 'color', 'rgb(255, 0, 0)'); + cy.get(".color-map").should("have.css", "color", "rgb(203, 41, 41)"); + cy.get(".hue-map").should("have.css", "color", "rgb(255, 0, 0)"); //Checking if the correct color is being selected - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('color'); - expect(value).to.equal('#CB2929'); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("color"); + expect(value).to.equal("#CB2929"); }); //Selecting color from the palette - cy.get('.color-map > .color-selector').click(65, 87, {force: true}); - cy.get('.color-map').should('have.css', 'color', 'rgb(56, 0, 0)'); + cy.get(".color-map > .color-selector").click(65, 87, { force: true }); + cy.get(".color-map").should("have.css", "color", "rgb(56, 0, 0)"); //Checking if the expected color is selected and getting displayed - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('color'); - expect(value).to.equal('#380000'); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("color"); + expect(value).to.equal("#380000"); }); //Selecting the color from the hue map - cy.get('.hue-map > .hue-selector').click(35, -1, {force: true}); - cy.get('.color-map').should('have.css', 'color', 'rgb(56, 45, 0)'); - cy.get('.hue-map').should('have.css', 'color', 'rgb(255, 204, 0)'); - cy.get('.color-map > .color-selector').click(55, 12, {force: true}); - cy.get('.color-map').should('have.css', 'color', 'rgb(46, 37, 0)'); + cy.get(".hue-map > .hue-selector").click(35, -1, { force: true }); + cy.get(".color-map").should("have.css", "color", "rgb(56, 45, 0)"); + cy.get(".hue-map").should("have.css", "color", "rgb(255, 204, 0)"); + cy.get(".color-map > .color-selector").click(55, 12, { force: true }); + cy.get(".color-map").should("have.css", "color", "rgb(46, 37, 0)"); //Checking if the correct color is being displayed - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('color'); - expect(value).to.equal('#2e2500'); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("color"); + expect(value).to.equal("#2e2500"); }); //Clearing the field and checking if the field contains the placeholder "Choose a color" - cy.get('.input-with-feedback').click({force: true}); - cy.get_field('color', 'Color').type('{selectall}').clear(); - cy.get_field('color', 'Color').invoke('attr', 'placeholder').should('contain', 'Choose a color'); - + cy.get(".input-with-feedback").click({ force: true }); + cy.get_field("color", "Color").type("{selectall}").clear(); + cy.get_field("color", "Color") + .invoke("attr", "placeholder") + .should("contain", "Choose a color"); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/control_data.js b/cypress/integration/control_data.js index 78cece627b..d855df2919 100644 --- a/cypress/integration/control_data.js +++ b/cypress/integration/control_data.js @@ -1,134 +1,145 @@ -context('Data Control', () => { +context("Data Control", () => { before(() => { cy.login(); - cy.visit('/app/doctype'); - return cy.window().its('frappe').then(frappe => { - return frappe.xcall('frappe.tests.ui_test_helpers.create_doctype', { - name: 'Test Data Control', - fields: [ - { - "label": "Name", - "fieldname": "name1", - "fieldtype": "Data", - "options": "Name", - "in_list_view": 1, - "reqd": 1, - }, - { - "label": "Email-ID", - "fieldname": "email", - "fieldtype": "Data", - "options": "Email", - "in_list_view": 1, - "reqd": 1, - }, - { - "label": "Phone No.", - "fieldname": "phone", - "fieldtype": "Data", - "options": "Phone", - "in_list_view": 1, - "reqd": 1, - }, - ] + cy.visit("/app/doctype"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.xcall("frappe.tests.ui_test_helpers.create_doctype", { + name: "Test Data Control", + fields: [ + { + label: "Name", + fieldname: "name1", + fieldtype: "Data", + options: "Name", + in_list_view: 1, + reqd: 1, + }, + { + label: "Email-ID", + fieldname: "email", + fieldtype: "Data", + options: "Email", + in_list_view: 1, + reqd: 1, + }, + { + label: "Phone No.", + fieldname: "phone", + fieldtype: "Data", + options: "Phone", + in_list_view: 1, + reqd: 1, + }, + ], + }); }); - }); }); - it('check custom formatters', () => { + it("check custom formatters", () => { cy.visit(`/app/doctype/User`); - cy.get('[data-fieldname="fields"] .grid-row[data-idx="2"] [data-fieldname="fieldtype"] .static-area').should('have.text', '🔵 Section Break'); + cy.get( + '[data-fieldname="fields"] .grid-row[data-idx="2"] [data-fieldname="fieldtype"] .static-area' + ).should("have.text", "🔵 Section Break"); }); it('Verifying data control by inputting different patterns for "Name" field', () => { - cy.new_form('Test Data Control'); + cy.new_form("Test Data Control"); //Checking the URL for the new form of the doctype - cy.location("pathname").should('eq', '/app/test-data-control/new-test-data-control-1'); - cy.get('.title-text').should('have.text', 'New Test Data Control'); - cy.get('.frappe-control[data-fieldname="name1"]').find('label').should('have.class', 'reqd'); - cy.get('.frappe-control[data-fieldname="email"]').find('label').should('have.class', 'reqd'); - cy.get('.frappe-control[data-fieldname="phone"]').find('label').should('have.class', 'reqd'); + cy.location("pathname").should("eq", "/app/test-data-control/new-test-data-control-1"); + cy.get(".title-text").should("have.text", "New Test Data Control"); + cy.get('.frappe-control[data-fieldname="name1"]') + .find("label") + .should("have.class", "reqd"); + cy.get('.frappe-control[data-fieldname="email"]') + .find("label") + .should("have.class", "reqd"); + cy.get('.frappe-control[data-fieldname="phone"]') + .find("label") + .should("have.class", "reqd"); //Checking if the status is "Not Saved" initially - cy.get('.indicator-pill').should('have.text', 'Not Saved'); + cy.get(".indicator-pill").should("have.text", "Not Saved"); //Inputting data in the field - cy.fill_field('name1', '@@###', 'Data'); - cy.fill_field('email', 'test@example.com', 'Data'); - cy.fill_field('phone', '9834280031', 'Data'); + cy.fill_field("name1", "@@###", "Data"); + cy.fill_field("email", "test@example.com", "Data"); + cy.fill_field("phone", "9834280031", "Data"); //Checking if the border color of the field changes to red - cy.get('.frappe-control[data-fieldname="name1"]').should('have.class', 'has-error'); + cy.get('.frappe-control[data-fieldname="name1"]').should("have.class", "has-error"); cy.save(); //Checking for the error message - cy.get('.modal-title').should('have.text', 'Message'); - cy.get('.msgprint').should('have.text', '@@### is not a valid Name'); + cy.get(".modal-title").should("have.text", "Message"); + cy.get(".msgprint").should("have.text", "@@### is not a valid Name"); cy.hide_dialog(); - cy.get_field('name1', 'Data').clear({force: true}); - cy.fill_field('name1', 'Komal{}/!', 'Data'); - cy.get('.frappe-control[data-fieldname="name1"]').should('have.class', 'has-error'); + cy.get_field("name1", "Data").clear({ force: true }); + cy.fill_field("name1", "Komal{}/!", "Data"); + cy.get('.frappe-control[data-fieldname="name1"]').should("have.class", "has-error"); cy.save(); - cy.get('.modal-title').should('have.text', 'Message'); - cy.get('.msgprint').should('have.text', 'Komal{}/! is not a valid Name'); + cy.get(".modal-title").should("have.text", "Message"); + cy.get(".msgprint").should("have.text", "Komal{}/! is not a valid Name"); cy.hide_dialog(); }); it('Verifying data control by inputting different patterns for "Email" field', () => { - cy.get_field('name1', 'Data').clear({force: true}); - cy.fill_field('name1', 'Komal', 'Data'); - cy.get_field('email', 'Data').clear({force: true}); - cy.fill_field('email', 'komal', 'Data'); - cy.get('.frappe-control[data-fieldname="email"]').should('have.class', 'has-error'); + cy.get_field("name1", "Data").clear({ force: true }); + cy.fill_field("name1", "Komal", "Data"); + cy.get_field("email", "Data").clear({ force: true }); + cy.fill_field("email", "komal", "Data"); + cy.get('.frappe-control[data-fieldname="email"]').should("have.class", "has-error"); cy.save(); - cy.get('.modal-title').should('have.text', 'Message'); - cy.get('.msgprint').should('have.text', 'komal is not a valid Email Address'); + cy.get(".modal-title").should("have.text", "Message"); + cy.get(".msgprint").should("have.text", "komal is not a valid Email Address"); cy.hide_dialog(); - cy.get_field('email', 'Data').clear({force: true}); - cy.fill_field('email', 'komal@test', 'Data'); - cy.get('.frappe-control[data-fieldname="email"]').should('have.class', 'has-error'); + cy.get_field("email", "Data").clear({ force: true }); + cy.fill_field("email", "komal@test", "Data"); + cy.get('.frappe-control[data-fieldname="email"]').should("have.class", "has-error"); cy.save(); - cy.get('.modal-title').should('have.text', 'Message'); - cy.get('.msgprint').should('have.text', 'komal@test is not a valid Email Address'); + cy.get(".modal-title").should("have.text", "Message"); + cy.get(".msgprint").should("have.text", "komal@test is not a valid Email Address"); cy.hide_dialog(); }); it('Verifying data control by inputting different patterns for "Phone" field', () => { - cy.get_field('email', 'Data').clear({force: true}); - cy.fill_field('email', 'komal@test.com', 'Data'); - cy.get_field('phone', 'Data').clear({force: true}); - cy.fill_field('phone', 'komal', 'Data'); - cy.get('.frappe-control[data-fieldname="phone"]').should('have.class', 'has-error'); - cy.findByRole('button', {name: 'Save'}).click({force: true}); - cy.get('.modal-title').should('have.text', 'Message'); - cy.get('.msgprint').should('have.text', 'komal is not a valid Phone Number'); + cy.get_field("email", "Data").clear({ force: true }); + cy.fill_field("email", "komal@test.com", "Data"); + cy.get_field("phone", "Data").clear({ force: true }); + cy.fill_field("phone", "komal", "Data"); + cy.get('.frappe-control[data-fieldname="phone"]').should("have.class", "has-error"); + cy.findByRole("button", { name: "Save" }).click({ force: true }); + cy.get(".modal-title").should("have.text", "Message"); + cy.get(".msgprint").should("have.text", "komal is not a valid Phone Number"); cy.hide_dialog(); }); - it('Inputting correct data and saving the doc', () => { + it("Inputting correct data and saving the doc", () => { //Inputting the data as expected and saving the document - cy.get_field('name1', 'Data').clear({force: true}); - cy.get_field('email', 'Data').clear({force: true}); - cy.get_field('phone', 'Data').clear({force: true}); - cy.fill_field('name1', 'Komal', 'Data'); - cy.fill_field('email', 'komal@test.com', 'Data'); - cy.fill_field('phone', '9432380001', 'Data'); - cy.findByRole('button', {name: 'Save'}).click({force: true}); + cy.get_field("name1", "Data").clear({ force: true }); + cy.get_field("email", "Data").clear({ force: true }); + cy.get_field("phone", "Data").clear({ force: true }); + cy.fill_field("name1", "Komal", "Data"); + cy.fill_field("email", "komal@test.com", "Data"); + cy.fill_field("phone", "9432380001", "Data"); + cy.findByRole("button", { name: "Save" }).click({ force: true }); //Checking if the fields contains the data which has been filled in - cy.location("pathname").should('not.be', '/app/test-data-control/new-test-data-control-1'); - cy.get_field('name1').should('have.value', 'Komal'); - cy.get_field('email').should('have.value', 'komal@test.com'); - cy.get_field('phone').should('have.value', '9432380001'); + cy.location("pathname").should("not.be", "/app/test-data-control/new-test-data-control-1"); + cy.get_field("name1").should("have.value", "Komal"); + cy.get_field("email").should("have.value", "komal@test.com"); + cy.get_field("phone").should("have.value", "9432380001"); }); - it('Deleting the doc', () => { + it("Deleting the doc", () => { //Deleting the inserted document - cy.go_to_list('Test Data Control'); - cy.get('.list-row-checkbox').eq(0).click({force: true}); - cy.get('.actions-btn-group > .btn').contains('Actions').click(); + cy.go_to_list("Test Data Control"); + cy.get(".list-row-checkbox").eq(0).click({ force: true }); + cy.get(".actions-btn-group > .btn").contains("Actions").click(); cy.get('.actions-btn-group > .dropdown-menu [data-label="Delete"]').click(); - cy.click_modal_primary_button('Yes'); + cy.click_modal_primary_button("Yes"); }); }); diff --git a/cypress/integration/control_date.js b/cypress/integration/control_date.js index 6d9f0b9bcc..408f7b819e 100644 --- a/cypress/integration/control_date.js +++ b/cypress/integration/control_date.js @@ -1,82 +1,89 @@ -context('Date Control', () => { +context("Date Control", () => { before(() => { cy.login(); - cy.visit('/app'); + cy.visit("/app"); }); function get_dialog(date_field_options) { return cy.dialog({ - title: 'Date', - fields: [{ - "label": "Date", - "fieldname": "date", - "fieldtype": "Date", - "in_list_view": 1, - ...date_field_options - }] + title: "Date", + fields: [ + { + label: "Date", + fieldname: "date", + fieldtype: "Date", + in_list_view: 1, + ...date_field_options, + }, + ], }); } - it('Selecting a date from the datepicker', () => { + it("Selecting a date from the datepicker", () => { cy.clear_dialogs(); cy.clear_datepickers(); - get_dialog().as('dialog'); - cy.get_field('date', 'Date').click(); - cy.get('.datepicker--nav-title').click(); - cy.get('.datepicker--nav-title').click({force: true}); - + get_dialog().as("dialog"); + cy.get_field("date", "Date").click(); + cy.get(".datepicker--nav-title").click(); + cy.get(".datepicker--nav-title").click({ force: true }); //Inputing values in the date field - cy.get('.datepicker--years > .datepicker--cells > .datepicker--cell[data-year=2020]').click(); - cy.get('.datepicker--months > .datepicker--cells > .datepicker--cell[data-month=0]').click(); - cy.get('.datepicker--days > .datepicker--cells > .datepicker--cell[data-date=15]').click(); + cy.get( + ".datepicker--years > .datepicker--cells > .datepicker--cell[data-year=2020]" + ).click(); + cy.get( + ".datepicker--months > .datepicker--cells > .datepicker--cell[data-month=0]" + ).click(); + cy.get(".datepicker--days > .datepicker--cells > .datepicker--cell[data-date=15]").click(); // Verify if the selected date is set the date field - cy.window().its('cur_dialog.fields_dict.date.value').should('be.equal', '2020-01-15'); + cy.window().its("cur_dialog.fields_dict.date.value").should("be.equal", "2020-01-15"); }); - it('Checking next and previous button', () => { + it("Checking next and previous button", () => { cy.clear_dialogs(); cy.clear_datepickers(); - get_dialog({ default: '2020-01-15' }).as('dialog'); - cy.get_field('date', 'Date').click(); + get_dialog({ default: "2020-01-15" }).as("dialog"); + cy.get_field("date", "Date").click(); //Clicking on the next button in the datepicker - cy.get('.datepicker--nav-action[data-action=next]').click(); + cy.get(".datepicker--nav-action[data-action=next]").click(); //Selecting a date from the datepicker - cy.get('.datepicker--cell[data-date=15]').click({force: true}); + cy.get(".datepicker--cell[data-date=15]").click({ force: true }); //Verifying if the selected date has been displayed in the date field - cy.window().its('cur_dialog.fields_dict.date.value').should('be.equal', '2020-02-15'); + cy.window().its("cur_dialog.fields_dict.date.value").should("be.equal", "2020-02-15"); cy.wait(500); - cy.get_field('date', 'Date').click(); + cy.get_field("date", "Date").click(); //Clicking on the previous button in the datepicker - cy.get('.datepicker--nav-action[data-action=prev]').click(); + cy.get(".datepicker--nav-action[data-action=prev]").click(); //Selecting a date from the datepicker - cy.get('.datepicker--cell[data-date=15]').click({force: true}); + cy.get(".datepicker--cell[data-date=15]").click({ force: true }); //Verifying if the selected date has been displayed in the date field - cy.window().its('cur_dialog.fields_dict.date.value').should('be.equal', '2020-01-15'); + cy.window().its("cur_dialog.fields_dict.date.value").should("be.equal", "2020-01-15"); }); it('Clicking on "Today" button gives todays date', () => { cy.clear_dialogs(); cy.clear_datepickers(); - get_dialog().as('dialog'); - cy.get_field('date', 'Date').click(); + get_dialog().as("dialog"); + cy.get_field("date", "Date").click(); //Clicking on "Today" button - cy.get('.datepicker--button').click(); + cy.get(".datepicker--button").click(); //Verifying if clicking on "Today" button matches today's date - cy.window().then(win => { - expect(win.cur_dialog.fields_dict.date.value).to.be.equal(win.frappe.datetime.get_today()); + cy.window().then((win) => { + expect(win.cur_dialog.fields_dict.date.value).to.be.equal( + win.frappe.datetime.get_today() + ); }); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/control_date_range.js b/cypress/integration/control_date_range.js index 6f26b35f84..f95a3825cc 100644 --- a/cypress/integration/control_date_range.js +++ b/cypress/integration/control_date_range.js @@ -1,42 +1,48 @@ -context('Date Range Control', () => { +context("Date Range Control", () => { before(() => { cy.login(); - cy.visit('/app'); + cy.visit("/app"); }); function get_dialog() { return cy.dialog({ - title: 'Date Range', - fields: [{ - "label": "Date Range", - "fieldname": "date_range", - "fieldtype": "Date Range", - }] + title: "Date Range", + fields: [ + { + label: "Date Range", + fieldname: "date_range", + fieldtype: "Date Range", + }, + ], }); } - it('Selecting a date range from the datepicker', () => { + it("Selecting a date range from the datepicker", () => { cy.clear_dialogs(); cy.clear_datepickers(); - get_dialog().as('dialog'); - cy.get_field('date_range', 'Date Range').click(); - cy.get('.datepicker--nav-title').click(); - cy.get('.datepicker--nav-title').click({force: true}); + get_dialog().as("dialog"); + cy.get_field("date_range", "Date Range").click(); + cy.get(".datepicker--nav-title").click(); + cy.get(".datepicker--nav-title").click({ force: true }); //Inputing date range values in the date range field - cy.get('.datepicker--years > .datepicker--cells > .datepicker--cell[data-year=2020]').click(); - cy.get('.datepicker--months > .datepicker--cells > .datepicker--cell[data-month=0]').click(); - cy.get('.datepicker--cell[data-date=1]:first').click({force: true}); - cy.get('.datepicker--cell[data-date=15]:first').click({force: true}); + cy.get( + ".datepicker--years > .datepicker--cells > .datepicker--cell[data-year=2020]" + ).click(); + cy.get( + ".datepicker--months > .datepicker--cells > .datepicker--cell[data-month=0]" + ).click(); + cy.get(".datepicker--cell[data-date=1]:first").click({ force: true }); + cy.get(".datepicker--cell[data-date=15]:first").click({ force: true }); // Verify if the selected date range values is set in the date range field cy.window() - .its('cur_dialog') - .then(dialog => { + .its("cur_dialog") + .then((dialog) => { let date_range = dialog.get_value("date_range"); - expect(date_range[0]).to.equal('2020-01-01'); - expect(date_range[1]).to.equal('2020-01-15'); + expect(date_range[0]).to.equal("2020-01-01"); + expect(date_range[1]).to.equal("2020-01-15"); }); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/control_duration.js b/cypress/integration/control_duration.js index 09629a344f..a391eec7c1 100644 --- a/cypress/integration/control_duration.js +++ b/cypress/integration/control_duration.js @@ -1,46 +1,46 @@ -context('Control Duration', () => { +context("Control Duration", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); function get_dialog_with_duration(hide_days = 0, hide_seconds = 0) { return cy.dialog({ - title: 'Duration', - fields: [{ - 'fieldname': 'duration', - 'fieldtype': 'Duration', - 'hide_days': hide_days, - 'hide_seconds': hide_seconds - }] + title: "Duration", + fields: [ + { + fieldname: "duration", + fieldtype: "Duration", + hide_days: hide_days, + hide_seconds: hide_seconds, + }, + ], }); } - it('should set duration', () => { - get_dialog_with_duration().as('dialog'); - cy.get('.frappe-control[data-fieldname=duration] input') - .first() - .click(); - cy.get('.duration-input[data-duration=days]') + it("should set duration", () => { + get_dialog_with_duration().as("dialog"); + cy.get(".frappe-control[data-fieldname=duration] input").first().click(); + cy.get(".duration-input[data-duration=days]") .type(45, { force: true }) .blur({ force: true }); - cy.get('.duration-input[data-duration=minutes]') - .type(30) - .blur({ force: true }); - cy.get('.frappe-control[data-fieldname=duration] input').first().should('have.value', '45d 30m'); - cy.get('.frappe-control[data-fieldname=duration] input').first().blur(); - cy.get('.duration-picker').should('not.be.visible'); - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('duration'); + cy.get(".duration-input[data-duration=minutes]").type(30).blur({ force: true }); + cy.get(".frappe-control[data-fieldname=duration] input") + .first() + .should("have.value", "45d 30m"); + cy.get(".frappe-control[data-fieldname=duration] input").first().blur(); + cy.get(".duration-picker").should("not.be.visible"); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("duration"); expect(value).to.equal(3889800); cy.hide_dialog(); }); }); - it('should hide days or seconds according to duration options', () => { - get_dialog_with_duration(1, 1).as('dialog'); - cy.get('.frappe-control[data-fieldname=duration] input').first(); - cy.get('.duration-input[data-duration=days]').should('not.be.visible'); - cy.get('.duration-input[data-duration=seconds]').should('not.be.visible'); + it("should hide days or seconds according to duration options", () => { + get_dialog_with_duration(1, 1).as("dialog"); + cy.get(".frappe-control[data-fieldname=duration] input").first(); + cy.get(".duration-input[data-duration=days]").should("not.be.visible"); + cy.get(".duration-input[data-duration=seconds]").should("not.be.visible"); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/control_dynamic_link.js b/cypress/integration/control_dynamic_link.js index 32b2c274a8..7f34f7ad42 100644 --- a/cypress/integration/control_dynamic_link.js +++ b/cypress/integration/control_dynamic_link.js @@ -1,133 +1,159 @@ -context('Dynamic Link', () => { +context("Dynamic Link", () => { before(() => { cy.login(); - cy.visit('/app/doctype'); - return cy.window().its('frappe').then(frappe => { - return frappe.xcall('frappe.tests.ui_test_helpers.create_doctype', { - name: 'Test Dynamic Link', - fields: [ - { - "label": "Document Type", - "fieldname": "doc_type", - "fieldtype": "Link", - "options": "DocType", - "in_list_view": 1, - "in_standard_filter": 1, - }, - { - "label": "Document ID", - "fieldname": "doc_id", - "fieldtype": "Dynamic Link", - "options": "doc_type", - "in_list_view": 1, - "in_standard_filter": 1, - }, - ] + cy.visit("/app/doctype"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.xcall("frappe.tests.ui_test_helpers.create_doctype", { + name: "Test Dynamic Link", + fields: [ + { + label: "Document Type", + fieldname: "doc_type", + fieldtype: "Link", + options: "DocType", + in_list_view: 1, + in_standard_filter: 1, + }, + { + label: "Document ID", + fieldname: "doc_id", + fieldtype: "Dynamic Link", + options: "doc_type", + in_list_view: 1, + in_standard_filter: 1, + }, + ], + }); }); - }); }); - function get_dialog_with_dynamic_link() { return cy.dialog({ - title: 'Dynamic Link', - fields: [{ - "label": "Document Type", - "fieldname": "doc_type", - "fieldtype": "Link", - "options": "DocType", - "in_list_view": 1, - }, - { - "label": "Document ID", - "fieldname": "doc_id", - "fieldtype": "Dynamic Link", - "options": "doc_type", - "in_list_view": 1, - }] + title: "Dynamic Link", + fields: [ + { + label: "Document Type", + fieldname: "doc_type", + fieldtype: "Link", + options: "DocType", + in_list_view: 1, + }, + { + label: "Document ID", + fieldname: "doc_id", + fieldtype: "Dynamic Link", + options: "doc_type", + in_list_view: 1, + }, + ], }); } function get_dialog_with_dynamic_link_option() { return cy.dialog({ - title: 'Dynamic Link', - fields: [{ - "label": "Document Type", - "fieldname": "doc_type", - "fieldtype": "Link", - "options": "DocType", - "in_list_view": 1, - }, - { - "label": "Document ID", - "fieldname": "doc_id", - "fieldtype": "Dynamic Link", - "get_options": () => { - return "User"; + title: "Dynamic Link", + fields: [ + { + label: "Document Type", + fieldname: "doc_type", + fieldtype: "Link", + options: "DocType", + in_list_view: 1, }, - "in_list_view": 1, - }] + { + label: "Document ID", + fieldname: "doc_id", + fieldtype: "Dynamic Link", + get_options: () => { + return "User"; + }, + in_list_view: 1, + }, + ], }); } - it('Creating a dynamic link by passing option as function and verifying it in a dialog', () => { - get_dialog_with_dynamic_link_option().as('dialog'); - cy.get_field('doc_type').clear(); - cy.fill_field('doc_type', 'User', 'Link'); - cy.get_field('doc_id').click(); + it("Creating a dynamic link by passing option as function and verifying it in a dialog", () => { + get_dialog_with_dynamic_link_option().as("dialog"); + cy.get_field("doc_type").clear(); + cy.fill_field("doc_type", "User", "Link"); + cy.get_field("doc_id").click(); //Checking if the listbox have length greater than 0 - cy.get('[data-fieldname="doc_id"]').find('.awesomplete').find("li").its('length').should('be.gte', 0); - cy.get('.btn-modal-close').click({force: true}); + cy.get('[data-fieldname="doc_id"]') + .find(".awesomplete") + .find("li") + .its("length") + .should("be.gte", 0); + cy.get(".btn-modal-close").click({ force: true }); }); - it('Creating a dynamic link and verifying it in a dialog', () => { - get_dialog_with_dynamic_link().as('dialog'); - cy.get_field('doc_type').clear(); - cy.fill_field('doc_type', 'User', 'Link'); - cy.get_field('doc_id').click(); + it("Creating a dynamic link and verifying it in a dialog", () => { + get_dialog_with_dynamic_link().as("dialog"); + cy.get_field("doc_type").clear(); + cy.fill_field("doc_type", "User", "Link"); + cy.get_field("doc_id").click(); //Checking if the listbox have length greater than 0 - cy.get('[data-fieldname="doc_id"]').find('.awesomplete').find("li").its('length').should('be.gte', 0); - cy.get('.btn-modal-close').click({force: true, multiple: true}); + cy.get('[data-fieldname="doc_id"]') + .find(".awesomplete") + .find("li") + .its("length") + .should("be.gte", 0); + cy.get(".btn-modal-close").click({ force: true, multiple: true }); }); - it('Creating a dynamic link and verifying it', () => { - cy.visit('/app/test-dynamic-link'); + it("Creating a dynamic link and verifying it", () => { + cy.visit("/app/test-dynamic-link"); //Clicking on the Document ID field - cy.get_field('doc_type').clear(); + cy.get_field("doc_type").clear(); //Entering User in the Doctype field - cy.fill_field('doc_type', 'User', 'Link', {delay: 500}); - cy.get_field('doc_id').click(); + cy.fill_field("doc_type", "User", "Link", { delay: 500 }); + cy.get_field("doc_id").click(); //Checking if the listbox have length greater than 0 - cy.get('[data-fieldname="doc_id"]').find('.awesomplete').find("li").its('length').should('be.gte', 0); + cy.get('[data-fieldname="doc_id"]') + .find(".awesomplete") + .find("li") + .its("length") + .should("be.gte", 0); //Opening a new form for dynamic link doctype - cy.new_form('Test Dynamic Link'); - cy.get_field('doc_type').clear(); + cy.new_form("Test Dynamic Link"); + cy.get_field("doc_type").clear(); //Entering User in the Doctype field - cy.fill_field('doc_type', 'User', 'Link', {delay: 500}); - cy.get_field('doc_id').click(); + cy.fill_field("doc_type", "User", "Link", { delay: 500 }); + cy.get_field("doc_id").click(); //Checking if the listbox have length greater than 0 - cy.get('[data-fieldname="doc_id"]').find('.awesomplete').find("li").its('length').should('be.gte', 0); - cy.get_field('doc_type').clear(); + cy.get('[data-fieldname="doc_id"]') + .find(".awesomplete") + .find("li") + .its("length") + .should("be.gte", 0); + cy.get_field("doc_type").clear(); //Entering System Settings in the Doctype field - cy.intercept('/api/method/frappe.desk.search.search_link').as('search_query'); - cy.fill_field('doc_type', 'System Settings', 'Link', {delay: 500}); - cy.wait('@search_query'); - cy.get(`[data-fieldname="doc_type"] ul:visible li:first-child`) - .click({scrollBehavior: false}); + cy.intercept("/api/method/frappe.desk.search.search_link").as("search_query"); + cy.fill_field("doc_type", "System Settings", "Link", { delay: 500 }); + cy.wait("@search_query"); + cy.get(`[data-fieldname="doc_type"] ul:visible li:first-child`).click({ + scrollBehavior: false, + }); - cy.get_field('doc_id').click(); + cy.get_field("doc_id").click(); //Checking if the system throws error - cy.get('.modal-title').should('have.text', 'Error'); - cy.get('.msgprint').should('have.text', 'System Settings is not a valid DocType for Dynamic Link'); + cy.get(".modal-title").should("have.text", "Error"); + cy.get(".msgprint").should( + "have.text", + "System Settings is not a valid DocType for Dynamic Link" + ); }); }); diff --git a/cypress/integration/control_float.js b/cypress/integration/control_float.js index 670d1fe73e..c8261ad043 100644 --- a/cypress/integration/control_float.js +++ b/cypress/integration/control_float.js @@ -11,9 +11,9 @@ context("Control Float", () => { { fieldname: "float_number", fieldtype: "Float", - Label: "Float" - } - ] + Label: "Float", + }, + ], }); } @@ -21,27 +21,21 @@ context("Control Float", () => { get_dialog_with_float().as("dialog"); let data = get_data(); - data.forEach(x => { + data.forEach((x) => { cy.window() .its("frappe") - .then(frappe => { + .then((frappe) => { frappe.boot.sysdefaults.number_format = x.number_format; }); - x.values.forEach(d => { + x.values.forEach((d) => { cy.get_field("float_number", "Float").clear(); cy.fill_field("float_number", d.input, "Float").blur(); - cy.get_field("float_number", "Float").should( - "have.value", - d.blur_expected - ); + cy.get_field("float_number", "Float").should("have.value", d.blur_expected); cy.get_field("float_number", "Float").focus(); cy.get_field("float_number", "Float").blur(); cy.get_field("float_number", "Float").focus(); - cy.get_field("float_number", "Float").should( - "have.value", - d.focus_expected - ); + cy.get_field("float_number", "Float").should("have.value", d.focus_expected); }); }); }); @@ -54,19 +48,19 @@ context("Control Float", () => { { input: "364.87,334", blur_expected: "36.487,334", - focus_expected: "36487.334" + focus_expected: "36487.334", }, { input: "36487,334", blur_expected: "36.487,334", - focus_expected: "36487.334" + focus_expected: "36487.334", }, { input: "100", blur_expected: "100,000", - focus_expected: "100" - } - ] + focus_expected: "100", + }, + ], }, { number_format: "#,###.##", @@ -74,20 +68,20 @@ context("Control Float", () => { { input: "364,87.334", blur_expected: "36,487.334", - focus_expected: "36487.334" + focus_expected: "36487.334", }, { input: "36487.334", blur_expected: "36,487.334", - focus_expected: "36487.334" + focus_expected: "36487.334", }, { input: "100", blur_expected: "100.000", - focus_expected: "100" - } - ] - } + focus_expected: "100", + }, + ], + }, ]; } }); diff --git a/cypress/integration/control_icon.js b/cypress/integration/control_icon.js index d89eba8840..a965ed0f9e 100644 --- a/cypress/integration/control_icon.js +++ b/cypress/integration/control_icon.js @@ -1,50 +1,55 @@ -context('Control Icon', () => { +context("Control Icon", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); function get_dialog_with_icon() { return cy.dialog({ - title: 'Icon', - fields: [{ - label: 'Icon', - fieldname: 'icon', - fieldtype: 'Icon' - }] + title: "Icon", + fields: [ + { + label: "Icon", + fieldname: "icon", + fieldtype: "Icon", + }, + ], }); } - it('should set icon', () => { - get_dialog_with_icon().as('dialog'); - cy.get('.frappe-control[data-fieldname=icon]').findByRole('textbox').click(); + it("should set icon", () => { + get_dialog_with_icon().as("dialog"); + cy.get(".frappe-control[data-fieldname=icon]").findByRole("textbox").click(); - cy.get('.icon-picker .icon-wrapper[id=heart-active]').first().click(); - cy.get('.frappe-control[data-fieldname=icon]').findByRole('textbox').should('have.value', 'heart-active'); - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('icon'); - expect(value).to.equal('heart-active'); + cy.get(".icon-picker .icon-wrapper[id=heart-active]").first().click(); + cy.get(".frappe-control[data-fieldname=icon]") + .findByRole("textbox") + .should("have.value", "heart-active"); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("icon"); + expect(value).to.equal("heart-active"); }); - cy.get('.icon-picker .icon-wrapper[id=heart]').first().click(); - cy.get('.frappe-control[data-fieldname=icon]').findByRole('textbox').should('have.value', 'heart'); - cy.get('@dialog').then(dialog => { - let value = dialog.get_value('icon'); - expect(value).to.equal('heart'); + cy.get(".icon-picker .icon-wrapper[id=heart]").first().click(); + cy.get(".frappe-control[data-fieldname=icon]") + .findByRole("textbox") + .should("have.value", "heart"); + cy.get("@dialog").then((dialog) => { + let value = dialog.get_value("icon"); + expect(value).to.equal("heart"); }); }); - it('search for icon and clear search input', () => { - let search_text = 'ed'; - cy.get('.icon-picker').findByRole('searchbox').click().type(search_text); - cy.get('.icon-section .icon-wrapper:not(.hidden)').then(i => { - cy.get(`.icon-section .icon-wrapper[id*='${search_text}']`).then(icons => { + it("search for icon and clear search input", () => { + let search_text = "ed"; + cy.get(".icon-picker").findByRole("searchbox").click().type(search_text); + cy.get(".icon-section .icon-wrapper:not(.hidden)").then((i) => { + cy.get(`.icon-section .icon-wrapper[id*='${search_text}']`).then((icons) => { expect(i.length).to.equal(icons.length); }); }); - cy.get('.icon-picker').findByRole('searchbox').clear().blur(); - cy.get('.icon-section .icon-wrapper').should('not.have.class', 'hidden'); + cy.get(".icon-picker").findByRole("searchbox").clear().blur(); + cy.get(".icon-section .icon-wrapper").should("not.have.class", "hidden"); }); - -}); \ No newline at end of file +}); diff --git a/cypress/integration/control_link.js b/cypress/integration/control_link.js index 44153f7e4a..b34414e5ca 100644 --- a/cypress/integration/control_link.js +++ b/cypress/integration/control_link.js @@ -1,93 +1,101 @@ -context('Control Link', () => { +context("Control Link", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); beforeEach(() => { - cy.visit('/app/website'); + cy.visit("/app/website"); cy.create_records({ - doctype: 'ToDo', - description: 'this is a test todo for link' - }).as('todos'); + doctype: "ToDo", + description: "this is a test todo for link", + }).as("todos"); }); function get_dialog_with_link() { return cy.dialog({ - title: 'Link', + title: "Link", fields: [ { - 'label': 'Select ToDo', - 'fieldname': 'link', - 'fieldtype': 'Link', - 'options': 'ToDo', - } - ] + label: "Select ToDo", + fieldname: "link", + fieldtype: "Link", + options: "ToDo", + }, + ], }); } function get_dialog_with_user_link() { return cy.dialog({ - title: 'Link', + title: "Link", fields: [ { - 'label': 'Select User', - 'fieldname': 'link', - 'fieldtype': 'Link', - 'options': 'User', - } - ] + label: "Select User", + fieldname: "link", + fieldtype: "Link", + options: "User", + }, + ], }); } - it('should set the valid value', () => { - get_dialog_with_link().as('dialog'); + it("should set the valid value", () => { + get_dialog_with_link().as("dialog"); - cy.insert_doc("Property Setter", { - "doctype": "Property Setter", - "doc_type": "User", - "property": "translate_link_fields", - "property_type": "Check", - "doctype_or_field": "DocType", - "value": "0" - }, true); + cy.insert_doc( + "Property Setter", + { + doctype: "Property Setter", + doc_type: "User", + property: "translate_link_fields", + property_type: "Check", + doctype_or_field: "DocType", + value: "0", + }, + true + ); - cy.insert_doc("Property Setter", { - "doctype": "Property Setter", - "doc_type": "ToDo", - "property": "show_title_field_in_link", - "property_type": "Check", - "doctype_or_field": "DocType", - "value": "0" - }, true); + cy.insert_doc( + "Property Setter", + { + doctype: "Property Setter", + doc_type: "ToDo", + property: "show_title_field_in_link", + property_type: "Check", + doctype_or_field: "DocType", + value: "0", + }, + true + ); - cy.intercept('POST', '/api/method/frappe.desk.search.search_link').as('search_link'); + cy.intercept("POST", "/api/method/frappe.desk.search.search_link").as("search_link"); - cy.get('.frappe-control[data-fieldname=link] input').focus().as('input'); - cy.wait('@search_link'); - cy.get('@input').type('todo for link', { delay: 200 }); - cy.wait('@search_link'); - cy.get('.frappe-control[data-fieldname=link]').findByRole('listbox').should('be.visible'); - cy.get('.frappe-control[data-fieldname=link] input').type('{enter}', { delay: 100 }); - cy.get('.frappe-control[data-fieldname=link] input').blur(); - cy.get('@dialog').then(dialog => { - cy.get('@todos').then(todos => { - let value = dialog.get_value('link'); + cy.get(".frappe-control[data-fieldname=link] input").focus().as("input"); + cy.wait("@search_link"); + cy.get("@input").type("todo for link", { delay: 200 }); + cy.wait("@search_link"); + cy.get(".frappe-control[data-fieldname=link]").findByRole("listbox").should("be.visible"); + cy.get(".frappe-control[data-fieldname=link] input").type("{enter}", { delay: 100 }); + cy.get(".frappe-control[data-fieldname=link] input").blur(); + cy.get("@dialog").then((dialog) => { + cy.get("@todos").then((todos) => { + let value = dialog.get_value("link"); expect(value).to.eq(todos[0]); }); }); }); - it('should unset invalid value', () => { - get_dialog_with_link().as('dialog'); + it("should unset invalid value", () => { + get_dialog_with_link().as("dialog"); - cy.intercept('POST', '/api/method/frappe.client.validate_link').as('validate_link'); + cy.intercept("POST", "/api/method/frappe.client.validate_link").as("validate_link"); - cy.get('.frappe-control[data-fieldname=link] input') - .type('invalid value', { delay: 100 }) + cy.get(".frappe-control[data-fieldname=link] input") + .type("invalid value", { delay: 100 }) .blur(); - cy.wait('@validate_link'); - cy.get('.frappe-control[data-fieldname=link] input').should('have.value', ''); + cy.wait("@validate_link"); + cy.get(".frappe-control[data-fieldname=link] input").should("have.value", ""); }); it("should be possible set empty value explicitly", () => { @@ -95,295 +103,325 @@ context('Control Link', () => { cy.intercept("POST", "/api/method/frappe.client.validate_link").as("validate_link"); - cy.get(".frappe-control[data-fieldname=link] input") - .type(" ", { delay: 100 }) - .blur(); + cy.get(".frappe-control[data-fieldname=link] input").type(" ", { delay: 100 }).blur(); cy.wait("@validate_link"); cy.get(".frappe-control[data-fieldname=link] input").should("have.value", ""); cy.window() .its("cur_dialog") .then((dialog) => { - expect(dialog.get_value("link")).to.equal(''); + expect(dialog.get_value("link")).to.equal(""); }); }); - it('should route to form on arrow click', () => { - get_dialog_with_link().as('dialog'); + it("should route to form on arrow click", () => { + get_dialog_with_link().as("dialog"); - cy.intercept('POST', '/api/method/frappe.client.validate_link').as('validate_link'); - cy.intercept('POST', '/api/method/frappe.desk.search.search_link').as('search_link'); + cy.intercept("POST", "/api/method/frappe.client.validate_link").as("validate_link"); + cy.intercept("POST", "/api/method/frappe.desk.search.search_link").as("search_link"); - cy.get('@todos').then(todos => { - cy.get('.frappe-control[data-fieldname=link] input').as('input'); - cy.get('@input').focus(); - cy.wait('@search_link'); - cy.get('@input').type(todos[0]).blur(); - cy.wait('@validate_link'); - cy.get('@input').focus(); + cy.get("@todos").then((todos) => { + cy.get(".frappe-control[data-fieldname=link] input").as("input"); + cy.get("@input").focus(); + cy.wait("@search_link"); + cy.get("@input").type(todos[0]).blur(); + cy.wait("@validate_link"); + cy.get("@input").focus(); cy.wait(500); // wait for arrow to show - cy.get('.frappe-control[data-fieldname=link] .btn-open') - .should('be.visible') - .click(); - cy.location('pathname').should('eq', `/app/todo/${todos[0]}`); + cy.get(".frappe-control[data-fieldname=link] .btn-open").should("be.visible").click(); + cy.location("pathname").should("eq", `/app/todo/${todos[0]}`); }); }); - it('show title field in link', () => { + it("show title field in link", () => { + cy.insert_doc( + "Property Setter", + { + doctype: "Property Setter", + doc_type: "User", + property: "translate_link_fields", + property_type: "Check", + doctype_or_field: "DocType", + value: "0", + }, + true + ); - cy.insert_doc("Property Setter", { - "doctype": "Property Setter", - "doc_type": "User", - "property": "translate_link_fields", - "property_type": "Check", - "doctype_or_field": "DocType", - "value": "0" - }, true); - - cy.insert_doc("Property Setter", { - "doctype": "Property Setter", - "doc_type": "ToDo", - "property": "show_title_field_in_link", - "property_type": "Check", - "doctype_or_field": "DocType", - "value": "1" - }, true); + cy.insert_doc( + "Property Setter", + { + doctype: "Property Setter", + doc_type: "ToDo", + property: "show_title_field_in_link", + property_type: "Check", + doctype_or_field: "DocType", + value: "1", + }, + true + ); cy.clear_cache(); cy.wait(500); - get_dialog_with_link().as('dialog'); - cy.window().its('frappe').then(frappe => { - if (!frappe.boot) { - frappe.boot = { - link_title_doctypes: ['ToDo'] - }; - } else { - frappe.boot.link_title_doctypes = ['ToDo']; - } - }); + get_dialog_with_link().as("dialog"); + cy.window() + .its("frappe") + .then((frappe) => { + if (!frappe.boot) { + frappe.boot = { + link_title_doctypes: ["ToDo"], + }; + } else { + frappe.boot.link_title_doctypes = ["ToDo"]; + } + }); - cy.intercept('POST', '/api/method/frappe.desk.search.search_link').as('search_link'); + cy.intercept("POST", "/api/method/frappe.desk.search.search_link").as("search_link"); - cy.get('.frappe-control[data-fieldname=link] input').focus().as('input'); - cy.wait('@search_link'); - cy.get('@input').type('todo for link'); - cy.wait('@search_link'); - cy.get('.frappe-control[data-fieldname=link] ul').should('be.visible'); - cy.get('.frappe-control[data-fieldname=link] input').type('{enter}', { delay: 100 }); - cy.get('.frappe-control[data-fieldname=link] input').blur(); - cy.get('@dialog').then(dialog => { - cy.get('@todos').then(todos => { - let field = dialog.get_field('link'); + cy.get(".frappe-control[data-fieldname=link] input").focus().as("input"); + cy.wait("@search_link"); + cy.get("@input").type("todo for link"); + cy.wait("@search_link"); + cy.get(".frappe-control[data-fieldname=link] ul").should("be.visible"); + cy.get(".frappe-control[data-fieldname=link] input").type("{enter}", { delay: 100 }); + cy.get(".frappe-control[data-fieldname=link] input").blur(); + cy.get("@dialog").then((dialog) => { + cy.get("@todos").then((todos) => { + let field = dialog.get_field("link"); let value = field.get_value(); let label = field.get_label_value(); expect(value).to.eq(todos[0]); - expect(label).to.eq('this is a test todo for link'); + expect(label).to.eq("this is a test todo for link"); }); }); }); - it('should update dependant fields (via fetch_from)', () => { - cy.get('@todos').then(todos => { + it("should update dependant fields (via fetch_from)", () => { + cy.get("@todos").then((todos) => { cy.visit(`/app/todo/${todos[0]}`); - cy.intercept('POST', '/api/method/frappe.desk.search.search_link').as('search_link'); - cy.intercept('POST', '/api/method/frappe.client.validate_link').as('validate_link'); + cy.intercept("POST", "/api/method/frappe.desk.search.search_link").as("search_link"); + cy.intercept("POST", "/api/method/frappe.client.validate_link").as("validate_link"); - cy.get('.frappe-control[data-fieldname=assigned_by] input').focus().as('input'); - cy.get('@input').type('Administrator', {delay: 100}).blur(); - cy.wait('@validate_link'); - cy.get('.frappe-control[data-fieldname=assigned_by_full_name] .control-value').should( - 'contain', 'Administrator' + cy.get(".frappe-control[data-fieldname=assigned_by] input").focus().as("input"); + cy.get("@input").type("Administrator", { delay: 100 }).blur(); + cy.wait("@validate_link"); + cy.get(".frappe-control[data-fieldname=assigned_by_full_name] .control-value").should( + "contain", + "Administrator" ); - cy.window() - .its("cur_frm.doc.assigned_by") - .should("eq", "Administrator"); + cy.window().its("cur_frm.doc.assigned_by").should("eq", "Administrator"); // invalid input - cy.get('@input').clear().type('invalid input', {delay: 100}).blur(); - cy.get('.frappe-control[data-fieldname=assigned_by_full_name] .control-value').should( - 'contain', '' + cy.get("@input").clear().type("invalid input", { delay: 100 }).blur(); + cy.get(".frappe-control[data-fieldname=assigned_by_full_name] .control-value").should( + "contain", + "" ); - cy.window() - .its("cur_frm.doc.assigned_by") - .should("eq", null); + cy.window().its("cur_frm.doc.assigned_by").should("eq", null); // set valid value again - cy.get('@input').clear().focus(); - cy.wait('@search_link'); - cy.get('@input').type('Administrator', {delay: 100}).blur(); - cy.wait('@validate_link'); + cy.get("@input").clear().focus(); + cy.wait("@search_link"); + cy.get("@input").type("Administrator", { delay: 100 }).blur(); + cy.wait("@validate_link"); - cy.window() - .its("cur_frm.doc.assigned_by") - .should("eq", "Administrator"); + cy.window().its("cur_frm.doc.assigned_by").should("eq", "Administrator"); // clear input - cy.get('@input').clear().blur(); - cy.get('.frappe-control[data-fieldname=assigned_by_full_name] .control-value').should( - 'contain', '' + cy.get("@input").clear().blur(); + cy.get(".frappe-control[data-fieldname=assigned_by_full_name] .control-value").should( + "contain", + "" ); - cy.window() - .its("cur_frm.doc.assigned_by") - .should("eq", ""); + cy.window().its("cur_frm.doc.assigned_by").should("eq", ""); }); }); it("should set default values", () => { - cy.insert_doc("Property Setter", { - "doctype_or_field": "DocField", - "doc_type": "ToDo", - "field_name": "assigned_by", - "property": "default", - "property_type": "Text", - "value": "Administrator" - }, true); + cy.insert_doc( + "Property Setter", + { + doctype_or_field: "DocField", + doc_type: "ToDo", + field_name: "assigned_by", + property: "default", + property_type: "Text", + value: "Administrator", + }, + true + ); cy.reload(); cy.new_form("ToDo"); cy.fill_field("description", "new", "Text Editor"); cy.intercept("POST", "/api/method/frappe.desk.form.save.savedocs").as("save_form"); - cy.findByRole("button", {name: "Save"}).click(); + cy.findByRole("button", { name: "Save" }).click(); cy.wait("@save_form"); cy.get(".frappe-control[data-fieldname=assigned_by_full_name] .control-value").should( - "contain", "Administrator" + "contain", + "Administrator" ); // if user clears default value explicitly, system should not reset default again cy.get_field("assigned_by").clear().blur(); cy.intercept("POST", "/api/method/frappe.desk.form.save.savedocs").as("save_form"); - cy.findByRole("button", {name: "Save"}).click(); + cy.findByRole("button", { name: "Save" }).click(); cy.wait("@save_form"); cy.get_field("assigned_by").should("have.value", ""); cy.get(".frappe-control[data-fieldname=assigned_by_full_name] .control-value").should( - "contain", "" + "contain", + "" ); }); - it('show translated text for link with show_title_field_in_link enabled', () => { - cy.insert_doc("Property Setter", { - "doctype": "Property Setter", - "doc_type": "ToDo", - "property": "translate_link_fields", - "property_type": "Check", - "doctype_or_field": "DocType", - "value": "1" - }, true); + it("show translated text for link with show_title_field_in_link enabled", () => { + cy.insert_doc( + "Property Setter", + { + doctype: "Property Setter", + doc_type: "ToDo", + property: "translate_link_fields", + property_type: "Check", + doctype_or_field: "DocType", + value: "1", + }, + true + ); - cy.insert_doc("Property Setter", { - "doctype": "Property Setter", - "doc_type": "ToDo", - "property": "show_title_field_in_link", - "property_type": "Check", - "doctype_or_field": "DocType", - "value": "1" - }, true); + cy.insert_doc( + "Property Setter", + { + doctype: "Property Setter", + doc_type: "ToDo", + property: "show_title_field_in_link", + property_type: "Check", + doctype_or_field: "DocType", + value: "1", + }, + true + ); - cy.window().its('frappe').then(frappe => { - cy.insert_doc("Translation", { - doctype: "Translation", - language: frappe.boot.lang, - source_text: "this is a test todo for link", - translated_text: "this is a translated test todo for link", + cy.window() + .its("frappe") + .then((frappe) => { + cy.insert_doc("Translation", { + doctype: "Translation", + language: frappe.boot.lang, + source_text: "this is a test todo for link", + translated_text: "this is a translated test todo for link", + }); }); - }); cy.clear_cache(); cy.wait(500); - cy.window().its('frappe').then(frappe => { - if (!frappe.boot) { - frappe.boot = { - link_title_doctypes: ['ToDo'], - translatable_doctypes: ['ToDo'] - }; - } else { - frappe.boot.link_title_doctypes = ['ToDo']; - frappe.boot.translatable_doctypes = ['ToDo']; - } - }); + cy.window() + .its("frappe") + .then((frappe) => { + if (!frappe.boot) { + frappe.boot = { + link_title_doctypes: ["ToDo"], + translatable_doctypes: ["ToDo"], + }; + } else { + frappe.boot.link_title_doctypes = ["ToDo"]; + frappe.boot.translatable_doctypes = ["ToDo"]; + } + }); - get_dialog_with_link().as('dialog'); - cy.intercept('POST', '/api/method/frappe.desk.search.search_link').as('search_link'); + get_dialog_with_link().as("dialog"); + cy.intercept("POST", "/api/method/frappe.desk.search.search_link").as("search_link"); - cy.get('.frappe-control[data-fieldname=link] input').focus().as('input'); - cy.wait('@search_link'); - cy.get('@input').type('todo for link', { delay: 100 }); - cy.wait('@search_link'); - cy.get('.frappe-control[data-fieldname=link] ul').should('be.visible'); - cy.get('.frappe-control[data-fieldname=link] input').type('{enter}', { delay: 100 }); - cy.get('.frappe-control[data-fieldname=link] input').blur(); - cy.get('@dialog').then(dialog => { - cy.get('@todos').then(todos => { - let field = dialog.get_field('link'); + cy.get(".frappe-control[data-fieldname=link] input").focus().as("input"); + cy.wait("@search_link"); + cy.get("@input").type("todo for link", { delay: 100 }); + cy.wait("@search_link"); + cy.get(".frappe-control[data-fieldname=link] ul").should("be.visible"); + cy.get(".frappe-control[data-fieldname=link] input").type("{enter}", { delay: 100 }); + cy.get(".frappe-control[data-fieldname=link] input").blur(); + cy.get("@dialog").then((dialog) => { + cy.get("@todos").then((todos) => { + let field = dialog.get_field("link"); let value = field.get_value(); let label = field.get_label_value(); expect(value).to.eq(todos[0]); - expect(label).to.eq('this is a translated test todo for link'); + expect(label).to.eq("this is a translated test todo for link"); }); }); }); - it('show translated text for link with show_title_field_in_link disabled', () => { - cy.insert_doc("Property Setter", { - "doctype": "Property Setter", - "doc_type": "User", - "property": "translate_link_fields", - "property_type": "Check", - "doctype_or_field": "DocType", - "value": "1" - }, true); + it("show translated text for link with show_title_field_in_link disabled", () => { + cy.insert_doc( + "Property Setter", + { + doctype: "Property Setter", + doc_type: "User", + property: "translate_link_fields", + property_type: "Check", + doctype_or_field: "DocType", + value: "1", + }, + true + ); - cy.insert_doc("Property Setter", { - "doctype": "Property Setter", - "doc_type": "ToDo", - "property": "show_title_field_in_link", - "property_type": "Check", - "doctype_or_field": "DocType", - "value": "0" - }, true); + cy.insert_doc( + "Property Setter", + { + doctype: "Property Setter", + doc_type: "ToDo", + property: "show_title_field_in_link", + property_type: "Check", + doctype_or_field: "DocType", + value: "0", + }, + true + ); - cy.window().its('frappe').then(frappe => { - cy.insert_doc("Translation", { - doctype: "Translation", - language: frappe.boot.lang, - source_text: "test@erpnext.com", - translated_text: "translatedtest@erpnext.com", + cy.window() + .its("frappe") + .then((frappe) => { + cy.insert_doc("Translation", { + doctype: "Translation", + language: frappe.boot.lang, + source_text: "test@erpnext.com", + translated_text: "translatedtest@erpnext.com", + }); }); - }); cy.clear_cache(); cy.wait(500); - cy.window().its('frappe').then(frappe => { - if (!frappe.boot) { - frappe.boot = { - translatable_doctypes: ['User'] - }; - } else { - frappe.boot.translatable_doctypes = ['User']; - } - }); + cy.window() + .its("frappe") + .then((frappe) => { + if (!frappe.boot) { + frappe.boot = { + translatable_doctypes: ["User"], + }; + } else { + frappe.boot.translatable_doctypes = ["User"]; + } + }); - get_dialog_with_user_link().as('dialog'); - cy.intercept('POST', '/api/method/frappe.desk.search.search_link').as('search_link'); + get_dialog_with_user_link().as("dialog"); + cy.intercept("POST", "/api/method/frappe.desk.search.search_link").as("search_link"); - cy.get('.frappe-control[data-fieldname=link] input').focus().as('input'); - cy.wait('@search_link'); - cy.get('@input').type('test@erpnext.com', { delay: 100 }); - cy.wait('@search_link'); - cy.get('.frappe-control[data-fieldname=link] ul').should('be.visible'); - cy.get('.frappe-control[data-fieldname=link] input').type('{enter}', { delay: 100 }); - cy.get('.frappe-control[data-fieldname=link] input').blur(); - cy.get('@dialog').then(dialog => { - let field = dialog.get_field('link'); + cy.get(".frappe-control[data-fieldname=link] input").focus().as("input"); + cy.wait("@search_link"); + cy.get("@input").type("test@erpnext.com", { delay: 100 }); + cy.wait("@search_link"); + cy.get(".frappe-control[data-fieldname=link] ul").should("be.visible"); + cy.get(".frappe-control[data-fieldname=link] input").type("{enter}", { delay: 100 }); + cy.get(".frappe-control[data-fieldname=link] input").blur(); + cy.get("@dialog").then((dialog) => { + let field = dialog.get_field("link"); let value = field.get_value(); let label = field.get_label_value(); - expect(value).to.eq('test@erpnext.com'); - expect(label).to.eq('translatedtest@erpnext.com'); + expect(value).to.eq("test@erpnext.com"); + expect(label).to.eq("translatedtest@erpnext.com"); }); }); }); diff --git a/cypress/integration/control_markdown_editor.js b/cypress/integration/control_markdown_editor.js index 34f94f13bf..16c3dac51f 100644 --- a/cypress/integration/control_markdown_editor.js +++ b/cypress/integration/control_markdown_editor.js @@ -7,12 +7,9 @@ context("Control Markdown Editor", () => { it("should allow inserting images by drag and drop", () => { cy.visit("/app/web-page/new"); cy.fill_field("content_type", "Markdown", "Select"); - cy.get_field("main_section_md", "Markdown Editor").attachFile( - "sample_image.jpg", - { - subjectType: "drag-n-drop" - } - ); + cy.get_field("main_section_md", "Markdown Editor").attachFile("sample_image.jpg", { + subjectType: "drag-n-drop", + }); cy.click_modal_primary_button("Upload"); cy.get_field("main_section_md", "Markdown Editor").should( "contain", diff --git a/cypress/integration/control_phone.js b/cypress/integration/control_phone.js index 5a26decdee..b56343c2d8 100644 --- a/cypress/integration/control_phone.js +++ b/cypress/integration/control_phone.js @@ -1,4 +1,4 @@ -import doctype_with_phone from '../fixtures/doctype_with_phone'; +import doctype_with_phone from "../fixtures/doctype_with_phone"; context("Control Phone", () => { before(() => { @@ -9,10 +9,12 @@ context("Control Phone", () => { function get_dialog_with_phone() { return cy.dialog({ title: "Phone", - fields: [{ - "fieldname": "phone", - "fieldtype": "Phone", - }] + fields: [ + { + fieldname: "phone", + fieldtype: "Phone", + }, + ], }); } @@ -27,18 +29,16 @@ context("Control Phone", () => { let phone_number = "9312672712"; cy.get(".selected-phone > img").click().first(); - cy.get_field("phone") - .first() - .click({multiple: true}); + cy.get_field("phone").first().click({ multiple: true }); cy.get(".frappe-control[data-fieldname=phone]") .findByRole("textbox") .first() - .type(phone_number, {force: true}); + .type(phone_number, { force: true }); cy.get_field("phone").first().should("have.value", phone_number); - cy.get_field("phone").first().blur({force: true}); + cy.get_field("phone").first().blur({ force: true }); cy.wait(100); - cy.get("@dialog").then(dialog => { + cy.get("@dialog").then((dialog) => { let value = dialog.get_value("phone"); expect(value).to.equal("+91-" + phone_number); }); @@ -48,10 +48,12 @@ context("Control Phone", () => { let search_text = "india"; cy.get(".selected-phone").click().first(); cy.get(".phone-picker").findByRole("searchbox").click().type(search_text); - cy.get(".phone-section .phone-wrapper:not(.hidden)").then(i => { - cy.get(`.phone-section .phone-wrapper[id*="${search_text.toLowerCase()}"]`).then(countries => { - expect(i.length).to.equal(countries.length); - }); + cy.get(".phone-section .phone-wrapper:not(.hidden)").then((i) => { + cy.get(`.phone-section .phone-wrapper[id*="${search_text.toLowerCase()}"]`).then( + (countries) => { + expect(i.length).to.equal(countries.length); + } + ); }); cy.get(".phone-picker").findByRole("searchbox").clear().blur(); diff --git a/cypress/integration/control_rating.js b/cypress/integration/control_rating.js index 15c11b352b..613a6e9f92 100644 --- a/cypress/integration/control_rating.js +++ b/cypress/integration/control_rating.js @@ -1,56 +1,54 @@ -context('Control Rating', () => { +context("Control Rating", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); function get_dialog_with_rating() { return cy.dialog({ - title: 'Rating', - fields: [{ - 'fieldname': 'rate', - 'fieldtype': 'Rating', - 'options': 7 - }] + title: "Rating", + fields: [ + { + fieldname: "rate", + fieldtype: "Rating", + options: 7, + }, + ], }); } - it('click on the star rating to record value', () => { - get_dialog_with_rating().as('dialog'); + it("click on the star rating to record value", () => { + get_dialog_with_rating().as("dialog"); - cy.get('div.rating') - .children('svg') - .find('.right-half') + cy.get("div.rating") + .children("svg") + .find(".right-half") .first() .click() - .should('have.class', 'star-click'); - cy.get('@dialog').then(dialog => { - var value = dialog.get_value('rate'); - expect(value).to.equal(1/7); + .should("have.class", "star-click"); + cy.get("@dialog").then((dialog) => { + var value = dialog.get_value("rate"); + expect(value).to.equal(1 / 7); dialog.hide(); }); }); - it('hover on the star', () => { + it("hover on the star", () => { get_dialog_with_rating(); - cy.get('div.rating') - .children('svg') - .find('.right-half') + cy.get("div.rating") + .children("svg") + .find(".right-half") .first() - .invoke('trigger', 'mouseenter') - .should('have.class', 'star-hover') - .invoke('trigger', 'mouseleave') - .should('not.have.class', 'star-hover'); + .invoke("trigger", "mouseenter") + .should("have.class", "star-hover") + .invoke("trigger", "mouseleave") + .should("not.have.class", "star-hover"); }); - it('check number of stars in rating', () => { + it("check number of stars in rating", () => { get_dialog_with_rating(); - cy.get('div.rating') - .first() - .children('svg') - .should('have.length', 7); + cy.get("div.rating").first().children("svg").should("have.length", 7); }); - }); diff --git a/cypress/integration/control_select.js b/cypress/integration/control_select.js index 8e18d21260..5f7a07e0c4 100644 --- a/cypress/integration/control_select.js +++ b/cypress/integration/control_select.js @@ -1,37 +1,40 @@ -context('Control Select', () => { +context("Control Select", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); function get_dialog_with_select() { return cy.dialog({ - title: 'Select', - fields: [{ - 'fieldname': 'select_control', - 'fieldtype': 'Select', - 'placeholder': 'Select an Option', - 'options': ['', 'Option 1', 'Option 2', 'Option 2'], - }] + title: "Select", + fields: [ + { + fieldname: "select_control", + fieldtype: "Select", + placeholder: "Select an Option", + options: ["", "Option 1", "Option 2", "Option 2"], + }, + ], }); } - it('toggles placholder on clicking an option', () => { - get_dialog_with_select().as('dialog'); + it("toggles placholder on clicking an option", () => { + get_dialog_with_select().as("dialog"); - cy.get('.frappe-control[data-fieldname=select_control] .control-input').as('control'); - cy.get('.frappe-control[data-fieldname=select_control] .control-input select').as('select'); - cy.get('@control').get('.select-icon').should('exist'); - cy.get('@control').get('.placeholder').should('have.css', 'display', 'block'); - cy.get('@select').select('Option 1'); - cy.findByDisplayValue('Option 1').should('exist'); - cy.get('@control').get('.placeholder').should('have.css', 'display', 'none'); - cy.get('@select').invoke('val', ''); - cy.findByDisplayValue('Option 1').should('not.exist'); - cy.get('@control').get('.placeholder').should('have.css', 'display', 'block'); + cy.get(".frappe-control[data-fieldname=select_control] .control-input").as("control"); + cy.get(".frappe-control[data-fieldname=select_control] .control-input select").as( + "select" + ); + cy.get("@control").get(".select-icon").should("exist"); + cy.get("@control").get(".placeholder").should("have.css", "display", "block"); + cy.get("@select").select("Option 1"); + cy.findByDisplayValue("Option 1").should("exist"); + cy.get("@control").get(".placeholder").should("have.css", "display", "none"); + cy.get("@select").invoke("val", ""); + cy.findByDisplayValue("Option 1").should("not.exist"); + cy.get("@control").get(".placeholder").should("have.css", "display", "block"); - - cy.get('@dialog').then(dialog => { + cy.get("@dialog").then((dialog) => { dialog.hide(); }); }); diff --git a/cypress/integration/custom_buttons.js b/cypress/integration/custom_buttons.js index 6045d009c2..ddbd19731a 100644 --- a/cypress/integration/custom_buttons.js +++ b/cypress/integration/custom_buttons.js @@ -31,10 +31,7 @@ const check_button_count = (label, group = "TestGroup") => { .should("be.visible"); //reset viewport - cy.viewport( - Cypress.config("viewportWidth"), - Cypress.config("viewportHeight") - ); + cy.viewport(Cypress.config("viewportWidth"), Cypress.config("viewportHeight")); }; describe( diff --git a/cypress/integration/customize_form.js b/cypress/integration/customize_form.js index 3857d7ccd8..cd03f7b54c 100644 --- a/cypress/integration/customize_form.js +++ b/cypress/integration/customize_form.js @@ -1,19 +1,19 @@ -context('Customize Form', () => { +context("Customize Form", () => { before(() => { cy.login(); - cy.visit('/app/customize-form'); + cy.visit("/app/customize-form"); }); - it('Changing to naming rule should update autoname', () => { + it("Changing to naming rule should update autoname", () => { cy.fill_field("doc_type", "ToDo", "Link").blur(); cy.click_form_section("Naming"); const naming_rule_default_autoname_map = { "Set by user": "prompt", "By fieldname": "field:", 'By "Naming Series" field': "naming_series:", - "Expression": "format:", + Expression: "format:", "Expression (old style)": "", - "Random": "hash", - "By script": "" + Random: "hash", + "By script": "", }; Cypress._.forOwn(naming_rule_default_autoname_map, (value, naming_rule) => { cy.fill_field("naming_rule", naming_rule, "Select"); diff --git a/cypress/integration/dashboard_chart.js b/cypress/integration/dashboard_chart.js index ae71fcda3a..6023a50abe 100644 --- a/cypress/integration/dashboard_chart.js +++ b/cypress/integration/dashboard_chart.js @@ -1,22 +1,22 @@ -context('Dashboard Chart', () => { +context("Dashboard Chart", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); - it('Check filter populate for child table doctype', () => { - cy.visit('/app/dashboard-chart/new-dashboard-chart-1'); - cy.get('[data-fieldname="parent_document_type"]').should('have.css', 'display', 'none'); + it("Check filter populate for child table doctype", () => { + cy.visit("/app/dashboard-chart/new-dashboard-chart-1"); + cy.get('[data-fieldname="parent_document_type"]').should("have.css", "display", "none"); - cy.get_field('document_type', 'Link'); - cy.fill_field('document_type', 'Workspace Link', 'Link').focus().blur(); - cy.get_field('document_type', 'Link').should('have.value', 'Workspace Link'); + cy.get_field("document_type", "Link"); + cy.fill_field("document_type", "Workspace Link", "Link").focus().blur(); + cy.get_field("document_type", "Link").should("have.value", "Workspace Link"); - cy.fill_field('chart_name', 'Test Chart', 'Data'); + cy.fill_field("chart_name", "Test Chart", "Data"); cy.get('[data-fieldname="filters_json"]').click().wait(200); - cy.get('.modal-body .filter-action-buttons .add-filter').click(); - cy.get('.modal-body .fieldname-select-area').click(); - cy.get('.modal-actions .btn-modal-close').click(); + cy.get(".modal-body .filter-action-buttons .add-filter").click(); + cy.get(".modal-body .fieldname-select-area").click(); + cy.get(".modal-actions .btn-modal-close").click(); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/dashboard_links.js b/cypress/integration/dashboard_links.js index 019de1991d..31572b7976 100644 --- a/cypress/integration/dashboard_links.js +++ b/cypress/integration/dashboard_links.js @@ -1,91 +1,94 @@ -import doctype_with_child_table from '../fixtures/doctype_with_child_table'; -import child_table_doctype from '../fixtures/child_table_doctype'; -import child_table_doctype_1 from '../fixtures/child_table_doctype_1'; -import doctype_to_link from '../fixtures/doctype_to_link'; +import doctype_with_child_table from "../fixtures/doctype_with_child_table"; +import child_table_doctype from "../fixtures/child_table_doctype"; +import child_table_doctype_1 from "../fixtures/child_table_doctype_1"; +import doctype_to_link from "../fixtures/doctype_to_link"; const doctype_to_link_name = doctype_to_link.name; const child_table_doctype_name = child_table_doctype.name; -context('Dashboard links', () => { +context("Dashboard links", () => { before(() => { - cy.visit('/login'); + cy.visit("/login"); cy.login(); - cy.insert_doc('DocType', child_table_doctype, true); - cy.insert_doc('DocType', child_table_doctype_1, true); - cy.insert_doc('DocType', doctype_with_child_table, true); - cy.insert_doc('DocType', doctype_to_link, true); - return cy.window().its('frappe').then(frappe => { - return frappe.xcall("frappe.tests.ui_test_helpers.update_child_table", { - name: child_table_doctype_name + cy.insert_doc("DocType", child_table_doctype, true); + cy.insert_doc("DocType", child_table_doctype_1, true); + cy.insert_doc("DocType", doctype_with_child_table, true); + cy.insert_doc("DocType", doctype_to_link, true); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.xcall("frappe.tests.ui_test_helpers.update_child_table", { + name: child_table_doctype_name, + }); }); - }); }); - it('Adding a new contact, checking for the counter on the dashboard and deleting the created contact', () => { - cy.visit('/app/contact'); + it("Adding a new contact, checking for the counter on the dashboard and deleting the created contact", () => { + cy.visit("/app/contact"); cy.clear_filters(); - cy.visit('/app/user'); - cy.get('.list-row-col > .level-item > .ellipsis').eq(0).click({ force: true }); + cy.visit("/app/user"); + cy.get(".list-row-col > .level-item > .ellipsis").eq(0).click({ force: true }); //To check if initially the dashboard contains only the "Contact" link and there is no counter - cy.get('[data-doctype="Contact"]').should('contain', 'Contact'); + cy.get('[data-doctype="Contact"]').should("contain", "Contact"); //Adding a new contact cy.get('.document-link-badge[data-doctype="Contact"]').click(); cy.wait(300); - cy.findByRole('button', {name: 'Add Contact'}).should('be.visible'); - cy.findByRole('button', {name: 'Add Contact'}).click(); - cy.get('[data-doctype="Contact"][data-fieldname="first_name"]').type('Admin'); - cy.findByRole('button', {name: 'Save'}).click(); - cy.visit('/app/user'); - cy.get('.list-row-col > .level-item > .ellipsis').eq(0).click({ force: true }); + cy.findByRole("button", { name: "Add Contact" }).should("be.visible"); + cy.findByRole("button", { name: "Add Contact" }).click(); + cy.get('[data-doctype="Contact"][data-fieldname="first_name"]').type("Admin"); + cy.findByRole("button", { name: "Save" }).click(); + cy.visit("/app/user"); + cy.get(".list-row-col > .level-item > .ellipsis").eq(0).click({ force: true }); //To check if the counter for contact doc is "1" after adding the contact - cy.get('[data-doctype="Contact"] > .count').should('contain', '1'); - cy.get('[data-doctype="Contact"]').contains('Contact').click(); + cy.get('[data-doctype="Contact"] > .count').should("contain", "1"); + cy.get('[data-doctype="Contact"]').contains("Contact").click(); //Deleting the newly created contact - cy.visit('/app/contact'); - cy.get('.list-subject > .select-like > .list-row-checkbox').eq(0).click({ force: true }); - cy.findByRole('button', {name: 'Actions'}).click(); + cy.visit("/app/contact"); + cy.get(".list-subject > .select-like > .list-row-checkbox").eq(0).click({ force: true }); + cy.findByRole("button", { name: "Actions" }).click(); cy.get('.actions-btn-group [data-label="Delete"]').click(); - cy.findByRole('button', {name: 'Yes'}).click({delay: 700}); - + cy.findByRole("button", { name: "Yes" }).click({ delay: 700 }); //To check if the counter from the "Contact" doc link is removed cy.wait(700); - cy.visit('/app/user'); - cy.get('.list-row-col > .level-item > .ellipsis').eq(0).click({ force: true }); - cy.get('[data-doctype="Contact"]').should('contain', 'Contact'); + cy.visit("/app/user"); + cy.get(".list-row-col > .level-item > .ellipsis").eq(0).click({ force: true }); + cy.get('[data-doctype="Contact"]').should("contain", "Contact"); }); - it('Report link in dashboard', () => { - cy.visit('/app/user'); - cy.visit('/app/user/Administrator'); - cy.get('[data-doctype="Contact"]').should('contain', 'Contact'); - cy.findByText('Connections'); + it("Report link in dashboard", () => { + cy.visit("/app/user"); + cy.visit("/app/user/Administrator"); + cy.get('[data-doctype="Contact"]').should("contain", "Contact"); + cy.findByText("Connections"); cy.window() - .its('cur_frm') - .then(cur_frm => { + .its("cur_frm") + .then((cur_frm) => { cur_frm.dashboard.data.reports = [ { - 'label': 'Reports', - 'items': ['Website Analytics'] - } + label: "Reports", + items: ["Website Analytics"], + }, ]; cur_frm.dashboard.render_report_links(); - cy.get('[data-report="Website Analytics"]').contains('Website Analytics').click(); - cy.findByText('Website Analytics'); + cy.get('[data-report="Website Analytics"]').contains("Website Analytics").click(); + cy.findByText("Website Analytics"); }); }); - it('check if child table is populated with linked field on creation from dashboard link', () => { + it("check if child table is populated with linked field on creation from dashboard link", () => { cy.new_form(doctype_to_link_name); cy.fill_field("title", "Test Linking"); - cy.findByRole("button", {name: "Save"}).click(); + cy.findByRole("button", { name: "Save" }).click(); - cy.get('.document-link .btn-new').click(); - cy.get('.frappe-control[data-fieldname="child_table"] .rows .data-row .col[data-fieldname="doctype_to_link"]') - .should('contain.text', 'Test Linking'); + cy.get(".document-link .btn-new").click(); + cy.get( + '.frappe-control[data-fieldname="child_table"] .rows .data-row .col[data-fieldname="doctype_to_link"]' + ).should("contain.text", "Test Linking"); }); }); diff --git a/cypress/integration/data_field_form_validation.js b/cypress/integration/data_field_form_validation.js index c6feea5550..49513e72fb 100644 --- a/cypress/integration/data_field_form_validation.js +++ b/cypress/integration/data_field_form_validation.js @@ -1,43 +1,45 @@ -import data_field_validation_doctype from '../fixtures/data_field_validation_doctype'; +import data_field_validation_doctype from "../fixtures/data_field_validation_doctype"; const doctype_name = data_field_validation_doctype.name; - -context('Data Field Input Validation in New Form', () => { +context("Data Field Input Validation in New Form", () => { before(() => { cy.login(); - cy.visit('/app/website'); - return cy.insert_doc('DocType', data_field_validation_doctype, true); + cy.visit("/app/website"); + return cy.insert_doc("DocType", data_field_validation_doctype, true); }); function validateField(fieldname, invalid_value, valid_value) { // Invalid, should have has-error class cy.get_field(fieldname).clear().type(invalid_value).blur(); - cy.get(`.frappe-control[data-fieldname="${fieldname}"]`).should('have.class', 'has-error'); + cy.get(`.frappe-control[data-fieldname="${fieldname}"]`).should("have.class", "has-error"); // Valid value, should not have has-error class cy.get_field(fieldname).clear().type(valid_value); - cy.get(`.frappe-control[data-fieldname="${fieldname}"]`).should('not.have.class', 'has-error'); + cy.get(`.frappe-control[data-fieldname="${fieldname}"]`).should( + "not.have.class", + "has-error" + ); } - describe('Data Field Options', () => { - it('should validate email address', () => { + describe("Data Field Options", () => { + it("should validate email address", () => { cy.new_form(doctype_name); - validateField('email', 'captian', 'hello@test.com'); + validateField("email", "captian", "hello@test.com"); }); - it('should validate URL', () => { - validateField('url', 'jkl', 'https://frappe.io'); - validateField('url', 'abcd.com', 'http://google.com/home'); - validateField('url', '&&http://google.uae', 'gopher://frappe.io'); - validateField('url', 'ftt2:://google.in?q=news', 'ftps2://frappe.io/__/#home'); - validateField('url', 'ftt2://', 'ntps://localhost'); // For intranet URLs + it("should validate URL", () => { + validateField("url", "jkl", "https://frappe.io"); + validateField("url", "abcd.com", "http://google.com/home"); + validateField("url", "&&http://google.uae", "gopher://frappe.io"); + validateField("url", "ftt2:://google.in?q=news", "ftps2://frappe.io/__/#home"); + validateField("url", "ftt2://", "ntps://localhost"); // For intranet URLs }); - it('should validate phone number', () => { - validateField('phone', 'america', '89787878'); + it("should validate phone number", () => { + validateField("phone", "america", "89787878"); }); - it('should validate name', () => { - validateField('person_name', ' 777Hello', 'James Bond'); + it("should validate name", () => { + validateField("person_name", " 777Hello", "James Bond"); }); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/datetime.js b/cypress/integration/datetime.js index 4a24faf40b..7a8a68c1d9 100644 --- a/cypress/integration/datetime.js +++ b/cypress/integration/datetime.js @@ -1,53 +1,52 @@ -import datetime_doctype from '../fixtures/datetime_doctype'; +import datetime_doctype from "../fixtures/datetime_doctype"; const doctype_name = datetime_doctype.name; -context('Control Date, Time and DateTime', () => { +context("Control Date, Time and DateTime", () => { before(() => { cy.login(); - cy.visit('/app/website'); - return cy.insert_doc('DocType', datetime_doctype, true); + cy.visit("/app/website"); + return cy.insert_doc("DocType", datetime_doctype, true); }); - describe('Date formats', () => { + describe("Date formats", () => { let date_formats = [ { - date_format: 'dd-mm-yyyy', + date_format: "dd-mm-yyyy", part: 2, length: 4, - separator: '-' + separator: "-", }, { - date_format: 'mm/dd/yyyy', + date_format: "mm/dd/yyyy", part: 0, length: 2, - separator: '/' - } + separator: "/", + }, ]; - date_formats.forEach(d => { - it('test date format ' + d.date_format, () => { - cy.set_value('System Settings', 'System Settings', { - date_format: d.date_format + date_formats.forEach((d) => { + it("test date format " + d.date_format, () => { + cy.set_value("System Settings", "System Settings", { + date_format: d.date_format, }); cy.window() - .its('frappe') - .then(frappe => { + .its("frappe") + .then((frappe) => { // update sys_defaults value to avoid a reload frappe.sys_defaults.date_format = d.date_format; }); cy.new_form(doctype_name); - cy.get('.form-control[data-fieldname=date]').focus(); - cy.get('.datepickers-container .datepicker.active') - .should('be.visible'); + cy.get(".form-control[data-fieldname=date]").focus(); + cy.get(".datepickers-container .datepicker.active").should("be.visible"); cy.get( - '.datepickers-container .datepicker.active .datepicker--cell-day.-current-' + ".datepickers-container .datepicker.active .datepicker--cell-day.-current-" ).click({ force: true }); cy.window() - .its('cur_frm') - .then(cur_frm => { - let formatted_value = cur_frm.get_field('date').input.value; + .its("cur_frm") + .then((cur_frm) => { + let formatted_value = cur_frm.get_field("date").input.value; let parts = formatted_value.split(d.separator); expect(parts[d.part].length).to.equal(d.length); }); @@ -55,74 +54,72 @@ context('Control Date, Time and DateTime', () => { }); }); - describe('Time formats', () => { + describe("Time formats", () => { let time_formats = [ { - time_format: 'HH:mm:ss', - value: ' 11:00:12', - match_value: '11:00:12' + time_format: "HH:mm:ss", + value: " 11:00:12", + match_value: "11:00:12", }, { - time_format: 'HH:mm', - value: ' 11:00:12', - match_value: '11:00' - } + time_format: "HH:mm", + value: " 11:00:12", + match_value: "11:00", + }, ]; - time_formats.forEach(d => { - it('test time format ' + d.time_format, () => { - cy.set_value('System Settings', 'System Settings', { - time_format: d.time_format + time_formats.forEach((d) => { + it("test time format " + d.time_format, () => { + cy.set_value("System Settings", "System Settings", { + time_format: d.time_format, }); cy.window() - .its('frappe') - .then(frappe => { + .its("frappe") + .then((frappe) => { frappe.sys_defaults.time_format = d.time_format; }); cy.new_form(doctype_name); - cy.fill_field('time', d.value, 'Time').blur(); - cy.get_field('time').should('have.value', d.match_value); + cy.fill_field("time", d.value, "Time").blur(); + cy.get_field("time").should("have.value", d.match_value); }); }); }); - describe('DateTime formats', () => { + describe("DateTime formats", () => { let datetime_formats = [ { - date_format: 'dd.mm.yyyy', - time_format: 'HH:mm:ss', - value: ' 02.12.2019 11:00:12', - doc_value: '2019-12-02 00:30:12', // system timezone (America/New_York) - input_value: '02.12.2019 11:00:12' // admin timezone (Asia/Kolkata) + date_format: "dd.mm.yyyy", + time_format: "HH:mm:ss", + value: " 02.12.2019 11:00:12", + doc_value: "2019-12-02 00:30:12", // system timezone (America/New_York) + input_value: "02.12.2019 11:00:12", // admin timezone (Asia/Kolkata) }, { - date_format: 'mm-dd-yyyy', - time_format: 'HH:mm', - value: ' 12-02-2019 11:00:00', - doc_value: '2019-12-02 00:30:00', // system timezone (America/New_York) - input_value: '12-02-2019 11:00' // admin timezone (Asia/Kolkata) - } + date_format: "mm-dd-yyyy", + time_format: "HH:mm", + value: " 12-02-2019 11:00:00", + doc_value: "2019-12-02 00:30:00", // system timezone (America/New_York) + input_value: "12-02-2019 11:00", // admin timezone (Asia/Kolkata) + }, ]; - datetime_formats.forEach(d => { + datetime_formats.forEach((d) => { it(`test datetime format ${d.date_format} ${d.time_format}`, () => { - cy.set_value('System Settings', 'System Settings', { + cy.set_value("System Settings", "System Settings", { date_format: d.date_format, - time_format: d.time_format + time_format: d.time_format, }); cy.window() - .its('frappe') - .then(frappe => { + .its("frappe") + .then((frappe) => { frappe.sys_defaults.date_format = d.date_format; frappe.sys_defaults.time_format = d.time_format; }); cy.new_form(doctype_name); - cy.fill_field('datetime', d.value, 'Datetime').blur(); - cy.get_field('datetime').should('have.value', d.input_value); + cy.fill_field("datetime", d.value, "Datetime").blur(); + cy.get_field("datetime").should("have.value", d.input_value); - cy.window() - .its('cur_frm.doc.datetime') - .should('eq', d.doc_value); + cy.window().its("cur_frm.doc.datetime").should("eq", d.doc_value); }); }); }); diff --git a/cypress/integration/datetime_field_form_validation.js b/cypress/integration/datetime_field_form_validation.js index ef47a0fbf7..1a549d8a1d 100644 --- a/cypress/integration/datetime_field_form_validation.js +++ b/cypress/integration/datetime_field_form_validation.js @@ -16,4 +16,4 @@ // cy.get('.indicator-pill').should('contain', 'Open').should('have.class', 'red'); // }); // }); -// }); \ No newline at end of file +// }); diff --git a/cypress/integration/depends_on.js b/cypress/integration/depends_on.js index 12f54f2b6e..6419809466 100644 --- a/cypress/integration/depends_on.js +++ b/cypress/integration/depends_on.js @@ -1,135 +1,152 @@ -context('Depends On', () => { +context("Depends On", () => { before(() => { cy.login(); - cy.visit('/app/website'); - return cy.window().its('frappe').then(frappe => { - return frappe.xcall('frappe.tests.ui_test_helpers.create_child_doctype', { - name: 'Child Test Depends On', - fields: [ - { - "label": "Child Test Field", - "fieldname": "child_test_field", - "fieldtype": "Data", - "in_list_view": 1, - }, - { - "label": "Child Dependant Field", - "fieldname": "child_dependant_field", - "fieldtype": "Data", - "in_list_view": 1, - }, - { - "label": "Child Display Dependant Field", - "fieldname": "child_display_dependant_field", - "fieldtype": "Data", - "in_list_view": 1, - }, - ] + cy.visit("/app/website"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.xcall("frappe.tests.ui_test_helpers.create_child_doctype", { + name: "Child Test Depends On", + fields: [ + { + label: "Child Test Field", + fieldname: "child_test_field", + fieldtype: "Data", + in_list_view: 1, + }, + { + label: "Child Dependant Field", + fieldname: "child_dependant_field", + fieldtype: "Data", + in_list_view: 1, + }, + { + label: "Child Display Dependant Field", + fieldname: "child_display_dependant_field", + fieldtype: "Data", + in_list_view: 1, + }, + ], + }); + }) + .then((frappe) => { + return frappe.xcall("frappe.tests.ui_test_helpers.create_doctype", { + name: "Test Depends On", + fields: [ + { + label: "Test Field", + fieldname: "test_field", + fieldtype: "Data", + }, + { + label: "Dependant Field", + fieldname: "dependant_field", + fieldtype: "Data", + mandatory_depends_on: "eval:doc.test_field=='Some Value'", + read_only_depends_on: "eval:doc.test_field=='Some Other Value'", + }, + { + label: "Display Dependant Field", + fieldname: "display_dependant_field", + fieldtype: "Data", + depends_on: "eval:doc.test_field=='Value'", + }, + { + label: "Child Test Depends On Field", + fieldname: "child_test_depends_on_field", + fieldtype: "Table", + read_only_depends_on: "eval:doc.test_field=='Some Other Value'", + options: "Child Test Depends On", + }, + { + label: "Dependent Tab", + fieldname: "dependent_tab", + fieldtype: "Tab Break", + depends_on: "eval:doc.test_field=='Show Tab'", + }, + { + fieldname: "tab_section", + fieldtype: "Section Break", + }, + { + label: "Field in Tab", + fieldname: "field_in_tab", + fieldtype: "Data", + }, + ], + }); }); - }).then(frappe => { - return frappe.xcall('frappe.tests.ui_test_helpers.create_doctype', { - name: 'Test Depends On', - fields: [ - { - "label": "Test Field", - "fieldname": "test_field", - "fieldtype": "Data", - }, - { - "label": "Dependant Field", - "fieldname": "dependant_field", - "fieldtype": "Data", - "mandatory_depends_on": "eval:doc.test_field=='Some Value'", - "read_only_depends_on": "eval:doc.test_field=='Some Other Value'", - }, - { - "label": "Display Dependant Field", - "fieldname": "display_dependant_field", - "fieldtype": "Data", - 'depends_on': "eval:doc.test_field=='Value'" - }, - { - "label": "Child Test Depends On Field", - "fieldname": "child_test_depends_on_field", - "fieldtype": "Table", - 'read_only_depends_on': "eval:doc.test_field=='Some Other Value'", - 'options': "Child Test Depends On" - }, - { - "label": "Dependent Tab", - "fieldname": "dependent_tab", - "fieldtype": "Tab Break", - "depends_on": "eval:doc.test_field=='Show Tab'" - }, - { - "fieldname": "tab_section", - "fieldtype": "Section Break", - }, - { - "label": "Field in Tab", - "fieldname": "field_in_tab", - "fieldtype": "Data", - } - ] - }); - }); }); - it('should show the tab on other setting field value', () => { - cy.new_form('Test Depends On'); - cy.fill_field('test_field', 'Show Tab'); - cy.get('body').click(); - cy.findByRole("tab", {name: "Dependent Tab"}).should('be.visible'); + it("should show the tab on other setting field value", () => { + cy.new_form("Test Depends On"); + cy.fill_field("test_field", "Show Tab"); + cy.get("body").click(); + cy.findByRole("tab", { name: "Dependent Tab" }).should("be.visible"); }); - it('should set the field as mandatory depending on other fields value', () => { - cy.new_form('Test Depends On'); - cy.fill_field('test_field', 'Some Value'); - cy.findByRole('button', {name: 'Save'}).click(); - cy.get('.msgprint-dialog .modal-title').contains('Missing Fields').should('be.visible'); + it("should set the field as mandatory depending on other fields value", () => { + cy.new_form("Test Depends On"); + cy.fill_field("test_field", "Some Value"); + cy.findByRole("button", { name: "Save" }).click(); + cy.get(".msgprint-dialog .modal-title").contains("Missing Fields").should("be.visible"); cy.hide_dialog(); - cy.fill_field('test_field', 'Random value'); - cy.findByRole('button', {name: 'Save'}).click(); - cy.get('.msgprint-dialog .modal-title').contains('Missing Fields').should('not.be.visible'); + cy.fill_field("test_field", "Random value"); + cy.findByRole("button", { name: "Save" }).click(); + cy.get(".msgprint-dialog .modal-title") + .contains("Missing Fields") + .should("not.be.visible"); }); - it('should set the field as read only depending on other fields value', () => { - cy.new_form('Test Depends On'); - cy.fill_field('dependant_field', 'Some Value'); - cy.fill_field('test_field', 'Some Other Value'); - cy.get('body').click(); - cy.get('.control-input [data-fieldname="dependant_field"]').should('be.disabled'); - cy.fill_field('test_field', 'Random Value'); - cy.get('body').click(); - cy.get('.control-input [data-fieldname="dependant_field"]').should('not.be.disabled'); + it("should set the field as read only depending on other fields value", () => { + cy.new_form("Test Depends On"); + cy.fill_field("dependant_field", "Some Value"); + cy.fill_field("test_field", "Some Other Value"); + cy.get("body").click(); + cy.get('.control-input [data-fieldname="dependant_field"]').should("be.disabled"); + cy.fill_field("test_field", "Random Value"); + cy.get("body").click(); + cy.get('.control-input [data-fieldname="dependant_field"]').should("not.be.disabled"); }); - it('should set the table and its fields as read only depending on other fields value', () => { - cy.new_form('Test Depends On'); - cy.fill_field('dependant_field', 'Some Value'); + it("should set the table and its fields as read only depending on other fields value", () => { + cy.new_form("Test Depends On"); + cy.fill_field("dependant_field", "Some Value"); //cy.fill_field('test_field', 'Some Other Value'); - cy.get('.frappe-control[data-fieldname="child_test_depends_on_field"]').as('table'); - cy.get('@table').findByRole('button', {name: 'Add Row'}).click(); - cy.get('@table').find('[data-idx="1"]').as('row1'); - cy.get('@row1').find('.btn-open-row').click(); - cy.get('@row1').find('.form-in-grid').as('row1-form_in_grid'); + cy.get('.frappe-control[data-fieldname="child_test_depends_on_field"]').as("table"); + cy.get("@table").findByRole("button", { name: "Add Row" }).click(); + cy.get("@table").find('[data-idx="1"]').as("row1"); + cy.get("@row1").find(".btn-open-row").click(); + cy.get("@row1").find(".form-in-grid").as("row1-form_in_grid"); //cy.get('@row1-form_in_grid').find('') - cy.fill_table_field('child_test_depends_on_field', '1', 'child_test_field', 'Some Value'); - cy.fill_table_field('child_test_depends_on_field', '1', 'child_dependant_field', 'Some Other Value'); + cy.fill_table_field("child_test_depends_on_field", "1", "child_test_field", "Some Value"); + cy.fill_table_field( + "child_test_depends_on_field", + "1", + "child_dependant_field", + "Some Other Value" + ); - cy.get('@row1-form_in_grid').find('.grid-collapse-row').click(); + cy.get("@row1-form_in_grid").find(".grid-collapse-row").click(); // set the table to read-only - cy.fill_field('test_field', 'Some Other Value'); + cy.fill_field("test_field", "Some Other Value"); // grid row form fields should be read-only - cy.get('@row1').find('.btn-open-row').click(); + cy.get("@row1").find(".btn-open-row").click(); - cy.get('@row1-form_in_grid').find('.control-input [data-fieldname="child_test_field"]').should('be.disabled'); - cy.get('@row1-form_in_grid').find('.control-input [data-fieldname="child_dependant_field"]').should('be.disabled'); + cy.get("@row1-form_in_grid") + .find('.control-input [data-fieldname="child_test_field"]') + .should("be.disabled"); + cy.get("@row1-form_in_grid") + .find('.control-input [data-fieldname="child_dependant_field"]') + .should("be.disabled"); }); - it('should display the field depending on other fields value', () => { - cy.new_form('Test Depends On'); - cy.get('.control-input [data-fieldname="display_dependant_field"]').should('not.be.visible'); + it("should display the field depending on other fields value", () => { + cy.new_form("Test Depends On"); + cy.get('.control-input [data-fieldname="display_dependant_field"]').should( + "not.be.visible" + ); cy.get('.control-input [data-fieldname="test_field"]').clear(); - cy.fill_field('test_field', 'Value'); - cy.get('body').click(); - cy.get('.control-input [data-fieldname="display_dependant_field"]').should('be.visible'); + cy.fill_field("test_field", "Value"); + cy.get("body").click(); + cy.get('.control-input [data-fieldname="display_dependant_field"]').should("be.visible"); }); }); diff --git a/cypress/integration/discussions.js b/cypress/integration/discussions.js index caf7d6c3f9..55bcabce19 100644 --- a/cypress/integration/discussions.js +++ b/cypress/integration/discussions.js @@ -1,79 +1,101 @@ -context('Discussions', () => { +context("Discussions", () => { before(() => { cy.login(); - cy.visit('/app'); - return cy.window().its('frappe').then(frappe => { - return frappe.call('frappe.tests.ui_test_helpers.create_data_for_discussions'); - }); + cy.visit("/app"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.call("frappe.tests.ui_test_helpers.create_data_for_discussions"); + }); }); const reply_through_modal = () => { - cy.visit('/test-page-discussions'); + cy.visit("/test-page-discussions"); // Open the modal - cy.get('.reply').click(); + cy.get(".reply").click(); cy.wait(500); - cy.get('.discussion-modal').should('be.visible'); + cy.get(".discussion-modal").should("be.visible"); // Enter title - cy.get('.modal .topic-title').type('Discussion from tests') - .should('have.value', 'Discussion from tests'); + cy.get(".modal .topic-title") + .type("Discussion from tests") + .should("have.value", "Discussion from tests"); // Enter comment - cy.get('.modal .comment-field') - .type('This is a discussion from the cypress ui tests.') - .should('have.value', 'This is a discussion from the cypress ui tests.'); + cy.get(".modal .comment-field") + .type("This is a discussion from the cypress ui tests.") + .should("have.value", "This is a discussion from the cypress ui tests."); // Submit - cy.get('.modal .submit-discussion').click(); + cy.get(".modal .submit-discussion").click(); cy.wait(2000); // Check if discussion is added to page and content is visible - cy.get('.sidebar-parent:first .discussion-topic-title').should('have.text', 'Discussion from tests'); - cy.get('.discussion-on-page:visible').should('have.class', 'show'); - cy.get('.discussion-on-page:visible .reply-card .reply-text') - .should('have.text', 'This is a discussion from the cypress ui tests.\n'); - + cy.get(".sidebar-parent:first .discussion-topic-title").should( + "have.text", + "Discussion from tests" + ); + cy.get(".discussion-on-page:visible").should("have.class", "show"); + cy.get(".discussion-on-page:visible .reply-card .reply-text").should( + "have.text", + "This is a discussion from the cypress ui tests.\n" + ); }; const reply_through_comment_box = () => { - cy.get('.discussion-form:visible .comment-field') - .type('This is a discussion from the cypress ui tests. \n\nThis comment was entered through the commentbox on the page.') - .should('have.value', 'This is a discussion from the cypress ui tests. \n\nThis comment was entered through the commentbox on the page.'); + cy.get(".discussion-form:visible .comment-field") + .type( + "This is a discussion from the cypress ui tests. \n\nThis comment was entered through the commentbox on the page." + ) + .should( + "have.value", + "This is a discussion from the cypress ui tests. \n\nThis comment was entered through the commentbox on the page." + ); - cy.get('.discussion-form:visible .submit-discussion').click(); + cy.get(".discussion-form:visible .submit-discussion").click(); cy.wait(3000); - cy.get('.discussion-on-page:visible').should('have.class', 'show'); - cy.get('.discussion-on-page:visible').children(".reply-card").eq(1).find(".reply-text") - .should('have.text', 'This is a discussion from the cypress ui tests. \n\nThis comment was entered through the commentbox on the page.\n'); + cy.get(".discussion-on-page:visible").should("have.class", "show"); + cy.get(".discussion-on-page:visible") + .children(".reply-card") + .eq(1) + .find(".reply-text") + .should( + "have.text", + "This is a discussion from the cypress ui tests. \n\nThis comment was entered through the commentbox on the page.\n" + ); }; const cancel_and_clear_comment_box = () => { - cy.get('.discussion-form:visible .comment-field') - .type('This is a discussion from the cypress ui tests.') - .should('have.value', 'This is a discussion from the cypress ui tests.'); + cy.get(".discussion-form:visible .comment-field") + .type("This is a discussion from the cypress ui tests.") + .should("have.value", "This is a discussion from the cypress ui tests."); - cy.get('.discussion-form:visible .cancel-comment').click(); - cy.get('.discussion-form:visible .comment-field').should('have.value', ''); + cy.get(".discussion-form:visible .cancel-comment").click(); + cy.get(".discussion-form:visible .comment-field").should("have.value", ""); }; const single_thread_discussion = () => { - cy.visit('/test-single-thread'); - cy.get('.discussions-sidebar').should('have.length', 0); - cy.get('.reply').should('have.length', 0); + cy.visit("/test-single-thread"); + cy.get(".discussions-sidebar").should("have.length", 0); + cy.get(".reply").should("have.length", 0); - cy.get('.discussion-form:visible .comment-field') - .type('This comment is being made on a single thread discussion.') - .should('have.value', 'This comment is being made on a single thread discussion.'); + cy.get(".discussion-form:visible .comment-field") + .type("This comment is being made on a single thread discussion.") + .should("have.value", "This comment is being made on a single thread discussion."); - cy.get('.discussion-form:visible .submit-discussion').click(); + cy.get(".discussion-form:visible .submit-discussion").click(); cy.wait(3000); - cy.get('.discussion-on-page').children(".reply-card").eq(-1).find(".reply-text") - .should('have.text', 'This comment is being made on a single thread discussion.\n'); + cy.get(".discussion-on-page") + .children(".reply-card") + .eq(-1) + .find(".reply-text") + .should("have.text", "This comment is being made on a single thread discussion.\n"); }; - it('reply through modal', reply_through_modal); - it('reply through comment box', reply_through_comment_box); - it('cancel and clear comment box', cancel_and_clear_comment_box); - it('single thread discussion', single_thread_discussion); + it("reply through modal", reply_through_modal); + it("reply through comment box", reply_through_comment_box); + it("cancel and clear comment box", cancel_and_clear_comment_box); + it("single thread discussion", single_thread_discussion); }); diff --git a/cypress/integration/file_uploader.js b/cypress/integration/file_uploader.js index 3d4f92df3c..669f9ba385 100644 --- a/cypress/integration/file_uploader.js +++ b/cypress/integration/file_uploader.js @@ -1,78 +1,82 @@ -context('FileUploader', () => { +context("FileUploader", () => { before(() => { cy.login(); - cy.visit('/app'); + cy.visit("/app"); }); function open_upload_dialog() { - cy.window().its('frappe').then(frappe => { - new frappe.ui.FileUploader(); - }); + cy.window() + .its("frappe") + .then((frappe) => { + new frappe.ui.FileUploader(); + }); } - it('upload dialog api works', () => { + it("upload dialog api works", () => { open_upload_dialog(); - cy.get_open_dialog().should('contain', 'Drag and drop files'); + cy.get_open_dialog().should("contain", "Drag and drop files"); cy.hide_dialog(); }); - it('should accept dropped files', () => { + it("should accept dropped files", () => { open_upload_dialog(); - cy.get_open_dialog().find('.file-upload-area').attachFile('example.json', { - subjectType: 'drag-n-drop', + cy.get_open_dialog().find(".file-upload-area").attachFile("example.json", { + subjectType: "drag-n-drop", }); - cy.get_open_dialog().find('.file-name').should('contain', 'example.json'); - cy.intercept('POST', '/api/method/upload_file').as('upload_file'); - cy.get_open_dialog().findByRole('button', {name: 'Upload'}).click(); - cy.wait('@upload_file').its('response.statusCode').should('eq', 200); - cy.get('.modal:visible').should('not.exist'); + cy.get_open_dialog().find(".file-name").should("contain", "example.json"); + cy.intercept("POST", "/api/method/upload_file").as("upload_file"); + cy.get_open_dialog().findByRole("button", { name: "Upload" }).click(); + cy.wait("@upload_file").its("response.statusCode").should("eq", 200); + cy.get(".modal:visible").should("not.exist"); }); - it('should accept uploaded files', () => { + it("should accept uploaded files", () => { open_upload_dialog(); - cy.get_open_dialog().findByRole('button', {name: 'Library'}).click(); - cy.findByPlaceholderText('Search by filename or extension').type('example.json'); - cy.get_open_dialog().findAllByText('example.json').first().click(); - cy.intercept('POST', '/api/method/upload_file').as('upload_file'); - cy.get_open_dialog().findByRole('button', {name: 'Upload'}).click(); - cy.wait('@upload_file').its('response.body.message') - .should('have.property', 'file_name', 'example.json'); - cy.get('.modal:visible').should('not.exist'); + cy.get_open_dialog().findByRole("button", { name: "Library" }).click(); + cy.findByPlaceholderText("Search by filename or extension").type("example.json"); + cy.get_open_dialog().findAllByText("example.json").first().click(); + cy.intercept("POST", "/api/method/upload_file").as("upload_file"); + cy.get_open_dialog().findByRole("button", { name: "Upload" }).click(); + cy.wait("@upload_file") + .its("response.body.message") + .should("have.property", "file_name", "example.json"); + cy.get(".modal:visible").should("not.exist"); }); - it('should accept web links', () => { + it("should accept web links", () => { open_upload_dialog(); - cy.get_open_dialog().findByRole('button', {name: 'Link'}).click(); + cy.get_open_dialog().findByRole("button", { name: "Link" }).click(); cy.get_open_dialog() - .findByPlaceholderText('Attach a web link') - .type('https://github.com', { delay: 100, force: true }); - cy.intercept('POST', '/api/method/upload_file').as('upload_file'); - cy.get_open_dialog().findByRole('button', {name: 'Upload'}).click(); - cy.wait('@upload_file').its('response.body.message') - .should('have.property', 'file_url', 'https://github.com'); - cy.get('.modal:visible').should('not.exist'); + .findByPlaceholderText("Attach a web link") + .type("https://github.com", { delay: 100, force: true }); + cy.intercept("POST", "/api/method/upload_file").as("upload_file"); + cy.get_open_dialog().findByRole("button", { name: "Upload" }).click(); + cy.wait("@upload_file") + .its("response.body.message") + .should("have.property", "file_url", "https://github.com"); + cy.get(".modal:visible").should("not.exist"); }); - it('should allow cropping and optimization for valid images', () => { + it("should allow cropping and optimization for valid images", () => { open_upload_dialog(); - cy.get_open_dialog().find('.file-upload-area').attachFile('sample_image.jpg', { - subjectType: 'drag-n-drop', + cy.get_open_dialog().find(".file-upload-area").attachFile("sample_image.jpg", { + subjectType: "drag-n-drop", }); - cy.get_open_dialog().findAllByText('sample_image.jpg').should('exist'); - cy.get_open_dialog().find('.btn-crop').first().click(); - cy.get_open_dialog().findByRole('button', {name: 'Crop'}).click(); - cy.get_open_dialog().findAllByRole('checkbox', {name: 'Optimize'}).should('exist'); - cy.get_open_dialog().findAllByLabelText('Optimize').first().click(); + cy.get_open_dialog().findAllByText("sample_image.jpg").should("exist"); + cy.get_open_dialog().find(".btn-crop").first().click(); + cy.get_open_dialog().findByRole("button", { name: "Crop" }).click(); + cy.get_open_dialog().findAllByRole("checkbox", { name: "Optimize" }).should("exist"); + cy.get_open_dialog().findAllByLabelText("Optimize").first().click(); - cy.intercept('POST', '/api/method/upload_file').as('upload_file'); - cy.get_open_dialog().findByRole('button', {name: 'Upload'}).click(); - cy.wait('@upload_file').its('response.statusCode').should('eq', 200); - cy.get('.modal:visible').should('not.exist'); + cy.intercept("POST", "/api/method/upload_file").as("upload_file"); + cy.get_open_dialog().findByRole("button", { name: "Upload" }).click(); + cy.wait("@upload_file").its("response.statusCode").should("eq", 200); + cy.get(".modal:visible").should("not.exist"); }); }); diff --git a/cypress/integration/first_day_of_the_week.js b/cypress/integration/first_day_of_the_week.js index 1e65b78990..784c068f01 100644 --- a/cypress/integration/first_day_of_the_week.js +++ b/cypress/integration/first_day_of_the_week.js @@ -4,42 +4,48 @@ context("First Day of the Week", () => { }); beforeEach(() => { - cy.visit('/app/system-settings'); - cy.findByText('Date and Number Format').click(); + cy.visit("/app/system-settings"); + cy.findByText("Date and Number Format").click(); }); it("Date control starts with same day as selected in System Settings", () => { - cy.intercept('POST', '/api/method/frappe.core.doctype.system_settings.system_settings.load').as("load_settings"); - cy.fill_field('first_day_of_the_week', 'Tuesday', 'Select'); - cy.findByRole('button', {name: 'Save'}).click(); + cy.intercept( + "POST", + "/api/method/frappe.core.doctype.system_settings.system_settings.load" + ).as("load_settings"); + cy.fill_field("first_day_of_the_week", "Tuesday", "Select"); + cy.findByRole("button", { name: "Save" }).click(); cy.wait("@load_settings"); cy.dialog({ - title: 'Date', + title: "Date", fields: [ { - label: 'Date', - fieldname: 'date', - fieldtype: 'Date' - } - ] + label: "Date", + fieldname: "date", + fieldtype: "Date", + }, + ], }); - cy.get_field('date').click(); - cy.get('.datepicker--day-name').eq(0).should('have.text', 'Tu'); + cy.get_field("date").click(); + cy.get(".datepicker--day-name").eq(0).should("have.text", "Tu"); }); it("Calendar view starts with same day as selected in System Settings", () => { - cy.intercept('POST', '/api/method/frappe.core.doctype.system_settings.system_settings.load').as("load_settings"); - cy.fill_field('first_day_of_the_week', 'Monday', 'Select'); - cy.findByRole('button', {name: 'Save'}).click(); + cy.intercept( + "POST", + "/api/method/frappe.core.doctype.system_settings.system_settings.load" + ).as("load_settings"); + cy.fill_field("first_day_of_the_week", "Monday", "Select"); + cy.findByRole("button", { name: "Save" }).click(); cy.wait("@load_settings"); cy.visit("app/todo/view/calendar/default"); - cy.get('.fc-day-header > span').eq(0).should('have.text', 'Mon'); + cy.get(".fc-day-header > span").eq(0).should("have.text", "Mon"); }); after(() => { - cy.visit('/app/system-settings'); - cy.findByText('Date and Number Format').click(); - cy.fill_field('first_day_of_the_week', 'Sunday', 'Select'); - cy.findByRole('button', {name: 'Save'}).click(); + cy.visit("/app/system-settings"); + cy.findByText("Date and Number Format").click(); + cy.fill_field("first_day_of_the_week", "Sunday", "Select"); + cy.findByRole("button", { name: "Save" }).click(); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/folder_navigation.js b/cypress/integration/folder_navigation.js index 484419b4aa..e15a354de0 100644 --- a/cypress/integration/folder_navigation.js +++ b/cypress/integration/folder_navigation.js @@ -1,79 +1,85 @@ -context('Folder Navigation', () => { +context("Folder Navigation", () => { before(() => { - cy.visit('/login'); + cy.visit("/login"); cy.login(); - cy.visit('/app/file'); + cy.visit("/app/file"); }); - it('Adding Folders', () => { + it("Adding Folders", () => { //Adding filter to go into the home folder - cy.get('.filter-selector > .btn').findByText('1 filter').click(); - cy.findByRole('button', {name: 'Clear Filters'}).click(); - cy.get('.filter-action-buttons > .text-muted').findByText('+ Add a Filter').click(); - cy.get('.fieldname-select-area > .awesomplete > .form-control').type('Fol{enter}'); - cy.get('.filter-field > .form-group > .link-field > .awesomplete > .input-with-feedback').type('Home{enter}'); - cy.get('.filter-action-buttons > div > .btn-primary').findByText('Apply Filters').click(); + cy.get(".filter-selector > .btn").findByText("1 filter").click(); + cy.findByRole("button", { name: "Clear Filters" }).click(); + cy.get(".filter-action-buttons > .text-muted").findByText("+ Add a Filter").click(); + cy.get(".fieldname-select-area > .awesomplete > .form-control").type("Fol{enter}"); + cy.get( + ".filter-field > .form-group > .link-field > .awesomplete > .input-with-feedback" + ).type("Home{enter}"); + cy.get(".filter-action-buttons > div > .btn-primary").findByText("Apply Filters").click(); //Adding folder (Test Folder) cy.click_menu_button("New Folder"); - cy.fill_field('value', 'Test Folder'); - cy.click_modal_primary_button('Create'); + cy.fill_field("value", "Test Folder"); + cy.click_modal_primary_button("Create"); }); - it('Navigating the nested folders, checking if the URL formed is correct, checking if the added content in the child folder is correct', () => { + it("Navigating the nested folders, checking if the URL formed is correct, checking if the added content in the child folder is correct", () => { //Navigating inside the Attachments folder cy.get('[title="Attachments"] > span').click(); //To check if the URL formed after visiting the attachments folder is correct - cy.location('pathname').should('eq', '/app/file/view/home/Attachments'); - cy.visit('/app/file/view/home/Attachments'); + cy.location("pathname").should("eq", "/app/file/view/home/Attachments"); + cy.visit("/app/file/view/home/Attachments"); //Adding folder inside the attachments folder cy.click_menu_button("New Folder"); - cy.fill_field('value', 'Test Folder'); - cy.click_modal_primary_button('Create'); + cy.fill_field("value", "Test Folder"); + cy.click_modal_primary_button("Create"); //Navigating inside the added folder in the Attachments folder cy.get('[title="Test Folder"] > span').click(); //To check if the URL is correct after visiting the Test Folder - cy.location('pathname').should('eq', '/app/file/view/home/Attachments/Test%20Folder'); - cy.visit('/app/file/view/home/Attachments/Test%20Folder'); + cy.location("pathname").should("eq", "/app/file/view/home/Attachments/Test%20Folder"); + cy.visit("/app/file/view/home/Attachments/Test%20Folder"); //Adding a file inside the Test Folder - cy.findByRole('button', {name: 'Add File'}).eq(0).click({force: true}); - cy.get('.file-uploader').findByText('Link').click(); - cy.get('.input-group > .form-control').type('https://wallpaperplay.com/walls/full/8/2/b/72402.jpg'); - cy.click_modal_primary_button('Upload'); + cy.findByRole("button", { name: "Add File" }).eq(0).click({ force: true }); + cy.get(".file-uploader").findByText("Link").click(); + cy.get(".input-group > .form-control").type( + "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg" + ); + cy.click_modal_primary_button("Upload"); //To check if the added file is present in the Test Folder - cy.get('span.level-item > span').should('contain', 'Test Folder'); - cy.get('.list-row-container').eq(0).should('contain.text', '72402.jpg'); - cy.get('.list-row-checkbox').eq(0).click(); + cy.get("span.level-item > span").should("contain", "Test Folder"); + cy.get(".list-row-container").eq(0).should("contain.text", "72402.jpg"); + cy.get(".list-row-checkbox").eq(0).click(); cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.reportview.delete_items' - }).as('file_deleted'); + method: "POST", + url: "api/method/frappe.desk.reportview.delete_items", + }).as("file_deleted"); //Deleting the added file from the Test folder cy.click_action_button("Delete"); - cy.click_modal_primary_button('Yes'); - cy.wait('@file_deleted'); + cy.click_modal_primary_button("Yes"); + cy.wait("@file_deleted"); //Deleting the Test Folder - cy.visit('/app/file/view/home/Attachments'); - cy.get('.list-row-checkbox').eq(0).click(); + cy.visit("/app/file/view/home/Attachments"); + cy.get(".list-row-checkbox").eq(0).click(); cy.click_action_button("Delete"); - cy.click_modal_primary_button('Yes'); - cy.wait('@file_deleted'); + cy.click_modal_primary_button("Yes"); + cy.wait("@file_deleted"); }); - it('Deleting Test Folder from the home', () => { - //Deleting the Test Folder added in the home directory - cy.visit('/app/file/view/home'); - cy.get('.level-left > .list-subject > .file-select >.list-row-checkbox').eq(0).click({force: true, delay: 500}); + it("Deleting Test Folder from the home", () => { + //Deleting the Test Folder added in the home directory + cy.visit("/app/file/view/home"); + cy.get(".level-left > .list-subject > .file-select >.list-row-checkbox") + .eq(0) + .click({ force: true, delay: 500 }); cy.click_action_button("Delete"); - cy.click_modal_primary_button('Yes'); + cy.click_modal_primary_button("Yes"); }); }); diff --git a/cypress/integration/form.js b/cypress/integration/form.js index 53b87994d7..43ab5350b7 100644 --- a/cypress/integration/form.js +++ b/cypress/integration/form.js @@ -1,107 +1,114 @@ -context('Form', () => { +context("Form", () => { before(() => { cy.login(); - cy.visit('/app/website'); - return cy.window().its('frappe').then(frappe => { - return frappe.call("frappe.tests.ui_test_helpers.create_contact_records"); - }); + cy.visit("/app/website"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.call("frappe.tests.ui_test_helpers.create_contact_records"); + }); }); - it('create a new form', () => { - cy.visit('/app/todo/new'); - cy.get_field('description', 'Text Editor').type('this is a test todo', {force: true}).wait(200); - cy.get('.page-title').should('contain', 'Not Saved'); + it("create a new form", () => { + cy.visit("/app/todo/new"); + cy.get_field("description", "Text Editor") + .type("this is a test todo", { force: true }) + .wait(200); + cy.get(".page-title").should("contain", "Not Saved"); cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.form.save.savedocs' - }).as('form_save'); - cy.get('.primary-action').click(); - cy.wait('@form_save').its('response.statusCode').should('eq', 200); + method: "POST", + url: "api/method/frappe.desk.form.save.savedocs", + }).as("form_save"); + cy.get(".primary-action").click(); + cy.wait("@form_save").its("response.statusCode").should("eq", 200); - cy.go_to_list('ToDo'); - cy.clear_filters() - cy.get('.page-head').findByTitle('To Do').should('exist'); - cy.get('.list-row').should('contain', 'this is a test todo'); + cy.go_to_list("ToDo"); + cy.clear_filters(); + cy.get(".page-head").findByTitle("To Do").should("exist"); + cy.get(".list-row").should("contain", "this is a test todo"); }); - it('navigates between documents with child table list filters applied', () => { - cy.visit('/app/contact'); + it("navigates between documents with child table list filters applied", () => { + cy.visit("/app/contact"); cy.clear_filters(); - cy.get('.standard-filter-section [data-fieldname="name"] input').type('Test Form Contact 3').blur(); - cy.click_listview_row_item_with_text('Test Form Contact 3'); + cy.get('.standard-filter-section [data-fieldname="name"] input') + .type("Test Form Contact 3") + .blur(); + cy.click_listview_row_item_with_text("Test Form Contact 3"); - cy.get('#page-Contact .page-head').findByTitle('Test Form Contact 3').should('exist'); - cy.get('.prev-doc').should('be.visible').click(); - cy.get('.msgprint-dialog .modal-body').contains('No further records').should('be.visible'); + cy.get("#page-Contact .page-head").findByTitle("Test Form Contact 3").should("exist"); + cy.get(".prev-doc").should("be.visible").click(); + cy.get(".msgprint-dialog .modal-body").contains("No further records").should("be.visible"); cy.hide_dialog(); - cy.get('#page-Contact .page-head').findByTitle('Test Form Contact 3').should('exist'); - cy.get('.next-doc').should('be.visible').click(); - cy.get('.msgprint-dialog .modal-body').contains('No further records').should('be.visible'); + cy.get("#page-Contact .page-head").findByTitle("Test Form Contact 3").should("exist"); + cy.get(".next-doc").should("be.visible").click(); + cy.get(".msgprint-dialog .modal-body").contains("No further records").should("be.visible"); cy.hide_dialog(); - cy.get('#page-Contact .page-head').findByTitle('Test Form Contact 3').should('exist'); + cy.get("#page-Contact .page-head").findByTitle("Test Form Contact 3").should("exist"); // clear filters - cy.visit('/app/contact'); + cy.visit("/app/contact"); cy.clear_filters(); }); - it('validates behaviour of Data options validations in child table', () => { + it("validates behaviour of Data options validations in child table", () => { // test email validations for set_invalid controller - let website_input = 'website.in'; - let valid_email = 'user@email.com'; - let expectBackgroundColor = 'rgb(255, 245, 245)'; + let website_input = "website.in"; + let valid_email = "user@email.com"; + let expectBackgroundColor = "rgb(255, 245, 245)"; - cy.visit('/app/contact/new'); - cy.get('.frappe-control[data-fieldname="email_ids"]').as('table'); - cy.get('@table').find('button.grid-add-row').click(); - cy.get('@table').find('button.grid-add-row').click(); - cy.get('@table').find('[data-idx="1"]').as('row1'); - cy.get('@table').find('[data-idx="2"]').as('row2'); - cy.get('@row1').click(); - cy.get('@row1').find('input.input-with-feedback.form-control').as('email_input1'); + cy.visit("/app/contact/new"); + cy.get('.frappe-control[data-fieldname="email_ids"]').as("table"); + cy.get("@table").find("button.grid-add-row").click(); + cy.get("@table").find("button.grid-add-row").click(); + cy.get("@table").find('[data-idx="1"]').as("row1"); + cy.get("@table").find('[data-idx="2"]').as("row2"); + cy.get("@row1").click(); + cy.get("@row1").find("input.input-with-feedback.form-control").as("email_input1"); - cy.get('@email_input1').type(website_input, { waitForAnimations: false }); - cy.fill_field('company_name', 'Test Company'); + cy.get("@email_input1").type(website_input, { waitForAnimations: false }); + cy.fill_field("company_name", "Test Company"); - cy.get('@row2').click(); - cy.get('@row2').find('input.input-with-feedback.form-control').as('email_input2'); - cy.get('@email_input2').type(valid_email, { waitForAnimations: false }); + cy.get("@row2").click(); + cy.get("@row2").find("input.input-with-feedback.form-control").as("email_input2"); + cy.get("@email_input2").type(valid_email, { waitForAnimations: false }); - cy.get('@row1').click(); - cy.get('@email_input1').should($div => { + cy.get("@row1").click(); + cy.get("@email_input1").should(($div) => { const style = window.getComputedStyle($div[0]); expect(style.backgroundColor).to.equal(expectBackgroundColor); }); - cy.get('@email_input1').should('have.class', 'invalid'); + cy.get("@email_input1").should("have.class", "invalid"); - cy.get('@row2').click(); - cy.get('@email_input2').should('not.have.class', 'invalid'); + cy.get("@row2").click(); + cy.get("@email_input2").should("not.have.class", "invalid"); }); - it('Shows version conflict warning', { scrollBehavior: false }, () => { - cy.visit('/app/todo'); + it("Shows version conflict warning", { scrollBehavior: false }, () => { + cy.visit("/app/todo"); - cy.insert_doc("ToDo", {"description": "old"}).then(doc => { + cy.insert_doc("ToDo", { description: "old" }).then((doc) => { cy.visit(`/app/todo/${doc.name}`); // make form dirty cy.fill_field("status", "Cancelled", "Select"); // update doc using api - simulating parallel change by another user - cy.update_doc("ToDo", doc.name, {"status": "Closed"}).then(() => { - cy.findByRole("button", {name: "Refresh"}).click(); + cy.update_doc("ToDo", doc.name, { status: "Closed" }).then(() => { + cy.findByRole("button", { name: "Refresh" }).click(); cy.get_field("status", "Select").should("have.value", "Closed"); - }) - }) + }); + }); }); - it('let user undo/redo field value changes', { scrollBehavior: false }, () => { + it("let user undo/redo field value changes", { scrollBehavior: false }, () => { const jump_to_field = (field_label) => { cy.get("body") - .type("{esc}") // lose focus if any - .type("{ctrl+j}") // jump to field + .type("{esc}") // lose focus if any + .type("{ctrl+j}") // jump to field .type(field_label) .wait(500) .type("{enter}") @@ -111,16 +118,13 @@ context('Form', () => { }; const type_value = (value) => { - cy.focused() - .clear() - .type(value) - .type("{esc}"); + cy.focused().clear().type(value).type("{esc}"); }; const undo = () => cy.get("body").type("{esc}").type("{ctrl+z}").wait(500); const redo = () => cy.get("body").type("{esc}").type("{ctrl+y}").wait(500); - cy.new_form('User'); + cy.new_form("User"); jump_to_field("Email"); type_value("admin@example.com"); @@ -132,7 +136,7 @@ context('Form', () => { type_value("12-31-01"); jump_to_field("Send Welcome Email"); - cy.focused().uncheck() + cy.focused().uncheck(); // make a mistake jump_to_field("Username"); @@ -140,19 +144,27 @@ context('Form', () => { // undo behaviour undo(); - cy.get_field("username").should('have.value', 'admin42'); + cy.get_field("username").should("have.value", "admin42"); // redo behaviour redo(); - cy.get_field("username").should('have.value', 'admin24'); + cy.get_field("username").should("have.value", "admin24"); // undo everything & redo everything, ensure same values at the end - undo(); undo(); undo(); undo(); undo(); - redo(); redo(); redo(); redo(); redo(); + undo(); + undo(); + undo(); + undo(); + undo(); + redo(); + redo(); + redo(); + redo(); + redo(); - cy.get_field("username").should('have.value', 'admin24'); - cy.get_field("email").should('have.value', 'admin@example.com'); - cy.get_field("birth_date").should('have.value', '12-31-2001'); // parsed value - cy.get_field("send_welcome_email").should('not.be.checked'); + cy.get_field("username").should("have.value", "admin24"); + cy.get_field("email").should("have.value", "admin@example.com"); + cy.get_field("birth_date").should("have.value", "12-31-2001"); // parsed value + cy.get_field("send_welcome_email").should("not.be.checked"); }); }); diff --git a/cypress/integration/form_tab_break.js b/cypress/integration/form_tab_break.js index 45c3c92084..91695cb143 100644 --- a/cypress/integration/form_tab_break.js +++ b/cypress/integration/form_tab_break.js @@ -1,31 +1,30 @@ -import doctype_with_tab_break from '../fixtures/doctype_with_tab_break'; +import doctype_with_tab_break from "../fixtures/doctype_with_tab_break"; const doctype_name = doctype_with_tab_break.name; context("Form Tab Break", () => { before(() => { cy.login(); - cy.visit('/app/website'); - return cy.insert_doc('DocType', doctype_with_tab_break, true); + cy.visit("/app/website"); + return cy.insert_doc("DocType", doctype_with_tab_break, true); }); it("Should switch tab and open correct tabs on validation error", () => { cy.new_form(doctype_name); // test tab switch - cy.findByRole("tab", {name: "Tab 2"}).click(); + cy.findByRole("tab", { name: "Tab 2" }).click(); cy.findByText("Phone"); - cy.findByRole("tab", {name: "Details"}).click(); + cy.findByRole("tab", { name: "Details" }).click(); cy.findByText("Name"); // form should switch to the tab with un-filled mandatory field cy.fill_field("username", "Test"); - cy.findByRole("button", {name: "Save"}).click(); + cy.findByRole("button", { name: "Save" }).click(); cy.findByText("Missing Fields"); cy.hide_dialog(); cy.findByText("Phone"); cy.fill_field("phone", "12345678"); - cy.findByRole("button", {name: "Save"}).click(); + cy.findByRole("button", { name: "Save" }).click(); // After save, first tab should have dashboard cy.get(".form-tabs > .nav-item").eq(0).click(); cy.findByText("Connections"); - }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/form_tour.js b/cypress/integration/form_tour.js index 507a07ab1a..f4ae0dbb6d 100644 --- a/cypress/integration/form_tour.js +++ b/cypress/integration/form_tour.js @@ -1,88 +1,94 @@ -context.skip('Form Tour', () => { +context.skip("Form Tour", () => { before(() => { cy.login(); - cy.visit('/app'); - return cy.window().its('frappe').then(frappe => { - return frappe.call("frappe.tests.ui_test_helpers.create_form_tour"); - }); + cy.visit("/app"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.call("frappe.tests.ui_test_helpers.create_form_tour"); + }); }); const open_test_form_tour = () => { - cy.visit('/app/form-tour/Test Form Tour'); - cy.findByRole('button', {name: 'Show Tour'}).should('be.visible').as('show_tour'); - cy.get('@show_tour').click(); + cy.visit("/app/form-tour/Test Form Tour"); + cy.findByRole("button", { name: "Show Tour" }).should("be.visible").as("show_tour"); + cy.get("@show_tour").click(); cy.wait(500); - cy.url().should('include', '/app/contact'); + cy.url().should("include", "/app/contact"); }; - it('jump to a form tour', open_test_form_tour); + it("jump to a form tour", open_test_form_tour); - it('navigates a form tour', () => { + it("navigates a form tour", () => { open_test_form_tour(); - cy.get('.frappe-driver').should('be.visible'); - cy.get('.frappe-control[data-fieldname="first_name"]').as('first_name'); - cy.get('@first_name').should('have.class', 'driver-highlighted-element'); - cy.get('.frappe-driver').findByRole('button', {name: 'Next'}).as('next_btn'); + cy.get(".frappe-driver").should("be.visible"); + cy.get('.frappe-control[data-fieldname="first_name"]').as("first_name"); + cy.get("@first_name").should("have.class", "driver-highlighted-element"); + cy.get(".frappe-driver").findByRole("button", { name: "Next" }).as("next_btn"); // next btn shouldn't move to next step, if first name is not entered - cy.get('@next_btn').click(); + cy.get("@next_btn").click(); cy.wait(500); - cy.get('@first_name').should('have.class', 'driver-highlighted-element'); + cy.get("@first_name").should("have.class", "driver-highlighted-element"); // after filling the field, next step should be highlighted - cy.fill_field('first_name', 'Test Name', 'Data'); + cy.fill_field("first_name", "Test Name", "Data"); cy.wait(500); - cy.get('@next_btn').click(); + cy.get("@next_btn").click(); cy.wait(500); // assert field is highlighted - cy.get('.frappe-control[data-fieldname="last_name"]').as('last_name'); - cy.get('@last_name').should('have.class', 'driver-highlighted-element'); + cy.get('.frappe-control[data-fieldname="last_name"]').as("last_name"); + cy.get("@last_name").should("have.class", "driver-highlighted-element"); // after filling the field, next step should be highlighted - cy.fill_field('last_name', 'Test Last Name', 'Data'); + cy.fill_field("last_name", "Test Last Name", "Data"); cy.wait(500); - cy.get('@next_btn').click(); + cy.get("@next_btn").click(); cy.wait(500); // assert field is highlighted - cy.get('.frappe-control[data-fieldname="phone_nos"]').as('phone_nos'); - cy.get('@phone_nos').should('have.class', 'driver-highlighted-element'); + cy.get('.frappe-control[data-fieldname="phone_nos"]').as("phone_nos"); + cy.get("@phone_nos").should("have.class", "driver-highlighted-element"); // move to next step cy.wait(500); - cy.get('@next_btn').click(); + cy.get("@next_btn").click(); cy.wait(500); // assert add row btn is highlighted - cy.get('@phone_nos').find('.grid-add-row').as('add_row'); - cy.get('@add_row').should('have.class', 'driver-highlighted-element'); + cy.get("@phone_nos").find(".grid-add-row").as("add_row"); + cy.get("@add_row").should("have.class", "driver-highlighted-element"); // add a row & move to next step cy.wait(500); - cy.get('@add_row').click(); + cy.get("@add_row").click(); cy.wait(500); // assert table field is highlighted - cy.get('.grid-row-open .frappe-control[data-fieldname="phone"]').as('phone'); - cy.get('@phone').should('have.class', 'driver-highlighted-element'); + cy.get('.grid-row-open .frappe-control[data-fieldname="phone"]').as("phone"); + cy.get("@phone").should("have.class", "driver-highlighted-element"); // enter value in a table field - let field = cy.fill_table_field('phone_nos', '1', 'phone', '1234567890'); + let field = cy.fill_table_field("phone_nos", "1", "phone", "1234567890"); field.blur(); // move to collapse row step cy.wait(500); - cy.get('.driver-popover-title').contains('Test Title 4').siblings().get('@next_btn').click(); + cy.get(".driver-popover-title") + .contains("Test Title 4") + .siblings() + .get("@next_btn") + .click(); cy.wait(500); // collapse row - cy.get('.grid-row-open .grid-collapse-row').click(); + cy.get(".grid-row-open .grid-collapse-row").click(); cy.wait(500); // assert save btn is highlighted - cy.get('.primary-action').should('have.class', 'driver-highlighted-element'); + cy.get(".primary-action").should("have.class", "driver-highlighted-element"); cy.wait(500); - cy.get('.frappe-driver').findByRole('button', {name: 'Save'}).should('be.visible'); - + cy.get(".frappe-driver").findByRole("button", { name: "Save" }).should("be.visible"); }); }); diff --git a/cypress/integration/grid.js b/cypress/integration/grid.js index 4fa52712cf..6cf9e8cdc7 100644 --- a/cypress/integration/grid.js +++ b/cypress/integration/grid.js @@ -1,92 +1,114 @@ -context('Grid', () => { +context("Grid", () => { beforeEach(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); before(() => { cy.login(); - cy.visit('/app/website'); - return cy.window().its('frappe').then(frappe => { - return frappe.call("frappe.tests.ui_test_helpers.create_contact_phone_nos_records"); - }); + cy.visit("/app/website"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.call( + "frappe.tests.ui_test_helpers.create_contact_phone_nos_records" + ); + }); }); - it('update docfield property using update_docfield_property', () => { - cy.visit('/app/contact/Test Contact'); - cy.window().its("cur_frm").then(frm => { - cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); - let field = frm.get_field("phone_nos"); - field.grid.update_docfield_property("is_primary_phone", "hidden", true); + it("update docfield property using update_docfield_property", () => { + cy.visit("/app/contact/Test Contact"); + cy.window() + .its("cur_frm") + .then((frm) => { + cy.get('.frappe-control[data-fieldname="phone_nos"]').as("table"); + let field = frm.get_field("phone_nos"); + field.grid.update_docfield_property("is_primary_phone", "hidden", true); - cy.get('@table').find('[data-idx="1"] .edit-grid-row').click(); - cy.get('.grid-row-open').as('table-form'); - cy.get('@table-form').find('.frappe-control[data-fieldname="is_primary_phone"]').should("be.hidden"); - cy.get('@table-form').find('.grid-footer-toolbar').click(); + cy.get("@table").find('[data-idx="1"] .edit-grid-row').click(); + cy.get(".grid-row-open").as("table-form"); + cy.get("@table-form") + .find('.frappe-control[data-fieldname="is_primary_phone"]') + .should("be.hidden"); + cy.get("@table-form").find(".grid-footer-toolbar").click(); - cy.get('@table').find('[data-idx="2"] .edit-grid-row').click(); - cy.get('.grid-row-open').as('table-form'); - cy.get('@table-form').find('.frappe-control[data-fieldname="is_primary_phone"]').should("be.hidden"); - cy.get('@table-form').find('.grid-footer-toolbar').click(); - }); + cy.get("@table").find('[data-idx="2"] .edit-grid-row').click(); + cy.get(".grid-row-open").as("table-form"); + cy.get("@table-form") + .find('.frappe-control[data-fieldname="is_primary_phone"]') + .should("be.hidden"); + cy.get("@table-form").find(".grid-footer-toolbar").click(); + }); }); - it('update docfield property using toggle_display', () => { - cy.visit('/app/contact/Test Contact'); - cy.window().its("cur_frm").then(frm => { - cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); - let field = frm.get_field("phone_nos"); - field.grid.toggle_display("is_primary_mobile_no", false); + it("update docfield property using toggle_display", () => { + cy.visit("/app/contact/Test Contact"); + cy.window() + .its("cur_frm") + .then((frm) => { + cy.get('.frappe-control[data-fieldname="phone_nos"]').as("table"); + let field = frm.get_field("phone_nos"); + field.grid.toggle_display("is_primary_mobile_no", false); - cy.get('@table').find('[data-idx="1"] .edit-grid-row').click(); - cy.get('.grid-row-open').as('table-form'); - cy.get('@table-form').find('.frappe-control[data-fieldname="is_primary_mobile_no"]').should("be.hidden"); - cy.get('@table-form').find('.grid-footer-toolbar').click(); + cy.get("@table").find('[data-idx="1"] .edit-grid-row').click(); + cy.get(".grid-row-open").as("table-form"); + cy.get("@table-form") + .find('.frappe-control[data-fieldname="is_primary_mobile_no"]') + .should("be.hidden"); + cy.get("@table-form").find(".grid-footer-toolbar").click(); - cy.get('@table').find('[data-idx="2"] .edit-grid-row').click(); - cy.get('.grid-row-open').as('table-form'); - cy.get('@table-form').find('.frappe-control[data-fieldname="is_primary_mobile_no"]').should("be.hidden"); - cy.get('@table-form').find('.grid-footer-toolbar').click(); - }); + cy.get("@table").find('[data-idx="2"] .edit-grid-row').click(); + cy.get(".grid-row-open").as("table-form"); + cy.get("@table-form") + .find('.frappe-control[data-fieldname="is_primary_mobile_no"]') + .should("be.hidden"); + cy.get("@table-form").find(".grid-footer-toolbar").click(); + }); }); - it('update docfield property using toggle_enable', () => { - cy.visit('/app/contact/Test Contact'); - cy.window().its("cur_frm").then(frm => { - cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); - let field = frm.get_field("phone_nos"); - field.grid.toggle_enable("phone", false); + it("update docfield property using toggle_enable", () => { + cy.visit("/app/contact/Test Contact"); + cy.window() + .its("cur_frm") + .then((frm) => { + cy.get('.frappe-control[data-fieldname="phone_nos"]').as("table"); + let field = frm.get_field("phone_nos"); + field.grid.toggle_enable("phone", false); + cy.get("@table").find('[data-idx="1"] .edit-grid-row').click(); + cy.get(".grid-row-open").as("table-form"); + cy.get("@table-form") + .find('.frappe-control[data-fieldname="phone"] .control-value') + .should("have.class", "like-disabled-input"); + cy.get("@table-form").find(".grid-footer-toolbar").click(); - cy.get('@table').find('[data-idx="1"] .edit-grid-row').click(); - cy.get('.grid-row-open').as('table-form'); - cy.get('@table-form').find('.frappe-control[data-fieldname="phone"] .control-value').should('have.class', 'like-disabled-input'); - cy.get('@table-form').find('.grid-footer-toolbar').click(); - - cy.get('@table').find('[data-idx="2"] .edit-grid-row').click(); - cy.get('.grid-row-open').as('table-form'); - cy.get('@table-form').find('.frappe-control[data-fieldname="phone"] .control-value').should('have.class', 'like-disabled-input'); - cy.get('@table-form').find('.grid-footer-toolbar').click(); - }); + cy.get("@table").find('[data-idx="2"] .edit-grid-row').click(); + cy.get(".grid-row-open").as("table-form"); + cy.get("@table-form") + .find('.frappe-control[data-fieldname="phone"] .control-value') + .should("have.class", "like-disabled-input"); + cy.get("@table-form").find(".grid-footer-toolbar").click(); + }); }); - it('update docfield property using toggle_reqd', () => { - cy.visit('/app/contact/Test Contact'); - cy.window().its("cur_frm").then(frm => { - cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); - let field = frm.get_field("phone_nos"); - field.grid.toggle_reqd("phone", false); + it("update docfield property using toggle_reqd", () => { + cy.visit("/app/contact/Test Contact"); + cy.window() + .its("cur_frm") + .then((frm) => { + cy.get('.frappe-control[data-fieldname="phone_nos"]').as("table"); + let field = frm.get_field("phone_nos"); + field.grid.toggle_reqd("phone", false); - cy.get('@table').find('[data-idx="1"] .edit-grid-row').click(); - cy.get('.grid-row-open').as('table-form'); - cy.get_field("phone").as('phone-field'); - cy.get('@phone-field').focus().clear().wait(500).blur(); - cy.get('@phone-field').should("not.have.class", "has-error"); - cy.get('@table-form').find('.grid-footer-toolbar').click(); + cy.get("@table").find('[data-idx="1"] .edit-grid-row').click(); + cy.get(".grid-row-open").as("table-form"); + cy.get_field("phone").as("phone-field"); + cy.get("@phone-field").focus().clear().wait(500).blur(); + cy.get("@phone-field").should("not.have.class", "has-error"); + cy.get("@table-form").find(".grid-footer-toolbar").click(); - cy.get('@table').find('[data-idx="2"] .edit-grid-row').click(); - cy.get('.grid-row-open').as('table-form'); - cy.get_field("phone").as('phone-field'); - cy.get('@phone-field').focus().clear().wait(500).blur(); - cy.get('@phone-field').should("not.have.class", "has-error"); - cy.get('@table-form').find('.grid-footer-toolbar').click(); - - }); + cy.get("@table").find('[data-idx="2"] .edit-grid-row').click(); + cy.get(".grid-row-open").as("table-form"); + cy.get_field("phone").as("phone-field"); + cy.get("@phone-field").focus().clear().wait(500).blur(); + cy.get("@phone-field").should("not.have.class", "has-error"); + cy.get("@table-form").find(".grid-footer-toolbar").click(); + }); }); }); - diff --git a/cypress/integration/grid_configuration.js b/cypress/integration/grid_configuration.js index 7193d804c2..9112d7023e 100644 --- a/cypress/integration/grid_configuration.js +++ b/cypress/integration/grid_configuration.js @@ -1,23 +1,23 @@ -context('Grid Configuration', () => { +context("Grid Configuration", () => { beforeEach(() => { cy.login(); - cy.visit('/app/doctype/User'); + cy.visit("/app/doctype/User"); }); - it('Set user wise grid settings', () => { + it("Set user wise grid settings", () => { cy.wait(100); - cy.get('.frappe-control[data-fieldname="fields"]').as('table'); - cy.get('@table').find('.icon-sm').click(); + cy.get('.frappe-control[data-fieldname="fields"]').as("table"); + cy.get("@table").find(".icon-sm").click(); cy.wait(100); - cy.get('.frappe-control[data-fieldname="fields_html"]').as('modal'); - cy.get('@modal').find('.add-new-fields').click(); + cy.get('.frappe-control[data-fieldname="fields_html"]').as("modal"); + cy.get("@modal").find(".add-new-fields").click(); cy.wait(100); cy.get('[type="checkbox"][data-unit="read_only"]').check(); - cy.findByRole('button', {name: 'Add'}).click(); + cy.findByRole("button", { name: "Add" }).click(); cy.wait(100); - cy.get('[data-fieldname="options"]').invoke('attr', 'value', '1'); - cy.get('.form-control.column-width[data-fieldname="options"]').trigger('change'); - cy.findByRole('button', {name: 'Update'}).click(); + cy.get('[data-fieldname="options"]').invoke("attr", "value", "1"); + cy.get('.form-control.column-width[data-fieldname="options"]').trigger("change"); + cy.findByRole("button", { name: "Update" }).click(); cy.wait(200); - cy.get('[title="Read Only"').should('be.visible'); + cy.get('[title="Read Only"').should("be.visible"); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/grid_keyboard_shortcut.js b/cypress/integration/grid_keyboard_shortcut.js index 9cf39165ad..414e822516 100644 --- a/cypress/integration/grid_keyboard_shortcut.js +++ b/cypress/integration/grid_keyboard_shortcut.js @@ -1,40 +1,47 @@ -context('Grid Keyboard Shortcut', () => { +context("Grid Keyboard Shortcut", () => { let total_count = 0; before(() => { cy.login(); }); beforeEach(() => { cy.reload(); - cy.visit('/app/contact/new-contact-1'); + cy.visit("/app/contact/new-contact-1"); cy.get('.frappe-control[data-fieldname="email_ids"]').find(".grid-add-row").click(); }); - it('Insert new row at the end', () => { - cy.add_new_row_in_grid('{ctrl}{shift}{downarrow}', (cy, total_count) => { - cy.get('[data-name="new-contact-email-1"]').should('have.attr', 'data-idx', `${total_count+1}`); - }, total_count); + it("Insert new row at the end", () => { + cy.add_new_row_in_grid( + "{ctrl}{shift}{downarrow}", + (cy, total_count) => { + cy.get('[data-name="new-contact-email-1"]').should( + "have.attr", + "data-idx", + `${total_count + 1}` + ); + }, + total_count + ); }); - it('Insert new row at the top', () => { - cy.add_new_row_in_grid('{ctrl}{shift}{uparrow}', (cy) => { - cy.get('[data-name="new-contact-email-1"]').should('have.attr', 'data-idx', '2'); + it("Insert new row at the top", () => { + cy.add_new_row_in_grid("{ctrl}{shift}{uparrow}", (cy) => { + cy.get('[data-name="new-contact-email-1"]').should("have.attr", "data-idx", "2"); }); }); - it('Insert new row below', () => { - cy.add_new_row_in_grid('{ctrl}{downarrow}', (cy) => { - cy.get('[data-name="new-contact-email-1"]').should('have.attr', 'data-idx', '1'); + it("Insert new row below", () => { + cy.add_new_row_in_grid("{ctrl}{downarrow}", (cy) => { + cy.get('[data-name="new-contact-email-1"]').should("have.attr", "data-idx", "1"); }); }); - it('Insert new row above', () => { - cy.add_new_row_in_grid('{ctrl}{uparrow}', (cy) => { - cy.get('[data-name="new-contact-email-1"]').should('have.attr', 'data-idx', '2'); + it("Insert new row above", () => { + cy.add_new_row_in_grid("{ctrl}{uparrow}", (cy) => { + cy.get('[data-name="new-contact-email-1"]').should("have.attr", "data-idx", "2"); }); }); }); -Cypress.Commands.add('add_new_row_in_grid', (shortcut_keys, callbackFn, total_count) => { - cy.get('.frappe-control[data-fieldname="email_ids"]').as('table'); - cy.get('@table').find('.grid-body [data-fieldname="email_id"]').first().click(); - cy.get('@table').find('.grid-body [data-fieldname="email_id"]') - .first().type(shortcut_keys); +Cypress.Commands.add("add_new_row_in_grid", (shortcut_keys, callbackFn, total_count) => { + cy.get('.frappe-control[data-fieldname="email_ids"]').as("table"); + cy.get("@table").find('.grid-body [data-fieldname="email_id"]').first().click(); + cy.get("@table").find('.grid-body [data-fieldname="email_id"]').first().type(shortcut_keys); callbackFn(cy, total_count); -}); \ No newline at end of file +}); diff --git a/cypress/integration/grid_pagination.js b/cypress/integration/grid_pagination.js index 84b3320282..097f2a5cdc 100644 --- a/cypress/integration/grid_pagination.js +++ b/cypress/integration/grid_pagination.js @@ -1,65 +1,73 @@ -context('Grid Pagination', () => { +context("Grid Pagination", () => { beforeEach(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); before(() => { cy.login(); - cy.visit('/app/website'); - return cy.window().its('frappe').then(frappe => { - return frappe.call("frappe.tests.ui_test_helpers.create_contact_phone_nos_records"); - }); + cy.visit("/app/website"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.call( + "frappe.tests.ui_test_helpers.create_contact_phone_nos_records" + ); + }); }); - it('creates pages for child table', () => { - cy.visit('/app/contact/Test Contact'); - cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); - cy.get('@table').find('.current-page-number').should('have.value', '1'); - cy.get('@table').find('.total-page-number').should('contain', '20'); - cy.get('@table').find('.grid-body .grid-row').should('have.length', 50); + it("creates pages for child table", () => { + cy.visit("/app/contact/Test Contact"); + cy.get('.frappe-control[data-fieldname="phone_nos"]').as("table"); + cy.get("@table").find(".current-page-number").should("have.value", "1"); + cy.get("@table").find(".total-page-number").should("contain", "20"); + cy.get("@table").find(".grid-body .grid-row").should("have.length", 50); }); - it('goes to the next and previous page', () => { - cy.visit('/app/contact/Test Contact'); - cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); - cy.get('@table').find('.next-page').click(); - cy.get('@table').find('.current-page-number').should('have.value', '2'); - cy.get('@table').find('.grid-body .grid-row').first().should('have.attr', 'data-idx', '51'); - cy.get('@table').find('.prev-page').click(); - cy.get('@table').find('.current-page-number').should('have.value', '1'); - cy.get('@table').find('.grid-body .grid-row').first().should('have.attr', 'data-idx', '1'); + it("goes to the next and previous page", () => { + cy.visit("/app/contact/Test Contact"); + cy.get('.frappe-control[data-fieldname="phone_nos"]').as("table"); + cy.get("@table").find(".next-page").click(); + cy.get("@table").find(".current-page-number").should("have.value", "2"); + cy.get("@table") + .find(".grid-body .grid-row") + .first() + .should("have.attr", "data-idx", "51"); + cy.get("@table").find(".prev-page").click(); + cy.get("@table").find(".current-page-number").should("have.value", "1"); + cy.get("@table").find(".grid-body .grid-row").first().should("have.attr", "data-idx", "1"); }); - it('adds and deletes rows and changes page', () => { - cy.visit('/app/contact/Test Contact'); - cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); - cy.get('@table').findByRole('button', {name: 'Add Row'}).click(); - cy.get('@table').find('.grid-body .row-index').should('contain', 1001); - cy.get('@table').find('.current-page-number').should('have.value', '21'); - cy.get('@table').find('.total-page-number').should('contain', '21'); - cy.get('@table').find('.grid-body .grid-row .grid-row-check').click({ force: true }); - cy.get('@table').findByRole('button', {name: 'Delete'}).click(); - cy.get('@table').find('.grid-body .row-index').last().should('contain', 1000); - cy.get('@table').find('.current-page-number').should('have.value', '20'); - cy.get('@table').find('.total-page-number').should('contain', '20'); + it("adds and deletes rows and changes page", () => { + cy.visit("/app/contact/Test Contact"); + cy.get('.frappe-control[data-fieldname="phone_nos"]').as("table"); + cy.get("@table").findByRole("button", { name: "Add Row" }).click(); + cy.get("@table").find(".grid-body .row-index").should("contain", 1001); + cy.get("@table").find(".current-page-number").should("have.value", "21"); + cy.get("@table").find(".total-page-number").should("contain", "21"); + cy.get("@table").find(".grid-body .grid-row .grid-row-check").click({ force: true }); + cy.get("@table").findByRole("button", { name: "Delete" }).click(); + cy.get("@table").find(".grid-body .row-index").last().should("contain", 1000); + cy.get("@table").find(".current-page-number").should("have.value", "20"); + cy.get("@table").find(".total-page-number").should("contain", "20"); }); - it('go to specific page, use up and down arrow, type characters, 0 page and more than existing page', () => { - cy.visit('/app/contact/Test Contact'); - cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); - cy.get('@table').find('.current-page-number').focus().clear().type('17').blur(); - cy.get('@table').find('.grid-body .row-index').should('contain', 801); + it("go to specific page, use up and down arrow, type characters, 0 page and more than existing page", () => { + cy.visit("/app/contact/Test Contact"); + cy.get('.frappe-control[data-fieldname="phone_nos"]').as("table"); + cy.get("@table").find(".current-page-number").focus().clear().type("17").blur(); + cy.get("@table").find(".grid-body .row-index").should("contain", 801); - cy.get('@table').find('.current-page-number').focus().type('{uparrow}{uparrow}'); - cy.get('@table').find('.current-page-number').should('have.value', '19'); + cy.get("@table").find(".current-page-number").focus().type("{uparrow}{uparrow}"); + cy.get("@table").find(".current-page-number").should("have.value", "19"); - cy.get('@table').find('.current-page-number').focus().type('{downarrow}{downarrow}'); - cy.get('@table').find('.current-page-number').should('have.value', '17'); + cy.get("@table").find(".current-page-number").focus().type("{downarrow}{downarrow}"); + cy.get("@table").find(".current-page-number").should("have.value", "17"); - cy.get('@table').find('.current-page-number').focus().clear().type('700').blur(); - cy.get('@table').find('.current-page-number').should('have.value', '20'); + cy.get("@table").find(".current-page-number").focus().clear().type("700").blur(); + cy.get("@table").find(".current-page-number").should("have.value", "20"); - cy.get('@table').find('.current-page-number').focus().clear().type('0').blur(); - cy.get('@table').find('.current-page-number').should('have.value', '1'); + cy.get("@table").find(".current-page-number").focus().clear().type("0").blur(); + cy.get("@table").find(".current-page-number").should("have.value", "1"); - cy.get('@table').find('.current-page-number').focus().clear().type('abc').blur(); - cy.get('@table').find('.current-page-number').should('have.value', '1'); + cy.get("@table").find(".current-page-number").focus().clear().type("abc").blur(); + cy.get("@table").find(".current-page-number").should("have.value", "1"); }); // it('deletes all rows', ()=> { // cy.visit('/app/contact/Test Contact'); @@ -69,4 +77,4 @@ context('Grid Pagination', () => { // cy.get('.modal-dialog .btn-primary').contains('Yes').click(); // cy.get('@table').find('.grid-body .grid-row').should('have.length', 0); // }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/grid_search.js b/cypress/integration/grid_search.js index d30545a2e1..3d43412313 100644 --- a/cypress/integration/grid_search.js +++ b/cypress/integration/grid_search.js @@ -1,107 +1,133 @@ -import doctype_with_child_table from '../fixtures/doctype_with_child_table'; -import child_table_doctype from '../fixtures/child_table_doctype'; -import child_table_doctype_1 from '../fixtures/child_table_doctype_1'; +import doctype_with_child_table from "../fixtures/doctype_with_child_table"; +import child_table_doctype from "../fixtures/child_table_doctype"; +import child_table_doctype_1 from "../fixtures/child_table_doctype_1"; const doctype_with_child_table_name = doctype_with_child_table.name; -context('Grid Search', () => { +context("Grid Search", () => { before(() => { - cy.visit('/login'); + cy.visit("/login"); cy.login(); - cy.visit('/app/website'); - cy.insert_doc('DocType', child_table_doctype, true); - cy.insert_doc('DocType', child_table_doctype_1, true); - cy.insert_doc('DocType', doctype_with_child_table, true); - return cy.window().its('frappe').then(frappe => { - return frappe.xcall("frappe.tests.ui_test_helpers.insert_doctype_with_child_table_record", { - name: doctype_with_child_table_name + cy.visit("/app/website"); + cy.insert_doc("DocType", child_table_doctype, true); + cy.insert_doc("DocType", child_table_doctype_1, true); + cy.insert_doc("DocType", doctype_with_child_table, true); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.xcall( + "frappe.tests.ui_test_helpers.insert_doctype_with_child_table_record", + { + name: doctype_with_child_table_name, + } + ); }); - }); }); - it('Test search row visibility', () => { - cy.window().its('frappe').then(frappe => { - frappe.model.user_settings.save('Doctype With Child Table', 'GridView', { - 'Child Table Doctype 1': [ - {'fieldname': 'data', 'columns': 2}, - {'fieldname': 'barcode', 'columns': 1}, - {'fieldname': 'check', 'columns': 1}, - {'fieldname': 'rating', 'columns': 2}, - {'fieldname': 'duration', 'columns': 2}, - {'fieldname': 'date', 'columns': 2} - ] + it("Test search row visibility", () => { + cy.window() + .its("frappe") + .then((frappe) => { + frappe.model.user_settings.save("Doctype With Child Table", "GridView", { + "Child Table Doctype 1": [ + { fieldname: "data", columns: 2 }, + { fieldname: "barcode", columns: 1 }, + { fieldname: "check", columns: 1 }, + { fieldname: "rating", columns: 2 }, + { fieldname: "duration", columns: 2 }, + { fieldname: "date", columns: 2 }, + ], + }); }); - }); cy.visit(`/app/doctype-with-child-table/Test Grid Search`); - cy.get('.frappe-control[data-fieldname="child_table_1"]').as('table'); - cy.get('@table').find('.grid-row-check:last').click(); - cy.get('@table').find('.grid-footer').contains('Delete').click(); - cy.get('.grid-heading-row .grid-row .search').should('not.exist'); + cy.get('.frappe-control[data-fieldname="child_table_1"]').as("table"); + cy.get("@table").find(".grid-row-check:last").click(); + cy.get("@table").find(".grid-footer").contains("Delete").click(); + cy.get(".grid-heading-row .grid-row .search").should("not.exist"); }); - it('test search field for different fieldtypes', () => { + it("test search field for different fieldtypes", () => { cy.visit(`/app/doctype-with-child-table/Test Grid Search`); - cy.get('.frappe-control[data-fieldname="child_table_1"]').as('table'); + cy.get('.frappe-control[data-fieldname="child_table_1"]').as("table"); // Index Column - cy.get('@table').find('.grid-heading-row .row-index.search input').type('3'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 2); - cy.get('@table').find('.grid-heading-row .row-index.search input').clear(); + cy.get("@table").find(".grid-heading-row .row-index.search input").type("3"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 2); + cy.get("@table").find(".grid-heading-row .row-index.search input").clear(); // Data Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Data"]').type('Data'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 1); - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Data"]').clear(); + cy.get("@table") + .find('.grid-heading-row .search input[data-fieldtype="Data"]') + .type("Data"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 1); + cy.get("@table").find('.grid-heading-row .search input[data-fieldtype="Data"]').clear(); // Barcode Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Barcode"]').type('092'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 4); - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Barcode"]').clear(); + cy.get("@table") + .find('.grid-heading-row .search input[data-fieldtype="Barcode"]') + .type("092"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 4); + cy.get("@table").find('.grid-heading-row .search input[data-fieldtype="Barcode"]').clear(); // Check Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Check"]').type('1'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 9); - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Check"]').clear(); + cy.get("@table").find('.grid-heading-row .search input[data-fieldtype="Check"]').type("1"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 9); + cy.get("@table").find('.grid-heading-row .search input[data-fieldtype="Check"]').clear(); - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Check"]').type('0'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 11); - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Check"]').clear(); + cy.get("@table").find('.grid-heading-row .search input[data-fieldtype="Check"]').type("0"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 11); + cy.get("@table").find('.grid-heading-row .search input[data-fieldtype="Check"]').clear(); // Rating Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Rating"]').type('3'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 3); - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Rating"]').clear(); + cy.get("@table") + .find('.grid-heading-row .search input[data-fieldtype="Rating"]') + .type("3"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 3); + cy.get("@table").find('.grid-heading-row .search input[data-fieldtype="Rating"]').clear(); // Duration Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Duration"]').type('3d'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 3); - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Duration"]').clear(); + cy.get("@table") + .find('.grid-heading-row .search input[data-fieldtype="Duration"]') + .type("3d"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 3); + cy.get("@table") + .find('.grid-heading-row .search input[data-fieldtype="Duration"]') + .clear(); // Date Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Date"]').type('2022'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 4); - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Date"]').clear(); + cy.get("@table") + .find('.grid-heading-row .search input[data-fieldtype="Date"]') + .type("2022"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 4); + cy.get("@table").find('.grid-heading-row .search input[data-fieldtype="Date"]').clear(); }); - it('test with multiple filter', () => { - cy.get('.frappe-control[data-fieldname="child_table_1"]').as('table'); + it("test with multiple filter", () => { + cy.get('.frappe-control[data-fieldname="child_table_1"]').as("table"); // Data Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Data"]').type('a'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 10); + cy.get("@table").find('.grid-heading-row .search input[data-fieldtype="Data"]').type("a"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 10); // Barcode Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Barcode"]').type('0'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 8); + cy.get("@table") + .find('.grid-heading-row .search input[data-fieldtype="Barcode"]') + .type("0"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 8); // Duration Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Duration"]').type('d'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 5); + cy.get("@table") + .find('.grid-heading-row .search input[data-fieldtype="Duration"]') + .type("d"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 5); // Date Column - cy.get('@table').find('.grid-heading-row .search input[data-fieldtype="Date"]').type('02-'); - cy.get('@table').find('.grid-body .rows .grid-row').should('have.length', 2); + cy.get("@table") + .find('.grid-heading-row .search input[data-fieldtype="Date"]') + .type("02-"); + cy.get("@table").find(".grid-body .rows .grid-row").should("have.length", 2); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/kanban.js b/cypress/integration/kanban.js index 6ebab5d008..7296a12666 100644 --- a/cypress/integration/kanban.js +++ b/cypress/integration/kanban.js @@ -1,75 +1,100 @@ -context('Kanban Board', () => { +context("Kanban Board", () => { before(() => { cy.login(); - cy.visit('/app'); + cy.visit("/app"); }); - it('Create ToDo Kanban', () => { - cy.visit('/app/todo'); + it("Create ToDo Kanban", () => { + cy.visit("/app/todo"); - cy.get('.page-actions .custom-btn-group button').click(); - cy.get('.page-actions .custom-btn-group ul.dropdown-menu li').contains('Kanban').click(); + cy.get(".page-actions .custom-btn-group button").click(); + cy.get(".page-actions .custom-btn-group ul.dropdown-menu li").contains("Kanban").click(); cy.focused().blur(); - cy.fill_field('board_name', 'ToDo Kanban', 'Data'); - cy.fill_field('field_name', 'Status', 'Select'); - cy.click_modal_primary_button('Save'); + cy.fill_field("board_name", "ToDo Kanban", "Data"); + cy.fill_field("field_name", "Status", "Select"); + cy.click_modal_primary_button("Save"); - cy.get('.title-text').should('contain', 'ToDo Kanban'); + cy.get(".title-text").should("contain", "ToDo Kanban"); }); - it('Create ToDo from kanban', () => { + it("Create ToDo from kanban", () => { cy.intercept({ - method: 'POST', - url: 'api/method/frappe.client.save' - }).as('save-todo'); + method: "POST", + url: "api/method/frappe.client.save", + }).as("save-todo"); - cy.click_listview_primary_button('Add ToDo'); + cy.click_listview_primary_button("Add ToDo"); - cy.fill_field('description', 'Test Kanban ToDo', 'Text Editor').wait(300); - cy.get('.modal-footer .btn-primary').last().click(); + cy.fill_field("description", "Test Kanban ToDo", "Text Editor").wait(300); + cy.get(".modal-footer .btn-primary").last().click(); - cy.wait('@save-todo'); + cy.wait("@save-todo"); }); - it('Add and Remove fields', () => { - cy.visit('/app/todo/view/kanban/ToDo Kanban'); + it("Add and Remove fields", () => { + cy.visit("/app/todo/view/kanban/ToDo Kanban"); - cy.intercept('POST', '/api/method/frappe.desk.doctype.kanban_board.kanban_board.save_settings').as('save-kanban'); - cy.intercept('POST', '/api/method/frappe.desk.doctype.kanban_board.kanban_board.update_order').as('update-order'); + cy.intercept( + "POST", + "/api/method/frappe.desk.doctype.kanban_board.kanban_board.save_settings" + ).as("save-kanban"); + cy.intercept( + "POST", + "/api/method/frappe.desk.doctype.kanban_board.kanban_board.update_order" + ).as("update-order"); - cy.get('.page-actions .menu-btn-group > .btn').click(); - cy.get('.page-actions .menu-btn-group .dropdown-menu li').contains('Kanban Settings').click(); - cy.get('.add-new-fields').click(); + cy.get(".page-actions .menu-btn-group > .btn").click(); + cy.get(".page-actions .menu-btn-group .dropdown-menu li") + .contains("Kanban Settings") + .click(); + cy.get(".add-new-fields").click(); - cy.get('.checkbox-options .checkbox').contains('ID').click(); - cy.get('.checkbox-options .checkbox').contains('Status').first().click(); - cy.get('.checkbox-options .checkbox').contains('Priority').click(); + cy.get(".checkbox-options .checkbox").contains("ID").click(); + cy.get(".checkbox-options .checkbox").contains("Status").first().click(); + cy.get(".checkbox-options .checkbox").contains("Priority").click(); - cy.get('.modal-footer .btn-primary').last().click(); + cy.get(".modal-footer .btn-primary").last().click(); - cy.get('.frappe-control .label-area').contains('Show Labels').click(); - cy.click_modal_primary_button('Save'); + cy.get(".frappe-control .label-area").contains("Show Labels").click(); + cy.click_modal_primary_button("Save"); - cy.wait('@save-kanban'); + cy.wait("@save-kanban"); - cy.get('.kanban-column[data-column-value="Open"] .kanban-cards').as('open-cards'); - cy.get('@open-cards').find('.kanban-card .kanban-card-doc').first().should('contain', 'ID:'); - cy.get('@open-cards').find('.kanban-card .kanban-card-doc').first().should('contain', 'Status:'); - cy.get('@open-cards').find('.kanban-card .kanban-card-doc').first().should('contain', 'Priority:'); + cy.get('.kanban-column[data-column-value="Open"] .kanban-cards').as("open-cards"); + cy.get("@open-cards") + .find(".kanban-card .kanban-card-doc") + .first() + .should("contain", "ID:"); + cy.get("@open-cards") + .find(".kanban-card .kanban-card-doc") + .first() + .should("contain", "Status:"); + cy.get("@open-cards") + .find(".kanban-card .kanban-card-doc") + .first() + .should("contain", "Priority:"); - cy.get('.page-actions .menu-btn-group > .btn').click(); - cy.get('.page-actions .menu-btn-group .dropdown-menu li').contains('Kanban Settings').click(); - cy.get_open_dialog().find('.frappe-control[data-fieldname="fields_html"] div[data-label="ID"] .remove-field').click(); + cy.get(".page-actions .menu-btn-group > .btn").click(); + cy.get(".page-actions .menu-btn-group .dropdown-menu li") + .contains("Kanban Settings") + .click(); + cy.get_open_dialog() + .find( + '.frappe-control[data-fieldname="fields_html"] div[data-label="ID"] .remove-field' + ) + .click(); - cy.wait('@update-order'); - cy.get_open_dialog().find('.frappe-control .label-area').contains('Show Labels').click(); - cy.get('.modal-footer .btn-primary').last().click(); + cy.wait("@update-order"); + cy.get_open_dialog().find(".frappe-control .label-area").contains("Show Labels").click(); + cy.get(".modal-footer .btn-primary").last().click(); - cy.wait('@save-kanban'); - - cy.get('@open-cards').find('.kanban-card .kanban-card-doc').first().should('not.contain', 'ID:'); + cy.wait("@save-kanban"); + cy.get("@open-cards") + .find(".kanban-card .kanban-card-doc") + .first() + .should("not.contain", "ID:"); }); // it('Drag todo', () => { @@ -84,4 +109,4 @@ context('Kanban Board', () => { // cy.wait('@drag-completed'); // }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/list_paging.js b/cypress/integration/list_paging.js index 0cf6f2e565..3071950260 100644 --- a/cypress/integration/list_paging.js +++ b/cypress/integration/list_paging.js @@ -1,39 +1,42 @@ -context('List Paging', () => { +context("List Paging", () => { before(() => { cy.login(); - cy.visit('/app/website'); - return cy.window().its('frappe').then(frappe => { - return frappe.call("frappe.tests.ui_test_helpers.create_multiple_todo_records"); - }); + cy.visit("/app/website"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.call("frappe.tests.ui_test_helpers.create_multiple_todo_records"); + }); }); - it('test load more with count selection buttons', () => { - cy.visit('/app/todo/view/report'); - cy.clear_filters() + it("test load more with count selection buttons", () => { + cy.visit("/app/todo/view/report"); + cy.clear_filters(); - cy.get('.list-paging-area .list-count').should('contain.text', '20 of'); - cy.get('.list-paging-area .btn-more').click(); - cy.get('.list-paging-area .list-count').should('contain.text', '40 of'); - cy.get('.list-paging-area .btn-more').click(); - cy.get('.list-paging-area .list-count').should('contain.text', '60 of'); + cy.get(".list-paging-area .list-count").should("contain.text", "20 of"); + cy.get(".list-paging-area .btn-more").click(); + cy.get(".list-paging-area .list-count").should("contain.text", "40 of"); + cy.get(".list-paging-area .btn-more").click(); + cy.get(".list-paging-area .list-count").should("contain.text", "60 of"); cy.get('.list-paging-area .btn-group .btn-paging[data-value="100"]').click(); - cy.get('.list-paging-area .list-count').should('contain.text', '100 of'); - cy.get('.list-paging-area .btn-more').click(); - cy.get('.list-paging-area .list-count').should('contain.text', '200 of'); - cy.get('.list-paging-area .btn-more').click(); - cy.get('.list-paging-area .list-count').should('contain.text', '300 of'); + cy.get(".list-paging-area .list-count").should("contain.text", "100 of"); + cy.get(".list-paging-area .btn-more").click(); + cy.get(".list-paging-area .list-count").should("contain.text", "200 of"); + cy.get(".list-paging-area .btn-more").click(); + cy.get(".list-paging-area .list-count").should("contain.text", "300 of"); // check if refresh works after load more cy.get('.page-head .standard-actions [data-original-title="Refresh"]').click(); - cy.get('.list-paging-area .list-count').should('contain.text', '300 of'); + cy.get(".list-paging-area .list-count").should("contain.text", "300 of"); cy.get('.list-paging-area .btn-group .btn-paging[data-value="500"]').click(); - cy.get('.list-paging-area .list-count').should('contain.text', '500 of'); - cy.get('.list-paging-area .btn-more').click(); + cy.get(".list-paging-area .list-count").should("contain.text", "500 of"); + cy.get(".list-paging-area .btn-more").click(); - cy.get('.list-paging-area .list-count').should('contain.text', '1000 of'); + cy.get(".list-paging-area .list-count").should("contain.text", "1000 of"); }); }); diff --git a/cypress/integration/list_view.js b/cypress/integration/list_view.js index ee12b37638..7fb0ef445c 100644 --- a/cypress/integration/list_view.js +++ b/cypress/integration/list_view.js @@ -1,48 +1,67 @@ -context('List View', () => { +context("List View", () => { before(() => { cy.login(); - cy.visit('/app/website'); - return cy.window().its('frappe').then(frappe => { - return frappe.xcall("frappe.tests.ui_test_helpers.setup_workflow"); - }); + cy.visit("/app/website"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.xcall("frappe.tests.ui_test_helpers.setup_workflow"); + }); }); - it('Keep checkbox checked after Refresh', () => { - cy.go_to_list('ToDo'); - cy.clear_filters() - cy.get('.list-row-container .list-row-checkbox').click({ multiple: true, force: true }); - cy.get('.actions-btn-group button').contains('Actions').should('be.visible'); - cy.intercept('/api/method/frappe.desk.reportview.get').as('list-refresh'); + it("Keep checkbox checked after Refresh", () => { + cy.go_to_list("ToDo"); + cy.clear_filters(); + cy.get(".list-row-container .list-row-checkbox").click({ multiple: true, force: true }); + cy.get(".actions-btn-group button").contains("Actions").should("be.visible"); + cy.intercept("/api/method/frappe.desk.reportview.get").as("list-refresh"); cy.wait(3000); // wait before you hit another refresh cy.get('button[data-original-title="Refresh"]').click(); - cy.wait('@list-refresh'); - cy.get('.list-row-container .list-row-checkbox:checked').should('be.visible'); + cy.wait("@list-refresh"); + cy.get(".list-row-container .list-row-checkbox:checked").should("be.visible"); }); it('enables "Actions" button', () => { - const actions = ['Approve', 'Reject', 'Edit', 'Export', 'Assign To', 'Apply Assignment Rule', 'Add Tags', 'Print', 'Delete']; - cy.go_to_list('ToDo'); - cy.clear_filters() - cy.get('.list-row-container:contains("Pending") .list-row-checkbox').click({ multiple: true, force: true }); - cy.get('.actions-btn-group button').contains('Actions').should('be.visible').click(); - cy.get('.dropdown-menu li:visible .dropdown-item').should('have.length', 9).each((el, index) => { - cy.wrap(el).contains(actions[index]); - }).then((elements) => { - cy.intercept({ - method: 'POST', - url: 'api/method/frappe.model.workflow.bulk_workflow_approval' - }).as('bulk-approval'); - cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.reportview.get' - }).as('real-time-update'); - cy.wrap(elements).contains('Approve').click(); - cy.wait(['@bulk-approval', '@real-time-update']); - cy.wait(300); - cy.get_open_dialog().find('.btn-modal-close').click(); - cy.reload(); - cy.clear_filters(); - cy.get('.list-row-container:visible').should('contain', 'Approved'); + const actions = [ + "Approve", + "Reject", + "Edit", + "Export", + "Assign To", + "Apply Assignment Rule", + "Add Tags", + "Print", + "Delete", + ]; + cy.go_to_list("ToDo"); + cy.clear_filters(); + cy.get('.list-row-container:contains("Pending") .list-row-checkbox').click({ + multiple: true, + force: true, }); + cy.get(".actions-btn-group button").contains("Actions").should("be.visible").click(); + cy.get(".dropdown-menu li:visible .dropdown-item") + .should("have.length", 9) + .each((el, index) => { + cy.wrap(el).contains(actions[index]); + }) + .then((elements) => { + cy.intercept({ + method: "POST", + url: "api/method/frappe.model.workflow.bulk_workflow_approval", + }).as("bulk-approval"); + cy.intercept({ + method: "POST", + url: "api/method/frappe.desk.reportview.get", + }).as("real-time-update"); + cy.wrap(elements).contains("Approve").click(); + cy.wait(["@bulk-approval", "@real-time-update"]); + cy.wait(300); + cy.get_open_dialog().find(".btn-modal-close").click(); + cy.reload(); + cy.clear_filters(); + cy.get(".list-row-container:visible").should("contain", "Approved"); + }); }); }); diff --git a/cypress/integration/list_view_settings.js b/cypress/integration/list_view_settings.js index 61d4b8aae5..5e66ee43f5 100644 --- a/cypress/integration/list_view_settings.js +++ b/cypress/integration/list_view_settings.js @@ -1,36 +1,36 @@ -context('List View Settings', () => { +context("List View Settings", () => { beforeEach(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); - it('Default settings', () => { - cy.visit('/app/List/DocType/List'); - cy.get('.list-count').should('contain', "20 of"); - cy.get('.list-stats').should('contain', "Tags"); + it("Default settings", () => { + cy.visit("/app/List/DocType/List"); + cy.get(".list-count").should("contain", "20 of"); + cy.get(".list-stats").should("contain", "Tags"); }); - it('disable count and sidebar stats then verify', () => { + it("disable count and sidebar stats then verify", () => { cy.wait(300); - cy.visit('/app/List/DocType/List'); + cy.visit("/app/List/DocType/List"); cy.wait(300); - cy.get('.list-count').should('contain', "20 of"); - cy.get('.menu-btn-group button').click(); - cy.get('.dropdown-menu li').filter(':visible').contains('List Settings').click(); - cy.get('.modal-dialog').should('contain', 'DocType Settings'); + cy.get(".list-count").should("contain", "20 of"); + cy.get(".menu-btn-group button").click(); + cy.get(".dropdown-menu li").filter(":visible").contains("List Settings").click(); + cy.get(".modal-dialog").should("contain", "DocType Settings"); - cy.findByLabelText('Disable Count').check({ force: true }); - cy.findByLabelText('Disable Sidebar Stats').check({ force: true }); - cy.findByRole('button', {name: 'Save'}).click(); + cy.findByLabelText("Disable Count").check({ force: true }); + cy.findByLabelText("Disable Sidebar Stats").check({ force: true }); + cy.findByRole("button", { name: "Save" }).click(); cy.reload({ force: true }); - cy.get('.list-count').should('be.empty'); - cy.get('.list-sidebar .list-tags').should('not.exist'); + cy.get(".list-count").should("be.empty"); + cy.get(".list-sidebar .list-tags").should("not.exist"); - cy.get('.menu-btn-group button').click({ force: true }); - cy.get('.dropdown-menu li').filter(':visible').contains('List Settings').click(); - cy.get('.modal-dialog').should('contain', 'DocType Settings'); - cy.findByLabelText('Disable Count').uncheck({ force: true }); - cy.findByLabelText('Disable Sidebar Stats').uncheck({ force: true }); - cy.findByRole('button', {name: 'Save'}).click(); + cy.get(".menu-btn-group button").click({ force: true }); + cy.get(".dropdown-menu li").filter(":visible").contains("List Settings").click(); + cy.get(".modal-dialog").should("contain", "DocType Settings"); + cy.findByLabelText("Disable Count").uncheck({ force: true }); + cy.findByLabelText("Disable Sidebar Stats").uncheck({ force: true }); + cy.findByRole("button", { name: "Save" }).click(); }); }); diff --git a/cypress/integration/login.js b/cypress/integration/login.js index 98739bb4c9..2db4b1fdcd 100644 --- a/cypress/integration/login.js +++ b/cypress/integration/login.js @@ -1,68 +1,66 @@ -context('Login', () => { +context("Login", () => { beforeEach(() => { - cy.request('/api/method/logout'); - cy.visit('/login'); - cy.location('pathname').should('eq', '/login'); + cy.request("/api/method/logout"); + cy.visit("/login"); + cy.location("pathname").should("eq", "/login"); }); - it('greets with login screen', () => { - cy.get('.page-card-head').contains('Login'); + it("greets with login screen", () => { + cy.get(".page-card-head").contains("Login"); }); - it('validates password', () => { - cy.get('#login_email').type('Administrator'); - cy.findByRole('button', {name: 'Login'}).click(); - cy.location('pathname').should('eq', '/login'); + it("validates password", () => { + cy.get("#login_email").type("Administrator"); + cy.findByRole("button", { name: "Login" }).click(); + cy.location("pathname").should("eq", "/login"); }); - it('validates email', () => { - cy.get('#login_password').type('qwe'); - cy.findByRole('button', {name: 'Login'}).click(); - cy.location('pathname').should('eq', '/login'); + it("validates email", () => { + cy.get("#login_password").type("qwe"); + cy.findByRole("button", { name: "Login" }).click(); + cy.location("pathname").should("eq", "/login"); }); - it('shows invalid login if incorrect credentials', () => { - cy.get('#login_email').type('Administrator'); - cy.get('#login_password').type('qwer'); + it("shows invalid login if incorrect credentials", () => { + cy.get("#login_email").type("Administrator"); + cy.get("#login_password").type("qwer"); - cy.findByRole('button', {name: 'Login'}).click(); - cy.findByRole('button', {name: 'Invalid Login. Try again.'}).should('exist'); - cy.location('pathname').should('eq', '/login'); + cy.findByRole("button", { name: "Login" }).click(); + cy.findByRole("button", { name: "Invalid Login. Try again." }).should("exist"); + cy.location("pathname").should("eq", "/login"); }); - it('logs in using correct credentials', () => { - cy.get('#login_email').type('Administrator'); - cy.get('#login_password').type(Cypress.config('adminPassword')); + it("logs in using correct credentials", () => { + cy.get("#login_email").type("Administrator"); + cy.get("#login_password").type(Cypress.config("adminPassword")); - cy.findByRole('button', {name: 'Login'}).click(); - cy.location('pathname').should('eq', '/app'); - cy.window().its('frappe.session.user').should('eq', 'Administrator'); + cy.findByRole("button", { name: "Login" }).click(); + cy.location("pathname").should("eq", "/app"); + cy.window().its("frappe.session.user").should("eq", "Administrator"); }); - it('check redirect after login', () => { - + it("check redirect after login", () => { // mock for OAuth 2.0 client_id, redirect_uri, scope and state const payload = new URLSearchParams({ - uuid: '6fed1519-cfd8-4a2d-84a6-9a1799c7c741', - encoded_string: 'hello all', - encoded_url: 'http://test.localhost/callback', - base64_string: 'aGVsbG8gYWxs' + uuid: "6fed1519-cfd8-4a2d-84a6-9a1799c7c741", + encoded_string: "hello all", + encoded_url: "http://test.localhost/callback", + base64_string: "aGVsbG8gYWxs", }); - cy.request('/api/method/logout'); + cy.request("/api/method/logout"); // redirect-to /me page with params to mock OAuth 2.0 like request cy.visit( - '/login?redirect-to=/me?' + - encodeURIComponent(payload.toString().replace("+", " ")) + "/login?redirect-to=/me?" + encodeURIComponent(payload.toString().replace("+", " ")) ); - cy.get('#login_email').type('Administrator'); - cy.get('#login_password').type(Cypress.config('adminPassword')); + cy.get("#login_email").type("Administrator"); + cy.get("#login_password").type(Cypress.config("adminPassword")); - cy.findByRole('button', {name: 'Login'}).click(); + cy.findByRole("button", { name: "Login" }).click(); // verify redirected location and url params after login - cy.url().should('include', '/me?' + payload.toString().replace('+', '%20')); + cy.url().should("include", "/me?" + payload.toString().replace("+", "%20")); }); }); diff --git a/cypress/integration/multi_select_dialog.js b/cypress/integration/multi_select_dialog.js index 607db506c7..1be56d3b3d 100644 --- a/cypress/integration/multi_select_dialog.js +++ b/cypress/integration/multi_select_dialog.js @@ -1,99 +1,102 @@ -context('MultiSelectDialog', () => { +context("MultiSelectDialog", () => { before(() => { cy.login(); - cy.visit('/app'); + cy.visit("/app"); const contact_template = { - "doctype": "Contact", - "first_name": "Test", - "status": "Passive", - "email_ids": [ + doctype: "Contact", + first_name: "Test", + status: "Passive", + email_ids: [ { - "doctype": "Contact Email", - "email_id": "test@example.com", - "is_primary": 0 - } - ] + doctype: "Contact Email", + email_id: "test@example.com", + is_primary: 0, + }, + ], }; - const promises = Array.from({length: 25}) - .map(() => cy.insert_doc('Contact', contact_template, true)); + const promises = Array.from({ length: 25 }).map(() => + cy.insert_doc("Contact", contact_template, true) + ); Promise.all(promises); }); function open_multi_select_dialog() { - cy.window().its('frappe').then(frappe => { - new frappe.ui.form.MultiSelectDialog({ - doctype: "Contact", - target: {}, - setters: { - status: null, - gender: null - }, - add_filters_group: 1, - allow_child_item_selection: 1, - child_fieldname: "email_ids", - child_columns: ["email_id", "is_primary"] + cy.window() + .its("frappe") + .then((frappe) => { + new frappe.ui.form.MultiSelectDialog({ + doctype: "Contact", + target: {}, + setters: { + status: null, + gender: null, + }, + add_filters_group: 1, + allow_child_item_selection: 1, + child_fieldname: "email_ids", + child_columns: ["email_id", "is_primary"], + }); }); - }); } - it('checks multi select dialog api works', () => { + it("checks multi select dialog api works", () => { open_multi_select_dialog(); - cy.get_open_dialog().should('contain', 'Select Contacts'); + cy.get_open_dialog().should("contain", "Select Contacts"); }); - it('checks for filters', () => { - ['search_term', 'status', 'gender'].forEach(fieldname => { - cy.get_open_dialog().get(`.frappe-control[data-fieldname="${fieldname}"]`).should('exist'); + it("checks for filters", () => { + ["search_term", "status", "gender"].forEach((fieldname) => { + cy.get_open_dialog() + .get(`.frappe-control[data-fieldname="${fieldname}"]`) + .should("exist"); }); // add_filters_group: 1 should add a filter group - cy.get_open_dialog().get(`.frappe-control[data-fieldname="filter_area"]`).should('exist'); - + cy.get_open_dialog().get(`.frappe-control[data-fieldname="filter_area"]`).should("exist"); }); - it('checks for child item selection', () => { - cy.get_open_dialog() - .get(`.dt-row-header`).should('not.exist'); + it("checks for child item selection", () => { + cy.get_open_dialog().get(`.dt-row-header`).should("not.exist"); cy.get_open_dialog() .get(`.frappe-control[data-fieldname="allow_child_item_selection"]`) .find('input[data-fieldname="allow_child_item_selection"]') - .should('exist') - .click({force: true}); + .should("exist") + .click({ force: true }); cy.get_open_dialog() .get(`.frappe-control[data-fieldname="child_selection_area"]`) - .should('exist'); + .should("exist"); - cy.get_open_dialog() - .get(`.dt-row-header`).should('contain', 'Contact'); + cy.get_open_dialog().get(`.dt-row-header`).should("contain", "Contact"); - cy.get_open_dialog() - .get(`.dt-row-header`).should('contain', 'Email Id'); + cy.get_open_dialog().get(`.dt-row-header`).should("contain", "Email Id"); - cy.get_open_dialog() - .get(`.dt-row-header`).should('contain', 'Is Primary'); + cy.get_open_dialog().get(`.dt-row-header`).should("contain", "Is Primary"); }); - it('tests more button', () => { + it("tests more button", () => { cy.get_open_dialog() .get(`.frappe-control[data-fieldname="more_child_btn"]`) - .should('exist') - .as('more-btn'); - - cy.get_open_dialog().get('.datatable .dt-scrollable .dt-row').should(($rows) => { - expect($rows).to.have.length(20); - }); + .should("exist") + .as("more-btn"); - cy.intercept('POST', 'api/method/frappe.client.get_list').as('get-more-records'); - cy.get('@more-btn').find('button').click({force: true}); - cy.wait('@get-more-records'); + cy.get_open_dialog() + .get(".datatable .dt-scrollable .dt-row") + .should(($rows) => { + expect($rows).to.have.length(20); + }); - cy.get_open_dialog().get('.datatable .dt-scrollable .dt-row').should(($rows) => { - if ($rows.length <= 20) { - throw new Error("More button doesn't work"); - } - }); + cy.intercept("POST", "api/method/frappe.client.get_list").as("get-more-records"); + cy.get("@more-btn").find("button").click({ force: true }); + cy.wait("@get-more-records"); + cy.get_open_dialog() + .get(".datatable .dt-scrollable .dt-row") + .should(($rows) => { + if ($rows.length <= 20) { + throw new Error("More button doesn't work"); + } + }); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/navigation.js b/cypress/integration/navigation.js index b4e023c53e..2302296f23 100644 --- a/cypress/integration/navigation.js +++ b/cypress/integration/navigation.js @@ -1,25 +1,29 @@ -context('Navigation', () => { +context("Navigation", () => { before(() => { cy.login(); }); - it('Navigate to route with hash in document name', () => { - cy.insert_doc('ToDo', {'__newname': 'ABC#123', 'description': 'Test this', 'ignore_duplicate': true}); - cy.visit('/app/todo/ABC#123'); - cy.title().should('eq', 'Test this - ABC#123'); - cy.get_field('description', 'Text Editor').contains('Test this'); - cy.go('back'); - cy.title().should('eq', 'Website'); + it("Navigate to route with hash in document name", () => { + cy.insert_doc("ToDo", { + __newname: "ABC#123", + description: "Test this", + ignore_duplicate: true, + }); + cy.visit("/app/todo/ABC#123"); + cy.title().should("eq", "Test this - ABC#123"); + cy.get_field("description", "Text Editor").contains("Test this"); + cy.go("back"); + cy.title().should("eq", "Website"); }); - it.only('Navigate to previous page after login', () => { - cy.visit('/app/todo'); - cy.get('.page-head').findByTitle('To Do').should('be.visible'); - cy.request('/api/method/logout'); - cy.reload().as('reload'); - cy.get('@reload').get('.page-card .btn-primary').contains('Login').click(); - cy.location('pathname').should('eq', '/login'); + it.only("Navigate to previous page after login", () => { + cy.visit("/app/todo"); + cy.get(".page-head").findByTitle("To Do").should("be.visible"); + cy.request("/api/method/logout"); + cy.reload().as("reload"); + cy.get("@reload").get(".page-card .btn-primary").contains("Login").click(); + cy.location("pathname").should("eq", "/login"); cy.login(); - cy.visit('/app'); - cy.location('pathname').should('eq', '/app/todo'); + cy.visit("/app"); + cy.location("pathname").should("eq", "/app/todo"); }); }); diff --git a/cypress/integration/number_card.js b/cypress/integration/number_card.js index a01ff1152d..eb0f19be26 100644 --- a/cypress/integration/number_card.js +++ b/cypress/integration/number_card.js @@ -1,22 +1,22 @@ -context('Number Card', () => { +context("Number Card", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); - it('Check filter populate for child table doctype', () => { - cy.visit('/app/number-card/new-number-card-1'); - cy.get('[data-fieldname="parent_document_type"]').should('have.css', 'display', 'none'); + it("Check filter populate for child table doctype", () => { + cy.visit("/app/number-card/new-number-card-1"); + cy.get('[data-fieldname="parent_document_type"]').should("have.css", "display", "none"); - cy.get_field('document_type', 'Link'); - cy.fill_field('document_type', 'Workspace Link', 'Link').focus().blur(); - cy.get_field('document_type', 'Link').should('have.value', 'Workspace Link'); + cy.get_field("document_type", "Link"); + cy.fill_field("document_type", "Workspace Link", "Link").focus().blur(); + cy.get_field("document_type", "Link").should("have.value", "Workspace Link"); - cy.fill_field('label', 'Test Number Card', 'Data'); + cy.fill_field("label", "Test Number Card", "Data"); cy.get('[data-fieldname="filters_json"]').click().wait(200); - cy.get('.modal-body .filter-action-buttons .add-filter').click(); - cy.get('.modal-body .fieldname-select-area').click(); - cy.get('.modal-actions .btn-modal-close').click(); + cy.get(".modal-body .filter-action-buttons .add-filter").click(); + cy.get(".modal-body .fieldname-select-area").click(); + cy.get(".modal-actions .btn-modal-close").click(); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/query_report.js b/cypress/integration/query_report.js index 43f26f8b50..5dd0ab2d53 100644 --- a/cypress/integration/query_report.js +++ b/cypress/integration/query_report.js @@ -1,63 +1,91 @@ -context('Query Report', () => { +context("Query Report", () => { before(() => { cy.login(); - cy.visit('/app/website'); - cy.insert_doc('Report', { - 'report_name': 'Test ToDo Report', - 'ref_doctype': 'ToDo', - 'report_type': 'Query Report', - 'query': 'select * from tabToDo' - }, true).as('doc'); + cy.visit("/app/website"); + cy.insert_doc( + "Report", + { + report_name: "Test ToDo Report", + ref_doctype: "ToDo", + report_type: "Query Report", + query: "select * from tabToDo", + }, + true + ).as("doc"); cy.create_records({ - doctype: 'ToDo', - description: 'this is a test todo for query report' - }).as('todos'); + doctype: "ToDo", + description: "this is a test todo for query report", + }).as("todos"); }); - it('add custom column in report', () => { - cy.visit('/app/query-report/Permitted Documents For User'); + it("add custom column in report", () => { + cy.visit("/app/query-report/Permitted Documents For User"); - cy.get('.page-form.flex', { timeout: 60000 }).should('have.length', 1).then(() => { - cy.get('#page-query-report input[data-fieldname="user"]').as('input-user'); - cy.get('@input-user').focus().type('test@erpnext.com', { delay: 100 }).blur(); - cy.wait(300); - cy.get('#page-query-report input[data-fieldname="doctype"]').as('input-role'); - cy.get('@input-role').focus().type('Role', { delay: 100 }).blur(); + cy.get(".page-form.flex", { timeout: 60000 }) + .should("have.length", 1) + .then(() => { + cy.get('#page-query-report input[data-fieldname="user"]').as("input-user"); + cy.get("@input-user").focus().type("test@erpnext.com", { delay: 100 }).blur(); + cy.wait(300); + cy.get('#page-query-report input[data-fieldname="doctype"]').as("input-role"); + cy.get("@input-role").focus().type("Role", { delay: 100 }).blur(); - cy.get('.datatable').should('exist'); - cy.get('#page-query-report .page-actions .menu-btn-group button').click({ force: true }); - cy.get('#page-query-report .menu-btn-group .dropdown-menu').contains('Add Column').click({ force: true }); - cy.get_open_dialog().get('.modal-title').should('contain', 'Add Column'); - cy.get('select[data-fieldname="doctype"]').select("Role", { force: true }); - cy.get('select[data-fieldname="field"]').select("Role Name", { force: true }); - cy.get('select[data-fieldname="insert_after"]').select("Name", { force: true }); - cy.get_open_dialog().findByRole('button', {name: 'Submit'}).click({ force: true }); - cy.get('#page-query-report .page-actions .menu-btn-group button').click({ force: true }); - cy.get('#page-query-report .menu-btn-group .dropdown-menu').contains('Save').click({ timeout: 100, force: true }); - cy.get_open_dialog().get('.modal-title').should('contain', 'Save Report'); + cy.get(".datatable").should("exist"); + cy.get("#page-query-report .page-actions .menu-btn-group button").click({ + force: true, + }); + cy.get("#page-query-report .menu-btn-group .dropdown-menu") + .contains("Add Column") + .click({ force: true }); + cy.get_open_dialog().get(".modal-title").should("contain", "Add Column"); + cy.get('select[data-fieldname="doctype"]').select("Role", { force: true }); + cy.get('select[data-fieldname="field"]').select("Role Name", { force: true }); + cy.get('select[data-fieldname="insert_after"]').select("Name", { force: true }); + cy.get_open_dialog() + .findByRole("button", { name: "Submit" }) + .click({ force: true }); + cy.get("#page-query-report .page-actions .menu-btn-group button").click({ + force: true, + }); + cy.get("#page-query-report .menu-btn-group .dropdown-menu") + .contains("Save") + .click({ timeout: 100, force: true }); + cy.get_open_dialog().get(".modal-title").should("contain", "Save Report"); - cy.get('input[data-fieldname="report_name"]').type("Test Report", { delay: 100, force: true }); - cy.get_open_dialog().findByRole('button', {name: 'Submit'}).click({ timeout: 1000, force: true }); - }); + cy.get('input[data-fieldname="report_name"]').type("Test Report", { + delay: 100, + force: true, + }); + cy.get_open_dialog() + .findByRole("button", { name: "Submit" }) + .click({ timeout: 1000, force: true }); + }); }); let save_report_and_open = (report, update_name) => { - cy.get('#page-query-report .page-actions .menu-btn-group button').click({ force: true }); - cy.get('#page-query-report .menu-btn-group .dropdown-menu').contains('Save').click({ timeout: 100, force: true }); - cy.get_open_dialog().get('.modal-title').should('contain', 'Save Report'); + cy.get("#page-query-report .page-actions .menu-btn-group button").click({ force: true }); + cy.get("#page-query-report .menu-btn-group .dropdown-menu") + .contains("Save") + .click({ timeout: 100, force: true }); + cy.get_open_dialog().get(".modal-title").should("contain", "Save Report"); - cy.get('input[data-fieldname="report_name"]').type(update_name, { delay: 100, force: true }); - cy.get_open_dialog().findByRole('button', {name: 'Submit'}).click({ timeout: 1000, force: true }); + cy.get('input[data-fieldname="report_name"]').type(update_name, { + delay: 100, + force: true, + }); + cy.get_open_dialog() + .findByRole("button", { name: "Submit" }) + .click({ timeout: 1000, force: true }); - cy.visit('/app/query-report/'+report); - cy.get('.datatable').should('exist'); + cy.visit("/app/query-report/" + report); + cy.get(".datatable").should("exist"); }; - it('test multi level query report', () => { - cy.visit('/app/query-report/Test ToDo Report'); - cy.get('.datatable').should('exist'); + it("test multi level query report", () => { + cy.visit("/app/query-report/Test ToDo Report"); + cy.get(".datatable").should("exist"); - save_report_and_open('Test ToDo Report 1', ' 1'); - save_report_and_open('Test ToDo Report 11', '1'); + save_report_and_open("Test ToDo Report 1", " 1"); + save_report_and_open("Test ToDo Report 11", "1"); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/recorder.js b/cypress/integration/recorder.js index 57d3c01356..de95a852fc 100644 --- a/cypress/integration/recorder.js +++ b/cypress/integration/recorder.js @@ -1,66 +1,72 @@ -context.skip('Recorder', () => { +context.skip("Recorder", () => { before(() => { cy.login(); }); beforeEach(() => { - cy.visit('/app/recorder'); - return cy.window().its('frappe').then(frappe => { - // reset recorder - return frappe.xcall("frappe.recorder.stop").then(() => { - return frappe.xcall("frappe.recorder.delete"); + cy.visit("/app/recorder"); + return cy + .window() + .its("frappe") + .then((frappe) => { + // reset recorder + return frappe.xcall("frappe.recorder.stop").then(() => { + return frappe.xcall("frappe.recorder.delete"); + }); }); - }); }); - it('Recorder Empty State', () => { - cy.get('.page-head').findByTitle('Recorder').should('exist'); + it("Recorder Empty State", () => { + cy.get(".page-head").findByTitle("Recorder").should("exist"); - cy.get('.indicator-pill').should('contain', 'Inactive').should('have.class', 'red'); + cy.get(".indicator-pill").should("contain", "Inactive").should("have.class", "red"); - cy.get('.page-actions').findByRole('button', {name: 'Start'}).should('exist'); - cy.get('.page-actions').findByRole('button', {name: 'Clear'}).should('exist'); + cy.get(".page-actions").findByRole("button", { name: "Start" }).should("exist"); + cy.get(".page-actions").findByRole("button", { name: "Clear" }).should("exist"); - cy.get('.msg-box').should('contain', 'Recorder is Inactive'); - cy.get('.msg-box').findByRole('button', {name: 'Start Recording'}).should('exist'); + cy.get(".msg-box").should("contain", "Recorder is Inactive"); + cy.get(".msg-box").findByRole("button", { name: "Start Recording" }).should("exist"); }); - it('Recorder Start', () => { - cy.get('.page-actions').findByRole('button', {name: 'Start'}).click(); - cy.get('.indicator-pill').should('contain', 'Active').should('have.class', 'green'); + it("Recorder Start", () => { + cy.get(".page-actions").findByRole("button", { name: "Start" }).click(); + cy.get(".indicator-pill").should("contain", "Active").should("have.class", "green"); - cy.get('.msg-box').should('contain', 'No Requests found'); + cy.get(".msg-box").should("contain", "No Requests found"); - cy.visit('/app/List/DocType/List'); - cy.intercept('POST', '/api/method/frappe.desk.reportview.get').as('list_refresh'); - cy.wait('@list_refresh'); + cy.visit("/app/List/DocType/List"); + cy.intercept("POST", "/api/method/frappe.desk.reportview.get").as("list_refresh"); + cy.wait("@list_refresh"); - cy.get('.page-head').findByTitle('DocType').should('exist'); - cy.get('.list-count').should('contain', '20 of '); + cy.get(".page-head").findByTitle("DocType").should("exist"); + cy.get(".list-count").should("contain", "20 of "); - cy.visit('/app/recorder'); - cy.get('.page-head').findByTitle('Recorder').should('exist'); - cy.get('.frappe-list .result-list').should('contain', '/api/method/frappe.desk.reportview.get'); + cy.visit("/app/recorder"); + cy.get(".page-head").findByTitle("Recorder").should("exist"); + cy.get(".frappe-list .result-list").should( + "contain", + "/api/method/frappe.desk.reportview.get" + ); }); - it('Recorder View Request', () => { - cy.get('.page-actions').findByRole('button', {name: 'Start'}).click(); + it("Recorder View Request", () => { + cy.get(".page-actions").findByRole("button", { name: "Start" }).click(); - cy.visit('/app/List/DocType/List'); - cy.intercept('POST', '/api/method/frappe.desk.reportview.get').as('list_refresh'); - cy.wait('@list_refresh'); + cy.visit("/app/List/DocType/List"); + cy.intercept("POST", "/api/method/frappe.desk.reportview.get").as("list_refresh"); + cy.wait("@list_refresh"); - cy.get('.page-head').findByTitle('DocType').should('exist'); - cy.get('.list-count').should('contain', '20 of '); + cy.get(".page-head").findByTitle("DocType").should("exist"); + cy.get(".list-count").should("contain", "20 of "); - cy.visit('/app/recorder'); + cy.visit("/app/recorder"); - cy.get('.frappe-list .list-row-container span') - .contains('/api/method/frappe') - .should('be.visible') - .click({force: true}); + cy.get(".frappe-list .list-row-container span") + .contains("/api/method/frappe") + .should("be.visible") + .click({ force: true }); - cy.url().should('include', '/recorder/request'); - cy.get('form').should('contain', '/api/method/frappe'); + cy.url().should("include", "/recorder/request"); + cy.get("form").should("contain", "/api/method/frappe"); }); }); diff --git a/cypress/integration/report_view.js b/cypress/integration/report_view.js index bacbf9c172..27fe840450 100644 --- a/cypress/integration/report_view.js +++ b/cypress/integration/report_view.js @@ -1,42 +1,46 @@ -import custom_submittable_doctype from '../fixtures/custom_submittable_doctype'; +import custom_submittable_doctype from "../fixtures/custom_submittable_doctype"; const doctype_name = custom_submittable_doctype.name; -context('Report View', () => { +context("Report View", () => { before(() => { cy.login(); - cy.visit('/app/website'); - cy.insert_doc('DocType', custom_submittable_doctype, true); + cy.visit("/app/website"); + cy.insert_doc("DocType", custom_submittable_doctype, true); cy.clear_cache(); - cy.insert_doc(doctype_name, { - 'title': 'Doc 1', - 'description': 'Random Text', - 'enabled': 0, - 'docstatus': 1 // submit document - }, true); + cy.insert_doc( + doctype_name, + { + title: "Doc 1", + description: "Random Text", + enabled: 0, + docstatus: 1, // submit document + }, + true + ); }); - it('Field with enabled allow_on_submit should be editable.', () => { - cy.intercept('POST', 'api/method/frappe.client.set_value').as('value-update'); + it("Field with enabled allow_on_submit should be editable.", () => { + cy.intercept("POST", "api/method/frappe.client.set_value").as("value-update"); cy.visit(`/app/List/${doctype_name}/Report`); // check status column added from docstatus - cy.get('.dt-row-0 > .dt-cell--col-3').should('contain', 'Submitted'); - let cell = cy.get('.dt-row-0 > .dt-cell--col-4'); + cy.get(".dt-row-0 > .dt-cell--col-3").should("contain", "Submitted"); + let cell = cy.get(".dt-row-0 > .dt-cell--col-4"); // select the cell cell.dblclick(); - cell.get('.dt-cell__edit--col-4').findByRole('checkbox').check({ force: true }); - cy.get('.dt-row-0 > .dt-cell--col-3').click(); // click outside + cell.get(".dt-cell__edit--col-4").findByRole("checkbox").check({ force: true }); + cy.get(".dt-row-0 > .dt-cell--col-3").click(); // click outside - cy.wait('@value-update'); + cy.wait("@value-update"); - cy.call('frappe.client.get_value', { + cy.call("frappe.client.get_value", { doctype: doctype_name, filters: { - title: 'Doc 1', + title: "Doc 1", }, - fieldname: 'enabled' - }).then(r => { + fieldname: "enabled", + }).then((r) => { expect(r.message.enabled).to.equals(1); }); }); diff --git a/cypress/integration/sidebar.js b/cypress/integration/sidebar.js index 2831c9bad5..6ed2d4022c 100644 --- a/cypress/integration/sidebar.js +++ b/cypress/integration/sidebar.js @@ -1,55 +1,64 @@ -context('Sidebar', () => { +context("Sidebar", () => { before(() => { - cy.visit('/login'); + cy.visit("/login"); cy.login(); - cy.visit('/app/doctype'); + cy.visit("/app/doctype"); }); it('Test for checking "Assigned To" counter value, adding filter and adding & removing an assignment', () => { cy.click_sidebar_button("Assigned To"); //To check if no filter is available in "Assigned To" dropdown - cy.get('.empty-state').should('contain', 'No filters found'); + cy.get(".empty-state").should("contain", "No filters found"); cy.click_sidebar_button("Created By"); //To check if "Created By" dropdown contains filter - cy.get('.group-by-item > .dropdown-item').should('contain', 'Me'); + cy.get(".group-by-item > .dropdown-item").should("contain", "Me"); //Assigning a doctype to a user - cy.visit('/app/doctype/ToDo'); - cy.get('.form-assignments > .flex > .text-muted').click(); - cy.get_field('assign_to_me', 'Check').click(); - cy.get('.modal-footer > .standard-actions > .btn-primary').click(); - cy.visit('/app/doctype'); + cy.visit("/app/doctype/ToDo"); + cy.get(".form-assignments > .flex > .text-muted").click(); + cy.get_field("assign_to_me", "Check").click(); + cy.get(".modal-footer > .standard-actions > .btn-primary").click(); + cy.visit("/app/doctype"); cy.click_sidebar_button("Assigned To"); //To check if filter is added in "Assigned To" dropdown after assignment - cy.get('.group-by-field.show > .dropdown-menu > .group-by-item > .dropdown-item').should('contain', '1'); + cy.get(".group-by-field.show > .dropdown-menu > .group-by-item > .dropdown-item").should( + "contain", + "1" + ); //To check if there is no filter added to the listview - cy.get('.filter-selector > .btn').should('contain', 'Filter'); + cy.get(".filter-selector > .btn").should("contain", "Filter"); //To add a filter to display data into the listview - cy.get('.group-by-field.show > .dropdown-menu > .group-by-item > .dropdown-item').click(); + cy.get(".group-by-field.show > .dropdown-menu > .group-by-item > .dropdown-item").click(); //To check if filter is applied - cy.click_filter_button().should('contain', '1 filter'); - cy.get('.fieldname-select-area > .awesomplete > .form-control').should('have.value', 'Assigned To'); - cy.get('.condition').should('have.value', 'like'); - cy.get('.filter-field > .form-group > .input-with-feedback').should('have.value', '%Administrator%'); + cy.click_filter_button().should("contain", "1 filter"); + cy.get(".fieldname-select-area > .awesomplete > .form-control").should( + "have.value", + "Assigned To" + ); + cy.get(".condition").should("have.value", "like"); + cy.get(".filter-field > .form-group > .input-with-feedback").should( + "have.value", + "%Administrator%" + ); cy.click_filter_button(); //To remove the applied filter cy.clear_filters(); //To remove the assignment - cy.visit('/app/doctype/ToDo'); - cy.get('.assignments > .avatar-group > .avatar > .avatar-frame').click(); - cy.get('.remove-btn').click({force: true}); + cy.visit("/app/doctype/ToDo"); + cy.get(".assignments > .avatar-group > .avatar > .avatar-frame").click(); + cy.get(".remove-btn").click({ force: true }); cy.hide_dialog(); - cy.visit('/app/doctype'); + cy.visit("/app/doctype"); cy.click_sidebar_button("Assigned To"); - cy.get('.empty-state').should('contain', 'No filters found'); + cy.get(".empty-state").should("contain", "No filters found"); }); }); diff --git a/cypress/integration/table_multiselect.js b/cypress/integration/table_multiselect.js index ae93354964..133af44d51 100644 --- a/cypress/integration/table_multiselect.js +++ b/cypress/integration/table_multiselect.js @@ -1,51 +1,57 @@ -context('Table MultiSelect', () => { +context("Table MultiSelect", () => { before(() => { cy.login(); }); - let name = 'table multiselect' + Math.random().toString().slice(2, 8); + let name = "table multiselect" + Math.random().toString().slice(2, 8); - it('select value from multiselect dropdown', () => { - cy.new_form('Assignment Rule'); - cy.fill_field('__newname', name); - cy.fill_field('document_type', 'Blog Post'); - cy.get('.section-head').contains('Assignment Rules').scrollIntoView(); - cy.fill_field('assign_condition', 'status=="Open"', 'Code'); - cy.get('input[data-fieldname="users"]').focus().as('input'); - cy.get('input[data-fieldname="users"] + ul').should('be.visible'); - cy.get('@input').type('test{enter}', { delay: 100 }); - cy.get('.frappe-control[data-fieldname="users"] .form-control .tb-selected-value .btn-link-to-form') - .as('selected-value'); - cy.get('@selected-value').should('contain', 'test@erpnext.com'); + it("select value from multiselect dropdown", () => { + cy.new_form("Assignment Rule"); + cy.fill_field("__newname", name); + cy.fill_field("document_type", "Blog Post"); + cy.get(".section-head").contains("Assignment Rules").scrollIntoView(); + cy.fill_field("assign_condition", 'status=="Open"', "Code"); + cy.get('input[data-fieldname="users"]').focus().as("input"); + cy.get('input[data-fieldname="users"] + ul').should("be.visible"); + cy.get("@input").type("test{enter}", { delay: 100 }); + cy.get( + '.frappe-control[data-fieldname="users"] .form-control .tb-selected-value .btn-link-to-form' + ).as("selected-value"); + cy.get("@selected-value").should("contain", "test@erpnext.com"); - cy.intercept('POST', '/api/method/frappe.desk.form.save.savedocs').as('save_form'); + cy.intercept("POST", "/api/method/frappe.desk.form.save.savedocs").as("save_form"); // trigger save - cy.get('.primary-action').click(); - cy.wait('@save_form').its('response.statusCode').should('eq', 200); - cy.get('@selected-value').should('contain', 'test@erpnext.com'); + cy.get(".primary-action").click(); + cy.wait("@save_form").its("response.statusCode").should("eq", 200); + cy.get("@selected-value").should("contain", "test@erpnext.com"); }); - it('delete value using backspace', () => { - cy.go_to_list('Assignment Rule'); - cy.get(`.list-subject:contains("table multiselect")`).last().find('a').click(); - cy.get('input[data-fieldname="users"]').focus().type('{backspace}'); - cy.get('.frappe-control[data-fieldname="users"] .form-control .tb-selected-value') - .should('not.exist'); + it("delete value using backspace", () => { + cy.go_to_list("Assignment Rule"); + cy.get(`.list-subject:contains("table multiselect")`).last().find("a").click(); + cy.get('input[data-fieldname="users"]').focus().type("{backspace}"); + cy.get('.frappe-control[data-fieldname="users"] .form-control .tb-selected-value').should( + "not.exist" + ); }); - it('delete value using x', () => { - cy.go_to_list('Assignment Rule'); - cy.get(`.list-subject:contains("table multiselect")`).last().find('a').click(); - cy.get('.frappe-control[data-fieldname="users"] .form-control .tb-selected-value').as('existing_value'); - cy.get('@existing_value').find('.btn-remove').click(); - cy.get('@existing_value').should('not.exist'); + it("delete value using x", () => { + cy.go_to_list("Assignment Rule"); + cy.get(`.list-subject:contains("table multiselect")`).last().find("a").click(); + cy.get('.frappe-control[data-fieldname="users"] .form-control .tb-selected-value').as( + "existing_value" + ); + cy.get("@existing_value").find(".btn-remove").click(); + cy.get("@existing_value").should("not.exist"); }); - it('navigate to selected value', () => { - cy.go_to_list('Assignment Rule'); - cy.get(`.list-subject:contains("table multiselect")`).last().find('a').click(); - cy.get('.frappe-control[data-fieldname="users"] .form-control .tb-selected-value').as('existing_value'); - cy.get('@existing_value').find('.btn-link-to-form').click(); - cy.location('pathname').should('contain', '/user/test@erpnext.com'); + it("navigate to selected value", () => { + cy.go_to_list("Assignment Rule"); + cy.get(`.list-subject:contains("table multiselect")`).last().find("a").click(); + cy.get('.frappe-control[data-fieldname="users"] .form-control .tb-selected-value').as( + "existing_value" + ); + cy.get("@existing_value").find(".btn-link-to-form").click(); + cy.location("pathname").should("contain", "/user/test@erpnext.com"); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/theme_switcher_dialog.js b/cypress/integration/theme_switcher_dialog.js index b4297e5674..158ff3e244 100644 --- a/cypress/integration/theme_switcher_dialog.js +++ b/cypress/integration/theme_switcher_dialog.js @@ -1,30 +1,29 @@ -context('Theme Switcher Shortcut', () => { +context("Theme Switcher Shortcut", () => { before(() => { cy.login(); - cy.visit('/app'); + cy.visit("/app"); }); beforeEach(() => { cy.reload(); }); - it('Check Toggle', () => { - cy.open_theme_dialog('{ctrl+shift+g}'); - cy.get('.modal-backdrop').should('exist'); - cy.get('.theme-grid > div').first().click(); - cy.close_theme('{ctrl+shift+g}'); - cy.get('.modal-backdrop').should('not.exist'); + it("Check Toggle", () => { + cy.open_theme_dialog("{ctrl+shift+g}"); + cy.get(".modal-backdrop").should("exist"); + cy.get(".theme-grid > div").first().click(); + cy.close_theme("{ctrl+shift+g}"); + cy.get(".modal-backdrop").should("not.exist"); }); - it('Check Enter', () => { - cy.open_theme_dialog('{ctrl+shift+g}'); - cy.get('.theme-grid > div').first().click(); - cy.close_theme('{enter}'); - cy.get('.modal-backdrop').should('not.exist'); + it("Check Enter", () => { + cy.open_theme_dialog("{ctrl+shift+g}"); + cy.get(".theme-grid > div").first().click(); + cy.close_theme("{enter}"); + cy.get(".modal-backdrop").should("not.exist"); }); - }); -Cypress.Commands.add('open_theme_dialog', (shortcut_keys) => { - cy.get('body').type(shortcut_keys); +Cypress.Commands.add("open_theme_dialog", (shortcut_keys) => { + cy.get("body").type(shortcut_keys); +}); +Cypress.Commands.add("close_theme", (shortcut_keys) => { + cy.get(".modal-header").type(shortcut_keys); }); -Cypress.Commands.add('close_theme', (shortcut_keys) => { - cy.get('.modal-header').type(shortcut_keys); -}); \ No newline at end of file diff --git a/cypress/integration/timeline.js b/cypress/integration/timeline.js index e7308fbaa7..5841891af6 100644 --- a/cypress/integration/timeline.js +++ b/cypress/integration/timeline.js @@ -1,83 +1,91 @@ -import custom_submittable_doctype from '../fixtures/custom_submittable_doctype'; +import custom_submittable_doctype from "../fixtures/custom_submittable_doctype"; -context('Timeline', () => { +context("Timeline", () => { before(() => { - cy.visit('/login'); + cy.visit("/login"); cy.login(); }); - it('Adding new ToDo, adding new comment, verifying comment addition & deletion and deleting ToDo', () => { + it("Adding new ToDo, adding new comment, verifying comment addition & deletion and deleting ToDo", () => { //Adding new ToDo - cy.visit('/app/todo/new-todo-1'); - cy.get('[data-fieldname="description"] .ql-editor.ql-blank').type('Test ToDo', {force: true}).wait(200); - cy.get('.page-head .page-actions').findByRole('button', {name: 'Save'}).click(); + cy.visit("/app/todo/new-todo-1"); + cy.get('[data-fieldname="description"] .ql-editor.ql-blank') + .type("Test ToDo", { force: true }) + .wait(200); + cy.get(".page-head .page-actions").findByRole("button", { name: "Save" }).click(); - cy.go_to_list('ToDo'); - cy.clear_filters() + cy.go_to_list("ToDo"); + cy.clear_filters(); cy.click_listview_row_item(0); //To check if the comment box is initially empty and tying some text into it - cy.get('[data-fieldname="comment"] .ql-editor').should('contain', '').type('Testing Timeline'); + cy.get('[data-fieldname="comment"] .ql-editor') + .should("contain", "") + .type("Testing Timeline"); //Adding new comment - cy.get('.comment-box').findByRole('button', {name: 'Comment'}).click(); + cy.get(".comment-box").findByRole("button", { name: "Comment" }).click(); //To check if the commented text is visible in the timeline content - cy.get('.timeline-content').should('contain', 'Testing Timeline'); + cy.get(".timeline-content").should("contain", "Testing Timeline"); //Editing comment cy.click_timeline_action_btn("Edit"); - cy.get('.timeline-content [data-fieldname="comment"] .ql-editor').first().type(' 123'); + cy.get('.timeline-content [data-fieldname="comment"] .ql-editor').first().type(" 123"); cy.click_timeline_action_btn("Save"); //To check if the edited comment text is visible in timeline content - cy.get('.timeline-content').should('contain', 'Testing Timeline 123'); + cy.get(".timeline-content").should("contain", "Testing Timeline 123"); //Discarding comment cy.click_timeline_action_btn("Edit"); cy.click_timeline_action_btn("Dismiss"); //To check if after discarding the timeline content is same as previous - cy.get('.timeline-content').should('contain', 'Testing Timeline 123'); + cy.get(".timeline-content").should("contain", "Testing Timeline 123"); //Deleting the added comment - cy.get('.timeline-message-box .more-actions > .action-btn').click(); //Menu button in timeline item - cy.get('.timeline-message-box .more-actions .dropdown-item').contains('Delete').click({ force: true }); - cy.get_open_dialog().findByRole('button', {name: 'Yes'}).click({ force: true }); + cy.get(".timeline-message-box .more-actions > .action-btn").click(); //Menu button in timeline item + cy.get(".timeline-message-box .more-actions .dropdown-item") + .contains("Delete") + .click({ force: true }); + cy.get_open_dialog().findByRole("button", { name: "Yes" }).click({ force: true }); - cy.get('.timeline-content').should('not.contain', 'Testing Timeline 123'); + cy.get(".timeline-content").should("not.contain", "Testing Timeline 123"); }); - it('Timeline should have submit and cancel activity information', () => { - cy.visit('/app/doctype'); + it("Timeline should have submit and cancel activity information", () => { + cy.visit("/app/doctype"); //Creating custom doctype - cy.insert_doc('DocType', custom_submittable_doctype, true); + cy.insert_doc("DocType", custom_submittable_doctype, true); - cy.visit('/app/custom-submittable-doctype'); - cy.click_listview_primary_button('Add Custom Submittable DocType'); + cy.visit("/app/custom-submittable-doctype"); + cy.click_listview_primary_button("Add Custom Submittable DocType"); //Adding a new entry for the created custom doctype - cy.fill_field('title', 'Test'); - cy.click_modal_primary_button('Save'); - cy.click_modal_primary_button('Submit'); + cy.fill_field("title", "Test"); + cy.click_modal_primary_button("Save"); + cy.click_modal_primary_button("Submit"); - cy.visit('/app/custom-submittable-doctype'); + cy.visit("/app/custom-submittable-doctype"); cy.click_listview_row_item(0); //To check if the submission of the documemt is visible in the timeline content - cy.get('.timeline-content').should('contain', 'Administrator submitted this document'); - cy.get('[id="page-Custom Submittable DocType"] .page-actions').findByRole('button', {name: 'Cancel'}).click(); - cy.get_open_dialog().findByRole('button', {name: 'Yes'}).click(); + cy.get(".timeline-content").should("contain", "Administrator submitted this document"); + cy.get('[id="page-Custom Submittable DocType"] .page-actions') + .findByRole("button", { name: "Cancel" }) + .click(); + cy.get_open_dialog().findByRole("button", { name: "Yes" }).click(); //To check if the cancellation of the documemt is visible in the timeline content - cy.get('.timeline-content').should('contain', 'Administrator cancelled this document'); + cy.get(".timeline-content").should("contain", "Administrator cancelled this document"); //Deleting the document - cy.visit('/app/custom-submittable-doctype'); + cy.visit("/app/custom-submittable-doctype"); cy.select_listview_row_checkbox(0); - cy.get('.page-actions').findByRole('button', {name: 'Actions'}).click(); + cy.get(".page-actions").findByRole("button", { name: "Actions" }).click(); cy.get('.page-actions .actions-btn-group [data-label="Delete"]').click(); - cy.click_modal_primary_button('Yes'); + cy.click_modal_primary_button("Yes"); }); }); diff --git a/cypress/integration/timeline_email.js b/cypress/integration/timeline_email.js index 993847bcb8..3a22f49bfa 100644 --- a/cypress/integration/timeline_email.js +++ b/cypress/integration/timeline_email.js @@ -1,76 +1,93 @@ -context('Timeline Email', () => { +context("Timeline Email", () => { before(() => { - cy.visit('/login'); + cy.visit("/login"); cy.login(); - cy.visit('/app/todo'); + cy.visit("/app/todo"); }); - it('Adding new ToDo', () => { - cy.click_listview_primary_button('Add ToDo'); - cy.get('.custom-actions:visible > .btn').contains("Edit Full Form").click({delay: 500}); - cy.fill_field("description", "Test ToDo", "Text Editor"); + it("Adding new ToDo", () => { + cy.click_listview_primary_button("Add ToDo"); + cy.get(".custom-actions:visible > .btn").contains("Edit Full Form").click({ delay: 500 }); + cy.fill_field("description", "Test ToDo", "Text Editor"); cy.wait(500); - cy.get('.primary-action').contains('Save').click({force: true}); + cy.get(".primary-action").contains("Save").click({ force: true }); cy.wait(700); }); - it('Adding email and verifying timeline content for email attachment', () => { - cy.visit('/app/todo'); - cy.click_listview_row_item_with_text('Test ToDo'); + it("Adding email and verifying timeline content for email attachment", () => { + cy.visit("/app/todo"); + cy.click_listview_row_item_with_text("Test ToDo"); //Creating a new email - cy.get('.timeline-actions > .timeline-item > .action-buttons > .action-btn').click(); - cy.fill_field('recipients', 'test@example.com', 'MultiSelect'); - cy.get('.modal.show > .modal-dialog > .modal-content > .modal-body > :nth-child(1) > .form-layout > .form-page > :nth-child(3) > .section-body > .form-column > form > [data-fieldtype="Text Editor"] > .form-group > .control-input-wrapper > .control-input > .ql-container > .ql-editor').type('Test Mail'); + cy.get(".timeline-actions > .timeline-item > .action-buttons > .action-btn").click(); + cy.fill_field("recipients", "test@example.com", "MultiSelect"); + cy.get( + '.modal.show > .modal-dialog > .modal-content > .modal-body > :nth-child(1) > .form-layout > .form-page > :nth-child(3) > .section-body > .form-column > form > [data-fieldtype="Text Editor"] > .form-group > .control-input-wrapper > .control-input > .ql-container > .ql-editor' + ).type("Test Mail"); //Adding attachment to the email - cy.get('.add-more-attachments > .btn').click(); - cy.get('.mt-2 > .btn > .mt-1').eq(2).click(); - cy.get('.input-group > .form-control').type('https://wallpaperplay.com/walls/full/8/2/b/72402.jpg'); - cy.get('.btn-primary').contains('Upload').click(); + cy.get(".add-more-attachments > .btn").click(); + cy.get(".mt-2 > .btn > .mt-1").eq(2).click(); + cy.get(".input-group > .form-control").type( + "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg" + ); + cy.get(".btn-primary").contains("Upload").click(); //Sending the email - cy.click_modal_primary_button('Send', {delay: 500}); + cy.click_modal_primary_button("Send", { delay: 500 }); //To check if the sent mail content is shown in the timeline content - cy.get('[data-doctype="Communication"] > .timeline-content').should('contain', 'Test Mail'); + cy.get('[data-doctype="Communication"] > .timeline-content').should( + "contain", + "Test Mail" + ); //To check if the attachment of email is shown in the timeline content - cy.get('.timeline-content').should('contain', 'Added 72402.jpg'); + cy.get(".timeline-content").should("contain", "Added 72402.jpg"); //Deleting the sent email - cy.get('[title="Open Communication"] > .icon').first().click({force: true}); - cy.get('#page-Communication > .page-head > .container > .row > .col > .standard-actions > .menu-btn-group > .btn').click(); - cy.get('#page-Communication > .page-head > .container > .row > .col > .standard-actions > .menu-btn-group > .dropdown-menu > li > .grey-link').eq(9).click(); - cy.get('.modal.show > .modal-dialog > .modal-content > .modal-footer > .standard-actions > .btn-primary').click(); + cy.get('[title="Open Communication"] > .icon').first().click({ force: true }); + cy.get( + "#page-Communication > .page-head > .container > .row > .col > .standard-actions > .menu-btn-group > .btn" + ).click(); + cy.get( + "#page-Communication > .page-head > .container > .row > .col > .standard-actions > .menu-btn-group > .dropdown-menu > li > .grey-link" + ) + .eq(9) + .click(); + cy.get( + ".modal.show > .modal-dialog > .modal-content > .modal-footer > .standard-actions > .btn-primary" + ).click(); }); - it('Deleting attachment and ToDo', () => { - cy.visit('/app/todo'); - cy.click_listview_row_item_with_text('Test ToDo'); + it("Deleting attachment and ToDo", () => { + cy.visit("/app/todo"); + cy.click_listview_row_item_with_text("Test ToDo"); //Removing the added attachment - cy.get('.attachment-row > .data-pill > .remove-btn > .icon').click(); + cy.get(".attachment-row > .data-pill > .remove-btn > .icon").click(); cy.wait(500); - cy.get('.modal-footer:visible > .standard-actions > .btn-primary').contains('Yes').click(); + cy.get(".modal-footer:visible > .standard-actions > .btn-primary").contains("Yes").click(); //To check if the removed attachment is shown in the timeline content - cy.get('.timeline-content').should('contain', 'Removed 72402.jpg'); + cy.get(".timeline-content").should("contain", "Removed 72402.jpg"); cy.wait(500); //To check if the discard button functionality in email is working correctly - cy.get('.timeline-actions > .timeline-item > .action-buttons > .action-btn').click(); - cy.fill_field('recipients', 'test@example.com', 'MultiSelect'); - cy.get('.modal-footer > .standard-actions > .btn-secondary').contains('Discard').click(); + cy.get(".timeline-actions > .timeline-item > .action-buttons > .action-btn").click(); + cy.fill_field("recipients", "test@example.com", "MultiSelect"); + cy.get(".modal-footer > .standard-actions > .btn-secondary").contains("Discard").click(); cy.wait(500); - cy.get('.timeline-actions > .timeline-item > .action-buttons > .action-btn').click(); + cy.get(".timeline-actions > .timeline-item > .action-buttons > .action-btn").click(); cy.wait(500); - cy.get_field('recipients', 'MultiSelect').should('have.text', ''); - cy.get('.modal-header:visible > .modal-actions > .btn-modal-close > .icon').click(); + cy.get_field("recipients", "MultiSelect").should("have.text", ""); + cy.get(".modal-header:visible > .modal-actions > .btn-modal-close > .icon").click(); //Deleting the added ToDo - cy.get('.menu-btn-group:visible > .btn').click(); - cy.get('.menu-btn-group:visible > .dropdown-menu > li > .dropdown-item').contains('Delete').click(); - cy.get('.modal-footer:visible > .standard-actions > .btn-primary').click(); + cy.get(".menu-btn-group:visible > .btn").click(); + cy.get(".menu-btn-group:visible > .dropdown-menu > li > .dropdown-item") + .contains("Delete") + .click(); + cy.get(".modal-footer:visible > .standard-actions > .btn-primary").click(); }); }); diff --git a/cypress/integration/url_data_field.js b/cypress/integration/url_data_field.js index cf22c62363..c74bc8b1a2 100644 --- a/cypress/integration/url_data_field.js +++ b/cypress/integration/url_data_field.js @@ -1,43 +1,42 @@ -import data_field_validation_doctype from '../fixtures/data_field_validation_doctype'; +import data_field_validation_doctype from "../fixtures/data_field_validation_doctype"; const doctype_name = data_field_validation_doctype.name; -context('URL Data Field Input', () => { +context("URL Data Field Input", () => { before(() => { cy.login(); - cy.visit('/app/website'); - return cy.insert_doc('DocType', data_field_validation_doctype, true); + cy.visit("/app/website"); + return cy.insert_doc("DocType", data_field_validation_doctype, true); }); - - describe('URL Data Field Input ', () => { - it('should not show URL link button without focus', () => { + describe("URL Data Field Input ", () => { + it("should not show URL link button without focus", () => { cy.new_form(doctype_name); - cy.get_field('url').clear().type('https://frappe.io'); - cy.get_field('url').blur().wait(500); - cy.get('.link-btn').should('not.be.visible'); + cy.get_field("url").clear().type("https://frappe.io"); + cy.get_field("url").blur().wait(500); + cy.get(".link-btn").should("not.be.visible"); }); - it('should show URL link button on focus', () => { - cy.get_field('url').focus().wait(500); - cy.get('.link-btn').should('be.visible'); + it("should show URL link button on focus", () => { + cy.get_field("url").focus().wait(500); + cy.get(".link-btn").should("be.visible"); }); - it('should not show URL link button for invalid URL', () => { - cy.get_field('url').clear().type('fuzzbuzz'); - cy.get('.link-btn').should('not.be.visible'); + it("should not show URL link button for invalid URL", () => { + cy.get_field("url").clear().type("fuzzbuzz"); + cy.get(".link-btn").should("not.be.visible"); }); - it('should have valid URL link with target _blank', () => { - cy.get_field('url').clear().type('https://frappe.io'); - cy.get('.link-btn .btn-open').should('have.attr', 'href', 'https://frappe.io'); - cy.get('.link-btn .btn-open').should('have.attr', 'target', '_blank'); + it("should have valid URL link with target _blank", () => { + cy.get_field("url").clear().type("https://frappe.io"); + cy.get(".link-btn .btn-open").should("have.attr", "href", "https://frappe.io"); + cy.get(".link-btn .btn-open").should("have.attr", "target", "_blank"); }); - it('should inject anchor tag in read-only URL data field', () => { + it("should inject anchor tag in read-only URL data field", () => { cy.get('[data-fieldname="read_only_url"]') - .find('a') - .should('have.attr', 'target', '_blank'); + .find("a") + .should("have.attr", "target", "_blank"); }); }); -}); \ No newline at end of file +}); diff --git a/cypress/integration/web_form.js b/cypress/integration/web_form.js index 74edee0eb9..d69d7ec576 100644 --- a/cypress/integration/web_form.js +++ b/cypress/integration/web_form.js @@ -1,256 +1,270 @@ -context('Web Form', () => { +context("Web Form", () => { before(() => { cy.login(); }); - it('Create Web Form', () => { - cy.visit('/app/web-form/new'); + it("Create Web Form", () => { + cy.visit("/app/web-form/new"); - cy.intercept('POST', '/api/method/frappe.desk.form.save.savedocs').as('save_form'); + cy.intercept("POST", "/api/method/frappe.desk.form.save.savedocs").as("save_form"); - cy.fill_field('title', 'Note'); - cy.fill_field('doc_type', 'Note', 'Link'); - cy.fill_field('module', 'Website', 'Link'); - cy.click_custom_action_button('Get Fields'); - cy.click_custom_action_button('Publish'); + cy.fill_field("title", "Note"); + cy.fill_field("doc_type", "Note", "Link"); + cy.fill_field("module", "Website", "Link"); + cy.click_custom_action_button("Get Fields"); + cy.click_custom_action_button("Publish"); - cy.wait('@save_form'); + cy.wait("@save_form"); - cy.get_field('route').should('have.value', 'note'); - cy.get('.title-area .indicator-pill').contains('Published'); + cy.get_field("route").should("have.value", "note"); + cy.get(".title-area .indicator-pill").contains("Published"); }); - it('Open Web Form (Logged in User)', () => { - cy.visit('/note'); + it("Open Web Form (Logged in User)", () => { + cy.visit("/note"); - cy.fill_field('title', 'Note 1'); - cy.get('.web-form-actions button').contains('Save').click(); + cy.fill_field("title", "Note 1"); + cy.get(".web-form-actions button").contains("Save").click(); - cy.url().should('include', '/note/Note%201'); + cy.url().should("include", "/note/Note%201"); - cy.visit('/note'); - cy.url().should('include', '/note/Note%201'); + cy.visit("/note"); + cy.url().should("include", "/note/Note%201"); }); - it('Open Web Form (Guest)', () => { - cy.request('/api/method/logout'); - cy.visit('/note'); + it("Open Web Form (Guest)", () => { + cy.request("/api/method/logout"); + cy.visit("/note"); - cy.url().should('include', '/note/new'); + cy.url().should("include", "/note/new"); - cy.fill_field('title', 'Guest Note 1'); - cy.get('.web-form-actions button').contains('Save').click(); + cy.fill_field("title", "Guest Note 1"); + cy.get(".web-form-actions button").contains("Save").click(); - cy.url().should('include', '/note/new'); + cy.url().should("include", "/note/new"); - cy.visit('/note'); - cy.url().should('include', '/note/new'); + cy.visit("/note"); + cy.url().should("include", "/note/new"); }); - it('Login Required', () => { + it("Login Required", () => { cy.login(); - cy.visit('/app/web-form/note'); + cy.visit("/app/web-form/note"); - cy.findByRole("tab", {name: "Form Settings"}).click(); - cy.get('input[data-fieldname="login_required"]').check({force: true}); + cy.findByRole("tab", { name: "Form Settings" }).click(); + cy.get('input[data-fieldname="login_required"]').check({ force: true }); cy.save(); - cy.visit('/note'); - cy.url().should('include', '/note/Note%201'); + cy.visit("/note"); + cy.url().should("include", "/note/Note%201"); - cy.call('logout'); + cy.call("logout"); - cy.visit('/note'); + cy.visit("/note"); cy.get_open_dialog() - .get('.modal-message') - .contains('You are not permitted to access this page without login.'); + .get(".modal-message") + .contains("You are not permitted to access this page without login."); }); - it('Show List', () => { + it("Show List", () => { cy.login(); - cy.visit('/app/web-form/note'); + cy.visit("/app/web-form/note"); - cy.findByRole("tab", {name: "List Settings"}).click(); + cy.findByRole("tab", { name: "List Settings" }).click(); cy.get('input[data-fieldname="show_list"]').check(); cy.save(); - cy.visit('/note'); - cy.url().should('include', '/note/list'); - cy.get('.web-list-table').should('be.visible'); + cy.visit("/note"); + cy.url().should("include", "/note/list"); + cy.get(".web-list-table").should("be.visible"); }); - it('Show Custom List Title', () => { - cy.visit('/app/web-form/note'); + it("Show Custom List Title", () => { + cy.visit("/app/web-form/note"); - cy.findByRole("tab", {name: "List Settings"}).click(); - cy.fill_field('list_title', 'Note List'); + cy.findByRole("tab", { name: "List Settings" }).click(); + cy.fill_field("list_title", "Note List"); cy.save(); - cy.visit('/note'); - cy.url().should('include', '/note/list'); - cy.get('.web-list-header h1').should('contain.text', 'Note List'); + cy.visit("/note"); + cy.url().should("include", "/note/list"); + cy.get(".web-list-header h1").should("contain.text", "Note List"); }); - it('Show Custom List Columns', () => { - cy.visit('/note'); - cy.url().should('include', '/note/list'); + it("Show Custom List Columns", () => { + cy.visit("/note"); + cy.url().should("include", "/note/list"); - cy.get('.web-list-table thead th').contains('Name'); - cy.get('.web-list-table thead th').contains('Title'); + cy.get(".web-list-table thead th").contains("Name"); + cy.get(".web-list-table thead th").contains("Title"); - cy.visit('/app/web-form/note'); + cy.visit("/app/web-form/note"); - cy.findByRole("tab", {name: "List Settings"}).click(); + cy.findByRole("tab", { name: "List Settings" }).click(); - cy.get('[data-fieldname="list_columns"] .grid-footer button').contains('Add Row').as('add-row'); + cy.get('[data-fieldname="list_columns"] .grid-footer button') + .contains("Add Row") + .as("add-row"); - cy.get('@add-row').click(); - cy.get('[data-fieldname="list_columns"] .grid-body .rows').as('grid-rows'); - cy.get('@grid-rows').find('.grid-row:first [data-fieldname="fieldname"]').click(); - cy.get('@grid-rows').find('.grid-row:first select[data-fieldname="fieldname"]').select('Title (Data)'); + cy.get("@add-row").click(); + cy.get('[data-fieldname="list_columns"] .grid-body .rows').as("grid-rows"); + cy.get("@grid-rows").find('.grid-row:first [data-fieldname="fieldname"]').click(); + cy.get("@grid-rows") + .find('.grid-row:first select[data-fieldname="fieldname"]') + .select("Title (Data)"); - cy.get('@add-row').click(); - cy.get('@grid-rows').find('.grid-row[data-idx="2"] [data-fieldname="fieldname"]').click(); - cy.get('@grid-rows').find('.grid-row[data-idx="2"] select[data-fieldname="fieldname"]').select('Public (Check)'); + cy.get("@add-row").click(); + cy.get("@grid-rows").find('.grid-row[data-idx="2"] [data-fieldname="fieldname"]').click(); + cy.get("@grid-rows") + .find('.grid-row[data-idx="2"] select[data-fieldname="fieldname"]') + .select("Public (Check)"); - cy.get('@add-row').click(); - cy.get('@grid-rows').find('.grid-row:last [data-fieldname="fieldname"]').click(); - cy.get('@grid-rows').find('.grid-row:last select[data-fieldname="fieldname"]').select('Content (Text Editor)'); + cy.get("@add-row").click(); + cy.get("@grid-rows").find('.grid-row:last [data-fieldname="fieldname"]').click(); + cy.get("@grid-rows") + .find('.grid-row:last select[data-fieldname="fieldname"]') + .select("Content (Text Editor)"); cy.save(); - cy.visit('/note'); - cy.url().should('include', '/note/list'); - cy.get('.web-list-table thead th').contains('Title'); - cy.get('.web-list-table thead th').contains('Public'); - cy.get('.web-list-table thead th').contains('Content'); + cy.visit("/note"); + cy.url().should("include", "/note/list"); + cy.get(".web-list-table thead th").contains("Title"); + cy.get(".web-list-table thead th").contains("Public"); + cy.get(".web-list-table thead th").contains("Content"); }); - it('Breadcrumbs', () => { - cy.visit('/note/Note 1'); - cy.get('.breadcrumb-container .breadcrumb .breadcrumb-item:first a') - .should('contain.text', 'Note').click(); - cy.url().should('include', '/note/list'); + it("Breadcrumbs", () => { + cy.visit("/note/Note 1"); + cy.get(".breadcrumb-container .breadcrumb .breadcrumb-item:first a") + .should("contain.text", "Note") + .click(); + cy.url().should("include", "/note/list"); }); - it('Custom Breadcrumbs', () => { - cy.visit('/app/web-form/note'); - - cy.findByRole("tab", {name: "Form Settings"}).click(); - cy.get('.form-section .section-head').contains('Customization').click(); - cy.fill_field('breadcrumbs', '[{"label": _("Notes"), "route":"note"}]', 'Code'); - cy.get('.form-section .section-head').contains('Customization').click(); + it("Custom Breadcrumbs", () => { + cy.visit("/app/web-form/note"); + + cy.findByRole("tab", { name: "Form Settings" }).click(); + cy.get(".form-section .section-head").contains("Customization").click(); + cy.fill_field("breadcrumbs", '[{"label": _("Notes"), "route":"note"}]', "Code"); + cy.get(".form-section .section-head").contains("Customization").click(); cy.save(); - cy.visit('/note/Note 1'); - cy.get('.breadcrumb-container .breadcrumb .breadcrumb-item:first a') - .should('contain.text', 'Notes'); + cy.visit("/note/Note 1"); + cy.get(".breadcrumb-container .breadcrumb .breadcrumb-item:first a").should( + "contain.text", + "Notes" + ); }); - it('Read Only', () => { + it("Read Only", () => { cy.login(); - cy.visit('/note'); - cy.url().should('include', '/note/list'); + cy.visit("/note"); + cy.url().should("include", "/note/list"); // Read Only Field cy.get('.web-list-table tbody tr[id="Note 1"]').click(); - cy.get('.frappe-control[data-fieldname="title"] .control-input') - .should('have.css', 'display', 'none'); + cy.get('.frappe-control[data-fieldname="title"] .control-input').should( + "have.css", + "display", + "none" + ); }); - it('Edit Mode', () => { - cy.visit('/app/web-form/note'); + it("Edit Mode", () => { + cy.visit("/app/web-form/note"); - cy.findByRole("tab", {name: "Form Settings"}).click(); + cy.findByRole("tab", { name: "Form Settings" }).click(); cy.get('input[data-fieldname="allow_edit"]').check(); cy.save(); - cy.visit('/note/Note 1'); - cy.url().should('include', '/note/Note%201'); + cy.visit("/note/Note 1"); + cy.url().should("include", "/note/Note%201"); - cy.get('.web-form-actions a').contains('Edit').click(); - cy.url().should('include', '/note/Note%201/edit'); + cy.get(".web-form-actions a").contains("Edit").click(); + cy.url().should("include", "/note/Note%201/edit"); // Editable Field - cy.get_field('title').should('have.value', 'Note 1'); - - cy.fill_field('title', ' Edited'); - cy.get('.web-form-actions button').contains('Save').click(); - cy.get_field('title').should('have.value', 'Note 1 Edited'); + cy.get_field("title").should("have.value", "Note 1"); + + cy.fill_field("title", " Edited"); + cy.get(".web-form-actions button").contains("Save").click(); + cy.get_field("title").should("have.value", "Note 1 Edited"); }); - it('Allow Multiple Response', () => { - cy.visit('/app/web-form/note'); + it("Allow Multiple Response", () => { + cy.visit("/app/web-form/note"); - cy.findByRole("tab", {name: "Form Settings"}).click(); + cy.findByRole("tab", { name: "Form Settings" }).click(); cy.get('input[data-fieldname="allow_multiple"]').check(); cy.save(); - cy.visit('/note'); - cy.url().should('include', '/note/list'); + cy.visit("/note"); + cy.url().should("include", "/note/list"); - cy.get('.web-list-actions a:visible').contains('New').click(); - cy.url().should('include', '/note/new'); + cy.get(".web-list-actions a:visible").contains("New").click(); + cy.url().should("include", "/note/new"); - cy.fill_field('title', 'Note 2'); - cy.get('.web-form-actions button').contains('Save').click(); + cy.fill_field("title", "Note 2"); + cy.get(".web-form-actions button").contains("Save").click(); }); - it('Allow Delete', () => { - cy.visit('/app/web-form/note'); + it("Allow Delete", () => { + cy.visit("/app/web-form/note"); - cy.findByRole("tab", {name: "Form Settings"}).click(); + cy.findByRole("tab", { name: "Form Settings" }).click(); cy.get('input[data-fieldname="allow_delete"]').check(); cy.save(); - cy.visit('/note'); - cy.url().should('include', '/note/list'); + cy.visit("/note"); + cy.url().should("include", "/note/list"); cy.get('.web-list-table tbody tr[id="Note 1"] .list-col-checkbox').click(); cy.get('.web-list-table tbody tr[id="Note 2"] .list-col-checkbox').click(); - cy.get('.web-list-actions button:visible').contains('Delete').click({force: true}); + cy.get(".web-list-actions button:visible").contains("Delete").click({ force: true }); - cy.get('.web-list-actions button').contains('Delete').should('not.be.visible'); + cy.get(".web-list-actions button").contains("Delete").should("not.be.visible"); - cy.visit('/note'); - cy.get('.web-list-table tbody tr[id="Note 1"]').should('not.exist'); - cy.get('.web-list-table tbody tr[id="Note 2"]').should('not.exist'); - cy.get('.web-list-table tbody tr[id="Guest Note 1"]').should('exist'); + cy.visit("/note"); + cy.get('.web-list-table tbody tr[id="Note 1"]').should("not.exist"); + cy.get('.web-list-table tbody tr[id="Note 2"]').should("not.exist"); + cy.get('.web-list-table tbody tr[id="Guest Note 1"]').should("exist"); }); - it('Navigate and Submit a WebForm', () => { - cy.visit('/update-profile'); + it("Navigate and Submit a WebForm", () => { + cy.visit("/update-profile"); - cy.get('.web-form-actions a').contains('Edit').click(); + cy.get(".web-form-actions a").contains("Edit").click(); - cy.fill_field('last_name', '_Test User'); + cy.fill_field("last_name", "_Test User"); - cy.get('.web-form-actions .btn-primary').click(); - cy.url().should('include', '/me'); + cy.get(".web-form-actions .btn-primary").click(); + cy.url().should("include", "/me"); }); - it('Navigate and Submit a MultiStep WebForm', () => { - cy.call('frappe.tests.ui_test_helpers.update_webform_to_multistep').then(() => { - cy.visit('/update-profile-duplicate'); + it("Navigate and Submit a MultiStep WebForm", () => { + cy.call("frappe.tests.ui_test_helpers.update_webform_to_multistep").then(() => { + cy.visit("/update-profile-duplicate"); - cy.get('.web-form-actions a').contains('Edit').click(); + cy.get(".web-form-actions a").contains("Edit").click(); - cy.fill_field('last_name', '_Test User'); + cy.fill_field("last_name", "_Test User"); - cy.get('.btn-next').should('be.visible'); - cy.get('.btn-next').click(); + cy.get(".btn-next").should("be.visible"); + cy.get(".btn-next").click(); - cy.get('.btn-previous').should('be.visible'); - cy.get('.btn-next').should('not.be.visible'); + cy.get(".btn-previous").should("be.visible"); + cy.get(".btn-next").should("not.be.visible"); - cy.get('.web-form-actions .btn-primary').click(); - cy.url().should('include', '/me'); + cy.get(".web-form-actions .btn-primary").click(); + cy.url().should("include", "/me"); }); }); }); diff --git a/cypress/integration/workspace.js b/cypress/integration/workspace.js index a12d86b3d6..e7d97c705b 100644 --- a/cypress/integration/workspace.js +++ b/cypress/integration/workspace.js @@ -1,185 +1,214 @@ -context('Workspace 2.0', () => { +context("Workspace 2.0", () => { before(() => { - cy.visit('/login'); + cy.visit("/login"); cy.login(); }); - it('Navigate to page from sidebar', () => { - cy.visit('/app/build'); - cy.get('.codex-editor__redactor .ce-block'); + it("Navigate to page from sidebar", () => { + cy.visit("/app/build"); + cy.get(".codex-editor__redactor .ce-block"); cy.get('.sidebar-item-container[item-name="Settings"]').first().click(); - cy.location('pathname').should('eq', '/app/settings'); + cy.location("pathname").should("eq", "/app/settings"); }); - it('Create Private Page', () => { + it("Create Private Page", () => { cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.doctype.workspace.workspace.new_page' - }).as('new_page'); + method: "POST", + url: "api/method/frappe.desk.doctype.workspace.workspace.new_page", + }).as("new_page"); - cy.get('.codex-editor__redactor .ce-block'); + cy.get(".codex-editor__redactor .ce-block"); cy.get('.custom-actions button[data-label="Create%20Workspace"]').click(); - cy.fill_field('title', 'Test Private Page', 'Data'); - cy.fill_field('icon', 'edit', 'Icon'); - cy.get_open_dialog().find('.modal-header').click(); - cy.get_open_dialog().find('.btn-primary').click(); + cy.fill_field("title", "Test Private Page", "Data"); + cy.fill_field("icon", "edit", "Icon"); + cy.get_open_dialog().find(".modal-header").click(); + cy.get_open_dialog().find(".btn-primary").click(); // check if sidebar item is added in pubic section - cy.get('.sidebar-item-container[item-name="Test Private Page"]').should('have.attr', 'item-public', '0'); + cy.get('.sidebar-item-container[item-name="Test Private Page"]').should( + "have.attr", + "item-public", + "0" + ); cy.get('.standard-actions .btn-primary[data-label="Save"]').click(); cy.wait(300); - cy.get('.sidebar-item-container[item-name="Test Private Page"]').should('have.attr', 'item-public', '0'); + cy.get('.sidebar-item-container[item-name="Test Private Page"]').should( + "have.attr", + "item-public", + "0" + ); - cy.wait('@new_page'); + cy.wait("@new_page"); }); - it('Create Child Page', () => { + it("Create Child Page", () => { cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.doctype.workspace.workspace.new_page' - }).as('new_page'); + method: "POST", + url: "api/method/frappe.desk.doctype.workspace.workspace.new_page", + }).as("new_page"); - cy.get('.codex-editor__redactor .ce-block'); + cy.get(".codex-editor__redactor .ce-block"); cy.get('.custom-actions button[data-label="Create%20Workspace"]').click(); - cy.fill_field('title', 'Test Child Page', 'Data'); - cy.fill_field('parent', 'Test Private Page', 'Select'); - cy.fill_field('icon', 'edit', 'Icon'); - cy.get_open_dialog().find('.modal-header').click(); - cy.get_open_dialog().find('.btn-primary').click(); + cy.fill_field("title", "Test Child Page", "Data"); + cy.fill_field("parent", "Test Private Page", "Select"); + cy.fill_field("icon", "edit", "Icon"); + cy.get_open_dialog().find(".modal-header").click(); + cy.get_open_dialog().find(".btn-primary").click(); // check if sidebar item is added in pubic section - cy.get('.sidebar-item-container[item-name="Test Child Page"]').should('have.attr', 'item-public', '0'); + cy.get('.sidebar-item-container[item-name="Test Child Page"]').should( + "have.attr", + "item-public", + "0" + ); cy.get('.standard-actions .btn-primary[data-label="Save"]').click(); cy.wait(300); - cy.get('.sidebar-item-container[item-name="Test Child Page"]').should('have.attr', 'item-public', '0'); + cy.get('.sidebar-item-container[item-name="Test Child Page"]').should( + "have.attr", + "item-public", + "0" + ); - cy.wait('@new_page'); + cy.wait("@new_page"); }); - it('Duplicate Page', () => { + it("Duplicate Page", () => { cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.doctype.workspace.workspace.duplicate_page' - }).as('page_duplicated'); + method: "POST", + url: "api/method/frappe.desk.doctype.workspace.workspace.duplicate_page", + }).as("page_duplicated"); - cy.get('.codex-editor__redactor .ce-block'); - cy.get('.standard-actions .btn-secondary[data-label=Edit]').click(); + cy.get(".codex-editor__redactor .ce-block"); + cy.get(".standard-actions .btn-secondary[data-label=Edit]").click(); - cy.get('.sidebar-item-container[item-name="Test Private Page"]').as('sidebar-item'); + cy.get('.sidebar-item-container[item-name="Test Private Page"]').as("sidebar-item"); - cy.get('@sidebar-item').find('.standard-sidebar-item').first().click(); - cy.get('@sidebar-item').find('.dropdown-btn').first().click(); - cy.get('@sidebar-item').find('.dropdown-list .dropdown-item').contains('Duplicate').first().click({force: true}); + cy.get("@sidebar-item").find(".standard-sidebar-item").first().click(); + cy.get("@sidebar-item").find(".dropdown-btn").first().click(); + cy.get("@sidebar-item") + .find(".dropdown-list .dropdown-item") + .contains("Duplicate") + .first() + .click({ force: true }); - cy.get_open_dialog().fill_field('title', 'Duplicate Page', 'Data'); - cy.click_modal_primary_button('Duplicate'); + cy.get_open_dialog().fill_field("title", "Duplicate Page", "Data"); + cy.click_modal_primary_button("Duplicate"); - cy.wait('@page_duplicated'); + cy.wait("@page_duplicated"); }); - it('Drag Sidebar Item', () => { + it("Drag Sidebar Item", () => { cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.doctype.workspace.workspace.sort_pages' - }).as('page_sorted'); + method: "POST", + url: "api/method/frappe.desk.doctype.workspace.workspace.sort_pages", + }).as("page_sorted"); - cy.get('.sidebar-item-container[item-name="Duplicate Page"]').as('sidebar-item'); + cy.get('.sidebar-item-container[item-name="Duplicate Page"]').as("sidebar-item"); - cy.get('@sidebar-item').find('.standard-sidebar-item').first().click(); - cy.get('@sidebar-item').find('.drag-handle').first().move({ deltaX: 0, deltaY: 100 }); + cy.get("@sidebar-item").find(".standard-sidebar-item").first().click(); + cy.get("@sidebar-item").find(".drag-handle").first().move({ deltaX: 0, deltaY: 100 }); - cy.get('.sidebar-item-container[item-name="Build"]').as('sidebar-item'); + cy.get('.sidebar-item-container[item-name="Build"]').as("sidebar-item"); - cy.get('@sidebar-item').find('.standard-sidebar-item').first().click(); - cy.get('@sidebar-item').find('.drag-handle').first().move({ deltaX: 0, deltaY: 100 }); + cy.get("@sidebar-item").find(".standard-sidebar-item").first().click(); + cy.get("@sidebar-item").find(".drag-handle").first().move({ deltaX: 0, deltaY: 100 }); - cy.wait('@page_sorted'); + cy.wait("@page_sorted"); }); - it('Edit Page Detail', () => { + it("Edit Page Detail", () => { cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.doctype.workspace.workspace.update_page' - }).as('page_updated'); + method: "POST", + url: "api/method/frappe.desk.doctype.workspace.workspace.update_page", + }).as("page_updated"); - cy.get('.sidebar-item-container[item-name="Test Private Page"]').as('sidebar-item'); + cy.get('.sidebar-item-container[item-name="Test Private Page"]').as("sidebar-item"); - cy.get('@sidebar-item').find('.standard-sidebar-item').first().click(); - cy.get('@sidebar-item').find('.dropdown-btn').first().click(); - cy.get('@sidebar-item').find('.dropdown-list .dropdown-item').contains('Edit').first().click({force: true}); + cy.get("@sidebar-item").find(".standard-sidebar-item").first().click(); + cy.get("@sidebar-item").find(".dropdown-btn").first().click(); + cy.get("@sidebar-item") + .find(".dropdown-list .dropdown-item") + .contains("Edit") + .first() + .click({ force: true }); - cy.get_open_dialog().fill_field('title', ' 1', 'Data'); + cy.get_open_dialog().fill_field("title", " 1", "Data"); cy.get_open_dialog().find('input[data-fieldname="is_public"]').check(); - cy.click_modal_primary_button('Update'); + cy.click_modal_primary_button("Update"); - cy.get('.standard-sidebar-section:first .sidebar-item-container[item-name="Test Private Page"]').should('not.exist'); - cy.get('.standard-sidebar-section:last .sidebar-item-container[item-name="Test Private Page 1"]').should('exist'); + cy.get( + '.standard-sidebar-section:first .sidebar-item-container[item-name="Test Private Page"]' + ).should("not.exist"); + cy.get( + '.standard-sidebar-section:last .sidebar-item-container[item-name="Test Private Page 1"]' + ).should("exist"); - cy.wait('@page_updated'); + cy.wait("@page_updated"); }); - it('Add New Block', () => { - cy.get('.sidebar-item-container[item-name="Duplicate Page"]').as('sidebar-item'); + it("Add New Block", () => { + cy.get('.sidebar-item-container[item-name="Duplicate Page"]').as("sidebar-item"); - cy.get('@sidebar-item').find('.standard-sidebar-item').first().click(); + cy.get("@sidebar-item").find(".standard-sidebar-item").first().click(); - cy.get('.ce-block').click().type('{enter}'); - cy.get('.block-list-container .block-list-item').contains('Heading').click(); - cy.get(":focus").type('Header'); - cy.get(".ce-block:last").find('.ce-header').should('exist'); + cy.get(".ce-block").click().type("{enter}"); + cy.get(".block-list-container .block-list-item").contains("Heading").click(); + cy.get(":focus").type("Header"); + cy.get(".ce-block:last").find(".ce-header").should("exist"); - cy.get('.ce-block:last').click().type('{enter}'); - cy.get('.block-list-container .block-list-item').contains('Text').click(); - cy.get(":focus").type('Paragraph text'); - cy.get(".ce-block:last").find('.ce-paragraph').should('exist'); + cy.get(".ce-block:last").click().type("{enter}"); + cy.get(".block-list-container .block-list-item").contains("Text").click(); + cy.get(":focus").type("Paragraph text"); + cy.get(".ce-block:last").find(".ce-paragraph").should("exist"); }); - it('Delete A Block', () => { + it("Delete A Block", () => { cy.get(":focus").click(); - cy.get('.paragraph-control .setting-btn').click(); - cy.get('.paragraph-control .dropdown-item').contains('Delete').click(); - cy.get(".ce-block:last").find('.ce-paragraph').should('not.exist'); + cy.get(".paragraph-control .setting-btn").click(); + cy.get(".paragraph-control .dropdown-item").contains("Delete").click(); + cy.get(".ce-block:last").find(".ce-paragraph").should("not.exist"); }); - it('Shrink and Expand A Block', () => { + it("Shrink and Expand A Block", () => { cy.get(":focus").click(); - cy.get('.ce-block:last .setting-btn').click(); - cy.get('.ce-block:last .dropdown-item').contains('Shrink').click(); - cy.get(".ce-block:last").should('have.class', 'col-xs-11'); - cy.get('.ce-block:last .dropdown-item').contains('Shrink').click(); - cy.get(".ce-block:last").should('have.class', 'col-xs-10'); - cy.get('.ce-block:last .dropdown-item').contains('Shrink').click(); - cy.get(".ce-block:last").should('have.class', 'col-xs-9'); - cy.get('.ce-block:last .dropdown-item').contains('Expand').click(); - cy.get(".ce-block:last").should('have.class', 'col-xs-10'); - cy.get('.ce-block:last .dropdown-item').contains('Expand').click(); - cy.get(".ce-block:last").should('have.class', 'col-xs-11'); - cy.get('.ce-block:last .dropdown-item').contains('Expand').click(); - cy.get(".ce-block:last").should('have.class', 'col-xs-12'); + cy.get(".ce-block:last .setting-btn").click(); + cy.get(".ce-block:last .dropdown-item").contains("Shrink").click(); + cy.get(".ce-block:last").should("have.class", "col-xs-11"); + cy.get(".ce-block:last .dropdown-item").contains("Shrink").click(); + cy.get(".ce-block:last").should("have.class", "col-xs-10"); + cy.get(".ce-block:last .dropdown-item").contains("Shrink").click(); + cy.get(".ce-block:last").should("have.class", "col-xs-9"); + cy.get(".ce-block:last .dropdown-item").contains("Expand").click(); + cy.get(".ce-block:last").should("have.class", "col-xs-10"); + cy.get(".ce-block:last .dropdown-item").contains("Expand").click(); + cy.get(".ce-block:last").should("have.class", "col-xs-11"); + cy.get(".ce-block:last .dropdown-item").contains("Expand").click(); + cy.get(".ce-block:last").should("have.class", "col-xs-12"); cy.get('.standard-actions .btn-primary[data-label="Save"]').click(); }); - it('Delete Duplicate Page', () => { + it("Delete Duplicate Page", () => { cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.doctype.workspace.workspace.delete_page' - }).as('page_deleted'); + method: "POST", + url: "api/method/frappe.desk.doctype.workspace.workspace.delete_page", + }).as("page_deleted"); - cy.get('.codex-editor__redactor .ce-block'); - cy.get('.standard-actions .btn-secondary[data-label=Edit]').click(); + cy.get(".codex-editor__redactor .ce-block"); + cy.get(".standard-actions .btn-secondary[data-label=Edit]").click(); cy.get('.sidebar-item-container[item-name="Duplicate Page"]') - .find('.sidebar-item-control .setting-btn').click(); + .find(".sidebar-item-control .setting-btn") + .click(); cy.get('.sidebar-item-container[item-name="Duplicate Page"]') - .find('.dropdown-item[title="Delete Workspace"]').click({force: true}); + .find('.dropdown-item[title="Delete Workspace"]') + .click({ force: true }); cy.wait(300); - cy.get('.modal-footer > .standard-actions > .btn-modal-primary:visible').first().click(); - cy.get('.sidebar-item-container[item-name="Duplicate Page"]').should('not.exist'); + cy.get(".modal-footer > .standard-actions > .btn-modal-primary:visible").first().click(); + cy.get('.sidebar-item-container[item-name="Duplicate Page"]').should("not.exist"); - cy.wait('@page_deleted'); + cy.wait("@page_deleted"); }); - -}); \ No newline at end of file +}); diff --git a/cypress/integration/workspace_blocks.js b/cypress/integration/workspace_blocks.js index 527cacab93..5b3167b3ac 100644 --- a/cypress/integration/workspace_blocks.js +++ b/cypress/integration/workspace_blocks.js @@ -1,140 +1,152 @@ -context('Workspace Blocks', () => { +context("Workspace Blocks", () => { before(() => { cy.login(); - cy.visit('/app'); - return cy.window().its('frappe').then(frappe => { - return frappe.xcall("frappe.tests.ui_test_helpers.setup_workflow"); - }); + cy.visit("/app"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.xcall("frappe.tests.ui_test_helpers.setup_workflow"); + }); }); - it('Create Test Page', () => { + it("Create Test Page", () => { cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.doctype.workspace.workspace.new_page' - }).as('new_page'); + method: "POST", + url: "api/method/frappe.desk.doctype.workspace.workspace.new_page", + }).as("new_page"); - cy.visit('/app/website'); - cy.get('.codex-editor__redactor .ce-block'); + cy.visit("/app/website"); + cy.get(".codex-editor__redactor .ce-block"); cy.get('.custom-actions button[data-label="Create%20Workspace"]').click(); - cy.fill_field('title', 'Test Block Page', 'Data'); - cy.fill_field('icon', 'edit', 'Icon'); - cy.get_open_dialog().find('.modal-header').click(); - cy.get_open_dialog().find('.btn-primary').click(); + cy.fill_field("title", "Test Block Page", "Data"); + cy.fill_field("icon", "edit", "Icon"); + cy.get_open_dialog().find(".modal-header").click(); + cy.get_open_dialog().find(".btn-primary").click(); // check if sidebar item is added in private section - cy.get('.sidebar-item-container[item-name="Test Block Page"]').should('have.attr', 'item-public', '0'); + cy.get('.sidebar-item-container[item-name="Test Block Page"]').should( + "have.attr", + "item-public", + "0" + ); cy.get('.standard-actions .btn-primary[data-label="Save"]').click(); cy.wait(300); - cy.get('.sidebar-item-container[item-name="Test Block Page"]').should('have.attr', 'item-public', '0'); + cy.get('.sidebar-item-container[item-name="Test Block Page"]').should( + "have.attr", + "item-public", + "0" + ); - cy.wait('@new_page'); + cy.wait("@new_page"); }); - it('Quick List Block', () => { + it("Quick List Block", () => { cy.create_records([ { - doctype: 'ToDo', - description: 'Quick List ToDo 1', - status: 'Open' + doctype: "ToDo", + description: "Quick List ToDo 1", + status: "Open", }, { - doctype: 'ToDo', - description: 'Quick List ToDo 2', - status: 'Open' + doctype: "ToDo", + description: "Quick List ToDo 2", + status: "Open", }, { - doctype: 'ToDo', - description: 'Quick List ToDo 3', - status: 'Open' + doctype: "ToDo", + description: "Quick List ToDo 3", + status: "Open", }, { - doctype: 'ToDo', - description: 'Quick List ToDo 4', - status: 'Open' - } + doctype: "ToDo", + description: "Quick List ToDo 4", + status: "Open", + }, ]); cy.intercept({ - method: 'GET', - url: 'api/method/frappe.desk.form.load.getdoctype' - }).as('get_doctype'); + method: "GET", + url: "api/method/frappe.desk.form.load.getdoctype", + }).as("get_doctype"); - cy.get('.codex-editor__redactor .ce-block'); - cy.get('.standard-actions .btn-secondary[data-label=Edit]').click(); + cy.get(".codex-editor__redactor .ce-block"); + cy.get(".standard-actions .btn-secondary[data-label=Edit]").click(); // test quick list creation - cy.get('.ce-block').first().click({force: true}).type('{enter}'); - cy.get('.block-list-container .block-list-item').contains('Quick List').click(); + cy.get(".ce-block").first().click({ force: true }).type("{enter}"); + cy.get(".block-list-container .block-list-item").contains("Quick List").click(); - cy.get_open_dialog().find('.modal-header').click(); + cy.get_open_dialog().find(".modal-header").click(); - cy.fill_field('document_type', 'ToDo', 'Link').blur(); - cy.fill_field('label', 'ToDo', 'Data').blur(); - cy.wait('@get_doctype'); + cy.fill_field("document_type", "ToDo", "Link").blur(); + cy.fill_field("label", "ToDo", "Data").blur(); + cy.wait("@get_doctype"); - cy.get_open_dialog().find('.filter-edit-area').should('contain', 'No filters selected'); - cy.get_open_dialog().find('.filter-area .add-filter').click(); + cy.get_open_dialog().find(".filter-edit-area").should("contain", "No filters selected"); + cy.get_open_dialog().find(".filter-area .add-filter").click(); - cy.get_open_dialog().find('.fieldname-select-area input').type('Workflow State{enter}').blur(); - cy.get_open_dialog().find('.filter-field .input-with-feedback').type('Pending'); + cy.get_open_dialog() + .find(".fieldname-select-area input") + .type("Workflow State{enter}") + .blur(); + cy.get_open_dialog().find(".filter-field .input-with-feedback").type("Pending"); - cy.get_open_dialog().find('.modal-header').click(); - cy.get_open_dialog().find('.btn-primary').click(); + cy.get_open_dialog().find(".modal-header").click(); + cy.get_open_dialog().find(".btn-primary").click(); cy.get('.standard-actions .btn-primary[data-label="Save"]').click(); + cy.get(".codex-editor__redactor .ce-block"); - cy.get('.codex-editor__redactor .ce-block'); + cy.get(".ce-block .quick-list-widget-box").first().as("todo-quick-list"); - cy.get('.ce-block .quick-list-widget-box').first().as('todo-quick-list'); - - cy.get('@todo-quick-list').find('.quick-list-item .status').should('contain', 'Pending'); + cy.get("@todo-quick-list").find(".quick-list-item .status").should("contain", "Pending"); // test quick-list-item - cy.get('@todo-quick-list').find('.quick-list-item .title') + cy.get("@todo-quick-list") + .find(".quick-list-item .title") .first() - .invoke('attr', 'title') - .then(title => { - cy.get('@todo-quick-list').find('.quick-list-item').contains(title).click(); - cy.get_field('description', 'Text Editor').should('contain', title); - cy.click_action_button('Approve'); + .invoke("attr", "title") + .then((title) => { + cy.get("@todo-quick-list").find(".quick-list-item").contains(title).click(); + cy.get_field("description", "Text Editor").should("contain", title); + cy.click_action_button("Approve"); }); - cy.go('back'); + cy.go("back"); // test filter-list - cy.get('@todo-quick-list').realHover().find('.widget-control .filter-list').click(); + cy.get("@todo-quick-list").realHover().find(".widget-control .filter-list").click(); - cy.get_open_dialog().find('.filter-field .input-with-feedback').type('{selectall}Approved'); - cy.get_open_dialog().find('.modal-header').click(); - cy.get_open_dialog().find('.btn-primary').click(); - - cy.get('@todo-quick-list').find('.quick-list-item .status').should('contain', 'Approved'); + cy.get_open_dialog() + .find(".filter-field .input-with-feedback") + .type("{selectall}Approved"); + cy.get_open_dialog().find(".modal-header").click(); + cy.get_open_dialog().find(".btn-primary").click(); + cy.get("@todo-quick-list").find(".quick-list-item .status").should("contain", "Approved"); // test refresh-list cy.intercept({ - method: 'POST', - url: 'api/method/frappe.desk.reportview.get' - }).as('refresh-list'); - - cy.get('@todo-quick-list').realHover().find('.widget-control .refresh-list').click(); - cy.wait('@refresh-list'); + method: "POST", + url: "api/method/frappe.desk.reportview.get", + }).as("refresh-list"); + cy.get("@todo-quick-list").realHover().find(".widget-control .refresh-list").click(); + cy.wait("@refresh-list"); // test add-new - cy.get('@todo-quick-list').realHover().find('.widget-control .add-new').click(); - cy.url().should('include', `/todo/new-todo-1`); - cy.go('back'); - + cy.get("@todo-quick-list").realHover().find(".widget-control .add-new").click(); + cy.url().should("include", `/todo/new-todo-1`); + cy.go("back"); // test see-all - cy.get('@todo-quick-list').find('.widget-footer .see-all').click(); + cy.get("@todo-quick-list").find(".widget-footer .see-all").click(); cy.open_list_filter(); cy.get('.filter-field input[data-fieldname="workflow_state"]') - .invoke('val') - .should('eq', 'Pending'); - cy.go('back'); + .invoke("val") + .should("eq", "Pending"); + cy.go("back"); }); - -}); \ No newline at end of file +}); diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index 9720faa666..b13275373c 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -12,6 +12,6 @@ // the project's config changing) module.exports = (on, config) => { - require('@cypress/code-coverage/task')(on, config); + require("@cypress/code-coverage/task")(on, config); return config; -}; \ No newline at end of file +}; diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 5424e8c6e4..cbb88cb8cb 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -1,6 +1,6 @@ -import 'cypress-file-upload'; -import '@testing-library/cypress/add-commands'; -import '@4tw/cypress-drag-drop'; +import "cypress-file-upload"; +import "@testing-library/cypress/add-commands"; +import "@4tw/cypress-drag-drop"; import "cypress-real-events/support"; // *********************************************** // This example commands.js shows you how to @@ -28,296 +28,304 @@ import "cypress-real-events/support"; // -- This is will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }); -Cypress.Commands.add('login', (email, password) => { +Cypress.Commands.add("login", (email, password) => { if (!email) { - email = 'Administrator'; + email = "Administrator"; } if (!password) { - password = Cypress.env('adminPassword'); + password = Cypress.env("adminPassword"); } cy.request({ - url: '/api/method/login', - method: 'POST', + url: "/api/method/login", + method: "POST", body: { usr: email, - pwd: password - } + pwd: password, + }, }); }); -Cypress.Commands.add('call', (method, args) => { +Cypress.Commands.add("call", (method, args) => { return cy .window() - .its('frappe.csrf_token') - .then(csrf_token => { + .its("frappe.csrf_token") + .then((csrf_token) => { return cy .request({ url: `/api/method/${method}`, - method: 'POST', + method: "POST", body: args, headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - 'X-Frappe-CSRF-Token': csrf_token - } + Accept: "application/json", + "Content-Type": "application/json", + "X-Frappe-CSRF-Token": csrf_token, + }, }) - .then(res => { + .then((res) => { expect(res.status).eq(200); return res.body; }); }); }); -Cypress.Commands.add('get_list', (doctype, fields = [], filters = []) => { +Cypress.Commands.add("get_list", (doctype, fields = [], filters = []) => { filters = JSON.stringify(filters); fields = JSON.stringify(fields); let url = `/api/resource/${doctype}?fields=${fields}&filters=${filters}`; return cy .window() - .its('frappe.csrf_token') - .then(csrf_token => { + .its("frappe.csrf_token") + .then((csrf_token) => { return cy .request({ - method: 'GET', + method: "GET", url, headers: { - Accept: 'application/json', - 'X-Frappe-CSRF-Token': csrf_token - } + Accept: "application/json", + "X-Frappe-CSRF-Token": csrf_token, + }, }) - .then(res => { + .then((res) => { expect(res.status).eq(200); return res.body; }); }); }); -Cypress.Commands.add('get_doc', (doctype, name) => { +Cypress.Commands.add("get_doc", (doctype, name) => { return cy .window() - .its('frappe.csrf_token') - .then(csrf_token => { + .its("frappe.csrf_token") + .then((csrf_token) => { return cy .request({ - method: 'GET', + method: "GET", url: `/api/resource/${doctype}/${name}`, headers: { - Accept: 'application/json', - 'X-Frappe-CSRF-Token': csrf_token - } + Accept: "application/json", + "X-Frappe-CSRF-Token": csrf_token, + }, }) - .then(res => { + .then((res) => { expect(res.status).eq(200); return res.body; }); }); }); -Cypress.Commands.add('remove_doc', (doctype, name) => { +Cypress.Commands.add("remove_doc", (doctype, name) => { return cy .window() - .its('frappe.csrf_token') - .then(csrf_token => { + .its("frappe.csrf_token") + .then((csrf_token) => { return cy .request({ - method: 'DELETE', + method: "DELETE", url: `/api/resource/${doctype}/${name}`, headers: { - Accept: 'application/json', - 'X-Frappe-CSRF-Token': csrf_token - } + Accept: "application/json", + "X-Frappe-CSRF-Token": csrf_token, + }, }) - .then(res => { + .then((res) => { expect(res.status).eq(202); return res.body; }); }); }); -Cypress.Commands.add('create_records', doc => { +Cypress.Commands.add("create_records", (doc) => { return cy - .call('frappe.tests.ui_test_helpers.create_if_not_exists', {doc: JSON.stringify(doc)}) - .then(r => r.message); + .call("frappe.tests.ui_test_helpers.create_if_not_exists", { doc: JSON.stringify(doc) }) + .then((r) => r.message); }); -Cypress.Commands.add('set_value', (doctype, name, obj) => { - return cy.call('frappe.client.set_value', { +Cypress.Commands.add("set_value", (doctype, name, obj) => { + return cy.call("frappe.client.set_value", { doctype, name, - fieldname: obj + fieldname: obj, }); }); -Cypress.Commands.add('fill_field', (fieldname, value, fieldtype = 'Data') => { - cy.get_field(fieldname, fieldtype).as('input'); +Cypress.Commands.add("fill_field", (fieldname, value, fieldtype = "Data") => { + cy.get_field(fieldname, fieldtype).as("input"); - if (['Date', 'Time', 'Datetime'].includes(fieldtype)) { - cy.get('@input').click().wait(200); - cy.get('.datepickers-container .datepicker.active').should('exist'); + if (["Date", "Time", "Datetime"].includes(fieldtype)) { + cy.get("@input").click().wait(200); + cy.get(".datepickers-container .datepicker.active").should("exist"); } - if (fieldtype === 'Time') { - cy.get('@input').clear().wait(200); + if (fieldtype === "Time") { + cy.get("@input").clear().wait(200); } - if (fieldtype === 'Select') { - cy.get('@input').select(value); + if (fieldtype === "Select") { + cy.get("@input").select(value); } else { - cy.get('@input').type(value, { + cy.get("@input").type(value, { waitForAnimations: false, parseSpecialCharSequences: false, force: true, - delay: 100 + delay: 100, }); } - return cy.get('@input'); + return cy.get("@input"); }); -Cypress.Commands.add('get_field', (fieldname, fieldtype = 'Data') => { - let field_element = fieldtype === 'Select' ? 'select': 'input'; +Cypress.Commands.add("get_field", (fieldname, fieldtype = "Data") => { + let field_element = fieldtype === "Select" ? "select" : "input"; let selector = `[data-fieldname="${fieldname}"] ${field_element}:visible`; - if (fieldtype === 'Text Editor') { + if (fieldtype === "Text Editor") { selector = `[data-fieldname="${fieldname}"] .ql-editor[contenteditable=true]:visible`; } - if (fieldtype === 'Code') { + if (fieldtype === "Code") { selector = `[data-fieldname="${fieldname}"] .ace_text-input`; } - if (fieldtype === 'Markdown Editor') { + if (fieldtype === "Markdown Editor") { selector = `[data-fieldname="${fieldname}"] .ace-editor-target`; } return cy.get(selector).first(); }); -Cypress.Commands.add('fill_table_field', (tablefieldname, row_idx, fieldname, value, fieldtype = 'Data') => { - cy.get_table_field(tablefieldname, row_idx, fieldname, fieldtype).as('input'); +Cypress.Commands.add( + "fill_table_field", + (tablefieldname, row_idx, fieldname, value, fieldtype = "Data") => { + cy.get_table_field(tablefieldname, row_idx, fieldname, fieldtype).as("input"); - if (['Date', 'Time', 'Datetime'].includes(fieldtype)) { - cy.get('@input').click().wait(200); - cy.get('.datepickers-container .datepicker.active').should('exist'); - } - if (fieldtype === 'Time') { - cy.get('@input').clear().wait(200); - } + if (["Date", "Time", "Datetime"].includes(fieldtype)) { + cy.get("@input").click().wait(200); + cy.get(".datepickers-container .datepicker.active").should("exist"); + } + if (fieldtype === "Time") { + cy.get("@input").clear().wait(200); + } - if (fieldtype === 'Select') { - cy.get('@input').select(value); - } else { - cy.get('@input').type(value, {waitForAnimations: false, force: true}); + if (fieldtype === "Select") { + cy.get("@input").select(value); + } else { + cy.get("@input").type(value, { waitForAnimations: false, force: true }); + } + return cy.get("@input"); } - return cy.get('@input'); +); + +Cypress.Commands.add( + "get_table_field", + (tablefieldname, row_idx, fieldname, fieldtype = "Data") => { + let selector = `.frappe-control[data-fieldname="${tablefieldname}"]`; + selector += ` [data-idx="${row_idx}"]`; + + if (fieldtype === "Text Editor") { + selector += ` [data-fieldname="${fieldname}"] .ql-editor[contenteditable=true]`; + } else if (fieldtype === "Code") { + selector += ` [data-fieldname="${fieldname}"] .ace_text-input`; + } else { + selector += ` [data-fieldname="${fieldname}"]`; + return cy.get(selector).find(".form-control:visible, .static-area:visible").first(); + } + return cy.get(selector); + } +); + +Cypress.Commands.add("awesomebar", (text) => { + cy.get("#navbar-search").type(`${text}{downarrow}{enter}`, { delay: 700 }); }); -Cypress.Commands.add('get_table_field', (tablefieldname, row_idx, fieldname, fieldtype = 'Data') => { - let selector = `.frappe-control[data-fieldname="${tablefieldname}"]`; - selector += ` [data-idx="${row_idx}"]`; - - if (fieldtype === 'Text Editor') { - selector += ` [data-fieldname="${fieldname}"] .ql-editor[contenteditable=true]`; - } else if (fieldtype === 'Code') { - selector += ` [data-fieldname="${fieldname}"] .ace_text-input`; - } else { - selector += ` [data-fieldname="${fieldname}"]`; - return cy.get(selector).find('.form-control:visible, .static-area:visible').first(); - } - return cy.get(selector); -}); - -Cypress.Commands.add('awesomebar', text => { - cy.get('#navbar-search').type(`${text}{downarrow}{enter}`, {delay: 700}); -}); - -Cypress.Commands.add('new_form', doctype => { - let dt_in_route = doctype.toLowerCase().replace(/ /g, '-'); +Cypress.Commands.add("new_form", (doctype) => { + let dt_in_route = doctype.toLowerCase().replace(/ /g, "-"); cy.visit(`/app/${dt_in_route}/new`); - 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'); + 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"); }); -Cypress.Commands.add('go_to_list', doctype => { - let dt_in_route = doctype.toLowerCase().replace(/ /g, '-'); +Cypress.Commands.add("go_to_list", (doctype) => { + let dt_in_route = doctype.toLowerCase().replace(/ /g, "-"); cy.visit(`/app/${dt_in_route}`); }); -Cypress.Commands.add('clear_cache', () => { +Cypress.Commands.add("clear_cache", () => { cy.window() - .its('frappe') - .then(frappe => { + .its("frappe") + .then((frappe) => { frappe.ui.toolbar.clear_cache(); }); }); -Cypress.Commands.add('dialog', opts => { - return cy.window({ log: false }).its('frappe', { log: false }).then(frappe => { - Cypress.log({ - name: "dialog", - displayName: "dialog", - message: 'frappe.ui.Dialog', - consoleProps: () => { - return { - options: opts, - dialog: d - } - } +Cypress.Commands.add("dialog", (opts) => { + return cy + .window({ log: false }) + .its("frappe", { log: false }) + .then((frappe) => { + Cypress.log({ + name: "dialog", + displayName: "dialog", + message: "frappe.ui.Dialog", + consoleProps: () => { + return { + options: opts, + dialog: d, + }; + }, + }); + + var d = new frappe.ui.Dialog(opts); + d.show(); + return d; }); - - var d = new frappe.ui.Dialog(opts); - d.show(); - return d; - }); }); -Cypress.Commands.add('get_open_dialog', () => { - return cy.get('.modal:visible').last(); +Cypress.Commands.add("get_open_dialog", () => { + return cy.get(".modal:visible").last(); }); -Cypress.Commands.add('save', () => { - cy.intercept('/api').as('api'); - cy.get(`button[data-label="Save"]:visible`).click({scrollBehavior: false, force: true}); - cy.wait('@api'); +Cypress.Commands.add("save", () => { + cy.intercept("/api").as("api"); + cy.get(`button[data-label="Save"]:visible`).click({ scrollBehavior: false, force: true }); + cy.wait("@api"); }); -Cypress.Commands.add('hide_dialog', () => { +Cypress.Commands.add("hide_dialog", () => { cy.wait(300); - cy.get_open_dialog().focus().find('.btn-modal-close').click(); - cy.get('.modal:visible').should('not.exist'); + cy.get_open_dialog().focus().find(".btn-modal-close").click(); + cy.get(".modal:visible").should("not.exist"); }); -Cypress.Commands.add('clear_dialogs', () => { +Cypress.Commands.add("clear_dialogs", () => { cy.window().then((win) => { - win.$('.modal, .modal-backdrop').remove(); + win.$(".modal, .modal-backdrop").remove(); }); - cy.get('.modal').should('not.exist'); + cy.get(".modal").should("not.exist"); }); -Cypress.Commands.add('clear_datepickers', () => { +Cypress.Commands.add("clear_datepickers", () => { cy.window().then((win) => { - win.$('.datepicker').remove(); + win.$(".datepicker").remove(); }); - cy.get('.datepicker').should('not.exist'); + cy.get(".datepicker").should("not.exist"); }); - -Cypress.Commands.add('insert_doc', (doctype, args, ignore_duplicate) => { +Cypress.Commands.add("insert_doc", (doctype, args, ignore_duplicate) => { if (!args.doctype) { args.doctype = doctype; } return cy .window() - .its('frappe.csrf_token') - .then(csrf_token => { + .its("frappe.csrf_token") + .then((csrf_token) => { return cy .request({ - method: 'POST', + method: "POST", url: `/api/resource/${doctype}`, body: args, headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - 'X-Frappe-CSRF-Token': csrf_token + Accept: "application/json", + "Content-Type": "application/json", + "X-Frappe-CSRF-Token": csrf_token, }, - failOnStatusCode: !ignore_duplicate + failOnStatusCode: !ignore_duplicate, }) - .then(res => { + .then((res) => { let status_codes = [200]; if (ignore_duplicate) { status_codes.push(409); @@ -325,7 +333,11 @@ Cypress.Commands.add('insert_doc', (doctype, args, ignore_duplicate) => { let message = null; if (ignore_duplicate && !status_codes.includes(res.status)) { - message = `Document insert failed, response: ${JSON.stringify(res, null, '\t')}`; + message = `Document insert failed, response: ${JSON.stringify( + res, + null, + "\t" + )}`; } expect(res.status).to.be.oneOf(status_codes, message); return res.body.data; @@ -333,112 +345,117 @@ Cypress.Commands.add('insert_doc', (doctype, args, ignore_duplicate) => { }); }); -Cypress.Commands.add('update_doc', (doctype, docname, args) => { +Cypress.Commands.add("update_doc", (doctype, docname, args) => { return cy .window() - .its('frappe.csrf_token') - .then(csrf_token => { + .its("frappe.csrf_token") + .then((csrf_token) => { return cy .request({ - method: 'PUT', + method: "PUT", url: `/api/resource/${doctype}/${docname}`, body: args, headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - 'X-Frappe-CSRF-Token': csrf_token + Accept: "application/json", + "Content-Type": "application/json", + "X-Frappe-CSRF-Token": csrf_token, }, }) - .then(res => { + .then((res) => { expect(res.status).to.eq(200); return res.body.data; }); }); }); - -Cypress.Commands.add('open_list_filter', () => { - cy.get('.filter-section .filter-button').click(); +Cypress.Commands.add("open_list_filter", () => { + cy.get(".filter-section .filter-button").click(); cy.wait(300); - cy.get('.filter-popover').should('exist'); + cy.get(".filter-popover").should("exist"); }); -Cypress.Commands.add('click_custom_action_button', (name) => { +Cypress.Commands.add("click_custom_action_button", (name) => { cy.get(`.custom-actions [data-label="${encodeURIComponent(name)}"]`).click(); }); -Cypress.Commands.add('click_action_button', (name) => { - cy.findByRole('button', {name: 'Actions'}).click(); +Cypress.Commands.add("click_action_button", (name) => { + cy.findByRole("button", { name: "Actions" }).click(); cy.get(`.actions-btn-group [data-label="${encodeURIComponent(name)}"]`).click(); }); -Cypress.Commands.add('click_menu_button', (name) => { - cy.get('.standard-actions .menu-btn-group > .btn').click(); +Cypress.Commands.add("click_menu_button", (name) => { + cy.get(".standard-actions .menu-btn-group > .btn").click(); cy.get(`.menu-btn-group [data-label="${encodeURIComponent(name)}"]`).click(); }); -Cypress.Commands.add('clear_filters', () => { +Cypress.Commands.add("clear_filters", () => { let has_filter = false; cy.intercept({ - method: 'POST', - url: 'api/method/frappe.model.utils.user_settings.save' - }).as('filter-saved'); - cy.get('.filter-section .filter-button').click({force: true}); + method: "POST", + url: "api/method/frappe.model.utils.user_settings.save", + }).as("filter-saved"); + cy.get(".filter-section .filter-button").click({ force: true }); cy.wait(300); - cy.get('.filter-popover').should('exist'); - cy.get('.filter-popover').then(popover => { - if (popover.find('input.input-with-feedback')[0].value != '') { + cy.get(".filter-popover").should("exist"); + cy.get(".filter-popover").then((popover) => { + if (popover.find("input.input-with-feedback")[0].value != "") { has_filter = true; } }); - cy.get('.filter-popover').find('.clear-filters').click(); - cy.get('.filter-section .filter-button').click(); - cy.window().its('cur_list').then(cur_list => { - cur_list && cur_list.filter_area && cur_list.filter_area.clear(); - has_filter && cy.wait('@filter-saved'); - }); + cy.get(".filter-popover").find(".clear-filters").click(); + cy.get(".filter-section .filter-button").click(); + cy.window() + .its("cur_list") + .then((cur_list) => { + cur_list && cur_list.filter_area && cur_list.filter_area.clear(); + has_filter && cy.wait("@filter-saved"); + }); }); -Cypress.Commands.add('click_modal_primary_button', (btn_name) => { +Cypress.Commands.add("click_modal_primary_button", (btn_name) => { cy.wait(400); - cy.get('.modal-footer > .standard-actions > .btn-primary').contains(btn_name).click({force: true}); + cy.get(".modal-footer > .standard-actions > .btn-primary") + .contains(btn_name) + .click({ force: true }); }); -Cypress.Commands.add('click_sidebar_button', (btn_name) => { - cy.get('.list-group-by-fields .list-link > a').contains(btn_name).click({force: true}); +Cypress.Commands.add("click_sidebar_button", (btn_name) => { + cy.get(".list-group-by-fields .list-link > a").contains(btn_name).click({ force: true }); }); -Cypress.Commands.add('click_listview_row_item', (row_no) => { - cy.get('.list-row > .level-left > .list-subject > .level-item > .ellipsis').eq(row_no).click({force: true}); +Cypress.Commands.add("click_listview_row_item", (row_no) => { + cy.get(".list-row > .level-left > .list-subject > .level-item > .ellipsis") + .eq(row_no) + .click({ force: true }); }); -Cypress.Commands.add('click_listview_row_item_with_text', (text) => { - cy.get('.list-row > .level-left > .list-subject > .level-item > .ellipsis') +Cypress.Commands.add("click_listview_row_item_with_text", (text) => { + cy.get(".list-row > .level-left > .list-subject > .level-item > .ellipsis") .contains(text) .first() - .click({force: true}); + .click({ force: true }); }); -Cypress.Commands.add('click_filter_button', () => { - cy.get('.filter-selector > .btn').click(); +Cypress.Commands.add("click_filter_button", () => { + cy.get(".filter-selector > .btn").click(); }); -Cypress.Commands.add('click_listview_primary_button', (btn_name) => { - cy.get('.primary-action').contains(btn_name).click({force: true}); +Cypress.Commands.add("click_listview_primary_button", (btn_name) => { + cy.get(".primary-action").contains(btn_name).click({ force: true }); }); -Cypress.Commands.add('click_doc_primary_button', (btn_name) => { - cy.get('.primary-action').contains(btn_name).click({force: true}); +Cypress.Commands.add("click_doc_primary_button", (btn_name) => { + cy.get(".primary-action").contains(btn_name).click({ force: true }); }); -Cypress.Commands.add('click_timeline_action_btn', (btn_name) => { - cy.get('.timeline-message-box .actions .action-btn').contains(btn_name).click(); +Cypress.Commands.add("click_timeline_action_btn", (btn_name) => { + cy.get(".timeline-message-box .actions .action-btn").contains(btn_name).click(); }); -Cypress.Commands.add('select_listview_row_checkbox', (row_no) => { - cy.get('.frappe-list .select-like > .list-row-checkbox').eq(row_no).click(); +Cypress.Commands.add("select_listview_row_checkbox", (row_no) => { + cy.get(".frappe-list .select-like > .list-row-checkbox").eq(row_no).click(); }); -Cypress.Commands.add('click_form_section', (section_name) => { - cy.get('.section-head').contains(section_name).click(); +Cypress.Commands.add("click_form_section", (section_name) => { + cy.get(".section-head").contains(section_name).click(); }); diff --git a/cypress/support/index.js b/cypress/support/index.js index 5980e96677..8ce8317a2f 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -14,10 +14,10 @@ // *********************************************************** // Import commands.js using ES2015 syntax: -import './commands'; -import '@cypress/code-coverage/support'; +import "./commands"; +import "@cypress/code-coverage/support"; -Cypress.on('uncaught:exception', (err, runnable) => { +Cypress.on("uncaught:exception", (err, runnable) => { return false; }); @@ -25,5 +25,5 @@ Cypress.on('uncaught:exception', (err, runnable) => { // require('./commands') Cypress.Cookies.defaults({ - preserve: 'sid' -}); \ No newline at end of file + preserve: "sid", +}); diff --git a/esbuild/build-cleanup.js b/esbuild/build-cleanup.js index cf03606a34..023fce08c5 100644 --- a/esbuild/build-cleanup.js +++ b/esbuild/build-cleanup.js @@ -4,9 +4,9 @@ const fs = require("fs"); const glob = require("fast-glob"); module.exports = { - name: 'build_cleanup', + name: "build_cleanup", setup(build) { - build.onEnd(result => { + build.onEnd((result) => { if (result.errors.length) return; clean_dist_files(Object.keys(result.metafile.outputs)); }); @@ -14,25 +14,18 @@ module.exports = { }; function clean_dist_files(new_files) { - new_files.forEach( - file => { - if (file.endsWith(".map")) return; + new_files.forEach((file) => { + if (file.endsWith(".map")) return; - const pattern = file.split(".").slice(0, -2).join(".") + "*"; - glob.sync(pattern).forEach( - file_to_delete => { - if (file_to_delete.startsWith(file)) return; + const pattern = file.split(".").slice(0, -2).join(".") + "*"; + glob.sync(pattern).forEach((file_to_delete) => { + if (file_to_delete.startsWith(file)) return; - fs.unlink(path.resolve(file_to_delete), err => { - if (!err) return; + fs.unlink(path.resolve(file_to_delete), (err) => { + if (!err) return; - console.error( - `Error deleting ${file.split(path.sep).pop()}` - ); - }); - } - - ); - } - ); -} \ No newline at end of file + console.error(`Error deleting ${file.split(path.sep).pop()}`); + }); + }); + }); +} diff --git a/esbuild/esbuild.js b/esbuild/esbuild.js index 4aa1ebc824..56910cbcac 100644 --- a/esbuild/esbuild.js +++ b/esbuild/esbuild.js @@ -8,7 +8,7 @@ const yargs = require("yargs"); const cliui = require("cliui")(); const chalk = require("chalk"); const html_plugin = require("./frappe-html"); -const rtlcss = require('rtlcss'); +const rtlcss = require("rtlcss"); const postCssPlugin = require("@frappe/esbuild-plugin-postcss2").default; const ignore_assets = require("./ignore-assets"); const sass_options = require("./sass_options"); @@ -25,44 +25,41 @@ const { log_warn, log_error, bench_path, - get_redis_subscriber + get_redis_subscriber, } = require("./utils"); const argv = yargs .usage("Usage: node esbuild [options]") .option("apps", { type: "string", - description: "Run build for specific apps" + description: "Run build for specific apps", }) .option("skip_frappe", { type: "boolean", - description: "Skip building frappe assets" + description: "Skip building frappe assets", }) .option("files", { type: "string", - description: "Run build for specified bundles" + description: "Run build for specified bundles", }) .option("watch", { type: "boolean", - description: "Run in watch mode and rebuild on file changes" + description: "Run in watch mode and rebuild on file changes", }) .option("live-reload", { type: "boolean", description: `Automatically reload Desk when assets are rebuilt. - Can only be used with the --watch flag.` + Can only be used with the --watch flag.`, }) .option("production", { type: "boolean", - description: "Run build in production mode" + description: "Run build in production mode", }) .option("run-build-command", { type: "boolean", - description: "Run build command for apps" + description: "Run build command for apps", }) - .example( - "node esbuild --apps frappe,erpnext", - "Run build only for frappe and erpnext" - ) + .example("node esbuild --apps frappe,erpnext", "Run build only for frappe and erpnext") .example( "node esbuild --files frappe/website.bundle.js,frappe/desk.bundle.js", "Run build only for specified bundles" @@ -70,7 +67,7 @@ const argv = yargs .version(false).argv; const APPS = (!argv.apps ? app_list : argv.apps.split(",")).filter( - app => !(argv.skip_frappe && app == "frappe") + (app) => !(argv.skip_frappe && app == "frappe") ); const FILES_TO_BUILD = argv.files ? argv.files.split(",") : []; const WATCH_MODE = Boolean(argv.watch); @@ -81,17 +78,15 @@ const TOTAL_BUILD_TIME = `${chalk.black.bgGreen(" DONE ")} Total Build Time`; const NODE_PATHS = [].concat( // node_modules of apps directly importable app_list - .map(app => path.resolve(get_app_path(app), "../node_modules")) + .map((app) => path.resolve(get_app_path(app), "../node_modules")) .filter(fs.existsSync), // import js file of any app if you provide the full path - app_list - .map(app => path.resolve(get_app_path(app), "..")) - .filter(fs.existsSync) + app_list.map((app) => path.resolve(get_app_path(app), "..")).filter(fs.existsSync) ); execute() .then(() => RUN_BUILD_COMMAND && run_build_command_for_apps(APPS)) - .catch(e => console.error(e)); + .catch((e) => console.error(e)); if (WATCH_MODE) { // listen for open files in editor event @@ -131,7 +126,7 @@ function build_assets_for_apps(apps, files) { ? get_files_to_build(files) : get_all_files_to_build(apps); - return glob(include_patterns, { ignore: ignore_patterns }).then(files => { + return glob(include_patterns, { ignore: ignore_patterns }).then((files) => { let output_path = assets_path; let file_map = {}; @@ -143,39 +138,38 @@ function build_assets_for_apps(apps, files) { let extension = path.extname(file); let output_name = path.basename(file, extension); - if ( - [".css", ".scss", ".less", ".sass", ".styl"].includes(extension) - ) { + if ([".css", ".scss", ".less", ".sass", ".styl"].includes(extension)) { output_name = path.join("css", output_name); } else if ([".js", ".ts"].includes(extension)) { output_name = path.join("js", output_name); } output_name = path.join(app, "dist", output_name); - if (Object.keys(file_map).includes(output_name) || Object.keys(style_file_map).includes(output_name)) { - log_warn( - `Duplicate output file ${output_name} generated from ${file}` - ); + if ( + Object.keys(file_map).includes(output_name) || + Object.keys(style_file_map).includes(output_name) + ) { + log_warn(`Duplicate output file ${output_name} generated from ${file}`); } if ([".css", ".scss", ".less", ".sass", ".styl"].includes(extension)) { style_file_map[output_name] = file; - rtl_style_file_map[output_name.replace('/css/', '/css-rtl/')] = file; + rtl_style_file_map[output_name.replace("/css/", "/css-rtl/")] = file; } else { file_map[output_name] = file; } } let build = build_files({ files: file_map, - outdir: output_path + outdir: output_path, }); let style_build = build_style_files({ files: style_file_map, - outdir: output_path + outdir: output_path, }); let rtl_style_build = build_style_files({ files: rtl_style_file_map, outdir: output_path, - rtl_style: true + rtl_style: true, }); return Promise.all([build, style_build, rtl_style_build]); }); @@ -188,11 +182,7 @@ function get_all_files_to_build(apps) { for (let app of apps) { let public_path = get_public_path(app); include_patterns.push( - path.resolve( - public_path, - "**", - "*.bundle.{js,ts,css,sass,scss,less,styl}" - ) + path.resolve(public_path, "**", "*.bundle.{js,ts,css,sass,scss,less,styl}") ); ignore_patterns.push( path.resolve(public_path, "node_modules"), @@ -202,7 +192,7 @@ function get_all_files_to_build(apps) { return { include_patterns, - ignore_patterns + ignore_patterns, }; } @@ -223,16 +213,12 @@ function get_files_to_build(files) { return { include_patterns, - ignore_patterns + ignore_patterns, }; } function build_files({ files, outdir }) { - let build_plugins = [ - html_plugin, - build_cleanup_plugin, - vue(), - ]; + let build_plugins = [html_plugin, build_cleanup_plugin, vue()]; return esbuild.build(get_build_options(files, outdir, build_plugins)); } @@ -247,8 +233,8 @@ function build_style_files({ files, outdir, rtl_style = false }) { build_cleanup_plugin, postCssPlugin({ plugins: plugins, - sassOptions: sass_options - }) + sassOptions: sass_options, + }), ]; plugins.push(require("autoprefixer")); @@ -259,7 +245,7 @@ function get_build_options(files, outdir, plugins) { return { entryPoints: files, entryNames: "[dir]/[name].[hash]", - target: ['es2017'], + target: ["es2017"], outdir, sourcemap: true, bundle: true, @@ -267,12 +253,10 @@ function get_build_options(files, outdir, plugins) { minify: PRODUCTION, nodePaths: NODE_PATHS, define: { - "process.env.NODE_ENV": JSON.stringify( - PRODUCTION ? "production" : "development" - ) + "process.env.NODE_ENV": JSON.stringify(PRODUCTION ? "production" : "development"), }, plugins: plugins, - watch: get_watch_config() + watch: get_watch_config(), }; } @@ -286,17 +270,13 @@ function get_watch_config() { log(chalk.dim(error.stack)); notify_redis({ error }); } else { - let { - new_assets_json, - prev_assets_json - } = await write_assets_json(result.metafile); + let { new_assets_json, prev_assets_json } = await write_assets_json( + result.metafile + ); let changed_files; if (prev_assets_json) { - changed_files = get_rebuilt_assets( - prev_assets_json, - new_assets_json - ); + changed_files = get_rebuilt_assets(prev_assets_json, new_assets_json); let timestamp = new Date().toLocaleTimeString(); let message = `${timestamp}: Compiled ${changed_files.length} files...`; @@ -309,7 +289,7 @@ function get_watch_config() { } notify_redis({ success: true, changed_files }); } - } + }, }; } return null; @@ -324,11 +304,11 @@ function log_built_assets(results) { cliui.div( { text: chalk.cyan.bold("File"), - width: column_widths[0] + width: column_widths[0], }, { text: chalk.cyan.bold("Size"), - width: column_widths[1] + width: column_widths[1], } ); cliui.div(""); @@ -344,7 +324,7 @@ function log_built_assets(results) { output_by_dist_path[dist_path] = output_by_dist_path[dist_path] || []; output_by_dist_path[dist_path].push({ name: filename, - size: (data.bytes / 1000).toFixed(2) + " Kb" + size: (data.bytes / 1000).toFixed(2) + " Kb", }); } @@ -352,7 +332,7 @@ function log_built_assets(results) { let files = output_by_dist_path[dist_path]; cliui.div({ text: dist_path, - width: column_widths[0] + width: column_widths[0], }); for (let i in files) { @@ -367,11 +347,11 @@ function log_built_assets(results) { cliui.div( { text: branch + chalk[color]("" + file.name), - width: column_widths[0] + width: column_widths[0], }, { text: file.size, - width: column_widths[1] + width: column_widths[1], } ); } @@ -393,7 +373,7 @@ async function write_assets_json(metafile) { let asset_path = "/" + path.relative(sites_path, output); if (info.entryPoint) { let key = path.basename(info.entryPoint); - if (key.endsWith('.css') && asset_path.includes('/css-rtl/')) { + if (key.endsWith(".css") && asset_path.includes("/css-rtl/")) { rtl = true; key = `rtl_${key}`; } @@ -401,7 +381,7 @@ async function write_assets_json(metafile) { } } - let assets_json_path = path.resolve(assets_path, `assets${rtl?'-rtl':''}.json`); + let assets_json_path = path.resolve(assets_path, `assets${rtl ? "-rtl" : ""}.json`); let assets_json; try { assets_json = await fs.promises.readFile(assets_json_path, "utf-8"); @@ -413,26 +393,23 @@ async function write_assets_json(metafile) { let new_assets_json = Object.assign({}, assets_json, out); curr_assets_json = new_assets_json; - await fs.promises.writeFile( - assets_json_path, - JSON.stringify(new_assets_json, null, 4) - ); + await fs.promises.writeFile(assets_json_path, JSON.stringify(new_assets_json, null, 4)); await update_assets_json_in_cache(); return { new_assets_json, - prev_assets_json + prev_assets_json, }; } function update_assets_json_in_cache() { // update assets_json cache in redis, so that it can be read directly by python - return new Promise(resolve => { + return new Promise((resolve) => { let client = get_redis_subscriber("redis_cache"); // handle error event to avoid printing stack traces - client.on("error", _ => { + client.on("error", (_) => { log_warn("Cannot connect to redis_cache to update assets_json"); }); - client.del("assets_json", err => { + client.del("assets_json", (err) => { client.unref(); resolve(); }); @@ -464,7 +441,7 @@ function run_build_command_for_apps(apps) { async function notify_redis({ error, success, changed_files }) { // notify redis which in turns tells socketio to publish this to browser let subscriber = get_redis_subscriber("redis_socketio"); - subscriber.on("error", _ => { + subscriber.on("error", (_) => { log_warn("Cannot connect to redis_socketio for browser events"); }); @@ -472,20 +449,20 @@ async function notify_redis({ error, success, changed_files }) { if (error) { let formatted = await esbuild.formatMessages(error.errors, { kind: "error", - terminalWidth: 100 + terminalWidth: 100, }); let stack = error.stack.replace(new RegExp(bench_path, "g"), ""); payload = { error, formatted, - stack + stack, }; } if (success) { payload = { success: true, changed_files, - live_reload: argv["live-reload"] + live_reload: argv["live-reload"], }; } @@ -493,14 +470,14 @@ async function notify_redis({ error, success, changed_files }) { "events", JSON.stringify({ event: "build_event", - message: payload + message: payload, }) ); } function open_in_editor() { let subscriber = get_redis_subscriber("redis_socketio"); - subscriber.on("error", _ => { + subscriber.on("error", (_) => { log_warn("Cannot connect to redis_socketio for open_in_editor events"); }); subscriber.on("message", (event, file) => { diff --git a/esbuild/frappe-html.js b/esbuild/frappe-html.js index 9a7edb144d..d38a0c23cb 100644 --- a/esbuild/frappe-html.js +++ b/esbuild/frappe-html.js @@ -4,24 +4,24 @@ module.exports = { let path = require("path"); let fs = require("fs/promises"); - build.onResolve({ filter: /\.html$/ }, args => { + build.onResolve({ filter: /\.html$/ }, (args) => { return { path: path.join(args.resolveDir, args.path), - namespace: "frappe-html" + namespace: "frappe-html", }; }); - build.onLoad({ filter: /.*/, namespace: "frappe-html" }, args => { + build.onLoad({ filter: /.*/, namespace: "frappe-html" }, (args) => { let filepath = args.path; let filename = path.basename(filepath).split(".")[0]; return fs .readFile(filepath, "utf-8") - .then(content => { + .then((content) => { content = scrub_html_template(content); return { contents: `\n\tfrappe.templates['${filename}'] = \`${content}\`;\n`, - watchFiles: [filepath] + watchFiles: [filepath], }; }) .catch(() => { @@ -29,13 +29,13 @@ module.exports = { contents: "", warnings: [ { - text: `There was an error importing ${filepath}` - } - ] + text: `There was an error importing ${filepath}`, + }, + ], }; }); }); - } + }, }; function scrub_html_template(content) { diff --git a/esbuild/ignore-assets.js b/esbuild/ignore-assets.js index 5edfef2110..fad7a95e0d 100644 --- a/esbuild/ignore-assets.js +++ b/esbuild/ignore-assets.js @@ -1,11 +1,11 @@ module.exports = { name: "frappe-ignore-asset", setup(build) { - build.onResolve({ filter: /^\/assets\// }, args => { + build.onResolve({ filter: /^\/assets\// }, (args) => { return { path: args.path, - external: true + external: true, }; }); - } + }, }; diff --git a/esbuild/sass_options.js b/esbuild/sass_options.js index 0c1189e90c..92b691cb46 100644 --- a/esbuild/sass_options.js +++ b/esbuild/sass_options.js @@ -1,19 +1,13 @@ let path = require("path"); let { get_app_path, app_list } = require("./utils"); -let node_modules_path = path.resolve( - get_app_path("frappe"), - "..", - "node_modules" -); -let app_paths = app_list - .map(get_app_path) - .map(app_path => path.resolve(app_path, "..")); +let node_modules_path = path.resolve(get_app_path("frappe"), "..", "node_modules"); +let app_paths = app_list.map(get_app_path).map((app_path) => path.resolve(app_path, "..")); module.exports = { includePaths: [node_modules_path, ...app_paths], quietDeps: true, - importer: function(url) { + importer: function (url) { if (url.startsWith("~")) { // strip ~ so that it can resolve from node_modules url = url.slice(1); @@ -24,7 +18,7 @@ module.exports = { } // normal file, let it go return { - file: url + file: url, }; - } + }, }; diff --git a/esbuild/utils.js b/esbuild/utils.js index b2a4e98d54..db58b89e8b 100644 --- a/esbuild/utils.js +++ b/esbuild/utils.js @@ -26,24 +26,20 @@ const bundle_map = app_list.reduce((out, app) => { const public_js_path = public_js_paths[app]; if (fs.existsSync(public_js_path)) { const all_files = fs.readdirSync(public_js_path); - const js_files = all_files.filter(file => file.endsWith(".js")); + const js_files = all_files.filter((file) => file.endsWith(".js")); for (let js_file of js_files) { const filename = path.basename(js_file).split(".")[0]; - out[path.join(app, "js", filename)] = path.resolve( - public_js_path, - js_file - ); + out[path.join(app, "js", filename)] = path.resolve(public_js_path, js_file); } } return out; }, {}); -const get_public_path = app => public_paths[app]; +const get_public_path = (app) => public_paths[app]; -const get_build_json_path = app => - path.resolve(get_public_path(app), "build.json"); +const get_build_json_path = (app) => path.resolve(get_public_path(app), "build.json"); function get_build_json(app) { try { @@ -62,7 +58,7 @@ function delete_file(path) { function run_serially(tasks) { let result = Promise.resolve(); - tasks.forEach(task => { + tasks.forEach((task) => { if (task) { result = result.then ? result.then(task) : Promise.resolve(); } @@ -70,12 +66,12 @@ function run_serially(tasks) { return result; } -const get_app_path = app => app_paths[app]; +const get_app_path = (app) => app_paths[app]; function get_apps_list() { return fs .readFileSync(path.resolve(sites_path, "apps.txt"), { - encoding: "utf-8" + encoding: "utf-8", }) .split("\n") .filter(Boolean); @@ -116,7 +112,7 @@ function get_redis_subscriber(kind) { let { get_redis_subscriber: get_redis, get_conf } = require("../node_utils"); if (process.env.CI == 1 || get_conf().developer_mode == 1) { - retry_strategy = () => { } + retry_strategy = () => {}; } else { retry_strategy = function (options) { // abort after 10 connection attempts @@ -124,7 +120,7 @@ function get_redis_subscriber(kind) { return undefined; } return Math.min(options.attempt * 100, 2000); - } + }; } return get_redis(kind, { retry_strategy }); } @@ -146,5 +142,5 @@ module.exports = { log, log_warn, log_error, - get_redis_subscriber + get_redis_subscriber, }; diff --git a/frappe/automation/doctype/assignment_rule/assignment_rule.js b/frappe/automation/doctype/assignment_rule/assignment_rule.js index 97bed4f8f3..3e029e8444 100644 --- a/frappe/automation/doctype/assignment_rule/assignment_rule.js +++ b/frappe/automation/doctype/assignment_rule/assignment_rule.js @@ -1,82 +1,77 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Assignment Rule', { - refresh: function(frm) { - frm.trigger('setup_assignment_days_buttons'); - frm.trigger('set_options'); +frappe.ui.form.on("Assignment Rule", { + refresh: function (frm) { + frm.trigger("setup_assignment_days_buttons"); + frm.trigger("set_options"); // refresh description frm.events.rule(frm); }, - setup: function(frm) { + setup: function (frm) { frm.set_query("document_type", () => { return { filters: { - name: ["!=", "ToDo"] - } + name: ["!=", "ToDo"], + }, }; }); }, - document_type: function(frm) { - frm.trigger('set_options'); + document_type: function (frm) { + frm.trigger("set_options"); }, - setup_assignment_days_buttons: function(frm) { - const labels = ['Weekends', 'Weekdays', 'All Days']; + setup_assignment_days_buttons: function (frm) { + const labels = ["Weekends", "Weekdays", "All Days"]; let get_days = (label) => { - const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; - const weekends = ['Saturday', 'Sunday']; + const weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]; + const weekends = ["Saturday", "Sunday"]; return { - 'All Days': weekdays.concat(weekends), - 'Weekdays': weekdays, - 'Weekends': weekends, + "All Days": weekdays.concat(weekends), + Weekdays: weekdays, + Weekends: weekends, }[label]; }; let set_days = (e) => { - frm.clear_table('assignment_days'); + frm.clear_table("assignment_days"); const label = $(e.currentTarget).text(); - get_days(label).forEach((day) => - frm.add_child('assignment_days', { day: day }) - ); - frm.refresh_field('assignment_days'); + get_days(label).forEach((day) => frm.add_child("assignment_days", { day: day })); + frm.refresh_field("assignment_days"); }; - labels.forEach(label => - frm.fields_dict['assignment_days'].grid.add_custom_button( - label, - set_days, - 'top' - ) + labels.forEach((label) => + frm.fields_dict["assignment_days"].grid.add_custom_button(label, set_days, "top") ); }, - rule: function(frm) { + rule: function (frm) { const description_map = { - 'Round Robin': __('Assign one by one, in sequence'), - 'Load Balancing': __('Assign to the one who has the least assignments'), - 'Based on Field': __('Assign to the user set in this field'), + "Round Robin": __("Assign one by one, in sequence"), + "Load Balancing": __("Assign to the one who has the least assignments"), + "Based on Field": __("Assign to the user set in this field"), }; - frm.get_field('rule').set_description(description_map[frm.doc.rule]); + frm.get_field("rule").set_description(description_map[frm.doc.rule]); }, set_options(frm) { const doctype = frm.doc.document_type; frm.set_fields_as_options( - 'field', + "field", doctype, - (df) => ['Dynamic Link', 'Data'].includes(df.fieldtype) - || (df.fieldtype == 'Link' && df.options == 'User'), - [{ label: 'Owner', value: 'owner' }] + (df) => + ["Dynamic Link", "Data"].includes(df.fieldtype) || + (df.fieldtype == "Link" && df.options == "User"), + [{ label: "Owner", value: "owner" }] ); if (doctype) { - frm.set_fields_as_options( - 'due_date_based_on', - doctype, - (df) => ['Date', 'Datetime'].includes(df.fieldtype) - ).then(options => frm.set_df_property('due_date_based_on', 'hidden', !options.length)); + frm.set_fields_as_options("due_date_based_on", doctype, (df) => + ["Date", "Datetime"].includes(df.fieldtype) + ).then((options) => + frm.set_df_property("due_date_based_on", "hidden", !options.length) + ); } }, }); diff --git a/frappe/automation/doctype/auto_repeat/auto_repeat.js b/frappe/automation/doctype/auto_repeat/auto_repeat.js index 80f2255f47..c0fa2696be 100644 --- a/frappe/automation/doctype/auto_repeat/auto_repeat.js +++ b/frappe/automation/doctype/auto_repeat/auto_repeat.js @@ -2,41 +2,45 @@ // For license information, please see license.txt frappe.provide("frappe.auto_repeat"); -frappe.ui.form.on('Auto Repeat', { - setup: function(frm) { - frm.fields_dict['reference_doctype'].get_query = function() { +frappe.ui.form.on("Auto Repeat", { + setup: function (frm) { + frm.fields_dict["reference_doctype"].get_query = function () { return { - query: "frappe.automation.doctype.auto_repeat.auto_repeat.get_auto_repeat_doctypes" + query: "frappe.automation.doctype.auto_repeat.auto_repeat.get_auto_repeat_doctypes", }; }; - frm.fields_dict['reference_document'].get_query = function() { + frm.fields_dict["reference_document"].get_query = function () { return { filters: { - "auto_repeat": '' - } + auto_repeat: "", + }, }; }; - frm.fields_dict['print_format'].get_query = function() { + frm.fields_dict["print_format"].get_query = function () { return { filters: { - "doc_type": frm.doc.reference_doctype - } + doc_type: frm.doc.reference_doctype, + }, }; }; }, - refresh: function(frm) { + refresh: function (frm) { // auto repeat message if (frm.is_new()) { - let customize_form_link = `${__('Customize Form')}`; - frm.dashboard.set_headline(__('To configure Auto Repeat, enable "Allow Auto Repeat" from {0}.', [customize_form_link])); + let customize_form_link = `${__("Customize Form")}`; + frm.dashboard.set_headline( + __('To configure Auto Repeat, enable "Allow Auto Repeat" from {0}.', [ + customize_form_link, + ]) + ); } // view document button if (!frm.is_dirty()) { - let label = __('View {0}', [__(frm.doc.reference_doctype)]); + let label = __("View {0}", [__(frm.doc.reference_doctype)]); frm.add_custom_button(label, () => frappe.set_route("List", frm.doc.reference_doctype, { auto_repeat: frm.doc.name }) ); @@ -45,24 +49,24 @@ frappe.ui.form.on('Auto Repeat', { // auto repeat schedule frappe.auto_repeat.render_schedule(frm); - frm.trigger('toggle_submit_on_creation'); + frm.trigger("toggle_submit_on_creation"); }, - reference_doctype: function(frm) { - frm.trigger('toggle_submit_on_creation'); + reference_doctype: function (frm) { + frm.trigger("toggle_submit_on_creation"); }, - toggle_submit_on_creation: function(frm) { + toggle_submit_on_creation: function (frm) { // submit on creation checkbox if (frm.doc.reference_doctype) { frappe.model.with_doctype(frm.doc.reference_doctype, () => { let meta = frappe.get_meta(frm.doc.reference_doctype); - frm.toggle_display('submit_on_creation', meta.is_submittable); + frm.toggle_display("submit_on_creation", meta.is_submittable); }); } }, - template: function(frm) { + template: function (frm) { if (frm.doc.template) { frappe.model.with_doc("Email Template", frm.doc.template, () => { let email_template = frappe.get_doc("Email Template", frm.doc.template); @@ -74,11 +78,11 @@ frappe.ui.form.on('Auto Repeat', { } }, - get_contacts: function(frm) { - frm.call('fetch_linked_contacts'); + get_contacts: function (frm) { + frm.call("fetch_linked_contacts"); }, - preview_message: function(frm) { + preview_message: function (frm) { if (frm.doc.message) { frappe.call({ method: "frappe.automation.doctype.auto_repeat.auto_repeat.generate_message_preview", @@ -86,29 +90,29 @@ frappe.ui.form.on('Auto Repeat', { reference_dt: frm.doc.reference_doctype, reference_doc: frm.doc.reference_document, subject: frm.doc.subject, - message: frm.doc.message + message: frm.doc.message, }, - callback: function(r) { + callback: function (r) { if (r.message) { - frappe.msgprint(r.message.message, r.message.subject) + frappe.msgprint(r.message.message, r.message.subject); } - } + }, }); } else { - frappe.msgprint(__("Please setup a message first"), __("Message not setup")) + frappe.msgprint(__("Please setup a message first"), __("Message not setup")); } - } + }, }); -frappe.auto_repeat.render_schedule = function(frm) { - if (!frm.is_dirty() && frm.doc.status !== 'Disabled') { - frm.call("get_auto_repeat_schedule").then(r => { +frappe.auto_repeat.render_schedule = function (frm) { + if (!frm.is_dirty() && frm.doc.status !== "Disabled") { + frm.call("get_auto_repeat_schedule").then((r) => { frm.dashboard.reset(); frm.dashboard.add_section( frappe.render_template("auto_repeat_schedule", { - schedule_details: r.message || [] + schedule_details: r.message || [], }), - __('Auto Repeat Schedule') + __("Auto Repeat Schedule") ); frm.dashboard.show(); }); diff --git a/frappe/automation/doctype/auto_repeat/auto_repeat_list.js b/frappe/automation/doctype/auto_repeat/auto_repeat_list.js index f906580f7e..f970341fa3 100644 --- a/frappe/automation/doctype/auto_repeat/auto_repeat_list.js +++ b/frappe/automation/doctype/auto_repeat/auto_repeat_list.js @@ -1,11 +1,11 @@ -frappe.listview_settings['Auto Repeat'] = { +frappe.listview_settings["Auto Repeat"] = { add_fields: ["next_schedule_date"], - get_indicator: function(doc) { + get_indicator: function (doc) { var colors = { - "Active": "green", - "Disabled": "red", - "Completed": "blue", + Active: "green", + Disabled: "red", + Completed: "blue", }; return [__(doc.status), colors[doc.status], "status,=," + doc.status]; - } + }, }; diff --git a/frappe/automation/doctype/milestone/milestone.js b/frappe/automation/doctype/milestone/milestone.js index 9a1cf577ff..2a5ab04135 100644 --- a/frappe/automation/doctype/milestone/milestone.js +++ b/frappe/automation/doctype/milestone/milestone.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Milestone', { +frappe.ui.form.on("Milestone", { // refresh: function(frm) { - // } }); diff --git a/frappe/automation/doctype/milestone_tracker/milestone_tracker.js b/frappe/automation/doctype/milestone_tracker/milestone_tracker.js index 2a74bfb070..bf5be880a0 100644 --- a/frappe/automation/doctype/milestone_tracker/milestone_tracker.js +++ b/frappe/automation/doctype/milestone_tracker/milestone_tracker.js @@ -1,14 +1,14 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Milestone Tracker', { - refresh: function(frm) { - frm.trigger('update_options'); +frappe.ui.form.on("Milestone Tracker", { + refresh: function (frm) { + frm.trigger("update_options"); }, - document_type: function(frm) { - frm.trigger('update_options'); + document_type: function (frm) { + frm.trigger("update_options"); }, - update_options: function(frm) { + update_options: function (frm) { // update select options for `track_field` let doctype = frm.doc.document_type; let track_fields = []; @@ -16,18 +16,16 @@ frappe.ui.form.on('Milestone Tracker', { if (doctype) { frappe.model.with_doctype(doctype, () => { // get all date and datetime fields - frappe.get_meta(doctype).fields.map(df => { - if (['Link', 'Select'].includes(df.fieldtype)) { - track_fields.push({label: df.label, value: df.fieldname}); + frappe.get_meta(doctype).fields.map((df) => { + if (["Link", "Select"].includes(df.fieldtype)) { + track_fields.push({ label: df.label, value: df.fieldname }); } }); - frm.set_df_property('track_field', 'options', track_fields); + frm.set_df_property("track_field", "options", track_fields); }); } else { // update select options - frm.set_df_property('track_field', 'options', []); + frm.set_df_property("track_field", "options", []); } - }, - }); diff --git a/frappe/contacts/doctype/address/address.js b/frappe/contacts/doctype/address/address.js index 63574622c0..548dd40060 100644 --- a/frappe/contacts/doctype/address/address.js +++ b/frappe/contacts/doctype/address/address.js @@ -2,60 +2,74 @@ // For license information, please see license.txt frappe.ui.form.on("Address", { - refresh: function(frm) { - if(frm.doc.__islocal) { + refresh: function (frm) { + if (frm.doc.__islocal) { const last_doc = frappe.contacts.get_last_doc(frm); - if(frappe.dynamic_link && frappe.dynamic_link.doc - && frappe.dynamic_link.doc.name == last_doc.docname) { - frm.set_value('links', ''); - frm.add_child('links', { + if ( + frappe.dynamic_link && + frappe.dynamic_link.doc && + frappe.dynamic_link.doc.name == last_doc.docname + ) { + frm.set_value("links", ""); + frm.add_child("links", { link_doctype: frappe.dynamic_link.doctype, - link_name: frappe.dynamic_link.doc[frappe.dynamic_link.fieldname] + link_name: frappe.dynamic_link.doc[frappe.dynamic_link.fieldname], }); } } - frm.set_query('link_doctype', "links", function() { + frm.set_query("link_doctype", "links", function () { return { query: "frappe.contacts.address_and_contact.filter_dynamic_link_doctypes", filters: { fieldtype: "HTML", fieldname: "address_html", - } - } + }, + }; }); frm.refresh_field("links"); if (frm.doc.links) { for (let i in frm.doc.links) { let link = frm.doc.links[i]; - frm.add_custom_button(__("{0}: {1}", [__(link.link_doctype), __(link.link_name)]), function() { - frappe.set_route("Form", link.link_doctype, link.link_name); - }, __("Links")); + frm.add_custom_button( + __("{0}: {1}", [__(link.link_doctype), __(link.link_name)]), + function () { + frappe.set_route("Form", link.link_doctype, link.link_name); + }, + __("Links") + ); } } }, - validate: function(frm) { + validate: function (frm) { // clear linked customer / supplier / sales partner on saving... - if(frm.doc.links) { - frm.doc.links.forEach(function(d) { + if (frm.doc.links) { + frm.doc.links.forEach(function (d) { frappe.model.remove_from_locals(d.link_doctype, d.link_name); }); } }, - after_save: function(frm) { + after_save: function (frm) { frappe.run_serially([ () => frappe.timeout(1), () => { const last_doc = frappe.contacts.get_last_doc(frm); - if (frappe.dynamic_link && frappe.dynamic_link.doc && frappe.dynamic_link.doc.name == last_doc.docname) { + if ( + frappe.dynamic_link && + frappe.dynamic_link.doc && + frappe.dynamic_link.doc.name == last_doc.docname + ) { for (let i in frm.doc.links) { let link = frm.doc.links[i]; - if (last_doc.doctype == link.link_doctype && last_doc.docname == link.link_name) { - frappe.set_route('Form', last_doc.doctype, last_doc.docname); + if ( + last_doc.doctype == link.link_doctype && + last_doc.docname == link.link_name + ) { + frappe.set_route("Form", last_doc.doctype, last_doc.docname); } } } - } + }, ]); - } + }, }); diff --git a/frappe/contacts/doctype/address_template/address_template.js b/frappe/contacts/doctype/address_template/address_template.js index 502d02e7f9..bfe139bce8 100644 --- a/frappe/contacts/doctype/address_template/address_template.js +++ b/frappe/contacts/doctype/address_template/address_template.js @@ -1,16 +1,16 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Address Template', { - refresh: function(frm) { - if(frm.is_new() && !frm.doc.template) { +frappe.ui.form.on("Address Template", { + refresh: function (frm) { + if (frm.is_new() && !frm.doc.template) { // set default template via js so that it is translated frappe.call({ - method: 'frappe.contacts.doctype.address_template.address_template.get_default_address_template', - callback: function(r) { - frm.set_value('template', r.message); - } + method: "frappe.contacts.doctype.address_template.address_template.get_default_address_template", + callback: function (r) { + frm.set_value("template", r.message); + }, }); } - } + }, }); diff --git a/frappe/contacts/doctype/contact/contact.js b/frappe/contacts/doctype/contact/contact.js index fae6e6515e..d4ae9379fa 100644 --- a/frappe/contacts/doctype/contact/contact.js +++ b/frappe/contacts/doctype/contact/contact.js @@ -5,49 +5,52 @@ frappe.ui.form.on("Contact", { onload(frm) { frm.email_field = "email_id"; }, - refresh: function(frm) { - if(frm.doc.__islocal) { + refresh: function (frm) { + if (frm.doc.__islocal) { const last_doc = frappe.contacts.get_last_doc(frm); - if(frappe.dynamic_link && frappe.dynamic_link.doc - && frappe.dynamic_link.doc.name == last_doc.docname) { - frm.set_value('links', ''); - frm.add_child('links', { + if ( + frappe.dynamic_link && + frappe.dynamic_link.doc && + frappe.dynamic_link.doc.name == last_doc.docname + ) { + frm.set_value("links", ""); + frm.add_child("links", { link_doctype: frappe.dynamic_link.doctype, - link_name: frappe.dynamic_link.doc[frappe.dynamic_link.fieldname] + link_name: frappe.dynamic_link.doc[frappe.dynamic_link.fieldname], }); } } - if(!frm.doc.user && !frm.is_new() && frm.perm[0].write) { - frm.add_custom_button(__("Invite as User"), function() { + if (!frm.doc.user && !frm.is_new() && frm.perm[0].write) { + frm.add_custom_button(__("Invite as User"), function () { return frappe.call({ method: "frappe.contacts.doctype.contact.contact.invite_user", args: { - contact: frm.doc.name + contact: frm.doc.name, }, - callback: function(r) { + callback: function (r) { frm.set_value("user", r.message); - } + }, }); }); } - frm.set_query('link_doctype', "links", function() { + frm.set_query("link_doctype", "links", function () { return { query: "frappe.contacts.address_and_contact.filter_dynamic_link_doctypes", filters: { fieldtype: "HTML", fieldname: "contact_html", - } - } + }, + }; }); frm.refresh_field("links"); let numbers = frm.doc.phone_nos; if (numbers && numbers.length && frappe.phone_call.handler) { - frm.add_custom_button(__('Call'), () => { + frm.add_custom_button(__("Call"), () => { numbers = frm.doc.phone_nos .sort((prev, next) => next.is_primary_mobile_no - prev.is_primary_mobile_no) - .map(d => d.phone); + .map((d) => d.phone); frappe.phone_call.handler(numbers); }); } @@ -55,73 +58,94 @@ frappe.ui.form.on("Contact", { if (frm.doc.links) { frappe.call({ method: "frappe.contacts.doctype.contact.contact.address_query", - args: {links: frm.doc.links}, - callback: function(r) { + args: { links: frm.doc.links }, + callback: function (r) { if (r && r.message) { frm.set_query("address", function () { return { filters: { name: ["in", r.message], - } - } + }, + }; }); } - } + }, }); for (let i in frm.doc.links) { let link = frm.doc.links[i]; - frm.add_custom_button(__("{0}: {1}", [__(link.link_doctype), __(link.link_name)]), function() { - frappe.set_route("Form", link.link_doctype, link.link_name); - }, __("Links")); + frm.add_custom_button( + __("{0}: {1}", [__(link.link_doctype), __(link.link_name)]), + function () { + frappe.set_route("Form", link.link_doctype, link.link_name); + }, + __("Links") + ); } } }, - validate: function(frm) { + validate: function (frm) { // clear linked customer / supplier / sales partner on saving... - if(frm.doc.links) { - frm.doc.links.forEach(function(d) { + if (frm.doc.links) { + frm.doc.links.forEach(function (d) { frappe.model.remove_from_locals(d.link_doctype, d.link_name); }); } }, - after_save: function(frm) { + after_save: function (frm) { frappe.run_serially([ () => frappe.timeout(1), () => { const last_doc = frappe.contacts.get_last_doc(frm); - if (frappe.dynamic_link && frappe.dynamic_link.doc && frappe.dynamic_link.doc.name == last_doc.docname) { + if ( + frappe.dynamic_link && + frappe.dynamic_link.doc && + frappe.dynamic_link.doc.name == last_doc.docname + ) { for (let i in frm.doc.links) { let link = frm.doc.links[i]; - if (last_doc.doctype == link.link_doctype && last_doc.docname == link.link_name) { - frappe.set_route('Form', last_doc.doctype, last_doc.docname); + if ( + last_doc.doctype == link.link_doctype && + last_doc.docname == link.link_name + ) { + frappe.set_route("Form", last_doc.doctype, last_doc.docname); } } } - } + }, ]); }, - sync_with_google_contacts: function(frm) { + sync_with_google_contacts: function (frm) { if (frm.doc.sync_with_google_contacts) { - frappe.db.get_value("Google Contacts", {"email_id": frappe.session.user}, "name", (r) => { - if (r && r.name) { - frm.set_value("google_contacts", r.name); + frappe.db.get_value( + "Google Contacts", + { email_id: frappe.session.user }, + "name", + (r) => { + if (r && r.name) { + frm.set_value("google_contacts", r.name); + } } - }) + ); } - } + }, }); frappe.ui.form.on("Dynamic Link", { - link_name:function(frm, cdt, cdn){ + link_name: function (frm, cdt, cdn) { var child = locals[cdt][cdn]; - if(child.link_name) { + if (child.link_name) { frappe.model.with_doctype(child.link_doctype, function () { - var title_field = frappe.get_meta(child.link_doctype).title_field || "name" - frappe.model.get_value(child.link_doctype, child.link_name, title_field, function (r) { - frappe.model.set_value(cdt, cdn, "link_title", r[title_field]) - }) - }) + var title_field = frappe.get_meta(child.link_doctype).title_field || "name"; + frappe.model.get_value( + child.link_doctype, + child.link_name, + title_field, + function (r) { + frappe.model.set_value(cdt, cdn, "link_title", r[title_field]); + } + ); + }); } - } -}) + }, +}); diff --git a/frappe/contacts/doctype/contact/contact_list.js b/frappe/contacts/doctype/contact/contact_list.js index a93b3f0d73..2b3cd8a062 100644 --- a/frappe/contacts/doctype/contact/contact_list.js +++ b/frappe/contacts/doctype/contact/contact_list.js @@ -1,3 +1,3 @@ -frappe.listview_settings['Contact'] = { +frappe.listview_settings["Contact"] = { add_fields: ["image"], -}; \ No newline at end of file +}; diff --git a/frappe/contacts/doctype/gender/gender.js b/frappe/contacts/doctype/gender/gender.js index e2fd2f18eb..3b34b1584e 100644 --- a/frappe/contacts/doctype/gender/gender.js +++ b/frappe/contacts/doctype/gender/gender.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Gender', { - refresh: function() { - - } +frappe.ui.form.on("Gender", { + refresh: function () {}, }); diff --git a/frappe/contacts/doctype/salutation/salutation.js b/frappe/contacts/doctype/salutation/salutation.js index 856b72e04c..e7da1f389b 100644 --- a/frappe/contacts/doctype/salutation/salutation.js +++ b/frappe/contacts/doctype/salutation/salutation.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Salutation', { - refresh: function() { - - } +frappe.ui.form.on("Salutation", { + refresh: function () {}, }); diff --git a/frappe/contacts/report/addresses_and_contacts/addresses_and_contacts.js b/frappe/contacts/report/addresses_and_contacts/addresses_and_contacts.js index 10137e80d5..9870ee611b 100644 --- a/frappe/contacts/report/addresses_and_contacts/addresses_and_contacts.js +++ b/frappe/contacts/report/addresses_and_contacts/addresses_and_contacts.js @@ -2,32 +2,32 @@ // For license information, please see license.txt frappe.query_reports["Addresses And Contacts"] = { - "filters": [ + filters: [ { - "reqd": 1, - "fieldname":"reference_doctype", - "label": __("Entity Type"), - "fieldtype": "Link", - "options": "DocType", - "get_query": function() { + reqd: 1, + fieldname: "reference_doctype", + label: __("Entity Type"), + fieldtype: "Link", + options: "DocType", + get_query: function () { return { - "filters": { - "name": ["in", "Contact, Address"], - } - } - } + filters: { + name: ["in", "Contact, Address"], + }, + }; + }, }, { - "fieldname":"reference_name", - "label": __("Entity Name"), - "fieldtype": "Dynamic Link", - "get_options": function() { - let reference_doctype = frappe.query_report.get_filter_value('reference_doctype'); - if(!reference_doctype) { + fieldname: "reference_name", + label: __("Entity Name"), + fieldtype: "Dynamic Link", + get_options: function () { + let reference_doctype = frappe.query_report.get_filter_value("reference_doctype"); + if (!reference_doctype) { frappe.throw(__("Please select Entity Type first")); } return reference_doctype; - } - } - ] -} + }, + }, + ], +}; diff --git a/frappe/core/doctype/access_log/access_log.js b/frappe/core/doctype/access_log/access_log.js index d36d10768b..94f1bf732d 100644 --- a/frappe/core/doctype/access_log/access_log.js +++ b/frappe/core/doctype/access_log/access_log.js @@ -1,17 +1,17 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Access Log', { +frappe.ui.form.on("Access Log", { show_document: function (frm) { - frappe.set_route('Form', frm.doc.export_from, frm.doc.reference_document); + frappe.set_route("Form", frm.doc.export_from, frm.doc.reference_document); }, show_report: function (frm) { - if (frm.doc.report_name.includes('/')) { + if (frm.doc.report_name.includes("/")) { frappe.set_route(frm.doc.report_name); } else { let filters = frm.doc.filters ? JSON.parse(frm.doc.filters) : {}; - frappe.set_route('query-report', frm.doc.report_name, filters); + frappe.set_route("query-report", frm.doc.report_name, filters); } - } + }, }); diff --git a/frappe/core/doctype/activity_log/activity_log.js b/frappe/core/doctype/activity_log/activity_log.js index 97e49e4b34..7df644a86a 100644 --- a/frappe/core/doctype/activity_log/activity_log.js +++ b/frappe/core/doctype/activity_log/activity_log.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Activity Log', { - refresh: function() { - - } +frappe.ui.form.on("Activity Log", { + refresh: function () {}, }); diff --git a/frappe/core/doctype/activity_log/activity_log_list.js b/frappe/core/doctype/activity_log/activity_log_list.js index e3a75a1941..53758a7b62 100644 --- a/frappe/core/doctype/activity_log/activity_log_list.js +++ b/frappe/core/doctype/activity_log/activity_log_list.js @@ -1,13 +1,12 @@ -frappe.listview_settings['Activity Log'] = { - get_indicator: function(doc) { - if(doc.operation == "Login" && doc.status == "Success") - return [__(doc.status), "green"]; - else if(doc.operation == "Login" && doc.status == "Failed") +frappe.listview_settings["Activity Log"] = { + get_indicator: function (doc) { + if (doc.operation == "Login" && doc.status == "Success") return [__(doc.status), "green"]; + else if (doc.operation == "Login" && doc.status == "Failed") return [__(doc.status), "red"]; }, - onload: function(listview) { + onload: function (listview) { frappe.require("logtypes.bundle.js", () => { frappe.utils.logtypes.show_log_retention_message(cur_list.doctype); - }) + }); }, }; diff --git a/frappe/core/doctype/comment/comment.js b/frappe/core/doctype/comment/comment.js index a793f766cb..4d227f6f5f 100644 --- a/frappe/core/doctype/comment/comment.js +++ b/frappe/core/doctype/comment/comment.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Comment', { +frappe.ui.form.on("Comment", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/communication/communication.js b/frappe/core/doctype/communication/communication.js index 07674d16ae..a36af705a7 100644 --- a/frappe/core/doctype/communication/communication.js +++ b/frappe/core/doctype/communication/communication.js @@ -1,120 +1,158 @@ frappe.ui.form.on("Communication", { - onload: function(frm) { - if(frm.doc.content) { + onload: function (frm) { + if (frm.doc.content) { frm.doc.content = frappe.dom.remove_script_and_style(frm.doc.content); } - frm.set_query("reference_doctype", function() { + frm.set_query("reference_doctype", function () { return { filters: { - "issingle": 0, - "istable": 0 - } - } + issingle: 0, + istable: 0, + }, + }; }); }, - refresh: function(frm) { - if(frm.is_new()) return; + refresh: function (frm) { + if (frm.is_new()) return; frm.convert_to_click && frm.set_convert_button(); frm.subject_field = "subject"; // content field contains weird table html that does not render well in Quill // this field is not to be edited directly anyway, so setting it as read only - frm.set_df_property('content', 'read_only', 1); + frm.set_df_property("content", "read_only", 1); - if(frm.doc.reference_doctype && frm.doc.reference_name) { - frm.add_custom_button(__(frm.doc.reference_name), function() { + if (frm.doc.reference_doctype && frm.doc.reference_name) { + frm.add_custom_button(__(frm.doc.reference_name), function () { frappe.set_route("Form", frm.doc.reference_doctype, frm.doc.reference_name); }); } else { // if an unlinked communication, set email field - if (frm.doc.sent_or_received==="Received") { + if (frm.doc.sent_or_received === "Received") { frm.email_field = "sender"; } else { frm.email_field = "recipients"; } } - if(frm.doc.status==="Open") { - frm.add_custom_button(__("Close"), function() { - frm.trigger('mark_as_closed_open'); + if (frm.doc.status === "Open") { + frm.add_custom_button(__("Close"), function () { + frm.trigger("mark_as_closed_open"); }); } else if (frm.doc.status !== "Linked") { - frm.add_custom_button(__("Reopen"), function() { - frm.trigger('mark_as_closed_open'); + frm.add_custom_button(__("Reopen"), function () { + frm.trigger("mark_as_closed_open"); }); } - frm.add_custom_button(__("Relink"), function() { - frm.trigger('show_relink_dialog'); + frm.add_custom_button(__("Relink"), function () { + frm.trigger("show_relink_dialog"); }); - if(frm.doc.communication_type=="Communication" - && frm.doc.communication_medium == "Email" - && frm.doc.sent_or_received == "Received") { - - frm.add_custom_button(__("Reply"), function() { - frm.trigger('reply'); + if ( + frm.doc.communication_type == "Communication" && + frm.doc.communication_medium == "Email" && + frm.doc.sent_or_received == "Received" + ) { + frm.add_custom_button(__("Reply"), function () { + frm.trigger("reply"); }); - frm.add_custom_button(__("Reply All"), function() { - frm.trigger('reply_all'); - }, __("Actions")); + frm.add_custom_button( + __("Reply All"), + function () { + frm.trigger("reply_all"); + }, + __("Actions") + ); - frm.add_custom_button(__("Forward"), function() { - frm.trigger('forward_mail'); - }, __("Actions")); + frm.add_custom_button( + __("Forward"), + function () { + frm.trigger("forward_mail"); + }, + __("Actions") + ); - frm.add_custom_button(frm.doc.seen ? __("Mark as Unread") : __("Mark as Read"), function() { - frm.trigger('mark_as_read_unread'); - }, __("Actions")); + frm.add_custom_button( + frm.doc.seen ? __("Mark as Unread") : __("Mark as Read"), + function () { + frm.trigger("mark_as_read_unread"); + }, + __("Actions") + ); - frm.add_custom_button(__("Move"), function() { - frm.trigger('show_move_dialog'); - }, __("Actions")); + frm.add_custom_button( + __("Move"), + function () { + frm.trigger("show_move_dialog"); + }, + __("Actions") + ); - if(frm.doc.email_status != "Spam") - frm.add_custom_button(__("Mark as Spam"), function() { - frm.trigger('mark_as_spam'); - }, __("Actions")); + if (frm.doc.email_status != "Spam") + frm.add_custom_button( + __("Mark as Spam"), + function () { + frm.trigger("mark_as_spam"); + }, + __("Actions") + ); - if(frm.doc.email_status != "Trash") { - frm.add_custom_button(__("Move To Trash"), function() { - frm.trigger('move_to_trash'); - }, __("Actions")); + if (frm.doc.email_status != "Trash") { + frm.add_custom_button( + __("Move To Trash"), + function () { + frm.trigger("move_to_trash"); + }, + __("Actions") + ); } - frm.add_custom_button(__("Contact"), function() { - frm.trigger('add_to_contact'); - }, __('Create')); + frm.add_custom_button( + __("Contact"), + function () { + frm.trigger("add_to_contact"); + }, + __("Create") + ); } - if(frm.doc.communication_type=="Communication" - && frm.doc.communication_medium == "Phone" - && frm.doc.sent_or_received == "Received"){ - - frm.add_custom_button(__("Add Contact"), function() { - frm.trigger('add_to_contact'); - }, __("Actions")); + if ( + frm.doc.communication_type == "Communication" && + frm.doc.communication_medium == "Phone" && + frm.doc.sent_or_received == "Received" + ) { + frm.add_custom_button( + __("Add Contact"), + function () { + frm.trigger("add_to_contact"); + }, + __("Actions") + ); } }, - show_relink_dialog: function(frm) { - var d = new frappe.ui.Dialog ({ + show_relink_dialog: function (frm) { + var d = new frappe.ui.Dialog({ title: __("Relink Communication"), - fields: [{ - "fieldtype": "Link", - "options": "DocType", - "label": __("Reference Doctype"), - "fieldname": "reference_doctype", - "get_query": function() {return {"query": "frappe.email.get_communication_doctype"}} - }, - { - "fieldtype": "Dynamic Link", - "options": "reference_doctype", - "label": __("Reference Name"), - "fieldname": "reference_name" - }] + fields: [ + { + fieldtype: "Link", + options: "DocType", + label: __("Reference Doctype"), + fieldname: "reference_doctype", + get_query: function () { + return { query: "frappe.email.get_communication_doctype" }; + }, + }, + { + fieldtype: "Dynamic Link", + options: "reference_doctype", + label: __("Reference Name"), + fieldname: "reference_name", + }, + ], }); d.set_value("reference_doctype", frm.doc.reference_doctype); d.set_value("reference_name", frm.doc.reference_name); @@ -122,24 +160,27 @@ frappe.ui.form.on("Communication", { var values = d.get_values(); if (values) { frappe.confirm( - __('Are you sure you want to relink this communication to {0}?', [values["reference_name"]]), + __("Are you sure you want to relink this communication to {0}?", [ + values["reference_name"], + ]), function () { d.hide(); frappe.call({ method: "frappe.email.relink", args: { - "name": frm.doc.name, - "reference_doctype": values["reference_doctype"], - "reference_name": values["reference_name"] + name: frm.doc.name, + reference_doctype: values["reference_doctype"], + reference_name: values["reference_name"], }, callback: function () { frm.refresh(); - } + }, }); }, - function() { + function () { frappe.show_alert({ - message: __('Document not Relinked'), 'indicator': 'info' + message: __("Document not Relinked"), + indicator: "info", }); } ); @@ -148,24 +189,26 @@ frappe.ui.form.on("Communication", { d.show(); }, - show_move_dialog: function(frm) { - var d = new frappe.ui.Dialog ({ + show_move_dialog: function (frm) { + var d = new frappe.ui.Dialog({ title: __("Move"), - fields: [{ - "fieldtype": "Link", - "options": "Email Account", - "label": __("Email Account"), - "fieldname": "email_account", - "reqd": 1, - "get_query": function() { - return { - "filters": { - "name": ["!=", frm.doc.email_account], - "enable_incoming": ["=", 1] - } - }; - } - }], + fields: [ + { + fieldtype: "Link", + options: "Email Account", + label: __("Email Account"), + fieldname: "email_account", + reqd: 1, + get_query: function () { + return { + filters: { + name: ["!=", frm.doc.email_account], + enable_incoming: ["=", 1], + }, + }; + }, + }, + ], primary_action_label: __("Move"), primary_action(values) { d.hide(); @@ -173,88 +216,88 @@ frappe.ui.form.on("Communication", { method: "frappe.email.inbox.move_email", args: { communication: frm.doc.name, - email_account: values.email_account + email_account: values.email_account, }, freeze: true, - callback: function() { + callback: function () { window.history.back(); - } + }, }); - } + }, }); d.show(); }, - mark_as_read_unread: function(frm) { - var action = frm.doc.seen? "Unread": "Read"; + mark_as_read_unread: function (frm) { + var action = frm.doc.seen ? "Unread" : "Read"; var flag = "(\\SEEN)"; return frappe.call({ method: "frappe.email.inbox.create_email_flag_queue", args: { - 'names': [frm.doc.name], - 'action': action, - 'flag': flag + names: [frm.doc.name], + action: action, + flag: flag, }, freeze: true, - callback: function() { + callback: function () { frm.reload_doc(); - } + }, }); }, - mark_as_closed_open: function(frm) { + mark_as_closed_open: function (frm) { var status = frm.doc.status == "Open" ? "Closed" : "Open"; return frappe.call({ method: "frappe.email.inbox.mark_as_closed_open", args: { communication: frm.doc.name, - status: status + status: status, }, freeze: true, - callback: function() { + callback: function () { frm.reload_doc(); - } + }, }); }, - reply: function(frm) { + reply: function (frm) { var args = frm.events.get_mail_args(frm); $.extend(args, { subject: __("Re: {0}", [frm.doc.subject]), - recipients: frm.doc.sender - }) + recipients: frm.doc.sender, + }); new frappe.views.CommunicationComposer(args); }, - reply_all: function(frm) { - var args = frm.events.get_mail_args(frm) + reply_all: function (frm) { + var args = frm.events.get_mail_args(frm); $.extend(args, { subject: __("Res: {0}", [frm.doc.subject]), recipients: frm.doc.sender, - cc: frm.doc.cc - }) + cc: frm.doc.cc, + }); new frappe.views.CommunicationComposer(args); }, - forward_mail: function(frm) { - var args = frm.events.get_mail_args(frm) + forward_mail: function (frm) { + var args = frm.events.get_mail_args(frm); $.extend(args, { forward: true, subject: __("Fw: {0}", [frm.doc.subject]), - }) + }); new frappe.views.CommunicationComposer(args); }, - get_mail_args: function(frm) { - var sender_email_id = "" - $.each(frappe.boot.email_accounts, function(idx, account) { - if(account.email_account == frm.doc.email_account) { - sender_email_id = account.email_id - return + get_mail_args: function (frm) { + var sender_email_id = ""; + $.each(frappe.boot.email_accounts, function (idx, account) { + if (account.email_account == frm.doc.email_account) { + sender_email_id = account.email_id; + return; } }); @@ -263,51 +306,51 @@ frappe.ui.form.on("Communication", { doc: frm.doc, last_email: frm.doc, sender: sender_email_id, - attachments: frm.doc.attachments - } + attachments: frm.doc.attachments, + }; }, - add_to_contact: function(frm) { + add_to_contact: function (frm) { var me = this; - var fullname = frm.doc.sender_full_name || "" + var fullname = frm.doc.sender_full_name || ""; - var names = fullname.split(" ") - var first_name = names[0] - var last_name = names.length >= 2? names[names.length - 1]: "" + var names = fullname.split(" "); + var first_name = names[0]; + var last_name = names.length >= 2 ? names[names.length - 1] : ""; frappe.route_options = { - "email_id": frm.doc.sender || "", - "first_name": first_name, - "last_name": last_name, - "mobile_no": frm.doc.phone_no || "" - } - frappe.new_doc("Contact") + email_id: frm.doc.sender || "", + first_name: first_name, + last_name: last_name, + mobile_no: frm.doc.phone_no || "", + }; + frappe.new_doc("Contact"); }, - mark_as_spam: function(frm) { + mark_as_spam: function (frm) { frappe.call({ method: "frappe.email.inbox.mark_as_spam", args: { communication: frm.doc.name, - sender: frm.doc.sender + sender: frm.doc.sender, }, freeze: true, - callback: function(r) { - frappe.msgprint(__("Email has been marked as spam")) - } - }) + callback: function (r) { + frappe.msgprint(__("Email has been marked as spam")); + }, + }); }, - move_to_trash: function(frm) { + move_to_trash: function (frm) { frappe.call({ method: "frappe.email.inbox.mark_as_trash", args: { - communication: frm.doc.name + communication: frm.doc.name, }, freeze: true, - callback: function(r) { - frappe.msgprint(__("Email has been moved to trash")) - } - }) - } + callback: function (r) { + frappe.msgprint(__("Email has been moved to trash")); + }, + }); + }, }); diff --git a/frappe/core/doctype/communication/communication_list.js b/frappe/core/doctype/communication/communication_list.js index 315b74a39c..4ef3a384ff 100644 --- a/frappe/core/doctype/communication/communication_list.js +++ b/frappe/core/doctype/communication/communication_list.js @@ -1,25 +1,32 @@ -frappe.listview_settings['Communication'] = { +frappe.listview_settings["Communication"] = { add_fields: [ - "sent_or_received","recipients", "subject", - "communication_medium", "communication_type", - "sender", "seen", "reference_doctype", "reference_name", - "has_attachment", "communication_date" + "sent_or_received", + "recipients", + "subject", + "communication_medium", + "communication_type", + "sender", + "seen", + "reference_doctype", + "reference_name", + "has_attachment", + "communication_date", ], filters: [["status", "=", "Open"]], - onload: function(list_view) { - let method = "frappe.email.inbox.create_email_flag_queue" + onload: function (list_view) { + let method = "frappe.email.inbox.create_email_flag_queue"; - list_view.page.add_menu_item(__("Mark as Read"), function() { + list_view.page.add_menu_item(__("Mark as Read"), function () { list_view.call_for_selected_items(method, { action: "Read" }); }); - list_view.page.add_menu_item(__("Mark as Unread"), function() { + list_view.page.add_menu_item(__("Mark as Unread"), function () { list_view.call_for_selected_items(method, { action: "Unread" }); }); }, - primary_action: function() { + primary_action: function () { new frappe.views.CommunicationComposer(); - } + }, }; diff --git a/frappe/core/doctype/custom_docperm/custom_docperm.js b/frappe/core/doctype/custom_docperm/custom_docperm.js index 1f04a638a1..0da50217d2 100644 --- a/frappe/core/doctype/custom_docperm/custom_docperm.js +++ b/frappe/core/doctype/custom_docperm/custom_docperm.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Custom DocPerm', { - refresh: function(frm) { - - } +frappe.ui.form.on("Custom DocPerm", { + refresh: function (frm) {}, }); diff --git a/frappe/core/doctype/custom_role/custom_role.js b/frappe/core/doctype/custom_role/custom_role.js index 85302a48b7..16b86485ed 100644 --- a/frappe/core/doctype/custom_role/custom_role.js +++ b/frappe/core/doctype/custom_role/custom_role.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Custom Role', { - refresh: function(frm) { - - } +frappe.ui.form.on("Custom Role", { + refresh: function (frm) {}, }); diff --git a/frappe/core/doctype/data_export/data_export.js b/frappe/core/doctype/data_export/data_export.js index f195e79119..8d65a209b5 100644 --- a/frappe/core/doctype/data_export/data_export.js +++ b/frappe/core/doctype/data_export/data_export.js @@ -1,64 +1,65 @@ // Copyright (c) 2018, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Data Export', { - refresh: frm => { +frappe.ui.form.on("Data Export", { + refresh: (frm) => { frm.disable_save(); - frm.page.set_primary_action('Export', () => { + frm.page.set_primary_action("Export", () => { can_export(frm) ? export_data(frm) : null; }); }, onload: (frm) => { frm.set_query("reference_doctype", () => { return { - "filters": { - "issingle": 0, - "istable": 0, - "name": ['in', frappe.boot.user.can_export] - } + filters: { + issingle: 0, + istable: 0, + name: ["in", frappe.boot.user.can_export], + }, }; }); }, - reference_doctype: frm => { + reference_doctype: (frm) => { const doctype = frm.doc.reference_doctype; if (doctype) { frappe.model.with_doctype(doctype, () => set_field_options(frm)); } else { reset_filter_and_field(frm); } - } + }, }); -const can_export = frm => { +const can_export = (frm) => { const doctype = frm.doc.reference_doctype; - const parent_multicheck_options = frm.fields_multicheck[doctype] ? - frm.fields_multicheck[doctype].get_checked_options() : []; + const parent_multicheck_options = frm.fields_multicheck[doctype] + ? frm.fields_multicheck[doctype].get_checked_options() + : []; let is_valid_form = false; if (!doctype) { - frappe.msgprint(__('Please select the Document Type.')); + frappe.msgprint(__("Please select the Document Type.")); } else if (!parent_multicheck_options.length) { - frappe.msgprint(__('Atleast one field of Parent Document Type is mandatory')); + frappe.msgprint(__("Atleast one field of Parent Document Type is mandatory")); } else { is_valid_form = true; } return is_valid_form; }; -const export_data = frm => { - let get_template_url = '/api/method/frappe.core.doctype.data_export.exporter.export_data'; +const export_data = (frm) => { + let get_template_url = "/api/method/frappe.core.doctype.data_export.exporter.export_data"; var export_params = () => { let columns = {}; - Object.keys(frm.fields_multicheck).forEach(dt => { + Object.keys(frm.fields_multicheck).forEach((dt) => { const options = frm.fields_multicheck[dt].get_checked_options(); columns[dt] = options; }); return { doctype: frm.doc.reference_doctype, select_columns: JSON.stringify(columns), - filters: frm.filter_list.get_filters().map(filter => filter.slice(1, 4)), + filters: frm.filter_list.get_filters().map((filter) => filter.slice(1, 4)), file_type: frm.doc.file_type, template: true, - with_data: 1 + with_data: 1, }; }; @@ -86,26 +87,24 @@ const set_field_options = (frm) => { frm.filter_list = new frappe.ui.FilterGroup({ parent: filter_wrapper, doctype: doctype, - on_change: () => { }, + on_change: () => {}, }); // Add 'Select All' and 'Unselect All' button make_multiselect_buttons(parent_wrapper); frm.fields_multicheck = {}; - related_doctypes.forEach(dt => { + related_doctypes.forEach((dt) => { frm.fields_multicheck[dt] = add_doctype_field_multicheck_control(dt, parent_wrapper); }); frm.refresh(); }; -const make_multiselect_buttons = parent_wrapper => { - const button_container = $(parent_wrapper) - .append('
') - .find('.flex'); +const make_multiselect_buttons = (parent_wrapper) => { + const button_container = $(parent_wrapper).append('
').find(".flex"); - ["Select All", "Unselect All"].map(d => { + ["Select All", "Unselect All"].map((d) => { frappe.ui.form.make_control({ parent: $(button_container), df: { @@ -113,59 +112,59 @@ const make_multiselect_buttons = parent_wrapper => { fieldname: frappe.scrub(d), fieldtype: "Button", click: () => { - checkbox_toggle(d !== 'Select All'); - } + checkbox_toggle(d !== "Select All"); + }, }, - render_input: true + render_input: true, }); }); - $(button_container).find('.frappe-control').map((index, button) => { - $(button).css({"margin-right": "1em"}); - }); + $(button_container) + .find(".frappe-control") + .map((index, button) => { + $(button).css({ "margin-right": "1em" }); + }); function checkbox_toggle(checked) { - $(parent_wrapper).find('[data-fieldtype="MultiCheck"]').map((index, element) => { - $(element).find(`:checkbox`).prop("checked", checked).trigger('click'); - }); + $(parent_wrapper) + .find('[data-fieldtype="MultiCheck"]') + .map((index, element) => { + $(element).find(`:checkbox`).prop("checked", checked).trigger("click"); + }); } - }; -const get_doctypes = parentdt => { - return [parentdt].concat( - frappe.meta.get_table_fields(parentdt).map(df => df.options) - ); +const get_doctypes = (parentdt) => { + return [parentdt].concat(frappe.meta.get_table_fields(parentdt).map((df) => df.options)); }; const add_doctype_field_multicheck_control = (doctype, parent_wrapper) => { const fields = get_fields(doctype); - const options = fields - .map(df => { - return { - label: df.label, - value: df.fieldname, - danger: df.reqd, - checked: 1 - }; - }); + const options = fields.map((df) => { + return { + label: df.label, + value: df.fieldname, + danger: df.reqd, + checked: 1, + }; + }); const multicheck_control = frappe.ui.form.make_control({ parent: parent_wrapper, df: { - "label": doctype, - "fieldname": doctype + '_fields', - "fieldtype": "MultiCheck", - "options": options, - "columns": 3, + label: doctype, + fieldname: doctype + "_fields", + fieldtype: "MultiCheck", + options: options, + columns: 3, }, - render_input: true + render_input: true, }); multicheck_control.refresh_input(); return multicheck_control; }; -const filter_fields = df => frappe.model.is_value_type(df) && !df.hidden; -const get_fields = dt => frappe.meta.get_docfields(dt).filter(filter_fields); \ No newline at end of file +const filter_fields = (df) => frappe.model.is_value_type(df) && !df.hidden; +const get_fields = (dt) => frappe.meta.get_docfields(dt).filter(filter_fields); diff --git a/frappe/core/doctype/data_import/data_import.js b/frappe/core/doctype/data_import/data_import.js index dfc560a98a..7db3aa9629 100644 --- a/frappe/core/doctype/data_import/data_import.js +++ b/frappe/core/doctype/data_import/data_import.js @@ -1,17 +1,17 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Data Import', { +frappe.ui.form.on("Data Import", { setup(frm) { - frappe.realtime.on('data_import_refresh', ({ data_import }) => { + frappe.realtime.on("data_import_refresh", ({ data_import }) => { frm.import_in_progress = false; if (data_import !== frm.doc.name) return; - frappe.model.clear_doc('Data Import', frm.doc.name); - frappe.model.with_doc('Data Import', frm.doc.name).then(() => { + frappe.model.clear_doc("Data Import", frm.doc.name); + frappe.model.with_doc("Data Import", frm.doc.name).then(() => { frm.refresh(); }); }); - frappe.realtime.on('data_import_progress', data => { + frappe.realtime.on("data_import_progress", (data) => { frm.import_in_progress = true; if (data.data_import !== frm.doc.name) { return; @@ -31,20 +31,16 @@ frappe.ui.form.on('Data Import', { if (data.success) { let message_args = [data.current, data.total, eta_message]; message = - frm.doc.import_type === 'Insert New Records' - ? __('Importing {0} of {1}, {2}', message_args) - : __('Updating {0} of {1}, {2}', message_args); + frm.doc.import_type === "Insert New Records" + ? __("Importing {0} of {1}, {2}", message_args) + : __("Updating {0} of {1}, {2}", message_args); } if (data.skipping) { - message = __('Skipping {0} of {1}, {2}', [ - data.current, - data.total, - eta_message - ]); + message = __("Skipping {0} of {1}, {2}", [data.current, data.total, eta_message]); } - frm.dashboard.show_progress(__('Import Progress'), percent, message); - frm.page.set_indicator(__('In Progress'), 'orange'); - frm.trigger('update_primary_action'); + frm.dashboard.show_progress(__("Import Progress"), percent, message); + frm.page.set_indicator(__("In Progress"), "orange"); + frm.trigger("update_primary_action"); // hide progress when complete if (data.current === data.total) { @@ -55,18 +51,18 @@ frappe.ui.form.on('Data Import', { } }); - frm.set_query('reference_doctype', () => { + frm.set_query("reference_doctype", () => { return { filters: { - name: ['in', frappe.boot.user.can_import] - } + name: ["in", frappe.boot.user.can_import], + }, }; }); - frm.get_field('import_file').df.options = { + frm.get_field("import_file").df.options = { restrictions: { - allowed_file_types: ['.csv', '.xls', '.xlsx'] - } + allowed_file_types: [".csv", ".xls", ".xlsx"], + }, }; frm.has_import_file = () => { @@ -76,33 +72,31 @@ frappe.ui.form.on('Data Import', { refresh(frm) { frm.page.hide_icon_group(); - frm.trigger('update_indicators'); - frm.trigger('import_file'); - frm.trigger('show_import_log'); - frm.trigger('show_import_warnings'); - frm.trigger('toggle_submit_after_import'); + frm.trigger("update_indicators"); + frm.trigger("import_file"); + frm.trigger("show_import_log"); + frm.trigger("show_import_warnings"); + frm.trigger("toggle_submit_after_import"); - if (frm.doc.status != 'Pending') - frm.trigger('show_import_status'); + if (frm.doc.status != "Pending") frm.trigger("show_import_status"); - frm.trigger('show_report_error_button'); + frm.trigger("show_report_error_button"); - if (frm.doc.status === 'Partial Success') { - frm.add_custom_button(__('Export Errored Rows'), () => - frm.trigger('export_errored_rows') + if (frm.doc.status === "Partial Success") { + frm.add_custom_button(__("Export Errored Rows"), () => + frm.trigger("export_errored_rows") ); } - if (frm.doc.status.includes('Success')) { - frm.add_custom_button( - __('Go to {0} List', [__(frm.doc.reference_doctype)]), - () => frappe.set_route('List', frm.doc.reference_doctype) + if (frm.doc.status.includes("Success")) { + frm.add_custom_button(__("Go to {0} List", [__(frm.doc.reference_doctype)]), () => + frappe.set_route("List", frm.doc.reference_doctype) ); } }, onload_post_render(frm) { - frm.trigger('update_primary_action'); + frm.trigger("update_primary_action"); }, update_primary_action(frm) { @@ -111,13 +105,12 @@ frappe.ui.form.on('Data Import', { return; } frm.disable_save(); - if (frm.doc.status !== 'Success') { - if (!frm.is_new() && (frm.has_import_file())) { - let label = - frm.doc.status === 'Pending' ? __('Start Import') : __('Retry'); + if (frm.doc.status !== "Success") { + if (!frm.is_new() && frm.has_import_file()) { + let label = frm.doc.status === "Pending" ? __("Start Import") : __("Retry"); frm.page.set_primary_action(label, () => frm.events.start_import(frm)); } else { - frm.page.set_primary_action(__('Save'), () => frm.save()); + frm.page.set_primary_action(__("Save"), () => frm.save()); } } }, @@ -133,11 +126,11 @@ frappe.ui.form.on('Data Import', { show_import_status(frm) { frappe.call({ - 'method': 'frappe.core.doctype.data_import.data_import.get_import_status', - 'args': { - 'data_import_name': frm.doc.name + method: "frappe.core.doctype.data_import.data_import.get_import_status", + args: { + data_import_name: frm.doc.name, }, - 'callback': function(r) { + callback: function (r) { let successful_records = cint(r.message.success); let failed_records = cint(r.message.failed); let total_records = cint(r.message.total_records); @@ -147,52 +140,64 @@ frappe.ui.form.on('Data Import', { let message; if (failed_records === 0) { let message_args = [successful_records]; - if (frm.doc.import_type === 'Insert New Records') { + if (frm.doc.import_type === "Insert New Records") { message = successful_records > 1 - ? __('Successfully imported {0} records.', message_args) - : __('Successfully imported {0} record.', message_args); + ? __("Successfully imported {0} records.", message_args) + : __("Successfully imported {0} record.", message_args); } else { message = successful_records > 1 - ? __('Successfully updated {0} records.', message_args) - : __('Successfully updated {0} record.', message_args); + ? __("Successfully updated {0} records.", message_args) + : __("Successfully updated {0} record.", message_args); } } else { let message_args = [successful_records, total_records]; - if (frm.doc.import_type === 'Insert New Records') { + if (frm.doc.import_type === "Insert New Records") { message = successful_records > 1 - ? __('Successfully imported {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.', message_args) - : __('Successfully imported {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.', message_args); + ? __( + "Successfully imported {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.", + message_args + ) + : __( + "Successfully imported {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.", + message_args + ); } else { message = successful_records > 1 - ? __('Successfully updated {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.', message_args) - : __('Successfully updated {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.', message_args); + ? __( + "Successfully updated {0} records out of {1}. Click on Export Errored Rows, fix the errors and import again.", + message_args + ) + : __( + "Successfully updated {0} record out of {1}. Click on Export Errored Rows, fix the errors and import again.", + message_args + ); } } frm.dashboard.set_headline(message); - } + }, }); }, show_report_error_button(frm) { - if (frm.doc.status === 'Error') { + if (frm.doc.status === "Error") { frappe.db - .get_list('Error Log', { + .get_list("Error Log", { filters: { method: frm.doc.name }, - fields: ['method', 'error'], - order_by: 'creation desc', - limit: 1 + fields: ["method", "error"], + order_by: "creation desc", + limit: 1, }) - .then(result => { + .then((result) => { if (result.length > 0) { - frm.add_custom_button('Report Error', () => { + frm.add_custom_button("Report Error", () => { let fake_xhr = { responseText: JSON.stringify({ - exc: result[0].error - }) + exc: result[0].error, + }), }; frappe.request.report_error(fake_xhr, {}); }); @@ -202,21 +207,19 @@ frappe.ui.form.on('Data Import', { }, start_import(frm) { - frm - .call({ - method: 'form_start_import', - args: { data_import: frm.doc.name }, - btn: frm.page.btn_primary - }) - .then(r => { - if (r.message === true) { - frm.disable_save(); - } - }); + frm.call({ + method: "form_start_import", + args: { data_import: frm.doc.name }, + btn: frm.page.btn_primary, + }).then((r) => { + if (r.message === true) { + frm.disable_save(); + } + }); }, download_template(frm) { - frappe.require('data_import_tools.bundle.js', () => { + frappe.require("data_import_tools.bundle.js", () => { frm.data_exporter = new frappe.data_import.DataExporter( frm.doc.reference_doctype, frm.doc.import_type @@ -225,127 +228,123 @@ frappe.ui.form.on('Data Import', { }, reference_doctype(frm) { - frm.trigger('toggle_submit_after_import'); + frm.trigger("toggle_submit_after_import"); }, toggle_submit_after_import(frm) { - frm.toggle_display('submit_after_import', false); + frm.toggle_display("submit_after_import", false); let doctype = frm.doc.reference_doctype; if (doctype) { frappe.model.with_doctype(doctype, () => { let meta = frappe.get_meta(doctype); - frm.toggle_display('submit_after_import', meta.is_submittable); + frm.toggle_display("submit_after_import", meta.is_submittable); }); } }, google_sheets_url(frm) { if (!frm.is_dirty()) { - frm.trigger('import_file'); + frm.trigger("import_file"); } else { - frm.trigger('update_primary_action'); + frm.trigger("update_primary_action"); } }, refresh_google_sheet(frm) { - frm.trigger('import_file'); + frm.trigger("import_file"); }, import_file(frm) { - frm.toggle_display('section_import_preview', frm.has_import_file()); + frm.toggle_display("section_import_preview", frm.has_import_file()); if (!frm.has_import_file()) { - frm.get_field('import_preview').$wrapper.empty(); + frm.get_field("import_preview").$wrapper.empty(); return; } else { - frm.trigger('update_primary_action'); + frm.trigger("update_primary_action"); } // load import preview - frm.get_field('import_preview').$wrapper.empty(); + frm.get_field("import_preview").$wrapper.empty(); $('') - .html(__('Loading import file...')) - .appendTo(frm.get_field('import_preview').$wrapper); + .html(__("Loading import file...")) + .appendTo(frm.get_field("import_preview").$wrapper); - frm - .call({ - method: 'get_preview_from_template', - args: { - data_import: frm.doc.name, - import_file: frm.doc.import_file, - google_sheets_url: frm.doc.google_sheets_url + frm.call({ + method: "get_preview_from_template", + args: { + data_import: frm.doc.name, + import_file: frm.doc.import_file, + google_sheets_url: frm.doc.google_sheets_url, + }, + error_handlers: { + TimestampMismatchError() { + // ignore this error }, - error_handlers: { - TimestampMismatchError() { - // ignore this error - } - } - }) - .then(r => { - let preview_data = r.message; - frm.events.show_import_preview(frm, preview_data); - frm.events.show_import_warnings(frm, preview_data); - }); + }, + }).then((r) => { + let preview_data = r.message; + frm.events.show_import_preview(frm, preview_data); + frm.events.show_import_warnings(frm, preview_data); + }); }, show_import_preview(frm, preview_data) { let import_log = preview_data.import_log; - if ( - frm.import_preview && - frm.import_preview.doctype === frm.doc.reference_doctype - ) { + if (frm.import_preview && frm.import_preview.doctype === frm.doc.reference_doctype) { frm.import_preview.preview_data = preview_data; frm.import_preview.import_log = import_log; frm.import_preview.refresh(); return; } - frappe.require('data_import_tools.bundle.js', () => { + frappe.require("data_import_tools.bundle.js", () => { frm.import_preview = new frappe.data_import.ImportPreview({ - wrapper: frm.get_field('import_preview').$wrapper, + wrapper: frm.get_field("import_preview").$wrapper, doctype: frm.doc.reference_doctype, preview_data, import_log, frm, events: { remap_column(changed_map) { - let template_options = JSON.parse(frm.doc.template_options || '{}'); - template_options.column_to_field_map = template_options.column_to_field_map || {}; + let template_options = JSON.parse(frm.doc.template_options || "{}"); + template_options.column_to_field_map = + template_options.column_to_field_map || {}; Object.assign(template_options.column_to_field_map, changed_map); - frm.set_value('template_options', JSON.stringify(template_options)); - frm.save().then(() => frm.trigger('import_file')); - } - } + frm.set_value("template_options", JSON.stringify(template_options)); + frm.save().then(() => frm.trigger("import_file")); + }, + }, }); }); }, export_errored_rows(frm) { open_url_post( - '/api/method/frappe.core.doctype.data_import.data_import.download_errored_template', + "/api/method/frappe.core.doctype.data_import.data_import.download_errored_template", { - data_import_name: frm.doc.name + data_import_name: frm.doc.name, } ); }, export_import_log(frm) { open_url_post( - '/api/method/frappe.core.doctype.data_import.data_import.download_import_log', + "/api/method/frappe.core.doctype.data_import.data_import.download_import_log", { - data_import_name: frm.doc.name + data_import_name: frm.doc.name, } ); }, show_import_warnings(frm, preview_data) { let columns = preview_data.columns; - let warnings = JSON.parse(frm.doc.template_warnings || '[]'); + let warnings = JSON.parse(frm.doc.template_warnings || "[]"); warnings = warnings.concat(preview_data.warnings || []); - frm.toggle_display('import_warnings_section', warnings.length > 0); + frm.toggle_display("import_warnings_section", warnings.length > 0); if (warnings.length === 0) { - frm.get_field('import_warnings').$wrapper.html(''); + frm.get_field("import_warnings").$wrapper.html(""); return; } @@ -361,36 +360,38 @@ frappe.ui.form.on('Data Import', { } } - let html = ''; + let html = ""; html += Object.keys(warnings_by_row) - .map(row_number => { + .map((row_number) => { let message = warnings_by_row[row_number] - .map(w => { + .map((w) => { if (w.field) { let label = w.field.label + (w.field.parent !== frm.doc.reference_doctype ? ` (${w.field.parent})` - : ''); + : ""); return `
  • ${label}: ${w.message}
  • `; } return `
  • ${w.message}
  • `; }) - .join(''); + .join(""); return `
    -
    ${__('Row {0}', [row_number])}
    +
    ${__("Row {0}", [row_number])}
      ${message}
    `; }) - .join(''); + .join(""); html += other_warnings - .map(warning => { - let header = ''; + .map((warning) => { + let header = ""; if (warning.col) { - let column_number = `${__('Column {0}', [warning.col])}`; + let column_number = `${__("Column {0}", [ + warning.col, + ])}`; let column_header = columns[warning.col].header_title; header = `${column_number} (${column_header})`; } @@ -401,8 +402,8 @@ frappe.ui.form.on('Data Import', { `; }) - .join(''); - frm.get_field('import_warnings').$wrapper.html(` + .join(""); + frm.get_field("import_warnings").$wrapper.html(`
    ${html}
    @@ -410,62 +411,62 @@ frappe.ui.form.on('Data Import', { }, show_failed_logs(frm) { - frm.trigger('show_import_log'); + frm.trigger("show_import_log"); }, render_import_log(frm) { frappe.call({ - 'method': 'frappe.client.get_list', - 'args': { - 'doctype': 'Data Import Log', - 'filters': { - 'data_import': frm.doc.name + method: "frappe.client.get_list", + args: { + doctype: "Data Import Log", + filters: { + data_import: frm.doc.name, }, - 'fields': ['success', 'docname', 'messages', 'exception', 'row_indexes'], - 'limit_page_length': 5000, - 'order_by': 'log_index' + fields: ["success", "docname", "messages", "exception", "row_indexes"], + limit_page_length: 5000, + order_by: "log_index", }, - callback: function(r) { + callback: function (r) { let logs = r.message; if (logs.length === 0) return; - frm.toggle_display('import_log_section', true); + frm.toggle_display("import_log_section", true); let rows = logs - .map(log => { - let html = ''; + .map((log) => { + let html = ""; if (log.success) { - if (frm.doc.import_type === 'Insert New Records') { - html = __('Successfully imported {0}', [ + if (frm.doc.import_type === "Insert New Records") { + html = __("Successfully imported {0}", [ `${frappe.utils.get_form_link( frm.doc.reference_doctype, log.docname, true - )}` + )}`, ]); } else { - html = __('Successfully updated {0}', [ + html = __("Successfully updated {0}", [ `${frappe.utils.get_form_link( frm.doc.reference_doctype, log.docname, true - )}` + )}`, ]); } } else { - let messages = (JSON.parse(log.messages || '[]')) + let messages = JSON.parse(log.messages || "[]") .map(JSON.parse) - .map(m => { - let title = m.title ? `${m.title}` : ''; - let message = m.message ? `
    ${m.message}
    ` : ''; + .map((m) => { + let title = m.title ? `${m.title}` : ""; + let message = m.message ? `
    ${m.message}
    ` : ""; return title + message; }) - .join(''); + .join(""); let id = frappe.dom.get_unique_id(); html = `${messages}
    @@ -473,15 +474,15 @@ frappe.ui.form.on('Data Import', {
    `; } - let indicator_color = log.success ? 'green' : 'red'; - let title = log.success ? __('Success') : __('Failure'); + let indicator_color = log.success ? "green" : "red"; + let title = log.success ? __("Success") : __("Failure"); if (frm.doc.show_failed_logs && log.success) { - return ''; + return ""; } return ` - ${JSON.parse(log.row_indexes).join(', ')} + ${JSON.parse(log.row_indexes).join(", ")}
    ${title}
    @@ -490,54 +491,54 @@ frappe.ui.form.on('Data Import', { `; }) - .join(''); + .join(""); if (!rows && frm.doc.show_failed_logs) { rows = ` - ${__('No failed logs')} + ${__("No failed logs")} `; } - frm.get_field('import_log_preview').$wrapper.html(` + frm.get_field("import_log_preview").$wrapper.html(` - - - + + + ${rows}
    ${__('Row Number')}${__('Status')}${__('Message')}${__("Row Number")}${__("Status")}${__("Message")}
    `); - } + }, }); }, show_import_log(frm) { - frm.toggle_display('import_log_section', false); + frm.toggle_display("import_log_section", false); if (frm.import_in_progress) { return; } frappe.call({ - 'method': 'frappe.client.get_count', - 'args': { - 'doctype': 'Data Import Log', - 'filters': { - 'data_import': frm.doc.name - } + method: "frappe.client.get_count", + args: { + doctype: "Data Import Log", + filters: { + data_import: frm.doc.name, + }, }, - 'callback': function(r) { + callback: function (r) { let count = r.message; if (count < 5000) { - frm.trigger('render_import_log'); + frm.trigger("render_import_log"); } else { - frm.toggle_display('import_log_section', false); - frm.add_custom_button(__('Export Import Log'), () => - frm.trigger('export_import_log') + frm.toggle_display("import_log_section", false); + frm.add_custom_button(__("Export Import Log"), () => + frm.trigger("export_import_log") ); } - } + }, }); }, }); diff --git a/frappe/core/doctype/data_import/data_import_list.js b/frappe/core/doctype/data_import/data_import_list.js index 6ab750ba25..c054655e62 100644 --- a/frappe/core/doctype/data_import/data_import_list.js +++ b/frappe/core/doctype/data_import/data_import_list.js @@ -1,46 +1,44 @@ let imports_in_progress = []; -frappe.listview_settings['Data Import'] = { +frappe.listview_settings["Data Import"] = { onload(listview) { - frappe.realtime.on('data_import_progress', data => { + frappe.realtime.on("data_import_progress", (data) => { if (!imports_in_progress.includes(data.data_import)) { imports_in_progress.push(data.data_import); } }); - frappe.realtime.on('data_import_refresh', data => { - imports_in_progress = imports_in_progress.filter( - d => d !== data.data_import - ); + frappe.realtime.on("data_import_refresh", (data) => { + imports_in_progress = imports_in_progress.filter((d) => d !== data.data_import); listview.refresh(); }); }, - get_indicator: function(doc) { + get_indicator: function (doc) { var colors = { - 'Pending': 'orange', - 'Not Started': 'orange', - 'Partial Success': 'orange', - 'Success': 'green', - 'In Progress': 'orange', - 'Error': 'red' + Pending: "orange", + "Not Started": "orange", + "Partial Success": "orange", + Success: "green", + "In Progress": "orange", + Error: "red", }; let status = doc.status; if (imports_in_progress.includes(doc.name)) { - status = 'In Progress'; + status = "In Progress"; } - if (status == 'Pending') { - status = 'Not Started'; + if (status == "Pending") { + status = "Not Started"; } - return [__(status), colors[status], 'status,=,' + doc.status]; + return [__(status), colors[status], "status,=," + doc.status]; }, formatters: { import_type(value) { return { - 'Insert New Records': __('Insert'), - 'Update Existing Records': __('Update') + "Insert New Records": __("Insert"), + "Update Existing Records": __("Update"), }[value]; - } + }, }, - hide_name_column: true + hide_name_column: true, }; diff --git a/frappe/core/doctype/data_import_log/data_import_log.js b/frappe/core/doctype/data_import_log/data_import_log.js index c376edeec9..19ba0eb727 100644 --- a/frappe/core/doctype/data_import_log/data_import_log.js +++ b/frappe/core/doctype/data_import_log/data_import_log.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Data Import Log', { +frappe.ui.form.on("Data Import Log", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/deleted_document/deleted_document.js b/frappe/core/doctype/deleted_document/deleted_document.js index 3125cb2f1c..34e13c01ab 100644 --- a/frappe/core/doctype/deleted_document/deleted_document.js +++ b/frappe/core/doctype/deleted_document/deleted_document.js @@ -1,22 +1,22 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Deleted Document', { - refresh: function(frm) { - if(frm.doc.restored) { - frm.add_custom_button(__('Open'), function() { - frappe.set_route('Form', frm.doc.deleted_doctype, frm.doc.new_name); +frappe.ui.form.on("Deleted Document", { + refresh: function (frm) { + if (frm.doc.restored) { + frm.add_custom_button(__("Open"), function () { + frappe.set_route("Form", frm.doc.deleted_doctype, frm.doc.new_name); }); } else { - frm.add_custom_button(__('Restore'), function() { + frm.add_custom_button(__("Restore"), function () { frappe.call({ - method: 'frappe.core.doctype.deleted_document.deleted_document.restore', - args: {name: frm.doc.name}, - callback: function(r) { + method: "frappe.core.doctype.deleted_document.deleted_document.restore", + args: { name: frm.doc.name }, + callback: function (r) { frm.reload_doc(); - } + }, }); }); } - } + }, }); diff --git a/frappe/core/doctype/deleted_document/deleted_document_list.js b/frappe/core/doctype/deleted_document/deleted_document_list.js index 92413bfdf4..6a271f5ae9 100644 --- a/frappe/core/doctype/deleted_document/deleted_document_list.js +++ b/frappe/core/doctype/deleted_document/deleted_document_list.js @@ -3,27 +3,36 @@ frappe.listview_settings["Deleted Document"] = { const action = () => { const selected_docs = doclist.get_checked_items(); if (selected_docs.length > 0) { - let docnames = selected_docs.map(doc => doc.name); + let docnames = selected_docs.map((doc) => doc.name); frappe.call({ method: "frappe.core.doctype.deleted_document.deleted_document.bulk_restore", args: { docnames }, callback: function (r) { if (r.message) { let body = (docnames) => { - const html = docnames.map(docname => { + const html = docnames.map((docname) => { return `
  • ${docname}
  • `; }); return "
      " + html.join(""); }; let message = (title, docnames) => { - return (docnames.length > 0) ? title + body(docnames) + "
    ": ""; + return docnames.length > 0 ? title + body(docnames) + "" : ""; }; const { restored, invalid, failed } = r.message; - const restored_summary = message(__("Documents restored successfully"), restored); - const invalid_summary = message(__("Documents that were already restored"), invalid); - const failed_summary = message(__("Documents that failed to restore"), failed); + const restored_summary = message( + __("Documents restored successfully"), + restored + ); + const invalid_summary = message( + __("Documents that were already restored"), + invalid + ); + const failed_summary = message( + __("Documents that failed to restore"), + failed + ); const summary = restored_summary + invalid_summary + failed_summary; frappe.msgprint(summary, __("Document Restoration Summary"), true); diff --git a/frappe/core/doctype/docshare/docshare.js b/frappe/core/doctype/docshare/docshare.js index 48db47a8cc..4d68c65cff 100644 --- a/frappe/core/doctype/docshare/docshare.js +++ b/frappe/core/doctype/docshare/docshare.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('DocShare', { - refresh: function(frm) { - - } +frappe.ui.form.on("DocShare", { + refresh: function (frm) {}, }); diff --git a/frappe/core/doctype/doctype/doctype.js b/frappe/core/doctype/doctype/doctype.js index 3a9b1f63dc..e91a05e17d 100644 --- a/frappe/core/doctype/doctype/doctype.js +++ b/frappe/core/doctype/doctype/doctype.js @@ -1,19 +1,19 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt -frappe.ui.form.on('DocType', { - refresh: function(frm) { - frm.set_query('role', 'permissions', function(doc) { - if (doc.custom && frappe.session.user != 'Administrator') { +frappe.ui.form.on("DocType", { + refresh: function (frm) { + frm.set_query("role", "permissions", function (doc) { + if (doc.custom && frappe.session.user != "Administrator") { return { query: "frappe.core.doctype.role.role.role_query", - filters: [['Role', 'name', '!=', 'All']] + filters: [["Role", "name", "!=", "All"]], }; } }); - if(frappe.session.user !== "Administrator" || !frappe.boot.developer_mode) { - if(frm.is_new()) { + if (frappe.session.user !== "Administrator" || !frappe.boot.developer_mode) { + if (frm.is_new()) { frm.set_value("custom", 1); } frm.toggle_enable("custom", 0); @@ -23,37 +23,46 @@ frappe.ui.form.on('DocType', { if (!frm.is_new() && !frm.doc.istable) { if (frm.doc.issingle) { - frm.add_custom_button(__('Go to {0}', [__(frm.doc.name)]), () => { + frm.add_custom_button(__("Go to {0}", [__(frm.doc.name)]), () => { window.open(`/app/${frappe.router.slug(frm.doc.name)}`); }); } else { - frm.add_custom_button(__('Go to {0} List', [__(frm.doc.name)]), () => { + frm.add_custom_button(__("Go to {0} List", [__(frm.doc.name)]), () => { window.open(`/app/${frappe.router.slug(frm.doc.name)}`); }); } } const customize_form_link = "Customize Form"; - if(!frappe.boot.developer_mode && !frm.doc.custom) { + if (!frappe.boot.developer_mode && !frm.doc.custom) { // make the document read-only frm.set_read_only(); - frm.dashboard.add_comment(__("DocTypes can not be modified, please use {0} instead", [customize_form_link]), "blue", true); + frm.dashboard.add_comment( + __("DocTypes can not be modified, please use {0} instead", [customize_form_link]), + "blue", + true + ); } else if (frappe.boot.developer_mode) { - let msg = __("This site is running in developer mode. Any change made here will be updated in code."); + let msg = __( + "This site is running in developer mode. Any change made here will be updated in code." + ); msg += "
    "; - msg += __("If you just want to customize for your site, use {0} instead.", [customize_form_link]); + msg += __("If you just want to customize for your site, use {0} instead.", [ + customize_form_link, + ]); frm.dashboard.add_comment(msg, "yellow"); } - if(frm.is_new()) { + if (frm.is_new()) { frm.events.set_default_permission(frm); } else { frm.toggle_enable("engine", 0); } // set label for "In List View" for child tables - frm.get_docfield('fields', 'in_list_view').label = frm.doc.istable ? - __('In Grid View') : __('In List View'); + frm.get_docfield("fields", "in_list_view").label = frm.doc.istable + ? __("In Grid View") + : __("In List View"); frm.cscript.autoname(frm); frm.cscript.set_naming_rule_description(frm); @@ -61,8 +70,8 @@ frappe.ui.form.on('DocType', { istable: (frm) => { if (frm.doc.istable && frm.is_new()) { - frm.set_value('autoname', 'autoincrement'); - frm.set_value('allow_rename', 0); + frm.set_value("autoname", "autoincrement"); + frm.set_value("allow_rename", 0); } else if (!frm.doc.istable && !frm.is_new()) { frm.events.set_default_permission(frm); } @@ -70,7 +79,7 @@ frappe.ui.form.on('DocType', { set_default_permission: (frm) => { if (!(frm.doc.permissions && frm.doc.permissions.length)) { - frm.add_child('permissions', {role: 'System Manager'}); + frm.add_child("permissions", { role: "System Manager" }); } }, }); @@ -98,15 +107,15 @@ frappe.ui.form.on("DocField", { } let doctypes = frm.doc.fields - .filter(df => df.fieldtype == "Link") - .filter(df => df.options && df.fieldname != row.fieldname) - .map(df => ({ + .filter((df) => df.fieldtype == "Link") + .filter((df) => df.options && df.fieldname != row.fieldname) + .map((df) => ({ label: `${df.options} (${df.fieldname})`, - value: df.fieldname + value: df.fieldname, })); $doctype_select.add_options([ { label: __("Select DocType"), value: "", selected: true }, - ...doctypes + ...doctypes, ]); $doctype_select.on("change", () => { @@ -120,27 +129,25 @@ frappe.ui.form.on("DocField", { let link_fieldname = $doctype_select.val(); if (!link_fieldname) return; - let link_field = frm.doc.fields.find( - df => df.fieldname === link_fieldname - ); + let link_field = frm.doc.fields.find((df) => df.fieldname === link_fieldname); let link_doctype = link_field.options; frappe.model.with_doctype(link_doctype, () => { let fields = frappe.meta .get_docfields(link_doctype, null, { - fieldtype: ["not in", frappe.model.no_value_type] + fieldtype: ["not in", frappe.model.no_value_type], }) - .map(df => ({ + .map((df) => ({ label: `${df.label} (${df.fieldtype})`, - value: df.fieldname + value: df.fieldname, })); $field_select.add_options([ { label: __("Select Field"), value: "", selected: true, - disabled: true + disabled: true, }, - ...fields + ...fields, ]); if (curr_value.fieldname) { @@ -161,9 +168,9 @@ frappe.ui.form.on("DocField", { } }, - fieldtype: function(frm) { + fieldtype: function (frm) { frm.trigger("max_attachments"); - } + }, }); -extend_cscript(cur_frm.cscript, new frappe.model.DocTypeController({frm: cur_frm})); +extend_cscript(cur_frm.cscript, new frappe.model.DocTypeController({ frm: cur_frm })); diff --git a/frappe/core/doctype/document_naming_rule/document_naming_rule.js b/frappe/core/doctype/document_naming_rule/document_naming_rule.js index 097a4e9a6e..70d95673e6 100644 --- a/frappe/core/doctype/document_naming_rule/document_naming_rule.js +++ b/frappe/core/doctype/document_naming_rule/document_naming_rule.js @@ -1,64 +1,70 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Document Naming Rule', { - refresh: function(frm) { - frm.trigger('document_type'); +frappe.ui.form.on("Document Naming Rule", { + refresh: function (frm) { + frm.trigger("document_type"); if (!frm.doc.__islocal) frm.trigger("add_update_counter_button"); }, document_type: (frm) => { // update the select field options with fieldnames if (frm.doc.document_type) { frappe.model.with_doctype(frm.doc.document_type, () => { - let fieldnames = frappe.get_meta(frm.doc.document_type).fields - .filter((d) => { + let fieldnames = frappe + .get_meta(frm.doc.document_type) + .fields.filter((d) => { return frappe.model.no_value_type.indexOf(d.fieldtype) === -1; - }).map((d) => { - return {label: `${d.label} (${d.fieldname})`, value: d.fieldname}; + }) + .map((d) => { + return { label: `${d.label} (${d.fieldname})`, value: d.fieldname }; }); frm.fields_dict.conditions.grid.update_docfield_property( - 'field', 'options', fieldnames + "field", + "options", + fieldnames ); }); } }, add_update_counter_button: (frm) => { - frm.add_custom_button(__('Update Counter'), function() { + frm.add_custom_button(__("Update Counter"), function () { + const fields = [ + { + fieldtype: "Data", + fieldname: "new_counter", + label: __("New Counter"), + default: frm.doc.counter, + reqd: 1, + description: __( + "Warning: Updating counter may lead to document name conflicts if not done properly" + ), + }, + ]; - const fields = [{ - fieldtype: 'Data', - fieldname: 'new_counter', - label: __('New Counter'), - default: frm.doc.counter, - reqd: 1, - description: __('Warning: Updating counter may lead to document name conflicts if not done properly') - }]; - - let primary_action_label = __('Save'); + let primary_action_label = __("Save"); let primary_action = (fields) => { frappe.call({ - method: 'frappe.core.doctype.document_naming_rule.document_naming_rule.update_current', + method: "frappe.core.doctype.document_naming_rule.document_naming_rule.update_current", args: { name: frm.doc.name, - new_counter: fields.new_counter + new_counter: fields.new_counter, }, - callback: function() { + callback: function () { frm.set_value("counter", fields.new_counter); dialog.hide(); - } + }, }); }; const dialog = new frappe.ui.Dialog({ - title: __('Update Counter Value for Prefix: {0}', [frm.doc.prefix]), + title: __("Update Counter Value for Prefix: {0}", [frm.doc.prefix]), fields, primary_action_label, - primary_action + primary_action, }); dialog.show(); - }); - } + }, }); diff --git a/frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.js b/frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.js index 8ef39c7b70..fdf46e82e0 100644 --- a/frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.js +++ b/frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Document Naming Rule Condition', { +frappe.ui.form.on("Document Naming Rule Condition", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/document_naming_settings/document_naming_settings.js b/frappe/core/doctype/document_naming_settings/document_naming_settings.js index 2dc5fc4d58..2a9ec4aae5 100644 --- a/frappe/core/doctype/document_naming_settings/document_naming_settings.js +++ b/frappe/core/doctype/document_naming_settings/document_naming_settings.js @@ -2,28 +2,28 @@ // For license information, please see license.txt frappe.ui.form.on("Document Naming Settings", { - refresh: function(frm) { + refresh: function (frm) { frm.trigger("setup_transaction_autocomplete"); frm.disable_save(); }, - setup_transaction_autocomplete: function(frm) { + setup_transaction_autocomplete: function (frm) { frappe.call({ method: "get_transactions_and_prefixes", doc: frm.doc, - callback: function(r) { + callback: function (r) { frm.fields_dict.transaction_type.set_data(r.message.transactions); frm.fields_dict.prefix.set_data(r.message.prefixes); }, }); }, - transaction_type: function(frm) { + transaction_type: function (frm) { frm.set_value("user_must_always_select", 0); frappe.call({ method: "get_options", doc: frm.doc, - callback: function(r) { + callback: function (r) { frm.set_value("naming_series_options", r.message); if (r.message && r.message.split("\n")[0] == "") frm.set_value("user_must_always_select", 1); @@ -31,23 +31,23 @@ frappe.ui.form.on("Document Naming Settings", { }); }, - prefix: function(frm) { + prefix: function (frm) { frappe.call({ method: "get_current", doc: frm.doc, - callback: function(r) { + callback: function (r) { frm.refresh_field("current_value"); }, }); }, - update: function(frm) { + update: function (frm) { frappe.call({ method: "update_series", doc: frm.doc, freeze: true, freeze_msg: __("Updating naming series options"), - callback: function(r) { + callback: function (r) { frm.trigger("setup_transaction_autocomplete"); frm.trigger("transaction_type"); }, @@ -58,14 +58,11 @@ frappe.ui.form.on("Document Naming Settings", { frappe.call({ method: "preview_series", doc: frm.doc, - callback: function(r) { + callback: function (r) { if (!r.exc) { frm.set_value("series_preview", r.message); } else { - frm.set_value( - "series_preview", - __("Failed to generate preview of series") - ); + frm.set_value("series_preview", __("Failed to generate preview of series")); } }, }); diff --git a/frappe/core/doctype/document_share_key/document_share_key.js b/frappe/core/doctype/document_share_key/document_share_key.js index c51233e10f..7e1712beff 100644 --- a/frappe/core/doctype/document_share_key/document_share_key.js +++ b/frappe/core/doctype/document_share_key/document_share_key.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Document Share Key', { +frappe.ui.form.on("Document Share Key", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/domain/domain.js b/frappe/core/doctype/domain/domain.js index 397ed4b19c..9b51c10d77 100644 --- a/frappe/core/doctype/domain/domain.js +++ b/frappe/core/doctype/domain/domain.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Domain', { - refresh: function(frm) { - - } +frappe.ui.form.on("Domain", { + refresh: function (frm) {}, }); diff --git a/frappe/core/doctype/domain_settings/domain_settings.js b/frappe/core/doctype/domain_settings/domain_settings.js index 7178cb4cd6..87386ce9bd 100644 --- a/frappe/core/doctype/domain_settings/domain_settings.js +++ b/frappe/core/doctype/domain_settings/domain_settings.js @@ -1,66 +1,69 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Domain Settings', { - before_load: function(frm) { - if(!frm.domains_multicheck) { +frappe.ui.form.on("Domain Settings", { + before_load: function (frm) { + if (!frm.domains_multicheck) { frm.domains_multicheck = frappe.ui.form.make_control({ parent: frm.fields_dict.domains_html.$wrapper, df: { fieldname: "domains_multicheck", fieldtype: "MultiCheck", get_data: () => { - let active_domains = (frm.doc.active_domains || []).map(row => row.domain); - return frappe.boot.all_domains.map(domain => { + let active_domains = (frm.doc.active_domains || []).map( + (row) => row.domain + ); + return frappe.boot.all_domains.map((domain) => { return { label: domain, value: domain, - checked: active_domains.includes(domain) + checked: active_domains.includes(domain), }; }); }, on_change: () => { frm.dirty(); - } + }, }, - render_input: true + render_input: true, }); frm.domains_multicheck.refresh_input(); } }, - validate: function(frm) { - frm.trigger('set_options_in_table'); + validate: function (frm) { + frm.trigger("set_options_in_table"); }, - set_options_in_table: function(frm) { + set_options_in_table: function (frm) { let selected_options = frm.domains_multicheck.get_value(); let unselected_options = frm.domains_multicheck.options - .map(option => option.value) - .filter(value => { + .map((option) => option.value) + .filter((value) => { return !selected_options.includes(value); }); - let map = {}, list = []; - (frm.doc.active_domains || []).map(row => { + let map = {}, + list = []; + (frm.doc.active_domains || []).map((row) => { map[row.domain] = row.name; list.push(row.domain); }); - unselected_options.map(option => { - if(list.includes(option)) { + unselected_options.map((option) => { + if (list.includes(option)) { frappe.model.clear_doc("Has Domain", map[option]); } }); - selected_options.map(option => { - if(!list.includes(option)) { + selected_options.map((option) => { + if (!list.includes(option)) { frappe.model.clear_doc("Has Domain", map[option]); let row = frappe.model.add_child(frm.doc, "Has Domain", "active_domains"); row.domain = option; } }); - refresh_field('active_domains'); - } + refresh_field("active_domains"); + }, }); diff --git a/frappe/core/doctype/error_log/error_log.js b/frappe/core/doctype/error_log/error_log.js index 1262002b04..85b1c8b60a 100644 --- a/frappe/core/doctype/error_log/error_log.js +++ b/frappe/core/doctype/error_log/error_log.js @@ -2,11 +2,11 @@ // For license information, please see license.txt frappe.ui.form.on("Error Log", { - refresh: function(frm) { + refresh: function (frm) { frm.disable_save(); if (frm.doc.reference_doctype && frm.doc.reference_name) { - frm.add_custom_button(__("Show Related Errors"), function() { + frm.add_custom_button(__("Show Related Errors"), function () { frappe.set_route("List", "Error Log", { reference_doctype: frm.doc.reference_doctype, reference_name: frm.doc.reference_name, diff --git a/frappe/core/doctype/error_log/error_log_list.js b/frappe/core/doctype/error_log/error_log_list.js index e92773a9de..dabe95d6d7 100644 --- a/frappe/core/doctype/error_log/error_log_list.js +++ b/frappe/core/doctype/error_log/error_log_list.js @@ -1,6 +1,6 @@ frappe.listview_settings["Error Log"] = { add_fields: ["seen"], - get_indicator: function(doc) { + get_indicator: function (doc) { if (cint(doc.seen)) { return [__("Seen"), "green", "seen,=,1"]; } else { @@ -8,11 +8,11 @@ frappe.listview_settings["Error Log"] = { } }, order_by: "seen asc, modified desc", - onload: function(listview) { - listview.page.add_menu_item(__("Clear Error Logs"), function() { + onload: function (listview) { + listview.page.add_menu_item(__("Clear Error Logs"), function () { frappe.call({ method: "frappe.core.doctype.error_log.error_log.clear_error_logs", - callback: function() { + callback: function () { listview.refresh(); }, }); @@ -20,6 +20,6 @@ frappe.listview_settings["Error Log"] = { frappe.require("logtypes.bundle.js", () => { frappe.utils.logtypes.show_log_retention_message(cur_list.doctype); - }) + }); }, }; diff --git a/frappe/core/doctype/error_snapshot/error_snapshot.js b/frappe/core/doctype/error_snapshot/error_snapshot.js index c1b2d996a1..f8a7e3ded5 100644 --- a/frappe/core/doctype/error_snapshot/error_snapshot.js +++ b/frappe/core/doctype/error_snapshot/error_snapshot.js @@ -1,14 +1,18 @@ -frappe.ui.form.on("Error Snapshot", "load", function(frm){ +frappe.ui.form.on("Error Snapshot", "load", function (frm) { frm.set_read_only(true); }); -frappe.ui.form.on("Error Snapshot", "refresh", function(frm){ - frm.set_df_property("view", "options", frappe.render_template("error_snapshot", {"doc": frm.doc})); +frappe.ui.form.on("Error Snapshot", "refresh", function (frm) { + frm.set_df_property( + "view", + "options", + frappe.render_template("error_snapshot", { doc: frm.doc }) + ); if (frm.doc.relapses) { - frm.add_custom_button(__('Show Relapses'), function() { + frm.add_custom_button(__("Show Relapses"), function () { frappe.route_options = { - parent_error_snapshot: frm.doc.name + parent_error_snapshot: frm.doc.name, }; frappe.set_route("List", "Error Snapshot"); }); diff --git a/frappe/core/doctype/error_snapshot/error_snapshot_list.js b/frappe/core/doctype/error_snapshot/error_snapshot_list.js index 553495beb1..b331788852 100644 --- a/frappe/core/doctype/error_snapshot/error_snapshot_list.js +++ b/frappe/core/doctype/error_snapshot/error_snapshot_list.js @@ -1,19 +1,19 @@ frappe.listview_settings["Error Snapshot"] = { add_fields: ["parent_error_snapshot", "relapses", "seen"], - filters:[ - ["parent_error_snapshot","=",null], - ["seen", "=", false] + filters: [ + ["parent_error_snapshot", "=", null], + ["seen", "=", false], ], - get_indicator: function(doc){ - if (doc.parent_error_snapshot && doc.parent_error_snapshot.length){ + get_indicator: function (doc) { + if (doc.parent_error_snapshot && doc.parent_error_snapshot.length) { return [__("Relapsed"), !doc.seen ? "orange" : "blue", "parent_error_snapshot,!=,"]; } else { return [__("First Level"), !doc.seen ? "red" : "green", "parent_error_snapshot,=,"]; } }, - onload: function(listview) { + onload: function (listview) { frappe.require("logtypes.bundle.js", () => { frappe.utils.logtypes.show_log_retention_message(cur_list.doctype); - }) + }); }, -} +}; diff --git a/frappe/core/doctype/file/file.js b/frappe/core/doctype/file/file.js index ecad8d884a..f9051dc896 100644 --- a/frappe/core/doctype/file/file.js +++ b/frappe/core/doctype/file/file.js @@ -1,23 +1,27 @@ -frappe.ui.form.on("File", "refresh", function(frm) { - if(!frm.doc.is_folder) { - frm.add_custom_button(__('Download'), function() { - var file_url = frm.doc.file_url; - if (frm.doc.file_name) { - file_url = file_url.replace(/#/g, '%23'); - } - window.open(file_url); - }, "fa fa-download"); +frappe.ui.form.on("File", "refresh", function (frm) { + if (!frm.doc.is_folder) { + frm.add_custom_button( + __("Download"), + function () { + var file_url = frm.doc.file_url; + if (frm.doc.file_name) { + file_url = file_url.replace(/#/g, "%23"); + } + window.open(file_url); + }, + "fa fa-download" + ); } frm.get_field("preview_html").$wrapper.html(`
    `); - var is_raster_image = (/\.(gif|jpg|jpeg|tiff|png)$/i).test(frm.doc.file_url); + var is_raster_image = /\.(gif|jpg|jpeg|tiff|png)$/i.test(frm.doc.file_url); var is_optimizable = !frm.doc.is_folder && is_raster_image && frm.doc.file_size > 0; if (is_optimizable) { - frm.add_custom_button(__("Optimize"), function() { + frm.add_custom_button(__("Optimize"), function () { frappe.show_alert(__("Optimizing image...")); frm.call("optimize_file").then(() => { frappe.show_alert(__("Image optimized")); @@ -25,16 +29,16 @@ frappe.ui.form.on("File", "refresh", function(frm) { }); } - if(frm.doc.file_name && frm.doc.file_name.split('.').splice(-1)[0]==='zip') { - frm.add_custom_button(__('Unzip'), function() { + if (frm.doc.file_name && frm.doc.file_name.split(".").splice(-1)[0] === "zip") { + frm.add_custom_button(__("Unzip"), function () { frappe.call({ method: "frappe.core.api.file.unzip_file", args: { name: frm.doc.name, }, - callback: function() { - frappe.set_route('List', 'File'); - } + callback: function () { + frappe.set_route("List", "File"); + }, }); }); } diff --git a/frappe/core/doctype/installed_applications/installed_applications.js b/frappe/core/doctype/installed_applications/installed_applications.js index 9a1fd5ac18..223c028e7a 100644 --- a/frappe/core/doctype/installed_applications/installed_applications.js +++ b/frappe/core/doctype/installed_applications/installed_applications.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Installed Applications', { +frappe.ui.form.on("Installed Applications", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/language/language.js b/frappe/core/doctype/language/language.js index e60282ebbf..9c7852f9e0 100644 --- a/frappe/core/doctype/language/language.js +++ b/frappe/core/doctype/language/language.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Language', { - refresh: function(frm) { - - } +frappe.ui.form.on("Language", { + refresh: function (frm) {}, }); diff --git a/frappe/core/doctype/log_setting_user/log_setting_user.js b/frappe/core/doctype/log_setting_user/log_setting_user.js index a1eb824e22..61f3aa67c5 100644 --- a/frappe/core/doctype/log_setting_user/log_setting_user.js +++ b/frappe/core/doctype/log_setting_user/log_setting_user.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Log Setting User', { +frappe.ui.form.on("Log Setting User", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/log_settings/log_settings.js b/frappe/core/doctype/log_settings/log_settings.js index dc7cc7eac2..b72cd5285a 100644 --- a/frappe/core/doctype/log_settings/log_settings.js +++ b/frappe/core/doctype/log_settings/log_settings.js @@ -7,9 +7,7 @@ frappe.ui.form.on("Log Settings", { const added_doctypes = frm.doc.logs_to_clear.map((r) => r.ref_doctype); return { query: "frappe.core.doctype.log_settings.log_settings.get_log_doctypes", - filters: [ - ["name", "not in", added_doctypes], - ], + filters: [["name", "not in", added_doctypes]], }; }); }, diff --git a/frappe/core/doctype/module_def/module_def.js b/frappe/core/doctype/module_def/module_def.js index 73d2d6562c..8d542e620d 100644 --- a/frappe/core/doctype/module_def/module_def.js +++ b/frappe/core/doctype/module_def/module_def.js @@ -1,13 +1,13 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Module Def', { - refresh: function(frm) { - frappe.xcall('frappe.core.doctype.module_def.module_def.get_installed_apps').then(r => { - frm.set_df_property('app_name', 'options', JSON.parse(r)); +frappe.ui.form.on("Module Def", { + refresh: function (frm) { + frappe.xcall("frappe.core.doctype.module_def.module_def.get_installed_apps").then((r) => { + frm.set_df_property("app_name", "options", JSON.parse(r)); if (!frm.doc.app_name) { - frm.set_value('app_name', 'frappe'); + frm.set_value("app_name", "frappe"); } }); - } + }, }); diff --git a/frappe/core/doctype/module_profile/module_profile.js b/frappe/core/doctype/module_profile/module_profile.js index 3714d31ade..7860577a6c 100644 --- a/frappe/core/doctype/module_profile/module_profile.js +++ b/frappe/core/doctype/module_profile/module_profile.js @@ -19,5 +19,5 @@ frappe.ui.form.on("Module Profile", { if (frm.module_editor) { frm.module_editor.set_modules_in_table(); } - } + }, }); diff --git a/frappe/core/doctype/navbar_item/navbar_item.js b/frappe/core/doctype/navbar_item/navbar_item.js index bd4274db49..b14d0a5670 100644 --- a/frappe/core/doctype/navbar_item/navbar_item.js +++ b/frappe/core/doctype/navbar_item/navbar_item.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Navbar Item', { +frappe.ui.form.on("Navbar Item", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/navbar_settings/navbar_settings.js b/frappe/core/doctype/navbar_settings/navbar_settings.js index e2c157fe6a..c0e1113087 100644 --- a/frappe/core/doctype/navbar_settings/navbar_settings.js +++ b/frappe/core/doctype/navbar_settings/navbar_settings.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Navbar Settings', { +frappe.ui.form.on("Navbar Settings", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/package/package.js b/frappe/core/doctype/package/package.js index 90e2eed1e3..97d9c32c85 100644 --- a/frappe/core/doctype/package/package.js +++ b/frappe/core/doctype/package/package.js @@ -1,17 +1,20 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Package', { - validate: function(frm) { +frappe.ui.form.on("Package", { + validate: function (frm) { if (!frm.doc.package_name) { - frm.set_value('package_name', frm.doc.name.toLowerCase().replace(' ', '-')); + frm.set_value("package_name", frm.doc.name.toLowerCase().replace(" ", "-")); } }, - license_type: function(frm) { - frappe.call('frappe.core.doctype.package.package.get_license_text', - {'license_type': frm.doc.license_type}).then(r => { - frm.set_value('license', r.message); - }); - } + license_type: function (frm) { + frappe + .call("frappe.core.doctype.package.package.get_license_text", { + license_type: frm.doc.license_type, + }) + .then((r) => { + frm.set_value("license", r.message); + }); + }, }); diff --git a/frappe/core/doctype/package_import/package_import.js b/frappe/core/doctype/package_import/package_import.js index c01a6266cc..72f5bbf681 100644 --- a/frappe/core/doctype/package_import/package_import.js +++ b/frappe/core/doctype/package_import/package_import.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Package Import', { +frappe.ui.form.on("Package Import", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/package_release/package_release.js b/frappe/core/doctype/package_release/package_release.js index 9eabe36839..af482fc4a0 100644 --- a/frappe/core/doctype/package_release/package_release.js +++ b/frappe/core/doctype/package_release/package_release.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Package Release', { +frappe.ui.form.on("Package Release", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/page/page.js b/frappe/core/doctype/page/page.js index d1d9600e59..295dca1aae 100644 --- a/frappe/core/doctype/page/page.js +++ b/frappe/core/doctype/page/page.js @@ -1,16 +1,16 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Page', { - refresh: function(frm) { - if (!frappe.boot.developer_mode && frappe.session.user != 'Administrator') { +frappe.ui.form.on("Page", { + refresh: function (frm) { + if (!frappe.boot.developer_mode && frappe.session.user != "Administrator") { // make the document read-only frm.set_read_only(); } if (!frm.is_new() && !frm.doc.istable) { - frm.add_custom_button(__('Go to {0} Page', [frm.doc.title || frm.doc.name]), () => { + frm.add_custom_button(__("Go to {0} Page", [frm.doc.title || frm.doc.name]), () => { frappe.set_route(frm.doc.name); }); } - } + }, }); diff --git a/frappe/core/doctype/patch_log/patch_log.js b/frappe/core/doctype/patch_log/patch_log.js index b52876ac97..171a1d3a0f 100644 --- a/frappe/core/doctype/patch_log/patch_log.js +++ b/frappe/core/doctype/patch_log/patch_log.js @@ -1,8 +1,8 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Patch Log', { - refresh: function(frm) { +frappe.ui.form.on("Patch Log", { + refresh: function (frm) { frm.disable_save(); - } + }, }); diff --git a/frappe/core/doctype/prepared_report/prepared_report.js b/frappe/core/doctype/prepared_report/prepared_report.js index 6a7cf2728c..58f4c1957f 100644 --- a/frappe/core/doctype/prepared_report/prepared_report.js +++ b/frappe/core/doctype/prepared_report/prepared_report.js @@ -1,15 +1,15 @@ // Copyright (c) 2018, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Prepared Report', { - onload: function(frm) { +frappe.ui.form.on("Prepared Report", { + onload: function (frm) { var wrapper = $(frm.fields_dict["filter_values"].wrapper).empty(); let filter_table = $(` - - + + @@ -17,29 +17,29 @@ frappe.ui.form.on('Prepared Report', { const filters = JSON.parse(frm.doc.filters); - Object.keys(filters).forEach(key => { + Object.keys(filters).forEach((key) => { const filter_row = $(``); - filter_table.find('tbody').append(filter_row); + filter_table.find("tbody").append(filter_row); }); wrapper.append(filter_table); }, - refresh: function(frm) { + refresh: function (frm) { frm.disable_save(); - if (frm.doc.status == 'Completed') { + if (frm.doc.status == "Completed") { frm.page.set_primary_action(__("Show Report"), () => { frappe.set_route( "query-report", frm.doc.report_name, frappe.utils.make_query_string({ - prepared_report_name: frm.doc.name + prepared_report_name: frm.doc.name, }) ); }); } - } + }, }); diff --git a/frappe/core/doctype/prepared_report/prepared_report_list.js b/frappe/core/doctype/prepared_report/prepared_report_list.js index 8acb3bc75a..1414dd7580 100644 --- a/frappe/core/doctype/prepared_report/prepared_report_list.js +++ b/frappe/core/doctype/prepared_report/prepared_report_list.js @@ -1,12 +1,12 @@ -frappe.listview_settings['Prepared Report'] = { +frappe.listview_settings["Prepared Report"] = { add_fields: ["status"], - get_indicator: function(doc) { - if(doc.status==="Completed"){ + get_indicator: function (doc) { + if (doc.status === "Completed") { return [__("Completed"), "green", "status,=,Completed"]; - } else if(doc.status ==="Error"){ + } else if (doc.status === "Error") { return [__("Error"), "red", "status,=,Error"]; - } else if(doc.status ==="Queued"){ + } else if (doc.status === "Queued") { return [__("Queued"), "orange", "status,=,Queued"]; } - } -}; \ No newline at end of file + }, +}; diff --git a/frappe/core/doctype/report/report.js b/frappe/core/doctype/report/report.js index 71ed0dac64..c912e217a6 100644 --- a/frappe/core/doctype/report/report.js +++ b/frappe/core/doctype/report/report.js @@ -1,5 +1,5 @@ -frappe.ui.form.on('Report', { - refresh: function(frm) { +frappe.ui.form.on("Report", { + refresh: function (frm) { if (frm.doc.is_standard === "Yes" && !frappe.boot.developer_mode) { // make the document read-only frm.disable_form(); @@ -8,43 +8,51 @@ frappe.ui.form.on('Report', { } let doc = frm.doc; - frm.add_custom_button(__("Show Report"), function() { - switch(doc.report_type) { - case "Report Builder": - frappe.set_route('List', doc.ref_doctype, 'Report', doc.name); - break; - case "Query Report": - frappe.set_route("query-report", doc.name); - break; - case "Script Report": - frappe.set_route("query-report", doc.name); - break; - case "Custom Report": - frappe.set_route("query-report", doc.name); - break; - } - }, "fa fa-table"); + frm.add_custom_button( + __("Show Report"), + function () { + switch (doc.report_type) { + case "Report Builder": + frappe.set_route("List", doc.ref_doctype, "Report", doc.name); + break; + case "Query Report": + frappe.set_route("query-report", doc.name); + break; + case "Script Report": + frappe.set_route("query-report", doc.name); + break; + case "Custom Report": + frappe.set_route("query-report", doc.name); + break; + } + }, + "fa fa-table" + ); if (doc.is_standard === "Yes" && frm.perm[0].write) { - frm.add_custom_button(doc.disabled ? __("Enable Report") : __("Disable Report"), function() { - frm.call('toggle_disable', { - disable: doc.disabled ? 0 : 1 - }).then(() => { - frm.reload_doc(); - }); - }, doc.disabled ? "fa fa-check" : "fa fa-off"); + frm.add_custom_button( + doc.disabled ? __("Enable Report") : __("Disable Report"), + function () { + frm.call("toggle_disable", { + disable: doc.disabled ? 0 : 1, + }).then(() => { + frm.reload_doc(); + }); + }, + doc.disabled ? "fa fa-check" : "fa fa-off" + ); } }, - ref_doctype: function(frm) { - if(frm.doc.ref_doctype) { + ref_doctype: function (frm) { + if (frm.doc.ref_doctype) { frm.trigger("set_doctype_roles"); } }, - set_doctype_roles: function(frm) { - return frm.call('set_doctype_roles').then(() => { - frm.refresh_field('roles'); + set_doctype_roles: function (frm) { + return frm.call("set_doctype_roles").then(() => { + frm.refresh_field("roles"); }); - } -}) + }, +}); diff --git a/frappe/core/doctype/role/role.js b/frappe/core/doctype/role/role.js index 595e857d02..c0a65bcf58 100644 --- a/frappe/core/doctype/role/role.js +++ b/frappe/core/doctype/role/role.js @@ -1,8 +1,8 @@ // Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See LICENSE -frappe.ui.form.on('Role', { - refresh: function(frm) { +frappe.ui.form.on("Role", { + refresh: function (frm) { if (frm.doc.name === "All") { frm.dashboard.add_comment( __("Role 'All' will be given to all System Users."), @@ -10,15 +10,15 @@ frappe.ui.form.on('Role', { ); } - frm.set_df_property('is_custom', 'read_only', frappe.session.user !== 'Administrator'); + frm.set_df_property("is_custom", "read_only", frappe.session.user !== "Administrator"); - frm.add_custom_button("Role Permissions Manager", function() { - frappe.route_options = {"role": frm.doc.name}; + frm.add_custom_button("Role Permissions Manager", function () { + frappe.route_options = { role: frm.doc.name }; frappe.set_route("permission-manager"); }); - frm.add_custom_button("Show Users", function() { - frappe.route_options = {"role": frm.doc.name}; + frm.add_custom_button("Show Users", function () { + frappe.route_options = { role: frm.doc.name }; frappe.set_route("List", "User", "Report"); }); - } + }, }); diff --git a/frappe/core/doctype/role_permission_for_page_and_report/role_permission_for_page_and_report.js b/frappe/core/doctype/role_permission_for_page_and_report/role_permission_for_page_and_report.js index 5048d24077..86d09bef27 100644 --- a/frappe/core/doctype/role_permission_for_page_and_report/role_permission_for_page_and_report.js +++ b/frappe/core/doctype/role_permission_for_page_and_report/role_permission_for_page_and_report.js @@ -1,22 +1,22 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Role Permission for Page and Report', { - setup: function(frm) { +frappe.ui.form.on("Role Permission for Page and Report", { + setup: function (frm) { frm.trigger("set_queries"); }, - refresh: function(frm) { + refresh: function (frm) { frm.disable_save(); frm.role_area.hide(); frm.events.setup_buttons(frm); }, - setup_buttons: function(frm) { + setup_buttons: function (frm) { frm.clear_custom_buttons(); frm.page.clear_actions(); if (frm.doc.set_role_for && frm.doc[frappe.model.scrub(frm.doc.set_role_for)]) { - frm.add_custom_button(__("Reset to defaults"), function() { + frm.add_custom_button(__("Reset to defaults"), function () { frm.trigger("reset_roles"); }); @@ -26,34 +26,34 @@ frappe.ui.form.on('Role Permission for Page and Report', { } }, - onload: function(frm) { + onload: function (frm) { if (!frm.roles_editor) { frm.role_area = $(frm.fields_dict.roles_html.wrapper); frm.roles_editor = new frappe.RoleEditor(frm.role_area, frm); } }, - set_queries: function(frm) { - frm.set_query("page", function() { + set_queries: function (frm) { + frm.set_query("page", function () { return { filters: { - system_page: 0 - } - } + system_page: 0, + }, + }; }); }, - set_role_for: function(frm) { - frm.trigger("clear_fields") - frm.toggle_display('roles_html', false) + set_role_for: function (frm) { + frm.trigger("clear_fields"); + frm.toggle_display("roles_html", false); }, - clear_fields: function(frm) { - var field = (frm.doc.set_role_for == 'Report') ? 'page' : 'report'; - frm.set_value(field, ''); + clear_fields: function (frm) { + var field = frm.doc.set_role_for == "Report" ? "page" : "report"; + frm.set_value(field, ""); }, - page: function(frm) { + page: function (frm) { frm.events.setup_buttons(frm); if (frm.doc.page) { frm.trigger("set_report_page_data"); @@ -62,7 +62,7 @@ frappe.ui.form.on('Role Permission for Page and Report', { } }, - report: function(frm) { + report: function (frm) { frm.events.setup_buttons(frm); if (frm.doc.report) { frm.trigger("set_report_page_data"); @@ -71,57 +71,57 @@ frappe.ui.form.on('Role Permission for Page and Report', { } }, - set_report_page_data: function(frm) { - frm.toggle_display('roles_html', true) + set_report_page_data: function (frm) { + frm.toggle_display("roles_html", true); frm.role_area.show(); return frm.call({ - method:"set_report_page_data", + method: "set_report_page_data", doc: frm.doc, - callback: function(r) { - refresh_field('roles') - frm.roles_editor.show() - } - }) + callback: function (r) { + refresh_field("roles"); + frm.roles_editor.show(); + }, + }); }, - update_report_page_data: function(frm) { - frm.trigger("validate_mandatory_fields") - if(frm.roles_editor) { - frm.roles_editor.set_roles_in_table() + update_report_page_data: function (frm) { + frm.trigger("validate_mandatory_fields"); + if (frm.roles_editor) { + frm.roles_editor.set_roles_in_table(); } return frm.call({ - method:"update_report_page_data", + method: "update_report_page_data", doc: frm.doc, - callback: function(r) { - refresh_field('roles') - frm.roles_editor.show() - frappe.msgprint(__("Successfully Updated")) - } - }) + callback: function (r) { + refresh_field("roles"); + frm.roles_editor.show(); + frappe.msgprint(__("Successfully Updated")); + }, + }); }, - reset_roles: function(frm) { - frm.trigger("validate_mandatory_fields") + reset_roles: function (frm) { + frm.trigger("validate_mandatory_fields"); return frm.call({ - method:"reset_roles", + method: "reset_roles", doc: frm.doc, - callback: function(r) { - refresh_field('roles') - frm.roles_editor.show() - frappe.msgprint(__("Successfully Updated")) - } - }) + callback: function (r) { + refresh_field("roles"); + frm.roles_editor.show(); + frappe.msgprint(__("Successfully Updated")); + }, + }); }, - validate_mandatory_fields: function(frm) { - if(!frm.doc.set_role_for){ - frappe.throw(__("Mandatory field: set role for")) + validate_mandatory_fields: function (frm) { + if (!frm.doc.set_role_for) { + frappe.throw(__("Mandatory field: set role for")); } - if(frm.doc.set_role_for && !frm.doc[frm.doc.set_role_for.toLocaleLowerCase()]) { - frappe.throw(__("Mandatory field: {0}", [frm.doc.set_role_for])) + if (frm.doc.set_role_for && !frm.doc[frm.doc.set_role_for.toLocaleLowerCase()]) { + frappe.throw(__("Mandatory field: {0}", [frm.doc.set_role_for])); } - } + }, }); diff --git a/frappe/core/doctype/role_profile/role_profile.js b/frappe/core/doctype/role_profile/role_profile.js index e43980770a..1a5ed95287 100644 --- a/frappe/core/doctype/role_profile/role_profile.js +++ b/frappe/core/doctype/role_profile/role_profile.js @@ -1,21 +1,20 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Role Profile', { - refresh: function(frm) { +frappe.ui.form.on("Role Profile", { + refresh: function (frm) { if (has_common(frappe.user_roles, ["Administrator", "System Manager"])) { if (!frm.roles_editor) { const role_area = $(frm.fields_dict.roles_html.wrapper); frm.roles_editor = new frappe.RoleEditor(role_area, frm); } frm.roles_editor.show(); - } }, - validate: function(frm) { + validate: function (frm) { if (frm.roles_editor) { frm.roles_editor.set_roles_in_table(); } - } + }, }); diff --git a/frappe/core/doctype/scheduled_job_log/scheduled_job_log.js b/frappe/core/doctype/scheduled_job_log/scheduled_job_log.js index d43160c658..dd9691854d 100644 --- a/frappe/core/doctype/scheduled_job_log/scheduled_job_log.js +++ b/frappe/core/doctype/scheduled_job_log/scheduled_job_log.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Scheduled Job Log', { +frappe.ui.form.on("Scheduled Job Log", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/scheduled_job_log/scheduled_job_log_list.js b/frappe/core/doctype/scheduled_job_log/scheduled_job_log_list.js index 5ddccb5d44..1edd718651 100644 --- a/frappe/core/doctype/scheduled_job_log/scheduled_job_log_list.js +++ b/frappe/core/doctype/scheduled_job_log/scheduled_job_log_list.js @@ -1,7 +1,7 @@ frappe.listview_settings["Scheduled Job Log"] = { - onload: function(listview) { + onload: function (listview) { frappe.require("logtypes.bundle.js", () => { frappe.utils.logtypes.show_log_retention_message(cur_list.doctype); - }) + }); }, }; diff --git a/frappe/core/doctype/scheduled_job_type/scheduled_job_type.js b/frappe/core/doctype/scheduled_job_type/scheduled_job_type.js index 55907b17fc..238754277b 100644 --- a/frappe/core/doctype/scheduled_job_type/scheduled_job_type.js +++ b/frappe/core/doctype/scheduled_job_type/scheduled_job_type.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Scheduled Job Type', { +frappe.ui.form.on("Scheduled Job Type", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/server_script/server_script.js b/frappe/core/doctype/server_script/server_script.js index ca34af11ab..ca5b8d721b 100644 --- a/frappe/core/doctype/server_script/server_script.js +++ b/frappe/core/doctype/server_script/server_script.js @@ -1,31 +1,30 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Server Script', { - setup: function(frm) { - frm.trigger('setup_help'); +frappe.ui.form.on("Server Script", { + setup: function (frm) { + frm.trigger("setup_help"); }, - refresh: function(frm) { - if (frm.doc.script_type != 'Scheduler Event') { + refresh: function (frm) { + if (frm.doc.script_type != "Scheduler Event") { frm.dashboard.hide(); } if (!frm.is_new()) { - frm.add_custom_button(__('Compare Versions'), () => { + frm.add_custom_button(__("Compare Versions"), () => { new frappe.ui.DiffView("Server Script", "script", frm.doc.name); }); } - - frm.call('get_autocompletion_items') - .then(r => r.message) - .then(items => { - frm.set_df_property('script', 'autocompletions', items); + frm.call("get_autocompletion_items") + .then((r) => r.message) + .then((items) => { + frm.set_df_property("script", "autocompletions", items); }); }, setup_help(frm) { - frm.get_field('help_html').html(` + frm.get_field("help_html").html(`

    DocType Event

    Add logic for standard doctype events like Before Insert, After Submit, etc.

    @@ -77,6 +76,5 @@ where tenant_id = 2
     order by creation desc
     
    `); - } - + }, }); diff --git a/frappe/core/doctype/session_default_settings/session_default_settings.js b/frappe/core/doctype/session_default_settings/session_default_settings.js index f7cce14809..af333e29a3 100644 --- a/frappe/core/doctype/session_default_settings/session_default_settings.js +++ b/frappe/core/doctype/session_default_settings/session_default_settings.js @@ -1,15 +1,15 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt -frappe.ui.form.on('Session Default Settings', { - refresh: function(frm) { - frm.set_query('ref_doctype', 'session_defaults', function() { +frappe.ui.form.on("Session Default Settings", { + refresh: function (frm) { + frm.set_query("ref_doctype", "session_defaults", function () { return { filters: { issingle: 0, - istable: 0 - } + istable: 0, + }, }; }); - } + }, }); diff --git a/frappe/core/doctype/success_action/success_action.js b/frappe/core/doctype/success_action/success_action.js index 50ddb3b66a..993f6eabf4 100644 --- a/frappe/core/doctype/success_action/success_action.js +++ b/frappe/core/doctype/success_action/success_action.js @@ -1,28 +1,28 @@ // Copyright (c) 2018, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Success Action', { +frappe.ui.form.on("Success Action", { on_load: (frm) => { if (!frm.action_multicheck) { - frm.trigger('set_next_action_multicheck'); + frm.trigger("set_next_action_multicheck"); } }, refresh: (frm) => { if (!frm.action_multicheck) { - frm.trigger('set_next_action_multicheck'); + frm.trigger("set_next_action_multicheck"); } }, validate: (frm) => { const checked_actions = frm.action_multicheck.get_checked_options(); if (checked_actions.length < 2) { - frappe.msgprint(__('Select atleast 2 actions')); + frappe.msgprint(__("Select atleast 2 actions")); } else { return true; } }, before_save: (frm) => { const checked_actions = frm.action_multicheck.get_checked_options(); - frm.doc.next_actions = checked_actions.join('\n'); + frm.doc.next_actions = checked_actions.join("\n"); }, after_save: (frm) => { frappe.boot.success_action.push(frm.doc); @@ -30,31 +30,31 @@ frappe.ui.form.on('Success Action', { }, set_next_action_multicheck: (frm) => { const next_actions_wrapper = frm.fields_dict.next_actions_html.$wrapper; - const checked_actions = frm.doc.next_actions ? frm.doc.next_actions.split('\n') : []; - const action_multicheck_options = get_default_next_actions().map(action => { + const checked_actions = frm.doc.next_actions ? frm.doc.next_actions.split("\n") : []; + const action_multicheck_options = get_default_next_actions().map((action) => { return { label: action.label, value: action.value, - checked: checked_actions.length ? checked_actions.includes(action.value) : 1 + checked: checked_actions.length ? checked_actions.includes(action.value) : 1, }; }); frm.action_multicheck = frappe.ui.form.make_control({ parent: next_actions_wrapper, df: { - 'label': 'Next Actions', - 'fieldname': 'next_actions_multicheck', - 'fieldtype': 'MultiCheck', - 'options': action_multicheck_options, + label: "Next Actions", + fieldname: "next_actions_multicheck", + fieldtype: "MultiCheck", + options: action_multicheck_options, }, }); - } + }, }); const get_default_next_actions = () => { return [ - { label: __('New'), value: 'new' }, - { label: __('Print'), value: 'print' }, - { label: __('Email'), value: 'email' }, - { label: __('View All'), value: 'list' } + { label: __("New"), value: "new" }, + { label: __("Print"), value: "print" }, + { label: __("Email"), value: "email" }, + { label: __("View All"), value: "list" }, ]; -}; \ No newline at end of file +}; diff --git a/frappe/core/doctype/system_settings/system_settings.js b/frappe/core/doctype/system_settings/system_settings.js index 5128ae24cb..f7c43045d2 100644 --- a/frappe/core/doctype/system_settings/system_settings.js +++ b/frappe/core/doctype/system_settings/system_settings.js @@ -1,12 +1,12 @@ frappe.ui.form.on("System Settings", { - refresh: function(frm) { + refresh: function (frm) { frappe.call({ method: "frappe.core.doctype.system_settings.system_settings.load", - callback: function(data) { + callback: function (data) { frappe.all_timezones = data.message.timezones; frm.set_df_property("time_zone", "options", frappe.all_timezones); - $.each(data.message.defaults, function(key, val) { + $.each(data.message.defaults, function (key, val) { frm.set_value(key, val); frappe.sys_defaults[key] = val; }); @@ -14,30 +14,30 @@ frappe.ui.form.on("System Settings", { frappe.app.setup_moment(); delete frm.re_setup_moment; } - } + }, }); }, - enable_password_policy: function(frm) { + enable_password_policy: function (frm) { if (frm.doc.enable_password_policy == 0) { frm.set_value("minimum_password_score", ""); } else { frm.set_value("minimum_password_score", "2"); } }, - enable_two_factor_auth: function(frm) { + enable_two_factor_auth: function (frm) { if (frm.doc.enable_two_factor_auth == 0) { frm.set_value("bypass_2fa_for_retricted_ip_users", 0); frm.set_value("bypass_restrict_ip_check_if_2fa_enabled", 0); } }, - enable_prepared_report_auto_deletion: function(frm) { + enable_prepared_report_auto_deletion: function (frm) { if (frm.doc.enable_prepared_report_auto_deletion) { if (!frm.doc.prepared_report_expiry_period) { - frm.set_value('prepared_report_expiry_period', 7); + frm.set_value("prepared_report_expiry_period", 7); } } }, - on_update: function(frm) { + on_update: function (frm) { if (frappe.boot.time_zone && frappe.boot.time_zone.system !== frm.doc.time_zone) { // Clear cache after saving to refresh the values of boot. frappe.ui.toolbar.clear_cache(); diff --git a/frappe/core/doctype/transaction_log/transaction_log.js b/frappe/core/doctype/transaction_log/transaction_log.js index 569cd9bf61..8f22b859f7 100644 --- a/frappe/core/doctype/transaction_log/transaction_log.js +++ b/frappe/core/doctype/transaction_log/transaction_log.js @@ -1,6 +1,4 @@ // Copyright (c) 2018, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Transaction Log', { - -}); +frappe.ui.form.on("Transaction Log", {}); diff --git a/frappe/core/doctype/translation/translation.js b/frappe/core/doctype/translation/translation.js index 454f2564ba..a1b5b182b8 100644 --- a/frappe/core/doctype/translation/translation.js +++ b/frappe/core/doctype/translation/translation.js @@ -1,9 +1,8 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt - -frappe.ui.form.on('Translation', { - refresh: function() { +frappe.ui.form.on("Translation", { + refresh: function () { // - } + }, }); diff --git a/frappe/core/doctype/user/user.js b/frappe/core/doctype/user/user.js index 05a1102c03..24f9eb2cea 100644 --- a/frappe/core/doctype/user/user.js +++ b/frappe/core/doctype/user/user.js @@ -1,78 +1,85 @@ -frappe.ui.form.on('User', { - before_load: function(frm) { - var update_tz_select = function(user_language) { +frappe.ui.form.on("User", { + before_load: function (frm) { + var update_tz_select = function (user_language) { frm.set_df_property("time_zone", "options", [""].concat(frappe.all_timezones)); }; - if(!frappe.all_timezones) { + if (!frappe.all_timezones) { frappe.call({ method: "frappe.core.doctype.user.user.get_timezones", - callback: function(r) { + callback: function (r) { frappe.all_timezones = r.message.timezones; update_tz_select(); - } + }, }); } else { update_tz_select(); } - }, - role_profile_name: function(frm) { - if(frm.doc.role_profile_name) { + role_profile_name: function (frm) { + if (frm.doc.role_profile_name) { frappe.call({ - "method": "frappe.core.doctype.user.user.get_role_profile", + method: "frappe.core.doctype.user.user.get_role_profile", args: { - role_profile: frm.doc.role_profile_name + role_profile: frm.doc.role_profile_name, }, - callback: function(data) { + callback: function (data) { frm.set_value("roles", []); - $.each(data.message || [], function(i, v) { + $.each(data.message || [], function (i, v) { var d = frm.add_child("roles"); d.role = v.role; }); frm.roles_editor.show(); - } + }, }); } }, - module_profile: function(frm) { + module_profile: function (frm) { if (frm.doc.module_profile) { frappe.call({ - "method": "frappe.core.doctype.user.user.get_module_profile", + method: "frappe.core.doctype.user.user.get_module_profile", args: { - module_profile: frm.doc.module_profile + module_profile: frm.doc.module_profile, }, - callback: function(data) { + callback: function (data) { frm.set_value("block_modules", []); - $.each(data.message || [], function(i, v) { + $.each(data.message || [], function (i, v) { let d = frm.add_child("block_modules"); d.module = v.module; }); frm.module_editor && frm.module_editor.show(); - } + }, }); } }, - onload: function(frm) { + onload: function (frm) { frm.can_edit_roles = has_access_to_edit_user(); if (frm.is_new() && frm.roles_editor) { frm.roles_editor.reset(); } - if (frm.can_edit_roles && !frm.is_new() && in_list(['System User', 'Website User'], frm.doc.user_type)) { + if ( + frm.can_edit_roles && + !frm.is_new() && + in_list(["System User", "Website User"], frm.doc.user_type) + ) { if (!frm.roles_editor) { - const role_area = $('
    ') - .appendTo(frm.fields_dict.roles_html.wrapper); + const role_area = $('
    ').appendTo( + frm.fields_dict.roles_html.wrapper + ); - frm.roles_editor = new frappe.RoleEditor(role_area, frm, frm.doc.role_profile_name ? 1 : 0); + frm.roles_editor = new frappe.RoleEditor( + role_area, + frm, + frm.doc.role_profile_name ? 1 : 0 + ); - if (frm.doc.user_type == 'System User') { - var module_area = $('
    ') - .appendTo(frm.fields_dict.modules_html.wrapper); + if (frm.doc.user_type == "System User") { + var module_area = $("
    ").appendTo(frm.fields_dict.modules_html.wrapper); frm.module_editor = new frappe.ModuleEditor(frm, module_area); } } else { @@ -80,111 +87,140 @@ frappe.ui.form.on('User', { } } }, - refresh: function(frm) { + refresh: function (frm) { let doc = frm.doc; if (frm.is_new()) { frm.set_value("time_zone", frappe.sys_defaults.time_zone); } - if (in_list(['System User', 'Website User'], frm.doc.user_type) - && !frm.is_new() && !frm.roles_editor && frm.can_edit_roles) { + if ( + in_list(["System User", "Website User"], frm.doc.user_type) && + !frm.is_new() && + !frm.roles_editor && + frm.can_edit_roles + ) { frm.reload_doc(); return; } - if(doc.name===frappe.session.user && !doc.__unsaved - && frappe.all_timezones - && (doc.language || frappe.boot.user.language) - && doc.language !== frappe.boot.user.language) { + if ( + doc.name === frappe.session.user && + !doc.__unsaved && + frappe.all_timezones && + (doc.language || frappe.boot.user.language) && + doc.language !== frappe.boot.user.language + ) { frappe.msgprint(__("Refreshing...")); window.location.reload(); } - frm.toggle_display(['sb1', 'sb3', 'modules_access'], false); + frm.toggle_display(["sb1", "sb3", "modules_access"], false); - if(!frm.is_new()) { - if(has_access_to_edit_user()) { + if (!frm.is_new()) { + if (has_access_to_edit_user()) { + frm.add_custom_button( + __("Set User Permissions"), + function () { + frappe.route_options = { + user: doc.name, + }; + frappe.set_route("List", "User Permission"); + }, + __("Permissions") + ); - frm.add_custom_button(__("Set User Permissions"), function() { - frappe.route_options = { - "user": doc.name - }; - frappe.set_route('List', 'User Permission'); - }, __("Permissions")); + frm.add_custom_button( + __("View Permitted Documents"), + () => + frappe.set_route("query-report", "Permitted Documents For User", { + user: frm.doc.name, + }), + __("Permissions") + ); - frm.add_custom_button(__('View Permitted Documents'), - () => frappe.set_route('query-report', 'Permitted Documents For User', - {user: frm.doc.name}), __("Permissions")); - - frm.toggle_display(['sb1', 'sb3', 'modules_access'], true); + frm.toggle_display(["sb1", "sb3", "modules_access"], true); } - frm.add_custom_button(__("Reset Password"), function() { - frappe.call({ - method: "frappe.core.doctype.user.user.reset_password", - args: { - "user": frm.doc.name - } - }); - }, __("Password")); + frm.add_custom_button( + __("Reset Password"), + function () { + frappe.call({ + method: "frappe.core.doctype.user.user.reset_password", + args: { + user: frm.doc.name, + }, + }); + }, + __("Password") + ); if (frappe.user.has_role("System Manager")) { frappe.db.get_single_value("LDAP Settings", "enabled").then((value) => { if (value === 1 && frm.doc.name != "Administrator") { - frm.add_custom_button(__("Reset LDAP Password"), function() { - const d = new frappe.ui.Dialog({ - title: __("Reset LDAP Password"), - fields: [ - { - label: __("New Password"), - fieldtype: "Password", - fieldname: "new_password", - reqd: 1 + frm.add_custom_button( + __("Reset LDAP Password"), + function () { + const d = new frappe.ui.Dialog({ + title: __("Reset LDAP Password"), + fields: [ + { + label: __("New Password"), + fieldtype: "Password", + fieldname: "new_password", + reqd: 1, + }, + { + label: __("Confirm New Password"), + fieldtype: "Password", + fieldname: "confirm_password", + reqd: 1, + }, + { + label: __("Logout All Sessions"), + fieldtype: "Check", + fieldname: "logout_sessions", + }, + ], + primary_action: (values) => { + d.hide(); + if (values.new_password !== values.confirm_password) { + frappe.throw(__("Passwords do not match!")); + } + frappe.call( + "frappe.integrations.doctype.ldap_settings.ldap_settings.reset_password", + { + user: frm.doc.email, + password: values.new_password, + logout: values.logout_sessions, + } + ); }, - { - label: __("Confirm New Password"), - fieldtype: "Password", - fieldname: "confirm_password", - reqd: 1 - }, - { - label: __("Logout All Sessions"), - fieldtype: "Check", - fieldname: "logout_sessions" - } - ], - primary_action: (values) => { - d.hide(); - if (values.new_password !== values.confirm_password) { - frappe.throw(__("Passwords do not match!")); - } - frappe.call( - "frappe.integrations.doctype.ldap_settings.ldap_settings.reset_password", { - user: frm.doc.email, - password: values.new_password, - logout: values.logout_sessions - }); - } - }); - d.show(); - }, __("Password")); + }); + d.show(); + }, + __("Password") + ); } }); } if (frappe.session.user == doc.name || frappe.user.has_role("System Manager")) { - frm.add_custom_button(__("Reset OTP Secret"), function() { - frappe.call({ - method: "frappe.twofactor.reset_otp_secret", - args: { - "user": frm.doc.name - } - }); - }, __("Password")); + frm.add_custom_button( + __("Reset OTP Secret"), + function () { + frappe.call({ + method: "frappe.twofactor.reset_otp_secret", + args: { + user: frm.doc.name, + }, + }); + }, + __("Password") + ); } - frm.trigger('enabled'); + frm.trigger("enabled"); if (frm.roles_editor && frm.can_edit_roles) { frm.roles_editor.disable = frm.doc.role_profile_name ? 1 : 0; @@ -193,10 +229,12 @@ frappe.ui.form.on('User', { frm.module_editor && frm.module_editor.show(); - if(frappe.session.user==doc.name) { + if (frappe.session.user == doc.name) { // update display settings - if(doc.user_image) { - frappe.boot.user_info[frappe.session.user].image = frappe.utils.get_file_link(doc.user_image); + if (doc.user_image) { + frappe.boot.user_info[frappe.session.user].image = frappe.utils.get_file_link( + doc.user_image + ); } } } @@ -208,51 +246,50 @@ frappe.ui.form.on('User', { } } if (!found) { - frm.add_custom_button(__("Create User Email"), function() { + frm.add_custom_button(__("Create User Email"), function () { frm.events.create_user_email(frm); }); } } - if (frappe.route_flags.unsaved===1){ + if (frappe.route_flags.unsaved === 1) { delete frappe.route_flags.unsaved; - for ( var i=0;i { - child_row.used_oauth = value.auth_method === "OAuth"; - frm.refresh_field("user_emails", cdn, "used_oauth"); - }); - } + frappe.model.get_value( + "Email Account", + child_row.email_account, + "auth_method", + (value) => { + child_row.used_oauth = value.auth_method === "OAuth"; + frm.refresh_field("user_emails", cdn, "used_oauth"); + } + ); + }, }); - function has_access_to_edit_user() { return has_common(frappe.user_roles, get_roles_for_editing_user()); } function get_roles_for_editing_user() { - return frappe.get_meta('User').permissions - .filter(perm => perm.permlevel >= 1 && perm.write) - .map(perm => perm.role) || ['System Manager']; + return ( + frappe + .get_meta("User") + .permissions.filter((perm) => perm.permlevel >= 1 && perm.write) + .map((perm) => perm.role) || ["System Manager"] + ); } diff --git a/frappe/core/doctype/user/user_list.js b/frappe/core/doctype/user/user_list.js index 5632edf0cc..334ed0b370 100644 --- a/frappe/core/doctype/user/user_list.js +++ b/frappe/core/doctype/user/user_list.js @@ -1,19 +1,19 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt -frappe.listview_settings['User'] = { +frappe.listview_settings["User"] = { add_fields: ["enabled", "user_type", "user_image"], - filters: [["enabled","=",1]], - prepare_data: function(data) { + filters: [["enabled", "=", 1]], + prepare_data: function (data) { data["user_for_avatar"] = data["name"]; }, - get_indicator: function(doc) { - if(doc.enabled) { + get_indicator: function (doc) { + if (doc.enabled) { return [__("Active"), "green", "enabled,=,1"]; } else { return [__("Disabled"), "grey", "enabled,=,0"]; } - } + }, }; frappe.help.youtube_id["User"] = "8Slw1hsTmUI"; diff --git a/frappe/core/doctype/user_group/user_group.js b/frappe/core/doctype/user_group/user_group.js index 2aa9b68658..cab1f5dff1 100644 --- a/frappe/core/doctype/user_group/user_group.js +++ b/frappe/core/doctype/user_group/user_group.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('User Group', { +frappe.ui.form.on("User Group", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/user_group_member/user_group_member.js b/frappe/core/doctype/user_group_member/user_group_member.js index 0b2dbe0d46..4c4011c8b4 100644 --- a/frappe/core/doctype/user_group_member/user_group_member.js +++ b/frappe/core/doctype/user_group_member/user_group_member.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('User Group Member', { +frappe.ui.form.on("User Group Member", { // refresh: function(frm) { - // } }); diff --git a/frappe/core/doctype/user_permission/user_permission.js b/frappe/core/doctype/user_permission/user_permission.js index f6989db5d8..39ee4348b9 100644 --- a/frappe/core/doctype/user_permission/user_permission.js +++ b/frappe/core/doctype/user_permission/user_permission.js @@ -1,59 +1,58 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('User Permission', { - setup: frm => { +frappe.ui.form.on("User Permission", { + setup: (frm) => { frm.set_query("allow", () => { return { - "filters": { + filters: { issingle: 0, - istable: 0 - } + istable: 0, + }, }; }); - frm.set_query('applicable_for', () => { + frm.set_query("applicable_for", () => { return { - 'query': 'frappe.core.doctype.user_permission.user_permission.get_applicable_for_doctype_list', - 'doctype': frm.doc.allow + query: "frappe.core.doctype.user_permission.user_permission.get_applicable_for_doctype_list", + doctype: frm.doc.allow, }; }); - }, - refresh: frm => { - frm.add_custom_button(__('View Permitted Documents'), - () => frappe.set_route('query-report', 'Permitted Documents For User', - { user: frm.doc.user })); - frm.trigger('set_applicable_for_constraint'); - frm.trigger('toggle_hide_descendants'); + refresh: (frm) => { + frm.add_custom_button(__("View Permitted Documents"), () => + frappe.set_route("query-report", "Permitted Documents For User", { + user: frm.doc.user, + }) + ); + frm.trigger("set_applicable_for_constraint"); + frm.trigger("toggle_hide_descendants"); }, - allow: frm => { + allow: (frm) => { if (frm.doc.allow) { if (frm.doc.for_value) { - frm.set_value('for_value', null); + frm.set_value("for_value", null); } - frm.trigger('toggle_hide_descendants'); + frm.trigger("toggle_hide_descendants"); } }, - apply_to_all_doctypes: frm => { - frm.trigger('set_applicable_for_constraint'); + apply_to_all_doctypes: (frm) => { + frm.trigger("set_applicable_for_constraint"); }, - set_applicable_for_constraint: frm => { - frm.toggle_reqd('applicable_for', !frm.doc.apply_to_all_doctypes); + set_applicable_for_constraint: (frm) => { + frm.toggle_reqd("applicable_for", !frm.doc.apply_to_all_doctypes); if (frm.doc.apply_to_all_doctypes && frm.doc.applicable_for) { - frm.set_value('applicable_for', null, null, true); + frm.set_value("applicable_for", null, null, true); } }, - toggle_hide_descendants: frm => { + toggle_hide_descendants: (frm) => { let show = frappe.boot.nested_set_doctypes.includes(frm.doc.allow); - frm.toggle_display('hide_descendants', show); - } - - + frm.toggle_display("hide_descendants", show); + }, }); diff --git a/frappe/core/doctype/user_permission/user_permission_list.js b/frappe/core/doctype/user_permission/user_permission_list.js index 0ce66fa8e3..ce5e624403 100644 --- a/frappe/core/doctype/user_permission/user_permission_list.js +++ b/frappe/core/doctype/user_permission/user_permission_list.js @@ -1,18 +1,17 @@ -frappe.listview_settings['User Permission'] = { - - onload: function(list_view) { +frappe.listview_settings["User Permission"] = { + onload: function (list_view) { var me = this; - list_view.page.add_inner_button( __("Add / Update"), function() { - let dialog =new frappe.ui.Dialog({ - title : __('Add User Permissions'), + list_view.page.add_inner_button(__("Add / Update"), function () { + let dialog = new frappe.ui.Dialog({ + title: __("Add User Permissions"), fields: [ { - fieldname: 'user', - label: __('For User'), - fieldtype: 'Link', - options: 'User', + fieldname: "user", + label: __("For User"), + fieldtype: "Link", + options: "User", reqd: 1, - onchange: function() { + onchange: function () { dialog.fields_dict.doctype.set_input(undefined); dialog.fields_dict.docname.set_input(undefined); dialog.set_df_property("docname", "hidden", 1); @@ -20,77 +19,87 @@ frappe.listview_settings['User Permission'] = { dialog.set_df_property("apply_to_all_doctypes", "hidden", 1); dialog.set_df_property("applicable_doctypes", "hidden", 1); dialog.set_df_property("hide_descendants", "hidden", 1); - } + }, }, { - fieldname: 'doctype', - label: __('Document Type'), - fieldtype: 'Link', - options: 'DocType', + fieldname: "doctype", + label: __("Document Type"), + fieldtype: "Link", + options: "DocType", reqd: 1, - onchange: function() { + onchange: function () { me.on_doctype_change(dialog); - } + }, }, { - fieldname: 'docname', - label: __('Document Name'), - fieldtype: 'Dynamic Link', - options: 'doctype', + fieldname: "docname", + label: __("Document Name"), + fieldtype: "Dynamic Link", + options: "doctype", hidden: 1, - onchange: function() { + onchange: function () { let field = dialog.fields_dict["docname"]; - if(field.value != field.last_value) { - if(dialog.fields_dict.doctype.value && dialog.fields_dict.docname.value && dialog.fields_dict.user.value){ - me.get_applicable_doctype(dialog).then(applicable => { - me.get_multi_select_options(dialog, applicable).then(options => { - me.applicable_options = options; - me.on_docname_change(dialog, options, applicable); - if(options.length > 5){ - dialog.fields_dict.applicable_doctypes.setup_select_all(); + if (field.value != field.last_value) { + if ( + dialog.fields_dict.doctype.value && + dialog.fields_dict.docname.value && + dialog.fields_dict.user.value + ) { + me.get_applicable_doctype(dialog).then((applicable) => { + me.get_multi_select_options(dialog, applicable).then( + (options) => { + me.applicable_options = options; + me.on_docname_change(dialog, options, applicable); + if (options.length > 5) { + dialog.fields_dict.applicable_doctypes.setup_select_all(); + } } - }); + ); }); } } - } + }, }, { fieldtype: "Section Break", - hide_border: 1 + hide_border: 1, }, { - fieldname: 'is_default', - label: __('Is Default'), - fieldtype: 'Check', - hidden: 1 - }, - { - fieldname: 'apply_to_all_doctypes', - label: __('Apply to all Documents Types'), - fieldtype: 'Check', + fieldname: "is_default", + label: __("Is Default"), + fieldtype: "Check", hidden: 1, - onchange: function() { - if(dialog.fields_dict.doctype.value && dialog.fields_dict.docname.value && dialog.fields_dict.user.value){ + }, + { + fieldname: "apply_to_all_doctypes", + label: __("Apply to all Documents Types"), + fieldtype: "Check", + hidden: 1, + onchange: function () { + if ( + dialog.fields_dict.doctype.value && + dialog.fields_dict.docname.value && + dialog.fields_dict.user.value + ) { me.on_apply_to_all_doctypes_change(dialog, me.applicable_options); - if(me.applicable_options.length > 5){ + if (me.applicable_options.length > 5) { dialog.fields_dict.applicable_doctypes.setup_select_all(); } } - } + }, }, { - fieldtype: "Column Break" + fieldtype: "Column Break", }, { - fieldname: 'hide_descendants', - label: __('Hide Descendants'), - fieldtype: 'Check', - hidden: 1 + fieldname: "hide_descendants", + label: __("Hide Descendants"), + fieldtype: "Check", + hidden: 1, }, { fieldtype: "Section Break", - hide_border: 1 + hide_border: 1, }, { label: __("Applicable Document Types"), @@ -98,7 +107,7 @@ frappe.listview_settings['User Permission'] = { fieldtype: "MultiCheck", options: [], columns: 2, - hidden: 1 + hidden: 1, }, ], primary_action: (data) => { @@ -107,126 +116,137 @@ frappe.listview_settings['User Permission'] = { async: false, method: "frappe.core.doctype.user_permission.user_permission.add_user_permissions", args: { - data : data + data: data, }, - callback: function(r) { - if(r.message === 1) { - frappe.show_alert({message:__("User Permissions created sucessfully"), indicator:'blue'}); + callback: function (r) { + if (r.message === 1) { + frappe.show_alert({ + message: __("User Permissions created sucessfully"), + indicator: "blue", + }); } else { - frappe.show_alert({message:__("Nothing to update"), indicator:'red'}); - + frappe.show_alert({ + message: __("Nothing to update"), + indicator: "red", + }); } - } + }, }); dialog.hide(); list_view.refresh(); }, - primary_action_label: __('Submit') + primary_action_label: __("Submit"), }); dialog.show(); }); - list_view.page.add_inner_button( __("Bulk Delete"), function() { + list_view.page.add_inner_button(__("Bulk Delete"), function () { const dialog = new frappe.ui.Dialog({ - title: __('Clear User Permissions'), + title: __("Clear User Permissions"), fields: [ { - fieldname: 'user', - label: __('For User'), - fieldtype: 'Link', - options: 'User', - reqd: 1 + fieldname: "user", + label: __("For User"), + fieldtype: "Link", + options: "User", + reqd: 1, }, { - fieldname: 'for_doctype', - label: __('For Document Type'), - fieldtype: 'Link', - options: 'DocType', - reqd: 1 + fieldname: "for_doctype", + label: __("For Document Type"), + fieldtype: "Link", + options: "DocType", + reqd: 1, }, ], primary_action: (data) => { // mandatory not filled if (!data) return; - frappe.confirm(__('Are you sure?'), () => { + frappe.confirm(__("Are you sure?"), () => { frappe - .xcall('frappe.core.doctype.user_permission.user_permission.clear_user_permissions', data) - .then(data => { + .xcall( + "frappe.core.doctype.user_permission.user_permission.clear_user_permissions", + data + ) + .then((data) => { dialog.hide(); - let message = ''; + let message = ""; if (data === 0) { - message = __('No records deleted'); - } else if(data === 1) { - message = __('{0} record deleted', [data]); + message = __("No records deleted"); + } else if (data === 1) { + message = __("{0} record deleted", [data]); } else { - message = __('{0} records deleted', [data]); + message = __("{0} records deleted", [data]); } frappe.show_alert({ message, - indicator: 'info' + indicator: "info", }); list_view.refresh(); }); }); - }, - primary_action_label: __('Delete') + primary_action_label: __("Delete"), }); dialog.show(); }); }, - validate: function(dialog, data) { - if(dialog.fields_dict.applicable_doctypes.get_unchecked_options().length == 0) { + validate: function (dialog, data) { + if (dialog.fields_dict.applicable_doctypes.get_unchecked_options().length == 0) { data.apply_to_all_doctypes = 1; data.applicable_doctypes = []; return data; } - if(data.apply_to_all_doctypes == 0 && !("applicable_doctypes" in data)) { + if (data.apply_to_all_doctypes == 0 && !("applicable_doctypes" in data)) { frappe.throw(__("Please select applicable Doctypes")); } return data; }, - get_applicable_doctype: function(dialog) { - return new Promise(resolve => { - frappe.call({ - method: 'frappe.core.doctype.user_permission.user_permission.check_applicable_doc_perm', - async: false, - args:{ - user: dialog.fields_dict.user.value, - doctype: dialog.fields_dict.doctype.value, - docname: dialog.fields_dict.docname.value - } - }).then(r => { - resolve(r.message); - }); + get_applicable_doctype: function (dialog) { + return new Promise((resolve) => { + frappe + .call({ + method: "frappe.core.doctype.user_permission.user_permission.check_applicable_doc_perm", + async: false, + args: { + user: dialog.fields_dict.user.value, + doctype: dialog.fields_dict.doctype.value, + docname: dialog.fields_dict.docname.value, + }, + }) + .then((r) => { + resolve(r.message); + }); }); }, - get_multi_select_options: function(dialog, applicable){ - return new Promise(resolve => { - frappe.call({ - method: 'frappe.desk.form.linked_with.get_linked_doctypes', - async: false, - args:{ - user: dialog.fields_dict.user.value, - doctype: dialog.fields_dict.doctype.value, - docname: dialog.fields_dict.docname.value - } - }).then(r => { - var options = []; - for(var d in r.message){ - var checked = ($.inArray(d, applicable) != -1) ? 1 : 0; - options.push({ "label":d, "value": d , "checked": checked}); - } - resolve(options); - }); + get_multi_select_options: function (dialog, applicable) { + return new Promise((resolve) => { + frappe + .call({ + method: "frappe.desk.form.linked_with.get_linked_doctypes", + async: false, + args: { + user: dialog.fields_dict.user.value, + doctype: dialog.fields_dict.doctype.value, + docname: dialog.fields_dict.docname.value, + }, + }) + .then((r) => { + var options = []; + for (var d in r.message) { + var checked = $.inArray(d, applicable) != -1 ? 1 : 0; + options.push({ label: d, value: d, checked: checked }); + } + resolve(options); + }); }); }, - on_doctype_change: function(dialog) { + on_doctype_change: function (dialog) { dialog.set_df_property("docname", "hidden", 0); dialog.set_df_property("docname", "reqd", 1); dialog.set_df_property("is_default", "hidden", 0); @@ -237,12 +257,15 @@ frappe.listview_settings['User Permission'] = { dialog.refresh(); }, - on_docname_change: function(dialog, options, applicable) { - if(applicable.length != 0 ) { + on_docname_change: function (dialog, options, applicable) { + if (applicable.length != 0) { dialog.set_primary_action("Update"); dialog.set_title("Update User Permissions"); dialog.set_df_property("applicable_doctypes", "options", options); - if(dialog.fields_dict.applicable_doctypes.get_checked_options().length == options.length) { + if ( + dialog.fields_dict.applicable_doctypes.get_checked_options().length == + options.length + ) { dialog.set_df_property("applicable_doctypes", "hidden", 1); } else { dialog.set_df_property("applicable_doctypes", "hidden", 0); @@ -257,8 +280,8 @@ frappe.listview_settings['User Permission'] = { dialog.refresh(); }, - on_apply_to_all_doctypes_change: function(dialog, options) { - if(dialog.fields_dict.apply_to_all_doctypes.get_value() == 0) { + on_apply_to_all_doctypes_change: function (dialog, options) { + if (dialog.fields_dict.apply_to_all_doctypes.get_value() == 0) { dialog.set_df_property("applicable_doctypes", "hidden", 0); dialog.set_df_property("applicable_doctypes", "options", options); } else { @@ -266,5 +289,5 @@ frappe.listview_settings['User Permission'] = { dialog.set_df_property("applicable_doctypes", "hidden", 1); } dialog.refresh_sections(); - } + }, }; diff --git a/frappe/core/doctype/user_type/user_type.js b/frappe/core/doctype/user_type/user_type.js index 6b53248fd4..5cf0dbb25f 100644 --- a/frappe/core/doctype/user_type/user_type.js +++ b/frappe/core/doctype/user_type/user_type.js @@ -1,72 +1,71 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('User Type', { - refresh: function(frm) { - if (frm.is_new() && !frappe.boot.developer_mode) - frm.set_value('is_standard', 1); +frappe.ui.form.on("User Type", { + refresh: function (frm) { + if (frm.is_new() && !frappe.boot.developer_mode) frm.set_value("is_standard", 1); - frm.set_query('document_type', 'user_doctypes', function() { + frm.set_query("document_type", "user_doctypes", function () { return { filters: { - istable: 0 - } + istable: 0, + }, }; }); - frm.set_query('document_type', 'select_doctypes', function() { + frm.set_query("document_type", "select_doctypes", function () { return { filters: { - istable: 0 - } + istable: 0, + }, }; }); - frm.set_query('document_type', 'custom_select_doctypes', function() { + frm.set_query("document_type", "custom_select_doctypes", function () { return { filters: { - istable: 0 - } + istable: 0, + }, }; }); - frm.set_query('role', function() { + frm.set_query("role", function () { return { filters: { is_custom: 1, disabled: 0, - desk_access: 1 - } + desk_access: 1, + }, }; }); - frm.set_query('apply_user_permission_on', function() { + frm.set_query("apply_user_permission_on", function () { return { - query: "frappe.core.doctype.user_type.user_type.get_user_linked_doctypes" + query: "frappe.core.doctype.user_type.user_type.get_user_linked_doctypes", }; }); }, - onload: function(frm) { - frm.trigger('get_user_id_fields'); + onload: function (frm) { + frm.trigger("get_user_id_fields"); }, - apply_user_permission_on: function(frm) { - frm.set_value('user_id_field', ''); - frm.trigger('get_user_id_fields'); + apply_user_permission_on: function (frm) { + frm.set_value("user_id_field", ""); + frm.trigger("get_user_id_fields"); }, - get_user_id_fields: function(frm) { + get_user_id_fields: function (frm) { if (frm.doc.apply_user_permission_on) { frappe.call({ - method: 'frappe.core.doctype.user_type.user_type.get_user_id', + method: "frappe.core.doctype.user_type.user_type.get_user_id", args: { - parent: frm.doc.apply_user_permission_on + parent: frm.doc.apply_user_permission_on, + }, + callback: function (r) { + set_field_options("user_id_field", [""].concat(r.message)); }, - callback: function(r) { - set_field_options('user_id_field', [""].concat(r.message)); - } }); } - } + }, }); diff --git a/frappe/core/doctype/user_type/user_type_list.js b/frappe/core/doctype/user_type/user_type_list.js index 9a9ef417ac..856fe8985e 100644 --- a/frappe/core/doctype/user_type/user_type_list.js +++ b/frappe/core/doctype/user_type/user_type_list.js @@ -1,4 +1,4 @@ -frappe.listview_settings['User Type'] = { +frappe.listview_settings["User Type"] = { add_fields: ["is_standard"], get_indicator: function (doc) { if (doc.is_standard) { @@ -6,5 +6,5 @@ frappe.listview_settings['User Type'] = { } else { return [__("Custom"), "blue", "is_standard,=,0"]; } - } + }, }; diff --git a/frappe/core/doctype/version/version.js b/frappe/core/doctype/version/version.js index d39d2eac03..1e26e5f748 100644 --- a/frappe/core/doctype/version/version.js +++ b/frappe/core/doctype/version/version.js @@ -1,9 +1,12 @@ -frappe.ui.form.on("Version", "refresh", function(frm) { - $(frappe.render_template('version_view', {doc:frm.doc, data:JSON.parse(frm.doc.data)})) - .appendTo(frm.fields_dict.table_html.$wrapper.empty()); +frappe.ui.form.on("Version", "refresh", function (frm) { + $( + frappe.render_template("version_view", { doc: frm.doc, data: JSON.parse(frm.doc.data) }) + ).appendTo(frm.fields_dict.table_html.$wrapper.empty()); - frm.add_custom_button(__('Show all Versions'), function() { - frappe.set_route('List', 'Version', - {ref_doctype: frm.doc.ref_doctype, docname: frm.doc.docname}); + frm.add_custom_button(__("Show all Versions"), function () { + frappe.set_route("List", "Version", { + ref_doctype: frm.doc.ref_doctype, + docname: frm.doc.docname, + }); }); }); diff --git a/frappe/core/doctype/view_log/view_log.js b/frappe/core/doctype/view_log/view_log.js index a8c95b01e8..06d23802be 100644 --- a/frappe/core/doctype/view_log/view_log.js +++ b/frappe/core/doctype/view_log/view_log.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('View Log', { - refresh: function(frm) { - - } +frappe.ui.form.on("View Log", { + refresh: function (frm) {}, }); diff --git a/frappe/core/page/background_jobs/background_jobs.js b/frappe/core/page/background_jobs/background_jobs.js index 7334bfd5dd..94c7bbf3bc 100644 --- a/frappe/core/page/background_jobs/background_jobs.js +++ b/frappe/core/page/background_jobs/background_jobs.js @@ -1,4 +1,4 @@ -frappe.pages["background_jobs"].on_page_load = wrapper => { +frappe.pages["background_jobs"].on_page_load = (wrapper) => { const background_job = new BackgroundJobs(wrapper); $(wrapper).bind("show", () => { @@ -13,20 +13,15 @@ class BackgroundJobs { this.page = frappe.ui.make_app_page({ parent: wrapper, title: __("Background Jobs"), - single_column: true + single_column: true, }); this.page.add_inner_button(__("Remove Failed Jobs"), () => { - frappe.confirm( - __("Are you sure you want to remove all failed jobs?"), - () => { - frappe - .call( - "frappe.core.page.background_jobs.background_jobs.remove_failed_jobs" - ) - .then(() => this.refresh_jobs()); - } - ); + frappe.confirm(__("Are you sure you want to remove all failed jobs?"), () => { + frappe + .call("frappe.core.page.background_jobs.background_jobs.remove_failed_jobs") + .then(() => this.refresh_jobs()); + }); }); this.page.main.addClass("frappe-card"); @@ -34,10 +29,7 @@ class BackgroundJobs { this.$content = $(this.page.body).find(".table-area"); this.make_filters(); - this.refresh_jobs = frappe.utils.throttle( - this.refresh_jobs.bind(this), - 1000 - ); + this.refresh_jobs = frappe.utils.throttle(this.refresh_jobs.bind(this), 1000); } make_filters() { @@ -50,7 +42,7 @@ class BackgroundJobs { change: () => { this.queue_timeout.toggle(this.view.get_value() === "Jobs"); this.job_status.toggle(this.view.get_value() === "Jobs"); - } + }, }); this.queue_timeout = this.page.add_field({ label: __("Queue"), @@ -60,9 +52,9 @@ class BackgroundJobs { { label: "All Queues", value: "all" }, { label: "Default", value: "default" }, { label: "Short", value: "short" }, - { label: "Long", value: "long" } + { label: "Long", value: "long" }, ], - default: "all" + default: "all", }); this.job_status = this.page.add_field({ label: __("Job Status"), @@ -74,9 +66,9 @@ class BackgroundJobs { { label: "Deferred", value: "deferred" }, { label: "Started", value: "started" }, { label: "Finished", value: "finished" }, - { label: "Failed", value: "failed" } + { label: "Failed", value: "failed" }, ], - default: "all" + default: "all", }); this.auto_refresh = this.page.add_field({ label: __("Auto Refresh"), @@ -87,7 +79,7 @@ class BackgroundJobs { if (this.auto_refresh.get_value()) { this.refresh_jobs(); } - } + }, }); } @@ -98,16 +90,15 @@ class BackgroundJobs { update_scheduler_status() { frappe.call({ - method: - "frappe.core.page.background_jobs.background_jobs.get_scheduler_status", - callback: r => { + method: "frappe.core.page.background_jobs.background_jobs.get_scheduler_status", + callback: (r) => { let { status } = r.message; if (status === "active") { this.page.set_indicator(__("Scheduler: Active"), "green"); } else { this.page.set_indicator(__("Scheduler: Inactive"), "red"); } - } + }, }); } @@ -125,25 +116,21 @@ class BackgroundJobs { frappe.call({ method: "frappe.core.page.background_jobs.background_jobs.get_info", args, - callback: res => { + callback: (res) => { this.page.add_inner_message(""); - let template = - view === "Jobs" ? "background_jobs" : "background_workers"; + let template = view === "Jobs" ? "background_jobs" : "background_workers"; this.$content.html( frappe.render_template(template, { - jobs: res.message || [] + jobs: res.message || [], }) ); let auto_refresh = this.auto_refresh.get_value(); - if ( - frappe.get_route()[0] === "background_jobs" && - auto_refresh - ) { + if (frappe.get_route()[0] === "background_jobs" && auto_refresh) { setTimeout(() => this.refresh_jobs(), 2000); } - } + }, }); } } diff --git a/frappe/core/page/dashboard_view/dashboard_view.js b/frappe/core/page/dashboard_view/dashboard_view.js index bf9fb2a286..8f2c56910c 100644 --- a/frappe/core/page/dashboard_view/dashboard_view.js +++ b/frappe/core/page/dashboard_view/dashboard_view.js @@ -1,19 +1,18 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt -frappe.provide('frappe.dashboards'); -frappe.provide('frappe.dashboards.chart_sources'); +frappe.provide("frappe.dashboards"); +frappe.provide("frappe.dashboards.chart_sources"); - -frappe.pages['dashboard-view'].on_page_load = function(wrapper) { +frappe.pages["dashboard-view"].on_page_load = function (wrapper) { frappe.ui.make_app_page({ parent: wrapper, title: __("Dashboard"), - single_column: true + single_column: true, }); frappe.dashboard = new Dashboard(wrapper); - $(wrapper).bind('show', function() { + $(wrapper).bind("show", function () { frappe.dashboard.show(); }); }; @@ -37,20 +36,20 @@ class Dashboard { } else { // last opened if (frappe.last_dashboard) { - frappe.set_re_route('dashboard-view', frappe.last_dashboard); + frappe.set_re_route("dashboard-view", frappe.last_dashboard); } else { // default dashboard - frappe.db.get_list('Dashboard', {filters: {is_default: 1}}).then(data => { + frappe.db.get_list("Dashboard", { filters: { is_default: 1 } }).then((data) => { if (data && data.length) { - frappe.set_re_route('dashboard-view', data[0].name); + frappe.set_re_route("dashboard-view", data[0].name); } else { // no default, get the latest one - frappe.db.get_list('Dashboard', {limit: 1}).then(data => { + frappe.db.get_list("Dashboard", { limit: 1 }).then((data) => { if (data && data.length) { - frappe.set_re_route('dashboard-view', data[0].name); + frappe.set_re_route("dashboard-view", data[0].name); } else { // create a new dashboard! - frappe.new_doc('Dashboard'); + frappe.new_doc("Dashboard"); } }); } @@ -63,9 +62,9 @@ class Dashboard { if (this.dashboard_name !== current_dashboard_name) { this.dashboard_name = current_dashboard_name; let title = this.dashboard_name; - if (!this.dashboard_name.toLowerCase().includes(__('dashboard'))) { + if (!this.dashboard_name.toLowerCase().includes(__("dashboard"))) { // ensure dashboard title has "dashboard" - title = __('{0} Dashboard', [title]); + title = __("{0} Dashboard", [title]); } this.page.set_title(title); this.set_dropdown(); @@ -81,31 +80,30 @@ class Dashboard { } refresh() { - frappe.run_serially([ - () => this.render_cards(), - () => this.render_charts() - ]); + frappe.run_serially([() => this.render_cards(), () => this.render_charts()]); } render_charts() { return this.get_permitted_items( - 'frappe.desk.doctype.dashboard.dashboard.get_permitted_charts' - ).then(charts => { + "frappe.desk.doctype.dashboard.dashboard.get_permitted_charts" + ).then((charts) => { if (!charts.length) { - frappe.msgprint(__('No Permitted Charts on this Dashboard'), __('No Permitted Charts')) + frappe.msgprint( + __("No Permitted Charts on this Dashboard"), + __("No Permitted Charts") + ); } frappe.dashboard_utils.get_dashboard_settings().then((settings) => { - let chart_config = settings.chart_config? JSON.parse(settings.chart_config): {}; - this.charts = - charts.map(chart => { - return { - chart_name: chart.chart, - label: chart.chart, - chart_settings: chart_config[chart.chart] || {}, - ...chart - } - }); + let chart_config = settings.chart_config ? JSON.parse(settings.chart_config) : {}; + this.charts = charts.map((chart) => { + return { + chart_name: chart.chart, + label: chart.chart, + chart_settings: chart_config[chart.chart] || {}, + ...chart, + }; + }); this.chart_group = new frappe.widget.WidgetGroup({ title: null, @@ -121,24 +119,23 @@ class Dashboard { }, widgets: this.charts, }); - }) + }); }); } render_cards() { return this.get_permitted_items( - 'frappe.desk.doctype.dashboard.dashboard.get_permitted_cards' - ).then(cards => { + "frappe.desk.doctype.dashboard.dashboard.get_permitted_cards" + ).then((cards) => { if (!cards.length) { return; } - this.number_cards = - cards.map(card => { - return { - name: card.card, - }; - }); + this.number_cards = cards.map((card) => { + return { + name: card.card, + }; + }); this.number_card_group = new frappe.widget.WidgetGroup({ container: this.container, @@ -157,41 +154,43 @@ class Dashboard { } get_permitted_items(method) { - return frappe.xcall( - method, - { - dashboard_name: this.dashboard_name - } - ).then(items => { - return items; - }); + return frappe + .xcall(method, { + dashboard_name: this.dashboard_name, + }) + .then((items) => { + return items; + }); } set_dropdown() { this.page.clear_menu(); - this.page.add_menu_item(__('Edit'), () => { - frappe.set_route('Form', 'Dashboard', frappe.dashboard.dashboard_name); + this.page.add_menu_item(__("Edit"), () => { + frappe.set_route("Form", "Dashboard", frappe.dashboard.dashboard_name); }); - this.page.add_menu_item(__('New'), () => { - frappe.new_doc('Dashboard'); + this.page.add_menu_item(__("New"), () => { + frappe.new_doc("Dashboard"); }); - this.page.add_menu_item(__('Refresh All'), () => { - this.chart_group && - this.chart_group.widgets_list.forEach(chart => chart.refresh()); + this.page.add_menu_item(__("Refresh All"), () => { + this.chart_group && this.chart_group.widgets_list.forEach((chart) => chart.refresh()); this.number_card_group && - this.number_card_group.widgets_list.forEach(card => card.render_card()); + this.number_card_group.widgets_list.forEach((card) => card.render_card()); }); - frappe.db.get_list('Dashboard').then(dashboards => { - dashboards.map(dashboard => { + frappe.db.get_list("Dashboard").then((dashboards) => { + dashboards.map((dashboard) => { let name = dashboard.name; if (name != this.dashboard_name) { - this.page.add_menu_item(name, () => frappe.set_route("dashboard-view", name), 1); + this.page.add_menu_item( + name, + () => frappe.set_route("dashboard-view", name), + 1 + ); } }); }); } -} \ No newline at end of file +} diff --git a/frappe/core/page/permission_manager/permission_manager.js b/frappe/core/page/permission_manager/permission_manager.js index 8a06a9aac5..f29df0d3e5 100644 --- a/frappe/core/page/permission_manager/permission_manager.js +++ b/frappe/core/page/permission_manager/permission_manager.js @@ -1,20 +1,21 @@ -frappe.pages['permission-manager'].on_page_load = (wrapper) => { +frappe.pages["permission-manager"].on_page_load = (wrapper) => { let page = frappe.ui.make_app_page({ parent: wrapper, - title: __('Role Permissions Manager'), + title: __("Role Permissions Manager"), card_layout: true, - single_column: true + single_column: true, }); frappe.breadcrumbs.add("Setup"); - $("
    ").appendTo(page.main); + $("
    ").appendTo( + page.main + ); $(frappe.render_template("permission_manager_help", {})).appendTo(page.main); wrapper.permission_engine = new frappe.PermissionEngine(wrapper); - }; -frappe.pages['permission-manager'].refresh = function (wrapper) { +frappe.pages["permission-manager"].refresh = function (wrapper) { wrapper.permission_engine.set_from_route(); }; @@ -30,33 +31,38 @@ frappe.PermissionEngine = class PermissionEngine { make() { this.make_reset_button(); - frappe.call({ - module: "frappe.core", - page: "permission_manager", - method: "get_roles_and_doctypes" - }).then((res) => { - this.options = res.message; - this.setup_page(); - }); + frappe + .call({ + module: "frappe.core", + page: "permission_manager", + method: "get_roles_and_doctypes", + }) + .then((res) => { + this.options = res.message; + this.setup_page(); + }); } setup_page() { - this.doctype_select - = this.wrapper.page.add_select(__("Document Type"), - [{ value: "", label: __("Select Document Type") + "..." }].concat(this.options.doctypes)) - .change(function () { - frappe.set_route("permission-manager", $(this).val()); - }); + this.doctype_select = this.wrapper.page + .add_select( + __("Document Type"), + [{ value: "", label: __("Select Document Type") + "..." }].concat( + this.options.doctypes + ) + ) + .change(function () { + frappe.set_route("permission-manager", $(this).val()); + }); - this.role_select - = this.wrapper.page.add_select(__("Roles"), - [__("Select Role") + "..."].concat(this.options.roles)) - .change(() => { - this.refresh(); - }); + this.role_select = this.wrapper.page + .add_select(__("Roles"), [__("Select Role") + "..."].concat(this.options.roles)) + .change(() => { + this.refresh(); + }); - this.page.add_inner_button(__('Set User Permissions'), () => { - return frappe.set_route('List', 'User Permission'); + this.page.add_inner_button(__("Set User Permissions"), () => { + return frappe.set_route("List", "User Permission"); }); this.set_from_route(); } @@ -91,7 +97,7 @@ frappe.PermissionEngine = class PermissionEngine { page: "permission_manager", method: "get_standard_permissions", args: { doctype: doctype }, - callback: callback + callback: callback, }); } return false; @@ -100,18 +106,22 @@ frappe.PermissionEngine = class PermissionEngine { reset_std_permissions(data) { let doctype = this.get_doctype(); let d = frappe.confirm(__("Reset Permissions for {0}?", [doctype]), () => { - return frappe.call({ - module: "frappe.core", - page: "permission_manager", - method: "reset", - args: { doctype } - }).then(() => { - this.refresh(); - }); + return frappe + .call({ + module: "frappe.core", + page: "permission_manager", + method: "reset", + args: { doctype }, + }) + .then(() => { + this.refresh(); + }); }); // show standard permissions - let $d = $(d.wrapper).find(".frappe-confirm-message").append("
    Standard Permissions:

    "); + let $d = $(d.wrapper) + .find(".frappe-confirm-message") + .append("
    Standard Permissions:

    "); let $wrapper = $("

    ").appendTo($d); data.message.forEach((d) => { let rights = this.rights @@ -164,14 +174,16 @@ frappe.PermissionEngine = class PermissionEngine { } // get permissions - frappe.call({ - module: "frappe.core", - page: "permission_manager", - method: "get_permissions", - args: { doctype, role } - }).then((r) => { - this.render(r.message); - }); + frappe + .call({ + module: "frappe.core", + page: "permission_manager", + method: "get_permissions", + args: { doctype, role }, + }) + .then((r) => { + this.render(r.message); + }); } render(perm_list) { @@ -187,19 +199,21 @@ frappe.PermissionEngine = class PermissionEngine { } show_permission_table(perm_list) { - this.table = $("
    \ + this.table = $( + "
    \
    ${ __("Filter") }${ __("Value") }${__("Filter")}${__("Value")}
    ${frappe.model.unscrub(key)} ${filters[key]}
    \ \ \
    \ - ").appendTo(this.body); + " + ).appendTo(this.body); const table_columns = [ [__("Document Type"), 150], [__("Role"), 170], [__("Level"), 40], [__("Permissions"), 350], - ["", 40] + ["", 40], ]; table_columns.forEach((col) => { @@ -236,9 +250,9 @@ frappe.PermissionEngine = class PermissionEngine { let perm_cell = this.add_cell(row, d, "permissions"); let perm_container = $("
    ").appendTo(perm_cell); - this.rights.forEach(r => { - if (!d.is_submittable && ['submit', 'cancel', 'amend'].includes(r)) return; - if (d.in_create && ['create', 'write', 'delete'].includes(r)) return; + this.rights.forEach((r) => { + if (!d.is_submittable && ["submit", "cancel", "amend"].includes(r)) return; + if (d.in_create && ["create", "write", "delete"].includes(r)) return; this.add_check(perm_container, d, r); }); @@ -248,7 +262,8 @@ frappe.PermissionEngine = class PermissionEngine { } add_cell(row, d, fieldname) { - return $("").appendTo(row) + return $("") + .appendTo(row) .attr("data-fieldname", fieldname) .addClass("pt-4") .html(__(d[fieldname])); @@ -266,19 +281,20 @@ frappe.PermissionEngine = class PermissionEngine {

    ${__(description)}

    - `) + ` + ) .appendTo(cell) .attr("data-fieldname", fieldname); - checkbox.find("input") + checkbox + .find("input") .prop("checked", d[fieldname] ? true : false) .attr("data-ptype", fieldname) .attr("data-role", d.role) .attr("data-permlevel", d.permlevel) .attr("data-doctype", d.parent); - checkbox.find("label") - .css("text-transform", "capitalize"); + checkbox.find("label").css("text-transform", "capitalize"); return checkbox; } @@ -290,8 +306,23 @@ frappe.PermissionEngine = class PermissionEngine { } get rights() { - return ["select", "read", "write", "create", "delete", "submit", "cancel", "amend", - "print", "email", "report", "import", "export", "set_user_permissions", "share"]; + return [ + "select", + "read", + "write", + "create", + "delete", + "submit", + "cancel", + "amend", + "print", + "email", + "report", + "import", + "export", + "set_user_permissions", + "share", + ]; } set_show_users(cell, role) { @@ -305,22 +336,29 @@ frappe.PermissionEngine = class PermissionEngine { page: "permission_manager", method: "get_users_with_role", args: { - role: role + role: role, }, callback: function (r) { r.message = $.map(r.message, function (p) { return $.format('{1}', [p, p]); }); - frappe.msgprint(__("Users with role {0}:", [__(role)]) - + "
    " + r.message.join("
    ")); - } + frappe.msgprint( + __("Users with role {0}:", [__(role)]) + + "
    " + + r.message.join("
    ") + ); + }, }); return false; }); } add_delete_button(row, d) { - $(``) + $( + `` + ) .appendTo($(``).appendTo(row)) .attr("data-doctype", d.parent) .attr("data-role", d.role) @@ -333,7 +371,7 @@ frappe.PermissionEngine = class PermissionEngine { args: { doctype: d.parent, role: d.role, - permlevel: d.permlevel + permlevel: d.permlevel, }, callback: (r) => { if (r.exc) { @@ -341,7 +379,7 @@ frappe.PermissionEngine = class PermissionEngine { } else { this.refresh(); } - } + }, }); }); } @@ -350,7 +388,7 @@ frappe.PermissionEngine = class PermissionEngine { let me = this; this.body.on("click", ".show-user-permissions", () => { frappe.route_options = { allow: this.get_doctype() || "" }; - frappe.set_route('List', 'User Permission'); + frappe.set_route("List", "User Permission"); }); this.body.on("click", "input[type='checkbox']", function () { @@ -361,7 +399,7 @@ frappe.PermissionEngine = class PermissionEngine { permlevel: chk.attr("data-permlevel"), doctype: chk.attr("data-doctype"), ptype: chk.attr("data-ptype"), - value: chk.prop("checked") ? 1 : 0 + value: chk.prop("checked") ? 1 : 0, }; return frappe.call({ module: "frappe.core", @@ -376,7 +414,7 @@ frappe.PermissionEngine = class PermissionEngine { } else { me.get_perm(args.role)[args.ptype] = args.value; } - } + }, }); }); } @@ -389,19 +427,30 @@ frappe.PermissionEngine = class PermissionEngine { title: __("Add New Permission Rule"), fields: [ { - fieldtype: "Select", label: __("Document Type"), - options: this.options.doctypes, reqd: 1, fieldname: "parent" + fieldtype: "Select", + label: __("Document Type"), + options: this.options.doctypes, + reqd: 1, + fieldname: "parent", }, { - fieldtype: "Select", label: __("Role"), - options: this.options.roles, reqd: 1, fieldname: "role" + fieldtype: "Select", + label: __("Role"), + options: this.options.roles, + reqd: 1, + fieldname: "role", }, { - fieldtype: "Select", label: __("Permission Level"), - options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], reqd: 1, fieldname: "permlevel", - description: __("Level 0 is for document level permissions, higher levels for field level permissions.") - } - ] + fieldtype: "Select", + label: __("Permission Level"), + options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], + reqd: 1, + fieldname: "permlevel", + description: __( + "Level 0 is for document level permissions, higher levels for field level permissions." + ), + }, + ], }); if (this.get_doctype()) { d.set_value("parent", this.get_doctype()); @@ -412,7 +461,7 @@ frappe.PermissionEngine = class PermissionEngine { d.get_input("role").prop("disabled", true); } d.set_value("permlevel", "0"); - d.set_primary_action(__('Add'), () => { + d.set_primary_action(__("Add"), () => { let args = d.get_values(); if (!args) { return; @@ -428,7 +477,7 @@ frappe.PermissionEngine = class PermissionEngine { } else { this.refresh(); } - } + }, }); d.hide(); }); @@ -439,13 +488,11 @@ frappe.PermissionEngine = class PermissionEngine { } make_reset_button() { - this.page.set_secondary_action( - __("Restore Original Permissions"), - () => { - this.get_standard_permissions((data) => { - this.reset_std_permissions(data); - }); + this.page.set_secondary_action(__("Restore Original Permissions"), () => { + this.get_standard_permissions((data) => { + this.reset_std_permissions(data); }); + }); } get_perm(role) { @@ -455,7 +502,9 @@ frappe.PermissionEngine = class PermissionEngine { } get_link_fields(doctype) { - return frappe.get_children("DocType", doctype, "fields", - { fieldtype: "Link", options: ["not in", ["User", '[Select]']] }); + return frappe.get_children("DocType", doctype, "fields", { + fieldtype: "Link", + options: ["not in", ["User", "[Select]"]], + }); } }; diff --git a/frappe/core/page/recorder/recorder.js b/frappe/core/page/recorder/recorder.js index f1f74daf71..83b8d1a636 100644 --- a/frappe/core/page/recorder/recorder.js +++ b/frappe/core/page/recorder/recorder.js @@ -1,28 +1,28 @@ -frappe.pages['recorder'].on_page_load = function(wrapper) { +frappe.pages["recorder"].on_page_load = function (wrapper) { frappe.ui.make_app_page({ parent: wrapper, - title: __('Recorder'), + title: __("Recorder"), single_column: true, - card_layout: true + card_layout: true, }); frappe.recorder = new Recorder(wrapper); - $(wrapper).bind('show', function() { + $(wrapper).bind("show", function () { frappe.recorder.show(); }); - frappe.require('recorder.bundle.js'); + frappe.require("recorder.bundle.js"); }; class Recorder { constructor(wrapper) { this.wrapper = $(wrapper); - this.container = this.wrapper.find('.layout-main-section'); + this.container = this.wrapper.find(".layout-main-section"); this.container.append($('
    ')); } show() { if (!this.view || this.view.$route.name == "recorder-detail") return; - this.view.$router.replace({name: "recorder-detail"}); + this.view.$router.replace({ name: "recorder-detail" }); } } diff --git a/frappe/core/report/permitted_documents_for_user/permitted_documents_for_user.js b/frappe/core/report/permitted_documents_for_user/permitted_documents_for_user.js index 195f25f533..f840a49c92 100644 --- a/frappe/core/report/permitted_documents_for_user/permitted_documents_for_user.js +++ b/frappe/core/report/permitted_documents_for_user/permitted_documents_for_user.js @@ -2,33 +2,33 @@ // MIT License. See license.txt frappe.query_reports["Permitted Documents For User"] = { - "filters": [ + filters: [ { - "fieldname": "user", - "label": __("User"), - "fieldtype": "Link", - "options": "User", - "reqd": 1 + fieldname: "user", + label: __("User"), + fieldtype: "Link", + options: "User", + reqd: 1, }, { - "fieldname": "doctype", - "label": __("DocType"), - "fieldtype": "Link", - "options": "DocType", - "reqd": 1, - "get_query": function () { + fieldname: "doctype", + label: __("DocType"), + fieldtype: "Link", + options: "DocType", + reqd: 1, + get_query: function () { return { - "query": "frappe.core.report.permitted_documents_for_user.permitted_documents_for_user.query_doctypes", - "filters": { - "user": frappe.query_report.get_filter_value('user') - } - } - } + query: "frappe.core.report.permitted_documents_for_user.permitted_documents_for_user.query_doctypes", + filters: { + user: frappe.query_report.get_filter_value("user"), + }, + }; + }, }, { - "fieldname": "show_permissions", - "label": __("Show Permissions"), - "fieldtype": "Check" - } - ] -} + fieldname: "show_permissions", + label: __("Show Permissions"), + fieldtype: "Check", + }, + ], +}; diff --git a/frappe/core/report/transaction_log_report/transaction_log_report.js b/frappe/core/report/transaction_log_report/transaction_log_report.js index 54ecf3fcf1..3c7261306d 100644 --- a/frappe/core/report/transaction_log_report/transaction_log_report.js +++ b/frappe/core/report/transaction_log_report/transaction_log_report.js @@ -3,9 +3,9 @@ /* eslint-disable */ frappe.query_reports["Transaction Log Report"] = { - onload: function(query_report) { - query_report.add_make_chart_button = function() { + onload: function (query_report) { + query_report.add_make_chart_button = function () { // }; - } -} + }, +}; diff --git a/frappe/core/web_form/edit_profile/edit_profile.js b/frappe/core/web_form/edit_profile/edit_profile.js index 699703c579..8f56ebb353 100644 --- a/frappe/core/web_form/edit_profile/edit_profile.js +++ b/frappe/core/web_form/edit_profile/edit_profile.js @@ -1,3 +1,3 @@ -frappe.ready(function() { +frappe.ready(function () { // bind events here -}) \ No newline at end of file +}); diff --git a/frappe/custom/doctype/client_script/client_script.js b/frappe/custom/doctype/client_script/client_script.js index 18786c62cf..67bb0083c8 100644 --- a/frappe/custom/doctype/client_script/client_script.js +++ b/frappe/custom/doctype/client_script/client_script.js @@ -1,46 +1,49 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Client Script', { +frappe.ui.form.on("Client Script", { setup(frm) { frm.get_field("sample").html(SAMPLE_HTML); }, refresh(frm) { if (frm.doc.dt && frm.doc.script) { - frm.add_custom_button(__('Go to {0}', [frm.doc.dt]), - () => frappe.set_route('List', frm.doc.dt, 'List')); + frm.add_custom_button(__("Go to {0}", [frm.doc.dt]), () => + frappe.set_route("List", frm.doc.dt, "List") + ); } - if (frm.doc.view == 'Form') { - frm.add_custom_button(__('Add script for Child Table'), () => { + if (frm.doc.view == "Form") { + frm.add_custom_button(__("Add script for Child Table"), () => { frappe.model.with_doctype(frm.doc.dt, () => { - const child_tables = frappe.meta.get_docfields(frm.doc.dt, null, { - fieldtype: 'Table' - }).map(df => df.options); + const child_tables = frappe.meta + .get_docfields(frm.doc.dt, null, { + fieldtype: "Table", + }) + .map((df) => df.options); const d = new frappe.ui.Dialog({ - title: __('Select Child Table'), + title: __("Select Child Table"), fields: [ { - label: __('Select Child Table'), - fieldtype: 'Link', - fieldname: 'cdt', - options: 'DocType', + label: __("Select Child Table"), + fieldtype: "Link", + fieldname: "cdt", + options: "DocType", get_query: () => { return { filters: { istable: 1, - name: ['in', child_tables] - } + name: ["in", child_tables], + }, }; - } - } + }, + }, ], primary_action: ({ cdt }) => { - cdt = d.get_field('cdt').value; + cdt = d.get_field("cdt").value; frm.events.add_script_for_doctype(frm, cdt); d.hide(); - } + }, }); d.show(); @@ -48,39 +51,39 @@ frappe.ui.form.on('Client Script', { }); if (!frm.is_new()) { - frm.add_custom_button(__('Compare Versions'), () => { + frm.add_custom_button(__("Compare Versions"), () => { new frappe.ui.DiffView("Client Script", "script", frm.doc.name); }); } } - frm.set_query('dt', { + frm.set_query("dt", { filters: { - istable: 0 - } + istable: 0, + }, }); }, dt(frm) { - frm.toggle_display('view', !frappe.boot.single_types.includes(frm.doc.dt)); + frm.toggle_display("view", !frappe.boot.single_types.includes(frm.doc.dt)); if (!frm.doc.script) { frm.events.add_script_for_doctype(frm, frm.doc.dt); } if (frm.doc.script && !frm.doc.script.includes(frm.doc.dt)) { - frm.doc.script = ''; + frm.doc.script = ""; frm.events.add_script_for_doctype(frm, frm.doc.dt); } }, view(frm) { - let has_form_boilerplate = frm.doc.script.includes('frappe.ui.form.on') - if (frm.doc.view === 'List' && has_form_boilerplate) { - frm.set_value('script', ''); + let has_form_boilerplate = frm.doc.script.includes("frappe.ui.form.on"); + if (frm.doc.view === "List" && has_form_boilerplate) { + frm.set_value("script", ""); } - if (frm.doc.view === 'Form' && !has_form_boilerplate) { - frm.trigger('dt'); + if (frm.doc.view === "Form" && !has_form_boilerplate) { + frm.trigger("dt"); } }, @@ -93,12 +96,12 @@ frappe.ui.form.on('${doctype}', { } }) `.trim(); - let script = (frm.doc.script || ''); + let script = frm.doc.script || ""; if (script) { - script += '\n\n'; + script += "\n\n"; } - frm.set_value('script', script + boilerplate); - } + frm.set_value("script", script + boilerplate); + }, }); const SAMPLE_HTML = `

    Client Script Help

    diff --git a/frappe/custom/doctype/client_script/ui_test_client_script.js b/frappe/custom/doctype/client_script/ui_test_client_script.js index 022f677151..0d202d697c 100644 --- a/frappe/custom/doctype/client_script/ui_test_client_script.js +++ b/frappe/custom/doctype/client_script/ui_test_client_script.js @@ -12,14 +12,14 @@ context("Client Script", () => { dt: "ToDo", view: "Form", enabled: 1, - script: `console.log('todo form script')` + script: `console.log('todo form script')`, }, true ); cy.visit("/app/todo/new", { onBeforeLoad(win) { cy.spy(win.console, "log").as("consoleLog"); - } + }, }); cy.get("@consoleLog").should("be.calledWith", "todo form script"); }); @@ -32,14 +32,14 @@ context("Client Script", () => { dt: "ToDo", view: "List", enabled: 1, - script: `console.log('todo list script')` + script: `console.log('todo list script')`, }, true ); cy.visit("/app/todo", { onBeforeLoad(win) { cy.spy(win.console, "log").as("consoleLog"); - } + }, }); cy.get("@consoleLog").should("be.calledWith", "todo list script"); }); @@ -52,19 +52,16 @@ context("Client Script", () => { dt: "ToDo", view: "List", enabled: 0, - script: `console.log('todo disabled script')` + script: `console.log('todo disabled script')`, }, true ); cy.visit("/app/todo", { onBeforeLoad(win) { cy.spy(win.console, "log").as("consoleLog"); - } + }, }); - cy.get("@consoleLog").should( - "not.be.calledWith", - "todo disabled script" - ); + cy.get("@consoleLog").should("not.be.calledWith", "todo disabled script"); }); it("should run multiple scripts", () => { @@ -75,7 +72,7 @@ context("Client Script", () => { dt: "ToDo", view: "Form", enabled: 1, - script: `console.log('todo form script 1')` + script: `console.log('todo form script 1')`, }, true ); @@ -86,14 +83,14 @@ context("Client Script", () => { dt: "ToDo", view: "Form", enabled: 1, - script: `console.log('todo form script 2')` + script: `console.log('todo form script 2')`, }, true ); cy.visit("/app/todo/new", { onBeforeLoad(win) { cy.spy(win.console, "log").as("consoleLog"); - } + }, }); cy.get("@consoleLog").should("be.calledWith", "todo form script 1"); cy.get("@consoleLog").should("be.calledWith", "todo form script 2"); diff --git a/frappe/custom/doctype/custom_field/custom_field.js b/frappe/custom/doctype/custom_field/custom_field.js index c59fabeaa6..fba19ca45e 100644 --- a/frappe/custom/doctype/custom_field/custom_field.js +++ b/frappe/custom/doctype/custom_field/custom_field.js @@ -4,88 +4,99 @@ // Refresh // -------- -frappe.ui.form.on('Custom Field', { - setup: function(frm) { - frm.set_query('dt', function(doc) { +frappe.ui.form.on("Custom Field", { + setup: function (frm) { + frm.set_query("dt", function (doc) { var filters = [ - ['DocType', 'issingle', '=', 0], - ['DocType', 'custom', '=', 0], - ['DocType', 'name', 'not in', frappe.model.core_doctypes_list], - ['DocType', 'restrict_to_domain', 'in', frappe.boot.active_domains] + ["DocType", "issingle", "=", 0], + ["DocType", "custom", "=", 0], + ["DocType", "name", "not in", frappe.model.core_doctypes_list], + ["DocType", "restrict_to_domain", "in", frappe.boot.active_domains], ]; - if(frappe.session.user!=="Administrator") { - filters.push(['DocType', 'module', 'not in', ['Core', 'Custom']]) + if (frappe.session.user !== "Administrator") { + filters.push(["DocType", "module", "not in", ["Core", "Custom"]]); } return { - "filters": filters - } + filters: filters, + }; }); }, - refresh: function(frm) { - frm.toggle_enable('dt', frm.doc.__islocal); - frm.trigger('dt'); - frm.toggle_reqd('label', !frm.doc.fieldname); + refresh: function (frm) { + frm.toggle_enable("dt", frm.doc.__islocal); + frm.trigger("dt"); + frm.toggle_reqd("label", !frm.doc.fieldname); }, - dt: function(frm) { - if(!frm.doc.dt) { - set_field_options('insert_after', ''); + dt: function (frm) { + if (!frm.doc.dt) { + set_field_options("insert_after", ""); return; } var insert_after = frm.doc.insert_after || null; return frappe.call({ - method: 'frappe.custom.doctype.custom_field.custom_field.get_fields_label', + method: "frappe.custom.doctype.custom_field.custom_field.get_fields_label", args: { doctype: frm.doc.dt, fieldname: frm.doc.fieldname }, - callback: function(r) { - if(r) { - if(r._server_messages && r._server_messages.length) { + callback: function (r) { + if (r) { + if (r._server_messages && r._server_messages.length) { frm.set_value("dt", ""); } else { - set_field_options('insert_after', r.message); - var fieldnames = $.map(r.message, function(v) { return v.value; }); + set_field_options("insert_after", r.message); + var fieldnames = $.map(r.message, function (v) { + return v.value; + }); - if(insert_after==null || !in_list(fieldnames, insert_after)) { + if (insert_after == null || !in_list(fieldnames, insert_after)) { insert_after = fieldnames[-1]; } - frm.set_value('insert_after', insert_after); + frm.set_value("insert_after", insert_after); } } - } + }, }); - }, - label: function(frm) { - if(frm.doc.label && frappe.utils.has_special_chars(frm.doc.label)) { - frm.fields_dict['label_help'].disp_area.innerHTML = - ''+__('Special Characters are not allowed')+''; - frm.set_value('label', ''); + label: function (frm) { + if (frm.doc.label && frappe.utils.has_special_chars(frm.doc.label)) { + frm.fields_dict["label_help"].disp_area.innerHTML = + '' + __("Special Characters are not allowed") + ""; + frm.set_value("label", ""); } else { - frm.fields_dict['label_help'].disp_area.innerHTML = ''; + frm.fields_dict["label_help"].disp_area.innerHTML = ""; } }, - fieldtype: function(frm) { - if(frm.doc.fieldtype == 'Link') { - frm.fields_dict['options_help'].disp_area.innerHTML = - __('Name of the Document Type (DocType) you want this field to be linked to. e.g. Customer'); - } else if(frm.doc.fieldtype == 'Select') { - frm.fields_dict['options_help'].disp_area.innerHTML = - __('Options for select. Each option on a new line.')+' '+__('e.g.:')+'
    '+__('Option 1')+'
    '+__('Option 2')+'
    '+__('Option 3')+'
    '; - } else if(frm.doc.fieldtype == 'Dynamic Link') { - frm.fields_dict['options_help'].disp_area.innerHTML = - __('Fieldname which will be the DocType for this link field.'); + fieldtype: function (frm) { + if (frm.doc.fieldtype == "Link") { + frm.fields_dict["options_help"].disp_area.innerHTML = __( + "Name of the Document Type (DocType) you want this field to be linked to. e.g. Customer" + ); + } else if (frm.doc.fieldtype == "Select") { + frm.fields_dict["options_help"].disp_area.innerHTML = + __("Options for select. Each option on a new line.") + + " " + + __("e.g.:") + + "
    " + + __("Option 1") + + "
    " + + __("Option 2") + + "
    " + + __("Option 3") + + "
    "; + } else if (frm.doc.fieldtype == "Dynamic Link") { + frm.fields_dict["options_help"].disp_area.innerHTML = __( + "Fieldname which will be the DocType for this link field." + ); } else { - frm.fields_dict['options_help'].disp_area.innerHTML = ''; + frm.fields_dict["options_help"].disp_area.innerHTML = ""; } - } + }, }); - -frappe.utils.has_special_chars = function(t) { - var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?"; +frappe.utils.has_special_chars = function (t) { + var iChars = "!@#$%^&*()+=-[]\\';,./{}|\":<>?"; for (var i = 0; i < t.length; i++) { if (iChars.indexOf(t.charAt(i)) != -1) { return true; } } return false; -} +}; diff --git a/frappe/custom/doctype/customize_form/customize_form.js b/frappe/custom/doctype/customize_form/customize_form.js index 3ec6795f0e..a35db2ca18 100644 --- a/frappe/custom/doctype/customize_form/customize_form.js +++ b/frappe/custom/doctype/customize_form/customize_form.js @@ -4,7 +4,7 @@ frappe.provide("frappe.customize_form"); frappe.ui.form.on("Customize Form", { - setup: function(frm) { + setup: function (frm) { // save the last setting if refreshing window.addEventListener("beforeunload", () => { if (frm.doc.doc_type && frm.doc.doc_type != "undefined") { @@ -13,67 +13,59 @@ frappe.ui.form.on("Customize Form", { }); }, - onload: function(frm) { - frm.set_query("doc_type", function() { + onload: function (frm) { + frm.set_query("doc_type", function () { return { filters: [ ["DocType", "issingle", "=", 0], ["DocType", "custom", "=", 0], - [ - "DocType", - "name", - "not in", - frappe.model.core_doctypes_list - ], - [ - "DocType", - "restrict_to_domain", - "in", - frappe.boot.active_domains - ] - ] + ["DocType", "name", "not in", frappe.model.core_doctypes_list], + ["DocType", "restrict_to_domain", "in", frappe.boot.active_domains], + ], }; }); - frm.set_query("default_print_format", function() { + frm.set_query("default_print_format", function () { return { filters: { print_format_type: ["!=", "JS"], - doc_type: ["=", frm.doc.doc_type] - } + doc_type: ["=", frm.doc.doc_type], + }, }; }); - $(frm.wrapper).on("grid-row-render", function(e, grid_row) { + $(frm.wrapper).on("grid-row-render", function (e, grid_row) { if (grid_row.doc && grid_row.doc.fieldtype == "Section Break") { $(grid_row.row).css({ "font-weight": "bold" }); } grid_row.row.removeClass("highlight"); - if (grid_row.doc.is_custom_field && - !grid_row.row.hasClass('highlight') && - !grid_row.doc.is_system_generated) { + if ( + grid_row.doc.is_custom_field && + !grid_row.row.hasClass("highlight") && + !grid_row.doc.is_system_generated + ) { grid_row.row.addClass("highlight"); } }); - $(frm.wrapper).on("grid-make-sortable", function(e, frm) { + $(frm.wrapper).on("grid-make-sortable", function (e, frm) { frm.trigger("setup_sortable"); }); - $(frm.wrapper).on("grid-move-row", function(e, frm) { + $(frm.wrapper).on("grid-move-row", function (e, frm) { frm.trigger("setup_sortable"); }); }, - doc_type: function(frm) { + doc_type: function (frm) { if (frm.doc.doc_type) { return frm.call({ method: "fetch_to_customize", doc: frm.doc, freeze: true, - callback: function(r) { + callback: function (r) { if (r) { if (r._server_messages && r._server_messages.length) { frm.set_value("doc_type", ""); @@ -83,15 +75,15 @@ frappe.ui.form.on("Customize Form", { } } localStorage["customize_doctype"] = frm.doc.doc_type; - } + }, }); } else { frm.refresh(); } }, - setup_sortable: function(frm) { - frm.doc.fields.forEach(function(f, i) { + setup_sortable: function (frm) { + frm.doc.fields.forEach(function (f, i) { if (!f.is_custom_field) { f._sortable = false; } @@ -99,7 +91,7 @@ frappe.ui.form.on("Customize Form", { if (f.fieldtype == "Table") { frm.add_custom_button( f.options, - function() { + function () { frm.set_value("doc_type", f.options); }, __("Customize Child Table") @@ -109,17 +101,17 @@ frappe.ui.form.on("Customize Form", { frm.fields_dict.fields.grid.refresh(); }, - refresh: function(frm) { + refresh: function (frm) { frm.disable_save(true); frm.page.clear_icons(); if (frm.doc.doc_type) { - frm.page.set_title(__('Customize Form - {0}', [frm.doc.doc_type])); + frm.page.set_title(__("Customize Form - {0}", [frm.doc.doc_type])); frappe.customize_form.set_primary_action(frm); frm.add_custom_button( __("Go to {0} List", [__(frm.doc.doc_type)]), - function() { + function () { frappe.set_route("List", frm.doc.doc_type); }, __("Actions") @@ -127,7 +119,7 @@ frappe.ui.form.on("Customize Form", { frm.add_custom_button( __("Reload"), - function() { + function () { frm.script_manager.trigger("doc_type"); }, __("Actions") @@ -135,24 +127,21 @@ frappe.ui.form.on("Customize Form", { frm.add_custom_button( __("Reset to defaults"), - function() { - frappe.customize_form.confirm( - __("Remove all customizations?"), - frm - ); + function () { + frappe.customize_form.confirm(__("Remove all customizations?"), frm); }, __("Actions") ); frm.add_custom_button( __("Set Permissions"), - function() { + function () { frappe.set_route("permission-manager", frm.doc.doc_type); }, __("Actions") ); - const is_autoname_autoincrement = frm.doc.autoname === 'autoincrement'; + const is_autoname_autoincrement = frm.doc.autoname === "autoincrement"; frm.set_df_property("naming_rule", "hidden", is_autoname_autoincrement); frm.set_df_property("autoname", "read_only", is_autoname_autoincrement); } @@ -181,37 +170,37 @@ frappe.ui.form.on("Customize Form", { if (frappe.boot.developer_mode) { frm.add_custom_button( __("Export Customizations"), - function() { + function () { frappe.prompt( [ { fieldtype: "Link", fieldname: "module", options: "Module Def", - label: __("Module to Export") + label: __("Module to Export"), }, { fieldtype: "Check", fieldname: "sync_on_migrate", label: __("Sync on Migrate"), - default: 1 + default: 1, }, { fieldtype: "Check", fieldname: "with_permissions", label: __("Export Custom Permissions"), - default: 1 - } + default: 1, + }, ], - function(data) { + function (data) { frappe.call({ method: "frappe.modules.utils.export_customizations", args: { doctype: frm.doc.doc_type, module: data.module, sync_on_migrate: data.sync_on_migrate, - with_permissions: data.with_permissions - } + with_permissions: data.with_permissions, + }, }); }, __("Select Module") @@ -225,127 +214,131 @@ frappe.ui.form.on("Customize Form", { setup_sort_order(frm) { // sort order select if (frm.doc.doc_type) { - var fields = $.map(frm.doc.fields, function(df) { - return frappe.model.is_value_type(df.fieldtype) - ? df.fieldname - : null; + var fields = $.map(frm.doc.fields, function (df) { + return frappe.model.is_value_type(df.fieldtype) ? df.fieldname : null; }); fields = ["", "name", "modified"].concat(fields); frm.set_df_property("sort_field", "options", fields); } - } + }, }); // can't delete standard fields frappe.ui.form.on("Customize Form Field", { - before_fields_remove: function(frm, doctype, name) { + before_fields_remove: function (frm, doctype, name) { var row = frappe.get_doc(doctype, name); if (!(row.is_custom_field || row.__islocal)) { frappe.msgprint(__("Cannot delete standard field. You can hide it if you want")); throw "cannot delete standard field"; } }, - fields_add: function(frm, cdt, cdn) { + fields_add: function (frm, cdt, cdn) { var f = frappe.model.get_doc(cdt, cdn); f.is_system_generated = false; f.is_custom_field = true; - } + }, }); // can't delete standard links frappe.ui.form.on("DocType Link", { - before_links_remove: function(frm, doctype, name) { + before_links_remove: function (frm, doctype, name) { let row = frappe.get_doc(doctype, name); if (!(row.custom || row.__islocal)) { frappe.msgprint(__("Cannot delete standard link. You can hide it if you want")); throw "cannot delete standard link"; } }, - links_add: function(frm, cdt, cdn) { + links_add: function (frm, cdt, cdn) { let f = frappe.model.get_doc(cdt, cdn); f.custom = 1; - } + }, }); // can't delete standard actions frappe.ui.form.on("DocType Action", { - before_actions_remove: function(frm, doctype, name) { + before_actions_remove: function (frm, doctype, name) { let row = frappe.get_doc(doctype, name); if (!(row.custom || row.__islocal)) { frappe.msgprint(__("Cannot delete standard action. You can hide it if you want")); throw "cannot delete standard action"; } }, - actions_add: function(frm, cdt, cdn) { + actions_add: function (frm, cdt, cdn) { let f = frappe.model.get_doc(cdt, cdn); f.custom = 1; - } + }, }); // can't delete standard states frappe.ui.form.on("DocType State", { - before_states_remove: function(frm, doctype, name) { + before_states_remove: function (frm, doctype, name) { let row = frappe.get_doc(doctype, name); if (!(row.custom || row.__islocal)) { frappe.msgprint(__("Cannot delete standard document state.")); throw "cannot delete standard document state"; } }, - states_add: function(frm, cdt, cdn) { + states_add: function (frm, cdt, cdn) { let f = frappe.model.get_doc(cdt, cdn); f.custom = 1; - } + }, }); -frappe.customize_form.set_primary_action = function(frm) { - frm.page.set_primary_action(__("Update"), function() { +frappe.customize_form.set_primary_action = function (frm) { + frm.page.set_primary_action(__("Update"), function () { if (frm.doc.doc_type) { return frm.call({ doc: frm.doc, freeze: true, btn: frm.page.btn_primary, method: "save_customization", - callback: function(r) { + callback: function (r) { if (!r.exc) { frappe.customize_form.clear_locals_and_refresh(frm); frm.script_manager.trigger("doc_type"); } - } + }, }); } }); }; -frappe.customize_form.confirm = function(msg, frm) { +frappe.customize_form.confirm = function (msg, frm) { if (!frm.doc.doc_type) return; var d = new frappe.ui.Dialog({ - title: 'Reset To Defaults', + title: "Reset To Defaults", fields: [ - {fieldtype:"HTML", options:__("All customizations will be removed. Please confirm.")}, + { + fieldtype: "HTML", + options: __("All customizations will be removed. Please confirm."), + }, ], - primary_action: function() { + primary_action: function () { return frm.call({ doc: frm.doc, method: "reset_to_defaults", - callback: function(r) { + callback: function (r) { if (r.exc) { frappe.msgprint(r.exc); } else { d.hide(); - frappe.show_alert({message:__('Customizations Reset'), indicator:'green'}); + frappe.show_alert({ + message: __("Customizations Reset"), + indicator: "green", + }); frappe.customize_form.clear_locals_and_refresh(frm); } - } + }, }); - } + }, }); frappe.customize_form.confirm.dialog = d; d.show(); -} +}; -frappe.customize_form.clear_locals_and_refresh = function(frm) { +frappe.customize_form.clear_locals_and_refresh = function (frm) { delete frm.doc.__unsaved; // clear doctype from locals frappe.model.clear_doc("DocType", frm.doc.doc_type); @@ -353,4 +346,4 @@ frappe.customize_form.clear_locals_and_refresh = function(frm) { frm.refresh(); }; -extend_cscript(cur_frm.cscript, new frappe.model.DocTypeController({frm: cur_frm})); +extend_cscript(cur_frm.cscript, new frappe.model.DocTypeController({ frm: cur_frm })); diff --git a/frappe/custom/doctype/doctype_layout/doctype_layout.js b/frappe/custom/doctype/doctype_layout/doctype_layout.js index 533efea9b8..f91f04f762 100644 --- a/frappe/custom/doctype/doctype_layout/doctype_layout.js +++ b/frappe/custom/doctype/doctype_layout/doctype_layout.js @@ -1,30 +1,32 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('DocType Layout', { - refresh: function(frm) { - frm.trigger('document_type'); +frappe.ui.form.on("DocType Layout", { + refresh: function (frm) { + frm.trigger("document_type"); frm.events.set_button(frm); }, document_type(frm) { - frm.set_fields_as_options('fields', frm.doc.document_type, null, [], 'fieldname').then(() => { - // child table empty? then show all fields as default - if (frm.doc.document_type) { - if (!(frm.doc.fields || []).length) { - for (let f of frappe.get_doc('DocType', frm.doc.document_type).fields) { - frm.add_child('fields', { fieldname: f.fieldname, label: f.label }); + frm.set_fields_as_options("fields", frm.doc.document_type, null, [], "fieldname").then( + () => { + // child table empty? then show all fields as default + if (frm.doc.document_type) { + if (!(frm.doc.fields || []).length) { + for (let f of frappe.get_doc("DocType", frm.doc.document_type).fields) { + frm.add_child("fields", { fieldname: f.fieldname, label: f.label }); + } } } } - }); + ); }, set_button(frm) { if (!frm.is_new()) { - frm.add_custom_button(__('Go to {0} List', [frm.doc.name]), () => { + frm.add_custom_button(__("Go to {0} List", [frm.doc.name]), () => { window.open(`/app/${frappe.router.slug(frm.doc.name)}`); }); } - } + }, }); diff --git a/frappe/custom/doctype/property_setter/property_setter.js b/frappe/custom/doctype/property_setter/property_setter.js index bff5ad0e63..955e01c33e 100644 --- a/frappe/custom/doctype/property_setter/property_setter.js +++ b/frappe/custom/doctype/property_setter/property_setter.js @@ -1,10 +1,10 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt -frappe.ui.form.on('Property Setter', { - validate: function(frm) { - if(frm.doc.property_type=='Check' && !in_list(['0','1'], frm.doc.value)) { - frappe.throw(__('Value for a check field can be either 0 or 1')); +frappe.ui.form.on("Property Setter", { + validate: function (frm) { + if (frm.doc.property_type == "Check" && !in_list(["0", "1"], frm.doc.value)) { + frappe.throw(__("Value for a check field can be either 0 or 1")); } - } + }, }); diff --git a/frappe/desk/doctype/bulk_update/bulk_update.js b/frappe/desk/doctype/bulk_update/bulk_update.js index bb9cf2af51..017eee1480 100644 --- a/frappe/desk/doctype/bulk_update/bulk_update.js +++ b/frappe/desk/doctype/bulk_update/bulk_update.js @@ -1,65 +1,69 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Bulk Update', { - refresh: function(frm) { - frm.set_query("document_type", function() { +frappe.ui.form.on("Bulk Update", { + refresh: function (frm) { + frm.set_query("document_type", function () { return { filters: [ - ['DocType', 'issingle', '=', 0], - ['DocType', 'name', 'not in', frappe.model.core_doctypes_list] - ] + ["DocType", "issingle", "=", 0], + ["DocType", "name", "not in", frappe.model.core_doctypes_list], + ], }; }); - frm.page.set_primary_action(__('Update'), function() { + frm.page.set_primary_action(__("Update"), function () { if (!frm.doc.update_value) { frappe.throw(__('Field "value" is mandatory. Please specify value to be updated')); } else { - frappe.call({ - method: 'frappe.desk.doctype.bulk_update.bulk_update.update', - args: { - doctype: frm.doc.document_type, - field: frm.doc.field, - value: frm.doc.update_value, - condition: frm.doc.condition, - limit: frm.doc.limit - }, - }).then(r => { - let failed = r.message; - if (!failed) failed = []; + frappe + .call({ + method: "frappe.desk.doctype.bulk_update.bulk_update.update", + args: { + doctype: frm.doc.document_type, + field: frm.doc.field, + value: frm.doc.update_value, + condition: frm.doc.condition, + limit: frm.doc.limit, + }, + }) + .then((r) => { + let failed = r.message; + if (!failed) failed = []; - if (failed.length && !r._server_messages) { - frappe.throw(__('Cannot update {0}', [failed.map(f => f.bold ? f.bold(): f).join(', ')])); - } else { - frappe.msgprint({ - title: __('Success'), - message: __('Updated Successfully'), - indicator: 'green' - }); - } + if (failed.length && !r._server_messages) { + frappe.throw( + __("Cannot update {0}", [ + failed.map((f) => (f.bold ? f.bold() : f)).join(", "), + ]) + ); + } else { + frappe.msgprint({ + title: __("Success"), + message: __("Updated Successfully"), + indicator: "green", + }); + } - frappe.hide_progress(); - frm.save(); - }); + frappe.hide_progress(); + frm.save(); + }); } }); }, - document_type: function(frm) { + document_type: function (frm) { // set field options - if(!frm.doc.document_type) return; + if (!frm.doc.document_type) return; - frappe.model.with_doctype(frm.doc.document_type, function() { - var options = $.map(frappe.get_meta(frm.doc.document_type).fields, - function(d) { - if(d.fieldname && frappe.model.no_value_type.indexOf(d.fieldtype)===-1) { - return d.fieldname; - } - return null; + frappe.model.with_doctype(frm.doc.document_type, function () { + var options = $.map(frappe.get_meta(frm.doc.document_type).fields, function (d) { + if (d.fieldname && frappe.model.no_value_type.indexOf(d.fieldtype) === -1) { + return d.fieldname; } - ); - frm.set_df_property('field', 'options', options); + return null; + }); + frm.set_df_property("field", "options", options); }); - } + }, }); diff --git a/frappe/desk/doctype/calendar_view/calendar_view.js b/frappe/desk/doctype/calendar_view/calendar_view.js index a58a9555db..c302c1a4d8 100644 --- a/frappe/desk/doctype/calendar_view/calendar_view.js +++ b/frappe/desk/doctype/calendar_view/calendar_view.js @@ -1,35 +1,36 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Calendar View', { - onload: function(frm) { - frm.trigger('reference_doctype'); +frappe.ui.form.on("Calendar View", { + onload: function (frm) { + frm.trigger("reference_doctype"); }, - refresh: function(frm) { + refresh: function (frm) { if (!frm.is_new()) { - frm.add_custom_button(__('Show Calendar'), - () => frappe.set_route('List', frm.doc.reference_doctype, 'Calendar', frm.doc.name)); + frm.add_custom_button(__("Show Calendar"), () => + frappe.set_route("List", frm.doc.reference_doctype, "Calendar", frm.doc.name) + ); } }, - reference_doctype: function(frm) { + reference_doctype: function (frm) { const { reference_doctype } = frm.doc; if (!reference_doctype) return; frappe.model.with_doctype(reference_doctype, () => { const meta = frappe.get_meta(reference_doctype); - const subject_options = meta.fields.filter( - df => !frappe.model.no_value_type.includes(df.fieldtype) - ).map(df => df.fieldname); + const subject_options = meta.fields + .filter((df) => !frappe.model.no_value_type.includes(df.fieldtype)) + .map((df) => df.fieldname); - const date_options = meta.fields.filter( - df => ['Date', 'Datetime'].includes(df.fieldtype) - ).map(df => df.fieldname); + const date_options = meta.fields + .filter((df) => ["Date", "Datetime"].includes(df.fieldtype)) + .map((df) => df.fieldname); - frm.set_df_property('subject_field', 'options', subject_options); - frm.set_df_property('start_date_field', 'options', date_options); - frm.set_df_property('end_date_field', 'options', date_options); + frm.set_df_property("subject_field", "options", subject_options); + frm.set_df_property("start_date_field", "options", date_options); + frm.set_df_property("end_date_field", "options", date_options); frm.refresh(); }); - } + }, }); diff --git a/frappe/desk/doctype/console_log/console_log.js b/frappe/desk/doctype/console_log/console_log.js index 1ef4fdce59..9a980667ac 100644 --- a/frappe/desk/doctype/console_log/console_log.js +++ b/frappe/desk/doctype/console_log/console_log.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Console Log', { +frappe.ui.form.on("Console Log", { // refresh: function(frm) { - // } }); diff --git a/frappe/desk/doctype/dashboard/dashboard.js b/frappe/desk/doctype/dashboard/dashboard.js index c640259cf2..9f584ca552 100644 --- a/frappe/desk/doctype/dashboard/dashboard.js +++ b/frappe/desk/doctype/dashboard/dashboard.js @@ -1,30 +1,30 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Dashboard', { - refresh: function(frm) { - frm.add_custom_button(__("Show Dashboard"), - () => frappe.set_route('dashboard-view', frm.doc.name) +frappe.ui.form.on("Dashboard", { + refresh: function (frm) { + frm.add_custom_button(__("Show Dashboard"), () => + frappe.set_route("dashboard-view", frm.doc.name) ); if (!frappe.boot.developer_mode && frm.doc.is_standard) { frm.disable_form(); } - frm.set_query("chart", "charts", function() { + frm.set_query("chart", "charts", function () { return { filters: { is_public: 1, - } + }, }; }); - frm.set_query("card", "cards", function() { + frm.set_query("card", "cards", function () { return { filters: { is_public: 1, - } + }, }; }); - } + }, }); diff --git a/frappe/desk/doctype/dashboard/dashboard_list.js b/frappe/desk/doctype/dashboard/dashboard_list.js index d60a324048..80ebbd4355 100644 --- a/frappe/desk/doctype/dashboard/dashboard_list.js +++ b/frappe/desk/doctype/dashboard/dashboard_list.js @@ -1,4 +1,4 @@ -frappe.listview_settings['Dashboard'] = { +frappe.listview_settings["Dashboard"] = { button: { show(doc) { return doc.name; @@ -7,10 +7,10 @@ frappe.listview_settings['Dashboard'] = { return frappe.utils.icon("dashboard-list", "sm"); }, get_description(doc) { - return __('View {0}', [`${doc.name}`]); + return __("View {0}", [`${doc.name}`]); }, action(doc) { - frappe.set_route('dashboard-view', doc.name); - } + frappe.set_route("dashboard-view", doc.name); + }, }, -}; \ No newline at end of file +}; diff --git a/frappe/desk/doctype/dashboard_chart/dashboard_chart.js b/frappe/desk/doctype/dashboard_chart/dashboard_chart.js index 0b93786e8e..b1c23eba28 100644 --- a/frappe/desk/doctype/dashboard_chart/dashboard_chart.js +++ b/frappe/desk/doctype/dashboard_chart/dashboard_chart.js @@ -1,42 +1,44 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.provide('frappe.dashboards.chart_sources'); +frappe.provide("frappe.dashboards.chart_sources"); -frappe.ui.form.on('Dashboard Chart', { - setup: function(frm) { +frappe.ui.form.on("Dashboard Chart", { + setup: function (frm) { // fetch timeseries from source - frm.add_fetch('source', 'timeseries', 'timeseries'); + frm.add_fetch("source", "timeseries", "timeseries"); }, - before_save: function(frm) { - let dynamic_filters = JSON.parse(frm.doc.dynamic_filters_json || 'null'); - let static_filters = JSON.parse(frm.doc.filters_json || 'null'); - static_filters = - frappe.dashboard_utils.remove_common_static_filter_values(static_filters, dynamic_filters); + before_save: function (frm) { + let dynamic_filters = JSON.parse(frm.doc.dynamic_filters_json || "null"); + let static_filters = JSON.parse(frm.doc.filters_json || "null"); + static_filters = frappe.dashboard_utils.remove_common_static_filter_values( + static_filters, + dynamic_filters + ); - frm.set_value('filters_json', JSON.stringify(static_filters)); - frm.trigger('show_filters'); + frm.set_value("filters_json", JSON.stringify(static_filters)); + frm.trigger("show_filters"); }, - refresh: function(frm) { + refresh: function (frm) { frm.chart_filters = null; frm.is_disabled = !frappe.boot.developer_mode && frm.doc.is_standard; if (frm.is_disabled) { - !frm.doc.custom_options && frm.set_df_property('chart_options_section', 'hidden', 1); + !frm.doc.custom_options && frm.set_df_property("chart_options_section", "hidden", 1); frm.disable_form(); } - frm.add_custom_button('Add Chart to Dashboard', () => { + frm.add_custom_button("Add Chart to Dashboard", () => { const dialog = frappe.dashboard_utils.get_add_to_dashboard_dialog( frm.doc.name, - 'Dashboard Chart', - 'frappe.desk.doctype.dashboard_chart.dashboard_chart.add_chart_to_dashboard' + "Dashboard Chart", + "frappe.desk.doctype.dashboard_chart.dashboard_chart.add_chart_to_dashboard" ); if (!frm.doc.chart_name) { - frappe.msgprint(__('Please create chart first')); + frappe.msgprint(__("Please create chart first")); } else { dialog.show(); } @@ -45,199 +47,227 @@ frappe.ui.form.on('Dashboard Chart', { frm.set_df_property("filters_section", "hidden", 1); frm.set_df_property("dynamic_filters_section", "hidden", 1); - frm.trigger('set_parent_document_type'); - frm.trigger('set_time_series'); - frm.set_query('document_type', function() { + frm.trigger("set_parent_document_type"); + frm.trigger("set_time_series"); + frm.set_query("document_type", function () { return { filters: { - 'issingle': false - } - } + issingle: false, + }, + }; }); - frm.trigger('update_options'); - frm.trigger('set_heatmap_year_options'); + frm.trigger("update_options"); + frm.trigger("set_heatmap_year_options"); if (frm.doc.report_name) { - frm.trigger('set_chart_report_filters'); + frm.trigger("set_chart_report_filters"); } }, - is_standard: function(frm) { + is_standard: function (frm) { if (frappe.boot.developer_mode && frm.doc.is_standard) { - frm.trigger('render_dynamic_filters_table'); + frm.trigger("render_dynamic_filters_table"); } else { frm.set_df_property("dynamic_filters_section", "hidden", 1); } }, - source: function(frm) { + source: function (frm) { frm.trigger("show_filters"); }, - set_heatmap_year_options: function(frm) { - if (frm.doc.type == 'Heatmap') { - frappe.db.get_doc('System Settings').then(doc => { + set_heatmap_year_options: function (frm) { + if (frm.doc.type == "Heatmap") { + frappe.db.get_doc("System Settings").then((doc) => { const creation_date = doc.creation; - frm.set_df_property('heatmap_year', 'options', frappe.dashboard_utils.get_years_since_creation(creation_date)); + frm.set_df_property( + "heatmap_year", + "options", + frappe.dashboard_utils.get_years_since_creation(creation_date) + ); }); } }, - chart_type: function(frm) { - frm.trigger('set_time_series'); - if (frm.doc.chart_type == 'Report') { - frm.set_query('report_name', () => { + chart_type: function (frm) { + frm.trigger("set_time_series"); + if (frm.doc.chart_type == "Report") { + frm.set_query("report_name", () => { return { filters: { - 'report_type': ['!=', 'Report Builder'] - } - } + report_type: ["!=", "Report Builder"], + }, + }; }); } else { - frm.set_value('document_type', ''); + frm.set_value("document_type", ""); } }, - set_time_series: function(frm) { + set_time_series: function (frm) { // set timeseries based on chart type - if (['Count', 'Average', 'Sum'].includes(frm.doc.chart_type)) { - frm.set_value('timeseries', 1); + if (["Count", "Average", "Sum"].includes(frm.doc.chart_type)) { + frm.set_value("timeseries", 1); } else { - frm.set_value('timeseries', 0); + frm.set_value("timeseries", 0); } }, - document_type: function(frm) { + document_type: function (frm) { // update `based_on` options based on date / datetime fields - frm.set_value('source', ''); - frm.set_value('based_on', ''); - frm.set_value('value_based_on', ''); - frm.set_value('parent_document_type', ''); - frm.set_value('filters_json', '[]'); - frm.set_value('dynamic_filters_json', '[]'); - frm.trigger('update_options'); - frm.trigger('set_parent_document_type'); + frm.set_value("source", ""); + frm.set_value("based_on", ""); + frm.set_value("value_based_on", ""); + frm.set_value("parent_document_type", ""); + frm.set_value("filters_json", "[]"); + frm.set_value("dynamic_filters_json", "[]"); + frm.trigger("update_options"); + frm.trigger("set_parent_document_type"); }, - report_name: function(frm) { - frm.set_value('x_field', ''); - frm.set_value('y_axis', []); - frm.set_df_property('x_field', 'options', []); - frm.set_value('filters_json', '{}'); - frm.set_value('dynamic_filters_json', '{}'); - frm.set_value('use_report_chart', 0); - frm.trigger('set_chart_report_filters'); + report_name: function (frm) { + frm.set_value("x_field", ""); + frm.set_value("y_axis", []); + frm.set_df_property("x_field", "options", []); + frm.set_value("filters_json", "{}"); + frm.set_value("dynamic_filters_json", "{}"); + frm.set_value("use_report_chart", 0); + frm.trigger("set_chart_report_filters"); }, - set_chart_report_filters: function(frm) { + set_chart_report_filters: function (frm) { let report_name = frm.doc.report_name; if (report_name) { if (frm.doc.filters_json.length > 2) { - frm.trigger('show_filters'); - frm.trigger('set_chart_field_options'); + frm.trigger("show_filters"); + frm.trigger("set_chart_field_options"); } else { - frappe.report_utils.get_report_filters(report_name).then(filters => { + frappe.report_utils.get_report_filters(report_name).then((filters) => { if (filters) { frm.chart_filters = filters; let filter_values = frappe.report_utils.get_filter_values(filters); - frm.set_value('filters_json', JSON.stringify(filter_values)); + frm.set_value("filters_json", JSON.stringify(filter_values)); } - frm.trigger('show_filters'); - frm.trigger('set_chart_field_options'); + frm.trigger("show_filters"); + frm.trigger("set_chart_field_options"); }); } - } }, - use_report_chart: function(frm) { - !frm.doc.use_report_chart && frm.trigger('set_chart_field_options'); + use_report_chart: function (frm) { + !frm.doc.use_report_chart && frm.trigger("set_chart_field_options"); }, - set_chart_field_options: function(frm) { + set_chart_field_options: function (frm) { let filters = frm.doc.filters_json.length > 2 ? JSON.parse(frm.doc.filters_json) : null; if (frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2) { filters = frappe.dashboard_utils.get_all_filters(frm.doc); } - frappe.xcall( - 'frappe.desk.query_report.run', - { + frappe + .xcall("frappe.desk.query_report.run", { report_name: frm.doc.report_name, filters: filters, - ignore_prepared_report: 1 - } - ).then(data => { - frm.report_data = data; - let report_has_chart = Boolean(data.chart); + ignore_prepared_report: 1, + }) + .then((data) => { + frm.report_data = data; + let report_has_chart = Boolean(data.chart); - frm.set_df_property('use_report_chart', 'hidden', !report_has_chart); + frm.set_df_property("use_report_chart", "hidden", !report_has_chart); - if (!frm.doc.use_report_chart) { - if (data.result.length) { - frm.field_options = frappe.report_utils.get_field_options_from_report(data.columns, data); - frm.set_df_property('x_field', 'options', frm.field_options.non_numeric_fields); - if (!frm.field_options.numeric_fields.length) { - frappe.msgprint(__("Report has no numeric fields, please change the Report Name")); + if (!frm.doc.use_report_chart) { + if (data.result.length) { + frm.field_options = frappe.report_utils.get_field_options_from_report( + data.columns, + data + ); + frm.set_df_property( + "x_field", + "options", + frm.field_options.non_numeric_fields + ); + if (!frm.field_options.numeric_fields.length) { + frappe.msgprint( + __("Report has no numeric fields, please change the Report Name") + ); + } else { + let y_field_df = frappe.meta.get_docfield( + "Dashboard Chart Field", + "y_field", + frm.doc.name + ); + y_field_df.options = frm.field_options.numeric_fields; + } } else { - let y_field_df = frappe.meta.get_docfield('Dashboard Chart Field', 'y_field', frm.doc.name); - y_field_df.options = frm.field_options.numeric_fields; + frappe.msgprint( + __( + "Report has no data, please modify the filters or change the Report Name" + ) + ); } } else { - frappe.msgprint(__('Report has no data, please modify the filters or change the Report Name')); + frm.set_value("use_report_chart", 1); + frm.set_df_property("use_report_chart", "hidden", false); } - } else { - frm.set_value('use_report_chart', 1); - frm.set_df_property('use_report_chart', 'hidden', false); - } - }); + }); }, - timespan: function(frm) { + timespan: function (frm) { const time_interval_options = { "Select Date Range": ["Quarterly", "Monthly", "Weekly", "Daily"], "All Time": ["Yearly", "Monthly"], "Last Year": ["Quarterly", "Monthly", "Weekly", "Daily"], "Last Quarter": ["Monthly", "Weekly", "Daily"], "Last Month": ["Weekly", "Daily"], - "Last Week": ["Daily"] + "Last Week": ["Daily"], }; if (frm.doc.timespan) { - frm.set_df_property('time_interval', 'options', time_interval_options[frm.doc.timespan]); + frm.set_df_property( + "time_interval", + "options", + time_interval_options[frm.doc.timespan] + ); } }, - update_options: function(frm) { + update_options: function (frm) { let doctype = frm.doc.document_type; let date_fields = [ - {label: __('Created On'), value: 'creation'}, - {label: __('Last Modified On'), value: 'modified'} + { label: __("Created On"), value: "creation" }, + { label: __("Last Modified On"), value: "modified" }, ]; let value_fields = []; - let group_by_fields = [{label: 'Created By', value: 'owner'}]; + let group_by_fields = [{ label: "Created By", value: "owner" }]; let aggregate_function_fields = []; - let update_form = function() { + let update_form = function () { // update select options - frm.set_df_property('based_on', 'options', date_fields); - frm.set_df_property('value_based_on', 'options', value_fields); - frm.set_df_property('group_by_based_on', 'options', group_by_fields); - frm.set_df_property('aggregate_function_based_on', 'options', aggregate_function_fields); + frm.set_df_property("based_on", "options", date_fields); + frm.set_df_property("value_based_on", "options", value_fields); + frm.set_df_property("group_by_based_on", "options", group_by_fields); + frm.set_df_property( + "aggregate_function_based_on", + "options", + aggregate_function_fields + ); frm.trigger("show_filters"); - } - + }; if (doctype) { frappe.model.with_doctype(doctype, () => { // get all date and datetime fields - frappe.get_meta(doctype).fields.map(df => { - if (['Date', 'Datetime'].includes(df.fieldtype)) { - date_fields.push({label: df.label, value: df.fieldname}); + frappe.get_meta(doctype).fields.map((df) => { + if (["Date", "Datetime"].includes(df.fieldtype)) { + date_fields.push({ label: df.label, value: df.fieldname }); } - if (['Int', 'Float', 'Currency', 'Percent', 'Duration'].includes(df.fieldtype)) { - value_fields.push({label: df.label, value: df.fieldname}); - aggregate_function_fields.push({label: df.label, value: df.fieldname}); + if ( + ["Int", "Float", "Currency", "Percent", "Duration"].includes(df.fieldtype) + ) { + value_fields.push({ label: df.label, value: df.fieldname }); + aggregate_function_fields.push({ label: df.label, value: df.fieldname }); } - if (['Link', 'Select'].includes(df.fieldtype)) { - group_by_fields.push({label: df.label, value: df.fieldname}); + if (["Link", "Select"].includes(df.fieldtype)) { + group_by_fields.push({ label: df.label, value: df.fieldname }); } }); update_form(); @@ -246,92 +276,89 @@ frappe.ui.form.on('Dashboard Chart', { // update select options update_form(); } - }, - show_filters: function(frm) { + show_filters: function (frm) { frm.chart_filters = []; - frappe.dashboard_utils.get_filters_for_chart_type(frm.doc).then(filters => { + frappe.dashboard_utils.get_filters_for_chart_type(frm.doc).then((filters) => { if (filters) { frm.chart_filters = filters; } - frm.trigger('render_filters_table'); + frm.trigger("render_filters_table"); if (frappe.boot.developer_mode && frm.doc.is_standard) { - frm.trigger('render_dynamic_filters_table'); + frm.trigger("render_dynamic_filters_table"); } }); }, - render_filters_table: function(frm) { + render_filters_table: function (frm) { frm.set_df_property("filters_section", "hidden", 0); - let is_document_type = frm.doc.chart_type!== 'Report' && frm.doc.chart_type!=='Custom'; - let is_dynamic_filter = f => ['Date', 'DateRange'].includes(f.fieldtype) && f.default; + let is_document_type = frm.doc.chart_type !== "Report" && frm.doc.chart_type !== "Custom"; + let is_dynamic_filter = (f) => ["Date", "DateRange"].includes(f.fieldtype) && f.default; - let wrapper = $(frm.get_field('filters_json').wrapper).empty(); + let wrapper = $(frm.get_field("filters_json").wrapper).empty(); let table = $(` - - - + + +
    ${__('Filter')}${__('Condition')}${__('Value')}${__("Filter")}${__("Condition")}${__("Value")}
    `).appendTo(wrapper); $(`

    ${__("Click table to edit")}

    `).appendTo(wrapper); - let filters = JSON.parse(frm.doc.filters_json || '[]'); + let filters = JSON.parse(frm.doc.filters_json || "[]"); var filters_set = false; // Set dynamic filters for reports - if (frm.doc.chart_type == 'Report') { + if (frm.doc.chart_type == "Report") { let set_filters = false; - frm.chart_filters.forEach(f => { + frm.chart_filters.forEach((f) => { if (is_dynamic_filter(f)) { filters[f.fieldname] = f.default; set_filters = true; } }); - set_filters && frm.set_value('filters_json', JSON.stringify(filters)); + set_filters && frm.set_value("filters_json", JSON.stringify(filters)); } let fields = []; if (is_document_type) { fields = [ { - fieldtype: 'HTML', - fieldname: 'filter_area', - } + fieldtype: "HTML", + fieldname: "filter_area", + }, ]; if (filters.length > 0) { - filters.forEach( filter => { - const filter_row = - $(` + filters.forEach((filter) => { + const filter_row = $(` ${filter[1]} ${filter[2] || ""} ${filter[3]} `); - table.find('tbody').append(filter_row); + table.find("tbody").append(filter_row); filters_set = true; }); } } else if (frm.chart_filters.length) { - fields = frm.chart_filters.filter(f => f.fieldname); + fields = frm.chart_filters.filter((f) => f.fieldname); - fields.map(f => { + fields.map((f) => { if (filters[f.fieldname]) { - let condition = '='; - const filter_row = - $(` + let condition = "="; + const filter_row = $(` ${f.label} ${condition} ${filters[f.fieldname] || ""} `); - table.find('tbody').append(filter_row); + table.find("tbody").append(filter_row); filters_set = true; } }); @@ -340,39 +367,39 @@ frappe.ui.form.on('Dashboard Chart', { if (!filters_set) { const filter_row = $(` ${__("Click to Set Filters")}`); - table.find('tbody').append(filter_row); + table.find("tbody").append(filter_row); } - table.on('click', () => { - frm.is_disabled && frappe.throw(__('Cannot edit filters for standard charts')); + table.on("click", () => { + frm.is_disabled && frappe.throw(__("Cannot edit filters for standard charts")); let dialog = new frappe.ui.Dialog({ - title: __('Set Filters'), - fields: fields.filter(f => !is_dynamic_filter(f)), - primary_action: function() { + title: __("Set Filters"), + fields: fields.filter((f) => !is_dynamic_filter(f)), + primary_action: function () { let values = this.get_values(); if (values) { this.hide(); if (is_document_type) { let filters = frm.filter_group.get_filters(); - frm.set_value('filters_json', JSON.stringify(filters)); + frm.set_value("filters_json", JSON.stringify(filters)); } else { - frm.set_value('filters_json', JSON.stringify(values)); + frm.set_value("filters_json", JSON.stringify(values)); } - frm.trigger('show_filters'); - if (frm.doc.chart_type == 'Report') { - frm.trigger('set_chart_report_filters'); + frm.trigger("show_filters"); + if (frm.doc.chart_type == "Report") { + frm.trigger("set_chart_report_filters"); } } }, - primary_action_label: "Set" + primary_action_label: "Set", }); frappe.dashboards.filters_dialog = dialog; if (is_document_type) { frm.filter_group = new frappe.ui.FilterGroup({ - parent: dialog.get_field('filter_area').$wrapper, + parent: dialog.get_field("filter_area").$wrapper, doctype: frm.doc.document_type, parent_doctype: frm.doc.parent_document_type, on_change: () => {}, @@ -383,12 +410,14 @@ frappe.ui.form.on('Dashboard Chart', { dialog.show(); - if (frm.doc.chart_type == 'Report') { + if (frm.doc.chart_type == "Report") { //Set query report object so that it can be used while fetching filter values in the report - frappe.query_report = new frappe.views.QueryReport({'filters': dialog.fields_list}); - frappe.query_reports[frm.doc.report_name] - && frappe.query_reports[frm.doc.report_name].onload - && frappe.query_reports[frm.doc.report_name].onload(frappe.query_report); + frappe.query_report = new frappe.views.QueryReport({ + filters: dialog.fields_list, + }); + frappe.query_reports[frm.doc.report_name] && + frappe.query_reports[frm.doc.report_name].onload && + frappe.query_reports[frm.doc.report_name].onload(frappe.query_report); } dialog.set_values(filters); @@ -398,37 +427,40 @@ frappe.ui.form.on('Dashboard Chart', { render_dynamic_filters_table(frm) { frm.set_df_property("dynamic_filters_section", "hidden", 0); - let is_document_type = frm.doc.chart_type !== 'Report' - && frm.doc.chart_type !== 'Custom'; + let is_document_type = frm.doc.chart_type !== "Report" && frm.doc.chart_type !== "Custom"; - let wrapper = $(frm.get_field('dynamic_filters_json').wrapper).empty(); + let wrapper = $(frm.get_field("dynamic_filters_json").wrapper).empty(); - frm.dynamic_filter_table = $(` + frm.dynamic_filter_table = + $(`
    - - - + + +
    ${__('Filter')}${__('Condition')}${__('Value')}${__("Filter")}${__("Condition")}${__("Value")}
    `).appendTo(wrapper); - frm.dynamic_filters = frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2 - ? JSON.parse(frm.doc.dynamic_filters_json) - : null; + frm.dynamic_filters = + frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2 + ? JSON.parse(frm.doc.dynamic_filters_json) + : null; - frm.trigger('set_dynamic_filters_in_table'); + frm.trigger("set_dynamic_filters_in_table"); - let filters = JSON.parse(frm.doc.filters_json || '[]'); + let filters = JSON.parse(frm.doc.filters_json || "[]"); let fields = frappe.dashboard_utils.get_fields_for_dynamic_filter_dialog( - is_document_type, filters, frm.dynamic_filters + is_document_type, + filters, + frm.dynamic_filters ); - frm.dynamic_filter_table.on('click', () => { + frm.dynamic_filter_table.on("click", () => { let dialog = new frappe.ui.Dialog({ - title: __('Set Dynamic Filters'), + title: __("Set Dynamic Filters"), fields: fields, primary_action: () => { let values = dialog.get_values(); @@ -436,19 +468,19 @@ frappe.ui.form.on('Dashboard Chart', { let dynamic_filters = []; for (let key of Object.keys(values)) { if (is_document_type) { - let [doctype, fieldname] = key.split(':'); - dynamic_filters.push([doctype, fieldname, '=', values[key]]); + let [doctype, fieldname] = key.split(":"); + dynamic_filters.push([doctype, fieldname, "=", values[key]]); } } if (is_document_type) { - frm.set_value('dynamic_filters_json', JSON.stringify(dynamic_filters)); + frm.set_value("dynamic_filters_json", JSON.stringify(dynamic_filters)); } else { - frm.set_value('dynamic_filters_json', JSON.stringify(values)); + frm.set_value("dynamic_filters_json", JSON.stringify(values)); } - frm.trigger('set_dynamic_filters_in_table'); + frm.trigger("set_dynamic_filters_in_table"); }, - primary_action_label: "Set" + primary_action_label: "Set", }); dialog.show(); @@ -456,71 +488,70 @@ frappe.ui.form.on('Dashboard Chart', { }); }, - set_dynamic_filters_in_table: function(frm) { - frm.dynamic_filters = frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2 - ? JSON.parse(frm.doc.dynamic_filters_json) - : null; + set_dynamic_filters_in_table: function (frm) { + frm.dynamic_filters = + frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2 + ? JSON.parse(frm.doc.dynamic_filters_json) + : null; if (!frm.dynamic_filters) { const filter_row = $(` ${__("Click to Set Dynamic Filters")}`); - frm.dynamic_filter_table.find('tbody').html(filter_row); + frm.dynamic_filter_table.find("tbody").html(filter_row); } else { - let filter_rows = ''; + let filter_rows = ""; if ($.isArray(frm.dynamic_filters)) { - frm.dynamic_filters.forEach(filter => { - filter_rows += - ` + frm.dynamic_filters.forEach((filter) => { + filter_rows += ` ${filter[1]} ${filter[2] || ""} ${filter[3]} `; }); } else { - let condition = '='; + let condition = "="; for (let [key, val] of Object.entries(frm.dynamic_filters)) { - filter_rows += - ` + filter_rows += ` ${key} ${condition} ${val || ""} - ` - ; + `; } } - frm.dynamic_filter_table.find('tbody').html(filter_rows); + frm.dynamic_filter_table.find("tbody").html(filter_rows); } }, - set_parent_document_type: async function(frm) { + set_parent_document_type: async function (frm) { let document_type = frm.doc.document_type; - let doc_is_table = document_type && - (await frappe.db.get_value('DocType', document_type, 'istable')).message.istable; + let doc_is_table = + document_type && + (await frappe.db.get_value("DocType", document_type, "istable")).message.istable; - frm.set_df_property('parent_document_type', 'hidden', !doc_is_table); + frm.set_df_property("parent_document_type", "hidden", !doc_is_table); if (document_type && doc_is_table) { - let parent = await frappe.db.get_list('DocField', { + let parent = await frappe.db.get_list("DocField", { filters: { - 'fieldtype': 'Table', - 'options': document_type + fieldtype: "Table", + options: document_type, }, - fields: ['parent'] + fields: ["parent"], }); - parent && frm.set_query('parent_document_type', function() { - return { - filters: { - "name": ['in', parent.map(({ parent }) => parent)] - } - }; - }); + parent && + frm.set_query("parent_document_type", function () { + return { + filters: { + name: ["in", parent.map(({ parent }) => parent)], + }, + }; + }); if (parent.length === 1) { - frm.set_value('parent_document_type', parent[0].parent); + frm.set_value("parent_document_type", parent[0].parent); } } - } - + }, }); diff --git a/frappe/desk/doctype/dashboard_chart_source/dashboard_chart_source.js b/frappe/desk/doctype/dashboard_chart_source/dashboard_chart_source.js index 96dd40d3c1..6f1fa36ffd 100644 --- a/frappe/desk/doctype/dashboard_chart_source/dashboard_chart_source.js +++ b/frappe/desk/doctype/dashboard_chart_source/dashboard_chart_source.js @@ -1,5 +1,4 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Dashboard Chart Source', { -}); +frappe.ui.form.on("Dashboard Chart Source", {}); diff --git a/frappe/desk/doctype/dashboard_settings/dashboard_settings.js b/frappe/desk/doctype/dashboard_settings/dashboard_settings.js index 8e7966366d..aa5be2b1a5 100644 --- a/frappe/desk/doctype/dashboard_settings/dashboard_settings.js +++ b/frappe/desk/doctype/dashboard_settings/dashboard_settings.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Dashboard Settings', { +frappe.ui.form.on("Dashboard Settings", { // refresh: function(frm) { - // } }); diff --git a/frappe/desk/doctype/desktop_icon/desktop_icon.js b/frappe/desk/doctype/desktop_icon/desktop_icon.js index 58ea09e732..72ef1f7a12 100644 --- a/frappe/desk/doctype/desktop_icon/desktop_icon.js +++ b/frappe/desk/doctype/desktop_icon/desktop_icon.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Desktop Icon', { - refresh: function(frm) { - - } +frappe.ui.form.on("Desktop Icon", { + refresh: function (frm) {}, }); diff --git a/frappe/desk/doctype/event/event.js b/frappe/desk/doctype/event/event.js index 87d78bae94..61bf66f5e5 100644 --- a/frappe/desk/doctype/event/event.js +++ b/frappe/desk/doctype/event/event.js @@ -3,70 +3,79 @@ frappe.provide("frappe.desk"); frappe.ui.form.on("Event", { - onload: function(frm) { - frm.set_query('reference_doctype', "event_participants", function() { - return { - "filters": { - "issingle": 0, - } - }; - }); - frm.set_query('google_calendar', function() { + onload: function (frm) { + frm.set_query("reference_doctype", "event_participants", function () { return { filters: { - "owner": frappe.session.user - } + issingle: 0, + }, + }; + }); + frm.set_query("google_calendar", function () { + return { + filters: { + owner: frappe.session.user, + }, }; }); }, - refresh: function(frm) { - if(frm.doc.event_participants) { - frm.doc.event_participants.forEach(value => { - frm.add_custom_button(__(value.reference_docname), function() { - frappe.set_route("Form", value.reference_doctype, value.reference_docname); - }, __("Participants")); - }) + refresh: function (frm) { + if (frm.doc.event_participants) { + frm.doc.event_participants.forEach((value) => { + frm.add_custom_button( + __(value.reference_docname), + function () { + frappe.set_route("Form", value.reference_doctype, value.reference_docname); + }, + __("Participants") + ); + }); } frm.page.set_inner_btn_group_as_primary(__("Add Participants")); - frm.add_custom_button(__('Add Contacts'), function() { - new frappe.desk.eventParticipants(frm, "Contact"); - }, __("Add Participants")); + frm.add_custom_button( + __("Add Contacts"), + function () { + new frappe.desk.eventParticipants(frm, "Contact"); + }, + __("Add Participants") + ); }, - repeat_on: function(frm) { - if(frm.doc.repeat_on==="Every Day") { - ["monday", "tuesday", "wednesday", "thursday", - "friday", "saturday", "sunday"].map(function(v) { + repeat_on: function (frm) { + if (frm.doc.repeat_on === "Every Day") { + ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"].map( + function (v) { frm.set_value(v, 1); - }); + } + ); } - } + }, }); frappe.ui.form.on("Event Participants", { - event_participants_remove: function(frm, cdt, cdn) { - if (cdt&&!cdn.includes("New Event Participants")){ + event_participants_remove: function (frm, cdt, cdn) { + if (cdt && !cdn.includes("New Event Participants")) { frappe.call({ type: "POST", method: "frappe.desk.doctype.event.event.delete_communication", args: { - "event": frm.doc, - "reference_doctype": cdt, - "reference_docname": cdn + event: frm.doc, + reference_doctype: cdt, + reference_docname: cdn, }, freeze: true, - callback: function(r) { - if(r.exc) { + callback: function (r) { + if (r.exc) { frappe.show_alert({ message: __("{0}", [r.exc]), - indicator: 'orange' + indicator: "orange", }); } - } + }, }); } - } + }, }); frappe.desk.eventParticipants = class eventParticipants { @@ -86,7 +95,7 @@ frappe.desk.eventParticipants = class eventParticipants { dynamic_link_reference: me.doctype, fieldname: "reference_docname", target: table, - txt: "" + txt: "", }); } }; diff --git a/frappe/desk/doctype/event/event_calendar.js b/frappe/desk/doctype/event/event_calendar.js index df474a0258..bfdd09b864 100644 --- a/frappe/desk/doctype/event/event_calendar.js +++ b/frappe/desk/doctype/event/event_calendar.js @@ -1,16 +1,16 @@ frappe.views.calendar["Event"] = { field_map: { - "start": "starts_on", - "end": "ends_on", - "id": "name", - "allDay": "all_day", - "title": "subject", - "status": "event_type", - "color": "color" + start: "starts_on", + end: "ends_on", + id: "name", + allDay: "all_day", + title: "subject", + status: "event_type", + color: "color", }, style_map: { - "Public": "success", - "Private": "info" + Public: "success", + Private: "info", }, - get_events_method: "frappe.desk.doctype.event.event.get_events" -} \ No newline at end of file + get_events_method: "frappe.desk.doctype.event.event.get_events", +}; diff --git a/frappe/desk/doctype/event/event_list.js b/frappe/desk/doctype/event/event_list.js index 5d73d9dd1a..f6460288d8 100644 --- a/frappe/desk/doctype/event/event_list.js +++ b/frappe/desk/doctype/event/event_list.js @@ -1,8 +1,8 @@ -frappe.listview_settings['Event'] = { +frappe.listview_settings["Event"] = { add_fields: ["starts_on", "ends_on"], - onload: function() { + onload: function () { frappe.route_options = { - "status": "Open" + status: "Open", }; - } -} \ No newline at end of file + }, +}; diff --git a/frappe/desk/doctype/form_tour/form_tour.js b/frappe/desk/doctype/form_tour/form_tour.js index 3f3fc0ff8a..1e67e10779 100644 --- a/frappe/desk/doctype/form_tour/form_tour.js +++ b/frappe/desk/doctype/form_tour/form_tour.js @@ -1,10 +1,10 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Form Tour', { - setup: function(frm) { +frappe.ui.form.on("Form Tour", { + setup: function (frm) { if (!frm.doc.is_standard || frappe.boot.developer_mode) { - frm.trigger('setup_queries'); + frm.trigger("setup_queries"); } }, @@ -13,28 +13,26 @@ frappe.ui.form.on('Form Tour', { frm.trigger("disable_form"); } - frm.add_custom_button(__('Show Tour'), async () => { + frm.add_custom_button(__("Show Tour"), async () => { const issingle = await check_if_single(frm.doc.reference_doctype); let route_changed = null; if (issingle) { - route_changed = frappe.set_route('Form', frm.doc.reference_doctype); + route_changed = frappe.set_route("Form", frm.doc.reference_doctype); } else if (frm.doc.first_document) { const name = await get_first_document(frm.doc.reference_doctype); - route_changed = frappe.set_route('Form', frm.doc.reference_doctype, name); + route_changed = frappe.set_route("Form", frm.doc.reference_doctype, name); } else { - route_changed = frappe.set_route('Form', frm.doc.reference_doctype, 'new'); + route_changed = frappe.set_route("Form", frm.doc.reference_doctype, "new"); } route_changed.then(() => { const tour_name = frm.doc.name; - cur_frm.tour - .init({ tour_name }) - .then(() => cur_frm.tour.start()); + cur_frm.tour.init({ tour_name }).then(() => cur_frm.tour.start()); }); }); }, - disable_form: function(frm) { + disable_form: function (frm) { frm.set_read_only(); frm.fields .filter((field) => field.has_input) @@ -45,51 +43,48 @@ frappe.ui.form.on('Form Tour', { }, setup_queries(frm) { - frm.set_query("reference_doctype", function() { + frm.set_query("reference_doctype", function () { return { filters: { - istable: 0 - } + istable: 0, + }, }; }); - frm.trigger('reference_doctype'); + frm.trigger("reference_doctype"); }, reference_doctype(frm) { if (!frm.doc.reference_doctype) return; - frm.set_fields_as_options( - "fieldname", - frm.doc.reference_doctype, - df => !df.hidden - ).then(options => { - frm.fields_dict.steps.grid.update_docfield_property( - "fieldname", - "options", - [""].concat(options) - ); - }); + frm.set_fields_as_options("fieldname", frm.doc.reference_doctype, (df) => !df.hidden).then( + (options) => { + frm.fields_dict.steps.grid.update_docfield_property( + "fieldname", + "options", + [""].concat(options) + ); + } + ); frm.set_fields_as_options( - 'parent_fieldname', + "parent_fieldname", frm.doc.reference_doctype, - (df) => df.fieldtype == "Table" && !df.hidden, - ).then(options => { + (df) => df.fieldtype == "Table" && !df.hidden + ).then((options) => { frm.fields_dict.steps.grid.update_docfield_property( "parent_fieldname", "options", [""].concat(options) ); }); - - } + }, }); -frappe.ui.form.on('Form Tour Step', { +frappe.ui.form.on("Form Tour Step", { form_render(frm, cdt, cdn) { if (locals[cdt][cdn].is_table_field) { - frm.trigger('parent_fieldname', cdt, cdn); + frm.trigger("parent_fieldname", cdt, cdn); } }, parent_fieldname(frm, cdt, cdn) { @@ -97,37 +92,36 @@ frappe.ui.form.on('Form Tour Step', { const parent_fieldname_df = frappe .get_meta(frm.doc.reference_doctype) - .fields.find(df => df.fieldname == child_row.parent_fieldname); + .fields.find((df) => df.fieldname == child_row.parent_fieldname); frm.set_fields_as_options( - 'fieldname', + "fieldname", parent_fieldname_df.options, - (df) => !df.hidden, - ).then(options => { + (df) => !df.hidden + ).then((options) => { frm.fields_dict.steps.grid.update_docfield_property( "fieldname", "options", [""].concat(options) ); if (child_row.fieldname) { - frappe.model.set_value(cdt, cdn, 'fieldname', child_row.fieldname); + frappe.model.set_value(cdt, cdn, "fieldname", child_row.fieldname); } }); - } + }, }); async function check_if_single(doctype) { - const { message } = await frappe.db.get_value('DocType', doctype, 'issingle'); + const { message } = await frappe.db.get_value("DocType", doctype, "issingle"); return message.issingle || 0; } async function get_first_document(doctype) { let docname; - await frappe.db.get_list(doctype, { order_by: "creation" }).then(res => { - if (Array.isArray(res) && res.length) - docname = res[0].name; + await frappe.db.get_list(doctype, { order_by: "creation" }).then((res) => { + if (Array.isArray(res) && res.length) docname = res[0].name; }); - return docname || 'new'; + return docname || "new"; } diff --git a/frappe/desk/doctype/global_search_settings/global_search_settings.js b/frappe/desk/doctype/global_search_settings/global_search_settings.js index c333f83585..147a72eef1 100644 --- a/frappe/desk/doctype/global_search_settings/global_search_settings.js +++ b/frappe/desk/doctype/global_search_settings/global_search_settings.js @@ -1,14 +1,17 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Global Search Settings', { - refresh: function(frm) { - - frappe.realtime.on('global_search_settings', (data) => { +frappe.ui.form.on("Global Search Settings", { + refresh: function (frm) { + frappe.realtime.on("global_search_settings", (data) => { if (data.progress) { - frm.dashboard.show_progress('Setting up Global Search', data.progress / data.total * 100, data.msg); + frm.dashboard.show_progress( + "Setting up Global Search", + (data.progress / data.total) * 100, + data.msg + ); if (data.progress === data.total) { - frm.dashboard.hide_progress('Setting up Global Search'); + frm.dashboard.hide_progress("Setting up Global Search"); } } }); @@ -16,14 +19,14 @@ frappe.ui.form.on('Global Search Settings', { frm.add_custom_button(__("Reset"), function () { frappe.call({ method: "frappe.desk.doctype.global_search_settings.global_search_settings.reset_global_search_settings_doctypes", - callback: function() { + callback: function () { frappe.show_alert({ message: __("Global Search Document Types Reset."), - indicator: "green" + indicator: "green", }); frm.refresh(); - } + }, }); }); - } + }, }); diff --git a/frappe/desk/doctype/kanban_board/kanban_board.js b/frappe/desk/doctype/kanban_board/kanban_board.js index ff80a58fa0..3b815fef0e 100644 --- a/frappe/desk/doctype/kanban_board/kanban_board.js +++ b/frappe/desk/doctype/kanban_board/kanban_board.js @@ -1,43 +1,45 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Kanban Board', { - onload: function(frm) { - frm.trigger('reference_doctype'); +frappe.ui.form.on("Kanban Board", { + onload: function (frm) { + frm.trigger("reference_doctype"); }, - refresh: function(frm) { - if(frm.is_new()) return; - frm.add_custom_button("Show Board", function() { + refresh: function (frm) { + if (frm.is_new()) return; + frm.add_custom_button("Show Board", function () { frappe.set_route("List", frm.doc.reference_doctype, "Kanban", frm.doc.name); }); }, - reference_doctype: function(frm) { - + reference_doctype: function (frm) { // set field options - if(!frm.doc.reference_doctype) return; + if (!frm.doc.reference_doctype) return; - frappe.model.with_doctype(frm.doc.reference_doctype, function() { - var options = $.map(frappe.get_meta(frm.doc.reference_doctype).fields, - function(d) { - if(d.fieldname && d.fieldtype === 'Select' && - frappe.model.no_value_type.indexOf(d.fieldtype)===-1) { - return d.fieldname; - } - return null; - }); - frm.set_df_property('field_name', 'options', options); - frm.get_field('field_name').refresh(); + frappe.model.with_doctype(frm.doc.reference_doctype, function () { + var options = $.map(frappe.get_meta(frm.doc.reference_doctype).fields, function (d) { + if ( + d.fieldname && + d.fieldtype === "Select" && + frappe.model.no_value_type.indexOf(d.fieldtype) === -1 + ) { + return d.fieldname; + } + return null; + }); + frm.set_df_property("field_name", "options", options); + frm.get_field("field_name").refresh(); }); }, - field_name: function(frm) { + field_name: function (frm) { var field = frappe.meta.get_field(frm.doc.reference_doctype, frm.doc.field_name); frm.doc.columns = []; - field.options && field.options.split('\n').forEach(function(o) { - o = o.trim(); - if(!o) return; - var d = frm.add_child('columns'); - d.column_name = o; - }); + field.options && + field.options.split("\n").forEach(function (o) { + o = o.trim(); + if (!o) return; + var d = frm.add_child("columns"); + d.column_name = o; + }); frm.refresh(); - } + }, }); diff --git a/frappe/desk/doctype/list_view_settings/list_view_settings.js b/frappe/desk/doctype/list_view_settings/list_view_settings.js index db33f71675..007a242dd3 100644 --- a/frappe/desk/doctype/list_view_settings/list_view_settings.js +++ b/frappe/desk/doctype/list_view_settings/list_view_settings.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('List View Settings', { +frappe.ui.form.on("List View Settings", { // refresh: function(frm) { - // } -}); \ No newline at end of file +}); diff --git a/frappe/desk/doctype/module_onboarding/module_onboarding.js b/frappe/desk/doctype/module_onboarding/module_onboarding.js index d95920e2ca..0e312025bf 100644 --- a/frappe/desk/doctype/module_onboarding/module_onboarding.js +++ b/frappe/desk/doctype/module_onboarding/module_onboarding.js @@ -2,7 +2,7 @@ // For license information, please see license.txt frappe.ui.form.on("Module Onboarding", { - refresh: function(frm) { + refresh: function (frm) { frappe.boot.developer_mode && frm.set_intro( __( @@ -15,7 +15,7 @@ frappe.ui.form.on("Module Onboarding", { } }, - disable_form: function(frm) { + disable_form: function (frm) { frm.set_read_only(); frm.fields .filter((field) => field.has_input) diff --git a/frappe/desk/doctype/note/note.js b/frappe/desk/doctype/note/note.js index 5718180b70..dd556a3969 100644 --- a/frappe/desk/doctype/note/note.js +++ b/frappe/desk/doctype/note/note.js @@ -1,5 +1,5 @@ frappe.ui.form.on("Note", { - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.__islocal) { frm.events.set_editable(frm, true); } else { @@ -8,13 +8,13 @@ frappe.ui.form.on("Note", { } // toggle edit - frm.add_custom_button("Edit", function() { + frm.add_custom_button("Edit", function () { frm.events.set_editable(frm, !frm.is_note_editable); }); frm.events.set_editable(frm, false); } }, - set_editable: function(frm, editable) { + set_editable: function (frm, editable) { // hide all fields other than content // no permission @@ -24,7 +24,7 @@ frappe.ui.form.on("Note", { frm.set_df_property("content", "read_only", editable ? 0 : 1); // hide all other fields - $.each(frm.fields_dict, function(fieldname) { + $.each(frm.fields_dict, function (fieldname) { if (fieldname !== "content") { frm.set_df_property(fieldname, "hidden", editable ? 0 : 1); } @@ -36,10 +36,10 @@ frappe.ui.form.on("Note", { // set flag for toggle frm.is_note_editable = editable; - } + }, }); -frappe.tour['Note'] = [ +frappe.tour["Note"] = [ { fieldname: "title", title: "Title of the Note", @@ -48,6 +48,7 @@ frappe.tour['Note'] = [ { fieldname: "public", title: "Sets the Note to Public", - description: "You can change the visibility of the note with this, setting it to public will allow other users to view it.", + description: + "You can change the visibility of the note with this, setting it to public will allow other users to view it.", }, -]; \ No newline at end of file +]; diff --git a/frappe/desk/doctype/note/note_list.js b/frappe/desk/doctype/note/note_list.js index f7f8d37dcf..1e0ed40880 100644 --- a/frappe/desk/doctype/note/note_list.js +++ b/frappe/desk/doctype/note/note_list.js @@ -1,13 +1,13 @@ -frappe.listview_settings['Note'] = { - onload: function(me) { +frappe.listview_settings["Note"] = { + onload: function (me) { me.page.set_title(__("Notes")); }, add_fields: ["title", "public"], - get_indicator: function(doc) { - if(doc.public) { + get_indicator: function (doc) { + if (doc.public) { return [__("Public"), "green", "public,=,Yes"]; } else { return [__("Private"), "gray", "public,=,No"]; } - } -} + }, +}; diff --git a/frappe/desk/doctype/notification_log/notification_log.js b/frappe/desk/doctype/notification_log/notification_log.js index 1f381d115b..ea5fdc6400 100644 --- a/frappe/desk/doctype/notification_log/notification_log.js +++ b/frappe/desk/doctype/notification_log/notification_log.js @@ -1,25 +1,25 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Notification Log', { - refresh: function(frm) { +frappe.ui.form.on("Notification Log", { + refresh: function (frm) { if (frm.doc.attached_file) { - frm.trigger('set_attachment'); + frm.trigger("set_attachment"); } else { - frm.get_field('attachment_link').$wrapper.empty(); + frm.get_field("attachment_link").$wrapper.empty(); } }, - open_reference_document: function(frm) { + open_reference_document: function (frm) { const dt = frm.doc.document_type; const dn = frm.doc.document_name; - frappe.set_route('Form', dt, dn); + frappe.set_route("Form", dt, dn); }, - set_attachment: function(frm) { + set_attachment: function (frm) { const attachment = JSON.parse(frm.doc.attached_file); - const $wrapper = frm.get_field('attachment_link').$wrapper; + const $wrapper = frm.get_field("attachment_link").$wrapper; $wrapper.html(`
    @@ -41,5 +41,5 @@ frappe.ui.form.on('Notification Log', { frappe.msgprint(__("Please enable pop-ups")); } }); - } + }, }); diff --git a/frappe/desk/doctype/notification_settings/notification_settings.js b/frappe/desk/doctype/notification_settings/notification_settings.js index cc2fd95204..ba72369273 100644 --- a/frappe/desk/doctype/notification_settings/notification_settings.js +++ b/frappe/desk/doctype/notification_settings/notification_settings.js @@ -1,28 +1,27 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Notification Settings', { +frappe.ui.form.on("Notification Settings", { onload: (frm) => { frappe.breadcrumbs.add({ - label: __('Settings'), - route: '#modules/Settings', - type: 'Custom' + label: __("Settings"), + route: "#modules/Settings", + type: "Custom", }); - frm.set_query('subscribed_documents', () => { + frm.set_query("subscribed_documents", () => { return { filters: { - istable: 0 - } + istable: 0, + }, }; }); }, refresh: (frm) => { - if (frappe.user.has_role('System Manager')) { - frm.add_custom_button(__('Go to Notification Settings List'), () => { - frappe.set_route('List', 'Notification Settings'); + if (frappe.user.has_role("System Manager")) { + frm.add_custom_button(__("Go to Notification Settings List"), () => { + frappe.set_route("List", "Notification Settings"); }); } - } - + }, }); diff --git a/frappe/desk/doctype/number_card/number_card.js b/frappe/desk/doctype/number_card/number_card.js index 79ddb71187..77ab2b4ef8 100644 --- a/frappe/desk/doctype/number_card/number_card.js +++ b/frappe/desk/doctype/number_card/number_card.js @@ -1,73 +1,75 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Number Card', { - refresh: function(frm) { +frappe.ui.form.on("Number Card", { + refresh: function (frm) { if (!frappe.boot.developer_mode && frm.doc.is_standard) { frm.disable_form(); } frm.set_df_property("filters_section", "hidden", 1); frm.set_df_property("dynamic_filters_section", "hidden", 1); - frm.trigger('set_options'); + frm.trigger("set_options"); if (!frm.doc.type) { - frm.set_value('type', 'Document Type'); + frm.set_value("type", "Document Type"); } - if (frm.doc.type == 'Report' && frm.doc.report_name) { - frm.trigger('set_report_filters'); + if (frm.doc.type == "Report" && frm.doc.report_name) { + frm.trigger("set_report_filters"); } - if (frm.doc.type == 'Custom') { + if (frm.doc.type == "Custom") { if (!frappe.boot.developer_mode) { frm.disable_form(); } frm.filters = eval(frm.doc.filters_config); - frm.trigger('set_filters_description'); - frm.trigger('set_method_description'); - frm.trigger('render_filters_table'); + frm.trigger("set_filters_description"); + frm.trigger("set_method_description"); + frm.trigger("render_filters_table"); } - frm.trigger('set_parent_document_type'); + frm.trigger("set_parent_document_type"); if (!frm.is_new()) { - frm.trigger('create_add_to_dashboard_button'); + frm.trigger("create_add_to_dashboard_button"); } }, - create_add_to_dashboard_button: function(frm) { - frm.add_custom_button('Add Card to Dashboard', () => { + create_add_to_dashboard_button: function (frm) { + frm.add_custom_button("Add Card to Dashboard", () => { const dialog = frappe.dashboard_utils.get_add_to_dashboard_dialog( frm.doc.name, - 'Number Card', - 'frappe.desk.doctype.number_card.number_card.add_card_to_dashboard' + "Number Card", + "frappe.desk.doctype.number_card.number_card.add_card_to_dashboard" ); if (!frm.doc.name) { - frappe.msgprint(__('Please create Card first')); + frappe.msgprint(__("Please create Card first")); } else { dialog.show(); } }); }, - before_save: function(frm) { - let dynamic_filters = JSON.parse(frm.doc.dynamic_filters_json || 'null'); - let static_filters = JSON.parse(frm.doc.filters_json || 'null'); - static_filters = - frappe.dashboard_utils.remove_common_static_filter_values(static_filters, dynamic_filters); + before_save: function (frm) { + let dynamic_filters = JSON.parse(frm.doc.dynamic_filters_json || "null"); + let static_filters = JSON.parse(frm.doc.filters_json || "null"); + static_filters = frappe.dashboard_utils.remove_common_static_filter_values( + static_filters, + dynamic_filters + ); - frm.set_value('filters_json', JSON.stringify(static_filters)); - frm.trigger('render_filters_table'); - frm.trigger('render_dynamic_filters_table'); + frm.set_value("filters_json", JSON.stringify(static_filters)); + frm.trigger("render_filters_table"); + frm.trigger("render_dynamic_filters_table"); }, - is_standard: function(frm) { - frm.trigger('render_dynamic_filters_table'); + is_standard: function (frm) { + frm.trigger("render_dynamic_filters_table"); frm.set_df_property("dynamic_filters_section", "hidden", 1); }, - set_filters_description: function(frm) { - if (frm.doc.type == 'Custom') { + set_filters_description: function (frm) { + if (frm.doc.type == "Custom") { frm.fields_dict.filters_config.set_description(` Set the filters here. For example:
    @@ -91,8 +93,8 @@ frappe.ui.form.on('Number Card', {
     		}
     	},
     
    -	set_method_description: function(frm) {
    -		if (frm.doc.type == 'Custom') {
    +	set_method_description: function (frm) {
    +		if (frm.doc.type == "Custom") {
     			frm.fields_dict.method.set_description(`
     		Set the path to a whitelisted function that will return the number on the card in the format:
     
    @@ -105,53 +107,52 @@ frappe.ui.form.on('Number Card', {
     		}
     	},
     
    -	type: function(frm) {
    -		frm.trigger('set_filters_description');
    -		if (frm.doc.type == 'Report') {
    -			frm.set_query('report_name', () => {
    +	type: function (frm) {
    +		frm.trigger("set_filters_description");
    +		if (frm.doc.type == "Report") {
    +			frm.set_query("report_name", () => {
     				return {
     					filters: {
    -						'report_type': ['!=', 'Report Builder']
    -					}
    +						report_type: ["!=", "Report Builder"],
    +					},
     				};
     			});
     		}
    -
     	},
     
    -	report_name: function(frm) {
    +	report_name: function (frm) {
     		frm.filters = [];
    -		frm.set_value('filters_json', '{}');
    -		frm.set_value('dynamic_filters_json', '{}');
    -		frm.set_df_property('report_field', 'options', []);
    -		frm.trigger('set_report_filters');
    +		frm.set_value("filters_json", "{}");
    +		frm.set_value("dynamic_filters_json", "{}");
    +		frm.set_df_property("report_field", "options", []);
    +		frm.trigger("set_report_filters");
     	},
     
    -	filters_config: function(frm) {
    +	filters_config: function (frm) {
     		frm.filters = eval(frm.doc.filters_config);
     		const filter_values = frappe.report_utils.get_filter_values(frm.filters);
    -		frm.set_value('filters_json', JSON.stringify(filter_values));
    -		frm.trigger('render_filters_table');
    +		frm.set_value("filters_json", JSON.stringify(filter_values));
    +		frm.trigger("render_filters_table");
     	},
     
    -	document_type: function(frm) {
    -		frm.set_query('document_type', function() {
    +	document_type: function (frm) {
    +		frm.set_query("document_type", function () {
     			return {
     				filters: {
    -					'issingle': false
    -				}
    +					issingle: false,
    +				},
     			};
     		});
    -		frm.set_value('filters_json', '[]');
    -		frm.set_value('dynamic_filters_json', '[]');
    -		frm.set_value('aggregate_function_based_on', '');
    -		frm.set_value('parent_document_type', '');
    -		frm.trigger('set_options');
    -		frm.trigger('set_parent_document_type');
    +		frm.set_value("filters_json", "[]");
    +		frm.set_value("dynamic_filters_json", "[]");
    +		frm.set_value("aggregate_function_based_on", "");
    +		frm.set_value("parent_document_type", "");
    +		frm.trigger("set_options");
    +		frm.trigger("set_parent_document_type");
     	},
     
    -	set_options: function(frm) {
    -		if (frm.doc.type !== 'Document Type') {
    +	set_options: function (frm) {
    +		if (frm.doc.type !== "Document Type") {
     			return;
     		}
     
    @@ -160,134 +161,148 @@ frappe.ui.form.on('Number Card', {
     
     		if (doctype) {
     			frappe.model.with_doctype(doctype, () => {
    -				frappe.get_meta(doctype).fields.map(df => {
    +				frappe.get_meta(doctype).fields.map((df) => {
     					if (frappe.model.numeric_fieldtypes.includes(df.fieldtype)) {
    -						if (df.fieldtype == 'Currency') {
    -							if (!df.options || df.options !== 'Company:company:default_currency') {
    +						if (df.fieldtype == "Currency") {
    +							if (!df.options || df.options !== "Company:company:default_currency") {
     								return;
     							}
     						}
    -						aggregate_based_on_fields.push({label: df.label, value: df.fieldname});
    +						aggregate_based_on_fields.push({ label: df.label, value: df.fieldname });
     					}
     				});
     
    -				frm.set_df_property('aggregate_function_based_on', 'options', aggregate_based_on_fields);
    +				frm.set_df_property(
    +					"aggregate_function_based_on",
    +					"options",
    +					aggregate_based_on_fields
    +				);
     			});
    -			frm.trigger('render_filters_table');
    -			frm.trigger('render_dynamic_filters_table');
    +			frm.trigger("render_filters_table");
    +			frm.trigger("render_dynamic_filters_table");
     		}
     	},
     
    -	set_report_filters: function(frm) {
    +	set_report_filters: function (frm) {
     		const report_name = frm.doc.report_name;
     		if (report_name) {
    -			frappe.report_utils.get_report_filters(report_name).then(filters => {
    +			frappe.report_utils.get_report_filters(report_name).then((filters) => {
     				if (filters) {
     					frm.filters = filters;
     					const filter_values = frappe.report_utils.get_filter_values(filters);
     					if (frm.doc.filters_json.length <= 2) {
    -						frm.set_value('filters_json', JSON.stringify(filter_values));
    +						frm.set_value("filters_json", JSON.stringify(filter_values));
     					}
     				}
    -				frm.trigger('render_filters_table');
    -				frm.trigger('set_report_field_options');
    -				frm.trigger('render_dynamic_filters_table');
    +				frm.trigger("render_filters_table");
    +				frm.trigger("set_report_field_options");
    +				frm.trigger("render_dynamic_filters_table");
     			});
     		}
     	},
     
    -	set_report_field_options: function(frm) {
    +	set_report_field_options: function (frm) {
     		let filters = frm.doc.filters_json.length > 2 ? JSON.parse(frm.doc.filters_json) : null;
     		if (frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2) {
     			filters = frappe.dashboard_utils.get_all_filters(frm.doc);
     		}
    -		frappe.xcall(
    -			'frappe.desk.query_report.run',
    -			{
    +		frappe
    +			.xcall("frappe.desk.query_report.run", {
     				report_name: frm.doc.report_name,
     				filters: filters,
    -				ignore_prepared_report: 1
    -			}
    -		).then(data => {
    -			if (data.result.length) {
    -				frm.field_options = frappe.report_utils.get_field_options_from_report(data.columns, data);
    -				frm.set_df_property('report_field', 'options', frm.field_options.numeric_fields);
    -				if (!frm.field_options.numeric_fields.length) {
    -					frappe.msgprint(__("Report has no numeric fields, please change the Report Name"));
    +				ignore_prepared_report: 1,
    +			})
    +			.then((data) => {
    +				if (data.result.length) {
    +					frm.field_options = frappe.report_utils.get_field_options_from_report(
    +						data.columns,
    +						data
    +					);
    +					frm.set_df_property(
    +						"report_field",
    +						"options",
    +						frm.field_options.numeric_fields
    +					);
    +					if (!frm.field_options.numeric_fields.length) {
    +						frappe.msgprint(
    +							__("Report has no numeric fields, please change the Report Name")
    +						);
    +					}
    +				} else {
    +					frappe.msgprint(
    +						__(
    +							"Report has no data, please modify the filters or change the Report Name"
    +						)
    +					);
     				}
    -			} else {
    -				frappe.msgprint(__('Report has no data, please modify the filters or change the Report Name'));
    -			}
    -		});
    +			});
     	},
     
    -	render_filters_table: function(frm) {
    +	render_filters_table: function (frm) {
     		frm.set_df_property("filters_section", "hidden", 0);
    -		let is_document_type = frm.doc.type == 'Document Type';
    -		let is_dynamic_filter = f => ['Date', 'DateRange'].includes(f.fieldtype) && f.default;
    +		let is_document_type = frm.doc.type == "Document Type";
    +		let is_dynamic_filter = (f) => ["Date", "DateRange"].includes(f.fieldtype) && f.default;
     
    -		let wrapper = $(frm.get_field('filters_json').wrapper).empty();
    +		let wrapper = $(frm.get_field("filters_json").wrapper).empty();
     		let table = $(`
    -					
    -					
    -					
    +					
    +					
    +					
    ${__('Filter')}${__('Condition')}${__('Value')}${__("Filter")}${__("Condition")}${__("Value")}
    `).appendTo(wrapper); $(`

    ${__("Click table to edit")}

    `).appendTo(wrapper); - let filters = JSON.parse(frm.doc.filters_json || '[]'); + let filters = JSON.parse(frm.doc.filters_json || "[]"); let filters_set = false; // Set dynamic filters for reports - if (frm.doc.type == 'Report') { + if (frm.doc.type == "Report") { let set_filters = false; - frm.filters.forEach(f => { + frm.filters.forEach((f) => { if (is_dynamic_filter(f)) { filters[f.fieldname] = f.default; set_filters = true; } }); - set_filters && frm.set_value('filters_json', JSON.stringify(filters)); + set_filters && frm.set_value("filters_json", JSON.stringify(filters)); } let fields = []; if (is_document_type) { fields = [ { - fieldtype: 'HTML', - fieldname: 'filter_area', - } + fieldtype: "HTML", + fieldname: "filter_area", + }, ]; if (filters.length) { - filters.forEach(filter => { - const filter_row = - $(` + filters.forEach((filter) => { + const filter_row = $(` ${filter[1]} ${filter[2] || ""} ${filter[3]} `); - table.find('tbody').append(filter_row); + table.find("tbody").append(filter_row); }); filters_set = true; } } else if (frm.filters.length) { - fields = frm.filters.filter(f => f.fieldname); - fields.map(f => { + fields = frm.filters.filter((f) => f.fieldname); + fields.map((f) => { if (filters[f.fieldname]) { - let condition = '='; - const filter_row = - $(` + let condition = "="; + const filter_row = $(` ${f.label} ${condition} ${filters[f.fieldname] || ""} `); - table.find('tbody').append(filter_row); + table.find("tbody").append(filter_row); if (!filters_set) filters_set = true; } }); @@ -296,32 +311,32 @@ frappe.ui.form.on('Number Card', { if (!filters_set) { const filter_row = $(` ${__("Click to Set Filters")}`); - table.find('tbody').append(filter_row); + table.find("tbody").append(filter_row); } - table.on('click', () => { + table.on("click", () => { let dialog = new frappe.ui.Dialog({ - title: __('Set Filters'), - fields: fields.filter(f => !is_dynamic_filter(f)), - primary_action: function() { + title: __("Set Filters"), + fields: fields.filter((f) => !is_dynamic_filter(f)), + primary_action: function () { let values = this.get_values(); if (values) { this.hide(); if (is_document_type) { let filters = frm.filter_group.get_filters(); - frm.set_value('filters_json', JSON.stringify(filters)); + frm.set_value("filters_json", JSON.stringify(filters)); } else { - frm.set_value('filters_json', JSON.stringify(values)); + frm.set_value("filters_json", JSON.stringify(values)); } - frm.trigger('render_filters_table'); + frm.trigger("render_filters_table"); } }, - primary_action_label: "Set" + primary_action_label: "Set", }); if (is_document_type) { frm.filter_group = new frappe.ui.FilterGroup({ - parent: dialog.get_field('filter_area').$wrapper, + parent: dialog.get_field("filter_area").$wrapper, doctype: frm.doc.document_type, parent_doctype: frm.doc.parent_document_type, on_change: () => {}, @@ -331,56 +346,61 @@ frappe.ui.form.on('Number Card', { dialog.show(); - if (frm.doc.type == 'Report') { + if (frm.doc.type == "Report") { //Set query report object so that it can be used while fetching filter values in the report - frappe.query_report = new frappe.views.QueryReport({'filters': dialog.fields_list}); - frappe.query_reports[frm.doc.report_name] - && frappe.query_reports[frm.doc.report_name].onload - && frappe.query_reports[frm.doc.report_name].onload(frappe.query_report); + frappe.query_report = new frappe.views.QueryReport({ + filters: dialog.fields_list, + }); + frappe.query_reports[frm.doc.report_name] && + frappe.query_reports[frm.doc.report_name].onload && + frappe.query_reports[frm.doc.report_name].onload(frappe.query_report); } dialog.set_values(filters); }); - }, render_dynamic_filters_table(frm) { - if (!frappe.boot.developer_mode || !frm.doc.is_standard || frm.doc.type == 'Custom') { + if (!frappe.boot.developer_mode || !frm.doc.is_standard || frm.doc.type == "Custom") { return; } frm.set_df_property("dynamic_filters_section", "hidden", 0); - let is_document_type = frm.doc.type == 'Document Type'; + let is_document_type = frm.doc.type == "Document Type"; - let wrapper = $(frm.get_field('dynamic_filters_json').wrapper).empty(); + let wrapper = $(frm.get_field("dynamic_filters_json").wrapper).empty(); - frm.dynamic_filter_table = $(` + frm.dynamic_filter_table = + $(`
    - - - + + +
    ${__('Filter')}${__('Condition')}${__('Value')}${__("Filter")}${__("Condition")}${__("Value")}
    `).appendTo(wrapper); - frm.dynamic_filters = frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2 - ? JSON.parse(frm.doc.dynamic_filters_json) - : null; + frm.dynamic_filters = + frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2 + ? JSON.parse(frm.doc.dynamic_filters_json) + : null; - frm.trigger('set_dynamic_filters_in_table'); + frm.trigger("set_dynamic_filters_in_table"); - let filters = JSON.parse(frm.doc.filters_json || '[]'); + let filters = JSON.parse(frm.doc.filters_json || "[]"); let fields = frappe.dashboard_utils.get_fields_for_dynamic_filter_dialog( - is_document_type, filters, frm.dynamic_filters + is_document_type, + filters, + frm.dynamic_filters ); - frm.dynamic_filter_table.on('click', () => { + frm.dynamic_filter_table.on("click", () => { let dialog = new frappe.ui.Dialog({ - title: __('Set Dynamic Filters'), + title: __("Set Dynamic Filters"), fields: fields, primary_action: () => { let values = dialog.get_values(); @@ -388,19 +408,19 @@ frappe.ui.form.on('Number Card', { let dynamic_filters = []; for (let key of Object.keys(values)) { if (is_document_type) { - let [doctype, fieldname] = key.split(':'); - dynamic_filters.push([doctype, fieldname, '=', values[key]]); + let [doctype, fieldname] = key.split(":"); + dynamic_filters.push([doctype, fieldname, "=", values[key]]); } } if (is_document_type) { - frm.set_value('dynamic_filters_json', JSON.stringify(dynamic_filters)); + frm.set_value("dynamic_filters_json", JSON.stringify(dynamic_filters)); } else { - frm.set_value('dynamic_filters_json', JSON.stringify(values)); + frm.set_value("dynamic_filters_json", JSON.stringify(values)); } - frm.trigger('set_dynamic_filters_in_table'); + frm.trigger("set_dynamic_filters_in_table"); }, - primary_action_label: "Set" + primary_action_label: "Set", }); dialog.show(); @@ -408,71 +428,70 @@ frappe.ui.form.on('Number Card', { }); }, - set_dynamic_filters_in_table: function(frm) { - frm.dynamic_filters = frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2 - ? JSON.parse(frm.doc.dynamic_filters_json) - : null; + set_dynamic_filters_in_table: function (frm) { + frm.dynamic_filters = + frm.doc.dynamic_filters_json && frm.doc.dynamic_filters_json.length > 2 + ? JSON.parse(frm.doc.dynamic_filters_json) + : null; if (!frm.dynamic_filters) { const filter_row = $(` ${__("Click to Set Dynamic Filters")}`); - frm.dynamic_filter_table.find('tbody').html(filter_row); + frm.dynamic_filter_table.find("tbody").html(filter_row); } else { - let filter_rows = ''; + let filter_rows = ""; if ($.isArray(frm.dynamic_filters)) { - frm.dynamic_filters.forEach(filter => { - filter_rows += - ` + frm.dynamic_filters.forEach((filter) => { + filter_rows += ` ${filter[1]} ${filter[2] || ""} ${filter[3]} `; }); } else { - let condition = '='; + let condition = "="; for (let [key, val] of Object.entries(frm.dynamic_filters)) { - filter_rows += - ` + filter_rows += ` ${key} ${condition} ${val || ""} - ` - ; + `; } } - frm.dynamic_filter_table.find('tbody').html(filter_rows); + frm.dynamic_filter_table.find("tbody").html(filter_rows); } }, - set_parent_document_type: async function(frm) { + set_parent_document_type: async function (frm) { let document_type = frm.doc.document_type; - let doc_is_table = document_type && - (await frappe.db.get_value('DocType', document_type, 'istable')).message.istable; + let doc_is_table = + document_type && + (await frappe.db.get_value("DocType", document_type, "istable")).message.istable; - frm.set_df_property('parent_document_type', 'hidden', !doc_is_table); + frm.set_df_property("parent_document_type", "hidden", !doc_is_table); if (document_type && doc_is_table) { - let parent = await frappe.db.get_list('DocField', { + let parent = await frappe.db.get_list("DocField", { filters: { - 'fieldtype': 'Table', - 'options': document_type + fieldtype: "Table", + options: document_type, }, - fields: ['parent'] + fields: ["parent"], }); - parent && frm.set_query('parent_document_type', function() { - return { - filters: { - "name": ['in', parent.map(({ parent }) => parent)] - } - }; - }); + parent && + frm.set_query("parent_document_type", function () { + return { + filters: { + name: ["in", parent.map(({ parent }) => parent)], + }, + }; + }); if (parent.length === 1) { - frm.set_value('parent_document_type', parent[0].parent); + frm.set_value("parent_document_type", parent[0].parent); } } - } - + }, }); diff --git a/frappe/desk/doctype/onboarding_permission/onboarding_permission.js b/frappe/desk/doctype/onboarding_permission/onboarding_permission.js index 752b8a02cc..ec2c8a03b0 100644 --- a/frappe/desk/doctype/onboarding_permission/onboarding_permission.js +++ b/frappe/desk/doctype/onboarding_permission/onboarding_permission.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Onboarding Permission', { +frappe.ui.form.on("Onboarding Permission", { // refresh: function(frm) { - // } }); diff --git a/frappe/desk/doctype/onboarding_step/onboarding_step.js b/frappe/desk/doctype/onboarding_step/onboarding_step.js index 3c9bbab9ac..67b2ed0501 100644 --- a/frappe/desk/doctype/onboarding_step/onboarding_step.js +++ b/frappe/desk/doctype/onboarding_step/onboarding_step.js @@ -2,18 +2,17 @@ // For license information, please see license.txt frappe.ui.form.on("Onboarding Step", { - - setup: function(frm) { - frm.set_query("form_tour", function() { + setup: function (frm) { + frm.set_query("form_tour", function () { return { filters: { - reference_doctype: frm.doc.reference_document - } + reference_doctype: frm.doc.reference_document, + }, }; }); }, - refresh: function(frm) { + refresh: function (frm) { frappe.boot.developer_mode && frm.set_intro( __( @@ -30,15 +29,16 @@ frappe.ui.form.on("Onboarding Step", { } }, - reference_document: function(frm) { + reference_document: function (frm) { if (frm.doc.reference_document && frm.doc.action == "Update Settings") { setup_fields(frm); } }, - action: function(frm) { + action: function (frm) { if (frm.doc.action == "Show Form Tour") { - frm.fields_dict.reference_document.set_description(`You need to add the steps in the contoller JS file. For example: note.js + frm.fields_dict.reference_document + .set_description(`You need to add the steps in the contoller JS file. For example: note.js
    
     frappe.tour['Note'] = [
     	{
    @@ -54,7 +54,7 @@ frappe.tour['Note'] = [
     		}
     	},
     
    -	disable_form: function(frm) {
    +	disable_form: function (frm) {
     		frm.set_read_only();
     		frm.fields
     			.filter((field) => field.has_input)
    @@ -71,9 +71,7 @@ function setup_fields(frm) {
     			let fields = frappe
     				.get_meta(frm.doc.reference_document)
     				.fields.filter((df) => {
    -					return ["Data", "Check", "Int", "Link", "Select"].includes(
    -						df.fieldtype
    -					);
    +					return ["Data", "Check", "Int", "Link", "Select"].includes(df.fieldtype);
     				})
     				.map((df) => {
     					return {
    diff --git a/frappe/desk/doctype/route_history/route_history.js b/frappe/desk/doctype/route_history/route_history.js
    index 19689e406b..c68d4e2b54 100644
    --- a/frappe/desk/doctype/route_history/route_history.js
    +++ b/frappe/desk/doctype/route_history/route_history.js
    @@ -1,8 +1,6 @@
     // Copyright (c) 2018, Frappe Technologies and contributors
     // For license information, please see license.txt
     
    -frappe.ui.form.on('Route History', {
    -	refresh: function() {
    -
    -	}
    +frappe.ui.form.on("Route History", {
    +	refresh: function () {},
     });
    diff --git a/frappe/desk/doctype/route_history/route_history_list.js b/frappe/desk/doctype/route_history/route_history_list.js
    index 84a441852c..03bf86b9fd 100644
    --- a/frappe/desk/doctype/route_history/route_history_list.js
    +++ b/frappe/desk/doctype/route_history/route_history_list.js
    @@ -1,7 +1,7 @@
     frappe.listview_settings["Route History"] = {
    -	onload: function(listview) {
    +	onload: function (listview) {
     		frappe.require("logtypes.bundle.js", () => {
     			frappe.utils.logtypes.show_log_retention_message(cur_list.doctype);
    -		})
    +		});
     	},
     };
    diff --git a/frappe/desk/doctype/system_console/system_console.js b/frappe/desk/doctype/system_console/system_console.js
    index 7751ffe860..dc73f33b67 100644
    --- a/frappe/desk/doctype/system_console/system_console.js
    +++ b/frappe/desk/doctype/system_console/system_console.js
    @@ -1,21 +1,21 @@
     // Copyright (c) 2020, Frappe Technologies and contributors
     // For license information, please see license.txt
     
    -frappe.ui.form.on('System Console', {
    -	onload: function(frm) {
    +frappe.ui.form.on("System Console", {
    +	onload: function (frm) {
     		frappe.ui.keys.add_shortcut({
    -			shortcut: 'shift+enter',
    -			action: () => frm.page.btn_primary.trigger('click'),
    +			shortcut: "shift+enter",
    +			action: () => frm.page.btn_primary.trigger("click"),
     			page: frm.page,
    -			description: __('Execute Console script'),
    +			description: __("Execute Console script"),
     			ignore_inputs: true,
     		});
     		frm.set_value("type", "Python");
     	},
     
    -	refresh: function(frm) {
    +	refresh: function (frm) {
     		frm.disable_save();
    -		frm.page.set_primary_action(__("Execute"), $btn => {
    +		frm.page.set_primary_action(__("Execute"), ($btn) => {
     			$btn.text(__("Executing..."));
     			return frm
     				.execute_action("Execute")
    @@ -24,7 +24,7 @@ frappe.ui.form.on('System Console', {
     		});
     	},
     
    -	type: function(frm) {
    +	type: function (frm) {
     		if (frm.doc.type == "Python") {
     			frm.set_value("output", "");
     			if (frm.sql_output) {
    @@ -34,7 +34,7 @@ frappe.ui.form.on('System Console', {
     		}
     	},
     
    -	render_sql_output: function(frm) {
    +	render_sql_output: function (frm) {
     		if (frm.doc.type !== "SQL") return;
     		if (frm.sql_output) {
     			frm.sql_output.destroy();
    @@ -46,50 +46,51 @@ frappe.ui.form.on('System Console', {
     		}
     
     		let result = JSON.parse(frm.doc.output);
    -		frm.set_value("output", `${result.length} ${result.length == 1 ? 'row' : 'rows'}`);
    +		frm.set_value("output", `${result.length} ${result.length == 1 ? "row" : "rows"}`);
     
     		if (result.length) {
     			let columns = Object.keys(result[0]);
    -			frm.sql_output = new DataTable(
    -				frm.get_field("sql_output").$wrapper.get(0),
    -				{
    -					columns,
    -					data: result
    -				}
    -			);
    +			frm.sql_output = new DataTable(frm.get_field("sql_output").$wrapper.get(0), {
    +				columns,
    +				data: result,
    +			});
     		}
     	},
     
    -	show_processlist: function(frm) {
    +	show_processlist: function (frm) {
     		if (frm.doc.show_processlist) {
     			// keep refreshing every 5 seconds
     			frm.events.refresh_processlist(frm);
    -			frm.processlist_interval = setInterval(() => frm.events.refresh_processlist(frm), 5000);
    +			frm.processlist_interval = setInterval(
    +				() => frm.events.refresh_processlist(frm),
    +				5000
    +			);
     		} else {
     			if (frm.processlist_interval) {
    -
     				// end it
     				clearInterval(frm.processlist_interval);
    -				frm.get_field("processlist").html('');
    +				frm.get_field("processlist").html("");
     			}
     		}
     	},
     
    -	refresh_processlist: function(frm) {
    +	refresh_processlist: function (frm) {
     		let timestamp = new Date();
    -		frappe.call('frappe.desk.doctype.system_console.system_console.show_processlist').then(r => {
    -			let rows = '';
    -			for (let row of r.message) {
    -				rows += `
    +		frappe
    +			.call("frappe.desk.doctype.system_console.system_console.show_processlist")
    +			.then((r) => {
    +				let rows = "";
    +				for (let row of r.message) {
    +					rows += `
     					${row.Id}
     					${row.Time}
     					${row.State}
     					${row.Info}
     					${row.Progress}
    -				`
    -			}
    +				`;
    +				}
     
    -			frm.get_field('processlist').html(`
    +				frm.get_field("processlist").html(`
     				

    Requested on: ${timestamp}

    @@ -100,6 +101,6 @@ frappe.ui.form.on('System Console', { ${rows}`); - }); + }); }, }); diff --git a/frappe/desk/doctype/tag/tag.js b/frappe/desk/doctype/tag/tag.js index f55f98c3d0..1c60f417e0 100644 --- a/frappe/desk/doctype/tag/tag.js +++ b/frappe/desk/doctype/tag/tag.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Tag', { +frappe.ui.form.on("Tag", { // refresh: function(frm) { - // } }); diff --git a/frappe/desk/doctype/tag_link/tag_link.js b/frappe/desk/doctype/tag_link/tag_link.js index d85655bb90..e2cb4fcd7f 100644 --- a/frappe/desk/doctype/tag_link/tag_link.js +++ b/frappe/desk/doctype/tag_link/tag_link.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Tag Link', { +frappe.ui.form.on("Tag Link", { // refresh: function(frm) { - // } }); diff --git a/frappe/desk/doctype/todo/todo.js b/frappe/desk/doctype/todo/todo.js index 0317281371..6c1af67d2b 100644 --- a/frappe/desk/doctype/todo/todo.js +++ b/frappe/desk/doctype/todo/todo.js @@ -1,40 +1,55 @@ // bind events frappe.ui.form.on("ToDo", { - onload: function(frm) { - frm.set_query("reference_type", function(txt) { + onload: function (frm) { + frm.set_query("reference_type", function (txt) { return { - "filters": { - "issingle": 0, - } + filters: { + issingle: 0, + }, }; }); }, - refresh: function(frm) { - if(frm.doc.reference_type && frm.doc.reference_name) { - frm.add_custom_button(__(frm.doc.reference_name), function() { + refresh: function (frm) { + if (frm.doc.reference_type && frm.doc.reference_name) { + frm.add_custom_button(__(frm.doc.reference_name), function () { frappe.set_route("Form", frm.doc.reference_type, frm.doc.reference_name); }); } if (!frm.doc.__islocal) { - if(frm.doc.status!=="Closed") { - frm.add_custom_button(__("Close"), function() { - frm.set_value("status", "Closed"); - frm.save(null, function() { - // back to list - frappe.set_route("List", "ToDo"); - }); - }, "fa fa-check", "btn-success"); + if (frm.doc.status !== "Closed") { + frm.add_custom_button( + __("Close"), + function () { + frm.set_value("status", "Closed"); + frm.save(null, function () { + // back to list + frappe.set_route("List", "ToDo"); + }); + }, + "fa fa-check", + "btn-success" + ); } else { - frm.add_custom_button(__("Reopen"), function() { - frm.set_value("status", "Open"); - frm.save(); - }, null, "btn-default"); + frm.add_custom_button( + __("Reopen"), + function () { + frm.set_value("status", "Open"); + frm.save(); + }, + null, + "btn-default" + ); } - frm.add_custom_button(__("New"), function() { - frappe.new_doc("ToDo") - }, null, "btn-default"); + frm.add_custom_button( + __("New"), + function () { + frappe.new_doc("ToDo"); + }, + null, + "btn-default" + ); } - } + }, }); diff --git a/frappe/desk/doctype/todo/todo_calendar.js b/frappe/desk/doctype/todo/todo_calendar.js index 8ba020fac1..f79243a86e 100644 --- a/frappe/desk/doctype/todo/todo_calendar.js +++ b/frappe/desk/doctype/todo/todo_calendar.js @@ -3,29 +3,27 @@ frappe.views.calendar["ToDo"] = { field_map: { - "start": "date", - "end": "date", - "id": "name", - "title": "description", - "allDay": "allDay", - "progress": "progress" + start: "date", + end: "date", + id: "name", + title: "description", + allDay: "allDay", + progress: "progress", }, gantt: true, filters: [ { - "fieldtype": "Link", - "fieldname": "reference_type", - "options": "Task", - "label": __("Task") + fieldtype: "Link", + fieldname: "reference_type", + options: "Task", + label: __("Task"), }, { - "fieldtype": "Dynamic Link", - "fieldname": "reference_name", - "options": "reference_type", - "label": __("Task") - } - + fieldtype: "Dynamic Link", + fieldname: "reference_name", + options: "reference_type", + label: __("Task"), + }, ], - get_events_method: "frappe.desk.calendar.get_events" + get_events_method: "frappe.desk.calendar.get_events", }; - diff --git a/frappe/desk/doctype/todo/todo_list.js b/frappe/desk/doctype/todo/todo_list.js index 53564cc017..2e4534e05c 100644 --- a/frappe/desk/doctype/todo/todo_list.js +++ b/frappe/desk/doctype/todo/todo_list.js @@ -1,40 +1,44 @@ -frappe.listview_settings['ToDo'] = { +frappe.listview_settings["ToDo"] = { hide_name_column: true, add_fields: ["reference_type", "reference_name"], - onload: function(me) { + onload: function (me) { if (!frappe.route_options) { frappe.route_options = { - "owner": frappe.session.user, - "status": "Open" + owner: frappe.session.user, + status: "Open", }; } me.page.set_title(__("To Do")); }, button: { - show: function(doc) { + show: function (doc) { return doc.reference_name; }, - get_label: function() { - return __('Open'); + get_label: function () { + return __("Open"); }, - get_description: function(doc) { - return __('Open {0}', [`${doc.reference_type} ${doc.reference_name}`]) + get_description: function (doc) { + return __("Open {0}", [`${doc.reference_type} ${doc.reference_name}`]); + }, + action: function (doc) { + frappe.set_route("Form", doc.reference_type, doc.reference_name); }, - action: function(doc) { - frappe.set_route('Form', doc.reference_type, doc.reference_name); - } }, - refresh: function(me) { + refresh: function (me) { if (me.todo_sidebar_setup) return; // add assigned by me - me.page.add_sidebar_item(__("Assigned By Me"), function() { - me.filter_area.add([[me.doctype, "assigned_by", '=', frappe.session.user]]); - }, ('.list-link[data-view="Kanban"]')); + me.page.add_sidebar_item( + __("Assigned By Me"), + function () { + me.filter_area.add([[me.doctype, "assigned_by", "=", frappe.session.user]]); + }, + '.list-link[data-view="Kanban"]' + ); me.todo_sidebar_setup = true; }, -} \ No newline at end of file +}; diff --git a/frappe/desk/doctype/workspace/workspace.js b/frappe/desk/doctype/workspace/workspace.js index 3f912127fc..25721f9ae2 100644 --- a/frappe/desk/doctype/workspace/workspace.js +++ b/frappe/desk/doctype/workspace/workspace.js @@ -1,26 +1,30 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Workspace', { - setup: function() { - frappe.meta.get_field('Workspace Link', 'only_for').no_default = true; +frappe.ui.form.on("Workspace", { + setup: function () { + frappe.meta.get_field("Workspace Link", "only_for").no_default = true; }, - refresh: function(frm) { + refresh: function (frm) { frm.enable_save(); - if (frm.doc.for_user || (frm.doc.public && !frm.has_perm('write') && - !frappe.user.has_role('Workspace Manager'))) { - frm.trigger('disable_form'); + if ( + frm.doc.for_user || + (frm.doc.public && + !frm.has_perm("write") && + !frappe.user.has_role("Workspace Manager")) + ) { + frm.trigger("disable_form"); } }, - disable_form: function(frm) { + disable_form: function (frm) { frm.fields - .filter(field => field.has_input) - .forEach(field => { + .filter((field) => field.has_input) + .forEach((field) => { frm.set_df_property(field.df.fieldname, "read_only", "1"); }); frm.disable_save(); - } -}); \ No newline at end of file + }, +}); diff --git a/frappe/desk/page/activity/activity.js b/frappe/desk/page/activity/activity.js index 7b4e8ddc1a..0291edb225 100644 --- a/frappe/desk/page/activity/activity.js +++ b/frappe/desk/page/activity/activity.js @@ -3,12 +3,12 @@ frappe.provide("frappe.activity"); -frappe.pages['activity'].on_page_load = function (wrapper) { +frappe.pages["activity"].on_page_load = function (wrapper) { var me = this; frappe.ui.make_app_page({ parent: wrapper, - single_column: true + single_column: true, }); me.page = wrapper.page; @@ -16,8 +16,8 @@ frappe.pages['activity'].on_page_load = function (wrapper) { frappe.model.with_doctype("Communication", function () { me.page.list = new frappe.views.Activity({ - doctype: 'Communication', - parent: wrapper + doctype: "Communication", + parent: wrapper, }); }); @@ -29,17 +29,21 @@ frappe.pages['activity'].on_page_load = function (wrapper) { doctype = $(this).attr("data-doctype"), docname = $(this).attr("data-docname"); - [link_doctype, link_name, doctype, docname] = - [link_doctype, link_name, doctype, docname].map(decodeURIComponent); + [link_doctype, link_name, doctype, docname] = [ + link_doctype, + link_name, + doctype, + docname, + ].map(decodeURIComponent); - link_doctype = link_doctype && link_doctype !== 'null' ? link_doctype : null; - link_name = link_name && link_name !== 'null' ? link_name : null; + link_doctype = link_doctype && link_doctype !== "null" ? link_doctype : null; + link_name = link_name && link_name !== "null" ? link_name : null; if (doctype && docname) { if (link_doctype && link_name) { frappe.route_options = { - scroll_to: { "doctype": doctype, "name": docname } - } + scroll_to: { doctype: doctype, name: docname }, + }; } frappe.set_route(["Form", link_doctype || doctype, link_name || docname]); @@ -48,37 +52,46 @@ frappe.pages['activity'].on_page_load = function (wrapper) { // Build Report Button if (frappe.boot.user.can_get_report.indexOf("Feed") != -1) { - this.page.add_menu_item(__('Build Report'), function () { - frappe.set_route("List", "Feed", "Report"); - }, 'fa fa-th') + this.page.add_menu_item( + __("Build Report"), + function () { + frappe.set_route("List", "Feed", "Report"); + }, + "fa fa-th" + ); } - this.page.add_menu_item(__('Activity Log'), function () { - frappe.route_options = { - "user": frappe.session.user - } + this.page.add_menu_item( + __("Activity Log"), + function () { + frappe.route_options = { + user: frappe.session.user, + }; - frappe.set_route("List", "Activity Log", "Report"); - }, 'fa fa-th'); + frappe.set_route("List", "Activity Log", "Report"); + }, + "fa fa-th" + ); }; -frappe.pages['activity'].on_page_show = function () { +frappe.pages["activity"].on_page_show = function () { frappe.breadcrumbs.add("Desk"); -} +}; frappe.activity.last_feed_date = false; frappe.activity.Feed = class Feed { constructor(row, data) { this.scrub_data(data); this.add_date_separator(row, data); - if (!data.add_class) - data.add_class = "label-default"; + if (!data.add_class) data.add_class = "label-default"; data.link = ""; if (data.link_doctype && data.link_name) { - data.link = frappe.format(data.link_name, { fieldtype: "Link", options: data.link_doctype }, - { label: __(data.link_doctype) + " " + __(data.link_name) }); - + data.link = frappe.format( + data.link_name, + { fieldtype: "Link", options: data.link_doctype }, + { label: __(data.link_doctype) + " " + __(data.link_name) } + ); } else if (data.feed_type === "Comment" && data.comment_type === "Comment") { // hack for backward compatiblity data.link_doctype = data.reference_doctype; @@ -86,17 +99,20 @@ frappe.activity.Feed = class Feed { data.reference_doctype = "Communication"; data.reference_name = data.name; - data.link = frappe.format(data.link_name, { fieldtype: "Link", options: data.link_doctype }, - { label: __(data.link_doctype) + " " + __(data.link_name) }); - + data.link = frappe.format( + data.link_name, + { fieldtype: "Link", options: data.link_doctype }, + { label: __(data.link_doctype) + " " + __(data.link_name) } + ); } else if (data.reference_doctype && data.reference_name) { - data.link = frappe.format(data.reference_name, { fieldtype: "Link", options: data.reference_doctype }, - { label: __(data.reference_doctype) + " " + __(data.reference_name) }); + data.link = frappe.format( + data.reference_name, + { fieldtype: "Link", options: data.reference_doctype }, + { label: __(data.reference_doctype) + " " + __(data.reference_name) } + ); } - $(row) - .append(frappe.render_template("activity_row", data)) - .find("a").addClass("grey"); + $(row).append(frappe.render_template("activity_row", data)).find("a").addClass("grey"); } scrub_data(data) { @@ -106,11 +122,12 @@ frappe.activity.Feed = class Feed { data.icon = "fa fa-flag"; // color for comment - data.add_class = { - "Comment": "label-danger", - "Assignment": "label-warning", - "Login": "label-default" - }[data.comment_type || data.communication_medium] || "label-info" + data.add_class = + { + Comment: "label-danger", + Assignment: "label-warning", + Login: "label-default", + }[data.comment_type || data.communication_medium] || "label-info"; data.when = comment_when(data.creation); data.feed_type = data.comment_type || data.communication_medium; @@ -120,18 +137,24 @@ frappe.activity.Feed = class Feed { var date = frappe.datetime.str_to_obj(data.creation); var last = frappe.activity.last_feed_date; - if ((last && frappe.datetime.obj_to_str(last) != frappe.datetime.obj_to_str(date)) || (!last)) { - var diff = frappe.datetime.get_day_diff(frappe.datetime.get_today(), frappe.datetime.obj_to_str(date)); + if ( + (last && frappe.datetime.obj_to_str(last) != frappe.datetime.obj_to_str(date)) || + !last + ) { + var diff = frappe.datetime.get_day_diff( + frappe.datetime.get_today(), + frappe.datetime.obj_to_str(date) + ); var pdate; if (diff < 1) { - pdate = 'Today'; + pdate = "Today"; } else if (diff < 2) { - pdate = 'Yesterday'; + pdate = "Yesterday"; } else { pdate = frappe.datetime.global_date_format(date); } data.date_sep = pdate; - data.date_class = pdate == 'Today' ? "date-indicator blue" : "date-indicator"; + data.date_class = pdate == "Today" ? "date-indicator blue" : "date-indicator"; } else { data.date_sep = null; data.date_class = ""; @@ -141,26 +164,28 @@ frappe.activity.Feed = class Feed { }; frappe.activity.render_heatmap = function (page) { - $('
    \ + $( + '
    \
    \ -
    ').prependTo(page.main); +
    ' + ).prependTo(page.main); frappe.call({ method: "frappe.desk.page.activity.activity.get_heatmap_data", callback: function (r) { if (r.message) { new frappe.Chart(".heatmap", { - type: 'heatmap', - start: new Date(moment().subtract(1, 'year').toDate()), + type: "heatmap", + start: new Date(moment().subtract(1, "year").toDate()), countLabel: "actions", discreteDomains: 1, radius: 3, // default 0 data: { - 'dataPoints': r.message - } + dataPoints: r.message, + }, }); } - } + }, }); }; @@ -173,10 +198,9 @@ frappe.views.Activity = class Activity extends frappe.views.BaseList { setup_defaults() { super.setup_defaults(); - this.page_title = __('Activity'); - this.doctype = 'Communication'; - this.method = 'frappe.desk.page.activity.activity.get_feed'; - + this.page_title = __("Activity"); + this.doctype = "Communication"; + this.method = "frappe.desk.page.activity.activity.get_feed"; } setup_filter_area() { @@ -187,18 +211,14 @@ frappe.views.Activity = class Activity extends frappe.views.BaseList { // } - setup_sort_selector() { + setup_sort_selector() {} - } - - setup_side_bar() { - - } + setup_side_bar() {} get_args() { return { start: this.start, - page_length: this.page_length + page_length: this.page_length, }; } @@ -213,8 +233,11 @@ frappe.views.Activity = class Activity extends frappe.views.BaseList { } render() { - this.data.map(value => { - const row = $('
    ').data("data", value).appendTo(this.$result).get(0); + this.data.map((value) => { + const row = $('
    ') + .data("data", value) + .appendTo(this.$result) + .get(0); new frappe.activity.Feed(row, value); }); } diff --git a/frappe/desk/page/backups/backups.js b/frappe/desk/page/backups/backups.js index d6cab750f0..08289cab2d 100644 --- a/frappe/desk/page/backups/backups.js +++ b/frappe/desk/page/backups/backups.js @@ -1,18 +1,18 @@ -frappe.pages['backups'].on_page_load = function (wrapper) { +frappe.pages["backups"].on_page_load = function (wrapper) { var page = frappe.ui.make_app_page({ parent: wrapper, - title: __('Download Backups'), - single_column: true + title: __("Download Backups"), + single_column: true, }); page.add_inner_button(__("Set Number of Backups"), function () { - frappe.set_route('Form', 'System Settings'); + frappe.set_route("Form", "System Settings"); }); page.add_inner_button(__("Download Files Backup"), function () { frappe.call({ method: "frappe.desk.page.backups.backups.schedule_files_backup", - args: { "user_email": frappe.session.user_email } + args: { user_email: frappe.session.user_email }, }); }); @@ -23,18 +23,18 @@ frappe.pages['backups'].on_page_load = function (wrapper) { method: "frappe.utils.backups.get_backup_encryption_key", callback: function (r) { frappe.msgprint({ - title: __('Backup Encryption Key'), + title: __("Backup Encryption Key"), message: __(r.message), - indicator: 'blue' + indicator: "blue", }); - } + }, }); }); } else { frappe.msgprint({ - title: __('Error'), - message: __('System Manager privileges required.'), - indicator: 'red' + title: __("Error"), + message: __("System Manager privileges required."), + indicator: "red", }); } }); diff --git a/frappe/desk/page/leaderboard/leaderboard.js b/frappe/desk/page/leaderboard/leaderboard.js index aa1678af37..845dac0d63 100644 --- a/frappe/desk/page/leaderboard/leaderboard.js +++ b/frappe/desk/page/leaderboard/leaderboard.js @@ -1,7 +1,7 @@ frappe.pages["leaderboard"].on_page_load = (wrapper) => { frappe.leaderboard = new Leaderboard(wrapper); - $(wrapper).bind('show', ()=> { + $(wrapper).bind("show", () => { // Get which leaderboard to show let doctype = frappe.get_route()[1]; frappe.leaderboard.show_leaderboard(doctype); @@ -9,7 +9,6 @@ frappe.pages["leaderboard"].on_page_load = (wrapper) => { }; class Leaderboard { - constructor(parent) { frappe.ui.make_app_page({ parent: parent, @@ -20,11 +19,12 @@ class Leaderboard { this.parent = parent; this.page = this.parent.page; - this.page.sidebar.html(`
      `); - this.$sidebar_list = this.page.sidebar.find('ul'); + this.page.sidebar.html( + `
        ` + ); + this.$sidebar_list = this.page.sidebar.find("ul"); this.get_leaderboard_config(); - } get_leaderboard_config() { @@ -32,47 +32,57 @@ class Leaderboard { this.filters = {}; this.leaderboard_limit = 20; - frappe.xcall("frappe.desk.page.leaderboard.leaderboard.get_leaderboard_config").then(config => { - this.leaderboard_config = config; - for (let doctype in this.leaderboard_config) { - this.doctypes.push(doctype); - this.filters[doctype] = this.leaderboard_config[doctype].fields.map(field => { - if (typeof field ==='object') { - return field.label || field.fieldname; - } - return field; - }); - } + frappe + .xcall("frappe.desk.page.leaderboard.leaderboard.get_leaderboard_config") + .then((config) => { + this.leaderboard_config = config; + for (let doctype in this.leaderboard_config) { + this.doctypes.push(doctype); + this.filters[doctype] = this.leaderboard_config[doctype].fields.map( + (field) => { + if (typeof field === "object") { + return field.label || field.fieldname; + } + return field; + } + ); + } - // For translation. Do not remove this - // __("This Week"), __("This Month"), __("This Quarter"), __("This Year"), - // __("Last Week"), __("Last Month"), __("Last Quarter"), __("Last Year"), - // __("All Time"), __("Select From Date") - this.timespans = [ - "This Week", "This Month", "This Quarter", "This Year", - "Last Week", "Last Month", "Last Quarter", "Last Year", - "All Time", "Select Date Range" - ]; + // For translation. Do not remove this + // __("This Week"), __("This Month"), __("This Quarter"), __("This Year"), + // __("Last Week"), __("Last Month"), __("Last Quarter"), __("Last Year"), + // __("All Time"), __("Select From Date") + this.timespans = [ + "This Week", + "This Month", + "This Quarter", + "This Year", + "Last Week", + "Last Month", + "Last Quarter", + "Last Year", + "All Time", + "Select Date Range", + ]; - // for saving current selected filters - const _initial_doctype = frappe.get_route()[1] || this.doctypes[0]; - const _initial_timespan = this.timespans[0]; - const _initial_filter = this.filters[_initial_doctype]; + // for saving current selected filters + const _initial_doctype = frappe.get_route()[1] || this.doctypes[0]; + const _initial_timespan = this.timespans[0]; + const _initial_filter = this.filters[_initial_doctype]; - this.options = { - selected_doctype: _initial_doctype, - selected_filter: _initial_filter, - selected_filter_item: _initial_filter[0], - selected_timespan: _initial_timespan, - }; + this.options = { + selected_doctype: _initial_doctype, + selected_filter: _initial_filter, + selected_filter_item: _initial_filter[0], + selected_timespan: _initial_timespan, + }; - this.message = null; - this.make(); - }); + this.message = null; + this.make(); + }); } make() { - this.$container = $(`
        @@ -80,7 +90,7 @@ class Leaderboard { this.$graph_area = this.$container.find(".leaderboard-graph"); - this.doctypes.map(doctype => { + this.doctypes.map((doctype) => { const icon = this.leaderboard_config[doctype].icon; this.get_sidebar_item(doctype, icon).appendTo(this.$sidebar_list); }); @@ -94,7 +104,6 @@ class Leaderboard { // Get which leaderboard to show let doctype = frappe.get_route()[1]; this.show_leaderboard(doctype); - } setup_leaderboard_fields() { @@ -108,25 +117,27 @@ class Leaderboard { change: (e) => { this.options.selected_company = e.currentTarget.value; this.make_request(); - } + }, }); - this.timespan_select = this.page.add_select(__("Timespan"), - this.timespans.map(d => { - return {"label": __(d), value: d }; + this.timespan_select = this.page.add_select( + __("Timespan"), + this.timespans.map((d) => { + return { label: __(d), value: d }; }) ); this.create_date_range_field(); - this.type_select = this.page.add_select(__("Field"), - this.options.selected_filter.map(d => { - return {"label": __(frappe.model.unscrub(d)), value: d }; + this.type_select = this.page.add_select( + __("Field"), + this.options.selected_filter.map((d) => { + return { label: __(frappe.model.unscrub(d)), value: d }; }) ); this.timespan_select.on("change", (e) => { this.options.selected_timespan = e.currentTarget.value; - if (this.options.selected_timespan === 'Select Date Range') { + if (this.options.selected_timespan === "Select Date Range") { this.date_range_field.show(); } else { this.date_range_field.hide(); @@ -141,30 +152,33 @@ class Leaderboard { } create_date_range_field() { - let timespan_field = $(this.parent).find(`.frappe-control[data-original-title="${__('Timespan')}"]`); - this.date_range_field = $(`
        `).insertAfter(timespan_field).hide(); + let timespan_field = $(this.parent).find( + `.frappe-control[data-original-title="${__("Timespan")}"]` + ); + this.date_range_field = $(`
        `) + .insertAfter(timespan_field) + .hide(); let date_field = frappe.ui.form.make_control({ df: { - fieldtype: 'DateRange', - fieldname: 'selected_date_range', + fieldtype: "DateRange", + fieldname: "selected_date_range", placeholder: __("Date Range"), default: [frappe.datetime.month_start(), frappe.datetime.now_date()], - input_class: 'input-xs', + input_class: "input-xs", reqd: 1, change: () => { this.selected_date_range = date_field.get_value(); if (this.selected_date_range) this.make_request(); - } + }, }, - parent: $(this.parent).find('.from-date-field'), - render_input: 1 + parent: $(this.parent).find(".from-date-field"), + render_input: 1, }); } render_selected_doctype() { - - this.$sidebar_list.on("click", "li", (e)=> { + this.$sidebar_list.on("click", "li", (e) => { let $li = $(e.currentTarget); let doctype = $li.find(".doctype-text").attr("doctype-value"); @@ -174,8 +188,8 @@ class Leaderboard { this.options.selected_filter_item = this.filters[doctype][0]; this.type_select.empty().add_options( - this.options.selected_filter.map(d => { - return {"label": __(frappe.model.unscrub(d)), value: d }; + this.options.selected_filter.map((d) => { + return { label: __(frappe.model.unscrub(d)), value: d }; }) ); if (this.leaderboard_config[this.options.selected_doctype].company_disabled) { @@ -193,10 +207,10 @@ class Leaderboard { } render_search_box() { - - this.$search_box = - $(``; + }) + .join(""); - const html = - `
        + const html = `
        ${filters}
        `; return html; } render_list_result(items) { + let _html = items + .map((item, index) => { + const $value = $(this.get_item_html(item, index + 1)); + const $item_container = $(`
        `).append($value); + return $item_container[0].outerHTML; + }) + .join(""); - let _html = items.map((item, index) => { - const $value = $(this.get_item_html(item, index+1)); - const $item_container = $(`
        `).append($value); - return $item_container[0].outerHTML; - }).join(""); - - let html = - `
        + let html = `
        ${_html}
        @@ -328,7 +336,7 @@ class Leaderboard { } render_message() { - const display_class = this.message ? '' : 'hide'; + const display_class = this.message ? "" : "hide"; let html = `
        { - let fieldname = field.fieldname || field; - return fieldname === this.options.selected_filter_item; - })); + const value = frappe.format( + item.value, + fields.find((field) => { + let fieldname = field.fieldname || field; + return fieldname === this.options.selected_filter_item; + }) + ); const link = `/app/${frappe.router.slug(this.options.selected_doctype)}/${item.name}`; - const name_html = item.formatted_name ? - `${item.formatted_name}` + const name_html = item.formatted_name + ? `${item.formatted_name}` : ` ${item.name} `; - const html = - `
        + const html = `
        ${index}
        @@ -369,11 +379,11 @@ class Leaderboard { } get_sidebar_item(item, icon) { - let icon_html = icon ? frappe.utils.icon(icon, 'md') : ''; + let icon_html = icon ? frappe.utils.icon(icon, "md") : ""; return $(`
      • ${icon_html} - ${ __(item) } + ${__(item)}
      • `); } @@ -391,9 +401,11 @@ class Leaderboard { "last quarter": [frappe.datetime.add_months(current_date, -3), current_date], "last year": [frappe.datetime.add_months(current_date, -12), current_date], "all time": null, - "select date range": this.selected_date_range || [frappe.datetime.month_start(), current_date] - } + "select date range": this.selected_date_range || [ + frappe.datetime.month_start(), + current_date, + ], + }; return date_range_map[timespan]; } - } diff --git a/frappe/desk/page/setup_wizard/setup_wizard.js b/frappe/desk/page/setup_wizard/setup_wizard.js index c683655dd5..1cfceb29b0 100644 --- a/frappe/desk/page/setup_wizard/setup_wizard.js +++ b/frappe/desk/page/setup_wizard/setup_wizard.js @@ -27,11 +27,11 @@ frappe.setup = { $.each(frappe.setup.events[event] || [], function (i, fn) { fn(); }); - } -} + }, +}; -frappe.pages['setup-wizard'].on_page_load = function (wrapper) { - let requires = (frappe.boot.setup_wizard_requires || []); +frappe.pages["setup-wizard"].on_page_load = function (wrapper) { + let requires = frappe.boot.setup_wizard_requires || []; frappe.require(requires, function () { frappe.call({ method: "frappe.desk.page.setup_wizard.setup_wizard.load_languages", @@ -46,19 +46,19 @@ frappe.pages['setup-wizard'].on_page_load = function (wrapper) { slide_class: frappe.setup.SetupWizardSlide, unidirectional: 1, done_state: 1, - } + }; frappe.wizard = new frappe.setup.SetupWizard(wizard_settings); frappe.setup.run_event("after_load"); let route = frappe.get_route(); if (route) { frappe.wizard.show_slide(route[1]); } - } + }, }); }); }; -frappe.pages['setup-wizard'].on_page_show = function () { +frappe.pages["setup-wizard"].on_page_show = function () { if (frappe.get_route()[1]) { frappe.wizard && frappe.wizard.show_slide(frappe.get_route()[1]); } @@ -67,7 +67,7 @@ frappe.pages['setup-wizard'].on_page_show = function () { frappe.setup.on("before_load", function () { // load slides frappe.setup.slides_settings.forEach((s) => { - if (!(s.name === 'user' && frappe.boot.developer_mode)) { + if (!(s.name === "user" && frappe.boot.developer_mode)) { // if not user slide with developer mode frappe.setup.add_slide(s); } @@ -87,26 +87,26 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { make() { super.make(); this.container.addClass("container setup-wizard-slide with-form"); - this.$next_btn.addClass('action'); - this.$complete_btn.addClass('action'); + this.$next_btn.addClass("action"); + this.$complete_btn.addClass("action"); this.setup_keyboard_nav(); } setup_keyboard_nav() { - $('body').on('keydown', this.handle_enter_press.bind(this)); + $("body").on("keydown", this.handle_enter_press.bind(this)); } disable_keyboard_nav() { - $('body').off('keydown', this.handle_enter_press.bind(this)); + $("body").off("keydown", this.handle_enter_press.bind(this)); } handle_enter_press(e) { if (e.which === frappe.ui.keyCode.ENTER) { var $target = $(e.target); - if ($target.hasClass('prev-btn')) { - $target.trigger('click'); + if ($target.hasClass("prev-btn")) { + $target.trigger("click"); } else { - this.container.find('.next-btn').trigger('click'); + this.container.find(".next-btn").trigger("click"); e.preventDefault(); } } @@ -134,8 +134,10 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { super.show_hide_prev_next(id); if (id + 1 === this.slides.length) { this.$next_btn.removeClass("btn-primary").hide(); - this.$complete_btn.addClass("btn-primary").show() - .on('click', () => this.action_on_complete()); + this.$complete_btn + .addClass("btn-primary") + .show() + .on("click", () => this.action_on_complete()); } else { this.$next_btn.addClass("btn-primary").show(); this.$complete_btn.removeClass("btn-primary").hide(); @@ -170,7 +172,7 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { this.show_slide(this.current_id); this.refresh(this.current_id); setTimeout(() => { - this.container.find('.form-control').first().focus(); + this.container.find(".form-control").first().focus(); }, 200); this.in_refresh_slides = false; } @@ -186,15 +188,15 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { method: "frappe.desk.page.setup_wizard.setup_wizard.setup_complete", args: { args: this.values }, callback: (r) => { - if (r.message.status === 'ok') { + if (r.message.status === "ok") { this.post_setup_success(); - } else if (r.message.status === 'registered') { + } else if (r.message.status === "registered") { this.update_setup_message(__("starting the setup...")); } else if (r.message.fail !== undefined) { this.abort_setup(r.message.fail); } }, - error: () => this.abort_setup("Error in setup") + error: () => this.abort_setup("Error in setup"), }); } @@ -205,17 +207,17 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { } setTimeout(function () { // Reload - window.location.href = '/app'; + window.location.href = "/app"; }, 2000); } abort_setup(fail_msg) { - this.$working_state.find('.state-icon-container').html(''); + this.$working_state.find(".state-icon-container").html(""); fail_msg = fail_msg ? fail_msg : __("Failed to complete setup"); - this.update_setup_message('Could not start up: ' + fail_msg); + this.update_setup_message("Could not start up: " + fail_msg); - this.$working_state.find('.title').html('Setup failed'); + this.$working_state.find(".title").html("Setup failed"); this.$abort_btn.show(); } @@ -226,19 +228,19 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { if (data.stage_status) { // .html('Process '+ data.progress[0] + ' of ' + data.progress[1] + ': ' + data.stage_status); this.update_setup_message(data.stage_status); - this.set_setup_load_percent((data.progress[0] + 1) / data.progress[1] * 100); + this.set_setup_load_percent(((data.progress[0] + 1) / data.progress[1]) * 100); } if (data.fail_msg) { this.abort_setup(data.fail_msg); } - if (data.status === 'ok') { + if (data.status === "ok") { this.post_setup_success(); } - }) + }); } update_setup_message(message) { - this.$working_state.find('.setup-message').html(message); + this.$working_state.find(".setup-message").html(message); } get_setup_slides_filtered_by_domain() { @@ -246,14 +248,16 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { frappe.setup.slides.forEach(function (slide) { if (frappe.setup.domains) { let active_domains = frappe.setup.domains; - if (!slide.domains || - slide.domains.filter(d => active_domains.includes(d)).length > 0) { + if ( + !slide.domains || + slide.domains.filter((d) => active_domains.includes(d)).length > 0 + ) { filtered_slides.push(slide); } } else { filtered_slides.push(slide); } - }) + }); return filtered_slides; } @@ -263,7 +267,8 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { this.$working_state = this.get_message( __("Setting up your system"), - __("Starting Frappe ...")).appendTo(this.parent); + __("Starting Frappe ...") + ).appendTo(this.parent); this.attach_abort_button(); @@ -272,11 +277,13 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { } attach_abort_button() { - this.$abort_btn = $(``); - this.$working_state.find('.content').append(this.$abort_btn); + this.$abort_btn = $( + `` + ); + this.$working_state.find(".content").append(this.$abort_btn); - this.$abort_btn.on('click', () => { - $(this.parent).find('.setup-in-progress').remove(); + this.$abort_btn.on("click", () => { + $(this.parent).find(".setup-in-progress").remove(); this.container.show(); frappe.set_route(this.page_name, this.slides.length - 1); }); @@ -301,12 +308,12 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides { } set_setup_complete_message(title, message) { - this.$working_state.find('.title').html(title); - this.$working_state.find('.setup-message').html(message); + this.$working_state.find(".title").html(title); + this.$working_state.find(".setup-message").html(message); } set_setup_load_percent(percent) { - this.$working_state.find('.progress-bar').css({ "width": percent + "%" }); + this.$working_state.find(".progress-bar").css({ width: percent + "%" }); } }; @@ -333,7 +340,6 @@ frappe.setup.SetupWizardSlide = class SetupWizardSlide extends frappe.ui.Slide { }); } } - }; // Frappe slides settings @@ -349,7 +355,7 @@ frappe.setup.slides_settings = [ fieldname: "language", label: __("Your Language"), fieldtype: "Autocomplete", - placeholder: __('Select Language'), + placeholder: __("Select Language"), default: "English", reqd: 1, }, @@ -357,16 +363,16 @@ frappe.setup.slides_settings = [ fieldname: "country", label: __("Your Country"), fieldtype: "Autocomplete", - placeholder: __('Select Country'), + placeholder: __("Select Country"), reqd: 1, }, { - fieldtype: "Section Break" + fieldtype: "Section Break", }, { fieldname: "timezone", label: __("Time Zone"), - placeholder: __('Select Time Zone'), + placeholder: __("Select Time Zone"), fieldtype: "Select", reqd: 1, }, @@ -374,10 +380,10 @@ frappe.setup.slides_settings = [ { fieldname: "currency", label: __("Currency"), - placeholder: __('Select Currency'), + placeholder: __("Select Currency"), fieldtype: "Select", reqd: 1, - } + }, ], onload: function (slide) { @@ -387,7 +393,10 @@ frappe.setup.slides_settings = [ frappe.setup.utils.load_regional_data(slide, this.setup_fields); } if (!slide.get_value("language")) { - let session_language = frappe.setup.utils.get_language_name_from_code(frappe.boot.lang || navigator.language) || "English"; + let session_language = + frappe.setup.utils.get_language_name_from_code( + frappe.boot.lang || navigator.language + ) || "English"; let language_field = slide.get_field("language"); language_field.set_input(session_language); @@ -408,23 +417,30 @@ frappe.setup.slides_settings = [ }, { // Profile slide - name: 'user', + name: "user", title: __("The First User: You"), icon: "fa fa-user", fields: [ { - "fieldtype": "Attach Image", "fieldname": "attach_user_image", - label: __("Attach Your Picture"), is_private: 0, align: 'center' + fieldtype: "Attach Image", + fieldname: "attach_user_image", + label: __("Attach Your Picture"), + is_private: 0, + align: "center", }, { - "fieldname": "full_name", "label": __("Full Name"), "fieldtype": "Data", - reqd: 1 + fieldname: "full_name", + label: __("Full Name"), + fieldtype: "Data", + reqd: 1, }, { - "fieldname": "email", "label": __("Email Address") + ' (' + __("Will be your login ID") + ')', - "fieldtype": "Data", "options": "Email" + fieldname: "email", + label: __("Email Address") + " (" + __("Will be your login ID") + ")", + fieldtype: "Data", + options: "Email", }, - { "fieldname": "password", "label": __("Password"), "fieldtype": "Password" } + { fieldname: "password", label: __("Password"), fieldtype: "Password" }, ], onload: function (slide) { @@ -437,7 +453,8 @@ frappe.setup.slides_settings = [ if (frappe.boot.user.first_name || frappe.boot.user.last_name) { slide.form.fields_dict.full_name.set_input( - [frappe.boot.user.first_name, frappe.boot.user.last_name].join(' ').trim()); + [frappe.boot.user.first_name, frappe.boot.user.last_name].join(" ").trim() + ); } var user_image = frappe.get_cookie("user_image"); @@ -449,7 +466,6 @@ frappe.setup.slides_settings = [ $attach_user_image.find(".img-container").toggle(true); } delete slide.form.fields_dict.email; - } else { slide.form.fields_dict.email.df.reqd = 1; slide.form.fields_dict.email.refresh(); @@ -475,7 +491,7 @@ frappe.setup.slides_settings = [ } } }, - } + }, ]; frappe.setup.utils = { @@ -485,7 +501,7 @@ frappe.setup.utils = { callback: function (data) { frappe.setup.data.regional_data = data.message; callback(slide); - } + }, }); }, @@ -497,7 +513,7 @@ frappe.setup.utils = { frappe.setup.data.full_name = r.message.full_name; frappe.setup.data.email = r.message.email; callback(slide); - } + }, }); }, @@ -512,28 +528,28 @@ frappe.setup.utils = { Set a slide's country, timezone and currency fields */ let data = frappe.setup.data.regional_data; - let country_field = slide.get_field('country'); + let country_field = slide.get_field("country"); let translated_countries = []; - Object.keys(data.country_info).sort().forEach(country => { - translated_countries.push({ - label: __(country), - value: country + Object.keys(data.country_info) + .sort() + .forEach((country) => { + translated_countries.push({ + label: __(country), + value: country, + }); }); - }); country_field.set_data(translated_countries); - slide.get_input("currency") + slide + .get_input("currency") .empty() .add_options( - frappe.utils.unique( - $.map(data.country_info, opts => opts.currency).sort() - ) + frappe.utils.unique($.map(data.country_info, (opts) => opts.currency).sort()) ); - slide.get_input("timezone").empty() - .add_options(data.all_timezones); + slide.get_input("timezone").empty().add_options(data.all_timezones); // set values if present if (frappe.wizard.values.country) { @@ -547,24 +563,27 @@ frappe.setup.utils = { }, bind_language_events: function (slide) { - slide.get_input("language").unbind("change").on("change", function () { - clearTimeout(slide.language_call_timeout); - slide.language_call_timeout = setTimeout(() => { - var lang = $(this).val() || "English"; - frappe._messages = {}; - frappe.call({ - method: "frappe.desk.page.setup_wizard.setup_wizard.load_messages", - freeze: true, - args: { - language: lang - }, - callback: function () { - frappe.setup._from_load_messages = true; - frappe.wizard.refresh_slides(); - } - }); - }, 500); - }); + slide + .get_input("language") + .unbind("change") + .on("change", function () { + clearTimeout(slide.language_call_timeout); + slide.language_call_timeout = setTimeout(() => { + var lang = $(this).val() || "English"; + frappe._messages = {}; + frappe.call({ + method: "frappe.desk.page.setup_wizard.setup_wizard.load_messages", + freeze: true, + args: { + language: lang, + }, + callback: function () { + frappe.setup._from_load_messages = true; + frappe.wizard.refresh_slides(); + }, + }); + }, 500); + }); }, get_language_name_from_code: function (language_code) { @@ -594,8 +613,8 @@ frappe.setup.utils = { slide.get_field("timezone").set_input($timezone.val()); // temporarily set date format - frappe.boot.sysdefaults.date_format = (data.country_info[country].date_format - || "dd-mm-yyyy"); + frappe.boot.sysdefaults.date_format = + data.country_info[country].date_format || "dd-mm-yyyy"; }); slide.get_input("currency").on("change", function () { diff --git a/frappe/desk/page/translation_tool/translation_tool.js b/frappe/desk/page/translation_tool/translation_tool.js index 13f68e647a..5739eddfc7 100644 --- a/frappe/desk/page/translation_tool/translation_tool.js +++ b/frappe/desk/page/translation_tool/translation_tool.js @@ -1,7 +1,7 @@ -frappe.pages['translation-tool'].on_page_load = function(wrapper) { +frappe.pages["translation-tool"].on_page_load = function (wrapper) { var page = frappe.ui.make_app_page({ parent: wrapper, - title: __('Translation Tool'), + title: __("Translation Tool"), single_column: true, card_layout: true, }); @@ -13,77 +13,74 @@ class TranslationTool { constructor(page) { this.page = page; this.wrapper = $(page.body); - this.wrapper.append(frappe.render_template('translation_tool')); + this.wrapper.append(frappe.render_template("translation_tool")); frappe.utils.bind_actions_with_object(this.wrapper, this); this.active_translation = null; this.edited_translations = {}; this.setup_search_box(); this.setup_language_filter(); this.page.set_primary_action( - __('Contribute Translations'), + __("Contribute Translations"), this.show_confirmation_dialog.bind(this) ); - this.page.set_secondary_action( - __('Refresh'), - this.fetch_messages_then_render.bind(this) - ); + this.page.set_secondary_action(__("Refresh"), this.fetch_messages_then_render.bind(this)); this.update_header(); } setup_language_filter() { - let languages = Object.keys(frappe.boot.lang_dict).map(language_label => { + let languages = Object.keys(frappe.boot.lang_dict).map((language_label) => { let value = frappe.boot.lang_dict[language_label]; return { label: `${language_label} (${value})`, - value: value + value: value, }; }); let language_selector = this.page.add_field({ - fieldname: 'language', - fieldtype: 'Select', + fieldname: "language", + fieldtype: "Select", options: languages, change: () => { let language = language_selector.get_value(); - localStorage.setItem('translation_language', language); + localStorage.setItem("translation_language", language); this.language = language; this.fetch_messages_then_render(); - } + }, }); - let translation_language = localStorage.getItem('translation_language'); - if (translation_language || frappe.boot.lang !== 'en') { + let translation_language = localStorage.getItem("translation_language"); + if (translation_language || frappe.boot.lang !== "en") { language_selector.set_value(translation_language || frappe.boot.lang); } else { frappe.prompt( { - label: __('Please select target language for translation'), - fieldname: 'language', - fieldtype: 'Select', + label: __("Please select target language for translation"), + fieldname: "language", + fieldtype: "Select", options: languages, - reqd: 1 + reqd: 1, }, - values => { + (values) => { language_selector.set_value(values.language); }, - __('Select Language') + __("Select Language") ); } } setup_search_box() { let search_box = this.page.add_field({ - fieldname: 'search', - fieldtype: 'Data', - label: __('Search Source Text'), + fieldname: "search", + fieldtype: "Data", + label: __("Search Source Text"), change: () => { this.search_text = search_box.get_value(); this.fetch_messages_then_render(); - } + }, }); } fetch_messages_then_render() { - this.fetch_messages().then(messages => { + this.fetch_messages().then((messages) => { this.messages = messages; this.render_messages(messages); }); @@ -91,13 +88,13 @@ class TranslationTool { } fetch_messages() { - frappe.dom.freeze(__('Fetching...')); + frappe.dom.freeze(__("Fetching...")); return frappe - .xcall('frappe.translate.get_messages', { + .xcall("frappe.translate.get_messages", { language: this.language, - search_text: this.search_text + search_text: this.search_text, }) - .then(messages => { + .then((messages) => { return messages; }) .finally(() => { @@ -106,7 +103,7 @@ class TranslationTool { } render_messages(messages) { - let template = message => ` + let template = (message) => `
        `; - let html = messages.map(template).join(''); - this.wrapper.find('.translation-item-container').html(html); + let html = messages.map(template).join(""); + this.wrapper.find(".translation-item-container").html(html); } on_translation_click(e, $el) { - let message_id = decodeURIComponent($el.data('message-id')); - this.wrapper.find('.translation-item').removeClass('active'); - $el.addClass('active'); - this.active_translation = this.messages.find(m => m.id === message_id); + let message_id = decodeURIComponent($el.data("message-id")); + this.wrapper.find(".translation-item").removeClass("active"); + $el.addClass("active"); + this.active_translation = this.messages.find((m) => m.id === message_id); this.edit_translation(this.active_translation); } @@ -135,17 +132,19 @@ class TranslationTool { if (this.form) { this.form.set_values({}); } - this.get_additional_info(translation.id).then(data => { + this.get_additional_info(translation.id).then((data) => { this.make_edit_form(translation, data); }); } get_additional_info(source_id) { - frappe.dom.freeze('Fetching...'); - return frappe.xcall('frappe.translate.get_source_additional_info', { - source: source_id, - language: this.page.fields_dict['language'].get_value() - }).finally(frappe.dom.unfreeze); + frappe.dom.freeze("Fetching..."); + return frappe + .xcall("frappe.translate.get_source_additional_info", { + source: source_id, + language: this.page.fields_dict["language"].get_value(), + }) + .finally(frappe.dom.unfreeze); } make_edit_form(translation, { contributions, positions }) { @@ -153,80 +152,77 @@ class TranslationTool { this.form = new frappe.ui.FieldGroup({ fields: [ { - fieldtype: 'HTML', - fieldname: 'header', - read_only: 1 - }, - { - fieldtype: 'Data', - fieldname: 'id', - hidden: 1 - }, - { - label: 'Source Text', - fieldtype: 'Code', - fieldname: 'source_text', + fieldtype: "HTML", + fieldname: "header", read_only: 1, - enable_copy_button: 1 }, { - label: 'Context', - fieldtype: 'Code', - fieldname: 'context', - read_only: 1 + fieldtype: "Data", + fieldname: "id", + hidden: 1, }, { - label: 'DocType', - fieldtype: 'Data', - fieldname: 'doctype', - read_only: 1 + label: "Source Text", + fieldtype: "Code", + fieldname: "source_text", + read_only: 1, + enable_copy_button: 1, }, { - label: 'Translated Text', - fieldtype: 'Small Text', - fieldname: 'translated_text', + label: "Context", + fieldtype: "Code", + fieldname: "context", + read_only: 1, }, { - label: 'Suggest', - fieldtype: 'Button', + label: "DocType", + fieldtype: "Data", + fieldname: "doctype", + read_only: 1, + }, + { + label: "Translated Text", + fieldtype: "Small Text", + fieldname: "translated_text", + }, + { + label: "Suggest", + fieldtype: "Button", click: () => { let { id, translated_text, source_text } = this.form.get_values(); let existing_value = this.form.translation_dict.translated_text; - if ( - is_null(translated_text) || - existing_value === translated_text - ) { + if (is_null(translated_text) || existing_value === translated_text) { delete this.edited_translations[id]; } else if (existing_value !== translated_text) { this.edited_translations[id] = { id, translated_text, - source_text + source_text, }; } this.update_header(); - } + }, }, { - fieldtype: 'Section Break', - fieldname: 'contributed_translations_section', - label: 'Contributed Translations' + fieldtype: "Section Break", + fieldname: "contributed_translations_section", + label: "Contributed Translations", }, { - fieldtype: 'HTML', - fieldname: 'contributed_translations' + fieldtype: "HTML", + fieldname: "contributed_translations", }, { - fieldtype: 'Section Break', + fieldtype: "Section Break", collapsible: 1, - label: 'Occurences in source code' + label: "Occurences in source code", }, { - fieldtype: 'HTML', - fieldname: 'positions' + fieldtype: "HTML", + fieldname: "positions", }, ], - body: this.wrapper.find('.translation-edit-form') + body: this.wrapper.find(".translation-edit-form"), }); this.form.make(); @@ -235,8 +231,8 @@ class TranslationTool { this.form.set_values(translation); this.form.translation_dict = translation; - this.form.set_df_property('doctype', 'hidden', !translation.doctype); - this.form.set_df_property('context', 'hidden', !translation.context); + this.form.set_df_property("doctype", "hidden", !translation.doctype); + this.form.set_df_property("context", "hidden", !translation.context); this.set_status(translation); this.setup_contributions(contributions); @@ -244,13 +240,13 @@ class TranslationTool { } setup_header() { - this.form.get_field('header').$wrapper.html(`
        + this.form.get_field("header").$wrapper.html(`
        `); } set_status(translation) { - this.form.get_field('header').$wrapper.find('.translation-status').html(` + this.form.get_field("header").$wrapper.find(".translation-status").html(` ${this.get_indicator_status_text(translation)} @@ -258,15 +254,16 @@ class TranslationTool { } setup_positions(positions) { - let position_dom = ''; + let position_dom = ""; if (positions && positions.length) { - position_dom = positions.map(position => { - if (position.path.startsWith('DocType: ')) { - return `
        + position_dom = positions + .map((position) => { + if (position.path.startsWith("DocType: ")) { + return `
        ${position.path}
        `; - } else { - return `
        + } else { + return ``; - } - }).join(''); + } + }) + .join(""); } - this.form.get_field('positions').$wrapper.html(position_dom); + this.form.get_field("positions").$wrapper.html(position_dom); } setup_contributions(contributions) { const contributions_exists = contributions && contributions.length; if (contributions_exists) { - let contributions_html = contributions.map(c => { + let contributions_html = contributions.map((c) => { return `
        ${c.translated}
        @@ -293,62 +291,70 @@ class TranslationTool {
        `; }); - this.form.get_field('contributed_translations').html(contributions_html); + this.form.get_field("contributed_translations").html(contributions_html); } - this.form.set_df_property('contributed_translations_section', 'hidden', !contributions_exists); + this.form.set_df_property( + "contributed_translations_section", + "hidden", + !contributions_exists + ); } show_confirmation_dialog() { this.confirmation_dialog = new frappe.ui.Dialog({ fields: [ { - label: __('Language'), - fieldname: 'language', - fieldtype: 'Data', + label: __("Language"), + fieldname: "language", + fieldtype: "Data", read_only: 1, bold: 1, - default: this.language + default: this.language, }, { - fieldtype: 'HTML', - fieldname: 'edited_translations' - } + fieldtype: "HTML", + fieldname: "edited_translations", + }, ], - title: __('Confirm Translations'), + title: __("Confirm Translations"), no_submit_on_enter: true, - primary_action_label: __('Submit'), - primary_action: values => { + primary_action_label: __("Submit"), + primary_action: (values) => { this.create_translations(values).then(this.confirmation_dialog.hide()); - } + }, }); - this.confirmation_dialog.get_field('edited_translations').html(` + this.confirmation_dialog.get_field("edited_translations").html(`
        Progress / Wait Event
        - - + + - ${Object.values(this.edited_translations).map(t => ` + ${Object.values(this.edited_translations) + .map( + (t) => ` - `).join('')} + ` + ) + .join("")}
        ${__('Source Text')}${__('Translated Text')}${__("Source Text")}${__("Translated Text")}
        ${t.source_text} ${t.translated_text}
        `); this.confirmation_dialog.show(); } create_translations() { - frappe.dom.freeze(__('Submitting...')); + frappe.dom.freeze(__("Submitting...")); return frappe - .xcall( - 'frappe.core.doctype.translation.translation.create_translations', - { - translation_map: this.edited_translations, - language: this.language - } - ) + .xcall("frappe.core.doctype.translation.translation.create_translations", { + translation_map: this.edited_translations, + language: this.language, + }) .then(() => { frappe.dom.unfreeze(); - frappe.show_alert({ message: __('Successfully Submitted!'), indicator: 'success'}); + frappe.show_alert({ + message: __("Successfully Submitted!"), + indicator: "success", + }); this.edited_translations = {}; this.update_header(); this.fetch_messages_then_render(); @@ -359,11 +365,11 @@ class TranslationTool { setup_local_contributions() { // TODO: Refactor frappe - .xcall('frappe.translate.get_contributions', { - language: this.language + .xcall("frappe.translate.get_contributions", { + language: this.language, }) - .then(messages => { - let template = message => ` + .then((messages) => { + let template = (message) => `
        `; - let html = messages.map(template).join(''); - this.wrapper.find('.translation-item-tr').html(html); + let html = messages.map(template).join(""); + this.wrapper.find(".translation-item-tr").html(html); }); } show_translation_status_modal(e, $el) { - let message_id = decodeURIComponent($el.data('message-id')); + let message_id = decodeURIComponent($el.data("message-id")); - frappe.xcall('frappe.translate.get_contribution_status', { message_id }) - .then(doc => { - let d = new frappe.ui.Dialog({ - title: __('Contribution Status'), - fields: [ - { - fieldname: 'source_message', - label: __('Source Message'), - fieldtype: 'Data', - read_only: 1 + frappe.xcall("frappe.translate.get_contribution_status", { message_id }).then((doc) => { + let d = new frappe.ui.Dialog({ + title: __("Contribution Status"), + fields: [ + { + fieldname: "source_message", + label: __("Source Message"), + fieldtype: "Data", + read_only: 1, + }, + { + fieldname: "translated", + label: __("Translated Message"), + fieldtype: "Data", + read_only: 1, + }, + { + fieldname: "contribution_status", + label: __("Contribution Status"), + fieldtype: "Data", + read_only: 1, + }, + { + fieldname: "modified_by", + label: __("Verified By"), + fieldtype: "Data", + read_only: 1, + depends_on: (doc) => { + return doc.contribution_status == "Verified"; }, - { - fieldname: 'translated', - label: __('Translated Message'), - fieldtype: 'Data', - read_only: 1 - }, - { - fieldname: 'contribution_status', - label: __('Contribution Status'), - fieldtype: 'Data', - read_only: 1 - }, - { - fieldname: 'modified_by', - label: __('Verified By'), - fieldtype: 'Data', - read_only: 1, - depends_on: doc => { - return doc.contribution_status == 'Verified'; - } - }, - ] - }); - d.set_values(doc); - d.show(); + }, + ], }); + d.set_values(doc); + d.show(); + }); } update_header() { - let edited_translations_count = Object.keys(this.edited_translations) - .length; + let edited_translations_count = Object.keys(this.edited_translations).length; if (edited_translations_count) { - let message = ''; + let message = ""; if (edited_translations_count == 1) { - message = __('{0} translation pending', [edited_translations_count]); + message = __("{0} translation pending", [edited_translations_count]); } else { - message = __('{0} translations pending', [edited_translations_count]); + message = __("{0} translations pending", [edited_translations_count]); } - this.page.set_indicator(message, 'orange'); + this.page.set_indicator(message, "orange"); } else { - this.page.set_indicator(''); + this.page.set_indicator(""); } - this.page.btn_primary.prop('disabled', !edited_translations_count); + this.page.btn_primary.prop("disabled", !edited_translations_count); } get_indicator_color(message_obj) { - return !message_obj.translated ? 'red' : message_obj.translated_by_google ? 'orange' : 'blue'; + return !message_obj.translated + ? "red" + : message_obj.translated_by_google + ? "orange" + : "blue"; } get_indicator_status_text(message_obj) { if (!message_obj.translated) { - return __('Untranslated'); + return __("Untranslated"); } else if (message_obj.translated_by_google) { - return __('Google Translation'); + return __("Google Translation"); } else { - return __('Community Contribution'); + return __("Community Contribution"); } } get_contribution_indicator_color(message_obj) { - return message_obj.contribution_status == 'Pending' ? 'orange' : 'green'; + return message_obj.contribution_status == "Pending" ? "orange" : "green"; } get_code_url(path, line_no, app) { diff --git a/frappe/desk/page/user_profile/user_profile.js b/frappe/desk/page/user_profile/user_profile.js index 5890975e69..e4cef59cc7 100644 --- a/frappe/desk/page/user_profile/user_profile.js +++ b/frappe/desk/page/user_profile/user_profile.js @@ -1,5 +1,5 @@ -frappe.pages['user-profile'].on_page_load = function (wrapper) { - frappe.require('user_profile_controller.bundle.js', () => { +frappe.pages["user-profile"].on_page_load = function (wrapper) { + frappe.require("user_profile_controller.bundle.js", () => { let user_profile = new frappe.ui.UserProfile(wrapper); user_profile.show(); }); diff --git a/frappe/desk/page/user_profile/user_profile_controller.js b/frappe/desk/page/user_profile/user_profile_controller.js index 40b542d5c3..5103bd8a19 100644 --- a/frappe/desk/page/user_profile/user_profile_controller.js +++ b/frappe/desk/page/user_profile/user_profile_controller.js @@ -1,5 +1,5 @@ import BaseTimeline from "../../../public/js/frappe/form/footer/base_timeline"; -frappe.provide('frappe.energy_points'); +frappe.provide("frappe.energy_points"); class UserProfile { constructor(wrapper) { @@ -7,9 +7,9 @@ class UserProfile { this.page = frappe.ui.make_app_page({ parent: wrapper, }); - this.sidebar = this.wrapper.find('.layout-side-section'); - this.main_section = this.wrapper.find('.layout-main-section'); - this.wrapper.bind('show', () => { + this.sidebar = this.wrapper.find(".layout-side-section"); + this.main_section = this.wrapper.find(".layout-main-section"); + this.wrapper.bind("show", () => { this.show(); }); } @@ -17,13 +17,13 @@ class UserProfile { show() { let route = frappe.get_route(); this.user_id = route[1] || frappe.session.user; - frappe.dom.freeze(__('Loading user profile') + '...'); - frappe.db.exists('User', this.user_id).then(exists => { + frappe.dom.freeze(__("Loading user profile") + "..."); + frappe.db.exists("User", this.user_id).then((exists) => { frappe.dom.unfreeze(); if (exists) { this.make_user_profile(); } else { - frappe.msgprint(__('User does not exist')); + frappe.msgprint(__("User does not exist")); } }); } @@ -32,7 +32,7 @@ class UserProfile { this.user = frappe.user_info(this.user_id); this.page.set_title(this.user.fullname); this.setup_user_search(); - this.main_section.empty().append(frappe.render_template('user_profile')); + this.main_section.empty().append(frappe.render_template("user_profile")); this.energy_points = 0; this.review_points = 0; this.rank = 0; @@ -41,91 +41,92 @@ class UserProfile { this.render_points_and_rank(); this.render_heatmap(); this.render_line_chart(); - this.render_percentage_chart('type', 'Type Distribution'); + this.render_percentage_chart("type", "Type Distribution"); this.create_percentage_chart_filters(); this.setup_user_activity_timeline(); } setup_user_search() { this.$user_search_button = this.page.set_secondary_action( - __('Change User'), + __("Change User"), () => this.show_user_search_dialog(), - { icon: 'change', size: 'sm' } + { icon: "change", size: "sm" } ); } show_user_search_dialog() { let dialog = new frappe.ui.Dialog({ - title: __('Change User'), + title: __("Change User"), fields: [ { - fieldtype: 'Link', - fieldname: 'user', - options: 'User', - label: __('User'), - } + fieldtype: "Link", + fieldname: "user", + options: "User", + label: __("User"), + }, ], - primary_action_label: __('Go'), + primary_action_label: __("Go"), primary_action: ({ user }) => { dialog.hide(); - frappe.set_route('user-profile', user); - } + frappe.set_route("user-profile", user); + }, }); dialog.show(); } render_heatmap() { - this.heatmap = new frappe.Chart('.performance-heatmap', { - type: 'heatmap', - countLabel: 'Energy Points', + this.heatmap = new frappe.Chart(".performance-heatmap", { + type: "heatmap", + countLabel: "Energy Points", data: {}, discreteDomains: 1, radius: 3, - height: 150 + height: 150, }); this.update_heatmap_data(); this.create_heatmap_chart_filters(); } update_heatmap_data(date_from) { - frappe.xcall('frappe.desk.page.user_profile.user_profile.get_energy_points_heatmap_data', { - user: this.user_id, - date: date_from || frappe.datetime.year_start(), - }).then((r) => { - this.heatmap.update({ dataPoints: r }); - }); + frappe + .xcall("frappe.desk.page.user_profile.user_profile.get_energy_points_heatmap_data", { + user: this.user_id, + date: date_from || frappe.datetime.year_start(), + }) + .then((r) => { + this.heatmap.update({ dataPoints: r }); + }); } - render_line_chart() { this.line_chart_filters = [ - ['Energy Point Log', 'user', '=', this.user_id, false], - ['Energy Point Log', 'type', '!=', 'Review', false] + ["Energy Point Log", "user", "=", this.user_id, false], + ["Energy Point Log", "type", "!=", "Review", false], ]; this.line_chart_config = { - timespan: 'Last Month', - time_interval: 'Daily', - type: 'Line', - value_based_on: 'points', - chart_type: 'Sum', - document_type: 'Energy Point Log', - name: 'Energy Points', - width: 'half', - based_on: 'creation' + timespan: "Last Month", + time_interval: "Daily", + type: "Line", + value_based_on: "points", + chart_type: "Sum", + document_type: "Energy Point Log", + name: "Energy Points", + width: "half", + based_on: "creation", }; - this.line_chart = new frappe.Chart('.performance-line-chart', { - type: 'line', + this.line_chart = new frappe.Chart(".performance-line-chart", { + type: "line", height: 200, data: { labels: [], - datasets: [{}] + datasets: [{}], }, - colors: ['purple'], + colors: ["purple"], axisOptions: { - xIsSeries: 1 - } + xIsSeries: 1, + }, }); this.update_line_chart_data(); this.create_line_chart_filters(); @@ -134,217 +135,258 @@ class UserProfile { update_line_chart_data() { this.line_chart_config.filters_json = JSON.stringify(this.line_chart_filters); - frappe.xcall('frappe.desk.doctype.dashboard_chart.dashboard_chart.get', { - chart: this.line_chart_config, - no_cache: 1, - }).then(chart => { - this.line_chart.update(chart); - }); + frappe + .xcall("frappe.desk.doctype.dashboard_chart.dashboard_chart.get", { + chart: this.line_chart_config, + no_cache: 1, + }) + .then((chart) => { + this.line_chart.update(chart); + }); } // eslint-disable-next-line no-unused-vars render_percentage_chart(field, title) { - frappe.xcall('frappe.desk.page.user_profile.user_profile.get_energy_points_percentage_chart_data', { - user: this.user_id, - field: field - }).then(chart => { - if (chart.labels.length) { - this.percentage_chart = new frappe.Chart('.performance-percentage-chart', { - type: 'percentage', - data: { - labels: chart.labels, - datasets: chart.datasets - }, - truncateLegends: 1, - barOptions: { - height: 11, - depth: 1 - }, - height: 200, - maxSlices: 8, - colors: ['purple', 'blue', 'cyan', 'teal', 'pink', 'red', 'orange', 'yellow'], - }); - } else { - this.wrapper.find('.percentage-chart-container').hide(); - } - }); + frappe + .xcall( + "frappe.desk.page.user_profile.user_profile.get_energy_points_percentage_chart_data", + { + user: this.user_id, + field: field, + } + ) + .then((chart) => { + if (chart.labels.length) { + this.percentage_chart = new frappe.Chart(".performance-percentage-chart", { + type: "percentage", + data: { + labels: chart.labels, + datasets: chart.datasets, + }, + truncateLegends: 1, + barOptions: { + height: 11, + depth: 1, + }, + height: 200, + maxSlices: 8, + colors: [ + "purple", + "blue", + "cyan", + "teal", + "pink", + "red", + "orange", + "yellow", + ], + }); + } else { + this.wrapper.find(".percentage-chart-container").hide(); + } + }); } create_line_chart_filters() { let filters = [ { - label: 'All', - options: ['All', 'Auto', 'Criticism', 'Appreciation', 'Revert'], + label: "All", + options: ["All", "Auto", "Criticism", "Appreciation", "Revert"], action: (selected_item) => { - if (selected_item === 'All') { + if (selected_item === "All") { this.line_chart_filters = [ - ['Energy Point Log', 'user', '=', this.user_id, false], - ['Energy Point Log', 'type', '!=', 'Review', false] + ["Energy Point Log", "user", "=", this.user_id, false], + ["Energy Point Log", "type", "!=", "Review", false], ]; } else { - this.line_chart_filters[1] = ['Energy Point Log', 'type', '=', selected_item, false]; + this.line_chart_filters[1] = [ + "Energy Point Log", + "type", + "=", + selected_item, + false, + ]; } this.update_line_chart_data(); - } + }, }, { - label: 'Last Month', - options: ['Last Week', 'Last Month', 'Last Quarter', 'Last Year'], + label: "Last Month", + options: ["Last Week", "Last Month", "Last Quarter", "Last Year"], action: (selected_item) => { this.line_chart_config.timespan = selected_item; this.update_line_chart_data(); - } + }, }, { - label: 'Daily', - options: ['Daily', 'Weekly', 'Monthly'], + label: "Daily", + options: ["Daily", "Weekly", "Monthly"], action: (selected_item) => { this.line_chart_config.time_interval = selected_item; this.update_line_chart_data(); - } + }, }, ]; - frappe.dashboard_utils.render_chart_filters(filters, 'chart-filter', '.line-chart-options', 1); + frappe.dashboard_utils.render_chart_filters( + filters, + "chart-filter", + ".line-chart-options", + 1 + ); } create_percentage_chart_filters() { let filters = [ { - label: 'Type', - options: ['Type', 'Reference Doctype', 'Rule'], - fieldnames: ['type', 'reference_doctype', 'rule'], + label: "Type", + options: ["Type", "Reference Doctype", "Rule"], + fieldnames: ["type", "reference_doctype", "rule"], action: (selected_item, fieldname) => { - let title = selected_item + ' Distribution'; + let title = selected_item + " Distribution"; this.render_percentage_chart(fieldname, title); - } + }, }, ]; - frappe.dashboard_utils.render_chart_filters(filters, 'chart-filter', '.percentage-chart-options'); + frappe.dashboard_utils.render_chart_filters( + filters, + "chart-filter", + ".percentage-chart-options" + ); } create_heatmap_chart_filters() { let filters = [ { label: frappe.dashboard_utils.get_year(frappe.datetime.now_date()), - options: frappe.dashboard_utils.get_years_since_creation(frappe.boot.user.creation), + options: frappe.dashboard_utils.get_years_since_creation( + frappe.boot.user.creation + ), action: (selected_item) => { this.update_heatmap_data(frappe.datetime.obj_to_str(selected_item)); - } + }, }, ]; - frappe.dashboard_utils.render_chart_filters(filters, 'chart-filter', '.heatmap-options'); + frappe.dashboard_utils.render_chart_filters(filters, "chart-filter", ".heatmap-options"); } - edit_profile() { let edit_profile_dialog = new frappe.ui.Dialog({ - title: __('Edit Profile'), + title: __("Edit Profile"), fields: [ { - fieldtype: 'Attach Image', - fieldname: 'user_image', - label: 'Profile Image', + fieldtype: "Attach Image", + fieldname: "user_image", + label: "Profile Image", }, { - fieldtype: 'Data', - fieldname: 'interest', - label: 'Interests', + fieldtype: "Data", + fieldname: "interest", + label: "Interests", }, { - fieldtype: 'Column Break' + fieldtype: "Column Break", }, { - fieldtype: 'Data', - fieldname: 'location', - label: 'Location', + fieldtype: "Data", + fieldname: "location", + label: "Location", }, { - fieldtype: 'Section Break', - fieldname: 'Interest', + fieldtype: "Section Break", + fieldname: "Interest", }, { - fieldtype: 'Small Text', - fieldname: 'bio', - label: 'Bio', - } + fieldtype: "Small Text", + fieldname: "bio", + label: "Bio", + }, ], - primary_action: values => { + primary_action: (values) => { edit_profile_dialog.disable_primary_action(); - frappe.xcall('frappe.desk.page.user_profile.user_profile.update_profile_info', { - profile_info: values - }).then(user => { - user.image = user.user_image; - this.user = Object.assign(values, user); - edit_profile_dialog.hide(); - this.render_user_details(); - }).finally(() => { - edit_profile_dialog.enable_primary_action(); - }); + frappe + .xcall("frappe.desk.page.user_profile.user_profile.update_profile_info", { + profile_info: values, + }) + .then((user) => { + user.image = user.user_image; + this.user = Object.assign(values, user); + edit_profile_dialog.hide(); + this.render_user_details(); + }) + .finally(() => { + edit_profile_dialog.enable_primary_action(); + }); }, - primary_action_label: __('Save') + primary_action_label: __("Save"), }); edit_profile_dialog.set_values({ user_image: this.user.image, location: this.user.location, interest: this.user.interest, - bio: this.user.bio + bio: this.user.bio, }); edit_profile_dialog.show(); } render_user_details() { - this.sidebar.empty().append(frappe.render_template('user_profile_sidebar', { - user_image: this.user.image, - user_abbr: this.user.abbr, - user_location: this.user.location, - user_interest: this.user.interest, - user_bio: this.user.bio, - })); + this.sidebar.empty().append( + frappe.render_template("user_profile_sidebar", { + user_image: this.user.image, + user_abbr: this.user.abbr, + user_location: this.user.location, + user_interest: this.user.interest, + user_bio: this.user.bio, + }) + ); this.setup_user_profile_links(); } setup_user_profile_links() { if (this.user_id !== frappe.session.user) { - this.wrapper.find('.profile-links').hide(); + this.wrapper.find(".profile-links").hide(); } else { - this.wrapper.find('.edit-profile-link').on('click', () => { + this.wrapper.find(".edit-profile-link").on("click", () => { this.edit_profile(); }); - this.wrapper.find('.user-settings-link').on('click', () => { + this.wrapper.find(".user-settings-link").on("click", () => { this.go_to_user_settings(); }); } } get_user_rank() { - return frappe.xcall('frappe.desk.page.user_profile.user_profile.get_user_rank', { - user: this.user_id, - }).then(r => { - if (r.monthly_rank.length) this.month_rank = r.monthly_rank[0]; - if (r.all_time_rank.length) this.rank = r.all_time_rank[0]; - }); + return frappe + .xcall("frappe.desk.page.user_profile.user_profile.get_user_rank", { + user: this.user_id, + }) + .then((r) => { + if (r.monthly_rank.length) this.month_rank = r.monthly_rank[0]; + if (r.all_time_rank.length) this.rank = r.all_time_rank[0]; + }); } get_user_points() { - return frappe.xcall( - 'frappe.social.doctype.energy_point_log.energy_point_log.get_user_energy_and_review_points', - { - user: this.user_id, - } - ).then(r => { - if (r[this.user_id]) { - this.energy_points = r[this.user_id].energy_points; - this.review_points = r[this.user_id].review_points; - } - }); + return frappe + .xcall( + "frappe.social.doctype.energy_point_log.energy_point_log.get_user_energy_and_review_points", + { + user: this.user_id, + } + ) + .then((r) => { + if (r[this.user_id]) { + this.energy_points = r[this.user_id].energy_points; + this.review_points = r[this.user_id].review_points; + } + }); } render_points_and_rank() { - let $profile_details = this.wrapper.find('.user-stats'); - let $profile_details_wrapper = this.wrapper.find('.user-stats-detail'); + let $profile_details = this.wrapper.find(".user-stats"); + let $profile_details_wrapper = this.wrapper.find(".user-stats-detail"); const _get_stat_dom = (value, label, icon) => { return `
        @@ -359,10 +401,10 @@ class UserProfile { this.get_user_rank().then(() => { this.get_user_points().then(() => { let html = $(` - ${_get_stat_dom(this.energy_points, __('Energy Points'), "color-energy-points")} - ${_get_stat_dom(this.review_points, __('Review Points'), "color-review-points")} - ${_get_stat_dom(this.rank, __('Rank'), "color-rank")} - ${_get_stat_dom(this.month_rank, __('Monthly Rank'), "color-monthly-rank")} + ${_get_stat_dom(this.energy_points, __("Energy Points"), "color-energy-points")} + ${_get_stat_dom(this.review_points, __("Review Points"), "color-review-points")} + ${_get_stat_dom(this.rank, __("Rank"), "color-rank")} + ${_get_stat_dom(this.month_rank, __("Monthly Rank"), "color-monthly-rank")} `); $profile_details.append(html); @@ -372,14 +414,14 @@ class UserProfile { } go_to_user_settings() { - frappe.set_route('Form', 'User', this.user_id); + frappe.set_route("Form", "User", this.user_id); } setup_user_activity_timeline() { this.user_activity_timeline = new UserProfileTimeline({ - parent: this.wrapper.find('.recent-activity-list'), - footer: this.wrapper.find('.recent-activity-footer'), - user: this.user_id + parent: this.wrapper.find(".recent-activity-list"), + footer: this.wrapper.find(".recent-activity-footer"), + user: this.user_id, }); this.user_activity_timeline.refresh(); @@ -397,24 +439,27 @@ class UserProfileTimeline extends BaseTimeline { return this.get_user_activity_data().then((activities) => { if (!activities.length) { this.show_more_button.hide(); - this.timeline_wrapper.html(`
        ${__('No activities to show')}
        `); + this.timeline_wrapper.html(`
        ${__("No activities to show")}
        `); return; } this.show_more_button.toggle(activities.length === this.activity_limit); - this.timeline_items = activities.map((activity) => this.get_activity_timeline_item(activity)); + this.timeline_items = activities.map((activity) => + this.get_activity_timeline_item(activity) + ); }); } get_user_activity_data() { - return frappe.xcall('frappe.desk.page.user_profile.user_profile.get_energy_points_list', { + return frappe.xcall("frappe.desk.page.user_profile.user_profile.get_energy_points_list", { start: this.activity_start, limit: this.activity_limit, - user: this.user + user: this.user, }); } get_activity_timeline_item(data) { - let icon = data.type == 'Appreciation' ? 'clap': data.type == 'Criticism' ? 'criticize': null; + let icon = + data.type == "Appreciation" ? "clap" : data.type == "Criticism" ? "criticize" : null; return { icon: icon, creation: data.creation, @@ -424,23 +469,27 @@ class UserProfileTimeline extends BaseTimeline { } setup_show_more_activity() { - this.show_more_button = $(`
        ${__('Show More Activity')}`); + this.show_more_button = $( + `${__("Show More Activity")}` + ); this.show_more_button.hide(); this.footer.append(this.show_more_button); - this.show_more_button.on('click', () => this.show_more_activity()); + this.show_more_button.on("click", () => this.show_more_activity()); } show_more_activity() { this.activity_start += this.activity_limit; - this.get_user_activity_data().then(activities => { + this.get_user_activity_data().then((activities) => { if (!activities.length || activities.length < this.activity_limit) { this.show_more_button.hide(); } - let timeline_items = activities.map((activity) => this.get_activity_timeline_item(activity)); + let timeline_items = activities.map((activity) => + this.get_activity_timeline_item(activity) + ); timeline_items.map((item) => this.add_timeline_item(item, true)); }); } } -frappe.provide('frappe.ui'); +frappe.provide("frappe.ui"); frappe.ui.UserProfile = UserProfile; diff --git a/frappe/desk/report/todo/todo.js b/frappe/desk/report/todo/todo.js index bb2e0f7846..52fee62afd 100644 --- a/frappe/desk/report/todo/todo.js +++ b/frappe/desk/report/todo/todo.js @@ -3,7 +3,5 @@ /* eslint-disable */ frappe.query_reports["ToDo"] = { - "filters": [ - - ] -} + filters: [], +}; diff --git a/frappe/email/doctype/auto_email_report/auto_email_report.js b/frappe/email/doctype/auto_email_report/auto_email_report.js index 3423c3ccba..6930078512 100644 --- a/frappe/email/doctype/auto_email_report/auto_email_report.js +++ b/frappe/email/doctype/auto_email_report/auto_email_report.js @@ -1,139 +1,156 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Auto Email Report', { - refresh: function(frm) { - frm.trigger('fetch_report_filters'); - if(!frm.is_new()) { - frm.add_custom_button(__('Download'), function() { +frappe.ui.form.on("Auto Email Report", { + refresh: function (frm) { + frm.trigger("fetch_report_filters"); + if (!frm.is_new()) { + frm.add_custom_button(__("Download"), function () { var w = window.open( frappe.urllib.get_full_url( - "/api/method/frappe.email.doctype.auto_email_report.auto_email_report.download?" - +"name="+encodeURIComponent(frm.doc.name))); - if(!w) { - frappe.msgprint(__("Please enable pop-ups")); return; + "/api/method/frappe.email.doctype.auto_email_report.auto_email_report.download?" + + "name=" + + encodeURIComponent(frm.doc.name) + ) + ); + if (!w) { + frappe.msgprint(__("Please enable pop-ups")); + return; } }); - frm.add_custom_button(__('Send Now'), function() { + frm.add_custom_button(__("Send Now"), function () { frappe.call({ - method: 'frappe.email.doctype.auto_email_report.auto_email_report.send_now', - args: {name: frm.doc.name}, - callback: function() { - frappe.msgprint(__('Scheduled to send')); - } + method: "frappe.email.doctype.auto_email_report.auto_email_report.send_now", + args: { name: frm.doc.name }, + callback: function () { + frappe.msgprint(__("Scheduled to send")); + }, }); }); } else { - if(!frm.doc.user) { - frm.set_value('user', frappe.session.user); + if (!frm.doc.user) { + frm.set_value("user", frappe.session.user); } - if(!frm.doc.email_to) { - frm.set_value('email_to', frappe.session.user); + if (!frm.doc.email_to) { + frm.set_value("email_to", frappe.session.user); } } }, - report: function(frm) { - frm.set_value('filters', ''); - frm.trigger('fetch_report_filters'); + report: function (frm) { + frm.set_value("filters", ""); + frm.trigger("fetch_report_filters"); }, fetch_report_filters(frm) { - if (frm.doc.report - && frm.doc.report_type !== 'Report Builder' - && frm.script_setup_for !== frm.doc.report + if ( + frm.doc.report && + frm.doc.report_type !== "Report Builder" && + frm.script_setup_for !== frm.doc.report ) { frappe.call({ method: "frappe.desk.query_report.get_script", args: { - report_name: frm.doc.report + report_name: frm.doc.report, }, - callback: function(r) { + callback: function (r) { frappe.dom.eval(r.message.script || ""); frm.script_setup_for = frm.doc.report; - frm.trigger('show_filters'); - } + frm.trigger("show_filters"); + }, }); } else { - frm.trigger('show_filters'); + frm.trigger("show_filters"); } }, - show_filters: function(frm) { - var wrapper = $(frm.get_field('filters_display').wrapper); + show_filters: function (frm) { + var wrapper = $(frm.get_field("filters_display").wrapper); wrapper.empty(); - if(frm.doc.report_type === 'Custom Report' || (frm.doc.report_type !== 'Report Builder' - && frappe.query_reports[frm.doc.report] - && frappe.query_reports[frm.doc.report].filters)) { - + if ( + frm.doc.report_type === "Custom Report" || + (frm.doc.report_type !== "Report Builder" && + frappe.query_reports[frm.doc.report] && + frappe.query_reports[frm.doc.report].filters) + ) { // make a table to show filters - var table = $('\ - \ -
        '+__('Filter')+''+__('Value')+'
        ').appendTo(wrapper); - $('

        ' + __("Click table to edit") + '

        ').appendTo(wrapper); + var table = $( + '\ + \ +
        ' + + __("Filter") + + "" + + __("Value") + + "
        " + ).appendTo(wrapper); + $('

        ' + __("Click table to edit") + "

        ").appendTo( + wrapper + ); - var filters = JSON.parse(frm.doc.filters || '{}'); + var filters = JSON.parse(frm.doc.filters || "{}"); let report_filters; - if (frm.doc.report_type === 'Custom Report' - && frappe.query_reports[frm.doc.reference_report] - && frappe.query_reports[frm.doc.reference_report].filters) { + if ( + frm.doc.report_type === "Custom Report" && + frappe.query_reports[frm.doc.reference_report] && + frappe.query_reports[frm.doc.reference_report].filters + ) { report_filters = frappe.query_reports[frm.doc.reference_report].filters; } else { report_filters = frappe.query_reports[frm.doc.report].filters; } - if(report_filters && report_filters.length > 0) { - frm.set_value('filter_meta', JSON.stringify(report_filters)); + if (report_filters && report_filters.length > 0) { + frm.set_value("filter_meta", JSON.stringify(report_filters)); if (frm.is_dirty()) { frm.save(); } } - var report_filters_list = [] - $.each(report_filters, function(key, val){ + var report_filters_list = []; + $.each(report_filters, function (key, val) { // Remove break fieldtype from the filters - if(val.fieldtype != 'Break') { - report_filters_list.push(val) + if (val.fieldtype != "Break") { + report_filters_list.push(val); } - }) + }); report_filters = report_filters_list; const mandatory_css = { "background-color": "var(--error-bg)", - "font-weight": "bold" + "font-weight": "bold", }; - report_filters.forEach(f => { + report_filters.forEach((f) => { const css = f.reqd ? mandatory_css : {}; const row = $("").appendTo(table.find("tbody")); $("" + f.label + "").appendTo(row); - $("" + frappe.format(filters[f.fieldname], f) +"") + $("" + frappe.format(filters[f.fieldname], f) + "") .css(css) .appendTo(row); }); - table.on('click', function() { + table.on("click", function () { var dialog = new frappe.ui.Dialog({ fields: report_filters, - primary_action: function() { + primary_action: function () { var values = this.get_values(); - if(values) { + if (values) { this.hide(); - frm.set_value('filters', JSON.stringify(values)); - frm.trigger('show_filters'); + frm.set_value("filters", JSON.stringify(values)); + frm.trigger("show_filters"); } - } + }, }); dialog.show(); dialog.set_values(filters); - }) + }); // populate dynamic date field selection let date_fields = report_filters - .filter(df => df.fieldtype === 'Date') - .map(df => ({ label: df.label, value: df.fieldname })); - frm.set_df_property('from_date_field', 'options', date_fields); - frm.set_df_property('to_date_field', 'options', date_fields); - frm.toggle_display('dynamic_report_filters_section', date_fields.length > 0); + .filter((df) => df.fieldtype === "Date") + .map((df) => ({ label: df.label, value: df.fieldname })); + frm.set_df_property("from_date_field", "options", date_fields); + frm.set_df_property("to_date_field", "options", date_fields); + frm.toggle_display("dynamic_report_filters_section", date_fields.length > 0); } - } + }, }); diff --git a/frappe/email/doctype/document_follow/document_follow.js b/frappe/email/doctype/document_follow/document_follow.js index 3fdf055d36..59efb37341 100644 --- a/frappe/email/doctype/document_follow/document_follow.js +++ b/frappe/email/doctype/document_follow/document_follow.js @@ -1,6 +1,4 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Document Follow', { - -}); +frappe.ui.form.on("Document Follow", {}); diff --git a/frappe/email/doctype/email_account/email_account.js b/frappe/email/doctype/email_account/email_account.js index 3faf83800d..3e42af7051 100644 --- a/frappe/email/doctype/email_account/email_account.js +++ b/frappe/email/doctype/email_account/email_account.js @@ -1,84 +1,83 @@ frappe.email_defaults = { - "GMail": { - "email_server": "imap.gmail.com", - "incoming_port": 993, - "use_ssl": 1, - "enable_outgoing": 1, - "smtp_server": "smtp.gmail.com", - "smtp_port": 587, - "use_tls": 1, - "use_imap": 1 + GMail: { + email_server: "imap.gmail.com", + incoming_port: 993, + use_ssl: 1, + enable_outgoing: 1, + smtp_server: "smtp.gmail.com", + smtp_port: 587, + use_tls: 1, + use_imap: 1, }, "Outlook.com": { - "email_server": "imap-mail.outlook.com", - "use_ssl": 1, - "enable_outgoing": 1, - "smtp_server": "smtp-mail.outlook.com", - "smtp_port": 587, - "use_tls": 1, - "use_imap": 1 + email_server: "imap-mail.outlook.com", + use_ssl: 1, + enable_outgoing: 1, + smtp_server: "smtp-mail.outlook.com", + smtp_port: 587, + use_tls: 1, + use_imap: 1, }, - "Sendgrid": { - "enable_outgoing": 1, - "smtp_server": "smtp.sendgrid.net", - "smtp_port": 587, - "use_tls": 1, + Sendgrid: { + enable_outgoing: 1, + smtp_server: "smtp.sendgrid.net", + smtp_port: 587, + use_tls: 1, }, - "SparkPost": { - "enable_incoming": 0, - "enable_outgoing": 1, - "smtp_server": "smtp.sparkpostmail.com", - "smtp_port": 587, - "use_tls": 1 + SparkPost: { + enable_incoming: 0, + enable_outgoing: 1, + smtp_server: "smtp.sparkpostmail.com", + smtp_port: 587, + use_tls: 1, }, "Yahoo Mail": { - "email_server": "imap.mail.yahoo.com", - "use_ssl": 1, - "enable_outgoing": 1, - "smtp_server": "smtp.mail.yahoo.com", - "smtp_port": 587, - "use_tls": 1, - "use_imap": 1 + email_server: "imap.mail.yahoo.com", + use_ssl: 1, + enable_outgoing: 1, + smtp_server: "smtp.mail.yahoo.com", + smtp_port: 587, + use_tls: 1, + use_imap: 1, }, "Yandex.Mail": { - "email_server": "imap.yandex.com", - "use_ssl": 1, - "enable_outgoing": 1, - "smtp_server": "smtp.yandex.com", - "smtp_port": 587, - "use_tls": 1, - "use_imap": 1 + email_server: "imap.yandex.com", + use_ssl: 1, + enable_outgoing: 1, + smtp_server: "smtp.yandex.com", + smtp_port: 587, + use_tls: 1, + use_imap: 1, }, }; frappe.email_defaults_pop = { - "GMail": { - "email_server": "pop.gmail.com" + GMail: { + email_server: "pop.gmail.com", }, "Outlook.com": { - "email_server": "pop3-mail.outlook.com" + email_server: "pop3-mail.outlook.com", }, "Yahoo Mail": { - "email_server": "pop.mail.yahoo.com" + email_server: "pop.mail.yahoo.com", }, "Yandex.Mail": { - "email_server": "pop.yandex.com" + email_server: "pop.yandex.com", }, - }; function oauth_access(frm) { return frappe.call({ method: "frappe.email.oauth.oauth_access", args: { - "email_account": frm.doc.name, - "service": frm.doc.service || "" + email_account: frm.doc.name, + service: frm.doc.service || "", }, - callback: function(r) { + callback: function (r) { if (!r.exc) { window.open(r.message.url, "_self"); } - } + }, }); } @@ -86,9 +85,9 @@ function set_default_max_attachment_size(frm, field) { if (frm.doc.__islocal && !frm.doc[field]) { frappe.call({ method: "frappe.core.api.file.get_max_file_size", - callback: function(r) { + callback: function (r) { if (!r.exc) { - frm.set_value(field, Number(r.message)/(1024*1024)); + frm.set_value(field, Number(r.message) / (1024 * 1024)); } }, }); @@ -96,12 +95,12 @@ function set_default_max_attachment_size(frm, field) { } frappe.ui.form.on("Email Account", { - service: function(frm) { - $.each(frappe.email_defaults[frm.doc.service], function(key, value) { + service: function (frm) { + $.each(frappe.email_defaults[frm.doc.service], function (key, value) { frm.set_value(key, value); }); if (!frm.doc.use_imap) { - $.each(frappe.email_defaults_pop[frm.doc.service], function(key, value) { + $.each(frappe.email_defaults_pop[frm.doc.service], function (key, value) { frm.set_value(key, value); }); } @@ -109,54 +108,56 @@ frappe.ui.form.on("Email Account", { frm.events.toggle_auth_method(frm); }, - use_imap: function(frm) { + use_imap: function (frm) { if (!frm.doc.use_imap) { - $.each(frappe.email_defaults_pop[frm.doc.service], function(key, value) { + $.each(frappe.email_defaults_pop[frm.doc.service], function (key, value) { frm.set_value(key, value); }); - } - else{ - $.each(frappe.email_defaults[frm.doc.service], function(key, value) { + } else { + $.each(frappe.email_defaults[frm.doc.service], function (key, value) { frm.set_value(key, value); }); } }, - enable_incoming: function(frm) { + enable_incoming: function (frm) { frm.trigger("warn_autoreply_on_incoming"); }, - enable_auto_reply: function(frm) { + enable_auto_reply: function (frm) { frm.trigger("warn_autoreply_on_incoming"); }, - notify_if_unreplied: function(frm) { + notify_if_unreplied: function (frm) { frm.set_df_property("send_notification_to", "reqd", frm.doc.notify_if_unreplied); }, - onload: function(frm) { - if (frappe.utils.get_query_params().successful_authorization === '1') { + onload: function (frm) { + if (frappe.utils.get_query_params().successful_authorization === "1") { frappe.show_alert(__("Successfully Authorized")); // FIXME: find better alternative window.history.replaceState(null, "", window.location.pathname); } frm.set_df_property("append_to", "only_select", true); - frm.set_query("append_to", "frappe.email.doctype.email_account.email_account.get_append_to"); - frm.set_query("append_to", "imap_folder", function() { + frm.set_query( + "append_to", + "frappe.email.doctype.email_account.email_account.get_append_to" + ); + frm.set_query("append_to", "imap_folder", function () { return { - query: "frappe.email.doctype.email_account.email_account.get_append_to" + query: "frappe.email.doctype.email_account.email_account.get_append_to", }; }); if (frm.doc.__islocal) { - frm.add_child("imap_folder", {"folder_name": "INBOX"}); + frm.add_child("imap_folder", { folder_name: "INBOX" }); frm.refresh_field("imap_folder"); } - frm.toggle_display(['auth_method'], frm.doc.service === "GMail"); + frm.toggle_display(["auth_method"], frm.doc.service === "GMail"); set_default_max_attachment_size(frm, "attachment_limit"); }, - refresh: function(frm) { + refresh: function (frm) { frm.events.set_domain_fields(frm); frm.events.enable_incoming(frm); frm.events.notify_if_unreplied(frm); @@ -165,7 +166,7 @@ frappe.ui.form.on("Email Account", { if (frappe.route_flags.delete_user_from_locals && frappe.route_flags.linked_user) { delete frappe.route_flags.delete_user_from_locals; - delete locals['User'][frappe.route_flags.linked_user]; + delete locals["User"][frappe.route_flags.linked_user]; } }, @@ -175,67 +176,71 @@ frappe.ui.form.on("Email Account", { } }, - toggle_auth_method: function(frm) { + toggle_auth_method: function (frm) { if (frm.doc.service !== "GMail") { - frm.toggle_display(['auth_method'], false); + frm.toggle_display(["auth_method"], false); frm.doc.auth_method = "Basic"; } else { - frm.toggle_display(['auth_method'], true); + frm.toggle_display(["auth_method"], true); } }, - show_gmail_message_for_less_secure_apps: function(frm) { + show_gmail_message_for_less_secure_apps: function (frm) { frm.dashboard.clear_headline(); - let msg = __("GMail will only work if you enable 2-step authentication and use app-specific password OR use OAuth."); + let msg = __( + "GMail will only work if you enable 2-step authentication and use app-specific password OR use OAuth." + ); let cta = __("Read the step by step guide here."); msg += ` ${cta}`; - if (frm.doc.service==="GMail") { + if (frm.doc.service === "GMail") { frm.dashboard.set_headline_alert(msg); } }, show_oauth_authorization_message(frm) { if (frm.doc.auth_method === "OAuth" && !frm.doc.refresh_token) { - let msg = __('OAuth has been enabled but not authorised. Please use "Authorise API Access" button to do the same.') + let msg = __( + 'OAuth has been enabled but not authorised. Please use "Authorise API Access" button to do the same.' + ); frm.dashboard.clear_headline(); frm.dashboard.set_headline_alert(msg, "yellow"); } }, - authorize_api_access: function(frm) { + authorize_api_access: function (frm) { oauth_access(frm); }, - email_id:function(frm) { + email_id: function (frm) { //pull domain and if no matching domain go create one frm.events.update_domain(frm); }, - update_domain: function(frm) { + update_domain: function (frm) { if (!frm.doc.email_id && !frm.doc.service) { return; } frappe.call({ - method: 'get_domain', + method: "get_domain", doc: frm.doc, args: { - "email_id": frm.doc.email_id + email_id: frm.doc.email_id, }, - callback: function(r) { + callback: function (r) { if (r.message) { frm.events.set_domain_fields(frm, r.message); } - } + }, }); }, - set_domain_fields: function(frm, args) { + set_domain_fields: function (frm, args) { if (!args) { - args = frappe.route_flags.set_domain_values? frappe.route_options: {}; + args = frappe.route_flags.set_domain_values ? frappe.route_options : {}; } - for(var field in args) { + for (var field in args) { frm.set_value(field, args[field]); } @@ -243,24 +248,28 @@ frappe.ui.form.on("Email Account", { frappe.route_options = {}; }, - email_sync_option: function(frm) { + email_sync_option: function (frm) { // confirm if the ALL sync option is selected if (frm.doc.email_sync_option == "ALL") { - var msg = __("You are selecting Sync Option as ALL, It will resync all read as well as unread message from server. This may also cause the duplication of Communication (emails)."); - frappe.confirm(msg, null, function() { + var msg = __( + "You are selecting Sync Option as ALL, It will resync all read as well as unread message from server. This may also cause the duplication of Communication (emails)." + ); + frappe.confirm(msg, null, function () { frm.set_value("email_sync_option", "UNSEEN"); }); } }, - warn_autoreply_on_incoming: function(frm) { + warn_autoreply_on_incoming: function (frm) { if (frm.doc.enable_incoming && frm.doc.enable_auto_reply && frm.doc.__islocal) { - var msg = __("Enabling auto reply on an incoming email account will send automated replies to all the synchronized emails. Do you wish to continue?"); - frappe.confirm(msg, null, function() { + var msg = __( + "Enabling auto reply on an incoming email account will send automated replies to all the synchronized emails. Do you wish to continue?" + ); + frappe.confirm(msg, null, function () { frm.set_value("enable_auto_reply", 0); - frappe.show_alert({message: __("Disabled Auto Reply"), indicator: "blue"}); + frappe.show_alert({ message: __("Disabled Auto Reply"), indicator: "blue" }); }); } - } + }, }); diff --git a/frappe/email/doctype/email_account/email_account_list.js b/frappe/email/doctype/email_account/email_account_list.js index 5ec56fb3db..5913706cbf 100644 --- a/frappe/email/doctype/email_account/email_account_list.js +++ b/frappe/email/doctype/email_account/email_account_list.js @@ -1,23 +1,24 @@ frappe.listview_settings["Email Account"] = { add_fields: ["default_incoming", "default_outgoing", "enable_incoming", "enable_outgoing"], - get_indicator: function(doc) { - if(doc.default_incoming && doc.default_outgoing) { - var color = (doc.enable_incoming && doc.enable_outgoing) ? "blue" : "gray"; - return [__("Default Sending and Inbox"), color, "default_incoming,=,Yes|default_outgoing,=,Yes"] - } - else if(doc.default_incoming) { + get_indicator: function (doc) { + if (doc.default_incoming && doc.default_outgoing) { + var color = doc.enable_incoming && doc.enable_outgoing ? "blue" : "gray"; + return [ + __("Default Sending and Inbox"), + color, + "default_incoming,=,Yes|default_outgoing,=,Yes", + ]; + } else if (doc.default_incoming) { color = doc.enable_incoming ? "blue" : "gray"; return [__("Default Inbox"), color, "default_incoming,=,Yes"]; - } - else if(doc.default_outgoing) { + } else if (doc.default_outgoing) { color = doc.enable_outgoing ? "blue" : "gray"; return [__("Default Sending"), color, "default_outgoing,=,Yes"]; - } - else { + } else { color = doc.enable_incoming ? "blue" : "gray"; return [__("Inbox"), color, "is_global,=,No|is_default=No"]; } - } -} + }, +}; frappe.help.youtube_id["Email Account"] = "YFYe0DrB95o"; diff --git a/frappe/email/doctype/email_domain/email_domain.js b/frappe/email/doctype/email_domain/email_domain.js index 1716bf9900..ea93758905 100644 --- a/frappe/email/doctype/email_domain/email_domain.js +++ b/frappe/email/doctype/email_domain/email_domain.js @@ -1,29 +1,28 @@ - frappe.ui.form.on("Email Domain", { - email_id:function(frm){ - frm.set_value("domain_name",frm.doc.email_id.split("@")[1]) + email_id: function (frm) { + frm.set_value("domain_name", frm.doc.email_id.split("@")[1]); }, - refresh:function(frm){ - if (frm.doc.email_id){ - frm.set_value("domain_name",frm.doc.email_id.split("@")[1]) + refresh: function (frm) { + if (frm.doc.email_id) { + frm.set_value("domain_name", frm.doc.email_id.split("@")[1]); } if (frm.doc.__islocal != 1 && frappe.route_flags.return_to_email_account) { var route = frappe.get_prev_route(); delete frappe.route_flags.return_to_email_account; - frappe.route_flags.set_domain_values = true + frappe.route_flags.set_domain_values = true; - frappe.route_options = { + (frappe.route_options = { domain: frm.doc.name, use_imap: frm.doc.use_imap, email_server: frm.doc.email_server, use_ssl: frm.doc.use_ssl, smtp_server: frm.doc.smtp_server, use_tls: frm.doc.use_tls, - smtp_port: frm.doc.smtp_port - }, - frappe.set_route(route); + smtp_port: frm.doc.smtp_port, + }), + frappe.set_route(route); } - } -}) \ No newline at end of file + }, +}); diff --git a/frappe/email/doctype/email_flag_queue/email_flag_queue.js b/frappe/email/doctype/email_flag_queue/email_flag_queue.js index 19c4d4b0c1..ee062815f5 100644 --- a/frappe/email/doctype/email_flag_queue/email_flag_queue.js +++ b/frappe/email/doctype/email_flag_queue/email_flag_queue.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Email Flag Queue', { - refresh: function(frm) { - - } +frappe.ui.form.on("Email Flag Queue", { + refresh: function (frm) {}, }); diff --git a/frappe/email/doctype/email_group/email_group.js b/frappe/email/doctype/email_group/email_group.js index 404600c97d..5ad4a39dd9 100644 --- a/frappe/email/doctype/email_group/email_group.js +++ b/frappe/email/doctype/email_group/email_group.js @@ -1,46 +1,74 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on("Email Group", "refresh", function(frm) { - if(!frm.is_new()) { - frm.add_custom_button(__("Import Subscribers"), function() { - frappe.prompt({fieldtype:"Select", options: frm.doc.__onload.import_types, - label:__("Import Email From"), fieldname:"doctype", reqd:1}, - function(data) { - frappe.call({ - method: "frappe.email.doctype.email_group.email_group.import_from", - args: { - "name": frm.doc.name, - "doctype": data.doctype - }, - callback: function(r) { - frm.set_value("total_subscribers", r.message); - } - }) - }, __("Import Subscribers"), __("Import")); - }, __("Action")); +frappe.ui.form.on("Email Group", "refresh", function (frm) { + if (!frm.is_new()) { + frm.add_custom_button( + __("Import Subscribers"), + function () { + frappe.prompt( + { + fieldtype: "Select", + options: frm.doc.__onload.import_types, + label: __("Import Email From"), + fieldname: "doctype", + reqd: 1, + }, + function (data) { + frappe.call({ + method: "frappe.email.doctype.email_group.email_group.import_from", + args: { + name: frm.doc.name, + doctype: data.doctype, + }, + callback: function (r) { + frm.set_value("total_subscribers", r.message); + }, + }); + }, + __("Import Subscribers"), + __("Import") + ); + }, + __("Action") + ); - frm.add_custom_button(__("Add Subscribers"), function() { - frappe.prompt({fieldtype:"Text", - label:__("Email Addresses"), fieldname:"email_list", reqd:1}, - function(data) { - frappe.call({ - method: "frappe.email.doctype.email_group.email_group.add_subscribers", - args: { - "name": frm.doc.name, - "email_list": data.email_list - }, - callback: function(r) { - frm.set_value("total_subscribers", r.message); - } - }) - }, __("Add Subscribers"), __("Add")); - }, __("Action")); - - frm.add_custom_button(__("New Newsletter"), function() { - frappe.route_options = {"email_group": frm.doc.name}; - frappe.new_doc("Newsletter"); - }, __("Action")); + frm.add_custom_button( + __("Add Subscribers"), + function () { + frappe.prompt( + { + fieldtype: "Text", + label: __("Email Addresses"), + fieldname: "email_list", + reqd: 1, + }, + function (data) { + frappe.call({ + method: "frappe.email.doctype.email_group.email_group.add_subscribers", + args: { + name: frm.doc.name, + email_list: data.email_list, + }, + callback: function (r) { + frm.set_value("total_subscribers", r.message); + }, + }); + }, + __("Add Subscribers"), + __("Add") + ); + }, + __("Action") + ); + frm.add_custom_button( + __("New Newsletter"), + function () { + frappe.route_options = { email_group: frm.doc.name }; + frappe.new_doc("Newsletter"); + }, + __("Action") + ); } }); diff --git a/frappe/email/doctype/email_group_member/email_group_member.js b/frappe/email/doctype/email_group_member/email_group_member.js index 417eb70119..ca2c17ad81 100644 --- a/frappe/email/doctype/email_group_member/email_group_member.js +++ b/frappe/email/doctype/email_group_member/email_group_member.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Email Group Member', { - refresh: function(frm) { - - } +frappe.ui.form.on("Email Group Member", { + refresh: function (frm) {}, }); diff --git a/frappe/email/doctype/email_queue/email_queue.js b/frappe/email/doctype/email_queue/email_queue.js index b6ef0ec082..2ac4b6f7fe 100644 --- a/frappe/email/doctype/email_queue/email_queue.js +++ b/frappe/email/doctype/email_queue/email_queue.js @@ -2,37 +2,37 @@ // For license information, please see license.txt frappe.ui.form.on("Email Queue", { - refresh: function(frm) { - if (["Not Sent","Partially Sent"].indexOf(frm.doc.status)!=-1) { - let button = frm.add_custom_button("Send Now", function() { + refresh: function (frm) { + if (["Not Sent", "Partially Sent"].indexOf(frm.doc.status) != -1) { + let button = frm.add_custom_button("Send Now", function () { frappe.call({ - method: 'frappe.email.doctype.email_queue.email_queue.send_now', + method: "frappe.email.doctype.email_queue.email_queue.send_now", args: { - name: frm.doc.name + name: frm.doc.name, }, btn: button, - callback: function() { + callback: function () { frm.reload_doc(); - } + }, }); }); } - if (["Error","Partially Errored"].indexOf(frm.doc.status)!=-1) { - let button = frm.add_custom_button("Retry Sending", function() { + if (["Error", "Partially Errored"].indexOf(frm.doc.status) != -1) { + let button = frm.add_custom_button("Retry Sending", function () { frm.call({ method: "retry_sending", args: { - name: frm.doc.name + name: frm.doc.name, }, btn: button, - callback: function(r) { + callback: function (r) { if (!r.exc) { frm.set_value("status", "Not Sent"); } - } - }) + }, + }); }); } - } + }, }); diff --git a/frappe/email/doctype/email_queue/email_queue_list.js b/frappe/email/doctype/email_queue/email_queue_list.js index ab2a1b9a45..b00503b6f8 100644 --- a/frappe/email/doctype/email_queue/email_queue_list.js +++ b/frappe/email/doctype/email_queue/email_queue_list.js @@ -1,39 +1,41 @@ -frappe.listview_settings['Email Queue'] = { - get_indicator: function(doc) { - var colour = {'Sent': 'green', 'Sending': 'blue', 'Not Sent': 'grey', 'Error': 'red', 'Expired': 'orange'}; +frappe.listview_settings["Email Queue"] = { + get_indicator: function (doc) { + var colour = { + Sent: "green", + Sending: "blue", + "Not Sent": "grey", + Error: "red", + Expired: "orange", + }; return [__(doc.status), colour[doc.status], "status,=," + doc.status]; }, refresh: show_toggle_sending_button, - onload: function(list_view) { + onload: function (list_view) { frappe.require("logtypes.bundle.js", () => { frappe.utils.logtypes.show_log_retention_message(list_view.doctype); - }) - } + }); + }, }; function show_toggle_sending_button(list_view) { - if (!has_common(frappe.user_roles, ["Administrator", "System Manager"])) - return; + if (!has_common(frappe.user_roles, ["Administrator", "System Manager"])) return; const sending_disabled = cint(frappe.sys_defaults.suspend_email_queue); const label = sending_disabled ? __("Resume Sending") : __("Suspend Sending"); - list_view.page.add_inner_button( - label, - async () => { - await frappe.xcall( - "frappe.email.doctype.email_queue.email_queue.toggle_sending", + list_view.page.add_inner_button(label, async () => { + await frappe.xcall( + "frappe.email.doctype.email_queue.email_queue.toggle_sending", - // enable if disabled - {enable: sending_disabled} - ); + // enable if disabled + { enable: sending_disabled } + ); - // set new value for suspend_email_queue in sys_defaults - frappe.sys_defaults.suspend_email_queue = sending_disabled ? 0 : 1; + // set new value for suspend_email_queue in sys_defaults + frappe.sys_defaults.suspend_email_queue = sending_disabled ? 0 : 1; - // clear the button and show one with the opposite label - list_view.page.remove_inner_button(label); - show_toggle_sending_button(list_view); - } - ); -} \ No newline at end of file + // clear the button and show one with the opposite label + list_view.page.remove_inner_button(label); + show_toggle_sending_button(list_view); + }); +} diff --git a/frappe/email/doctype/email_rule/email_rule.js b/frappe/email/doctype/email_rule/email_rule.js index 974bcd4e51..2670ef3e1c 100644 --- a/frappe/email/doctype/email_rule/email_rule.js +++ b/frappe/email/doctype/email_rule/email_rule.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Email Rule', { - refresh: function(frm) { - - } +frappe.ui.form.on("Email Rule", { + refresh: function (frm) {}, }); diff --git a/frappe/email/doctype/email_template/email_template.js b/frappe/email/doctype/email_template/email_template.js index 62ce4d94ad..33327005a5 100644 --- a/frappe/email/doctype/email_template/email_template.js +++ b/frappe/email/doctype/email_template/email_template.js @@ -1,8 +1,6 @@ // Copyright (c) 2018, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Email Template', { - refresh: function() { - - } +frappe.ui.form.on("Email Template", { + refresh: function () {}, }); diff --git a/frappe/email/doctype/email_unsubscribe/email_unsubscribe.js b/frappe/email/doctype/email_unsubscribe/email_unsubscribe.js index 9a022cf4ca..5f1e28e9b9 100644 --- a/frappe/email/doctype/email_unsubscribe/email_unsubscribe.js +++ b/frappe/email/doctype/email_unsubscribe/email_unsubscribe.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Email Unsubscribe', { - refresh: function(frm) { - - } +frappe.ui.form.on("Email Unsubscribe", { + refresh: function (frm) {}, }); diff --git a/frappe/email/doctype/newsletter/newsletter.js b/frappe/email/doctype/newsletter/newsletter.js index 3c52e61cbb..8a81bbaab3 100644 --- a/frappe/email/doctype/newsletter/newsletter.js +++ b/frappe/email/doctype/newsletter/newsletter.js @@ -1,113 +1,146 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -frappe.ui.form.on('Newsletter', { +frappe.ui.form.on("Newsletter", { refresh(frm) { let doc = frm.doc; let can_write = in_list(frappe.boot.user.can_write, doc.doctype); if (!frm.is_new() && !frm.is_dirty() && !doc.email_sent && can_write) { - frm.add_custom_button(__('Send a test email'), () => { - frm.events.send_test_email(frm); - }, __('Preview')); + frm.add_custom_button( + __("Send a test email"), + () => { + frm.events.send_test_email(frm); + }, + __("Preview") + ); - frm.add_custom_button(__('Check broken links'), () => { - frm.dashboard.set_headline(__('Checking broken links...')); - frm.call('find_broken_links').then(r => { - frm.dashboard.set_headline(''); - let links = r.message; - if (links && links.length) { - let html = '
          ' + links.map(link => `
        • ${link}
        • `).join('') + '
        '; - frm.dashboard.set_headline(__("Following links are broken in the email content: {0}", [html])); - } else { - frm.dashboard.set_headline(__("No broken links found in the email content")); - setTimeout(() => { - frm.dashboard.set_headline(''); - }, 3000); - } - }); - }, __('Preview')); - - frm.add_custom_button(__('Send now'), () => { - if (frm.doc.schedule_send) { - frappe.confirm(__("This newsletter was scheduled to send on a later date. Are you sure you want to send it now?"), function () { - frm.events.send_emails(frm); + frm.add_custom_button( + __("Check broken links"), + () => { + frm.dashboard.set_headline(__("Checking broken links...")); + frm.call("find_broken_links").then((r) => { + frm.dashboard.set_headline(""); + let links = r.message; + if (links && links.length) { + let html = + "
          " + + links.map((link) => `
        • ${link}
        • `).join("") + + "
        "; + frm.dashboard.set_headline( + __("Following links are broken in the email content: {0}", [html]) + ); + } else { + frm.dashboard.set_headline( + __("No broken links found in the email content") + ); + setTimeout(() => { + frm.dashboard.set_headline(""); + }, 3000); + } }); - return; - } - frappe.confirm(__("Are you sure you want to send this newsletter now?"), () => { - frm.events.send_emails(frm); - }); - }, __('Send')); + }, + __("Preview") + ); - frm.add_custom_button(__('Schedule sending'), () => { - frm.events.schedule_send_dialog(frm); - }, __('Send')); + frm.add_custom_button( + __("Send now"), + () => { + if (frm.doc.schedule_send) { + frappe.confirm( + __( + "This newsletter was scheduled to send on a later date. Are you sure you want to send it now?" + ), + function () { + frm.events.send_emails(frm); + } + ); + return; + } + frappe.confirm( + __("Are you sure you want to send this newsletter now?"), + () => { + frm.events.send_emails(frm); + } + ); + }, + __("Send") + ); + + frm.add_custom_button( + __("Schedule sending"), + () => { + frm.events.schedule_send_dialog(frm); + }, + __("Send") + ); } frm.events.update_sending_status(frm); if (frm.is_new() && !doc.sender_email) { let { fullname, email } = frappe.user_info(doc.owner); - frm.set_value('sender_email', email); - frm.set_value('sender_name', fullname); + frm.set_value("sender_email", email); + frm.set_value("sender_name", fullname); } - frm.trigger('update_schedule_message'); + frm.trigger("update_schedule_message"); }, send_emails(frm) { frappe.dom.freeze(__("Queuing emails...")); - frm.call('send_emails').then(() => { + frm.call("send_emails").then(() => { frm.refresh(); frappe.dom.unfreeze(); - frappe.show_alert(__("Queued {0} emails", [frappe.utils.shorten_number(frm.doc.total_recipients)])); + frappe.show_alert( + __("Queued {0} emails", [frappe.utils.shorten_number(frm.doc.total_recipients)]) + ); }); }, schedule_send_dialog(frm) { let hours = frappe.utils.range(24); - let time_slots = hours.map(hour => { - return `${(hour + '').padStart(2, '0')}:00`; + let time_slots = hours.map((hour) => { + return `${(hour + "").padStart(2, "0")}:00`; }); let d = new frappe.ui.Dialog({ - title: __('Schedule Newsletter'), + title: __("Schedule Newsletter"), fields: [ { - label: __('Date'), - fieldname: 'date', - fieldtype: 'Date', + label: __("Date"), + fieldname: "date", + fieldtype: "Date", options: { - minDate: new Date() - } + minDate: new Date(), + }, }, { - label: __('Time'), - fieldname: 'time', - fieldtype: 'Select', + label: __("Time"), + fieldname: "time", + fieldtype: "Select", options: time_slots, }, ], - primary_action_label: __('Schedule'), + primary_action_label: __("Schedule"), primary_action({ date, time }) { - frm.set_value('schedule_sending', 1); - frm.set_value('schedule_send', `${date} ${time}:00`); + frm.set_value("schedule_sending", 1); + frm.set_value("schedule_send", `${date} ${time}:00`); d.hide(); frm.save(); }, - secondary_action_label: __('Cancel Scheduling'), + secondary_action_label: __("Cancel Scheduling"), secondary_action() { - frm.set_value('schedule_sending', 0); - frm.set_value('schedule_send', ''); + frm.set_value("schedule_sending", 0); + frm.set_value("schedule_send", ""); d.hide(); frm.save(); - } + }, }); if (frm.doc.schedule_sending) { - let parts = frm.doc.schedule_send.split(' '); + let parts = frm.doc.schedule_send.split(" "); if (parts.length === 2) { let [date, time] = parts; - d.set_value('date', date); - d.set_value('time', time.slice(0, 5)); + d.set_value("date", date); + d.set_value("time", time.slice(0, 5)); } } d.show(); @@ -115,35 +148,37 @@ frappe.ui.form.on('Newsletter', { send_test_email(frm) { let d = new frappe.ui.Dialog({ - title: __('Send Test Email'), + title: __("Send Test Email"), fields: [ { - label: __('Email'), - fieldname: 'email', - fieldtype: 'Data', - options: 'Email', - } + label: __("Email"), + fieldname: "email", + fieldtype: "Data", + options: "Email", + }, ], - primary_action_label: __('Send'), + primary_action_label: __("Send"), primary_action({ email }) { - d.get_primary_btn().text(__('Sending...')).prop('disabled', true); - frm.call('send_test_email', { email }) - .then(() => { - d.get_primary_btn().text(__('Send again')).prop('disabled', false); - }); - } + d.get_primary_btn().text(__("Sending...")).prop("disabled", true); + frm.call("send_test_email", { email }).then(() => { + d.get_primary_btn().text(__("Send again")).prop("disabled", false); + }); + }, }); d.show(); }, async update_sending_status(frm) { - if (frm.doc.email_sent && frm.$wrapper.is(':visible') && !frm.waiting_for_request) { + if (frm.doc.email_sent && frm.$wrapper.is(":visible") && !frm.waiting_for_request) { frm.waiting_for_request = true; - let res = await frm.call('get_sending_status'); + let res = await frm.call("get_sending_status"); frm.waiting_for_request = false; let stats = res.message; stats && frm.events.update_sending_progress(frm, stats); - if (stats.sent + stats.error >= frm.doc.total_recipients || (!stats.total && !stats.emails_queued)) { + if ( + stats.sent + stats.error >= frm.doc.total_recipients || + (!stats.total && !stats.emails_queued) + ) { frm.sending_status && clearInterval(frm.sending_status); frm.sending_status = null; return; @@ -162,7 +197,11 @@ frappe.ui.form.on('Newsletter', { } if (stats.total) { frm.page.set_indicator(__("Sending"), "blue"); - frm.dashboard.show_progress(__('Sending emails'), stats.sent * 100 / frm.doc.total_recipients, __("{0} of {1} sent", [stats.sent, frm.doc.total_recipients])); + frm.dashboard.show_progress( + __("Sending emails"), + (stats.sent * 100) / frm.doc.total_recipients, + __("{0} of {1} sent", [stats.sent, frm.doc.total_recipients]) + ); } else if (stats.emails_queued) { frm.page.set_indicator(__("Queued"), "blue"); } @@ -178,9 +217,11 @@ frappe.ui.form.on('Newsletter', { update_schedule_message(frm) { if (!frm.doc.email_sent && frm.doc.schedule_send) { let datetime = frappe.datetime.global_date_format(frm.doc.schedule_send); - frm.dashboard.set_headline_alert(__('This newsletter is scheduled to be sent on {0}', [datetime.bold()])); + frm.dashboard.set_headline_alert( + __("This newsletter is scheduled to be sent on {0}", [datetime.bold()]) + ); } else { frm.dashboard.clear_headline(); } - } + }, }); diff --git a/frappe/email/doctype/newsletter/newsletter_list.js b/frappe/email/doctype/newsletter/newsletter_list.js index 0b82f1c9e4..0921de02b4 100644 --- a/frappe/email/doctype/newsletter/newsletter_list.js +++ b/frappe/email/doctype/newsletter/newsletter_list.js @@ -1,6 +1,6 @@ -frappe.listview_settings['Newsletter'] = { +frappe.listview_settings["Newsletter"] = { add_fields: ["subject", "email_sent", "schedule_sending"], - get_indicator: function(doc) { + get_indicator: function (doc) { if (doc.email_sent) { return [__("Sent"), "green", "email_sent,=,Yes"]; } else if (doc.schedule_sending) { @@ -8,5 +8,5 @@ frappe.listview_settings['Newsletter'] = { } else { return [__("Not Sent"), "gray", "email_sent,=,No"]; } - } + }, }; diff --git a/frappe/email/doctype/notification/notification.js b/frappe/email/doctype/notification/notification.js index f14447707f..4e3b1eae53 100644 --- a/frappe/email/doctype/notification/notification.js +++ b/frappe/email/doctype/notification/notification.js @@ -1,100 +1,98 @@ // Copyright (c) 2018, Frappe Technologies and contributors // For license information, please see license.txt -this.frm.add_fetch('sender', 'email_id', 'sender_email'); +this.frm.add_fetch("sender", "email_id", "sender_email"); -this.frm.fields_dict.sender.get_query = function() { +this.frm.fields_dict.sender.get_query = function () { return { filters: { - enable_outgoing: 1 - } + enable_outgoing: 1, + }, }; }; frappe.notification = { - setup_fieldname_select: function(frm) { + setup_fieldname_select: function (frm) { // get the doctype to update fields if (!frm.doc.document_type) { return; } - frappe.model.with_doctype(frm.doc.document_type, function() { - let get_select_options = function(df, parent_field) { + frappe.model.with_doctype(frm.doc.document_type, function () { + let get_select_options = function (df, parent_field) { // Append parent_field name along with fieldname for child table fields - let select_value = parent_field ? df.fieldname + ',' + parent_field : df.fieldname; + let select_value = parent_field ? df.fieldname + "," + parent_field : df.fieldname; return { value: select_value, - label: df.fieldname + ' (' + __(df.label) + ')' + label: df.fieldname + " (" + __(df.label) + ")", }; }; - let get_date_change_options = function() { - let date_options = $.map(fields, function(d) { - return d.fieldtype == 'Date' || d.fieldtype == 'Datetime' + let get_date_change_options = function () { + let date_options = $.map(fields, function (d) { + return d.fieldtype == "Date" || d.fieldtype == "Datetime" ? get_select_options(d) : null; }); // append creation and modified date to Date Change field return date_options.concat([ - { value: 'creation', label: `creation (${__('Created On')})` }, - { value: 'modified', label: `modified (${__('Last Modified Date')})` } + { value: "creation", label: `creation (${__("Created On")})` }, + { value: "modified", label: `modified (${__("Last Modified Date")})` }, ]); }; - let fields = frappe.get_doc('DocType', frm.doc.document_type).fields; - let options = $.map(fields, function(d) { + let fields = frappe.get_doc("DocType", frm.doc.document_type).fields; + let options = $.map(fields, function (d) { return in_list(frappe.model.no_value_type, d.fieldtype) - ? null : get_select_options(d); + ? null + : get_select_options(d); }); // set value changed options - frm.set_df_property('value_changed', 'options', [''].concat(options)); - frm.set_df_property( - 'set_property_after_alert', - 'options', - [''].concat(options) - ); + frm.set_df_property("value_changed", "options", [""].concat(options)); + frm.set_df_property("set_property_after_alert", "options", [""].concat(options)); // set date changed options - frm.set_df_property('date_changed', 'options', get_date_change_options()); + frm.set_df_property("date_changed", "options", get_date_change_options()); let receiver_fields = []; - if (frm.doc.channel === 'Email') { - receiver_fields = $.map(fields, function(d) { - + if (frm.doc.channel === "Email") { + receiver_fields = $.map(fields, function (d) { // Add User and Email fields from child into select dropdown - if (d.fieldtype == 'Table') { - let child_fields = frappe.get_doc('DocType', d.options).fields; - return $.map(child_fields, function(df) { - return df.options == 'Email' || - (df.options == 'User' && df.fieldtype == 'Link') - ? get_select_options(df, d.fieldname) : null; + if (d.fieldtype == "Table") { + let child_fields = frappe.get_doc("DocType", d.options).fields; + return $.map(child_fields, function (df) { + return df.options == "Email" || + (df.options == "User" && df.fieldtype == "Link") + ? get_select_options(df, d.fieldname) + : null; }); - // Add User and Email fields from parent into select dropdown + // Add User and Email fields from parent into select dropdown } else { - return d.options == 'Email' || - (d.options == 'User' && d.fieldtype == 'Link') - ? get_select_options(d) : null; + return d.options == "Email" || + (d.options == "User" && d.fieldtype == "Link") + ? get_select_options(d) + : null; } }); - } else if (in_list(['WhatsApp', 'SMS'], frm.doc.channel)) { - receiver_fields = $.map(fields, function(d) { - return d.options == 'Phone' ? get_select_options(d) : null; + } else if (in_list(["WhatsApp", "SMS"], frm.doc.channel)) { + receiver_fields = $.map(fields, function (d) { + return d.options == "Phone" ? get_select_options(d) : null; }); } // set email recipient options frm.fields_dict.recipients.grid.update_docfield_property( - 'receiver_by_document_field', - 'options', - [''].concat(["owner"]).concat(receiver_fields) + "receiver_by_document_field", + "options", + [""].concat(["owner"]).concat(receiver_fields) ); }); }, - setup_example_message: function(frm) { - let template = ''; - if (frm.doc.channel === 'Email') { + setup_example_message: function (frm) { + let template = ""; + if (frm.doc.channel === "Email") { template = `
        Message Example
        <h3>Order Overdue</h3>
        @@ -114,7 +112,7 @@ Last comment: {{ comments[-1].comment }} by {{ comments[-1].by }}
         </ul>
         
        `; - } else if (in_list(['Slack', 'System Notification', 'SMS'], frm.doc.channel)) { + } else if (in_list(["Slack", "System Notification", "SMS"], frm.doc.channel)) { template = `
        Message Example
        *Order Overdue*
        @@ -133,71 +131,72 @@ Last comment: {{ comments[-1].comment }} by {{ comments[-1].by }}
         
        `; } if (template) { - frm.set_df_property('message_examples', 'options', template); + frm.set_df_property("message_examples", "options", template); } - - } + }, }; -frappe.ui.form.on('Notification', { - onload: function(frm) { - frm.set_query('document_type', function() { +frappe.ui.form.on("Notification", { + onload: function (frm) { + frm.set_query("document_type", function () { return { filters: { - istable: 0 - } + istable: 0, + }, }; }); - frm.set_query('print_format', function() { + frm.set_query("print_format", function () { return { filters: { - doc_type: frm.doc.document_type - } + doc_type: frm.doc.document_type, + }, }; }); }, - refresh: function(frm) { + refresh: function (frm) { frappe.notification.setup_fieldname_select(frm); frappe.notification.setup_example_message(frm); - frm.get_field('is_standard').toggle(frappe.boot.developer_mode); - frm.trigger('event'); + frm.get_field("is_standard").toggle(frappe.boot.developer_mode); + frm.trigger("event"); }, - document_type: function(frm) { + document_type: function (frm) { frappe.notification.setup_fieldname_select(frm); }, - view_properties: function(frm) { + view_properties: function (frm) { frappe.route_options = { doc_type: frm.doc.document_type }; - frappe.set_route('Form', 'Customize Form'); + frappe.set_route("Form", "Customize Form"); }, - event: function(frm) { - if (in_list(['Days Before', 'Days After'], frm.doc.event)) { - frm.add_custom_button(__('Get Alerts for Today'), function() { + event: function (frm) { + if (in_list(["Days Before", "Days After"], frm.doc.event)) { + frm.add_custom_button(__("Get Alerts for Today"), function () { frappe.call({ - method: - 'frappe.email.doctype.notification.notification.get_documents_for_today', + method: "frappe.email.doctype.notification.notification.get_documents_for_today", args: { - notification: frm.doc.name + notification: frm.doc.name, }, - callback: function(r) { + callback: function (r) { if (r.message) { frappe.msgprint(r.message); } else { - frappe.msgprint(__('No alerts for today')); + frappe.msgprint(__("No alerts for today")); } - } + }, }); }); } }, - channel: function(frm) { - frm.toggle_reqd('recipients', frm.doc.channel == 'Email'); + channel: function (frm) { + frm.toggle_reqd("recipients", frm.doc.channel == "Email"); frappe.notification.setup_fieldname_select(frm); frappe.notification.setup_example_message(frm); - if (frm.doc.channel === 'SMS' && frm.doc.__islocal) { - frm.set_df_property('channel', - 'description', `To use SMS Channel, initialize SMS Settings.`); + if (frm.doc.channel === "SMS" && frm.doc.__islocal) { + frm.set_df_property( + "channel", + "description", + `To use SMS Channel, initialize SMS Settings.` + ); } else { - frm.set_df_property('channel', 'description', ` `); + frm.set_df_property("channel", "description", ` `); } - } + }, }); diff --git a/frappe/event_streaming/doctype/document_type_mapping/document_type_mapping.js b/frappe/event_streaming/doctype/document_type_mapping/document_type_mapping.js index 22b7f2ef4c..ad9ab0f51d 100644 --- a/frappe/event_streaming/doctype/document_type_mapping/document_type_mapping.js +++ b/frappe/event_streaming/doctype/document_type_mapping/document_type_mapping.js @@ -1,28 +1,37 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Document Type Mapping', { - local_doctype: function(frm) { +frappe.ui.form.on("Document Type Mapping", { + local_doctype: function (frm) { if (frm.doc.local_doctype) { - frappe.model.clear_table(frm.doc, 'field_mapping'); + frappe.model.clear_table(frm.doc, "field_mapping"); let fields = frm.events.get_fields(frm); - $.each(fields, function(i, data) { - let row = frappe.model.add_child(frm.doc, 'Document Type Field Mapping', 'field_mapping'); + $.each(fields, function (i, data) { + let row = frappe.model.add_child( + frm.doc, + "Document Type Field Mapping", + "field_mapping" + ); row.local_fieldname = data; }); - refresh_field('field_mapping'); + refresh_field("field_mapping"); } }, - get_fields: function(frm) { + get_fields: function (frm) { let filtered_fields = []; - frappe.model.with_doctype(frm.doc.local_doctype, ()=> { - frappe.get_meta(frm.doc.local_doctype).fields.map( field => { - if (field.fieldname !== 'remote_docname' && field.fieldname !== 'remote_site_name' && frappe.model.is_value_type(field) && !field.hidden) { + frappe.model.with_doctype(frm.doc.local_doctype, () => { + frappe.get_meta(frm.doc.local_doctype).fields.map((field) => { + if ( + field.fieldname !== "remote_docname" && + field.fieldname !== "remote_site_name" && + frappe.model.is_value_type(field) && + !field.hidden + ) { filtered_fields.push(field.fieldname); } }); }); return filtered_fields; - } + }, }); diff --git a/frappe/event_streaming/doctype/event_consumer/event_consumer.js b/frappe/event_streaming/doctype/event_consumer/event_consumer.js index 66d92699fa..2bcf96f9f3 100644 --- a/frappe/event_streaming/doctype/event_consumer/event_consumer.js +++ b/frappe/event_streaming/doctype/event_consumer/event_consumer.js @@ -1,19 +1,17 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Event Consumer', { - refresh: function(frm) { +frappe.ui.form.on("Event Consumer", { + refresh: function (frm) { // formatter for subscribed doctype approval status - frm.set_indicator_formatter('status', - function(doc) { - let indicator = 'orange'; - if (doc.status == 'Approved') { - indicator = 'green'; - } else if (doc.status == 'Rejected') { - indicator = 'red'; - } - return indicator; + frm.set_indicator_formatter("status", function (doc) { + let indicator = "orange"; + if (doc.status == "Approved") { + indicator = "green"; + } else if (doc.status == "Rejected") { + indicator = "red"; } - ); - } + return indicator; + }); + }, }); diff --git a/frappe/event_streaming/doctype/event_producer/event_producer.js b/frappe/event_streaming/doctype/event_producer/event_producer.js index c2c3389e92..23ca482433 100644 --- a/frappe/event_streaming/doctype/event_producer/event_producer.js +++ b/frappe/event_streaming/doctype/event_producer/event_producer.js @@ -1,27 +1,25 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Event Producer', { - refresh: function(frm) { - frm.set_query('ref_doctype', 'producer_doctypes', function() { +frappe.ui.form.on("Event Producer", { + refresh: function (frm) { + frm.set_query("ref_doctype", "producer_doctypes", function () { return { filters: { issingle: 0, - istable: 0 - } + istable: 0, + }, }; }); - frm.set_indicator_formatter('status', - function(doc) { - let indicator = 'orange'; - if (doc.status == 'Approved') { - indicator = 'green'; - } else if (doc.status == 'Rejected') { - indicator = 'red'; - } - return indicator; + frm.set_indicator_formatter("status", function (doc) { + let indicator = "orange"; + if (doc.status == "Approved") { + indicator = "green"; + } else if (doc.status == "Rejected") { + indicator = "red"; } - ); - } + return indicator; + }); + }, }); diff --git a/frappe/event_streaming/doctype/event_producer_last_update/event_producer_last_update.js b/frappe/event_streaming/doctype/event_producer_last_update/event_producer_last_update.js index 15730e4c5f..6d18be43e3 100644 --- a/frappe/event_streaming/doctype/event_producer_last_update/event_producer_last_update.js +++ b/frappe/event_streaming/doctype/event_producer_last_update/event_producer_last_update.js @@ -1,8 +1,7 @@ // Copyright (c) 2020, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Event Producer Last Update', { +frappe.ui.form.on("Event Producer Last Update", { // refresh: function(frm) { - // } }); diff --git a/frappe/event_streaming/doctype/event_sync_log/event_sync_log.js b/frappe/event_streaming/doctype/event_sync_log/event_sync_log.js index 5199e3f02d..7cc3198bae 100644 --- a/frappe/event_streaming/doctype/event_sync_log/event_sync_log.js +++ b/frappe/event_streaming/doctype/event_sync_log/event_sync_log.js @@ -1,24 +1,24 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Event Sync Log', { - refresh: function(frm) { - if (frm.doc.status == 'Failed') { - frm.add_custom_button(__('Resync'), function() { +frappe.ui.form.on("Event Sync Log", { + refresh: function (frm) { + if (frm.doc.status == "Failed") { + frm.add_custom_button(__("Resync"), function () { frappe.call({ method: "frappe.event_streaming.doctype.event_producer.event_producer.resync", args: { update: frm.doc, }, - callback: function(r) { + callback: function (r) { if (r.message) { frappe.msgprint(r.message); - frm.set_value('status', r.message); + frm.set_value("status", r.message); frm.save(); } - } + }, }); }); } - } + }, }); diff --git a/frappe/event_streaming/doctype/event_sync_log/event_sync_log_list.js b/frappe/event_streaming/doctype/event_sync_log/event_sync_log_list.js index 75d67003c4..97d2ee0a1d 100644 --- a/frappe/event_streaming/doctype/event_sync_log/event_sync_log_list.js +++ b/frappe/event_streaming/doctype/event_sync_log/event_sync_log_list.js @@ -1,9 +1,9 @@ -frappe.listview_settings['Event Sync Log'] = { - get_indicator: function(doc) { +frappe.listview_settings["Event Sync Log"] = { + get_indicator: function (doc) { var colors = { - "Failed": "red", - "Synced": "green" + Failed: "red", + Synced: "green", }; return [__(doc.status), colors[doc.status], "status,=," + doc.status]; - } + }, }; diff --git a/frappe/event_streaming/doctype/event_update_log/event_update_log.js b/frappe/event_streaming/doctype/event_update_log/event_update_log.js index c5e8ed5915..d901799780 100644 --- a/frappe/event_streaming/doctype/event_update_log/event_update_log.js +++ b/frappe/event_streaming/doctype/event_update_log/event_update_log.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Event Update Log', { +frappe.ui.form.on("Event Update Log", { // refresh: function(frm) { - // } }); diff --git a/frappe/geo/doctype/country/country.js b/frappe/geo/doctype/country/country.js index 62159a1fe7..75bb3f46d5 100644 --- a/frappe/geo/doctype/country/country.js +++ b/frappe/geo/doctype/country/country.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Country', { - refresh: function(frm) { - - } +frappe.ui.form.on("Country", { + refresh: function (frm) {}, }); diff --git a/frappe/geo/doctype/currency/currency.js b/frappe/geo/doctype/currency/currency.js index af2d6ebc4e..08915893a5 100644 --- a/frappe/geo/doctype/currency/currency.js +++ b/frappe/geo/doctype/currency/currency.js @@ -1,11 +1,11 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: See license.txt -frappe.ui.form.on('Currency', { +frappe.ui.form.on("Currency", { refresh(frm) { frm.set_intro(""); - if(!frm.doc.enabled) { + if (!frm.doc.enabled) { frm.set_intro(__("This Currency is disabled. Enable to use in transactions")); } - } + }, }); diff --git a/frappe/integrations/doctype/connected_app/connected_app.js b/frappe/integrations/doctype/connected_app/connected_app.js index 4d20f65559..11dcda235e 100644 --- a/frappe/integrations/doctype/connected_app/connected_app.js +++ b/frappe/integrations/doctype/connected_app/connected_app.js @@ -1,38 +1,38 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Connected App', { - refresh: frm => { - frm.add_custom_button(__('Get OpenID Configuration'), async () => { +frappe.ui.form.on("Connected App", { + refresh: (frm) => { + frm.add_custom_button(__("Get OpenID Configuration"), async () => { if (!frm.doc.openid_configuration) { - frappe.msgprint(__('Please enter OpenID Configuration URL')); + frappe.msgprint(__("Please enter OpenID Configuration URL")); } else { try { const response = await fetch(frm.doc.openid_configuration); const oidc = await response.json(); - frm.set_value('authorization_uri', oidc.authorization_endpoint); - frm.set_value('token_uri', oidc.token_endpoint); - frm.set_value('userinfo_uri', oidc.userinfo_endpoint); - frm.set_value('introspection_uri', oidc.introspection_endpoint); - frm.set_value('revocation_uri', oidc.revocation_endpoint); + frm.set_value("authorization_uri", oidc.authorization_endpoint); + frm.set_value("token_uri", oidc.token_endpoint); + frm.set_value("userinfo_uri", oidc.userinfo_endpoint); + frm.set_value("introspection_uri", oidc.introspection_endpoint); + frm.set_value("revocation_uri", oidc.revocation_endpoint); } catch (error) { - frappe.msgprint(__('Please check OpenID Configuration URL')); + frappe.msgprint(__("Please check OpenID Configuration URL")); } } }); if (!frm.is_new()) { - frm.add_custom_button(__('Connect to {}', [frm.doc.provider_name]), async () => { + frm.add_custom_button(__("Connect to {}", [frm.doc.provider_name]), async () => { frappe.call({ - method: 'initiate_web_application_flow', + method: "initiate_web_application_flow", doc: frm.doc, - callback: function(r) { - window.open(r.message, '_blank'); - } + callback: function (r) { + window.open(r.message, "_blank"); + }, }); }); } - frm.toggle_display('sb_client_credentials_section', !frm.is_new()); - } + frm.toggle_display("sb_client_credentials_section", !frm.is_new()); + }, }); diff --git a/frappe/integrations/doctype/dropbox_settings/dropbox_settings.js b/frappe/integrations/doctype/dropbox_settings/dropbox_settings.js index ea731fafc2..9a5e9a4dc7 100644 --- a/frappe/integrations/doctype/dropbox_settings/dropbox_settings.js +++ b/frappe/integrations/doctype/dropbox_settings/dropbox_settings.js @@ -1,51 +1,54 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Dropbox Settings', { - refresh: function(frm) { - frm.toggle_display(["app_access_key", "app_secret_key"], !(frm.doc.__onload && frm.doc.__onload.dropbox_setup_via_site_config)); +frappe.ui.form.on("Dropbox Settings", { + refresh: function (frm) { + frm.toggle_display( + ["app_access_key", "app_secret_key"], + !(frm.doc.__onload && frm.doc.__onload.dropbox_setup_via_site_config) + ); frm.clear_custom_buttons(); frm.events.take_backup(frm); }, - allow_dropbox_access: function(frm) { + allow_dropbox_access: function (frm) { if (frm.doc.app_access_key && frm.doc.app_secret_key) { frappe.call({ method: "frappe.integrations.doctype.dropbox_settings.dropbox_settings.get_dropbox_authorize_url", freeze: true, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { window.open(r.message.auth_url); } - } - }) - } - else if (frm.doc.__onload && frm.doc.__onload.dropbox_setup_via_site_config) { + }, + }); + } else if (frm.doc.__onload && frm.doc.__onload.dropbox_setup_via_site_config) { frappe.call({ method: "frappe.integrations.doctype.dropbox_settings.dropbox_settings.get_redirect_url", freeze: true, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { window.open(r.message.auth_url); } - } - }) - } - else { - frappe.msgprint(__("Please enter values for App Access Key and App Secret Key")) + }, + }); + } else { + frappe.msgprint(__("Please enter values for App Access Key and App Secret Key")); } }, - take_backup: function(frm) { - if (frm.doc.enabled && ((frm.doc.app_access_key && frm.doc.app_secret_key) - || (frm.doc.__onload && frm.doc.__onload.dropbox_setup_via_site_config))) { - frm.add_custom_button(__("Take Backup Now"), function(frm){ + take_backup: function (frm) { + if ( + frm.doc.enabled && + ((frm.doc.app_access_key && frm.doc.app_secret_key) || + (frm.doc.__onload && frm.doc.__onload.dropbox_setup_via_site_config)) + ) { + frm.add_custom_button(__("Take Backup Now"), function (frm) { frappe.call({ method: "frappe.integrations.doctype.dropbox_settings.dropbox_settings.take_backup", - freeze: true - }) - }).addClass("btn-primary") + freeze: true, + }); + }).addClass("btn-primary"); } - } + }, }); - diff --git a/frappe/integrations/doctype/google_calendar/google_calendar.js b/frappe/integrations/doctype/google_calendar/google_calendar.js index f30c52b2f2..977dee8dfe 100644 --- a/frappe/integrations/doctype/google_calendar/google_calendar.js +++ b/frappe/integrations/doctype/google_calendar/google_calendar.js @@ -2,15 +2,22 @@ // For license information, please see license.txt frappe.ui.form.on("Google Calendar", { - refresh: function(frm) { + refresh: function (frm) { if (frm.is_new()) { - frm.dashboard.set_headline(__("To use Google Calendar, enable {0}.", [`${__('Google Settings')}`])); + frm.dashboard.set_headline( + __("To use Google Calendar, enable {0}.", [ + `${__("Google Settings")}`, + ]) + ); } frappe.realtime.on("import_google_calendar", (data) => { if (data.progress) { - frm.dashboard.show_progress("Syncing Google Calendar", data.progress / data.total * 100, - __("Syncing {0} of {1}", [data.progress, data.total])); + frm.dashboard.show_progress( + "Syncing Google Calendar", + (data.progress / data.total) * 100, + __("Syncing {0} of {1}", [data.progress, data.total]) + ); if (data.progress === data.total) { frm.dashboard.hide_progress("Syncing Google Calendar"); } @@ -21,38 +28,40 @@ frappe.ui.form.on("Google Calendar", { frm.add_custom_button(__("Sync Calendar"), function () { frappe.show_alert({ indicator: "green", - message: __("Syncing") - }); - frappe.call({ - method: "frappe.integrations.doctype.google_calendar.google_calendar.sync", - args: { - "g_calendar": frm.doc.name - }, - }).then((r) => { - frappe.hide_progress(); - frappe.msgprint(r.message); + message: __("Syncing"), }); + frappe + .call({ + method: "frappe.integrations.doctype.google_calendar.google_calendar.sync", + args: { + g_calendar: frm.doc.name, + }, + }) + .then((r) => { + frappe.hide_progress(); + frappe.msgprint(r.message); + }); }); } }, - authorize_google_calendar_access: function(frm) { + authorize_google_calendar_access: function (frm) { let reauthorize = 0; - if(frm.doc.authorization_code) { + if (frm.doc.authorization_code) { reauthorize = 1; } frappe.call({ method: "frappe.integrations.doctype.google_calendar.google_calendar.authorize_access", args: { - "g_calendar": frm.doc.name, - "reauthorize": reauthorize + g_calendar: frm.doc.name, + reauthorize: reauthorize, }, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { frm.save(); window.open(r.message.url); } - } + }, }); - } + }, }); diff --git a/frappe/integrations/doctype/google_contacts/google_contacts.js b/frappe/integrations/doctype/google_contacts/google_contacts.js index 6e8035f38d..06289b0ca5 100644 --- a/frappe/integrations/doctype/google_contacts/google_contacts.js +++ b/frappe/integrations/doctype/google_contacts/google_contacts.js @@ -1,54 +1,63 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Google Contacts', { - refresh: function(frm) { +frappe.ui.form.on("Google Contacts", { + refresh: function (frm) { if (!frm.doc.enable) { - frm.dashboard.set_headline(__("To use Google Contacts, enable {0}.", [`${__('Google Settings')}`])); + frm.dashboard.set_headline( + __("To use Google Contacts, enable {0}.", [ + `${__("Google Settings")}`, + ]) + ); } - frappe.realtime.on('import_google_contacts', (data) => { + frappe.realtime.on("import_google_contacts", (data) => { if (data.progress) { - frm.dashboard.show_progress('Import Google Contacts', data.progress / data.total * 100, - __('Importing {0} of {1}', [data.progress, data.total])); + frm.dashboard.show_progress( + "Import Google Contacts", + (data.progress / data.total) * 100, + __("Importing {0} of {1}", [data.progress, data.total]) + ); if (data.progress === data.total) { - frm.dashboard.hide_progress('Import Google Contacts'); + frm.dashboard.hide_progress("Import Google Contacts"); } } }); if (frm.doc.refresh_token) { - let sync_button = frm.add_custom_button(__('Sync Contacts'), function () { + let sync_button = frm.add_custom_button(__("Sync Contacts"), function () { frappe.show_alert({ - indicator: 'green', - message: __('Syncing') - }); - frappe.call({ - method: "frappe.integrations.doctype.google_contacts.google_contacts.sync", - args: { - "g_contact": frm.doc.name - }, - btn: sync_button - }).then((r) => { - frappe.hide_progress(); - frappe.msgprint(r.message); + indicator: "green", + message: __("Syncing"), }); + frappe + .call({ + method: "frappe.integrations.doctype.google_contacts.google_contacts.sync", + args: { + g_contact: frm.doc.name, + }, + btn: sync_button, + }) + .then((r) => { + frappe.hide_progress(); + frappe.msgprint(r.message); + }); }); } }, - authorize_google_contacts_access: function(frm) { + authorize_google_contacts_access: function (frm) { frappe.call({ method: "frappe.integrations.doctype.google_contacts.google_contacts.authorize_access", args: { - "g_contact": frm.doc.name, - "reauthorize": frm.doc.authorization_code ? 1 : 0 + g_contact: frm.doc.name, + reauthorize: frm.doc.authorization_code ? 1 : 0, }, - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { frm.save(); window.open(r.message.url); } - } + }, }); - } + }, }); diff --git a/frappe/integrations/doctype/google_drive/google_drive.js b/frappe/integrations/doctype/google_drive/google_drive.js index b38c0fb8e6..208c1e5e1a 100644 --- a/frappe/integrations/doctype/google_drive/google_drive.js +++ b/frappe/integrations/doctype/google_drive/google_drive.js @@ -1,16 +1,23 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Google Drive', { - refresh: function(frm) { +frappe.ui.form.on("Google Drive", { + refresh: function (frm) { if (!frm.doc.enable) { - frm.dashboard.set_headline(__("To use Google Drive, enable {0}.", [`${__('Google Settings')}`])); + frm.dashboard.set_headline( + __("To use Google Drive, enable {0}.", [ + `${__("Google Settings")}`, + ]) + ); } frappe.realtime.on("upload_to_google_drive", (data) => { if (data.progress) { - frm.dashboard.show_progress("Uploading to Google Drive", data.progress / data.total * 100, - __("{0}", [data.message])); + frm.dashboard.show_progress( + "Uploading to Google Drive", + (data.progress / data.total) * 100, + __("{0}", [data.message]) + ); if (data.progress === data.total) { frm.dashboard.hide_progress("Uploading to Google Drive"); } @@ -21,37 +28,43 @@ frappe.ui.form.on('Google Drive', { let sync_button = frm.add_custom_button(__("Take Backup"), function () { frappe.show_alert({ indicator: "green", - message: __("Backing up to Google Drive.") - }); - frappe.call({ - method: "frappe.integrations.doctype.google_drive.google_drive.take_backup", - btn: sync_button - }).then((r) => { - frappe.msgprint(r.message); + message: __("Backing up to Google Drive."), }); + frappe + .call({ + method: "frappe.integrations.doctype.google_drive.google_drive.take_backup", + btn: sync_button, + }) + .then((r) => { + frappe.msgprint(r.message); + }); }); } if (frm.doc.enable && frm.doc.backup_folder_name && !frm.doc.refresh_token) { - frm.dashboard.set_headline(__("Click on Authorize Google Drive Access to authorize Google Drive Access.")); + frm.dashboard.set_headline( + __( + "Click on Authorize Google Drive Access to authorize Google Drive Access." + ) + ); } if (frm.doc.enable && frm.doc.refresh_token && frm.doc.authorization_code) { frm.page.set_indicator("Authorized", "green"); } }, - authorize_google_drive_access: function(frm) { + authorize_google_drive_access: function (frm) { frappe.call({ method: "frappe.integrations.doctype.google_drive.google_drive.authorize_access", args: { - "reauthorize": frm.doc.authorization_code ? 1 : 0 + reauthorize: frm.doc.authorization_code ? 1 : 0, }, - callback: function(r) { + callback: function (r) { if (!r.exc) { frm.save(); window.open(r.message.url); } - } + }, }); - } + }, }); diff --git a/frappe/integrations/doctype/google_settings/google_settings.js b/frappe/integrations/doctype/google_settings/google_settings.js index 01a127db7f..58093034b5 100644 --- a/frappe/integrations/doctype/google_settings/google_settings.js +++ b/frappe/integrations/doctype/google_settings/google_settings.js @@ -1,8 +1,14 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Google Settings', { - refresh: function(frm) { - frm.dashboard.set_headline(__("For more information, {0}.", [`${__('Click here')}`])); - } +frappe.ui.form.on("Google Settings", { + refresh: function (frm) { + frm.dashboard.set_headline( + __("For more information, {0}.", [ + `${__( + "Click here" + )}`, + ]) + ); + }, }); diff --git a/frappe/integrations/doctype/integration_request/integration_request.js b/frappe/integrations/doctype/integration_request/integration_request.js index 4b3b9a2de7..ac810f4d73 100644 --- a/frappe/integrations/doctype/integration_request/integration_request.js +++ b/frappe/integrations/doctype/integration_request/integration_request.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Integration Request', { - refresh: function(frm) { - - } +frappe.ui.form.on("Integration Request", { + refresh: function (frm) {}, }); diff --git a/frappe/integrations/doctype/ldap_settings/ldap_settings.js b/frappe/integrations/doctype/ldap_settings/ldap_settings.js index 9ac95883b7..2ca7370ecf 100644 --- a/frappe/integrations/doctype/ldap_settings/ldap_settings.js +++ b/frappe/integrations/doctype/ldap_settings/ldap_settings.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('LDAP Settings', { - refresh: function(frm) { - - } +frappe.ui.form.on("LDAP Settings", { + refresh: function (frm) {}, }); diff --git a/frappe/integrations/doctype/oauth_authorization_code/oauth_authorization_code.js b/frappe/integrations/doctype/oauth_authorization_code/oauth_authorization_code.js index 32746e6752..83ad1b3ee5 100644 --- a/frappe/integrations/doctype/oauth_authorization_code/oauth_authorization_code.js +++ b/frappe/integrations/doctype/oauth_authorization_code/oauth_authorization_code.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('OAuth Authorization Code', { - refresh: function(frm) { - - } +frappe.ui.form.on("OAuth Authorization Code", { + refresh: function (frm) {}, }); diff --git a/frappe/integrations/doctype/oauth_bearer_token/oauth_bearer_token.js b/frappe/integrations/doctype/oauth_bearer_token/oauth_bearer_token.js index da69753903..7794f2fb70 100644 --- a/frappe/integrations/doctype/oauth_bearer_token/oauth_bearer_token.js +++ b/frappe/integrations/doctype/oauth_bearer_token/oauth_bearer_token.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('OAuth Bearer Token', { - refresh: function(frm) { - - } +frappe.ui.form.on("OAuth Bearer Token", { + refresh: function (frm) {}, }); diff --git a/frappe/integrations/doctype/oauth_client/oauth_client.js b/frappe/integrations/doctype/oauth_client/oauth_client.js index b0caa562b1..3ddd1a046b 100644 --- a/frappe/integrations/doctype/oauth_client/oauth_client.js +++ b/frappe/integrations/doctype/oauth_client/oauth_client.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('OAuth Client', { - refresh: function(frm) { - - } +frappe.ui.form.on("OAuth Client", { + refresh: function (frm) {}, }); diff --git a/frappe/integrations/doctype/oauth_provider_settings/oauth_provider_settings.js b/frappe/integrations/doctype/oauth_provider_settings/oauth_provider_settings.js index 6d7d071934..0071b4e977 100644 --- a/frappe/integrations/doctype/oauth_provider_settings/oauth_provider_settings.js +++ b/frappe/integrations/doctype/oauth_provider_settings/oauth_provider_settings.js @@ -1,8 +1,6 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('OAuth Provider Settings', { - refresh: function(frm) { - - } +frappe.ui.form.on("OAuth Provider Settings", { + refresh: function (frm) {}, }); diff --git a/frappe/integrations/doctype/s3_backup_settings/s3_backup_settings.js b/frappe/integrations/doctype/s3_backup_settings/s3_backup_settings.js index 1a1b8a7c67..6db4087cf3 100755 --- a/frappe/integrations/doctype/s3_backup_settings/s3_backup_settings.js +++ b/frappe/integrations/doctype/s3_backup_settings/s3_backup_settings.js @@ -1,26 +1,26 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('S3 Backup Settings', { - refresh: function(frm) { +frappe.ui.form.on("S3 Backup Settings", { + refresh: function (frm) { frm.clear_custom_buttons(); frm.events.take_backup(frm); }, - take_backup: function(frm) { + take_backup: function (frm) { if (frm.doc.access_key_id && frm.doc.secret_access_key) { - frm.add_custom_button(__("Take Backup Now"), function(){ + frm.add_custom_button(__("Take Backup Now"), function () { frm.dashboard.set_headline_alert("S3 Backup Started!"); frappe.call({ method: "frappe.integrations.doctype.s3_backup_settings.s3_backup_settings.take_backups_s3", - callback: function(r) { - if(!r.exc) { + callback: function (r) { + if (!r.exc) { frappe.msgprint(__("S3 Backup complete!")); frm.dashboard.clear_headline(); } - } + }, }); }).addClass("btn-primary"); } - } + }, }); diff --git a/frappe/integrations/doctype/slack_webhook_url/slack_webhook_url.js b/frappe/integrations/doctype/slack_webhook_url/slack_webhook_url.js index b7a972bdc1..49991fcffe 100644 --- a/frappe/integrations/doctype/slack_webhook_url/slack_webhook_url.js +++ b/frappe/integrations/doctype/slack_webhook_url/slack_webhook_url.js @@ -1,6 +1,4 @@ // Copyright (c) 2018, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Slack Webhook URL', { - -}); +frappe.ui.form.on("Slack Webhook URL", {}); diff --git a/frappe/integrations/doctype/social_login_key/social_login_key.js b/frappe/integrations/doctype/social_login_key/social_login_key.js index e2cbb3459f..033beffff0 100644 --- a/frappe/integrations/doctype/social_login_key/social_login_key.js +++ b/frappe/integrations/doctype/social_login_key/social_login_key.js @@ -1,12 +1,19 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt const fields = [ - "provider_name", "base_url", "custom_base_url", - "icon", "authorize_url", "access_token_url", "redirect_url", - "api_endpoint", "api_endpoint_args", "auth_url_data" + "provider_name", + "base_url", + "custom_base_url", + "icon", + "authorize_url", + "access_token_url", + "redirect_url", + "api_endpoint", + "api_endpoint_args", + "auth_url_data", ]; -frappe.ui.form.on('Social Login Key', { +frappe.ui.form.on("Social Login Key", { refresh(frm) { frm.trigger("setup_fields"); }, @@ -16,23 +23,25 @@ frappe.ui.form.on('Social Login Key', { }, social_login_provider(frm) { - if(frm.doc.social_login_provider != "Custom") { - frappe.call({ - "doc": frm.doc, - "method": "get_social_login_provider", - "args": { - "provider": frm.doc.social_login_provider - } - }).done((r) => { - const provider = r.message; - for(var field of fields) { - frm.set_value(field, provider[field]); - frm.set_df_property(field, "read_only", 1); - if (frm.doc.custom_base_url) { - frm.toggle_enable("base_url", 1); + if (frm.doc.social_login_provider != "Custom") { + frappe + .call({ + doc: frm.doc, + method: "get_social_login_provider", + args: { + provider: frm.doc.social_login_provider, + }, + }) + .done((r) => { + const provider = r.message; + for (var field of fields) { + frm.set_value(field, provider[field]); + frm.set_df_property(field, "read_only", 1); + if (frm.doc.custom_base_url) { + frm.toggle_enable("base_url", 1); + } } - } - }); + }); } else { frm.trigger("clear_fields"); frm.trigger("setup_fields"); @@ -41,38 +50,35 @@ frappe.ui.form.on('Social Login Key', { setup_fields(frm) { // set custom_base_url to read only for "Custom" provider - if(frm.doc.social_login_provider == "Custom") { + if (frm.doc.social_login_provider == "Custom") { frm.set_value("custom_base_url", 1); frm.set_df_property("custom_base_url", "read_only", 1); } // set fields to read only for providers from template - for(var f of fields) { - if(frm.doc.social_login_provider != "Custom"){ + for (var f of fields) { + if (frm.doc.social_login_provider != "Custom") { frm.set_df_property(f, "read_only", 1); } } // enable base_url for providers with custom_base_url - if(frm.doc.custom_base_url) { + if (frm.doc.custom_base_url) { frm.set_df_property("base_url", "read_only", 0); frm.fields_dict["sb_identity_details"].collapse(false); } // hide social_login_provider and provider_name for non local - if(!frm.doc.__islocal && - (frm.doc.social_login_provider || - frm.doc.provider_name)) { + if (!frm.doc.__islocal && (frm.doc.social_login_provider || frm.doc.provider_name)) { frm.set_df_property("social_login_provider", "hidden", 1); frm.set_df_property("provider_name", "hidden", 1); } }, clear_fields(frm) { - for(var field of fields){ + for (var field of fields) { frm.set_value(field, ""); frm.set_df_property(field, "read_only", 0); } - } - + }, }); diff --git a/frappe/integrations/doctype/token_cache/token_cache.js b/frappe/integrations/doctype/token_cache/token_cache.js index b7cac9b804..c8074c876b 100644 --- a/frappe/integrations/doctype/token_cache/token_cache.js +++ b/frappe/integrations/doctype/token_cache/token_cache.js @@ -1,8 +1,7 @@ // Copyright (c) 2019, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Token Cache', { +frappe.ui.form.on("Token Cache", { // refresh: function(frm) { - // } }); diff --git a/frappe/integrations/doctype/webhook/webhook.js b/frappe/integrations/doctype/webhook/webhook.js index f4cb4373ea..302cacc194 100644 --- a/frappe/integrations/doctype/webhook/webhook.js +++ b/frappe/integrations/doctype/webhook/webhook.js @@ -6,27 +6,41 @@ frappe.webhook = { if (frm.doc.webhook_doctype) { frappe.model.with_doctype(frm.doc.webhook_doctype, () => { // get doctype fields - let fields = $.map(frappe.get_doc("DocType", frm.doc.webhook_doctype).fields, (d) => { - if (frappe.model.no_value_type.includes(d.fieldtype) && !(frappe.model.table_fields.includes(d.fieldtype))) { - return null; - } else if (d.fieldtype === 'Currency' || d.fieldtype === 'Float') { - return { label: d.label, value: d.fieldname }; - } else { - return { label: `${__(d.label)} (${d.fieldtype})`, value: d.fieldname }; + let fields = $.map( + frappe.get_doc("DocType", frm.doc.webhook_doctype).fields, + (d) => { + if ( + frappe.model.no_value_type.includes(d.fieldtype) && + !frappe.model.table_fields.includes(d.fieldtype) + ) { + return null; + } else if (d.fieldtype === "Currency" || d.fieldtype === "Float") { + return { label: d.label, value: d.fieldname }; + } else { + return { + label: `${__(d.label)} (${d.fieldtype})`, + value: d.fieldname, + }; + } } - }); + ); // add meta fields for (let field of frappe.model.std_fields) { if (field.fieldname == "name") { fields.unshift({ label: "Name (Doc Name)", value: "name" }); } else { - fields.push({ label: `${__(field.label)} (${field.fieldtype})`, value: field.fieldname }); + fields.push({ + label: `${__(field.label)} (${field.fieldtype})`, + value: field.fieldname, + }); } } frm.fields_dict.webhook_data.grid.update_docfield_property( - 'fieldname', 'options', [""].concat(fields) + "fieldname", + "options", + [""].concat(fields) ); }); } @@ -42,22 +56,29 @@ frappe.webhook = { } if (header_value) { - let header_row = (frm.doc.webhook_headers || []).find(row => row.key === 'Content-Type'); + let header_row = (frm.doc.webhook_headers || []).find( + (row) => row.key === "Content-Type" + ); if (header_row) { - frappe.model.set_value(header_row.doctype, header_row.name, "value", header_value); + frappe.model.set_value( + header_row.doctype, + header_row.name, + "value", + header_value + ); } else { frm.add_child("webhook_headers", { - "key": "Content-Type", - "value": header_value + key: "Content-Type", + value: header_value, }); } frm.refresh(); } } - } + }, }; -frappe.ui.form.on('Webhook', { +frappe.ui.form.on("Webhook", { refresh: (frm) => { frappe.webhook.set_fieldname_select(frm); }, @@ -71,7 +92,7 @@ frappe.ui.form.on('Webhook', { }, enable_security: (frm) => { - frm.toggle_reqd('webhook_secret', frm.doc.enable_security); + frm.toggle_reqd("webhook_secret", frm.doc.enable_security); }, preview_document: (frm) => { @@ -83,13 +104,15 @@ frappe.ui.form.on('Webhook', { frm.refresh_field("preview_request_body"); }, }); - } + }, }); frappe.ui.form.on("Webhook Data", { fieldname: (frm, cdt, cdn) => { let row = locals[cdt][cdn]; - let df = frappe.get_meta(frm.doc.webhook_doctype).fields.filter((field) => field.fieldname == row.fieldname); + let df = frappe + .get_meta(frm.doc.webhook_doctype) + .fields.filter((field) => field.fieldname == row.fieldname); if (!df.length) { // check if field is a meta field @@ -98,5 +121,5 @@ frappe.ui.form.on("Webhook Data", { row.key = df.length ? df[0].fieldname : "name"; frm.refresh_field("webhook_data"); - } + }, }); diff --git a/frappe/integrations/doctype/webhook_request_log/webhook_request_log.js b/frappe/integrations/doctype/webhook_request_log/webhook_request_log.js index 9ec4f11536..1cb8c5ec76 100644 --- a/frappe/integrations/doctype/webhook_request_log/webhook_request_log.js +++ b/frappe/integrations/doctype/webhook_request_log/webhook_request_log.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Webhook Request Log', { +frappe.ui.form.on("Webhook Request Log", { // refresh: function(frm) { - // } }); diff --git a/frappe/printing/doctype/letter_head/letter_head.js b/frappe/printing/doctype/letter_head/letter_head.js index ca4dad2d07..55d97cf37f 100644 --- a/frappe/printing/doctype/letter_head/letter_head.js +++ b/frappe/printing/doctype/letter_head/letter_head.js @@ -1,8 +1,8 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Letter Head', { - refresh: function(frm) { +frappe.ui.form.on("Letter Head", { + refresh: function (frm) { frm.flag_public_attachments = true; - } + }, }); diff --git a/frappe/printing/doctype/network_printer_settings/network_printer_settings.js b/frappe/printing/doctype/network_printer_settings/network_printer_settings.js index 043afd388f..2d094d8038 100644 --- a/frappe/printing/doctype/network_printer_settings/network_printer_settings.js +++ b/frappe/printing/doctype/network_printer_settings/network_printer_settings.js @@ -1,29 +1,29 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Network Printer Settings', { - onload (frm) { +frappe.ui.form.on("Network Printer Settings", { + onload(frm) { frm.trigger("connect_print_server"); }, - server_ip (frm) { + server_ip(frm) { frm.trigger("connect_print_server"); }, - port (frm) { + port(frm) { frm.trigger("connect_print_server"); }, - connect_print_server (frm) { + connect_print_server(frm) { if (frm.doc.server_ip && frm.doc.port) { frappe.call({ - "doc": frm.doc, - "method": "get_printers_list", - "args": { + doc: frm.doc, + method: "get_printers_list", + args: { ip: frm.doc.server_ip, - port: frm.doc.port + port: frm.doc.port, + }, + callback: function (data) { + frm.set_df_property("printer_name", "options", [""].concat(data.message)); }, - callback: function(data) { - frm.set_df_property('printer_name', 'options', [""].concat(data.message)); - } }); } - } + }, }); diff --git a/frappe/printing/doctype/print_format/print_format.js b/frappe/printing/doctype/print_format/print_format.js index 3fd1d9d148..94f0ae5b1c 100644 --- a/frappe/printing/doctype/print_format/print_format.js +++ b/frappe/printing/doctype/print_format/print_format.js @@ -17,9 +17,9 @@ frappe.ui.form.on("Print Format", { if (frm.doc.standard === "Yes" && frappe.session.user !== "Administrator") { frm.set_intro(__("Please duplicate this to make changes")); } - frm.trigger('render_buttons'); - frm.toggle_display('standard', frappe.boot.developer_mode); - frm.trigger('hide_absolute_value_field'); + frm.trigger("render_buttons"); + frm.toggle_display("standard", frappe.boot.developer_mode); + frm.trigger("hide_absolute_value_field"); }, render_buttons: function (frm) { frm.page.clear_inner_toolbar(); @@ -36,22 +36,21 @@ frappe.ui.form.on("Print Format", { frappe.set_route("print-format-builder", frm.doc.name); } }); - } - else if (frm.doc.custom_format && !frm.doc.raw_printing) { + } else if (frm.doc.custom_format && !frm.doc.raw_printing) { frm.set_df_property("html", "reqd", 1); } if (frappe.model.can_read(frm.doc.doc_type)) { - frappe.db.get_value('DocType', frm.doc.doc_type, 'default_print_format', (r) => { + frappe.db.get_value("DocType", frm.doc.doc_type, "default_print_format", (r) => { if (r.default_print_format != frm.doc.name) { frm.add_custom_button(__("Set as Default"), function () { frappe.call({ method: "frappe.printing.doctype.print_format.print_format.make_default", args: { - name: frm.doc.name + name: frm.doc.name, }, - callback: function() { + callback: function () { frm.refresh(); - } + }, }); }); } @@ -61,13 +60,13 @@ frappe.ui.form.on("Print Format", { }, custom_format: function (frm) { var value = frm.doc.custom_format ? 0 : 1; - frm.set_value('align_labels_right', value); - frm.set_value('show_section_headings', value); - frm.set_value('line_breaks', value); - frm.trigger('render_buttons'); + frm.set_value("align_labels_right", value); + frm.set_value("show_section_headings", value); + frm.set_value("line_breaks", value); + frm.trigger("render_buttons"); }, doc_type: function (frm) { - frm.trigger('hide_absolute_value_field'); + frm.trigger("hide_absolute_value_field"); }, hide_absolute_value_field: function (frm) { // TODO: make it work with frm.doc.doc_type @@ -76,9 +75,11 @@ frappe.ui.form.on("Print Format", { if (doctype) { frappe.model.with_doctype(doctype, () => { const meta = frappe.get_meta(doctype); - const has_int_float_currency_field = meta.fields.filter(df => in_list(['Int', 'Float', 'Currency'], df.fieldtype)); - frm.toggle_display('absolute_value', has_int_float_currency_field.length); + const has_int_float_currency_field = meta.fields.filter((df) => + in_list(["Int", "Float", "Currency"], df.fieldtype) + ); + frm.toggle_display("absolute_value", has_int_float_currency_field.length); }); } - } + }, }); diff --git a/frappe/printing/doctype/print_format_field_template/print_format_field_template.js b/frappe/printing/doctype/print_format_field_template/print_format_field_template.js index 7fbb0d7359..4aa00ae5e7 100644 --- a/frappe/printing/doctype/print_format_field_template/print_format_field_template.js +++ b/frappe/printing/doctype/print_format_field_template/print_format_field_template.js @@ -1,8 +1,7 @@ // Copyright (c) 2021, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Print Format Field Template', { +frappe.ui.form.on("Print Format Field Template", { // refresh: function(frm) { - // } }); diff --git a/frappe/printing/doctype/print_heading/print_heading.js b/frappe/printing/doctype/print_heading/print_heading.js index 39f26a2e0f..3a2c615363 100644 --- a/frappe/printing/doctype/print_heading/print_heading.js +++ b/frappe/printing/doctype/print_heading/print_heading.js @@ -1,8 +1,6 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Print Heading', { - refresh: function(frm) { - - } +frappe.ui.form.on("Print Heading", { + refresh: function (frm) {}, }); diff --git a/frappe/printing/doctype/print_settings/print_settings.js b/frappe/printing/doctype/print_settings/print_settings.js index b1311166ee..dc939c298d 100644 --- a/frappe/printing/doctype/print_settings/print_settings.js +++ b/frappe/printing/doctype/print_settings/print_settings.js @@ -1,19 +1,23 @@ // Copyright (c) 2018, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Print Settings', { - print_style: function(frm) { - frappe.db.get_value('Print Style', frm.doc.print_style, 'preview').then((r) => { - if(r.message.preview) { +frappe.ui.form.on("Print Settings", { + print_style: function (frm) { + frappe.db.get_value("Print Style", frm.doc.print_style, "preview").then((r) => { + if (r.message.preview) { frm.get_field("print_style_preview").$wrapper.html( - ``); + `` + ); } else { frm.get_field("print_style_preview").$wrapper.html( - `

        ${__("No Preview")}

        `); + `

        ${__( + "No Preview" + )}

        ` + ); } }); }, - onload: function(frm) { + onload: function (frm) { frm.script_manager.trigger("print_style"); - } + }, }); diff --git a/frappe/printing/doctype/print_style/print_style.js b/frappe/printing/doctype/print_style/print_style.js index 44c4a528f4..3177e1aa09 100644 --- a/frappe/printing/doctype/print_style/print_style.js +++ b/frappe/printing/doctype/print_style/print_style.js @@ -1,10 +1,10 @@ // Copyright (c) 2017, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Print Style', { - refresh: function(frm) { - frm.add_custom_button(__('Print Settings'), () => { - frappe.set_route('Form', 'Print Settings'); - }) - } +frappe.ui.form.on("Print Style", { + refresh: function (frm) { + frm.add_custom_button(__("Print Settings"), () => { + frappe.set_route("Form", "Print Settings"); + }); + }, }); diff --git a/frappe/printing/page/print/print.js b/frappe/printing/page/print/print.js index 7db6930a60..90e7328a30 100644 --- a/frappe/printing/page/print/print.js +++ b/frappe/printing/page/print/print.js @@ -1,11 +1,11 @@ -frappe.pages['print'].on_page_load = function(wrapper) { +frappe.pages["print"].on_page_load = function (wrapper) { frappe.ui.make_app_page({ parent: wrapper, }); let print_view = new frappe.ui.form.PrintView(wrapper); - $(wrapper).bind('show', () => { + $(wrapper).bind("show", () => { const route = frappe.get_route(); const doctype = route[1]; const docname = route.slice(2).join("/"); @@ -19,8 +19,9 @@ frappe.pages['print'].on_page_load = function(wrapper) { }); }); } else { - print_view.frm = frappe.route_options.frm.doctype ? - frappe.route_options.frm : frappe.route_options.frm.frm; + print_view.frm = frappe.route_options.frm.doctype + ? frappe.route_options.frm + : frappe.route_options.frm.frm; frappe.route_options.frm = null; print_view.show(print_view.frm); } @@ -37,7 +38,7 @@ frappe.ui.form.PrintView = class { make() { this.print_wrapper = this.page.main.empty().html( `