@@ -0,0 +1,15 @@ | |||||
frappe.ui.form.on("Version", "refresh", function(frm) { | |||||
frm.add_custom_button("Restore", function() { | |||||
frappe.call({ | |||||
method:"frappe.core.doctype.version.version.restore", | |||||
args: { | |||||
version: frm.doc.name | |||||
}, | |||||
callback: function(r) { | |||||
if(!r.exc) { | |||||
msgprint("Version Restored."); | |||||
} | |||||
} | |||||
}) | |||||
}) | |||||
}) |
@@ -9,4 +9,22 @@ import frappe, json | |||||
class DocType: | class DocType: | ||||
def __init__(self, d, dl): | def __init__(self, d, dl): | ||||
self.doc, self.doclist = d, dl | self.doc, self.doclist = d, dl | ||||
@frappe.whitelist() | |||||
def restore(version): | |||||
if not "System Manager" in frappe.get_roles(): | |||||
raise frappe.PermissionError | |||||
version = frappe.doc("Version", version) | |||||
doclist = json.loads(version.doclist_json) | |||||
# check if renamed | |||||
if doclist[0].get("name") != version.docname: | |||||
doclist[0]["name"] = version.docname | |||||
for d in doclist[1:]: | |||||
d["parent"] = version.docname | |||||
doclist[0]["modified"] = frappe.conn.get_value(version.ref_doctype, version.docname, "modified") | |||||
# overwrite | |||||
frappe.bean(doclist).save() |
@@ -205,6 +205,8 @@ frappe.ui.form.Toolbar = Class.extend({ | |||||
current = this.appframe.get_title_right_text(), | current = this.appframe.get_title_right_text(), | ||||
status = null; | status = null; | ||||
this.appframe.clear_primary_action(); | |||||
if(this.can_submit()) { | if(this.can_submit()) { | ||||
status = "Submit"; | status = "Submit"; | ||||
} else if(this.can_save()) { | } else if(this.can_save()) { | ||||
@@ -77,6 +77,13 @@ frappe.ui.AppFrame = Class.extend({ | |||||
return this.parent.find(".titlebar-item.text-right").attr("data-text"); | return this.parent.find(".titlebar-item.text-right").attr("data-text"); | ||||
}, | }, | ||||
clear_primary_action: function() { | |||||
if(this.primary_dropdown) { | |||||
this.primary_dropdown.remove(); | |||||
this.primary_dropdown = null; | |||||
} | |||||
}, | |||||
add_primary_action: function(label, click, icon) { | add_primary_action: function(label, click, icon) { | ||||
if(!this.primary_dropdown) { | if(!this.primary_dropdown) { | ||||
if(!this.primary_action) { | if(!this.primary_action) { | ||||
@@ -792,7 +792,7 @@ _f.Frm.prototype.add_custom_button = function(label, fn, icon) { | |||||
return this.appframe.add_primary_action(label, fn, icon || "icon-arrow-right"); | return this.appframe.add_primary_action(label, fn, icon || "icon-arrow-right"); | ||||
} | } | ||||
_f.Frm.prototype.clear_custom_buttons = function() { | _f.Frm.prototype.clear_custom_buttons = function() { | ||||
this.toolbar.refresh() | |||||
this.toolbar.clear_primary_action() | |||||
} | } | ||||
_f.Frm.prototype.add_fetch = function(link_field, src_field, tar_field) { | _f.Frm.prototype.add_fetch = function(link_field, src_field, tar_field) { | ||||