mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
Clean up
This commit is contained in:
parent
699fa6712d
commit
043f889249
@ -25,6 +25,7 @@ class GridFieldBulkManager implements GridField_HTMLProvider, GridField_ColumnPr
|
|||||||
'actions' => array()
|
'actions' => array()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds any class that should not be used as they break the component
|
* Holds any class that should not be used as they break the component
|
||||||
* These cannot be removed from the blacklist
|
* These cannot be removed from the blacklist
|
||||||
|
@ -11,40 +11,26 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
|||||||
* component configuration
|
* component configuration
|
||||||
*
|
*
|
||||||
* 'fileRelationName' => field name of the $has_one File/Image relation
|
* 'fileRelationName' => field name of the $has_one File/Image relation
|
||||||
* 'editableFields' => fields editable on the Model
|
* 'folderName' => where to upload the files
|
||||||
* 'fieldsClassBlacklist' => field types that will be removed from the automatic form generation
|
* 'maxFileSize' => maximum file size allowed per upload
|
||||||
* 'fieldsNameBlacklist' => fields that will be removed from the automatic form generation
|
* 'sequentialUploads' => process uploads 1 after the other rather than all at once
|
||||||
*
|
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $config = array(
|
protected $config = array(
|
||||||
'fileRelationName' => null,
|
'fileRelationName' => null,
|
||||||
'editableFields' => null,
|
'folderName' => 'bulkUpload',
|
||||||
'fieldsClassBlacklist' => array(),
|
'maxFileSize' => null,
|
||||||
'fieldsNameBlacklist' => array(),
|
|
||||||
'folderName' => 'bulkUpload',
|
|
||||||
'maxFileSize' => null,
|
|
||||||
'sequentialUploads' => false
|
'sequentialUploads' => false
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds any class that should not be used as they break the component
|
|
||||||
* These cannot be removed from the blacklist
|
|
||||||
*/
|
|
||||||
protected $forbiddenFieldsClasses = array( 'GridField', 'UploadField' );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $fileRelationName
|
* @param string $fileRelationName
|
||||||
* @param string/array $editableFields
|
* @param string/array $editableFields
|
||||||
*/
|
*/
|
||||||
public function __construct($fileRelationName = null, $editableFields = null)
|
public function __construct($fileRelationName = null)
|
||||||
{
|
{
|
||||||
if ( $fileRelationName != null ) $this->setConfig ( 'fileRelationName', $fileRelationName );
|
if ( $fileRelationName != null ) $this->setConfig ( 'fileRelationName', $fileRelationName );
|
||||||
if ( $editableFields != null ) $this->setConfig ( 'editableFields', $editableFields );
|
|
||||||
|
|
||||||
//init classes blacklist with forbidden classes
|
|
||||||
$this->config['fieldsClassBlacklist'] = $this->forbiddenFieldsClasses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,17 +44,6 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
|||||||
if (!key_exists($reference, $this->config) ) {
|
if (!key_exists($reference, $this->config) ) {
|
||||||
user_error("Unknown option reference: $reference", E_USER_ERROR);
|
user_error("Unknown option reference: $reference", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ($reference == 'fieldsClassBlacklist' || $reference == 'fieldsClassBlacklist' || $reference == 'editableFields') && !is_array($value) )
|
|
||||||
{
|
|
||||||
$value = array($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
//makes sure $forbiddenFieldsClasses are in no matter what
|
|
||||||
if ( $reference == 'fieldsClassBlacklist' )
|
|
||||||
{
|
|
||||||
$value = array_unique( array_merge($value, $this->forbiddenFieldsClasses) );
|
|
||||||
}
|
|
||||||
|
|
||||||
//makes sure maxFileSize is INT
|
//makes sure maxFileSize is INT
|
||||||
if ( $reference == 'maxFileSize' && !is_int($value) )
|
if ( $reference == 'maxFileSize' && !is_int($value) )
|
||||||
@ -97,58 +72,6 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
|||||||
if ( $reference ) return $this->config[$reference];
|
if ( $reference ) return $this->config[$reference];
|
||||||
else return $this->config;
|
else return $this->config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a field to the editable fields blacklist
|
|
||||||
*
|
|
||||||
* @param string $fieldName
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
function addFieldNameToBlacklist ( $fieldName )
|
|
||||||
{
|
|
||||||
return array_push( $this->config['fieldsNameBlacklist'], $fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a class to the editable fields blacklist
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
function addClassToBlacklist ( $className )
|
|
||||||
{
|
|
||||||
return array_push( $this->config['fieldsClassBlacklist'], $className);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a field to the editable fields blacklist
|
|
||||||
*
|
|
||||||
* @param string $fieldName
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
function removeFieldNameFromBlacklist ( $fieldName )
|
|
||||||
{
|
|
||||||
if (key_exists($fieldName, $this->config['fieldsNameBlacklist'])) {
|
|
||||||
return delete( $this->config['fieldsNameBlacklist'][$fieldName] );
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a class to the editable fields blacklist
|
|
||||||
*
|
|
||||||
* @param string $className
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
function removeClassFromBlacklist ( $className )
|
|
||||||
{
|
|
||||||
if (key_exists($className, $this->config['fieldsNameBlacklist']) && !in_array($className, $this->forbiddenFieldsClasses)) {
|
|
||||||
return delete( $this->config['fieldsNameBlacklist'][$className] );
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ******************************************************************************** */
|
/* ******************************************************************************** */
|
||||||
|
|
||||||
@ -326,9 +249,9 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getURLHandlers($gridField) {
|
public function getURLHandlers($gridField) {
|
||||||
return array(
|
return array(
|
||||||
'bulkupload' => 'handleBulkUpload'
|
'bulkupload' => 'handleBulkUpload'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -340,8 +263,8 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
|
|||||||
*/
|
*/
|
||||||
public function handleBulkUpload($gridField, $request)
|
public function handleBulkUpload($gridField, $request)
|
||||||
{
|
{
|
||||||
$controller = $gridField->getForm()->Controller();
|
$controller = $gridField->getForm()->Controller();
|
||||||
$handler = new GridFieldBulkUpload_Request($gridField, $this, $controller);
|
$handler = new GridFieldBulkUpload_Request($gridField, $this, $controller);
|
||||||
|
|
||||||
return $handler->handleRequest($request, DataModel::inst());
|
return $handler->handleRequest($request, DataModel::inst());
|
||||||
}
|
}
|
||||||
|
@ -148,6 +148,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all updloads with warning or error
|
||||||
|
*/
|
||||||
$('.bulkUploadClearErrorButton').entwine({
|
$('.bulkUploadClearErrorButton').entwine({
|
||||||
onmatch: function(){
|
onmatch: function(){
|
||||||
this.removeClass('action');
|
this.removeClass('action');
|
||||||
@ -165,6 +168,11 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel all uploads
|
||||||
|
* Clear the ones with warnings/error and delete dataObjects from the successful ones
|
||||||
|
*/
|
||||||
$('.bulkUploadCancelButton').entwine({
|
$('.bulkUploadCancelButton').entwine({
|
||||||
onmatch: function(){
|
onmatch: function(){
|
||||||
this.removeClass('action');
|
this.removeClass('action');
|
||||||
@ -222,6 +230,10 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear all the warning/error/finished uploads
|
||||||
|
*/
|
||||||
$('.bulkUploadFinishButton').entwine({
|
$('.bulkUploadFinishButton').entwine({
|
||||||
onmatch: function(){
|
onmatch: function(){
|
||||||
this.removeClass('action');
|
this.removeClass('action');
|
||||||
@ -259,7 +271,7 @@
|
|||||||
if ( $doBulkActionButton.length > 0 )
|
if ( $doBulkActionButton.length > 0 )
|
||||||
{
|
{
|
||||||
this.addClass('loading');
|
this.addClass('loading');
|
||||||
|
|
||||||
recordsID = $records.map(function() {
|
recordsID = $records.map(function() {
|
||||||
return parseInt( $(this).data('recordid') )
|
return parseInt( $(this).data('recordid') )
|
||||||
}).get();
|
}).get();
|
||||||
@ -269,130 +281,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* save changes button behaviour
|
|
||||||
* loop through edited forms and submit data
|
|
||||||
*/
|
|
||||||
$('#bulkImageUploadUpdateBtn:not(.ui-state-disabled)').entwine({
|
|
||||||
onmatch: function()
|
|
||||||
{
|
|
||||||
$(this).data('completedForms', 0);
|
|
||||||
},
|
|
||||||
onunmatch: function(){},
|
|
||||||
onclick: function(e)
|
|
||||||
{
|
|
||||||
var formsWithUpadtes,
|
|
||||||
url,
|
|
||||||
data,
|
|
||||||
cacheBuster
|
|
||||||
;
|
|
||||||
|
|
||||||
formsWithUpadtes = $('form.bulkImageUploadUpdateForm.hasUpdate');
|
|
||||||
$(this).data('formsToUpdate', $(formsWithUpadtes).length);
|
|
||||||
url = $(this).data('url');
|
|
||||||
|
|
||||||
if ( $(formsWithUpadtes).length > 0 )
|
|
||||||
{
|
|
||||||
$(this).addClass('loading');
|
|
||||||
}
|
|
||||||
|
|
||||||
$(formsWithUpadtes).each(function()
|
|
||||||
{
|
|
||||||
cacheBuster = new Date().getTime() + '_' + $(this).attr('name');
|
|
||||||
if ( url.indexOf('?') !== -1 )
|
|
||||||
{
|
|
||||||
cacheBuster = '&cacheBuster=' + cacheBuster;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
cacheBuster = '?cacheBuster=' + cacheBuster;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = $(this).serialize();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: url + cacheBuster,
|
|
||||||
data: data,
|
|
||||||
type: "POST",
|
|
||||||
context: $(this)
|
|
||||||
}).done(function() {
|
|
||||||
var btn = $('#bulkImageUploadUpdateBtn'),
|
|
||||||
totalForms = parseInt( $(btn).data('formsToUpdate') ),
|
|
||||||
counter = parseInt( $(btn).data('completedForms') )
|
|
||||||
;
|
|
||||||
|
|
||||||
counter = counter + 1;
|
|
||||||
$(btn).data('completedForms', counter);
|
|
||||||
|
|
||||||
$(this).removeClass('hasUpdate');
|
|
||||||
$(this).parents('li').find('.ss-uploadfield-item-status').removeClass('dirty').addClass('updated').html(ss.i18n._t('GridFieldBulkTools.EDIT_UPDATED'));
|
|
||||||
$(this).parents('li').find('.ss-uploadfield-item-info').removeClass('dirty').addClass('updated');
|
|
||||||
$(this).parents('li').find('.ss-uploadfield-item-editform').css('display', 'none');
|
|
||||||
|
|
||||||
$(this).removeClass('hasUpdate');
|
|
||||||
|
|
||||||
if ( counter == totalForms )
|
|
||||||
{
|
|
||||||
$('#bulkImageUploadUpdateBtn').data('completedForms', 0);
|
|
||||||
$('#bulkImageUploadUpdateBtn').removeClass('loading');
|
|
||||||
$('#bulkImageUploadUpdateBtn').addClass('ui-state-disabled');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
|
||||||
* cancel button behaviour
|
|
||||||
* loop through edit forms and submit for deletion
|
|
||||||
*/
|
|
||||||
$('#bulkImageUploadUpdateCancelBtn:not(.ui-state-disabled)').entwine({
|
|
||||||
onclick: function(e)
|
|
||||||
{
|
|
||||||
var url = $(this).data('url'),
|
|
||||||
cacheBuster = new Date().getTime()
|
|
||||||
;
|
|
||||||
|
|
||||||
if ( url.indexOf('?') !== -1 )
|
|
||||||
{
|
|
||||||
cacheBuster = '&cacheBuster=' + cacheBuster;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
cacheBuster = '?cacheBuster=' + cacheBuster;
|
|
||||||
}
|
|
||||||
|
|
||||||
$('form.bulkImageUploadUpdateForm').each(function()
|
|
||||||
{
|
|
||||||
var data = $(this).serialize();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: url + cacheBuster,
|
|
||||||
data: data,
|
|
||||||
type: "POST",
|
|
||||||
context: $(this)
|
|
||||||
}).done(function() {
|
|
||||||
|
|
||||||
$(this).parents('li.ss-uploadfield-item').empty().remove();
|
|
||||||
|
|
||||||
if ( $('li.ss-uploadfield-item').length == 0 )
|
|
||||||
{
|
|
||||||
$('.ss-uploadfield-editandorganize').css('display', 'none');
|
|
||||||
$('#Form_bulkImageUploadForm').removeClass('loading');
|
|
||||||
$('#bulkImageUploadUpdateCancelBtn').addClass('ui-state-disabled');
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}); // colymba namespace
|
}); // colymba namespace
|
||||||
|
|
||||||
}); // ss namespace
|
}); // ss namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user