html.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. App.HTML.setTplKeys = function (tpl, o, empty) {
  2. var empty = empty || '';
  3. fb.log(empty);
  4. tpl.set(':source', $.toJSON(o).replace(/'/gi, "\\'"))
  5. $(o).each(function (i, object) {
  6. $.each(o, function (key) {
  7. var val = o[key];
  8. if (empty == true) {
  9. tpl.set(':' + key, val || '');
  10. } else {
  11. tpl.set(':' + key, val || '');
  12. }
  13. });
  14. });
  15. return tpl;
  16. }
  17. //
  18. // BUILD FORMS
  19. //
  20. App.HTML.Build.dns_form = function (options, id) {
  21. if ('undefined' == typeof App.Env.initialParams) {
  22. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  23. }
  24. var tpl = App.Templates.get('FORM', 'dns');
  25. tpl.set(':source', options);
  26. options = App.Helpers.evalJSON(options) || {};
  27. if (App.Helpers.isEmpty(options)) {
  28. tpl.set(':title', 'New dns record');
  29. tpl.set(':save_button', 'ADD');
  30. } else {
  31. tpl.set(':title', 'Edit dns record');
  32. tpl.set(':save_button', 'SAVE');
  33. }
  34. tpl.set(':id', id || '');
  35. tpl.set(':DNS_DOMAIN', options.DNS_DOMAIN || '');
  36. tpl.set(':IP', options.IP || '');
  37. tpl.set(':TTL', options.TTL || '');
  38. tpl.set(':SOA', options.SOA || '');
  39. tpl.set(':DATE', options.DATE || '');
  40. tpl = App.HTML.Build.dns_selects(tpl, options);
  41. tpl = App.HTML.toggle_suspended_form(tpl, options);
  42. return tpl.finalize();
  43. }
  44. App.HTML.Build.ip_form = function (options, id) {
  45. if ('undefined' == typeof App.Env.initialParams) {
  46. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  47. }
  48. var tpl = App.Templates.get('FORM', 'ip');
  49. tpl.set(':source', options);
  50. options = App.Helpers.evalJSON(options) || {};
  51. if (App.Helpers.isEmpty(options)) {
  52. tpl.set(':title', 'New ip address');
  53. tpl.set(':save_button', 'ADD');
  54. } else {
  55. tpl.set(':title', 'Edit ip address');
  56. tpl.set(':save_button', 'SAVE');
  57. }
  58. tpl.set(':id', id || '');
  59. tpl.set(':IP_ADDRESS', options.IP_ADDRESS || '');
  60. tpl.set(':NETMASK', options.NETMASK || '');
  61. tpl.set(':NAME', options.NAME || '');
  62. tpl = App.HTML.Build.ip_selects(tpl, options);
  63. tpl = App.HTML.toggle_suspended_form(tpl, options);
  64. return tpl.finalize();
  65. }
  66. App.HTML.Build.user_form = function (options, id) {
  67. var in_edit = false;
  68. if (!App.Helpers.isEmpty(options)) {
  69. in_edit = true;
  70. }
  71. if ('undefined' == typeof App.Env.initialParams) {
  72. return alert('Please wait a bit. Some background processes are not yet executed. Thank you for patience.');
  73. }
  74. var tpl = App.Templates.get('FORM', 'user');
  75. tpl.set(':source', options);
  76. tpl.set(':id', id || '');
  77. options = App.Helpers.evalJSON(options) || {};
  78. if (App.Helpers.isEmpty(options)) {
  79. tpl.set(':title', 'New user');
  80. tpl.set(':save_button', 'ADD');
  81. } else {
  82. tpl.set(':title', 'Edit user');
  83. tpl.set(':save_button', 'SAVE');
  84. }
  85. options = !App.Helpers.isEmpty(options) ? options : App.Empty.USER;
  86. if (in_edit == true) {
  87. options.PASSWORD = App.Settings.PASSWORD_IMMUTE;
  88. var ns = [];
  89. $([3, 4, 5, 6, 7, 8]).each(function (i, index) {
  90. if (options['NS' + index].trim() != '') {
  91. var tpl_ns = App.Templates.get('NS_INPUT', 'user');
  92. tpl_ns.set(':NS_LABEL', 'NS #' + (index));
  93. tpl_ns.set(':NAME', options['NS' + index]);
  94. ns[ns.length++] = tpl_ns.finalize();
  95. }
  96. });
  97. ns[ns.length++] = App.Templates.get('PLUS_ONE_NS', 'user').finalize();
  98. tpl.set(':NS', ns.done());
  99. } else {
  100. tpl.set(':NS', '');
  101. }
  102. tpl = App.HTML.setTplKeys(tpl, options, true);
  103. tpl = App.HTML.Build.user_selects(tpl, options);
  104. tpl = App.HTML.toggle_suspended_form(tpl, options);
  105. if (options.REPORTS_ENABLED == 'yes') {
  106. tpl.set(':CHECKED', 'checked="checked"');
  107. } else {
  108. tpl.set(':CHECKED', '');
  109. }
  110. if (!in_edit) {
  111. tpl.set(':REPORTS_ENABLED_EDITABLE', 'hidden');
  112. }
  113. return tpl.finalize();
  114. }
  115. App.HTML.Build.web_domain_form = function (options, id) {
  116. if ('undefined' == typeof App.Env.initialParams) {
  117. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  118. }
  119. var in_edit = false;
  120. if (!App.Helpers.isEmpty(options)) {
  121. in_edit = true;
  122. }
  123. var tpl = App.Templates.get('FORM', 'web_domain');
  124. tpl.set(':source', options);
  125. tpl.set(':id', id || '');
  126. options = App.Helpers.evalJSON(options) || {};
  127. if (App.Helpers.isEmpty(options)) {
  128. tpl.set(':title', 'New WEB domain');
  129. tpl.set(':save_button', 'ADD');
  130. } else {
  131. tpl.set(':title', 'Edit WEB domain');
  132. tpl.set(':save_button', 'SAVE');
  133. }
  134. options = !App.Helpers.isEmpty(options) ? options : App.Empty.WEB_DOMAIN;
  135. if (in_edit == true) {
  136. options.STATS_PASSWORD = options.STATS_LOGIN.trim() != '' ? App.Settings.PASSWORD_IMMUTE : '';
  137. }
  138. tpl = App.HTML.setTplKeys(tpl, options, true);
  139. tpl = App.HTML.Build.web_domain_selects(tpl, options);
  140. tpl = App.HTML.toggle_suspended_form(tpl, options);
  141. if (options.CGI == 'yes') {
  142. tpl.set(':CHECKED_CGI', 'checked="checked"');
  143. }
  144. if (options.ELOG == 'yes') {
  145. tpl.set(':CHECKED_ELOG', 'checked="checked"');
  146. }
  147. if (options.STATS_LOGIN.trim() != '') {
  148. tpl.set(':STAT_AUTH', 'checked="checked"');
  149. tpl.set(':ACTIVE_LOGIN', '');
  150. tpl.set(':ACTIVE_PASSWORD', '');
  151. tpl.set(':stats_auth_checked', 'checked="checked"');
  152. } else {
  153. tpl.set(':ACTIVE_LOGIN', 'hidden');
  154. tpl.set(':ACTIVE_PASSWORD', 'hidden');
  155. tpl.set(':stats_auth_checked', '');
  156. }
  157. return tpl.finalize();
  158. }
  159. App.HTML.Build.db_form = function (options, id) {
  160. var in_edit = false;
  161. if (!App.Helpers.isEmpty(options)) {
  162. in_edit = true;
  163. }
  164. if ('undefined' == typeof App.Env.initialParams) {
  165. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  166. }
  167. var tpl = App.Templates.get('FORM', 'db');
  168. tpl.set(':source', options);
  169. tpl.set(':id', id || '');
  170. options = App.Helpers.evalJSON(options) || {};
  171. if (App.Helpers.isEmpty(options)) {
  172. tpl.set(':title', 'New database');
  173. tpl.set(':save_button', 'ADD');
  174. } else {
  175. tpl.set(':title', 'Edit database "' + options.DB + '"');
  176. tpl.set(':save_button', 'SAVE');
  177. }
  178. options = !App.Helpers.isEmpty(options) ? options : App.Empty.DB;
  179. if (in_edit == true) {
  180. options.PASSWORD = App.Settings.PASSWORD_IMMUTE;
  181. }
  182. tpl = App.HTML.setTplKeys(tpl, options, true);
  183. tpl = App.HTML.Build.db_selects(tpl, options);
  184. tpl = App.HTML.toggle_suspended_form(tpl, options);
  185. return tpl.finalize();
  186. }
  187. App.HTML.Build.cron_form = function (options, id) {
  188. if ('undefined' == typeof App.Env.initialParams) {
  189. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  190. }
  191. var tpl = App.Templates.get('FORM', 'cron');
  192. tpl.set(':source', options);
  193. tpl.set(':id', id || '');
  194. options = App.Helpers.evalJSON(options) || {};
  195. if (App.Helpers.isEmpty(options)) {
  196. tpl.set(':title', 'New cron entry');
  197. tpl.set(':save_button', 'ADD');
  198. } else {
  199. tpl.set(':title', 'Edit cron entry');
  200. tpl.set(':save_button', 'SAVE');
  201. }
  202. options = !App.Helpers.isEmpty(options) ? options : {
  203. DAY: '',
  204. MONTH: '',
  205. WDAY: '',
  206. HOUR: '',
  207. CMD: '',
  208. MIN: ''
  209. };
  210. tpl = App.HTML.setTplKeys(tpl, options);
  211. tpl = App.HTML.toggle_suspended_form(tpl, options);
  212. return tpl.finalize();
  213. }
  214. //
  215. // BUILD ENTRIES
  216. //
  217. App.HTML.Build.ip_entry = function (o) {
  218. var tpl = App.Templates.get('ENTRY', 'ip');
  219. tpl = App.HTML.setTplKeys(tpl, o);
  220. tpl = App.HTML.toggle_suspended_entry(tpl, o);
  221. return tpl.finalize();
  222. }
  223. App.HTML.Build.dns_entry = function (o, is_new) {
  224. var tpl = App.Templates.get('ENTRY', 'dns');
  225. tpl = App.HTML.setTplKeys(tpl, o);
  226. var ip = o.IP.split('.');
  227. tpl.set(':IP', ip.join('<span class="dot">.</span>'));
  228. tpl.set(':CHECKED', '');
  229. if (is_new) {
  230. var now = new Date();
  231. tpl.set(':DATE', now.format("d.mm.yyyy"));
  232. }
  233. tpl.set(':TPL_VAL', o.TPL);
  234. tpl = App.HTML.toggle_suspended_entry(tpl, o);
  235. return tpl.finalize();
  236. }
  237. App.HTML.Build.user_entry = function (o, key) {
  238. var processed_data = {
  239. 'NICKNAME': key,
  240. 'U_DISK_PERCENTAGE': o.U_DISK > 0 ? o.U_DISK / o.DISK_QUOTA * 100 : 1,
  241. 'U_BANDWIDTH_PERCENTAGE': o.U_BANDWIDTH > 0 ? o.U_BANDWIDTH / o.BANDWIDTH * 100 : 1,
  242. 'U_DISK': o.U_DISK == 0 ? 1 : App.Helpers.formatNumber(o.U_DISK),
  243. 'U_BANDWIDTH': o.U_BANDWIDTH == 0 ? 1 : App.Helpers.formatNumber(o.U_BANDWIDTH),
  244. 'DISK_QUOTA_MEASURE': App.Helpers.getMbHumanMeasure(o.DISK_QUOTA),
  245. 'BANDWIDTH_MEASURE': App.Helpers.getMbHumanMeasure(o.BANDWIDTH),
  246. 'BANDWIDTH': App.Helpers.getMbHuman(o.BANDWIDTH),
  247. 'DISK_QUOTA': App.Helpers.getMbHuman(o.DISK_QUOTA)
  248. };
  249. var o = $.extend(o, processed_data);
  250. o.U_DISK_PERCENTAGE_2 = o.U_DISK_PERCENTAGE;
  251. o.U_DISK_PERCENTAGE_3 = o.U_DISK_PERCENTAGE;
  252. o.BANDWIDTH_MEASURE_2 = o.BANDWIDTH_MEASURE;
  253. o.DISK_QUOTA_MEASURE_2 = o.DISK_QUOTA_MEASURE;
  254. o.U_BANDWIDTH_PERCENTAGE_2 = o.U_BANDWIDTH_PERCENTAGE;
  255. o.U_BANDWIDTH_PERCENTAGE_3 = o.U_BANDWIDTH_PERCENTAGE;
  256. var tpl = App.Templates.get('ENTRY', 'user');
  257. tpl = App.HTML.setTplKeys(tpl, o);
  258. tpl = App.HTML.toggle_suspended_entry(tpl, o);
  259. var ns = [];
  260. var ns_full = [];
  261. $([1, 2, 3, 4, 5, 6, 7, 8]).each(function (i, index) {
  262. var key = 'NS' + index;
  263. if ('undefined' != typeof o[key]) {
  264. if (o[key].trim() != '') {
  265. var tpl_ns = App.Templates.get('NS_RECORD', 'user');
  266. tpl_ns.set(':NAME', o[key]);
  267. var tpl_finalized = tpl_ns.finalize();
  268. ns_full[ns_full.length++] = tpl_finalized;
  269. if (i < App.Settings.USER_VISIBLE_NS) {
  270. ns[ns.length++] = tpl_finalized;
  271. }
  272. }
  273. }
  274. });
  275. if (ns_full.length <= App.Settings.USER_VISIBLE_NS) {
  276. tpl.set(':NS', ns.done());
  277. } else {
  278. var ns_custom = App.Templates.get('NS_MINIMIZED', 'user');
  279. ns_custom.set(':NS_MINI', ns.done());
  280. ns_custom.set(':NS_FULL', ns_full.done());
  281. ns_custom.set(':MORE_NUMBER', Math.abs(App.Settings.USER_VISIBLE_NS - ns_full.length));
  282. tpl.set(':NS', ns_custom.finalize());
  283. }
  284. tpl = App.HTML.Build.user_web_tpl(tpl, o);
  285. tpl.set(':REPORTS_ENABLED', o.REPORTS_ENABLED == 'yes' ? 'enabled' : 'DISABLED');
  286. if (o.U_DISK_PERCENTAGE > 100) {
  287. var tpl_over = App.Templates.get('over_bar', 'general');
  288. var difference = parseInt(o.U_DISK_PERCENTAGE, 10) - 100;
  289. tpl_over.set(':OVER_PERCENTS', difference);
  290. tpl_over.set(':OVER_PERCENTS_2', difference);
  291. tpl.set(':OVER_BAR', tpl_over.finalize());
  292. tpl.set(':U_DISK_PERCENTAGE_3', 100);
  293. tpl.set(':OVER_DRAFT_VALUE', 'overdraft');
  294. } else {
  295. tpl.set(':OVER_BAR', '');
  296. tpl.set(':OVER_DRAFT_VALUE', '');
  297. }
  298. if (o.U_BANDWIDTH_PERCENTAGE > 100) {
  299. var tpl_over = App.Templates.get('over_bar', 'general');
  300. var difference = parseInt(o.U_BANDWIDTH_PERCENTAGE, 10) - 100;
  301. tpl_over.set(':OVER_PERCENTS', difference);
  302. tpl_over.set(':OVER_PERCENTS_2', difference);
  303. tpl.set(':OVER_BAR_2', tpl_over.finalize());
  304. tpl.set(':U_BANDWIDTH_PERCENTAGE_3', 100);
  305. tpl.set(':OVER_DRAFT_VALUE_2', 'overdraft');
  306. } else {
  307. tpl.set(':OVER_BAR_2', '');
  308. tpl.set(':OVER_DRAFT_VALUE_2', '');
  309. }
  310. return tpl.finalize();
  311. }
  312. App.HTML.Build.web_domain_entry = function (o, key) {
  313. var processed_data = {
  314. DOMAIN: key
  315. };
  316. var o = $.extend(o, processed_data);
  317. var tpl = App.Templates.get('ENTRY', 'web_domain');
  318. tpl = App.HTML.setTplKeys(tpl, o);
  319. tpl = App.HTML.toggle_suspended_entry(tpl, o);
  320. if (o.STATS_LOGIN.trim() != '') {
  321. tpl.set(':STATS_AUTH', '+auth');
  322. } else {
  323. tpl.set(':STATS_AUTH', '');
  324. }
  325. tpl.set(':DISK', App.Env.initialParams.PROFILE.BANDWIDTH);
  326. tpl.set(':BANDWIDTH', App.Env.initialParams.PROFILE.DISK);
  327. tpl = App.HTML.toggle_suspended_entry(tpl, o);
  328. return tpl.finalize();
  329. }
  330. App.HTML.Build.mail_entry = function (o, key) {
  331. var processed_data = {
  332. DOMAIN: key
  333. };
  334. var o = $.extend(o, processed_data);
  335. var tpl = App.Templates.get('ENTRY', 'mail');
  336. tpl = App.HTML.setTplKeys(tpl, o);
  337. tpl = App.HTML.toggle_suspended_entry(tpl, o);
  338. return tpl.finalize();
  339. }
  340. App.HTML.Build.db_entry = function (o, key) {
  341. var user_list_html = [];
  342. $(o['USERS']).each(function (i, o) {
  343. var tpl = App.Templates.get('USER_ITEM', 'db');
  344. tpl.set(':NAME', o);
  345. user_list_html.push(tpl.finalize());
  346. });
  347. var wrapper = App.Templates.get('USER_ITEMS_WRAPPER', 'db');
  348. wrapper.set(':CONTENT', user_list_html.done());
  349. var processed_data = {
  350. 'USER_LIST': wrapper.finalize(),
  351. 'USERS': o['USERS'].length || 0,
  352. 'U_DISK_PERCENTAGE': o.U_DISK > 0 ? o.U_DISK / o.DISK * 100 : 0.01,
  353. 'DISK_MEASURE': App.Helpers.getMbHumanMeasure(o.DISK),
  354. 'DISK': App.Helpers.getMbHuman(o.DISK)
  355. };
  356. var o = $.extend(o, processed_data);
  357. var tpl = App.Templates.get('ENTRY', 'db');
  358. tpl = App.HTML.setTplKeys(tpl, o);
  359. tpl = App.HTML.toggle_suspended_entry(tpl, o);
  360. return tpl.finalize();
  361. }
  362. App.HTML.Build.cron_entry = function (o, key) {
  363. var processed_data = {
  364. DOMAIN: key
  365. };
  366. var o = $.extend(o, processed_data);
  367. var tpl = App.Templates.get('ENTRY', 'cron');
  368. tpl = App.HTML.setTplKeys(tpl, o);
  369. tpl = App.HTML.toggle_suspended_entry(tpl, o);
  370. return tpl.finalize();
  371. }
  372. //
  373. // GENERAL METHODS
  374. //
  375. App.HTML.Build.backup_list = function(backups)
  376. {
  377. if (!backups || backups.length == 0) {
  378. return '<br /><br /><center><h1>Backups are not available</h1></center>';
  379. }
  380. var acc = [];
  381. $.each(backups, function(key) {
  382. var bckp = backups[key];
  383. var tpl = App.Templates.get('ENTRY', 'backup');
  384. tpl.set(':CREATED_AT', key);
  385. tpl.set(':CREATED_AT_TIME', bckp.TIME);
  386. tpl.set(':CREATED_AT_TIME', bckp.TIME);
  387. acc[acc.length++] = tpl.finalize()
  388. })
  389. var wrap = App.Templates.get('WRAPPER', 'backup');
  390. wrap.set(':CONTENT', acc.done());
  391. return wrap.finalize();
  392. }
  393. //
  394. // HANDY METHODS
  395. //
  396. App.HTML.toggle_suspended_form = function(tpl, options)
  397. {
  398. if (App.Constants.SUSPENDED_YES == options.SUSPEND) {
  399. tpl.set(':SUSPENDED_CHECKED', 'checked="checked"');
  400. tpl.set(':FORM_SUSPENDED', 'form-suspended');
  401. tpl.set(':SUSPENDED_VALUE', 'on');
  402. } else {
  403. tpl.set(':SUSPENDED_CHECKED', '');
  404. tpl.set(':FORM_SUSPENDED', '');
  405. tpl.set(':SUSPENDED_VALUE', 'off');
  406. }
  407. return tpl;
  408. }
  409. App.HTML.toggle_suspended_entry = function(tpl, options)
  410. {
  411. if (App.Constants.SUSPENDED_YES == options.SUSPEND) {
  412. var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general');
  413. tpl.set(':SUSPENDED_CLASS', 'inactive-row');
  414. } else {
  415. var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general');
  416. tpl.set(':SUSPENDED_CLASS', '');
  417. }
  418. tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
  419. return tpl;
  420. }
  421. App.HTML.makeDatabases = function (databases) {
  422. var acc = [];
  423. $(databases).each(function (i, o) {
  424. var tpl = App.Templates.get('database', 'database');
  425. tpl.set(':name', o.Database);
  426. tpl.set(':db_name', o.Database);
  427. acc[acc.length++] = tpl.finalize();
  428. });
  429. return acc.done();
  430. }
  431. App.HTML.makeDbTableList = function (data) {
  432. var acc = [];
  433. $(data).each(function (i, o) {
  434. var name = App.Helpers.getFirstValue(o);
  435. var tpl = App.Templates.get('database_table', 'database');
  436. tpl.set(':name', name);
  437. tpl.set(':table_name', name);
  438. acc[acc.length++] = tpl.finalize();
  439. });
  440. return acc.done();
  441. }
  442. App.HTML.makeDbFieldsList = function (data) {
  443. var acc = [];
  444. $(data).each(function (i, o) {
  445. var details = [o['Type'], o['Null'], o['Key'], o['Default'], o['Extra']].join(' ');
  446. var tpl = App.Templates.get('database_field', 'database');
  447. tpl.set(':name', o.Field);
  448. tpl.set(':details', details);
  449. acc[acc.length++] = tpl.finalize();
  450. });
  451. return acc.done();
  452. }
  453. App.HTML.Build.options = function (initial, default_value) {
  454. var opts = [];
  455. $.each(initial, function (key) {
  456. var selected = key == default_value ? 'selected="selected"' : '';
  457. opts[opts.length++] = '<option value="' + key + '" ' + selected + '>' + initial[key] + '</options>';
  458. });
  459. return opts.join('');
  460. }
  461. App.HTML.Build.dns_records = function (records) {
  462. var acc = [];
  463. $.each(records, function (i, record) {
  464. var record = records[i];
  465. var tpl = App.HTML.Build.dns_subrecord(record);
  466. acc[acc.length++] = tpl.finalize();
  467. });
  468. return acc.done();
  469. }
  470. App.HTML.Build.dns_subrecord = function (record) {
  471. var tpl = App.Templates.get('SUBENTRY', 'dns');
  472. tpl.set(':RECORD', record.RECORD || '');
  473. tpl.set(':RECORD_VALUE', record.RECORD_VALUE || '');
  474. tpl.set(':RECORD_ID', record.RECORD_ID || '');
  475. tpl.set(':RECORD_TYPE', App.HTML.Build.options(App.Env.initialParams.DNS.record.RECORD_TYPE, (record.RECORD_TYPE || -1)));
  476. return tpl;
  477. }
  478. App.HTML.Build.ssl_key_file = function () {
  479. return '<iframe src="' + App.Helpers.getUploadUrl() + '?action=show&type=key" width="500px;" height="53px;" framevorder="0" scroll="no">..</iframe>';
  480. }
  481. App.HTML.Build.ssl_cert_file = function () {
  482. return '<iframe src="' + App.Helpers.getUploadUrl() + '?action=show&type=cert" width="500px;" height="53px;" framevorder="0" scroll="no">..</iframe>';
  483. }
  484. App.HTML.Build.user_selects = function (tpl, options) {
  485. var acc = [];
  486. var pkg = App.Env.initialParams.USERS.PACKAGE;
  487. $.each(pkg, function (val) {
  488. var tpl = App.Templates.get('select_option', 'general');
  489. tpl.set(':VALUE', val);
  490. tpl.set(':TEXT', pkg[val]);
  491. tpl.set(':SELECTED', val == options.PACKAGE ? 'selected="selected"' : '');
  492. acc[acc.length++] = tpl.finalize();
  493. });
  494. tpl.set(':PACKAGE_OPTIONS', acc.done());
  495. acc = [];
  496. var shell = App.Env.initialParams.USERS.SHELL;
  497. $.each(shell, function (val) {
  498. var tpl = App.Templates.get('select_option', 'general');
  499. tpl.set(':VALUE', val);
  500. tpl.set(':TEXT', shell[val]);
  501. tpl.set(':SELECTED', val == options.SHELL ? 'selected="selected"' : '');
  502. acc[acc.length++] = tpl.finalize();
  503. });
  504. tpl.set(':SHELL_OPTIONS', acc.done());
  505. return tpl;
  506. }
  507. App.HTML.Build.db_selects = function (tpl, options) {
  508. var acc = [];
  509. var items = App.Env.initialParams.DB.TYPE;
  510. $.each(items, function (val) {
  511. var tpl = App.Templates.get('select_option', 'general');
  512. tpl.set(':VALUE', val);
  513. tpl.set(':TEXT', items[val]);
  514. tpl.set(':SELECTED', val == options.TYPE ? 'selected="selected"' : '');
  515. acc[acc.length++] = tpl.finalize();
  516. });
  517. tpl.set(':TYPE_OPTIONS', acc.done());
  518. acc = [];
  519. var items = App.Env.initialParams.DB.HOST;
  520. $.each(items, function (val) {
  521. var tpl = App.Templates.get('select_option', 'general');
  522. tpl.set(':VALUE', val);
  523. tpl.set(':TEXT', items[val]);
  524. tpl.set(':SELECTED', val == options.HOST ? 'selected="selected"' : '');
  525. acc[acc.length++] = tpl.finalize();
  526. });
  527. tpl.set(':HOST_OPTIONS', acc.done());
  528. return tpl;
  529. }
  530. App.HTML.Build.ip_selects = function (tpl, options) {
  531. var users = App.Env.initialParams.IP.OWNER;
  532. var opts = App.HTML.Build.options(users, options.OWNER);
  533. tpl.set(':owner_options', opts);
  534. var opts = App.HTML.Build.options(App.Env.initialParams.IP.STATUSES, options.STATUS);
  535. tpl.set(':status_options', opts);
  536. var opts = App.HTML.Build.options(App.Env.initialParams.IP.INTERFACES, options.INTERFACE);
  537. tpl.set(':interface_options', opts);
  538. return tpl;
  539. }
  540. App.HTML.Build.dns_selects = function (tpl, options) {
  541. try {
  542. var obj = {};
  543. $.each(App.Env.initialParams.DNS.TPL, function (key) {
  544. obj[key] = key;
  545. });
  546. var opts = App.HTML.Build.options(obj, options.PACKAGE);
  547. tpl.set(':TPL', opts);
  548. tpl.set(':TPL_DEFAULT_VALUE', options.TPL || App.Helpers.getFirstKey(obj));
  549. } catch (e) {
  550. return tpl;
  551. }
  552. return tpl;
  553. }
  554. App.HTML.Build.web_domain_selects = function (tpl, options) {
  555. try {
  556. var obj = App.Env.initialParams.WEB_DOMAIN.IP;
  557. var opts = App.HTML.Build.options(obj, options.IP);
  558. tpl.set(':IP_OPTIONS', opts);
  559. var obj = {};
  560. $.each(App.Env.initialParams.WEB_DOMAIN.TPL, function (key) {
  561. obj[key] = key;
  562. });
  563. var opts = App.HTML.Build.options(obj, options.TPL);
  564. tpl.set(':TPL_OPTIONS', opts);
  565. var obj = App.Env.initialParams.WEB_DOMAIN.STAT;
  566. var opts = App.HTML.Build.options(obj, options.STAT);
  567. tpl.set(':STAT_OPTIONS', opts);
  568. } catch (e) {
  569. return tpl;
  570. }
  571. return tpl;
  572. }
  573. App.HTML.Build.user_web_tpl = function (tpl, o) {
  574. var wt = [];
  575. var wt_full = [];
  576. var templates = o.WEB_TPL;
  577. templates = templates.split(',');
  578. if (templates.length == 0) {
  579. templates = templates.split(' ');
  580. }
  581. $(templates).each(function (i, web_tpl) {
  582. var tpl_wt = App.Templates.get('WEB_TPL', 'user');
  583. tpl_wt.set(':NAME', web_tpl);
  584. var tpl_finalized = tpl_wt.finalize();
  585. wt_full[wt_full.length++] = tpl_finalized;
  586. if (i < App.Settings.USER_VISIBLE_WEB_TPL) {
  587. wt[wt.length++] = tpl_finalized;
  588. }
  589. });
  590. if (templates.length <= App.Settings.USER_VISIBLE_NS) {
  591. tpl.set(':WEB_TPL', wt.done());
  592. } else {
  593. var wt_custom = App.Templates.get('WEB_TPL_MINIMIZED', 'user');
  594. wt_custom.set(':WEB_TPL_MINI', wt.done());
  595. wt_custom.set(':WEB_TPL_FULL', wt_full.done());
  596. wt_custom.set(':MORE_NUMBER', Math.abs(App.Settings.USER_VISIBLE_NS - wt_full.length));
  597. tpl.set(':WEB_TPL', wt_custom.finalize());
  598. }
  599. return tpl;
  600. }