File size: 1,705 Bytes
eb67da4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
frappe.ui.form.ControlButton = frappe.ui.form.ControlData.extend({ can_write() { // should be always true in case of button return true; }, make_input: function() { var me = this; const btn_type = this.df.primary ? 'btn-primary': 'btn-default'; this.$input = $(`<button class="btn btn-xs ${btn_type}">`) .prependTo(me.input_area) .on("click", function() { me.onclick(); }); this.input = this.$input.get(0); this.set_input_attributes(); this.has_input = true; this.toggle_label(false); }, onclick: function() { if (this.frm && this.frm.doc) { if (this.frm.script_manager.has_handlers(this.df.fieldname, this.doctype)) { this.frm.script_manager.trigger(this.df.fieldname, this.doctype, this.docname); } else { if (this.df.options) { this.run_server_script(); } } } else if (this.df.click) { this.df.click(); } }, run_server_script: function() { // DEPRECATE var me = this; if(this.frm && this.frm.docname) { frappe.call({ method: "run_doc_method", args: {'docs': this.frm.doc, 'method': this.df.options }, btn: this.$input, callback: function(r) { if(!r.exc) { me.frm.refresh_fields(); } } }); } }, hide() { this.$input.hide(); }, set_input_areas: function() { this._super(); $(this.disp_area).removeClass().addClass("hide"); }, set_empty_description: function() { this.$wrapper.find(".help-box").empty().toggle(false); }, set_label: function(label) { if (label) { this.df.label = label; } label = (this.df.icon ? frappe.utils.icon(this.df.icon) : "") + __(this.df.label); $(this.label_span).html(" "); this.$input && this.$input.html(label); } }); |