2012-02-28 22:02:02 +00:00
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
2013-05-16 16:19:28 +00:00
|
|
|
* @author Bartek Przybylski, Christopher Schäpers, Thomas Tanghus
|
2012-03-24 17:35:16 +00:00
|
|
|
* @copyright 2012 Bartek Przybylski bartek@alefzero.eu
|
2012-02-28 22:02:02 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-07-03 12:38:40 +00:00
|
|
|
/* global alert */
|
2014-04-04 09:52:15 +00:00
|
|
|
|
2012-02-28 22:02:02 +00:00
|
|
|
/**
|
2012-05-05 11:48:12 +00:00
|
|
|
* this class to ease the usage of jquery dialogs
|
2014-06-23 21:56:10 +00:00
|
|
|
* @lends OC.dialogs
|
2012-02-28 22:02:02 +00:00
|
|
|
*/
|
2012-09-05 20:22:04 +00:00
|
|
|
var OCdialogs = {
|
2013-05-17 05:14:43 +00:00
|
|
|
// dialog button types
|
|
|
|
YES_NO_BUTTONS: 70,
|
|
|
|
OK_BUTTONS: 71,
|
|
|
|
// used to name each dialog
|
2014-04-14 17:29:00 +00:00
|
|
|
dialogsCounter: 0,
|
2012-05-05 11:48:12 +00:00
|
|
|
/**
|
|
|
|
* displays alert dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
2013-04-06 08:07:12 +00:00
|
|
|
* @param callback which will be triggered when user presses OK
|
|
|
|
* @param modal make the dialog modal
|
2012-05-05 11:48:12 +00:00
|
|
|
*/
|
|
|
|
alert:function(text, title, callback, modal) {
|
2014-03-01 01:46:27 +00:00
|
|
|
this.message(
|
|
|
|
text,
|
|
|
|
title,
|
|
|
|
'alert',
|
|
|
|
OCdialogs.OK_BUTTON,
|
|
|
|
callback,
|
|
|
|
modal
|
|
|
|
);
|
2012-05-05 11:48:12 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* displays info dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
2013-04-06 08:07:12 +00:00
|
|
|
* @param callback which will be triggered when user presses OK
|
|
|
|
* @param modal make the dialog modal
|
2012-05-05 11:48:12 +00:00
|
|
|
*/
|
|
|
|
info:function(text, title, callback, modal) {
|
2013-05-17 05:14:43 +00:00
|
|
|
this.message(text, title, 'info', OCdialogs.OK_BUTTON, callback, modal);
|
2012-05-05 11:48:12 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* displays confirmation dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
2014-04-14 17:29:00 +00:00
|
|
|
* @param callback which will be triggered when user presses YES or NO
|
|
|
|
* (true or false would be passed to callback respectively)
|
2013-04-06 08:07:12 +00:00
|
|
|
* @param modal make the dialog modal
|
2012-05-05 11:48:12 +00:00
|
|
|
*/
|
|
|
|
confirm:function(text, title, callback, modal) {
|
2014-07-03 12:38:40 +00:00
|
|
|
return this.message(
|
2014-03-01 01:46:27 +00:00
|
|
|
text,
|
|
|
|
title,
|
|
|
|
'notice',
|
|
|
|
OCdialogs.YES_NO_BUTTONS,
|
|
|
|
callback,
|
|
|
|
modal
|
|
|
|
);
|
2012-05-05 11:48:12 +00:00
|
|
|
},
|
2016-10-31 11:22:21 +00:00
|
|
|
/**
|
|
|
|
* displays confirmation dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
|
|
|
* @param callback which will be triggered when user presses YES or NO
|
|
|
|
* (true or false would be passed to callback respectively)
|
|
|
|
* @param modal make the dialog modal
|
|
|
|
*/
|
|
|
|
confirmHtml:function(text, title, callback, modal) {
|
|
|
|
return this.message(
|
|
|
|
text,
|
|
|
|
title,
|
|
|
|
'notice',
|
|
|
|
OCdialogs.YES_NO_BUTTONS,
|
|
|
|
callback,
|
|
|
|
modal,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
},
|
2014-05-09 15:09:06 +00:00
|
|
|
/**
|
|
|
|
* displays prompt dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
|
|
|
* @param callback which will be triggered when user presses YES or NO
|
|
|
|
* (true or false would be passed to callback respectively)
|
|
|
|
* @param modal make the dialog modal
|
|
|
|
* @param name name of the input field
|
2014-05-11 08:55:00 +00:00
|
|
|
* @param password whether the input should be a password input
|
2014-05-09 15:09:06 +00:00
|
|
|
*/
|
|
|
|
prompt: function (text, title, callback, modal, name, password) {
|
2014-07-03 12:38:40 +00:00
|
|
|
return $.when(this._getMessageTemplate()).then(function ($tmpl) {
|
2014-05-09 15:09:06 +00:00
|
|
|
var dialogName = 'oc-dialog-' + OCdialogs.dialogsCounter + '-content';
|
|
|
|
var dialogId = '#' + dialogName;
|
|
|
|
var $dlg = $tmpl.octemplate({
|
|
|
|
dialog_name: dialogName,
|
|
|
|
title : title,
|
|
|
|
message : text,
|
|
|
|
type : 'notice'
|
|
|
|
});
|
|
|
|
var input = $('<input/>');
|
|
|
|
input.attr('type', password ? 'password' : 'text').attr('id', dialogName + '-input');
|
|
|
|
var label = $('<label/>').attr('for', dialogName + '-input').text(name + ': ');
|
|
|
|
$dlg.append(label);
|
|
|
|
$dlg.append(input);
|
|
|
|
if (modal === undefined) {
|
|
|
|
modal = false;
|
|
|
|
}
|
|
|
|
$('body').append($dlg);
|
2016-12-09 09:47:40 +00: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) {
|
|
|
|
callback = _.once(callback);
|
|
|
|
}
|
|
|
|
|
2014-07-03 12:38:40 +00:00
|
|
|
var buttonlist = [{
|
|
|
|
text : t('core', 'No'),
|
|
|
|
click: function () {
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(false, input.val());
|
|
|
|
}
|
|
|
|
$(dialogId).ocdialog('close');
|
|
|
|
}
|
|
|
|
}, {
|
2014-05-09 15:09:06 +00:00
|
|
|
text : t('core', 'Yes'),
|
|
|
|
click : function () {
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(true, input.val());
|
|
|
|
}
|
|
|
|
$(dialogId).ocdialog('close');
|
|
|
|
},
|
|
|
|
defaultButton: true
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
$(dialogId).ocdialog({
|
|
|
|
closeOnEscape: true,
|
|
|
|
modal : modal,
|
2016-12-09 09:47:40 +00:00
|
|
|
buttons : buttonlist,
|
|
|
|
close : function() {
|
|
|
|
// callback is already fired if Yes/No is clicked directly
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(false, input.val());
|
|
|
|
}
|
|
|
|
}
|
2014-05-09 15:09:06 +00:00
|
|
|
});
|
2016-11-24 11:35:59 +00:00
|
|
|
input.focus();
|
2014-05-09 15:09:06 +00:00
|
|
|
OCdialogs.dialogsCounter++;
|
|
|
|
});
|
|
|
|
},
|
2013-04-06 08:07:12 +00:00
|
|
|
/**
|
|
|
|
* show a file picker to pick a file from
|
|
|
|
* @param title dialog title
|
|
|
|
* @param callback which will be triggered when user presses Choose
|
|
|
|
* @param multiselect whether it should be possible to select multiple files
|
2015-04-13 08:35:45 +00:00
|
|
|
* @param mimetypeFilter mimetype to filter by - directories will always be included
|
2013-04-06 08:07:12 +00:00
|
|
|
* @param modal make the dialog modal
|
|
|
|
*/
|
2014-04-14 17:29:00 +00:00
|
|
|
filepicker:function(title, callback, multiselect, mimetypeFilter, modal) {
|
2013-05-17 02:54:08 +00:00
|
|
|
var self = this;
|
2014-06-20 11:39:46 +00:00
|
|
|
// avoid opening the picker twice
|
|
|
|
if (this.filepicker.loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.filepicker.loading = true;
|
2016-11-25 18:23:17 +00:00
|
|
|
this.filepicker.filesClient = (OCA.Sharing && OCA.Sharing.PublicApp && OCA.Sharing.PublicApp.fileList)? OCA.Sharing.PublicApp.fileList.filesClient: OC.Files.getClient();
|
2013-05-15 22:23:05 +00:00
|
|
|
$.when(this._getFilePickerTemplate()).then(function($tmpl) {
|
2014-06-20 11:39:46 +00:00
|
|
|
self.filepicker.loading = false;
|
2014-04-14 17:29:00 +00:00
|
|
|
var dialogName = 'oc-dialog-filepicker-content';
|
2013-05-17 02:54:08 +00:00
|
|
|
if(self.$filePicker) {
|
2013-06-02 19:52:59 +00:00
|
|
|
self.$filePicker.ocdialog('close');
|
2013-05-17 02:54:08 +00:00
|
|
|
}
|
|
|
|
self.$filePicker = $tmpl.octemplate({
|
2014-04-14 17:29:00 +00:00
|
|
|
dialog_name: dialogName,
|
2016-10-21 14:35:55 +00:00
|
|
|
title: title,
|
|
|
|
emptytext: t('core', 'No files in here')
|
2014-04-14 17:29:00 +00:00
|
|
|
}).data('path', '').data('multiselect', multiselect).data('mimetype', mimetypeFilter);
|
2013-04-06 08:07:12 +00:00
|
|
|
|
2013-08-01 16:44:01 +00:00
|
|
|
if (modal === undefined) {
|
|
|
|
modal = false;
|
|
|
|
}
|
|
|
|
if (multiselect === undefined) {
|
|
|
|
multiselect = false;
|
|
|
|
}
|
2014-04-14 17:29:00 +00:00
|
|
|
if (mimetypeFilter === undefined) {
|
|
|
|
mimetypeFilter = '';
|
2013-08-01 16:44:01 +00:00
|
|
|
}
|
2013-04-06 08:07:12 +00:00
|
|
|
|
2013-05-17 02:54:08 +00:00
|
|
|
$('body').append(self.$filePicker);
|
2013-04-06 08:07:12 +00:00
|
|
|
|
2013-05-17 02:54:08 +00:00
|
|
|
self.$filePicker.ready(function() {
|
2016-10-17 12:26:25 +00:00
|
|
|
self.$filelist = self.$filePicker.find('.filelist tbody');
|
2013-05-17 02:54:08 +00:00
|
|
|
self.$dirTree = self.$filePicker.find('.dirtree');
|
2016-10-14 15:31:10 +00:00
|
|
|
self.$dirTree.on('click', 'div:not(:last-child)', self, self._handleTreeListSelect.bind(self));
|
2016-10-17 12:26:25 +00:00
|
|
|
self.$filelist.on('click', 'tr', function(event) {
|
2013-05-17 06:42:15 +00:00
|
|
|
self._handlePickerClick(event, $(this));
|
2013-05-15 22:23:05 +00:00
|
|
|
});
|
2013-05-17 06:42:15 +00:00
|
|
|
self._fillFilePicker('');
|
2013-09-02 21:53:45 +00:00
|
|
|
});
|
2013-04-06 08:07:12 +00:00
|
|
|
|
2013-05-15 22:23:05 +00:00
|
|
|
// build buttons
|
|
|
|
var functionToCall = function() {
|
|
|
|
if (callback !== undefined) {
|
|
|
|
var datapath;
|
|
|
|
if (multiselect === true) {
|
|
|
|
datapath = [];
|
2016-10-17 12:26:25 +00:00
|
|
|
self.$filelist.find('tr.filepicker_element_selected').each(function(index, element) {
|
|
|
|
datapath.push(self.$filePicker.data('path') + '/' + $(element).data('entryname'));
|
2013-05-15 22:23:05 +00:00
|
|
|
});
|
|
|
|
} else {
|
2013-07-31 19:21:02 +00:00
|
|
|
datapath = self.$filePicker.data('path');
|
2016-10-20 13:42:57 +00:00
|
|
|
var selectedName = self.$filelist.find('tr.filepicker_element_selected').data('entryname');
|
|
|
|
if (selectedName) {
|
|
|
|
datapath += '/' + selectedName;
|
|
|
|
}
|
2013-05-15 22:23:05 +00:00
|
|
|
}
|
|
|
|
callback(datapath);
|
2013-06-02 19:52:59 +00:00
|
|
|
self.$filePicker.ocdialog('close');
|
2012-05-05 11:48:12 +00:00
|
|
|
}
|
2013-05-15 22:23:05 +00:00
|
|
|
};
|
|
|
|
var buttonlist = [{
|
|
|
|
text: t('core', 'Choose'),
|
2013-06-03 01:31:33 +00:00
|
|
|
click: functionToCall,
|
|
|
|
defaultButton: true
|
2013-05-15 22:23:05 +00:00
|
|
|
}];
|
2013-04-06 08:07:12 +00:00
|
|
|
|
2013-06-02 19:52:59 +00:00
|
|
|
self.$filePicker.ocdialog({
|
2013-05-17 05:14:43 +00:00
|
|
|
closeOnEscape: true,
|
2015-05-06 09:15:48 +00:00
|
|
|
// max-width of 600
|
2016-11-28 13:05:46 +00:00
|
|
|
width: 600,
|
|
|
|
height: 500,
|
2013-05-15 22:23:05 +00:00
|
|
|
modal: modal,
|
2013-05-17 02:54:08 +00:00
|
|
|
buttons: buttonlist,
|
2014-04-14 17:29:00 +00:00
|
|
|
close: function() {
|
2013-06-03 01:19:35 +00:00
|
|
|
try {
|
|
|
|
$(this).ocdialog('destroy').remove();
|
|
|
|
} catch(e) {}
|
2013-05-17 02:54:08 +00:00
|
|
|
self.$filePicker = null;
|
|
|
|
}
|
2013-05-15 22:23:05 +00:00
|
|
|
});
|
2016-08-22 12:21:47 +00:00
|
|
|
|
|
|
|
// We can access primary class only from oc-dialog.
|
|
|
|
// Hence this is one of the approach to get the choose button.
|
|
|
|
var getOcDialog = self.$filePicker.closest('.oc-dialog');
|
|
|
|
var buttonEnableDisable = getOcDialog.find('.primary');
|
2016-10-17 11:08:55 +00:00
|
|
|
if (self.$filePicker.data('mimetype') === "httpd/unix-directory") {
|
|
|
|
buttonEnableDisable.prop("disabled", false);
|
|
|
|
} else {
|
|
|
|
buttonEnableDisable.prop("disabled", true);
|
|
|
|
}
|
2013-05-15 22:23:05 +00:00
|
|
|
})
|
2013-09-11 14:02:12 +00:00
|
|
|
.fail(function(status, error) {
|
|
|
|
// If the method is called while navigating away
|
|
|
|
// from the page, it is probably not needed ;)
|
2014-06-20 11:39:46 +00:00
|
|
|
self.filepicker.loading = false;
|
2013-09-11 19:15:32 +00:00
|
|
|
if(status !== 0) {
|
2013-09-11 14:02:12 +00:00
|
|
|
alert(t('core', 'Error loading file picker template: {error}', {error: error}));
|
|
|
|
}
|
2013-04-06 08:07:12 +00:00
|
|
|
});
|
2012-05-05 11:48:12 +00:00
|
|
|
},
|
2013-04-06 08:07:12 +00:00
|
|
|
/**
|
|
|
|
* Displays raw dialog
|
|
|
|
* You better use a wrapper instead ...
|
|
|
|
*/
|
2016-10-31 11:22:21 +00:00
|
|
|
message:function(content, title, dialogType, buttons, callback, modal, allowHtml) {
|
2014-07-03 12:38:40 +00:00
|
|
|
return $.when(this._getMessageTemplate()).then(function($tmpl) {
|
2014-04-14 17:29:00 +00:00
|
|
|
var dialogName = 'oc-dialog-' + OCdialogs.dialogsCounter + '-content';
|
|
|
|
var dialogId = '#' + dialogName;
|
2013-05-15 22:23:05 +00:00
|
|
|
var $dlg = $tmpl.octemplate({
|
2014-04-14 17:29:00 +00:00
|
|
|
dialog_name: dialogName,
|
2013-05-15 22:23:05 +00:00
|
|
|
title: title,
|
|
|
|
message: content,
|
2014-04-14 17:29:00 +00:00
|
|
|
type: dialogType
|
2016-10-31 11:22:21 +00:00
|
|
|
}, allowHtml ? {escapeFunction: ''} : {});
|
2013-08-01 16:44:01 +00:00
|
|
|
if (modal === undefined) {
|
|
|
|
modal = false;
|
|
|
|
}
|
2013-05-15 22:23:05 +00:00
|
|
|
$('body').append($dlg);
|
|
|
|
var buttonlist = [];
|
|
|
|
switch (buttons) {
|
2014-04-14 17:29:00 +00:00
|
|
|
case OCdialogs.YES_NO_BUTTONS:
|
|
|
|
buttonlist = [{
|
2014-07-03 12:38:40 +00:00
|
|
|
text: t('core', 'No'),
|
2014-04-14 17:29:00 +00:00
|
|
|
click: function(){
|
|
|
|
if (callback !== undefined) {
|
2014-07-03 12:38:40 +00:00
|
|
|
callback(false);
|
2014-04-14 17:29:00 +00:00
|
|
|
}
|
|
|
|
$(dialogId).ocdialog('close');
|
2014-07-03 12:38:40 +00:00
|
|
|
}
|
2014-04-14 17:29:00 +00:00
|
|
|
},
|
|
|
|
{
|
2014-07-03 12:38:40 +00:00
|
|
|
text: t('core', 'Yes'),
|
2014-04-14 17:29:00 +00:00
|
|
|
click: function(){
|
|
|
|
if (callback !== undefined) {
|
2014-07-03 12:38:40 +00:00
|
|
|
callback(true);
|
2013-05-15 22:23:05 +00:00
|
|
|
}
|
2014-04-14 17:29:00 +00:00
|
|
|
$(dialogId).ocdialog('close');
|
2014-07-03 12:38:40 +00:00
|
|
|
},
|
|
|
|
defaultButton: true
|
2014-04-14 17:29:00 +00:00
|
|
|
}];
|
2013-05-15 22:23:05 +00:00
|
|
|
break;
|
2014-04-14 17:29:00 +00:00
|
|
|
case OCdialogs.OK_BUTTON:
|
|
|
|
var functionToCall = function() {
|
|
|
|
$(dialogId).ocdialog('close');
|
|
|
|
if(callback !== undefined) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
buttonlist[0] = {
|
2017-04-18 07:53:02 +00:00
|
|
|
text: t('core', 'OK'),
|
2014-04-14 17:29:00 +00:00
|
|
|
click: functionToCall,
|
|
|
|
defaultButton: true
|
|
|
|
};
|
2013-05-15 22:23:05 +00:00
|
|
|
break;
|
2013-07-31 19:21:02 +00:00
|
|
|
}
|
2013-04-06 08:07:12 +00:00
|
|
|
|
2014-04-14 17:29:00 +00:00
|
|
|
$(dialogId).ocdialog({
|
2013-05-17 05:14:43 +00:00
|
|
|
closeOnEscape: true,
|
2013-05-15 22:23:05 +00:00
|
|
|
modal: modal,
|
|
|
|
buttons: buttonlist
|
|
|
|
});
|
2014-04-14 17:29:00 +00:00
|
|
|
OCdialogs.dialogsCounter++;
|
2013-05-15 22:23:05 +00:00
|
|
|
})
|
2013-09-11 14:02:12 +00:00
|
|
|
.fail(function(status, error) {
|
|
|
|
// If the method is called while navigating away from
|
|
|
|
// the page, we still want to deliver the message.
|
|
|
|
if(status === 0) {
|
|
|
|
alert(title + ': ' + content);
|
|
|
|
} else {
|
|
|
|
alert(t('core', 'Error loading message template: {error}', {error: error}));
|
|
|
|
}
|
2013-08-12 10:33:22 +00:00
|
|
|
});
|
|
|
|
},
|
2013-08-22 12:29:00 +00:00
|
|
|
_fileexistsshown: false,
|
2013-08-12 10:33:22 +00:00
|
|
|
/**
|
|
|
|
* Displays file exists dialog
|
2013-08-22 12:29:00 +00: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
|
2015-10-02 07:55:43 +00:00
|
|
|
* @return {Promise} jquery promise that resolves after the dialog template was loaded
|
2013-08-12 10:33:22 +00:00
|
|
|
*/
|
|
|
|
fileexists:function(data, original, replacement, controller) {
|
2013-08-22 12:29:00 +00:00
|
|
|
var self = this;
|
2015-10-02 07:55:43 +00:00
|
|
|
var dialogDeferred = new $.Deferred();
|
2013-09-07 12:52:56 +00:00
|
|
|
|
|
|
|
var getCroppedPreview = function(file) {
|
|
|
|
var deferred = new $.Deferred();
|
|
|
|
// Only process image files.
|
2013-10-10 13:54:00 +00:00
|
|
|
var type = file.type && file.type.split('/').shift();
|
2013-09-07 12:52:56 +00:00
|
|
|
if (window.FileReader && type === 'image') {
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function (e) {
|
2013-09-19 07:47:51 +00:00
|
|
|
var blob = new Blob([e.target.result]);
|
2013-09-07 12:52:56 +00:00
|
|
|
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);
|
2014-04-14 17:29:00 +00:00
|
|
|
};
|
2013-09-07 12:52:56 +00:00
|
|
|
};
|
|
|
|
reader.readAsArrayBuffer(file);
|
|
|
|
} else {
|
|
|
|
deferred.reject();
|
|
|
|
}
|
|
|
|
return deferred;
|
|
|
|
};
|
|
|
|
|
|
|
|
var crop = function(img) {
|
|
|
|
var canvas = document.createElement('canvas'),
|
2015-09-29 14:32:43 +00:00
|
|
|
targetSize = 96,
|
|
|
|
width = img.width,
|
|
|
|
height = img.height,
|
|
|
|
x, y, size;
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2015-09-29 14:32:43 +00:00
|
|
|
// Calculate the width and height, constraining the proportions
|
2013-09-07 12:52:56 +00:00
|
|
|
if (width > height) {
|
|
|
|
y = 0;
|
|
|
|
x = (width - height) / 2;
|
|
|
|
} else {
|
|
|
|
y = (height - width) / 2;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
size = Math.min(width, height);
|
|
|
|
|
2015-09-29 14:32:43 +00:00
|
|
|
// Set canvas size to the cropped area
|
|
|
|
canvas.width = size;
|
|
|
|
canvas.height = size;
|
2013-09-07 12:52:56 +00:00
|
|
|
var ctx = canvas.getContext("2d");
|
2015-09-29 14:32:43 +00:00
|
|
|
ctx.drawImage(img, x, y, size, size, 0, 0, size, size);
|
|
|
|
|
|
|
|
// Resize the canvas to match the destination (right size uses 96px)
|
|
|
|
resampleHermite(canvas, size, size, targetSize, targetSize);
|
|
|
|
|
2013-09-07 12:52:56 +00:00
|
|
|
return canvas.toDataURL("image/png", 0.7);
|
|
|
|
};
|
|
|
|
|
2015-09-29 14:32:43 +00: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
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
|
|
|
|
for (var j = 0; j < H2; j++) {
|
|
|
|
for (var i = 0; i < W2; i++) {
|
|
|
|
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;
|
|
|
|
for (var yy = Math.floor(j * ratio_h); yy < (j + 1) * ratio_h; yy++) {
|
|
|
|
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
|
|
|
|
for (var xx = Math.floor(i * ratio_w); xx < (i + 1) * ratio_w; xx++) {
|
|
|
|
var dx = Math.abs(center_x - (xx + 0.5)) / ratio_w_half;
|
|
|
|
var w = Math.sqrt(w0 + dx * dx);
|
|
|
|
if (w >= -1 && w <= 1) {
|
|
|
|
//hermite filter
|
|
|
|
weight = 2 * w * w * w - 3 * w * w + 1;
|
|
|
|
if (weight > 0) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data2[x2] = gx_r / weights;
|
|
|
|
data2[x2 + 1] = gx_g / weights;
|
|
|
|
data2[x2 + 2] = gx_b / weights;
|
|
|
|
data2[x2 + 3] = gx_a / weights_alpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2014-12-08 14:26:31 +00:00
|
|
|
var addConflict = function($conflicts, original, replacement) {
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2014-12-08 14:26:31 +00:00
|
|
|
var $conflict = $conflicts.find('.template').clone().removeClass('template').addClass('conflict');
|
|
|
|
var $originalDiv = $conflict.find('.original');
|
|
|
|
var $replacementDiv = $conflict.find('.replacement');
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2014-12-08 14:26:31 +00:00
|
|
|
$conflict.data('data',data);
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2014-12-08 14:26:31 +00:00
|
|
|
$conflict.find('.filename').text(original.name);
|
|
|
|
$originalDiv.find('.size').text(humanFileSize(original.size));
|
|
|
|
$originalDiv.find('.mtime').text(formatDate(original.mtime));
|
2013-09-18 15:58:15 +00:00
|
|
|
// ie sucks
|
|
|
|
if (replacement.size && replacement.lastModifiedDate) {
|
2014-12-08 14:26:31 +00:00
|
|
|
$replacementDiv.find('.size').text(humanFileSize(replacement.size));
|
|
|
|
$replacementDiv.find('.mtime').text(formatDate(replacement.lastModifiedDate));
|
2013-09-18 15:58:15 +00:00
|
|
|
}
|
2014-02-21 10:18:23 +00:00
|
|
|
var path = original.directory + '/' +original.name;
|
2015-05-29 11:49:51 +00:00
|
|
|
var urlSpec = {
|
|
|
|
file: path,
|
|
|
|
x: 96,
|
|
|
|
y: 96,
|
|
|
|
c: original.etag,
|
|
|
|
forceIcon: 0
|
|
|
|
};
|
2015-07-20 14:51:28 +00:00
|
|
|
var previewpath = Files.generatePreviewUrl(urlSpec);
|
2015-05-29 16:34:38 +00:00
|
|
|
// Escaping single quotes
|
2015-07-20 14:51:28 +00:00
|
|
|
previewpath = previewpath.replace(/'/g, "%27");
|
2015-05-29 15:49:26 +00:00
|
|
|
$originalDiv.find('.icon').css({"background-image": "url('" + previewpath + "')"});
|
2013-09-18 15:58:15 +00:00
|
|
|
getCroppedPreview(replacement).then(
|
|
|
|
function(path){
|
2014-12-08 14:26:31 +00:00
|
|
|
$replacementDiv.find('.icon').css('background-image','url(' + path + ')');
|
2013-09-18 15:58:15 +00:00
|
|
|
}, function(){
|
2015-07-08 12:55:11 +00:00
|
|
|
path = OC.MimeType.getIconUrl(replacement.type);
|
|
|
|
$replacementDiv.find('.icon').css('background-image','url(' + path + ')');
|
2013-08-22 12:29:00 +00:00
|
|
|
}
|
2013-09-18 15:58:15 +00:00
|
|
|
);
|
2015-09-19 13:44:49 +00:00
|
|
|
// connect checkboxes with labels
|
|
|
|
var checkboxId = $conflicts.find('.conflict').length;
|
|
|
|
$originalDiv.find('input:checkbox').attr('id', 'checkbox_original_'+checkboxId);
|
|
|
|
$replacementDiv.find('input:checkbox').attr('id', 'checkbox_replacement_'+checkboxId);
|
|
|
|
|
2014-12-08 14:26:31 +00:00
|
|
|
$conflicts.append($conflict);
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2013-09-18 15:58:15 +00:00
|
|
|
//set more recent mtime bold
|
|
|
|
// ie sucks
|
2014-05-21 11:19:02 +00:00
|
|
|
if (replacement.lastModifiedDate && replacement.lastModifiedDate.getTime() > original.mtime) {
|
2014-12-08 14:26:31 +00:00
|
|
|
$replacementDiv.find('.mtime').css('font-weight', 'bold');
|
2014-05-21 11:19:02 +00:00
|
|
|
} else if (replacement.lastModifiedDate && replacement.lastModifiedDate.getTime() < original.mtime) {
|
2014-12-08 14:26:31 +00:00
|
|
|
$originalDiv.find('.mtime').css('font-weight', 'bold');
|
2013-09-18 15:58:15 +00:00
|
|
|
} else {
|
|
|
|
//TODO add to same mtime collection?
|
|
|
|
}
|
|
|
|
|
|
|
|
// set bigger size bold
|
|
|
|
if (replacement.size && replacement.size > original.size) {
|
2014-12-08 14:26:31 +00:00
|
|
|
$replacementDiv.find('.size').css('font-weight', 'bold');
|
2013-09-18 15:58:15 +00:00
|
|
|
} else if (replacement.size && replacement.size < original.size) {
|
2014-12-08 14:26:31 +00:00
|
|
|
$originalDiv.find('.size').css('font-weight', 'bold');
|
2013-09-18 15:58:15 +00:00
|
|
|
} else {
|
|
|
|
//TODO add to same size collection?
|
|
|
|
}
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2013-09-18 15:58:15 +00:00
|
|
|
//TODO show skip action for files with same size and mtime in bottom row
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2014-12-08 14:26:31 +00:00
|
|
|
// always keep readonly files
|
|
|
|
|
|
|
|
if (original.status === 'readonly') {
|
|
|
|
$originalDiv
|
|
|
|
.addClass('readonly')
|
|
|
|
.find('input[type="checkbox"]')
|
|
|
|
.prop('checked', true)
|
|
|
|
.prop('disabled', true);
|
|
|
|
$originalDiv.find('.message')
|
2017-05-01 03:42:53 +00:00
|
|
|
.text(t('core','read-only'));
|
2014-12-08 14:26:31 +00:00
|
|
|
}
|
2013-09-04 13:24:25 +00:00
|
|
|
};
|
2013-09-06 20:40:10 +00:00
|
|
|
//var selection = controller.getSelection(data.originalFiles);
|
|
|
|
//if (selection.defaultAction) {
|
|
|
|
// controller[selection.defaultAction](data);
|
|
|
|
//} else {
|
2014-04-14 17:29:00 +00:00
|
|
|
var dialogName = 'oc-dialog-fileexists-content';
|
|
|
|
var dialogId = '#' + dialogName;
|
|
|
|
if (this._fileexistsshown) {
|
|
|
|
// add conflict
|
|
|
|
|
2014-12-08 14:26:31 +00:00
|
|
|
var $conflicts = $(dialogId+ ' .conflicts');
|
|
|
|
addConflict($conflicts, original, replacement);
|
2014-04-14 17:29:00 +00:00
|
|
|
|
|
|
|
var count = $(dialogId+ ' .conflict').length;
|
|
|
|
var title = n('core',
|
|
|
|
'{count} file conflict',
|
|
|
|
'{count} file conflicts',
|
|
|
|
count,
|
|
|
|
{count:count}
|
|
|
|
);
|
|
|
|
$(dialogId).parent().children('.oc-dialog-title').text(title);
|
|
|
|
|
|
|
|
//recalculate dimensions
|
|
|
|
$(window).trigger('resize');
|
2015-10-02 07:55:43 +00:00
|
|
|
dialogDeferred.resolve();
|
2014-04-14 17:29:00 +00:00
|
|
|
} else {
|
|
|
|
//create dialog
|
|
|
|
this._fileexistsshown = true;
|
|
|
|
$.when(this._getFileExistsTemplate()).then(function($tmpl) {
|
|
|
|
var title = t('core','One file conflict');
|
|
|
|
var $dlg = $tmpl.octemplate({
|
|
|
|
dialog_name: dialogName,
|
|
|
|
title: title,
|
|
|
|
type: 'fileexists',
|
|
|
|
|
|
|
|
allnewfiles: t('core','New Files'),
|
|
|
|
allexistingfiles: t('core','Already existing files'),
|
|
|
|
|
|
|
|
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.')
|
|
|
|
});
|
|
|
|
$('body').append($dlg);
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2015-10-02 07:55:43 +00:00
|
|
|
if (original && replacement) {
|
|
|
|
var $conflicts = $dlg.find('.conflicts');
|
|
|
|
addConflict($conflicts, original, replacement);
|
|
|
|
}
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2014-04-14 17:29:00 +00:00
|
|
|
var buttonlist = [{
|
|
|
|
text: t('core', 'Cancel'),
|
|
|
|
classes: 'cancel',
|
|
|
|
click: function(){
|
|
|
|
if ( typeof controller.onCancel !== 'undefined') {
|
|
|
|
controller.onCancel(data);
|
2013-08-16 09:40:55 +00:00
|
|
|
}
|
2014-04-14 17:29:00 +00:00
|
|
|
$(dialogId).ocdialog('close');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: t('core', 'Continue'),
|
|
|
|
classes: 'continue',
|
|
|
|
click: function(){
|
|
|
|
if ( typeof controller.onContinue !== 'undefined') {
|
|
|
|
controller.onContinue($(dialogId + ' .conflict'));
|
2013-08-16 09:40:55 +00:00
|
|
|
}
|
2014-04-14 17:29:00 +00:00
|
|
|
$(dialogId).ocdialog('close');
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
$(dialogId).ocdialog({
|
|
|
|
width: 500,
|
|
|
|
closeOnEscape: true,
|
|
|
|
modal: true,
|
|
|
|
buttons: buttonlist,
|
|
|
|
closeButton: null,
|
|
|
|
close: function() {
|
|
|
|
self._fileexistsshown = false;
|
2013-09-08 08:11:35 +00:00
|
|
|
$(this).ocdialog('destroy').remove();
|
|
|
|
}
|
2014-04-14 17:29:00 +00:00
|
|
|
});
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2014-04-14 17:29:00 +00:00
|
|
|
$(dialogId).css('height','auto');
|
2013-08-12 10:33:22 +00:00
|
|
|
|
2015-10-08 10:27:33 +00:00
|
|
|
var $primaryButton = $dlg.closest('.oc-dialog').find('button.continue');
|
|
|
|
$primaryButton.prop('disabled', true);
|
|
|
|
|
|
|
|
function updatePrimaryButton() {
|
2015-10-08 15:13:28 +00:00
|
|
|
var checkedCount = $dlg.find('.conflicts .checkbox:checked').length;
|
2015-10-08 10:27:33 +00:00
|
|
|
$primaryButton.prop('disabled', checkedCount === 0);
|
|
|
|
}
|
|
|
|
|
2014-04-14 17:29:00 +00:00
|
|
|
//add checkbox toggling actions
|
|
|
|
$(dialogId).find('.allnewfiles').on('click', function() {
|
2014-12-08 14:26:31 +00:00
|
|
|
var $checkboxes = $(dialogId).find('.conflict .replacement input[type="checkbox"]');
|
|
|
|
$checkboxes.prop('checked', $(this).prop('checked'));
|
2014-04-14 17:29:00 +00:00
|
|
|
});
|
|
|
|
$(dialogId).find('.allexistingfiles').on('click', function() {
|
2014-12-08 14:26:31 +00:00
|
|
|
var $checkboxes = $(dialogId).find('.conflict .original:not(.readonly) input[type="checkbox"]');
|
|
|
|
$checkboxes.prop('checked', $(this).prop('checked'));
|
2014-04-14 17:29:00 +00:00
|
|
|
});
|
2014-12-08 14:26:31 +00:00
|
|
|
$(dialogId).find('.conflicts').on('click', '.replacement,.original:not(.readonly)', function() {
|
|
|
|
var $checkbox = $(this).find('input[type="checkbox"]');
|
|
|
|
$checkbox.prop('checked', !$checkbox.prop('checked'));
|
2014-04-14 17:29:00 +00:00
|
|
|
});
|
2014-12-08 14:26:31 +00:00
|
|
|
$(dialogId).find('.conflicts').on('click', '.replacement input[type="checkbox"],.original:not(.readonly) input[type="checkbox"]', function() {
|
|
|
|
var $checkbox = $(this);
|
2015-10-02 07:55:43 +00:00
|
|
|
$checkbox.prop('checked', !$checkbox.prop('checked'));
|
2014-04-14 17:29:00 +00:00
|
|
|
});
|
2013-09-07 12:52:56 +00:00
|
|
|
|
2014-04-14 17:29:00 +00:00
|
|
|
//update counters
|
|
|
|
$(dialogId).on('click', '.replacement,.allnewfiles', function() {
|
|
|
|
var count = $(dialogId).find('.conflict .replacement input[type="checkbox"]:checked').length;
|
|
|
|
if (count === $(dialogId+ ' .conflict').length) {
|
|
|
|
$(dialogId).find('.allnewfiles').prop('checked', true);
|
|
|
|
$(dialogId).find('.allnewfiles + .count').text(t('core','(all selected)'));
|
|
|
|
} else if (count > 0) {
|
|
|
|
$(dialogId).find('.allnewfiles').prop('checked', false);
|
|
|
|
$(dialogId).find('.allnewfiles + .count').text(t('core','({count} selected)',{count:count}));
|
|
|
|
} else {
|
|
|
|
$(dialogId).find('.allnewfiles').prop('checked', false);
|
|
|
|
$(dialogId).find('.allnewfiles + .count').text('');
|
|
|
|
}
|
2015-10-08 10:27:33 +00:00
|
|
|
updatePrimaryButton();
|
2013-08-22 12:29:00 +00:00
|
|
|
});
|
2014-04-14 17:29:00 +00:00
|
|
|
$(dialogId).on('click', '.original,.allexistingfiles', function(){
|
|
|
|
var count = $(dialogId).find('.conflict .original input[type="checkbox"]:checked').length;
|
|
|
|
if (count === $(dialogId+ ' .conflict').length) {
|
|
|
|
$(dialogId).find('.allexistingfiles').prop('checked', true);
|
|
|
|
$(dialogId).find('.allexistingfiles + .count').text(t('core','(all selected)'));
|
|
|
|
} else if (count > 0) {
|
|
|
|
$(dialogId).find('.allexistingfiles').prop('checked', false);
|
|
|
|
$(dialogId).find('.allexistingfiles + .count')
|
|
|
|
.text(t('core','({count} selected)',{count:count}));
|
|
|
|
} else {
|
|
|
|
$(dialogId).find('.allexistingfiles').prop('checked', false);
|
|
|
|
$(dialogId).find('.allexistingfiles + .count').text('');
|
|
|
|
}
|
2015-10-08 10:27:33 +00:00
|
|
|
updatePrimaryButton();
|
2014-04-14 17:29:00 +00:00
|
|
|
});
|
2015-10-08 10:27:33 +00:00
|
|
|
|
2015-10-02 07:55:43 +00:00
|
|
|
dialogDeferred.resolve();
|
2014-04-14 17:29:00 +00:00
|
|
|
})
|
|
|
|
.fail(function() {
|
2015-10-02 07:55:43 +00:00
|
|
|
dialogDeferred.reject();
|
2014-04-14 17:29:00 +00:00
|
|
|
alert(t('core', 'Error loading file exists template'));
|
|
|
|
});
|
|
|
|
}
|
2013-09-06 20:40:10 +00:00
|
|
|
//}
|
2015-10-02 07:55:43 +00:00
|
|
|
return dialogDeferred.promise();
|
2012-05-05 11:48:12 +00:00
|
|
|
},
|
2013-05-17 06:42:15 +00:00
|
|
|
_getFilePickerTemplate: function() {
|
|
|
|
var defer = $.Deferred();
|
|
|
|
if(!this.$filePickerTemplate) {
|
|
|
|
var self = this;
|
|
|
|
$.get(OC.filePath('core', 'templates', 'filepicker.html'), function(tmpl) {
|
|
|
|
self.$filePickerTemplate = $(tmpl);
|
2016-10-17 12:26:25 +00:00
|
|
|
self.$listTmpl = self.$filePickerTemplate.find('.filelist tr:first-child').detach();
|
2013-05-17 06:42:15 +00:00
|
|
|
defer.resolve(self.$filePickerTemplate);
|
|
|
|
})
|
2013-09-11 14:02:12 +00:00
|
|
|
.fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
|
defer.reject(jqXHR.status, errorThrown);
|
2013-05-17 06:42:15 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
defer.resolve(this.$filePickerTemplate);
|
|
|
|
}
|
|
|
|
return defer.promise();
|
|
|
|
},
|
|
|
|
_getMessageTemplate: function() {
|
|
|
|
var defer = $.Deferred();
|
|
|
|
if(!this.$messageTemplate) {
|
|
|
|
var self = this;
|
|
|
|
$.get(OC.filePath('core', 'templates', 'message.html'), function(tmpl) {
|
|
|
|
self.$messageTemplate = $(tmpl);
|
|
|
|
defer.resolve(self.$messageTemplate);
|
|
|
|
})
|
2013-09-11 14:02:12 +00:00
|
|
|
.fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
|
defer.reject(jqXHR.status, errorThrown);
|
2013-05-17 06:42:15 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
defer.resolve(this.$messageTemplate);
|
|
|
|
}
|
|
|
|
return defer.promise();
|
|
|
|
},
|
2013-08-12 10:33:22 +00:00
|
|
|
_getFileExistsTemplate: function () {
|
|
|
|
var defer = $.Deferred();
|
|
|
|
if (!this.$fileexistsTemplate) {
|
|
|
|
var self = this;
|
|
|
|
$.get(OC.filePath('files', 'templates', 'fileexists.html'), function (tmpl) {
|
|
|
|
self.$fileexistsTemplate = $(tmpl);
|
|
|
|
defer.resolve(self.$fileexistsTemplate);
|
|
|
|
})
|
|
|
|
.fail(function () {
|
|
|
|
defer.reject();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
defer.resolve(this.$fileexistsTemplate);
|
|
|
|
}
|
|
|
|
return defer.promise();
|
|
|
|
},
|
2016-10-17 11:35:59 +00:00
|
|
|
_getFileList: function(dir, mimeType) { //this is only used by the spreedme app atm
|
2013-09-05 16:40:55 +00:00
|
|
|
if (typeof(mimeType) === "string") {
|
2013-09-06 11:33:17 +00:00
|
|
|
mimeType = [mimeType];
|
2013-09-05 14:54:12 +00:00
|
|
|
}
|
2013-09-05 16:40:55 +00:00
|
|
|
|
2013-05-17 06:42:15 +00:00
|
|
|
return $.getJSON(
|
2013-10-28 19:22:06 +00:00
|
|
|
OC.filePath('files', 'ajax', 'list.php'),
|
2013-09-05 16:40:55 +00:00
|
|
|
{
|
|
|
|
dir: dir,
|
|
|
|
mimetypes: JSON.stringify(mimeType)
|
|
|
|
}
|
2013-05-17 06:42:15 +00:00
|
|
|
);
|
|
|
|
},
|
2013-04-06 08:07:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* fills the filepicker with files
|
|
|
|
*/
|
2013-05-17 06:42:15 +00:00
|
|
|
_fillFilePicker:function(dir) {
|
2013-05-15 22:23:05 +00:00
|
|
|
var self = this;
|
2015-10-19 21:43:12 +00:00
|
|
|
this.$filelist.empty().addClass('icon-loading');
|
2013-05-17 02:54:08 +00:00
|
|
|
this.$filePicker.data('path', dir);
|
2016-10-17 11:35:59 +00:00
|
|
|
var filter = this.$filePicker.data('mimetype');
|
|
|
|
if (typeof(filter) === "string") {
|
|
|
|
filter = [filter];
|
|
|
|
}
|
|
|
|
self.filepicker.filesClient.getFolderContents(dir).then(function(status, files) {
|
2016-10-19 12:22:33 +00:00
|
|
|
if (filter) {
|
|
|
|
files = files.filter(function (file) {
|
|
|
|
return filter == [] || file.type === 'dir' || filter.indexOf(file.mimetype) !== -1;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
files = files.sort(function(a, b) {
|
2016-10-17 11:35:59 +00:00
|
|
|
if (a.type === 'dir' && b.type !== 'dir') {
|
|
|
|
return -1;
|
|
|
|
} else if(a.type !== 'dir' && b.type === 'dir') {
|
|
|
|
return 1;
|
2013-05-17 02:54:08 +00:00
|
|
|
} else {
|
2016-10-17 11:35:59 +00:00
|
|
|
return 0;
|
2013-05-17 02:54:08 +00:00
|
|
|
}
|
2013-05-15 22:23:05 +00:00
|
|
|
});
|
|
|
|
|
2013-05-17 06:42:15 +00:00
|
|
|
self._fillSlug();
|
2013-05-15 22:23:05 +00:00
|
|
|
|
2016-10-21 14:35:55 +00:00
|
|
|
if (files.length === 0) {
|
|
|
|
self.$filePicker.find('.emptycontent').show();
|
|
|
|
} else {
|
|
|
|
self.$filePicker.find('.emptycontent').hide();
|
|
|
|
}
|
|
|
|
|
2016-10-17 11:35:59 +00:00
|
|
|
$.each(files, function(idx, entry) {
|
2015-12-24 07:59:32 +00:00
|
|
|
entry.icon = OC.MimeType.getIconUrl(entry.mimetype);
|
2017-05-01 04:09:29 +00:00
|
|
|
var simpleSize, sizeColor;
|
2016-10-17 12:26:25 +00:00
|
|
|
if (typeof(entry.size) !== 'undefined' && entry.size >= 0) {
|
2017-05-01 04:09:29 +00:00
|
|
|
simpleSize = humanFileSize(parseInt(entry.size, 10), true);
|
|
|
|
sizeColor = Math.round(160 - Math.pow((entry.size / (1024 * 1024)), 2));
|
2016-10-17 12:26:25 +00:00
|
|
|
} else {
|
|
|
|
simpleSize = t('files', 'Pending');
|
2017-05-01 04:09:29 +00:00
|
|
|
sizeColor = 80;
|
2016-10-17 12:26:25 +00:00
|
|
|
}
|
|
|
|
var $row = self.$listTmpl.octemplate({
|
2013-05-17 02:54:08 +00:00
|
|
|
type: entry.type,
|
|
|
|
dir: dir,
|
|
|
|
filename: entry.name,
|
2016-10-17 12:26:25 +00:00
|
|
|
date: OC.Util.relativeModifiedDate(entry.mtime),
|
|
|
|
size: simpleSize,
|
|
|
|
sizeColor: sizeColor,
|
|
|
|
icon: entry.icon
|
2013-05-17 02:54:08 +00:00
|
|
|
});
|
2015-07-13 15:38:13 +00:00
|
|
|
if (entry.type === 'file') {
|
2013-10-28 19:22:06 +00:00
|
|
|
var urlSpec = {
|
2016-10-14 15:29:36 +00:00
|
|
|
file: dir + '/' + entry.name,
|
2013-10-28 19:22:06 +00:00
|
|
|
};
|
2016-10-14 15:29:36 +00:00
|
|
|
var img = new Image();
|
2013-10-28 19:22:06 +00:00
|
|
|
var previewUrl = OC.generateUrl('/core/preview.png?') + $.param(urlSpec);
|
2016-10-14 15:29:36 +00:00
|
|
|
img.onload = function() {
|
|
|
|
if (img.width > 5) {
|
2016-10-17 12:26:25 +00:00
|
|
|
$row.find('td.filename').attr('style', 'background-image:url(' + previewUrl + ')');
|
2016-10-14 15:29:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
img.src = previewUrl;
|
2013-10-28 19:22:06 +00:00
|
|
|
}
|
2016-10-17 12:26:25 +00:00
|
|
|
self.$filelist.append($row);
|
2013-05-17 02:54:08 +00:00
|
|
|
});
|
2013-04-06 17:21:15 +00:00
|
|
|
|
2015-10-19 21:43:12 +00:00
|
|
|
self.$filelist.removeClass('icon-loading');
|
2013-05-17 02:54:08 +00:00
|
|
|
});
|
2012-05-05 11:48:12 +00:00
|
|
|
},
|
2013-04-06 08:07:12 +00:00
|
|
|
/**
|
|
|
|
* fills the tree list with directories
|
|
|
|
*/
|
2013-05-17 06:42:15 +00:00
|
|
|
_fillSlug: function() {
|
2013-05-17 02:54:08 +00:00
|
|
|
this.$dirTree.empty();
|
2013-08-12 10:33:22 +00:00
|
|
|
var self = this;
|
2016-10-14 15:31:10 +00:00
|
|
|
var dir;
|
2013-05-17 02:54:08 +00:00
|
|
|
var path = this.$filePicker.data('path');
|
2016-10-14 15:31:10 +00:00
|
|
|
var $template = $('<div data-dir="{dir}"><a>{name}</a></div>').addClass('crumb');
|
2013-05-17 05:14:43 +00:00
|
|
|
if(path) {
|
|
|
|
var paths = path.split('/');
|
|
|
|
$.each(paths, function(index, dir) {
|
2013-07-31 19:21:02 +00:00
|
|
|
dir = paths.pop();
|
2013-05-17 05:14:43 +00:00
|
|
|
if(dir === '') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
self.$dirTree.prepend($template.octemplate({
|
|
|
|
dir: paths.join('/') + '/' + dir,
|
|
|
|
name: dir
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
2013-05-17 14:18:40 +00:00
|
|
|
$template.octemplate({
|
2013-05-17 02:54:08 +00:00
|
|
|
dir: '',
|
2016-10-14 15:31:10 +00:00
|
|
|
name: '' // Ugly but works ;)
|
|
|
|
}, {escapeFunction: null}).prependTo(this.$dirTree);
|
2013-04-06 08:07:12 +00:00
|
|
|
},
|
2013-04-06 14:44:13 +00:00
|
|
|
/**
|
|
|
|
* handle selection made in the tree list
|
|
|
|
*/
|
2013-05-17 06:42:15 +00:00
|
|
|
_handleTreeListSelect:function(event) {
|
2013-05-17 02:54:08 +00:00
|
|
|
var self = event.data;
|
2016-10-14 15:31:10 +00:00
|
|
|
var dir = $(event.target).parent().data('dir');
|
2013-05-17 06:42:15 +00:00
|
|
|
self._fillFilePicker(dir);
|
2016-10-14 15:31:10 +00:00
|
|
|
var getOcDialog = (event.target).closest('.oc-dialog');
|
2016-08-22 12:21:47 +00:00
|
|
|
var buttonEnableDisable = $('.primary', getOcDialog);
|
2016-10-17 11:09:21 +00:00
|
|
|
if (this.$filePicker.data('mimetype') === "httpd/unix-directory") {
|
2016-09-07 13:17:52 +00:00
|
|
|
buttonEnableDisable.prop("disabled", false);
|
|
|
|
} else {
|
|
|
|
buttonEnableDisable.prop("disabled", true);
|
|
|
|
}
|
2013-04-06 08:07:12 +00:00
|
|
|
},
|
2013-04-06 14:44:13 +00:00
|
|
|
/**
|
|
|
|
* handle clicks made in the filepicker
|
|
|
|
*/
|
2013-05-17 06:42:15 +00:00
|
|
|
_handlePickerClick:function(event, $element) {
|
2016-08-22 12:21:47 +00:00
|
|
|
var getOcDialog = this.$filePicker.closest('.oc-dialog');
|
|
|
|
var buttonEnableDisable = getOcDialog.find('.primary');
|
2013-05-17 02:54:08 +00:00
|
|
|
if ($element.data('type') === 'file') {
|
|
|
|
if (this.$filePicker.data('multiselect') !== true || !event.ctrlKey) {
|
|
|
|
this.$filelist.find('.filepicker_element_selected').removeClass('filepicker_element_selected');
|
2012-05-05 11:48:12 +00:00
|
|
|
}
|
2013-05-17 02:54:08 +00:00
|
|
|
$element.toggleClass('filepicker_element_selected');
|
2016-08-22 12:21:47 +00:00
|
|
|
buttonEnableDisable.prop("disabled", false);
|
2013-05-17 02:54:08 +00:00
|
|
|
} else if ( $element.data('type') === 'dir' ) {
|
2013-07-31 19:21:02 +00:00
|
|
|
this._fillFilePicker(this.$filePicker.data('path') + '/' + $element.data('entryname'));
|
2016-09-07 13:17:52 +00:00
|
|
|
if (this.$filePicker.data('mimetype') === "httpd/unix-directory") {
|
|
|
|
buttonEnableDisable.prop("disabled", false);
|
|
|
|
} else {
|
|
|
|
buttonEnableDisable.prop("disabled", true);
|
|
|
|
}
|
2012-05-05 11:48:12 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-28 22:02:02 +00:00
|
|
|
};
|