瀏覽代碼

fixed custom action issue, restore in versions

version-14
Rushabh Mehta 11 年之前
父節點
當前提交
d63fc463c1
共有 5 個檔案被更改,包括 44 行新增2 行删除
  1. +15
    -0
      frappe/core/doctype/version/version.js
  2. +19
    -1
      frappe/core/doctype/version/version.py
  3. +2
    -0
      frappe/public/js/frappe/form/toolbar.js
  4. +7
    -0
      frappe/public/js/frappe/ui/appframe.js
  5. +1
    -1
      frappe/public/js/legacy/form.js

+ 15
- 0
frappe/core/doctype/version/version.js 查看文件

@@ -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.");
}
}
})
})
})

+ 19
- 1
frappe/core/doctype/version/version.py 查看文件

@@ -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()

+ 2
- 0
frappe/public/js/frappe/form/toolbar.js 查看文件

@@ -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()) {


+ 7
- 0
frappe/public/js/frappe/ui/appframe.js 查看文件

@@ -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) {


+ 1
- 1
frappe/public/js/legacy/form.js 查看文件

@@ -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) {


Loading…
取消
儲存