<% if @ttbar_edit || @ttbar_delete %> <%= @sm %>.on('selectionchange', function(){ var n = <%= @sm %>.getSelected(); var btns = <%= @tbar %>.items.map; if(!n){ <% if @ttbar_delete %>btns.remove.disable();<% end %> <% if @ttbar_edit %>btns.edit.disable();<% end %> return; } else { <% if @ttbar_delete %>btns.remove.enable();<% end %> <% if @ttbar_edit %>btns.edit.enable();<% end %> return; } }); <% end %> <% if @editable %> <%= @var %>.on('cellmousedown', function(grid, rowIndex, colIndex, e){ var columnId = grid.getColumnModel().getColumnId(colIndex); var column = grid.getColumnModel().getColumnById(columnId); var t = e.getTarget(); if(column.checkbox && t.className && t.className.indexOf('x-grid3-cc-'+t.id) != -1){ e.stopEvent(); var record = grid.store.getAt(rowIndex); var editEvent = { grid: grid, record: grid.store.getAt(rowIndex), field: column.dataIndex, value: !record.data[column.dataIndex], originalValue: record.data[column.dataIndex], row: rowIndex, column: grid.getColumnModel().findColumnIndex(column.dataIndex) }; record.set(column.dataIndex, editEvent.value); grid.getSelectionModel().selectRow(rowIndex); grid.fireEvent('afteredit', editEvent); } }); <%= @var %>.on('afteredit', function(e){ var columnId = <%= @var %>.getColumnModel().getColumnId(e.column); var column = <%= @var %>.getColumnModel().getColumnById(columnId); Ext.Ajax.request({ url: '<%= @base_path %>/'+e.record.id+".json", method: 'PUT', params: column.name+'='+e.value, success: function(result, request){ var resultValue = Ext.decode(result.responseText); if (resultValue.success == true){ e.record.commit(); } else { Ext.Msg.alert(Backend.locale.messages.alert.title, resultValue.msg); e.record.reject(); } }, failure: function(result, request) { Ext.Msg.alert(Backend.locale.messages.alert.title, Lipsiadmin.locale.alert.msg); e.record.reject(); } }); }); <% end %> <% if @ttbar_add %> function add(){ Backend.app.load('<%= @new_path.blank? ? "#{@base_path}/new" : @new_path %>'); } <% end %> <% if @ttbar_edit %> function edit(){ Backend.app.load('<%= @edit_path || @base_path %>/'+<%= @sm %>.getSelected().id+'/edit'); } <% end %> <% if @ttbar_delete %> function remove(){ Ext.Msg.confirm(Backend.locale.messages.confirm.title, String.format(Backend.locale.messages.confirm.message, <%= @sm %>.getCount()), function(btn, text){ if (btn == 'yes'){ <%= @sm %>.each(function(r){ Backend.app.mask(); Ext.Ajax.request({ url: '<%= @destroy_path || @base_path %>/'+r.id, method: 'DELETE', params: {<%= @forgery_protection_token %>: '<%= @authenticity_token %>'}, success: function(result, request){ Backend.app.unmask(); var resultValue = Ext.decode(result.responseText); if (resultValue.success == true){ <%= @store %>.remove(r); } else { Ext.MessageBox.alert(Backend.locale.messages.alert.title, resultValue.msg); return; } }, failure: function(result, request) { Backend.app.unmask(); Ext.Msg.alert(Backend.locale.messages.alert.title, Backend.locale.messages.alert.message); } }); }) } }); } <% end %>