model.js 4.4 KB

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