API remove cancel and edit upload buttons

API remove cancel and edit btns
This commit is contained in:
Thierry François 2018-02-22 10:15:42 +02:00
parent efb89e5b64
commit aa9bf472c6
3 changed files with 6 additions and 138 deletions

View File

@ -78,8 +78,6 @@
refresh: function(total, done, error) refresh: function(total, done, error)
{ {
var $info = this.find('.colymba-bulkupload-info'), var $info = this.find('.colymba-bulkupload-info'),
$editBtn = this.find('.bulkUploadEditButton'),
$cancelBtn = this.find('.bulkUploadCancelButton'),
$finishBtn = this.find('.bulkUploadFinishButton'), $finishBtn = this.find('.bulkUploadFinishButton'),
$clearErrorBtn = this.find('.bulkUploadClearErrorButton') $clearErrorBtn = this.find('.bulkUploadClearErrorButton')
; ;
@ -95,8 +93,6 @@
error error
)); ));
$cancelBtn.removeClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'false').removeAttr('disabled');
//if there are still uploads going //if there are still uploads going
if ( (done + error) < total ) if ( (done + error) < total )
{ {
@ -109,15 +105,6 @@
else{ else{
this.removeClass('loading'); this.removeClass('loading');
$finishBtn.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 all done and OK, enable edit
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');
} }
//toggle clear error button //toggle clear error button
@ -132,8 +119,6 @@
else{ else{
//if not uploading, reset + hide //if not uploading, reset + hide
this.css({display: 'none'}).removeClass('loading'); this.css({display: 'none'}).removeClass('loading');
$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'); $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'); $clearErrorBtn.addClass('ui-state-disabled ssui-button-disabled').attr('aria-disabled', 'true').attr('disabled', 'true');
} }
@ -161,70 +146,6 @@
} }
}); });
/**
* Cancel all uploads
* Clear the ones with warnings/error and delete dataObjects from the successful ones
*/
$('.bulkUploadCancelButton:not(.ui-state-disabled)').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]'),
$other = $li.not($records),
$doBulkActionButton = $bulkUpload.parents('.ss-gridfield-table').find('.doBulkActionButton'),
recordsID
;
$other.each(function(index, Element){
// skip in progress
$(this).remove();
});
if ( $doBulkActionButton.length > 0 )
{
recordsID = $records.map(function() {
return parseInt( $(this).data('recordid') )
}).get();
this.addClass('loading');
$doBulkActionButton.doBulkAction('delete', recordsID, this.cancelCallback, this);
}
},
cancelCallback: function(data)
{
var $bulkUpload = this.parents('.bulkUpload'),
$li = $bulkUpload.find('li.ss-uploadfield-item'),
ids
;
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();
}
});
$(this).parents('.ss-gridfield').entwine('.').entwine('ss').reload();
}
this.removeClass('loading');
}
});
/** /**
* Clear all the warning/error/finished uploads * Clear all the warning/error/finished uploads
@ -252,33 +173,6 @@
} }
}); });
$('.bulkUploadEditButton:not(.ui-state-disabled)').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 )
{
this.addClass('loading');
recordsID = $records.map(function() {
return parseInt( $(this).data('recordid') )
}).get();
$doBulkActionButton.doBulkAction('bulkedit', recordsID);
}
}
});
}); // colymba namespace }); // colymba namespace
}); // ss namespace }); // ss namespace

View File

@ -369,10 +369,7 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
if (!singleton($gridField->getModelClass())->canEdit()) { if (!singleton($gridField->getModelClass())->canEdit()) {
return array(); return array();
} }
// check BulkManager exists
$bulkManager = $gridField->getConfig()->getComponentsByType('Colymba\\BulkManager\\BulkManager');
// upload management buttons // upload management buttons
$finishButton = FormAction::create('Finish', _t('GRIDFIELD_BULK_UPLOAD.FINISH_BTN_LABEL', 'Finish')) $finishButton = FormAction::create('Finish', _t('GRIDFIELD_BULK_UPLOAD.FINISH_BTN_LABEL', 'Finish'))
->addExtraClass('bulkUploadFinishButton') ->addExtraClass('bulkUploadFinishButton')
@ -384,37 +381,12 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
->setAttribute('data-icon', 'arrow-circle-double') ->setAttribute('data-icon', 'arrow-circle-double')
->setUseButtonTag(true); ->setUseButtonTag(true);
if (count($bulkManager)) { // get uploadField
$cancelButton = FormAction::create('Cancel', _t('GRIDFIELD_BULK_UPLOAD.CANCEL_BTN_LABEL', 'Cancel'))
->addExtraClass('bulkUploadCancelButton ss-ui-action-destructive')
->setAttribute('data-icon', 'decline')
->setAttribute('data-url', $gridField->Link('bulkupload/cancel'))
->setUseButtonTag(true);
$bulkManager_config = $bulkManager->first()->getConfig();
$bulkManager_actions = $bulkManager_config['actions'];
if (array_key_exists('bulkedit', $bulkManager_actions)) {
$editAllButton = FormAction::create('EditAll', _t('GRIDFIELD_BULK_UPLOAD.EDIT_ALL_BTN_LABEL', 'Edit all'))
->addExtraClass('bulkUploadEditButton')
->setAttribute('data-icon', 'pencil')
->setAttribute('data-url', $gridField->Link('bulkupload/edit'))
->setUseButtonTag(true);
} else {
$editAllButton = '';
}
} else {
$cancelButton = '';
$editAllButton = '';
}
// get uploadField + inject extra buttons
$uploadField = $this->bulkUploadField($gridField); $uploadField = $this->bulkUploadField($gridField);
$uploadField->FinishButton = $finishButton;
$uploadField->CancelButton = $cancelButton;
$uploadField->EditAllButton = $editAllButton;
$uploadField->ClearErrorButton = $clearErrorButton;
$data = ArrayData::create(array( $data = ArrayData::create(array(
'Finish' => $finishButton,
'ClearErrors' => $clearErrorButton,
'Colspan' => (count($gridField->getColumns())), 'Colspan' => (count($gridField->getColumns())),
'UploadField' => $uploadField->Field() // call ->Field() to get requirements in right order 'UploadField' => $uploadField->Field() // call ->Field() to get requirements in right order
)); ));

View File

@ -1,5 +1,7 @@
<tr class="bulkUploader"> <tr class="bulkUploader">
<th class="" colspan="$Colspan"> <th class="" colspan="$Colspan">
$UploadField $UploadField
$Finish
$ClearErrors
</th> </th>
</tr> </tr>