model.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. App.Model.DNS.loadList = function()
  2. {
  3. App.Ajax.request('DNS.getList', {}, App.View.listItems);
  4. }
  5. App.Model.IP.loadList = function()
  6. {
  7. App.Ajax.request('IP.getList', {}, App.View.listItems);
  8. }
  9. App.Model.USER.loadList = function()
  10. {
  11. App.Ajax.request('USER.getList', {}, App.View.listItems);
  12. }
  13. App.Model.WEB_DOMAIN.loadList = function()
  14. {
  15. App.Ajax.request('WEB_DOMAIN.getList', {}, App.View.listItems);
  16. }
  17. App.Model.MAIL.loadList = function()
  18. {
  19. App.Ajax.request('MAIL.getList', {}, App.View.listItems);
  20. }
  21. App.Model.DB.loadList = function()
  22. {
  23. App.Ajax.request('DB.getList', {}, App.View.listItems);
  24. }
  25. App.Model.CRON.loadList = function()
  26. {
  27. App.Ajax.request('CRON.getList', {}, App.View.listItems);
  28. }
  29. App.Model.add = function(values, source_json)
  30. {
  31. var method = App.Settings.getMethodName('add');
  32. App.Ajax.request(method, {
  33. spell: $.toJSON(values)
  34. }, function(reply){
  35. if(!reply.result) {
  36. App.Helpers.Warn('Changes were not applied');
  37. }
  38. else {
  39. var build_method = App.Env.getWorldName() + '_entry';
  40. var tpl = App.HTML.Build[build_method](values, 'new');
  41. App.Ref.CONTENT..replaceWith(tpl);
  42. // todo: reply.data;
  43. }
  44. });
  45. }
  46. App.Model.remove = function(world, elm)
  47. {
  48. var method = App.Settings.getMethodName('delete');
  49. App.Ajax.request(method,
  50. {
  51. spell: $('.source', elm).val()
  52. },
  53. function(reply)
  54. {
  55. if (!reply.result) {
  56. App.Helpers.Warn('Changes were not applied');
  57. }
  58. else {
  59. $(elm).remove();
  60. }
  61. });
  62. }
  63. App.Model.update = function(values, source_json, elm)
  64. { alert(source_json);
  65. var method = App.Settings.getMethodName('update');
  66. var build_method = App.Env.getWorldName() + '_entry';
  67. App.Ajax.request(method, {
  68. 'old': source_json,
  69. 'new': App.Helpers.toJSON(values)
  70. }, function(reply){
  71. if(!reply.result) {
  72. var tpl = App.HTML.Build[build_method](App.Helpers.evalJSON(source_json));
  73. $(elm).replaceWith(tpl);
  74. App.Helpers.updateScreen();
  75. App.Helpers.Warn('Changes were not applied');
  76. }
  77. else {
  78. var tpl = App.HTML.Build[build_method](reply.data);
  79. $(elm).replaceWith(tpl);
  80. App.Helpers.updateScreen();
  81. }
  82. // TODO: !
  83. });
  84. }
  85. /*
  86. App.Model.IP.update = function(values, source_json) {
  87. App.Ajax.request('IP.update', {
  88. 'source': source_json,
  89. 'target': App.Helpers.toJSON(values)
  90. }, function(reply){
  91. if(!reply.result) {
  92. App.Pages.IP.ipNotSaved(reply);
  93. }
  94. });
  95. }
  96. App.Model.IP.add = function(values) {
  97. App.Ajax.request('IP.add', {
  98. 'target': App.Helpers.toJSON(values)
  99. }, function(reply){
  100. if(!reply.result) {
  101. App.Helpers.alert(reply.message)
  102. }
  103. });
  104. }
  105. App.Model.IP.remove = function(values_json, elm) {
  106. App.Ajax.request('IP.remove', {
  107. 'target': values_json
  108. }, function(reply){
  109. if(!reply.result) {
  110. App.Helpers.alert(reply.message);
  111. }
  112. else {
  113. elm.remove();
  114. }
  115. });
  116. }*/