Download reports in mobile
This commit is contained in:
parent
b5c449f860
commit
1898f5f8e1
2 changed files with 37 additions and 5 deletions
|
|
@ -1,3 +1,5 @@
|
|||
frappe.provide('frappe.utils');
|
||||
|
||||
function get_url_arg(name) {
|
||||
return get_query_params()[name] || "";
|
||||
}
|
||||
|
|
@ -36,8 +38,29 @@ function get_query_params(query_string) {
|
|||
return query_params;
|
||||
}
|
||||
|
||||
function make_query_string(obj) {
|
||||
var query_params = [];
|
||||
$.each(obj, function(k, v) { query_params.push(encodeURIComponent(k) + "=" + encodeURIComponent(v)); });
|
||||
return "?" + query_params.join("&");
|
||||
function make_query_string(obj, encode=true) {
|
||||
let query_params = [];
|
||||
for (let key in obj) {
|
||||
let value = obj[key];
|
||||
if (value === undefined || value === '' || value === null) {
|
||||
continue;
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
|
||||
if (encode) {
|
||||
key = encodeURIComponent(key);
|
||||
value = encodeURIComponent(value);
|
||||
}
|
||||
|
||||
query_params.push(`${key}=${value}`);
|
||||
}
|
||||
return '?' + query_params.join('&');
|
||||
}
|
||||
|
||||
Object.assign(frappe.utils, {
|
||||
get_url_arg,
|
||||
get_query_params,
|
||||
make_query_string
|
||||
});
|
||||
|
|
@ -62,8 +62,17 @@ function $c_obj_csv(doc, method, arg) {
|
|||
open_url_post(frappe.request.url, args);
|
||||
}
|
||||
|
||||
// call a url as POST
|
||||
function open_url_post(URL, PARAMS, new_window) {
|
||||
if (window.cordova) {
|
||||
let url = URL + 'api/method/' + PARAMS.cmd + frappe.utils.make_query_string(PARAMS, false);
|
||||
window.location.href = url;
|
||||
} else {
|
||||
// call a url as POST
|
||||
_open_url_post(URL, PARAMS, new_window);
|
||||
}
|
||||
}
|
||||
|
||||
function _open_url_post(URL, PARAMS, new_window) {
|
||||
var temp=document.createElement("form");
|
||||
temp.action=URL;
|
||||
temp.method="POST";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue