This commit is contained in:
Anand Doshi 2014-06-05 18:05:37 +05:30
parent 1c3f931f61
commit de428f9967
2 changed files with 21 additions and 20 deletions

View file

@ -5,6 +5,7 @@ frappe.provide('frappe.utils');
frappe.utils = {
get_file_link: function(filename) {
filename = cstr(filename);
if(frappe.utils.is_url(filename)) {
return filename;
} else if(filename.indexOf("/")===-1) {
@ -14,7 +15,7 @@ frappe.utils = {
}
},
is_html: function(txt) {
if(txt.indexOf("<br>")==-1 && txt.indexOf("<p")==-1
if(txt.indexOf("<br>")==-1 && txt.indexOf("<p")==-1
&& txt.indexOf("<img")==-1 && txt.indexOf("<div")==-1) {
return false;
}
@ -95,7 +96,7 @@ frappe.utils = {
me.footnote_area = $('<div class="alert alert-info form-intro-area" style="margin-top: 20px;">')
.appendTo(wrapper);
}
if(txt) {
if(txt.search(/<p>/)==-1) txt = '<p>' + txt + '</p>';
me.footnote_area.html(txt);
@ -113,11 +114,11 @@ frappe.utils = {
return args;
},
get_url_from_dict: function(args) {
return $.map(args, function(val, key) {
if(val!==null)
return encodeURIComponent(key)+"="+encodeURIComponent(val);
else
return null;
return $.map(args, function(val, key) {
if(val!==null)
return encodeURIComponent(key)+"="+encodeURIComponent(val);
else
return null;
}).join("&") || "";
},
validate_type: function ( val, type ) {
@ -153,11 +154,11 @@ frappe.utils = {
},
guess_style: function(text, default_style) {
var style = default_style;
if(!text)
if(!text)
return style;
if(has_words(["Open", "Pending"], text)) {
style = "danger";
} else if(has_words(["Closed", "Finished", "Converted", "Completed", "Confirmed",
} else if(has_words(["Closed", "Finished", "Converted", "Completed", "Confirmed",
"Approved", "Yes", "Active"], text)) {
style = "success";
} else if(has_words(["Submitted"], text)) {
@ -165,7 +166,7 @@ frappe.utils = {
}
return style;
},
sort: function(list, key, compare_type, reverse) {
if(list.length < 2)
return list;
@ -178,14 +179,14 @@ frappe.utils = {
return flt(a[key]) - flt(b[key]);
}
};
if(!compare_type)
compare_type = typeof list[0][key]==="string" ? "string" : "number";
list.sort(sort_fn[compare_type]);
if(reverse) { list.reverse(); }
return list;
},
unique: function(list) {
@ -199,7 +200,7 @@ frappe.utils = {
}
return arr;
},
dict: function(keys,values) {
// make dictionaries from keys and values
var out = [];
@ -212,17 +213,17 @@ frappe.utils = {
});
return out;
},
sum: function(list) {
return list.reduce(function(previous_value, current_value) { return flt(previous_value) + flt(current_value); }, 0.0);
},
resize_image: function(reader, callback, max_width, max_height) {
var tempImg = new Image();
if(!max_width) max_width = 600;
if(!max_height) max_height = 400;
tempImg.src = reader.result;
tempImg.onload = function() {
var tempW = tempImg.width;
var tempH = tempImg.height;

View file

@ -27,7 +27,7 @@ def get_report_doc(report_name):
def get_script(report_name):
report = get_report_doc(report_name)
module = frappe.db.get_value("DocType", report.ref_doctype, "module")
module = report.module or frappe.db.get_value("DocType", report.ref_doctype, "module")
module_path = get_module_path(module)
report_folder = os.path.join(module_path, "report", scrub(report.name))
script_path = os.path.join(report_folder, scrub(report.name) + ".js")
@ -71,7 +71,7 @@ def run(report_name, filters=()):
result = [list(t) for t in frappe.db.sql(report.query, filters)]
columns = [c[0] for c in frappe.db.get_description()]
else:
module = frappe.db.get_value("DocType", report.ref_doctype, "module")
module = report.module or frappe.db.get_value("DocType", report.ref_doctype, "module")
if report.is_standard=="Yes":
method_name = frappe.local.module_app[scrub(module)] + "." + scrub(module) \
+ ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute"