html.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. App.HTML.setTplKeys = function(tpl, o, empty)
  2. {
  3. var empty = empty || '';
  4. fb.log(empty);
  5. tpl.set(':source', $.toJSON(o).replace(/'/gi, "\\'"))
  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. {try{
  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. }catch(e){fb.error(e);}
  106. return tpl.finalize();
  107. }
  108. App.HTML.Build.options = function(initial, default_value)
  109. {
  110. var opts = [];
  111. $.each(initial, function(key){
  112. var selected = key == default_value ? 'selected="selected"' : '';
  113. opts[opts.length++] = '<option value="'+key+'" '+selected+'>'+initial[key]+'</options>';
  114. });
  115. return opts.join('');
  116. }
  117. App.HTML.Build.ip_entry = function(o)
  118. {
  119. var tpl = App.Templates.get('ENTRY', 'ip');
  120. tpl = App.HTML.setTplKeys(tpl, o);
  121. /*if (App.Constants.SUSPENDED_YES == o.SUSPENDED) {
  122. var sub_tpl = App.Templates.get('SUSPENDED_TPL_ENABLED', 'ip');
  123. }
  124. else {
  125. var sub_tpl = App.Templates.get('SUSPENDED_TPL_DISABLED', 'ip');
  126. }*/
  127. tpl.set(':SUSPENDED_TPL', '');
  128. return tpl.finalize();
  129. }
  130. App.HTML.Build.dns_entry = function(o, is_new)
  131. {
  132. var tpl = App.Templates.get('ENTRY', 'dns');
  133. tpl = App.HTML.setTplKeys(tpl, o);
  134. var ip = o.IP.split('.');
  135. tpl.set(':IP', ip.join('<span class="dot">.</span>'));
  136. tpl.set(':CHECKED', '');
  137. if (is_new) {
  138. var now = new Date();
  139. tpl.set(':DATE', now.format("d.mm.yyyy"));
  140. }
  141. /*if (App.Constants.SUSPENDED_YES == o.SUSPEND) {
  142. var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general');
  143. }
  144. else {
  145. var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general');
  146. }*/
  147. tpl.set(':SUSPENDED_TPL', '');
  148. return tpl.finalize();
  149. }
  150. App.HTML.Build.user_entry = function(o, key)
  151. {
  152. var processed_data = {
  153. 'NICKNAME' : key,
  154. 'U_DISK_PERCENTAGE' : o.U_DISK > 0 ? o.U_DISK / o.DISK_QUOTA * 100 : 0.01,
  155. 'U_BANDWIDTH_PERCENTAGE': o.U_BANDWIDTH > 0 ? o.U_BANDWIDTH / o.BANDWIDTH * 100 : 0.01,
  156. 'DISK_QUOTA_MEASURE' : App.Helpers.getMbHumanMeasure(o.DISK_QUOTA),
  157. 'BANDWIDTH_MEASURE' : App.Helpers.getMbHumanMeasure(o.BANDWIDTH),
  158. 'BANDWIDTH' : App.Helpers.getMbHuman(o.BANDWIDTH),
  159. 'DISK_QUOTA' : App.Helpers.getMbHuman(o.DISK_QUOTA)
  160. };
  161. var o = $.extend(o, processed_data);
  162. var tpl = App.Templates.get('ENTRY', 'user');
  163. tpl = App.HTML.setTplKeys(tpl, o);
  164. tpl.set(':SUSPENDED_TPL', '');//sub_tpl.finalize());
  165. var ns = [];
  166. var ns_full = [];
  167. $([1,2,3,4,5,6,7,8]).each(function(i, index)
  168. {
  169. if (o['NS'+index].trim() != '') {
  170. var tpl_ns = App.Templates.get('NS_RECORD', 'user');
  171. tpl_ns.set(':NAME', o['NS'+index]);
  172. var tpl_finalized = tpl_ns.finalize();
  173. ns_full[ns_full.length++] = tpl_finalized;
  174. if (i < App.Settings.USER_VISIBLE_NS) {
  175. ns[ns.length++] = tpl_finalized;
  176. }
  177. }
  178. });
  179. if (ns_full.length <= App.Settings.USER_VISIBLE_NS) {
  180. tpl.set(':NS', ns.done());
  181. }
  182. else {
  183. var ns_custom = App.Templates.get('NS_MINIMIZED', 'user');
  184. ns_custom.set(':NS_MINI', ns.done());
  185. ns_custom.set(':NS_FULL', ns_full.done());
  186. ns_custom.set(':MORE_NUMBER', Math.abs(App.Settings.USER_VISIBLE_NS - ns_full.length));
  187. tpl.set(':NS', ns_custom.finalize());
  188. }
  189. tpl.set(':REPORTS_ENABLED', o.REPORTS_ENABLED == 'yes' ? 'enabled' : 'DISABLED');
  190. return tpl.finalize();
  191. }
  192. App.HTML.Build.user_form = function(options, id)
  193. {
  194. var in_edit = false;
  195. if (!App.Helpers.isEmpty(options)) {
  196. in_edit = true;
  197. }
  198. if('undefined' == typeof App.Env.initialParams) {
  199. return alert('Please wait a bit. Some background processes are not yet executed. Thank you for patience.');
  200. }
  201. var tpl = App.Templates.get('FORM', 'user');
  202. tpl.set(':source', options);
  203. tpl.set(':id', id || '');
  204. options = App.Helpers.evalJSON(options) || {};
  205. if (App.Helpers.isEmpty(options)) {
  206. tpl.set(':title', 'New user');
  207. tpl.set(':save_button', 'ADD');
  208. }
  209. else {
  210. tpl.set(':title', 'Edit user');
  211. tpl.set(':save_button', 'SAVE');
  212. }
  213. options = !App.Helpers.isEmpty(options) ? options : App.Empty.USER;
  214. // NS
  215. var ns = [];
  216. $([3,4,5,6,7,8]).each(function(i, index)
  217. {
  218. if (options['NS'+index].trim() != '') {
  219. var tpl_ns = App.Templates.get('NS_INPUT', 'user');
  220. tpl_ns.set(':NS_LABEL', 'NS #' + (index));
  221. tpl_ns.set(':NAME', options['NS'+index]);
  222. ns[ns.length++] = tpl_ns.finalize();
  223. }
  224. });
  225. ns[ns.length++] = App.Templates.get('PLUS_ONE_NS', 'user').finalize();
  226. tpl.set(':NS', ns.done());
  227. if (in_edit == true) {
  228. options.PASSWORD = App.Settings.PASSWORD_IMMUTE;
  229. }
  230. tpl = App.HTML.setTplKeys(tpl, options, true);
  231. tpl = App.HTML.Build.user_selects(tpl, options);
  232. if (options.REPORTS_ENABLED == 'yes') {
  233. tpl.set(':CHECKED', 'checked="checked"');
  234. }
  235. else {
  236. tpl.set(':CHECKED', '');
  237. }
  238. return tpl.finalize();
  239. }
  240. App.HTML.Build.web_domain_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', 'web_domain');
  247. tpl = App.HTML.setTplKeys(tpl, o);
  248. if (App.Constants.SUSPENDED_YES == o.SUSPEND) {
  249. var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general');
  250. }
  251. else {
  252. var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general');
  253. }
  254. tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
  255. return tpl.finalize();
  256. }
  257. App.HTML.Build.web_domain_form = function(options, id)
  258. {
  259. if('undefined' == typeof App.Env.initialParams) {
  260. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  261. }
  262. var tpl = App.Templates.get('FORM', 'web_domain');
  263. tpl.set(':source', options);
  264. tpl.set(':id', id || '');
  265. options = App.Helpers.evalJSON(options) || {};
  266. if (App.Helpers.isEmpty(options)) {
  267. tpl.set(':title', 'New WEB domain');
  268. tpl.set(':save_button', 'ADD');
  269. }
  270. else {
  271. tpl.set(':title', 'Edit WEB domain');
  272. tpl.set(':save_button', 'SAVE');
  273. }
  274. options = !App.Helpers.isEmpty(options) ? options : App.Empty.WEB_DOMAIN;
  275. tpl = App.HTML.setTplKeys(tpl, options, true);
  276. tpl = App.HTML.Build.web_domain_selects(tpl, options);
  277. return tpl.finalize();
  278. }
  279. App.HTML.Build.mail_entry = function(o, key)
  280. {
  281. var processed_data = {
  282. DOMAIN: key
  283. };
  284. var o = $.extend(o, processed_data);
  285. var tpl = App.Templates.get('ENTRY', 'mail');
  286. tpl = App.HTML.setTplKeys(tpl, o);
  287. return tpl.finalize();
  288. }
  289. App.HTML.Build.db_entry = function(o, key)
  290. {
  291. var user_list_html = [];
  292. $(o['USERS']).each(function(i, o)
  293. {
  294. var tpl = App.Templates.get('USER_ITEM', 'db');
  295. tpl.set(':NAME', o);
  296. user_list_html.push(tpl.finalize());
  297. });
  298. var wrapper = App.Templates.get('USER_ITEMS_WRAPPER', 'db');
  299. wrapper.set(':CONTENT', user_list_html.done());
  300. var processed_data = {
  301. 'USER_LIST': wrapper.finalize(),
  302. 'USERS': o['USERS'].length || 0,
  303. 'U_DISK_PERCENTAGE' : o.U_DISK > 0 ? o.U_DISK / o.DISK * 100 : 0.01,
  304. 'DISK_MEASURE': App.Helpers.getMbHumanMeasure(o.DISK),
  305. 'DISK': App.Helpers.getMbHuman(o.DISK)
  306. };
  307. var o = $.extend(o, processed_data);
  308. var tpl = App.Templates.get('ENTRY', 'db');
  309. tpl = App.HTML.setTplKeys(tpl, o);
  310. return tpl.finalize();
  311. }
  312. App.HTML.Build.db_form = function(options, id)
  313. {
  314. var in_edit = false;
  315. if (!App.Helpers.isEmpty(options)) {
  316. in_edit = true;
  317. }
  318. if('undefined' == typeof App.Env.initialParams) {
  319. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  320. }
  321. var tpl = App.Templates.get('FORM', 'db');
  322. tpl.set(':source', options);
  323. tpl.set(':id', id || '');
  324. options = App.Helpers.evalJSON(options) || {};
  325. if (App.Helpers.isEmpty(options)) {
  326. tpl.set(':title', 'New database');
  327. tpl.set(':save_button', 'ADD');
  328. }
  329. else {
  330. tpl.set(':title', 'Edit database "'+options.DB+'"');
  331. tpl.set(':save_button', 'SAVE');
  332. }
  333. options = !App.Helpers.isEmpty(options) ? options : App.Empty.DB;
  334. if (in_edit == true) {
  335. options.PASSWORD = App.Settings.PASSWORD_IMMUTE;
  336. }
  337. tpl = App.HTML.setTplKeys(tpl, options, true);
  338. tpl = App.HTML.Build.db_selects(tpl, options);
  339. return tpl.finalize();
  340. }
  341. App.HTML.Build.cron_entry = function(o, key)
  342. {
  343. var processed_data = {
  344. DOMAIN: key
  345. };
  346. var o = $.extend(o, processed_data);
  347. var tpl = App.Templates.get('ENTRY', 'cron');
  348. tpl = App.HTML.setTplKeys(tpl, o);
  349. if (App.Constants.SUSPENDED_YES == o.SUSPENDED) {
  350. var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general');
  351. }
  352. else {
  353. var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general');
  354. }
  355. tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
  356. return tpl.finalize();
  357. }
  358. App.HTML.Build.cron_form = function(options, id)
  359. {try{
  360. if('undefined' == typeof App.Env.initialParams) {
  361. return alert('PLease wait a bit. Some background processes are not yet executed. Thank you for patience.');
  362. }
  363. var tpl = App.Templates.get('FORM', 'cron');
  364. tpl.set(':source', options);
  365. tpl.set(':id', id || '');
  366. options = App.Helpers.evalJSON(options) || {};
  367. if (App.Helpers.isEmpty(options)) {
  368. tpl.set(':title', 'New cron entry');
  369. tpl.set(':save_button', 'ADD');
  370. }
  371. else {
  372. tpl.set(':title', 'Edit cron entry');
  373. tpl.set(':save_button', 'SAVE');
  374. }
  375. options = !App.Helpers.isEmpty(options) ? options : {DAY:'', MONTH: '', WDAY:'',HOUR:'',CMD:'',MIN:''};
  376. tpl = App.HTML.setTplKeys(tpl, options);
  377. /*tpl.set(':id', id || '');
  378. tpl.set(':IP_ADDRESS', options.IP_ADDRESS || '');
  379. tpl.set(':NETMASK', options.NETMASK || '');
  380. tpl.set(':NAME', options.NAME || '');*/
  381. //tpl = App.HTML.Build.ip_selects(tpl, options);
  382. }catch(e){fb.error(e);}
  383. return tpl.finalize();
  384. }
  385. App.HTML.Build.dns_records = function(records)
  386. {
  387. var acc = [];
  388. $.each(records, function(i, record)
  389. {
  390. var record = records[i];
  391. var tpl = App.HTML.Build.dns_subrecord(record);
  392. acc[acc.length++] = tpl.finalize();
  393. });
  394. return acc.done();
  395. }
  396. App.HTML.Build.dns_subrecord = function(record)
  397. {
  398. var tpl = App.Templates.get('SUBENTRY', 'dns');
  399. tpl.set(':RECORD', record.RECORD || '');
  400. tpl.set(':RECORD_VALUE', record.RECORD_VALUE || '');
  401. tpl.set(':RECORD_ID', record.RECORD_ID || '');
  402. //tpl.set(':RECORD_TYPE_VALUE', '');
  403. tpl.set(':RECORD_TYPE', App.HTML.Build.options(App.Env.initialParams.DNS.record.RECORD_TYPE, (record.RECORD_TYPE || -1)));
  404. return tpl;
  405. }
  406. App.HTML.Build.user_selects = function(tpl, options)
  407. {
  408. var acc = [];
  409. // PACKAGE
  410. var pkg = App.Env.initialParams.USERS.PACKAGE;
  411. $.each(pkg, function(val)
  412. {
  413. var tpl = App.Templates.get('select_option', 'general');
  414. tpl.set(':VALUE', val);
  415. tpl.set(':TEXT', pkg[val]);
  416. tpl.set(':SELECTED', val == options.PACKAGE ? 'selected="selected"' : '');
  417. acc[acc.length++] = tpl.finalize();
  418. });
  419. tpl.set(':PACKAGE_OPTIONS', acc.done());
  420. // ROLE
  421. acc = [];
  422. var roles = App.Env.initialParams.USERS.ROLE;
  423. $.each(roles, function(val)
  424. {
  425. var tpl = App.Templates.get('select_option', 'general');
  426. tpl.set(':VALUE', val);
  427. tpl.set(':TEXT', roles[val]);
  428. tpl.set(':SELECTED', val == options.ROLE ? 'selected="selected"' : '');
  429. acc[acc.length++] = tpl.finalize();
  430. });
  431. tpl.set(':ROLE_OPTIONS', acc.done());
  432. // SHELL
  433. acc = [];
  434. var shell = App.Env.initialParams.USERS.SHELL;
  435. $.each(shell, function(val)
  436. {
  437. var tpl = App.Templates.get('select_option', 'general');
  438. tpl.set(':VALUE', val);
  439. tpl.set(':TEXT', shell[val]);
  440. tpl.set(':SELECTED', val == options.SHELL ? 'selected="selected"' : '');
  441. acc[acc.length++] = tpl.finalize();
  442. });
  443. tpl.set(':SHELL_OPTIONS', acc.done());
  444. return tpl;
  445. }
  446. App.HTML.Build.db_selects = function(tpl, options)
  447. {
  448. var acc = [];
  449. // PACKAGE
  450. var items = App.Env.initialParams.DB.TYPE;
  451. $.each(items, function(val)
  452. {
  453. var tpl = App.Templates.get('select_option', 'general');
  454. tpl.set(':VALUE', val);
  455. tpl.set(':TEXT', items[val]);
  456. tpl.set(':SELECTED', val == options.TYPE ? 'selected="selected"' : '');
  457. acc[acc.length++] = tpl.finalize();
  458. });
  459. tpl.set(':TYPE_OPTIONS', acc.done());
  460. // ROLE
  461. acc = [];
  462. var items = App.Env.initialParams.DB.HOST;
  463. $.each(items, function(val)
  464. {
  465. var tpl = App.Templates.get('select_option', 'general');
  466. tpl.set(':VALUE', val);
  467. tpl.set(':TEXT', items[val]);
  468. tpl.set(':SELECTED', val == options.HOST ? 'selected="selected"' : '');
  469. acc[acc.length++] = tpl.finalize();
  470. });
  471. tpl.set(':HOST_OPTIONS', acc.done());
  472. return tpl;
  473. }
  474. App.HTML.Build.ip_selects = function(tpl, options)
  475. {
  476. // OWNER
  477. var users = App.Env.initialParams.IP.OWNER;
  478. var opts = App.HTML.Build.options(users, options.OWNER);
  479. tpl.set(':owner_options', opts);
  480. // STATUS
  481. var opts = App.HTML.Build.options(App.Env.initialParams.IP.STATUSES, options.STATUS);
  482. tpl.set(':status_options', opts);
  483. // INTERFACE
  484. var opts = App.HTML.Build.options(App.Env.initialParams.IP.INTERFACES, options.INTERFACE);
  485. tpl.set(':interface_options', opts);
  486. return tpl;
  487. }
  488. App.HTML.Build.dns_selects = function(tpl, options)
  489. {
  490. try {
  491. // TPL
  492. var obj = App.Env.initialParams.DNS.TPL;
  493. var opts = App.HTML.Build.options(obj, options.TPL);
  494. tpl.set(':TPL', opts);
  495. tpl.set(':TPL_DEFAULT_VALUE', options.TPL || App.Helpers.getFirstKey(obj));
  496. }
  497. catch (e) {
  498. return tpl;
  499. }
  500. return tpl;
  501. }
  502. App.HTML.Build.web_domain_selects = function(tpl, options)
  503. {
  504. try {
  505. // IP
  506. var obj = App.Env.initialParams.WEB_DOMAIN.IP;
  507. var opts = App.HTML.Build.options(obj, options.IP);
  508. tpl.set(':IP_OPTIONS', opts);
  509. // TPL
  510. var obj = App.Env.initialParams.WEB_DOMAIN.TPL;
  511. var opts = App.HTML.Build.options(obj, options.TPL);
  512. tpl.set(':TPL_OPTIONS', opts);
  513. }
  514. catch (e) {
  515. return tpl;
  516. }
  517. return tpl;
  518. }