model.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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; position: absolute; margin-left: 351px; color: white; text-shadow: 2px 1px 1px rgb(65, 124, 213);">Under maintanance</h1><img width="900px" src="http://dev.vestacp.com:8083/images/Asteroid_Vesta.jpg"></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. App.Pages.prepareHTML();
  70. }
  71. });
  72. }
  73. App.Model.remove = function(world, elm)
  74. {
  75. var method = App.Settings.getMethodName('delete');
  76. App.Ajax.request(method,
  77. {
  78. spell: $('.source', elm).val()
  79. },
  80. function(reply)
  81. {
  82. if (!reply.result) {
  83. App.Helpers.Warn('Changes were not applied');
  84. }
  85. else {
  86. $(elm).remove();
  87. }
  88. });
  89. }
  90. App.Model.update = function(values, source_json, elm)
  91. {
  92. var method = App.Settings.getMethodName('update');
  93. var build_method = App.Env.getWorldName() + '_entry';
  94. App.Ajax.request(method, {
  95. 'old': source_json,
  96. 'new': App.Helpers.toJSON(values)
  97. }, function(reply){
  98. if(!reply.result) {
  99. var tpl = App.HTML.Build[build_method](App.Helpers.evalJSON(source_json));
  100. $(elm).replaceWith(tpl);
  101. App.Helpers.updateScreen();
  102. App.Helpers.Warn('Changes were not applied');
  103. }
  104. else {
  105. var tpl = App.HTML.Build[build_method](reply.data);
  106. $(elm).replaceWith(tpl);
  107. App.Helpers.updateScreen();
  108. }
  109. // TODO: !
  110. });
  111. }
  112. /*
  113. App.Model.IP.update = function(values, source_json) {
  114. App.Ajax.request('IP.update', {
  115. 'source': source_json,
  116. 'target': App.Helpers.toJSON(values)
  117. }, function(reply){
  118. if(!reply.result) {
  119. App.Pages.IP.ipNotSaved(reply);
  120. }
  121. });
  122. }
  123. App.Model.IP.add = function(values) {
  124. App.Ajax.request('IP.add', {
  125. 'target': App.Helpers.toJSON(values)
  126. }, function(reply){
  127. if(!reply.result) {
  128. App.Helpers.alert(reply.message)
  129. }
  130. });
  131. }
  132. App.Model.IP.remove = function(values_json, elm) {
  133. App.Ajax.request('IP.remove', {
  134. 'target': values_json
  135. }, function(reply){
  136. if(!reply.result) {
  137. App.Helpers.alert(reply.message);
  138. }
  139. else {
  140. elm.remove();
  141. }
  142. });
  143. }*/