mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
housekeeping, comments and formatting
This commit is contained in:
parent
8089c14447
commit
9bc46687b1
@ -259,9 +259,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
|||||||
//sequential upload
|
//sequential upload
|
||||||
$uploadField->setConfig('sequentialUploads', $this->component->getConfig('sequentialUploads'));
|
$uploadField->setConfig('sequentialUploads', $this->component->getConfig('sequentialUploads'));
|
||||||
|
|
||||||
/* *
|
//Create form
|
||||||
* Create form
|
|
||||||
*/
|
|
||||||
$form = new Form(
|
$form = new Form(
|
||||||
$this,
|
$this,
|
||||||
'uploadForm',
|
'uploadForm',
|
||||||
|
@ -1,54 +1,80 @@
|
|||||||
(function($) {
|
(function($) {
|
||||||
|
|
||||||
$.entwine('ss', function($) {
|
$.entwine('ss', function($) {
|
||||||
|
|
||||||
// start SS overhides
|
// ============================================================================================
|
||||||
|
// start SS namespace overrides
|
||||||
|
// ============================================================================================
|
||||||
|
|
||||||
|
/*
|
||||||
|
* open/close edit form
|
||||||
|
*/
|
||||||
$('div.ss-upload .ss-uploadfield-item-edit, div.ss-upload .ss-uploadfield-item-name').entwine({
|
$('div.ss-upload .ss-uploadfield-item-edit, div.ss-upload .ss-uploadfield-item-name').entwine({
|
||||||
onclick: function(e){
|
onclick: function(e)
|
||||||
|
{
|
||||||
this.closest('.ss-uploadfield-item').find('.ss-uploadfield-item-editform').toggleEditForm();
|
this.closest('.ss-uploadfield-item').find('.ss-uploadfield-item-editform').toggleEditForm();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* edit all button
|
||||||
|
* @TODO fix
|
||||||
|
*/
|
||||||
$('div.ss-upload .fileOverview .ss-uploadfield-item-edit-all').entwine({
|
$('div.ss-upload .fileOverview .ss-uploadfield-item-edit-all').entwine({
|
||||||
onmatch: function(){
|
onmatch: function()
|
||||||
|
{
|
||||||
if( !$(this).hasClass('opened') ){
|
if( !$(this).hasClass('opened') ){
|
||||||
$(this).addClass('opened');
|
$(this).addClass('opened');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onunmatch: function(){
|
onunmatch: function(){},
|
||||||
|
onclick: function(e)
|
||||||
},
|
{
|
||||||
onclick: function(e) {
|
if( $(this).hasClass('opened') )
|
||||||
if($(this).hasClass('opened')){
|
{
|
||||||
$('.ss-uploadfield-files .ss-uploadfield-item-editform').hide();
|
$('.ss-uploadfield-files .ss-uploadfield-item-editform').hide();
|
||||||
$(this).removeClass('opened');
|
$(this).removeClass('opened');
|
||||||
}else{
|
}
|
||||||
|
else{
|
||||||
$('.ss-uploadfield-files .ss-uploadfield-item-editform').show();
|
$('.ss-uploadfield-files .ss-uploadfield-item-editform').show();
|
||||||
$(this).addClass('opened');
|
$(this).addClass('opened');
|
||||||
}
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* show/hide edit form
|
||||||
|
* overrides default behaviour
|
||||||
|
*/
|
||||||
$('div.ss-upload .ss-uploadfield-item-editform').entwine({
|
$('div.ss-upload .ss-uploadfield-item-editform').entwine({
|
||||||
toggleEditForm: function() {
|
toggleEditForm: function()
|
||||||
|
{
|
||||||
if( this.css('display') == 'none' ) {
|
if( this.css('display') == 'none' ) {
|
||||||
this.show();
|
this.show();
|
||||||
}else{
|
}
|
||||||
|
else{
|
||||||
this.hide();
|
this.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prevent submitting of individual edit forms
|
||||||
|
*/
|
||||||
$('#Form_uploadForm, div.ss-upload .ss-uploadfield-item-editform form').entwine({
|
$('#Form_uploadForm, div.ss-upload .ss-uploadfield-item-editform form').entwine({
|
||||||
onsubmit: function(e) {
|
onsubmit: function(e)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* initialise disabled state
|
||||||
|
*/
|
||||||
$('#bulkImageUploadUpdateBtn,#bulkImageUploadUpdateCancelBtn').entwine({
|
$('#bulkImageUploadUpdateBtn,#bulkImageUploadUpdateCancelBtn').entwine({
|
||||||
onmatch: function(){
|
onmatch: function()
|
||||||
|
{
|
||||||
$(this).addClass('ui-state-disabled ssui-button-disabled');
|
$(this).addClass('ui-state-disabled ssui-button-disabled');
|
||||||
$(this).attr('aria-disabled', 'true');
|
$(this).attr('aria-disabled', 'true');
|
||||||
$(this).attr('disabled', 'true');
|
$(this).attr('disabled', 'true');
|
||||||
@ -56,12 +82,16 @@
|
|||||||
onunmatch: function(){}
|
onunmatch: function(){}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* finish/return button
|
||||||
|
*/
|
||||||
$('#bulkImageUploadFinishBtn').entwine({
|
$('#bulkImageUploadFinishBtn').entwine({
|
||||||
onmatch: function(){},
|
onmatch: function(){},
|
||||||
onunmatch: function(){},
|
onunmatch: function(){},
|
||||||
onclick: function(e){
|
onclick: function(e)
|
||||||
var formsWithUpadtes = $('form.bulkImageUploadUpdateForm.hasUpdate').length,
|
{
|
||||||
confirmed = true;
|
var formsWithUpadtes = $('form.bulkImageUploadUpdateForm.hasUpdate').length,
|
||||||
|
confirmed = true;
|
||||||
|
|
||||||
if ( formsWithUpadtes > 0 )
|
if ( formsWithUpadtes > 0 )
|
||||||
{
|
{
|
||||||
@ -78,23 +108,34 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// end SS overhides
|
// ============================================================================================
|
||||||
// start add-on behaviours
|
// end SS namespace overrides
|
||||||
|
// ============================================================================================
|
||||||
|
|
||||||
|
// ============================================================================================
|
||||||
|
// start add-on behaviours
|
||||||
|
// ============================================================================================
|
||||||
|
|
||||||
$.entwine('colymba', function($) {
|
$.entwine('colymba', function($) {
|
||||||
|
|
||||||
$('.bulkImageUploadUpdateForm').entwine({
|
/*
|
||||||
onmatch: function(){
|
* handles individual edit forms changes
|
||||||
},
|
* updates buttons and visual styles
|
||||||
onunmatch: function(){
|
*/
|
||||||
},
|
$('.bulkImageUploadUpdateForm').entwine({
|
||||||
haschanged: function(){
|
onmatch: function(){},
|
||||||
var itemInfo, itemStatus;
|
onunmatch: function(){},
|
||||||
|
haschanged: function()
|
||||||
|
{
|
||||||
|
var itemInfo,
|
||||||
|
itemStatus
|
||||||
|
;
|
||||||
|
|
||||||
itemStatus = $(this).parents('li').find('.ss-uploadfield-item-status');
|
itemStatus = $(this).parents('li').find('.ss-uploadfield-item-status');
|
||||||
itemInfo = $(this).parents('li').find('.ss-uploadfield-item-info');
|
itemInfo = $(this).parents('li').find('.ss-uploadfield-item-info');
|
||||||
|
|
||||||
if ( !$(this).hasClass('hasUpdate') ) {
|
if ( !$(this).hasClass('hasUpdate') )
|
||||||
|
{
|
||||||
$(this).addClass('hasUpdate');
|
$(this).addClass('hasUpdate');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,56 +149,81 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* catches edit form changes
|
||||||
|
*/
|
||||||
$('.bulkImageUploadUpdateForm input.text, .bulkImageUploadUpdateForm input.checkbox, .bulkImageUploadUpdateForm select, .bulkImageUploadUpdateForm textarea').entwine({
|
$('.bulkImageUploadUpdateForm input.text, .bulkImageUploadUpdateForm input.checkbox, .bulkImageUploadUpdateForm select, .bulkImageUploadUpdateForm textarea').entwine({
|
||||||
onchange: function(){
|
onchange: function()
|
||||||
|
{
|
||||||
this.closest('.bulkImageUploadUpdateForm').haschanged();
|
this.closest('.bulkImageUploadUpdateForm').haschanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//textarea node is being removed from the DOM when the HTMLEditorFieldChanges, not the best but works
|
/*
|
||||||
|
* catches edit form changes
|
||||||
|
* HTMLEditorField hack
|
||||||
|
*/
|
||||||
|
//textarea node is being removed from the DOM when the HTMLEditorFieldChanges, not the best but works
|
||||||
$('.field.htmleditor textarea').entwine({
|
$('.field.htmleditor textarea').entwine({
|
||||||
onmatch: function(){
|
onmatch: function(){},
|
||||||
},
|
onunmatch: function()
|
||||||
onunmatch: function(){
|
{
|
||||||
//note sure why querying straight from the texarea doesn't work... maybe because it is already removed from DOM?
|
//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();
|
$('input[type="hidden"][name="'+$(this).attr('name')+'"]').parents('.bulkImageUploadUpdateForm').haschanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* save changes button behaviour
|
||||||
|
* loop through edited forms and submit data
|
||||||
|
*/
|
||||||
$('#bulkImageUploadUpdateBtn:not(.ui-state-disabled)').entwine({
|
$('#bulkImageUploadUpdateBtn:not(.ui-state-disabled)').entwine({
|
||||||
onmatch: function(){
|
onmatch: function()
|
||||||
|
{
|
||||||
$(this).data('completedForms', 0);
|
$(this).data('completedForms', 0);
|
||||||
},
|
},
|
||||||
onunmatch: function(){
|
onunmatch: function(){},
|
||||||
},
|
onclick: function(e)
|
||||||
onclick: function(e){
|
{
|
||||||
|
var formsWithUpadtes,
|
||||||
var formsWithUpadtes, url, data, cacheBuster;
|
url,
|
||||||
|
data,
|
||||||
|
cacheBuster
|
||||||
|
;
|
||||||
|
|
||||||
formsWithUpadtes = $('form.bulkImageUploadUpdateForm.hasUpdate');
|
formsWithUpadtes = $('form.bulkImageUploadUpdateForm.hasUpdate');
|
||||||
$(this).data('formsToUpdate', $(formsWithUpadtes).length);
|
$(this).data('formsToUpdate', $(formsWithUpadtes).length);
|
||||||
url = $(this).data('url');
|
url = $(this).data('url');
|
||||||
|
|
||||||
if ( $(formsWithUpadtes).length > 0 ) $(this).addClass('loading');
|
if ( $(formsWithUpadtes).length > 0 )
|
||||||
|
{
|
||||||
|
$(this).addClass('loading');
|
||||||
|
}
|
||||||
|
|
||||||
//@TODO execute 'doFinish' even when no form have been changed
|
$(formsWithUpadtes).each(function()
|
||||||
$(formsWithUpadtes).each(function(){
|
{
|
||||||
cacheBuster = new Date().getTime() + '_' + $(this).attr('name');
|
cacheBuster = new Date().getTime() + '_' + $(this).attr('name');
|
||||||
if ( url.indexOf('?') !== -1 ) cacheBuster = '&cacheBuster=' + cacheBuster;
|
if ( url.indexOf('?') !== -1 )
|
||||||
else cacheBuster = '?cacheBuster=' + cacheBuster;
|
{
|
||||||
|
cacheBuster = '&cacheBuster=' + cacheBuster;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
cacheBuster = '?cacheBuster=' + cacheBuster;
|
||||||
|
}
|
||||||
|
|
||||||
data = $(this).serialize();
|
data = $(this).serialize();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url + cacheBuster,
|
url: url + cacheBuster,
|
||||||
data: data,
|
data: data,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
context: $(this)
|
context: $(this)
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
|
var btn = $('#bulkImageUploadUpdateBtn'),
|
||||||
var btn = $('#bulkImageUploadUpdateBtn');
|
totalForms = parseInt( $(btn).data('formsToUpdate') ),
|
||||||
var totalForms = parseInt( $(btn).data('formsToUpdate') );
|
counter = parseInt( $(btn).data('completedForms') )
|
||||||
var counter = parseInt( $(btn).data('completedForms') );
|
;
|
||||||
|
|
||||||
counter = counter + 1;
|
counter = counter + 1;
|
||||||
$(btn).data('completedForms', counter);
|
$(btn).data('completedForms', counter);
|
||||||
|
|
||||||
@ -168,51 +234,67 @@
|
|||||||
|
|
||||||
$(this).removeClass('hasUpdate');
|
$(this).removeClass('hasUpdate');
|
||||||
|
|
||||||
if ( counter == totalForms ) {
|
if ( counter == totalForms )
|
||||||
|
{
|
||||||
$('#bulkImageUploadUpdateBtn').data('completedForms', 0);
|
$('#bulkImageUploadUpdateBtn').data('completedForms', 0);
|
||||||
$('#bulkImageUploadUpdateBtn').removeClass('loading');
|
$('#bulkImageUploadUpdateBtn').removeClass('loading');
|
||||||
$('#bulkImageUploadUpdateBtn').addClass('ui-state-disabled');
|
$('#bulkImageUploadUpdateBtn').addClass('ui-state-disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.ss-uploadfield-item-editform').entwine({
|
/*
|
||||||
onmatch: function(e){
|
* edit forms ovverides
|
||||||
|
*/
|
||||||
|
$('.ss-uploadfield-item-editform').entwine({
|
||||||
|
onmatch: function(e)
|
||||||
|
{
|
||||||
$('#bulkImageUploadUpdateCancelBtn').removeClass('ui-state-disabled ssui-button-disabled');
|
$('#bulkImageUploadUpdateCancelBtn').removeClass('ui-state-disabled ssui-button-disabled');
|
||||||
$('#bulkImageUploadUpdateCancelBtn').attr('aria-disabled', 'false');
|
$('#bulkImageUploadUpdateCancelBtn').attr('aria-disabled', 'false');
|
||||||
$('#bulkImageUploadUpdateCancelBtn').removeAttr('disabled');
|
$('#bulkImageUploadUpdateCancelBtn').removeAttr('disabled');
|
||||||
},
|
},
|
||||||
onunmatch: function(){
|
onunmatch: function(){}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* cancel button behaviour
|
||||||
|
* loop through edit forms and submit for deletion
|
||||||
|
*/
|
||||||
$('#bulkImageUploadUpdateCancelBtn:not(.ui-state-disabled)').entwine({
|
$('#bulkImageUploadUpdateCancelBtn:not(.ui-state-disabled)').entwine({
|
||||||
onclick: function(e){
|
onclick: function(e)
|
||||||
|
{
|
||||||
|
var url = $(this).data('url'),
|
||||||
|
cacheBuster = new Date().getTime()
|
||||||
|
;
|
||||||
|
|
||||||
|
if ( url.indexOf('?') !== -1 )
|
||||||
|
{
|
||||||
|
cacheBuster = '&cacheBuster=' + cacheBuster;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
cacheBuster = '?cacheBuster=' + cacheBuster;
|
||||||
|
}
|
||||||
|
|
||||||
var url = $(this).data('url');
|
$('form.bulkImageUploadUpdateForm').each(function()
|
||||||
var cacheBuster = new Date().getTime();
|
{
|
||||||
if ( url.indexOf('?') !== -1 ) cacheBuster = '&cacheBuster=' + cacheBuster;
|
|
||||||
else cacheBuster = '?cacheBuster=' + cacheBuster;
|
|
||||||
|
|
||||||
$('form.bulkImageUploadUpdateForm').each(function(){
|
|
||||||
var data = $(this).serialize();
|
var data = $(this).serialize();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url + cacheBuster,
|
url: url + cacheBuster,
|
||||||
data: data,
|
data: data,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
context: $(this)
|
context: $(this)
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
|
|
||||||
$(this).parents('li.ss-uploadfield-item').empty().remove();
|
$(this).parents('li.ss-uploadfield-item').empty().remove();
|
||||||
|
|
||||||
if ( $('li.ss-uploadfield-item').length == 0 ) {
|
if ( $('li.ss-uploadfield-item').length == 0 )
|
||||||
|
{
|
||||||
$('.ss-uploadfield-editandorganize').css('display', 'none');
|
$('.ss-uploadfield-editandorganize').css('display', 'none');
|
||||||
$('#Form_bulkImageUploadForm').removeClass('loading');
|
$('#Form_bulkImageUploadForm').removeClass('loading');
|
||||||
$('#bulkImageUploadUpdateCancelBtn').addClass('ui-state-disabled');
|
$('#bulkImageUploadUpdateCancelBtn').addClass('ui-state-disabled');
|
||||||
@ -221,13 +303,14 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
});
|
||||||
|
// ============================================================================================
|
||||||
|
// end add-on behaviours
|
||||||
|
// ============================================================================================
|
||||||
|
|
||||||
|
});
|
||||||
}(jQuery));
|
}(jQuery));
|
Loading…
Reference in New Issue
Block a user