html.js 18 KB

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