mirror of
https://github.com/Studio-42/elFinder
synced 2026-06-08 12:37:09 +00:00
48576af671
* Refactor touch event binding in elfinder.js (#3762) for jquery 4.0 * Refactor name trimming in elFinder.resources.js (#3763) for jquery 4.0 * Replace jQuery methods with native JavaScript equivalents (#3764) for jquery 4.0 * Refactor command binding to use bind method (#3765) for jquery 4.0 * Refactor search input value handling and buttonset (#3766) for jquery 4.0 * Refactor function calls to use bind instead of proxy (#3767) for jquery 4.0 * Refactor text trimming method in parseUploadData (#3768) for jquery 4.0 * Fix mime trimming and whitespace handling (#3769) for jquery 4.0 * Refactor value trimming to use native trim method (#3772) for jquery 4.0 * Fix binding of 'make' method in mkfile.js (#3773) for jquery 4.0 * Fix binding of make function in mkdir command (#3774) for jquery 4.0 * Fix string trimming for translator names (#3775) for jquery 4.0 * Fix binding of mixin make function in edit.js (#3776) For jquery 4 * Refactor permission value trimming method (#3777) For jquery 4.0 * fix: to support jQuery 4.0.0 * update: use jQuery 4.0.0/jQueyUI 1.14.2 --------- Co-authored-by: Brian Stone <brianstone@hotmail.com.au>
101 lines
2.4 KiB
JavaScript
101 lines
2.4 KiB
JavaScript
/**
|
|
* @class elFinder command "archive"
|
|
* Archive selected files
|
|
*
|
|
* @author Dmitry (dio) Levashov
|
|
**/
|
|
elFinder.prototype.commands.archive = function() {
|
|
"use strict";
|
|
var self = this,
|
|
fm = self.fm,
|
|
mimes = [],
|
|
dfrd;
|
|
|
|
this.variants = [];
|
|
|
|
this.disableOnSearch = false;
|
|
|
|
this.nextAction = {};
|
|
|
|
/**
|
|
* Update mimes on open/reload
|
|
*
|
|
* @return void
|
|
**/
|
|
fm.bind('open reload', function() {
|
|
self.variants = [];
|
|
$.each((mimes = fm.option('archivers')['create'] || []), function(i, mime) {
|
|
self.variants.push([mime, fm.mime2kind(mime)]);
|
|
});
|
|
self.change();
|
|
});
|
|
|
|
this.getstate = function(select) {
|
|
var sel = this.files(select),
|
|
cnt = sel.length,
|
|
chk = (cnt && ! fm.isRoot(sel[0]) && (fm.file(sel[0].phash) || {}).write),
|
|
filter = function(files) {
|
|
var fres = true;
|
|
return $.grep(files, function(f) {
|
|
fres = fres && f.read && f.hash.indexOf(cwdId) === 0 ? true : false;
|
|
return fres;
|
|
});
|
|
},
|
|
cwdId;
|
|
|
|
if (chk && fm.searchStatus.state > 1) {
|
|
if (chk = (cnt === filter(sel).length)) {
|
|
cwdId = fm.cwd().volumeid;
|
|
}
|
|
}
|
|
|
|
return chk && !this._disabled && mimes.length && (cnt || (dfrd && dfrd.state() == 'pending')) ? 0 : -1;
|
|
};
|
|
|
|
this.exec = function(hashes, type) {
|
|
var files = this.files(hashes),
|
|
cnt = files.length,
|
|
mime = type || mimes[0],
|
|
cwd = fm.file(files[0].phash) || null,
|
|
error = ['errArchive', 'errPerm', 'errCreatingTempDir', 'errFtpDownloadFile', 'errFtpUploadFile', 'errFtpMkdir', 'errArchiveExec', 'errExtractExec', 'errRm'],
|
|
i, open;
|
|
|
|
dfrd = $.Deferred().fail(function(error) {
|
|
error && fm.error(error);
|
|
});
|
|
|
|
if (! (cnt && mimes.length && $.inArray(mime, mimes) !== -1)) {
|
|
return dfrd.reject();
|
|
}
|
|
|
|
if (!cwd.write) {
|
|
return dfrd.reject(error);
|
|
}
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
if (!files[i].read) {
|
|
return dfrd.reject(error);
|
|
}
|
|
}
|
|
|
|
self.mime = mime;
|
|
self.prefix = ((cnt > 1)? 'Archive' : files[0].name) + (fm.option('archivers')['createext']? '.' + fm.option('archivers')['createext'][mime] : '');
|
|
self.data = {targets : self.hashes(hashes), type : mime};
|
|
|
|
if (fm.cwd().hash !== cwd.hash) {
|
|
open = fm.exec('open', cwd.hash).done(function() {
|
|
fm.one('cwdrender', function() {
|
|
fm.selectfiles({files : hashes});
|
|
dfrd = fm.res('mixin', 'make').bind(self)();
|
|
});
|
|
});
|
|
} else {
|
|
fm.selectfiles({files : hashes});
|
|
dfrd = fm.res('mixin', 'make').bind(self)();
|
|
}
|
|
|
|
return dfrd;
|
|
};
|
|
|
|
};
|