[fix] rename tool #2861

This commit is contained in:
Rushabh Mehta 2015-03-02 15:05:36 +05:30
parent 905f8328ab
commit 00e3b26597
3 changed files with 32 additions and 51 deletions

View File

@ -1,50 +1,30 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
cur_frm.cscript.refresh = function(doc) {
return frappe.call({
method: "erpnext.utilities.doctype.rename_tool.rename_tool.get_doctypes",
callback: function(r) {
cur_frm.set_df_property("select_doctype", "options", r.message);
cur_frm.cscript.setup_upload();
}
});
}
cur_frm.cscript.select_doctype = function() {
cur_frm.cscript.setup_upload();
}
cur_frm.cscript.setup_upload = function() {
var me = this;
var $wrapper = $(cur_frm.fields_dict.upload_html.wrapper).empty()
.html("<hr><div class='alert alert-warning'>" +
__("Upload a .csv file with two columns: the old name and the new name. Max 500 rows.")
+ "</div>");
var $log = $(cur_frm.fields_dict.rename_log.wrapper).empty();
// upload
frappe.upload.make({
parent: $wrapper,
args: {
method: 'erpnext.utilities.doctype.rename_tool.rename_tool.upload',
select_doctype: cur_frm.doc.select_doctype
},
sample_url: "e.g. http://example.com/somefile.csv",
callback: function(attachment, r) {
$log.empty().html("<hr>");
$.each(r.message, function(i, v) {
$("<div>" + v + "</div>").appendTo($log);
frappe.ui.form.on("Rename Tool", {
onload: function(frm) {
return frappe.call({
method: "erpnext.utilities.doctype.rename_tool.rename_tool.get_doctypes",
callback: function(r) {
frm.set_df_property("select_doctype", "options", r.message);
frm.cscript.setup_upload();
}
});
},
refresh: function(frm) {
frm.disable_save();
frm.page.set_primary_action(__("Rename"), function() {
frm.get_field("rename_log").$wrapper.html("<p>Renaming...</p>");
frappe.call({
method: "erpnext.utilities.doctype.rename_tool.rename_tool.upload",
args: {
select_doctype: frm.doc.select_doctype
},
callback: function(r) {
frm.get_field("rename_log").$wrapper.html(r.message);
}
});
}
});
// rename button
$wrapper.find('form input[type="submit"]')
.click(function() {
$log.html("Working...");
})
.addClass("btn-primary")
.attr('value', 'Upload and Rename')
}
});
}
})

View File

@ -13,9 +13,10 @@
"permlevel": 0
},
{
"fieldname": "upload_html",
"fieldtype": "HTML",
"label": "Upload HTML",
"description": "Attach .csv file with two columns, one for the old name and one for the new name",
"fieldname": "file_to_rename",
"fieldtype": "Attach",
"label": "File to Rename",
"permlevel": 0
},
{
@ -31,7 +32,7 @@
"idx": 1,
"issingle": 1,
"max_attachments": 1,
"modified": "2015-02-05 05:11:44.714515",
"modified": "2015-03-02 02:35:34.129309",
"modified_by": "Administrator",
"module": "Utilities",
"name": "Rename Tool",

View File

@ -19,7 +19,7 @@ def get_doctypes():
@frappe.whitelist()
def upload(select_doctype=None, rows=None):
from frappe.utils.csvutils import read_csv_content_from_uploaded_file
from frappe.utils.csvutils import read_csv_content_from_attached_file
from frappe.model.rename_doc import rename_doc
if not select_doctype:
@ -29,7 +29,7 @@ def upload(select_doctype=None, rows=None):
raise frappe.PermissionError
if not rows:
rows = read_csv_content_from_uploaded_file()
rows = read_csv_content_from_attached_file(frappe.get_doc("Rename Tool", "Rename Tool"))
if not rows:
frappe.throw(_("Please select a valid csv file with data"))