DatasetControl.download() 수정, .current-row 수정

master
mjkhan21 4 months ago
parent 8976b5e96b
commit 29bf938974

@ -63,6 +63,7 @@
} }
.current-row {background-color:rgba(105, 108, 255, 0.16);} .current-row {background-color:rgba(105, 108, 255, 0.16);}
.current-row td:not(:last-child) {border-right: 1px solid white;}
.table th {font-size:1rem;} .table th {font-size:1rem;}

@ -200,6 +200,7 @@ function onError(xhr, options, error) {
if (xhr.readyState == 0) if (xhr.readyState == 0)
return dialog.alert("서버에 접근할 수 없습니다."); return dialog.alert("서버에 접근할 수 없습니다.");
try {
var resp = JSON.parse(xhr.responseText); var resp = JSON.parse(xhr.responseText);
if (resp.handler) if (resp.handler)
return eval(resp.handler); return eval(resp.handler);
@ -210,6 +211,9 @@ function onError(xhr, options, error) {
msgs = msgs.join("<br />"); msgs = msgs.join("<br />");
if (msgs) if (msgs)
dialog.alert(msgs); dialog.alert(msgs);
} catch (e) {
dialog.alert("요청을 처리하는 중 오류가 발생했습니다.");
}
} }
var ajax = { var ajax = {
@ -226,7 +230,7 @@ var ajax = {
} }
var success = options.success; var success = options.success;
options.success = function(resp) { options.success = function(resp, msg, xhr) {
if ("string" == typeof resp) if ("string" == typeof resp)
resp = trim(resp); resp = trim(resp);
@ -236,7 +240,7 @@ var ajax = {
debug("response", resp); debug("response", resp);
if (!resp.failed) if (!resp.failed)
return success(resp); return success(resp, msg, xhr);
dialog.alert({ dialog.alert({
title:resp.title, title:resp.title,

@ -1347,10 +1347,13 @@ class DatasetControl {
} }
download(type) { download(type) {
this.query.download = type || "xls"; let params = Object.assign({}, this.query);
let query = toQuery(this.query); params.download = type || "xls";
this.query.download = null;
document.location.href = this.urls.load + "?" + query; return download.get({
url: this.urls.load,
data: params
});
} }
setData(obj, option) { setData(obj, option) {
@ -1486,6 +1489,10 @@ class DatasetControl {
this.reload({prev: selected.length == this.dataset.length}); this.reload({prev: selected.length == this.dataset.length});
} }
selector(selector) {
return this.dataBinder().selector(selector);
}
querySelector(selector) { querySelector(selector) {
return this.dataBinder().querySelector(selector); return this.dataBinder().querySelector(selector);
} }

@ -1,19 +1,5 @@
function upload(options) { function createObjectURL(file) {
options.enctype = "multipart/form-data"; return (window.URL || window.webkitURL).createObjectURL(file);
options.processData = options.contentType = false;
var data = options.data,
formData = new FormData();
for (var key in data) {
var val = data[key];
if (!Array.isArray(val))
formData.append(key, val);
else {
for (var i = 0; i < val.length; ++i)
formData.append(key, val[i]);
}
}
options.data = formData;
ajax.post(options);
} }
function fileInput(conf) { function fileInput(conf) {
@ -55,7 +41,7 @@ function fileInput(conf) {
getURLs:function() { getURLs:function() {
try { try {
return obj.files.map(file => (window.URL || window.webkitURL).createObjectURL(file)); return obj.files.map(file => createObjectURL(file));
} catch (e) { } catch (e) {
return []; return [];
} }
@ -101,10 +87,59 @@ function uploadSupport(selector) {
for (var i = 0; i < length; ++i) { for (var i = 0; i < length; ++i) {
var file = files[i]; var file = files[i];
file.id = "file-" + new Date().getTime() + "-" + i; file.id = "file-" + new Date().getTime() + "-" + i;
file.url = (window.URL || window.webkitURL).createObjectURL(file); file.url = createObjectURL(file);
array.push(file); array.push(file);
} }
fileset.setData(array); fileset.setData(array);
}); });
return fileset; return fileset;
} }
var download = {
filename: (str) => {
if (str.indexOf("filename=") < 0)
return null;
let regexp = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/,
matches = regexp.exec(str);
return matches && matches[1] ? matches[1].replace(/['"]/g, "") : null;
},
_init: options => {
options.cache = false;
options.xhrFields = {responseType: "blob"};
options.success = (data, msg, xhr) => {
let disp = xhr.getResponseHeader("Content-Disposition"),
filename = download.filename(decodeURIComponent(disp)),
link = document.createElement("a");
link.href = createObjectURL(new Blob([data]));
link.download = filename;
link.click();
};
return options;
},
get: function(options) {
ajax.get(download._init(options));
},
post: function(options) {
ajax.post(download._init(options));
}
};
function upload(options) {
options.enctype = "multipart/form-data";
options.processData = options.contentType = false;
var data = options.data,
formData = new FormData();
for (var key in data) {
var val = data[key];
if (!Array.isArray(val))
formData.append(key, val);
else {
for (var i = 0; i < val.length; ++i)
formData.append(key, val[i]);
}
}
options.data = formData;
ajax.post(options);
}
Loading…
Cancel
Save