X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=public%2Fedit_table.js;h=5c8d00dbe7f9058378debdc55393ff31b01f2a1e;hb=019450645acad67df21e709c77dcc73703ceffec;hp=5fbdad931e54f0509d166517b14c4331b00d97ee;hpb=73a18a20de57f75f69cabe4d92685e860137aa04;p=MojoFacets.git
diff --git a/public/edit_table.js b/public/edit_table.js
index 5fbdad9..5c8d00d 100644
--- a/public/edit_table.js
+++ b/public/edit_table.js
@@ -2,17 +2,43 @@ $(document).ready( function() {
var cell_blur = function() {
console.debug( 'cell_blur'
- , this
- , $(this).val()
+// , this
+// , $(this).val()
);
- var content = $(this).val();
- if ( 0 ) { // leave delimiters in edited cells visible
- var vals = content.split('¶');
- content = vals.join('¶');
- }
- var cell = $('
'+content+' | ');
- $(this).replaceWith( cell );
- console.info( cell );
+
+/*
+ // FIXME primary key is fixed to 1st column
+ var pk = $('table tr th:nth(0) > a').text();
+ var id = $(this).parent().siblings(':nth(0)').text()
+*/
+ var _row_id = $(this).parent().parent().attr('title');
+
+ var x = $(this).parent().attr('cellIndex');
+ var y = $(this).parent().parent().attr('rowIndex');
+
+ var new_content = $(this).val();
+// $(this).replaceWith( new_content );
+
+ var name = $('table tr th:nth('+x+') > a').text();
+ console.info( x, y, _row_id, name, new_content );
+
+ var update = $(this);
+
+ $.post( '/data/edit', {
+ path: document.title, _row_id: _row_id,
+ name: name, new_content: new_content
+ } , function(data, textStatus) {
+ console.debug( 'data:', data, 'status:', textStatus );
+ if ( ! data ) {
+ data = new_content; // fallback to submited data for 304
+ } else {
+ if ( $('a.save_actions').length == 0 )
+ $('a.actions').before('save')
+ }
+ var vals = data.split('¶');
+ data = vals.join('¶');
+ update.replaceWith( data );
+ });
}
var cell_click = function(event) {
@@ -21,10 +47,14 @@ var cell_click = function(event) {
, event
, $(this).text()
);
- var content = $(this).text(); // we don't want para markup
- var rows = content.split('¶').length * 2 + 1;
+ var new_content = $(this).text() // we don't want para markup
+ .replace(/^[ \n\r]+/,'')
+ .replace(/[ \n\r]+$/,'')
+ ;
+console.debug( 'new_content', new_content );
+ var rows = new_content.split('¶').length * 2 + 1;
var textarea = $('');
- textarea.val( content );
+ textarea.val( new_content );
$(this).html( textarea );
textarea.focus();
textarea.blur( cell_blur )