Remove old style custom scripts (#17077)

* fix: Move Newsletter script from frappe to erpnext

* fix: Remove old style client scripts

* C-Form

* fix: Cost Center

* fix: Fiscal Year

* fix: Monthly Distribution

* fix: Payment Gateway Account

* fix: Pricing Rule

* fix: Missing semicolon
diff --git a/erpnext/accounts/doctype/c_form/c_form.js b/erpnext/accounts/doctype/c_form/c_form.js
index 92cdb63..3d0fc0a 100644
--- a/erpnext/accounts/doctype/c_form/c_form.js
+++ b/erpnext/accounts/doctype/c_form/c_form.js
@@ -4,24 +4,38 @@
 //c-form js file
 // -----------------------------
 
+frappe.ui.form.on('C-Form', {
+	setup(frm) {
+		frm.fields_dict.invoices.grid.get_field("invoice_no").get_query = function(doc) {
+			return {
+				filters: {
+					"docstatus": 1,
+					"customer": doc.customer,
+					"company": doc.company,
+					"c_form_applicable": 'Yes',
+					"c_form_no": ''
+				}
+			};
+		}
 
-cur_frm.fields_dict.invoices.grid.get_field("invoice_no").get_query = function(doc) {
-	return {
-		filters: {
-			"docstatus": 1,
-			"customer": doc.customer,
-			"company": doc.company,
-			"c_form_applicable": 'Yes',
-			"c_form_no": ''
+		frm.fields_dict.state.get_query = function() {
+			return {
+				filters: {
+					country: "India"
+				}
+			};
 		}
 	}
-}
+});
 
-cur_frm.fields_dict.state.get_query = function(doc) {
-	return {filters: { country: "India"}}
-}
+frappe.ui.form.on('C-Form Invoice Detail', {
+	invoice_no(frm, cdt, cdn) {
+		let d = frappe.get_doc(cdt, cdn);
 
-cur_frm.cscript.invoice_no = function(doc, cdt, cdn) {
-	var d = locals[cdt][cdn];
-	return get_server_fields('get_invoice_details', d.invoice_no, 'invoices', doc, cdt, cdn, 1);
-}
\ No newline at end of file
+		frm.call('get_invoice_details', {
+			invoice_no: d.invoice_no
+		}).then(r => {
+			frappe.model.set_value(cdt, cdn, r.message);
+		});
+	}
+});
diff --git a/erpnext/accounts/doctype/cost_center/cost_center.js b/erpnext/accounts/doctype/cost_center/cost_center.js
index 3df4da5..96ec57d 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.js
+++ b/erpnext/accounts/doctype/cost_center/cost_center.js
@@ -22,6 +22,28 @@
 				frm.trigger("update_cost_center_number");
 			});
 		}
+
+		let intro_txt = '';
+		let doc = frm.doc;
+		frm.toggle_display('cost_center_name', doc.__islocal);
+		frm.toggle_enable(['is_group', 'company'], doc.__islocal);
+
+		if(!doc.__islocal && doc.is_group==1) {
+			intro_txt += __('Note: This Cost Center is a Group. Cannot make accounting entries against groups.');
+		}
+
+		frm.events.hide_unhide_group_ledger(frm);
+
+		frm.toggle_display('sb1', doc.is_group==0);
+		frm.set_intro(intro_txt);
+
+		if(!frm.doc.__islocal) {
+			frm.add_custom_button(__('Chart of Cost Centers'),
+				function() { frappe.set_route("Tree", "Cost Center"); });
+
+			frm.add_custom_button(__('Budget'),
+				function() { frappe.set_route("List", "Budget", {'cost_center': frm.doc.name}); });
+		}
 	},
 	update_cost_center_number: function(frm) {
 		var d = new frappe.ui.Dialog({
@@ -64,62 +86,38 @@
 			primary_action_label: __('Update')
 		});
 		d.show();
+	},
+
+	parent_cost_center(frm) {
+		if(!frm.doc.company) {
+			frappe.msgprint(__('Please enter company name first'));
+		}
+	},
+
+	hide_unhide_group_ledger(frm) {
+		let doc = frm.doc;
+		if (doc.is_group == 1) {
+			frm.add_custom_button(__('Convert to Non-Group'),
+				() => frm.events.convert_to_ledger(frm));
+		} else if (doc.is_group == 0) {
+			frm.add_custom_button(__('Convert to Group'),
+				() => frm.events.convert_to_group(frm));
+		}
+	},
+
+	convert_to_group(frm) {
+		frm.call('convert_ledger_to_group').then(r => {
+			if(r.message === 1) {
+				frm.refresh();
+			}
+		});
+	},
+
+	convert_to_ledger(frm) {
+		frm.call('convert_group_to_ledger').then(r => {
+			if(r.message === 1) {
+				frm.refresh();
+			}
+		});
 	}
 });
-
-cur_frm.cscript.refresh = function(doc, cdt, cdn) {
-	var intro_txt = '';
-	cur_frm.toggle_display('cost_center_name', doc.__islocal);
-	cur_frm.toggle_enable(['is_group', 'company'], doc.__islocal);
-
-	if(!doc.__islocal && doc.is_group==1) {
-		intro_txt += __('Note: This Cost Center is a Group. Cannot make accounting entries against groups.');
-	}
-
-	cur_frm.cscript.hide_unhide_group_ledger(doc);
-
-	cur_frm.toggle_display('sb1', doc.is_group==0)
-	cur_frm.set_intro(intro_txt);
-
-	if(!cur_frm.doc.__islocal) {
-		cur_frm.add_custom_button(__('Chart of Cost Centers'),
-			function() { frappe.set_route("Tree", "Cost Center"); });
-
-		cur_frm.add_custom_button(__('Budget'),
-			function() { frappe.set_route("List", "Budget", {'cost_center': cur_frm.doc.name}); });
-	}
-}
-
-cur_frm.cscript.parent_cost_center = function(doc, cdt, cdn) {
-	if(!doc.company){
-		frappe.msgprint(__('Please enter company name first'));
-	}
-}
-
-cur_frm.cscript.hide_unhide_group_ledger = function(doc) {
-	if (doc.is_group == 1) {
-		cur_frm.add_custom_button(__('Convert to Non-Group'),
-			function() { cur_frm.cscript.convert_to_ledger(); }, "fa fa-retweet",
-				"btn-default")
-	} else if (doc.is_group == 0) {
-		cur_frm.add_custom_button(__('Convert to Group'),
-			function() { cur_frm.cscript.convert_to_group(); }, "fa fa-retweet",
-				"btn-default")
-	}
-}
-
-cur_frm.cscript.convert_to_ledger = function(doc, cdt, cdn) {
-	return $c_obj(cur_frm.doc,'convert_group_to_ledger','',function(r,rt) {
-		if(r.message == 1) {
-			cur_frm.refresh();
-		}
-	});
-}
-
-cur_frm.cscript.convert_to_group = function(doc, cdt, cdn) {
-	return $c_obj(cur_frm.doc,'convert_ledger_to_group','',function(r,rt) {
-		if(r.message == 1) {
-			cur_frm.refresh();
-		}
-	});
-}
diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.js b/erpnext/accounts/doctype/fiscal_year/fiscal_year.js
index 4dc6433..152e17d 100644
--- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.js
+++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.js
@@ -1,37 +1,31 @@
 // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
 
-$.extend(cur_frm.cscript, {
-	onload: function() {
-		if(cur_frm.doc.__islocal) {
-			cur_frm.set_value("year_start_date",
+frappe.ui.form.on('Fiscal Year', {
+	onload: function(frm) {
+		if(frm.doc.__islocal) {
+			frm.set_value("year_start_date",
 				frappe.datetime.add_days(frappe.defaults.get_default("year_end_date"), 1));
 		}
 	},
-	refresh: function (doc, dt, dn) {
-		var me = this;
-		this.frm.toggle_enable('year_start_date', doc.__islocal)
-		this.frm.toggle_enable('year_end_date', doc.__islocal)
+	refresh: function (frm) {
+		let doc = frm.doc;
+		frm.toggle_enable('year_start_date', doc.__islocal);
+		frm.toggle_enable('year_end_date', doc.__islocal);
 
 		if (!doc.__islocal && (doc.name != frappe.sys_defaults.fiscal_year)) {
-			this.frm.add_custom_button(__("Default"),
-				this.frm.cscript.set_as_default, "fa fa-star");
-			this.frm.set_intro(__("To set this Fiscal Year as Default, click on 'Set as Default'"));
+			frm.add_custom_button(__("Set as Default"), () => frm.events.set_as_default(frm));
+			frm.set_intro(__("To set this Fiscal Year as Default, click on 'Set as Default'"));
 		} else {
-			this.frm.set_intro("");
+			frm.set_intro("");
 		}
 	},
-	set_as_default: function() {
-		return frappe.call({
-			doc: cur_frm.doc,
-			method: "set_as_default"
-		});
+	set_as_default: function(frm) {
+		return frm.call('set_as_default');
 	},
-	year_start_date: function(doc, dt, dn) {
-		var me = this;
-
-		var year_end_date =
-			frappe.datetime.add_days(frappe.datetime.add_months(this.frm.doc.year_start_date, 12), -1);
-		this.frm.set_value("year_end_date", year_end_date);
+	year_start_date: function(frm) {
+		let year_end_date =
+			frappe.datetime.add_days(frappe.datetime.add_months(frm.doc.year_start_date, 12), -1);
+		frm.set_value("year_end_date", year_end_date);
 	},
 });
diff --git a/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js b/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js
index 7b489de..569f008 100644
--- a/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js
+++ b/erpnext/accounts/doctype/monthly_distribution/monthly_distribution.js
@@ -1,16 +1,16 @@
 // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
 
-cur_frm.cscript.onload = function(doc,cdt,cdn){
-	if(doc.__islocal){
-		var callback1 = function(r,rt){
-			refresh_field('percentages');
+frappe.ui.form.on('Monthly Distribution', {
+	onload(frm) {
+		if(frm.doc.__islocal) {
+			return frm.call('get_months').then(() => {
+				frm.refresh_field('percentages');
+			});
 		}
+	},
 
-		return $c('runserverobj', {'method':'get_months', 'docs':doc}, callback1);
+	refresh(frm) {
+		frm.toggle_display('distribution_id', frm.doc.__islocal);
 	}
-}
-
-cur_frm.cscript.refresh = function(doc,cdt,cdn){
-	cur_frm.toggle_display('distribution_id', doc.__islocal);
-}
+});
diff --git a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js
index e1fe5a1..8f09bc3 100644
--- a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js
+++ b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js
@@ -1,6 +1,10 @@
-cur_frm.cscript.refresh = function(doc, dt, dn){
-	if(!doc.__islocal){
-		var df = frappe.meta.get_docfield(doc.doctype, "payment_gateway", doc.name);
-		df.read_only = 1;
+// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
+// License: GNU General Public License v3. See license.txt
+
+frappe.ui.form.on('Payment Gateway Account', {
+	refresh(frm) {
+		if(!frm.doc.__islocal) {
+			frm.set_df_property('payment_gateway', 'read_only', 1);
+		}
 	}
-}
\ No newline at end of file
+});
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js
index e5b6336..c92b58b 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js
@@ -1,108 +1,6 @@
 // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
 
-frappe.ui.form.on("Pricing Rule", "refresh", function(frm) {
-	var help_content =
-		`<table class="table table-bordered" style="background-color: #f9f9f9;">
-			<tr><td>
-				<h4>
-					<i class="fa fa-hand-right"></i>
-					${__('Notes')}
-				</h4>
-				<ul>
-					<li>
-						${__("Pricing Rule is made to overwrite Price List / define discount percentage, based on some criteria.")}
-					</li>
-					<li>
-						${__("If selected Pricing Rule is made for 'Rate', it will overwrite Price List. Pricing Rule rate is the final rate, so no further discount should be applied. Hence, in transactions like Sales Order, Purchase Order etc, it will be fetched in 'Rate' field, rather than 'Price List Rate' field.")}
-					</li>
-					<li>
-						${__('Discount Percentage can be applied either against a Price List or for all Price List.')}
-					</li>
-					<li>
-						${__('To not apply Pricing Rule in a particular transaction, all applicable Pricing Rules should be disabled.')}
-					</li>
-				</ul>
-			</td></tr>
-			<tr><td>
-				<h4><i class="fa fa-question-sign"></i>
-					${__('How Pricing Rule is applied?')}
-				</h4>
-				<ol>
-					<li>
-						${__("Pricing Rule is first selected based on 'Apply On' field, which can be Item, Item Group or Brand.")}
-					</li>
-					<li>
-						${__("Then Pricing Rules are filtered out based on Customer, Customer Group, Territory, Supplier, Supplier Group, Campaign, Sales Partner etc.")}
-					</li>
-					<li>
-						${__('Pricing Rules are further filtered based on quantity.')}
-					</li>
-					<li>
-						${__('If two or more Pricing Rules are found based on the above conditions, Priority is applied. Priority is a number between 0 to 20 while default value is zero (blank). Higher number means it will take precedence if there are multiple Pricing Rules with same conditions.')}
-					</li>
-					<li>
-						${__('Even if there are multiple Pricing Rules with highest priority, then following internal priorities are applied:')}
-						<ul>
-							<li>
-								${__('Item Code > Item Group > Brand')}
-							</li>
-							<li>
-								${__('Customer > Customer Group > Territory')}
-							</li>
-							<li>
-								${__('Supplier > Supplier Group')}
-							</li>
-						</ul>
-					</li>
-					<li>
-						${__('If multiple Pricing Rules continue to prevail, users are asked to set Priority manually to resolve conflict.')}
-					</li>
-				</ol>
-			</td></tr>
-		</table>`;
-
-	set_field_options("pricing_rule_help", help_content);
-
-	cur_frm.cscript.set_options_for_applicable_for();
-});
-
-cur_frm.cscript.set_options_for_applicable_for = function() {
-	var options = [""];
-	var applicable_for = cur_frm.doc.applicable_for;
-
-	if(cur_frm.doc.selling) {
-		options = $.merge(options, ["Customer", "Customer Group", "Territory", "Sales Partner", "Campaign"]);
-	}
-	if(cur_frm.doc.buying) {
-		$.merge(options, ["Supplier", "Supplier Group"]);
-	}
-
-	set_field_options("applicable_for", options.join("\n"));
-
-	if(!in_list(options, applicable_for)) applicable_for = null;
-	cur_frm.set_value("applicable_for", applicable_for)
-}
-
-cur_frm.cscript.selling = function() {
-	cur_frm.cscript.set_options_for_applicable_for();
-}
-
-cur_frm.cscript.buying = function() {
-	cur_frm.cscript.set_options_for_applicable_for();
-}
-
-//Dynamically change the description based on type of margin
-cur_frm.cscript.margin_type = function(doc){
-	cur_frm.set_df_property('margin_rate_or_amount', 'description', doc.margin_type=='Percentage'?'In Percentage %':'In Amount')
-}
-
-frappe.ui.form.on('Pricing Rule', 'rate_or_discount', function(frm){
-	if(frm.doc.rate_or_discount == 'Rate') {
-		frm.set_value('for_price_list', "")
-	}
-})
-
 frappe.ui.form.on('Pricing Rule', {
 	setup: function(frm) {
 		frm.fields_dict["for_price_list"].get_query = function(doc){
@@ -199,7 +97,7 @@
 				</td></tr>
 			</table>`;
 
-		set_field_options("pricing_rule_help", help_content);
+		frm.set_df_property('pricing_rule_help', 'options', help_content);
 		frm.events.set_options_for_applicable_for(frm);
 		frm.trigger("toggle_reqd_apply_on");
 	},
@@ -256,5 +154,4 @@
 		if(!in_list(options, applicable_for)) applicable_for = null;
 		frm.set_value("applicable_for", applicable_for);
 	}
-
 });
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 47d2056..85f2804 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -24,7 +24,8 @@
 doctype_js = {
 	"Communication": "public/js/communication.js",
 	"Event": "public/js/event.js",
-	"Website Theme": "public/js/website_theme.js"
+	"Website Theme": "public/js/website_theme.js",
+	"Newsletter": "public/js/newsletter.js"
 }
 
 welcome_email = "erpnext.setup.utils.welcome_email"
diff --git a/erpnext/public/js/newsletter.js b/erpnext/public/js/newsletter.js
new file mode 100644
index 0000000..3a4dbf8
--- /dev/null
+++ b/erpnext/public/js/newsletter.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
+// License: GNU General Public License v3. See license.txt
+
+frappe.ui.form.on('Newsletter', {
+	refresh() {
+		erpnext.toggle_naming_series();
+	}
+});