Guest User

Untitled

a guest
Jun 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. $(document).ready(function () {
  2. var tree = $('#listagem_cadastro_menu').tree({
  3. primaryKey: 'id',
  4. uiLibrary: 'materialicons',
  5. iconsLibrary: 'materialicons',
  6. dataSource: '/Permissao/Get',
  7. params: { NivelID: @ViewBag.ID},
  8. checkboxes: true,
  9. icons: {
  10. expand: '<i class="material-icons">keyboard_arrow_right</i>',
  11. collapse: '<i class="material-icons">keyboard_arrow_right</i>',
  12. },
  13. });
  14.  
  15. tree.on('checkboxChange', function (e, $node, record, state) {
  16. // alert('record ' + JSON.stringify(record));
  17. //alert('node ' + JSON.stringify($node))
  18. //alert('state ' + JSON.stringify(e))
  19. //alert(record.checked);
  20. atualizaPermissao(record.id, record.checked);
  21.  
  22. });
  23.  
  24. function atualizaPermissao(MenuID, checked) {
  25. $.ajax({
  26. url: "/Permissao/SaveCheckedNode",
  27. data: { NivelID: @ViewBag.ID, MenuID: MenuID, checked: checked },
  28. dataType: "json",
  29. method: 'POST',
  30. }
  31. )
  32. .fail(function () {
  33. alert('Failed to save.');
  34. });
  35. }
  36. });
  37.  
  38. [HttpPost]
  39. public JsonResult SaveCheckedNode (int NivelID, int MenuID, bool @checked)
  40. {
  41.  
  42. if (@checked == true)
  43. {
  44. var Menus = db.MENUs.Find(MenuID);
  45. var Nivel = db.NIVELs.Find(NivelID);
  46.  
  47. Menus.NIVELs.Add(Nivel);
  48. db.Entry(Menus).State = System.Data.Entity.EntityState.Modified;
  49. db.SaveChanges();
  50. }
  51. else if (@checked == false)
  52. {
  53. var Menus = db.MENUs.Find(MenuID);
  54. var Nivel = db.NIVELs.Find(NivelID);
  55.  
  56. Menus.NIVELs.Remove(Nivel);
  57. db.Entry(Menus).State = System.Data.Entity.EntityState.Modified;
  58. db.SaveChanges();
  59. }
  60. return Json(@checked, JsonRequestBehavior.AllowGet);
  61. }
Add Comment
Please, Sign In to add comment