/** * Return the HTML/script required for this control. Do it only once. * @return string The HTML/javascript required for this control. */ public function pre_out() { $out = ''; if (!FormControlTree::$outpre) { FormControlTree::$outpre = true; $out = <<<CUSTOM_TREE_JS \t\t\t\t<script type="text/javascript"> \$(function(){ \t\$('ol.tree').nestedSortable({ \t\tdisableNesting: 'no-nest', \t\tforcePlaceholderSize: true, \t\thandle: '.handle', \t\titems: 'li.treeitem', \t\topacity: .6, \t\tplaceholder: 'placeholder', \t\ttabSize: 25, \t\ttolerance: 'pointer', \t\ttoleranceElement: '> div' \t}); \t\$('.tree_control').closest('form').submit(function(){ \t\tvar tree_input = \$('.tree_control input[type=hidden]', this); \t\ttree_input.each(function(){ \t\t\tvar tree_input = \$(this); \t\t\tvar data = tree_input.siblings().nestedSortable('toArray', {startDepthCount: 1}); \t\t\tvar comma = ''; \t\t\tvar v = ''; \t\t\tfor(var i in data) { \t\t\t\tif(data[i].item_id != 'root') { \t\t\t\t\tv += comma + '{"id":"' + parseInt(data[i].item_id) + '","left":"' + (parseInt(data[i].left)-1) + '","right":"' + (parseInt(data[i].right)-1) + '"}'; \t\t\t\t\tcomma = ','; \t\t\t\t} \t\t\t} \t\t\tv = '[' + v + ']'; \t\t\ttree_input.val(v); \t\t}); \t}); }); \t\t\t\t</script> CUSTOM_TREE_JS; } return $this->controls_js($out); }
/** * Return the HTML/script required for this control. Do it only once. * @return string The HTML/javascript required for this control. */ public function pre_out() { $out = ''; if ( !FormControlTree::$outpre ) { FormControlTree::$outpre = true; $out = <<< CUSTOM_TREE_JS <script type="text/javascript"> $(document).ready(function(){ $('ol.tree').nestedSortable({ disableNesting: 'no-nest', forcePlaceholderSize: true, handle: 'div', items: 'li', opacity: .6, placeholder: 'placeholder', tabSize: 25, tolerance: 'pointer', toleranceElement: '> div' }); $('.tree_submitted').closest('form').submit(function(){ var tree_input = $('.tree_submitted', this); var data = tree_input.siblings().nestedSortable('toArray', {startDepthCount: 1}); var comma = ''; var v = ''; for(var i in data) { if(data[i].item_id != 'root') { v += comma + '{"id":"' + parseInt(data[i].item_id) + '","left":"' + (parseInt(data[i].left)-1) + '","right":"' + (parseInt(data[i].right)-1) + '"}'; comma = ','; } } v = '[' + v + ']'; tree_input.val(v); }); }); </script> CUSTOM_TREE_JS; } return $out; }