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
|
|
|
|
// ============================================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open/close edit form
|
|
|
|
*/
|
2012-07-16 22:39:01 +02:00
|
|
|
$('div.ss-upload .ss-uploadfield-item-edit, div.ss-upload .ss-uploadfield-item-name').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onclick: function(e)
|
|
|
|
{
|
2012-07-16 22:39:01 +02:00
|
|
|
this.closest('.ss-uploadfield-item').find('.ss-uploadfield-item-editform').toggleEditForm();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* edit all button
|
|
|
|
* @TODO fix
|
|
|
|
*/
|
2012-07-16 22:39:01 +02:00
|
|
|
$('div.ss-upload .fileOverview .ss-uploadfield-item-edit-all').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onmatch: function()
|
|
|
|
{
|
2012-07-16 22:39:01 +02:00
|
|
|
if( !$(this).hasClass('opened') ){
|
|
|
|
$(this).addClass('opened');
|
2013-01-17 22:32:54 +01:00
|
|
|
}
|
2012-07-16 22:39:01 +02:00
|
|
|
},
|
2013-06-23 17:17:42 +02:00
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function(e)
|
|
|
|
{
|
|
|
|
if( $(this).hasClass('opened') )
|
|
|
|
{
|
2012-07-16 22:39:01 +02:00
|
|
|
$('.ss-uploadfield-files .ss-uploadfield-item-editform').hide();
|
|
|
|
$(this).removeClass('opened');
|
2013-06-23 17:17:42 +02:00
|
|
|
}
|
|
|
|
else{
|
2012-07-16 22:39:01 +02:00
|
|
|
$('.ss-uploadfield-files .ss-uploadfield-item-editform').show();
|
|
|
|
$(this).addClass('opened');
|
|
|
|
}
|
2013-06-23 17:17:42 +02:00
|
|
|
|
2012-08-09 23:30:50 +02:00
|
|
|
e.preventDefault();
|
2012-07-16 22:39:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* show/hide edit form
|
|
|
|
* overrides default behaviour
|
|
|
|
*/
|
2012-07-16 22:39:01 +02:00
|
|
|
$('div.ss-upload .ss-uploadfield-item-editform').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
toggleEditForm: function()
|
|
|
|
{
|
2012-07-16 22:39:01 +02:00
|
|
|
if( this.css('display') == 'none' ) {
|
|
|
|
this.show();
|
2013-06-23 17:17:42 +02:00
|
|
|
}
|
|
|
|
else{
|
2012-07-16 22:39:01 +02:00
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-03-04 09:54:28 +01:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* prevent submitting of individual edit forms
|
|
|
|
*/
|
2013-06-23 14:08:26 +02:00
|
|
|
$('#Form_uploadForm, div.ss-upload .ss-uploadfield-item-editform form').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onsubmit: function(e)
|
|
|
|
{
|
2013-05-19 18:55:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* initialise disabled state
|
|
|
|
*/
|
2013-03-04 09:54:28 +01:00
|
|
|
$('#bulkImageUploadUpdateBtn,#bulkImageUploadUpdateCancelBtn').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onmatch: function()
|
|
|
|
{
|
2013-03-04 09:54:28 +01:00
|
|
|
$(this).addClass('ui-state-disabled ssui-button-disabled');
|
|
|
|
$(this).attr('aria-disabled', 'true');
|
|
|
|
$(this).attr('disabled', 'true');
|
|
|
|
},
|
|
|
|
onunmatch: function(){}
|
|
|
|
});
|
2013-06-23 14:08:26 +02:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* finish/return button
|
|
|
|
*/
|
2013-06-23 14:08:26 +02:00
|
|
|
$('#bulkImageUploadFinishBtn').entwine({
|
|
|
|
onmatch: function(){},
|
|
|
|
onunmatch: function(){},
|
2013-06-23 17:17:42 +02:00
|
|
|
onclick: function(e)
|
|
|
|
{
|
|
|
|
var formsWithUpadtes = $('form.bulkImageUploadUpdateForm.hasUpdate').length,
|
|
|
|
confirmed = true;
|
2013-06-23 14:08:26 +02:00
|
|
|
|
|
|
|
if ( formsWithUpadtes > 0 )
|
|
|
|
{
|
2013-06-23 18:10:22 +02:00
|
|
|
confirmed = confirm( ss.i18n._t('GridFieldBulkTools.FINISH_CONFIRM') );
|
2013-06-23 14:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (confirmed)
|
|
|
|
{
|
|
|
|
$('.cms-container').loadPanel(this.attr('href'), null, {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
// ============================================================================================
|
|
|
|
// start add-on behaviours
|
|
|
|
// ============================================================================================
|
|
|
|
|
2012-07-16 22:39:01 +02:00
|
|
|
$.entwine('colymba', function($) {
|
2013-01-25 22:26:43 +01:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* handles individual edit forms changes
|
|
|
|
* updates buttons and visual styles
|
|
|
|
*/
|
|
|
|
$('.bulkImageUploadUpdateForm').entwine({
|
|
|
|
onmatch: function(){},
|
|
|
|
onunmatch: function(){},
|
|
|
|
haschanged: function()
|
|
|
|
{
|
|
|
|
var itemInfo,
|
|
|
|
itemStatus
|
|
|
|
;
|
2012-08-09 23:30:50 +02:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
itemStatus = $(this).parents('li').find('.ss-uploadfield-item-status');
|
|
|
|
itemInfo = $(this).parents('li').find('.ss-uploadfield-item-info');
|
2012-08-09 23:30:50 +02:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
if ( !$(this).hasClass('hasUpdate') )
|
|
|
|
{
|
2013-01-25 22:26:43 +01:00
|
|
|
$(this).addClass('hasUpdate');
|
2012-07-16 22:39:01 +02:00
|
|
|
}
|
2012-08-09 23:30:50 +02:00
|
|
|
|
2013-06-23 18:10:22 +02:00
|
|
|
$(itemStatus).removeClass('updated').addClass('dirty').html(ss.i18n._t('GridFieldBulkTools.EDIT_CHANGED'));
|
2012-08-09 23:30:50 +02:00
|
|
|
if ( $(itemInfo).hasClass('updated') ) $(itemInfo).removeClass('updated');
|
|
|
|
if ( !$(itemInfo).hasClass('dirty') ) $(itemInfo).addClass('dirty');
|
2013-03-04 09:54:28 +01:00
|
|
|
|
|
|
|
$('#bulkImageUploadUpdateBtn').removeClass('ui-state-disabled ssui-button-disabled');
|
|
|
|
$('#bulkImageUploadUpdateBtn').attr('aria-disabled', 'false');
|
|
|
|
$('#bulkImageUploadUpdateBtn').removeAttr('disabled');
|
2013-01-25 22:26:43 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* catches edit form changes
|
|
|
|
*/
|
2013-01-25 22:26:43 +01:00
|
|
|
$('.bulkImageUploadUpdateForm input.text, .bulkImageUploadUpdateForm input.checkbox, .bulkImageUploadUpdateForm select, .bulkImageUploadUpdateForm textarea').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onchange: function()
|
|
|
|
{
|
2013-01-25 22:26:43 +01:00
|
|
|
this.closest('.bulkImageUploadUpdateForm').haschanged();
|
2012-07-16 22:39:01 +02:00
|
|
|
}
|
|
|
|
});
|
2013-01-25 22:26:43 +01:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* catches edit form changes
|
|
|
|
* HTMLEditorField hack
|
|
|
|
*/
|
|
|
|
//textarea node is being removed from the DOM when the HTMLEditorFieldChanges, not the best but works
|
2013-01-25 22:26:43 +01:00
|
|
|
$('.field.htmleditor textarea').entwine({
|
2013-06-23 17:17:42 +02:00
|
|
|
onmatch: function(){},
|
|
|
|
onunmatch: function()
|
|
|
|
{
|
2013-01-25 22:26:43 +01:00
|
|
|
//note sure why querying straight from the texarea doesn't work... maybe because it is already removed from DOM?
|
|
|
|
$('input[type="hidden"][name="'+$(this).attr('name')+'"]').parents('.bulkImageUploadUpdateForm').haschanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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-06-23 17:17:42 +02:00
|
|
|
/*
|
|
|
|
* edit forms ovverides
|
|
|
|
*/
|
|
|
|
$('.ss-uploadfield-item-editform').entwine({
|
|
|
|
onmatch: function(e)
|
|
|
|
{
|
2013-03-04 09:54:28 +01:00
|
|
|
$('#bulkImageUploadUpdateCancelBtn').removeClass('ui-state-disabled ssui-button-disabled');
|
|
|
|
$('#bulkImageUploadUpdateCancelBtn').attr('aria-disabled', 'false');
|
|
|
|
$('#bulkImageUploadUpdateCancelBtn').removeAttr('disabled');
|
2013-01-17 22:32:54 +01:00
|
|
|
},
|
2013-06-23 17:17:42 +02:00
|
|
|
onunmatch: function(){}
|
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
|
|
|
|
2012-07-16 22:39:01 +02:00
|
|
|
});
|
2013-06-23 17:17:42 +02:00
|
|
|
// ============================================================================================
|
|
|
|
// end add-on behaviours
|
|
|
|
// ============================================================================================
|
2012-07-16 22:39:01 +02:00
|
|
|
|
2013-06-23 17:17:42 +02:00
|
|
|
});
|
2012-07-16 22:39:01 +02:00
|
|
|
}(jQuery));
|