Commit d6baa866 authored by Frank Bergmann's avatar Frank Bergmann

- Now downloading and uploading

parent 6c6c538a
This diff is collapsed.
This diff is collapsed.
/*
* Data related to a file.
*
......@@ -10,24 +9,35 @@ Ext.define('POSync.model.File', {
extend: 'Ext.data.TreeModel',
idProperty: 'id',
fields: [
'id', // The system wide unique ID for this object (-> cr_items.item_id)
// FIXME: could better be file_id
'name', // The name and extension (without path) of the file or folder
'version_id', // The active version of the file (-> cr_revisions.revision_id) (empty string for folders)
'description', // Description of the file or folder
'title', // Title of the file or folder
'id', // The system wide unique ID for this object (=file_id)
'name', // The name (with extension) of the file or directory
'path', // The absolute path relative to the project folder, excluding name
'extension', // file extension
'type', // 'file' or 'directory'
'mime_type', // MIME type, empty for folders
'local_p', // 't' for a local file (client), 'f' for remote (server) file
'title', // Title of the file or folder
'description', // Description of the file or folder
'content_length', // File length in bytes (empty string for folders)
'creation_date', // Date of first creation
'publish_date',
'modification_date', // Date of last modification
'sha1', // sha-1 hash of the content (empty string for folders)
// OpenACS properites
'file_id', // ]po[ object_id of the file
'version_id', // The version of the file (cr_revisions.revision_id), empty for folders
// Sencha properties
'level',
'children', // FIXME: To be deleted
'iconCls', // Used by ExtJS for the icon, seems to work
// FIXME: should be generated automatically from 'type' (icon-TYPE)
'content_length', // File length in bytes (empty string for folders)
'sha1', // sha-1 Hash of the content (empty string for folders)
'expanded', // true or false (without quotes), default state for tree
'type', // 'folder' for folders and the mime-type for file
'leaf', // false for folders, true for files
// added by SALO
'level', // FIXME: let ExtJS calculate this
'mime_type', // FIXME: same as 'type' for files, and empty string for folders
'publish_date', // empty string for folders
'children' // undefined for files, a (possibly empty) array for folders
'expanded', // default state for tree, true or false (without quotes)
'expandable', // not sure
'leaf', // true if node has no children
],
/**
......@@ -38,14 +48,11 @@ Ext.define('POSync.model.File', {
// Skip the root and the 1st level folder, which refers to the project itself.
if ("root" == me.get('id')) return [];
if ("root" == me.get('parentId')) return [];
//if ("root" == me.get('parentId')) return [];
var fileType = me.get('type');
var parentId = me.get('parentId');
if (!parentId) return [me.get('name')];
var fileStore = Ext.StoreManager.get('Files');
var parent = fileStore.getById(parentId);
if (!parent) return [me.get('name')];
var parent = me.parentNode;
if (!parent) return [];
var parentPath = parent.getPathArray();
// For a file return just the path (=parentPath)
......
......@@ -12,6 +12,7 @@ Ext.define('POSync.store.Files', {
requires: 'POSync.model.File',
model: 'POSync.model.File',
nodeParam: 'object_id',
root: {
expanded: true,
children: []
......@@ -24,5 +25,46 @@ Ext.define('POSync.store.Files', {
type: 'json',
root: 'children'
}
},
/**
* Load the store with tree (from local directory)
*/
loadTree: function (tree) {
var proxy = this.getProxy();
proxy.data = tree;
this.load();
},
/**
* Check if a file with the given path exists
*/
searchUsingPathArray: function(pathArray) {
var me = this;
var root = me.getRootNode();
// root = root.childNodes[0]; // root is the project's root, so we need to start one below
// Iterate through the pathArray elements from
// the top to find the file in the local folder
var node = root;
for (var i = 0; i < pathArray.length; i++) {
var path = pathArray[i];
// Check all children
var child = null;
var children = node.childNodes;
if (!children) return null;
for (var j = 0; j < children.length; j++) {
var childName = children[j].get('name');
if (path === childName) {
child = children[j];
}
}
if (!child) return null;
node = child;
}
return child;
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment