Implement action callback + cancel behaviour

This commit is contained in:
colymba 2014-04-06 17:39:41 +03:00 committed by Thierry Francois
parent d141765752
commit 20350d3f35
2 changed files with 54 additions and 24 deletions

View File

@ -126,19 +126,24 @@
}, },
onclick: function(e) onclick: function(e)
{ {
var $parent = $(this).parents('.bulkManagerOptions'), var $parent = $(this).parents('.bulkManagerOptions'),
$btn = $parent.find('a.doBulkActionButton'), action = $parent.find('select.bulkActionName').val(),
ids = $(this).parents('.bulkManagerOptions').find('input.bulkSelectAll:first').getSelectRecordsID()
;
action = $parent.find('select.bulkActionName').val(), this.doBulkAction(action, ids);
config = $btn.data('config'), },
url = this.getActionURL(action, $(this).data('url')), doBulkAction: function(action, ids, callbackFunction, callbackContext)
{
var $parent = $(this).parents('.bulkManagerOptions'),
$btn = $parent.find('a.doBulkActionButton'),
ids = $(this).parents('.bulkManagerOptions').find('input.bulkSelectAll:first').getSelectRecordsID(), config = $btn.data('config'),
data = { records: ids } url = this.getActionURL(action, $(this).data('url')),
data = { records: ids }
; ;
if ( ids.length <= 0 ) if ( ids.length <= 0 )
{ {
alert( ss.i18n._t('GridFieldBulkManager.BULKACTION_EMPTY_SELECT') ); alert( ss.i18n._t('GridFieldBulkManager.BULKACTION_EMPTY_SELECT') );
@ -163,9 +168,15 @@
data: data, data: data,
type: "POST", type: "POST",
context: $(this) context: $(this)
}).done(function() { }).done(function(data, textStatus, jqXHR) {
$(this).parents('.ss-gridfield').entwine('.').entwine('ss').reload();
$btn.removeClass('loading'); $btn.removeClass('loading');
if ( callbackFunction && callbackContext )
{
callbackFunction.call(callbackContext, data);
}
else{
$(this).parents('.ss-gridfield').entwine('.').entwine('ss').reload();
}
}); });
} }
else{ else{
@ -174,12 +185,6 @@
window.location.href = url; window.location.href = url;
} }
},
doBulkAction: function(action, ids)
{
console.log(action, ids);
} }
}); });

View File

@ -172,12 +172,12 @@
onunmatch: function(){}, onunmatch: function(){},
onclick: function() onclick: function()
{ {
var $bulkUpload = this.parents('.bulkUpload'), var $bulkUpload = this.parents('.bulkUpload'),
$li = $bulkUpload.find('li.ss-uploadfield-item'), $li = $bulkUpload.find('li.ss-uploadfield-item'),
$records = $li.filter('[data-recordid]'), $records = $li.filter('[data-recordid]'),
recordsID, $other = $li.not($records),
$other = $li.not($records), $doBulkActionButton = $bulkUpload.parents('.ss-gridfield-table').find('.doBulkActionButton'),
$doBulkActionButton = $bulkUpload.parents('.ss-gridfield-table').find('.doBulkActionButton') recordsID
; ;
$other.each(function(index, Element){ $other.each(function(index, Element){
@ -191,8 +191,29 @@
return parseInt( $(this).data('recordid') ) return parseInt( $(this).data('recordid') )
}).get(); }).get();
$doBulkActionButton.doBulkAction('delete', recordsID); 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 = data.records
;
this.removeClass('loading');
$li.each(function(index, Element){
var $this = $(this),
recordID = parseInt( $this.data('recordid') )
;
if ( ids.indexOf(recordID) !== -1 )
{
$this.remove();
}
});
} }
}); });
@ -234,8 +255,12 @@
return parseInt( $(this).data('recordid') ) return parseInt( $(this).data('recordid') )
}).get(); }).get();
$doBulkActionButton.doBulkAction('edit', recordsID); $doBulkActionButton.doBulkAction('edit', recordsID, this.editCallback);
} }
},
editCallback: function(response)
{
} }
}); });