var selectedRow = null; var columns = null; var primaryKeyColumn = 'id'; var rowData = null; function deleteRow(data) { var table = $('table'); var tableName = table[table.selectedIndex].value; hakano.util.MessageBroker.queue({type:'remote:seamless.'+tableName+'.delete.request',data:{id:getPrimaryKey(data)}}); selectedRow = null; hakano.util.MessageBroker.queue({type:'local:search.table.nonselected',data:{}}); } function updateFromDelete(data) { var id = data['id']; $$('#search_results_table td.primarykey').each(function(td) { var value = td.innerHTML; if (value == id) { var parent = td.parentNode; Effect.Fade(parent, { afterFinish: function() { var p = parent.parentNode; p.removeChild(parent); $('search_count').innerHTML = parseInt($('search_count').innerHTML) - 1; $('search_total').innerHTML = parseInt($('search_total').innerHTML) - 1; } }); throw $break; } }); } function getPrimaryKey() { var idx = selectedRow.getAttribute('idx'); var datarow = rowData[parseInt(idx)]; return datarow[primaryKeyColumn||'id'] || ''; } function loadModels (data) { var models = data['models']; if (models.length > 0) { $('table_name').innerHTML = models[0].name; loadTableAssembly(models[0].model); } } function loadTableAssembly (tableName) { var request = 'remote:seamless.'+tableName+'.assembly.request'; hakano.util.MessageBroker.queue({type:request,data:{}}); } function loadColumns (data) { columns = data['columns']; refreshData(); } function refreshData() { var table = $('table'); var tableName = table[table.selectedIndex].value; hakano.util.MessageBroker.queue({type:'remote:seamless.'+tableName+'.list.request',data:{limit:10}}); } function displayRecord(edit) { var html = ''; var table = $('table'); var tableName = table[table.selectedIndex].value; if (edit) { var req = 'remote:seamless.' + tableName + '.update.request'; var resp = 'remote:seamless.' + tableName + '.update.response'; html+='
'; html+=''; html+=''; } html += ""; var idx = selectedRow.getAttribute('idx'); var datarow = rowData[parseInt(idx)]; var activators = (edit ? [] : null); for (var c=0,len=columns.length;c'+name+''; } else { html+=''; continue; } var value = datarow[name]; if (!value || value == 'null') value = ''; if (edit) { html+='\n'; } html+='
'; var type = 'text'; if (columns[c].type == 'boolean') { type = 'checkbox'; } html+=''; } html+='
'; if (edit) { html+="
0) { html+="activators='" + activators.join(',') + "' "; } html+=' onClickMessage="remote:seamless.' + tableName+'.update.request" '; html+="/>
"; html+="
"; } $('search_results_table_container').innerHTML = html; Seamless.wire($('search_results_table_container'),window,false,true); } function restoreTable () { if (rowData) { loadTable({rows:rowData}); } } function loadTable (data) { try { var rows = data['rows']; if (!rows) return; var html = ""; rowData = rows; html+=''; for (var c=0,len=columns.length;c'; } else { break; } } html+=''; for (var c=0,len=rows.length;c'; columns.each(function(col,idx) { var className = columns[idx].primary ? 'primarykey' : ''; html+=''; if (idx >= 5) throw $break; }); html+=''; } html+='
' + ( rows[c][col.name] || '') + '
'; $('search_results_table_container').innerHTML = html; selectedRow = null; $$('#search_results_table tr').each(function(cell) { cell.onclick = function(e) { var idx = cell.getAttribute('idx'); var datarow = rows[parseInt(idx)]; if (selectedRow) { $A(selectedRow.childNodes).each(function(n) { Element.removeClassName(n,'selected'); }); hakano.util.MessageBroker.queue({type:'local:search.table.unselected',data:{datarow:datarow}}); } if (selectedRow == cell) { hakano.util.MessageBroker.queue({type:'local:search.table.nonselected',data:{}}); selectedRow = null; return; } selectedRow = cell; $A(selectedRow.childNodes).each(function(n) { Element.addClassName(n,'selected'); }); hakano.util.MessageBroker.queue({type:'local:search.table.selected',data:{datarow:datarow}}); }; }); } catch(e) { alert(e); } }