html.js 16 KB

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