Roo/dialog/UploadCropbox.js
[roojs1] / Roo / dialog / UploadCropbox.js
index 170d21b..6271d21 100644 (file)
@@ -387,7 +387,6 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     
     onFileSelected : function(e)
     {
-        console.log("ON FILE SELECTED");
         e.preventDefault();
         
         if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
@@ -414,8 +413,6 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     
     loadCanvas : function(src)
     {   
-        console.log("LOAD CANVAS");
-        console.log(src);
         if(this.fireEvent('beforeloadcanvas', this, src) != false){
             
             this.reset();
@@ -432,7 +429,6 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     
     onLoadCanvas : function()
     {   
-        console.log("ON LOAD CANVAS");
         this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
         this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
 
@@ -470,7 +466,6 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     
     setCanvasPosition : function()
     {   
-        console.log("SET CANVAS POSITION");
         if(!this.canvasEl){
             return;
         }
@@ -563,14 +558,11 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         this.startScale = this.scale;
         this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
         
-        console.log("START SCALE:" . startScale);
-        console.log("TEST SCALE: " . startScale);
         if(!this.zoomable()){
             this.scale = this.startScale;
             return;
         }
 
-        console.log("END SCALE: " . endScale);
         
         this.draw();
         
@@ -584,12 +576,15 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         if(this.minWidth < this.minHeight){
             minScale = this.thumbEl.getHeight() / this.minHeight;
         }
-
-        console.log("MINSCALE: " + minScale);
         
         var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
         var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
 
+        console.log("ZOOM");
+        console.log("WIDTH: " + (this.thumbEl.getWidth() / this.getScaleLevel()));
+        console.log("HEIGHT: " + (this.thumbEl.getHeight() / this.getScaleLevel()));
+
+
         var maxWidth = this.imageEl.OriginWidth;
         var maxHeight = this.imageEl.OriginHeight;
         
@@ -621,8 +616,8 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
                 !this.isDocument &&
                 (this.rotate == 0 || this.rotate == 180) && 
                 (
-                    width < this.minWidth ||
-                    height < this.minHeight ||
+                    (this.imageEl.OriginWidth >= this.minWidth) && width < this.minWidth ||
+                    (this.imageEl.OriginHeight >= this.minHeight) && height < this.minHeight ||
                     width > maxWidth ||
                     height > maxHeight
                 )
@@ -765,14 +760,11 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     
     draw : function()
     {
-        console.log("DRAW");
         this.previewEl.dom.innerHTML = '';
         
         var canvasEl = document.createElement("canvas");
         
         var contextEl = canvasEl.getContext("2d");
-
-        console.log(this.getScaleLevel());
         
         canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
         canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
@@ -854,6 +846,7 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     
     crop : function()
     {
+        console.log("CROP");
         if(!this.canvasLoaded){
             return;
         }
@@ -864,6 +857,9 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         
         imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
         imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
+
+        console.log("IMAGECANVAS WIDTH: " + imageCanvas.width);
+        console.log("IMAGECANVAS HEIGHT: " + imageCanvas.height);
         
         var center = imageCanvas.width / 2;
         
@@ -876,44 +872,64 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         var canvas = document.createElement("canvas");
         
         var context = canvas.getContext("2d");
-                
-        canvas.width = this.minWidth;
-        canvas.height = this.minHeight;
+
+        canvas.width = this.thumbEl.getWidth() / this.getScaleLevel();
+        
+        canvas.height = this.thumbEl.getHeight() / this.getScaleLevel();
+
+        console.log("CANVAS WIDTH: " + canvas.width);
+        console.log("CANVAS HEIGHT: " + canvas.height);
+
+        console.log("SCALELEVLE: " + scaleLevel);
 
         switch (this.rotate) {
             case 0 :
                 
                 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
                 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
+
+                console.log("WIDTH: " + width);
+                console.log("HEIGHT: " + height);
                 
                 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
                 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
+
+                console.log("X: " + x);
+                console.log("Y: " + y);
                 
-                var targetWidth = this.minWidth - 2 * x;
-                var targetHeight = this.minHeight - 2 * y;
+                // var targetWidth = this.minWidth - 2 * x;
+                // var targetHeight = this.minHeight - 2 * y;
+
+                // console.log("targetWidth: " + targetWidth);
+                // console.log("targetHeight: " + targetHeight);
                 
-                var scale = 1;
+                // var scale = 1;
                 
-                if((x == 0 && y == 0) || (x == 0 && y > 0)){
-                    scale = targetWidth / width;
-                }
+                // if((x == 0 && y == 0) || (x == 0 && y > 0)){
+                //     scale = targetWidth / width;
+                // }
                 
-                if(x > 0 && y == 0){
-                    scale = targetHeight / height;
-                }
+                // if(x > 0 && y == 0){
+                //     scale = targetHeight / height;
+                // }
                 
-                if(x > 0 && y > 0){
-                    scale = targetWidth / width;
+                // if(x > 0 && y > 0){
+                //     scale = targetWidth / width;
                     
-                    if(width < height){
-                        scale = targetHeight / height;
-                    }
-                }
+                //     if(width < height){
+                //         scale = targetHeight / height;
+                //     }
+                // }
+
+                // console.log("scale: " + scale);
                 
-                context.scale(scale, scale);
+                // context.scale(scale, scale);
                 
-                var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
-                var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
+                var sx = this.thumbEl.getLeft(true) - this.previewEl.getLeft(true);
+                var sy = this.thumbEl.getTop(true) - this.previewEl.getTop(true);
+
+                console.log("sx: " + sx);
+                console.log("sy: " + sy);
 
                 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
                 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
@@ -1036,7 +1052,6 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
                 }
                 
                 context.scale(scale, scale);
-                
                 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
                 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
 
@@ -1098,7 +1113,6 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     
     setThumbBoxPosition : function()
     {
-        console.log("SET THUMBBOX POSITION");
         var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
         var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
         
@@ -1109,7 +1123,6 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     
     baseRotateLevel : function()
     {
-        console.log("BASE ROTATE LEVEL");
         this.baseRotate = 1;
         
         if(
@@ -1335,14 +1348,20 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         
         var formData = new FormData();
 
+        formData.append("onid", "43024");
+        formData.append("ontable", "pressrelease_boilerplate");
+
         formData.append('returnHTML', 'NO');
         
         if(crop){
             formData.append('crop', crop);
-        }
-        
-        if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
-            formData.append(this.paramName, file, file.name);
+            var blobBin = atob(crop.split(',')[1]);
+            var array = [];
+            for(var i = 0; i < blobBin.length; i++) {
+                array.push(blobBin.charCodeAt(i));
+            }
+            var croppedFile =new Blob([new Uint8Array(array)], {type: 'image/png'});
+            formData.append(this.paramName, croppedFile, file.name);
         }
         
         if(typeof(file.filename) != 'undefined'){
@@ -1352,7 +1371,7 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         if(typeof(file.mimetype) != 'undefined'){
             formData.append('mimetype', file.mimetype);
         }
-        
+
         if(this.fireEvent('arrange', this, formData) != false){
             this.xhr.send(formData);
         };
@@ -1398,8 +1417,6 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     
     prepare : function(file)
     {   
-        console.log("PREPARE");
-        console.log(file);
         if(this.loadMask){
             this.maskEl.mask(this.loadingText);
         }