Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. <a href="javascript:;" class="<?php if($value['collapsed']=='yes') echo 'expand'; else echo 'collapse';?>" onclick="constructAjaxTree('<?php echo $value['_id']?>','<?php echo $value['code']?>');"></a>
  2.  
  3. function constructAjaxTree(aspectid,aspectcode)
  4. {
  5.  
  6. if ($('.tag_input').find('.tag').length)
  7. {
  8. var elements = [];
  9.  
  10. //iterates through each input field and pushes the name to the array
  11. $(".tag_input").children(".tag").each(function() {
  12. var id = $(this).attr("id");
  13. elements.push(id);
  14. });
  15.  
  16. var geographylevel='';
  17. $.post('include/ajax.php', {option: 'checkavailabilitylevel', geography: elements}, function(response){
  18. geographylevel=response;
  19. $("#"+"div_"+aspectid).jstree({
  20. "xml_data" : {
  21. "ajax" : {
  22. "url" : "include/ajax.php?option=constructtree",
  23. "data" : function (n) {
  24. return { aspectcode : aspectcode, geographylevel : geographylevel };
  25.  
  26. }
  27. },
  28. "xsl" : "nest"
  29. },
  30. "plugins" : [ "themes", "xml_data","ui","checkbox","cookies" ],
  31. "checkbox":{"override_ui":true}
  32. }).bind("check_node.jstree", function (event, data) {
  33. // `data.rslt.obj` is the jquery extended node that was clicked
  34. var nodeid= data.rslt.obj.attr("id");
  35. addAspect(nodeid);
  36. });
  37. $("#"+"div_"+aspectid).bind("uncheck_node.jstree", function (event, data) {
  38. // `data.rslt.obj` is the jquery extended node that was clicked
  39. var nodeid=data.rslt.obj.attr("id");
  40. removeAspect(nodeid);
  41. });
  42. $('#'+'div_'+aspectid).delegate(".jstree-open>a", "click.jstree", function(event){
  43. $.jstree._reference(this).close_node(this,false,false);
  44. }).delegate(".jstree-closed>a", "click.jstree", function(event){
  45. $.jstree._reference(this).open_node(this,false,false);$('#')
  46. });
  47.  
  48. });
  49.  
  50.  
  51. }
  52. else
  53. {
  54. alert("Please Select Geography First");
  55. }
  56. }
  57.  
  58. if($_REQUEST['option']=='constructtree')
  59. {
  60. $splittedaspectcode=explode("~",$_REQUEST['aspectcode']);
  61. $xmlDoc = new DOMDocument();
  62. $xmlDoc->preserveWhiteSpace = false;
  63. $xmlDoc->load("../aspect.xml");
  64.  
  65. $xpath = new DOMXPath($xmlDoc);
  66. $query = "//item[@id='".$splittedaspectcode[0]."']";
  67. $nodeList = $xpath->query($query);
  68.  
  69.  
  70. $newDom = new DOMDocument('1.0','UTF-8');
  71. $root = $newDom->createElement('root');
  72. $root = $newDom->appendChild($root);
  73.  
  74.  
  75. foreach ($nodeList as $domElement){
  76. $domNode = $newDom->importNode($domElement, true);
  77. $root->appendChild($domNode);
  78. }
  79.  
  80. //$newDom->save("test.xml");
  81.  
  82. echo $newDom->saveXML();
  83.  
  84.  
  85.  
  86. //constructTree($db,$_REQUEST['aspectcode'],$_REQUEST['geographylevel']);
  87. }
  88.  
  89. <root>
  90. <item id="3" level="1" availabilitylevel="6" >
  91. <content><name><![CDATA[Households]]></name></content>
  92. <item id="3.1" level="2" availabilitylevel="6" class="node">
  93. <content><name><![CDATA[All Households]]></name></content>
  94. <item id="3.1.1" level="3" availabilitylevel="6">
  95. <content><name><![CDATA[Urban]]></name></content>
  96. </item>
  97. <item id="3.1.2" level="3" availabilitylevel="6">
  98. <content><name><![CDATA[Rural]]></name></content>
  99. </item>
  100. </item>
  101. </item>
  102. </root>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement