2012-02-03 00:59:40 +01:00
|
|
|
(function($) {
|
|
|
|
$.widget('blueimpUIX.fileupload', $.blueimpUI.fileupload, {
|
|
|
|
_initTemplates: function() {
|
2013-05-27 05:22:59 +02:00
|
|
|
this.options.templateContainer = document.createElement(
|
|
|
|
this._files.prop('nodeName')
|
|
|
|
);
|
|
|
|
this.options.uploadTemplate = window.tmpl(this.options.uploadTemplateName);
|
|
|
|
this.options.downloadTemplate = window.tmpl(this.options.downloadTemplateName);
|
|
|
|
},
|
2012-02-03 00:59:40 +01:00
|
|
|
_enableFileInputButton: function() {
|
|
|
|
$.blueimpUI.fileupload.prototype._enableFileInputButton.call(this);
|
|
|
|
this.element.find('.ss-uploadfield-addfile').show();
|
|
|
|
},
|
|
|
|
_disableFileInputButton: function() {
|
|
|
|
$.blueimpUI.fileupload.prototype._disableFileInputButton.call(this);
|
|
|
|
this.element.find('.ss-uploadfield-addfile').hide();
|
|
|
|
},
|
|
|
|
_onAdd: function(e, data) {
|
|
|
|
// use _onAdd instead of add since we only want it called once for a file set, not for each file
|
|
|
|
var result = $.blueimpUI.fileupload.prototype._onAdd.call(this, e, data);
|
|
|
|
var firstNewFile = this._files.find('.ss-uploadfield-item').slice(data.files.length*-1).first();
|
2012-05-20 12:22:04 +02:00
|
|
|
var top = '+=' + (firstNewFile.position().top - parseInt(firstNewFile.css('marginTop'), 10) || 0 - parseInt(firstNewFile.css('borderTopWidth'), 10) || 0);
|
2012-02-03 00:59:40 +01:00
|
|
|
firstNewFile.offsetParent().animate({scrollTop: top}, 1000);
|
2012-05-09 08:38:21 +02:00
|
|
|
|
|
|
|
/* Compute total size of files */
|
|
|
|
var fSize = 0;
|
|
|
|
for(var i = 0; i < data.files.length; i++){
|
|
|
|
if(typeof data.files[i].size === 'number'){
|
|
|
|
fSize = fSize + data.files[i].size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.fileOverview .uploadStatus .details .total').text(data.files.length);
|
|
|
|
if(typeof fSize === 'number' && fSize > 0){
|
|
|
|
fSize = this._formatFileSize(fSize);
|
|
|
|
$('.fileOverview .uploadStatus .details .fileSize').text(fSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Fixes case where someone uploads a single erroring file
|
|
|
|
if(data.files.length == 1 && data.files[0].error !== null){
|
|
|
|
$('.fileOverview .uploadStatus .state').text(ss.i18n._t('AssetUploadField.UploadField.UPLOADFAIL', 'Sorry your upload failed'));
|
2012-11-02 00:46:16 +01:00
|
|
|
$('.fileOverview .uploadStatus').addClass("bad").removeClass("good").removeClass("notice");
|
2012-05-09 08:38:21 +02:00
|
|
|
}else{
|
|
|
|
$('.fileOverview .uploadStatus .state').text(ss.i18n._t('AssetUploadField.UPLOADINPROGRESS', 'Please wait… upload in progress'));//.show();
|
2012-11-02 00:46:16 +01:00
|
|
|
$('.ss-uploadfield-item-edit-all').hide();
|
|
|
|
$('.fileOverview .uploadStatus').addClass("notice").removeClass("good").removeClass("bad");
|
2012-05-09 08:38:21 +02:00
|
|
|
}
|
|
|
|
|
2012-02-03 00:59:40 +01:00
|
|
|
return result;
|
2012-05-09 08:38:21 +02:00
|
|
|
},
|
2013-10-24 06:07:29 +02:00
|
|
|
_onDone: function (result, textStatus, jqXHR, options) {
|
|
|
|
// Mark form as dirty on completion of successful upload
|
2013-11-06 10:07:04 +01:00
|
|
|
if(this.options.changeDetection) {
|
|
|
|
this.element.closest('form').trigger('dirty');
|
|
|
|
}
|
|
|
|
|
2013-10-24 06:07:29 +02:00
|
|
|
$.blueimpUI.fileupload.prototype._onDone.call(this, result, textStatus, jqXHR, options);
|
|
|
|
},
|
2013-03-08 04:02:38 +01:00
|
|
|
_onSend: function (e, data) {
|
|
|
|
//check the array of existing files to see if we are trying to upload a file that already exists
|
|
|
|
var that = this;
|
2013-05-27 05:22:59 +02:00
|
|
|
var config = this.options;
|
2014-04-16 11:08:25 +02:00
|
|
|
if (config.overwriteWarning && config.replaceFile) {
|
2013-05-27 05:22:59 +02:00
|
|
|
$.get(
|
|
|
|
config['urlFileExists'],
|
|
|
|
{'filename': data.files[0].name},
|
|
|
|
function(response, status, xhr) {
|
|
|
|
if(response.exists) {
|
|
|
|
//display the dialogs with the question to overwrite or not
|
|
|
|
data.context.find('.ss-uploadfield-item-status')
|
|
|
|
.text(config.errorMessages.overwriteWarning)
|
|
|
|
.addClass('ui-state-warning-text');
|
|
|
|
data.context.find('.ss-uploadfield-item-progress').hide();
|
|
|
|
data.context.find('.ss-uploadfield-item-overwrite').show();
|
2013-06-20 05:21:18 +02:00
|
|
|
data.context.find('.ss-uploadfield-item-overwrite-warning').on('click', function(e){
|
2013-05-27 05:22:59 +02:00
|
|
|
data.context.find('.ss-uploadfield-item-progress').show();
|
|
|
|
data.context.find('.ss-uploadfield-item-overwrite').hide();
|
|
|
|
data.context.find('.ss-uploadfield-item-status')
|
|
|
|
.removeClass('ui-state-warning-text');
|
|
|
|
//upload only if the "overwrite" button is clicked
|
|
|
|
$.blueimpUI.fileupload.prototype._onSend.call(that, e, data);
|
2013-06-20 05:21:18 +02:00
|
|
|
|
|
|
|
e.preventDefault(); // Avoid a form submit
|
|
|
|
return false;
|
2013-05-27 05:22:59 +02:00
|
|
|
});
|
|
|
|
} else { //regular file upload
|
|
|
|
return $.blueimpUI.fileupload.prototype._onSend.call(that, e, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
2013-03-08 04:02:38 +01:00
|
|
|
return $.blueimpUI.fileupload.prototype._onSend.call(that, e, data);
|
|
|
|
}
|
|
|
|
},
|
2012-05-09 08:38:21 +02:00
|
|
|
_onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) {
|
2012-05-20 12:22:04 +02:00
|
|
|
$.blueimpUI.fileupload.prototype._onAlways.call(this, jqXHRorResult, textStatus, jqXHRorError, options);
|
2014-07-29 01:27:54 +02:00
|
|
|
|
|
|
|
if(typeof(jqXHRorError) === 'string') {
|
|
|
|
$('.fileOverview .uploadStatus .state').text(ss.i18n._t('AssetUploadField.UploadField.UPLOADFAIL', 'Sorry your upload failed'));
|
|
|
|
$('.fileOverview .uploadStatus').addClass("bad").removeClass("good").removeClass("notice");
|
|
|
|
} else if (jqXHRorError.status === 200) {
|
2012-11-02 00:46:16 +01:00
|
|
|
$('.fileOverview .uploadStatus .state').text(ss.i18n._t('AssetUploadField.FILEUPLOADCOMPLETED', 'File upload completed!'));//.hide();
|
|
|
|
$('.ss-uploadfield-item-edit-all').show();
|
|
|
|
$('.fileOverview .uploadStatus').addClass("good").removeClass("notice").removeClass("bad");
|
2012-05-20 12:22:04 +02:00
|
|
|
}
|
2013-05-27 05:22:59 +02:00
|
|
|
},
|
|
|
|
_create: function() {
|
|
|
|
$.blueimpUI.fileupload.prototype._create.call(this);
|
|
|
|
// Ensures that the visibility of the fileupload dialog is set correctly at initialisation
|
|
|
|
this._adjustMaxNumberOfFiles(0);
|
|
|
|
},
|
|
|
|
attach: function(data) {
|
2013-11-06 10:07:04 +01:00
|
|
|
if(this.options.changeDetection) {
|
|
|
|
this.element.closest('form').trigger('dirty');
|
|
|
|
}
|
2013-05-27 05:22:59 +02:00
|
|
|
|
|
|
|
// Handles attachment of already uploaded files, similar to add
|
|
|
|
var self = this,
|
|
|
|
files = data.files,
|
|
|
|
replaceFileID = data.replaceFileID,
|
|
|
|
valid = true;
|
|
|
|
|
|
|
|
// If replacing an element (and it exists), adjust max number of files at this point
|
|
|
|
var replacedElement = null;
|
|
|
|
if(replaceFileID) {
|
|
|
|
replacedElement = $(".ss-uploadfield-item[data-fileid='"+replaceFileID+"']");
|
|
|
|
if(replacedElement.length === 0) {
|
|
|
|
replacedElement = null;
|
|
|
|
} else {
|
|
|
|
self._adjustMaxNumberOfFiles(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate each file
|
|
|
|
$.each(files, function (index, file) {
|
|
|
|
self._adjustMaxNumberOfFiles(-1);
|
|
|
|
error = self._validate([file]);
|
|
|
|
valid = error && valid;
|
|
|
|
});
|
|
|
|
data.isAdjusted = true;
|
|
|
|
data.files.valid = data.isValidated = valid;
|
|
|
|
|
|
|
|
// Generate new file HTMl, and either append or replace (if replacing
|
|
|
|
// an already uploaded file).
|
|
|
|
data.context = this._renderDownload(files);
|
|
|
|
if(replacedElement) {
|
|
|
|
replacedElement.replaceWith(data.context);
|
|
|
|
} else {
|
|
|
|
data.context.appendTo(this._files);
|
|
|
|
}
|
|
|
|
data.context.data('data', data);
|
|
|
|
// Force reflow:
|
|
|
|
this._reflow = this._transition && data.context[0].offsetWidth;
|
|
|
|
data.context.addClass('in');
|
|
|
|
}
|
2012-02-03 00:59:40 +01:00
|
|
|
});
|
2012-05-09 08:38:21 +02:00
|
|
|
|
|
|
|
|
2012-02-03 00:59:40 +01:00
|
|
|
$.entwine('ss', function($) {
|
2012-05-09 08:38:21 +02:00
|
|
|
|
2012-02-03 00:59:40 +01:00
|
|
|
$('div.ss-upload').entwine({
|
2012-02-08 00:58:58 +01:00
|
|
|
|
|
|
|
Config: null,
|
|
|
|
|
2012-02-03 00:59:40 +01:00
|
|
|
onmatch: function() {
|
2012-03-02 00:43:14 +01:00
|
|
|
|
2015-09-21 00:00:05 +02:00
|
|
|
if (this.is('.readonly,.disabled')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var $fileInput = this.find('.ss-uploadfield-fromcomputer-fileinput'),
|
|
|
|
$dropZone = $('.ss-uploadfield-dropzone'),
|
|
|
|
config = $fileInput.data('config');
|
|
|
|
|
|
|
|
// Drag & drop is opt-in so we have to prevent the default behaviour
|
|
|
|
// (which is 'do nothing') when the drop zone is dragged over.
|
|
|
|
$dropZone.on('dragover', function (e) {
|
|
|
|
e.preventDefault();
|
2012-04-17 23:55:02 +02:00
|
|
|
});
|
2015-09-21 00:00:05 +02:00
|
|
|
|
|
|
|
$dropZone.on('dragenter', function (e) {
|
|
|
|
$dropZone.addClass('hover active');
|
|
|
|
});
|
|
|
|
|
|
|
|
$dropZone.on('dragleave', function (e) {
|
|
|
|
if (e.target === $dropZone[0]) {
|
|
|
|
$dropZone.removeClass('hover active');
|
|
|
|
}
|
2012-04-17 23:55:02 +02:00
|
|
|
});
|
2012-04-18 00:51:53 +02:00
|
|
|
|
2015-09-21 00:00:05 +02:00
|
|
|
$dropZone.on('drop', function (e) {
|
|
|
|
$dropZone.removeClass('hover active');
|
|
|
|
|
|
|
|
if (e.target !== $dropZone[0]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2012-02-08 00:58:58 +01:00
|
|
|
this.setConfig(config);
|
2015-09-21 00:00:05 +02:00
|
|
|
this.fileupload($.extend(true, {
|
2012-02-03 00:59:40 +01:00
|
|
|
formData: function(form) {
|
2012-07-20 03:11:38 +02:00
|
|
|
var idVal = $(form).find(':input[name=ID]').val();
|
2013-10-31 21:27:39 +01:00
|
|
|
var data = [{name: 'SecurityID', value: $(form).find(':input[name=SecurityID]').val()}];
|
|
|
|
if(idVal) data.push({name: 'ID', value: idVal});
|
|
|
|
|
|
|
|
return data;
|
2012-02-03 00:59:40 +01:00
|
|
|
},
|
|
|
|
errorMessages: {
|
2013-05-27 05:22:59 +02:00
|
|
|
// errorMessages for all error codes suggested from the plugin author, some will be overwritten by the config coming from php
|
2012-02-03 00:59:40 +01:00
|
|
|
1: ss.i18n._t('UploadField.PHP_MAXFILESIZE'),
|
|
|
|
2: ss.i18n._t('UploadField.HTML_MAXFILESIZE'),
|
|
|
|
3: ss.i18n._t('UploadField.ONLYPARTIALUPLOADED'),
|
|
|
|
4: ss.i18n._t('UploadField.NOFILEUPLOADED'),
|
|
|
|
5: ss.i18n._t('UploadField.NOTMPFOLDER'),
|
|
|
|
6: ss.i18n._t('UploadField.WRITEFAILED'),
|
|
|
|
7: ss.i18n._t('UploadField.STOPEDBYEXTENSION'),
|
2012-05-09 08:38:21 +02:00
|
|
|
maxFileSize: ss.i18n._t('UploadField.TOOLARGESHORT'),
|
2012-02-03 00:59:40 +01:00
|
|
|
minFileSize: ss.i18n._t('UploadField.TOOSMALL'),
|
2012-05-09 08:38:21 +02:00
|
|
|
acceptFileTypes: ss.i18n._t('UploadField.INVALIDEXTENSIONSHORT'),
|
|
|
|
maxNumberOfFiles: ss.i18n._t('UploadField.MAXNUMBEROFFILESSHORT'),
|
2012-02-03 00:59:40 +01:00
|
|
|
uploadedBytes: ss.i18n._t('UploadField.UPLOADEDBYTES'),
|
|
|
|
emptyResult: ss.i18n._t('UploadField.EMPTYRESULT')
|
|
|
|
},
|
|
|
|
send: function(e, data) {
|
2012-02-08 00:58:58 +01:00
|
|
|
if (data.context && data.dataType && data.dataType.substr(0, 6) === 'iframe') {
|
|
|
|
// Iframe Transport does not support progress events.
|
|
|
|
// In lack of an indeterminate progress bar, we set
|
|
|
|
// the progress to 100%, showing the full animated bar:
|
|
|
|
data.total = 1;
|
|
|
|
data.loaded = 1;
|
|
|
|
$(this).data('fileupload').options.progress(e, data);
|
|
|
|
}
|
2012-02-03 00:59:40 +01:00
|
|
|
},
|
|
|
|
progress: function(e, data) {
|
2012-02-08 00:58:58 +01:00
|
|
|
if (data.context) {
|
|
|
|
var value = parseInt(data.loaded / data.total * 100, 10) + '%';
|
|
|
|
data.context.find('.ss-uploadfield-item-status').html((data.total == 1)?ss.i18n._t('UploadField.LOADING'):value);
|
2012-05-09 08:38:21 +02:00
|
|
|
data.context.find('.ss-uploadfield-item-progressbarvalue').css('width', value);
|
2012-02-08 00:58:58 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-03 00:59:40 +01:00
|
|
|
},
|
|
|
|
config,
|
|
|
|
{
|
2015-09-21 00:00:05 +02:00
|
|
|
fileInput: $fileInput,
|
|
|
|
dropZone: $dropZone,
|
|
|
|
form: $fileInput.closest('form'),
|
2012-02-03 00:59:40 +01:00
|
|
|
previewAsCanvas: false,
|
|
|
|
acceptFileTypes: new RegExp(config.acceptFileTypes, 'i')
|
|
|
|
}
|
|
|
|
));
|
2012-10-31 11:34:12 +01:00
|
|
|
|
2012-02-03 00:59:40 +01:00
|
|
|
if (this.data('fileupload')._isXHRUpload({multipart: true})) {
|
2013-02-04 22:00:02 +01:00
|
|
|
$('.ss-uploadfield-item-uploador').hide().show();
|
2012-02-03 00:59:40 +01:00
|
|
|
}
|
2012-05-09 08:38:21 +02:00
|
|
|
|
2012-02-03 00:59:40 +01:00
|
|
|
this._super();
|
2012-02-08 00:58:58 +01:00
|
|
|
},
|
2012-05-14 01:43:36 +02:00
|
|
|
onunmatch: function() {
|
2015-09-28 22:58:01 +02:00
|
|
|
$('.ss-uploadfield-dropzone').off('dragover dragenter dragleave drop');
|
2012-05-14 01:43:36 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2013-03-26 22:56:08 +01:00
|
|
|
openSelectDialog: function(uploadedFile) {
|
2012-02-08 00:58:58 +01:00
|
|
|
// Create dialog and load iframe
|
|
|
|
var self = this, config = this.getConfig(), dialogId = 'ss-uploadfield-dialog-' + this.attr('id'), dialog = jQuery('#' + dialogId);
|
|
|
|
if(!dialog.length) dialog = jQuery('<div class="ss-uploadfield-dialog" id="' + dialogId + '" />');
|
2013-03-26 22:56:08 +01:00
|
|
|
|
|
|
|
// If user selected 'Choose another file', we need the ID of the file to replace
|
|
|
|
var iframeUrl = config['urlSelectDialog'];
|
|
|
|
var uploadedFileId = null;
|
|
|
|
if (uploadedFile && uploadedFile.attr('data-fileid') > 0){
|
|
|
|
uploadedFileId = uploadedFile.attr('data-fileid');
|
|
|
|
}
|
|
|
|
|
2012-02-08 00:58:58 +01:00
|
|
|
// Show dialog
|
2013-03-26 22:56:08 +01:00
|
|
|
dialog.ssdialog({iframeUrl: iframeUrl, height: 550});
|
2012-02-08 00:58:58 +01:00
|
|
|
|
|
|
|
// TODO Allow single-select
|
|
|
|
dialog.find('iframe').bind('load', function(e) {
|
2012-02-23 15:17:39 +01:00
|
|
|
var contents = $(this).contents(), gridField = contents.find('.ss-gridfield');
|
2012-02-08 00:58:58 +01:00
|
|
|
// TODO Fix jQuery custom event bubbling across iframes on same domain
|
|
|
|
// gridField.find('.ss-gridfield-items')).bind('selectablestop', function() {
|
|
|
|
// });
|
|
|
|
|
|
|
|
// Remove top margin (easier than including new selectors)
|
|
|
|
contents.find('table.ss-gridfield').css('margin-top', 0);
|
|
|
|
|
|
|
|
// Can't use live() in iframes...
|
|
|
|
contents.find('input[name=action_doAttach]').unbind('click.openSelectDialog').bind('click.openSelectDialog', function() {
|
|
|
|
// TODO Fix entwine method calls across iframe/document boundaries
|
|
|
|
var ids = $.map(gridField.find('.ss-gridfield-item.ui-selected'), function(el) {return $(el).data('id');});
|
2013-03-26 22:56:08 +01:00
|
|
|
if(ids && ids.length) self.attachFiles(ids, uploadedFileId);
|
2012-02-08 00:58:58 +01:00
|
|
|
|
|
|
|
dialog.ssdialog('close');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
dialog.ssdialog('open');
|
|
|
|
},
|
2013-03-26 22:56:08 +01:00
|
|
|
attachFiles: function(ids, uploadedFileId) {
|
2014-03-03 22:27:45 +01:00
|
|
|
var self = this,
|
|
|
|
config = this.getConfig(),
|
|
|
|
indicator = $('<div class="loader" />'),
|
|
|
|
target = (uploadedFileId) ? this.find(".ss-uploadfield-item[data-fileid='"+uploadedFileId+"']") : this.find('.ss-uploadfield-addfile');
|
|
|
|
|
|
|
|
target.children().hide();
|
|
|
|
target.append(indicator);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: config['urlAttach'],
|
|
|
|
data: {'ids': ids},
|
|
|
|
complete: function(xhr, status) {
|
|
|
|
target.children().show();
|
|
|
|
indicator.remove();
|
|
|
|
},
|
|
|
|
success: function(data, status, xhr) {
|
2015-09-09 10:24:56 +02:00
|
|
|
if (!data || $.isEmptyObject(data)) return;
|
|
|
|
|
2013-05-27 05:22:59 +02:00
|
|
|
self.fileupload('attach', {
|
2012-02-08 00:58:58 +01:00
|
|
|
files: data,
|
2013-05-27 05:22:59 +02:00
|
|
|
options: self.fileupload('option'),
|
|
|
|
replaceFileID: uploadedFileId
|
|
|
|
});
|
2012-02-08 00:58:58 +01:00
|
|
|
}
|
2014-03-03 22:27:45 +01:00
|
|
|
});
|
2012-02-08 00:58:58 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$('div.ss-upload *').entwine({
|
|
|
|
getUploadField: function() {
|
2012-04-17 23:55:02 +02:00
|
|
|
|
2012-02-08 00:58:58 +01:00
|
|
|
return this.parents('div.ss-upload:first');
|
2012-02-03 00:59:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$('div.ss-upload .ss-uploadfield-files .ss-uploadfield-item').entwine({
|
2014-07-14 01:15:38 +02:00
|
|
|
onadd: function() {
|
2012-05-11 06:07:07 +02:00
|
|
|
this._super();
|
2012-02-03 00:59:40 +01:00
|
|
|
this.closest('.ss-upload').find('.ss-uploadfield-addfile').addClass('borderTop');
|
|
|
|
},
|
2014-07-14 01:15:38 +02:00
|
|
|
onremove: function() {
|
2012-02-03 00:59:40 +01:00
|
|
|
$('.ss-uploadfield-files:not(:has(.ss-uploadfield-item))').closest('.ss-upload').find('.ss-uploadfield-addfile').removeClass('borderTop');
|
2012-05-11 06:07:07 +02:00
|
|
|
this._super();
|
2012-02-03 00:59:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$('div.ss-upload .ss-uploadfield-startall').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
this.closest('.ss-upload').find('.ss-uploadfield-item-start button').click();
|
2013-06-20 05:21:18 +02:00
|
|
|
e.preventDefault(); // Avoid a form submit
|
2012-02-03 00:59:40 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('div.ss-upload .ss-uploadfield-item-cancelfailed').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
this.closest('.ss-uploadfield-item').remove();
|
2013-06-20 05:21:18 +02:00
|
|
|
e.preventDefault(); // Avoid a form submit
|
2012-02-03 00:59:40 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2012-05-09 08:38:21 +02:00
|
|
|
|
2015-09-21 00:00:05 +02:00
|
|
|
$('div.ss-upload .upload-url').entwine({
|
|
|
|
onclick: function () {
|
|
|
|
$('.htmleditorfield-from-web').slideToggle(150, 'linear').find('input.remoteurl').focus();
|
|
|
|
}
|
|
|
|
});
|
2012-05-09 08:38:21 +02:00
|
|
|
|
2012-02-03 00:59:40 +01:00
|
|
|
$('div.ss-upload .ss-uploadfield-item-remove:not(.ui-state-disabled), .ss-uploadfield-item-delete:not(.ui-state-disabled)').entwine({
|
|
|
|
onclick: function(e) {
|
2013-11-06 10:07:04 +01:00
|
|
|
var field = this.closest('div.ss-upload'),
|
|
|
|
config = field.getConfig('changeDetection'),
|
|
|
|
fileupload = field.data('fileupload'),
|
2012-02-03 00:59:40 +01:00
|
|
|
item = this.closest('.ss-uploadfield-item'), msg = '';
|
|
|
|
|
2013-05-27 05:22:59 +02:00
|
|
|
if(this.is('.ss-uploadfield-item-delete')) {
|
|
|
|
if(confirm(ss.i18n._t('UploadField.ConfirmDelete'))) {
|
2013-11-06 10:07:04 +01:00
|
|
|
if(config.changeDetection) {
|
|
|
|
this.closest('form').trigger('dirty');
|
|
|
|
}
|
2014-07-14 01:15:38 +02:00
|
|
|
|
|
|
|
if (fileupload) {
|
|
|
|
fileupload._trigger('destroy', e, {
|
|
|
|
context: item,
|
|
|
|
url: this.data('href'),
|
|
|
|
type: 'get',
|
|
|
|
dataType: fileupload.options.dataType
|
|
|
|
});
|
|
|
|
}
|
2013-05-27 05:22:59 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Removed files will be applied to object on save
|
2013-11-06 10:07:04 +01:00
|
|
|
if(config.changeDetection) {
|
|
|
|
this.closest('form').trigger('dirty');
|
|
|
|
}
|
2014-07-14 01:15:38 +02:00
|
|
|
|
|
|
|
if (fileupload) {
|
|
|
|
fileupload._trigger('destroy', e, {context: item});
|
|
|
|
}
|
2012-02-03 00:59:40 +01:00
|
|
|
}
|
|
|
|
|
2013-06-20 05:21:18 +02:00
|
|
|
e.preventDefault(); // Avoid a form submit
|
2012-02-03 00:59:40 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2012-05-09 08:38:21 +02:00
|
|
|
|
2012-11-02 00:46:16 +01:00
|
|
|
$('div.ss-upload .ss-uploadfield-item-edit-all').entwine({
|
2012-05-09 08:38:21 +02:00
|
|
|
onclick: function(e) {
|
|
|
|
|
|
|
|
if($(this).hasClass('opened')){
|
|
|
|
$('.ss-uploadfield-item .ss-uploadfield-item-edit .toggle-details-icon.opened').each(function(i){
|
|
|
|
$(this).closest('.ss-uploadfield-item-edit').click();
|
|
|
|
});
|
|
|
|
$(this).removeClass('opened').find('.toggle-details-icon').removeClass('opened');
|
|
|
|
}else{
|
|
|
|
$('.ss-uploadfield-item .ss-uploadfield-item-edit .toggle-details-icon').each(function(i){
|
|
|
|
if(!$(this).hasClass('opened')){
|
|
|
|
$(this).closest('.ss-uploadfield-item-edit').click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(this).addClass('opened').find('.toggle-details-icon').addClass('opened');
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault(); // Avoid a form submit
|
2013-06-20 05:21:18 +02:00
|
|
|
return false;
|
2012-05-09 08:38:21 +02:00
|
|
|
}
|
|
|
|
});
|
2013-05-27 05:22:59 +02:00
|
|
|
$( 'div.ss-upload:not(.disabled):not(.readonly) .ss-uploadfield-item-edit').entwine({
|
2012-02-03 00:59:40 +01:00
|
|
|
onclick: function(e) {
|
2013-12-12 14:17:57 +01:00
|
|
|
var self = this,
|
|
|
|
editform = self.closest('.ss-uploadfield-item').find('.ss-uploadfield-item-editform'),
|
|
|
|
itemInfo = editform.prev('.ss-uploadfield-item-info'),
|
|
|
|
iframe = editform.find('iframe');
|
|
|
|
|
|
|
|
// Ignore clicks while the iframe is loading
|
|
|
|
if (iframe.parent().hasClass('loading')) {
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iframe.attr('src') == 'about:blank') {
|
|
|
|
// Lazy-load the iframe on editform toggle
|
|
|
|
iframe.attr('src', iframe.data('src'));
|
|
|
|
|
|
|
|
// Add loading class, disable buttons while loading is in progress
|
|
|
|
// (_prepareIframe() handles re-enabling them when appropriate)
|
|
|
|
iframe.parent().addClass('loading');
|
|
|
|
disabled=this.siblings();
|
|
|
|
disabled.addClass('ui-state-disabled');
|
|
|
|
disabled.attr('disabled', 'disabled');
|
|
|
|
|
|
|
|
iframe.on('load', function() {
|
|
|
|
iframe.parent().removeClass('loading');
|
|
|
|
|
|
|
|
// This ensures we only call _prepareIframe() on load once - otherwise it'll
|
|
|
|
// be superfluously called after clicking 'save' in the editform
|
|
|
|
if (iframe.data('src')) {
|
|
|
|
self._prepareIframe(iframe, editform, itemInfo);
|
|
|
|
iframe.data('src', '');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self._prepareIframe(iframe, editform, itemInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault(); // Avoid a form submit
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
_prepareIframe: function(iframe, editform, itemInfo) {
|
|
|
|
var disabled;
|
|
|
|
|
2012-05-11 12:40:57 +02:00
|
|
|
// Mark the row as changed if any of its form fields are edited
|
|
|
|
iframe.contents().ready(function() {
|
|
|
|
// Need to use the iframe's own jQuery, as custom event triggers
|
|
|
|
// (e.g. from TreeDropdownField) can't be captured by the parent jQuery object.
|
|
|
|
var iframe_jQuery = iframe.get(0).contentWindow.jQuery;
|
|
|
|
iframe_jQuery(iframe_jQuery.find(':input')).bind('change', function(e){
|
2012-05-11 04:43:17 +02:00
|
|
|
editform.removeClass('edited');
|
2012-05-09 08:38:21 +02:00
|
|
|
editform.addClass('edited');
|
|
|
|
});
|
2012-05-11 12:40:57 +02:00
|
|
|
});
|
|
|
|
|
2012-02-03 00:59:40 +01:00
|
|
|
if (editform.hasClass('loading')) {
|
|
|
|
// TODO Display loading indication, and register an event to toggle edit form
|
|
|
|
} else {
|
2012-05-09 08:38:21 +02:00
|
|
|
if(this.hasClass('ss-uploadfield-item-edit')){
|
|
|
|
disabled=this.siblings();
|
|
|
|
}else{
|
|
|
|
disabled=this.find('ss-uploadfield-item-edit').siblings();
|
|
|
|
}
|
|
|
|
editform.parent('.ss-uploadfield-item').removeClass('ui-state-warning');
|
2012-02-03 00:59:40 +01:00
|
|
|
editform.toggleEditForm();
|
2013-07-04 16:57:35 +02:00
|
|
|
|
|
|
|
if (itemInfo.find('.toggle-details-icon').hasClass('opened')) {
|
|
|
|
disabled.addClass('ui-state-disabled');
|
|
|
|
disabled.attr('disabled', 'disabled');
|
|
|
|
} else {
|
|
|
|
disabled.removeClass('ui-state-disabled');
|
|
|
|
disabled.removeAttr('disabled');
|
|
|
|
}
|
2012-02-03 00:59:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-05-09 08:38:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-03 00:59:40 +01:00
|
|
|
$('div.ss-upload .ss-uploadfield-item-editform').entwine({
|
2012-03-01 11:58:40 +01:00
|
|
|
fitHeight: function() {
|
2014-02-18 23:20:18 +01:00
|
|
|
var iframe = this.find('iframe'),
|
|
|
|
contents = iframe.contents().find('body'),
|
|
|
|
bodyH = contents.find('form').outerHeight(true), // We set the height to match the form's outer height
|
|
|
|
iframeH = bodyH + (iframe.outerHeight(true) - iframe.height()), // content's height + padding on iframe elem
|
|
|
|
containerH = iframeH + (this.outerHeight(true) - this.height()); // iframe height + padding on container elem
|
|
|
|
|
|
|
|
/* Set height of body except in IE8. Setting this in IE8 breaks the dropdown */
|
|
|
|
if( ! $.browser.msie && $.browser.version.slice(0,3) != "8.0"){
|
|
|
|
contents.find('body').css({'height': bodyH});
|
2012-05-10 06:47:52 +02:00
|
|
|
}
|
2013-12-12 14:17:57 +01:00
|
|
|
|
2014-02-18 23:20:18 +01:00
|
|
|
iframe.height(iframeH);
|
|
|
|
this.animate({height: containerH}, 500);
|
2012-03-01 11:58:40 +01:00
|
|
|
},
|
2012-02-03 00:59:40 +01:00
|
|
|
toggleEditForm: function() {
|
2012-05-09 08:38:21 +02:00
|
|
|
var itemInfo = this.prev('.ss-uploadfield-item-info'), status = itemInfo.find('.ss-uploadfield-item-status');
|
2013-05-26 01:11:05 +02:00
|
|
|
|
|
|
|
var iframe = this.find('iframe').contents(),
|
|
|
|
saved = iframe.find('#Form_EditForm_error');
|
|
|
|
|
|
|
|
var text = "";
|
2012-05-11 04:43:17 +02:00
|
|
|
|
2012-03-01 11:58:40 +01:00
|
|
|
if(this.height() === 0) {
|
2012-05-12 09:53:44 +02:00
|
|
|
text = ss.i18n._t('UploadField.Editing', "Editing ...");
|
2012-05-09 08:38:21 +02:00
|
|
|
this.fitHeight();
|
2013-10-23 11:16:47 +02:00
|
|
|
this.addClass('opened');
|
|
|
|
itemInfo.find('.toggle-details-icon').addClass('opened');
|
2012-05-11 04:43:17 +02:00
|
|
|
status.removeClass('ui-state-success-text').removeClass('ui-state-warning-text');
|
2012-05-09 08:38:21 +02:00
|
|
|
iframe.find('#Form_EditForm_action_doEdit').click(function(){
|
|
|
|
itemInfo.find('label .name').text(iframe.find('#Name input').val());
|
|
|
|
});
|
|
|
|
if($('div.ss-upload .ss-uploadfield-files .ss-uploadfield-item-actions .toggle-details-icon:not(.opened)').index() < 0){
|
2012-11-02 00:46:16 +01:00
|
|
|
$('div.ss-upload .ss-uploadfield-item-edit-all').addClass('opened').find('.toggle-details-icon').addClass('opened');
|
2012-05-09 08:38:21 +02:00
|
|
|
}
|
|
|
|
|
2012-03-01 11:58:40 +01:00
|
|
|
} else {
|
2012-11-02 00:46:16 +01:00
|
|
|
this.animate({height: 0}, 500);
|
2013-10-23 11:16:47 +02:00
|
|
|
this.removeClass('opened');
|
2012-05-09 08:38:21 +02:00
|
|
|
itemInfo.find('.toggle-details-icon').removeClass('opened');
|
2012-11-02 00:46:16 +01:00
|
|
|
$('div.ss-upload .ss-uploadfield-item-edit-all').removeClass('opened').find('.toggle-details-icon').removeClass('opened');
|
2012-05-09 08:38:21 +02:00
|
|
|
if(!this.hasClass('edited')){
|
2012-05-20 12:22:04 +02:00
|
|
|
text = ss.i18n._t('UploadField.NOCHANGES', 'No Changes');
|
2012-05-11 04:43:17 +02:00
|
|
|
status.addClass('ui-state-success-text');
|
2012-05-09 08:38:21 +02:00
|
|
|
}else{
|
|
|
|
if(saved.hasClass('good')){
|
2012-05-20 12:22:04 +02:00
|
|
|
text = ss.i18n._t('UploadField.CHANGESSAVED', 'Changes Saved');
|
2012-05-09 08:38:21 +02:00
|
|
|
this.removeClass('edited').parent('.ss-uploadfield-item').removeClass('ui-state-warning');
|
2012-05-11 04:43:17 +02:00
|
|
|
status.addClass('ui-state-success-text');
|
2012-05-09 08:38:21 +02:00
|
|
|
}else{
|
2012-05-20 12:22:04 +02:00
|
|
|
text = ss.i18n._t('UploadField.UNSAVEDCHANGES', 'Unsaved Changes');
|
2012-05-09 08:38:21 +02:00
|
|
|
this.parent('.ss-uploadfield-item').addClass('ui-state-warning');
|
2012-05-11 04:43:17 +02:00
|
|
|
status.addClass('ui-state-warning-text');
|
|
|
|
}
|
2012-05-09 08:38:21 +02:00
|
|
|
}
|
|
|
|
saved.removeClass('good').hide();
|
2012-03-01 11:58:40 +01:00
|
|
|
}
|
2012-05-11 04:43:17 +02:00
|
|
|
status.attr('title',text).text(text);
|
2012-02-03 00:59:40 +01:00
|
|
|
}
|
|
|
|
});
|
2012-02-08 00:58:58 +01:00
|
|
|
$('div.ss-upload .ss-uploadfield-fromfiles').entwine({
|
|
|
|
onclick: function(e) {
|
2013-03-26 22:56:08 +01:00
|
|
|
this.getUploadField().openSelectDialog(this.closest('.ss-uploadfield-item'));
|
2013-06-20 05:21:18 +02:00
|
|
|
e.preventDefault(); // Avoid a form submit
|
|
|
|
return false;
|
2012-02-08 00:58:58 +01:00
|
|
|
}
|
|
|
|
});
|
2012-02-03 00:59:40 +01:00
|
|
|
});
|
2012-04-20 01:05:54 +02:00
|
|
|
}(jQuery));
|