Skip to content

Commit

Permalink
elFindex.ajax removed. Add option "transport" to use custom backend c…
Browse files Browse the repository at this point in the history
…onnection
  • Loading branch information
dio-el-claire committed Jul 2, 2011
1 parent 38e9484 commit be83c1a
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 54 deletions.
1 change: 0 additions & 1 deletion src/connectors/php/elFinderVolumeDriver.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,6 @@ protected function stat($path) {
}

if ($root) {

$file['volumeid'] = $this->id;
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/commands/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ elFinder.prototype.commands.archive = function() {
}
}

return fm.ajax({
return fm.request({
data : {cmd : 'archive', targets : this.hashes(hashes), type : mime, current : cwd.hash},
notify : {type : 'archive', cnt : 1},
syncOnFail : true
Expand Down
4 changes: 2 additions & 2 deletions src/js/commands/duplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ elFinder.prototype.commands.duplicate = function() {
if (fm.oldAPI) {
$.each(files, function(i, file) {
args.push(function() {
return fm.ajax({
return fm.request({
data : {cmd : 'duplicate', target : file.hash, current : file.phash},
notify : {type : 'copy', cnt : 1}
});
Expand All @@ -59,7 +59,7 @@ elFinder.prototype.commands.duplicate = function() {
return fm.waterfall.apply(null, args);
}

return fm.ajax({
return fm.request({
data : {cmd : 'duplicate', targets : this.hashes(hashes)},
notify : {type : 'copy', cnt : cnt}
});
Expand Down
4 changes: 2 additions & 2 deletions src/js/commands/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ elFinder.prototype.commands.edit = function() {

editor.elfinderdialog('close');

fm.ajax({
fm.request({
options : {type : 'post'},
data : {
cmd : fm.oldAPI ? 'edit' : 'put',
Expand Down Expand Up @@ -122,7 +122,7 @@ elFinder.prototype.commands.edit = function() {
return dfrd.reject(error);
}

fm.ajax({
fm.request({
data : {
cmd : fm.oldAPI ? 'fread' : 'get',
target : hash,
Expand Down
2 changes: 1 addition & 1 deletion src/js/commands/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ elFinder.prototype.commands.extract = function() {
return dfrd.reject(error);
}

fm.ajax({
fm.request({
data : {cmd : 'extract', target : file.hash, current : file.phash},
notify : {type : 'extract', cnt : 1},
syncOnFail : true
Expand Down
2 changes: 1 addition & 1 deletion src/js/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ elFinder.prototype.commands.info = function() {

// send request to count total size
if (count.length) {
fm.ajax({
fm.request({
data : {cmd : 'size', targets : count},
preventDefault : true
})
Expand Down
2 changes: 1 addition & 1 deletion src/js/commands/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ elFinder.prototype.commands.open = function() {
if (cnt == 1 && (file = files[0]) && file.mime == 'directory') {
return file && !file.read
? dfrd.reject([errors.open, file.name, errors.denied])
: fm.ajax({
: fm.request({
data : {cmd : 'open', target : file.hash},
notify : {type : 'open', cnt : 1, hideCnt : true},
syncOnFail : true
Expand Down
6 changes: 3 additions & 3 deletions src/js/commands/paste.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ elFinder.prototype.commands.paste = function() {

$.each(groups, function(src, targets) {
args.push(function() {
return fm.ajax({
return fm.request({
data : {cmd : 'paste', current : fm.cwd().hash, src : src, dst : dst.hash, targets : targets, cut : cut ? 1 : 0},
notify : {type : cut ? 'move' : 'copy', cnt : targets.length}
});
Expand All @@ -156,7 +156,7 @@ elFinder.prototype.commands.paste = function() {

// new API
files = $.map(files, function(f) { return f.hash});
fm.ajax({
fm.request({
data : {cmd : 'paste', dst : dst.hash, targets : files, cut : cut ? 1 : 0},
notify : {type : cut ? 'move' : 'copy', cnt : cnt}
});
Expand All @@ -176,7 +176,7 @@ elFinder.prototype.commands.paste = function() {
} else {
dst.hash == fm.cwd().hash
? valid($.map(fm.files(), function(file) { return file.phash == dst.hash ? file.name : null }))
: fm.ajax({
: fm.request({
data : {cmd : 'ls', target : dst.hash},
notify : {type : 'preparecopy', cnt : 1, hideCnt : true},
preventFail : true
Expand Down
6 changes: 3 additions & 3 deletions src/js/commands/quicklook.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ elFinder.prototype.commands.quicklook.plugins = [
if ($.inArray(file.mime, mimes) !== -1) {
e.stopImmediatePropagation();

// stop loading on change file if not loadin yet
// stop loading on change file if not loaded yet
preview.one('change', function() {
if (!jqxhr.isResolved() && !jqxhr.isRejected()) {
jqxhr.reject();
}
});

jqxhr = fm.ajax({
jqxhr = fm.request({
options : {dataType : 'html'},
data : {cmd : fm.oldAPI ? 'open' : 'file', target : file.hash, current : file.phash},
preventDefault : true,
Expand Down Expand Up @@ -130,7 +130,7 @@ elFinder.prototype.commands.quicklook.plugins = [
}
});

jqxhr = fm.ajax({
jqxhr = fm.request({
data : {
cmd : fm.oldAPI ? 'fread' : 'get',
target : file.hash,
Expand Down
2 changes: 1 addition & 1 deletion src/js/commands/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ elFinder.prototype.commands.rename = function() {

parent.html(fm.escape(name));
fm.lockfiles({files : [file.hash]});
fm.ajax({
fm.request({
data : {cmd : 'rename', target : file.hash, name : name, current : file.phash},
notify : {type : 'rename', cnt : 1}
})
Expand Down
2 changes: 1 addition & 1 deletion src/js/commands/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ elFinder.prototype.commands.rm = function() {
label : self.title,
callback : function() {
fm.lockfiles({files : files});
fm.ajax({
fm.request({
data : {cmd : 'rm', targets : files, current : fm.cwd().hash}, // current - for old api
notify : {type : 'rm', cnt : cnt},
preventFail : true
Expand Down
2 changes: 1 addition & 1 deletion src/js/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ elFinder.prototype.commands.search = function() {
var fm = this.fm;

if (typeof(q) == 'string' && q) {
return fm.ajax({
return fm.request({
data : {cmd : 'search', q : q},
notify : {type : 'seach', cnt : 1, hideCnt : true}
});
Expand Down
34 changes: 23 additions & 11 deletions src/js/elFinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ window.elFinder = function(node, opts) {
**/
this.oldAPI = true;

this.OS = navigator.userAgent.indexOf('Mac') !== -1 ? 'mac' : navigator.userAgent.indexOf('Win') !== -1 ? 'win' : 'unknown';
/**
* User os. Required to bind native shortcuts for open/rename
*
* @type String
**/
this.OS = navigator.userAgent.indexOf('Mac') !== -1 ? 'mac' : navigator.userAgent.indexOf('Win') !== -1 ? 'win' : 'other';

/**
* Configuration options
Expand Down Expand Up @@ -652,6 +657,11 @@ window.elFinder = function(node, opts) {
return !!(data.error || rules[rules[cmd] ? cmd : 'defaults'](data));
}


this.transport = this.options.transport && typeof(this.options.transport.send) == 'function'
? this.options.transport
: { send : function(opts) { return $.ajax(opts) } }

/**
* Proccess ajax request.
* Fired events :
Expand Down Expand Up @@ -820,7 +830,9 @@ window.elFinder = function(node, opts) {
}
}

xhr = $.ajax(options).fail(error).success(success);
xhr = this.transport.send(options).fail(error).success(success);

// this.transport.send(options)

// add "open" xhr into queue
if (cmd == 'open') {
Expand Down Expand Up @@ -929,15 +941,15 @@ window.elFinder = function(node, opts) {
timeout, xhr;

xhr = self.oldAPI
? this.ajax(opts1)
? this.request(opts1)
: $.when(
this.ajax(opts1),
this.ajax(opts2)
this.request(opts1),
this.request(opts2)
);

xhr.fail(function(error) {
dfrd.reject(error);
error && self.ajax({
error && self.request({
data : {cmd : 'open', target : self.lastDir(''), tree : 1, init : 1},
notify : {type : 'open', cnt : 1, hideCnt : true}
});
Expand Down Expand Up @@ -1467,8 +1479,8 @@ window.elFinder = function(node, opts) {
.bind(keydown+' '+keypress, execShortcut);

// send initial request and start to pray >_<
this.trigger('init').
ajax({
this.trigger('init')
.request({
data : {cmd : 'open', target : self.lastDir(), init : 1, tree : 1},
preventDone : true,
notify : {type : 'open', cnt : 1, hideCnt : true},
Expand Down Expand Up @@ -1668,9 +1680,9 @@ elFinder.prototype = {
* @param Object request options
* @return $.Deferred
*/
ajax : function(options) {
return this.request(options);
},
// ajax : function(options) {
// return this.request(options);
// },

/**
* Bind callback to event(s) The callback is executed at most once per event.
Expand Down
48 changes: 32 additions & 16 deletions src/js/elFinder.options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Default config
* Default elFinder config
*
*/
elFinder.prototype.options = {
Expand All @@ -8,7 +8,7 @@ elFinder.prototype.options = {
*
* @type String
*/
url : '',
url : '',

/**
* Ajax request type.
Expand All @@ -18,20 +18,39 @@ elFinder.prototype.options = {
*/
requestType : 'get',

/**
* Transport to send request to backend.
* Required for future extensions using websockets/webdav etc.
* Must be an object with "send" method.
* transport.send must return $.Deferred() object
*
* @type Object
* @default null
* @example
* transport : {
* send : function(options) {
* var dfrd = $.Deferred();
* // connect to backend ...
* return dfrd;
* }
* }
**/
transport : null,

/**
* Interface language
*
* @type String
* @default "en"
*/
lang : 'en',
lang : 'en',

/**
* Additional css class for filemanager node.
*
* @type String
*/
cssClass : '',
cssClass : '',

commands : ['open', 'reload', 'home', 'up', 'back', 'forward', 'getfile', 'quicklook', 'download', 'rm', 'duplicate', 'rename', 'mkdir', 'mkfile', 'upload', 'copy', 'cut', 'paste', 'edit', 'extract', 'archive', 'search', 'info', 'view', 'help'],

Expand Down Expand Up @@ -120,16 +139,7 @@ elFinder.prototype.options = {
notifyDelay : 500,

syncTree : true,
/* callback to get file url (for wswing editors) */
editorCallback : null,
/* string to cut from file url begin before pass it to editorCallback. variants: '' - nothing to cut, 'root' - cut root url, 'http://...' - string if it exists in the beginig of url */
cutURL : '',
/* close elfinder after editorCallback */
closeOnEditorCallback : true,
/* i18 messages. not set manually! */
i18n : {},
/* fm view (icons|list) */
view : 'icons',

/* width */
width : 'auto',
/* height */
Expand Down Expand Up @@ -188,7 +198,7 @@ elFinder.prototype.options = {
* Distance in px to cwd bottom edge to start display files
*
* @type Number
* @default 100
* @default 50
*/
showThreshold : 50,

Expand All @@ -208,7 +218,13 @@ elFinder.prototype.options = {

// commands : ['back', 'forward', 'reload', 'up', 'home', 'open', 'copy', 'cut', 'paste', 'rm', 'info', 'duplicate', 'rename'],


/**
* How many thumbnails create in one request
*
* @type Number
* @default 5
*/
loadTmbs : 5,

/* cookie options */
cookie : {
Expand Down
2 changes: 1 addition & 1 deletion src/js/elFinder.resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ elFinder.prototype.resources = {

fm.lockfiles({files : [id]});

fm.ajax({
fm.request({
data : {cmd : cmd, name : name, current : phash, target : phash}, // current - for old api
notify : {type : cmd, cnt : 1},
preventFail : true,
Expand Down
11 changes: 7 additions & 4 deletions src/js/ui/cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ $.fn.elfindercwd = function(fm) {
**/
tmbUrl = '',

tmbNum = fm.options.loadTmbs > 0 ? fm.options.loadTmbs : 5,

/**
* File templates
*
Expand Down Expand Up @@ -437,7 +439,8 @@ $.fn.elfindercwd = function(fm) {
* @return Boolean
*/
attachThumbnails = function(images) {
var ret = true;
var ret = true, ndx;

$.each(images, function(hash, tmb) {
var node = cwd.find('#'+hash);
if (node.length) {
Expand Down Expand Up @@ -466,16 +469,16 @@ $.fn.elfindercwd = function(fm) {
var tmbs = [];

if (fm.oldAPI) {
fm.ajax({cmd : 'tmb', current : fm.cwd().hash, preventFail : true}).done(function(data) {
fm.request({cmd : 'tmb', current : fm.cwd().hash, preventFail : true}).done(function(data) {
if (attachThumbnails(data.images||[]) && data.tmb) {
loadThumbnails();
}
})
return;
}

while ((tmbs = files.splice(0, 5)).length) {
fm.ajax({cmd : 'tmb', targets : tmbs, preventFail : true}).done(function(data) {
while ((tmbs = files.splice(0, tmbNum)).length) {
fm.request({cmd : 'tmb', targets : tmbs, preventFail : true}).done(function(data) {
if (!attachThumbnails(data.images||[])) {
return;
}
Expand Down
Loading

0 comments on commit be83c1a

Please sign in to comment.