2014-05-03 17:33:57 +02:00
|
|
|
(function($) {
|
|
|
|
$.entwine('colymba', function($) {
|
2014-05-01 23:03:43 +02:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
$('#bulkEditToggle') .entwine({
|
|
|
|
onmatch: function(){},
|
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function(e)
|
|
|
|
{
|
|
|
|
var toggleFields = $(this).parents('#Form_bulkEditingForm').find('.ss-toggle h4'),
|
|
|
|
state = this.data('state')
|
|
|
|
;
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('.bulkEditingFieldHolder').entwine({
|
|
|
|
onmatch: function(){
|
|
|
|
var id = this.attr('id').split('_')[3],
|
|
|
|
name = 'bulkEditingForm',
|
|
|
|
$wrap = $('<div/>')
|
|
|
|
;
|
2013-12-05 16:48:01 +01:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
$wrap.attr('id', name + '_' + id).addClass(name).data('id', id);
|
|
|
|
this.wrap($wrap);
|
|
|
|
},
|
|
|
|
onunmatch: function(){}
|
|
|
|
});
|
2013-12-05 17:29:47 +01:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
$('.bulkEditingForm').entwine({
|
|
|
|
onchange: function(){
|
|
|
|
this.removeClass('updated');
|
|
|
|
if ( !this.hasClass('hasUpdate') )
|
|
|
|
{
|
|
|
|
this.addClass('hasUpdate');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#bulkEditingUpdateBtn').entwine({
|
|
|
|
onmatch: function(){},
|
|
|
|
onunmatch: function(){},
|
|
|
|
onclick: function(e){
|
|
|
|
e.stopImmediatePropagation();
|
2013-12-05 16:48:01 +01:00
|
|
|
|
2014-05-03 17:33:57 +02:00
|
|
|
var $formsWithUpadtes = $('div.bulkEditingForm.hasUpdate'),
|
|
|
|
url = this.data('url'),
|
|
|
|
data = {},
|
|
|
|
cacheBuster = new Date().getTime() + '_' + this.attr('name')
|
|
|
|
;
|
|
|
|
|
|
|
|
if ( $formsWithUpadtes.length > 0 )
|
|
|
|
{
|
|
|
|
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-03 17:33:57 +02:00
|
|
|
$formsWithUpadtes.each(function(){
|
|
|
|
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){
|
|
|
|
var $form = $('#bulkEditingForm_'+record.id)
|
|
|
|
$formHeader = $form.find('.ui-accordion-header')
|
|
|
|
;
|
|
|
|
|
|
|
|
$form.removeClass('hasUpdate').addClass('updated');
|
|
|
|
$formHeader.find('a').html(record.title);
|
|
|
|
$formHeader.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.removeClass('loading');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2013-12-05 16:48:01 +01:00
|
|
|
}(jQuery));
|