-
Notifications
You must be signed in to change notification settings - Fork 15
/
HtmlEditorImage.js
1699 lines (1543 loc) · 57 KB
/
HtmlEditorImage.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* HtmlEditorImageUpload plugin for Ext htmlEditor
*
* Adds a button to upload/insert/edit images
*
* @author Sami Racho
* @date December 2011
* @version 0.3
*
* @license Ext.ux.form.HtmlEditor.imageUpload is licensed under the terms of
* the Open Source LGPL 3.0 license. Commercial use is permitted to the extent
* that the code/component(s) do NOT become part of another Open Source or Commercially
* licensed development library or toolkit without explicit permission.
*
* License details: http://www.gnu.org/licenses/lgpl.html
*/
/**
* @class Ext.ux.form.HtmlEditor.imageUpload
*
* Creates new HtmlEditor.imageUpload plugin
* @constructor
* @param {Object} config The config object
*
* How to use
*
Just instatiate a new HtmlEditor.imageUpload inside htmlEditor plugins option:
xtype: 'htmleditor',
plugins: [new Ext.create('Ext.ux.form.HtmlEditor.imageUpload', {submitUrl:'myUploadScript.php',})],
height: 400,
style: 'background-color: white;',
anchor: '100%',
value: ''
*/
Ext.define('Ext.ux.form.HtmlEditor.imageUpload', {
/**
* @cfg {Array} options
* Associative array with all the strings.
* If not specified it will show all the strings in english
*/
lang: {
'Display': '',
'By Default': '',
'Inline': '',
'Block': '',
'Insert/Edit Image': '',
'Upload Image...': '',
'Uploading your photo...': '',
'Error': '',
'Width': '',
'Height': '',
'Align': '',
'Title': '',
'Class': '',
'Padding': '',
'Margin': '',
'Top': '',
'Bottom': '',
'Right': '',
'Left': '',
'None': '',
'Size & Details': '',
'More Options': '',
'Style': '',
'OK': '',
'Cancel': '',
'Delete Image': '',
'Confirmation': '',
'Are you sure you want to delete this image?': '',
'Your photo has been uploaded.': '',
'Real Size': ''
},
/**
* @cfg {String} submitUrl
* Path to the upload script.
* Default 'htmlEditorImageUpload.php'
*/
submitUrl: 'htmlEditorImageUpload.php',
/**
* @cfg {String} serverSideEdit
* Enables/disables server side image editing buttons.
* Default false
*/
disableServerSideEdit: false,
/**
* @cfg {String} serverSideEdit
* Enables/disables server side image deletion.
* Default false
*/
disableDelete: false,
/**
* @cfg {String} styling
* Enables/disables image css styling.
* Default false
*/
disableStyling: false,
/**
* @cfg {String} mamangerUrl
* Path to the image manager script.
* Default 'htmlEditorImageManager.php'
*/
managerUrl: 'htmlEditorImageUpload.php',
/**
* @cfg {integer} pageSize
* Number of images to show on the list.
* Default 6
*/
pageSize: 6,
/**
* @cfg {Boolean} values are:
* true : Default
* Allows the user to resize an image clicking on it and dragging with the mouse. (Only WebKit browsers)
* false
* The image wont be resized if the user drags on it
*/
dragResize: true,
/**
* @cfg {Boolean} values are:
* false : Default
* Context menu for images enabled
* true
* Context menu will not be avaible
*/
enableContextMenu: false,
/**
* @cfg {Boolean} values are:
* true : Default
* Allows the user to resize an image clicking on it and using the mousewheel. (Only WebKit browsers & Opera)
*
* false
* The image wont be resized if the user uses mousewheel on it
*/
wheelResize: true,
/**
* @cfg {String} iframeCss
* Path to the iframe css file.
* It's important to do not merge this css with other CSS files, because it will be applied to the htmleditor
* iframe head. If more css rules are included, it can suffer undesired effects
* Default 'css/iframe_styles.css'
*/
iframeCss: 'css/iframe_styles.css',
t: function (string) {
return this.lang[string] ? this.lang[string] : string;
},
constructor: function (config) {
Ext.apply(this, config);
this.callParent(arguments);
},
init: function (panel) {
this.cmp = panel;
this.cmp.on('render', this.onRender, this);
this.cmp.on('initialize', this.initialize, this);
this.cmp.on('beforedestroy', this.beforeDestroy, this);
},
initialize: function () {
var me = this;
var cmpDoc = this.cmp.getDoc();
me.flyDoc = Ext.fly(cmpDoc);
// Inject custom css file to iframe's head in order to simulate image control selector on click, over webKit and Opera browsers
if ((Ext.isWebKit || Ext.isOpera)) me._injectCss(me.cmp, me.iframeCss);
// attach context menu
if(me.enableContextMenu)me._contextMenu();
// attach events to control when the user interacts with an image
me.cmp.mon(me.flyDoc, 'dblclick', me._dblClick, me, {delegate : "img"});
me.cmp.mon(me.flyDoc, 'mouseup', me._docMouseUp, me);
me.cmp.mon(me.flyDoc, 'paste', me._removeSelectionHelpers, me);
// mousewheel resize event
if ((Ext.isWebKit || Ext.isOpera) && me.wheelResize) {
me.cmp.mon(me.flyDoc, 'mousewheel', me._wheelResize, me, {delegate : "img"});
}
// mouse drag resize event
if (Ext.isWebKit && me.dragResize) {
me.cmp.mon(me.flyDoc, 'drag', me._dragResize, me, {delegate : "img"});
}
},
beforeDestroy: function () {
var me = this;
if (me.uploadDialog) me.uploadDialog.destroy();
if (me.contextMenu) me.contextMenu.destroy();
},
onRender: function () {
var me = this;
var imageButton = Ext.create('Ext.button.Button', {
iconCls: 'x-htmleditor-imageupload',
handler: me._openImageDialog,
scope: me,
tooltip: me.t('Insert/Edit Image'),
overflowText: me.t('Insert/Edit Image')
});
var toolbar = me.cmp.getToolbar();
// we save a reference to this button to use it later
me.imageButton = imageButton;
me.cmp.getToolbar().add(imageButton);
},
//private
_contextMenu: function () {
var me = this;
if (!me.contextMenu) {
var editAction = Ext.create('Ext.Action', {
text: me.t('Edit'),
iconCls: 'x-htmleditor-imageupload-editbutton',
disabled: false,
handler: me._openImageDialog,
scope: me
});
var deleteAction = Ext.create('Ext.Action', {
iconCls: 'x-htmleditor-imageupload-deletebutton',
text: me.t('Delete'),
disabled: false,
handler: function () {
me.cmp.execCmd('delete')
}
});
var contextMenu = Ext.create('Ext.menu.Menu', {
closeAction: 'hide',
items: [editAction, deleteAction]
});
me.contextMenu = contextMenu;
}
me.cmp.mon(me.flyDoc, 'contextmenu', function (e, htmlEl) {
e.stopEvent();
e.stopPropagation();
var iframePos = this.cmp.getPosition();
var elementPos = e.getXY();
var pos = [iframePos[0] + elementPos[0], iframePos[1] + elementPos[1] + 30];
if (e.getTarget().tagName == 'IMG');
Ext.Function.defer(function () {
me.contextMenu.showAt(pos)
}, 100);
},
me,
{delegate:'img'}
);
},
//private
// instead of overriding the htmleditor header method we just append another css file to it's iframe head
_injectCss: function (cmp, cssFile) {
var frameName = cmp.iframeEl.dom.name;
var iframe;
if (document.frames) iframe = document.frames[frameName];
else iframe = window.frames[frameName];
// we have to add our custom css file to the iframe
var ss = iframe.document.createElement("link");
ss.type = "text/css";
ss.rel = "stylesheet";
ss.href = cssFile;
if (document.all) iframe.document.createStyleSheet(ss.href);
else iframe.document.getElementsByTagName("head")[0].appendChild(ss);
},
// private
_dblClick: function (evt) {
var me = this;
var target = evt.getTarget();
if (target.tagName == "IMG") {
me._openImageDialog()
}
},
//private
_openImageDialog: function () {
var me = this;
var cmp = this.cmp;
var doc = this.cmp.getDoc();
var win = this.cmp.win;
var sel = "";
var range = "";
var image = "";
var imagesList = doc.body.getElementsByTagName("IMG");
var imagesListLength = imagesList.length;
//insertAtCursor function is completely useless for this purpose, so I need to write all this stuff to insert html at caret position
// I need to know if the browser uses the W3C way or the Internet Explorer method
var ieBrowser = doc.selection && doc.selection.createRange ? true : false;
var nonIeBrowser = win.getSelection && win.getSelection().getRangeAt ? true : false;
if (nonIeBrowser) {
sel = win.getSelection();
// if focus is not in htmleditor area
try {
range = sel.getRangeAt(0);
} catch (err) {
win.focus();
range = sel.getRangeAt(0);
}
} else if (ieBrowser) {
//it's compulsory to get the focus before creating the range, if not we'll lose the caret position
win.focus();
sel = doc.selection;
range = sel.createRange();
}
// to make the things easier, if the user has an image selected when he presses the image upload button, I'll mark it with a custom attr "iu_edit".
// afterwards, if the user presses the ok button I just need to find the image with that attr, and replace it with the new one.
if (Ext.isIE && sel.type == "Control" && range.item(0).tagName == "IMG") {
image = r;
} else if (range.startContainer == range.endContainer) {
if (range.endOffset - range.startOffset < 2) {
if (range.startContainer.hasChildNodes()) {
var r = range.startContainer.childNodes[range.startOffset];
if (r.tagName) {
if (r.tagName == "IMG") image = r;
}
}
}
}
if (!image) {
//if we dont find the image we try to search by editable attr
for (i = 0; i < imagesListLength; i++) {
if (parseInt(imagesList[i].getAttribute('iu_edit')) > 0) {
image = imagesList[i];
break;
}
}
}
me.uploadDialog = Ext.create('Ext.ux.form.HtmlEditor.ImageDialog', {
lang: me.lang,
t: me.t,
submitUrl: me.submitUrl,
managerUrl: me.managerUrl,
iframeDoc: doc,
imageToEdit: image,
pageSize: me.pageSize,
imageButton: me.imageButton,
disableServerSideEdit: me.serverSideEdit,
disableStyling:me.styling,
disableDelete : me.disableDelete
});
me.uploadDialog.on('close', function () {
if (Ext.isIE) {
me.imageButton.toggle(false);
me._removeSelectionHelpers()
}
}, me);
// custom event that fires when the user presses the ok button on the dialog
me.uploadDialog.on('imageloaded', function () {
var newImage = this.getImage();
// if it's an edited image, we have to replace it with the new values
if (image != "") {
for (i = 0; i < imagesListLength; i++) {
if (parseInt(imagesList[i].getAttribute('iu_edit')) > 0) {
if (nonIeBrowser) {
imagesList[i].parentNode.replaceChild(newImage, imagesList[i]);
try {
if (sel) {
sel.selectAllChildren(doc.body);
sel.collapseToStart();
}
} catch (ex) {};
} else if (ieBrowser) {
imagesList[i].outerHTML = newImage.outerHTML;
}
break;
}
}
}
// if not we just insert a new image on the document
else {
if (nonIeBrowser) {
range.insertNode(newImage);
} else if (ieBrowser) {
win.focus();
range.select();
range.pasteHTML(newImage.outerHTML);
}
}
me.imageToEdit = "";
this.close();
me.imageButton.toggle(false);
});
me.uploadDialog.show();
},
//private
//Remove custom image attrs from the iframe body DOM
_removeSelectionHelpers: function () {
var me = this;
var imagesList = me.cmp.getDoc().body.getElementsByTagName("IMG");
var imagesListLength = imagesList.length;
for (i = 0; i < imagesListLength; i++) {
imagesList[i].removeAttribute('iu_edit');
}
},
//private
//When user uses mousewheel over an image
_wheelResize: function (e) {
var target = e.getTarget();
if (target.tagName == "IMG" && target.getAttribute('iu_edit') == 1) {
var delta = e.getWheelDelta();
var width = target.style.width ? parseInt(target.style.width.replace(/[^\d.]/g, "")) : target.width;
var height = target.style.height ? parseInt(target.style.height.replace(/[^\d.]/g, "")) : target.height;
target.removeAttribute('height');
target.style.removeProperty('height');
// change just width to keep aspect ratio
target.style.width = (delta < 1) ? width - 10 : width + 10;
e.preventDefault();
} else return;
},
//private
//When user drags over an image
_dragResize: function (e) {
var target = e.getTarget();
if (target.tagName == "IMG" && (target.getAttribute('iu_edit') == 1)) {
var width = e.getX() - target.offsetLeft;
var height = e.getY() - target.offsetTop;
target.style.width = width + "px";
target.style.height = height + "px";
e.preventDefault();
} else return;
},
//private
//When user clicks on content editable area
_docMouseUp: function (evt) {
var me = this;
var target = evt.getTarget();
me._removeSelectionHelpers();
if (target.tagName == "IMG") {
me.imageButton.toggle(true);
if ((me.wheelResize || me.dragResize) && (Ext.isWebKit || Ext.isOpera)) target.setAttribute('iu_edit', '1');
else target.setAttribute('iu_edit', '2');
// select image.
// On safari if we copy and paste the image, class attrs are converted to inline styles. It's a browser bug.
if (Ext.isWebKit) {
var sel = this.cmp.getWin().getSelection ? this.cmp.getWin().getSelection() : this.cmp.getWin().document.selection;
sel.setBaseAndExtent(target, 0, target, 1);
}
} else me.imageButton.toggle(false);
}
});
Ext.define('Ext.ux.form.HtmlEditor.ImageCropDialog', {
extend: 'Ext.window.Window',
imgSrc:'',
randomId:'',
bodyCls:'x-htmleditor-imageupload-cropdialog',
naturalWidth:0,
naturalHeight:0,
maxWidth:700,
maxHeight:500,
height:350,
width:400,
minHeight:350,
minWidth:400,
myResizer:null,
managerUrl:null,
autoScroll:true,
initComponent: function () {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype:'container',
html:'<div id="myResizable" style="position: absolute;z-index:9999;"></div>'
},
{
xtype: 'image',
itemId:'imageToCrop',
src: me.imgSrc+'?'+Math.floor(Math.random()*111111),
listeners: {
afterrender: me._attachOnLoadEvent,
scope:me
}
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
labelWidth:50,
xtype: 'slider',
itemId:'zoomSlider',
width: 150,
value: 100,
minValue:0,
maxValue:200,
fieldLabel: 'Zoom',
listeners:{
change:me._sliderChange,
scope:me
}
}
]
},{
xtype: 'container',
dock: 'bottom',
padding: 4,
items: [{
xtype: 'button',
style: {
'float': 'right'
},
text: 'Cancel',
handler: me.close,
scope: me
}, {
xtype: 'button',
style: {
'float': 'right',
'margin-right': '8px'
},
text: 'OK',
handler: me._cropImage,
scope: me
}]
}]
});
me.callParent(arguments);
me.setTitle('Crop Image');
},
//private
_attachOnLoadEvent: function (comp) {
var me = this;
var flyImg = Ext.fly(comp.getEl().dom);
comp.mon(flyImg, 'load', me._setupResizer, comp);
},
//private
_sliderChange: function(slider)
{
var me = this;
var imgToCrop = me.down('#imageToCrop');
var zoom = Math.round(me.naturalWidth*(slider.getValue()/100));
imgToCrop.setWidth(zoom);
},
//private
_setupResizer: function(ev,el)
{
var imageComp = this;
var cropWindow = this.up('window');
cropWindow.naturalWidth = el.width;
cropWindow.naturalHeight = el.height;
cropWindow.setWidth(el.width+12);
cropWindow.setHeight(el.height+94);
cropWindow.center();
if(!cropWindow.myResizer)
cropWindow.myResizer = Ext.create('Ext.resizer.Resizer', {
el: 'myResizable',
constrainTo:imageComp.getEl(),
handles: 'all',
minWidth: 16,
minHeight: 16,
width: 32,
height: 32,
pinned: true
});
},
//private
//method to crop the image
_cropImage: function (fileField) {
var me = this;
Ext.Msg.show({
title: 'Confirmation',
msg: 'Are you sure you want to crop this image?',
buttons: Ext.Msg.YESNO,
closable: false,
fn: function (btn) {
if (btn == 'yes') {
Ext.Ajax.request({
url: me.managerUrl,
method: 'POST',
params: {
'action': 'crop',
'image': me.imgSrc,
'zoom': me.down('#zoomSlider').getValue(),
'width': me.myResizer.getEl().dom.offsetWidth,
'height': me.myResizer.getEl().dom.offsetHeight,
'offsetLeft': me.myResizer.getEl().dom.offsetLeft,
'offsetTop':me.myResizer.getEl().dom.offsetTop
},
success: function (response) {
var result = Ext.JSON.decode(response.responseText);
if(result.success)
{
me.imgSrc = result.data['src'];
me.fireEvent('imagecropped');
}else{
Ext.Msg.alert('Error', 'Error: ' + result.errors);
}
}
});
}
}
});
}
});
Ext.define('Ext.ux.form.HtmlEditor.ImageDialog', {
extend: 'Ext.window.Window',
lang: null,
lang: null,
t: null,
submitUrl: null,
managerUrl: null,
iframeDoc: null,
pageSize: null,
imageToEdit: '',
closeAction: 'destroy',
width: 460,
modal: true,
resizable: false,
layout: {
type: 'fit'
},
title: '',
listeners: {
show: function (panel) {
// we force the focus on the dialog window to avoid control artifacts on IE
this._loadImageDetails();
panel.down('[name=src]').focus();
},
resize: function (panel) {
panel.center();
}
},
initComponent: function () {
var me = this;
var imageStore = Ext.create('Ext.data.Store', {
fields: [{
name: 'name',
type: 'string'
}, {
name: 'fullname',
type: 'string'
}, {
name: 'src',
type: 'string'
}, {
name: 'thumbSrc',
type: 'string'
}],
proxy: {
type: 'ajax',
url: me.managerUrl,
extraParams: {
action: 'imagesList'
},
reader: {
type: 'json',
root: 'data'
}
},
autoLoad: false,
pageSize: me.pageSize
});
// if I dont remove store records I get an internalId exception when refresh button is clicked
imageStore.on('beforeload', function (store)
{
while (store.getCount(0) > 0)
store.removeAt(0);
});
var alignStore = Ext.create('Ext.data.ArrayStore', {
autoDestroy: true,
idIndex: 0,
fields: [{
name: 'name',
type: 'string'
}, {
name: 'value',
type: 'string'
}],
data: [
[me.t('Left'), 'left'],
[me.t('None'), 'none'],
[me.t('Right'), 'right']
]
});
var displayStore = Ext.create('Ext.data.ArrayStore', {
autoDestroy: true,
idIndex: 0,
fields: [{
name: 'name',
type: 'string'
}, {
name: 'value',
type: 'string'
}],
data: [
[me.t('By Default'), ''],
[me.t('Inline'), 'inline'],
[me.t('Block'), 'block']
]
});
var unitsStore = Ext.create('Ext.data.ArrayStore', {
autoDestroy: true,
idIndex: 0,
fields: [{
name: 'name',
type: 'string'
}, {
name: 'value',
type: 'string'
}],
data: [
['px', 'px'],
['%', '%'],
['em', 'em'],
['in', 'in'],
['cm', 'cm'],
['mm', 'mm'],
['ex', 'ex'],
['pt', 'pt'],
['pc', 'pc']
]
});
me.items = [{
xtype: 'form',
name: 'imageUploadForm',
bodyPadding: 10,
items: [{
xtype: 'fieldcontainer',
height: 36,
padding: 4,
width: 450,
layout: {
columns: 2,
type: 'column'
},
items: [{
xtype: 'combobox',
name: 'src',
queryMode: 'remote',
fieldLabel: 'Url',
labelWidth: 50,
columnWidth: 0.70,
margin: '0 4 0 0',
editable: true,
allowBlank: true,
store: imageStore,
displayField: 'src',
valueField: 'src',
needsRefresh: false,
checkChangeBuffer: 500,
listeners: {
'expand': {
fn: me._comboExpand,
scope:me
},
'change': {
fn: me._comboChange,
scope: me
},
'select':{
fn: me._comboSelect,
scope: me
}
},
tpl: '<tpl for="."><table class="x-boundlist-item" style="width:50%;float:left"><tr><td style="vertical-align:top;width:12px"><tpl if="'+me.disableDelete+' == false"><a title="' + me.t('Delete Image') + '" href="#" img_fullname="{fullname}" class="x-htmleditor-imageupload-delete"></a></tpl></td><td><div class="x-htmleditor-imageupload-thumbcontainer"><img src="{thumbSrc}"/></div></td></tr><tr><td colspan="2" style="text-align:center;font-size:12px">{name}</td></tr></table></tpl>',
listConfig: {
loadingText: 'Searching...',
emptyText: 'No matching posts found.',
listeners: {
el: {
click: {
delegate: 'a.x-htmleditor-imageupload-delete',
scope:me,
fn: me._deleteImage
}
}
}
},
pageSize: me.pageSize
}, {
xtype: 'filefield',
buttonOnly: true,
name: 'photo-path',
name: 'photo-path',
value: '',
columnWidth: 0.30,
buttonText: me.t('Upload Image...'),
listeners: {
change: me._uploadImage,
scope: me
}
}]
}, {
xtype: 'fieldset',
title: me.t('More Options'),
itemId: 'fieldOptions',
collapsible: true,
layout: 'anchor',
collapsed: true,
defaults: {
anchor: '100%',
labelWidth: 72
},
items: [{
xtype: 'fieldset',
title: me.t('Size & Details'),
collapsible: true,
layout: 'anchor',
collapsed: false,
layout: {
type: 'table',
columns: 2
},
defaults: {
anchor: '100%',
labelWidth: 72
},
items: [{
xtype: 'container',
margin: 4,
padding: 1,
layout: {
align: 'middle',
pack: 'center',
type: 'hbox'
},
style: {
border: '1px solid #ccc'
},
height: 130,
width: 130,
padding:2,
items: [{
xtype: 'image',
itemId: 'vistaPrevia',
id:'',
resetImageSize: false,
listeners: {
afterrender: me._attachOnLoadEvent,
scope: me
}
}]
}, {
xtype: 'fieldcontainer',
layout: {
type: 'table',
columns: 3
},
defaults: {
labelSeparator: ' ',
fieldLabel: '',
labelAlign: 'left',
labelWidth: 72,
decimalSeparator: '.',
width: 164,
margin: '0 4 4 0'
},
items: [{
colspan: 3,
xtype: 'combobox',
width: 216,
name: 'float',
queryMode: 'local',
editable: false,
allowBlank: false,
fieldLabel: me.t('Align'),
value: 'left',
store: alignStore,
displayField: 'name',
valueField: 'value'
}, {
xtype: 'numberfield',
fieldLabel: me.t('Width'),
name: 'width',
minValue: 1,
maxValue: 9999,
constrainName: 'height',
listeners: {
change: me._checkConstrain
}
}, {
xtype: 'combobox',
name: 'widthUnits',
queryMode: 'local',
width: 48,
editable: false,
allowBlank: false,
emptyText: 'None',
value: 'px',
store: unitsStore,
displayField: 'name',
valueField: 'value'
}, {
rowspan: 2,
xtype: 'button',
itemId: 'constraintProp',
cls: 'x-htmleditor-imageupload-constrain',
enableToggle: true,
pressed: true,
style: {
border: '0px'
},
width: 24,
height: 50,
listeners: {
toggle: me._toggleConstrain,
scope: me
}
}, {
xtype: 'numberfield',
fieldLabel: me.t('Height'),
name: 'height',
minValue: 1,
maxValue: 9999,
constrainName: 'width',
listeners: {
change: me._checkConstrain
}
}, {
xtype: 'combobox',
name: 'heightUnits',
queryMode: 'local',
width: 48,
editable: false,
allowBlank: false,
emptyText: 'None',
value: 'px',
store: unitsStore,
displayField: 'name',
valueField: 'value'
}, {
colspan: 3,
xtype: 'displayfield',
fieldLabel: 'Real Size',