From 68f5afe1372f2a6651e20a9d6a76bc0aa21bb65a Mon Sep 17 00:00:00 2001 From: prssanna Date: Fri, 29 Jan 2021 12:24:57 +0530 Subject: [PATCH] style: spacing issues --- frappe/public/js/frappe/form/layout.js | 2 +- frappe/public/js/frappe/form/print_utils.js | 251 +++++++++++------- frappe/public/js/frappe/form/toolbar.js | 2 +- .../public/js/frappe/list/list_view_select.js | 248 +++++++++-------- frappe/public/js/frappe/views/formview.js | 2 +- 5 files changed, 296 insertions(+), 209 deletions(-) diff --git a/frappe/public/js/frappe/form/layout.js b/frappe/public/js/frappe/form/layout.js index 8c6b813973..2f4f29b8f9 100644 --- a/frappe/public/js/frappe/form/layout.js +++ b/frappe/public/js/frappe/form/layout.js @@ -551,7 +551,7 @@ frappe.ui.form.Layout = Class.extend({ frappe.throw(__('Invalid "depends_on" expression')); } - } else if (expression.substr(0,3)=='fn:' && this.frm) { + } else if (expression.substr(0, 3)=='fn:' && this.frm) { out = this.frm.script_manager.trigger(expression.substr(3), this.doctype, this.docname); } else { var value = doc[expression]; diff --git a/frappe/public/js/frappe/form/print_utils.js b/frappe/public/js/frappe/form/print_utils.js index b9bde48216..5b04cd01a4 100644 --- a/frappe/public/js/frappe/form/print_utils.js +++ b/frappe/public/js/frappe/form/print_utils.js @@ -1,38 +1,50 @@ -frappe.ui.get_print_settings = function (pdf, callback, letter_head, pick_columns) { +frappe.ui.get_print_settings = function( + pdf, + callback, + letter_head, + pick_columns +) { var print_settings = locals[":Print Settings"]["Print Settings"]; - var default_letter_head = locals[":Company"] && frappe.defaults.get_default('company') - ? locals[":Company"][frappe.defaults.get_default('company')]["default_letter_head"] - : ''; + var default_letter_head = + locals[":Company"] && frappe.defaults.get_default("company") + ? locals[":Company"][frappe.defaults.get_default("company")][ + "default_letter_head" + ] + : ""; - var columns = [{ - fieldtype: "Check", - fieldname: "with_letter_head", - label: __("With Letter head") - }, { - fieldtype: "Select", - fieldname: "letter_head", - label: __("Letter Head"), - depends_on: "with_letter_head", - options: frappe.boot.letter_heads, - default: letter_head || default_letter_head - }, { - fieldtype: "Select", - fieldname: "orientation", - label: __("Orientation"), - options: [ - { "value": "Landscape", "label": __("Landscape") }, - { "value": "Portrait", "label": __("Portrait") } - ], - default: "Landscape" - }]; + var columns = [ + { + fieldtype: "Check", + fieldname: "with_letter_head", + label: __("With Letter head") + }, + { + fieldtype: "Select", + fieldname: "letter_head", + label: __("Letter Head"), + depends_on: "with_letter_head", + options: frappe.boot.letter_heads, + default: letter_head || default_letter_head + }, + { + fieldtype: "Select", + fieldname: "orientation", + label: __("Orientation"), + options: [ + { value: "Landscape", label: __("Landscape") }, + { value: "Portrait", label: __("Portrait") } + ], + default: "Landscape" + } + ]; if (pick_columns) { columns.push( { label: __("Pick Columns"), fieldtype: "Check", - fieldname: "pick_columns", + fieldname: "pick_columns" }, { label: __("Select Columns"), @@ -48,18 +60,22 @@ frappe.ui.get_print_settings = function (pdf, callback, letter_head, pick_column ); } - return frappe.prompt(columns, function (data) { - var data = $.extend(print_settings, data); - if (!data.with_letter_head) { - data.letter_head = null; - } - if (data.letter_head) { - data.letter_head = frappe.boot.letter_heads[print_settings.letter_head]; - } - callback(data); - }, __("Print Settings")); -} - + return frappe.prompt( + columns, + function(data) { + var data = $.extend(print_settings, data); + if (!data.with_letter_head) { + data.letter_head = null; + } + if (data.letter_head) { + data.letter_head = + frappe.boot.letter_heads[print_settings.letter_head]; + } + callback(data); + }, + __("Print Settings") + ); +}; // qz tray connection wrapper // - allows active and inactive connections to resolve regardless @@ -67,62 +83,87 @@ frappe.ui.get_print_settings = function (pdf, callback, letter_head, pick_column // - if connection fails, catch the reject, fire the mimetype launcher // - after mimetype launcher is fired, try to connect 3 more times // - display success/fail message to user -frappe.ui.form.qz_connect = function () { - return new Promise(function (resolve, reject) { +frappe.ui.form.qz_connect = function() { + return new Promise(function(resolve, reject) { frappe.ui.form.qz_init().then(() => { - if (qz.websocket.isActive()) { // if already active, resolve immediately + if (qz.websocket.isActive()) { + // if already active, resolve immediately // frappe.show_alert({message: __('QZ Tray Connection Active!'), indicator: 'green'}); resolve(); } else { // try to connect once before firing the mimetype launcher frappe.show_alert({ - message: __('Attempting Connection to QZ Tray...'), - indicator: 'blue' + message: __("Attempting Connection to QZ Tray..."), + indicator: "blue" }); - qz.websocket.connect().then(() => { - frappe.show_alert({ - message: __('Connected to QZ Tray!'), - indicator: 'green' - }); - resolve(); - }, function retry(err) { - if (err.message === 'Unable to establish connection with QZ') { - // if a connect was not successful, launch the mimetype, try 3 more times + qz.websocket.connect().then( + () => { frappe.show_alert({ - message: __('Attempting to launch QZ Tray...'), - indicator: 'blue' - }, 14); - window.location.assign("qz:launch"); - qz.websocket.connect({ - retries: 3, - delay: 1 - }).then(() => { - frappe.show_alert({ - message: __('Connected to QZ Tray!'), - indicator: 'green' - }); - resolve(); - }, - () => { - frappe.throw(__('Error connecting to QZ Tray Application...

You need to have QZ Tray application installed and running, to use the Raw Print feature.

Click here to Download and install QZ Tray.
Click here to learn more about Raw Printing.')); - reject(); + message: __("Connected to QZ Tray!"), + indicator: "green" }); - } else { - frappe.show_alert({ - message: 'QZ Tray ' + err.toString(), - indicator: 'red' - }, 14); - reject(); + resolve(); + }, + function retry(err) { + if ( + err.message === + "Unable to establish connection with QZ" + ) { + // if a connect was not successful, launch the mimetype, try 3 more times + frappe.show_alert( + { + message: __( + "Attempting to launch QZ Tray..." + ), + indicator: "blue" + }, + 14 + ); + window.location.assign("qz:launch"); + qz.websocket + .connect({ + retries: 3, + delay: 1 + }) + .then( + () => { + frappe.show_alert({ + message: __( + "Connected to QZ Tray!" + ), + indicator: "green" + }); + resolve(); + }, + () => { + frappe.throw( + __( + 'Error connecting to QZ Tray Application...

You need to have QZ Tray application installed and running, to use the Raw Print feature.

Click here to Download and install QZ Tray.
Click here to learn more about Raw Printing.' + ) + ); + reject(); + } + ); + } else { + frappe.show_alert( + { + message: "QZ Tray " + err.toString(), + indicator: "red" + }, + 14 + ); + reject(); + } } - }); + ); } }); }); -} +}; -frappe.ui.form.qz_init = function () { +frappe.ui.form.qz_init = function() { // Initializing qz tray library - return new Promise((resolve) => { + return new Promise(resolve => { if (typeof qz === "object" && typeof qz.version === "string") { // resolve immediately if already Initialized resolve(); @@ -131,11 +172,11 @@ frappe.ui.form.qz_init = function () { "/assets/frappe/node_modules/js-sha256/build/sha256.min.js", "/assets/frappe/node_modules/qz-tray/qz-tray.js" ]; - frappe.require(qz_required_assets,() => { + frappe.require(qz_required_assets, () => { qz.api.setPromiseType(function promise(resolver) { return new Promise(resolver); }); - qz.api.setSha256Type(function (data) { + qz.api.setSha256Type(function(data) { // Codacy fix /*global sha256*/ return sha256(data); @@ -144,33 +185,39 @@ frappe.ui.form.qz_init = function () { }); // note 'frappe.require' does not have callback on fail. Hence, any failure cannot be communicated to the user. } - }); -} +}; -frappe.ui.form.qz_get_printer_list = function () { +frappe.ui.form.qz_get_printer_list = function() { // returns the list of printers that are available to the QZ Tray - return frappe.ui.form.qz_connect().then(function () { - return qz.printers.find(); - }).then((data) => { - return data; - }).catch((err) => { - frappe.ui.form.qz_fail(err); - }); -} + return frappe.ui.form + .qz_connect() + .then(function() { + return qz.printers.find(); + }) + .then(data => { + return data; + }) + .catch(err => { + frappe.ui.form.qz_fail(err); + }); +}; -frappe.ui.form.qz_success = function () { +frappe.ui.form.qz_success = function() { // notify qz successful print frappe.show_alert({ - message: __('Print Sent to the printer!'), - indicator: 'green' + message: __("Print Sent to the printer!"), + indicator: "green" }); -} +}; -frappe.ui.form.qz_fail = function (e) { +frappe.ui.form.qz_fail = function(e) { // notify qz errors - frappe.show_alert({ - message: __("QZ Tray Failed: ") + e.toString(), - indicator: 'red' - }, 20); -} + frappe.show_alert( + { + message: __("QZ Tray Failed: ") + e.toString(), + indicator: "red" + }, + 20 + ); +}; diff --git a/frappe/public/js/frappe/form/toolbar.js b/frappe/public/js/frappe/form/toolbar.js index a8dd503f43..25b8d71f13 100644 --- a/frappe/public/js/frappe/form/toolbar.js +++ b/frappe/public/js/frappe/form/toolbar.js @@ -249,7 +249,7 @@ frappe.ui.form.Toolbar = class Toolbar { }, true); this.print_icon = this.page.add_action_icon("printer", function() { me.frm.print_doc(); - },'', __("Print")); + }, '', __("Print")); } } diff --git a/frappe/public/js/frappe/list/list_view_select.js b/frappe/public/js/frappe/list/list_view_select.js index a059354ba8..646efcfbfe 100644 --- a/frappe/public/js/frappe/list/list_view_select.js +++ b/frappe/public/js/frappe/list/list_view_select.js @@ -1,4 +1,4 @@ -frappe.provide('frappe.views'); +frappe.provide("frappe.views"); frappe.views.ListViewSelect = class ListViewSelect { constructor(opts) { @@ -14,110 +14,112 @@ frappe.views.ListViewSelect = class ListViewSelect { action, true, null, - this.icon_map[view] || 'list' + this.icon_map[view] || "list" ); - $el.parent().attr('data-view', view) + $el.parent().attr("data-view", view); } set_current_view() { - this.current_view = 'List'; + this.current_view = "List"; const route = frappe.get_route(); - const view_name = frappe.utils.to_title_case(route[2] || ''); + const view_name = frappe.utils.to_title_case(route[2] || ""); if (route.length > 2 && frappe.views.view_modes.includes(view_name)) { this.current_view = view_name; - if (this.current_view === 'Kanban') { + if (this.current_view === "Kanban") { this.kanban_board = route[3]; - } else if (this.current_view === 'Inbox') { + } else if (this.current_view === "Inbox") { this.email_account = route[3]; } } } set_route(view, calendar_name) { - const route = [this.slug(), 'view', view]; + const route = [this.slug(), "view", view]; if (calendar_name) route.push(calendar_name); frappe.set_route(route); } setup_views() { const views = { - 'List': { + List: { condition: true, - action: () => this.set_route('list') + action: () => this.set_route("list") }, - 'Report': { + Report: { condition: true, - action: () => this.set_route('report'), + action: () => this.set_route("report"), current_view_handler: () => { const reports = this.get_reports(); - this.setup_dropdown_in_sidebar( - 'Report', - reports, - { - label: __('Report Builder'), - action: () => this.set_route('report') - } - ); - } - }, - 'Dashboard': { - condition: true, - action: () => this.set_route('dashboard') - }, - 'Calendar': { - condition: frappe.views.calendar[this.doctype], - action: () => this.set_route('calendar', 'default'), - current_view_handler: () => { - this.get_calendars().then(calendars => { - this.setup_dropdown_in_sidebar( - 'Calendar', - calendars, - ); + this.setup_dropdown_in_sidebar("Report", reports, { + label: __("Report Builder"), + action: () => this.set_route("report") }); } }, - 'Gantt': { - condition: frappe.views.calendar[this.doctype], - action: () => this.set_route('gantt') + Dashboard: { + condition: true, + action: () => this.set_route("dashboard") }, - 'Inbox': { - condition: this.doctype === "Communication" && frappe.boot.email_accounts.length, - action: () => this.set_route('inbox'), + Calendar: { + condition: frappe.views.calendar[this.doctype], + action: () => this.set_route("calendar", "default"), + current_view_handler: () => { + this.get_calendars().then(calendars => { + this.setup_dropdown_in_sidebar("Calendar", calendars); + }); + } + }, + Gantt: { + condition: frappe.views.calendar[this.doctype], + action: () => this.set_route("gantt") + }, + Inbox: { + condition: + this.doctype === "Communication" && + frappe.boot.email_accounts.length, + action: () => this.set_route("inbox"), current_view_handler: () => { const accounts = this.get_email_accounts(); let default_action; - if (has_common(frappe.user_roles, ["System Manager", "Administrator"])) { + if ( + has_common(frappe.user_roles, [ + "System Manager", + "Administrator" + ]) + ) { default_action = { - label: __('New Email Account'), + label: __("New Email Account"), action: () => frappe.new_doc("Email Account") - } + }; } this.setup_dropdown_in_sidebar( - 'Inbox', + "Inbox", accounts, - default_action, + default_action ); } }, - 'Image': { + Image: { condition: this.list_view.meta.image_field, - action: () => this.set_route('image') + action: () => this.set_route("image") }, - 'Tree': { - condition: frappe.treeview_settings[this.doctype] || frappe.get_meta(this.doctype).is_tree, - action: () => this.set_route('tree') + Tree: { + condition: + frappe.treeview_settings[this.doctype] || + frappe.get_meta(this.doctype).is_tree, + action: () => this.set_route("tree") }, - 'Kanban': { + Kanban: { condition: true, action: () => this.setup_kanban_boards(), current_view_handler: () => { - frappe.views.KanbanView.get_kanbans(this.doctype).then((kanbans) => - this.setup_kanban_switcher(kanbans) + frappe.views.KanbanView.get_kanbans(this.doctype).then( + kanbans => this.setup_kanban_switcher(kanbans) ); } - }, - } + } + }; frappe.views.view_modes.forEach(view => { if (this.current_view !== view && views[view].condition) { @@ -125,71 +127,78 @@ frappe.views.ListViewSelect = class ListViewSelect { } if (this.current_view == view) { - views[view].current_view_handler && views[view].current_view_handler(); + views[view].current_view_handler && + views[view].current_view_handler(); } }); } - setup_dropdown_in_sidebar(view, items, default_action) { if (!this.sidebar) return; - const views_wrapper = this.sidebar.sidebar.find('.views-section'); - views_wrapper.find('.sidebar-label').html(`${__(view)}`); - const $dropdown = views_wrapper.find('.views-dropdown'); + const views_wrapper = this.sidebar.sidebar.find(".views-section"); + views_wrapper.find(".sidebar-label").html(`${__(view)}`); + const $dropdown = views_wrapper.find(".views-dropdown"); let placeholder = `Select ${view}`; let html = ``; if (!items || !items.length) { html = `
- ${__('No {} Found', [view])} + ${__("No {} Found", [view])}
`; } else { items.map(item => { if (item.name == this.get_page_name()) { placeholder = item.name; } - html += `
  • ${item.name}
  • `; + html += `
  • ${ + item.name + }
  • `; }); } - views_wrapper.find('.selected-view').html(placeholder); + views_wrapper.find(".selected-view").html(placeholder); if (default_action) { - views_wrapper.find('.sidebar-action a').html(default_action.label); - views_wrapper.find('.sidebar-action a').click(() => default_action.action()); + views_wrapper.find(".sidebar-action a").html(default_action.label); + views_wrapper + .find(".sidebar-action a") + .click(() => default_action.action()); } $dropdown.html(html); - views_wrapper.removeClass('hide'); + views_wrapper.removeClass("hide"); } setup_kanban_switcher(kanbans) { - const kanban_switcher = - this.page.add_custom_button_group( - __('Select Kanban'), null, this.list_view.$filter_section - ); + const kanban_switcher = this.page.add_custom_button_group( + __("Select Kanban"), + null, + this.list_view.$filter_section + ); kanbans.map(k => { this.page.add_custom_menu_item( kanban_switcher, k.name, - () => this.set_route('kanban', k.name), + () => this.set_route("kanban", k.name), false ); }); this.page.add_custom_menu_item( kanban_switcher, - __('Create New Kanban Board'), + __("Create New Kanban Board"), () => frappe.views.KanbanView.show_kanban_dialog(this.doctype), true ); } get_page_name() { - return frappe.utils.to_title_case(frappe.get_route().slice(-1)[0] || '') + return frappe.utils.to_title_case( + frappe.get_route().slice(-1)[0] || "" + ); } get_reports() { @@ -197,18 +206,24 @@ frappe.views.ListViewSelect = class ListViewSelect { let added = []; let reports_to_add = []; - let add_reports = (reports) => { - reports.map((r) => { + let add_reports = reports => { + reports.map(r => { if (!r.ref_doctype || r.ref_doctype == this.doctype) { - const report_type = r.report_type === 'Report Builder' ? - `/app/list/${r.ref_doctype}/report` : 'query-report'; + const report_type = + r.report_type === "Report Builder" + ? `/app/list/${r.ref_doctype}/report` + : "query-report"; - const route = r.route || report_type + '/' + (r.title || r.name); + const route = + r.route || report_type + "/" + (r.title || r.name); if (added.indexOf(route) === -1) { // don't repeat added.push(route); - reports_to_add.push({name: r.title || r.name, route: route}); + reports_to_add.push({ + name: r.title || r.name, + route: route + }); } } }); @@ -220,7 +235,10 @@ frappe.views.ListViewSelect = class ListViewSelect { } // Sort reports alphabetically - var reports = Object.values(frappe.boot.user.all_reports).sort((a,b) => a.title.localeCompare(b.title)) || []; + var reports = + Object.values(frappe.boot.user.all_reports).sort((a, b) => + a.title.localeCompare(b.title) + ) || []; // from specially tagged reports add_reports(reports); @@ -229,10 +247,17 @@ frappe.views.ListViewSelect = class ListViewSelect { } setup_kanban_boards() { - const last_opened_kanban = frappe.model.user_settings[this.doctype]['Kanban'] - && frappe.model.user_settings[this.doctype]['Kanban'].last_kanban_board; + const last_opened_kanban = + frappe.model.user_settings[this.doctype]["Kanban"] && + frappe.model.user_settings[this.doctype]["Kanban"] + .last_kanban_board; if (last_opened_kanban) { - frappe.set_route('list', this.doctype, 'kanban', last_opened_kanban); + frappe.set_route( + "list", + this.doctype, + "kanban", + last_opened_kanban + ); } else { frappe.views.KanbanView.show_kanban_dialog(this.doctype, true); } @@ -242,35 +267,50 @@ frappe.views.ListViewSelect = class ListViewSelect { const doctype = this.doctype; let calendars = []; - return frappe.db.get_list('Calendar View', { - filters: { - reference_doctype: doctype - } - }).then(result => { - if (!(result && Array.isArray(result) && result.length)) return; + return frappe.db + .get_list("Calendar View", { + filters: { + reference_doctype: doctype + } + }) + .then(result => { + if (!(result && Array.isArray(result) && result.length)) return; - if (frappe.views.calendar[this.doctype]) { - // has standard calendar view - calendars.push({ - name: 'Default', - route: `/app/${this.slug()}/view/calendar/default` + if (frappe.views.calendar[this.doctype]) { + // has standard calendar view + calendars.push({ + name: "Default", + route: `/app/${this.slug()}/view/calendar/default` + }); + } + result.map(calendar => { + calendars.push({ + name: calendar.name, + route: `/app/${this.slug()}/view/calendar/${ + calendar.name + }` + }); }); - } - result.map(calendar => { - calendars.push({name: calendar.name, route: `/app/${this.slug()}/view/calendar/${calendar.name}`}); - }); - return calendars; - }); + return calendars; + }); } get_email_accounts() { let accounts_to_add = []; let accounts = frappe.boot.email_accounts; accounts.forEach(account => { - let email_account = (account.email_id == "All Accounts") ? "All Accounts" : account.email_account; + let email_account = + account.email_id == "All Accounts" + ? "All Accounts" + : account.email_account; let route = `/app/communication/inbox/${email_account}`; - let display_name = ["All Accounts", "Sent Mail", "Spam", "Trash"].includes(account.email_id) + let display_name = [ + "All Accounts", + "Sent Mail", + "Spam", + "Trash" + ].includes(account.email_id) ? __(account.email_id) : account.email_account; @@ -286,4 +326,4 @@ frappe.views.ListViewSelect = class ListViewSelect { slug() { return frappe.router.slug(frappe.router.doctype_layout || this.doctype); } -} \ No newline at end of file +}; diff --git a/frappe/public/js/frappe/views/formview.js b/frappe/public/js/frappe/views/formview.js index 22cefc0fff..87ec67650c 100644 --- a/frappe/public/js/frappe/views/formview.js +++ b/frappe/public/js/frappe/views/formview.js @@ -82,7 +82,7 @@ frappe.views.FormFactory = class FormFactory extends frappe.views.Factory { if (r && r['403']) return; // not permitted if (!(locals[doctype] && locals[doctype][name])) { - if (name && name.substr(0,3)==='new') { + if (name && name.substr(0, 3) === 'new') { this.render_new_doc(doctype, name, doctype_layout); } else { frappe.show_not_found(route);