CTreeView

Classa baktım.

Uygulamayı inceledim.

Click mantığı nasıl olur diye araştırmada takıldım.

Buradan sağolsunlar anlatmışlar, javascript ile children’ı olanların tıklandığında id sini okumayı yapabiliyorsun.

Sorun şurada;

Cookbook da


 echo str_replace(

            '"hasChildren":"0"',

            '"hasChildren":false',

            CTreeView::saveDataAsJson($children);

Kısmında hasChildren “0” değerini “false” yaptığımızda Children’ı olmayanların yanladındaki “+” , “-” açıp kapamaları gelmiyor.

İyi güzel altında bir daha children yoksa gelmesin zaten, ancak öyle yapıncada click’lemeside gidiyor. Click olayı gidince jsden okuduğum id gelmiyor. Id olmadan ona ait bir içerik çağıramıyorum.

Yardımlarınızı bekliyorum.

Herşey doğru zaten sistem bu şekilde çalışıyor

node lar <span> içerisine alındığı için tıklama özelliği kalkıyor. bunu ajaxFillTree action da

foreach veya reg replace ile text alanını salt texten html <a href="?" id="n_ID"> aaa</a> gibi bir şeye çevirmen lazım veya javascript ile node lar yüklenince her li için click eventi oluşturman gerekcek burda dikkat etmen gereken class treeview içerisinde class collapsable olmayan <li> ler için yapıcaksın

:) ben olsam bunu yapardım

Kolay gelsin

Kısa bir yolu yok yani, bir özellik tanımlama ile biticek bir iş değil anladım <_< Teşekkür ederim cevap için.

Belki yardımı olur.

controller


public function actionGetdir() {

	$dir = urldecode($_POST['dir']);

	$root = Yii::app()->controller->module->upload_dir;

	$getd = $root . $dir;


	if (file_exists($getd)) {

		$files = scandir($getd);

		natcasesort($files);

		if (count($files) > 2) {

			echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";

			foreach ($files as $file) {

				if (file_exists($getd . $file) && $file != '.' && $file != '..' && is_dir($getd . $file)) {

					echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($dir . $file) . "/\">" . htmlentities($file) . "</a></li>";

				}

			}

			echo "</ul>";

		}

	}

}

view


<?php echo $this->module->registerJs('jqueryFileTree.js'); ?>

<script type="text/javascript"> 

	$(document).ready( function() {

		$('#filetree').fileTree({

			root: '/',

			script: '<?php echo CController::createUrl("default/getdir")?>',

			token: '<?php echo Yii::app()->request->getCsrfToken()?>',

			multiFolder: false

		}, function(folder) {

			alert(folder);

		});

	});

</script>

jqueryFileTree.js


// jQuery File Tree Plugin

//

// Version 1.01

//

// Cory S.N. LaViska

// A Beautiful Site (hxxp://abeautifulsite.net/)

// 24 March 2008

//

// Visit hxxp://abeautifulsite.net/notebook.php?article=58 for more information

//

// Usage: $('.fileTreeDemo').fileTree( options, callback )

//

// Options:  root           - root folder to display; default = /

//           script         - location of the serverside AJAX file to use; default = jqueryFileTree.php

//           folderEvent    - event to trigger expand/collapse; default = click

//           expandSpeed    - default = 500 (ms); use -1 for no animation

//           collapseSpeed  - default = 500 (ms); use -1 for no animation

//           expandEasing   - easing function to use on expand (optional)

//           collapseEasing - easing function to use on collapse (optional)

//           multiFolder    - whether or not to limit the browser to one subfolder at a time

//           loadMessage    - Message to display while initial tree loads (can be HTML)

//

// History:

//

// 1.01 - updated to work with foreign characters in directory/file names (12 April 2008)

// 1.00 - released (24 March 2008)

//

// TERMS OF USE

// 

// This plugin is dual-licensed under the GNU General Public License and the MIT License and

// is copyright 2008 A Beautiful Site, LLC. 

//

if(jQuery) (function($){

	

	$.extend($.fn, {

		fileTree: function(o, h) {

			// Defaults

			if( !o ) var o = {};

			if( o.root == undefined ) o.root = '/';

			if( o.script == undefined ) o.script = 'default/getdir';

			if( o.folderEvent == undefined ) o.folderEvent = 'click';

			if( o.expandSpeed == undefined ) o.expandSpeed= 200;

			if( o.collapseSpeed == undefined ) o.collapseSpeed= 200;

			if( o.expandEasing == undefined ) o.expandEasing = null;

			if( o.collapseEasing == undefined ) o.collapseEasing = null;

			if( o.multiFolder == undefined ) o.multiFolder = true;

			if( o.loadMessage == undefined ) o.loadMessage = 'Loading...';

			

			$(this).each( function() {

				

				function showTree(c, t) {

					$(c).addClass('wait');

					$(".jqueryFileTree.start").remove();

					$.post(o.script, { dir: t, YII_CSRF_TOKEN: o.token}, function(data) {

						$(c).find('.start').html('');

						$(c).removeClass('wait').append(data);

						if( o.root == t ) $(c).find('UL:hidden').show(); else $(c).find('UL:hidden').slideDown({ duration: o.expandSpeed, easing: o.expandEasing });

						bindTree(c);

					});

				}

				

				function bindTree(t) {

					$(t).find('LI A').bind(o.folderEvent, function() {

						if( $(this).parent().hasClass('directory') ) {

							if( $(this).parent().hasClass('collapsed') ) {

								// Expand

								if( !o.multiFolder ) {

									$(this).parent().parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });

									$(this).parent().parent().find('LI.directory').removeClass('expanded').addClass('collapsed');

								}

								$(this).parent().find('UL').remove(); // cleanup

								showTree( $(this).parent(), escape($(this).attr('rel').match( /.*\// )) );

								$(this).parent().removeClass('collapsed').addClass('expanded');

							} else {

								// Collapse

								$(this).parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });

								$(this).parent().removeClass('expanded').addClass('collapsed');

							}

						} else {

							h($(this).attr('rel'));

						}

						return false;

					});

					// Prevent A from triggering the # on non-click events

					if( o.folderEvent.toLowerCase != 'click' ) $(t).find('LI A').bind('click', function() { return false; });

				}

				// Loading message

				$(this).html('<ul class="jqueryFileTree start"><li class="wait">' + o.loadMessage + '<li></ul>');

				// Get the initial file list

				showTree( $(this), escape(o.root) );

			});

		}

	});

	

})(jQuery);

Teşekkürler, tam olarak işimi göremedi. Sanırım ben başaramadım. Ben veritabanından yolları okuyorum, direk dizin içinden değil. Ama çok güzel örnek gösterdiğin çok yararlı oldu benim için.

Güzel örnekler vardı yukarıda, bunu da buraya eklemek istedim. Yapmak için uğraştığım şey bu örnekte daha kolay geldi. Dizi tanımlayıp dizide isim yerine <span onclick="alert(0);"> Name </span> şeklinde tanımladığında, ağaç yapısı senin dizin ile oluştuğu için "onclick" özelliği eklediklerin tıklanabilir oluyor içlerine istediğini koy istersen bir fonksiyona parametre yolla o yönlendirsin istersen direk işlem yap.