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

View File

@ -172,12 +172,12 @@
onunmatch: function(){},
onclick: function()
{
var $bulkUpload = this.parents('.bulkUpload'),
$li = $bulkUpload.find('li.ss-uploadfield-item'),
$records = $li.filter('[data-recordid]'),
recordsID,
$other = $li.not($records),
$doBulkActionButton = $bulkUpload.parents('.ss-gridfield-table').find('.doBulkActionButton')
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){
@ -191,8 +191,29 @@
return parseInt( $(this).data('recordid') )
}).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') )
}).get();
$doBulkActionButton.doBulkAction('edit', recordsID);
$doBulkActionButton.doBulkAction('edit', recordsID, this.editCallback);
}
},
editCallback: function(response)
{
}
});