2014-05-03 17:33:57 +02:00
|
|
|
(function($) {
|
|
|
|
$.entwine('colymba', function($) {
|
2014-05-01 23:03:43 +02:00
|
|
|
|
2014-05-04 13:34:31 +02:00
|
|
|
/**
|
|
|
|
* Toggle all accordion forms
|
|
|
|
* open or closed
|
|
|
|
*/
|
2014-05-03 17:33:57 +02:00
|
|
|
$('#bulkEditToggle') .entwine({
|
|
|
|
onmatch: function(){},
|
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function(e)
|
|
|
|
{
|
2014-05-04 15:48:28 +02:00
|
|
|
var toggleFields = this.parents('#Form_BulkEditingForm').find('.ss-toggle .ui-accordion-header'),
|
2014-05-04 13:34:31 +02:00
|
|
|
state = this.data('state')
|
2014-05-03 17:33:57 +02:00
|
|
|
;
|
2014-05-01 23:03:43 +02:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
if ( !state || state === 'close' )
|
|
|
|
{
|
|
|
|
state = 'open';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
state = 'close';
|
|
|
|
}
|
2014-05-01 23:03:43 +02:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
toggleFields.each(function()
|
|
|
|
{
|
|
|
|
var $this = $(this);
|
|
|
|
|
|
|
|
if ( state === 'open' && !$this.hasClass('ui-state-active') )
|
|
|
|
{
|
|
|
|
$this.click();
|
|
|
|
}
|
2014-05-01 23:03:43 +02:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
if ( state === 'close' && $this.hasClass('ui-state-active') )
|
|
|
|
{
|
|
|
|
$this.click();
|
|
|
|
}
|
|
|
|
});
|
2014-05-01 23:03:43 +02:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
this.data('state', state);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-05-04 13:34:31 +02:00
|
|
|
/**
|
|
|
|
* Contains each rocrds editing fields,
|
|
|
|
* tracks changes and updates...
|
|
|
|
*/
|
2014-05-03 17:33:57 +02:00
|
|
|
$('.bulkEditingFieldHolder').entwine({
|
2014-05-04 13:34:31 +02:00
|
|
|
onmatch: function(){},
|
|
|
|
onunmatch: function(){},
|
2014-05-03 17:33:57 +02:00
|
|
|
onchange: function(){
|
|
|
|
this.removeClass('updated');
|
|
|
|
if ( !this.hasClass('hasUpdate') )
|
|
|
|
{
|
|
|
|
this.addClass('hasUpdate');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-04 13:34:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save all button
|
|
|
|
* process all field holders with updates
|
|
|
|
*/
|
2014-05-03 17:33:57 +02:00
|
|
|
$('#bulkEditingUpdateBtn').entwine({
|
|
|
|
onmatch: function(){},
|
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function(e){
|
|
|
|
e.stopImmediatePropagation();
|
2013-12-05 16:48:01 +01:00
|
|
|
|
2014-05-04 13:34:31 +02:00
|
|
|
var $fieldHolders = $('div.bulkEditingFieldHolder.hasUpdate'),
|
2014-05-03 17:33:57 +02:00
|
|
|
url = this.data('url'),
|
|
|
|
data = {},
|
|
|
|
cacheBuster = new Date().getTime() + '_' + this.attr('name')
|
|
|
|
;
|
|
|
|
|
2014-05-04 13:34:31 +02:00
|
|
|
if ( $fieldHolders.length > 0 )
|
2014-05-03 17:33:57 +02:00
|
|
|
{
|
|
|
|
this.addClass('loading');
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return;
|
|
|
|
}
|
2013-12-05 17:29:47 +01:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
if ( url.indexOf('?') !== -1 )
|
|
|
|
{
|
|
|
|
cacheBuster = '&cacheBuster=' + cacheBuster;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
cacheBuster = '?cacheBuster=' + cacheBuster;
|
|
|
|
}
|
2013-12-05 17:29:47 +01:00
|
|
|
|
2014-05-04 13:34:31 +02:00
|
|
|
$fieldHolders.each(function(){
|
2014-05-03 17:33:57 +02:00
|
|
|
var $this = $(this);
|
|
|
|
data[$this.data('id')] = $this.find(':input').serializeArray();
|
|
|
|
});
|
2013-12-05 17:29:47 +01:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
$.ajax({
|
|
|
|
url: url + cacheBuster,
|
|
|
|
data: data,
|
|
|
|
type: "POST",
|
|
|
|
context: this
|
|
|
|
}).success(function(data, textStatus, jqXHR){
|
|
|
|
try{
|
|
|
|
data = $.parseJSON(data);
|
|
|
|
}catch(er){}
|
2013-12-05 16:48:01 +01:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
$.each(data.records, function(index, record){
|
2014-05-04 13:34:31 +02:00
|
|
|
var $fieldHolder = $('#Form_BulkEditingForm_RecordFields_'+record.id),
|
|
|
|
$header = $fieldHolder.find('.ui-accordion-header')
|
2014-05-03 17:33:57 +02:00
|
|
|
;
|
|
|
|
|
2014-05-04 13:34:31 +02:00
|
|
|
$fieldHolder.removeClass('hasUpdate').addClass('updated');
|
|
|
|
$header.find('a').html(record.title);
|
2014-05-04 15:48:28 +02:00
|
|
|
if ( $header.hasClass('ui-state-active') )
|
|
|
|
{
|
|
|
|
$header.click();
|
|
|
|
}
|
2014-05-03 17:33:57 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.removeClass('loading');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2013-12-05 16:48:01 +01:00
|
|
|
}(jQuery));
|