2007-09-15 03:08:25 +02:00
|
|
|
/**
|
|
|
|
* @author Mateusz
|
|
|
|
*/
|
|
|
|
var ImageTransformation = {
|
|
|
|
initialize: function() {
|
2007-09-16 02:49:34 +02:00
|
|
|
this.currentOperation = "";
|
|
|
|
this.currentResponse = new Array();
|
|
|
|
this.currentCallback = null;
|
2007-09-15 03:08:25 +02:00
|
|
|
this.resize = ImageTransformation.resize.bind(this);
|
|
|
|
this.rotate = ImageTransformation.rotate.bind(this);
|
|
|
|
this.crop = ImageTransformation.crop.bind(this);
|
|
|
|
this.save = ImageTransformation.save.bind(this);
|
2007-09-15 03:13:18 +02:00
|
|
|
this.close = ImageTransformation.close.bind(this);
|
2007-09-16 02:49:34 +02:00
|
|
|
this.onSuccess = ImageTransformation.onSuccess.bind(this);
|
|
|
|
this.onImageLoad = ImageTransformation.onImageLoad.bind(this);
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
|
2007-09-15 22:54:37 +02:00
|
|
|
resize: function(width,height,callback,imageAlreadyChangedSize) {
|
2007-09-16 02:49:34 +02:00
|
|
|
this.currentOperation = "resize";
|
|
|
|
this.currentCallback = callback;
|
2007-09-15 03:08:25 +02:00
|
|
|
if(imageHistory.modifiedOriginalImage) {
|
|
|
|
fileToResize = $('image').src;
|
|
|
|
} else {
|
|
|
|
fileToResize = imageEditor.originalImageFile;
|
|
|
|
}
|
|
|
|
var options = {
|
|
|
|
method: 'post',
|
|
|
|
postBody: 'command=resize&file=' + fileToResize + '&newImageWidth=' + width + '&newImageHeight=' + height,
|
2007-09-16 02:49:34 +02:00
|
|
|
onSuccess: this.onSuccess
|
|
|
|
};
|
|
|
|
|
2007-09-15 22:54:37 +02:00
|
|
|
if(imageAlreadyChangedSize == false) {
|
|
|
|
imageBox.showIndicator($('mainContainer'));
|
|
|
|
} else {
|
2007-09-16 02:49:34 +02:00
|
|
|
imageBox.showIndicator();
|
2007-09-15 22:54:37 +02:00
|
|
|
}
|
2007-09-15 03:19:43 +02:00
|
|
|
new Ajax.Request('admin/ImageEditor/manipulate', options);
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
|
2007-09-15 03:31:31 +02:00
|
|
|
rotate: function(angle,callback) {
|
2007-09-16 02:49:34 +02:00
|
|
|
this.currentOperation = "rotate";
|
|
|
|
this.currentCallback = callback;
|
2007-09-15 03:08:25 +02:00
|
|
|
var options = {
|
|
|
|
method: 'post',
|
|
|
|
postBody: 'command=rotate&file=' + $('image').src + '&angle=' + angle ,
|
2007-09-16 02:49:34 +02:00
|
|
|
onSuccess: this.onSuccess
|
2007-09-15 03:08:25 +02:00
|
|
|
};
|
|
|
|
imageBox.showIndicator();
|
2007-09-15 03:09:25 +02:00
|
|
|
new Ajax.Request('admin/ImageEditor/manipulate', options);
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
|
2007-09-15 03:31:31 +02:00
|
|
|
crop: function(top,left,width,height,callback) {
|
2007-09-16 02:49:34 +02:00
|
|
|
this.currentOperation = "crop";
|
|
|
|
this.currentCallback = callback;
|
2007-09-15 03:08:25 +02:00
|
|
|
var options = {
|
|
|
|
method: 'post',
|
|
|
|
postBody: 'command=crop&file=' + $('image').src + '&top=' + top + '&left=' + left + '&width=' + width + '&height=' + height,
|
2007-09-16 02:49:34 +02:00
|
|
|
onSuccess: this.onSuccess
|
2007-09-15 03:08:25 +02:00
|
|
|
};
|
|
|
|
imageBox.showIndicator();
|
2007-09-15 03:26:36 +02:00
|
|
|
new Ajax.Request('admin/ImageEditor/manipulate', options);
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
|
2007-09-15 22:53:26 +02:00
|
|
|
save: function(originalFile,editedFile,callback) {
|
2007-09-15 03:08:25 +02:00
|
|
|
var options = {
|
|
|
|
method: 'post',
|
|
|
|
postBody: 'command=save&editedFile=' + editedFile + '&originalFile=' + originalFile,
|
|
|
|
onSuccess: function(transport) {
|
2007-09-15 03:13:18 +02:00
|
|
|
eval(transport.responseText);
|
2007-09-15 22:53:26 +02:00
|
|
|
callback();
|
2007-09-15 03:19:43 +02:00
|
|
|
}
|
2007-09-15 03:08:25 +02:00
|
|
|
};
|
2007-09-15 03:13:18 +02:00
|
|
|
new Ajax.Request('admin/ImageEditor/save', options);
|
|
|
|
},
|
|
|
|
|
2007-09-15 22:53:26 +02:00
|
|
|
close: function(callback) {
|
2007-09-15 03:13:18 +02:00
|
|
|
var options = {
|
|
|
|
method: 'post',
|
|
|
|
postBody: '',
|
|
|
|
onSuccess: function(transport) {
|
|
|
|
eval(transport.responseText);
|
2007-09-15 22:53:26 +02:00
|
|
|
callback();
|
2007-09-15 03:19:43 +02:00
|
|
|
}
|
2007-09-15 03:13:18 +02:00
|
|
|
};
|
|
|
|
new Ajax.Request('admin/ImageEditor/close', options);
|
2007-09-16 02:49:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onSuccess: function(transport) {
|
|
|
|
this.currentResponse = eval('(' + transport.responseText + ')');
|
|
|
|
$('fakeImg').src = this.currentResponse.fileName;
|
|
|
|
Event.observe('fakeImg','load',this.onImageLoad);
|
|
|
|
},
|
|
|
|
|
|
|
|
onImageLoad: function(event) {
|
|
|
|
Event.stopObserving('fakeImg','load', this.onImageLoad);
|
|
|
|
$('image').src = this.currentResponse.fileName;
|
|
|
|
imageBox.hideIndicator();
|
|
|
|
resize.imageContainerResize.originalWidth = this.currentResponse.width;
|
|
|
|
resize.imageContainerResize.originalHeight = this.currentResponse.height;
|
|
|
|
$('imageContainer').style.height = this.currentResponse.height + 'px';
|
|
|
|
$('imageContainer').style.width = this.currentResponse.width + 'px';
|
|
|
|
$('image').style.height = this.currentResponse.height + 'px';
|
|
|
|
$('image').style.width = this.currentResponse.width + 'px';
|
|
|
|
imageHistory.add(this.currentOperation,$('image').src);
|
|
|
|
if(this.currentCallback != null) this.currentCallback();
|
2007-09-15 03:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|