model.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. App.Ref.CONTENT.html('<center><h1 style="padding-top: 20px;font-size: 28px;">Under maintanance</h1></center>');
  21. }
  22. App.Model.DB.loadList = function()
  23. {
  24. App.Ajax.request('DB.getList', {}, function(reply)
  25. {
  26. var acc = [];
  27. var build_method = App.Env.getWorldName() + '_entry';
  28. var data = reply.data;
  29. // TODO: fix it data.data
  30. $.each(data, function(key)
  31. {
  32. var db_list = data[key];
  33. fb.warn('KEY: %o', key);
  34. fb.warn('DATA: %o', data[key]);
  35. var tpl_divider = App.Templates.get('DIVIDER', 'db');
  36. tpl_divider.set(':TYPE', key);
  37. acc[acc.length++] = tpl_divider.finalize();
  38. $(db_list).each(function(i, o)
  39. {
  40. acc[acc.length++] = App.HTML.Build[build_method](o, key);
  41. });
  42. /*var o = data[key];
  43. fb.warn(key);
  44. acc[acc.length++] = App.HTML.Build[build_method](o, key);*/
  45. });
  46. var html = acc.done().wrapperize('ENTRIES_WRAPPER', App.Env.getWorldName());
  47. App.Ref.CONTENT.html(html);
  48. App.Helpers.updateScreen();
  49. });
  50. }
  51. App.Model.CRON.loadList = function()
  52. {
  53. App.Ajax.request('CRON.getList', {}, App.View.listItems);
  54. }
  55. App.Model.add = function(values, source_json)
  56. {
  57. var method = App.Settings.getMethodName('add');
  58. App.Ajax.request(method, {
  59. spell: $.toJSON(values)
  60. }, function(reply){
  61. if(!reply.result) {
  62. App.Helpers.Warn('Changes were not applied');
  63. }
  64. else {
  65. var build_method = App.Env.getWorldName() + '_entry';
  66. var tpl = App.HTML.Build[build_method](values, 'new');
  67. App.Ref.CONTENT..replaceWith(tpl);
  68. // todo: reply.data;
  69. }
  70. });
  71. }
  72. App.Model.remove = function(world, elm)
  73. {
  74. var method = App.Settings.getMethodName('delete');
  75. App.Ajax.request(method,
  76. {
  77. spell: $('.source', elm).val()
  78. },
  79. function(reply)
  80. {
  81. if (!reply.result) {
  82. App.Helpers.Warn('Changes were not applied');
  83. }
  84. else {
  85. $(elm).remove();
  86. }
  87. });
  88. }
  89. App.Model.update = function(values, source_json, elm)
  90. {
  91. var method = App.Settings.getMethodName('update');
  92. var build_method = App.Env.getWorldName() + '_entry';
  93. App.Ajax.request(method, {
  94. 'old': source_json,
  95. 'new': App.Helpers.toJSON(values)
  96. }, function(reply){
  97. if(!reply.result) {
  98. var tpl = App.HTML.Build[build_method](App.Helpers.evalJSON(source_json));
  99. $(elm).replaceWith(tpl);
  100. App.Helpers.updateScreen();
  101. App.Helpers.Warn('Changes were not applied');
  102. }
  103. else {
  104. var tpl = App.HTML.Build[build_method](reply.data);
  105. $(elm).replaceWith(tpl);
  106. App.Helpers.updateScreen();
  107. }
  108. // TODO: !
  109. });
  110. }
  111. /*
  112. App.Model.IP.update = function(values, source_json) {
  113. App.Ajax.request('IP.update', {
  114. 'source': source_json,
  115. 'target': App.Helpers.toJSON(values)
  116. }, function(reply){
  117. if(!reply.result) {
  118. App.Pages.IP.ipNotSaved(reply);
  119. }
  120. });
  121. }
  122. App.Model.IP.add = function(values) {
  123. App.Ajax.request('IP.add', {
  124. 'target': App.Helpers.toJSON(values)
  125. }, function(reply){
  126. if(!reply.result) {
  127. App.Helpers.alert(reply.message)
  128. }
  129. });
  130. }
  131. App.Model.IP.remove = function(values_json, elm) {
  132. App.Ajax.request('IP.remove', {
  133. 'target': values_json
  134. }, function(reply){
  135. if(!reply.result) {
  136. App.Helpers.alert(reply.message);
  137. }
  138. else {
  139. elm.remove();
  140. }
  141. });
  142. }*/