mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
Basic BulkUploader support for SS4
This commit is contained in:
parent
7221897f27
commit
e35e62adda
@ -3,7 +3,8 @@
|
||||
namespace Colymba\BulkUpload;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Forms\UploadField;
|
||||
//use SilverStripe\Forms\UploadField;
|
||||
use SilverStripe\AssetAdmin\Forms\UploadField;
|
||||
|
||||
/**
|
||||
* Custom UploadField used to override Link()
|
||||
|
@ -230,7 +230,7 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
|
||||
|
||||
/**
|
||||
* Returns the class name of container `DataObject` record.
|
||||
* Either as set in the component config or fron the `Gridfield` `dataClass.
|
||||
* Either as set in the component config or from the `Gridfield` `dataClass`.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -314,21 +314,22 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
|
||||
$uploadField = BulkUploadField::create($gridField, $fileRelationName, '')
|
||||
->setForm($gridField->getForm())
|
||||
|
||||
->setConfig('previewMaxWidth', 20)
|
||||
/*->setConfig('previewMaxWidth', 20)
|
||||
->setConfig('previewMaxHeight', 20)
|
||||
->setConfig('changeDetection', false)
|
||||
->setConfig('changeDetection', false)*/
|
||||
|
||||
->setRecord(DataObject::create()) // avoid UploadField to get auto-config from the Page (e.g fix allowedMaxFileNumber)
|
||||
|
||||
->setTemplate('BulkUploadField')
|
||||
/*->setTemplate('BulkUploadField')
|
||||
->setDownloadTemplateName('colymba-bulkuploaddownloadtemplate')
|
||||
|
||||
->setConfig('url', $gridField->Link('bulkupload/upload'))
|
||||
->setConfig('urlSelectDialog', $gridField->Link('bulkupload/select'))
|
||||
->setConfig('urlAttach', $gridField->Link('bulkupload/attach'))
|
||||
->setConfig('urlFileExists', $gridField->Link('bulkupload/fileexists'))
|
||||
->setConfig('urlFileExists', $gridField->Link('bulkupload/fileexists'))*/
|
||||
;
|
||||
|
||||
/*
|
||||
//set UploadField config
|
||||
foreach ($this->ufConfig as $key => $val) {
|
||||
$uploadField->setConfig($key, $val);
|
||||
@ -343,6 +344,17 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
|
||||
foreach ($this->ufValidatorSetup as $fn => $param) {
|
||||
$uploadField->getValidator()->{$fn}($param);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
$uploadLink = $gridField->Link('bulkupload/upload');
|
||||
$schema['data']['createFileEndpoint'] = [
|
||||
'url' => $uploadLink,
|
||||
'method' => 'post',
|
||||
'payloadFormat' => 'urlencoded',
|
||||
];
|
||||
$uploadField->setSchemaData($schema);
|
||||
|
||||
return $uploadField;
|
||||
}
|
||||
@ -410,13 +422,12 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
|
||||
$uploadField->ClearErrorButton = $clearErrorButton;
|
||||
|
||||
$data = ArrayData::create(array(
|
||||
'Colspan' => count($gridField->getColumns()),
|
||||
'UploadField' => $uploadField->Field(), // call ->Field() to get requirements in right order
|
||||
'Colspan' => (count($gridField->getColumns())),
|
||||
'UploadField' => $uploadField->Field() // call ->Field() to get requirements in right order
|
||||
));
|
||||
|
||||
Requirements::css(BULKEDITTOOLS_UPLOAD_PATH . '/css/GridFieldBulkUpload.css');
|
||||
Requirements::javascript(BULKEDITTOOLS_UPLOAD_PATH . '/javascript/GridFieldBulkUpload.js');
|
||||
Requirements::javascript(BULKEDITTOOLS_UPLOAD_PATH . '/javascript/GridFieldBulkUpload_downloadtemplate.js');
|
||||
Requirements::add_i18n_javascript(BULKEDITTOOLS_PATH . '/lang/js');
|
||||
|
||||
return array(
|
||||
@ -453,7 +464,7 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
|
||||
public function handleBulkUpload($gridField, $request)
|
||||
{
|
||||
$controller = $gridField->getForm()->getController();
|
||||
$handler = new BulkUploaderRequest($gridField, $this, $controller);
|
||||
$handler = new \Colymba\BulkUpload\BulkUploaderRequest($gridField, $this, $controller);
|
||||
|
||||
return $handler->handleRequest($request, DataModel::inst());
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
|
||||
|
||||
/**
|
||||
* Handles request from the GridFieldBulkUpload component.
|
||||
*
|
||||
@ -93,7 +95,7 @@ class BulkUploaderRequest extends RequestHandler
|
||||
*
|
||||
* @return string json
|
||||
*/
|
||||
public function upload(HTTPRequest $request)
|
||||
/*public function upload(HTTPRequest $request)
|
||||
{
|
||||
//create record
|
||||
$recordClass = $this->component->getRecordClassName($this->gridField);
|
||||
@ -102,10 +104,6 @@ class BulkUploaderRequest extends RequestHandler
|
||||
|
||||
// passes the current gridfield-instance to a call-back method on the new object
|
||||
$record->extend('onBulkUpload', $this->gridField);
|
||||
if ($record->hasMethod('onBulkImageUpload')) {
|
||||
Deprecation::notice('2.0', '"onBulkImageUpload" callback is deprecated, use "onBulkUpload" instead.');
|
||||
$record->extend('onBulkImageUpload', $this->gridField);
|
||||
}
|
||||
|
||||
//get uploadField and process upload
|
||||
$uploadField = $this->getUploadField();
|
||||
@ -131,6 +129,38 @@ class BulkUploaderRequest extends RequestHandler
|
||||
$this->contentTypeNegotiation($response);
|
||||
|
||||
return $response;
|
||||
}*/
|
||||
|
||||
public function upload(HTTPRequest $request)
|
||||
{
|
||||
// 1. DataObject
|
||||
//create record
|
||||
$recordClass = $this->component->getRecordClassName($this->gridField);
|
||||
$record = Object::create($recordClass);
|
||||
$record->write();
|
||||
|
||||
// passes the current gridfield-instance to a call-back method on the new object
|
||||
$record->extend('onBulkUpload', $this->gridField);
|
||||
|
||||
// 2. File Upload
|
||||
$assetAdmin = AssetAdmin::singleton();
|
||||
$uploadResponse = $assetAdmin->apiCreateFile($request);
|
||||
$file = null;
|
||||
|
||||
if ($uploadResponse->getStatusCode() == 200)
|
||||
{
|
||||
$responseData = Convert::json2array($uploadResponse->getBody());
|
||||
$responseData = array_shift($responseData);
|
||||
}
|
||||
|
||||
// 3. Add File to Record
|
||||
$fileRelationName = $this->component->getFileRelationName($this->gridField);
|
||||
$record->{"{$fileRelationName}ID"} = $responseData['id'];
|
||||
|
||||
// 4. Add to Gridfield List
|
||||
$this->gridField->list->add($record);
|
||||
|
||||
return $uploadResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,7 +7,7 @@
|
||||
/**
|
||||
* Makes sure the component is at the top :)
|
||||
*/
|
||||
$('.bulkUpload').entwine({
|
||||
$('.bulkUploader').entwine({
|
||||
onmatch: function(){
|
||||
var $tr = this.parents('thead').find('tr'),
|
||||
$component = this.clone(),
|
||||
|
@ -1,30 +0,0 @@
|
||||
window.tmpl.cache['colymba-bulkuploaddownloadtemplate'] = tmpl(
|
||||
'{% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}' +
|
||||
'<li class="ss-uploadfield-item template-download{% if (file.error) { %} ui-state-error{% }else{ %} done{% } %}" data-fileid="{%=file.id%}" data-recordid="{%=file.record.id%}">' +
|
||||
'<div class="ss-uploadfield-item-preview preview"><span>' +
|
||||
'<img src="{%=file.thumbnail_url%}" alt="" />' +
|
||||
'</span></div>' +
|
||||
'<div class="ss-uploadfield-item-info">' +
|
||||
'{% if (!file.error) { %}' +
|
||||
'<input type="hidden" name="{%=file.fieldname%}[Files][]" value="{%=file.id%}" />' +
|
||||
'{% } %}' +
|
||||
'<label class="ss-uploadfield-item-name">' +
|
||||
'<span class="name" title="{%=file.name%}">{%=file.name%}</span> ' +
|
||||
'<span class="size">{%=o.formatFileSize(file.size)%}</span>' +
|
||||
'{% if (!file.error) { %}' +
|
||||
'<div class="ss-uploadfield-item-status ui-state-success-text" title="'+ss.i18n._t('UploadField.Uploaded', 'Uploaded')+'">'+ss.i18n._t('UploadField.Uploaded', 'Uploaded')+'</div>' +
|
||||
'{% } else { %}' +
|
||||
'<div class="ss-uploadfield-item-status ui-state-error-text" title="{%=o.options.errorMessages[file.error] || file.error%}">{%=o.options.errorMessages[file.error] || file.error%}</div>' +
|
||||
'{% } %}' +
|
||||
'<div class="clear"><!-- --></div>' +
|
||||
'</label>' +
|
||||
'{% if (file.error) { %}' +
|
||||
'<div class="ss-uploadfield-item-actions">' +
|
||||
'<div class="ss-uploadfield-item-cancel ss-uploadfield-item-cancelfailed delete"><button class="icon icon-16" data-icon="delete" title="' + ss.i18n._t('UploadField.CANCELREMOVE', 'Cancel/Remove') + '">' + ss.i18n._t('UploadField.CANCELREMOVE', 'Cancel/Remove') + '</button></div>' +
|
||||
'</div>' +
|
||||
'{% } else { %}' +
|
||||
'{% } %}' +
|
||||
'</div>' +
|
||||
'</li>' +
|
||||
'{% } %}'
|
||||
);
|
@ -1,80 +0,0 @@
|
||||
<% if $canUpload || $canAttachExisting %>
|
||||
<div class="ss-uploadfield-item ss-uploadfield-addfile<% if $CustomisedItems %> borderTop<% end_if %>">
|
||||
<% if canUpload %>
|
||||
<div class="ss-uploadfield-item-preview ss-uploadfield-dropzone ui-corner-all">
|
||||
<% if $multiple %>
|
||||
<% _t('UploadField.DROPFILES', 'drop files') %>
|
||||
<% else %>
|
||||
<% _t('UploadField.DROPFILE', 'drop a file') %>
|
||||
<% end_if %>
|
||||
</div>
|
||||
<% end_if %>
|
||||
<div class="ss-uploadfield-item-info">
|
||||
<label class="ss-uploadfield-item-name">
|
||||
<% if $multiple %>
|
||||
<b><% _t('UploadField.ATTACHFILES', 'Attach files') %></b>
|
||||
<% else %>
|
||||
<b><% _t('UploadField.ATTACHFILE', 'Attach a file') %></b>
|
||||
<% end_if %>
|
||||
<% if $canPreviewFolder %>
|
||||
<small>(<%t UploadField.UPLOADSINTO 'saves into /{path}' path=$FolderName %>)</small>
|
||||
<% end_if %>
|
||||
</label>
|
||||
<% if $canUpload %>
|
||||
<label class="ss-uploadfield-fromcomputer ss-ui-button ui-corner-all" title="<% _t('UploadField.FROMCOMPUTERINFO', 'Upload from your computer') %>" data-icon="drive-upload">
|
||||
<% _t('UploadField.FROMCOMPUTER', 'From your computer') %>
|
||||
<input id="$id" name="{$Name}[Uploads][]" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString" type="file"<% if $multiple %> multiple="multiple"<% end_if %> />
|
||||
</label>
|
||||
<% else %>
|
||||
<input id="$id" name="{$Name}[Uploads][]" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString" type="hidden" />
|
||||
<% end_if %>
|
||||
|
||||
<% if $canAttachExisting %>
|
||||
<button class="ss-uploadfield-fromfiles ss-ui-button ui-corner-all" title="<% _t('UploadField.FROMCOMPUTERINFO', 'Select from files') %>" data-icon="network-cloud"><% _t('UploadField.FROMFILES', 'From files') %></button>
|
||||
<% end_if %>
|
||||
<% if $canUpload %>
|
||||
<% if not $autoUpload %>
|
||||
<button class="ss-uploadfield-startall ss-ui-button ui-corner-all" data-icon="navigation"><% _t('UploadField.STARTALL', 'Start all') %></button>
|
||||
<% end_if %>
|
||||
<% end_if %>
|
||||
<div class="clear"><!-- --></div>
|
||||
</div>
|
||||
<div class="clear"><!-- --></div>
|
||||
</div>
|
||||
|
||||
<div class="colymba-bulkupload-buttons">
|
||||
$FinishButton
|
||||
$CancelButton
|
||||
<span class="colymba-bulkupload-info"></span>
|
||||
$ClearErrorButton
|
||||
$EditAllButton
|
||||
</div>
|
||||
<% end_if %>
|
||||
|
||||
<ul class="ss-uploadfield-files files">
|
||||
<% if $CustomisedItems %>
|
||||
<% loop $CustomisedItems %>
|
||||
<li class="ss-uploadfield-item template-download" data-fileid="$ID">
|
||||
<div class="ss-uploadfield-item-preview preview"><span>
|
||||
<img alt="$hasRelation" src="$UploadFieldThumbnailURL" />
|
||||
</span></div>
|
||||
<div class="ss-uploadfield-item-info">
|
||||
<input type='hidden' value='$ID' name='{$Top.Name}[Files][]' />
|
||||
<label class="ss-uploadfield-item-name">
|
||||
<span class="name">$Name.XML</span>
|
||||
<span class="size">$Size</span>
|
||||
<div class="clear"><!-- --></div>
|
||||
</label>
|
||||
<div class="ss-uploadfield-item-actions">
|
||||
<% if $Top.isActive %>
|
||||
$UploadFieldFileButtons
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ss-uploadfield-item-editform includeParent">
|
||||
<iframe frameborder="0" data-src="$UploadFieldEditLink" src="about:blank"></iframe>
|
||||
</div>
|
||||
</li>
|
||||
<% end_loop %>
|
||||
<% end_if %>
|
||||
</ul>
|
@ -1,9 +1,5 @@
|
||||
<tr class="bulkUpload">
|
||||
<th class="component" colspan="$Colspan">
|
||||
|
||||
<div class="upload ss-upload ss-uploadfield">
|
||||
<tr class="bulkUploader">
|
||||
<th class="" colspan="$Colspan">
|
||||
$UploadField
|
||||
</div>
|
||||
|
||||
</th>
|
||||
</tr>
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "colymba/gridfield-bulk-editing-tools",
|
||||
"type": "silverstripe-module",
|
||||
"description": "SilverStripe 3 GridField component to upload images and edit records in bulk",
|
||||
"description": "SilverStripe GridField component to upload images and edit records in bulk",
|
||||
"homepage": "https://github.com/colymba/GridFieldBulkEditingTools",
|
||||
"keywords": ["silverstripe", "bulk upload", "image upload", "gridfield bulk upload"],
|
||||
"license": "BSD Simplified",
|
||||
@ -16,7 +16,8 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": "^4.0@dev"
|
||||
"silverstripe/framework": "^4.0@dev",
|
||||
"silverstripe/asset-admin": "^4.0@dev"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
Loading…
Reference in New Issue
Block a user