-
Notifications
You must be signed in to change notification settings - Fork 8
/
Extamples.CropWindow.js
79 lines (76 loc) · 2.07 KB
/
Extamples.CropWindow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Licence:
* You can use the Code as you like, only the URL http//www.thomas-lauria.de/ has to be in the used Files / Code
* @author Thomas Lauria
* http://www.thomas-lauria.de
*/
Ext.ns('Extamples');
Ext.define('Extamples.CropWindow', {
requires:['Ext.Window'],
extend: 'Ext.Window',
cropData: null,
imageUrl: '',
title: 'Image Crop Utility',
width: 660,
height: 510,
modal: true,
initComponent: function() {
this.fbar = {
xtype: 'toolbar',
items: [
{
xtype: 'button',
text: 'cancel',
itemId: 'cancelButton'
},
{
xtype: 'button',
text: 'save',
itemId: 'saveButton'
}
]
};
// I am using an image preloader here, for getting the initial height and width
this.callParent(arguments);
var imgLoad = new Image();
imgLoad.onload = (function(){
this.setSize(imgLoad.width + 20, imgLoad.height + 70);
var crop = new Ext.ux.ImageCrop({
src: this.imageUrl,
width: imgLoad.width,
height: imgLoad.height,
minWidth: 110,
minHeight: 110,
quadratic: true
});
crop.on('changeCrop', function(foo,x) {this.cropData = x;}, this);
this.add(crop);
}).bind(this);
imgLoad.src = this.imageUrl;
// handler for the buttons
this.down('#cancelButton').on('click', this.close, this);
this.down('#saveButton').on('click', this.saveCrop, this);
},
saveCrop: function() {
Ext.get('output-2').update('X Offset: '+this.cropData.x+' Y Offset: '+this.cropData.y+' Width: '+this.cropData.width+' Height: '+this.cropData.height);
if(this.fireEvent('save', this) === false){
return this;
}
this.close();
/*
* or you can use a ajax call!
Ext.Ajax.request({
url: this.imageUrl,
method: 'post',
params: this.cropData,
success: function(){
if(this.fireEvent('save', this) === false){
return this;
}
this.close();
},
scope: this
});
*/
}
});