2012-08-11 00:19:13 +02:00
|
|
|
(function($) {
|
|
|
|
|
|
|
|
$.entwine('colymba', function($) {
|
2012-09-05 20:14:44 +02:00
|
|
|
|
2012-08-11 00:19:13 +02:00
|
|
|
$('td.col-bulkSelect').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
},
|
|
|
|
onunmatch: function(){
|
|
|
|
},
|
|
|
|
onmouseover: function(){
|
|
|
|
//disable default row click behaviour -> avoid navigation to edit form when clicking the checkbox
|
2012-09-05 20:14:44 +02:00
|
|
|
$(this).parents('.ss-gridfield-item').find('.edit-link').removeClass('edit-link').addClass('tempDisabledEditLink');
|
2012-08-11 00:19:13 +02:00
|
|
|
},
|
|
|
|
onmouseout: function(){
|
|
|
|
//re-enable default row click behaviour
|
2012-09-05 20:14:44 +02:00
|
|
|
$(this).parents('.ss-gridfield-item').find('.tempDisabledEditLink').addClass('edit-link').removeClass('tempDisabledEditLink');
|
2012-08-11 00:19:13 +02:00
|
|
|
},
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('td.col-bulkSelect input').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
},
|
|
|
|
onunmatch: function(){
|
|
|
|
},
|
2012-08-11 15:21:53 +02:00
|
|
|
onclick: function(e) {
|
2013-04-29 18:03:32 +02:00
|
|
|
}
|
2012-08-11 15:21:53 +02:00
|
|
|
});
|
|
|
|
|
2013-04-29 18:01:32 +02:00
|
|
|
$('.toggleSelectAll').entwine({
|
2012-09-05 20:36:05 +02:00
|
|
|
onmatch: function(){
|
|
|
|
},
|
|
|
|
onunmatch: function(){
|
|
|
|
},
|
|
|
|
onclick: function(){
|
|
|
|
var state = $(this).prop('checked');
|
2013-04-29 17:33:47 +02:00
|
|
|
$(this).parents('.ss-gridfield-table').find('td.col-bulkSelect input').each(function(){$(this).prop('checked', state);});
|
2012-09-05 20:36:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-29 18:01:32 +02:00
|
|
|
$('select.bulkActionName').entwine({
|
2012-08-11 15:21:53 +02:00
|
|
|
onmatch: function(){
|
|
|
|
},
|
|
|
|
onunmatch: function(){
|
|
|
|
},
|
|
|
|
onchange: function(e) {
|
|
|
|
var value, btn, icon;
|
|
|
|
value = $(this).val();
|
2013-04-29 18:01:32 +02:00
|
|
|
btn = $(this).parents('.bulkManagerOptions').find('.doBulkActionButton');
|
|
|
|
icon = $(this).parents('.bulkManagerOptions').find('.doBulkActionButton .ui-icon');
|
2012-08-11 15:21:53 +02:00
|
|
|
|
|
|
|
switch (value) {
|
2012-08-12 16:48:34 +02:00
|
|
|
case 'edit':
|
2012-08-11 15:21:53 +02:00
|
|
|
$(btn).removeClass('ss-ui-action-destructive');
|
|
|
|
$(btn).attr('data-icon', 'pencil');
|
|
|
|
$(icon).removeClass('btn-icon-decline btn-icon-pencil').addClass('btn-icon-pencil');
|
2012-08-16 22:29:35 +02:00
|
|
|
|
|
|
|
$(btn).attr('href', $(btn).data('url')+'/edit');
|
2012-08-11 15:21:53 +02:00
|
|
|
break;
|
|
|
|
|
2012-08-12 16:48:34 +02:00
|
|
|
case 'unlink':
|
2012-08-11 15:21:53 +02:00
|
|
|
$(btn).removeClass('ss-ui-action-destructive');
|
|
|
|
$(btn).attr('data-icon', 'chain--minus');
|
|
|
|
$(icon).removeClass('btn-icon-decline btn-icon-pencil').addClass('btn-icon-chain--minus');
|
2012-08-16 22:29:35 +02:00
|
|
|
$(btn).removeAttr('href');
|
2012-08-11 15:21:53 +02:00
|
|
|
break;
|
|
|
|
|
2012-08-12 16:48:34 +02:00
|
|
|
case 'delete':
|
2012-08-11 15:21:53 +02:00
|
|
|
$(btn).addClass('ss-ui-action-destructive');
|
|
|
|
$(btn).attr('data-icon', 'decline');
|
|
|
|
$(icon).removeClass('btn-icon-decline btn-icon-pencil').addClass('btn-icon-decline');
|
2012-08-16 22:29:35 +02:00
|
|
|
$(btn).removeAttr('href');
|
2012-08-11 15:21:53 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-08-11 00:19:13 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-12 16:48:34 +02:00
|
|
|
//@TODO prevent button click to call default url request
|
2013-04-29 18:01:32 +02:00
|
|
|
$('.doBulkActionButton').entwine({
|
2012-08-11 15:21:53 +02:00
|
|
|
onmatch: function(){
|
|
|
|
},
|
|
|
|
onunmatch: function(){
|
|
|
|
},
|
2012-08-16 22:29:35 +02:00
|
|
|
onmouseover: function(){
|
|
|
|
var action, ids = [];
|
2013-04-29 18:01:32 +02:00
|
|
|
action = $(this).parents('.bulkManagerOptions').find('select.bulkActionName').val();
|
2012-08-16 22:29:35 +02:00
|
|
|
if ( action == 'edit' )
|
|
|
|
{
|
2013-04-29 17:37:48 +02:00
|
|
|
$(this).parents('.ss-gridfield-table').find('td.col-bulkSelect input:checked').each(function(){
|
2012-08-16 22:29:35 +02:00
|
|
|
ids.push( parseInt( $(this).attr('name').split('_')[1] ) );
|
|
|
|
});
|
|
|
|
if(ids.length > 0) $(this).attr('href', $(this).data('url')+'/'+action+'?records[]='+ids.join('&records[]=') );
|
|
|
|
}
|
|
|
|
},
|
2012-08-11 15:21:53 +02:00
|
|
|
onclick: function(e) {
|
2012-08-12 16:48:34 +02:00
|
|
|
var action, url, data = {}, ids = [], cacheBuster;
|
2013-04-29 18:01:32 +02:00
|
|
|
action = $(this).parents('.bulkManagerOptions').find('select.bulkActionName').val();
|
2012-08-12 16:48:34 +02:00
|
|
|
|
2012-08-16 22:29:35 +02:00
|
|
|
if ( action != 'edit' )
|
|
|
|
{
|
|
|
|
url = $(this).data('url');
|
|
|
|
cacheBuster = new Date().getTime();
|
2012-09-06 17:36:07 +02:00
|
|
|
|
2013-04-29 17:37:48 +02:00
|
|
|
$(this).parents('.ss-gridfield-table').find('td.col-bulkSelect input:checked').each(function(){
|
2012-08-16 22:29:35 +02:00
|
|
|
ids.push( parseInt( $(this).attr('name').split('_')[1] ) );
|
|
|
|
});
|
|
|
|
data.records = ids;
|
|
|
|
|
2013-02-02 13:15:09 +01:00
|
|
|
if ( url.indexOf('?') !== -1 ) cacheBuster = '&cacheBuster=' + cacheBuster;
|
|
|
|
else cacheBuster = '?cacheBuster=' + cacheBuster;
|
|
|
|
|
2012-08-16 22:29:35 +02:00
|
|
|
$.ajax({
|
2013-02-02 13:15:09 +01:00
|
|
|
url: url + '/' + action + cacheBuster,
|
2012-08-16 22:29:35 +02:00
|
|
|
data: data,
|
|
|
|
type: "POST",
|
|
|
|
context: $(this)
|
|
|
|
}).done(function() {
|
2012-09-06 17:36:07 +02:00
|
|
|
$(this).parents('.ss-gridfield').entwine('.').entwine('ss').reload();
|
2012-08-16 22:29:35 +02:00
|
|
|
});
|
|
|
|
}
|
2012-08-12 16:48:34 +02:00
|
|
|
|
2012-08-11 15:21:53 +02:00
|
|
|
}
|
|
|
|
});
|
2013-04-29 18:03:32 +02:00
|
|
|
|
|
|
|
/* **************************************************************************************
|
|
|
|
* EDITING */
|
2012-08-11 15:21:53 +02:00
|
|
|
|
2012-08-26 22:59:25 +02:00
|
|
|
$('.bulkEditingFieldHolder').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
var id, name = 'bulkEditingForm';
|
|
|
|
id = $(this).attr('id').split('_')[3];
|
|
|
|
$(this).wrap('<form name="'+name+'_'+id+'" id="'+name+'_'+id+'" class="'+name+'"/>');
|
|
|
|
},
|
|
|
|
onunmatch: function(){
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.bulkEditingForm input, .bulkEditingForm select, .bulkEditingForm textarea').entwine({
|
|
|
|
onchange: function(){
|
|
|
|
var form;
|
|
|
|
|
|
|
|
form = this.parents('form.bulkEditingForm');
|
|
|
|
|
|
|
|
if ( !$(form).hasClass('hasUpdate') ) {
|
|
|
|
$(form).addClass('hasUpdate');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#bulkEditingUpdateBtn').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
$(this).data('completedForms', 0);
|
|
|
|
},
|
|
|
|
onunmatch: function(){
|
|
|
|
},
|
|
|
|
onclick: function(e){
|
|
|
|
var formsWithUpadtes, url, data, cacheBuster;
|
|
|
|
|
|
|
|
formsWithUpadtes = $('form.bulkEditingForm.hasUpdate');
|
|
|
|
$(this).data('formsToUpdate', $(formsWithUpadtes).length);
|
|
|
|
url = $(this).data('url');
|
|
|
|
|
|
|
|
if ( $(formsWithUpadtes).length > 0 ) $(this).addClass('loading');
|
2013-04-29 18:03:32 +02:00
|
|
|
|
2012-08-26 22:59:25 +02:00
|
|
|
$(formsWithUpadtes).each(function(){
|
|
|
|
cacheBuster = new Date().getTime() + '_' + $(this).attr('name');
|
|
|
|
data = $(this).serialize();
|
2013-02-02 13:15:09 +01:00
|
|
|
|
|
|
|
if ( url.indexOf('?') !== -1 ) cacheBuster = '&cacheBuster=' + cacheBuster;
|
|
|
|
else cacheBuster = '?cacheBuster=' + cacheBuster;
|
|
|
|
|
2012-08-26 22:59:25 +02:00
|
|
|
$.ajax({
|
2013-04-16 22:58:06 +02:00
|
|
|
url: url + '/' + cacheBuster,
|
2012-08-26 22:59:25 +02:00
|
|
|
data: data,
|
|
|
|
type: "POST",
|
|
|
|
context: $(this)
|
|
|
|
}).done(function() {
|
|
|
|
|
|
|
|
var btn = $('#bulkEditingUpdateBtn');
|
|
|
|
var totalForms = parseInt( $(btn).data('formsToUpdate') );
|
|
|
|
var counter = parseInt( $(btn).data('completedForms') );
|
|
|
|
counter = counter + 1;
|
|
|
|
$(btn).data('completedForms', counter);
|
|
|
|
|
|
|
|
$(this).removeClass('hasUpdate');
|
|
|
|
|
|
|
|
if ( counter == totalForms ) {
|
|
|
|
$('#bulkEditingUpdateBtn').data('completedForms', 0);
|
|
|
|
$('#bulkEditingUpdateBtn').removeClass('loading');
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-11 00:19:13 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}(jQuery));
|