2019-09-25 19:19:42 +03:00
|
|
|
/* eslint-disable */
|
2019-04-29 19:16:15 +03:00
|
|
|
/*
|
|
|
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-11-03 11:22:59 +03:00
|
|
|
* @copyright Copyright (c) 2019 Gary Kim <gary@garykim.dev>
|
2019-04-29 19:16:15 +03:00
|
|
|
*
|
|
|
|
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-11-03 11:22:59 +03:00
|
|
|
* @author Gary Kim <gary@garykim.dev>
|
2012-02-29 02:02:02 +04:00
|
|
|
*
|
2019-04-29 19:16:15 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
2012-02-29 02:02:02 +04:00
|
|
|
*
|
2019-04-29 19:16:15 +03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2012-02-29 02:02:02 +04:00
|
|
|
*
|
2019-04-29 19:16:15 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2012-02-29 02:02:02 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-04-29 19:16:15 +03:00
|
|
|
* GNU Affero General Public License for more details.
|
2012-02-29 02:02:02 +04:00
|
|
|
*
|
2019-04-29 19:16:15 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2012-02-29 02:02:02 +04:00
|
|
|
*/
|
|
|
|
|
2019-04-29 19:16:15 +03:00
|
|
|
import _ from 'underscore'
|
|
|
|
import $ from 'jquery'
|
|
|
|
|
|
|
|
import OC from './index'
|
|
|
|
import OCA from '../OCA/index'
|
2014-04-04 13:52:15 +04:00
|
|
|
|
2012-02-29 02:02:02 +04:00
|
|
|
/**
|
2012-05-05 15:48:12 +04:00
|
|
|
* this class to ease the usage of jquery dialogs
|
2012-02-29 02:02:02 +04:00
|
|
|
*/
|
2019-04-29 19:16:15 +03:00
|
|
|
const Dialogs = {
|
2013-05-17 09:14:43 +04:00
|
|
|
// dialog button types
|
2019-04-29 19:16:15 +03:00
|
|
|
YES_NO_BUTTONS: 70,
|
|
|
|
OK_BUTTONS: 71,
|
2017-08-27 18:39:22 +03:00
|
|
|
|
|
|
|
FILEPICKER_TYPE_CHOOSE: 1,
|
|
|
|
FILEPICKER_TYPE_MOVE: 2,
|
|
|
|
FILEPICKER_TYPE_COPY: 3,
|
|
|
|
FILEPICKER_TYPE_COPY_MOVE: 4,
|
2019-09-25 15:55:13 +03:00
|
|
|
FILEPICKER_TYPE_CUSTOM: 5,
|
2017-08-27 18:39:22 +03:00
|
|
|
|
2013-05-17 09:14:43 +04:00
|
|
|
// used to name each dialog
|
2014-04-14 21:29:00 +04:00
|
|
|
dialogsCounter: 0,
|
2019-09-25 19:19:42 +03:00
|
|
|
|
2012-05-05 15:48:12 +04:00
|
|
|
/**
|
2019-04-29 19:16:15 +03:00
|
|
|
* displays alert dialog
|
2019-09-25 19:19:42 +03:00
|
|
|
* @param {string} text content of dialog
|
|
|
|
* @param {string} title dialog title
|
|
|
|
* @param {function} callback which will be triggered when user presses OK
|
|
|
|
* @param {boolean} [modal] make the dialog modal
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
alert: function(text, title, callback, modal) {
|
2014-03-01 05:46:27 +04:00
|
|
|
this.message(
|
|
|
|
text,
|
|
|
|
title,
|
|
|
|
'alert',
|
2019-04-29 19:16:15 +03:00
|
|
|
Dialogs.OK_BUTTON,
|
2014-03-01 05:46:27 +04:00
|
|
|
callback,
|
|
|
|
modal
|
2019-09-25 19:19:42 +03:00
|
|
|
)
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
|
|
|
/**
|
2019-04-29 19:16:15 +03:00
|
|
|
* displays info dialog
|
2019-09-25 19:19:42 +03:00
|
|
|
* @param {string} text content of dialog
|
|
|
|
* @param {string} title dialog title
|
|
|
|
* @param {function} callback which will be triggered when user presses OK
|
|
|
|
* @param {boolean} [modal] make the dialog modal
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
info: function(text, title, callback, modal) {
|
|
|
|
this.message(text, title, 'info', Dialogs.OK_BUTTON, callback, modal)
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
|
2012-05-05 15:48:12 +04:00
|
|
|
/**
|
2019-04-29 19:16:15 +03:00
|
|
|
* displays confirmation dialog
|
2019-09-25 19:19:42 +03:00
|
|
|
* @param {string} text content of dialog
|
|
|
|
* @param {string} title dialog title
|
|
|
|
* @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively)
|
|
|
|
* @param {boolean} [modal] make the dialog modal
|
|
|
|
* @returns {Promise}
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
confirm: function(text, title, callback, modal) {
|
2014-07-03 16:38:40 +04:00
|
|
|
return this.message(
|
2014-03-01 05:46:27 +04:00
|
|
|
text,
|
|
|
|
title,
|
|
|
|
'notice',
|
2019-04-29 19:16:15 +03:00
|
|
|
Dialogs.YES_NO_BUTTONS,
|
2014-03-01 05:46:27 +04:00
|
|
|
callback,
|
|
|
|
modal
|
2019-09-25 19:19:42 +03:00
|
|
|
)
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
2019-11-03 11:22:59 +03:00
|
|
|
/**
|
|
|
|
* displays confirmation dialog
|
|
|
|
* @param {string} text content of dialog
|
|
|
|
* @param {string} title dialog title
|
|
|
|
* @param {{type: Int, confirm: String, cancel: String, confirmClasses: String}} buttons text content of buttons
|
|
|
|
* @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively)
|
|
|
|
* @param {boolean} [modal] make the dialog modal
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
confirmDestructive: function(text, title, buttons, callback, modal) {
|
|
|
|
return this.message(
|
|
|
|
text,
|
|
|
|
title,
|
|
|
|
'none',
|
|
|
|
buttons,
|
|
|
|
callback,
|
2020-06-15 17:43:18 +03:00
|
|
|
modal === undefined ? true : modal
|
2019-11-03 11:22:59 +03:00
|
|
|
)
|
|
|
|
},
|
2016-10-31 14:22:21 +03:00
|
|
|
/**
|
2019-04-29 19:16:15 +03:00
|
|
|
* displays confirmation dialog
|
2019-09-25 19:19:42 +03:00
|
|
|
* @param {string} text content of dialog
|
|
|
|
* @param {string} title dialog title
|
|
|
|
* @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively)
|
|
|
|
* @param {boolean} [modal] make the dialog modal
|
|
|
|
* @returns {Promise}
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
confirmHtml: function(text, title, callback, modal) {
|
2016-10-31 14:22:21 +03:00
|
|
|
return this.message(
|
|
|
|
text,
|
|
|
|
title,
|
|
|
|
'notice',
|
2019-04-29 19:16:15 +03:00
|
|
|
Dialogs.YES_NO_BUTTONS,
|
2016-10-31 14:22:21 +03:00
|
|
|
callback,
|
|
|
|
modal,
|
|
|
|
true
|
2019-09-25 19:19:42 +03:00
|
|
|
)
|
2016-10-31 14:22:21 +03:00
|
|
|
},
|
2014-05-09 19:09:06 +04:00
|
|
|
/**
|
|
|
|
* displays prompt dialog
|
2019-09-25 19:19:42 +03:00
|
|
|
* @param {string} text content of dialog
|
|
|
|
* @param {string} title dialog title
|
|
|
|
* @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively)
|
|
|
|
* @param {boolean} [modal] make the dialog modal
|
|
|
|
* @param {string} name name of the input field
|
|
|
|
* @param {boolean} password whether the input should be a password input
|
|
|
|
* @returns {Promise}
|
2014-05-09 19:09:06 +04:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
prompt: function(text, title, callback, modal, name, password) {
|
|
|
|
return $.when(this._getMessageTemplate()).then(function($tmpl) {
|
|
|
|
var dialogName = 'oc-dialog-' + Dialogs.dialogsCounter + '-content'
|
|
|
|
var dialogId = '#' + dialogName
|
2014-05-09 19:09:06 +04:00
|
|
|
var $dlg = $tmpl.octemplate({
|
|
|
|
dialog_name: dialogName,
|
2019-04-29 19:16:15 +03:00
|
|
|
title: title,
|
|
|
|
message: text,
|
|
|
|
type: 'notice'
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
var input = $('<input/>')
|
|
|
|
input.attr('type', password ? 'password' : 'text').attr('id', dialogName + '-input').attr('placeholder', name)
|
|
|
|
var label = $('<label/>').attr('for', dialogName + '-input').text(name + ': ')
|
|
|
|
$dlg.append(label)
|
|
|
|
$dlg.append(input)
|
2014-05-09 19:09:06 +04:00
|
|
|
if (modal === undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
modal = false
|
2014-05-09 19:09:06 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$('body').append($dlg)
|
2016-12-09 12:47:40 +03:00
|
|
|
|
|
|
|
// wrap callback in _.once():
|
|
|
|
// only call callback once and not twice (button handler and close
|
|
|
|
// event) but call it for the close event, if ESC or the x is hit
|
|
|
|
if (callback !== undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
callback = _.once(callback)
|
2016-12-09 12:47:40 +03:00
|
|
|
}
|
|
|
|
|
2014-07-03 16:38:40 +04:00
|
|
|
var buttonlist = [{
|
2019-04-29 19:16:15 +03:00
|
|
|
text: t('core', 'No'),
|
2019-09-25 19:19:42 +03:00
|
|
|
click: function() {
|
2019-04-29 19:16:15 +03:00
|
|
|
if (callback !== undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
// eslint-disable-next-line standard/no-callback-literal
|
|
|
|
callback(false, input.val())
|
2014-07-03 16:38:40 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).ocdialog('close')
|
2014-05-09 19:09:06 +04:00
|
|
|
}
|
2019-04-29 19:16:15 +03:00
|
|
|
}, {
|
|
|
|
text: t('core', 'Yes'),
|
2019-09-25 19:19:42 +03:00
|
|
|
click: function() {
|
2019-04-29 19:16:15 +03:00
|
|
|
if (callback !== undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
// eslint-disable-next-line standard/no-callback-literal
|
|
|
|
callback(true, input.val())
|
2019-04-29 19:16:15 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).ocdialog('close')
|
2019-04-29 19:16:15 +03:00
|
|
|
},
|
|
|
|
defaultButton: true
|
2019-09-25 19:19:42 +03:00
|
|
|
}]
|
2014-05-09 19:09:06 +04:00
|
|
|
|
|
|
|
$(dialogId).ocdialog({
|
|
|
|
closeOnEscape: true,
|
2019-04-29 19:16:15 +03:00
|
|
|
modal: modal,
|
|
|
|
buttons: buttonlist,
|
2019-09-25 19:19:42 +03:00
|
|
|
close: function() {
|
2016-12-09 12:47:40 +03:00
|
|
|
// callback is already fired if Yes/No is clicked directly
|
|
|
|
if (callback !== undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
// eslint-disable-next-line standard/no-callback-literal
|
|
|
|
callback(false, input.val())
|
2016-12-09 12:47:40 +03:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
input.focus()
|
|
|
|
Dialogs.dialogsCounter++
|
|
|
|
})
|
2014-05-09 19:09:06 +04:00
|
|
|
},
|
2013-04-06 12:07:12 +04:00
|
|
|
/**
|
|
|
|
* show a file picker to pick a file from
|
2018-08-30 15:40:12 +03:00
|
|
|
*
|
|
|
|
* In order to pick several types of mime types they need to be passed as an
|
|
|
|
* array of strings.
|
|
|
|
*
|
|
|
|
* When no mime type filter is given only files can be selected. In order to
|
|
|
|
* be able to select both files and folders "['*', 'httpd/unix-directory']"
|
|
|
|
* should be used instead.
|
|
|
|
*
|
2019-09-25 19:19:42 +03:00
|
|
|
* @param {string} title dialog title
|
|
|
|
* @param {function} callback which will be triggered when user presses Choose
|
|
|
|
* @param {boolean} [multiselect] whether it should be possible to select multiple files
|
|
|
|
* @param {string[]} [mimetypeFilter] mimetype to filter by - directories will always be included
|
|
|
|
* @param {boolean} [modal] make the dialog modal
|
|
|
|
* @param {string} [type] Type of file picker : Choose, copy, move, copy and move
|
|
|
|
* @param {string} [path] path to the folder that the the file can be picket from
|
|
|
|
* @param {Object} [options] additonal options that need to be set
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
filepicker: function(title, callback, multiselect, mimetypeFilter, modal, type, path, options) {
|
|
|
|
var self = this
|
2018-11-08 15:30:39 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
this.filepicker.sortField = 'name'
|
|
|
|
this.filepicker.sortOrder = 'asc'
|
2014-06-20 15:39:46 +04:00
|
|
|
// avoid opening the picker twice
|
|
|
|
if (this.filepicker.loading) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2014-06-20 15:39:46 +04:00
|
|
|
}
|
2017-08-27 18:39:22 +03:00
|
|
|
|
|
|
|
if (type === undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
type = this.FILEPICKER_TYPE_CHOOSE
|
2017-08-27 18:39:22 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var emptyText = t('core', 'No files in here')
|
|
|
|
var newText = t('files', 'New folder')
|
2018-07-31 23:49:01 +03:00
|
|
|
if (type === this.FILEPICKER_TYPE_COPY || type === this.FILEPICKER_TYPE_MOVE || type === this.FILEPICKER_TYPE_COPY_MOVE) {
|
2019-09-25 19:19:42 +03:00
|
|
|
emptyText = t('core', 'No more subfolders in here')
|
2018-07-31 23:49:01 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
this.filepicker.loading = true
|
|
|
|
this.filepicker.filesClient = (OCA.Sharing && OCA.Sharing.PublicApp && OCA.Sharing.PublicApp.fileList) ? OCA.Sharing.PublicApp.fileList.filesClient : OC.Files.getClient()
|
2018-10-23 11:38:00 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
this.filelist = null
|
|
|
|
path = path || ''
|
2019-08-21 17:59:49 +03:00
|
|
|
options = Object.assign({
|
|
|
|
allowDirectoryChooser: false
|
|
|
|
}, options)
|
2018-12-20 16:34:26 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$.when(this._getFilePickerTemplate()).then(function($tmpl) {
|
|
|
|
self.filepicker.loading = false
|
|
|
|
var dialogName = 'oc-dialog-filepicker-content'
|
2019-04-29 19:16:15 +03:00
|
|
|
if (self.$filePicker) {
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$filePicker.ocdialog('close')
|
2013-05-17 06:54:08 +04:00
|
|
|
}
|
2018-08-30 15:23:47 +03:00
|
|
|
|
|
|
|
if (mimetypeFilter === undefined || mimetypeFilter === null) {
|
2019-09-25 19:19:42 +03:00
|
|
|
mimetypeFilter = []
|
2018-08-30 15:23:47 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
if (typeof (mimetypeFilter) === 'string') {
|
|
|
|
mimetypeFilter = [mimetypeFilter]
|
2018-08-30 15:23:47 +03:00
|
|
|
}
|
|
|
|
|
2013-05-17 06:54:08 +04:00
|
|
|
self.$filePicker = $tmpl.octemplate({
|
2014-04-14 21:29:00 +04:00
|
|
|
dialog_name: dialogName,
|
2016-10-21 17:35:55 +03:00
|
|
|
title: title,
|
2018-12-20 16:34:26 +03:00
|
|
|
emptytext: emptyText,
|
2019-03-22 12:22:07 +03:00
|
|
|
newtext: newText,
|
|
|
|
nameCol: t('core', 'Name'),
|
|
|
|
sizeCol: t('core', 'Size'),
|
|
|
|
modifiedCol: t('core', 'Modified')
|
2019-08-21 17:59:49 +03:00
|
|
|
}).data('path', path).data('multiselect', multiselect).data('mimetype', mimetypeFilter).data('allowDirectoryChooser', options.allowDirectoryChooser)
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2013-08-01 20:44:01 +04:00
|
|
|
if (modal === undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
modal = false
|
2013-08-01 20:44:01 +04:00
|
|
|
}
|
|
|
|
if (multiselect === undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
multiselect = false
|
2013-08-01 20:44:01 +04:00
|
|
|
}
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2018-11-30 17:15:52 +03:00
|
|
|
// No grid for IE!
|
2018-11-05 19:27:09 +03:00
|
|
|
if (OC.Util.isIE()) {
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$filePicker.find('#picker-view-toggle').remove()
|
|
|
|
self.$filePicker.find('#picker-filestable').removeClass('view-grid')
|
2018-11-05 19:27:09 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$('body').append(self.$filePicker)
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$showGridView = $('input#picker-showgridview')
|
|
|
|
self.$showGridView.on('change', _.bind(self._onGridviewChange, self))
|
2018-10-23 11:38:00 +03:00
|
|
|
|
2018-11-05 19:27:09 +03:00
|
|
|
if (!OC.Util.isIE()) {
|
2019-09-25 19:19:42 +03:00
|
|
|
self._getGridSettings()
|
2018-11-05 19:27:09 +03:00
|
|
|
}
|
2018-10-23 11:38:00 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var newButton = self.$filePicker.find('.actions.creatable .button-add')
|
2020-02-19 13:34:18 +03:00
|
|
|
if (type === self.FILEPICKER_TYPE_CHOOSE && !options.allowDirectoryChooser) {
|
2019-09-25 19:19:42 +03:00
|
|
|
newButton.hide()
|
2019-03-28 15:06:06 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
newButton.on('focus', function() {
|
|
|
|
self.$filePicker.ocdialog('setEnterCallback', function() {
|
|
|
|
event.stopImmediatePropagation()
|
|
|
|
event.preventDefault()
|
|
|
|
newButton.click()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
newButton.on('blur', function() {
|
|
|
|
self.$filePicker.ocdialog('unsetEnterCallback')
|
|
|
|
})
|
|
|
|
|
|
|
|
OC.registerMenu(newButton, self.$filePicker.find('.menu'), function() {
|
|
|
|
$input.focus()
|
|
|
|
self.$filePicker.ocdialog('setEnterCallback', function() {
|
|
|
|
event.stopImmediatePropagation()
|
|
|
|
event.preventDefault()
|
2020-02-19 13:58:04 +03:00
|
|
|
self.$filePicker.submit()
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
var newName = $input.val()
|
|
|
|
var lastPos = newName.lastIndexOf('.')
|
2018-12-20 16:34:26 +03:00
|
|
|
if (lastPos === -1) {
|
2019-09-25 19:19:42 +03:00
|
|
|
lastPos = newName.length
|
2018-12-20 16:34:26 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$input.selectRange(0, lastPos)
|
|
|
|
})
|
|
|
|
var $form = self.$filePicker.find('.filenameform')
|
|
|
|
var $input = $form.find('input[type=\'text\']')
|
|
|
|
var $submit = $form.find('input[type=\'submit\']')
|
|
|
|
$submit.on('click', function(event) {
|
|
|
|
event.stopImmediatePropagation()
|
|
|
|
event.preventDefault()
|
|
|
|
$form.submit()
|
|
|
|
})
|
|
|
|
|
2020-02-19 14:42:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the given file name is valid.
|
|
|
|
*
|
|
|
|
* @param name file name to check
|
|
|
|
* @return true if the file name is valid.
|
|
|
|
* @throws a string exception with an error message if
|
|
|
|
* the file name is not valid
|
|
|
|
*
|
|
|
|
* NOTE: This function is duplicated in the files app:
|
|
|
|
* https://github.com/nextcloud/server/blob/b9bc2417e7a8dc81feb0abe20359bedaf864f790/apps/files/js/files.js#L127-L148
|
|
|
|
*/
|
|
|
|
var isFileNameValid = function (name) {
|
|
|
|
var trimmedName = name.trim();
|
|
|
|
if (trimmedName === '.' || trimmedName === '..')
|
|
|
|
{
|
|
|
|
throw t('files', '"{name}" is an invalid file name.', {name: name})
|
|
|
|
} else if (trimmedName.length === 0) {
|
|
|
|
throw t('files', 'File name cannot be empty.')
|
|
|
|
} else if (trimmedName.indexOf('/') !== -1) {
|
|
|
|
throw t('files', '"/" is not allowed inside a file name.')
|
|
|
|
} else if (!!(trimmedName.match(OC.config.blacklist_files_regex))) {
|
|
|
|
throw t('files', '"{name}" is not an allowed filetype', {name: name})
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var checkInput = function() {
|
|
|
|
var filename = $input.val()
|
2018-12-20 16:34:26 +03:00
|
|
|
try {
|
2020-02-19 14:42:54 +03:00
|
|
|
if (!isFileNameValid(filename)) {
|
|
|
|
// isFileNameValid(filename) throws an exception itself
|
2019-09-25 19:19:42 +03:00
|
|
|
} else if (self.filelist.find(function(file) {
|
|
|
|
return file.name === this
|
2019-04-29 19:16:15 +03:00
|
|
|
}, filename)) {
|
2019-09-25 19:19:42 +03:00
|
|
|
throw t('files', '{newName} already exists', { newName: filename }, undefined, {
|
2018-12-20 16:34:26 +03:00
|
|
|
escape: false
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2018-12-20 16:34:26 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
return true
|
2018-12-20 16:34:26 +03:00
|
|
|
}
|
|
|
|
} catch (error) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$input.attr('title', error)
|
2019-04-29 19:16:15 +03:00
|
|
|
$input.tooltip({
|
|
|
|
placement: 'right',
|
|
|
|
trigger: 'manual',
|
|
|
|
'container': '.newFolderMenu'
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
$input.tooltip('fixTitle')
|
|
|
|
$input.tooltip('show')
|
|
|
|
$input.addClass('error')
|
2018-12-20 16:34:26 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return false
|
|
|
|
}
|
2018-12-20 16:34:26 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$form.on('submit', function(event) {
|
|
|
|
event.stopPropagation()
|
|
|
|
event.preventDefault()
|
2018-12-20 16:34:26 +03:00
|
|
|
|
2019-04-29 19:16:15 +03:00
|
|
|
if (checkInput()) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var newname = $input.val()
|
2018-12-20 16:34:26 +03:00
|
|
|
self.filepicker.filesClient.createDirectory(self.$filePicker.data('path') + "/" + newname).always(function (status) {
|
2019-09-25 19:19:42 +03:00
|
|
|
self._fillFilePicker(self.$filePicker.data('path') + "/" + newname)
|
|
|
|
})
|
|
|
|
OC.hideMenus()
|
|
|
|
self.$filePicker.ocdialog('unsetEnterCallback')
|
|
|
|
self.$filePicker.click()
|
|
|
|
$input.val(newText)
|
2018-12-20 16:34:26 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
$input.keypress(function(event) {
|
2018-12-31 21:10:41 +03:00
|
|
|
if (event.keyCode === 13 || event.which === 13) {
|
2019-09-25 19:19:42 +03:00
|
|
|
event.stopImmediatePropagation()
|
|
|
|
event.preventDefault()
|
|
|
|
$form.submit()
|
2018-12-20 16:34:26 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
self.$filePicker.ready(function() {
|
|
|
|
self.$fileListHeader = self.$filePicker.find('.filelist thead tr')
|
|
|
|
self.$filelist = self.$filePicker.find('.filelist tbody')
|
|
|
|
self.$filelistContainer = self.$filePicker.find('.filelist-container')
|
|
|
|
self.$dirTree = self.$filePicker.find('.dirtree')
|
|
|
|
self.$dirTree.on('click', 'div:not(:last-child)', self, function(event) {
|
|
|
|
self._handleTreeListSelect(event, type)
|
|
|
|
})
|
|
|
|
self.$filelist.on('click', 'tr', function(event) {
|
|
|
|
self._handlePickerClick(event, $(this), type)
|
|
|
|
})
|
|
|
|
self.$fileListHeader.on('click', 'a', function(event) {
|
|
|
|
var dir = self.$filePicker.data('path')
|
|
|
|
self.filepicker.sortField = $(event.currentTarget).data('sort')
|
|
|
|
self.filepicker.sortOrder = self.filepicker.sortOrder === 'asc' ? 'desc' : 'asc'
|
|
|
|
self._fillFilePicker(dir)
|
|
|
|
})
|
|
|
|
self._fillFilePicker(path)
|
|
|
|
})
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2013-05-16 02:23:05 +04:00
|
|
|
// build buttons
|
2019-09-25 19:19:42 +03:00
|
|
|
var functionToCall = function(returnType) {
|
2013-05-16 02:23:05 +04:00
|
|
|
if (callback !== undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var datapath
|
2013-05-16 02:23:05 +04:00
|
|
|
if (multiselect === true) {
|
2019-09-25 19:19:42 +03:00
|
|
|
datapath = []
|
|
|
|
self.$filelist.find('tr.filepicker_element_selected').each(function(index, element) {
|
|
|
|
datapath.push(self.$filePicker.data('path') + '/' + $(element).data('entryname'))
|
|
|
|
})
|
2013-05-16 02:23:05 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
datapath = self.$filePicker.data('path')
|
|
|
|
var selectedName = self.$filelist.find('tr.filepicker_element_selected').data('entryname')
|
2016-10-20 16:42:57 +03:00
|
|
|
if (selectedName) {
|
2019-09-25 19:19:42 +03:00
|
|
|
datapath += '/' + selectedName
|
2016-10-20 16:42:57 +03:00
|
|
|
}
|
2013-05-16 02:23:05 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
callback(datapath, returnType)
|
|
|
|
self.$filePicker.ocdialog('close')
|
2012-05-05 15:48:12 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|
2017-08-27 18:39:22 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var chooseCallback = function() {
|
|
|
|
functionToCall(Dialogs.FILEPICKER_TYPE_CHOOSE)
|
|
|
|
}
|
2017-08-27 18:39:22 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var copyCallback = function() {
|
|
|
|
functionToCall(Dialogs.FILEPICKER_TYPE_COPY)
|
|
|
|
}
|
2017-08-27 18:39:22 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var moveCallback = function() {
|
|
|
|
functionToCall(Dialogs.FILEPICKER_TYPE_MOVE)
|
|
|
|
}
|
2017-08-27 18:39:22 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var buttonlist = []
|
2019-04-29 19:16:15 +03:00
|
|
|
if (type === Dialogs.FILEPICKER_TYPE_CHOOSE) {
|
2017-08-27 18:39:22 +03:00
|
|
|
buttonlist.push({
|
|
|
|
text: t('core', 'Choose'),
|
|
|
|
click: chooseCallback,
|
|
|
|
defaultButton: true
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2019-09-25 15:55:13 +03:00
|
|
|
} else if (type === Dialogs.FILEPICKER_TYPE_CUSTOM) {
|
|
|
|
options.buttons.forEach(function(button) {
|
|
|
|
buttonlist.push({
|
|
|
|
text: button.text,
|
|
|
|
click: function() {
|
|
|
|
functionToCall(button.type)
|
|
|
|
},
|
|
|
|
defaultButton: button.defaultButton
|
|
|
|
})
|
|
|
|
})
|
2017-08-27 18:39:22 +03:00
|
|
|
} else {
|
2019-04-29 19:16:15 +03:00
|
|
|
if (type === Dialogs.FILEPICKER_TYPE_COPY || type === Dialogs.FILEPICKER_TYPE_COPY_MOVE) {
|
2017-08-27 18:39:22 +03:00
|
|
|
buttonlist.push({
|
|
|
|
text: t('core', 'Copy'),
|
|
|
|
click: copyCallback,
|
|
|
|
defaultButton: false
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2017-08-27 18:39:22 +03:00
|
|
|
}
|
2019-04-29 19:16:15 +03:00
|
|
|
if (type === Dialogs.FILEPICKER_TYPE_MOVE || type === Dialogs.FILEPICKER_TYPE_COPY_MOVE) {
|
2017-08-27 18:39:22 +03:00
|
|
|
buttonlist.push({
|
|
|
|
text: t('core', 'Move'),
|
|
|
|
click: moveCallback,
|
|
|
|
defaultButton: true
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2017-08-27 18:39:22 +03:00
|
|
|
}
|
|
|
|
}
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2013-06-02 23:52:59 +04:00
|
|
|
self.$filePicker.ocdialog({
|
2013-05-17 09:14:43 +04:00
|
|
|
closeOnEscape: true,
|
2015-05-06 12:15:48 +03:00
|
|
|
// max-width of 600
|
2016-11-28 16:05:46 +03:00
|
|
|
width: 600,
|
|
|
|
height: 500,
|
2013-05-16 02:23:05 +04:00
|
|
|
modal: modal,
|
2013-05-17 06:54:08 +04:00
|
|
|
buttons: buttonlist,
|
2017-08-27 18:39:22 +03:00
|
|
|
style: {
|
2019-09-25 19:19:42 +03:00
|
|
|
buttons: 'aside'
|
2017-08-27 18:39:22 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
close: function() {
|
2013-06-03 05:19:35 +04:00
|
|
|
try {
|
2019-09-25 19:19:42 +03:00
|
|
|
$(this).ocdialog('destroy').remove()
|
2019-04-29 19:16:15 +03:00
|
|
|
} catch (e) {
|
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$filePicker = null
|
2013-05-17 06:54:08 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2016-08-22 15:21:47 +03:00
|
|
|
|
|
|
|
// We can access primary class only from oc-dialog.
|
|
|
|
// Hence this is one of the approach to get the choose button.
|
2019-09-25 19:19:42 +03:00
|
|
|
var getOcDialog = self.$filePicker.closest('.oc-dialog')
|
|
|
|
var buttonEnableDisable = getOcDialog.find('.primary')
|
2019-10-29 14:22:15 +03:00
|
|
|
if (self.$filePicker.data('mimetype').indexOf('httpd/unix-directory') !== -1 || self.$filePicker.data('allowDirectoryChooser')) {
|
2019-09-25 19:19:42 +03:00
|
|
|
buttonEnableDisable.prop('disabled', false)
|
2016-10-17 14:08:55 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
buttonEnableDisable.prop('disabled', true)
|
2016-10-17 14:08:55 +03:00
|
|
|
}
|
2013-05-16 02:23:05 +04:00
|
|
|
})
|
2019-09-25 19:19:42 +03:00
|
|
|
.fail(function(status, error) {
|
2019-04-29 19:16:15 +03:00
|
|
|
// If the method is called while navigating away
|
|
|
|
// from the page, it is probably not needed ;)
|
2019-09-25 19:19:42 +03:00
|
|
|
self.filepicker.loading = false
|
2019-04-29 19:16:15 +03:00
|
|
|
if (status !== 0) {
|
2019-09-25 19:19:42 +03:00
|
|
|
alert(t('core', 'Error loading file picker template: {error}', { error: error }))
|
2019-04-29 19:16:15 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
2013-04-06 12:07:12 +04:00
|
|
|
/**
|
|
|
|
* Displays raw dialog
|
|
|
|
* You better use a wrapper instead ...
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
message: function(content, title, dialogType, buttons, callback, modal, allowHtml) {
|
|
|
|
return $.when(this._getMessageTemplate()).then(function($tmpl) {
|
|
|
|
var dialogName = 'oc-dialog-' + Dialogs.dialogsCounter + '-content'
|
|
|
|
var dialogId = '#' + dialogName
|
2013-05-16 02:23:05 +04:00
|
|
|
var $dlg = $tmpl.octemplate({
|
2014-04-14 21:29:00 +04:00
|
|
|
dialog_name: dialogName,
|
2013-05-16 02:23:05 +04:00
|
|
|
title: title,
|
|
|
|
message: content,
|
2014-04-14 21:29:00 +04:00
|
|
|
type: dialogType
|
2019-09-25 19:19:42 +03:00
|
|
|
}, allowHtml ? { escapeFunction: '' } : {})
|
2013-08-01 20:44:01 +04:00
|
|
|
if (modal === undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
modal = false
|
2013-08-01 20:44:01 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$('body').append($dlg)
|
|
|
|
var buttonlist = []
|
2013-05-16 02:23:05 +04:00
|
|
|
switch (buttons) {
|
2019-09-25 19:19:42 +03:00
|
|
|
case Dialogs.YES_NO_BUTTONS:
|
|
|
|
buttonlist = [{
|
|
|
|
text: t('core', 'No'),
|
|
|
|
click: function() {
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(false)
|
2014-04-14 21:29:00 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).ocdialog('close')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: t('core', 'Yes'),
|
|
|
|
click: function() {
|
2014-04-14 21:29:00 +04:00
|
|
|
if (callback !== undefined) {
|
2019-09-25 19:19:42 +03:00
|
|
|
callback(true)
|
2013-05-16 02:23:05 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).ocdialog('close')
|
|
|
|
},
|
|
|
|
defaultButton: true
|
|
|
|
}]
|
|
|
|
break
|
|
|
|
case Dialogs.OK_BUTTON:
|
|
|
|
var functionToCall = function() {
|
|
|
|
$(dialogId).ocdialog('close')
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buttonlist[0] = {
|
|
|
|
text: t('core', 'OK'),
|
|
|
|
click: functionToCall,
|
|
|
|
defaultButton: true
|
|
|
|
}
|
|
|
|
break
|
2019-11-03 11:22:59 +03:00
|
|
|
default:
|
|
|
|
if (typeof(buttons) === 'object') {
|
|
|
|
switch (buttons.type) {
|
|
|
|
case Dialogs.YES_NO_BUTTONS:
|
|
|
|
buttonlist = [{
|
|
|
|
text: buttons.cancel || t('core', 'No'),
|
|
|
|
click: function() {
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(false)
|
|
|
|
}
|
|
|
|
$(dialogId).ocdialog('close')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: buttons.confirm || t('core', 'Yes'),
|
|
|
|
click: function() {
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(true)
|
|
|
|
}
|
|
|
|
$(dialogId).ocdialog('close')
|
|
|
|
},
|
|
|
|
defaultButton: true,
|
|
|
|
classes: buttons.confirmClasses
|
|
|
|
}]
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
2013-07-31 23:21:02 +04:00
|
|
|
}
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2014-04-14 21:29:00 +04:00
|
|
|
$(dialogId).ocdialog({
|
2013-05-17 09:14:43 +04:00
|
|
|
closeOnEscape: true,
|
2013-05-16 02:23:05 +04:00
|
|
|
modal: modal,
|
|
|
|
buttons: buttonlist
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
Dialogs.dialogsCounter++
|
2013-05-16 02:23:05 +04:00
|
|
|
})
|
2019-09-25 19:19:42 +03:00
|
|
|
.fail(function(status, error) {
|
2019-04-29 19:16:15 +03:00
|
|
|
// If the method is called while navigating away from
|
|
|
|
// the page, we still want to deliver the message.
|
|
|
|
if (status === 0) {
|
2019-09-25 19:19:42 +03:00
|
|
|
alert(title + ': ' + content)
|
2019-04-29 19:16:15 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
alert(t('core', 'Error loading message template: {error}', { error: error }))
|
2019-04-29 19:16:15 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2013-08-12 14:33:22 +04:00
|
|
|
},
|
2013-08-22 16:29:00 +04:00
|
|
|
_fileexistsshown: false,
|
2013-08-12 14:33:22 +04:00
|
|
|
/**
|
|
|
|
* Displays file exists dialog
|
2013-08-22 16:29:00 +04:00
|
|
|
* @param {object} data upload object
|
|
|
|
* @param {object} original file with name, size and mtime
|
|
|
|
* @param {object} replacement file with name, size and mtime
|
|
|
|
* @param {object} controller with onCancel, onSkip, onReplace and onRename methods
|
2019-09-25 19:19:42 +03:00
|
|
|
* @returns {Promise} jquery promise that resolves after the dialog template was loaded
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
fileexists: function(data, original, replacement, controller) {
|
|
|
|
var self = this
|
|
|
|
var dialogDeferred = new $.Deferred()
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var getCroppedPreview = function(file) {
|
|
|
|
var deferred = new $.Deferred()
|
2013-09-07 16:52:56 +04:00
|
|
|
// Only process image files.
|
2019-09-25 19:19:42 +03:00
|
|
|
var type = file.type && file.type.split('/').shift()
|
2013-09-07 16:52:56 +04:00
|
|
|
if (window.FileReader && type === 'image') {
|
2019-09-25 19:19:42 +03:00
|
|
|
var reader = new FileReader()
|
|
|
|
reader.onload = function(e) {
|
|
|
|
var blob = new Blob([e.target.result])
|
|
|
|
window.URL = window.URL || window.webkitURL
|
|
|
|
var originalUrl = window.URL.createObjectURL(blob)
|
|
|
|
var image = new Image()
|
|
|
|
image.src = originalUrl
|
|
|
|
image.onload = function() {
|
|
|
|
var url = crop(image)
|
|
|
|
deferred.resolve(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reader.readAsArrayBuffer(file)
|
2013-09-07 16:52:56 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
deferred.reject()
|
2013-09-07 16:52:56 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return deferred
|
|
|
|
}
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var crop = function(img) {
|
|
|
|
var canvas = document.createElement('canvas')
|
|
|
|
var targetSize = 96
|
|
|
|
var width = img.width
|
|
|
|
var height = img.height
|
|
|
|
var x; var y; var size
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2015-09-29 17:32:43 +03:00
|
|
|
// Calculate the width and height, constraining the proportions
|
2013-09-07 16:52:56 +04:00
|
|
|
if (width > height) {
|
2019-09-25 19:19:42 +03:00
|
|
|
y = 0
|
|
|
|
x = (width - height) / 2
|
2013-09-07 16:52:56 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
y = (height - width) / 2
|
|
|
|
x = 0
|
2013-09-07 16:52:56 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
size = Math.min(width, height)
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2015-09-29 17:32:43 +03:00
|
|
|
// Set canvas size to the cropped area
|
2019-09-25 19:19:42 +03:00
|
|
|
canvas.width = size
|
|
|
|
canvas.height = size
|
|
|
|
var ctx = canvas.getContext('2d')
|
|
|
|
ctx.drawImage(img, x, y, size, size, 0, 0, size, size)
|
2015-09-29 17:32:43 +03:00
|
|
|
|
|
|
|
// Resize the canvas to match the destination (right size uses 96px)
|
2019-09-25 19:19:42 +03:00
|
|
|
resampleHermite(canvas, size, size, targetSize, targetSize)
|
2015-09-29 17:32:43 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
return canvas.toDataURL('image/png', 0.7)
|
|
|
|
}
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2015-09-29 17:32:43 +03:00
|
|
|
/**
|
|
|
|
* Fast image resize/resample using Hermite filter with JavaScript.
|
|
|
|
*
|
|
|
|
* @author: ViliusL
|
|
|
|
*
|
|
|
|
* @param {*} canvas
|
|
|
|
* @param {number} W
|
|
|
|
* @param {number} H
|
|
|
|
* @param {number} W2
|
|
|
|
* @param {number} H2
|
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
var resampleHermite = function(canvas, W, H, W2, H2) {
|
|
|
|
W2 = Math.round(W2)
|
|
|
|
H2 = Math.round(H2)
|
|
|
|
var img = canvas.getContext('2d').getImageData(0, 0, W, H)
|
|
|
|
var img2 = canvas.getContext('2d').getImageData(0, 0, W2, H2)
|
|
|
|
var data = img.data
|
|
|
|
var data2 = img2.data
|
|
|
|
var ratio_w = W / W2
|
|
|
|
var ratio_h = H / H2
|
|
|
|
var ratio_w_half = Math.ceil(ratio_w / 2)
|
|
|
|
var ratio_h_half = Math.ceil(ratio_h / 2)
|
2015-09-29 17:32:43 +03:00
|
|
|
|
|
|
|
for (var j = 0; j < H2; j++) {
|
|
|
|
for (var i = 0; i < W2; i++) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var x2 = (i + j * W2) * 4
|
|
|
|
var weight = 0
|
|
|
|
var weights = 0
|
|
|
|
var weights_alpha = 0
|
|
|
|
var gx_r = 0
|
|
|
|
var gx_g = 0
|
|
|
|
var gx_b = 0
|
|
|
|
var gx_a = 0
|
|
|
|
var center_y = (j + 0.5) * ratio_h
|
2015-09-29 17:32:43 +03:00
|
|
|
for (var yy = Math.floor(j * ratio_h); yy < (j + 1) * ratio_h; yy++) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var dy = Math.abs(center_y - (yy + 0.5)) / ratio_h_half
|
|
|
|
var center_x = (i + 0.5) * ratio_w
|
|
|
|
var w0 = dy * dy // pre-calc part of w
|
2015-09-29 17:32:43 +03:00
|
|
|
for (var xx = Math.floor(i * ratio_w); xx < (i + 1) * ratio_w; xx++) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var dx = Math.abs(center_x - (xx + 0.5)) / ratio_w_half
|
|
|
|
var w = Math.sqrt(w0 + dx * dx)
|
2015-09-29 17:32:43 +03:00
|
|
|
if (w >= -1 && w <= 1) {
|
2019-09-25 19:19:42 +03:00
|
|
|
// hermite filter
|
|
|
|
weight = 2 * w * w * w - 3 * w * w + 1
|
2015-09-29 17:32:43 +03:00
|
|
|
if (weight > 0) {
|
2019-09-25 19:19:42 +03:00
|
|
|
dx = 4 * (xx + yy * W)
|
|
|
|
// alpha
|
|
|
|
gx_a += weight * data[dx + 3]
|
|
|
|
weights_alpha += weight
|
|
|
|
// colors
|
|
|
|
if (data[dx + 3] < 255) { weight = weight * data[dx + 3] / 250 }
|
|
|
|
gx_r += weight * data[dx]
|
|
|
|
gx_g += weight * data[dx + 1]
|
|
|
|
gx_b += weight * data[dx + 2]
|
|
|
|
weights += weight
|
2015-09-29 17:32:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
data2[x2] = gx_r / weights
|
|
|
|
data2[x2 + 1] = gx_g / weights
|
|
|
|
data2[x2 + 2] = gx_b / weights
|
|
|
|
data2[x2 + 3] = gx_a / weights_alpha
|
2015-09-29 17:32:43 +03:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
canvas.getContext('2d').clearRect(0, 0, Math.max(W, W2), Math.max(H, H2))
|
|
|
|
canvas.width = W2
|
|
|
|
canvas.height = H2
|
|
|
|
canvas.getContext('2d').putImageData(img2, 0, 0)
|
|
|
|
}
|
2015-09-29 17:32:43 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var addConflict = function($conflicts, original, replacement) {
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var $conflict = $conflicts.find('.template').clone().removeClass('template').addClass('conflict')
|
|
|
|
var $originalDiv = $conflict.find('.original')
|
|
|
|
var $replacementDiv = $conflict.find('.replacement')
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$conflict.data('data', data)
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$conflict.find('.filename').text(original.name)
|
2020-02-07 19:08:50 +03:00
|
|
|
$originalDiv.find('.size').text(OC.Util.humanFileSize(original.size))
|
2020-05-07 17:52:27 +03:00
|
|
|
$originalDiv.find('.mtime').text(OC.Util.formatDate(original.mtime))
|
2013-09-18 19:58:15 +04:00
|
|
|
// ie sucks
|
|
|
|
if (replacement.size && replacement.lastModifiedDate) {
|
2020-02-07 19:08:50 +03:00
|
|
|
$replacementDiv.find('.size').text(OC.Util.humanFileSize(replacement.size))
|
2020-05-07 17:52:27 +03:00
|
|
|
$replacementDiv.find('.mtime').text(OC.Util.formatDate(replacement.lastModifiedDate))
|
2013-09-18 19:58:15 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
var path = original.directory + '/' + original.name
|
2015-05-29 14:49:51 +03:00
|
|
|
var urlSpec = {
|
2019-04-29 19:16:15 +03:00
|
|
|
file: path,
|
|
|
|
x: 96,
|
|
|
|
y: 96,
|
|
|
|
c: original.etag,
|
|
|
|
forceIcon: 0
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|
|
|
|
var previewpath = Files.generatePreviewUrl(urlSpec)
|
2015-05-29 19:34:38 +03:00
|
|
|
// Escaping single quotes
|
2019-09-25 19:19:42 +03:00
|
|
|
previewpath = previewpath.replace(/'/g, '%27')
|
|
|
|
$originalDiv.find('.icon').css({ 'background-image': "url('" + previewpath + "')" })
|
2013-09-18 19:58:15 +04:00
|
|
|
getCroppedPreview(replacement).then(
|
2019-09-25 19:19:42 +03:00
|
|
|
function(path) {
|
|
|
|
$replacementDiv.find('.icon').css('background-image', 'url(' + path + ')')
|
|
|
|
}, function() {
|
|
|
|
path = OC.MimeType.getIconUrl(replacement.type)
|
|
|
|
$replacementDiv.find('.icon').css('background-image', 'url(' + path + ')')
|
2013-08-22 16:29:00 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
)
|
2015-09-19 16:44:49 +03:00
|
|
|
// connect checkboxes with labels
|
2019-09-25 19:19:42 +03:00
|
|
|
var checkboxId = $conflicts.find('.conflict').length
|
|
|
|
$originalDiv.find('input:checkbox').attr('id', 'checkbox_original_' + checkboxId)
|
|
|
|
$replacementDiv.find('input:checkbox').attr('id', 'checkbox_replacement_' + checkboxId)
|
2015-09-19 16:44:49 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$conflicts.append($conflict)
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
// set more recent mtime bold
|
2013-09-18 19:58:15 +04:00
|
|
|
// ie sucks
|
2014-05-21 15:19:02 +04:00
|
|
|
if (replacement.lastModifiedDate && replacement.lastModifiedDate.getTime() > original.mtime) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$replacementDiv.find('.mtime').css('font-weight', 'bold')
|
2014-05-21 15:19:02 +04:00
|
|
|
} else if (replacement.lastModifiedDate && replacement.lastModifiedDate.getTime() < original.mtime) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$originalDiv.find('.mtime').css('font-weight', 'bold')
|
2013-09-18 19:58:15 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
// TODO add to same mtime collection?
|
2013-09-18 19:58:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// set bigger size bold
|
|
|
|
if (replacement.size && replacement.size > original.size) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$replacementDiv.find('.size').css('font-weight', 'bold')
|
2013-09-18 19:58:15 +04:00
|
|
|
} else if (replacement.size && replacement.size < original.size) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$originalDiv.find('.size').css('font-weight', 'bold')
|
2013-09-18 19:58:15 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
// TODO add to same size collection?
|
2013-09-18 19:58:15 +04:00
|
|
|
}
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
// TODO show skip action for files with same size and mtime in bottom row
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2014-12-08 17:26:31 +03:00
|
|
|
// always keep readonly files
|
|
|
|
|
|
|
|
if (original.status === 'readonly') {
|
|
|
|
$originalDiv
|
|
|
|
.addClass('readonly')
|
|
|
|
.find('input[type="checkbox"]')
|
2019-04-29 19:16:15 +03:00
|
|
|
.prop('checked', true)
|
2019-09-25 19:19:42 +03:00
|
|
|
.prop('disabled', true)
|
2014-12-08 17:26:31 +03:00
|
|
|
$originalDiv.find('.message')
|
2019-09-25 19:19:42 +03:00
|
|
|
.text(t('core', 'read-only'))
|
2014-12-08 17:26:31 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|
|
|
|
// var selection = controller.getSelection(data.originalFiles);
|
|
|
|
// if (selection.defaultAction) {
|
2013-09-07 00:40:10 +04:00
|
|
|
// controller[selection.defaultAction](data);
|
2019-09-25 19:19:42 +03:00
|
|
|
// } else {
|
|
|
|
var dialogName = 'oc-dialog-fileexists-content'
|
|
|
|
var dialogId = '#' + dialogName
|
2014-04-14 21:29:00 +04:00
|
|
|
if (this._fileexistsshown) {
|
|
|
|
// add conflict
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var $conflicts = $(dialogId + ' .conflicts')
|
|
|
|
addConflict($conflicts, original, replacement)
|
2014-04-14 21:29:00 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var count = $(dialogId + ' .conflict').length
|
2014-04-14 21:29:00 +04:00
|
|
|
var title = n('core',
|
2019-04-29 19:16:15 +03:00
|
|
|
'{count} file conflict',
|
|
|
|
'{count} file conflicts',
|
|
|
|
count,
|
2019-09-25 19:19:42 +03:00
|
|
|
{ count: count }
|
|
|
|
)
|
|
|
|
$(dialogId).parent().children('.oc-dialog-title').text(title)
|
2014-04-14 21:29:00 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
// recalculate dimensions
|
|
|
|
$(window).trigger('resize')
|
|
|
|
dialogDeferred.resolve()
|
2014-04-14 21:29:00 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
// create dialog
|
|
|
|
this._fileexistsshown = true
|
|
|
|
$.when(this._getFileExistsTemplate()).then(function($tmpl) {
|
|
|
|
var title = t('core', 'One file conflict')
|
2014-04-14 21:29:00 +04:00
|
|
|
var $dlg = $tmpl.octemplate({
|
|
|
|
dialog_name: dialogName,
|
|
|
|
title: title,
|
|
|
|
type: 'fileexists',
|
|
|
|
|
2019-04-29 19:16:15 +03:00
|
|
|
allnewfiles: t('core', 'New Files'),
|
|
|
|
allexistingfiles: t('core', 'Already existing files'),
|
2014-04-14 21:29:00 +04:00
|
|
|
|
2019-04-29 19:16:15 +03:00
|
|
|
why: t('core', 'Which files do you want to keep?'),
|
|
|
|
what: t('core', 'If you select both versions, the copied file will have a number added to its name.')
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
$('body').append($dlg)
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2015-10-02 10:55:43 +03:00
|
|
|
if (original && replacement) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var $conflicts = $dlg.find('.conflicts')
|
|
|
|
addConflict($conflicts, original, replacement)
|
2015-10-02 10:55:43 +03:00
|
|
|
}
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2014-04-14 21:29:00 +04:00
|
|
|
var buttonlist = [{
|
2019-04-29 19:16:15 +03:00
|
|
|
text: t('core', 'Cancel'),
|
|
|
|
classes: 'cancel',
|
2019-09-25 19:19:42 +03:00
|
|
|
click: function() {
|
2019-04-29 19:16:15 +03:00
|
|
|
if (typeof controller.onCancel !== 'undefined') {
|
2019-09-25 19:19:42 +03:00
|
|
|
controller.onCancel(data)
|
2014-04-14 21:29:00 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).ocdialog('close')
|
2019-04-29 19:16:15 +03:00
|
|
|
}
|
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
{
|
|
|
|
text: t('core', 'Continue'),
|
|
|
|
classes: 'continue',
|
|
|
|
click: function() {
|
|
|
|
if (typeof controller.onContinue !== 'undefined') {
|
|
|
|
controller.onContinue($(dialogId + ' .conflict'))
|
2014-04-14 21:29:00 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).ocdialog('close')
|
|
|
|
}
|
|
|
|
}]
|
2014-04-14 21:29:00 +04:00
|
|
|
|
|
|
|
$(dialogId).ocdialog({
|
|
|
|
width: 500,
|
|
|
|
closeOnEscape: true,
|
|
|
|
modal: true,
|
|
|
|
buttons: buttonlist,
|
|
|
|
closeButton: null,
|
2019-09-25 19:19:42 +03:00
|
|
|
close: function() {
|
|
|
|
self._fileexistsshown = false
|
|
|
|
$(this).ocdialog('destroy').remove()
|
2019-04-29 19:16:15 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).css('height', 'auto')
|
2013-08-12 14:33:22 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var $primaryButton = $dlg.closest('.oc-dialog').find('button.continue')
|
|
|
|
$primaryButton.prop('disabled', true)
|
2015-10-08 13:27:33 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
function updatePrimaryButton() {
|
|
|
|
var checkedCount = $dlg.find('.conflicts .checkbox:checked').length
|
|
|
|
$primaryButton.prop('disabled', checkedCount === 0)
|
2015-10-08 13:27:33 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
// add checkbox toggling actions
|
|
|
|
$(dialogId).find('.allnewfiles').on('click', function() {
|
|
|
|
var $checkboxes = $(dialogId).find('.conflict .replacement input[type="checkbox"]')
|
|
|
|
$checkboxes.prop('checked', $(this).prop('checked'))
|
|
|
|
})
|
|
|
|
$(dialogId).find('.allexistingfiles').on('click', function() {
|
|
|
|
var $checkboxes = $(dialogId).find('.conflict .original:not(.readonly) input[type="checkbox"]')
|
|
|
|
$checkboxes.prop('checked', $(this).prop('checked'))
|
|
|
|
})
|
|
|
|
$(dialogId).find('.conflicts').on('click', '.replacement,.original:not(.readonly)', function() {
|
|
|
|
var $checkbox = $(this).find('input[type="checkbox"]')
|
|
|
|
$checkbox.prop('checked', !$checkbox.prop('checked'))
|
|
|
|
})
|
|
|
|
$(dialogId).find('.conflicts').on('click', '.replacement input[type="checkbox"],.original:not(.readonly) input[type="checkbox"]', function() {
|
|
|
|
var $checkbox = $(this)
|
|
|
|
$checkbox.prop('checked', !$checkbox.prop('checked'))
|
|
|
|
})
|
|
|
|
|
|
|
|
// update counters
|
|
|
|
$(dialogId).on('click', '.replacement,.allnewfiles', function() {
|
|
|
|
var count = $(dialogId).find('.conflict .replacement input[type="checkbox"]:checked').length
|
2019-04-29 19:16:15 +03:00
|
|
|
if (count === $(dialogId + ' .conflict').length) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).find('.allnewfiles').prop('checked', true)
|
|
|
|
$(dialogId).find('.allnewfiles + .count').text(t('core', '(all selected)'))
|
2014-04-14 21:29:00 +04:00
|
|
|
} else if (count > 0) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).find('.allnewfiles').prop('checked', false)
|
|
|
|
$(dialogId).find('.allnewfiles + .count').text(t('core', '({count} selected)', { count: count }))
|
2014-04-14 21:29:00 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).find('.allnewfiles').prop('checked', false)
|
|
|
|
$(dialogId).find('.allnewfiles + .count').text('')
|
2014-04-14 21:29:00 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
updatePrimaryButton()
|
|
|
|
})
|
|
|
|
$(dialogId).on('click', '.original,.allexistingfiles', function() {
|
|
|
|
var count = $(dialogId).find('.conflict .original input[type="checkbox"]:checked').length
|
2019-04-29 19:16:15 +03:00
|
|
|
if (count === $(dialogId + ' .conflict').length) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).find('.allexistingfiles').prop('checked', true)
|
|
|
|
$(dialogId).find('.allexistingfiles + .count').text(t('core', '(all selected)'))
|
2014-04-14 21:29:00 +04:00
|
|
|
} else if (count > 0) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).find('.allexistingfiles').prop('checked', false)
|
2014-04-14 21:29:00 +04:00
|
|
|
$(dialogId).find('.allexistingfiles + .count')
|
2019-09-25 19:19:42 +03:00
|
|
|
.text(t('core', '({count} selected)', { count: count }))
|
2014-04-14 21:29:00 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
$(dialogId).find('.allexistingfiles').prop('checked', false)
|
|
|
|
$(dialogId).find('.allexistingfiles + .count').text('')
|
2014-04-14 21:29:00 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
updatePrimaryButton()
|
|
|
|
})
|
2015-10-08 13:27:33 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
dialogDeferred.resolve()
|
2014-04-14 21:29:00 +04:00
|
|
|
})
|
2019-09-25 19:19:42 +03:00
|
|
|
.fail(function() {
|
|
|
|
dialogDeferred.reject()
|
|
|
|
alert(t('core', 'Error loading file exists template'))
|
|
|
|
})
|
2014-04-14 21:29:00 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
// }
|
|
|
|
return dialogDeferred.promise()
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
2018-10-23 11:38:00 +03:00
|
|
|
// get the gridview setting and set the input accordingly
|
2019-09-25 19:19:42 +03:00
|
|
|
_getGridSettings: function() {
|
|
|
|
var self = this
|
|
|
|
$.get(OC.generateUrl('/apps/files/api/v1/showgridview'), function(response) {
|
|
|
|
self.$showGridView.get(0).checked = response.gridview
|
2018-10-23 11:38:00 +03:00
|
|
|
self.$showGridView.next('#picker-view-toggle')
|
|
|
|
.removeClass('icon-toggle-filelist icon-toggle-pictures')
|
|
|
|
.addClass(response.gridview ? 'icon-toggle-filelist' : 'icon-toggle-pictures')
|
2019-09-25 19:19:42 +03:00
|
|
|
$('.list-container').toggleClass('view-grid', response.gridview)
|
|
|
|
})
|
2018-10-23 11:38:00 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
_onGridviewChange: function() {
|
|
|
|
var show = this.$showGridView.is(':checked')
|
2018-10-23 11:38:00 +03:00
|
|
|
// only save state if user is logged in
|
|
|
|
if (OC.currentUser) {
|
|
|
|
$.post(OC.generateUrl('/apps/files/api/v1/showgridview'), {
|
|
|
|
show: show
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2018-10-23 11:38:00 +03:00
|
|
|
}
|
|
|
|
this.$showGridView.next('#picker-view-toggle')
|
|
|
|
.removeClass('icon-toggle-filelist icon-toggle-pictures')
|
|
|
|
.addClass(show ? 'icon-toggle-filelist' : 'icon-toggle-pictures')
|
2019-09-25 19:19:42 +03:00
|
|
|
$('.list-container').toggleClass('view-grid', show)
|
2018-10-23 11:38:00 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
_getFilePickerTemplate: function() {
|
|
|
|
var defer = $.Deferred()
|
2019-04-29 19:16:15 +03:00
|
|
|
if (!this.$filePickerTemplate) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var self = this
|
|
|
|
$.get(OC.filePath('core', 'templates', 'filepicker.html'), function(tmpl) {
|
|
|
|
self.$filePickerTemplate = $(tmpl)
|
|
|
|
self.$listTmpl = self.$filePickerTemplate.find('.filelist tbody tr:first-child').detach()
|
|
|
|
defer.resolve(self.$filePickerTemplate)
|
2013-05-17 10:42:15 +04:00
|
|
|
})
|
2019-09-25 19:19:42 +03:00
|
|
|
.fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
|
defer.reject(jqXHR.status, errorThrown)
|
|
|
|
})
|
2013-05-17 10:42:15 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
defer.resolve(this.$filePickerTemplate)
|
2013-05-17 10:42:15 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return defer.promise()
|
2013-05-17 10:42:15 +04:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
_getMessageTemplate: function() {
|
|
|
|
var defer = $.Deferred()
|
2019-04-29 19:16:15 +03:00
|
|
|
if (!this.$messageTemplate) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var self = this
|
|
|
|
$.get(OC.filePath('core', 'templates', 'message.html'), function(tmpl) {
|
|
|
|
self.$messageTemplate = $(tmpl)
|
|
|
|
defer.resolve(self.$messageTemplate)
|
2013-05-17 10:42:15 +04:00
|
|
|
})
|
2019-09-25 19:19:42 +03:00
|
|
|
.fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
|
defer.reject(jqXHR.status, errorThrown)
|
|
|
|
})
|
2013-05-17 10:42:15 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
defer.resolve(this.$messageTemplate)
|
2013-05-17 10:42:15 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return defer.promise()
|
2013-05-17 10:42:15 +04:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
_getFileExistsTemplate: function() {
|
|
|
|
var defer = $.Deferred()
|
2013-08-12 14:33:22 +04:00
|
|
|
if (!this.$fileexistsTemplate) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var self = this
|
|
|
|
$.get(OC.filePath('files', 'templates', 'fileexists.html'), function(tmpl) {
|
|
|
|
self.$fileexistsTemplate = $(tmpl)
|
|
|
|
defer.resolve(self.$fileexistsTemplate)
|
2013-08-12 14:33:22 +04:00
|
|
|
})
|
2019-09-25 19:19:42 +03:00
|
|
|
.fail(function() {
|
|
|
|
defer.reject()
|
|
|
|
})
|
2013-08-12 14:33:22 +04:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
defer.resolve(this.$fileexistsTemplate)
|
2013-08-12 14:33:22 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return defer.promise()
|
2013-08-12 14:33:22 +04:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
_getFileList: function(dir, mimeType) { // this is only used by the spreedme app atm
|
|
|
|
if (typeof (mimeType) === 'string') {
|
|
|
|
mimeType = [mimeType]
|
2013-09-05 18:54:12 +04:00
|
|
|
}
|
2013-09-05 20:40:55 +04:00
|
|
|
|
2013-05-17 10:42:15 +04:00
|
|
|
return $.getJSON(
|
2013-10-28 23:22:06 +04:00
|
|
|
OC.filePath('files', 'ajax', 'list.php'),
|
2013-09-05 20:40:55 +04:00
|
|
|
{
|
|
|
|
dir: dir,
|
|
|
|
mimetypes: JSON.stringify(mimeType)
|
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
)
|
2013-05-17 10:42:15 +04:00
|
|
|
},
|
2013-04-06 12:07:12 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* fills the filepicker with files
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
_fillFilePicker: function(dir) {
|
|
|
|
var self = this
|
|
|
|
this.$filelist.empty()
|
|
|
|
this.$filePicker.find('.emptycontent').hide()
|
|
|
|
this.$filelistContainer.addClass('icon-loading')
|
|
|
|
this.$filePicker.data('path', dir)
|
|
|
|
var filter = this.$filePicker.data('mimetype')
|
|
|
|
if (typeof (filter) === 'string') {
|
|
|
|
filter = [filter]
|
2016-10-17 14:35:59 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$fileListHeader.find('.sort-indicator').addClass('hidden').removeClass('icon-triangle-n').removeClass('icon-triangle-s')
|
|
|
|
self.$fileListHeader.find('[data-sort=' + self.filepicker.sortField + '] .sort-indicator').removeClass('hidden')
|
2018-11-08 15:30:39 +03:00
|
|
|
if (self.filepicker.sortOrder === 'asc') {
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$fileListHeader.find('[data-sort=' + self.filepicker.sortField + '] .sort-indicator').addClass('icon-triangle-n')
|
2018-11-08 15:32:10 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$fileListHeader.find('[data-sort=' + self.filepicker.sortField + '] .sort-indicator').addClass('icon-triangle-s')
|
2018-11-08 15:30:39 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
self.filepicker.filesClient.getFolderContents(dir).then(function(status, files) {
|
|
|
|
self.filelist = files
|
2018-08-30 15:40:12 +03:00
|
|
|
if (filter && filter.length > 0 && filter.indexOf('*') === -1) {
|
2019-09-25 19:19:42 +03:00
|
|
|
files = files.filter(function(file) {
|
|
|
|
return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1
|
|
|
|
})
|
2016-10-19 15:22:33 +03:00
|
|
|
}
|
2018-11-08 15:30:39 +03:00
|
|
|
|
|
|
|
var Comparators = {
|
2019-09-25 19:19:42 +03:00
|
|
|
name: function(fileInfo1, fileInfo2) {
|
2018-11-08 15:30:39 +03:00
|
|
|
if (fileInfo1.type === 'dir' && fileInfo2.type !== 'dir') {
|
2019-09-25 19:19:42 +03:00
|
|
|
return -1
|
2018-11-08 15:30:39 +03:00
|
|
|
}
|
|
|
|
if (fileInfo1.type !== 'dir' && fileInfo2.type === 'dir') {
|
2019-09-25 19:19:42 +03:00
|
|
|
return 1
|
2018-11-08 15:30:39 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return OC.Util.naturalSortCompare(fileInfo1.name, fileInfo2.name)
|
2018-11-08 15:30:39 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
size: function(fileInfo1, fileInfo2) {
|
|
|
|
return fileInfo1.size - fileInfo2.size
|
2018-11-08 15:30:39 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
mtime: function(fileInfo1, fileInfo2) {
|
|
|
|
return fileInfo1.mtime - fileInfo2.mtime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var comparator = Comparators[self.filepicker.sortField] || Comparators.name
|
|
|
|
files = files.sort(function(file1, file2) {
|
|
|
|
var isFavorite = function(fileInfo) {
|
|
|
|
return fileInfo.tags && fileInfo.tags.indexOf(OC.TAG_FAVORITE) >= 0
|
2018-11-08 15:30:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isFavorite(file1) && !isFavorite(file2)) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return -1
|
2018-11-08 15:30:39 +03:00
|
|
|
} else if (!isFavorite(file1) && isFavorite(file2)) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return 1
|
2013-05-17 06:54:08 +04:00
|
|
|
}
|
2018-11-08 15:30:39 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
return self.filepicker.sortOrder === 'asc' ? comparator(file1, file2) : -comparator(file1, file2)
|
|
|
|
})
|
2013-05-16 02:23:05 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
self._fillSlug()
|
2013-05-16 02:23:05 +04:00
|
|
|
|
2016-10-21 17:35:55 +03:00
|
|
|
if (files.length === 0) {
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$filePicker.find('.emptycontent').show()
|
|
|
|
self.$fileListHeader.hide()
|
2016-10-21 17:35:55 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$filePicker.find('.emptycontent').hide()
|
|
|
|
self.$fileListHeader.show()
|
2016-10-21 17:35:55 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$.each(files, function(idx, entry) {
|
|
|
|
entry.icon = OC.MimeType.getIconUrl(entry.mimetype)
|
|
|
|
var simpleSize, sizeColor
|
2019-04-29 19:16:15 +03:00
|
|
|
if (typeof (entry.size) !== 'undefined' && entry.size >= 0) {
|
2020-02-07 19:08:50 +03:00
|
|
|
simpleSize = OC.Util.humanFileSize(parseInt(entry.size, 10), true)
|
2019-09-25 19:19:42 +03:00
|
|
|
sizeColor = Math.round(160 - Math.pow((entry.size / (1024 * 1024)), 2))
|
2016-10-17 15:26:25 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
simpleSize = t('files', 'Pending')
|
|
|
|
sizeColor = 80
|
2016-10-17 15:26:25 +03:00
|
|
|
}
|
2019-03-30 12:28:42 +03:00
|
|
|
|
|
|
|
// split the filename in half if the size is bigger than 20 char
|
|
|
|
// for ellipsis
|
|
|
|
if (entry.name.length >= 10) {
|
|
|
|
// leave maximum 10 letters
|
|
|
|
var split = Math.min(Math.floor(entry.name.length / 2), 10)
|
|
|
|
var filename1 = entry.name.substr(0, entry.name.length - split)
|
|
|
|
var filename2 = entry.name.substr(entry.name.length - split)
|
|
|
|
} else {
|
|
|
|
var filename1 = entry.name
|
|
|
|
var filename2 = ''
|
|
|
|
}
|
|
|
|
|
2016-10-17 15:26:25 +03:00
|
|
|
var $row = self.$listTmpl.octemplate({
|
2013-05-17 06:54:08 +04:00
|
|
|
type: entry.type,
|
|
|
|
dir: dir,
|
|
|
|
filename: entry.name,
|
2019-03-30 12:28:42 +03:00
|
|
|
filename1: filename1,
|
|
|
|
filename2: filename2,
|
2016-10-17 15:26:25 +03:00
|
|
|
date: OC.Util.relativeModifiedDate(entry.mtime),
|
|
|
|
size: simpleSize,
|
|
|
|
sizeColor: sizeColor,
|
|
|
|
icon: entry.icon
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2015-07-13 18:38:13 +03:00
|
|
|
if (entry.type === 'file') {
|
2013-10-28 23:22:06 +04:00
|
|
|
var urlSpec = {
|
2016-10-14 18:29:36 +03:00
|
|
|
file: dir + '/' + entry.name,
|
2018-10-23 11:04:03 +03:00
|
|
|
x: 100,
|
|
|
|
y: 100
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|
|
|
|
var img = new Image()
|
|
|
|
var previewUrl = OC.generateUrl('/core/preview.png?') + $.param(urlSpec)
|
|
|
|
img.onload = function() {
|
2016-10-14 18:29:36 +03:00
|
|
|
if (img.width > 5) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$row.find('td.filename').attr('style', 'background-image:url(' + previewUrl + ')')
|
2016-10-14 18:29:36 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|
|
|
|
img.src = previewUrl
|
2013-10-28 23:22:06 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$filelist.append($row)
|
|
|
|
})
|
2013-04-06 21:21:15 +04:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
self.$filelistContainer.removeClass('icon-loading')
|
|
|
|
})
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
2013-04-06 12:07:12 +04:00
|
|
|
/**
|
|
|
|
* fills the tree list with directories
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
_fillSlug: function() {
|
2020-03-27 15:31:50 +03:00
|
|
|
var addButton = this.$dirTree.find('.actions.creatable').detach()
|
2019-09-25 19:19:42 +03:00
|
|
|
this.$dirTree.empty()
|
|
|
|
var self = this
|
2020-03-27 15:31:50 +03:00
|
|
|
|
|
|
|
self.$dirTree.append(addButton)
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var dir
|
|
|
|
var path = this.$filePicker.data('path')
|
|
|
|
var $template = $('<div data-dir="{dir}"><a>{name}</a></div>').addClass('crumb')
|
2019-04-29 19:16:15 +03:00
|
|
|
if (path) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var paths = path.split('/')
|
|
|
|
$.each(paths, function(index, dir) {
|
|
|
|
dir = paths.pop()
|
2019-04-29 19:16:15 +03:00
|
|
|
if (dir === '') {
|
2019-09-25 19:19:42 +03:00
|
|
|
return false
|
2013-05-17 09:14:43 +04:00
|
|
|
}
|
|
|
|
self.$dirTree.prepend($template.octemplate({
|
|
|
|
dir: paths.join('/') + '/' + dir,
|
|
|
|
name: dir
|
2019-09-25 19:19:42 +03:00
|
|
|
}))
|
|
|
|
})
|
2013-05-17 09:14:43 +04:00
|
|
|
}
|
2020-03-27 15:31:50 +03:00
|
|
|
|
2013-05-17 18:18:40 +04:00
|
|
|
$template.octemplate({
|
2013-05-17 06:54:08 +04:00
|
|
|
dir: '',
|
2016-10-14 18:31:10 +03:00
|
|
|
name: '' // Ugly but works ;)
|
2019-09-25 19:19:42 +03:00
|
|
|
}, { escapeFunction: null }).prependTo(this.$dirTree)
|
2020-06-15 17:43:18 +03:00
|
|
|
|
2013-04-06 12:07:12 +04:00
|
|
|
},
|
2013-04-06 18:44:13 +04:00
|
|
|
/**
|
|
|
|
* handle selection made in the tree list
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
_handleTreeListSelect: function(event, type) {
|
|
|
|
var self = event.data
|
|
|
|
var dir = $(event.target).closest('.crumb').data('dir')
|
|
|
|
self._fillFilePicker(dir)
|
|
|
|
var getOcDialog = (event.target).closest('.oc-dialog')
|
|
|
|
var buttonEnableDisable = $('.primary', getOcDialog)
|
|
|
|
this._changeButtonsText(type, dir.split(/[/]+/).pop())
|
2019-10-29 14:22:15 +03:00
|
|
|
if (this.$filePicker.data('mimetype').indexOf('httpd/unix-directory') !== -1 || this.$filePicker.data('allowDirectoryChooser')) {
|
2019-09-25 19:19:42 +03:00
|
|
|
buttonEnableDisable.prop('disabled', false)
|
2016-09-07 16:17:52 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
buttonEnableDisable.prop('disabled', true)
|
2016-09-07 16:17:52 +03:00
|
|
|
}
|
2013-04-06 12:07:12 +04:00
|
|
|
},
|
2013-04-06 18:44:13 +04:00
|
|
|
/**
|
|
|
|
* handle clicks made in the filepicker
|
2019-04-29 19:16:15 +03:00
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
_handlePickerClick: function(event, $element, type) {
|
|
|
|
var getOcDialog = this.$filePicker.closest('.oc-dialog')
|
|
|
|
var buttonEnableDisable = getOcDialog.find('.primary')
|
2013-05-17 06:54:08 +04:00
|
|
|
if ($element.data('type') === 'file') {
|
|
|
|
if (this.$filePicker.data('multiselect') !== true || !event.ctrlKey) {
|
2019-09-25 19:19:42 +03:00
|
|
|
this.$filelist.find('.filepicker_element_selected').removeClass('filepicker_element_selected')
|
2012-05-05 15:48:12 +04:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$element.toggleClass('filepicker_element_selected')
|
|
|
|
buttonEnableDisable.prop('disabled', false)
|
2019-04-29 19:16:15 +03:00
|
|
|
} else if ($element.data('type') === 'dir') {
|
2019-09-25 19:19:42 +03:00
|
|
|
this._fillFilePicker(this.$filePicker.data('path') + '/' + $element.data('entryname'))
|
|
|
|
this._changeButtonsText(type, $element.data('entryname'))
|
|
|
|
if (this.$filePicker.data('mimetype').indexOf('httpd/unix-directory') !== -1 || this.$filePicker.data('allowDirectoryChooser')) {
|
|
|
|
buttonEnableDisable.prop('disabled', false)
|
2016-09-07 16:17:52 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
buttonEnableDisable.prop('disabled', true)
|
2016-09-07 16:17:52 +03:00
|
|
|
}
|
2012-05-05 15:48:12 +04:00
|
|
|
}
|
2017-08-27 18:39:22 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle
|
|
|
|
* @param type of action
|
|
|
|
* @param dir on which to change buttons text
|
|
|
|
* @private
|
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
_changeButtonsText: function(type, dir) {
|
|
|
|
var copyText = dir === '' ? t('core', 'Copy') : t('core', 'Copy to {folder}', { folder: dir })
|
|
|
|
var moveText = dir === '' ? t('core', 'Move') : t('core', 'Move to {folder}', { folder: dir })
|
|
|
|
var buttons = $('.oc-dialog-buttonrow button')
|
2017-08-27 18:39:22 +03:00
|
|
|
switch (type) {
|
2019-09-25 15:55:13 +03:00
|
|
|
case this.FILEPICKER_TYPE_CHOOSE:
|
|
|
|
break
|
|
|
|
case this.FILEPICKER_TYPE_CUSTOM:
|
|
|
|
break
|
|
|
|
case this.FILEPICKER_TYPE_COPY:
|
|
|
|
buttons.text(copyText)
|
|
|
|
break
|
|
|
|
case this.FILEPICKER_TYPE_MOVE:
|
|
|
|
buttons.text(moveText)
|
|
|
|
break
|
|
|
|
case this.FILEPICKER_TYPE_COPY_MOVE:
|
|
|
|
buttons.eq(0).text(copyText)
|
|
|
|
buttons.eq(1).text(moveText)
|
|
|
|
break
|
2017-08-27 18:39:22 +03:00
|
|
|
}
|
2012-05-05 15:48:12 +04:00
|
|
|
}
|
2019-04-29 19:16:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Dialogs
|