model.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. /*var build_method = App.Env.getWorldName() + '_entry';
  83. var tpl = App.HTML.Build[build_method](values, 'new');
  84. App.Ref.CONTENT..replaceWith(tpl);*/
  85. // todo: reply.data;
  86. App.Pages.prepareHTML();
  87. App.Helpers.updateScreen();
  88. }
  89. });
  90. }
  91. App.Model.remove = function(world, elm)
  92. {
  93. var method = App.Settings.getMethodName('delete');
  94. App.Ajax.request(method,
  95. {
  96. spell: $('.source', elm).val()
  97. },
  98. function(reply)
  99. {
  100. if (!reply.result) {
  101. App.Helpers.Warn('Changes were not applied');
  102. }
  103. else {
  104. $(elm).remove();
  105. }
  106. });
  107. }
  108. App.Model.update = function(values, source_json, elm)
  109. {
  110. var method = App.Settings.getMethodName('update');
  111. var build_method = App.Env.getWorldName() + '_entry';
  112. App.Ajax.request(method, {
  113. 'old': source_json,
  114. 'new': App.Helpers.toJSON(values)
  115. }, function(reply){
  116. if(!reply.result) {
  117. var tpl = App.HTML.Build[build_method](App.Helpers.evalJSON(source_json));
  118. $(elm).replaceWith(tpl);
  119. App.Helpers.updateScreen();
  120. App.Helpers.Warn('Changes were not applied');
  121. }
  122. else {
  123. /*var tpl = App.HTML.Build[build_method](reply.data);
  124. $(elm).replaceWith(tpl);
  125. App.Helpers.updateScreen();*/
  126. // todo: reply.data;
  127. App.Pages.prepareHTML();
  128. App.Helpers.updateScreen();
  129. /*var refl = {'USER': 'LOGIN_NAME'};
  130. App.Model[App.Env.world].loadList(function(reply) {
  131. var acc = [];
  132. var build_method = App.Env.getWorldName() + '_entry';
  133. var data = reply.data;
  134. // TODO: fix it data.data
  135. $.each(data, function(key)
  136. {
  137. var o = data[key];
  138. fb.warn(key);
  139. acc[acc.length++] = App.HTML.Build[build_method](o, key);
  140. });
  141. var html = acc.done().wrapperize('ENTRIES_WRAPPER', App.Env.getWorldName());
  142. App.Ref.CONTENT.html(html);
  143. App.Helpers.updateScreen();
  144. );*/
  145. }
  146. // TODO: !
  147. });
  148. }
  149. /*
  150. App.Model.IP.update = function(values, source_json) {
  151. App.Ajax.request('IP.update', {
  152. 'source': source_json,
  153. 'target': App.Helpers.toJSON(values)
  154. }, function(reply){
  155. if(!reply.result) {
  156. App.Pages.IP.ipNotSaved(reply);
  157. }
  158. });
  159. }
  160. App.Model.IP.add = function(values) {
  161. App.Ajax.request('IP.add', {
  162. 'target': App.Helpers.toJSON(values)
  163. }, function(reply){
  164. if(!reply.result) {
  165. App.Helpers.alert(reply.message)
  166. }
  167. });
  168. }
  169. App.Model.IP.remove = function(values_json, elm) {
  170. App.Ajax.request('IP.remove', {
  171. 'target': values_json
  172. }, function(reply){
  173. if(!reply.result) {
  174. App.Helpers.alert(reply.message);
  175. }
  176. else {
  177. elm.remove();
  178. }
  179. });
  180. }*/