2015-11-12 15:40:28 +03:00
/ * *
* ownCloud
*
* @ author Juan Pablo Villafañez Ramos < jvillafanez @ owncloud . com >
* @ author Jesus Macias Portela < jesus @ owncloud . com >
* @ copyright ( C ) 2014 ownCloud , Inc .
*
2015-11-18 20:34:26 +03:00
* This file is licensed under the Affero General Public License version 3
* or later .
2015-11-12 15:40:28 +03:00
*
2015-11-18 20:34:26 +03:00
* See the COPYING - README file .
2015-11-12 15:40:28 +03:00
*
* /
2016-07-06 00:17:43 +03:00
/** @global Handlebars */
2018-10-19 18:35:13 +03:00
if ( ! OCA . Files _External ) {
OCA . Files _External = { } ;
2015-11-12 15:40:28 +03:00
}
2018-10-19 18:35:13 +03:00
if ( ! OCA . Files _External . StatusManager ) {
OCA . Files _External . StatusManager = { } ;
2015-11-18 14:12:32 +03:00
}
2018-10-19 18:35:13 +03:00
OCA . Files _External . StatusManager = {
2015-11-24 10:16:14 +03:00
2015-12-03 14:28:52 +03:00
mountStatus : null ,
mountPointList : null ,
2015-11-18 20:34:26 +03:00
2015-11-24 10:16:14 +03:00
/ * *
* Function
* @ param { callback } afterCallback
* /
2015-12-03 14:28:52 +03:00
getMountStatus : function ( afterCallback ) {
2015-11-18 20:34:26 +03:00
var self = this ;
if ( typeof afterCallback !== 'function' || self . isGetMountStatusRunning ) {
return ;
}
if ( self . mountStatus ) {
afterCallback ( self . mountStatus ) ;
}
} ,
2015-11-24 10:16:14 +03:00
/ * *
* Function Check mount point status from cache
* @ param { string } mount _point
* /
2015-12-03 14:28:52 +03:00
getMountPointListElement : function ( mount _point ) {
2015-11-18 20:34:26 +03:00
var element ;
2015-12-03 14:28:52 +03:00
$ . each ( this . mountPointList , function ( key , value ) {
2015-11-18 20:34:26 +03:00
if ( value . mount _point === mount _point ) {
element = value ;
return false ;
}
} ) ;
return element ;
} ,
2015-11-24 10:16:14 +03:00
/ * *
* Function Check mount point status from cache
* @ param { string } mount _point
* @ param { string } mount _point
* /
2015-12-03 14:28:52 +03:00
getMountStatusForMount : function ( mountData , afterCallback ) {
2015-11-18 20:34:26 +03:00
var self = this ;
if ( typeof afterCallback !== 'function' || self . isGetMountStatusRunning ) {
return $ . Deferred ( ) . resolve ( ) ;
}
var defObj ;
if ( self . mountStatus [ mountData . mount _point ] ) {
defObj = $ . Deferred ( ) ;
2015-12-03 14:28:52 +03:00
afterCallback ( mountData , self . mountStatus [ mountData . mount _point ] ) ;
2015-11-18 20:34:26 +03:00
defObj . resolve ( ) ; // not really useful, but it'll keep the same behaviour
} else {
defObj = $ . ajax ( {
2015-12-03 14:28:52 +03:00
type : 'GET' ,
2018-10-09 08:44:26 +03:00
url : OC . getRootPath ( ) + '/index.php/apps/files_external/' + ( ( mountData . type === 'personal' ) ? 'userstorages' : 'userglobalstorages' ) + '/' + mountData . id ,
2016-06-07 19:25:17 +03:00
data : { 'testOnly' : false } ,
2015-12-03 14:28:52 +03:00
success : function ( response ) {
2015-11-18 20:34:26 +03:00
if ( response && response . status === 0 ) {
self . mountStatus [ mountData . mount _point ] = response ;
} else {
2015-12-03 14:28:52 +03:00
var statusCode = response . status ? response . status : 1 ;
var statusMessage = response . statusMessage ? response . statusMessage : t ( 'files_external' , 'Empty response from the server' )
// failure response with error message
self . mountStatus [ mountData . mount _point ] = {
type : mountData . type ,
status : statusCode ,
id : mountData . id ,
error : statusMessage ,
2019-09-09 18:14:21 +03:00
userProvided : response . userProvided ,
2020-12-11 18:40:29 +03:00
authMechanism : response . authMechanism ,
canEdit : response . can _edit ,
2015-12-03 14:28:52 +03:00
} ;
2015-11-18 20:34:26 +03:00
}
afterCallback ( mountData , self . mountStatus [ mountData . mount _point ] ) ;
} ,
2015-12-03 14:28:52 +03:00
error : function ( jqxhr , state , error ) {
2015-11-18 20:34:26 +03:00
var message ;
2015-12-03 14:28:52 +03:00
if ( mountData . location === 3 ) {
2015-11-18 20:34:26 +03:00
// In this case the error is because mount point use Login credentials and don't exist in the session
2017-07-14 18:02:48 +03:00
message = t ( 'files_external' , 'Couldn\'t access. Please log out and in again to activate this mount point' ) ;
2015-11-18 20:34:26 +03:00
} else {
2016-11-07 13:25:53 +03:00
message = t ( 'files_external' , 'Couldn\'t get the information from the remote server: {code} {type}' , {
2015-12-03 14:28:52 +03:00
code : jqxhr . status ,
type : error
} ) ;
2015-11-18 20:34:26 +03:00
}
2015-12-03 14:28:52 +03:00
self . mountStatus [ mountData . mount _point ] = {
type : mountData . type ,
status : 1 ,
location : mountData . location ,
error : message
} ;
2015-11-18 20:34:26 +03:00
afterCallback ( mountData , self . mountStatus [ mountData . mount _point ] ) ;
}
} ) ;
}
return defObj ;
} ,
2015-11-24 10:16:14 +03:00
/ * *
* Function to get external mount point list from the files _external API
2019-09-25 19:19:42 +03:00
* @ param { Function } afterCallback function to be executed
2015-11-24 10:16:14 +03:00
* /
2015-12-03 14:28:52 +03:00
getMountPointList : function ( afterCallback ) {
2015-11-18 20:34:26 +03:00
var self = this ;
if ( typeof afterCallback !== 'function' || self . isGetMountPointListRunning ) {
return ;
}
if ( self . mountPointList ) {
afterCallback ( self . mountPointList ) ;
} else {
self . isGetMountPointListRunning = true ;
$ . ajax ( {
2015-12-03 14:28:52 +03:00
type : 'GET' ,
url : OC . linkToOCS ( 'apps/files_external/api/v1' ) + 'mounts?format=json' ,
success : function ( response ) {
2015-11-18 20:34:26 +03:00
self . mountPointList = [ ] ;
2015-12-03 14:28:52 +03:00
_ . each ( response . ocs . data , function ( mount ) {
2015-11-18 20:34:26 +03:00
var element = { } ;
element . mount _point = mount . name ;
element . type = mount . scope ;
element . location = "" ;
element . id = mount . id ;
element . backendText = mount . backend ;
element . backend = mount . class ;
self . mountPointList . push ( element ) ;
} ) ;
afterCallback ( self . mountPointList ) ;
} ,
2015-12-03 14:28:52 +03:00
error : function ( jqxhr , state , error ) {
2015-11-18 20:34:26 +03:00
self . mountPointList = [ ] ;
2017-02-14 23:26:00 +03:00
OC . Notification . show ( t ( 'files_external' , 'Couldn\'t get the list of external mount points: {type}' ,
{ type : error } ) , { type : 'error' }
) ;
2015-11-18 20:34:26 +03:00
} ,
2015-12-03 14:28:52 +03:00
complete : function ( ) {
2015-11-18 20:34:26 +03:00
self . isGetMountPointListRunning = false ;
}
} ) ;
}
} ,
2015-11-24 10:16:14 +03:00
/ * *
* Function to manage action when a mountpoint status = 1 ( Errored ) . Show a dialog to be redirected to settings page .
* @ param { string } name MountPoint Name
* /
2015-11-18 20:34:26 +03:00
2015-12-03 14:28:52 +03:00
manageMountPointError : function ( name ) {
this . getMountStatus ( $ . proxy ( function ( allMountStatus ) {
if ( allMountStatus . hasOwnProperty ( name ) && allMountStatus [ name ] . status > 0 && allMountStatus [ name ] . status < 7 ) {
2015-11-18 20:34:26 +03:00
var mountData = allMountStatus [ name ] ;
if ( mountData . type === "system" ) {
2019-09-09 18:14:21 +03:00
if ( mountData . userProvided || mountData . authMechanism === 'password::global::user' ) {
2015-12-03 14:28:52 +03:00
// personal mount whit credentials problems
2016-02-01 16:25:24 +03:00
this . showCredentialsDialog ( name , mountData ) ;
2020-12-11 18:40:29 +03:00
} else if ( mountData . canEdit ) {
2015-12-03 14:28:52 +03:00
OC . dialogs . confirm ( t ( 'files_external' , 'There was an error with message: ' ) + mountData . error + '. Do you want to review mount point config in admin settings page?' , t ( 'files_external' , 'External mount error' ) , function ( e ) {
if ( e === true ) {
2016-11-26 12:14:23 +03:00
OC . redirect ( OC . generateUrl ( '/settings/admin/externalstorages' ) ) ;
2015-12-03 14:28:52 +03:00
}
} ) ;
2020-12-11 18:40:29 +03:00
} else {
OC . dialogs . info ( t ( 'files_external' , 'There was an error with message: ' ) + mountData . error + '. Please contact your system administrator.' , t ( 'files_external' , 'External mount error' ) , ( ) => { } ) ;
2015-12-03 14:28:52 +03:00
}
2015-11-18 20:34:26 +03:00
} else {
2015-12-03 14:28:52 +03:00
OC . dialogs . confirm ( t ( 'files_external' , 'There was an error with message: ' ) + mountData . error + '. Do you want to review mount point config in personal settings page?' , t ( 'files_external' , 'External mount error' ) , function ( e ) {
if ( e === true ) {
2016-02-01 16:25:24 +03:00
OC . redirect ( OC . generateUrl ( '/settings/personal#' + t ( 'files_external' , 'external-storage' ) ) ) ;
2015-11-18 20:34:26 +03:00
}
} ) ;
}
}
} , this ) ) ;
} ,
2015-11-24 10:16:14 +03:00
/ * *
* Function to process a mount point in relation with their status , Called from Async Queue .
* @ param { object } mountData
* @ param { object } mountStatus
* /
2015-11-18 20:34:26 +03:00
2015-12-03 14:28:52 +03:00
processMountStatusIndividual : function ( mountData , mountStatus ) {
2015-11-18 20:34:26 +03:00
var mountPoint = mountData . mount _point ;
2015-12-03 14:28:52 +03:00
if ( mountStatus . status > 0 ) {
2018-10-19 18:35:13 +03:00
var trElement = FileList . findFileEl ( OCA . Files _External . StatusManager . Utils . jqSelEscape ( mountPoint ) ) ;
2015-11-18 20:34:26 +03:00
2018-10-19 18:35:13 +03:00
var route = OCA . Files _External . StatusManager . Utils . getIconRoute ( trElement ) + '-error' ;
2015-11-18 20:34:26 +03:00
2018-10-19 18:35:13 +03:00
if ( OCA . Files _External . StatusManager . Utils . isCorrectViewAndRootFolder ( ) ) {
OCA . Files _External . StatusManager . Utils . showIconError ( mountPoint , $ . proxy ( OCA . Files _External . StatusManager . manageMountPointError , OCA . Files _External . StatusManager ) , route ) ;
2015-11-18 20:34:26 +03:00
}
return false ;
} else {
2018-10-19 18:35:13 +03:00
if ( OCA . Files _External . StatusManager . Utils . isCorrectViewAndRootFolder ( ) ) {
OCA . Files _External . StatusManager . Utils . restoreFolder ( mountPoint ) ;
OCA . Files _External . StatusManager . Utils . toggleLink ( mountPoint , true , true ) ;
2015-11-18 20:34:26 +03:00
}
return true ;
}
} ,
2015-11-24 10:16:14 +03:00
/ * *
* Function to process a mount point in relation with their status
* @ param { object } mountData
* @ param { object } mountStatus
* /
2015-12-03 14:28:52 +03:00
processMountList : function ( mountList ) {
2015-11-18 20:34:26 +03:00
var elementList = null ;
2015-12-03 14:28:52 +03:00
$ . each ( mountList , function ( name , value ) {
2018-10-19 18:35:13 +03:00
var trElement = $ ( '#fileList tr[data-file=\"' + OCA . Files _External . StatusManager . Utils . jqSelEscape ( value . mount _point ) + '\"]' ) ; //FileList.findFileEl(OCA.Files_External.StatusManager.Utils.jqSelEscape(value.mount_point));
2015-11-18 20:34:26 +03:00
trElement . attr ( 'data-external-backend' , value . backend ) ;
if ( elementList ) {
elementList = elementList . add ( trElement ) ;
} else {
elementList = trElement ;
}
} ) ;
if ( elementList instanceof $ ) {
2018-10-19 18:35:13 +03:00
if ( OCA . Files _External . StatusManager . Utils . isCorrectViewAndRootFolder ( ) ) {
2015-11-18 20:34:26 +03:00
// Put their custom icon
2018-10-19 18:35:13 +03:00
OCA . Files _External . StatusManager . Utils . changeFolderIcon ( elementList ) ;
2015-11-18 20:34:26 +03:00
// Save default view
2018-10-19 18:35:13 +03:00
OCA . Files _External . StatusManager . Utils . storeDefaultFolderIconAndBgcolor ( elementList ) ;
2015-11-18 20:34:26 +03:00
// Disable row until check status
2015-11-24 10:52:02 +03:00
elementList . addClass ( 'externalDisabledRow' ) ;
2018-10-19 18:35:13 +03:00
OCA . Files _External . StatusManager . Utils . toggleLink ( elementList . find ( 'a.name' ) , false , false ) ;
2015-11-18 20:34:26 +03:00
}
}
} ,
2015-11-24 10:16:14 +03:00
/ * *
* Function to process the whole mount point list in relation with their status ( Async queue )
* /
2015-11-18 20:34:26 +03:00
2015-12-03 14:28:52 +03:00
launchFullConnectivityCheckOneByOne : function ( ) {
2015-11-18 20:34:26 +03:00
var self = this ;
2015-12-03 14:28:52 +03:00
this . getMountPointList ( function ( list ) {
2015-11-18 20:34:26 +03:00
// check if we have a list first
if ( list === undefined && ! self . emptyWarningShown ) {
self . emptyWarningShown = true ;
2017-07-14 18:02:48 +03:00
OC . Notification . show ( t ( 'files_external' , 'Couldn\'t fetch list of Windows network drive mount points: Empty response from server' ) ,
2017-02-14 23:26:00 +03:00
{ type : 'error' }
) ;
2015-11-18 20:34:26 +03:00
return ;
}
if ( list && list . length > 0 ) {
self . processMountList ( list ) ;
if ( ! self . mountStatus ) {
self . mountStatus = { } ;
}
var ajaxQueue = [ ] ;
2015-12-03 14:28:52 +03:00
$ . each ( list , function ( key , value ) {
var queueElement = {
funcName : $ . proxy ( self . getMountStatusForMount , self ) ,
funcArgs : [ value ,
$ . proxy ( self . processMountStatusIndividual , self ) ]
} ;
2015-11-18 20:34:26 +03:00
ajaxQueue . push ( queueElement ) ;
} ) ;
2019-02-07 12:15:27 +03:00
var rolQueue = new OCA . Files _External . StatusManager . RollingQueue ( ajaxQueue , 4 , function ( ) {
if ( ! self . notificationHasShown ) {
$ . each ( self . mountStatus , function ( key , value ) {
if ( value . status === 1 ) {
self . notificationHasShown = true ;
}
} ) ;
}
} ) ;
rolQueue . runQueue ( ) ;
2015-11-18 20:34:26 +03:00
}
} ) ;
} ,
2015-11-24 10:16:14 +03:00
/ * *
* Function to process a mount point list in relation with their status ( Async queue )
* @ param { object } mountListData
* @ param { boolean } recheck delete cached info and force api call to check mount point status
* /
2015-12-03 14:28:52 +03:00
launchPartialConnectivityCheck : function ( mountListData , recheck ) {
2015-11-18 20:34:26 +03:00
if ( mountListData . length === 0 ) {
return ;
}
var self = this ;
var ajaxQueue = [ ] ;
2015-12-03 14:28:52 +03:00
$ . each ( mountListData , function ( key , value ) {
2015-11-18 20:34:26 +03:00
if ( recheck && value . mount _point in self . mountStatus ) {
delete self . mountStatus [ value . mount _point ] ;
}
2015-12-03 14:28:52 +03:00
var queueElement = {
funcName : $ . proxy ( self . getMountStatusForMount , self ) ,
funcArgs : [ value ,
$ . proxy ( self . processMountStatusIndividual , self ) ]
} ;
2015-11-18 20:34:26 +03:00
ajaxQueue . push ( queueElement ) ;
} ) ;
2018-10-19 18:35:13 +03:00
new OCA . Files _External . StatusManager . RollingQueue ( ajaxQueue , 4 ) . runQueue ( ) ;
2015-11-18 20:34:26 +03:00
} ,
2015-11-24 10:16:14 +03:00
/ * *
* Function to relaunch some mount point status check
* @ param { string } mountListNames
* @ param { boolean } recheck delete cached info and force api call to check mount point status
* /
2015-12-03 14:28:52 +03:00
recheckConnectivityForMount : function ( mountListNames , recheck ) {
2015-11-18 20:34:26 +03:00
if ( mountListNames . length === 0 ) {
return ;
}
var self = this ;
var mountListData = [ ] ;
if ( ! self . mountStatus ) {
self . mountStatus = { } ;
}
2015-12-03 14:28:52 +03:00
$ . each ( mountListNames , function ( key , value ) {
2015-11-18 20:34:26 +03:00
var mountData = self . getMountPointListElement ( value ) ;
if ( mountData ) {
mountListData . push ( mountData ) ;
}
} ) ;
// for all mounts in the list, delete the cached status values
if ( recheck ) {
2015-12-03 14:28:52 +03:00
$ . each ( mountListData , function ( key , value ) {
2015-11-18 20:34:26 +03:00
if ( value . mount _point in self . mountStatus ) {
delete self . mountStatus [ value . mount _point ] ;
}
} ) ;
}
self . processMountList ( mountListData ) ;
self . launchPartialConnectivityCheck ( mountListData , recheck ) ;
2015-12-03 14:28:52 +03:00
} ,
2016-02-01 16:44:17 +03:00
credentialsDialogTemplate :
'<div id="files_external_div_form"><div>' +
'<div>{{credentials_text}}</div>' +
'<form>' +
'<input type="text" name="username" placeholder="{{placeholder_username}}"/>' +
2016-02-04 18:20:45 +03:00
'<input type="password" name="password" placeholder="{{placeholder_password}}"/>' +
2016-02-01 16:44:17 +03:00
'</form>' +
'</div></div>' ,
2015-12-03 14:28:52 +03:00
/ * *
* Function to display custom dialog to enter credentials
* @ param mountPoint
* @ param mountData
* /
showCredentialsDialog : function ( mountPoint , mountData ) {
2018-10-19 18:35:13 +03:00
var dialog = $ ( OCA . Files _External . Templates . credentialsDialog ( {
2016-02-01 16:44:17 +03:00
credentials _text : t ( 'files_external' , 'Please enter the credentials for the {mount} mount' , {
'mount' : mountPoint
} ) ,
placeholder _username : t ( 'files_external' , 'Username' ) ,
placeholder _password : t ( 'files_external' , 'Password' )
} ) ) ;
2015-12-03 14:28:52 +03:00
2016-02-01 16:44:17 +03:00
$ ( 'body' ) . append ( dialog ) ;
2015-12-03 14:28:52 +03:00
var apply = function ( ) {
2016-02-01 16:44:17 +03:00
var username = dialog . find ( '[name=username]' ) . val ( ) ;
var password = dialog . find ( '[name=password]' ) . val ( ) ;
2015-12-03 14:28:52 +03:00
var endpoint = OC . generateUrl ( 'apps/files_external/userglobalstorages/{id}' , {
id : mountData . id
} ) ;
$ ( '.oc-dialog-close' ) . hide ( ) ;
$ . ajax ( {
type : 'PUT' ,
url : endpoint ,
data : {
backendOptions : {
user : username ,
password : password
}
} ,
success : function ( data ) {
2019-12-18 17:32:39 +03:00
OC . Notification . show ( t ( 'files_external' , 'Credentials saved' ) , { type : 'success' } ) ;
2016-02-01 16:44:17 +03:00
dialog . ocdialog ( 'close' ) ;
2015-12-03 14:28:52 +03:00
/* Trigger status check again */
2018-10-19 18:35:13 +03:00
OCA . Files _External . StatusManager . recheckConnectivityForMount ( [ OC . basename ( data . mountPoint ) ] , true ) ;
2015-12-03 14:28:52 +03:00
} ,
error : function ( ) {
$ ( '.oc-dialog-close' ) . show ( ) ;
2017-02-14 23:26:00 +03:00
OC . Notification . show ( t ( 'files_external' , 'Credentials saving failed' ) , { type : 'error' } ) ;
2015-12-03 14:28:52 +03:00
}
} ) ;
2016-02-04 19:18:21 +03:00
return false ;
2015-12-03 14:28:52 +03:00
} ;
var ocdialogParams = {
modal : true ,
2016-02-04 19:18:21 +03:00
title : t ( 'files_external' , 'Credentials required' ) ,
2015-12-03 14:28:52 +03:00
buttons : [ {
text : t ( 'files_external' , 'Save' ) ,
click : apply ,
closeOnEscape : true
} ] ,
closeOnExcape : true
} ;
2016-02-01 16:44:17 +03:00
dialog . ocdialog ( ocdialogParams )
2015-12-03 14:28:52 +03:00
. bind ( 'ocdialogclose' , function ( ) {
2016-02-01 16:44:17 +03:00
dialog . ocdialog ( 'destroy' ) . remove ( ) ;
2015-12-03 14:28:52 +03:00
} ) ;
2016-02-04 19:18:21 +03:00
dialog . find ( 'form' ) . on ( 'submit' , apply ) ;
dialog . find ( 'form input:first' ) . focus ( ) ;
dialog . find ( 'form input' ) . keyup ( function ( e ) {
if ( ( e . which && e . which === 13 ) || ( e . keyCode && e . keyCode === 13 ) ) {
$ ( e . target ) . closest ( 'form' ) . submit ( ) ;
return false ;
} else {
return true ;
}
} ) ;
2015-11-18 20:34:26 +03:00
}
2015-11-12 15:40:28 +03:00
} ;
2015-11-18 14:12:32 +03:00
2018-10-19 18:35:13 +03:00
OCA . Files _External . StatusManager . Utils = {
2015-11-18 14:12:32 +03:00
2015-12-03 14:28:52 +03:00
showIconError : function ( folder , clickAction , errorImageUrl ) {
2015-11-18 20:34:26 +03:00
var imageUrl = "url(" + errorImageUrl + ")" ;
2018-10-19 18:35:13 +03:00
var trFolder = $ ( '#fileList tr[data-file=\"' + OCA . Files _External . StatusManager . Utils . jqSelEscape ( folder ) + '\"]' ) ; //FileList.findFileEl(OCA.Files_External.StatusManager.Utils.jqSelEscape(folder));
2015-11-18 20:34:26 +03:00
this . changeFolderIcon ( folder , imageUrl ) ;
this . toggleLink ( folder , false , clickAction ) ;
2015-11-24 10:52:02 +03:00
trFolder . addClass ( 'externalErroredRow' ) ;
2015-11-18 20:34:26 +03:00
} ,
/ * *
* @ param folder string with the folder or jQuery element pointing to the tr element
* /
2015-12-03 14:28:52 +03:00
storeDefaultFolderIconAndBgcolor : function ( folder ) {
2015-11-18 20:34:26 +03:00
var trFolder ;
if ( folder instanceof $ ) {
trFolder = folder ;
} else {
2018-10-19 18:35:13 +03:00
trFolder = $ ( '#fileList tr[data-file=\"' + OCA . Files _External . StatusManager . Utils . jqSelEscape ( folder ) + '\"]' ) ; //FileList.findFileEl(OCA.Files_External.StatusManager.Utils.jqSelEscape(folder)); //$('#fileList tr[data-file=\"' + OCA.Files_External.StatusManager.Utils.jqSelEscape(folder) + '\"]');
2015-11-18 20:34:26 +03:00
}
2015-12-03 14:28:52 +03:00
trFolder . each ( function ( ) {
2015-11-18 20:34:26 +03:00
var thisElement = $ ( this ) ;
if ( thisElement . data ( 'oldbgcolor' ) === undefined ) {
thisElement . data ( 'oldbgcolor' , thisElement . css ( 'background-color' ) ) ;
}
} ) ;
2017-12-27 18:17:00 +03:00
var icon = trFolder . find ( 'td.filename div.thumbnail' ) ;
2015-12-03 14:28:52 +03:00
icon . each ( function ( ) {
2015-11-18 20:34:26 +03:00
var thisElement = $ ( this ) ;
if ( thisElement . data ( 'oldImage' ) === undefined ) {
thisElement . data ( 'oldImage' , thisElement . css ( 'background-image' ) ) ;
}
} ) ;
} ,
/ * *
* @ param folder string with the folder or jQuery element pointing to the tr element
* /
2015-12-03 14:28:52 +03:00
restoreFolder : function ( folder ) {
2015-11-18 20:34:26 +03:00
var trFolder ;
if ( folder instanceof $ ) {
trFolder = folder ;
} else {
2018-10-19 18:35:13 +03:00
// can't use here FileList.findFileEl(OCA.Files_External.StatusManager.Utils.jqSelEscape(folder)); return incorrect instance of filelist
trFolder = $ ( '#fileList tr[data-file=\"' + OCA . Files _External . StatusManager . Utils . jqSelEscape ( folder ) + '\"]' ) ;
2015-11-18 20:34:26 +03:00
}
2015-11-24 10:52:02 +03:00
trFolder . removeClass ( 'externalErroredRow' ) . removeClass ( 'externalDisabledRow' ) ;
2017-12-27 18:17:00 +03:00
var tdChilds = trFolder . find ( "td.filename div.thumbnail" ) ;
2015-12-03 14:28:52 +03:00
tdChilds . each ( function ( ) {
2015-11-18 20:34:26 +03:00
var thisElement = $ ( this ) ;
thisElement . css ( 'background-image' , thisElement . data ( 'oldImage' ) ) ;
} ) ;
} ,
/ * *
* @ param folder string with the folder or jQuery element pointing to the first td element
* of the tr matching the folder name
* /
2015-12-03 14:28:52 +03:00
changeFolderIcon : function ( filename ) {
2015-11-18 20:34:26 +03:00
var file ;
var route ;
if ( filename instanceof $ ) {
//trElementList
2015-12-03 14:28:52 +03:00
$ . each ( filename , function ( index ) {
2018-10-19 18:35:13 +03:00
route = OCA . Files _External . StatusManager . Utils . getIconRoute ( $ ( this ) ) ;
2015-11-18 20:34:26 +03:00
$ ( this ) . attr ( "data-icon" , route ) ;
2017-12-27 18:17:00 +03:00
$ ( this ) . find ( 'td.filename div.thumbnail' ) . css ( 'background-image' , "url(" + route + ")" ) . css ( 'display' , 'none' ) . css ( 'display' , 'inline' ) ;
2015-11-18 20:34:26 +03:00
} ) ;
} else {
2017-12-27 18:17:00 +03:00
file = $ ( "#fileList tr[data-file=\"" + this . jqSelEscape ( filename ) + "\"] > td.filename div.thumbnail" ) ;
2016-07-06 00:17:43 +03:00
var parentTr = file . parents ( 'tr:first' ) ;
2018-10-19 18:35:13 +03:00
route = OCA . Files _External . StatusManager . Utils . getIconRoute ( parentTr ) ;
2015-11-18 20:34:26 +03:00
parentTr . attr ( "data-icon" , route ) ;
file . css ( 'background-image' , "url(" + route + ")" ) . css ( 'display' , 'none' ) . css ( 'display' , 'inline' ) ;
}
} ,
/ * *
* @ param backend string with the name of the external storage backend
* of the tr matching the folder name
* /
2015-12-03 14:28:52 +03:00
getIconRoute : function ( tr ) {
2016-12-09 14:50:14 +03:00
if ( OCA . Theming ) {
var icon = OC . generateUrl ( '/apps/theming/img/core/filetypes/folder-external.svg?v=' + OCA . Theming . cacheBuster ) ;
} else {
var icon = OC . imagePath ( 'core' , 'filetypes/folder-external' ) ;
}
2015-11-18 20:34:26 +03:00
var backend = null ;
if ( tr instanceof $ ) {
backend = tr . attr ( 'data-external-backend' ) ;
}
switch ( backend ) {
2016-01-15 15:06:12 +03:00
case 'windows_network_drive' :
2015-11-18 20:34:26 +03:00
icon = OC . imagePath ( 'windows_network_drive' , 'folder-windows' ) ;
break ;
}
return icon ;
} ,
2015-12-03 14:28:52 +03:00
toggleLink : function ( filename , active , action ) {
2015-11-18 20:34:26 +03:00
var link ;
if ( filename instanceof $ ) {
link = filename ;
} else {
2017-12-27 18:17:00 +03:00
link = $ ( "#fileList tr[data-file=\"" + this . jqSelEscape ( filename ) + "\"] > td.filename a.name" ) ;
2015-11-18 20:34:26 +03:00
}
if ( active ) {
link . off ( 'click.connectivity' ) ;
OCA . Files . App . fileList . fileActions . display ( link . parent ( ) , true , OCA . Files . App . fileList ) ;
} else {
link . find ( '.fileactions, .nametext .action' ) . remove ( ) ; // from files/js/fileactions (display)
link . off ( 'click.connectivity' ) ;
2015-12-03 14:28:52 +03:00
link . on ( 'click.connectivity' , function ( e ) {
2015-11-18 20:34:26 +03:00
if ( action && $ . isFunction ( action ) ) {
action ( filename ) ;
}
e . preventDefault ( ) ;
return false ;
} ) ;
}
} ,
2015-12-03 14:28:52 +03:00
isCorrectViewAndRootFolder : function ( ) {
2015-11-18 20:34:26 +03:00
// correct views = files & extstoragemounts
if ( OCA . Files . App . getActiveView ( ) === 'files' || OCA . Files . App . getActiveView ( ) === 'extstoragemounts' ) {
return OCA . Files . App . getCurrentAppContainer ( ) . find ( '#dir' ) . val ( ) === '/' ;
}
return false ;
} ,
/* escape a selector expression for jQuery */
2015-12-03 14:28:52 +03:00
jqSelEscape : function ( expression ) {
if ( expression ) {
2015-11-18 20:34:26 +03:00
return expression . replace ( /[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~]/g , '\\$&' ) ;
}
return null ;
} ,
/* Copied from http://stackoverflow.com/questions/2631001/javascript-test-for-existence-of-nested-object-key */
2015-12-03 14:28:52 +03:00
checkNested : function ( cobj /*, level1, level2, ... levelN*/ ) {
2015-11-18 20:34:26 +03:00
var args = Array . prototype . slice . call ( arguments ) ,
obj = args . shift ( ) ;
for ( var i = 0 ; i < args . length ; i ++ ) {
if ( ! obj || ! obj . hasOwnProperty ( args [ i ] ) ) {
return false ;
}
obj = obj [ args [ i ] ] ;
}
return true ;
}
2015-11-18 14:12:32 +03:00
} ;