@@ -253,13 +253,21 @@ frappe.ui.Page = Class.extend({ | |||||
add_inner_button: function(label, action, group) { | add_inner_button: function(label, action, group) { | ||||
let _action = function() { | let _action = function() { | ||||
let btn = $(this); | let btn = $(this); | ||||
let promise = action(); | |||||
if (promise && promise.then) { | |||||
let _ret = action(); | |||||
if (_ret && _ret.then) { | |||||
// returns a promise | |||||
btn.attr('disabled', true); | btn.attr('disabled', true); | ||||
promise.then(() => { | |||||
_ret.then(() => { | |||||
btn.attr('disabled', false); | btn.attr('disabled', false); | ||||
}) | }) | ||||
} | } | ||||
if (_ret && _ret.always) { | |||||
// returns frappe.call ($.ajax) | |||||
btn.attr('disabled', true); | |||||
_ret.always(() => { | |||||
btn.attr('disabled', false); | |||||
}); | |||||
} | |||||
} | } | ||||
if(group) { | if(group) { | ||||
var $group = this.get_inner_group_button(group); | var $group = this.get_inner_group_button(group); | ||||
@@ -20,7 +20,6 @@ frappe.provide('frappe.ui.form'); | |||||
frappe.ui.form.Controller = Class.extend({ | frappe.ui.form.Controller = Class.extend({ | ||||
init: function(opts) { | init: function(opts) { | ||||
$.extend(this, opts); | $.extend(this, opts); | ||||
this.setup && this.setup(); | |||||
} | } | ||||
}); | }); | ||||
@@ -77,7 +76,6 @@ _f.Frm.prototype.check_doctype_conflict = function(docname) { | |||||
}; | }; | ||||
_f.Frm.prototype.setup = function() { | _f.Frm.prototype.setup = function() { | ||||
var me = this; | var me = this; | ||||
this.fields = []; | this.fields = []; | ||||
this.fields_dict = {}; | this.fields_dict = {}; | ||||
@@ -413,7 +411,9 @@ _f.Frm.prototype.refresh = function(docname) { | |||||
} | } | ||||
// do setup | // do setup | ||||
if(!this.setup_done) this.setup(); | |||||
if(!this.setup_done) { | |||||
this.setup(); | |||||
} | |||||
// load the record for the first time, if not loaded (call 'onload') | // load the record for the first time, if not loaded (call 'onload') | ||||
this.cscript.is_onload = false; | this.cscript.is_onload = false; | ||||
@@ -89,5 +89,13 @@ frappe.tests = { | |||||
return frappe.run_serially(tasks); | return frappe.run_serially(tasks); | ||||
}); | }); | ||||
}, | |||||
click_button: function(text) { | |||||
$(`.btn:contains("${text}"):visible`).click(); | |||||
return frappe.timeout(0.3); | |||||
}, | |||||
click_link: function(text) { | |||||
$(`a:contains("${text}"):visible`).click(); | |||||
return frappe.timeout(0.3); | |||||
} | } | ||||
}; | }; |