1 $(document).ready( function() {
3 var cell_blur = function() {
4 console.debug( 'cell_blur'
10 // FIXME primary key is fixed to 1st column
11 var pk = $('table tr th:nth(0) > a').text();
12 var id = $(this).parent().siblings(':nth(0)').text()
14 var _row_id = $(this).parent().parent().attr('title');
16 var x = $(this).parent().index();
17 var y = $(this).parent().parent().index();
20 console.error('no x ', x, ' or y ', y, ' defined');
24 var new_content = $(this).val();
25 // $(this).replaceWith( new_content );
27 var name = $('table tr th:nth('+x+') > a').text();
28 console.info( x, y, _row_id, name, new_content );
32 $.post( '/data/edit', {
33 path: document.title, _row_id: _row_id,
34 name: name, new_content: new_content
35 } , function(data, textStatus) {
36 console.debug( 'data:', data, 'status:', textStatus );
38 data = new_content; // fallback to submited data for 304
40 $('span.save_actions').show();
42 var vals = data.split('¶');
43 data = vals.join('<span class=d>¶</span>');
44 update.replaceWith( data );
48 var cell_click = function(event) {
49 console.debug( 'cell_click'
55 if ( $(this).find('textarea').length ) return; // allready editing
57 var new_content = $(this).text() // we don't want para markup
58 .replace(/^[ \n\r]+/,'')
59 .replace(/[ \n\r]+$/,'')
61 console.debug( 'new_content', new_content );
62 var rows = new_content.split('¶').length * 2 + 1;
63 var textarea = $('<textarea rows='+rows+'/>');
64 textarea.val( new_content );
65 $(this).html( textarea );
67 textarea.blur( cell_blur )
71 console.info('double-click on cell to edit it');
72 $('table td').live( 'dblclick', cell_click );