examples/dialog/uploadCropbox.js
[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                                 beforeloadcanvas : function(self, src)
56                                 {
57                                     console.log(src);
58                                 },
59                                 loadcanvas : function (_self, imageEl)
60                                 {
61                                     if(imageEl.OriginWidth < 720) {
62                                         Roo.Msg.show({
63                                             title: 'Error',
64                                             msg: "Image width should be at least 720",
65                                             buttons: {ok : true},
66                                             fn: function(res) {
67                                                 _this.cropbox.selectorEl.dom.value = '';
68                                                 _this.cropbox.selectorEl.dom.click();
69                                             }
70                                         });
71                                         return false;
72                                     }
73                                 },
74                                 arrange : function (_self, formData)
75                                 {
76                                     formData.append("onid", "43024");
77                                     formData.append("ontable", "pressrelease_boilerplate");
78                                 }
79                             }
80                         }
81                     ]
82                 },
83                 {
84                     xtype : 'ContentPanel',
85                     xns: Roo,
86                     region : 'north',
87                     listeners : {
88                         activate : function (_self)
89                         {
90                             var style = 'font:bold 16px sans serif,tahoma,verdana,helvetica; color:rgba(0, 0, 0, 0.5);';
91                             this.setContent("<div style='width:100%; height:50px; display:flex; flex-direction:column; align-items:center; justify-content:center'>" 
92                             + "<h3 style='" + style + "'>Scroll the mouse wheel to resize the image</h3>"
93                             + "<h3 style='" + style + "'>Drag the image to move the image</h3></div>");
94                         }
95                     }
96                }
97             ],
98             buttons : [
99                 {
100                     xtype : 'Button',
101                     xns : Roo,
102                     text : 'Save',
103                     listeners : {
104                         click : function () {
105                             _this.cropbox.crop();
106                             _this.dialog.hide();
107                         }   
108                     }
109                 },
110                 {
111                     xtype : 'Button',
112                     xns : Roo,
113                     text : 'Cancel',
114                     listeners : {
115                         click : function () {
116                             _this.dialog.hide();
117                         }   
118                     }
119                 }
120             ]
121         });
122     }
123 }
124
125 var test = {
126
127     dialog : false,
128     callback : false,
129
130     show : function(data, cb)
131     {
132         if (!this.dialog) {
133             this.create();
134         }
135
136         this.callback = cb;
137         this.data = data;
138         this.dialog.show();
139     },
140
141     create : function()
142     {
143         var _this = this;
144         this.dialog = Roo.factory({
145             xns : Roo,
146             xtype : 'LayoutDialog',
147             width : 600,
148             height : 450,
149             center : {
150                 xns : Roo,
151                 xtype : 'LayoutRegion'
152             },
153             items : [
154                 {
155                     xns : Roo,
156                     xtype: 'GridPanel',
157                     region : "center",
158                     grid : {
159                         xns : Roo.grid,
160                         xtype : 'Grid',
161                         cm : [
162                             {
163                                 xns : Roo.grid,
164                                 xtype : 'ColumnModel',
165                                 header : 'test'
166                             }
167                         ],
168                         ds : {
169                             xns: Roo.data,
170                             xtype: 'Store'
171                         },
172                         toolbar : {
173                             xns: Roo,
174                             xtype: 'Toolbar',
175                             items : [
176                                 { 
177                                     xtype : 'Button',
178                                     text : 'Add',
179                                     listeners : {
180                                         click : function () {
181                                             uploadCropbox.show();
182                                             document.body.onfocus = function(e) {
183                                                 if(!uploadCropbox.cropbox.selectorEl.dom.files.length) {
184                                                     uploadCropbox.dialog.hide();
185                                                 }
186                                             }
187                                             uploadCropbox.cropbox.selectorEl.dom.click();
188                                         }
189                                     }
190                                 }
191                             ]
192                         }
193                     }
194                 }
195             ],
196         });
197     }
198 }
199
200 Roo.onReady(function() {
201     
202     Roo.get('show-dialog-btn').on('click',function () {
203         test.show({});
204     });
205 });