model.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 ' + App.Helpers.toJSON(reply.errors) );
  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. App.Helpers.updateScreen();
  71. }
  72. });
  73. }
  74. App.Model.remove = function(world, elm)
  75. {
  76. var method = App.Settings.getMethodName('delete');
  77. App.Ajax.request(method,
  78. {
  79. spell: $('.source', elm).val()
  80. },
  81. function(reply)
  82. {
  83. if (!reply.result) {
  84. App.Helpers.Warn('Changes were not applied');
  85. }
  86. else {
  87. $(elm).remove();
  88. }
  89. });
  90. }
  91. App.Model.update = function(values, source_json, elm)
  92. {
  93. var method = App.Settings.getMethodName('update');
  94. var build_method = App.Env.getWorldName() + '_entry';
  95. App.Ajax.request(method, {
  96. 'old': source_json,
  97. 'new': App.Helpers.toJSON(values)
  98. }, function(reply){
  99. if(!reply.result) {
  100. var tpl = App.HTML.Build[build_method](App.Helpers.evalJSON(source_json));
  101. $(elm).replaceWith(tpl);
  102. App.Helpers.updateScreen();
  103. App.Helpers.Warn('Changes were not applied');
  104. }
  105. else {
  106. /*var tpl = App.HTML.Build[build_method](reply.data);
  107. $(elm).replaceWith(tpl);
  108. App.Helpers.updateScreen();*/
  109. // todo: reply.data;
  110. App.Pages.prepareHTML();
  111. App.Helpers.updateScreen();
  112. }
  113. // TODO: !
  114. });
  115. }
  116. /*
  117. App.Model.IP.update = function(values, source_json) {
  118. App.Ajax.request('IP.update', {
  119. 'source': source_json,
  120. 'target': App.Helpers.toJSON(values)
  121. }, function(reply){
  122. if(!reply.result) {
  123. App.Pages.IP.ipNotSaved(reply);
  124. }
  125. });
  126. }
  127. App.Model.IP.add = function(values) {
  128. App.Ajax.request('IP.add', {
  129. 'target': App.Helpers.toJSON(values)
  130. }, function(reply){
  131. if(!reply.result) {
  132. App.Helpers.alert(reply.message)
  133. }
  134. });
  135. }
  136. App.Model.IP.remove = function(values_json, elm) {
  137. App.Ajax.request('IP.remove', {
  138. 'target': values_json
  139. }, function(reply){
  140. if(!reply.result) {
  141. App.Helpers.alert(reply.message);
  142. }
  143. else {
  144. elm.remove();
  145. }
  146. });
  147. }*/