Merge pull request #7094 from netchampfaris/remove-old-style-custom-scripts

fix: Remove cscript and cur_frm from all client scripts
This commit is contained in:
Suraj Shetty 2019-03-22 10:15:30 +05:30 committed by GitHub
commit b79308b3bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 121 additions and 133 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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.") + "<br>"
+ __("[Label]:[Field Type]/[Options]:[Width]") + "<br><br>"
+ __("Example:") + "<br>"
+ "Employee:Link/Employee:200" + "<br>"
+ "Rate:Currency:120" + "<br>")
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.") + "<br>"
+ __("[Label]:[Field Type]/[Options]:[Width]") + "<br><br>"
+ __("Example:") + "<br>"
+ "Employee:Link/Employee:200" + "<br>"
+ "Rate:Currency:120" + "<br>")
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');
});
}
})

View file

@ -140,7 +140,7 @@ frappe.ui.form.on('User', {
for ( var i=0;i<frm.doc.user_emails.length;i++) {
frm.doc.user_emails[i].idx=frm.doc.user_emails[i].idx+1;
}
cur_frm.dirty();
frm.dirty();
}
},

View file

@ -1,11 +1,10 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
// MIT License. See license.txt
$.extend(cur_frm.cscript, {
validate: function(doc) {
if(doc.property_type=='Check' && !in_list(['0','1'], doc.value)) {
frappe.msgprint(__('Value for a check field can be either 0 or 1'));
frappe.validated = false;
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'));
}
}
})
});

View file

@ -1,58 +1,59 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
/* globals erpnext */
cur_frm.cscript.refresh = function(doc) {
if(window.erpnext) erpnext.toggle_naming_series();
if(!doc.__islocal && !cint(doc.email_sent) && !doc.__unsaved
&& in_list(frappe.boot.user.can_write, doc.doctype)) {
cur_frm.add_custom_button(__('Send'), function() {
return $c_obj(doc, 'send_emails', '', function(r) {
cur_frm.refresh();
});
}, "fa fa-play", "btn-success");
}
frappe.ui.form.on('Newsletter', {
refresh(frm) {
let doc = frm.doc;
if(!doc.__islocal && !cint(doc.email_sent) && !doc.__unsaved
&& in_list(frappe.boot.user.can_write, doc.doctype)) {
frm.add_custom_button(__('Send'), function() {
frm.call('send_emails').then(() => {
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"
}
]);
}
}
}
}
});

View file

@ -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"));
}
}
}
});

View file

@ -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");
}