* @class elFinder command "archive"
* @author Dmitry (dio) Levashov
elFinder.prototype.commands.archive = function() {
this.disableOnSearch = false;
* Update mimes on open/reload
fm.bind('open reload', function() {
$.each((mimes = fm.option('archivers')['create'] || []), function(i, mime) {
self.variants.push([mime, fm.mime2kind(mime)]);
this.getstate = function(select) {
var sel = this.files(select),
chk = (cnt && ! fm.isRoot(sel[0]) && (fm.file(sel[0].phash) || {}).write),
filter = function(files) {
return $.grep(files, function(f) {
fres = fres && f.read && f.hash.indexOf(cwdId) === 0 ? true : false;
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),
cwd = fm.file(files[0].phash) || null,
error = ['errArchive', 'errPerm', 'errCreatingTempDir', 'errFtpDownloadFile', 'errFtpUploadFile', 'errFtpMkdir', 'errArchiveExec', 'errExtractExec', 'errRm'],
dfrd = $.Deferred().fail(function(error) {
error && fm.error(error);
if (! (cnt && mimes.length && $.inArray(mime, mimes) !== -1)) {
return dfrd.reject(error);
for (i = 0; i < cnt; i++) {
return dfrd.reject(error);
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 = $.proxy(fm.res('mixin', 'make'), self)();
fm.selectfiles({files : hashes});
dfrd = $.proxy(fm.res('mixin', 'make'), self)();