2007-09-15 03:08:25 +02:00
|
|
|
/**
|
|
|
|
* @author Mateusz
|
|
|
|
*/
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.ImageTransformation = {
|
2007-09-15 03:08:25 +02:00
|
|
|
initialize: function() {
|
2007-09-16 02:49:34 +02:00
|
|
|
this.currentOperation = "";
|
|
|
|
this.currentResponse = new Array();
|
|
|
|
this.currentCallback = null;
|
2007-10-03 01:26:35 +02:00
|
|
|
this.resize = ImageEditor.ImageTransformation.resize.bind(this);
|
|
|
|
this.rotate = ImageEditor.ImageTransformation.rotate.bind(this);
|
|
|
|
this.crop = ImageEditor.ImageTransformation.crop.bind(this);
|
|
|
|
this.save = ImageEditor.ImageTransformation.save.bind(this);
|
|
|
|
this.close = ImageEditor.ImageTransformation.close.bind(this);
|
|
|
|
this.onSuccess = ImageEditor.ImageTransformation.onSuccess.bind(this);
|
|
|
|
this.onImageLoad = ImageEditor.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-10-03 01:26:35 +02:00
|
|
|
if(ImageEditor.imageHistory.modifiedOriginalImage) {
|
|
|
|
var fileToResize = $('image').src;
|
2007-09-15 03:08:25 +02:00
|
|
|
} else {
|
2007-10-03 01:26:35 +02:00
|
|
|
var fileToResize = ImageEditor.imageEditor.originalImageFile;
|
2007-09-15 03:08:25 +02:00
|
|
|
}
|
|
|
|
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) {
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.imageBox.showIndicator($('Main'));
|
2007-09-15 22:54:37 +02:00
|
|
|
} else {
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.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
|
|
|
};
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.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
|
|
|
};
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.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;
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.imageBox.hideIndicator();
|
|
|
|
ImageEditor.resize.imageContainerResize.originalWidth = this.currentResponse.width;
|
|
|
|
ImageEditor.resize.imageContainerResize.originalHeight = this.currentResponse.height;
|
2007-09-16 02:49:34 +02:00
|
|
|
$('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';
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.imageHistory.add(this.currentOperation,$('image').src);
|
2007-09-16 02:49:34 +02:00
|
|
|
if(this.currentCallback != null) this.currentCallback();
|
2007-09-15 03:08:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|