fix #7330 - upload cropbox padding / edit
[roojs1] / examples / dialog / uploadCropbox.js
1 var uploadCropbox = {
2     dialog : false,
3     callback : false,
4
5     show : function(data, cb)
6     {
7         if (!this.dialog) {
8             this.create();
9         }
10
11         this.callback = cb;
12         this.data = data;
13         this.dialog.show();
14     },
15
16     create : function()
17     {
18         var _this = this;
19         this.dialog = Roo.factory({
20             xns : Roo,
21             xtype : 'LayoutDialog',
22             width : 800,
23             height : 600,
24             north : {
25                 xns : Roo,
26                 xtype : 'LayoutRegion',
27                 height : 50
28             },
29             center : {
30                 xns : Roo,
31                 xtype : 'LayoutRegion'
32             },
33             items : [
34                 {
35                     xtype: 'ContentPanel',
36                     xns: Roo,
37                     region : "center",
38                     items : [
39                         {
40                             xtype : 'UploadCropbox',
41                             xns : Roo.dialog,
42                             minWidth : 720,
43                             minHeight : 480,
44                             outputMaxWidth : 1200,
45                             windowSize : 300,
46                             url: 'http://localhost/web.MediaOutreach/press.local.php/Roo/Images.php',
47                             buttons: Roo.dialog.UploadCropbox.footer.CENTER,
48                             listeners : {
49                                 render : function (_self)
50                                 {
51                                     _this.cropbox = _self;
52                                     _this.cropbox.bodyEl.dom.style.height = (parseInt(_this.cropbox.bodyEl.dom.parentNode.parentNode.parentNode.style.height) - 34) + 'px';
53                                     _this.cropbox.bodyEl.dom.style.maxHeight = (parseInt(_this.cropbox.bodyEl.dom.parentNode.parentNode.parentNode.style.height) - 34) + 'px';
54                                 },
55                                 loadcanvas : function (_self, imageEl)
56                                 {
57                                     if(imageEl.OriginWidth < 720) {
58                                         Roo.Msg.show({
59                                             title: 'Error',
60                                             msg: "Image width should be at least 720",
61                                             buttons: {ok : true},
62                                             fn: function(res) {
63                                                 _this.cropbox.selectorEl.dom.value = '';
64                                                 _this.cropbox.selectorEl.dom.click();
65                                             }
66                                         });
67                                         return false;
68                                     }
69                                 },
70                                 arrange : function (_self, formData)
71                                 {
72                                     formData.append("onid", "43024");
73                                     formData.append("ontable", "pressrelease_boilerplate");
74                                 }
75                             }
76                         }
77                     ]
78                 },
79                 {
80                     xtype : 'ContentPanel',
81                     xns: Roo,
82                     region : 'north',
83                     listeners : {
84                         activate : function (_self)
85                         {
86                             var style = 'font:bold 16px sans serif,tahoma,verdana,helvetica; color:rgba(0, 0, 0, 0.5);';
87                             this.setContent("<div style='width:100%; height:50px; display:flex; flex-direction:column; align-items:center; justify-content:center'>" 
88                             + "<h3 style='" + style + "'>Scroll the mouse wheel to resize the image</h3>"
89                             + "<h3 style='" + style + "'>Drag the image to move the image</h3></div>");
90                         }
91                     }
92                }
93             ],
94             buttons : [
95                 {
96                     xtype : 'Button',
97                     xns : Roo,
98                     text : 'Save',
99                     listeners : {
100                         click : function () {
101                             _this.cropbox.crop();
102                             _this.dialog.hide();
103                         }   
104                     }
105                 },
106                 {
107                     xtype : 'Button',
108                     xns : Roo,
109                     text : 'Cancel',
110                     listeners : {
111                         click : function () {
112                             _this.dialog.hide();
113                         }   
114                     }
115                 }
116             ]
117         });
118     }
119 }
120
121 var test = {
122
123     dialog : false,
124     callback : false,
125
126     show : function(data, cb)
127     {
128         if (!this.dialog) {
129             this.create();
130         }
131
132         this.callback = cb;
133         this.data = data;
134         this.dialog.show();
135     },
136
137     create : function()
138     {
139         var _this = this;
140         this.dialog = Roo.factory({
141             xns : Roo,
142             xtype : 'LayoutDialog',
143             width : 600,
144             height : 450,
145             center : {
146                 xns : Roo,
147                 xtype : 'LayoutRegion'
148             },
149             items : [
150                 {
151                     xns : Roo,
152                     xtype: 'GridPanel',
153                     region : "center",
154                     grid : {
155                         xns : Roo.grid,
156                         xtype : 'Grid',
157                         cm : [
158                             {
159                                 xns : Roo.grid,
160                                 xtype : 'ColumnModel',
161                                 header : 'test'
162                             }
163                         ],
164                         ds : {
165                             xns: Roo.data,
166                             xtype: 'Store'
167                         },
168                         toolbar : {
169                             xns: Roo,
170                             xtype: 'Toolbar',
171                             items : [
172                                 { 
173                                     xtype : 'Button',
174                                     text : 'Add',
175                                     listeners : {
176                                         click : function () {
177                                             uploadCropbox.show();
178                                             document.body.onfocus = function(e) {
179                                                 if(!uploadCropbox.cropbox.selectorEl.dom.files.length) {
180                                                     uploadCropbox.dialog.hide();
181                                                 }
182                                             }
183                                             uploadCropbox.cropbox.selectorEl.dom.click();
184                                         }
185                                     }
186                                 }
187                             ]
188                         }
189                     }
190                 }
191             ],
192         });
193     }
194 }
195
196 Roo.onReady(function() {
197     
198     Roo.get('show-dialog-btn').on('click',function () {
199         test.show({});
200     });
201 });