mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
Streamline classes/id + simplify dom
This commit is contained in:
parent
e621f4895f
commit
4a17d7d74a
@ -63,8 +63,9 @@ class GridFieldBulkActionEditHandler extends GridFieldBulkActionHandler
|
||||
$config = $this->component->getConfig();
|
||||
|
||||
$editingCount = count($recordList);
|
||||
$singleton = singleton($this->gridField->getModelClass());
|
||||
$editingClassName = (($editingCount > 1) ? $singleton->i18n_plural_name() : $singleton->i18n_singular_name());
|
||||
$modelClass = $this->gridField->getModelClass();
|
||||
$singleton = singleton($modelClass);
|
||||
$titleModelClass = (($editingCount > 1) ? $singleton->i18n_plural_name() : $singleton->i18n_singular_name());
|
||||
|
||||
$header = LiteralField::create(
|
||||
'bulkEditHeader',
|
||||
@ -72,7 +73,7 @@ class GridFieldBulkActionEditHandler extends GridFieldBulkActionHandler
|
||||
'Editing {count} {class}',
|
||||
array(
|
||||
'count' => $editingCount,
|
||||
'class' => $editingClassName
|
||||
'class' => $titleModelClass
|
||||
)
|
||||
) . '</h1>'
|
||||
);
|
||||
@ -83,6 +84,8 @@ class GridFieldBulkActionEditHandler extends GridFieldBulkActionHandler
|
||||
|
||||
foreach ( $recordList as $id )
|
||||
{
|
||||
$record = DataObject::get_by_id($modelClass, $id);
|
||||
|
||||
$recordCMSDataFields = GridFieldBulkEditingHelper::getModelCMSDataFields( $config, $this->gridField->list->dataClass );
|
||||
$recordCMSDataFields = GridFieldBulkEditingHelper::getModelFilteredDataFields($config, $recordCMSDataFields);
|
||||
$recordCMSDataFields = GridFieldBulkEditingHelper::populateCMSDataFields( $recordCMSDataFields, $this->gridField->list->dataClass, $id );
|
||||
@ -92,17 +95,19 @@ class GridFieldBulkActionEditHandler extends GridFieldBulkActionHandler
|
||||
|
||||
$recordsFieldList->push(
|
||||
ToggleCompositeField::create(
|
||||
'GFBM_'.$id,
|
||||
DataObject::get_by_id($this->gridField->list->dataClass, $id)->getTitle(),
|
||||
'RecordFields_'.$id,
|
||||
$record->getTitle(),
|
||||
array_values($recordCMSDataFields)
|
||||
)->setHeadingLevel(4)
|
||||
)
|
||||
->setHeadingLevel(4)
|
||||
->setAttribute('data-id', $id)
|
||||
->addExtraClass('bulkEditingFieldHolder')
|
||||
);
|
||||
}
|
||||
|
||||
$form = new Form(
|
||||
$this,
|
||||
'bulkEditingForm',
|
||||
'BulkEditingForm',
|
||||
$recordsFieldList,
|
||||
$actions
|
||||
);
|
||||
|
@ -13,11 +13,11 @@
|
||||
text-decoration: underline;
|
||||
cursor: pointer; }
|
||||
|
||||
.bulkEditingForm {
|
||||
.bulkEditingFieldHolder {
|
||||
position: relative;
|
||||
float: left;
|
||||
width: 100%; }
|
||||
.bulkEditingForm.hasUpdate .ui-accordion-header {
|
||||
.bulkEditingFieldHolder.hasUpdate .ui-accordion-header {
|
||||
background-color: #f2ba11;
|
||||
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #f2ba11), color-stop(100%, #df6e00));
|
||||
background-image: -webkit-linear-gradient(top, #f2ba11 0%, #df6e00 100%);
|
||||
@ -25,10 +25,10 @@
|
||||
background-image: -o-linear-gradient(top, #f2ba11 0%, #df6e00 100%);
|
||||
background-image: -ms-linear-gradient(top, #f2ba11 0%, #df6e00 100%);
|
||||
background-image: linear-gradient(top, #f2ba11 0%, #df6e00 100%); }
|
||||
.bulkEditingForm.hasUpdate .ui-accordion-header a {
|
||||
.bulkEditingFieldHolder.hasUpdate .ui-accordion-header a {
|
||||
color: #fff;
|
||||
text-shadow: none; }
|
||||
.bulkEditingForm.updated .ui-accordion-header {
|
||||
.bulkEditingFieldHolder.updated .ui-accordion-header {
|
||||
background-color: #a4ca3a;
|
||||
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #a4ca3a), color-stop(100%, #59781d));
|
||||
background-image: -webkit-linear-gradient(top, #a4ca3a 0%, #59781d 100%);
|
||||
@ -36,6 +36,6 @@
|
||||
background-image: -o-linear-gradient(top, #a4ca3a 0%, #59781d 100%);
|
||||
background-image: -ms-linear-gradient(top, #a4ca3a 0%, #59781d 100%);
|
||||
background-image: linear-gradient(top, #a4ca3a 0%, #59781d 100%); }
|
||||
.bulkEditingForm.updated .ui-accordion-header a {
|
||||
.bulkEditingFieldHolder.updated .ui-accordion-header a {
|
||||
color: #fff;
|
||||
text-shadow: none; }
|
||||
|
@ -22,7 +22,7 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.bulkEditingForm
|
||||
.bulkEditingFieldHolder
|
||||
{
|
||||
position: relative;
|
||||
float: left;
|
||||
|
@ -1,12 +1,16 @@
|
||||
(function($) {
|
||||
$.entwine('colymba', function($) {
|
||||
|
||||
/**
|
||||
* Toggle all accordion forms
|
||||
* open or closed
|
||||
*/
|
||||
$('#bulkEditToggle') .entwine({
|
||||
onmatch: function(){},
|
||||
onunmatch: function(){},
|
||||
onclick: function(e)
|
||||
{
|
||||
var toggleFields = $(this).parents('#Form_bulkEditingForm').find('.ss-toggle h4'),
|
||||
var toggleFields = this.parents('#Form_BulkEditingForm').find('.ss-toggle h4'),
|
||||
state = this.data('state')
|
||||
;
|
||||
|
||||
@ -38,20 +42,13 @@
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Contains each rocrds editing fields,
|
||||
* tracks changes and updates...
|
||||
*/
|
||||
$('.bulkEditingFieldHolder').entwine({
|
||||
onmatch: function(){
|
||||
var id = this.attr('id').split('_')[3],
|
||||
name = 'bulkEditingForm',
|
||||
$wrap = $('<div/>')
|
||||
;
|
||||
|
||||
$wrap.attr('id', name + '_' + id).addClass(name).data('id', id);
|
||||
this.wrap($wrap);
|
||||
},
|
||||
onunmatch: function(){}
|
||||
});
|
||||
|
||||
$('.bulkEditingForm').entwine({
|
||||
onmatch: function(){},
|
||||
onunmatch: function(){},
|
||||
onchange: function(){
|
||||
this.removeClass('updated');
|
||||
if ( !this.hasClass('hasUpdate') )
|
||||
@ -61,19 +58,24 @@
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Save all button
|
||||
* process all field holders with updates
|
||||
*/
|
||||
$('#bulkEditingUpdateBtn').entwine({
|
||||
onmatch: function(){},
|
||||
onunmatch: function(){},
|
||||
onclick: function(e){
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
var $formsWithUpadtes = $('div.bulkEditingForm.hasUpdate'),
|
||||
var $fieldHolders = $('div.bulkEditingFieldHolder.hasUpdate'),
|
||||
url = this.data('url'),
|
||||
data = {},
|
||||
cacheBuster = new Date().getTime() + '_' + this.attr('name')
|
||||
;
|
||||
|
||||
if ( $formsWithUpadtes.length > 0 )
|
||||
if ( $fieldHolders.length > 0 )
|
||||
{
|
||||
this.addClass('loading');
|
||||
}
|
||||
@ -89,7 +91,7 @@
|
||||
cacheBuster = '?cacheBuster=' + cacheBuster;
|
||||
}
|
||||
|
||||
$formsWithUpadtes.each(function(){
|
||||
$fieldHolders.each(function(){
|
||||
var $this = $(this);
|
||||
data[$this.data('id')] = $this.find(':input').serializeArray();
|
||||
});
|
||||
@ -105,13 +107,13 @@
|
||||
}catch(er){}
|
||||
|
||||
$.each(data.records, function(index, record){
|
||||
var $form = $('#bulkEditingForm_'+record.id)
|
||||
$formHeader = $form.find('.ui-accordion-header')
|
||||
var $fieldHolder = $('#Form_BulkEditingForm_RecordFields_'+record.id),
|
||||
$header = $fieldHolder.find('.ui-accordion-header')
|
||||
;
|
||||
|
||||
$form.removeClass('hasUpdate').addClass('updated');
|
||||
$formHeader.find('a').html(record.title);
|
||||
$formHeader.click();
|
||||
$fieldHolder.removeClass('hasUpdate').addClass('updated');
|
||||
$header.find('a').html(record.title);
|
||||
$header.click();
|
||||
});
|
||||
|
||||
this.removeClass('loading');
|
||||
|
Loading…
Reference in New Issue
Block a user