diff --git a/bulkManager/code/GridFieldBulkManager.php b/bulkManager/code/GridFieldBulkManager.php index bb5d6e1..92f46c0 100644 --- a/bulkManager/code/GridFieldBulkManager.php +++ b/bulkManager/code/GridFieldBulkManager.php @@ -25,6 +25,7 @@ class GridFieldBulkManager implements GridField_HTMLProvider, GridField_ColumnPr 'actions' => array() ); + /** * Holds any class that should not be used as they break the component * These cannot be removed from the blacklist diff --git a/bulkUpload/code/GridFieldBulkUpload.php b/bulkUpload/code/GridFieldBulkUpload.php index fe16703..2794557 100644 --- a/bulkUpload/code/GridFieldBulkUpload.php +++ b/bulkUpload/code/GridFieldBulkUpload.php @@ -11,40 +11,26 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle * component configuration * * 'fileRelationName' => field name of the $has_one File/Image relation - * 'editableFields' => fields editable on the Model - * 'fieldsClassBlacklist' => field types that will be removed from the automatic form generation - * 'fieldsNameBlacklist' => fields that will be removed from the automatic form generation - * + * 'folderName' => where to upload the files + * 'maxFileSize' => maximum file size allowed per upload + * 'sequentialUploads' => process uploads 1 after the other rather than all at once * @var array */ protected $config = array( - 'fileRelationName' => null, - 'editableFields' => null, - 'fieldsClassBlacklist' => array(), - 'fieldsNameBlacklist' => array(), - 'folderName' => 'bulkUpload', - 'maxFileSize' => null, + 'fileRelationName' => null, + 'folderName' => 'bulkUpload', + 'maxFileSize' => null, '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/array $editableFields */ - public function __construct($fileRelationName = null, $editableFields = null) + public function __construct($fileRelationName = null) { 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) ) { 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 if ( $reference == 'maxFileSize' && !is_int($value) ) @@ -97,58 +72,6 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle if ( $reference ) return $this->config[$reference]; 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 */ public function getURLHandlers($gridField) { - return array( - 'bulkupload' => 'handleBulkUpload' - ); + return array( + 'bulkupload' => 'handleBulkUpload' + ); } /** @@ -340,8 +263,8 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle */ public function handleBulkUpload($gridField, $request) { - $controller = $gridField->getForm()->Controller(); - $handler = new GridFieldBulkUpload_Request($gridField, $this, $controller); + $controller = $gridField->getForm()->Controller(); + $handler = new GridFieldBulkUpload_Request($gridField, $this, $controller); return $handler->handleRequest($request, DataModel::inst()); } diff --git a/bulkUpload/javascript/GridFieldBulkUpload.js b/bulkUpload/javascript/GridFieldBulkUpload.js index fb99026..02b3285 100644 --- a/bulkUpload/javascript/GridFieldBulkUpload.js +++ b/bulkUpload/javascript/GridFieldBulkUpload.js @@ -148,6 +148,9 @@ }); + /** + * Clears all updloads with warning or error + */ $('.bulkUploadClearErrorButton').entwine({ onmatch: function(){ 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({ onmatch: function(){ this.removeClass('action'); @@ -222,6 +230,10 @@ } }); + + /** + * Clear all the warning/error/finished uploads + */ $('.bulkUploadFinishButton').entwine({ onmatch: function(){ this.removeClass('action'); @@ -259,7 +271,7 @@ if ( $doBulkActionButton.length > 0 ) { this.addClass('loading'); - + recordsID = $records.map(function() { return parseInt( $(this).data('recordid') ) }).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 }); // ss namespace