diff --git a/frappe/contacts/doctype/contact/contact.js b/frappe/contacts/doctype/contact/contact.js index d318ad14ab..c6ad8cc269 100644 --- a/frappe/contacts/doctype/contact/contact.js +++ b/frappe/contacts/doctype/contact/contact.js @@ -1,8 +1,10 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -cur_frm.email_field = "email_id"; frappe.ui.form.on("Contact", { + onload(frm) { + frm.email_field = "email_id"; + }, refresh: function(frm) { if(frm.doc.__islocal) { const last_doc = frappe.contacts.get_last_doc(frm); diff --git a/frappe/core/doctype/doctype/doctype.js b/frappe/core/doctype/doctype/doctype.js index 0374026855..95de1f07b5 100644 --- a/frappe/core/doctype/doctype/doctype.js +++ b/frappe/core/doctype/doctype/doctype.js @@ -39,8 +39,3 @@ frappe.ui.form.on('DocType', { __('In Grid View') : __('In List View'); } }) - -// for legacy... :) -cur_frm.cscript.validate = function(doc, cdt, cdn) { - doc.server_code_compiled = null; -} diff --git a/frappe/core/doctype/report/report.js b/frappe/core/doctype/report/report.js index 903a9cbac4..6b48ca137a 100644 --- a/frappe/core/doctype/report/report.js +++ b/frappe/core/doctype/report/report.js @@ -1,78 +1,67 @@ -cur_frm.cscript.report_type = function(doc) { - cur_frm.set_intro(""); - switch(doc.report_type) { - case "Report Builder": - cur_frm.set_intro(__("Report Builder reports are managed directly by the report builder. Nothing to do.")); - break; - case "Query Report": - cur_frm.set_intro(__("Write a SELECT query. Note result is not paged (all data is sent in one go).") - + __("To format columns, give column labels in the query.") + "
" - + __("[Label]:[Field Type]/[Options]:[Width]") + "

" - + __("Example:") + "
" - + "Employee:Link/Employee:200" + "
" - + "Rate:Currency:120" + "
") - break; - case "Script Report": - cur_frm.set_intro(__("Write a Python file in the same folder where this is saved and return column and result.")) - break; - } -} - -cur_frm.cscript.refresh = function(doc) { - cur_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; - } - }, "fa fa-table"); - - if (doc.is_standard === "Yes") { - cur_frm.add_custom_button(doc.disabled ? __("Enable Report") : __("Disable Report"), function() { - $.ajax({ - url: "/api/resource/Report/" + encodeURIComponent(doc.name), - type: "POST", - data: { - run_method: "toggle_disable", - disable: doc.disabled ? 0 : 1 - } - }).always(function() { - cur_frm.reload_doc(); - }); - }, doc.disabled ? "fa fa-check" : "fa fa-off"); - } - - cur_frm.cscript.report_type(doc); -} - - frappe.ui.form.on('Report', { refresh: function(frm) { - if(!frappe.boot.developer_mode && frappe.session.user != 'Administrator') { + if(!frappe.boot.developer_mode && frappe.session.user !== 'Administrator') { // make the document read-only frm.set_read_only(); } + + 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; + } + }, "fa fa-table"); + + if (doc.is_standard === "Yes") { + 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.events.report_type(frm); }, ref_doctype: function(frm) { if(frm.doc.ref_doctype) { - frm.trigger("set_doctype_roles") + frm.trigger("set_doctype_roles"); + } + }, + + report_type: function(frm) { + frm.set_intro(""); + switch(frm.doc.report_type) { + case "Report Builder": + frm.set_intro(__("Report Builder reports are managed directly by the report builder. Nothing to do.")); + break; + case "Query Report": + frm.set_intro(__("Write a SELECT query. Note result is not paged (all data is sent in one go).") + + __("To format columns, give column labels in the query.") + "
" + + __("[Label]:[Field Type]/[Options]:[Width]") + "

" + + __("Example:") + "
" + + "Employee:Link/Employee:200" + "
" + + "Rate:Currency:120" + "
") + break; + case "Script Report": + frm.set_intro(__("Write a Python file in the same folder where this is saved and return column and result.")); + break; } }, set_doctype_roles: function(frm) { - return frappe.call({ - method: "set_doctype_roles", - doc:frm.doc, - callback: function(r) { - refresh_field('roles') - } - }) + return frm.call('set_doctype_roles').then(() => { + frm.refresh_field('roles'); + }); } }) diff --git a/frappe/core/doctype/user/user.js b/frappe/core/doctype/user/user.js index d334731015..21f05c814d 100644 --- a/frappe/core/doctype/user/user.js +++ b/frappe/core/doctype/user/user.js @@ -140,7 +140,7 @@ frappe.ui.form.on('User', { for ( var i=0;i { + frm.refresh(); + }); + }, "fa fa-play", "btn-success"); + } - cur_frm.cscript.setup_dashboard(); + frm.events.setup_dashboard(frm); - if(doc.__islocal && !doc.send_from) { - cur_frm.set_value("send_from", - repl("%(fullname)s <%(email)s>", frappe.user_info(doc.owner))); - } -} + if(doc.__islocal && !doc.send_from) { + let { fullname, email } = frappe.user_info(doc.owner); + frm.set_value('send_from', `${fullname} <${email}>`); + } + }, -cur_frm.cscript.setup_dashboard = function() { - if(!cur_frm.doc.__islocal && cint(cur_frm.doc.email_sent) - && cur_frm.doc.__onload && cur_frm.doc.__onload.status_count) { - var stat = cur_frm.doc.__onload.status_count; - var total = cur_frm.doc.scheduled_to_send; - if(total) { - $.each(stat, function(k, v) { - stat[k] = flt(v * 100 / total, 2) + '%'; - }); + setup_dashboard(frm) { + if(!frm.doc.__islocal && cint(frm.doc.email_sent) + && frm.doc.__onload && frm.doc.__onload.status_count) { + var stat = frm.doc.__onload.status_count; + var total = frm.doc.scheduled_to_send; + if(total) { + $.each(stat, function(k, v) { + stat[k] = flt(v * 100 / total, 2) + '%'; + }); - cur_frm.dashboard.add_progress("Status", [ - { - title: stat["Not Sent"] + " Queued", - width: stat["Not Sent"], - progress_class: "progress-bar-info" - }, - { - title: stat["Sent"] + " Sent", - width: stat["Sent"], - progress_class: "progress-bar-success" - }, - { - title: stat["Sending"] + " Sending", - width: stat["Sending"], - progress_class: "progress-bar-warning" - }, - { - title: stat["Error"] + "% Error", - width: stat["Error"], - progress_class: "progress-bar-danger" - } - ]); + frm.dashboard.add_progress("Status", [ + { + title: stat["Not Sent"] + " Queued", + width: stat["Not Sent"], + progress_class: "progress-bar-info" + }, + { + title: stat["Sent"] + " Sent", + width: stat["Sent"], + progress_class: "progress-bar-success" + }, + { + title: stat["Sending"] + " Sending", + width: stat["Sending"], + progress_class: "progress-bar-warning" + }, + { + title: stat["Error"] + "% Error", + width: stat["Error"], + progress_class: "progress-bar-danger" + } + ]); + } } } -} \ No newline at end of file +}); diff --git a/frappe/geo/doctype/currency/currency.js b/frappe/geo/doctype/currency/currency.js index cb2202abff..af2d6ebc4e 100644 --- a/frappe/geo/doctype/currency/currency.js +++ b/frappe/geo/doctype/currency/currency.js @@ -1,9 +1,11 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: See license.txt -cur_frm.cscript.refresh = function(doc) { - cur_frm.set_intro(""); - if(!cur_frm.doc.enabled) { - cur_frm.set_intro(__("This Currency is disabled. Enable to use in transactions")) +frappe.ui.form.on('Currency', { + refresh(frm) { + frm.set_intro(""); + if(!frm.doc.enabled) { + frm.set_intro(__("This Currency is disabled. Enable to use in transactions")); + } } -} \ No newline at end of file +}); diff --git a/frappe/public/js/frappe/misc/address_and_contact.js b/frappe/public/js/frappe/misc/address_and_contact.js index 4bdc9bb9e6..3b05e5f0bb 100644 --- a/frappe/public/js/frappe/misc/address_and_contact.js +++ b/frappe/public/js/frappe/misc/address_and_contact.js @@ -11,7 +11,7 @@ $.extend(frappe.contacts, { if(frm.fields_dict['address_html'] && "addr_list" in frm.doc.__onload) { $(frm.fields_dict['address_html'].wrapper) .html(frappe.render_template("address_list", - cur_frm.doc.__onload)) + frm.doc.__onload)) .find(".btn-address").on("click", function() { frappe.new_doc("Address"); }); @@ -21,7 +21,7 @@ $.extend(frappe.contacts, { if(frm.fields_dict['contact_html'] && "contact_list" in frm.doc.__onload) { $(frm.fields_dict['contact_html'].wrapper) .html(frappe.render_template("contact_list", - cur_frm.doc.__onload)) + frm.doc.__onload)) .find(".btn-contact").on("click", function() { frappe.new_doc("Contact"); }