1. #721
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,162
    Vote Rating
    322
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Looks like it should work. Check if the path you're trying to expand really exists.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Blessing and Curse of refs, Grid MultiSearch Plugin


  2. #722
    Sencha Premium Member
    Join Date
    May 2007
    Posts
    57
    Vote Rating
    0
    tchitani is on a distinguished road

      0  

    Default


    Thanks Saki for the prompt response.

    The trick is the path does exist, but not loaded yet (I am retrieving this path info from the server call on grid render).
    But, when I click on grid row and pass the path to expandPath, only tree root reload event is fired, nothing else.

  3. #723
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,162
    Vote Rating
    322
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Hmm, expandPath should handle it. See http://examples.extjs.eu/?ex=treestate - there is similar, if not same, code to expand a path.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Blessing and Curse of refs, Grid MultiSearch Plugin


  4. #724
    Sencha Premium Member
    Join Date
    May 2007
    Posts
    57
    Vote Rating
    0
    tchitani is on a distinguished road

      0  

    Default


    Yes, it should work, and the code is similar.
    The only difference is that I'm preloading some children on the initial tree load, and then is using on-demand tree load.
    Can this be the issue why expandPath does not work?

  5. #725
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,162
    Vote Rating
    322
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    No idea. Try to step into the code with FB to see what's really happening.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Blessing and Curse of refs, Grid MultiSearch Plugin


  6. #726
    Sencha User
    Join Date
    May 2008
    Posts
    15
    Vote Rating
    0
    acidfilez is on a distinguished road

      0  

    Default FileTreePanel with java web application using struts

    FileTreePanel with java web application using struts


    I am using netbeans 6.7 java web app using the struts 1.3.8.

    I wanted to use jsakalos FileTreePanel but I got some problems:

    1) java apps comes in a WAR file. (Imposible to add/delete/rename/newdir/newfile without redeploying)
    2) jboss for example support exploded deployment. But writing insde your jboss/deploy directory (i think would give you big problem)

    Only solution is write to an external directory, I use this path: c:\home\users\factsweb (yes hard coded).

    3) The files I wanted to used were html and images which were outside the deploy directory, so this arent expose to jboss, so they cant be link by url.

    4) html and images files are private, only logged user can see them.

    The solution, lest start, Keep up!


    the struts-config-xml:
    Code:
    In the form-beans:
    
     <form-bean name="FileTreeAjaxActionForm"  type="cl.company.facts.form.diagrams.FileTreeAjaxActionForm"/>
    
    In the action-mappings:
    
     <action attribute="InstrumentoListActionForm"
                    input="/html/index.html"
                    name="FileTreeAjaxActionForm"
                    path="/FileTree"
                    scope="request"
                    validate="true"
                    type="cl.company.facts.action.diagrams.FileTreeAjaxAction" >
                <forward name="continue" path="/jsonWriterTreeNodeItemDTO.do" />
            </action>
    
    
    In the global-forwards:
    
    <forward name="jsonWriterTreeNodeItemDTO" path="/jsp_root/jsonWriterTreeNodeItemDTO.jsp" />
    
    Note: Use this jsp to do the transformation to a json.


    the jsonWriterTreeNodeItemDTO.jsp:
    Code:
    <%@ page contentType="application/json;charset=UTF-8" %>
    <%@ page import="net.sf.sojo.interchange.Serializer" %>
    <%@ page import="net.sf.sojo.interchange.json.JsonSerializer" %>
    <%@ page import="java.util.HashMap" %>
    <%@ page import="cl.company.informs.util.JsonUtil" %>
    <%@ page import="net.sf.sojo.core.filter.ClassPropertyFilter" %>
    <%@ page import="net.sf.sojo.core.filter.ClassPropertyFilterHandlerImpl" %>
    <%@ page import="cl.company.dto.factsweb.TreeNodeItemDTO" %>
    <%
            Serializer serializer = new JsonSerializer();
            java.lang.String[] pvExcludedProperties = {"~unique-id~", "class"};
    
            ClassPropertyFilterHandlerImpl handler = new ClassPropertyFilterHandlerImpl(
                    new ClassPropertyFilter(TreeNodeItemDTO.class, new String[]{"~unique-id~"}));
            serializer.setClassPropertyFilterHandler(handler);
    
            Object result = serializer.serialize(request.getAttribute("hmResult"));
            String jsResult = null;
            
            try{
                jsResult = result.toString();
            }
            catch (Exception e){
                System.out.println("Error jsonWriter.jsp:" + e.getMessage());
                e.printStackTrace();
            }
            jsResult = JsonUtil.formatJson(jsResult);
    %><%=jsResult%>

    the Action (be free to chage SecurityAction to Action):
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package cl.company.facts.action.diagrams;
    
    import cl.company.comun.util.StrUtil;
    import cl.company.dto.factsweb.TreeNodeItemDTO;
    import cl.company.facts.form.diagrams.FileTreeAjaxActionForm;
    import java.util.Hashtable;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionForward;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import cl.company.informs.security.SecurityAction;
    import cl.company.informs.util.ListFilesSubs;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import net.sf.sojo.interchange.Serializer;
    import net.sf.sojo.interchange.json.JsonSerializer;
    import org.apache.struts.upload.FormFile;
    
    public class FileTreeAjaxAction extends SecurityAction {
    
        private static final String CMD_GET = "get";
        private static final String CMD_UPLOAD = "upload";
        private static final String CMD_DELETE = "delete";
        private static final String CMD_DOWNLOAD = "download";
        private static final String CMD_RENAME = "rename";
        private static final String CMD_NEWDIR = "newdir";
    
        /**
         * This is the action returns the listing in a directory,
         * FileTreePanel alwasys send a path as root/....
         * So all files must go into the directory called root
         *
         * @param mapping The ActionMapping used to select this instance.
         * @param form The optional ActionForm bean for this request.
         * @param request The HTTP Request we are processing.
         * @param response The HTTP Response we are processing.
         * @throws java.lang.Exception
         * @return
         */
        public ActionForward doExecute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
    
            FileTreeAjaxActionForm uploadForm = (FileTreeAjaxActionForm) form;
            String command = StrUtil.formatStr(uploadForm.getCmd());
            if (FileTreeAjaxAction.CMD_GET.equals(command)) {
    
                doGet(mapping, form, request, response);
    
            } else if (FileTreeAjaxAction.CMD_UPLOAD.equals(command)) {
    
                doUpload(mapping, form, request, response);
    
                return null;
    
            } else if (FileTreeAjaxAction.CMD_DELETE.equals(command)) {
    
                doDelete(mapping, form, request, response);
    
            } else if (FileTreeAjaxAction.CMD_NEWDIR.equals(command)) {
    
                doNewDir(mapping, form, request, response);
    
            } else if (FileTreeAjaxAction.CMD_DOWNLOAD.equals(command)) {
    
                Map<String, Object> reply = new HashMap<String, Object>();
                reply.put("success", new Boolean(true));
                reply.put("cmd", "the command is download not implemented");
    
            } else if (FileTreeAjaxAction.CMD_RENAME.equals(command)) {
    
                doRename(mapping, form, request, response);
    
            } else if (StrUtil.EMPTY.equals(command)) {
    
                Map<String, Object> reply = new HashMap<String, Object>();
                reply.put("success", new Boolean(true));
                reply.put("cmd", "the command is empty we are returning a true");
    
            }
    
            response.setContentType("application/json;charset=UTF-8");
            return mapping.findForward("jsonWriterTreeNodeItemDTO");
        }
    
        //Upload Multiple files
        //try out
        public void doUpload(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) {
            Map<String, Object> reply = new HashMap<String, Object>();
            FileTreeAjaxActionForm uploadForm = (FileTreeAjaxActionForm) form;
            //dependin on the comman do this.
            String root = "c:\\home\\users\\factsweb" + File.separator;
            String path = StrUtil.formatStr(uploadForm.getPath());
    
            try {
                if (form.getMultipartRequestHandler() != null) {
                    Hashtable ble = form.getMultipartRequestHandler().getFileElements();
    
                    Enumeration elements = ble.elements();
                    while (elements.hasMoreElements()) {
                        FormFile myFile = (FormFile) elements.nextElement();
                        String contentType = myFile.getContentType();
                        String fileName = myFile.getFileName();
                        int fileSize = myFile.getFileSize();
                        byte[] fileData = myFile.getFileData();
    
                        String finalFilePath = root + path + File.separator + fileName;
                        finalFilePath = finalFilePath.replace("/".charAt(0), File.separatorChar);
                        finalFilePath = finalFilePath.replace("\\".charAt(0), File.separatorChar);
    
                        FileOutputStream file = new FileOutputStream(new File(finalFilePath));
                        file.write(myFile.getFileData());
                        file.close();
                    }
                    reply.put("success", new Boolean(true));
    
                    Serializer serializer = new JsonSerializer();
                    Object result = serializer.serialize(reply);
    
                    response.setContentType("text/html;charset=UTF-8");
    
                    PrintWriter out = response.getWriter();
                    try {
                        out.print(result.toString());
                    } finally {
                        out.close();
                    }
    
                } else {
                    reply.put("success", new Boolean(false));
                    reply.put("error", "getMultipartRequestHandler() is null");
    
    
                    Serializer serializer = new JsonSerializer();
                    Object result = serializer.serialize(reply);
    
                    response.setContentType("text/html;charset=UTF-8");
    
                    PrintWriter out = response.getWriter();
                    try {
                        out.print(result.toString());
                    } finally {
                        out.close();
                    }
                }
    
            } catch (Exception e) {
                //should never get here.
                e.printStackTrace();
            }
        }
    
        //GetFiles
        public void doGet(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) {
            Map<String, Object> reply = new HashMap<String, Object>();
            FileTreeAjaxActionForm uploadForm = (FileTreeAjaxActionForm) form;
            //dependin on the comman do this.
            String root = "c:\\home\\users\\factsweb" + File.separator;
            String path = StrUtil.formatStr(uploadForm.getPath());
            //now add the logic to get the root list
            List<TreeNodeItemDTO> noteItemList = new ArrayList<TreeNodeItemDTO>();
    
            try {
                TreeNodeItemDTO dto = new TreeNodeItemDTO();
                // Call the simple file listing method
                Map<String, String> myList = ListFilesSubs.getSimpleFileListing(root + path);
                Iterator it = myList.entrySet().iterator();
                while (it.hasNext()) {
                    dto = new TreeNodeItemDTO();
                    Map.Entry pairs = (Map.Entry) it.next();
    
                    dto.setText(pairs.getKey().toString());
                    dto.setDisabled(new Boolean(false));
                    //its a directory else a file
                    if (ListFilesSubs.DIRECTORY.equals(pairs.getValue())) {
                        dto.setIconcls("folder");
                        dto.setLeaf(new Boolean(false));
                        dto.setQtip("");
                    } else {
                        dto.setIconcls("file-txt");
                        dto.setLeaf(new Boolean(true));
                        dto.setQtip("Size: 1047552");
                    }
                    noteItemList.add(dto);
                }
                request.setAttribute("hmResult", noteItemList);
            } catch (Exception e) {
                reply.put("success", new Boolean(false));
                reply.put("error", "Cannot get by exception:" + e.getMessage());
                request.setAttribute("hmResult", reply);
            }
        }
    
        //Delete Files
        public void doDelete(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) {
            Map<String, Object> reply = new HashMap<String, Object>();
            FileTreeAjaxActionForm uploadForm = (FileTreeAjaxActionForm) form;
            //dependin on the comman do this.
            String root = "c:\\home\\users\\factsweb" + File.separator;
            String file = StrUtil.formatStr(uploadForm.getFile());
    
            try {
                String finalFilePath = root + file;
                finalFilePath = finalFilePath.replace("/".charAt(0), File.separatorChar);
                finalFilePath = finalFilePath.replace("\\".charAt(0), File.separatorChar);
                File theFile = new File(finalFilePath);
                if (theFile.delete()) {
                    reply.put("success", new Boolean(true));
                } else {
                    reply.put("success", new Boolean(false));
                    reply.put("error", "Cannot delete:" + file);
                }
    
                request.setAttribute("hmResult", reply);
            } catch (Exception e) {
                reply.put("success", new Boolean(false));
    
                reply.put("error", "Cannot delete by exception:" + e.getMessage());
                request.setAttribute("hmResult", reply);
            }
        }
    
        //Rename Files
        public void doRename(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) {
            Map<String, Object> reply = new HashMap<String, Object>();
            FileTreeAjaxActionForm uploadForm = (FileTreeAjaxActionForm) form;
            //dependin on the comman do this.
            String root = "c:\\home\\users\\factsweb" + File.separator;
            String fileOld = StrUtil.formatStr(uploadForm.getOldname());
            String fileNew = StrUtil.formatStr(uploadForm.getNewname());
    
            try {
    
                String finalFilePathNew = root + fileNew;
                finalFilePathNew = finalFilePathNew.replace("/".charAt(0), File.separatorChar);
                finalFilePathNew = finalFilePathNew.replace("\\".charAt(0), File.separatorChar);
                File theFileNew = new File(finalFilePathNew);
    
    
                String finalFilePathOld = root + fileOld;
                finalFilePathOld = finalFilePathOld.replace("/".charAt(0), File.separatorChar);
                finalFilePathOld = finalFilePathOld.replace("\\".charAt(0), File.separatorChar);
                File theFileOld = new File(finalFilePathOld);
    
                if (theFileOld.renameTo(theFileNew)) {
                    reply.put("success", new Boolean(true));
                } else {
                    reply.put("success", new Boolean(false));
                    reply.put("error", "Cannot rename file:'" + finalFilePathOld + "' to '" + finalFilePathNew + "'");
                }
    
                request.setAttribute("hmResult", reply);
            } catch (Exception e) {
                reply.put("success", new Boolean(false));
                reply.put("error", "Cannot renmae by exception:" + e.getMessage());
                request.setAttribute("hmResult", reply);
            }
        }
    
        //New Directory
        public void doNewDir(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) {
            Map<String, Object> reply = new HashMap<String, Object>();
            FileTreeAjaxActionForm uploadForm = (FileTreeAjaxActionForm) form;
            //dependin on the comman do this.
            String root = "c:\\home\\users\\factsweb" + File.separator;
            String nameDir = StrUtil.formatStr(uploadForm.getDir());
    
            try {
                String finalNewDirectory = root + nameDir;
                finalNewDirectory = finalNewDirectory.replace("/".charAt(0), File.separatorChar);
                finalNewDirectory = finalNewDirectory.replace("\\".charAt(0), File.separatorChar);
                File theNewDirectory = new File(finalNewDirectory);
    
                if (theNewDirectory.mkdir()) {
                    reply.put("success", new Boolean(true));
                } else {
                    reply.put("success", new Boolean(false));
                    reply.put("error", "Cannot make dir: " + finalNewDirectory);
                }
    
                request.setAttribute("hmResult", reply);
            } catch (Exception e) {
                reply.put("success", new Boolean(false));
                reply.put("error", "Cannot make dir by exception:" + e.getMessage());
                request.setAttribute("hmResult", reply);
            }
        }
    }

    the ActionForm:
    Code:
    /*
     * Generated by MyEclipse Struts
     * Template path: templates/java/JavaClass.vtl
     */
    package cl.company.facts.form.diagrams;
    
    import java.util.ArrayList;
    import org.apache.struts.upload.FormFile;
    
    /** 
     * Registro de versiones: <ul>
     * 
     * <li>FileTreeAjaxActionForm</li>
     * <li>$Id: FileTreeAjaxActionForm.java,v 1.1 2008/09/26 22:25:49 mcardona Exp $</li>
     * </ul>
     *
     * @author Magno Cardona Heck.
     * @author Anon
     * @version $Revision: 1.1 $,$Date: 2008/09/26 22:25:49 $
     * 
     * @struts.form name="FileTreeAjaxActionForm"
     */
    public class FileTreeAjaxActionForm extends org.apache.struts.action.ActionForm {
    
        private static long serialVersionUID = 4793888812818184727L;
    
    
        private ArrayList<FormFile> formFiles = new ArrayList<FormFile>();
        private FormFile f;
    
        public void setTestFile(int iIndex, FormFile formFile) {
            f = formFile;
            this.formFiles.add(formFile);
        }
    
        public FormFile getTestFile(int iIndex) {
            while (this.formFiles.size() <= iIndex) {
                this.formFiles.add(f);
            }
            return (FormFile) formFiles.get(iIndex);
        }
    
        public ArrayList getTestFiles() {
            return this.formFiles;
        }
        /*
         * Generated fields
         */
        /**  property */
        private String cmd;
        /** property */
        private String node;
        /** property */
        private String path;
        /** property */
        private String file;
        /** property */
        private String newname;
        /** property */
        private String oldname;
        /** property */
        private String dir;
    
        
        
    
        /**
         * @return the cmd
         */
        public String getCmd() {
            return cmd;
        }
    
        /**
         * @param cmd the cmd to set
         */
        public void setCmd(String cmd) {
            this.cmd = cmd;
        }
    
        /**
         * @return the node
         */
        public String getNode() {
            return node;
        }
    
        /**
         * @param node the node to set
         */
        public void setNode(String node) {
            this.node = node;
        }
    
        /**
         * @return the path
         */
        public String getPath() {
            return path;
        }
    
        /**
         * @param path the path to set
         */
        public void setPath(String path) {
            this.path = path;
        }
    
        /**
         * @return the file
         */
        public String getFile() {
            return file;
        }
    
        /**
         * @param file the file to set
         */
        public void setFile(String file) {
            this.file = file;
        }
    
        /**
         * @return the newname
         */
        public String getNewname() {
            return newname;
        }
    
        /**
         * @param newname the newname to set
         */
        public void setNewname(String newname) {
            this.newname = newname;
        }
    
        /**
         * @return the oldname
         */
        public String getOldname() {
            return oldname;
        }
    
        /**
         * @param oldname the oldname to set
         */
        public void setOldname(String oldname) {
            this.oldname = oldname;
        }
    
        /**
         * @return the dir
         */
        public String getDir() {
            return dir;
        }
    
        /**
         * @param dir the dir to set
         */
        public void setDir(String dir) {
            this.dir = dir;
        }
    }
    the index.html (can be a jsp):
    Code:
    <html>
        <head>
            <title>Tree</title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <link rel="stylesheet" type="text/css" href="../js/extjs/resources/css/ext-all.css" />
            <link rel="stylesheet" type="text/css" href="../css/application.css" />
            <link rel="stylesheet" type="text/css" href="../js/extjs/resources/css/core.css" />
    
            <link rel="stylesheet" type="text/css" href="../js/filetreepanel/css/icons.css">
            <link rel="stylesheet" type="text/css" href="../js/filetreepanel/css/filetree.css">
            <link rel="stylesheet" type="text/css" href="../js/filetreepanel/css/filetype.css">
            <link rel="stylesheet" type="text/css" href="../js/filetreepanel/css/famflag.css">
    
            <link rel="stylesheet" type="text/css" href="../js/filetreepanel/css/Ext.ux.IconCombo.css">
    
    
        </head>
        <body>
            <div id="loading-mask" style=""></div>
            <div id="loading">
                <div class="loading-indicator">
                    <img src="../images/ajax-loader.gif" alt="" style="margin-right:8px;float:left;vertical-align:text-top;"/>
                    Cargando - Arbol<br/><span id="loading-msg">Loading styles and images...</span>
                </div>
            </div>
            <div id="viewport">
                <div id="bd">
                    <div class="left-column">
                        <br/>
    
                        <script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Cargando Core API...';</script>
                        <script type="text/javascript" src="../js/extjs//adapter/ext/ext-base.js"></script>
    
                        <script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Cargando UI Componentes...';</script>
                        <script type="text/javascript" src="../js/extjs/ext-all.js"></script>
                        
                        <script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Cargando Locales ES...';</script>
                        <script type="text/javascript" src="../js/extjs/source/locale/ext-lang-es.js"  charset="utf-8"></script>
    
                        <script type="text/javascript" src="../js/filetreepanel/js/Ext.ux.form.BrowseButton.js"></script>
                        <script type="text/javascript" src="../js/filetreepanel/js/Ext.ux.FileUploader.js"></script>
                        <script type="text/javascript" src="../js/filetreepanel/js/Ext.ux.UploadPanel.js"></script>
                        <script type="text/javascript" src="../js/filetreepanel/js/Ext.ux.FileTreeMenu.js"></script>
                        <script type="text/javascript" src="../js/filetreepanel/js/Ext.ux.FileTreePanel.js"></script>
                        <script type="text/javascript" src="../js/filetreepanel/js/Ext.ux.form.ThemeCombo.js"></script>
                        <script type="text/javascript" src="../js/filetreepanel/js/Ext.ux.form.IconCombo.js"></script>
                        <script type="text/javascript" src="../js/filetreepanel/js/Ext.ux.form.LangSelectCombo.js"></script>
    
    
                        <!-- Last Script to run -->
                        <script type="text/javascript">document.getElementById('loading-msg').innerHTML = 'Inicializando...';</script>
                        <script type="text/javascript" src="initialize.js"></script>
    
                    </div>
                </div><!-- end bd -->
            </div><!-- end viewport -->
        </body>
    </html>
    the initialize.js (change this file to your needs because i am copying,deleting,mkdir,etc inside the jar, so i use /path/ in a servlet dipatcher to feed hmtl and images based if the user is authentificated to the server):
    Code:
    /*jslint adsafe:false, bitwise:false, browser:false, cap:false, debug:false, eqeqeq:true, evil:false, forin:false, fragment:false, glovar:true, laxbreak:false, nomen:true, on:false, passfail:false, plusplus:false, rhino:false, sidebar:false, undef:true, white:true, widget:false */
    /*extern  Ext console window netscape Components Tokenizer document setTimeout*/
    
    /**
     * An Application
     *
     * @author    Magno C Heck
     * @copyright (c) 2008, by Anon
     * @date      30 April 2008
     * @version   $Id: initialize.js,v 1.2 2008/10/27 15:03:31 mcardona Exp $
     *
     * @license application.js is licensed under the terms of the Open Source
     * LGPL 3.0 license. Commercial use is permitted to the extent that the 
     * code/component(s) do NOT become part of another Open Source or Commercially
     * licensed development library or toolkit without explicit permission.
     * 
     * License details: http://www.gnu.org/licenses/lgpl.html
     */
    Ext.namespace('Ext.myApp');
    
    Ext.EventManager.on(window, 'load', function () {
    
        //this is just a virtual place holder.
        //all the files are read from the filesystem. check the manual.
    
        var MyNewTree = Ext.extend(Ext.ux.FileTreePanel, {
            constructor: function(config) {
                config = Ext.apply({
    
                    }, config);
                MyNewTree.superclass.constructor.call(this, config);
            },
    
    
            onDblClick:function(node, e) {
                this.openNode(node,'_self', true);
            }, // eo function onDblClick
    
    
            //we need to change the /html/root/ to /path/ for the security reason.
            //adding redirect to do a simple if and do its magic.
            openNode:function(node, mode, redirect) {
    
                if(!this.enableOpen) {
                    return;
                }
    
                mode = mode || this.openMode;
    
                var url;
                var path;
                if(node.isLeaf()) {
                    path = this.getPath(node);
                    url = this.hrefPrefix + path + this.hrefSuffix;
                    if (redirect){
                        //chagne root/ to path/ but wait its contexts is still in the html/ directory
                        //force it to the base using ../
                        url = url.replace(/root\//,'../path/');
                    }
    
                    // fire beforeopen event
                    if(true !== this.eventsSuspended && false === this.fireEvent('beforeopen', this, node.text, url, mode)) {
                        return;
                    }
    
                    switch(mode) {
                        case 'popup':
                            if(!this.popup || this.popup.closed) {
                                this.popup = window.open(url, this.hrefTarget, this.popupFeatures);
                            }
                            this.popup.location = url;
                            if(this.focusPopup) {
                                this.popup.focus();
                            }
                            break;
    
                        case '_self':
                            window.location = url;
                            break;
    
                        case '_blank':
                            window.open(url);
                            break;
    
                        case 'download':
                            this.downloadFile(path, true);
                            break;
                    }
    
                    // fire open event
                    if(true !== this.eventsSuspended) {
                        this.fireEvent('open', this, node.text, url, mode);
                    }
                }
    
            },
    
            downloadFile:function(path, redirect) {
                if (redirect){
                    //chagne root/ to path/ but wait its contexts is still in the html/ directory
                    //force it to the base using ../
                    path = path.replace(/root\//,'../path/');
                }
                // create hidden target iframe
                var id = Ext.id();
                var frame = document.createElement('iframe');
                frame.id = id;
                frame.name = id;
                frame.className = 'x-hidden';
                if(Ext.isIE) {
                    frame.src = Ext.SSL_SECURE_URL;
                }
    
                document.body.appendChild(frame);
    
                if(Ext.isIE) {
                    document.frames[id].name = id;
                }
    
                var form = Ext.DomHelper.append(document.body, {
                    tag:'form'
                    ,
                    method:'post'
                    ,
                    action:this.downloadUrl || this.url
                    ,
                    target:id
                });
    
                document.body.appendChild(form);
    
                var hidden;
    
                // append cmd to form
                hidden = document.createElement('input');
                hidden.type = 'hidden';
                hidden.name = 'cmd';
                hidden.value = 'download';
                form.appendChild(hidden);
    
                // append path to form
                hidden = document.createElement('input');
                hidden.type = 'hidden';
                hidden.name = 'path';
                hidden.value = path;
                form.appendChild(hidden);
    
                var callback = function() {
                    Ext.EventManager.removeListener(frame, 'load', callback, this);
                    setTimeout(function() {
                        document.body.removeChild(form);
                    }, 100);
                    setTimeout(function() {
                        document.body.removeChild(frame);
                    }, 110);
                };
    
                Ext.EventManager.on(frame, 'load', callback, this);
    
                form.submit();
            }
    
        });
    
    
    
    
    
    
    
    
    
    
        //VIEWPORT APPLICATION
        Ext.myApp.viewPort = new Ext.Viewport({
            items: new MyNewTree({
                height:700,
                autoWidth: true,
                id: 'ftpBrowser',
                renderTo: 'viewport',
                rootPath: 'root',
                topMenu: true,
                url:'../FileTree.do',
                autoScroll: true,
                enableProgress: false,
                enableDD: false,
                openMode: '_self', //is overwritten in the dblClick too
                rootText: "inicio",
                singleUpload: false
            //	baseParams:{additional:'haha'}
            })
        });
    
        //hides the init loader
        setTimeout(function () {
            Ext.get('loading').remove();
            Ext.get('loading-mask').fadeOut({
                easing: 'easeOut',
                duration: 3,
                remove: true
            });
           
            //show the samart stuff here
    
            Ext.myApp.viewPortHeight = Ext.myApp.viewPort.getSize().height;
            
            //Some error will hunt me forever
            Ext.getCmp('ftpBrowser').setHeight(Ext.myApp.viewPortHeight - 3);
    
            // window with uploadpanel
            Ext.myApp.uploadWin = new Ext.Window({
                width:180,
                minWidth:165,
                id:'winid',
                height:220,
                minHeight:200,
                layout:'fit',
                border:false,
                closable:false,
                title:'UploadPanel',
                iconCls:'icon-upload',
                items:[{
                    xtype:'uploadpanel',
                    buttonsAt:'tbar',
                    id:'uppanel',
                    url:'../FileTree.do',
                    path:'root',
                    maxFileSize:1048576
                }]
            });
        //Ext.myApp.uploadWin.show.defer(500, win);
    
        }, 250);
    
    });
    //EOF
    In case you are interested in the html/image dispatcher servlet:
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package cl.company.informs.controller;
    
    import cl.company.comun.util.FileUtil;
    import cl.company.comun.util.StrUtil;
    import cl.company.j2ee.SessionUtil;
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     *
     * @author Magno
     */
    public class WebContentDispatcher extends HttpServlet {
    
        /** 
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         *
         *  /capture all url after the /path url.
         * 
         *  <servlet-mapping>
         *   <servlet-name>WebContentDispatcher</servlet-name>
         *   <url-pattern>/path/*</url-pattern>
         * </servlet-mapping>
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            String root = "c:\\home\\users\\factsweb" + File.separator + "root" + File.separator;
    
            String contextPath = request.getContextPath();
            String requestURL = request.getRequestURL().toString();
    
            String path = requestURL.replaceAll("http.*?" + contextPath + "/path/", "");
            String finalFilePath = root + path;
            finalFilePath = finalFilePath.replace("/".charAt(0), File.separatorChar);
            finalFilePath = finalFilePath.replace("\\".charAt(0), File.separatorChar);
            //System.out.println("finalFilePath:" + finalFilePath);
            String fileExtention = FileUtil.getFileExtention(finalFilePath);
            //System.out.println("fileExtention:" + fileExtention);
    
            String imagesTypes = "gif,jpg,jpeg,png,tif,tiff,pbm,bmp";
    
            if (StrUtil.isNotEmpty(fileExtention)) {
                fileExtention = fileExtention.toLowerCase();
    
                // If the request is an image
                if (imagesTypes.indexOf(fileExtention) >= 0) {
                    ServletOutputStream stream = null;
                    BufferedInputStream buf = null;
                    try {
                        stream = response.getOutputStream();
                        if (!SessionUtil.isAuthorize(request)) {
                            //change file to an error
                            fileExtention = "jpeg";
                            finalFilePath = root + ".." + File.separator + "global" +
                                    File.separator + "access_denied.jpg";
                        }
                        File theFile = new File(finalFilePath);
                        response.setContentType("image/" + fileExtention);
                        response.setContentLength((int) theFile.length());
                        FileInputStream input = new FileInputStream(theFile);
                        buf = new BufferedInputStream(input);
                        int readBytes = 0;
                        while ((readBytes = buf.read()) != -1) {
                            stream.write(readBytes);
                        }
                    } catch (IOException ioe) {
                        throw new ServletException(ioe.getMessage());
                    } finally {
                        if (stream != null) {
                            stream.close();
                        }
                        if (buf != null) {
                            buf.close();
                        }
                    }
    
                    // If the request is text/html, etc.
                } else { //text/html
                    response.setContentType("text/html;charset=UTF-8");
                    PrintWriter out = response.getWriter();
                    if (!SessionUtil.isAuthorize(request)) {
                        //change file to an error
    
                        finalFilePath = root + ".." + File.separator + "global" +
                                File.separator + "access_denied.html";
                        //System.out.println("final:" + finalFilePath);
                    }
                    String content = FileUtil.loadFile(finalFilePath);
                    if(StrUtil.isEmpty(content)){
                        content = "Error Reading File at Location: " + finalFilePath;
                        //example http://localhost:8080/FactsWEB/path/html/root/Applications/Prod/Prod.html
                    }
                    try {
                        out.print(content);
                    } finally {
                        out.close();
                    }
                }
    
            }
    
    
        }
    
        public static void main(String[] args) {
            String finalFilePath = "c:\\home\\users\\factsweb\\root\\Applications/Prod/Prod.html";
            finalFilePath = finalFilePath.replace("/".charAt(0), File.separatorChar);
            finalFilePath = finalFilePath.replace("\\".charAt(0), File.separatorChar);
            //System.out.println("final:" + finalFilePath);
        }
    
        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        /** 
         * Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        }
    
        /** 
         * Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        }
    
        /** 
         * Returns a short description of the servlet.
         * @return a String containing servlet description
         */
        @Override
        public String getServletInfo() {
            return "Short description";
        }// </editor-fold>
    }
    this servlet need to be configure in the web.xml:
    Code:
        <servlet>
            <servlet-name>WebContentDispatcher</servlet-name>
            <servlet-class>cl.company.informs.controller.WebContentDispatcher</servlet-class>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>WebContentDispatcher</servlet-name>
            <url-pattern>/path/*</url-pattern>
        </servlet-mapping>
    If someone request this uri
    Code:
    http://localhost:8080/YourAppNameWEB/path/gif/someImage.gif

    The WebContentDispatcher will go get the file from your root then go inside the folder gif, reads the someImage.gif and send the image via the servlet.

    But before sending it it checks if the user is inside the session, if not it will read from root/global/access_denied.jpg and send a nice image saying "access denied". Same for the html access_denied.html.

    The SessionUtil.isAuthorize have to be done by you:
    Code:
    public static boolean isAuthorize(HttpServletRequest request) { .. 
    //check if session expired
    //check if user is logged.
    }



    Note: upload needs to send response.setContentType("text/html;charset=UTF-8");
    otherwise it will download the .do file.

    Note2: download is not implemented in this release.

    Note3: i neede to add this image from your ext resources

    FactsWEB\web\js\filetreepanel\ext\resources\images\default\grid\wait.gif
    FactsWEB\web\js\filetreepanel\ext\resources\images\default\tree\folder.gif
    FactsWEB\web\js\filetreepanel\ext\resources\images\default\tree\folder-open.gif

    FactsWeb = the name of my java web app.

    Note4: yes you will need to change my code to make it work for you. Lazy !!

  7. #727
    Ext JS Premium Member Bobrovnik's Avatar
    Join Date
    Jul 2009
    Posts
    74
    Vote Rating
    0
    Bobrovnik is on a distinguished road

      0  

    Default


    Hi, are you going to make version valid for Ext 3.

    When I am trying to use your plugin and it throws me an exeptions. Like in topic https://extjs.com/forum/showthread.p...574#post375574 Could you please suggest any solution?

  8. #728
    Ext JS Premium Member Bobrovnik's Avatar
    Join Date
    Jul 2009
    Posts
    74
    Vote Rating
    0
    Bobrovnik is on a distinguished road

      0  

    Default


    After a day of trying to find out mistake. I have made some changes to FileTree extention, so now it works with Extjs 3.0 version.

    In file Ext.ux.FileTreeMenu.js

    PHP Code:
     var uploadPanelConfig = {
     
    contextmenu:this
    ,buttonsAt:config.buttonsAt || 'tbar'
     
    ,singleUpload:config.singleUpload || false
     
    ,maxFileSize:config.maxFileSize
     
    ,enableProgress:config.enableProgress
     
    }; 
    should be replaced with
    PHP Code:
    var uploadPanelConfig = {
            
    hideOnClick:false
            
    ,cmd:'upload-panel'
            
    ,contextmenu:this
            
    ,buttonsAt:config.buttonsAt || 'tbar'
            
    ,singleUpload:config.singleUpload || false
            
    ,maxFileSize:config.maxFileSize
            
    ,enableProgress:config.enableProgress
        
    }; 
    PHP Code:
     ,new Ext.menu.Adapter(new Ext.ux.UploadPanel(uploadPanelConfig), {
      
    hideOnClick:false
      
    ,cmd:'upload-panel'
    }) 
    with
    PHP Code:
    ,new Ext.ux.UploadPanel(uploadPanelConfig
    in file Ext.ux.FileTreePanel.js

    PHP Code:
    this.uploadPanel this.contextmenu.getItemByCmd('upload-panel').component
    replace with
    PHP Code:
    this.uploadPanel this.contextmenu.getItemByCmd('upload-panel'); 
    in file Ext.ux.FileUploader.js

    PHP Code:
    record.set('form'form); 
    with
    PHP Code:
    if(Ext.isIE)
        
    record.set('form'undefined);  // IE fix, without this it throws an exception
    else
        
    record.set('form'form); 
    in file Ext.ux.form.BrowseButton.js

    PHP Code:
       this.buttonCt this.el.child('.x-btn-center em'); 
    with
    PHP Code:
    this.buttonCt this.el.child('.x-btn-mc em'); 
    PHP Code:
    style: {
       
    position'absolute',
       
    cursor'pointer',
       
    right'0px',
       
    top'10px'

    with
    PHP Code:
    style: {
       
    position'absolute',
       
    cursor'pointer',
       
    right'0px',
       
    topExt.isIE '10px' :'0px' // Also another IE fix

    in file Ext.ux.UploadPanel.js Add line

    PHP Code:
    this.ownerCt.doLayout(); 
    PHP Code:
    ,onAddFile:function(bb) {
            
            if(
    true !== this.eventsSuspended && false === this.fireEvent('beforefileadd'thisbb.getInputFile())) {
                return;
            }
            var 
    inp bb.detachInputFile();
            
    inp.addClass('x-hidden');
            var 
    fileName this.getFileName(inp);

            
    // create new record and add it to store
            
    var rec = new this.store.recordType({
                 
    input:inp
                
    ,fileName:fileName
                
    ,filePath:this.getFilePath(inp)
                ,
    shortNameExt.util.Format.ellipsis(fileNamethis.maxLength)
                ,
    fileCls:this.getFileCls(fileName)
                ,
    state:'queued'
            
    }, inp.id);
            
    rec.commit();
            
    this.store.add(rec);

            
    this.syncShadow();

            
    this.uploadBtn.enable();
            
    this.removeAllBtn.enable();
            
            
    this.ownerCt.doLayout();
            
            if(
    true !== this.eventsSuspended) {
                
    this.fireEvent('fileadd'thisthis.storerec);
            }

        } 
    // eo onAddFile 

  9. #729
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,162
    Vote Rating
    322
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Thank you very much for finding and sharing these patches.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Blessing and Curse of refs, Grid MultiSearch Plugin


  10. #730
    Sencha User
    Join Date
    Jul 2009
    Posts
    32
    Vote Rating
    0
    avsomeren is on a distinguished road

      0  

    Default


    In the last codeblocks of your patch you are writing :

    in file Ext.ux.FileUploader.js Add line
    Code:
    this.ownerCt.doLayout(); 
    i presume you mean Ext.ux.UploadPanel.js ...

Thread Participants: 173

  1. danvega (10 Posts)
  2. jay@moduscreate.com (1 Post)
  3. jweber (1 Post)
  4. jt (1 Post)
  5. slacker775 (2 Posts)
  6. vmorale4 (12 Posts)
  7. stever (2 Posts)
  8. Dumbledore (9 Posts)
  9. ismoore (1 Post)
  10. mystix (8 Posts)
  11. sdrew (3 Posts)
  12. mxracer (1 Post)
  13. Foggy (3 Posts)
  14. madrabaz (8 Posts)
  15. Thorsten (4 Posts)
  16. Fabyo (1 Post)
  17. mschaefer (11 Posts)
  18. tchitani (3 Posts)
  19. loeppky (11 Posts)
  20. damsfx (1 Post)
  21. cmendez21 (7 Posts)
  22. anjelika (3 Posts)
  23. randcasburn (3 Posts)
  24. mjlecomte (3 Posts)
  25. esoteric (10 Posts)
  26. pravin_bluebird (1 Post)
  27. ZooKeeper (4 Posts)
  28. george.antoniadis (1 Post)
  29. fermo111 (1 Post)
  30. glaforge (2 Posts)
  31. Spirit (1 Post)
  32. newc_k (1 Post)
  33. adam.jimenez (9 Posts)
  34. juandj (10 Posts)
  35. rballman (2 Posts)
  36. Michelangelo (6 Posts)
  37. kk_kkk (7 Posts)
  38. issomesmo (5 Posts)
  39. mashiki (1 Post)
  40. juljupy (2 Posts)
  41. cafebabe (1 Post)
  42. ferrenliu (1 Post)
  43. smartlit (14 Posts)
  44. chunkT (1 Post)
  45. mankz (6 Posts)
  46. luisparada (4 Posts)
  47. iDevelopment (4 Posts)
  48. cblin (9 Posts)
  49. ljaeren (2 Posts)
  50. endlichstudent (9 Posts)
  51. RacingTomcat (1 Post)
  52. lobo-tuerto (5 Posts)
  53. maximumcoder (1 Post)
  54. calavera (3 Posts)
  55. ningle (5 Posts)
  56. jbird526 (4 Posts)
  57. sekundek (8 Posts)
  58. GokhanNL (1 Post)
  59. markkl (1 Post)
  60. basshcm (2 Posts)
  61. dbraiden (2 Posts)
  62. incaic (2 Posts)
  63. silcreval (6 Posts)
  64. sirioz10 (2 Posts)
  65. iulian (2 Posts)
  66. hsurya (7 Posts)
  67. johnrembo (2 Posts)
  68. fraric (4 Posts)
  69. Silver Paladin (5 Posts)
  70. Rafael (2 Posts)
  71. treqx (1 Post)
  72. spectrus (6 Posts)
  73. JoyfulBobHome (2 Posts)
  74. fxlacroix (3 Posts)
  75. jove4015 (1 Post)
  76. rtrocc (12 Posts)
  77. carl23934 (1 Post)
  78. ClemsonJeeper (1 Post)
  79. lagos.tout (2 Posts)
  80. craigharmonic (3 Posts)
  81. siebertm (3 Posts)
  82. zombeerose (11 Posts)
  83. keckeroo (1 Post)
  84. dotchris (7 Posts)
  85. fallenone (4 Posts)
  86. yhwh (1 Post)
  87. harirama (2 Posts)
  88. scroll (1 Post)
  89. mlim1972 (4 Posts)
  90. Arthur.Blake (1 Post)
  91. nileshgund (1 Post)
  92. blow (1 Post)
  93. piyushjain7 (1 Post)
  94. njeriextjs (3 Posts)
  95. hileon (1 Post)
  96. bomka (15 Posts)
  97. --maty (1 Post)
  98. WhiteRussian (1 Post)
  99. kpopov (1 Post)
  100. captainfish (5 Posts)
  101. Gosa (5 Posts)
  102. extjsF4n (1 Post)
  103. Chida (1 Post)
  104. Nthalk (2 Posts)
  105. nescha (2 Posts)
  106. jorgemuza (3 Posts)
  107. Eric24 (1 Post)
  108. edui (1 Post)
  109. shadoi (4 Posts)
  110. acidfilez (1 Post)
  111. BrainDrain (2 Posts)
  112. dimitrij.zub (1 Post)
  113. ixnixnixn (2 Posts)
  114. calicoder (2 Posts)
  115. wes (1 Post)
  116. mammerman (1 Post)
  117. Voronchuk (3 Posts)
  118. jwmianzu (3 Posts)
  119. gnomie (2 Posts)
  120. pflammer (2 Posts)
  121. The0s (2 Posts)
  122. gogogo521 (1 Post)
  123. tegel (2 Posts)
  124. wulfshayde (2 Posts)
  125. mikecx (2 Posts)
  126. paul@demiduk.com (1 Post)
  127. romulodelazzari (1 Post)
  128. sabline (2 Posts)
  129. mikecc (8 Posts)
  130. dan.plifeye (2 Posts)
  131. JGALFO (1 Post)
  132. Stephan Schrade (3 Posts)
  133. khurri.saleem (1 Post)
  134. voidus (1 Post)
  135. Shockdoc1 (1 Post)
  136. dport (3 Posts)
  137. jahman (3 Posts)
  138. Pachat (4 Posts)
  139. BIS (1 Post)
  140. sanraj (4 Posts)
  141. deemonas (1 Post)
  142. jpipas (2 Posts)
  143. martinrame (2 Posts)
  144. MrEnirO (2 Posts)
  145. elona (1 Post)
  146. cwford (6 Posts)
  147. triptonemeister (2 Posts)
  148. gonzalez (1 Post)
  149. wallacer (1 Post)
  150. Natalie (2 Posts)
  151. Phatnine (2 Posts)
  152. js_coder (3 Posts)
  153. Bobrovnik (4 Posts)
  154. kender (1 Post)
  155. avsomeren (2 Posts)
  156. rkulkarni (2 Posts)
  157. lxfliu (2 Posts)
  158. pbaker99 (2 Posts)
  159. naf305 (2 Posts)
  160. cybervirax (1 Post)
  161. AmrMostafa (1 Post)
  162. tumbochka (1 Post)
  163. exdelierium (1 Post)
  164. toubeau (4 Posts)
  165. nosferatum (1 Post)
  166. Boy.Kortman (1 Post)
  167. erlinis (1 Post)
  168. nhocoi (2 Posts)
  169. varunach (1 Post)
  170. _DR_ (1 Post)
  171. rodenp (1 Post)
  172. tutuianu_daniel (1 Post)
  173. Shabneez (2 Posts)

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar