2017-01-25 13:27:11 +01:00
|
|
|
(function($) {
|
|
|
|
$.entwine('ss', function($) {
|
2014-04-06 14:51:15 +02:00
|
|
|
|
|
|
|
$.entwine('colymba', function($) {
|
2014-04-07 18:32:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes sure the component is above the headers
|
|
|
|
*/
|
|
|
|
$('.bulkManagerOptions').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
var $parent = this.parents('thead'),
|
|
|
|
$tr = $parent.find('tr'),
|
|
|
|
|
|
|
|
targets = ['.filter-header', '.sortable-header'],
|
|
|
|
$target = $parent.find(targets.join(',')),
|
|
|
|
|
|
|
|
index = $tr.index(this),
|
|
|
|
newIndex = $tr.length - 1
|
|
|
|
;
|
|
|
|
|
|
|
|
$target.each(function(index, Element){
|
|
|
|
var idx = $tr.index(Element);
|
|
|
|
if ( idx < newIndex )
|
|
|
|
{
|
|
|
|
newIndex = idx;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if ( index > newIndex )
|
|
|
|
{
|
2015-08-26 23:36:02 +02:00
|
|
|
$tr.eq(newIndex).insertAfter($(this));
|
|
|
|
}
|
2014-04-07 18:32:43 +02:00
|
|
|
},
|
|
|
|
onunmatch: function(){}
|
|
|
|
});
|
|
|
|
|
2017-01-25 13:27:11 +01:00
|
|
|
|
2014-05-04 16:12:05 +02:00
|
|
|
/**
|
|
|
|
* Bulkselect table cell behaviours
|
|
|
|
*/
|
2014-04-06 14:51:15 +02:00
|
|
|
$('td.col-bulkSelect').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
},
|
2017-01-25 13:27:11 +01:00
|
|
|
onunmatch: function(){
|
2014-04-06 14:51:15 +02:00
|
|
|
},
|
|
|
|
onmouseover: function(){
|
|
|
|
//disable default row click behaviour -> avoid navigation to edit form when clicking the checkbox
|
|
|
|
$(this).parents('.ss-gridfield-item').find('.edit-link').removeClass('edit-link').addClass('tempDisabledEditLink');
|
|
|
|
},
|
|
|
|
onmouseout: function(){
|
|
|
|
//re-enable default row click behaviour
|
|
|
|
$(this).parents('.ss-gridfield-item').find('.tempDisabledEditLink').addClass('edit-link').removeClass('tempDisabledEditLink');
|
|
|
|
},
|
|
|
|
onclick: function(e) {
|
|
|
|
//check/uncheck checkbox when clicking cell
|
|
|
|
var cb = $(e.target).find('input');
|
|
|
|
if ( !$(cb).prop('checked') ) $(cb).prop('checked', true);
|
|
|
|
else $(cb).prop('checked', false);
|
|
|
|
}
|
|
|
|
});
|
2014-05-04 16:12:05 +02:00
|
|
|
|
2017-01-25 13:27:11 +01:00
|
|
|
|
2014-05-04 16:12:05 +02:00
|
|
|
/**
|
|
|
|
* Individual select checkbox behaviour
|
|
|
|
*/
|
2014-04-06 14:51:15 +02:00
|
|
|
$('td.col-bulkSelect input').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
},
|
2017-01-25 13:27:11 +01:00
|
|
|
onunmatch: function(){
|
2014-04-06 14:51:15 +02:00
|
|
|
},
|
|
|
|
onclick: function(e) {
|
2017-01-25 13:27:11 +01:00
|
|
|
$(this).parents('.grid-field__table').find('input.bulkSelectAll').prop('checked', '');
|
2014-04-06 14:51:15 +02:00
|
|
|
}
|
|
|
|
});
|
2017-01-25 13:27:11 +01:00
|
|
|
|
2014-05-04 16:12:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bulkselect checkbox behaviours
|
|
|
|
*/
|
2014-04-06 14:51:15 +02:00
|
|
|
$('input.bulkSelectAll').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
},
|
2017-01-25 13:27:11 +01:00
|
|
|
onunmatch: function(){
|
2014-04-06 14:51:15 +02:00
|
|
|
},
|
|
|
|
onclick: function()
|
|
|
|
{
|
|
|
|
var state = $(this).prop('checked');
|
2017-01-25 13:27:11 +01:00
|
|
|
$(this).parents('.grid-field__table')
|
2014-04-06 14:51:15 +02:00
|
|
|
.find('td.col-bulkSelect input')
|
2014-07-09 14:46:08 +02:00
|
|
|
.prop('checked', state)
|
|
|
|
.trigger('change');
|
2014-04-06 14:51:15 +02:00
|
|
|
},
|
|
|
|
getSelectRecordsID: function()
|
|
|
|
{
|
2017-01-25 13:27:11 +01:00
|
|
|
return $(this).parents('.grid-field__table')
|
2014-04-06 14:51:15 +02:00
|
|
|
.find('td.col-bulkSelect input:checked')
|
2017-01-25 13:27:11 +01:00
|
|
|
.map(function() {
|
2014-04-06 14:51:15 +02:00
|
|
|
return parseInt( $(this).data('record') )
|
|
|
|
})
|
|
|
|
.get();
|
|
|
|
}
|
|
|
|
});
|
2014-05-04 16:12:05 +02:00
|
|
|
|
2017-01-25 13:27:11 +01:00
|
|
|
|
2014-05-04 16:12:05 +02:00
|
|
|
/**
|
|
|
|
* Bulk action dropdown behaviours
|
|
|
|
*/
|
2014-04-06 14:51:15 +02:00
|
|
|
$('select.bulkActionName').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
},
|
2017-01-25 13:27:11 +01:00
|
|
|
onunmatch: function(){
|
2014-04-06 14:51:15 +02:00
|
|
|
},
|
|
|
|
onchange: function(e)
|
2013-12-01 12:31:35 +01:00
|
|
|
{
|
2018-02-12 14:11:49 +01:00
|
|
|
var value = $(this).val(),
|
|
|
|
$parent = $(this).parents('.bulkManagerOptions'),
|
|
|
|
$btn = $parent.find('.doBulkActionButton'),
|
|
|
|
config = $btn.data('config');
|
2014-04-06 14:51:15 +02:00
|
|
|
|
|
|
|
$.each( config, function( configKey, configData )
|
2013-12-01 12:31:35 +01:00
|
|
|
{
|
2014-04-06 14:51:15 +02:00
|
|
|
if ( configKey != value )
|
|
|
|
{
|
2018-02-12 14:11:49 +01:00
|
|
|
$btn.removeClass(configData['buttonClasses']);
|
2014-04-06 14:51:15 +02:00
|
|
|
}
|
|
|
|
});
|
2018-02-27 12:49:51 +01:00
|
|
|
|
|
|
|
if(!value)
|
|
|
|
{
|
|
|
|
$btn.addClass('disabled');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$btn.removeClass('disabled');
|
|
|
|
}
|
|
|
|
|
2018-02-12 14:11:49 +01:00
|
|
|
$btn.addClass(config[value]['buttonClasses']).addClass('btn-outline-secondary');
|
|
|
|
|
|
|
|
|
|
|
|
if ( config[value]['icon'] )
|
|
|
|
{
|
|
|
|
var $img = $btn.find('img');
|
|
|
|
|
|
|
|
if ($img.length)
|
|
|
|
{
|
|
|
|
$img.attr('src', config[value]['icon']);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$btn.prepend('<img src="'+config[value]['icon']+'" alt="" />');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$btn.find('img').remove();
|
|
|
|
}
|
2013-12-01 12:31:35 +01:00
|
|
|
|
|
|
|
|
2018-02-12 14:11:49 +01:00
|
|
|
if ( config[value]['destructive'] )
|
2014-04-06 14:51:15 +02:00
|
|
|
{
|
2018-02-12 14:11:49 +01:00
|
|
|
$btn.addClass('btn-outline-danger');
|
2014-04-06 14:51:15 +02:00
|
|
|
}
|
|
|
|
else{
|
2018-02-12 14:11:49 +01:00
|
|
|
$btn.removeClass('btn-outline-danger');
|
2014-04-06 14:51:15 +02:00
|
|
|
}
|
2017-01-25 13:27:11 +01:00
|
|
|
|
|
|
|
}
|
2014-04-06 14:51:15 +02:00
|
|
|
});
|
2017-01-25 13:27:11 +01:00
|
|
|
|
2014-05-04 16:12:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* bulk action button behaviours
|
|
|
|
*/
|
2014-04-06 14:51:15 +02:00
|
|
|
$('.doBulkActionButton').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
},
|
2017-01-25 13:27:11 +01:00
|
|
|
onunmatch: function(){
|
2014-04-06 14:51:15 +02:00
|
|
|
},
|
|
|
|
getActionURL: function(action, url)
|
2014-03-14 12:58:16 +01:00
|
|
|
{
|
2014-04-06 14:51:15 +02:00
|
|
|
var cacheBuster = new Date().getTime();
|
|
|
|
url = url.split('?');
|
|
|
|
|
|
|
|
if ( action )
|
|
|
|
{
|
|
|
|
action = '/' + action;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
action = '';
|
|
|
|
}
|
2014-03-14 12:58:16 +01:00
|
|
|
|
2014-04-06 14:51:15 +02:00
|
|
|
if ( url[1] )
|
|
|
|
{
|
|
|
|
url = url[0] + action + '?' + url[1] + '&' + 'cacheBuster=' + cacheBuster;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
url = url[0] + action + '?' + 'cacheBuster=' + cacheBuster;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
onclick: function(e)
|
2014-03-14 12:58:16 +01:00
|
|
|
{
|
2014-04-06 16:39:41 +02:00
|
|
|
var $parent = $(this).parents('.bulkManagerOptions'),
|
|
|
|
action = $parent.find('select.bulkActionName').val(),
|
|
|
|
ids = $(this).parents('.bulkManagerOptions').find('input.bulkSelectAll:first').getSelectRecordsID()
|
2017-01-25 13:27:11 +01:00
|
|
|
;
|
2013-12-01 17:51:30 +01:00
|
|
|
|
2017-01-25 13:27:11 +01:00
|
|
|
this.doBulkAction(action, ids);
|
2014-04-06 16:39:41 +02:00
|
|
|
},
|
2013-12-01 17:51:30 +01:00
|
|
|
|
2018-03-14 21:21:54 +01:00
|
|
|
doBulkAction: function(action, ids)
|
2017-01-25 13:27:11 +01:00
|
|
|
{
|
2014-04-06 16:39:41 +02:00
|
|
|
var $parent = $(this).parents('.bulkManagerOptions'),
|
|
|
|
$btn = $parent.find('a.doBulkActionButton'),
|
2018-03-14 21:21:54 +01:00
|
|
|
$msg = $parent.find('.message'),
|
2013-12-01 17:51:30 +01:00
|
|
|
|
2014-04-06 16:39:41 +02:00
|
|
|
config = $btn.data('config'),
|
|
|
|
url = this.getActionURL(action, $(this).data('url')),
|
|
|
|
data = { records: ids }
|
2014-04-06 14:51:15 +02:00
|
|
|
;
|
2017-01-25 13:27:11 +01:00
|
|
|
|
2014-04-06 14:51:15 +02:00
|
|
|
if ( ids.length <= 0 )
|
|
|
|
{
|
2014-04-13 18:56:12 +02:00
|
|
|
alert( ss.i18n._t('GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT') );
|
2014-04-06 14:51:15 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-12-01 17:51:30 +01:00
|
|
|
|
2014-04-06 18:55:25 +02:00
|
|
|
//if ( $btn.hasClass('ss-ui-action-destructive') )
|
2018-02-12 14:11:49 +01:00
|
|
|
if ( config[action]['destructive'] )
|
2013-12-05 18:44:56 +01:00
|
|
|
{
|
2014-04-13 18:56:12 +02:00
|
|
|
if( !confirm(ss.i18n._t('GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION')) )
|
2014-04-06 14:51:15 +02:00
|
|
|
{
|
|
|
|
return false;
|
2017-01-25 13:27:11 +01:00
|
|
|
}
|
|
|
|
}
|
2013-12-05 18:44:56 +01:00
|
|
|
|
2017-01-25 13:27:11 +01:00
|
|
|
$btn.addClass('loading');
|
2018-03-14 21:21:54 +01:00
|
|
|
$msg.removeClass('static show error warning');
|
2013-12-05 17:54:17 +01:00
|
|
|
|
2018-02-12 14:11:49 +01:00
|
|
|
if ( config[action]['xhr'] )
|
2014-04-06 14:51:15 +02:00
|
|
|
{
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
type: "POST",
|
|
|
|
context: $(this)
|
2018-03-14 21:21:54 +01:00
|
|
|
}).always(function(data, textStatus, jqXHR) {
|
|
|
|
$btn.removeClass('loading');
|
|
|
|
|
|
|
|
//if request fail, return a +4xx status code, extract json response
|
|
|
|
if (data.responseText) {
|
|
|
|
data = JSON.parse(data.responseText);
|
2014-04-06 16:39:41 +02:00
|
|
|
}
|
2018-03-14 21:21:54 +01:00
|
|
|
|
|
|
|
$msg.html(data.message);
|
|
|
|
|
|
|
|
if(data.isError) {
|
|
|
|
$msg.addClass('static error');
|
|
|
|
} else if (data.isWarning) {
|
|
|
|
$msg.addClass('show warning');
|
|
|
|
} else {
|
|
|
|
$msg.addClass('show');
|
2014-04-06 16:39:41 +02:00
|
|
|
}
|
2018-03-14 21:21:54 +01:00
|
|
|
|
|
|
|
bulkTools.gridfieldRefresh($(this).parents('.ss-gridfield'), data);
|
2014-04-06 14:51:15 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
var records = 'records[]='+ids.join('&records[]=');
|
|
|
|
url = url + '&' + records;
|
2013-12-01 17:51:30 +01:00
|
|
|
|
2014-04-06 14:51:15 +02:00
|
|
|
window.location.href = url;
|
|
|
|
}
|
2013-12-01 17:51:30 +01:00
|
|
|
}
|
2014-04-06 14:51:15 +02:00
|
|
|
});
|
2013-04-29 18:03:32 +02:00
|
|
|
|
2017-01-25 13:27:11 +01:00
|
|
|
|
|
|
|
});
|
2014-04-06 14:51:15 +02:00
|
|
|
});
|
2015-08-26 23:36:02 +02:00
|
|
|
}(jQuery));
|