Loading ...
Sorry, an error occurred while loading the content.

49181Re: YUI Uploader in Extjs

Expand Messages
  • sepideh_r
    May 30, 2009
    • 0 Attachment
      Hi,

      Here is a clean code with abs. urls, avoiding possible mistakes on namespacing...
      What I am missing? :S

      thanks



      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
      <head>
      <title id="page-title">Clean call</title>

      <!-- *************************************************************************************** -->
      <style type="text/css">
      /*margin and padding on body element
      can introduce errors in determining
      element position and are not recommended;
      we turn them off as a foundation for YUI
      CSS treatments. */
      body {
      margin:0;
      padding:0;
      }
      </style>
      <!-- *************************************************************************************** -->

      <link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css" />
      <script src="../ext/adapter/ext/ext-base.js"></script>

      <!-- *************************************************************************************** -->
      <link rel="stylesheet" type="text/css" href="/uploader/clean/build/fonts/fonts-min.css" />
      <link rel="stylesheet" type="text/css" href="/uploader/clean/build/datatable/assets/skins/sam/datatable.css" />
      <script type="text/javascript" src="/uploader/clean/build/utilities.js"></script>
      <script type="text/javascript" src="/uploader/clean/build/yahoo-dom-event/yahoo-dom-event.js"></script>
      <script type="text/javascript" src="/uploader/clean/build/element/element-min.js"></script>
      <script type="text/javascript" src="/uploader/clean/build/uploader/uploader.js"></script>
      <script type="text/javascript" src="/uploader/clean/build/datasource/datasource-min.js"></script>
      <script type="text/javascript" src="/uploader/clean/build/datatable/datatable-min.js"></script>
      <!-- *************************************************************************************** -->
      <script type="text/javascript" src="/uploader/ext/adapter/yui/ext-yui-adapter.js"></script>
      <script src="../ext/ext-all-debug.js"></script>
      <script>
      Ext.onReady(function(){

      var win = new Ext.Window({
      width:400
      ,id:'autoload-win'
      ,height:300
      ,autoScroll:true
      ,autoLoad:false
      ,title:Ext.getDom('page-title').innerHTML
      ,tbl: new Ext.XTemplate(
      '<div id="uiElements" style="display:inline;">',
      '<br><br><div id="uploaderContainer">',
      '<div id="uploaderOverlay" style="position:absolute; z-index:2;border:1px solid crimson"></div>',
      '<div id="selectFilesLink" style="z-index:1"><a id="selectLink" href="#">Select Files</a></div>',
      '</div><br>',
      '<div id="uploadFilesLink"><a id="uploadLink" onClick="upload(); return false;" href="#">Upload Files</a></div>',
      '</div>',
      '<div id="simUploads"> Number of simultaneous uploads:',
      '<select id="simulUploads">',
      '<option value="1">1</option>',
      '<option value="2">2</option>',
      '<option value="3">3</option>',
      '<option value="4">4</option>',
      '</select>',
      '</div>',
      '<div id="dataTableContainer"></div>'
      ),
      listeners:{show:function() {
      this.tbl.overwrite(this.body, this);


      YAHOO.util.Event.onDOMReady(function () {
      var uiLayer = YAHOO.util.Dom.getRegion("selectLink");
      var overlay = YAHOO.util.Dom.get("uploaderOverlay");
      YAHOO.util.Dom.setStyle(overlay, 'width', uiLayer.right-uiLayer.left + "px");
      YAHOO.util.Dom.setStyle(overlay, "height", uiLayer.bottom-uiLayer.top + "px");
      });

      // Custom URL for the uploader swf file (same folder).
      YAHOO.widget.Uploader.SWFURL = "/uploader/clean/build/uploader/assets/uploader.swf";

      // Instantiate the uploader and write it to its placeholder div.
      var uploader = new YAHOO.widget.Uploader( "uploaderOverlay" );

      // Add event listeners to various events on the uploader.
      // Methods on the uploader should only be called once the
      // contentReady event has fired.

      uploader.addListener("contentReady", handleContentReady);
      uploader.addListener("fileSelect", onFileSelect)
      uploader.addListener("uploadStart", onUploadStart);
      uploader.addListener("uploadProgress", onUploadProgress);
      uploader.addListener("uploadCancel", onUploadCancel);
      uploader.addListener("uploadComplete", onUploadComplete);
      uploader.addListener("uploadCompleteData", onUploadResponse);
      uploader.addListener("uploadError", onUploadError);
      uploader.addListener("rollOver", handleRollOver);
      uploader.addListener("rollOut", handleRollOut);
      uploader.addListener("click", handleClick);

      // Variable for holding the filelist.
      var fileList;


      // When the mouse rolls over the uploader, this function
      // is called in response to the rollOver event.
      // It changes the appearance of the UI element below the Flash overlay.
      function handleRollOver () {
      YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "color", "#FFFFFF");
      YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "background-color", "#000000");
      }

      // On rollOut event, this function is called, which changes the appearance of the
      // UI element below the Flash layer back to its original state.
      function handleRollOut () {
      YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "color", "#0000CC");
      YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "background-color", "#FFFFFF");
      }

      // When the Flash layer is clicked, the "Browse" dialog is invoked.
      // The click event handler allows you to do something else if you need to.
      function handleClick () {
      }

      // When contentReady event is fired, you can call methods on the uploader.
      function handleContentReady () {
      // Allows multiple file selection in "Browse" dialog.
      uploader.setAllowMultipleFiles(true);
      }

      //console.log(uploader);
      //console.log(fileList);

      // Actually uploads the files. In this case,
      // uploadAll() is used for automated queueing and upload
      // of all files on the list.
      // You can manage the queue on your own and use "upload" instead,
      // if you need to modify the properties of the request for each
      // individual file.
      function upload() {
      if (fileList != null) {
      uploader.setSimUploadLimit(parseInt(document.getElementById("simulUploads").value));
      uploader.uploadAll("../upload_simple.php", "POST", null, "Filedata");
      }
      }

      // Fired when the user selects files in the "Browse" dialog
      // and clicks "Ok".
      function onFileSelect(event) {
      if(event.fileList != null) {
      fileList = event.fileList;
      createDataTable(fileList);
      }
      }



      function createDataTable(entries) {


      rowCounter = 0;
      this.fileIdHash = {};
      this.dataArr = [];
      for(var i in entries) {
      var entry = entries[i];
      entry["progress"] = "<div style='height:5px;width:100px;background-color:#CCC;'></div>";
      dataArr.unshift(entry);
      }

      for (var j = 0; j < dataArr.length; j++) {
      this.fileIdHash[dataArr[j].id] = j;
      }

      var myColumnDefs = [
      {key:"name", label: "File Name", sortable:false},
      {key:"size", label: "Size", sortable:false},
      {key:"mDate", label: "Created", sortable:false},
      {key:"modified", label: "Modified", sortable:false},
      {key:"type", label: "Type", sortable:false},
      {key:"progress", label: "Upload progress", sortable:false}
      ];

      this.myDataSource = new YAHOO.util.DataSource(dataArr);
      this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
      this.myDataSource.responseSchema = {
      fields: ["id","name","mDate","modified","type", "size", "progress"]
      };

      this.singleSelectDataTable = new YAHOO.widget.DataTable("dataTableContainer",
      myColumnDefs, this.myDataSource, {
      caption:"Files To Upload",
      selectionMode:"single"
      });
      }

      // Do something on each file's upload start.
      function onUploadStart(event) {

      }

      // Do something on each file's upload progress event.
      function onUploadProgress(event) {
      rowNum = fileIdHash[event["id"]];
      prog = Math.round(100*(event["bytesLoaded"]/event["bytesTotal"]));
      progbar = "<div style='height:5px;width:100px;background-color:#CCC;'><div style='height:5px;background-color:#F00;width:" + prog + "px;'></div></div>";
      singleSelectDataTable.updateRow(rowNum, {name: dataArr[rowNum]["name"], mDate: dataArr[rowNum]["mDate"], size: dataArr[rowNum]["size"], type: dataArr[rowNum]["type"], progress: progbar});
      }

      // Do something when each file's upload is complete.
      function onUploadComplete(event) {
      rowNum = fileIdHash[event["id"]];
      prog = Math.round(100*(event["bytesLoaded"]/event["bytesTotal"]));
      progbar = "<div style='height:5px;width:100px;background-color:#CCC;'><div style='height:5px;background-color:#0F0;width:100px;'></div></div>";
      // singleSelectDataTable.updateRow(rowNum, {name: dataArr[rowNum]["name"], size: dataArr[rowNum]["size"], progress: progbar});
      singleSelectDataTable.updateRow(rowNum, {name: dataArr[rowNum]["name"], created: dataArr[rowNum]["created"], size: dataArr[rowNum]["size"], type: dataArr[rowNum]["type"], progress: progbar});
      }

      // Do something if a file upload throws an error.
      // (When uploadAll() is used, the Uploader will
      // attempt to continue uploading.
      function onUploadError(event) {

      }

      // Do something if an upload is cancelled.
      function onUploadCancel(event) {

      }

      // Do something when data is received back from the server.
      function onUploadResponse(event) {

      }
      }}
      });
      win.show();

      });
      </script>
      </head>
      <body>

      </body>
      </html>




      --- In ydn-javascript@yahoogroups.com, "sepideh_r" <sepideh_r@...> wrote:
      >
      > --- In ydn-javascript@yahoogroups.com, Adam Moore <adamoore@> wrote:
      > >
      > > On Fri, May 29, 2009 at 07:07:58PM -0000, sepideh_r wrote:
      > > > Tried to added uploader into extjs code but the "add file" link is not
      > > > activated. When I look at the swf path in FireBug, sounds correct but
      > > > uploader itself is not listed in dom window... any suggestion where
      > > > should I look for the problem, please?
      > >
      > > Re: 'sounds correct'... make sure it is correct. Make sure you read the
      > > sections of the documentation that talk about Flash version
      > > requirements, and SWF file location implications:
      > >
      > > http://developer.yahoo.com/yui/uploader/
      > >
      > > Beyond that, we will need to see the code to help.
      > >
      > > -Adam
      > >
      > Thanks for your quick reponse, Adam
      >
      > Okay, not "SOUNDs", it is really "CORRECT", have the successful response headers apearing in firebug. will clean up the code to add it here; uploader alone as a HTML was working perfectly... when tried to implement the html tags with extjs, lost the link... hmmm, will read more and clean up the code to ask for your help soon
      > thanks
      >
    • Show all 5 messages in this topic