Last active
October 7, 2019 15:56
-
-
Save monroy95/82b2ffc8bd5f2a48507f07f884d5635b to your computer and use it in GitHub Desktop.
WIP snippets frappe js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and | |
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the | |
// same ids are connected. | |
// Example: | |
// "Print to console": { | |
// "prefix": "log", | |
// "body": [ | |
// "console.log('$1');", | |
// "$2" | |
// ], | |
// "description": "Log output to console" | |
// } | |
"Frappe Call": { | |
"prefix": "frappe_call", | |
"body": [ | |
"frappe.call({", | |
"\tmethod: 'factura_electronica.api.guardar_pdf_servidor ',", | |
"\targs: {", | |
"\t\tnombre_archivo: frm.doc.name,", | |
"\t\tcae_de_factura_electronica: frm.doc.cae_factura_electronica", | |
"\t},", | |
"\tcallback: function () {", | |
"\t\tfrm.reload_doc();", | |
"\t}", | |
"});" | |
], | |
"description": "Utilizado para hacer llamados AJAX al backend python" | |
}, | |
"Frappe Alert": { | |
"prefix": "frappe_alert", | |
"body": [ | |
"frappe.show_alert({", | |
"\tindicator: 'green',", | |
"\tmessage: __('$1')", | |
"});" | |
], | |
"description": "Mensaje de alerta" | |
}, | |
"Form Doctype": { | |
"prefix": "form_doctype", | |
"body": [ | |
"frappe.ui.form.on(doctype, {", | |
"\tevent1() {", | |
"\t\t// handle event 1", | |
"\t},", | |
"\tevent2() {", | |
"\t\t// handle event 2", | |
"\t}", | |
"})" | |
], | |
"description": "Estructura similir a cuando se crear un neuvo doctype" | |
}, | |
// Botones | |
"Boton Simple": { | |
"prefix": "frappe_btn_simple", | |
"body": [ | |
"frm.add_custom_button(__('Button Name'), () => {", | |
"\t// Your code", | |
"});" | |
], | |
"description": "Boton Simple" | |
}, | |
"Boton en grupo": { | |
"prefix": "frappe_btn_group", | |
"body": [ | |
"frm.add_custom_button('Closed', () => {", | |
"\tfrm.doc.status = 'Closed'", | |
"}, 'Set Status');" | |
], | |
"description": "Agrega un boton customizado en el dropdown de la parte superior derecha" | |
}, | |
"Eliminar boton customizado": { | |
"prefix": "frappe_delete_btn", | |
"body": "frm.clear_custom_button('Open Reference form');", | |
"description": "Elimina un especifico boton customizado que se encuentren en el dt" | |
}, | |
"Eliminar grupo de botones customizados": { | |
"prefix": "frappe_delete_btn_group", | |
"body": "frm.clear_custom_button('Closed', 'Set Status');", | |
"description": "Elimina botones personalizados de un grupo" | |
}, | |
"Eliminar botones customizados": { | |
"prefix": "frappe_delete_all_btns", | |
"body": "frm.clear_custom_buttons();", | |
"description": "Elimina todos los botones customizados que se encuentren en el doctype" | |
}, | |
"Child Table event for field": { | |
"prefix": "frappe_child_field", | |
"body": [ | |
"frappe.ui.form.on('Quotation Item', {", | |
"\t// cdt is Child DocType name i.e Quotation Item", | |
"\t// cdn is the row name for e.g bbfcb8da6a", | |
"\titem_code(frm, cdt, cdn) {", | |
"\t\tlet row = frappe.get_doc(cdt, cdn);", | |
"\t}", | |
"})" | |
] | |
}, | |
// Asignar valores a campos | |
"Asignar valor a campo": { | |
"prefix": "frappe_set_value", | |
"body": [ | |
"// set a single value", | |
"frm.set_value('FIELD-NAME', 'FIELD-VALUE')" | |
], | |
"description": "Establece un valor a un campo especifico" | |
}, | |
"Asignar valor a DT": { | |
"prefix": "frappe_set_value_form", | |
"body": [ | |
"frm.set_value({", | |
"\tstatus: 'Open',", | |
"\tdescription: 'New description'", | |
"})" | |
], | |
"description": "Asigna estado y descripcion al doctype que este trabajando" | |
}, | |
"Asignar valor a campo con trigger": { | |
"prefix": "frappe_set_value_trigger", | |
"body": [ | |
"frm.set_value('FIELD-NAME', 'FIELD-VALUE')", | |
".then(() => {", | |
"\t// do something after value is set", | |
"})" | |
], | |
"description": "Permite asignar un valor a un especifico campo, con la diferencia que tiene un trgger despues de la asginacion" | |
}, | |
"Cambiar tipo de campo": { | |
"prefix": "frappe_change_fieldtype", | |
"body": "frm.set_df_property('description', 'fieldtype', 'Text');", | |
"description": "Cambia el tipo de campo, fieldname-fieldtype-type" | |
}, | |
"Asingnar valores a un campo select": { | |
"prefix": "frappe_set_vals_select", | |
"body": "frm.set_df_property('status', 'options', ['Open', 'Closed'])", | |
"description": "Permite asignar valores a un campo select, el ultimo campo debe ser un array" | |
}, | |
"Establecer campo como obligatorio": { | |
"prefix": "frappe_set_mandatory", | |
"body": "frm.set_df_property('[fieldname]', 'reqd', 1)", | |
"description": "Permite establecer un campo como obligatorio" | |
}, | |
"Establecer como lectura o escritura": { | |
"prefix": "frappe_set_readonly", | |
"body": "frm.set_df_property('[fieldname]', 'read_only', 1)", | |
"description": "Permite establecer un campo como solo lectura = 0 o solo escritura = 1" | |
}, | |
// Triggers | |
"Refresh Dt": { | |
"prefix": "frappe_refresh", | |
"body": "frm.refresh();", | |
"description": "Refresca el form con los ultimos cambios del servidor (retorna una promesa)" | |
}, | |
"Guardar Dt": { | |
"prefix": "frappe_save", | |
"body": "frm.save();", | |
"description": "Guarda el doctype que este trabajando (retorna una promesa)" | |
}, | |
"Validar Dt": { | |
"prefix": "frappe_submit", | |
"body": "frm.save('Submit');", | |
"description": "Valida el doctype que este trabajando (retorna una promesa)" | |
}, | |
"Cancelar Dt": { | |
"prefix": "frappe_calcel", | |
"body": "frm.save('Cancel');", | |
"description": "Cancela el doctype que este trabajando (retorna una promesa)" | |
}, | |
"Actualizar Dt": { | |
"prefix": "frappe_update", | |
"body": "frm.save('Update');", | |
"description": "Actualizar el doctype que este trabajando despues de ejecutar submit (retorna una promesa)" | |
}, | |
"habilitar Dt": { | |
"prefix": "frappe_enable", | |
"body": "frm.enable_save();", | |
"description": "habilita el boton guardar en el doctype" | |
}, | |
"Deshabilitar Dt": { | |
"prefix": "frappe_disable", | |
"body": "frm.disable_save();", | |
"description": "Deshabilita el boton guardar en el doctype" | |
}, | |
"Modal Email": { | |
"prefix": "frappe_dialog_email", | |
"body": "frm.email_doc();", | |
"description": "Abre un nuevo modal para Email" | |
}, | |
"Modal Email 2": { | |
"prefix": "frappe_dialog_email_2", | |
"body": "frm.email_doc(`Hello ${frm.doc.customer_name}`);", | |
"description": "Abre un nuevo modal para Email con cualquier mensaje" | |
}, | |
"Recargar Dt": { | |
"prefix": "frappe_reload", | |
"body": "frm.reload_doc();", | |
"description": "Recarga el doctype con los ultimos cambios del server y tambien ejecuta frappe.refresh()" | |
}, | |
"Recargar Campo": { | |
"prefix": "frappe_refresh_field", | |
"body": "frm.refresh_field('FIELD-NAME');", | |
"description": "Actualiza el campo especificado con el ultimo valor que le corresponda" | |
}, | |
"Comprobar cambios sin guardar": { | |
"prefix": "frappe_verify_save", | |
"body": [ | |
"if (frm.is_dirty()) {", | |
"\tfrappe.show_alert('Please save form before attaching a file')", | |
"}" | |
], | |
"description": "Verificar si hay cambios sin guardar, si es asi mostrara un alerta" | |
}, | |
"Comprobar Dt sin guardar": { | |
"prefix": "frappe_is_not_new", | |
"body": [ | |
"// add custom button only if form is not new", | |
"if (!frm.is_new()) {", | |
"\tfrm.add_custom_button('Click me', () => console.log('Clicked custom button'))", | |
"}" | |
], | |
"description": "Comprueba si el formulario es nuevo y aún no se ha guardado." | |
}, | |
"Agregar introduccion al Dt": { | |
"prefix": "frappe_set_intro", | |
"body": [ | |
"if (!frm.doc.description) {", | |
"\tfrm.set_intro('Please set the value of description');", | |
"}" | |
], | |
"description": "Coloqua texto de introducción en la parte superior del formulario." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment