[qo-modules-dev] [28] trash folder Ok

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


Revision: 28
Author:   ytorres
Date:     2008-11-16 22:14:32 +0100 (Sun, 16 Nov 2008)

Log Message:
-----------
trash folder Ok

Modified Paths:
--------------
    yannick/img/folder.png
    yannick/php/lib.php
    yannick/php/shortcuts.php
    yannick/shortcuts.js

Added Paths:
-----------
    yannick/img/folder_empty.png

Removed Paths:
-------------
    yannick/img/folder_open.png


Modified: yannick/img/folder.png
===================================================================
(Binary files differ)

Added: yannick/img/folder_empty.png
===================================================================
(Binary files differ)


Property changes on: yannick/img/folder_empty.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Deleted: yannick/img/folder_open.png
===================================================================
(Binary files differ)

Modified: yannick/php/lib.php
===================================================================
--- yannick/php/lib.php	2008-11-16 15:30:12 UTC (rev 27)
+++ yannick/php/lib.php	2008-11-16 21:14:32 UTC (rev 28)
@@ -72,7 +72,7 @@
 			  'nbItem'=>$nb_item,
 			  'size'=>$stat['size'],
 			  'lastmod'=>date('r', $stat['mtime']),
-			  'url'=>($nb_item > 0) ? $this->imgJs.'folder_open.png' : $this->imgJs.'folder.png'
+			  'url'=>($nb_item > 0) ? $this->imgJs.'folder.png' : $this->imgJs.'folder_empty.png'
 	      );
 
 	    }
@@ -80,6 +80,19 @@
 	}
 	$d->close();
 	
+	// We add manually the trash folder
+	$nb_item = $this->get_nb_item($this->home.$this->trash);
+	$stat = stat($this->home.$this->trash);
+	$items[] = array(
+		  'id'=>$i,
+		  'type'=>'trash',
+		  'name'=>'Trash',
+		  'nbItem'=>$nb_item,
+		  'size'=>$stat['size'],
+		  'lastmod'=>date('r', $stat['mtime']),
+		  'url'=>($nb_item > 0) ? $this->imgJs.'trash.png' : $this->imgJs.'trash_empty.png'
+	);
+	
 	return $items;
     
     } //get_files
@@ -156,10 +169,25 @@
 
     }
 
-    public function fs_move_to($FileName, $to) {
-      rename($this->home.$this->desktop.$FileName, $this->home.$this->desktop.$to.'/'.$FileName);
+    public function fs_move_to($FileName, $to, $type) {
+      if( $type == 'folder' ) {
+	if( file_exists($this->home.$this->desktop.$to.'/'.$FileName) ) {
+	  echo '{success:false, msg:"the folder already contains an item named <b>'.$FileName.'</b>"}'; exit;
+	} else {
+	  @rename($this->home.$this->desktop.$FileName, $this->home.$this->desktop.$to.'/'.$FileName) or die('{success:false, msg:"unKnow error"}');
+	}
+      } else if( $type == 'trash' ) {
+	if( file_exists($this->home.$this->trash.$FileName) ) {
+	  echo '{success:false, msg:"the trash already contains an item named <b>'.$FileName.'</b>"}'; exit;
+	} else {
+	  @rename($this->home.$this->desktop.$FileName, $this->home.$this->trash.$FileName) or die('{success:false, msg:"unKnow error"}');
+	}
+      }
+
+      $o->success = true;
+      echo json_encode($o);
     }
-    
+
     public function fs_remove_item($name, $type) {
       if( $type == 'folder' ) {
 	@rmdir($this->home.$this->desktop.$name) or die('{success:false, msg:"dir not empty"}');
@@ -180,13 +208,18 @@
 	if( !is_dir($this->home.$this->desktop.$name) ) {
 
 	  mkdir($this->home.$this->desktop.$name, 0777);
+
+	  $nb_item = 0;
+	  $stat = stat($this->home.$this->desktop.$name);
+
 	  $item = array(
 	    'id'=>uniqid(),
 	    'type'=>'folder',
 	    'name'=>$name,
-	    'size'=>disk_total_space($this->home.$this->desktop.$name),
-	    'lastmod'=>(filemtime($this->home.$this->desktop.$name)*1000),
-	    'url'=>$this->imgJs.'folder'
+	    'nbItem'=>0,
+	    'size'=>$stat['size'],
+	    'lastmod'=>date('r', $stat['mtime']),
+	    'url'=>$this->imgJs.'folder_empty.png'
 	  );
 	  $o->success = true;
 	  $o->item = $item;
@@ -202,12 +235,15 @@
 	touch($this->home.$this->desktop.$name, 0777);
 	chmod($this->home.$this->desktop.$name, 0777);
 
+	$stat = stat($this->home.$this->desktop.$name);
+
 	$item = array(
 	  'id'=>uniqid(),
 	  'type'=>'file',
 	  'name'=>$name,
-	  'size'=>filesize($this->home.$this->desktop.$name),
-	  'lastmod'=>(filemtime($this->home.$this->desktop.$name)*1000),
+	  'nbItem'=>NULL,
+	  'size'=>$stat['size'],
+	  'lastmod'=>date('r', $stat['mtime']),
 	  'url'=>$this->imgJs.'text.png'
 	);
 	$o->success = true;

Modified: yannick/php/shortcuts.php
===================================================================
--- yannick/php/shortcuts.php	2008-11-16 15:30:12 UTC (rev 27)
+++ yannick/php/shortcuts.php	2008-11-16 21:14:32 UTC (rev 28)
@@ -18,7 +18,7 @@
 	break;
 
   case 'move-to' :
-	$o->fs_move_to($_POST['name'], $_POST['moveTo']);
+	$o->fs_move_to($_POST['name'], $_POST['moveTo'], $_POST['type']);
 	break;
 
   case 'update-fileName' :

Modified: yannick/shortcuts.js
===================================================================
--- yannick/shortcuts.js	2008-11-16 15:30:12 UTC (rev 27)
+++ yannick/shortcuts.js	2008-11-16 21:14:32 UTC (rev 28)
@@ -14,7 +14,7 @@
     tpl: new Ext.XTemplate(
 	    '<tpl for=".">',
 	    '<div class="thumb-wrap" id="shortcuts_{id}">',
-		'<div class="thumb"><img src="{url}"></div>',
+		'<div class="thumb"><img src="{url}" id="shortcuts_{id}"></div>',
 		'<span class="x-editable">{shortName}</span></div>',
 	    '</tpl>',
 	    '<div class="x-clear"></div>'
@@ -76,7 +76,7 @@
         this.getEl().on('dblclick', this.LaunchApp, this, {delegate: 'div.thumb'});
 	
 	// Move icon
-	this.DDmoveIcon();
+	this.DDmoveIcon(true);
 	
 	// Monitor resize
 	this.ownerCt.on('resize', function() { this._ctxViewArrange('ifOut', this) }, this);
@@ -95,25 +95,31 @@
     },
 
     ToolTipBuild : function(node) {
-    	var record = this.store.getAt(this.indexOf(node));
 
+	var record = this.store.getById(node.id.substr(10, (node.id.length -1)));
 	// 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");
+	
+	if( record.data.type == 'file' ) {
+	  // For file, we don't display nbItem data
+	  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");
+	} else {
+	  TTcontent = "Name : "+record.data.name + "<br />Type : "+record.data.type+"<br/>Size : "+Ext.util.Format.fileSize(record.data.size)+"<br/>Nb Items : "+ record.data.nbItem +"<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({
+	record.tooltipImg = new Ext.ToolTip({
 	    target: itemImg,
 	    title: TTtitle,
 	    html: TTcontent,
 	    trackMouse:true
 	});
 
-	new Ext.ToolTip({
+	record.tooltipText = new Ext.ToolTip({
 	    target: itemText,
 	    title: TTtitle,
 	    html: TTcontent,
@@ -173,9 +179,14 @@
 
 		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';
+			Ext.DomQuery.selectNode("div[@id='"+targetId+"'] > div > img").src = 'img/folder.png';
 			view.select(node);
 			lastFolder = record;
+		} else if( record.data.type == 'trash' && targetId != this.id ) {
+			// We switch to trash
+			Ext.DomQuery.selectNode("div[@id='"+targetId+"'] > div > img").src = 'img/trash.png';
+			view.select(node);
+			lastFolder = record;
 		}
 	};
 
@@ -184,9 +195,9 @@
 		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 = record.data['url'];
+		if( record.data.type == 'folder' || record.data.type == 'trash' ) {
+			// We switch to normal folder / trash
+			Ext.DomQuery.selectNode("div[@id='"+targetId+"'] > div > img").src = record.data.url;
 			view.deselect(node);
 			lastFolder = null;
 		}
@@ -206,23 +217,52 @@
 		  // We move this file to this folder
 
 		  Ext.Ajax.request({
-		    scope: this,
 		    url: 'php/shortcuts.php',
 		    params: {
 		      moveTo: lastFolder.data.name,
 		      name: name,
+		      type: lastFolder.data.type,
 		      what: 'move-to'
 		    },
 		    success: function(response, options) {
 
-		      // We replace the folder icon of the target Folder
-		      Ext.DomQuery.selectNode("div[@id='shortcuts_"+lastFolder.data.id+"'] > div > img").src = lastFolder.data.url;
+		      var o = Ext.util.JSON.decode(response.responseText);
+			if( o.success ) {
 
-		      // We remove the dom and this record from this store
-		      clickEl.setStyle('visibility', 'hidden');
-		      view.store.remove(record);
-		      lastFolder = null;
+			  var clickNode = view.getNode(lastFolder.data.id);
+			  var clickRecord = view.store.getAt(view.indexOf(clickNode));
 
+			  // We replace the folder icon of the target Folder
+			  if( lastFolder.data.type == 'folder' ) {
+			    Ext.DomQuery.selectNode("div[@id='shortcuts_"+lastFolder.data.id+"'] > div > img").src = 'img/folder.png';
+			    clickRecord.set('url', 'img/folder.png');
+			  } else if( lastFolder.data.type == 'trash' ) {
+			    Ext.DomQuery.selectNode("div[@id='shortcuts_"+lastFolder.data.id+"'] > div > img").src = 'img/trash.png';
+			    clickRecord.set('url', 'img/trash.png');
+			  }
+
+			  // We remove the dom and this record from this store
+			  clickEl.setStyle('visibility', 'hidden');
+			  record.tooltipImg.destroy();
+			  record.tooltipText.destroy();
+			  view.store.remove(record);
+
+			  //We replace the icon ; the fact we remove the record from the dom move icon away.
+			  view.DDmoveIcon(false);
+
+			  // We update the nbItem from this record
+			  clickRecord.set('nbItem', (clickRecord.data.nbItem + 1));
+
+			  // We rebuild the tooltip
+			  view.ToolTipBuild(clickNode);
+
+			  // We re-init drag & drop
+			  view.DDstartDrag(clickNode);
+
+			  lastFolder = null;
+		      } else {
+			view.showMessageWindow('Error', o.msg, 'error');
+		      }
 		    }
 		  });
 
@@ -266,7 +306,8 @@
     },
 
     // Move shortCut onRender
-    DDmoveIcon : function() {
+    DDmoveIcon : function(animMove) {
+
 	Ext.Ajax.request({
 	  scope: this,
 	  url: 'php/shortcuts.php',
@@ -284,9 +325,8 @@
 		var name = record.data.name;
 
 		if( o[name] ) {
-		  console.log('on bouge ' + name + ': ' + o[name].posX);
 		  //Move
-		  Ext.get(node.id).moveTo(o[name].posX, o[name].posY, true);
+		  Ext.get(node.id).moveTo(o[name].posX, o[name].posY, animMove);
 		}
 	      }, this);
 
@@ -333,61 +373,69 @@
 
     },
 
-    LabelEditorSave: function(ed, NewValue, item) {
+    LabelEditorSave: function(ed, newName, item) {
         var name = this.store.getById(this.currentRecord).data.name;
 
-	Ext.Ajax.request({
-	  scope: this,
-	  url: 'php/shortcuts.php',
-	  params: {
-	      name: name,
-	      newName: NewValue,
-	      what: 'update-fileName'
-	  },
-	  success: function(response, options) {
-	    var o = Ext.util.JSON.decode(response.responseText);
-	    console.log(this);
-	    if( o.success === true ) {
+	if( ed.startValue != newName ) {
 
-	    var node = this.getNode(this.currentRecord);
-	    var itemY = Ext.get(node.id).getY();
-	    var itemX = Ext.get(node.id).getX();
+	  Ext.Ajax.request({
+	    scope: this,
+	    url: 'php/shortcuts.php',
+	    params: {
+		name: name,
+		newName: newName,
+		what: 'update-fileName'
+	    },
+	    success: function(response, options) {
+	      var o = Ext.util.JSON.decode(response.responseText);
 
+	      if( o.success === true ) {
 
-		// Save into the store
-		var record = this.store.getById(this.currentRecord);
-		record.set('name', o.newName);
-		record.set('shortName', Ext.util.Format.ellipsis(o.newName, 15));
+		  var node = this.getNode(this.currentRecord);
+		  var itemY = Ext.get(node.id).getY();
+		  var itemX = Ext.get(node.id).getX();
 
-		// After record.set, the item is re-position to he default position.. don't know why. We move it to he right position
-		Ext.get(node.id).moveTo(itemX, itemY);
+		  // Save into the store
+		  var record = this.store.getById(this.currentRecord);
+		  record.set('name', o.newName);
+		  record.set('shortName', Ext.util.Format.ellipsis(o.newName, 15));
 
-		// After record.set, the item stop be dragable. We reinitialise it.
-		this.DDstartDrag(this.getNode(this.currentRecord));
+		  // After record.set, the item is re-position to he default position.. don't know why. We move it to he right position
+		  Ext.get(node.id).moveTo(itemX, itemY);
 
-		// As the name has changed, we must save the position
-		this.setIconPosition();
+		  // After record.set, the item stop be dragable. We reinitialise it.
+		  this.DDstartDrag(this.getNode(this.currentRecord));
 
-	    } else {
-	      if( o.msg ) {
-		this.showMessageWindow('Error', 'this item allready exist ! Change the name', 'error');
+		  // As the name has changed, we must save the position
+		  this.setIconPosition();
+		  
+		  // Re-Build the tooltip
+		  this.ToolTipBuild(node);
+
+	      } else {
+		if( o.msg ) {
+		  this.showMessageWindow('Error', 'this item allready exist ! Change the name', 'error');
+		}
+		else {
+		  this.showMessageWindow('Error', 'Unknow error when change the name', 'error');
+		}
 	      }
-	      else {
-		this.showMessageWindow('Error', 'Unknow error when change the name', 'error');
-	      }
 	    }
-	  }
-	});
-
+	  });
+	}
     },
 
     // ContextMenu
     ctxInit: function(e, target) {
-
         if(!e.ctrlKey && !e.shiftKey){
             var item = this.findItemFromChild(target);
 	    if( item ) {
-	      this._ctxItems(e, item);
+	      var record = this.store.getAt(this.indexOf(item));
+	      if( record.data.type == 'trash' ) {
+		this._ctxTrash(e, item);
+	      } else {
+		this._ctxItems(e, item);
+	      }
 	      e.stopEvent();
 	    } else {
 	      this._ctxView(e);
@@ -398,6 +446,22 @@
         }
     },
 
+    _ctxTrash : function(e, item) {
+	var record = this.store.getAt(this.indexOf(item));
+	this.currentRecord = record.data.id;
+
+	// Select this item
+	this.select(item);
+
+	var menu = new Ext.menu.Menu();
+	menu.add({
+	    scope: this,
+            text: 'Empty this trash',
+            handler: function(){ this.showMessageWindow('Error', 'Not implemented yet', 'error'); }
+        });
+        menu.showAt(e.getXY());
+    },
+
     _ctxItems : function(e, item) {
 
 	var record = this.store.getAt(this.indexOf(item));
@@ -561,13 +625,14 @@
 	d.delay(1000);
       }
     },
-    
+
     addItem: function(e, type) {
       var m1, m2;
       if( type == 'folder' ) { m1 = 'New Folder'; m2 = 'Please enter the name for this new Folder:'; }
       if( type == 'file' ) { m1 = 'New File'; m2 = 'Please enter the name for this new File:'; }
+
       Ext.MessageBox.prompt(m1, m2, function(btn, text) {
-      
+
 	if( btn == 'ok' && text != '' ) {
 	
 	  	Ext.Ajax.request({
@@ -603,15 +668,20 @@
 
 		    this.store.add(Record);
 
+		    var node = Ext.get('shortcuts_'+o.item.id);
+
 		    // Move to the right position according to the right-click event
-		    Ext.get('shortcuts_'+o.item.id).moveTo(e.getPageX(),e.getPageY());
+		    node.moveTo(e.getPageX(),e.getPageY());
 
 		    // Re-initialise the drag&drop functionnality
-		    this.DDInit();
+		    this.DDstartDrag(node);
 
 		    //Save position
 		    this.setIconPosition();
 
+		    //Build the tooltip
+		    this.ToolTipBuild(node);
+
 		  } else {
 		    this.showMessageWindow('Error', 'this item allready exist ! Change the name', 'error'); // can be info in 3 parameters
 		  }


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