:javascript $(document).ready(function() { $.jgrid.no_legacy_api = true; $('##{name}_table').jqGrid(#{options.to_json}); $('##{name}_table').jqGrid('navGrid',"##{name}_pager", #{nav.to_json}); }); - if actions - if actions[:destroy] :javascript $(document).ready(function() { $("##{name}_table").jqGrid('navButtonAdd',"##{name}_pager", { caption: "", position: "first", buttonicon: "ui-icon-trash", onClickButton: function() { var rowId = $("##{name}_table").jqGrid('getGridParam', "selrow"); if(rowId == null) { alert("You must first select a row."); } else { var sure = confirm("Are you sure?") if(sure) { $.ajax({url: "#{url}/"+rowId, type: "DELETE", data: {authenticity_token: "#{form_authenticity_token}"}, success: function() { $("##{name}_table").trigger("reloadGrid"); } }); } } } }); }); - if actions[:update] :javascript $(document).ready(function() { $("##{name}_table").jqGrid('navButtonAdd',"##{name}_pager", { caption: "", position: "first", buttonicon: "ui-icon-pencil", onClickButton: function() { var rowId = $("##{name}_table").jqGrid('getGridParam', "selrow") if(rowId == null) { alert("You must first select a row."); } else { $.ajax({method: "GET", url: "#{url}#{actions[:update]}/"+rowId, success: function(data, status) { var dWidth = $(data).css("width"); var dHeight = $(data).css("height"); $("##{name}_update_dialog").append(data) $("#widget_submit").hide(); // HACK: easy way to make submit on enter work $("##{name}_update_dialog").find("form").submit(function() { $(this).ajaxSubmit({ url: "#{url}/"+rowId, type: "PUT", success: function(response, status) { if(!$(response).is("form")) { $("##{name}_update_dialog").dialog('close'); $("##{name}_table").trigger("reloadGrid"); } else { $("##{name}_update_dialog").find("form").replaceWith(response); } } }); return false; }); $("##{name}_update_dialog").dialog({ buttons: { "Save": function() {$(this).find("form").submit();}, "Cancel": function() {$(this).dialog('close');} }, title: "Edit", //width: dWidth, //height: dHeight, modal: true, draggable: false, //resizable: false, close: function() { $(this).dialog('destroy'); $("##{name}_update_dialog").children().remove(); $("##{name}_table").trigger("reloadGrid"); } }); } }); } } }); }); - if actions[:create] :javascript $(document).ready(function() { $("##{name}_table").jqGrid('navButtonAdd',"##{name}_pager", { caption: "", position: "first", buttonicon: "ui-icon-plus", onClickButton: function() { $.ajax({method: "GET", url: "#{url}#{actions[:create]}", success: function(data, status) { var dWidth = $(data).css("width"); var dHeight = $(data).css("height"); $("##{name}_create_dialog").append(data); $("#widget_submit").hide(); // HACK: easy way to make submit on enter work $("##{name}_create_dialog").find("form").submit(function() { $(this).ajaxSubmit({ url: $(this).attr("action"), data: $(this).serialize(), type: "POST", success: function(response, status) { if(!$(response).is("form")) { $("##{name}_create_dialog").dialog('close'); $("##{name}_table").trigger("reloadGrid"); } else { $("##{name}_create_dialog").find("form").replaceWith(response); } } }); return false; }); $("##{name}_create_dialog").dialog({ buttons: { "Save": function() {$(this).find("form").submit();}, "Cancel": function() {$(this).dialog('close');} }, title: "New", //width: dWidth, //height: dHeight, modal: true, draggable: false, //resizable: false, close: function() { $(this).dialog('destroy'); $("##{name}_create_dialog").children().remove(); $("##{name}_table").trigger("reloadGrid"); } }); } }); } }); });