mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
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:
parent
00f262e445
commit
71cb143070
@ -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,20 +91,30 @@ var Crop = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onCropStop: function(event) {
|
onCropStop: function(event) {
|
||||||
|
Element.hide($('cropOk'),$('cropCancel'));
|
||||||
this.doCrop();
|
this.doCrop();
|
||||||
},
|
},
|
||||||
|
|
||||||
doCrop: function() {
|
doCrop: function() {
|
||||||
|
if(this.isEnabled) {
|
||||||
newWidth = this.cropBox.getWidth()
|
newWidth = this.cropBox.getWidth()
|
||||||
newHeight = this.cropBox.getHeight() ;
|
newHeight = this.cropBox.getHeight() ;
|
||||||
startTop = this.cropBox.getTop() ;
|
startTop = this.cropBox.getTop() ;
|
||||||
startLeft = this.cropBox.getLeft() ;
|
startLeft = this.cropBox.getLeft() ;
|
||||||
if(newWidth > 35 && newHeight > 35) {
|
if(newWidth > 35 && newHeight > 35) {
|
||||||
imageTransformation.crop(startTop,startLeft,newWidth,newHeight);
|
imageTransformation.crop(startTop,startLeft,newWidth,newHeight,Crop.cropCallback.bind(this));
|
||||||
imageHistory.enable();
|
imageHistory.enable();
|
||||||
} else {
|
} else {
|
||||||
alert('Crop area too small');
|
alert('Crop area too small');
|
||||||
}
|
}
|
||||||
|
this.disable();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
cropCallback: function() {
|
||||||
|
effects.enableRotate();
|
||||||
|
this.enable();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setListeners: function() {
|
setListeners: function() {
|
||||||
@ -111,20 +124,29 @@ var Crop = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onCropStart: function() {
|
onCropStart: function() {
|
||||||
|
if(this.isEnabled) {
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
Element.show($('cropOk'),$('cropCancel'));
|
Element.show($('cropOk'),$('cropCancel'));
|
||||||
imageHistory.disable();
|
imageHistory.disable();
|
||||||
|
effects.disableRotate();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onCropOk: function() {
|
onCropOk: function() {
|
||||||
|
if(this.isEnabled) {
|
||||||
Element.hide($('cropOk'),$('cropCancel'));
|
Element.hide($('cropOk'),$('cropCancel'));
|
||||||
this.doCrop();
|
this.doCrop();
|
||||||
|
effects.disableRotate();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onCropCancel: function() {
|
onCropCancel: function() {
|
||||||
|
if(this.isEnabled) {
|
||||||
Element.hide($('cropOk'),$('cropCancel'));
|
Element.hide($('cropOk'),$('cropCancel'));
|
||||||
this.setVisible(false);
|
this.setVisible(false);
|
||||||
imageHistory.enable();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,13 +6,36 @@ var Effects = {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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 ,
|
||||||
@ -52,6 +52,7 @@ var ImageTransformation = {
|
|||||||
$('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();
|
||||||
|
@ -20,11 +20,22 @@ var Resize = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
resizeStop: function(event) {
|
resizeStop: function(event) {
|
||||||
|
if(EventStack.getLastEventElement() != null) {
|
||||||
imageElement = $('image');
|
imageElement = $('image');
|
||||||
EventStack.clearStack();
|
EventStack.clearStack();
|
||||||
if(this.imageContainerResize.originalWidth != imageElement.width || this.imageContainerResize.originalHeight != imageElement.height) {
|
if(this.imageContainerResize.originalWidth != imageElement.width || this.imageContainerResize.originalHeight != imageElement.height) {
|
||||||
imageTransformation.resize(imageElement.width,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()
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user