/public/javascripts/admin/inits/forgeos_cms/trees.js

https://github.com/webpulser/forgeos_cms · JavaScript · 94 lines · 78 code · 5 blank · 11 comment · 2 complexity · 6bd317b88fb6b092fa3cd56245f1053b MD5 · raw file

  1. jQuery(document).ready(function(){
  2. //init the tree for pages, blocks, widgets
  3. jQuery("#page-tree").tree({
  4. ui: {
  5. theme_path: '/stylesheets/jstree/themes/',
  6. theme_name : 'product_category',
  7. selected_parent_close: false
  8. },
  9. callback: {
  10. onload: function(TREE_OBJ){
  11. tree_id = jQuery(TREE_OBJ.container).attr('id');
  12. jQuery(TREE_OBJ.container).removeClass('tree-default');
  13. }
  14. }
  15. });
  16. // init the category tress
  17. init_category_tree("#page-tree",'PageCategory','/admin/page_categories.json');
  18. init_category_tree("#block-tree",'StaticContentCategory','/admin/static_content_categories.json');
  19. init_category_tree("#widget-tree",'WidgetCategory','/admin/widget_categories.json');
  20. // init the tress for category associations
  21. init_association_block_category_tree('#association-static-content-tree', 'static_content_block');
  22. init_association_block_category_tree('#association-carousel-tree', 'carousel');
  23. init_association_block_category_tree('#association-widget-actuality-tree', 'widget_actuality');
  24. init_association_block_category_tree('#association-widget-faq-tree', 'widget_faq');
  25. // init the trees for page associations
  26. init_association_page_tree('#association-static-content-page-tree', 'static_content_block');
  27. init_association_page_tree('#association-carousel-page-tree', 'carousel');
  28. init_association_page_tree('#association-widget-actuality-page-tree', 'widget_actuality');
  29. init_association_page_tree('#association-widget-faq-page-tree', 'widget_faq');
  30. //init the tree of blocks
  31. jQuery('.blocks-tree').tree({
  32. ui: {
  33. theme_path: '/stylesheets/jstree/themes/',
  34. theme_name : 'block_category',
  35. selected_parent_close: false
  36. },
  37. callback: {
  38. onload: function(TREE_OBJ){
  39. tree_id = jQuery(TREE_OBJ.container).attr('id');
  40. jQuery(TREE_OBJ.container).removeClass('tree-default');
  41. },
  42. onselect: function(NODE,TREE_OBJ){
  43. /*
  44. *Add click function on .small-icons.block items
  45. *Those items are li in blocks/widget tree (in dialog box)
  46. *and close the dialogg box
  47. **/
  48. var link = jQuery(NODE).find('a:first');
  49. if(!link.hasClass('active')){
  50. putInBlockList(link.attr('title'), link.text(), jQuery(NODE).attr('id').substr(6));
  51. closeDialogBox();
  52. jQuery('.selectedPageCol').removeClass('selectedPageCol');
  53. }
  54. return false;
  55. }
  56. }
  57. });
  58. //init the tree of pages
  59. jQuery(".pages-tree").tree({
  60. ui: {
  61. theme_path: '/stylesheets/jstree/themes/',
  62. theme_name : 'page_category',
  63. selected_parent_close: false
  64. },
  65. callback: {
  66. onload: function(TREE_OBJ){
  67. tree_id = jQuery(TREE_OBJ.container).attr('id');
  68. jQuery(TREE_OBJ.container).removeClass('tree-default');
  69. },
  70. onselect: function(NODE,TREE_OBJ){
  71. var link = jQuery(NODE).children('a');
  72. if(!link.hasClass('active')){
  73. var url = jQuery(link).attr('href');
  74. var block_id = url.split('/')[5];
  75. var page_id = get_rails_element_id(NODE);
  76. jQuery.ajax({
  77. url: url,
  78. complete: putInPageList(jQuery(link).text(), jQuery(link).attr('title'), block_id, page_id),
  79. data: 'authenticity_token=' + encodeURIComponent(window._forgeos_js_vars.token),
  80. dataType:'text',
  81. type:'post'
  82. });
  83. closeDialogBox();
  84. }
  85. return false;
  86. }
  87. }
  88. });
  89. });