;
}
function renderSelect() {
return ;
}
function renderOpBar() {
if (this.is_remote) {
return
{svg_send}{translate('Receive')}
{svg_add_folder}
{svg_trash}
;
}
return
{svg_add_folder}
{svg_trash}
{translate('Send')}{svg_send}
;
}
function get_updated() {
this.table.sortRows(false);
if (this.fd && this.fd.path) this.select_dir.value = this.fd.path;
}
function renderTable() {
var fd = this.fd;
var entries = fd.entries || [];
var table = this.table;
if (!table || !table.sortBy) {
entries.sort(this.foldersFirst);
}
var me = this;
var path = fd.path;
if (path != "/" && path) {
entries = [{ name: "..", type: 1 }].concat(entries);
}
var rows = entries.map(function(e) { return me.renderRow(e); });
var id = (this.is_remote ? "remote" : "local") + "-folder-view";
return
{translate('Name')}
{translate('Modified')}
{translate('Size')}
{rows}
{svg_checkmark}{translate('Show Hidden Files')}
;
}
function joinPath(name) {
var path = this.fd.path;
if (path == "/") {
if (this.sep() == "/") return this.sep() + name;
else return name;
}
return path + (path[path.length - 1] == this.sep() ? "" : this.sep()) + name;
}
function attached() {
var me = this;
this.table.onRowDoubleClick = function (row) {
var type = row[0].attributes["type"];
if (type > 3) return;
var name = row[1].text;
var path = name == ".." ? getParentPath(me.is_remote, me.fd.path) : me.joinPath(name);
me.table.resetCurrent();
me.goto(path, true);
}
this.get_updated();
}
function goto(path, push) {
if (!path) return;
if (this.sep() == "\\" && path.length == 2) { // windows drive
path += "\\";
}
if (push) this.pushHistory();
if (this.is_remote) {
handler.read_remote_dir(path, this.show_hidden);
} else {
var fd = handler.read_dir(path, this.show_hidden);
this.refresh({ fd: fd });
}
}
function refresh(data) {
if (!data.fd || !data.fd.path) return;
if (this.is_remote && !remote_home_dir) {
remote_home_dir = data.fd.path;
}
this.update(data);
var me = this;
self.timer(1ms, function() { me.get_updated(); });
}
function renderRow(entry) {
var path;
if (this.is_remote) {
path = handler.get_icon_path(entry.type, getExt(entry.name));
} else {
path = this.joinPath(entry.name);
}
var tm = entry.time ? new Date(entry.time.toFloat() * 1000.).toLocaleString() : 0;
return
{entry.name}
{tm || ""}
{getSize(entry.type, entry.size)}
;
}
event click $(#switch-hidden) {
this.show_hidden = !this.show_hidden;
this.refreshDir();
}
event click $(.goup) () {
var path = this.fd.path;
if (!path || path == "/") return;
path = getParentPath(this.is_remote, path);
this.goto(path, true);
}
event click $(.goback) () {
var path = this.history.pop();
if (!path) return;
this.goto(path, false);
}
event click $(.trash) () {
var rows = this.getCurrentRows();
if (!rows || rows.length == 0) return;
var delete_dirs = new Array();
for (var i = 0; i < rows.length; ++i) {
var row = rows[i];
var path = row[0];
var type = row[1];
var new_history = [];
for (var j = 0; j < this.history.length; ++j) {
var h = this.history[j];
if ((h + this.sep()).indexOf(path + this.sep()) == -1) new_history.push(h);
}
this.history = new_history;
if (type == 1) {
file_transfer.job_table.addDelDir(path, this.is_remote);
} else {
file_transfer.job_table.addDelFile(path, this.is_remote);
}
}
file_transfer.job_table.confirmDeletePolling(this.is_remote);
}
event click $(.add-folder) () {
var me = this;
msgbox("custom", translate("Create Folder"), "
\
" + translate("Please enter the folder name") + ":
\
\
", "", function(res=null) {
if (!res) return;
if (!res.name) return;
var name = res.name.trim();
if (!name) return;
if (name.indexOf(me.sep()) >= 0) {
handler.msgbox("custom-error", "Create Folder", "Invalid folder name");
return;
}
var path = me.joinPath(name);
var id = handler.get_next_job_id();
handler.create_dir(id, path, me.is_remote);
create_dir_jobs[id] = { is_remote: me.is_remote, path: path };
});
}
function refreshDir() {
this.goto(this.fd.path, false);
}
event click $(.refresh) () {
this.refreshDir();
}
event click $(.home) () {
var path = this.is_remote ? remote_home_dir : handler.get_home_dir();
if (!path) return;
if (path == this.fd.path) return;
this.goto(path, true);
}
function getCurrentRow() {
var row = this.table.getCurrentRow();
if (!row) return;
var name = row[1].text;
if (!name || name == "..") return;
var type = row[0].attributes["type"];
return [this.joinPath(name), type];
}
function getCurrentRows() {
var rows = this.table.getCurrentRows();
if (!rows || rows.length== 0) return;
var records = new Array();
for (var i = 0; i < rows.length; ++i) {
var name = rows[i][1].text;
if (!name || name == "..") continue;
var type = rows[i][0].attributes["type"];
records.push([this.joinPath(name), type]);
}
return records;
}
event click $(.send) () {
var rows = this.getCurrentRows();
if (!rows || rows.length == 0) return;
for (var i = 0; i < rows.length; ++i) {
file_transfer.job_table.send(rows[i][0], this.is_remote);
}
}
event change $(.select-dir) (_, el) {
var x = getTime() - last_key_time;
if (x < 1000) return;
if (this.fd.path != el.value) {
this.goto(el.value, true);
}
}
event keydown $(.select-dir) (evt, me) {
if (isEnterKey(evt)) {
this.goto(me.value, true);
}
}
function pushHistory() {
var path = this.fd.path;
if (!path) return;
if (path != this.history[this.history.length - 1]) this.history.push(path);
}
}
var file_transfer;
class FileTransfer: Reactor.Component {
function this() {
file_transfer = this;
}
function render() {
return