html.js 17 KB

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