[qo-modules-dev] [24] cleanup editable area ; solve editable bug ; DD init && item position after editable

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


Revision: 24
Author:   ytorres
Date:     2008-11-16 15:23:19 +0100 (Sun, 16 Nov 2008)

Log Message:
-----------
cleanup editable area ; solve editable bug ; DD init && item position after editable

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


Modified: yannick/main.js
===================================================================
--- yannick/main.js	2008-11-16 14:22:59 UTC (rev 23)
+++ yannick/main.js	2008-11-16 14:23:19 UTC (rev 24)
@@ -8,7 +8,7 @@
 	},
         root: 'items',
 	id: 'id',
-        fields: ['id', 'name', 'originName', 'url', 'size', 'lastmod', 'type', 'nbItem']
+        fields: ['id', 'name', 'url', 'size', 'lastmod', 'type', 'nbItem']
     });
     store.load();
 

Modified: yannick/php/lib.php
===================================================================
--- yannick/php/lib.php	2008-11-16 14:22:59 UTC (rev 23)
+++ yannick/php/lib.php	2008-11-16 14:23:19 UTC (rev 24)
@@ -39,7 +39,6 @@
 		$items[] = array(
 			    'id'=>$i,
 			    'type'=>'file',
-			    'originName'=>$name,
 			    'name'=>$name,
 			    'nbItem'=>NULL,
 			    'size'=>$stat['size'],
@@ -53,7 +52,6 @@
 		$items[] = array(
 			    'id'=>$i,
 			    'type'=>'file',
-			    'originName'=>$name,
 			    'name'=>$name,
 			    'nbItem'=>NULL,
 			    'size'=>$stat['size'],
@@ -70,7 +68,6 @@
 	      $items[] = array(
 			  'id'=>$i,
 			  'type'=>'folder',
-			  'originName'=>$name,
 			  'name'=>$name,
 			  'nbItem'=>$nb_item,
 			  'size'=>$stat['size'],
@@ -120,7 +117,6 @@
 
 	foreach ($xml->element as $item) {
 	  $state[(string)$item->filename] = Array(
-		'name' => (string)$item->filename,
 		'posX' => (int)$item->posx,
 		'posY' => (int)$item->posy
 		);
@@ -144,7 +140,7 @@
       for( $i=0; $i < count($newPosition); $i++ ) {
 	$file .= "
 	<element>
-	  <filename>".$newPosition[$i]['originName']."</filename>
+	  <filename>".$newPosition[$i]['name']."</filename>
 	  <posx>".$newPosition[$i]['x']."</posx>
 	  <posy>".$newPosition[$i]['y']."</posy>
 	</element>
@@ -187,7 +183,6 @@
 	  $item = array(
 	    'id'=>uniqid(),
 	    'type'=>'folder',
-	    'originName'=>$name,
 	    'name'=>$name,
 	    'size'=>disk_total_space($this->home.$this->desktop.$name),
 	    'lastmod'=>(filemtime($this->home.$this->desktop.$name)*1000),
@@ -210,7 +205,6 @@
 	$item = array(
 	  'id'=>uniqid(),
 	  'type'=>'file',
-	  'originName'=>$name,
 	  'name'=>$name,
 	  'size'=>filesize($this->home.$this->desktop.$name),
 	  'lastmod'=>(filemtime($this->home.$this->desktop.$name)*1000),
@@ -226,17 +220,23 @@
       }
     }
 
-    public function fs_update_filename($originName, $newName) {
+    public function fs_update_filename($name, $newName) {
 
       $o->success = false;
 
-      @rename($this->home.$this->desktop.$originName, $this->home.$this->desktop.$newName) or die(json_encode($o));
+      if( file_exists($this->home.$this->desktop.$newName) ) {
+	$o->msg = 'already';
+	echo json_encode($o);
+      } else {
 
-      $o->success = true;
-      $o->newName = $newName;
+	@rename($this->home.$this->desktop.$name, $this->home.$this->desktop.$newName) or die(json_encode($o));
 
-      echo json_encode($o);
+	$o->success = true;
+	$o->newName = $newName;
 
+	echo json_encode($o);
+
+      }
     }
 
     public function __destruct() {

Modified: yannick/php/shortcuts.php
===================================================================
--- yannick/php/shortcuts.php	2008-11-16 14:22:59 UTC (rev 23)
+++ yannick/php/shortcuts.php	2008-11-16 14:23:19 UTC (rev 24)
@@ -22,7 +22,7 @@
 	break;
 
   case 'update-fileName' :
-	$o->fs_update_filename($_POST['originName'], $_POST['newName']);
+	$o->fs_update_filename($_POST['name'], $_POST['newName']);
 	break;
 
   case 'new-item' :

Modified: yannick/shortcuts.js
===================================================================
--- yannick/shortcuts.js	2008-11-16 14:22:59 UTC (rev 23)
+++ yannick/shortcuts.js	2008-11-16 14:23:19 UTC (rev 24)
@@ -41,8 +41,6 @@
 
     prepareData: function(data) {
 	data.shortName = Ext.util.Format.ellipsis(data.name, 15);
-	//data.sizeString = Ext.util.Format.fileSize(data.size);
-	//data.dateString = data.lastmod.format("m/d/Y g:i a");
 	return data;
     },
  
@@ -91,7 +89,6 @@
 
       Ext.each(nodes, function(node) {
 
-	//console.log(view);
 	this.ToolTipBuild(node);
 
       }, this);
@@ -102,8 +99,8 @@
 
 	// 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");
+	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");
@@ -112,7 +109,6 @@
 	new Ext.ToolTip({
 	    target: itemImg,
 	    title: TTtitle,
-	    //width:200,
 	    html: TTcontent,
 	    trackMouse:true
 	});
@@ -120,7 +116,6 @@
 	new Ext.ToolTip({
 	    target: itemText,
 	    title: TTtitle,
-	    //width:200,
 	    html: TTcontent,
 	    trackMouse:true
 	});
@@ -131,23 +126,26 @@
     DDInit : function() {
 
       var nodes = this.getNodes();
-      var lastFolder = null;
 
       Ext.each(nodes, function(node) {
+	this.DDstartDrag(node);
+      }, this);
+    },
 
-	//var dd = Ext.get(node.id).initDD('pp');
+    DDstartDrag: function(node) {
+
+	var lastFolder = null;
+
 	var record = this.store.getAt(this.indexOf(node));
-	var originName = record.data['originName'];
+	var name = record.data.name;
 
 	var viewID = this.id;
 	var view = this;
 
-	var type = record.data['type'];
-
 	var dd1 = Ext.get(node.id);
 	dd1.dd = new Ext.dd.DDProxy(node.id, 'shortcuts');
 
-	// Call when we start to drag
+	// Call when we start to drag ; all type can be dragable
         dd1.dd.startDrag = function(x, y) {
 
 		var dragEl = Ext.get(this.getDragEl());
@@ -157,7 +155,6 @@
 		this.constrainTo(viewID);
 
 		// Hide the clicked element and copy the dom into the drag element
-		//clickEl.setStyle('visibility', 'hidden');
 		dragEl.dom.innerHTML = '<div class="thumb-wrap">'+clickEl.dom.innerHTML+'</div>';
 		
 		// Make the dragEl a little transparent
@@ -168,13 +165,13 @@
 
         };
 
-	// Drag over a valid node target
+	// Drag over a valid node target ; we can drag over a folder. Nothing else.
 	dd1.dd.onDragOver = function(e, targetId) {
 
 		var node = view.getNode(targetId);
 		var record = view.getRecord(node);
 
-		if( record.data['type'] == 'folder' && targetId != this.id ) {
+		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);
@@ -187,7 +184,7 @@
 		var node = view.getNode(targetId);
 		var record = view.getRecord(node);
 
-		if( record.data['type'] == 'folder' ) {
+		if( record.data.type == 'folder' ) {
 			// We switch to normal folder
 			Ext.DomQuery.selectNode("div[@id='"+targetId+"'] > div > img").src = record.data['url'];
 			view.deselect(node);
@@ -199,11 +196,11 @@
 
 		var dragEl = Ext.get(this.getDragEl());
 		var clickEl = Ext.get(this.getEl());
-		
+
 		// We render visible at the new position
 		clickEl.setStyle('visibility', 'visible');
 		clickEl.moveTo(dragEl.getX(), dragEl.getY());
-		
+
 		if( lastFolder ) {
 
 		  // We move this file to this folder
@@ -212,20 +209,20 @@
 		    scope: this,
 		    url: 'php/shortcuts.php',
 		    params: {
-		      moveTo: lastFolder.data['originName'],
-		      name: originName,
+		      moveTo: lastFolder.data.name,
+		      name: name,
 		      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'];
-		    
+		      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');
 		      view.store.remove(record);
 		      lastFolder = null;
-		      
+
 		    }
 		  });
 
@@ -236,9 +233,8 @@
 		}
 	};
 
-      }, this);
     },
-    
+
     setIconPosition: function() {
 
 	var nodes = this.getNodes();
@@ -248,11 +244,11 @@
 	Ext.each(nodes, function(node) {
 
 	  var record = this.store.getAt(this.indexOf(node));
-	  var originName = record.data['originName'];
+	  var name = record.data.name;
 	  var nodeElX = Ext.get(node.id).getX();
 	  var nodeElY = Ext.get(node.id).getY();
 
-	  newPosition[i] = { 'originName': originName, 'x': nodeElX, 'y': nodeElY };
+	  newPosition[i] = { 'name': name, 'x': nodeElX, 'y': nodeElY };
 	  i ++;
 	}, this);
 
@@ -268,7 +264,7 @@
 	});
 
     },
-    
+
     // Move shortCut onRender
     DDmoveIcon : function() {
 	Ext.Ajax.request({
@@ -284,12 +280,13 @@
 	      Ext.each(nodes, function(node) {
 
 		var record = this.store.getAt(this.indexOf(node));
-		
-		var originName = record.data['originName'];
-		
-		if( o[originName] ) {
+
+		var name = record.data.name;
+
+		if( o[name] ) {
+		  console.log('on bouge ' + name + ': ' + o[name].posX);
 		  //Move
-		  Ext.get(node.id).moveTo(o[originName].posX, o[originName].posY, true);
+		  Ext.get(node.id).moveTo(o[name].posX, o[name].posY, true);
 		}
 	      }, this);
 
@@ -304,18 +301,18 @@
       var item = this.findItemFromChild(target);
       var record = this.store.getAt(this.indexOf(item));
 
-      if( record.data['type'] == 'folder' ) {
+      if( record.data.type == 'folder' ) {
 	this.showMessageWindow('Info', 'Launch the FileExplorer', 'info');
       }
 
-      if( record.data['type'] == 'file' ) {
+      if( record.data.type == 'file' ) {
 	this.showMessageWindow('Info', 'Launch the FileEditor (need to be done according to the <b>mimeType</b> of this file)', 'info');
       }
 
-      if( record.data['type'] == 'shortcut' ) {
+      if( record.data.type == 'shortcut' ) {
 	this.showMessageWindow('Info', 'Launch this App', 'info');
       }
-      
+
     },
 
     // LabelEditor
@@ -327,7 +324,7 @@
 	      e.stopEvent();
 	      var record = this.store.getAt(this.indexOf(item));
 	      this.currentRecord = record.data.id;
-	      this.labelEditor.startEdit(target, record.data['name']);
+	      this.labelEditor.startEdit(target, record.data.name);
 	      this.labelEditor.on('complete', this.LabelEditorSave, this, {delegate: item});
 	    }
         } else {
@@ -337,38 +334,44 @@
     },
 
     LabelEditorSave: function(ed, NewValue, item) {
-     // Save into the store
-     this._LabelEditorUpdateStore(this.currentRecord, NewValue);
-     // Update LabelEl
-     this._LabelEditorUpdateEl(this.currentRecord, NewValue);
-     // Save to FileSystem
-     this._LabelEditorSaveToFileSystem(this.store.getById(this.currentRecord).data.originName, NewValue);
-    },
+        var name = this.store.getById(this.currentRecord).data.name;
 
-    _LabelEditorUpdateStore : function(id, NewValue) {
-      this.store.getById(id).data.name = NewValue;
-      this.store.getById(id).data.shortName = Ext.util.Format.ellipsis(NewValue, 15);
-    },
-
-    _LabelEditorUpdateEl : function(id, NewValue) {
-      Ext.DomQuery.selectNode("div[@id='shortcuts_"+id+"'] > span[@class='x-editable']").innerHTML =  Ext.util.Format.ellipsis(NewValue, 15);
-    },
-    
-    _LabelEditorSaveToFileSystem: function(originName, NewValue, item) {
-        var item = item;
 	Ext.Ajax.request({
 	  scope: this,
 	  url: 'php/shortcuts.php',
 	  params: {
-	      originName: originName,
+	      name: name,
 	      newName: NewValue,
 	      what: 'update-fileName'
 	  },
 	  success: function(response, options) {
 	    var o = Ext.util.JSON.decode(response.responseText);
-	    //Update originName
-	    var record = this.store.getById(this.currentRecord);
-	    record.data['originName'] = o.newName;
+	    console.log(this);
+	    if( o.success === true ) {
+
+	    var node = this.getNode(this.currentRecord);
+	    var itemY = Ext.get(node.id).getY();
+	    var itemX = Ext.get(node.id).getX();
+
+
+		// 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 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);
+
+		// After record.set, the item stop be dragable. We reinitialise it.
+		this.DDstartDrag(this.getNode(this.currentRecord));
+
+		// As the name has changed, we must save the position
+		this.setIconPosition();
+
+	    } else {
+	      if( o.msg ) { return 'already'; }
+	      else { return 'unknow'; }
+	    }
 	  }
 	});
 
@@ -403,7 +406,6 @@
 	menu.add({
 	    scope: this,
             text: 'Open',
-            //iconCls: '',
             handler: function(){ this.showMessageWindow('Error', 'Not implemented yet', 'error'); }
         });
 	menu.add({
@@ -520,22 +522,22 @@
       Ext.each(nodes, function(node) {
 	
 	var record = this.store.getAt(this.indexOf(node));
-	var name1 = record.data['name'];
-	var type1 = record.data['type'];
-	var size1 = record.data['size'];
+	var name = record.data.name;
+	var type = record.data.type;
+	var size = record.data.size;
 
-	sortArray[i] = {'name': name1, 'type': type1, 'size': size1, 'id': node.id };
+	sortArray[i] = {'name': name, 'type': type, 'size': size, 'id': node.id };
 
 	i ++;
 	
       }, this);
 
       if( by == 'name' ) {
-	sortArray.sort(function(a, b) { return a['name'] > b['name']; })
+	sortArray.sort(function(a, b) { return a.name > b.name; })
       } else if( by == 'type' ) {
-	sortArray.sort(function(a, b) { return a['type'] > b['type']; })
+	sortArray.sort(function(a, b) { return a.type > b.type; })
       } else if ( by == 'size' ) {
-	sortArray.sort(function(a, b) { return a['size'] > b['size']; })
+	sortArray.sort(function(a, b) { return a.size > b.size; })
       }
 
       // Now we move
@@ -580,7 +582,6 @@
 		    var RecordDef = Ext.data.Record.create([
 			{name: 'id', mapping: 'id'},
 			{name: 'name', mapping: 'name'},
-			{name: 'originName', mapping: 'originName'},
 			{name: 'url', mapping: 'url'},
 			{name: 'size', type: 'float', mapping: 'size'},
 			{name: 'lastmod', mapping: 'lastmod',  type:'date', dateFormat:'timestamp'},
@@ -590,7 +591,6 @@
 		    var Record = new RecordDef({
 		      id : o.item.id,
 		      name : o.item.name,
-		      originName : o.item.originName,
 		      url : o.item.url,
 		      size : o.item.size,
 		      lastmod : o.item.lastmod,
@@ -618,22 +618,21 @@
       }, this);
 
     },
-    
+
     delItem : function(record) {
-    
+
 		  Ext.Ajax.request({
 		  scope: this,
 		  url: 'php/shortcuts.php',
 		  params: {
-		      name: record.data['originName'],
-		      type: record.data['type'],
+		      name: record.data.name,
+		      type: record.data.type,
 		      what: 'remove-item'
 		  },
 		  success: function(response, options) {
 		    var o = Ext.util.JSON.decode(response.responseText);
 		    if( o.success ) {
 		      this.store.remove(record);
-		      
 		      // TODO
 		      this.showMessageWindow('TODO', 'We must erase this item from the state\'s file on success. Just to keep this file clean', 'error');
 		    } else {


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