html.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. App.HTML.setTplKeys = function(tpl, o, empty)
  2. {
  3. var empty = empty || '-';
  4. fb.log(empty);
  5. tpl.set(':source', $.toJSON(o))
  6. $(o).each(function(i, object)
  7. {
  8. $.each(o, function(key)
  9. {
  10. var val = o[key];
  11. if (empty == true) {
  12. tpl.set(':' + key, val || '');
  13. }
  14. else {
  15. tpl.set(':' + key, val || '-');
  16. }
  17. });
  18. });
  19. return tpl;
  20. }
  21. App.HTML.makeDatabases = function(databases)
  22. {
  23. var acc = [];
  24. $(databases).each(function(i, o)
  25. {
  26. var tpl = App.Templates.get('database', 'database');
  27. tpl.set(':name', o.Database);
  28. tpl.set(':db_name', o.Database);
  29. acc[acc.length++] = tpl.finalize();
  30. });
  31. return acc.done();
  32. }
  33. App.HTML.makeDbTableList = function(data)
  34. {
  35. var acc = [];
  36. $(data).each(function(i, o)
  37. {
  38. var name = App.Helpers.getFirstValue(o);
  39. var tpl = App.Templates.get('database_table', 'database');
  40. tpl.set(':name', name);
  41. tpl.set(':table_name', name);
  42. acc[acc.length++] = tpl.finalize();
  43. });
  44. return acc.done();
  45. }
  46. App.HTML.makeDbFieldsList = function(data)
  47. {
  48. var acc = [];
  49. $(data).each(function(i, o)
  50. {
  51. var details = [o['Type'], o['Null'], o['Key'], o['Default'], o['Extra']].join(' ');
  52. var tpl = App.Templates.get('database_field', 'database');
  53. tpl.set(':name', o.Field);
  54. tpl.set(':details', details);
  55. acc[acc.length++] = tpl.finalize();
  56. });
  57. return acc.done();
  58. }
  59. App.HTML.Build.dns_form = function(options, id)
  60. {
  61. if('undefined' == typeof App.Env.initialParams) {
  62. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  63. }
  64. var tpl = App.Templates.get('FORM', 'dns');
  65. tpl.set(':source', options);
  66. options = App.Helpers.evalJSON(options) || {};
  67. if (App.Helpers.isEmpty(options)) {
  68. tpl.set(':title', 'New dns record');
  69. tpl.set(':save_button', 'ADD');
  70. }
  71. else {
  72. tpl.set(':title', 'Edit dns record');
  73. tpl.set(':save_button', 'SAVE');
  74. }
  75. tpl.set(':id', id || '');
  76. tpl.set(':DNS_DOMAIN', options.DNS_DOMAIN || '');
  77. tpl.set(':IP', options.IP || '');
  78. tpl.set(':TTL', options.TTL || '');
  79. tpl.set(':SOA', options.SOA || '');
  80. tpl.set(':DATE', options.DATE || '');
  81. tpl = App.HTML.Build.dns_selects(tpl, options);
  82. return tpl.finalize();
  83. }
  84. App.HTML.Build.ip_form = function(options, id)
  85. {
  86. if('undefined' == typeof App.Env.initialParams) {
  87. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  88. }
  89. var tpl = App.Templates.get('FORM', 'ip');
  90. tpl.set(':source', options);
  91. options = App.Helpers.evalJSON(options) || {};
  92. if (App.Helpers.isEmpty(options)) {
  93. tpl.set(':title', 'New ip address');
  94. tpl.set(':save_button', 'ADD');
  95. }
  96. else {
  97. tpl.set(':title', 'Edit ip address');
  98. tpl.set(':save_button', 'SAVE');
  99. }
  100. tpl.set(':id', id || '');
  101. tpl.set(':IP_ADDRESS', options.IP_ADDRESS || '');
  102. tpl.set(':NETMASK', options.NETMASK || '');
  103. tpl.set(':NAME', options.NAME || '');
  104. tpl = App.HTML.Build.ip_selects(tpl, options);
  105. return tpl.finalize();
  106. }
  107. App.HTML.Build.ip_selects = function(tpl, options)
  108. {
  109. // OWNER
  110. var opts = App.HTML.Build.options(App.Env.initialParams.IP.SYS_USERS, options.OWNER);
  111. tpl.set(':owner_options', opts);
  112. // STATUS
  113. var opts = App.HTML.Build.options(App.Env.initialParams.IP.STATUSES, options.STATUS);
  114. tpl.set(':status_options', opts);
  115. // INTERFACE
  116. var opts = App.HTML.Build.options(App.Env.initialParams.IP.INTERFACES, options.INTERFACE);
  117. tpl.set(':interface_options', opts);
  118. return tpl;
  119. }
  120. App.HTML.Build.dns_selects = function(tpl, options)
  121. {
  122. try {
  123. // TPL
  124. var obj = App.Env.initialParams.DNS.TPL;
  125. var opts = App.HTML.Build.options(obj, options.TPL);
  126. tpl.set(':TPL', opts);
  127. tpl.set(':TPL_DEFAULT_VALUE', options.TPL || App.Helpers.getFirstKey(obj));
  128. }
  129. catch (e) {
  130. return '';
  131. }
  132. return tpl;
  133. }
  134. App.HTML.Build.options = function(initial, default_value)
  135. {
  136. var opts = [];
  137. $.each(initial, function(key){
  138. var selected = key == default_value ? 'selected="selected"' : '';
  139. opts[opts.length++] = '<option value="'+key+'" '+selected+'>'+initial[key]+'</options>';
  140. });
  141. return opts.join('');
  142. }
  143. App.HTML.Build.ip_entry = function(o)
  144. {
  145. var tpl = App.Templates.get('ENTRY', 'ip');
  146. tpl = App.HTML.setTplKeys(tpl, o);
  147. if (App.Constants.SUSPENDED_YES == o.SUSPENDED) {
  148. var sub_tpl = App.Templates.get('SUSPENDED_TPL_ENABLED', 'ip');
  149. }
  150. else {
  151. var sub_tpl = App.Templates.get('SUSPENDED_TPL_DISABLED', 'ip');
  152. }
  153. tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
  154. return tpl.finalize();
  155. }
  156. App.HTML.Build.dns_entry = function(o, is_new)
  157. {
  158. var tpl = App.Templates.get('ENTRY', 'dns');
  159. tpl = App.HTML.setTplKeys(tpl, o);
  160. var ip = o.IP.split('.');
  161. tpl.set(':IP', ip.join('<span class="dot">.</span>'));
  162. tpl.set(':CHECKED', '');
  163. if (is_new) {
  164. var now = new Date();
  165. tpl.set(':DATE', now.format("d.mm.yyyy"));
  166. }
  167. if (App.Constants.SUSPENDED_YES == o.SUSPEND) {
  168. var sub_tpl = App.Templates.get('SUSPENDED_TPL_ENABLED', 'dns');
  169. }
  170. else {
  171. var sub_tpl = App.Templates.get('SUSPENDED_TPL_DISABLED', 'dns');
  172. }
  173. tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
  174. return tpl.finalize();
  175. }
  176. App.HTML.Build.user_entry = function(o, key)
  177. {
  178. var processed_data = {
  179. 'NICKNAME': key,
  180. 'BANDWIDTH_PERCENTS': 90,
  181. 'U_DISK_PERCENTS': 80
  182. };
  183. var o = $.extend(o, processed_data);
  184. var tpl = App.Templates.get('ENTRY', 'user');
  185. tpl = App.HTML.setTplKeys(tpl, o);
  186. if (App.Constants.SUSPENDED_YES == o.SUSPENDED) {
  187. var sub_tpl = App.Templates.get('SUSPENDED_TPL_ENABLED', 'ip');
  188. }
  189. else {
  190. var sub_tpl = App.Templates.get('SUSPENDED_TPL_DISABLED', 'ip');
  191. }
  192. tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
  193. return tpl.finalize();
  194. }
  195. App.HTML.Build.user_form = function(options, id)
  196. {
  197. if('undefined' == typeof App.Env.initialParams) {
  198. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  199. }
  200. var tpl = App.Templates.get('FORM', 'user');
  201. tpl.set(':source', options);
  202. tpl.set(':id', id || '');
  203. options = App.Helpers.evalJSON(options) || {};
  204. if (App.Helpers.isEmpty(options)) {
  205. tpl.set(':title', 'New user');
  206. tpl.set(':save_button', 'ADD');
  207. }
  208. else {
  209. tpl.set(':title', 'Edit user');
  210. tpl.set(':save_button', 'SAVE');
  211. }
  212. options = !App.Helpers.isEmpty(options) ? options : {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','NS':''};
  213. tpl = App.HTML.setTplKeys(tpl, options, true);
  214. tpl = App.HTML.Build.user_selects(tpl, options);
  215. return tpl.finalize();
  216. }
  217. App.HTML.Build.web_domain_entry = function(o, key)
  218. {
  219. // TODO:
  220. /*<span class="domain-name">~!:ALIAS~!,</span>\
  221. <span class="domain-name">naumov-socolov.org.md,</span>\
  222. <span class="domain-name">naumov-socolov.to</span>\*/
  223. var processed_data = {
  224. DOMAIN: key
  225. };
  226. var o = $.extend(o, processed_data);
  227. //fb.info(o);
  228. var tpl = App.Templates.get('ENTRY', 'web_domain');
  229. tpl = App.HTML.setTplKeys(tpl, o);
  230. /*if (App.Constants.SUSPENDED_YES == o.SUSPENDED) {
  231. var sub_tpl = App.Templates.get('SUSPENDED_TPL_ENABLED', 'ip');
  232. }
  233. else {
  234. var sub_tpl = App.Templates.get('SUSPENDED_TPL_DISABLED', 'ip');
  235. }
  236. tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
  237. */
  238. return tpl.finalize();
  239. }
  240. App.HTML.Build.mail_entry = function(o, key)
  241. {
  242. var processed_data = {
  243. DOMAIN: key
  244. };
  245. var o = $.extend(o, processed_data);
  246. var tpl = App.Templates.get('ENTRY', 'mail');
  247. tpl = App.HTML.setTplKeys(tpl, o);
  248. return tpl.finalize();
  249. }
  250. App.HTML.Build.db_entry = function(o, key)
  251. {
  252. var processed_data = {
  253. DOMAIN: key
  254. };
  255. var o = $.extend(o, processed_data);
  256. var tpl = App.Templates.get('ENTRY', 'db');
  257. tpl = App.HTML.setTplKeys(tpl, o);
  258. return tpl.finalize();
  259. }
  260. App.HTML.Build.cron_entry = function(o, key)
  261. {
  262. var processed_data = {
  263. DOMAIN: key
  264. };
  265. var o = $.extend(o, processed_data);
  266. var tpl = App.Templates.get('ENTRY', 'cron');
  267. tpl = App.HTML.setTplKeys(tpl, o);
  268. return tpl.finalize();
  269. }
  270. App.HTML.Build.dns_records = function(records)
  271. {
  272. var acc = [];
  273. $.each(records, function(i, record)
  274. {
  275. var record = records[i];
  276. var tpl = App.HTML.Build.dns_subrecord(record);
  277. acc[acc.length++] = tpl.finalize();
  278. });
  279. return acc.done();
  280. }
  281. App.HTML.Build.dns_subrecord = function(record)
  282. {
  283. var tpl = App.Templates.get('SUBENTRY', 'dns');
  284. tpl.set(':RECORD', record.RECORD || '');
  285. tpl.set(':RECORD_VALUE', record.RECORD_VALUE || '');
  286. tpl.set(':RECORD_ID', record.RECORD_ID || '');
  287. //tpl.set(':RECORD_TYPE_VALUE', '');
  288. tpl.set(':RECORD_TYPE', App.HTML.Build.options(App.Env.initialParams.DNS.record.RECORD_TYPE, (record.RECORD_TYPE || -1)));
  289. return tpl;
  290. }
  291. App.HTML.Build.user_selects = function(tpl, options)
  292. {
  293. var acc = [];
  294. // PACKAGE
  295. var pkg = App.Env.initialParams.USERS.PACKAGE;
  296. $.each(pkg, function(val)
  297. {
  298. var tpl = App.Templates.get('select_option', 'general');
  299. tpl.set(':VALUE', val);
  300. tpl.set(':TEXT', pkg[val]);
  301. acc[acc.length++] = tpl.finalize();
  302. });
  303. tpl.set(':PACKAGE_OPTIONS', acc.done());
  304. // ROLE
  305. acc = [];
  306. var roles = App.Env.initialParams.USERS.ROLE;
  307. $.each(roles, function(val)
  308. {
  309. var tpl = App.Templates.get('select_option', 'general');
  310. tpl.set(':VALUE', val);
  311. tpl.set(':TEXT', roles[val]);
  312. acc[acc.length++] = tpl.finalize();
  313. });
  314. tpl.set(':ROLE_OPTIONS', acc.done());
  315. // SHELL
  316. acc = [];
  317. var shell = App.Env.initialParams.USERS.SHELL;
  318. $.each(shell, function(val)
  319. {
  320. var tpl = App.Templates.get('select_option', 'general');
  321. tpl.set(':VALUE', val);
  322. tpl.set(':TEXT', shell[val]);
  323. acc[acc.length++] = tpl.finalize();
  324. });
  325. tpl.set(':SHELL_OPTIONS', acc.done());
  326. return tpl;
  327. }