2012-02-29 02:02:02 +04:00
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
2013-05-16 20:19:28 +04:00
|
|
|
* @author Bartek Przybylski, Christopher Schäpers, Thomas Tanghus
|
2012-03-24 21:35:16 +04:00
|
|
|
* @copyright 2012 Bartek Przybylski bartek@alefzero.eu
|
2012-02-29 02:02:02 +04: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2012-09-06 00:22:04 +04:00
|
|
|
var OCdialogs = {
|
2013-05-17 09:14:43 +04:00
|
|
|
// dialog button types
|
|
|
|
YES_NO_BUTTONS: 70,
|
|
|
|
OK_BUTTONS: 71,
|
|
|
|
// used to name each dialog
|
|
|
|
dialogs_counter: 0,
|
2012-05-05 15:48:12 +04:00
|
|
|
/**
|
|
|
|
* displays alert dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
2013-04-06 12:07:12 +04:00
|
|
|
* @param callback which will be triggered when user presses OK
|
|
|
|
* @param modal make the dialog modal
|
2012-05-05 15:48:12 +04:00
|
|
|
*/
|
|
|
|
alert:function(text, title, callback, modal) {
|
2013-05-17 09:14:43 +04:00
|
|
|
this.message(text, title, 'alert', OCdialogs.OK_BUTTON, callback, modal);
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* displays info dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
2013-04-06 12:07:12 +04:00
|
|
|
* @param callback which will be triggered when user presses OK
|
|
|
|
* @param modal make the dialog modal
|
2012-05-05 15:48:12 +04:00
|
|
|
*/
|
|
|
|
info:function(text, title, callback, modal) {
|
2013-05-17 09:14:43 +04:00
|
|
|
this.message(text, title, 'info', OCdialogs.OK_BUTTON, callback, modal);
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* displays confirmation dialog
|
|
|
|
* @param text content of dialog
|
|
|
|
* @param title dialog title
|
2013-04-06 12:07:12 +04:00
|
|
|
* @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
|
2012-05-05 15:48:12 +04:00
|
|
|
*/
|
|
|
|
confirm:function(text, title, callback, modal) {
|
2013-05-17 09:14:43 +04:00
|
|
|
this.message(text, title, 'notice', OCdialogs.YES_NO_BUTTONS, callback, modal);
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
2013-04-06 12:07:12 +04: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
|
|
|
|
* @param mimetype_filter mimetype to filter by
|
|
|
|
* @param modal make the dialog modal
|
|
|
|
*/
|
2012-05-05 15:48:12 +04:00
|
|
|
filepicker:function(title, callback, multiselect, mimetype_filter, modal) {
|
2013-05-17 06:54:08 +04:00
|
|
|
var self = this;
|
2013-05-16 02:23:05 +04:00
|
|
|
$.when(this._getFilePickerTemplate()).then(function($tmpl) {
|
2013-05-17 06:54:08 +04:00
|
|
|
var dialog_name = 'oc-dialog-filepicker-content';
|
2013-05-16 02:23:05 +04:00
|
|
|
var dialog_id = '#' + dialog_name;
|
2013-05-17 06:54:08 +04:00
|
|
|
if(self.$filePicker) {
|
2013-06-02 23:52:59 +04:00
|
|
|
self.$filePicker.ocdialog('close');
|
2013-05-17 06:54:08 +04:00
|
|
|
}
|
|
|
|
self.$filePicker = $tmpl.octemplate({
|
2013-05-16 02:23:05 +04:00
|
|
|
dialog_name: dialog_name,
|
|
|
|
title: title
|
2013-09-03 01:53:45 +04:00
|
|
|
}).data('path', '').data('multiselect', multiselect).data('mimetype', mimetype_filter);
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2013-08-01 20:44:01 +04:00
|
|
|
if (modal === undefined) {
|
|
|
|
modal = false;
|
|
|
|
}
|
|
|
|
if (multiselect === undefined) {
|
|
|
|
multiselect = false;
|
|
|
|
}
|
|
|
|
if (mimetype_filter === undefined) {
|
|
|
|
mimetype_filter = '';
|
|
|
|
}
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2013-05-17 06:54:08 +04:00
|
|
|
$('body').append(self.$filePicker);
|
2013-04-06 12:07:12 +04:00
|
|
|
|
|
|
|
|
2013-05-17 06:54:08 +04:00
|
|
|
self.$filePicker.ready(function() {
|
|
|
|
self.$filelist = self.$filePicker.find('.filelist');
|
|
|
|
self.$dirTree = self.$filePicker.find('.dirtree');
|
2013-05-17 10:42:15 +04:00
|
|
|
self.$dirTree.on('click', 'span:not(:last-child)', self, self._handleTreeListSelect);
|
2013-05-17 06:54:08 +04:00
|
|
|
self.$filelist.on('click', 'li', function(event) {
|
2013-05-17 10:42:15 +04:00
|
|
|
self._handlePickerClick(event, $(this));
|
2013-05-16 02:23:05 +04:00
|
|
|
});
|
2013-05-17 10:42:15 +04:00
|
|
|
self._fillFilePicker('');
|
2013-09-03 01:53:45 +04:00
|
|
|
});
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2013-05-16 02:23:05 +04:00
|
|
|
// build buttons
|
|
|
|
var functionToCall = function() {
|
|
|
|
if (callback !== undefined) {
|
|
|
|
var datapath;
|
|
|
|
if (multiselect === true) {
|
|
|
|
datapath = [];
|
2013-05-17 06:54:08 +04:00
|
|
|
self.$filelist.find('.filepicker_element_selected .filename').each(function(index, element) {
|
|
|
|
datapath.push(self.$filePicker.data('path') + '/' + $(element).text());
|
2013-05-16 02:23:05 +04:00
|
|
|
});
|
|
|
|
} else {
|
2013-07-31 23:21:02 +04:00
|
|
|
datapath = self.$filePicker.data('path');
|
2013-05-17 06:54:08 +04:00
|
|
|
datapath += '/' + self.$filelist.find('.filepicker_element_selected .filename').text();
|
2013-05-16 02:23:05 +04:00
|
|
|
}
|
|
|
|
callback(datapath);
|
2013-06-02 23:52:59 +04:00
|
|
|
self.$filePicker.ocdialog('close');
|
2012-05-05 15:48:12 +04:00
|
|
|
}
|
2013-05-16 02:23:05 +04:00
|
|
|
};
|
|
|
|
var buttonlist = [{
|
|
|
|
text: t('core', 'Choose'),
|
2013-06-03 05:31:33 +04:00
|
|
|
click: functionToCall,
|
|
|
|
defaultButton: true
|
2013-05-16 02:23:05 +04: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,
|
2013-05-16 02:23:05 +04:00
|
|
|
width: (4/9)*$(document).width(),
|
|
|
|
height: 420,
|
|
|
|
modal: modal,
|
2013-05-17 06:54:08 +04:00
|
|
|
buttons: buttonlist,
|
|
|
|
close: function(event, ui) {
|
2013-06-03 05:19:35 +04:00
|
|
|
try {
|
|
|
|
$(this).ocdialog('destroy').remove();
|
|
|
|
} catch(e) {}
|
2013-05-17 06:54:08 +04:00
|
|
|
self.$filePicker = null;
|
|
|
|
}
|
2013-05-16 02:23:05 +04:00
|
|
|
});
|
|
|
|
})
|
2013-09-11 18:02:12 +04:00
|
|
|
.fail(function(status, error) {
|
|
|
|
// If the method is called while navigating away
|
|
|
|
// from the page, it is probably not needed ;)
|
2013-09-11 23:15:32 +04:00
|
|
|
if(status !== 0) {
|
2013-09-11 18:02:12 +04:00
|
|
|
alert(t('core', 'Error loading file picker template: {error}', {error: error}));
|
|
|
|
}
|
2013-04-06 12:07:12 +04: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 ...
|
|
|
|
*/
|
2012-05-05 15:48:12 +04:00
|
|
|
message:function(content, title, dialog_type, buttons, callback, modal) {
|
2013-05-16 02:23:05 +04:00
|
|
|
$.when(this._getMessageTemplate()).then(function($tmpl) {
|
|
|
|
var dialog_name = 'oc-dialog-' + OCdialogs.dialogs_counter + '-content';
|
|
|
|
var dialog_id = '#' + dialog_name;
|
|
|
|
var $dlg = $tmpl.octemplate({
|
|
|
|
dialog_name: dialog_name,
|
|
|
|
title: title,
|
|
|
|
message: content,
|
|
|
|
type: dialog_type
|
|
|
|
});
|
2013-08-01 20:44:01 +04:00
|
|
|
if (modal === undefined) {
|
|
|
|
modal = false;
|
|
|
|
}
|
2013-05-16 02:23:05 +04:00
|
|
|
$('body').append($dlg);
|
|
|
|
var buttonlist = [];
|
|
|
|
switch (buttons) {
|
|
|
|
case OCdialogs.YES_NO_BUTTONS:
|
|
|
|
buttonlist = [{
|
|
|
|
text: t('core', 'Yes'),
|
|
|
|
click: function(){
|
2013-08-01 20:44:01 +04:00
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(true);
|
|
|
|
}
|
2013-06-02 23:52:59 +04:00
|
|
|
$(dialog_id).ocdialog('close');
|
2013-06-03 05:31:33 +04:00
|
|
|
},
|
|
|
|
defaultButton: true
|
2013-05-16 02:23:05 +04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: t('core', 'No'),
|
|
|
|
click: function(){
|
2013-08-01 20:44:01 +04:00
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(false);
|
|
|
|
}
|
2013-06-02 23:52:59 +04:00
|
|
|
$(dialog_id).ocdialog('close');
|
2013-05-16 02:23:05 +04:00
|
|
|
}
|
|
|
|
}];
|
|
|
|
break;
|
|
|
|
case OCdialogs.OK_BUTTON:
|
2013-05-20 11:54:43 +04:00
|
|
|
var functionToCall = function() {
|
2013-06-02 23:52:59 +04:00
|
|
|
$(dialog_id).ocdialog('close');
|
2013-08-01 20:44:01 +04:00
|
|
|
if(callback !== undefined) {
|
|
|
|
callback();
|
|
|
|
}
|
2013-05-20 11:54:43 +04:00
|
|
|
};
|
2013-05-16 02:23:05 +04:00
|
|
|
buttonlist[0] = {
|
|
|
|
text: t('core', 'Ok'),
|
2013-06-03 05:31:33 +04:00
|
|
|
click: functionToCall,
|
|
|
|
defaultButton: true
|
2013-05-16 02:23:05 +04:00
|
|
|
};
|
|
|
|
break;
|
2013-07-31 23:21:02 +04:00
|
|
|
}
|
2013-04-06 12:07:12 +04:00
|
|
|
|
2013-06-02 23:52:59 +04:00
|
|
|
$(dialog_id).ocdialog({
|
2013-05-17 09:14:43 +04:00
|
|
|
closeOnEscape: true,
|
2013-05-16 02:23:05 +04:00
|
|
|
modal: modal,
|
|
|
|
buttons: buttonlist
|
|
|
|
});
|
|
|
|
OCdialogs.dialogs_counter++;
|
|
|
|
})
|
2013-09-11 18:02:12 +04: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 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
|
2013-08-12 14:33:22 +04:00
|
|
|
*/
|
|
|
|
fileexists:function(data, original, replacement, controller) {
|
2013-08-22 16:29:00 +04:00
|
|
|
var self = this;
|
2013-09-07 16:52:56 +04:00
|
|
|
|
|
|
|
var getCroppedPreview = function(file) {
|
|
|
|
var deferred = new $.Deferred();
|
|
|
|
// Only process image files.
|
2013-10-10 17:54:00 +04:00
|
|
|
var type = file.type && file.type.split('/').shift();
|
2013-09-07 16:52:56 +04:00
|
|
|
if (window.FileReader && type === 'image') {
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function (e) {
|
2013-09-19 11:47:51 +04:00
|
|
|
var blob = new Blob([e.target.result]);
|
2013-09-07 16:52:56 +04: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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
reader.readAsArrayBuffer(file);
|
|
|
|
} else {
|
|
|
|
deferred.reject();
|
|
|
|
}
|
|
|
|
return deferred;
|
|
|
|
};
|
|
|
|
|
|
|
|
var crop = function(img) {
|
|
|
|
var canvas = document.createElement('canvas'),
|
|
|
|
width = img.width,
|
|
|
|
height = img.height,
|
|
|
|
x, y, size;
|
|
|
|
|
|
|
|
// calculate the width and height, constraining the proportions
|
|
|
|
if (width > height) {
|
|
|
|
y = 0;
|
|
|
|
x = (width - height) / 2;
|
|
|
|
} else {
|
|
|
|
y = (height - width) / 2;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
size = Math.min(width, height);
|
|
|
|
|
|
|
|
// resize the canvas and draw the image data into it
|
|
|
|
canvas.width = 64;
|
|
|
|
canvas.height = 64;
|
|
|
|
var ctx = canvas.getContext("2d");
|
|
|
|
ctx.drawImage(img, x, y, size, size, 0, 0, 64, 64);
|
|
|
|
return canvas.toDataURL("image/png", 0.7);
|
|
|
|
};
|
|
|
|
|
2013-09-04 17:24:25 +04:00
|
|
|
var addConflict = function(conflicts, original, replacement) {
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-09-18 19:58:15 +04:00
|
|
|
var conflict = conflicts.find('.template').clone().removeClass('template').addClass('conflict');
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-09-18 19:58:15 +04:00
|
|
|
conflict.data('data',data);
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-09-18 19:58:15 +04:00
|
|
|
conflict.find('.filename').text(original.name);
|
|
|
|
conflict.find('.original .size').text(humanFileSize(original.size));
|
|
|
|
conflict.find('.original .mtime').text(formatDate(original.mtime*1000));
|
|
|
|
// ie sucks
|
|
|
|
if (replacement.size && replacement.lastModifiedDate) {
|
|
|
|
conflict.find('.replacement .size').text(humanFileSize(replacement.size));
|
|
|
|
conflict.find('.replacement .mtime').text(formatDate(replacement.lastModifiedDate));
|
|
|
|
}
|
|
|
|
var path = getPathForPreview(original.name);
|
2013-10-28 14:22:34 +04:00
|
|
|
Files.lazyLoadPreview(path, original.mime, function(previewpath){
|
2013-09-18 19:58:15 +04:00
|
|
|
conflict.find('.original .icon').css('background-image','url('+previewpath+')');
|
2013-10-28 14:22:34 +04:00
|
|
|
}, 96, 96, original.etag);
|
2013-09-18 19:58:15 +04:00
|
|
|
getCroppedPreview(replacement).then(
|
|
|
|
function(path){
|
|
|
|
conflict.find('.replacement .icon').css('background-image','url(' + path + ')');
|
|
|
|
}, function(){
|
2013-10-28 14:22:34 +04:00
|
|
|
Files.getMimeIcon(replacement.type,function(path){
|
2013-09-18 19:58:15 +04:00
|
|
|
conflict.find('.replacement .icon').css('background-image','url(' + path + ')');
|
|
|
|
});
|
2013-08-22 16:29:00 +04:00
|
|
|
}
|
2013-09-18 19:58:15 +04:00
|
|
|
);
|
|
|
|
conflicts.append(conflict);
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-09-18 19:58:15 +04:00
|
|
|
//set more recent mtime bold
|
|
|
|
// ie sucks
|
|
|
|
if (replacement.lastModifiedDate && replacement.lastModifiedDate.getTime() > original.mtime*1000) {
|
|
|
|
conflict.find('.replacement .mtime').css('font-weight', 'bold');
|
|
|
|
} else if (replacement.lastModifiedDate && replacement.lastModifiedDate.getTime() < original.mtime*1000) {
|
|
|
|
conflict.find('.original .mtime').css('font-weight', 'bold');
|
|
|
|
} else {
|
|
|
|
//TODO add to same mtime collection?
|
|
|
|
}
|
|
|
|
|
|
|
|
// set bigger size bold
|
|
|
|
if (replacement.size && replacement.size > original.size) {
|
|
|
|
conflict.find('.replacement .size').css('font-weight', 'bold');
|
|
|
|
} else if (replacement.size && replacement.size < original.size) {
|
|
|
|
conflict.find('.original .size').css('font-weight', 'bold');
|
|
|
|
} else {
|
|
|
|
//TODO add to same size collection?
|
|
|
|
}
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-09-18 19:58:15 +04:00
|
|
|
//TODO show skip action for files with same size and mtime in bottom row
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-09-04 17:24:25 +04:00
|
|
|
};
|
2013-09-07 00:40:10 +04:00
|
|
|
//var selection = controller.getSelection(data.originalFiles);
|
|
|
|
//if (selection.defaultAction) {
|
|
|
|
// controller[selection.defaultAction](data);
|
|
|
|
//} else {
|
2013-09-04 17:24:25 +04:00
|
|
|
var dialog_name = 'oc-dialog-fileexists-content';
|
|
|
|
var dialog_id = '#' + dialog_name;
|
|
|
|
if (this._fileexistsshown) {
|
|
|
|
// add conflict
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-09-04 17:24:25 +04:00
|
|
|
var conflicts = $(dialog_id+ ' .conflicts');
|
|
|
|
addConflict(conflicts, original, replacement);
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-09-19 13:25:41 +04:00
|
|
|
var count = $(dialog_id+ ' .conflict').length;
|
|
|
|
var title = n('files',
|
2013-09-19 14:05:30 +04:00
|
|
|
'{count} file conflict',
|
2013-09-19 13:25:41 +04:00
|
|
|
'{count} file conflicts',
|
|
|
|
count,
|
|
|
|
{count:count}
|
|
|
|
);
|
2013-09-04 17:24:25 +04:00
|
|
|
$(dialog_id).parent().children('.oc-dialog-title').text(title);
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-09-04 17:24:25 +04:00
|
|
|
//recalculate dimensions
|
2013-08-22 16:29:00 +04:00
|
|
|
$(window).trigger('resize');
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-08-22 16:29:00 +04:00
|
|
|
} else {
|
|
|
|
//create dialog
|
|
|
|
this._fileexistsshown = true;
|
|
|
|
$.when(this._getFileExistsTemplate()).then(function($tmpl) {
|
|
|
|
var title = t('files','One file conflict');
|
|
|
|
var $dlg = $tmpl.octemplate({
|
|
|
|
dialog_name: dialog_name,
|
|
|
|
title: title,
|
|
|
|
type: 'fileexists',
|
2013-08-16 13:40:55 +04:00
|
|
|
|
2013-08-22 16:29:00 +04:00
|
|
|
why: t('files','Which files do you want to keep?'),
|
2013-09-04 17:24:25 +04:00
|
|
|
what: t('files','If you select both versions, the copied file will have a number added to its name.')
|
2013-08-22 16:29:00 +04:00
|
|
|
});
|
|
|
|
$('body').append($dlg);
|
2013-08-16 13:40:55 +04:00
|
|
|
|
2013-09-04 17:24:25 +04:00
|
|
|
var conflicts = $($dlg).find('.conflicts');
|
|
|
|
addConflict(conflicts, original, replacement);
|
2013-08-22 16:29:00 +04:00
|
|
|
|
|
|
|
buttonlist = [{
|
|
|
|
text: t('core', 'Cancel'),
|
|
|
|
classes: 'cancel',
|
|
|
|
click: function(){
|
|
|
|
if ( typeof controller.onCancel !== 'undefined') {
|
|
|
|
controller.onCancel(data);
|
2013-08-16 13:40:55 +04:00
|
|
|
}
|
2013-09-07 00:40:10 +04:00
|
|
|
$(dialog_id).ocdialog('close');
|
2013-08-16 13:40:55 +04:00
|
|
|
}
|
|
|
|
},
|
2013-08-22 16:29:00 +04:00
|
|
|
{
|
|
|
|
text: t('core', 'Continue'),
|
|
|
|
classes: 'continue',
|
|
|
|
click: function(){
|
2013-09-05 19:46:19 +04:00
|
|
|
if ( typeof controller.onContinue !== 'undefined') {
|
2013-09-18 19:22:29 +04:00
|
|
|
controller.onContinue($(dialog_id + ' .conflict'));
|
2013-08-22 16:29:00 +04:00
|
|
|
}
|
|
|
|
$(dialog_id).ocdialog('close');
|
2013-08-16 13:40:55 +04:00
|
|
|
}
|
2013-08-22 16:29:00 +04:00
|
|
|
}];
|
|
|
|
|
|
|
|
$(dialog_id).ocdialog({
|
|
|
|
width: 500,
|
|
|
|
closeOnEscape: true,
|
|
|
|
modal: true,
|
|
|
|
buttons: buttonlist,
|
2013-09-08 12:11:35 +04:00
|
|
|
closeButton: null,
|
|
|
|
close: function(event, ui) {
|
2013-09-18 19:22:29 +04:00
|
|
|
self._fileexistsshown = false;
|
2013-09-08 12:11:35 +04:00
|
|
|
$(this).ocdialog('destroy').remove();
|
|
|
|
}
|
2013-08-22 16:29:00 +04:00
|
|
|
});
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-08-22 16:29:00 +04:00
|
|
|
$(dialog_id).css('height','auto');
|
2013-08-12 14:33:22 +04:00
|
|
|
|
2013-08-22 16:29:00 +04:00
|
|
|
//add checkbox toggling actions
|
2013-09-04 17:24:25 +04:00
|
|
|
$(dialog_id).find('.allnewfiles').on('click', function() {
|
2013-09-18 19:22:29 +04:00
|
|
|
var checkboxes = $(dialog_id).find('.conflict .replacement input[type="checkbox"]');
|
2013-08-22 16:29:00 +04:00
|
|
|
checkboxes.prop('checked', $(this).prop('checked'));
|
|
|
|
});
|
2013-09-04 17:24:25 +04:00
|
|
|
$(dialog_id).find('.allexistingfiles').on('click', function() {
|
2013-09-18 19:22:29 +04:00
|
|
|
var checkboxes = $(dialog_id).find('.conflict .original input[type="checkbox"]');
|
2013-08-22 16:29:00 +04:00
|
|
|
checkboxes.prop('checked', $(this).prop('checked'));
|
|
|
|
});
|
2013-09-04 17:24:25 +04:00
|
|
|
$(dialog_id).find('.conflicts').on('click', '.replacement,.original', function() {
|
2013-08-22 16:29:00 +04:00
|
|
|
var checkbox = $(this).find('input[type="checkbox"]');
|
|
|
|
checkbox.prop('checked', !checkbox.prop('checked'));
|
|
|
|
});
|
2013-09-05 12:19:54 +04:00
|
|
|
$(dialog_id).find('.conflicts').on('click', 'input[type="checkbox"]', function() {
|
|
|
|
var checkbox = $(this);
|
|
|
|
checkbox.prop('checked', !checkbox.prop('checked'));
|
|
|
|
});
|
2013-09-07 16:52:56 +04:00
|
|
|
|
2013-08-22 16:29:00 +04:00
|
|
|
//update counters
|
2013-09-04 17:24:25 +04:00
|
|
|
$(dialog_id).on('click', '.replacement,.allnewfiles', function() {
|
2013-09-18 19:22:29 +04:00
|
|
|
var count = $(dialog_id).find('.conflict .replacement input[type="checkbox"]:checked').length;
|
|
|
|
if (count === $(dialog_id+ ' .conflict').length) {
|
2013-08-22 16:29:00 +04:00
|
|
|
$(dialog_id).find('.allnewfiles').prop('checked', true);
|
|
|
|
$(dialog_id).find('.allnewfiles + .count').text(t('files','(all selected)'));
|
|
|
|
} else if (count > 0) {
|
|
|
|
$(dialog_id).find('.allnewfiles').prop('checked', false);
|
|
|
|
$(dialog_id).find('.allnewfiles + .count').text(t('files','({count} selected)',{count:count}));
|
|
|
|
} else {
|
|
|
|
$(dialog_id).find('.allnewfiles').prop('checked', false);
|
|
|
|
$(dialog_id).find('.allnewfiles + .count').text('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(dialog_id).on('click', '.original,.allexistingfiles', function(){
|
2013-09-18 19:22:29 +04:00
|
|
|
var count = $(dialog_id).find('.conflict .original input[type="checkbox"]:checked').length;
|
|
|
|
if (count === $(dialog_id+ ' .conflict').length) {
|
2013-08-22 16:29:00 +04:00
|
|
|
$(dialog_id).find('.allexistingfiles').prop('checked', true);
|
|
|
|
$(dialog_id).find('.allexistingfiles + .count').text(t('files','(all selected)'));
|
|
|
|
} else if (count > 0) {
|
|
|
|
$(dialog_id).find('.allexistingfiles').prop('checked', false);
|
|
|
|
$(dialog_id).find('.allexistingfiles + .count').text(t('files','({count} selected)',{count:count}));
|
|
|
|
} else {
|
|
|
|
$(dialog_id).find('.allexistingfiles').prop('checked', false);
|
|
|
|
$(dialog_id).find('.allexistingfiles + .count').text('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.fail(function() {
|
|
|
|
alert(t('core', 'Error loading file exists template'));
|
|
|
|
});
|
|
|
|
}
|
2013-09-07 00:40:10 +04:00
|
|
|
//}
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
2013-05-17 10:42:15 +04:00
|
|
|
_getFilePickerTemplate: function() {
|
|
|
|
var defer = $.Deferred();
|
|
|
|
if(!this.$filePickerTemplate) {
|
|
|
|
var self = this;
|
|
|
|
$.get(OC.filePath('core', 'templates', 'filepicker.html'), function(tmpl) {
|
|
|
|
self.$filePickerTemplate = $(tmpl);
|
|
|
|
self.$listTmpl = self.$filePickerTemplate.find('.filelist li:first-child').detach();
|
|
|
|
defer.resolve(self.$filePickerTemplate);
|
|
|
|
})
|
2013-09-11 18:02:12 +04:00
|
|
|
.fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
|
defer.reject(jqXHR.status, errorThrown);
|
2013-05-17 10:42:15 +04: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 18:02:12 +04:00
|
|
|
.fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
|
defer.reject(jqXHR.status, errorThrown);
|
2013-05-17 10:42:15 +04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
defer.resolve(this.$messageTemplate);
|
|
|
|
}
|
|
|
|
return defer.promise();
|
|
|
|
},
|
2013-08-12 14:33:22 +04: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();
|
|
|
|
},
|
2013-05-17 10:42:15 +04:00
|
|
|
_getFileList: function(dir, mimeType) {
|
2013-09-05 20:40:55 +04:00
|
|
|
if (typeof(mimeType) === "string") {
|
2013-09-06 15:33:17 +04:00
|
|
|
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(
|
|
|
|
OC.filePath('files', 'ajax', 'rawlist.php'),
|
2013-09-05 20:40:55 +04:00
|
|
|
{
|
|
|
|
dir: dir,
|
|
|
|
mimetypes: JSON.stringify(mimeType)
|
|
|
|
}
|
2013-05-17 10:42:15 +04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
_determineValue: function(element) {
|
2013-04-06 12:07:12 +04:00
|
|
|
if ( $(element).attr('type') === 'checkbox' ) {
|
|
|
|
return element.checked;
|
|
|
|
} else {
|
|
|
|
return $(element).val();
|
2012-05-05 15:48:12 +04:00
|
|
|
}
|
|
|
|
},
|
2013-04-06 12:07:12 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* fills the filepicker with files
|
|
|
|
*/
|
2013-05-17 10:42:15 +04:00
|
|
|
_fillFilePicker:function(dir) {
|
2013-04-06 16:42:56 +04:00
|
|
|
var dirs = [];
|
|
|
|
var others = [];
|
2013-05-16 02:23:05 +04:00
|
|
|
var self = this;
|
2013-05-17 06:54:08 +04:00
|
|
|
this.$filelist.empty().addClass('loading');
|
|
|
|
this.$filePicker.data('path', dir);
|
|
|
|
$.when(this._getFileList(dir, this.$filePicker.data('mimetype'))).then(function(response) {
|
|
|
|
$.each(response.data, function(index, file) {
|
|
|
|
if (file.type === 'dir') {
|
|
|
|
dirs.push(file);
|
|
|
|
} else {
|
|
|
|
others.push(file);
|
|
|
|
}
|
2013-05-16 02:23:05 +04:00
|
|
|
});
|
|
|
|
|
2013-05-17 10:42:15 +04:00
|
|
|
self._fillSlug();
|
2013-05-17 06:54:08 +04:00
|
|
|
var sorted = dirs.concat(others);
|
2013-05-16 02:23:05 +04:00
|
|
|
|
2013-05-17 06:54:08 +04:00
|
|
|
$.each(sorted, function(idx, entry) {
|
2013-07-31 23:21:02 +04:00
|
|
|
var $li = self.$listTmpl.octemplate({
|
2013-05-17 06:54:08 +04:00
|
|
|
type: entry.type,
|
|
|
|
dir: dir,
|
|
|
|
filename: entry.name,
|
|
|
|
date: OC.mtime2date(entry.mtime)
|
|
|
|
});
|
2013-09-14 16:35:23 +04:00
|
|
|
$li.find('img').attr('src', entry.mimetype_icon);
|
2013-05-17 06:54:08 +04:00
|
|
|
self.$filelist.append($li);
|
|
|
|
});
|
2013-04-06 21:21:15 +04:00
|
|
|
|
2013-05-17 06:54:08 +04:00
|
|
|
self.$filelist.removeClass('loading');
|
|
|
|
});
|
2012-05-05 15:48:12 +04:00
|
|
|
},
|
2013-04-06 12:07:12 +04:00
|
|
|
/**
|
|
|
|
* fills the tree list with directories
|
|
|
|
*/
|
2013-05-17 10:42:15 +04:00
|
|
|
_fillSlug: function() {
|
2013-05-17 06:54:08 +04:00
|
|
|
this.$dirTree.empty();
|
2013-08-12 14:33:22 +04:00
|
|
|
var self = this;
|
2013-05-17 06:54:08 +04:00
|
|
|
var path = this.$filePicker.data('path');
|
|
|
|
var $template = $('<span data-dir="{dir}">{name}</span>');
|
2013-05-17 09:14:43 +04:00
|
|
|
if(path) {
|
|
|
|
var paths = path.split('/');
|
|
|
|
$.each(paths, function(index, dir) {
|
2013-07-31 23:21:02 +04:00
|
|
|
dir = paths.pop();
|
2013-05-17 09:14:43 +04:00
|
|
|
if(dir === '') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
self.$dirTree.prepend($template.octemplate({
|
|
|
|
dir: paths.join('/') + '/' + dir,
|
|
|
|
name: dir
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
2013-05-17 18:18:40 +04:00
|
|
|
$template.octemplate({
|
2013-05-17 06:54:08 +04:00
|
|
|
dir: '',
|
2013-05-17 18:18:40 +04:00
|
|
|
name: ' ' // Ugly but works ;)
|
|
|
|
}, {escapeFunction: null}).addClass('home svg').prependTo(this.$dirTree);
|
2013-04-06 12:07:12 +04:00
|
|
|
},
|
2013-04-06 18:44:13 +04:00
|
|
|
/**
|
|
|
|
* handle selection made in the tree list
|
|
|
|
*/
|
2013-05-17 10:42:15 +04:00
|
|
|
_handleTreeListSelect:function(event) {
|
2013-05-17 06:54:08 +04:00
|
|
|
var self = event.data;
|
|
|
|
var dir = $(event.target).data('dir');
|
2013-05-17 10:42:15 +04:00
|
|
|
self._fillFilePicker(dir);
|
2013-04-06 12:07:12 +04:00
|
|
|
},
|
2013-04-06 18:44:13 +04:00
|
|
|
/**
|
|
|
|
* handle clicks made in the filepicker
|
|
|
|
*/
|
2013-05-17 10:42:15 +04:00
|
|
|
_handlePickerClick:function(event, $element) {
|
2013-05-17 06:54:08 +04: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 15:48:12 +04:00
|
|
|
}
|
2013-05-17 06:54:08 +04:00
|
|
|
$element.toggleClass('filepicker_element_selected');
|
2012-05-05 15:48:12 +04:00
|
|
|
return;
|
2013-05-17 06:54:08 +04:00
|
|
|
} else if ( $element.data('type') === 'dir' ) {
|
2013-07-31 23:21:02 +04:00
|
|
|
this._fillFilePicker(this.$filePicker.data('path') + '/' + $element.data('entryname'));
|
2012-05-05 15:48:12 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-29 02:02:02 +04:00
|
|
|
};
|