Skip to content

Commit

Permalink
[VD] add a new volume driver FlysystemGoogleDriveNetmount
Browse files Browse the repository at this point in the history
Usage
-----
```
composer require barryvdh/elfinder-flysystem-driver
composer require nao-pon/flysystem-google-drive:~1.1
google/apiclient:~2.0@rc
```

```php
// Load composer autoloader
require 'vender/autoload.php';

// Enable Google Drive as Netmount driver
include_once
dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderFlysystemGoogleDriveNetmount.php';
define('ELFINDER_GOOGLEDRIVE_CLIENTID', 'YOUR CLIENT ID');
define('ELFINDER_GOOGLEDRIVE_CLIENTSECRET', 'YOUR CLIENT SECRET');
```

Add "YOUR_CONNECTOR_URL(connector.php)?cmd=netmount&protocol=googledrive&host=1"
to "Authorized redirect URIs" in "Credentials" on Google API Manager.
  • Loading branch information
nao-pon committed Mar 23, 2016
1 parent 27ba0bb commit b45cfec
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 16 deletions.
1 change: 1 addition & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var dirmode = 0755,
path.join(src, 'php', 'elFinderSessionInterface.php')
]
.concat(grep(path.join(src, 'php'), '\\.class\.php$')),
.concat(grep(path.join(src, 'php'), 'Netmount\.php$')),
'misc':
[
path.join(src, 'js', 'proxy', 'elFinderSupportVer1.js'),
Expand Down
1 change: 1 addition & 0 deletions css/dialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@

.elfinder-netmount-tb { margin:0 auto; }
.elfinder-netmount-tb input { border:1px solid #ccc; }
.elfinder-netmount-tb .elfinder-button-icon { cursor: pointer; }

button.elfinder-info-button {
margin: -3.5px 0;
Expand Down
1 change: 1 addition & 0 deletions css/navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
.elfinder-tree .elfinder-navbar-root-ftp .elfinder-navbar-icon { background-image:url("../img/volume_icon_ftp.png"); }
.elfinder-tree .elfinder-navbar-root-sql .elfinder-navbar-icon { background-image:url("../img/volume_icon_sql.png"); }
.elfinder-tree .elfinder-navbar-root-dropbox .elfinder-navbar-icon { background-image:url("../img/volume_icon_dropbox.png"); }
.elfinder-tree .elfinder-navbar-root-googledrive .elfinder-navbar-icon { background-image:url("../img/volume_icon_googledrive.png"); }

/* icon in active/hove/dropactive state */
.ui-state-active .elfinder-navbar-icon,
Expand Down
Binary file added img/volume_icon_googledrive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 26 additions & 16 deletions js/commands/netmount.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ elFinder.prototype.commands.netmount = function() {
o = self.options,
create = function() {
var inputs = {
protocol : $('<select/>').change(function(){
protocol : $('<select/>').change(function(e, data){
var protocol = this.value;
content.find('.elfinder-netmount-tr').hide();
content.find('.elfinder-netmount-tr-'+protocol).show();
if (typeof o[protocol].select == 'function') {
o[protocol].select(fm);
o[protocol].select(fm, e, data);
}
})
},
Expand All @@ -44,7 +44,7 @@ elFinder.prototype.commands.netmount = function() {
modal : true,
destroyOnClose : true,
close : function() {
delete self.dialog;
//delete self.dialog;
dfrd.state() == 'pending' && dfrd.reject();
},
buttons : {}
Expand Down Expand Up @@ -74,8 +74,9 @@ elFinder.prototype.commands.netmount = function() {
content.find('.elfinder-netmount-tr').hide();

opts.buttons[fm.i18n('btnMount')] = function() {
var protocol = inputs.protocol.val();
var data = {cmd : 'netmount', protocol: protocol};
var protocol = inputs.protocol.val(),
data = {cmd : 'netmount', protocol: protocol},
cur = o[protocol];
$.each(content.find('input.elfinder-netmount-inputs-'+protocol), function(name, input) {
var val;
if (typeof input.val == 'function') {
Expand All @@ -97,9 +98,15 @@ elFinder.prototype.commands.netmount = function() {
data.added && data.added.length && fm.exec('open', data.added[0].hash);
dfrd.resolve();
})
.fail(function(error) { dfrd.reject(error); });
.fail(function(error) {
//self.dialog.elfinderdialog('open');
if (cur.fail && typeof cur.fail == 'function') {
cur.fail(fm, error);
}
dfrd.reject(error);
});

self.dialog.elfinderdialog('close');
self.dialog.elfinderdialog('close');
};

opts.buttons[fm.i18n('btnCancel')] = function() {
Expand All @@ -115,22 +122,25 @@ elFinder.prototype.commands.netmount = function() {
}
;

fm.bind('netmount', function(e) {
var d = e.data || null;
if (d && d.protocol) {
if (o[d.protocol] && typeof o[d.protocol].done == 'function') {
o[d.protocol].done(fm, d);
}
}
});

if (!self.dialog) {
self.dialog = create();
} else {
self.dialog.elfinderdialog('open');
}

return dfrd.promise();
}

self.fm.bind('netmount', function(e) {
var d = e.data || null,
o = self.options;
if (d && d.protocol) {
if (o[d.protocol] && typeof o[d.protocol].done == 'function') {
o[d.protocol].done(self.fm, d);
}
}
});

}

elFinder.prototype.commands.netunmount = function() {
Expand Down
54 changes: 54 additions & 0 deletions js/elFinder.options.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,60 @@ elFinder.prototype._options = {
self.inputs.pass.val("done");
}
}
},
googledrive: {
inputs: {
offline : $('<input type="checkbox"/>').on('change', function() {
$(this).parents('table.elfinder-netmount-tb').find('select:first').trigger('change', 'reset');
}),
host : $('<span><span class="elfinder-info-spinner"/></span><input type="hidden"/>'),
path : $('<input type="text" value="root"/>'),
user : $('<input type="hidden"/>'),
pass : $('<input type="hidden"/>')
},
select: function(fm, ev, data){
var f = this.inputs,
data = data || null;
if ($(f.host[0]).find('span.elfinder-info-spinner').length || data === 'reset') {
f.path.parent().prev().html(fm.i18n('FolderID'));
f.offline.attr('title', fm.i18n('offlineAccess'));
$(f.host[0]).empty().addClass('elfinder-info-spinner')
.parent().find('span.elfinder-button-icon').remove();
fm.request({
data : {cmd : 'netmount', protocol: 'googledrive', host: 'google.com', user: 'init', options: {id: fm.id, offline: f.offline.prop('checked')? 1:0, pass: f.host[1].value}},
preventDefault : true
}).done(function(data){
$(f.host[0]).removeClass("elfinder-info-spinner").html(data.body.replace(/\{msg:([^}]+)\}/g, function(whole,s1){return fm.i18n(s1,'Google.com');}));
}).fail(function(){});
} else {
f.offline.parent().parent()[f.user.val()? 'hide':'show']();
}
},
done: function(fm, data){
var f = this.inputs;
if (data.mode == 'makebtn') {
$(f.host[0]).removeClass('elfinder-info-spinner');
f.host.find('input').hover(function(){$(this).toggleClass('ui-state-hover');});
$(f.host[1]).val('');
f.user.val('');
f.pass.val('');
f.offline.parent().parent().show();
} else {
$(f.host[0]).html('Google.com&nbsp;').removeClass('elfinder-info-spinner');
$(f.host[0]).parent().append($('<span class="elfinder-button-icon elfinder-button-icon-reload" title="'+fm.i18n('revoke')+'">')
.on('click', function() {
$(f.host[1]).val('revoke');
$(this).parents('table.elfinder-netmount-tb').find('select:first').trigger('change', 'reset');
}));
$(f.host[1]).val('googledrive');
f.user.val('done');
f.pass.val('done');
f.offline.parent().parent().hide();
}
},
fail: function(fm, err){
$(this.inputs.user).parents('table.elfinder-netmount-tb').find('select:first').trigger('change', 'reset');
}
}
},

Expand Down
Loading

0 comments on commit b45cfec

Please sign in to comment.