mujma: Added exclusive lock on image operation. Starting each operation block others i.e you cannot rotate image when you are cropping area from it.

(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@41901 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-15 01:31:31 +00:00
parent 00f262e445
commit 71cb143070
5 changed files with 108 additions and 30 deletions

View File

@ -20,6 +20,8 @@ var Crop = {
this.onCropCancel = Crop.onCropCancel.bind(this); this.onCropCancel = Crop.onCropCancel.bind(this);
this.doCrop = Crop.doCrop.bind(this); this.doCrop = Crop.doCrop.bind(this);
this.setVisible = Crop.setVisible.bind(this); this.setVisible = Crop.setVisible.bind(this);
this.enable = Crop.enable.bind(this);
this.disable = Crop.disable.bind(this);
Event.observe('image','load',this.centerCropBox); Event.observe('image','load',this.centerCropBox);
options = { options = {
resizeStop: Crop.resizeStop.bind(this), resizeStop: Crop.resizeStop.bind(this),
@ -31,6 +33,7 @@ var Crop = {
Event.observe(this.cropBox,'dblclick',this.onCropStop.bind(this)); Event.observe(this.cropBox,'dblclick',this.onCropStop.bind(this));
this.setListeners(); this.setListeners();
this.setVisible(false); this.setVisible(false);
this.isEnabled = true;
}, },
resizeStop: function(event) { resizeStop: function(event) {
@ -88,22 +91,32 @@ var Crop = {
}, },
onCropStop: function(event) { onCropStop: function(event) {
Element.hide($('cropOk'),$('cropCancel'));
this.doCrop(); this.doCrop();
}, },
doCrop: function() { doCrop: function() {
newWidth = this.cropBox.getWidth() if(this.isEnabled) {
newHeight = this.cropBox.getHeight() ; newWidth = this.cropBox.getWidth()
startTop = this.cropBox.getTop() ; newHeight = this.cropBox.getHeight() ;
startLeft = this.cropBox.getLeft() ; startTop = this.cropBox.getTop() ;
if(newWidth > 35 && newHeight > 35) { startLeft = this.cropBox.getLeft() ;
imageTransformation.crop(startTop,startLeft,newWidth,newHeight); if(newWidth > 35 && newHeight > 35) {
imageHistory.enable(); imageTransformation.crop(startTop,startLeft,newWidth,newHeight,Crop.cropCallback.bind(this));
} else { imageHistory.enable();
alert('Crop area too small'); } else {
alert('Crop area too small');
}
this.disable();
} }
}, },
cropCallback: function() {
effects.enableRotate();
this.enable();
},
setListeners: function() { setListeners: function() {
Event.observe('cropStart','click',this.onCropStart); Event.observe('cropStart','click',this.onCropStart);
Event.observe('cropOk','click',this.onCropOk); Event.observe('cropOk','click',this.onCropOk);
@ -111,20 +124,29 @@ var Crop = {
}, },
onCropStart: function() { onCropStart: function() {
this.setVisible(true); if(this.isEnabled) {
Element.show($('cropOk'),$('cropCancel')); this.setVisible(true);
imageHistory.disable(); Element.show($('cropOk'),$('cropCancel'));
imageHistory.disable();
effects.disableRotate();
}
}, },
onCropOk: function() { onCropOk: function() {
Element.hide($('cropOk'),$('cropCancel')); if(this.isEnabled) {
this.doCrop(); Element.hide($('cropOk'),$('cropCancel'));
this.doCrop();
effects.disableRotate();
}
}, },
onCropCancel: function() { onCropCancel: function() {
Element.hide($('cropOk'),$('cropCancel')); if(this.isEnabled) {
this.setVisible(false); Element.hide($('cropOk'),$('cropCancel'));
imageHistory.enable(); this.setVisible(false);
imageHistory.enable();
effects.enableRotate();
}
}, },
setVisible: function(setVisible) { setVisible: function(setVisible) {
@ -137,5 +159,14 @@ var Crop = {
} }
resize.imageContainerResize.setVisible(!setVisible); resize.imageContainerResize.setVisible(!setVisible);
this.resizeCropBox.setVisible(setVisible); this.resizeCropBox.setVisible(setVisible);
} },
enable: function() {
this.isEnabled = true;
},
disable: function() {
this.isEnabled = false;
}
} }

View File

@ -5,14 +5,37 @@ var Effects = {
initialize: function() { initialize: function() {
this.setListeners = Effects.setListeners.bind(this); this.setListeners = Effects.setListeners.bind(this);
this.rotate = Effects.rotate.bind(this); this.rotate = Effects.rotate.bind(this);
this.setListeners(); this.setListeners();
this.isRotateEnabled = true;
this.enableRotate = Effects.enableRotate.bind(this);
this.disableRotate = Effects.disableRotate.bind(this);
}, },
rotate: function() { rotate: function() {
imageTransformation.rotate(90); if(this.isRotateEnabled) {
resize.imageContainerResize.disable();
crop.disable();
imageTransformation.rotate(90,Effects.rotateCallback.bind(this));
this.isRotateEnabled = false;
}
},
rotateCallback: function() {
resize.imageContainerResize.enable();
crop.enable();
this.isRotateEnabled = true;
}, },
setListeners: function() { setListeners: function() {
Event.observe('rotateButton','click',this.rotate); Event.observe('rotateButton','click',this.rotate);
} },
disableRotate: function() {
this.isRotateEnabled = false;
},
enableRotate: function() {
this.isRotateEnabled = true;
}
} }

View File

@ -37,7 +37,7 @@ var ImageTransformation = {
new Ajax.Request('admin/ImageEditor/manipulate', options); new Ajax.Request('admin/ImageEditor/manipulate', options);
}, },
rotate: function(angle) { rotate: function(angle,callback) {
var options = { var options = {
method: 'post', method: 'post',
postBody: 'command=rotate&file=' + $('image').src + '&angle=' + angle , postBody: 'command=rotate&file=' + $('image').src + '&angle=' + angle ,
@ -51,7 +51,8 @@ var ImageTransformation = {
$('imageContainer').style.width = response.width + 'px'; $('imageContainer').style.width = response.width + 'px';
$('imageContainer').style.height = response.height + 'px'; $('imageContainer').style.height = response.height + 'px';
imageHistory.add('rotate',$('image').src); imageHistory.add('rotate',$('image').src);
resize.imageContainerResize.placeClickBox(); resize.imageContainerResize.placeClickBox();
if(callback != null) callback();
} }
}; };
imageBox.showIndicator(); imageBox.showIndicator();
@ -59,7 +60,7 @@ var ImageTransformation = {
new Ajax.Request('admin/ImageEditor/manipulate', options); new Ajax.Request('admin/ImageEditor/manipulate', options);
}, },
crop: function(top,left,width,height) { crop: function(top,left,width,height,callback) {
var options = { var options = {
method: 'post', method: 'post',
postBody: 'command=crop&file=' + $('image').src + '&top=' + top + '&left=' + left + '&width=' + width + '&height=' + height, postBody: 'command=crop&file=' + $('image').src + '&top=' + top + '&left=' + left + '&width=' + width + '&height=' + height,
@ -73,6 +74,7 @@ var ImageTransformation = {
$('imageContainer').style.height = response.height + 'px'; $('imageContainer').style.height = response.height + 'px';
imageHistory.add('crop',$('image').src); imageHistory.add('crop',$('image').src);
crop.setVisible(false); crop.setVisible(false);
if(callback != null) callback();
} }
}; };
imageBox.showIndicator(); imageBox.showIndicator();

View File

@ -20,11 +20,22 @@ var Resize = {
}, },
resizeStop: function(event) { resizeStop: function(event) {
imageElement = $('image'); if(EventStack.getLastEventElement() != null) {
EventStack.clearStack(); imageElement = $('image');
if(this.imageContainerResize.originalWidth != imageElement.width || this.imageContainerResize.originalHeight != imageElement.height) { EventStack.clearStack();
imageTransformation.resize(imageElement.width,imageElement.height); if(this.imageContainerResize.originalWidth != imageElement.width || this.imageContainerResize.originalHeight != imageElement.height) {
} imageTransformation.resize(imageElement.width,imageElement.height,Resize.resizeCallback.bind(this));
}
effects.disableRotate();
crop.disable();
this.imageContainerResize.disable();
}
},
resizeCallback: function() {
effects.enableRotate();
crop.enable();
this.imageContainerResize.enable();
}, },
onDrag: function() onDrag: function()

View File

@ -16,6 +16,7 @@ Resizeable = {
this.placeClickBoxOnImageLoad(); this.placeClickBoxOnImageLoad();
this.originalHeight = 0; this.originalHeight = 0;
this.originalWidth = 0; this.originalWidth = 0;
this.isEnabled = true;
}, },
resizeStart: function(event) { resizeStart: function(event) {
@ -75,7 +76,7 @@ Resizeable = {
}, },
onResize: function(event) { onResize: function(event) {
if(EventStack.getLastEventElement() != null && this.isVisible) { if(EventStack.getLastEventElement() != null && this.isVisible && this.isEnabled) {
lastEventElement = EventStack.getLastEventElement(); lastEventElement = EventStack.getLastEventElement();
var relativeMouseX = this.getMousePos(event).x - this.element.getParentLeft(); var relativeMouseX = this.getMousePos(event).x - this.element.getParentLeft();
var relativeMouseY = this.getMousePos(event).y - this.element.getParentTop(); var relativeMouseY = this.getMousePos(event).y - this.element.getParentTop();
@ -217,6 +218,8 @@ Resizeable = {
this.addDraging = Resizeable.addDraging.bind(this); this.addDraging = Resizeable.addDraging.bind(this);
this.setVisible = Resizeable.setVisible.bind(this); this.setVisible = Resizeable.setVisible.bind(this);
this.removeDraging = Resizeable.removeDraging.bind(this); this.removeDraging = Resizeable.removeDraging.bind(this);
this.disable = Resizeable.disable.bind(this);
this.enable = Resizeable.enable.bind(this);
this.leftUpperDrag = Resizeable.leftUpperDrag.bind(this); this.leftUpperDrag = Resizeable.leftUpperDrag.bind(this);
this.leftMiddleDrag = Resizeable.leftMiddleDrag.bind(this); this.leftMiddleDrag = Resizeable.leftMiddleDrag.bind(this);
@ -284,5 +287,13 @@ Resizeable = {
this.lowerMiddleClickBox); this.lowerMiddleClickBox);
this.removeDraging(); this.removeDraging();
} }
},
disable: function() {
this.isEnabled = false;
},
enable: function() {
this.isEnabled = true;
} }
} }