[qo-modules-dev] [19] add tooltips

[ Thread Index | Date Index | More lists.tuxfamily.org/qo-modules-dev Archives ]


Revision: 19
Author:   ytorres
Date:     2008-11-14 23:03:44 +0100 (Fri, 14 Nov 2008)

Log Message:
-----------
add tooltips

Modified Paths:
--------------
    yannick/main.js
    yannick/php/lib.php
    yannick/php/shortcuts.php
    yannick/shortcuts.js

Added Paths:
-----------
    yannick/home/

Removed Paths:
-------------
    yannick/desktop/


Modified: yannick/main.js
===================================================================
--- yannick/main.js	2008-11-14 22:02:32 UTC (rev 18)
+++ yannick/main.js	2008-11-14 22:03:44 UTC (rev 19)
@@ -8,7 +8,7 @@
 	},
         root: 'items',
 	id: 'id',
-        fields: ['id', 'name', 'originName', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date', dateFormat:'timestamp'}, 'type']
+        fields: ['id', 'name', 'originName', 'url', 'size', 'lastmod', 'type', 'nbItem']
     });
     store.load();
 

Modified: yannick/php/lib.php
===================================================================
--- yannick/php/lib.php	2008-11-14 22:02:32 UTC (rev 18)
+++ yannick/php/lib.php	2008-11-14 22:03:44 UTC (rev 19)
@@ -4,8 +4,10 @@
 
 class shortcut {
 
-    var $desktop   = '../desktop/';
-    var $desktopJs = 'desktop/';
+    var $home      = '../home/'; // When we integrate this component, $home will looks like this : $home = '../member_id'.$memberId.'/home/';
+    var $desktop   = 'desktop/';
+    var $trash     = '.trash/';
+    var $desktopJs = 'home/desktop/';
     var $imgJs     = 'img/';
     var $stateFile = '.shortcutState';
 
@@ -18,7 +20,7 @@
     	$items = array();
 	$i = 0;
 	
-	$d = dir($this->desktop);
+	$d = dir($this->home.$this->desktop);
 	while($name = $d->read()){
 
 	    // Skip this for Linux's users
@@ -28,51 +30,52 @@
 	    if( substr($name, 0, 1) == '.' ) { continue; }
 
 	    // Files
-	    if( is_file($this->desktop.$name) ) {
+	    if( is_file($this->home.$this->desktop.$name) ) {
 
 	      // Images ?
 	      if(preg_match('/\.(jpg|gif|png)$/', $name)) {
 
-		$size = filesize($this->desktop.$name);
-		$lastmod = filemtime($this->desktop.$name)*1000;
+		$stat = stat($this->home.$this->desktop.$name);
 		$items[] = array(
 			    'id'=>$i,
 			    'type'=>'file',
 			    'originName'=>$name,
 			    'name'=>$name,
-			    'size'=>$size,
-			    'lastmod'=>$lastmod,
+			    'nbItem'=>NULL,
+			    'size'=>$stat['size'],
+			    'lastmod'=>date('r', $stat['mtime']),
 			    'url'=>$this->desktopJs.$name
 		);
 
 	      } else {
 	      // Common files
-		$size = filesize($this->desktop.$name);
-		$lastmod = filemtime($this->desktop.$name)*1000;
+		$stat = stat($this->home.$this->desktop.$name);
 		$items[] = array(
 			    'id'=>$i,
 			    'type'=>'file',
 			    'originName'=>$name,
 			    'name'=>$name,
-			    'size'=>$size,
-			    'lastmod'=>$lastmod,
+			    'nbItem'=>NULL,
+			    'size'=>$stat['size'],
+			    'lastmod'=>date('r', $stat['mtime']),
 			    'url'=>$this->imgJs.'text.png'
 		);
 
 	      }
-	    } else if( is_dir($this->desktop.$name) ) {
+	    } else if( is_dir($this->home.$this->desktop.$name) ) {
 
 	    // Folders
-	      $size = disk_total_space($this->desktop.$name);
-	      $lastmod = filemtime($this->desktop.$name)*1000;
+	      $nb_item = $this->get_nb_item($this->home.$this->desktop.$name);
+	      $stat = stat($this->home.$this->desktop.$name);
 	      $items[] = array(
 			  'id'=>$i,
 			  'type'=>'folder',
 			  'originName'=>$name,
 			  'name'=>$name,
-			  'size'=>$size,
-			  'lastmod'=>$lastmod,
-			  'url'=>$this->imgJs.'folder'
+			  'nbItem'=>$nb_item,
+			  'size'=>$stat['size'],
+			  'lastmod'=>date('r', $stat['mtime']),
+			  'url'=>($nb_item > 0) ? $this->imgJs.'folder_open.png' : $this->imgJs.'folder.png'
 	      );
 
 	    }
@@ -83,7 +86,21 @@
 	return $items;
     
     } //get_files
+    
+    public function get_nb_item($dir) {
+      $nb_item = 0;
+      $d = dir($dir);
+	while($name = $d->read()){
+	
+	    // Skip this for Linux's users
+	    if( $name == '..' || $name == '.' ) { continue; }
+	    $nb_item ++;
 
+	}
+      $d->close();
+      return $nb_item;
+    }
+
     public function get_desktop_items() {
 
 	$o = array('items'=>$this->get_files());
@@ -91,13 +108,13 @@
 
     } // get_desktop_items
 
-    public function get_state() {
+    public function get_icon_position() {
 
       $state = Array("success" => true);
 
-      if( !is_file($this->desktop.$this->stateFile) ) { echo "{success:false}"; }
+      if( !is_file($this->home.$this->desktop.$this->stateFile) ) { echo "{success:false}"; }
       else {
-	$content = file_get_contents($this->desktop.$this->stateFile);
+	$content = file_get_contents($this->home.$this->desktop.$this->stateFile);
 
 	$xml = new SimpleXMLElement($content);
 
@@ -113,32 +130,67 @@
       }
     }
 
+    public function set_icon_position($newPosition) {
+
+    $newPosition = str_replace('\"', '"', $newPosition);
+
+      // We rebuild the file
+      $file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+      <items>
+      ";
+
+      $newPosition = json_decode($newPosition, true);
+
+      for( $i=0; $i < count($newPosition); $i++ ) {
+	$file .= "
+	<element>
+	  <filename>".$newPosition[$i]['originName']."</filename>
+	  <posx>".$newPosition[$i]['x']."</posx>
+	  <posy>".$newPosition[$i]['y']."</posy>
+	</element>
+	";
+      }
+
+      $file .= "
+      </items>";
+
+      $fp = fopen($this->home.$this->desktop.$this->stateFile, 'w');
+      fwrite($fp, $file);
+      fclose($fp);
+
+    }
+
     public function fs_move_to($FileName, $to) {
-      rename($this->desktop.$FileName, $this->desktop.$to.'/'.$FileName);
+      rename($this->home.$this->desktop.$FileName, $this->home.$this->desktop.$to.'/'.$FileName);
     }
     
     public function fs_remove_item($name, $type) {
       if( $type == 'folder' ) {
-	@rmdir($this->desktop.$name) or die('{success:false, msg:"dir not empty"}');
+	@rmdir($this->home.$this->desktop.$name) or die('{success:false, msg:"dir not empty"}');
 	$o->success = true;
 	echo json_encode($o);
       }
+      if( $type == 'file' ) {
+	@unlink($this->home.$this->desktop.$name) or die('{success:false, msg:"error on delete"}');
+	$o->success = true;
+	echo json_encode($o);
+      }
     }
 
     public function fs_new_item($name, $type) {
     
       if( $type == 'folder' ) {
 	// New folder
-	if( !is_dir($this->desktop.$name) ) {
+	if( !is_dir($this->home.$this->desktop.$name) ) {
 
-	  mkdir($this->desktop.$name, 0777);
+	  mkdir($this->home.$this->desktop.$name, 0777);
 	  $item = array(
 	    'id'=>uniqid(),
 	    'type'=>'folder',
 	    'originName'=>$name,
 	    'name'=>$name,
-	    'size'=>disk_total_space($this->desktop.$name),
-	    'lastmod'=>(filemtime($this->desktop.$name)*1000),
+	    'size'=>disk_total_space($this->home.$this->desktop.$name),
+	    'lastmod'=>(filemtime($this->home.$this->desktop.$name)*1000),
 	    'url'=>$this->imgJs.'folder'
 	  );
 	  $o->success = true;
@@ -150,18 +202,18 @@
 	}
       } else if ( $type == 'file' ) {
 	// New file
-        if( !is_file($this->desktop.$name) ) {
+        if( !is_file($this->home.$this->desktop.$name) ) {
 
-	touch($this->desktop.$name, 0777);
-	chmod($this->desktop.$name, 0777);
+	touch($this->home.$this->desktop.$name, 0777);
+	chmod($this->home.$this->desktop.$name, 0777);
 
 	$item = array(
 	  'id'=>uniqid(),
 	  'type'=>'file',
 	  'originName'=>$name,
 	  'name'=>$name,
-	  'size'=>filesize($this->desktop.$name),
-	  'lastmod'=>(filemtime($this->desktop.$name)*1000),
+	  'size'=>filesize($this->home.$this->desktop.$name),
+	  'lastmod'=>(filemtime($this->home.$this->desktop.$name)*1000),
 	  'url'=>$this->imgJs.'text.png'
 	);
 	$o->success = true;
@@ -178,7 +230,7 @@
 
       $o->success = false;
 
-      @rename($this->desktop.$originName, $this->desktop.$newName) or die(json_encode($o));
+      @rename($this->home.$this->desktop.$originName, $this->home.$this->desktop.$newName) or die(json_encode($o));
 
       $o->success = true;
       $o->newName = $newName;

Modified: yannick/php/shortcuts.php
===================================================================
--- yannick/php/shortcuts.php	2008-11-14 22:02:32 UTC (rev 18)
+++ yannick/php/shortcuts.php	2008-11-14 22:03:44 UTC (rev 19)
@@ -3,10 +3,9 @@
 // Call the class
 include "lib.php";
 
-$o = new shortcut();
-
 $what = $_POST['what'];
 
+$o = new shortcut();
 
 switch ($what) {
 
@@ -14,8 +13,8 @@
 	$o->get_desktop_items();
 	break;
 
-  case 'get-state' :
-	$o->get_state();
+  case 'get-icon-position' :
+	$o->get_icon_position();
 	break;
 
   case 'move-to' :
@@ -33,6 +32,10 @@
   case 'remove-item' :
 	$o->fs_remove_item($_POST['name'], $_POST['type']);
 	break;
+
+  case 'set-icon-position' :
+	$o->set_icon_position($_POST['newPosition']);
+	break;
 }
 
 ?>
\ No newline at end of file

Modified: yannick/shortcuts.js
===================================================================
--- yannick/shortcuts.js	2008-11-14 22:02:32 UTC (rev 18)
+++ yannick/shortcuts.js	2008-11-14 22:03:44 UTC (rev 19)
@@ -41,7 +41,7 @@
 
     prepareData: function(data) {
 	data.shortName = Ext.util.Format.ellipsis(data.name, 15);
-	data.sizeString = Ext.util.Format.fileSize(data.size);
+	//data.sizeString = Ext.util.Format.fileSize(data.size);
 	//data.dateString = data.lastmod.format("m/d/Y g:i a");
 	return data;
     },
@@ -65,6 +65,9 @@
         // Init Drag ShortCuts
 	this.DDInit();
 	
+	// Init toolTip for each item
+	this.ToolTipInit();
+	
 	// Init Editor for the label
         this.getEl().on('dblclick', this.LabelEditorInit, this, {delegate: 'span.x-editable'});
 	
@@ -81,7 +84,49 @@
 	this.ownerCt.on('resize', function() { this._ctxViewArrange('ifOut', this) }, this);
     },
 
+    ToolTipInit: function() {
 
+      Ext.QuickTips.init();
+      var nodes = this.getNodes();
+
+      Ext.each(nodes, function(node) {
+
+	//console.log(view);
+	this.ToolTipBuild(node);
+
+      }, this);
+    },
+
+    ToolTipBuild : function(node) {
+    	var record = this.store.getAt(this.indexOf(node));
+
+	// We build the content of the QuickTips
+	var TTcontent, TTtitle;
+	TTtitle = '<div style="text-align: center">'+record.data['name']+'</div><hr/>';
+	TTcontent = "Name : "+record.data['name'] + "<br />Type : "+record.data['type']+"<br/>Size : "+Ext.util.Format.fileSize(record.data['size'])+"<br/>Modified : "+Ext.util.Format.date(record.data['lastmod'], "m/d/Y g:i a");
+
+	// We place this QuickTips under the img & text
+	var itemImg = Ext.DomQuery.selectNode("div[@id='"+node.id+"'] > div > img");
+	var itemText = Ext.DomQuery.selectNode("div[@id='"+node.id+"'] > span");
+
+	new Ext.ToolTip({
+	    target: itemImg,
+	    title: TTtitle,
+	    //width:200,
+	    html: TTcontent,
+	    trackMouse:true
+	});
+
+	new Ext.ToolTip({
+	    target: itemText,
+	    title: TTtitle,
+	    //width:200,
+	    html: TTcontent,
+	    trackMouse:true
+	});
+
+    },
+
     // Drag & Drop
     DDInit : function() {
 
@@ -126,22 +171,26 @@
 	// Drag over a valid node target
 	dd1.dd.onDragOver = function(e, targetId) {
 
-		var record = view.getRecord(view.getNode(targetId));
+		var node = view.getNode(targetId);
+		var record = view.getRecord(node);
 
 		if( record.data['type'] == 'folder' && targetId != this.id ) {
 			// We switch to open folder
 			Ext.DomQuery.selectNode("div[@id='"+targetId+"'] > div > img").src = 'img/folder_open.png';
+			view.select(node);
 			lastFolder = record;
 		}
 	};
 
 	dd1.dd.onDragOut = function(e, targetId) {
 
-		var record = view.getRecord(view.getNode(targetId));
+		var node = view.getNode(targetId);
+		var record = view.getRecord(node);
 
 		if( record.data['type'] == 'folder' ) {
 			// We switch to normal folder
-			Ext.DomQuery.selectNode("div[@id='"+targetId+"'] > div > img").src = 'img/folder.png';
+			Ext.DomQuery.selectNode("div[@id='"+targetId+"'] > div > img").src = record.data['url'];
+			view.deselect(node);
 			lastFolder = null;
 		}
 	};
@@ -169,8 +218,8 @@
 		    },
 		    success: function(response, options) {
 		    
-		      // We replace the folder icon to the target Folder
-		      Ext.DomQuery.selectNode("div[@id='shortcuts_"+lastFolder.data['id']+"'] > div > img").src = 'img/folder.png';
+		      // We replace the folder icon of the target Folder
+		      Ext.DomQuery.selectNode("div[@id='shortcuts_"+lastFolder.data['id']+"'] > div > img").src = lastFolder.data['url'];
 		    
 		      // We remove the dom and this record from this store
 		      clickEl.setStyle('visibility', 'hidden');
@@ -182,18 +231,7 @@
 
 		} else {
 
-		  // Save the state
-		  Ext.Ajax.request({
-		    scope: this,
-		    url: 'php/set-state.php',
-		    params: {
-		      posX: dragEl.getX(),
-		      posY: dragEl.getY(),
-		      name: originName
-		    },
-		    success: function(response, options) {
-		    }
-		  });
+		  view.setIconPosition();
 
 		}
 	};
@@ -201,12 +239,42 @@
       }, this);
     },
     
+    setIconPosition: function() {
+
+	var nodes = this.getNodes();
+	var newPosition = [];
+	var i = 0;
+
+	Ext.each(nodes, function(node) {
+
+	  var record = this.store.getAt(this.indexOf(node));
+	  var originName = record.data['originName'];
+	  var nodeElX = Ext.get(node.id).getX();
+	  var nodeElY = Ext.get(node.id).getY();
+
+	  newPosition[i] = { 'originName': originName, 'x': nodeElX, 'y': nodeElY };
+	  i ++;
+	}, this);
+
+	Ext.Ajax.request({
+	  scope: this,
+	  url: 'php/shortcuts.php',
+	  params: {
+	    newPosition: Ext.util.JSON.encode(newPosition),
+	    what: 'set-icon-position'
+	  },
+	  success: function(response, options) {
+	  }
+	});
+
+    },
+    
     // Move shortCut onRender
     DDmoveIcon : function() {
 	Ext.Ajax.request({
 	  scope: this,
 	  url: 'php/shortcuts.php',
-	  params: { what:'get-state'},
+	  params: { what:'get-icon-position'},
 	  success: function(response, options) {
 
 	    var o = Ext.util.JSON.decode(response.responseText);
@@ -223,13 +291,12 @@
 		  //Move
 		  Ext.get(node.id).moveTo(o[originName].posX, o[originName].posY, true);
 		}
+	      }, this);
 
-	      }, this);
 	    }
 	 }
 	});
 
-
     },
 
     LaunchApp : function(e, target) {
@@ -440,8 +507,10 @@
 	  }
 	
 	}, this);
-	//TODO
-	this.showMessageWindow('TODO', 'Need to save this new position', 'info');
+	
+	// Set this position
+	var d = new Ext.util.DelayedTask(this.setIconPosition, this);
+	d.delay(1000);
 
       } else {
 
@@ -481,24 +550,9 @@
 	
       }, this);
 
-      // We must now save all this new position
-      var newPosition = [];
-      var i = 0;
-
-      Ext.each(nodes, function(node) {
-	
-	var record = this.store.getAt(this.indexOf(node));
-	var originName = record.data['originName'];
-	var nodeElX = Ext.get(node.id).getX();
-	var nodeElY = Ext.get(node.id).getY();
-
-	newPosition[i] = { 'originName': originName, 'x': nodeElX, 'y': nodeElY };
-	i ++;
-      }, this);
-      
-      //console.log(Ext.util.JSON.encode(newPosition));
-      //TODO
-      this.showMessageWindow('TODO', 'Need to save this new position', 'info');
+	// Set this position
+	var d = new Ext.util.DelayedTask(this.setIconPosition, this);
+	d.delay(1000);
       }
     },
     


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/