/src/fireice/Backend/Tree/Resources/public/js/dialogs.js

https://github.com/FireIce/fireice · JavaScript · 997 lines · 786 code · 198 blank · 13 comment · 87 complexity · f50732ba721eeb9acc1fd51f89e3e8b0 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////
  2. // Пользователи //
  3. ///////////////////////////////////////////////////////////////////////
  4. var id_user_edit;
  5. var id_group_edit;
  6. function getUsers()
  7. {
  8. setTitle('Список пользователей');
  9. action = undefined;
  10. id_action = undefined;
  11. $('#progress_id').show();
  12. $('#dialog_id').slideUp(100).html('');
  13. $.ajax({
  14. url: options.url + 'users/getusers',
  15. data: '',
  16. type: 'get',
  17. async: true,
  18. dataType : "json",
  19. cache: false,
  20. success: function (answer, textStatus) {
  21. if (answer === 'error') {
  22. errorAndToMain('Ошибка!', '#ff0000');
  23. } else if (answer === 'no_rights') {
  24. errorAndToMain('Нет прав!', '#ff0000');
  25. } else {
  26. getUsersData_callback(answer);
  27. }
  28. }
  29. });
  30. }
  31. function getUsersData_callback(answer)
  32. {
  33. var template = getTemplate(options.assets + '/tree/templates/users/users.html');
  34. var list_template = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/users/users_list.html') + '</script>';
  35. $('#dialog_id').html('');
  36. $( template ).tmpl( {add: answer.edit_right} ).appendTo('#dialog_id');
  37. for (var i=0; i<answer.list.length; i++) {
  38. answer.list[i]['edit_right'] = answer.edit_right;
  39. answer.list[i]['delete_right'] = answer.delete_right;
  40. }
  41. $( list_template ).tmpl( answer.list ).appendTo( '#users_list_id' );
  42. $('#progress_id').hide();
  43. $('#dialog_id .edit_user').click(function(){
  44. $.history.load('action/user_edit/id/' + $(this).attr('id_user'));
  45. });
  46. $('#dialog_id .del_user').click(function(){
  47. deleteUser( $(this).attr('id_user') );
  48. });
  49. $('#dialog_id .add_button').click(function(){
  50. $.history.load('action/user_add');
  51. });
  52. $('#dialog_id .cancel_button').click(function(){
  53. $.history.load('');
  54. });
  55. $('#dialog_id').slideDown(100);
  56. }
  57. function editUser(id_user)
  58. {
  59. $('#progress_id').show();
  60. $('#dialog_id').slideUp(100).html('');
  61. id_user_edit = id_user;
  62. answer = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/users/createedit_user.html') + '</script>';
  63. var arr = new Object();
  64. arr.action_title = 'Редактирование пользователя';
  65. $( answer ).tmpl( arr ).appendTo( '#dialog_id' );
  66. $.ajax({
  67. url: options.url + 'users/getuserdata',
  68. data: 'id=' + id_user_edit,
  69. type: 'get',
  70. async: true,
  71. dataType : "json",
  72. cache: false,
  73. success: function (answer, textStatus) {
  74. if (answer === 'error') {
  75. errorAndToMain('Ошибка!', '#ff0000');
  76. } else if (answer === 'no_rights') {
  77. errorAndToMain('Нет прав!', '#ff0000');
  78. } else {
  79. getUserData_callback(answer);
  80. }
  81. }
  82. });
  83. }
  84. function getUserData_callback(answer)
  85. {
  86. setTitle('Редактирование пользователя ' + answer.login.value);
  87. var plugin_templates = loadPlugins(answer);
  88. for (var plugin in answer)
  89. {
  90. var template = '<script type="text/x-jquery-tmpl">' + plugin_templates[plugin] + '</script>';
  91. $( template ).tmpl( answer[plugin] ).appendTo( '#dialog_id .data');
  92. }
  93. $('#progress_id').hide();
  94. $('#dialog_id').slideDown(100);
  95. $('#dialog_id .submit_button').click(function(){
  96. editUserSubmit();
  97. });
  98. $('#dialog_id .cancel_button').click(function(){
  99. $.history.load('action/users_list');
  100. });
  101. }
  102. function editUserSubmit()
  103. {
  104. data = '';
  105. $('#dialog_id input[type=text]').each(function(){
  106. field = $(this).attr('name');
  107. data += field + '=' + $(this).val() + '&';
  108. });
  109. $('#dialog_id select').each(function(){
  110. field = $(this).attr('name');
  111. data += field + '=' + $(this).val() + '&';
  112. });
  113. data += 'id=' + id_user_edit;
  114. $.ajax({
  115. url: options.url + 'users/edit',
  116. data: data,
  117. type: 'post',
  118. async: true,
  119. dataType : "json",
  120. cache: false,
  121. success: function (answer, textStatus) {
  122. editUserSubmit_callback(answer);
  123. }
  124. });
  125. }
  126. function editUserSubmit_callback(answer)
  127. {
  128. if (answer == 'ok')
  129. {
  130. showMessage('Сохранено!', '#38bc50');
  131. $.history.load('action/users_list');
  132. } else {
  133. showMessage('Ошибка!', '#ff0000');
  134. }
  135. }
  136. function addUser()
  137. {
  138. setTitle('Добавление нового пользователя');
  139. $('#progress_id').show();
  140. $('#dialog_id').slideUp(100).html('');
  141. answer = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/users/createedit_user.html') + '</script>';
  142. var arr = new Object();
  143. arr.action_title = 'Создание нового пользователя';
  144. $( answer ).tmpl( arr ).appendTo( '#dialog_id' );
  145. $.ajax({
  146. url: options.url + 'users/getuserdata',
  147. data: 'id=-1',
  148. type: 'get',
  149. async: true,
  150. dataType : "json",
  151. cache: false,
  152. success: function (answer, textStatus) {
  153. if (answer === 'error') {
  154. errorAndToMain('Ошибка!', '#ff0000');
  155. } else if (answer === 'no_rights') {
  156. errorAndToMain('Нет прав!', '#ff0000');
  157. } else {
  158. getCreateUserData_callback(answer);
  159. }
  160. }
  161. });
  162. }
  163. function getCreateUserData_callback(answer)
  164. {
  165. var plugin_templates = loadPlugins(answer);
  166. for (var plugin in answer)
  167. {
  168. var template = '<script type="text/x-jquery-tmpl">' + plugin_templates[plugin] + '</script>';
  169. $( template ).tmpl( answer[plugin] ).appendTo( '#dialog_id .data');
  170. }
  171. $('#progress_id').hide();
  172. $('#dialog_id').slideDown(100);
  173. $('#dialog_id .submit_button').click(function(){
  174. addUserSubmit();
  175. });
  176. $('#dialog_id .cancel_button').click(function(){
  177. $.history.load('action/users_list');
  178. });
  179. }
  180. function addUserSubmit()
  181. {
  182. data = '';
  183. $('#dialog_id input[type=text]').each(function(){
  184. field = $(this).attr('name');
  185. data += field + '=' + $(this).val() + '&';
  186. });
  187. $('#dialog_id select').each(function(){
  188. field = $(this).attr('name');
  189. data += field + '=' + $(this).val() + '&';
  190. });
  191. data = data.slice(0, -1);
  192. $.ajax({
  193. url: options.url + 'users/add',
  194. data: data,
  195. type: 'post',
  196. async: true,
  197. dataType : "json",
  198. cache: false,
  199. success: function (answer, textStatus) {
  200. addUserSubmit_callback(answer);
  201. }
  202. });
  203. }
  204. function addUserSubmit_callback(answer)
  205. {
  206. if (answer == 'ok')
  207. {
  208. showMessage('Пользователь добавлен!', '#38bc50');
  209. $.history.load('action/users_list');
  210. } else {
  211. showMessage('Ошибка!', '#ff0000');
  212. }
  213. }
  214. function deleteUser($id_user)
  215. {
  216. if (confirm('Вы уверены?'))
  217. {
  218. $.ajax({
  219. url: options.url + 'users/delete',
  220. data: 'id=' + $id_user,
  221. type: 'post',
  222. async: true,
  223. dataType : "json",
  224. cache: false,
  225. success: function (answer, textStatus) {
  226. deleteUser_callback(answer);
  227. }
  228. });
  229. }
  230. }
  231. function deleteUser_callback(answer)
  232. {
  233. if (answer == 'ok') {
  234. showMessage('Пользователь удалён!', '#38bc50');
  235. getUsers();
  236. } else if (answer == 'no_rights') {
  237. showMessage('Нет прав!', '#ff0000');
  238. } else {
  239. showMessage('Ошибка!', '#ff0000');
  240. }
  241. }
  242. ///////////////////////////////////////////////////////////////////////
  243. // Группы //
  244. ///////////////////////////////////////////////////////////////////////
  245. function getGroups()
  246. {
  247. setTitle('Список групп');
  248. action = undefined;
  249. id_action = undefined;
  250. $('#progress_id').show();
  251. $('#dialog_id').slideUp(100).html('');
  252. $.ajax({
  253. url: options.url + 'groups/getgroups',
  254. data: '',
  255. type: 'get',
  256. async: true,
  257. dataType : "json",
  258. cache: false,
  259. success: function (answer, textStatus) {
  260. if (answer === 'error') {
  261. errorAndToMain('Ошибка!', '#ff0000');
  262. } else if (answer === 'no_rights') {
  263. errorAndToMain('Нет прав!', '#ff0000');
  264. } else {
  265. getGroupsData_callback(answer);
  266. }
  267. }
  268. });
  269. }
  270. function getGroupsData_callback(answer)
  271. {
  272. var template = getTemplate(options.assets + '/tree/templates/groups/groups.html');
  273. var list_template = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/groups/groups_list.html') + '</script>';
  274. $('#dialog_id').html('');
  275. $( template ).tmpl( {add: answer.edit_right} ).appendTo( '#dialog_id' );
  276. for (var i=0; i<answer.list.length; i++) {
  277. answer.list[i]['edit_right'] = answer.edit_right;
  278. answer.list[i]['delete_right'] = answer.delete_right;
  279. }
  280. $( list_template ).tmpl( answer.list ).appendTo( '#groups_list_id' );
  281. $('#progress_id').hide();
  282. $('#dialog_id .edit_group').click(function(){
  283. $.history.load('action/group_edit/id/' + $(this).attr('id_group'));
  284. });
  285. $('#dialog_id .del_group').click(function(){
  286. deleteGroup( $(this).attr('id_group') );
  287. });
  288. $('#dialog_id .add_button').click(function(){
  289. $.history.load('action/group_add');
  290. });
  291. $('#dialog_id .cancel_button').click(function(){
  292. $.history.load('');
  293. });
  294. $('#dialog_id').slideDown(100);
  295. }
  296. function editGroup(id_group)
  297. {
  298. $('#progress_id').show();
  299. $('#dialog_id').slideUp(100).html('');
  300. id_group_edit = id_group;
  301. template = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/groups/createedit_group.html') + '</script>';
  302. var arr = new Object();
  303. arr.action_title = 'Редактирование Группы';
  304. $( template ).tmpl( arr ).appendTo( '#dialog_id' );
  305. $.ajax({
  306. url: options.url + 'groups/getgroupdata',
  307. data: 'id=' + id_group,
  308. type: 'get',
  309. async: true,
  310. dataType : "json",
  311. cache: false,
  312. success: function (answer, textStatus) {
  313. if (answer === 'error') {
  314. errorAndToMain('Ошибка!', '#ff0000');
  315. } else if (answer === 'no_rights') {
  316. errorAndToMain('Нет прав!', '#ff0000');
  317. } else {
  318. getGroupData_callback(answer);
  319. }
  320. }
  321. });
  322. }
  323. function getGroupData_callback(answer)
  324. {
  325. setTitle('Редактирование группы "' + answer.title.value + '"');
  326. var plugin_templates = loadPlugins(answer);
  327. for (var plugin in answer)
  328. {
  329. var template = '<script type="text/x-jquery-tmpl">' + plugin_templates[plugin] + '</script>';
  330. $( template ).tmpl( answer[plugin] ).appendTo( '#dialog_id .data');
  331. }
  332. $('#progress_id').hide();
  333. $('#dialog_id').slideDown(100);
  334. $('#dialog_id .submit_button').click(function(){
  335. editGroupSubmit();
  336. });
  337. $('#dialog_id .cancel_button').click(function(){
  338. $.history.load('action/groups_list');
  339. });
  340. }
  341. function editGroupSubmit()
  342. {
  343. data = '';
  344. $('#dialog_id input[type=text]').each(function(){
  345. field = $(this).attr('name');
  346. data += field + '=' + $(this).val() + '&';
  347. });
  348. $('#dialog_id select').each(function(){
  349. field = $(this).attr('name');
  350. data += field + '=' + $(this).val() + '&';
  351. });
  352. $('#dialog_id input[type=checkbox]').each(function(){
  353. field = $(this).attr('name');
  354. data += field + '=' + (($(this).is(':checked'))?'1':'0') + '&';
  355. });
  356. data += 'id=' + id_group_edit;
  357. $.ajax({
  358. url: options.url + 'groups/edit',
  359. data: data,
  360. type: 'post',
  361. async: true,
  362. dataType : "json",
  363. cache: false,
  364. success: function (answer, textStatus) {
  365. editGroupSubmit_callback(answer);
  366. }
  367. });
  368. }
  369. function editGroupSubmit_callback(answer)
  370. {
  371. if (answer == 'ok')
  372. {
  373. showMessage('Сохранено!', '#38bc50');
  374. $.history.load('action/groups_list');
  375. } else {
  376. showMessage('Ошибка!', '#ff0000');
  377. }
  378. }
  379. function addGroup()
  380. {
  381. setTitle('Добавление новой группы');
  382. $('#progress_id').show();
  383. $('#dialog_id').slideUp(100).html('');
  384. template = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/groups/createedit_group.html') + '</script>';
  385. var arr = new Object();
  386. arr.action_title = 'Добавление новой Группы';
  387. $( template ).tmpl( arr ).appendTo( '#dialog_id' );
  388. $.ajax({
  389. url: options.url + 'groups/getgroupdata',
  390. data: 'id=-1',
  391. type: 'get',
  392. async: true,
  393. dataType : "json",
  394. cache: false,
  395. success: function (answer, textStatus) {
  396. if (answer === 'error') {
  397. errorAndToMain('Ошибка!', '#ff0000');
  398. } else if (answer === 'no_rights') {
  399. errorAndToMain('Нет прав!', '#ff0000');
  400. } else {
  401. getCreateGroupData_callback(answer);
  402. }
  403. }
  404. });
  405. }
  406. function getCreateGroupData_callback(answer)
  407. {
  408. var plugin_templates = loadPlugins(answer);
  409. for (var plugin in answer)
  410. {
  411. var template = '<script type="text/x-jquery-tmpl">' + plugin_templates[plugin] + '</script>';
  412. $( template ).tmpl( answer[plugin] ).appendTo( '#dialog_id .data');
  413. }
  414. $('#progress_id').hide();
  415. $('#dialog_id').slideDown(100);
  416. $('#dialog_id .submit_button').click(function(){
  417. addGroupSubmit();
  418. });
  419. $('#dialog_id .cancel_button').click(function(){
  420. $.history.load('action/groups_list');
  421. });
  422. }
  423. function addGroupSubmit()
  424. {
  425. data = '';
  426. $('#dialog_id input[type=text]').each(function(){
  427. field = $(this).attr('name');
  428. data += field + '=' + $(this).val() + '&';
  429. });
  430. $('#dialog_id select').each(function(){
  431. field = $(this).attr('name');
  432. data += field + '=' + $(this).val() + '&';
  433. });
  434. $('#dialog_id input[type=checkbox]').each(function(){
  435. field = $(this).attr('name');
  436. data += field + '=' + (($(this).is(':checked'))?'1':'0') + '&';
  437. });
  438. data = data.slice(0, -1);
  439. $.ajax({
  440. url: options.url + 'groups/add',
  441. data: data,
  442. type: 'post',
  443. async: true,
  444. dataType : "json",
  445. cache: false,
  446. success: function (answer, textStatus) {
  447. if (answer === 'error') {
  448. errorAndToMain('Ошибка!', '#ff0000');
  449. } else if (answer === 'no_rights') {
  450. errorAndToMain('Нет прав!', '#ff0000');
  451. } else {
  452. addGroupSubmit_callback(answer);
  453. }
  454. }
  455. });
  456. }
  457. function addGroupSubmit_callback(answer)
  458. {
  459. if (answer == 'ok')
  460. {
  461. showMessage('Сохранено!', '#38bc50');
  462. $.history.load('action/groups_list');
  463. } else {
  464. showMessage('Ошибка!', '#ff0000');
  465. }
  466. }
  467. function deleteGroup(id_group)
  468. {
  469. if (confirm('Вы уверены?'))
  470. {
  471. $.ajax({
  472. url: options.url + 'groups/delete',
  473. data: 'id=' + id_group,
  474. type: 'post',
  475. async: true,
  476. dataType : "json",
  477. cache: false,
  478. success: function (answer, textStatus) {
  479. deleteGroup_callback(answer);
  480. }
  481. });
  482. }
  483. }
  484. function deleteGroup_callback(answer)
  485. {
  486. if (answer == 'ok')
  487. {
  488. showMessage('Группа удалена!', '#38bc50');
  489. getGroups();
  490. } else if (answer == 'no_rights') {
  491. showMessage('Нет прав!', '#ff0000');
  492. } else {
  493. showMessage('Ошибка!', '#ff0000');
  494. }
  495. }
  496. ///////////////////////////////////////////////////////////////////////
  497. // Права //
  498. ///////////////////////////////////////////////////////////////////////
  499. function rights(id)
  500. {
  501. id_action = id;
  502. $('#progress_id').show();
  503. $('#dialog_id').hide();
  504. $('#dialog_id').html('');
  505. var tmp;
  506. $.ajax({
  507. url: options.url + 'rights/getmodules',
  508. data: 'id=' + id,
  509. async: false,
  510. dataType : "json",
  511. cache: false,
  512. success: function (answer, textStatus) {
  513. if (answer === 'error') {
  514. errorAndToMain('Ошибка!', '#ff0000');
  515. tmp = false;
  516. } else if (answer === 'no_rights') {
  517. errorAndToMain('Нет прав!', '#ff0000');
  518. tmp = false;
  519. } else {
  520. tmp = getRightsData_callback(answer);
  521. }
  522. }
  523. });
  524. return tmp;
  525. }
  526. function getRightsData_callback(answer)
  527. {
  528. if (answer == 'error')
  529. {
  530. showMessage('Ошибка!', '#ff0000');
  531. $('#progress_id').hide();
  532. $.history.load('');
  533. return false;
  534. }
  535. setTitle(answer.node_title + '. Установка прав');
  536. var template = getTemplate(options.assets + '/tree/templates/rights_node/main_window.html');
  537. $( template ).tmpl( answer ).appendTo( '#dialog_id' );
  538. $('#dialog_id .inner').html(options.progress_block_html);
  539. $('#dialog_id .cancel_button').click(function(){
  540. $.history.load('');
  541. });
  542. $('#dialog_id input[type=radio]').click(function(){
  543. $.history.load('action/rights_list/id/' + id_action + '/module/' + $(this).attr('module_id'));
  544. });
  545. $('#progress_id').hide();
  546. $('#dialog_id').show();
  547. return answer['modules'][0]['id'];
  548. }
  549. function showModuleRights(id_mod)
  550. {
  551. id_module = id_mod;
  552. $.ajax({
  553. url: options.url + 'rights/getusers',
  554. data: 'id_node=' + id_action + '&id_module=' + id_module,
  555. type: 'get',
  556. async: true,
  557. dataType : "json",
  558. cache: false,
  559. success: function (answer, textStatus) {
  560. if (answer === 'error') {
  561. errorAndToMain('Ошибка!', '#ff0000');
  562. } else if (answer === 'no_rights') {
  563. errorAndToMain('Нет прав!', '#ff0000');
  564. } else {
  565. showModuleRights_callback(answer);
  566. }
  567. }
  568. });
  569. }
  570. function showModuleRights_callback(answer)
  571. {
  572. var template = '<div>' + getTemplate(options.assets + '/tree/templates/rights_node/users.html') + '</div>';
  573. var list_template = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/rights_node/users_list.html') + '</script>';
  574. $('#dialog_id .inner').html( template );
  575. $( list_template ).tmpl( answer ).appendTo( '#users_list_id' );
  576. $('#users_list_id .edit_rights').click(function(){
  577. $.history.load('action/edit_rights/id/' + id_action + '/module/' + id_module + '/user/' + $(this).attr('id_user'));
  578. });
  579. }
  580. function editRights(id_act, id_mod, id_user)
  581. {
  582. id_action = id_act;
  583. id_user_edit = id_user;
  584. id_module = id_mod;
  585. $('#progress_id').show();
  586. $('#dialog_id').slideUp(100).html('');
  587. $.ajax({
  588. url: options.url + 'rights/getuser',
  589. data: 'id_node=' + id_action + '&id_module=' + id_module + '&id_user=' + id_user,
  590. type: 'get',
  591. async: true,
  592. dataType : "json",
  593. cache: false,
  594. success: function (answer, textStatus) {
  595. if (answer === 'error') {
  596. errorAndToMain('Ошибка!', '#ff0000');
  597. } else if (answer === 'no_rights') {
  598. errorAndToMain('Нет прав!', '#ff0000');
  599. } else {
  600. editRights_callback(answer);
  601. }
  602. }
  603. });
  604. }
  605. function editRights_callback(answer)
  606. {
  607. if (answer == 'error')
  608. {
  609. showMessage('Ошибка!', '#ff0000');
  610. $('#progress_id').hide();
  611. $.history.load('');
  612. return false;
  613. }
  614. setTitle('Установка прав для пользователя ' + answer.user);
  615. var template = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/rights_node/edit_rights.html') + '</script>';
  616. var arr = new Object();
  617. $( template ).tmpl( answer ).appendTo( '#dialog_id' );
  618. var tmp = new Object();
  619. tmp['rights'] = answer.rights;
  620. var plugin_templates = loadPlugins(tmp);
  621. var template = '<script type="text/x-jquery-tmpl">' + plugin_templates['rights'] + '</script>';
  622. $( template ).tmpl( answer['rights'] ).appendTo( '#dialog_id .data');
  623. $('#progress_id').hide();
  624. $('#dialog_id').slideDown(100);
  625. $('#dialog_id .submit_button').click(function(){
  626. editRightsSubmit();
  627. });
  628. $('#dialog_id .cancel_button').click(function(){
  629. $.history.load('action/rights_list/id/' + id_action);
  630. });
  631. }
  632. function editRightsSubmit()
  633. {
  634. data = '';
  635. $('#dialog_id input[type=checkbox]').each(function(){
  636. field = $(this).attr('name');
  637. data += field + '=' + (($(this).is(':checked'))?'1':'0') + '&';
  638. });
  639. data += 'id_node=' + id_action + '&id_module=' + id_module + '&id_user=' + id_user_edit;
  640. $.ajax({
  641. url: options.url + 'rights/edit',
  642. data: data,
  643. type: 'post',
  644. async: true,
  645. dataType : "json",
  646. cache: false,
  647. success: function (answer, textStatus) {
  648. editRightsSubmit_callback(answer);
  649. }
  650. });
  651. }
  652. function editRightsSubmit_callback(answer)
  653. {
  654. if (answer == 'ok')
  655. {
  656. showMessage('Права изменены!', '#38bc50');
  657. $.history.load('action/rights_list/id/' + id_action);
  658. } else {
  659. showMessage('Ошибка!', '#ff0000');
  660. }
  661. }
  662. ///////////////////////////////////////////////////////////////////////
  663. // Сообщения //
  664. ///////////////////////////////////////////////////////////////////////
  665. function getNewMessages()
  666. {
  667. $.ajax({
  668. url: options.url + 'messages/get_new_messages',
  669. data: '',
  670. type: 'get',
  671. async: true,
  672. dataType : "json",
  673. cache: false,
  674. success: function (answer, textStatus) {
  675. getNewMessages_callback(answer);
  676. }
  677. });
  678. }
  679. function getNewMessages_callback(answer)
  680. {
  681. if (answer > 0)
  682. {
  683. $('#messages_link_id b').html(answer);
  684. $('#messages_link_id span').show();
  685. } else {
  686. $('#messages_link_id span').hide();
  687. }
  688. }
  689. function getMessages()
  690. {
  691. setTitle('Список сообщений');
  692. action = undefined;
  693. id_action = undefined;
  694. $('#progress_id').show();
  695. $('#dialog_id').slideUp(100).html('');
  696. $.ajax({
  697. url: options.url + 'messages/getmessages',
  698. data: '',
  699. type: 'get',
  700. async: true,
  701. dataType : "json",
  702. cache: false,
  703. success: function (answer, textStatus) {
  704. getMessages_callback(answer);
  705. }
  706. });
  707. }
  708. function getMessages_callback(answer)
  709. {
  710. var template = getTemplate(options.assets + '/tree/templates/messages/messages.html');
  711. var list_template = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/messages/messages_list.html') + '</script>';
  712. $('#dialog_id').html( template );
  713. $( list_template ).tmpl( answer ).appendTo( '#messages_list_id' );
  714. $('#progress_id').hide();
  715. $('#dialog_id .view_mess').click(function(){
  716. $.history.load('action/message/id/' + $(this).attr('id_mess'));
  717. });
  718. $('#dialog_id .del_mess').click(function(){
  719. deleteMessage($(this).attr('id_mess'));
  720. });
  721. $('#dialog_id .cancel_button').click(function(){
  722. $.history.load('');
  723. });
  724. $('#dialog_id').slideDown(100);
  725. }
  726. function getMessage(id)
  727. {
  728. $('#progress_id').show();
  729. $('#dialog_id').slideUp(100).html('');
  730. $.ajax({
  731. url: options.url + 'messages/getmessage',
  732. data: 'id=' + id,
  733. type: 'post',
  734. async: true,
  735. dataType : "json",
  736. cache: false,
  737. success: function (answer, textStatus) {
  738. getMessage_callback(answer);
  739. }
  740. });
  741. }
  742. function getMessage_callback(answer)
  743. {
  744. if (answer == 'error')
  745. {
  746. showMessage('Ошибка!', '#ff0000');
  747. $('#progress_id').hide();
  748. $.history.load('');
  749. return false;
  750. }
  751. getNewMessages();
  752. template = '<script type="text/x-jquery-tmpl">' + getTemplate(options.assets + '/tree/templates/messages/message.html') + '</script>';
  753. $( template ).tmpl( answer ).appendTo( '#dialog_id' );
  754. $('#progress_id').hide();
  755. $('#dialog_id').slideDown(100);
  756. $('#dialog_id .cancel_button').click(function(){
  757. $.history.load('action/messages_list');
  758. });
  759. }
  760. function deleteMessage(id)
  761. {
  762. if (confirm('Вы уверены?'))
  763. {
  764. $.ajax({
  765. url: options.url + 'messages/delmessage',
  766. data: 'id=' + id,
  767. type: 'post',
  768. async: true,
  769. dataType : "json",
  770. cache: false,
  771. success: function (answer, textStatus) {
  772. deleteMessage_callback(answer);
  773. }
  774. });
  775. }
  776. }
  777. function deleteMessage_callback(answer)
  778. {
  779. if (answer == 'ok')
  780. {
  781. showMessage('Сообщение удалено!', '#38bc50');
  782. getMessages();
  783. getNewMessages();
  784. } else {
  785. showMessage('Ошибка!', '#ff0000');
  786. }
  787. }
  788. // --------------------------------------------------------------------------------------------
  789. $(document).ready(function(){
  790. $('#messages_link_id').click(function(){
  791. $.history.load('action/messages_list');
  792. });
  793. $('#users_link_id').click(function(){
  794. $.history.load('action/users_list');
  795. });
  796. $('#groups_link_id').click(function(){
  797. $.history.load('action/groups_list');
  798. });
  799. });