| 1 |
(function($) { |
| 2 |
inlineEditUsergroup = { |
| 3 |
|
| 4 |
init : function() { |
| 5 |
var t = this, row = $('#inline-edit'); |
| 6 |
|
| 7 |
t.what = '#usergroup-'; |
| 8 |
|
| 9 |
$('.editinline').live('click', function(){ |
| 10 |
inlineEditUsergroup.edit(this); |
| 11 |
return false; |
| 12 |
}); |
| 13 |
|
| 14 |
// prepare the edit row |
| 15 |
row.keyup(function(e) { if(e.which == 27) return inlineEditUsergroup.revert(); }); |
| 16 |
|
| 17 |
$('a.cancel', row).click(function() { return inlineEditUsergroup.revert(); }); |
| 18 |
$('a.save', row).click(function() { return inlineEditUsergroup.save(this); }); |
| 19 |
$('input, select', row).keydown(function(e) { if(e.which == 13) return inlineEditUsergroup.save(this); }); |
| 20 |
|
| 21 |
$('#posts-filter input[type="submit"]').mousedown(function(e){ |
| 22 |
t.revert(); |
| 23 |
}); |
| 24 |
}, |
| 25 |
|
| 26 |
toggle : function(el) { |
| 27 |
var t = this; |
| 28 |
$(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el); |
| 29 |
}, |
| 30 |
|
| 31 |
edit : function(id) { |
| 32 |
var t = this, editRow; |
| 33 |
t.revert(); |
| 34 |
|
| 35 |
if ( typeof(id) == 'object' ) |
| 36 |
id = t.getId(id); |
| 37 |
|
| 38 |
editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id); |
| 39 |
$('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length); |
| 40 |
|
| 41 |
if ( $(t.what+id).hasClass('alternate') ) |
| 42 |
$(editRow).addClass('alternate'); |
| 43 |
|
| 44 |
$(t.what+id).hide().after(editRow); |
| 45 |
|
| 46 |
$(':input[name="name"]', editRow).val( $('.name', rowData).text() ); |
| 47 |
$(':input[name="description"]', editRow).val( $('.description', rowData).text() ); |
| 48 |
|
| 49 |
$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); |
| 50 |
$('.ptitle', editRow).eq(0).focus(); |
| 51 |
|
| 52 |
return false; |
| 53 |
}, |
| 54 |
|
| 55 |
save : function(id) { |
| 56 |
var params, fields, tax = $('input[name="taxonomy"]').val() || ''; |
| 57 |
|
| 58 |
if( typeof(id) == 'object' ) |
| 59 |
id = this.getId(id); |
| 60 |
|
| 61 |
$('table.widefat .inline-edit-save .waiting').show(); |
| 62 |
|
| 63 |
params = { |
| 64 |
action: 'inline_save_usergroup', |
| 65 |
usergroup_id: id, |
| 66 |
}; |
| 67 |
|
| 68 |
fields = $('#edit-'+id+' :input').serialize(); |
| 69 |
params = fields + '&' + $.param(params); |
| 70 |
|
| 71 |
|
| 72 |
// make ajax request |
| 73 |
$.post(ajaxurl, params, |
| 74 |
function(r) { |
| 75 |
var row, new_id; |
| 76 |
$('table.widefat .inline-edit-save .waiting').hide(); |
| 77 |
|
| 78 |
if (r) { |
| 79 |
if ( -1 != r.indexOf('<tr') ) { |
| 80 |
$(inlineEditUsergroup.what+id).remove(); |
| 81 |
new_id = $(r).attr('id'); |
| 82 |
|
| 83 |
$('#edit-'+id).before(r).remove(); |
| 84 |
row = new_id ? $('#'+new_id) : $(inlineEditUsergroup.what+id); |
| 85 |
row.hide().fadeIn(); |
| 86 |
} else |
| 87 |
$('#edit-'+id+' .inline-edit-save .error').html(r).show(); |
| 88 |
} else |
| 89 |
$('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show(); |
| 90 |
} |
| 91 |
); |
| 92 |
return false; |
| 93 |
}, |
| 94 |
|
| 95 |
revert : function() { |
| 96 |
var id = $('table.widefat tr.inline-editor').attr('id'); |
| 97 |
|
| 98 |
if ( id ) { |
| 99 |
$('table.widefat .inline-edit-save .waiting').hide(); |
| 100 |
$('#'+id).remove(); |
| 101 |
id = id.substr( id.lastIndexOf('-') + 1 ); |
| 102 |
$(this.what+id).show(); |
| 103 |
} |
| 104 |
|
| 105 |
return false; |
| 106 |
}, |
| 107 |
|
| 108 |
getId : function(o) { |
| 109 |
var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-'); |
| 110 |
return parts[parts.length - 1]; |
| 111 |
} |
| 112 |
}; |
| 113 |
|
| 114 |
$(document).ready(function(){inlineEditUsergroup.init();}); |
| 115 |
})(jQuery); |