{"size": 1085, "ext": "js", "max_stars_repo_path": "twilio_integration/public/js/voice_call_settings.js", "max_stars_repo_name": "leela/twilio-integration", "max_stars_repo_stars_event_min_datetime": "2020-10-08T18:19:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T01:43:55.000Z", "max_issues_repo_path": "twilio_integration/public/js/voice_call_settings.js", "max_issues_repo_name": "leela/twilio-integration", "max_issues_repo_issues_event_min_datetime": "2020-11-16T03:59:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T16:28:17.000Z", "max_forks_repo_path": "twilio_integration/public/js/voice_call_settings.js", "max_forks_repo_name": "leela/twilio-integration", "max_forks_repo_forks_event_min_datetime": "2020-11-02T08:19:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T07:15:47.000Z"}
{"max_stars_count": 36, "max_issues_count": 12, "max_forks_count": 39, "avg_line_length": 31.0, "max_line_length": 124, "alphanum_fraction": 0.6470046083}

frappe.ui.form.on('Voice Call Settings', {
	onload: function(frm) {
		if (!frappe.user_roles.includes('System Manager')){
			frm.set_value('user', frappe.session.user)
		}
	},
	refresh: function(frm) {
		frappe.call({
			method: "twilio_integration.twilio_integration.api.get_twilio_phone_numbers",
			callback: function(resp) {
				if (resp.message.length) {
					frm.set_df_property('twilio_number', 'options', resp.message);
					frm.refresh_field('twilio_number');
				}
				else {
					frappe.show_alert({
						message:__('Voice settings rely on Twilio settings. Please make sure that Twilio settings are configured & enabled.'),
						indicator:'red'
					}, 6);
				}
			}
		});
	},
	user: function(frm) {
		frappe.db.exists('Voice Call Settings', frm.doc.user).then( exists => {
			if (frm.doc.user && exists) {
				var doc_url = `/desk#Form/${frm.doc.doctype}/${frm.doc.user}`;
				var link_html = `<a href="${doc_url}">here</a>`;
				frappe.msgprint(__('Voice call settings already exist for user {0}. You can edit them {1}', [frm.doc.user, link_html]));
			}
		});
	}
});
