2013-06-23 17:17:42 +02:00
|
|
|
(function($) {
|
2012-07-16 22:39:01 +02:00
|
|
|
$.entwine('ss', function($) {
|
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
// start SS namespace overrides
|
2013-06-23 14:08:26 +02:00
|
|
|
|
2012-07-16 22:39:01 +02:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
// end SS namespace overrides
|
2012-07-16 22:39:01 +02:00
|
|
|
|
2014-04-06 14:51:15 +02:00
|
|
|
|
2014-04-05 18:54:50 +02:00
|
|
|
$.entwine('colymba', function($) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes sure the component is at the top :)
|
|
|
|
*/
|
|
|
|
$('.bulkUpload').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
var $tr = this.parents('thead').find('tr'),
|
|
|
|
$component = this.clone(),
|
|
|
|
index = $tr.index(this)
|
|
|
|
;
|
|
|
|
if ( index > 1 )
|
|
|
|
{
|
|
|
|
$component.insertAfter($tr.eq(0));
|
|
|
|
this.remove();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onunmatch: function(){}
|
|
|
|
});
|
|
|
|
|
2014-04-06 13:30:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Track upload progress...
|
|
|
|
*/
|
|
|
|
$('ul.ss-uploadfield-files').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onmatch: function(){},
|
2014-04-06 13:30:54 +02:00
|
|
|
onunmatch: function(){},
|
|
|
|
trackProgress: function()
|
2013-06-23 17:17:42 +02:00
|
|
|
{
|
2014-04-06 13:30:54 +02:00
|
|
|
var $li = this.find('li.ss-uploadfield-item'),
|
|
|
|
total = $li.length,
|
|
|
|
$done = $li.filter('.done'),
|
|
|
|
done = $done.length,
|
|
|
|
$errors = $li.not($done).find('.ui-state-warning-text,.ui-state-error-text'),
|
|
|
|
errors = $errors.length
|
2013-06-23 17:17:42 +02:00
|
|
|
;
|
2014-04-06 13:30:54 +02:00
|
|
|
|
|
|
|
this.parents('.ss-uploadfield').find('.colymba-bulkupload-buttons').refresh(total, done, errors);
|
|
|
|
/*
|
|
|
|
this.closest('.colymba-bulkupload-info').html(ss.i18n.sprintf(
|
|
|
|
ss.i18n._t('GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO'),
|
|
|
|
total,
|
|
|
|
done,
|
|
|
|
total
|
|
|
|
));*/
|
2013-01-25 22:26:43 +01:00
|
|
|
}
|
|
|
|
});
|
2014-04-06 13:30:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Track new and canceled updloads
|
|
|
|
*/
|
|
|
|
$('li.ss-uploadfield-item').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
this.parents('ul.ss-uploadfield-files').trackProgress();
|
|
|
|
},
|
|
|
|
onunmatch: function(){
|
|
|
|
$('ul.ss-uploadfield-files').trackProgress();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Track updload warning/errors
|
|
|
|
*/
|
|
|
|
$('li.ss-uploadfield-item .ui-state-warning-text,li.ss-uploadfield-item .ui-state-error-text').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
this.parents('ul.ss-uploadfield-files').trackProgress();
|
|
|
|
},
|
|
|
|
onunmatch: function(){
|
|
|
|
$('ul.ss-uploadfield-files').trackProgress();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Track completed uploads
|
|
|
|
*//*
|
|
|
|
$('li.ss-uploadfield-item.done').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
this.parents('ul.ss-uploadfield-files').trackProgress();
|
|
|
|
},
|
|
|
|
onunmatch: function(){},
|
|
|
|
});*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update buttons state and progress info...
|
|
|
|
*/
|
|
|
|
$('.colymba-bulkupload-buttons').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onmatch: function(){},
|
2014-04-06 13:30:54 +02:00
|
|
|
onunmatch: function(){},
|
|
|
|
refresh: function(total, done, error)
|
|
|
|
{
|
|
|
|
var $info = this.find('.colymba-bulkupload-info'),
|
|
|
|
$editBtn = this.find('.bulkUploadEditButton'),
|
|
|
|
$cancelBtn = this.find('.bulkUploadCancelButton'),
|
|
|
|
$finishBtn = this.find('.bulkUploadFinishButton'),
|
|
|
|
$clearErrorBtn = this.find('.bulkUploadClearErrorButton')
|
|
|
|
;
|
|
|
|
|
|
|
|
if ( total > 0 )
|
|
|
|
{
|
|
|
|
this.css({display: 'block'});
|
|
|
|
|
|
|
|
$info.html(ss.i18n.sprintf(
|
|
|
|
ss.i18n._t('GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO'),
|
|
|
|
total,
|
|
|
|
done,
|
|
|
|
error
|
|
|
|
));
|
|
|
|
|
|
|
|
$cancelBtn.removeClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'false').removeAttr('disabled');
|
|
|
|
$finishBtn.removeClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'false').removeAttr('disabled');
|
|
|
|
|
|
|
|
if ( total === done )
|
|
|
|
{
|
|
|
|
$editBtn.removeClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'false').removeAttr('disabled');
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$editBtn.addClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'true').attr('disabled', 'true');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( error > 0 )
|
|
|
|
{
|
|
|
|
$clearErrorBtn.removeClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'false').removeAttr('disabled');
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$clearErrorBtn.addClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'true').attr('disabled', 'true');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.css({display: 'none'});
|
|
|
|
$editBtn.addClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'true').attr('disabled', 'true');
|
|
|
|
$cancelBtn.addClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'true').attr('disabled', 'true');
|
|
|
|
$finishBtn.addClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'true').attr('disabled', 'true');
|
|
|
|
$clearErrorBtn.addClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'true').attr('disabled', 'true');
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 22:26:43 +01:00
|
|
|
});
|
2014-04-06 13:30:54 +02:00
|
|
|
|
|
|
|
|
2014-04-06 14:51:15 +02:00
|
|
|
$('.bulkUploadClearErrorButton').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
this.removeClass('action');
|
|
|
|
},
|
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function(e)
|
|
|
|
{
|
|
|
|
var $bulkUpload = this.parents('.bulkUpload'),
|
|
|
|
$errors = $bulkUpload.find('li.ss-uploadfield-item .ui-state-warning-text,li.ss-uploadfield-item .ui-state-error-text').parents('li')
|
|
|
|
;
|
|
|
|
|
|
|
|
$($errors.get().reverse()).each(function(index, Element){
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-04-06 13:30:54 +02:00
|
|
|
|
2014-04-06 14:51:15 +02:00
|
|
|
$('.bulkUploadCancelButton').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
this.removeClass('action');
|
|
|
|
},
|
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function()
|
|
|
|
{
|
2014-04-06 16:39:41 +02:00
|
|
|
var $bulkUpload = this.parents('.bulkUpload'),
|
|
|
|
$li = $bulkUpload.find('li.ss-uploadfield-item'),
|
|
|
|
$records = $li.filter('[data-recordid]'),
|
|
|
|
$other = $li.not($records),
|
|
|
|
$doBulkActionButton = $bulkUpload.parents('.ss-gridfield-table').find('.doBulkActionButton'),
|
|
|
|
recordsID
|
2014-04-06 14:51:15 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
$other.each(function(index, Element){
|
|
|
|
// skip in progress
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
if ( $doBulkActionButton.length > 0 )
|
|
|
|
{
|
|
|
|
recordsID = $records.map(function() {
|
|
|
|
return parseInt( $(this).data('recordid') )
|
|
|
|
}).get();
|
|
|
|
|
2014-04-06 16:39:41 +02:00
|
|
|
this.addClass('loading');
|
|
|
|
$doBulkActionButton.doBulkAction('delete', recordsID, this.cancelCallback, this);
|
2014-04-06 14:51:15 +02:00
|
|
|
}
|
2014-04-06 16:39:41 +02:00
|
|
|
},
|
|
|
|
cancelCallback: function(data)
|
|
|
|
{
|
|
|
|
var $bulkUpload = this.parents('.bulkUpload'),
|
|
|
|
$li = $bulkUpload.find('li.ss-uploadfield-item'),
|
2014-04-06 18:55:25 +02:00
|
|
|
ids
|
2014-04-06 16:39:41 +02:00
|
|
|
;
|
|
|
|
|
2014-04-06 18:55:25 +02:00
|
|
|
if ( data )
|
|
|
|
{
|
|
|
|
ids = data.records;
|
|
|
|
|
|
|
|
$li.each(function(index, Element){
|
|
|
|
var $this = $(this),
|
|
|
|
recordID = parseInt( $this.data('recordid') )
|
|
|
|
;
|
|
|
|
|
|
|
|
if ( ids.indexOf(recordID) !== -1 )
|
|
|
|
{
|
|
|
|
$this.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-04-06 16:39:41 +02:00
|
|
|
|
2014-04-06 18:55:25 +02:00
|
|
|
this.removeClass('loading');
|
2014-04-06 14:51:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.bulkUploadFinishButton').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
this.removeClass('action');
|
|
|
|
},
|
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function()
|
|
|
|
{
|
|
|
|
var $bulkUpload = this.parents('.bulkUpload'),
|
|
|
|
$li = $bulkUpload.find('li.ss-uploadfield-item')
|
|
|
|
;
|
|
|
|
|
2014-04-06 18:55:25 +02:00
|
|
|
this.addClass('loading');
|
2014-04-06 14:51:15 +02:00
|
|
|
$li.each(function(index, Element){
|
|
|
|
// skip in progress
|
|
|
|
$(this).remove();
|
|
|
|
});
|
2014-04-06 18:55:25 +02:00
|
|
|
this.removeClass('loading');
|
2014-04-06 14:51:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.bulkUploadEditButton').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
this.removeClass('action');
|
|
|
|
},
|
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function()
|
|
|
|
{
|
|
|
|
var $bulkUpload = this.parents('.bulkUpload'),
|
|
|
|
$li = $bulkUpload.find('li.ss-uploadfield-item'),
|
|
|
|
$records = $li.filter('[data-recordid]'),
|
|
|
|
recordsID,
|
|
|
|
$doBulkActionButton = $bulkUpload.parents('.ss-gridfield-table').find('.doBulkActionButton')
|
|
|
|
;
|
|
|
|
|
|
|
|
if ( $doBulkActionButton.length > 0 )
|
|
|
|
{
|
2014-04-06 18:55:25 +02:00
|
|
|
this.addClass('loading');
|
|
|
|
|
2014-04-06 14:51:15 +02:00
|
|
|
recordsID = $records.map(function() {
|
|
|
|
return parseInt( $(this).data('recordid') )
|
|
|
|
}).get();
|
|
|
|
|
2014-04-06 18:55:25 +02:00
|
|
|
$doBulkActionButton.doBulkAction('bulkedit', recordsID);
|
2014-04-06 14:51:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-04-06 13:30:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-25 22:26:43 +01:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* save changes button behaviour
|
|
|
|
* loop through edited forms and submit data
|
|
|
|
*/
|
2013-01-17 22:32:54 +01:00
|
|
|
$('#bulkImageUploadUpdateBtn:not(.ui-state-disabled)').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onmatch: function()
|
|
|
|
{
|
2012-07-16 22:39:01 +02:00
|
|
|
$(this).data('completedForms', 0);
|
|
|
|
},
|
2013-06-23 17:17:42 +02:00
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function(e)
|
|
|
|
{
|
|
|
|
var formsWithUpadtes,
|
|
|
|
url,
|
|
|
|
data,
|
|
|
|
cacheBuster
|
|
|
|
;
|
2012-07-16 22:39:01 +02:00
|
|
|
|
2012-08-13 17:05:14 +02:00
|
|
|
formsWithUpadtes = $('form.bulkImageUploadUpdateForm.hasUpdate');
|
2012-07-16 22:39:01 +02:00
|
|
|
$(this).data('formsToUpdate', $(formsWithUpadtes).length);
|
2012-08-13 17:05:14 +02:00
|
|
|
url = $(this).data('url');
|
2012-07-16 22:39:01 +02:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
if ( $(formsWithUpadtes).length > 0 )
|
|
|
|
{
|
|
|
|
$(this).addClass('loading');
|
|
|
|
}
|
2012-08-09 23:30:50 +02:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
$(formsWithUpadtes).each(function()
|
|
|
|
{
|
2012-08-13 17:05:14 +02:00
|
|
|
cacheBuster = new Date().getTime() + '_' + $(this).attr('name');
|
2013-06-23 17:17:42 +02:00
|
|
|
if ( url.indexOf('?') !== -1 )
|
|
|
|
{
|
|
|
|
cacheBuster = '&cacheBuster=' + cacheBuster;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
cacheBuster = '?cacheBuster=' + cacheBuster;
|
|
|
|
}
|
2013-01-17 22:02:42 +01:00
|
|
|
|
|
|
|
data = $(this).serialize();
|
|
|
|
|
2012-07-16 22:39:01 +02:00
|
|
|
$.ajax({
|
2013-06-23 17:17:42 +02:00
|
|
|
url: url + cacheBuster,
|
|
|
|
data: data,
|
|
|
|
type: "POST",
|
|
|
|
context: $(this)
|
|
|
|
}).done(function() {
|
|
|
|
var btn = $('#bulkImageUploadUpdateBtn'),
|
|
|
|
totalForms = parseInt( $(btn).data('formsToUpdate') ),
|
|
|
|
counter = parseInt( $(btn).data('completedForms') )
|
|
|
|
;
|
|
|
|
|
2012-07-16 22:39:01 +02:00
|
|
|
counter = counter + 1;
|
|
|
|
$(btn).data('completedForms', counter);
|
|
|
|
|
|
|
|
$(this).removeClass('hasUpdate');
|
2013-06-23 18:10:22 +02:00
|
|
|
$(this).parents('li').find('.ss-uploadfield-item-status').removeClass('dirty').addClass('updated').html(ss.i18n._t('GridFieldBulkTools.EDIT_UPDATED'));
|
2012-08-09 23:30:50 +02:00
|
|
|
$(this).parents('li').find('.ss-uploadfield-item-info').removeClass('dirty').addClass('updated');
|
2012-08-09 19:50:55 +02:00
|
|
|
$(this).parents('li').find('.ss-uploadfield-item-editform').css('display', 'none');
|
2012-07-16 22:39:01 +02:00
|
|
|
|
2012-08-09 23:30:50 +02:00
|
|
|
$(this).removeClass('hasUpdate');
|
2012-07-16 22:39:01 +02:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
if ( counter == totalForms )
|
|
|
|
{
|
2012-08-09 23:30:50 +02:00
|
|
|
$('#bulkImageUploadUpdateBtn').data('completedForms', 0);
|
|
|
|
$('#bulkImageUploadUpdateBtn').removeClass('loading');
|
2013-01-17 22:32:54 +01:00
|
|
|
$('#bulkImageUploadUpdateBtn').addClass('ui-state-disabled');
|
2013-06-23 17:17:42 +02:00
|
|
|
}
|
2012-07-16 22:39:01 +02:00
|
|
|
});
|
2013-06-23 17:17:42 +02:00
|
|
|
|
2013-06-02 20:07:00 +02:00
|
|
|
});
|
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
return false;
|
2012-07-16 22:39:01 +02:00
|
|
|
}
|
|
|
|
});
|
2013-01-17 22:32:54 +01:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* cancel button behaviour
|
|
|
|
* loop through edit forms and submit for deletion
|
|
|
|
*/
|
2013-01-17 22:32:54 +01:00
|
|
|
$('#bulkImageUploadUpdateCancelBtn:not(.ui-state-disabled)').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onclick: function(e)
|
|
|
|
{
|
|
|
|
var url = $(this).data('url'),
|
|
|
|
cacheBuster = new Date().getTime()
|
|
|
|
;
|
|
|
|
|
|
|
|
if ( url.indexOf('?') !== -1 )
|
|
|
|
{
|
|
|
|
cacheBuster = '&cacheBuster=' + cacheBuster;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
cacheBuster = '?cacheBuster=' + cacheBuster;
|
|
|
|
}
|
2012-07-16 22:39:01 +02:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
$('form.bulkImageUploadUpdateForm').each(function()
|
|
|
|
{
|
2012-07-16 22:39:01 +02:00
|
|
|
var data = $(this).serialize();
|
|
|
|
|
|
|
|
$.ajax({
|
2013-06-23 17:17:42 +02:00
|
|
|
url: url + cacheBuster,
|
|
|
|
data: data,
|
|
|
|
type: "POST",
|
|
|
|
context: $(this)
|
2012-07-16 22:39:01 +02:00
|
|
|
}).done(function() {
|
|
|
|
|
|
|
|
$(this).parents('li.ss-uploadfield-item').empty().remove();
|
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
if ( $('li.ss-uploadfield-item').length == 0 )
|
|
|
|
{
|
2012-07-16 22:39:01 +02:00
|
|
|
$('.ss-uploadfield-editandorganize').css('display', 'none');
|
|
|
|
$('#Form_bulkImageUploadForm').removeClass('loading');
|
2013-01-17 22:32:54 +01:00
|
|
|
$('#bulkImageUploadUpdateCancelBtn').addClass('ui-state-disabled');
|
2012-07-16 22:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2013-06-02 20:07:00 +02:00
|
|
|
});
|
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
return false;
|
2012-07-16 22:39:01 +02:00
|
|
|
}
|
|
|
|
});
|
2013-06-23 17:17:42 +02:00
|
|
|
|
2014-04-06 14:51:15 +02:00
|
|
|
}); // colymba namespace
|
2012-07-16 22:39:01 +02:00
|
|
|
|
2014-04-06 14:51:15 +02:00
|
|
|
}); // ss namespace
|
2014-04-06 13:30:54 +02:00
|
|
|
}(jQuery));
|